mirror of
https://github.com/love2d/love.git
synced 2026-08-16 00:02:12 +02:00
CRLF to LF
This commit is contained in:
@@ -1,52 +1,52 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#include "Body.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
|
||||
Body::~Body()
|
||||
{
|
||||
}
|
||||
|
||||
bool Body::getConstant(const char *in, Type &out)
|
||||
{
|
||||
return types.find(in, out);
|
||||
}
|
||||
|
||||
bool Body::getConstant(Type in, const char *&out)
|
||||
{
|
||||
return types.find(in, out);
|
||||
}
|
||||
|
||||
StringMap<Body::Type, Body::BODY_MAX_ENUM>::Entry Body::typeEntries[] =
|
||||
{
|
||||
{"static", Body::BODY_STATIC},
|
||||
{"dynamic", Body::BODY_DYNAMIC},
|
||||
{"kinematic", Body::BODY_KINEMATIC},
|
||||
};
|
||||
|
||||
StringMap<Body::Type, Body::BODY_MAX_ENUM> Body::types(Body::typeEntries, sizeof(Body::typeEntries));
|
||||
|
||||
} // physics
|
||||
} // love
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#include "Body.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
|
||||
Body::~Body()
|
||||
{
|
||||
}
|
||||
|
||||
bool Body::getConstant(const char *in, Type &out)
|
||||
{
|
||||
return types.find(in, out);
|
||||
}
|
||||
|
||||
bool Body::getConstant(Type in, const char *&out)
|
||||
{
|
||||
return types.find(in, out);
|
||||
}
|
||||
|
||||
StringMap<Body::Type, Body::BODY_MAX_ENUM>::Entry Body::typeEntries[] =
|
||||
{
|
||||
{"static", Body::BODY_STATIC},
|
||||
{"dynamic", Body::BODY_DYNAMIC},
|
||||
{"kinematic", Body::BODY_KINEMATIC},
|
||||
};
|
||||
|
||||
StringMap<Body::Type, Body::BODY_MAX_ENUM> Body::types(Body::typeEntries, sizeof(Body::typeEntries));
|
||||
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
+60
-60
@@ -1,60 +1,60 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_PHYSICS_BODY_H
|
||||
#define LOVE_PHYSICS_BODY_H
|
||||
|
||||
// LOVE
|
||||
#include "common/Object.h"
|
||||
#include "common/StringMap.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
|
||||
class Body : public Object
|
||||
{
|
||||
public:
|
||||
|
||||
enum Type
|
||||
{
|
||||
BODY_INVALID,
|
||||
BODY_STATIC,
|
||||
BODY_DYNAMIC,
|
||||
BODY_KINEMATIC,
|
||||
BODY_MAX_ENUM
|
||||
};
|
||||
|
||||
virtual ~Body();
|
||||
|
||||
static bool getConstant(const char *in, Type &out);
|
||||
static bool getConstant(Type in, const char *&out);
|
||||
|
||||
private:
|
||||
|
||||
static StringMap<Type, BODY_MAX_ENUM>::Entry typeEntries[];
|
||||
static StringMap<Type, BODY_MAX_ENUM> types;
|
||||
};
|
||||
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BODY_H
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_PHYSICS_BODY_H
|
||||
#define LOVE_PHYSICS_BODY_H
|
||||
|
||||
// LOVE
|
||||
#include "common/Object.h"
|
||||
#include "common/StringMap.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
|
||||
class Body : public Object
|
||||
{
|
||||
public:
|
||||
|
||||
enum Type
|
||||
{
|
||||
BODY_INVALID,
|
||||
BODY_STATIC,
|
||||
BODY_DYNAMIC,
|
||||
BODY_KINEMATIC,
|
||||
BODY_MAX_ENUM
|
||||
};
|
||||
|
||||
virtual ~Body();
|
||||
|
||||
static bool getConstant(const char *in, Type &out);
|
||||
static bool getConstant(Type in, const char *&out);
|
||||
|
||||
private:
|
||||
|
||||
static StringMap<Type, BODY_MAX_ENUM>::Entry typeEntries[];
|
||||
static StringMap<Type, BODY_MAX_ENUM> types;
|
||||
};
|
||||
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BODY_H
|
||||
|
||||
@@ -1,59 +1,59 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#include "Joint.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
|
||||
Joint::~Joint()
|
||||
{
|
||||
}
|
||||
|
||||
bool Joint::getConstant(const char *in, Type &out)
|
||||
{
|
||||
return types.find(in, out);
|
||||
}
|
||||
|
||||
bool Joint::getConstant(Type in, const char *&out)
|
||||
{
|
||||
return types.find(in, out);
|
||||
}
|
||||
|
||||
StringMap<Joint::Type, Joint::JOINT_MAX_ENUM>::Entry Joint::typeEntries[] =
|
||||
{
|
||||
{"distance", Joint::JOINT_DISTANCE},
|
||||
{"revolute", Joint::JOINT_REVOLUTE},
|
||||
{"prismatic", Joint::JOINT_PRISMATIC},
|
||||
{"mouse", Joint::JOINT_MOUSE},
|
||||
{"pulley", Joint::JOINT_PULLEY},
|
||||
{"gear", Joint::JOINT_GEAR},
|
||||
{"friction", Joint::JOINT_FRICTION},
|
||||
{"weld", Joint::JOINT_WELD},
|
||||
{"wheel", Joint::JOINT_WHEEL},
|
||||
{"rope", Joint::JOINT_ROPE},
|
||||
};
|
||||
|
||||
StringMap<Joint::Type, Joint::JOINT_MAX_ENUM> Joint::types(Joint::typeEntries, sizeof(Joint::typeEntries));
|
||||
|
||||
} // physics
|
||||
} // love
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#include "Joint.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
|
||||
Joint::~Joint()
|
||||
{
|
||||
}
|
||||
|
||||
bool Joint::getConstant(const char *in, Type &out)
|
||||
{
|
||||
return types.find(in, out);
|
||||
}
|
||||
|
||||
bool Joint::getConstant(Type in, const char *&out)
|
||||
{
|
||||
return types.find(in, out);
|
||||
}
|
||||
|
||||
StringMap<Joint::Type, Joint::JOINT_MAX_ENUM>::Entry Joint::typeEntries[] =
|
||||
{
|
||||
{"distance", Joint::JOINT_DISTANCE},
|
||||
{"revolute", Joint::JOINT_REVOLUTE},
|
||||
{"prismatic", Joint::JOINT_PRISMATIC},
|
||||
{"mouse", Joint::JOINT_MOUSE},
|
||||
{"pulley", Joint::JOINT_PULLEY},
|
||||
{"gear", Joint::JOINT_GEAR},
|
||||
{"friction", Joint::JOINT_FRICTION},
|
||||
{"weld", Joint::JOINT_WELD},
|
||||
{"wheel", Joint::JOINT_WHEEL},
|
||||
{"rope", Joint::JOINT_ROPE},
|
||||
};
|
||||
|
||||
StringMap<Joint::Type, Joint::JOINT_MAX_ENUM> Joint::types(Joint::typeEntries, sizeof(Joint::typeEntries));
|
||||
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
+68
-68
@@ -1,68 +1,68 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_PHYSICS_JOINT_H
|
||||
#define LOVE_PHYSICS_JOINT_H
|
||||
|
||||
// LOVE
|
||||
#include "common/Object.h"
|
||||
#include "common/StringMap.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
|
||||
class Joint : public Object
|
||||
{
|
||||
public:
|
||||
|
||||
enum Type
|
||||
{
|
||||
JOINT_INVALID,
|
||||
JOINT_DISTANCE,
|
||||
JOINT_REVOLUTE,
|
||||
JOINT_PRISMATIC,
|
||||
JOINT_MOUSE,
|
||||
JOINT_PULLEY,
|
||||
JOINT_GEAR,
|
||||
JOINT_FRICTION,
|
||||
JOINT_WELD,
|
||||
JOINT_WHEEL,
|
||||
JOINT_ROPE,
|
||||
JOINT_MAX_ENUM
|
||||
};
|
||||
|
||||
|
||||
virtual ~Joint();
|
||||
|
||||
static bool getConstant(const char *in, Type &out);
|
||||
static bool getConstant(Type in, const char *&out);
|
||||
|
||||
private:
|
||||
|
||||
static StringMap<Type, JOINT_MAX_ENUM>::Entry typeEntries[];
|
||||
static StringMap<Type, JOINT_MAX_ENUM> types;
|
||||
};
|
||||
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_JOINT_H
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_PHYSICS_JOINT_H
|
||||
#define LOVE_PHYSICS_JOINT_H
|
||||
|
||||
// LOVE
|
||||
#include "common/Object.h"
|
||||
#include "common/StringMap.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
|
||||
class Joint : public Object
|
||||
{
|
||||
public:
|
||||
|
||||
enum Type
|
||||
{
|
||||
JOINT_INVALID,
|
||||
JOINT_DISTANCE,
|
||||
JOINT_REVOLUTE,
|
||||
JOINT_PRISMATIC,
|
||||
JOINT_MOUSE,
|
||||
JOINT_PULLEY,
|
||||
JOINT_GEAR,
|
||||
JOINT_FRICTION,
|
||||
JOINT_WELD,
|
||||
JOINT_WHEEL,
|
||||
JOINT_ROPE,
|
||||
JOINT_MAX_ENUM
|
||||
};
|
||||
|
||||
|
||||
virtual ~Joint();
|
||||
|
||||
static bool getConstant(const char *in, Type &out);
|
||||
static bool getConstant(Type in, const char *&out);
|
||||
|
||||
private:
|
||||
|
||||
static StringMap<Type, JOINT_MAX_ENUM>::Entry typeEntries[];
|
||||
static StringMap<Type, JOINT_MAX_ENUM> types;
|
||||
};
|
||||
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_JOINT_H
|
||||
|
||||
@@ -1,53 +1,53 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#include "Shape.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
|
||||
Shape::~Shape()
|
||||
{
|
||||
}
|
||||
|
||||
bool Shape::getConstant(const char *in, Type &out)
|
||||
{
|
||||
return types.find(in, out);
|
||||
}
|
||||
|
||||
bool Shape::getConstant(Type in, const char *&out)
|
||||
{
|
||||
return types.find(in, out);
|
||||
}
|
||||
|
||||
StringMap<Shape::Type, Shape::SHAPE_MAX_ENUM>::Entry Shape::typeEntries[] =
|
||||
{
|
||||
{"circle", Shape::SHAPE_CIRCLE},
|
||||
{"polygon", Shape::SHAPE_POLYGON},
|
||||
{"edge", Shape::SHAPE_EDGE},
|
||||
{"chain", Shape::SHAPE_CHAIN},
|
||||
};
|
||||
|
||||
StringMap<Shape::Type, Shape::SHAPE_MAX_ENUM> Shape::types(Shape::typeEntries, sizeof(Shape::typeEntries));
|
||||
|
||||
} // physics
|
||||
} // love
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#include "Shape.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
|
||||
Shape::~Shape()
|
||||
{
|
||||
}
|
||||
|
||||
bool Shape::getConstant(const char *in, Type &out)
|
||||
{
|
||||
return types.find(in, out);
|
||||
}
|
||||
|
||||
bool Shape::getConstant(Type in, const char *&out)
|
||||
{
|
||||
return types.find(in, out);
|
||||
}
|
||||
|
||||
StringMap<Shape::Type, Shape::SHAPE_MAX_ENUM>::Entry Shape::typeEntries[] =
|
||||
{
|
||||
{"circle", Shape::SHAPE_CIRCLE},
|
||||
{"polygon", Shape::SHAPE_POLYGON},
|
||||
{"edge", Shape::SHAPE_EDGE},
|
||||
{"chain", Shape::SHAPE_CHAIN},
|
||||
};
|
||||
|
||||
StringMap<Shape::Type, Shape::SHAPE_MAX_ENUM> Shape::types(Shape::typeEntries, sizeof(Shape::typeEntries));
|
||||
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
+61
-61
@@ -1,61 +1,61 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_PHYSICS_SHAPE_H
|
||||
#define LOVE_PHYSICS_SHAPE_H
|
||||
|
||||
// LOVE
|
||||
#include "common/Object.h"
|
||||
#include "common/StringMap.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
|
||||
class Shape : public Object
|
||||
{
|
||||
public:
|
||||
|
||||
enum Type
|
||||
{
|
||||
SHAPE_INVALID,
|
||||
SHAPE_CIRCLE,
|
||||
SHAPE_POLYGON,
|
||||
SHAPE_EDGE,
|
||||
SHAPE_CHAIN,
|
||||
SHAPE_MAX_ENUM
|
||||
};
|
||||
|
||||
virtual ~Shape();
|
||||
|
||||
static bool getConstant(const char *in, Type &out);
|
||||
static bool getConstant(Type in, const char *&out);
|
||||
|
||||
private:
|
||||
|
||||
static StringMap<Type, SHAPE_MAX_ENUM>::Entry typeEntries[];
|
||||
static StringMap<Type, SHAPE_MAX_ENUM> types;
|
||||
};
|
||||
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_SHAPE_H
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_PHYSICS_SHAPE_H
|
||||
#define LOVE_PHYSICS_SHAPE_H
|
||||
|
||||
// LOVE
|
||||
#include "common/Object.h"
|
||||
#include "common/StringMap.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
|
||||
class Shape : public Object
|
||||
{
|
||||
public:
|
||||
|
||||
enum Type
|
||||
{
|
||||
SHAPE_INVALID,
|
||||
SHAPE_CIRCLE,
|
||||
SHAPE_POLYGON,
|
||||
SHAPE_EDGE,
|
||||
SHAPE_CHAIN,
|
||||
SHAPE_MAX_ENUM
|
||||
};
|
||||
|
||||
virtual ~Shape();
|
||||
|
||||
static bool getConstant(const char *in, Type &out);
|
||||
static bool getConstant(Type in, const char *&out);
|
||||
|
||||
private:
|
||||
|
||||
static StringMap<Type, SHAPE_MAX_ENUM>::Entry typeEntries[];
|
||||
static StringMap<Type, SHAPE_MAX_ENUM> types;
|
||||
};
|
||||
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_SHAPE_H
|
||||
|
||||
+474
-474
@@ -1,474 +1,474 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#include "Body.h"
|
||||
|
||||
#include "common/math.h"
|
||||
#include "common/Memoizer.h"
|
||||
|
||||
#include "Shape.h"
|
||||
#include "Fixture.h"
|
||||
#include "World.h"
|
||||
#include "Physics.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
Body::Body(World *world, b2Vec2 p, Body::Type type)
|
||||
: world(world)
|
||||
{
|
||||
world->retain();
|
||||
b2BodyDef def;
|
||||
def.position = Physics::scaleDown(p);
|
||||
body = world->world->CreateBody(&def);
|
||||
// Box2D body holds a reference to the love Body.
|
||||
this->retain();
|
||||
this->setType(type);
|
||||
Memoizer::add(body, this);
|
||||
}
|
||||
|
||||
Body::Body(b2Body *b)
|
||||
: body(b)
|
||||
{
|
||||
world = (World *)Memoizer::find(b->GetWorld());
|
||||
world->retain();
|
||||
// Box2D body holds a reference to the love Body.
|
||||
this->retain();
|
||||
Memoizer::add(body, this);
|
||||
}
|
||||
|
||||
Body::~Body()
|
||||
{
|
||||
world->release();
|
||||
body = 0;
|
||||
}
|
||||
|
||||
float Body::getX()
|
||||
{
|
||||
return Physics::scaleUp(body->GetPosition().x);
|
||||
}
|
||||
|
||||
float Body::getY()
|
||||
{
|
||||
return Physics::scaleUp(body->GetPosition().y);
|
||||
}
|
||||
|
||||
void Body::getPosition(float &x_o, float &y_o)
|
||||
{
|
||||
b2Vec2 v = Physics::scaleUp(body->GetPosition());
|
||||
x_o = v.x;
|
||||
y_o = v.y;
|
||||
}
|
||||
|
||||
void Body::getLinearVelocity(float &x_o, float &y_o)
|
||||
{
|
||||
b2Vec2 v = Physics::scaleUp(body->GetLinearVelocity());
|
||||
x_o = v.x;
|
||||
y_o = v.y;
|
||||
}
|
||||
|
||||
float Body::getAngle()
|
||||
{
|
||||
return body->GetAngle();
|
||||
}
|
||||
|
||||
void Body::getWorldCenter(float &x_o, float &y_o)
|
||||
{
|
||||
b2Vec2 v = Physics::scaleUp(body->GetWorldCenter());
|
||||
x_o = v.x;
|
||||
y_o = v.y;
|
||||
}
|
||||
|
||||
void Body::getLocalCenter(float &x_o, float &y_o)
|
||||
{
|
||||
b2Vec2 v = Physics::scaleUp(body->GetLocalCenter());
|
||||
x_o = v.x;
|
||||
y_o = v.y;
|
||||
}
|
||||
|
||||
float Body::getAngularVelocity() const
|
||||
{
|
||||
return body->GetAngularVelocity();
|
||||
}
|
||||
|
||||
float Body::getMass() const
|
||||
{
|
||||
return body->GetMass();
|
||||
}
|
||||
|
||||
float Body::getInertia() const
|
||||
{
|
||||
return Physics::scaleUp(Physics::scaleUp(body->GetInertia()));
|
||||
}
|
||||
|
||||
int Body::getMassData(lua_State *L)
|
||||
{
|
||||
b2MassData data;
|
||||
body->GetMassData(&data);
|
||||
b2Vec2 center = Physics::scaleUp(data.center);
|
||||
lua_pushnumber(L, center.x);
|
||||
lua_pushnumber(L, center.y);
|
||||
lua_pushnumber(L, data.mass);
|
||||
lua_pushnumber(L, Physics::scaleUp(Physics::scaleUp(data.I)));
|
||||
return 4;
|
||||
}
|
||||
|
||||
float Body::getAngularDamping() const
|
||||
{
|
||||
return body->GetAngularDamping();
|
||||
}
|
||||
|
||||
float Body::getLinearDamping() const
|
||||
{
|
||||
return body->GetLinearDamping();
|
||||
}
|
||||
|
||||
float Body::getGravityScale() const
|
||||
{
|
||||
return body->GetGravityScale();
|
||||
}
|
||||
|
||||
Body::Type Body::getType() const
|
||||
{
|
||||
switch (body->GetType())
|
||||
{
|
||||
case b2_staticBody:
|
||||
return BODY_STATIC;
|
||||
break;
|
||||
case b2_dynamicBody:
|
||||
return BODY_DYNAMIC;
|
||||
break;
|
||||
case b2_kinematicBody:
|
||||
return BODY_KINEMATIC;
|
||||
break;
|
||||
default:
|
||||
return BODY_INVALID;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void Body::applyLinearImpulse(float jx, float jy)
|
||||
{
|
||||
body->ApplyLinearImpulse(Physics::scaleDown(b2Vec2(jx, jy)), body->GetWorldCenter());
|
||||
}
|
||||
|
||||
void Body::applyLinearImpulse(float jx, float jy, float rx, float ry)
|
||||
{
|
||||
body->ApplyLinearImpulse(Physics::scaleDown(b2Vec2(jx, jy)), Physics::scaleDown(b2Vec2(rx, ry)));
|
||||
}
|
||||
|
||||
void Body::applyAngularImpulse(float impulse)
|
||||
{
|
||||
// Angular impulse is in kg*m^2/s, meaning it needs to be scaled twice
|
||||
body->ApplyAngularImpulse(Physics::scaleDown(Physics::scaleDown(impulse)));
|
||||
}
|
||||
|
||||
void Body::applyTorque(float t)
|
||||
{
|
||||
// Torque is in N*m, or kg*m^2/s^2, meaning it also needs to be scaled twice
|
||||
body->ApplyTorque(Physics::scaleDown(Physics::scaleDown(t)));
|
||||
}
|
||||
|
||||
void Body::applyForce(float fx, float fy, float rx, float ry)
|
||||
{
|
||||
body->ApplyForce(Physics::scaleDown(b2Vec2(fx, fy)), Physics::scaleDown(b2Vec2(rx, ry)));
|
||||
}
|
||||
|
||||
void Body::applyForce(float fx, float fy)
|
||||
{
|
||||
body->ApplyForceToCenter(Physics::scaleDown(b2Vec2(fx, fy)));
|
||||
}
|
||||
|
||||
void Body::setX(float x)
|
||||
{
|
||||
body->SetTransform(Physics::scaleDown(b2Vec2(x, getY())), getAngle());
|
||||
}
|
||||
|
||||
void Body::setY(float y)
|
||||
{
|
||||
body->SetTransform(Physics::scaleDown(b2Vec2(getX(), y)), getAngle());
|
||||
}
|
||||
|
||||
void Body::setLinearVelocity(float x, float y)
|
||||
{
|
||||
body->SetLinearVelocity(Physics::scaleDown(b2Vec2(x, y)));
|
||||
}
|
||||
|
||||
void Body::setAngle(float d)
|
||||
{
|
||||
body->SetTransform(body->GetPosition(), d);
|
||||
}
|
||||
|
||||
void Body::setAngularVelocity(float r)
|
||||
{
|
||||
body->SetAngularVelocity(r);
|
||||
}
|
||||
|
||||
void Body::setPosition(float x, float y)
|
||||
{
|
||||
body->SetTransform(Physics::scaleDown(b2Vec2(x, y)), body->GetAngle());
|
||||
}
|
||||
|
||||
void Body::setAngularDamping(float d)
|
||||
{
|
||||
body->SetAngularDamping(d);
|
||||
}
|
||||
|
||||
void Body::setLinearDamping(float d)
|
||||
{
|
||||
body->SetLinearDamping(d);
|
||||
}
|
||||
|
||||
void Body::resetMassData()
|
||||
{
|
||||
body->ResetMassData();
|
||||
}
|
||||
|
||||
void Body::setMassData(float x, float y, float m, float i)
|
||||
{
|
||||
b2MassData massData;
|
||||
massData.center = Physics::scaleDown(b2Vec2(x, y));
|
||||
massData.mass = m;
|
||||
massData.I = Physics::scaleDown(Physics::scaleDown(i));
|
||||
body->SetMassData(&massData);
|
||||
}
|
||||
|
||||
void Body::setMass(float m)
|
||||
{
|
||||
b2MassData data;
|
||||
body->GetMassData(&data);
|
||||
data.mass = m;
|
||||
body->SetMassData(&data);
|
||||
}
|
||||
|
||||
void Body::setInertia(float i)
|
||||
{
|
||||
b2MassData massData;
|
||||
massData.center = body->GetLocalCenter();
|
||||
massData.mass = body->GetMass();
|
||||
massData.I = Physics::scaleDown(Physics::scaleDown(i));
|
||||
body->SetMassData(&massData);
|
||||
}
|
||||
|
||||
void Body::setGravityScale(float scale)
|
||||
{
|
||||
body->SetGravityScale(scale);
|
||||
}
|
||||
|
||||
void Body::setType(Body::Type type)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case Body::BODY_STATIC:
|
||||
body->SetType(b2_staticBody);
|
||||
break;
|
||||
case Body::BODY_DYNAMIC:
|
||||
body->SetType(b2_dynamicBody);
|
||||
break;
|
||||
case Body::BODY_KINEMATIC:
|
||||
body->SetType(b2_kinematicBody);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void Body::getWorldPoint(float x, float y, float &x_o, float &y_o)
|
||||
{
|
||||
b2Vec2 v = Physics::scaleUp(body->GetWorldPoint(Physics::scaleDown(b2Vec2(x, y))));
|
||||
x_o = v.x;
|
||||
y_o = v.y;
|
||||
}
|
||||
|
||||
void Body::getWorldVector(float x, float y, float &x_o, float &y_o)
|
||||
{
|
||||
b2Vec2 v = Physics::scaleUp(body->GetWorldVector(Physics::scaleDown(b2Vec2(x, y))));
|
||||
x_o = v.x;
|
||||
y_o = v.y;
|
||||
}
|
||||
|
||||
int Body::getWorldPoints(lua_State *L)
|
||||
{
|
||||
int argc = lua_gettop(L);
|
||||
int vcount = (int)argc/2;
|
||||
// at least one point
|
||||
love::luax_assert_argc(L, 2);
|
||||
|
||||
for (int i = 0; i<vcount; i++)
|
||||
{
|
||||
float x = (float)lua_tonumber(L, 1);
|
||||
float y = (float)lua_tonumber(L, 2);
|
||||
// Remove them, so we don't run out of stack space
|
||||
lua_remove(L, 1);
|
||||
lua_remove(L, 1);
|
||||
// Time for scaling
|
||||
b2Vec2 point = Physics::scaleUp(body->GetWorldPoint(Physics::scaleDown(b2Vec2(x, y))));
|
||||
// And then we push the result
|
||||
lua_pushnumber(L, point.x);
|
||||
lua_pushnumber(L, point.y);
|
||||
}
|
||||
|
||||
return argc;
|
||||
}
|
||||
|
||||
void Body::getLocalPoint(float x, float y, float &x_o, float &y_o)
|
||||
{
|
||||
b2Vec2 v = Physics::scaleUp(body->GetLocalPoint(Physics::scaleDown(b2Vec2(x, y))));
|
||||
x_o = v.x;
|
||||
y_o = v.y;
|
||||
}
|
||||
|
||||
void Body::getLocalVector(float x, float y, float &x_o, float &y_o)
|
||||
{
|
||||
b2Vec2 v = Physics::scaleUp(body->GetLocalVector(Physics::scaleDown(b2Vec2(x, y))));
|
||||
x_o = v.x;
|
||||
y_o = v.y;
|
||||
}
|
||||
|
||||
void Body::getLinearVelocityFromWorldPoint(float x, float y, float &x_o, float &y_o)
|
||||
{
|
||||
b2Vec2 v = Physics::scaleUp(body->GetLinearVelocityFromWorldPoint(Physics::scaleDown(b2Vec2(x, y))));
|
||||
x_o = v.x;
|
||||
y_o = v.y;
|
||||
}
|
||||
|
||||
void Body::getLinearVelocityFromLocalPoint(float x, float y, float &x_o, float &y_o)
|
||||
{
|
||||
b2Vec2 v = Physics::scaleUp(body->GetLinearVelocityFromLocalPoint(Physics::scaleDown(b2Vec2(x, y))));
|
||||
x_o = v.x;
|
||||
y_o = v.y;
|
||||
}
|
||||
|
||||
bool Body::isBullet() const
|
||||
{
|
||||
return body->IsBullet();
|
||||
}
|
||||
|
||||
void Body::setBullet(bool bullet)
|
||||
{
|
||||
return body->SetBullet(bullet);
|
||||
}
|
||||
|
||||
bool Body::isActive() const
|
||||
{
|
||||
return body->IsActive();
|
||||
}
|
||||
|
||||
bool Body::isAwake() const
|
||||
{
|
||||
return body->IsAwake();
|
||||
}
|
||||
|
||||
void Body::setSleepingAllowed(bool allow)
|
||||
{
|
||||
body->SetSleepingAllowed(allow);
|
||||
}
|
||||
|
||||
bool Body::isSleepingAllowed() const
|
||||
{
|
||||
return body->IsSleepingAllowed();
|
||||
}
|
||||
|
||||
void Body::setActive(bool active)
|
||||
{
|
||||
body->SetActive(active);
|
||||
}
|
||||
|
||||
void Body::setAwake(bool awake)
|
||||
{
|
||||
body->SetAwake(awake);
|
||||
}
|
||||
|
||||
void Body::setFixedRotation(bool fixed)
|
||||
{
|
||||
body->SetFixedRotation(fixed);
|
||||
}
|
||||
|
||||
bool Body::isFixedRotation() const
|
||||
{
|
||||
return body->IsFixedRotation();
|
||||
}
|
||||
|
||||
World *Body::getWorld() const
|
||||
{
|
||||
return world;
|
||||
}
|
||||
|
||||
int Body::getFixtureList(lua_State *L) const
|
||||
{
|
||||
lua_newtable(L);
|
||||
b2Fixture *f = body->GetFixtureList();
|
||||
int i = 1;
|
||||
do
|
||||
{
|
||||
if (!f)
|
||||
break;
|
||||
Fixture *fixture = (Fixture *)Memoizer::find(f);
|
||||
if (!fixture)
|
||||
throw love::Exception("A fixture has escaped Memoizer!");
|
||||
fixture->retain();
|
||||
luax_newtype(L, "Fixture", PHYSICS_FIXTURE_T, (void *)fixture);
|
||||
lua_rawseti(L, -2, i);
|
||||
i++;
|
||||
}
|
||||
while ((f = f->GetNext()));
|
||||
return 1;
|
||||
}
|
||||
|
||||
b2Vec2 Body::getVector(lua_State *L)
|
||||
{
|
||||
love::luax_assert_argc(L, 2, 2);
|
||||
b2Vec2 v((float)lua_tonumber(L, 1), (float)lua_tonumber(L, 2));
|
||||
lua_pop(L, 2);
|
||||
return v;
|
||||
}
|
||||
|
||||
int Body::pushVector(lua_State *L, const b2Vec2 &v)
|
||||
{
|
||||
lua_pushnumber(L, v.x);
|
||||
lua_pushnumber(L, v.y);
|
||||
return 2;
|
||||
}
|
||||
|
||||
void Body::destroy()
|
||||
{
|
||||
if (world->world->IsLocked())
|
||||
{
|
||||
// Called during time step. Save reference for destruction afterwards.
|
||||
this->retain();
|
||||
world->destructBodies.push_back(this);
|
||||
return;
|
||||
}
|
||||
|
||||
world->world->DestroyBody(body);
|
||||
Memoizer::remove(body);
|
||||
body = NULL;
|
||||
|
||||
// Box2D body destroyed. Release its reference to the love Body.
|
||||
this->release();
|
||||
}
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#include "Body.h"
|
||||
|
||||
#include "common/math.h"
|
||||
#include "common/Memoizer.h"
|
||||
|
||||
#include "Shape.h"
|
||||
#include "Fixture.h"
|
||||
#include "World.h"
|
||||
#include "Physics.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
Body::Body(World *world, b2Vec2 p, Body::Type type)
|
||||
: world(world)
|
||||
{
|
||||
world->retain();
|
||||
b2BodyDef def;
|
||||
def.position = Physics::scaleDown(p);
|
||||
body = world->world->CreateBody(&def);
|
||||
// Box2D body holds a reference to the love Body.
|
||||
this->retain();
|
||||
this->setType(type);
|
||||
Memoizer::add(body, this);
|
||||
}
|
||||
|
||||
Body::Body(b2Body *b)
|
||||
: body(b)
|
||||
{
|
||||
world = (World *)Memoizer::find(b->GetWorld());
|
||||
world->retain();
|
||||
// Box2D body holds a reference to the love Body.
|
||||
this->retain();
|
||||
Memoizer::add(body, this);
|
||||
}
|
||||
|
||||
Body::~Body()
|
||||
{
|
||||
world->release();
|
||||
body = 0;
|
||||
}
|
||||
|
||||
float Body::getX()
|
||||
{
|
||||
return Physics::scaleUp(body->GetPosition().x);
|
||||
}
|
||||
|
||||
float Body::getY()
|
||||
{
|
||||
return Physics::scaleUp(body->GetPosition().y);
|
||||
}
|
||||
|
||||
void Body::getPosition(float &x_o, float &y_o)
|
||||
{
|
||||
b2Vec2 v = Physics::scaleUp(body->GetPosition());
|
||||
x_o = v.x;
|
||||
y_o = v.y;
|
||||
}
|
||||
|
||||
void Body::getLinearVelocity(float &x_o, float &y_o)
|
||||
{
|
||||
b2Vec2 v = Physics::scaleUp(body->GetLinearVelocity());
|
||||
x_o = v.x;
|
||||
y_o = v.y;
|
||||
}
|
||||
|
||||
float Body::getAngle()
|
||||
{
|
||||
return body->GetAngle();
|
||||
}
|
||||
|
||||
void Body::getWorldCenter(float &x_o, float &y_o)
|
||||
{
|
||||
b2Vec2 v = Physics::scaleUp(body->GetWorldCenter());
|
||||
x_o = v.x;
|
||||
y_o = v.y;
|
||||
}
|
||||
|
||||
void Body::getLocalCenter(float &x_o, float &y_o)
|
||||
{
|
||||
b2Vec2 v = Physics::scaleUp(body->GetLocalCenter());
|
||||
x_o = v.x;
|
||||
y_o = v.y;
|
||||
}
|
||||
|
||||
float Body::getAngularVelocity() const
|
||||
{
|
||||
return body->GetAngularVelocity();
|
||||
}
|
||||
|
||||
float Body::getMass() const
|
||||
{
|
||||
return body->GetMass();
|
||||
}
|
||||
|
||||
float Body::getInertia() const
|
||||
{
|
||||
return Physics::scaleUp(Physics::scaleUp(body->GetInertia()));
|
||||
}
|
||||
|
||||
int Body::getMassData(lua_State *L)
|
||||
{
|
||||
b2MassData data;
|
||||
body->GetMassData(&data);
|
||||
b2Vec2 center = Physics::scaleUp(data.center);
|
||||
lua_pushnumber(L, center.x);
|
||||
lua_pushnumber(L, center.y);
|
||||
lua_pushnumber(L, data.mass);
|
||||
lua_pushnumber(L, Physics::scaleUp(Physics::scaleUp(data.I)));
|
||||
return 4;
|
||||
}
|
||||
|
||||
float Body::getAngularDamping() const
|
||||
{
|
||||
return body->GetAngularDamping();
|
||||
}
|
||||
|
||||
float Body::getLinearDamping() const
|
||||
{
|
||||
return body->GetLinearDamping();
|
||||
}
|
||||
|
||||
float Body::getGravityScale() const
|
||||
{
|
||||
return body->GetGravityScale();
|
||||
}
|
||||
|
||||
Body::Type Body::getType() const
|
||||
{
|
||||
switch (body->GetType())
|
||||
{
|
||||
case b2_staticBody:
|
||||
return BODY_STATIC;
|
||||
break;
|
||||
case b2_dynamicBody:
|
||||
return BODY_DYNAMIC;
|
||||
break;
|
||||
case b2_kinematicBody:
|
||||
return BODY_KINEMATIC;
|
||||
break;
|
||||
default:
|
||||
return BODY_INVALID;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void Body::applyLinearImpulse(float jx, float jy)
|
||||
{
|
||||
body->ApplyLinearImpulse(Physics::scaleDown(b2Vec2(jx, jy)), body->GetWorldCenter());
|
||||
}
|
||||
|
||||
void Body::applyLinearImpulse(float jx, float jy, float rx, float ry)
|
||||
{
|
||||
body->ApplyLinearImpulse(Physics::scaleDown(b2Vec2(jx, jy)), Physics::scaleDown(b2Vec2(rx, ry)));
|
||||
}
|
||||
|
||||
void Body::applyAngularImpulse(float impulse)
|
||||
{
|
||||
// Angular impulse is in kg*m^2/s, meaning it needs to be scaled twice
|
||||
body->ApplyAngularImpulse(Physics::scaleDown(Physics::scaleDown(impulse)));
|
||||
}
|
||||
|
||||
void Body::applyTorque(float t)
|
||||
{
|
||||
// Torque is in N*m, or kg*m^2/s^2, meaning it also needs to be scaled twice
|
||||
body->ApplyTorque(Physics::scaleDown(Physics::scaleDown(t)));
|
||||
}
|
||||
|
||||
void Body::applyForce(float fx, float fy, float rx, float ry)
|
||||
{
|
||||
body->ApplyForce(Physics::scaleDown(b2Vec2(fx, fy)), Physics::scaleDown(b2Vec2(rx, ry)));
|
||||
}
|
||||
|
||||
void Body::applyForce(float fx, float fy)
|
||||
{
|
||||
body->ApplyForceToCenter(Physics::scaleDown(b2Vec2(fx, fy)));
|
||||
}
|
||||
|
||||
void Body::setX(float x)
|
||||
{
|
||||
body->SetTransform(Physics::scaleDown(b2Vec2(x, getY())), getAngle());
|
||||
}
|
||||
|
||||
void Body::setY(float y)
|
||||
{
|
||||
body->SetTransform(Physics::scaleDown(b2Vec2(getX(), y)), getAngle());
|
||||
}
|
||||
|
||||
void Body::setLinearVelocity(float x, float y)
|
||||
{
|
||||
body->SetLinearVelocity(Physics::scaleDown(b2Vec2(x, y)));
|
||||
}
|
||||
|
||||
void Body::setAngle(float d)
|
||||
{
|
||||
body->SetTransform(body->GetPosition(), d);
|
||||
}
|
||||
|
||||
void Body::setAngularVelocity(float r)
|
||||
{
|
||||
body->SetAngularVelocity(r);
|
||||
}
|
||||
|
||||
void Body::setPosition(float x, float y)
|
||||
{
|
||||
body->SetTransform(Physics::scaleDown(b2Vec2(x, y)), body->GetAngle());
|
||||
}
|
||||
|
||||
void Body::setAngularDamping(float d)
|
||||
{
|
||||
body->SetAngularDamping(d);
|
||||
}
|
||||
|
||||
void Body::setLinearDamping(float d)
|
||||
{
|
||||
body->SetLinearDamping(d);
|
||||
}
|
||||
|
||||
void Body::resetMassData()
|
||||
{
|
||||
body->ResetMassData();
|
||||
}
|
||||
|
||||
void Body::setMassData(float x, float y, float m, float i)
|
||||
{
|
||||
b2MassData massData;
|
||||
massData.center = Physics::scaleDown(b2Vec2(x, y));
|
||||
massData.mass = m;
|
||||
massData.I = Physics::scaleDown(Physics::scaleDown(i));
|
||||
body->SetMassData(&massData);
|
||||
}
|
||||
|
||||
void Body::setMass(float m)
|
||||
{
|
||||
b2MassData data;
|
||||
body->GetMassData(&data);
|
||||
data.mass = m;
|
||||
body->SetMassData(&data);
|
||||
}
|
||||
|
||||
void Body::setInertia(float i)
|
||||
{
|
||||
b2MassData massData;
|
||||
massData.center = body->GetLocalCenter();
|
||||
massData.mass = body->GetMass();
|
||||
massData.I = Physics::scaleDown(Physics::scaleDown(i));
|
||||
body->SetMassData(&massData);
|
||||
}
|
||||
|
||||
void Body::setGravityScale(float scale)
|
||||
{
|
||||
body->SetGravityScale(scale);
|
||||
}
|
||||
|
||||
void Body::setType(Body::Type type)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case Body::BODY_STATIC:
|
||||
body->SetType(b2_staticBody);
|
||||
break;
|
||||
case Body::BODY_DYNAMIC:
|
||||
body->SetType(b2_dynamicBody);
|
||||
break;
|
||||
case Body::BODY_KINEMATIC:
|
||||
body->SetType(b2_kinematicBody);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void Body::getWorldPoint(float x, float y, float &x_o, float &y_o)
|
||||
{
|
||||
b2Vec2 v = Physics::scaleUp(body->GetWorldPoint(Physics::scaleDown(b2Vec2(x, y))));
|
||||
x_o = v.x;
|
||||
y_o = v.y;
|
||||
}
|
||||
|
||||
void Body::getWorldVector(float x, float y, float &x_o, float &y_o)
|
||||
{
|
||||
b2Vec2 v = Physics::scaleUp(body->GetWorldVector(Physics::scaleDown(b2Vec2(x, y))));
|
||||
x_o = v.x;
|
||||
y_o = v.y;
|
||||
}
|
||||
|
||||
int Body::getWorldPoints(lua_State *L)
|
||||
{
|
||||
int argc = lua_gettop(L);
|
||||
int vcount = (int)argc/2;
|
||||
// at least one point
|
||||
love::luax_assert_argc(L, 2);
|
||||
|
||||
for (int i = 0; i<vcount; i++)
|
||||
{
|
||||
float x = (float)lua_tonumber(L, 1);
|
||||
float y = (float)lua_tonumber(L, 2);
|
||||
// Remove them, so we don't run out of stack space
|
||||
lua_remove(L, 1);
|
||||
lua_remove(L, 1);
|
||||
// Time for scaling
|
||||
b2Vec2 point = Physics::scaleUp(body->GetWorldPoint(Physics::scaleDown(b2Vec2(x, y))));
|
||||
// And then we push the result
|
||||
lua_pushnumber(L, point.x);
|
||||
lua_pushnumber(L, point.y);
|
||||
}
|
||||
|
||||
return argc;
|
||||
}
|
||||
|
||||
void Body::getLocalPoint(float x, float y, float &x_o, float &y_o)
|
||||
{
|
||||
b2Vec2 v = Physics::scaleUp(body->GetLocalPoint(Physics::scaleDown(b2Vec2(x, y))));
|
||||
x_o = v.x;
|
||||
y_o = v.y;
|
||||
}
|
||||
|
||||
void Body::getLocalVector(float x, float y, float &x_o, float &y_o)
|
||||
{
|
||||
b2Vec2 v = Physics::scaleUp(body->GetLocalVector(Physics::scaleDown(b2Vec2(x, y))));
|
||||
x_o = v.x;
|
||||
y_o = v.y;
|
||||
}
|
||||
|
||||
void Body::getLinearVelocityFromWorldPoint(float x, float y, float &x_o, float &y_o)
|
||||
{
|
||||
b2Vec2 v = Physics::scaleUp(body->GetLinearVelocityFromWorldPoint(Physics::scaleDown(b2Vec2(x, y))));
|
||||
x_o = v.x;
|
||||
y_o = v.y;
|
||||
}
|
||||
|
||||
void Body::getLinearVelocityFromLocalPoint(float x, float y, float &x_o, float &y_o)
|
||||
{
|
||||
b2Vec2 v = Physics::scaleUp(body->GetLinearVelocityFromLocalPoint(Physics::scaleDown(b2Vec2(x, y))));
|
||||
x_o = v.x;
|
||||
y_o = v.y;
|
||||
}
|
||||
|
||||
bool Body::isBullet() const
|
||||
{
|
||||
return body->IsBullet();
|
||||
}
|
||||
|
||||
void Body::setBullet(bool bullet)
|
||||
{
|
||||
return body->SetBullet(bullet);
|
||||
}
|
||||
|
||||
bool Body::isActive() const
|
||||
{
|
||||
return body->IsActive();
|
||||
}
|
||||
|
||||
bool Body::isAwake() const
|
||||
{
|
||||
return body->IsAwake();
|
||||
}
|
||||
|
||||
void Body::setSleepingAllowed(bool allow)
|
||||
{
|
||||
body->SetSleepingAllowed(allow);
|
||||
}
|
||||
|
||||
bool Body::isSleepingAllowed() const
|
||||
{
|
||||
return body->IsSleepingAllowed();
|
||||
}
|
||||
|
||||
void Body::setActive(bool active)
|
||||
{
|
||||
body->SetActive(active);
|
||||
}
|
||||
|
||||
void Body::setAwake(bool awake)
|
||||
{
|
||||
body->SetAwake(awake);
|
||||
}
|
||||
|
||||
void Body::setFixedRotation(bool fixed)
|
||||
{
|
||||
body->SetFixedRotation(fixed);
|
||||
}
|
||||
|
||||
bool Body::isFixedRotation() const
|
||||
{
|
||||
return body->IsFixedRotation();
|
||||
}
|
||||
|
||||
World *Body::getWorld() const
|
||||
{
|
||||
return world;
|
||||
}
|
||||
|
||||
int Body::getFixtureList(lua_State *L) const
|
||||
{
|
||||
lua_newtable(L);
|
||||
b2Fixture *f = body->GetFixtureList();
|
||||
int i = 1;
|
||||
do
|
||||
{
|
||||
if (!f)
|
||||
break;
|
||||
Fixture *fixture = (Fixture *)Memoizer::find(f);
|
||||
if (!fixture)
|
||||
throw love::Exception("A fixture has escaped Memoizer!");
|
||||
fixture->retain();
|
||||
luax_newtype(L, "Fixture", PHYSICS_FIXTURE_T, (void *)fixture);
|
||||
lua_rawseti(L, -2, i);
|
||||
i++;
|
||||
}
|
||||
while ((f = f->GetNext()));
|
||||
return 1;
|
||||
}
|
||||
|
||||
b2Vec2 Body::getVector(lua_State *L)
|
||||
{
|
||||
love::luax_assert_argc(L, 2, 2);
|
||||
b2Vec2 v((float)lua_tonumber(L, 1), (float)lua_tonumber(L, 2));
|
||||
lua_pop(L, 2);
|
||||
return v;
|
||||
}
|
||||
|
||||
int Body::pushVector(lua_State *L, const b2Vec2 &v)
|
||||
{
|
||||
lua_pushnumber(L, v.x);
|
||||
lua_pushnumber(L, v.y);
|
||||
return 2;
|
||||
}
|
||||
|
||||
void Body::destroy()
|
||||
{
|
||||
if (world->world->IsLocked())
|
||||
{
|
||||
// Called during time step. Save reference for destruction afterwards.
|
||||
this->retain();
|
||||
world->destructBodies.push_back(this);
|
||||
return;
|
||||
}
|
||||
|
||||
world->world->DestroyBody(body);
|
||||
Memoizer::remove(body);
|
||||
body = NULL;
|
||||
|
||||
// Box2D body destroyed. Release its reference to the love Body.
|
||||
this->release();
|
||||
}
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
+415
-415
@@ -1,415 +1,415 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_PHYSICS_BOX2D_BODY_H
|
||||
#define LOVE_PHYSICS_BOX2D_BODY_H
|
||||
|
||||
// LOVE
|
||||
#include "common/math.h"
|
||||
#include "common/runtime.h"
|
||||
#include "common/Object.h"
|
||||
#include "physics/Body.h"
|
||||
|
||||
// Box2D
|
||||
#include <Box2D/Box2D.h>
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
// Forward declarations.
|
||||
class World;
|
||||
class Shape;
|
||||
class Fixture;
|
||||
|
||||
/**
|
||||
* A Body is an entity which has position and orientation
|
||||
* in world space. A Body does have collision geometry
|
||||
* by itself, but depend on an arbitrary number of child Shape objects
|
||||
* which together constitute the final geometry for the Body.
|
||||
**/
|
||||
class Body : public love::physics::Body
|
||||
{
|
||||
public:
|
||||
// Friends.
|
||||
friend class Joint;
|
||||
friend class DistanceJoint;
|
||||
friend class MouseJoint;
|
||||
friend class CircleShape;
|
||||
friend class PolygonShape;
|
||||
friend class Shape;
|
||||
friend class Fixture;
|
||||
|
||||
// The Box2D body. (Should not be public?)
|
||||
b2Body *body;
|
||||
|
||||
/**
|
||||
* Create a Body at position p.
|
||||
**/
|
||||
Body(World *world, b2Vec2 p, Type type);
|
||||
|
||||
/**
|
||||
* Create a Body from an extant b2Body.
|
||||
**/
|
||||
Body(b2Body *b);
|
||||
|
||||
virtual ~Body();
|
||||
|
||||
/**
|
||||
* Gets the current x-position of the Body.
|
||||
**/
|
||||
float getX();
|
||||
|
||||
/**
|
||||
* Gets the current y-position of the Body.
|
||||
**/
|
||||
float getY();
|
||||
|
||||
/**
|
||||
* Gets the current angle (deg) of the Body.
|
||||
**/
|
||||
float getAngle();
|
||||
|
||||
/**
|
||||
* Gets the current position of the Body.
|
||||
* @returns The current position.
|
||||
**/
|
||||
void getPosition(float &x_o, float &y_o);
|
||||
|
||||
/**
|
||||
* Gets the velocity in the current center of mass.
|
||||
* @returns The velocity in the current center of mass.
|
||||
**/
|
||||
void getLinearVelocity(float &x_o, float &y_o);
|
||||
|
||||
/**
|
||||
* The current center of mass for the Body in world
|
||||
* coordinates.
|
||||
* @returns The x-component of the point.
|
||||
* @returns The y-component of the point.
|
||||
**/
|
||||
void getWorldCenter(float &x_o, float &y_o);
|
||||
|
||||
/**
|
||||
* The current center of mass for the Body in local
|
||||
* coordinates.
|
||||
* @returns The x-component of the point.
|
||||
* @returns The y-component of the point.
|
||||
**/
|
||||
void getLocalCenter(float &x_o, float &y_o);
|
||||
|
||||
/**
|
||||
* Get the current Body spin. (Angular velocity).
|
||||
**/
|
||||
float getAngularVelocity() const;
|
||||
|
||||
/**
|
||||
* Gets the Body's mass.
|
||||
**/
|
||||
float getMass() const;
|
||||
|
||||
/**
|
||||
* Gets the Body's intertia.
|
||||
**/
|
||||
float getInertia() const;
|
||||
|
||||
/**
|
||||
* Gets mass properties.
|
||||
**/
|
||||
int getMassData(lua_State *L);
|
||||
|
||||
/**
|
||||
* Gets the Body's angular damping.
|
||||
**/
|
||||
float getAngularDamping() const;
|
||||
|
||||
/**
|
||||
* Gets the Body's linear damping.
|
||||
**/
|
||||
float getLinearDamping() const;
|
||||
|
||||
/**
|
||||
* Gets the Body's gravity scale.
|
||||
**/
|
||||
float getGravityScale() const;
|
||||
|
||||
/**
|
||||
* Gets the type of body this is.
|
||||
**/
|
||||
Type getType() const;
|
||||
|
||||
/**
|
||||
* Apply an impulse (jx, jy) with offset (0, 0).
|
||||
**/
|
||||
void applyLinearImpulse(float jx, float jy);
|
||||
|
||||
/**
|
||||
* Apply an impulse (jx, jy) with offset (rx, ry).
|
||||
**/
|
||||
void applyLinearImpulse(float jx, float jy, float rx, float ry);
|
||||
|
||||
/**
|
||||
* Apply an angular impulse to the body.
|
||||
**/
|
||||
void applyAngularImpulse(float impulse);
|
||||
|
||||
/**
|
||||
* Apply torque (t).
|
||||
**/
|
||||
void applyTorque(float t);
|
||||
|
||||
/**
|
||||
* Apply force (fx, fy) with offset (0, 0).
|
||||
**/
|
||||
void applyForce(float fx, float fy);
|
||||
|
||||
/**
|
||||
* Apply force (fx, fy) with offset (rx, ry).
|
||||
**/
|
||||
void applyForce(float fx, float fy, float rx, float ry);
|
||||
|
||||
/**
|
||||
* Sets the x-position of the Body.
|
||||
**/
|
||||
void setX(float x);
|
||||
|
||||
/**
|
||||
* Sets the Y-position of the Body.
|
||||
**/
|
||||
void setY(float y);
|
||||
|
||||
/**
|
||||
* Sets the current velocity of the Body.
|
||||
**/
|
||||
void setLinearVelocity(float x, float y);
|
||||
|
||||
/**
|
||||
* Sets the angle of the Body.
|
||||
**/
|
||||
void setAngle(float d);
|
||||
|
||||
/**
|
||||
* Sets the current spin of the Body.
|
||||
**/
|
||||
void setAngularVelocity(float r);
|
||||
|
||||
/**
|
||||
* Sets the current position of the Body.
|
||||
**/
|
||||
void setPosition(float x, float y);
|
||||
|
||||
/**
|
||||
* Sets the mass from the currently attatched shapes.
|
||||
**/
|
||||
void resetMassData();
|
||||
|
||||
/**
|
||||
* Sets mass properties.
|
||||
* @param x The x-coordinate for the local center of mass.
|
||||
* @param y The y-coordinate for the local center of mass.
|
||||
* @param m The mass.
|
||||
* @param i The inertia.
|
||||
**/
|
||||
void setMassData(float x, float y, float m, float i);
|
||||
|
||||
/**
|
||||
* Sets just the mass. This is provided as a LOVE bonus. Lovely!
|
||||
* @param m The mass.
|
||||
**/
|
||||
void setMass(float m);
|
||||
|
||||
/**
|
||||
* Sets the inertia while keeping the other properties
|
||||
* (mass and local center).
|
||||
* @param i The inertia.
|
||||
**/
|
||||
void setInertia(float i);
|
||||
|
||||
/**
|
||||
* Sets the Body's angular damping.
|
||||
**/
|
||||
void setAngularDamping(float d);
|
||||
|
||||
/**
|
||||
* Sets the Body's linear damping.
|
||||
**/
|
||||
void setLinearDamping(float d);
|
||||
|
||||
/**
|
||||
* Sets the Body's gravity scale.
|
||||
**/
|
||||
void setGravityScale(float scale);
|
||||
|
||||
/**
|
||||
* Sets the type of body this is.
|
||||
**/
|
||||
void setType(Type type);
|
||||
|
||||
/**
|
||||
* Transforms a point (x, y) from local coordinates
|
||||
* to world coordinates.
|
||||
* @param x The x-coordinate of the local point.
|
||||
* @param y The y-coordinate of the local point.
|
||||
* @returns The x-coordinate of the point in world coordinates.
|
||||
* @returns The y-coordinate of the point in world coordinates.
|
||||
**/
|
||||
void getWorldPoint(float x, float y, float &x_o, float &y_o);
|
||||
|
||||
/**
|
||||
* Transforms a vector (x, y) from local coordinates
|
||||
* to world coordinates.
|
||||
* @param x The x-coordinate of the local vector.
|
||||
* @param y The y-coordinate of the local vector.
|
||||
* @returns The x-coordinate of the vector in world coordinates.
|
||||
* @returns The y-coordinate of the vector in world coordinates.
|
||||
**/
|
||||
void getWorldVector(float x, float y, float &x_o, float &y_o);
|
||||
|
||||
/**
|
||||
* Transforms a series of points (x, y) from local coordinates
|
||||
* to world coordinates.
|
||||
**/
|
||||
int getWorldPoints(lua_State *L);
|
||||
|
||||
/**
|
||||
* Transforms a point (x, y) from world coordinates
|
||||
* to local coordinates.
|
||||
* @param x The x-coordinate of the world point.
|
||||
* @param y The y-coordinate of the world point.
|
||||
* @returns The x-coordinate of the point in local coordinates.
|
||||
* @returns The y-coordinate of the point in local coordinates.
|
||||
**/
|
||||
void getLocalPoint(float x, float y, float &x_o, float &y_o);
|
||||
|
||||
/**
|
||||
* Transforms a vector (x, y) from world coordinates
|
||||
* to local coordinates.
|
||||
* @param x The x-coordinate of the world vector.
|
||||
* @param y The y-coordinate of the world vector.
|
||||
* @returns The x-coordinate of the vector in local coordinates.
|
||||
* @returns The y-coordinate of the vector in local coordinates.
|
||||
**/
|
||||
void getLocalVector(float x, float y, float &x_o, float &y_o);
|
||||
|
||||
/**
|
||||
* Gets the velocity on the Body for the given world point.
|
||||
* @param x The x-coordinate of the world point.
|
||||
* @param y The y-coordinate of the world point.
|
||||
* @returns The x-component of the velocity vector.
|
||||
* @returns The y-component of the velocity vector.
|
||||
**/
|
||||
void getLinearVelocityFromWorldPoint(float x, float y, float &x_o, float &y_o);
|
||||
|
||||
/**
|
||||
* Gets the velocity on the Body for the given local point.
|
||||
* @param x The x-coordinate of the local point.
|
||||
* @param y The y-coordinate of the local point.
|
||||
* @returns The x-component of the velocity vector.
|
||||
* @returns The y-component of the velocity vector.
|
||||
**/
|
||||
void getLinearVelocityFromLocalPoint(float x, float y, float &x_o, float &y_o);
|
||||
|
||||
/**
|
||||
* Returns true if the Body is a bullet, false otherwise.
|
||||
**/
|
||||
bool isBullet() const;
|
||||
|
||||
/**
|
||||
* Set whether this Body should be treated as a bullet.
|
||||
* Bullets require more processing power than normal shapes.
|
||||
**/
|
||||
void setBullet(bool bullet);
|
||||
|
||||
/**
|
||||
* Checks whether a Body is active or not. An inactive body
|
||||
* cannot be interacted with.
|
||||
**/
|
||||
bool isActive() const;
|
||||
|
||||
/**
|
||||
* Checks whether a Body is awake or not. A Body
|
||||
* will fall to sleep if nothing happens to it for while.
|
||||
**/
|
||||
bool isAwake() const;
|
||||
|
||||
/**
|
||||
* Controls whether this Body should be allowed to sleep.
|
||||
**/
|
||||
void setSleepingAllowed(bool allow);
|
||||
bool isSleepingAllowed() const;
|
||||
|
||||
/**
|
||||
* Changes the body's active state.
|
||||
**/
|
||||
void setActive(bool active);
|
||||
|
||||
/**
|
||||
* Changes the body's sleep state.
|
||||
**/
|
||||
void setAwake(bool awake);
|
||||
|
||||
void setFixedRotation(bool fixed);
|
||||
bool isFixedRotation() const;
|
||||
|
||||
/**
|
||||
* Get the World this Body resides in.
|
||||
*/
|
||||
World *getWorld() const;
|
||||
|
||||
/**
|
||||
* Get an array of all the Fixtures attached to this Body.
|
||||
* @return An array of Fixtures.
|
||||
**/
|
||||
int getFixtureList(lua_State *L) const;
|
||||
|
||||
/**
|
||||
* Destroy this body.
|
||||
**/
|
||||
void destroy();
|
||||
|
||||
private:
|
||||
|
||||
/**
|
||||
* Gets a 2d vector from the arguments on the stack.
|
||||
**/
|
||||
b2Vec2 getVector(lua_State *L);
|
||||
|
||||
/**
|
||||
* Pushed the x- and y-components of a vector on
|
||||
* the stack.
|
||||
**/
|
||||
int pushVector(lua_State *L, const b2Vec2 &v);
|
||||
|
||||
// We need a shared_ptr to the parent World,
|
||||
// because World can not be destroyed as long as
|
||||
// bodies exists in it.
|
||||
//
|
||||
// This ensures that a World only can be destroyed
|
||||
// once all bodies have been destroyed too.
|
||||
World *world;
|
||||
};
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_BODY_H
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_PHYSICS_BOX2D_BODY_H
|
||||
#define LOVE_PHYSICS_BOX2D_BODY_H
|
||||
|
||||
// LOVE
|
||||
#include "common/math.h"
|
||||
#include "common/runtime.h"
|
||||
#include "common/Object.h"
|
||||
#include "physics/Body.h"
|
||||
|
||||
// Box2D
|
||||
#include <Box2D/Box2D.h>
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
// Forward declarations.
|
||||
class World;
|
||||
class Shape;
|
||||
class Fixture;
|
||||
|
||||
/**
|
||||
* A Body is an entity which has position and orientation
|
||||
* in world space. A Body does have collision geometry
|
||||
* by itself, but depend on an arbitrary number of child Shape objects
|
||||
* which together constitute the final geometry for the Body.
|
||||
**/
|
||||
class Body : public love::physics::Body
|
||||
{
|
||||
public:
|
||||
// Friends.
|
||||
friend class Joint;
|
||||
friend class DistanceJoint;
|
||||
friend class MouseJoint;
|
||||
friend class CircleShape;
|
||||
friend class PolygonShape;
|
||||
friend class Shape;
|
||||
friend class Fixture;
|
||||
|
||||
// The Box2D body. (Should not be public?)
|
||||
b2Body *body;
|
||||
|
||||
/**
|
||||
* Create a Body at position p.
|
||||
**/
|
||||
Body(World *world, b2Vec2 p, Type type);
|
||||
|
||||
/**
|
||||
* Create a Body from an extant b2Body.
|
||||
**/
|
||||
Body(b2Body *b);
|
||||
|
||||
virtual ~Body();
|
||||
|
||||
/**
|
||||
* Gets the current x-position of the Body.
|
||||
**/
|
||||
float getX();
|
||||
|
||||
/**
|
||||
* Gets the current y-position of the Body.
|
||||
**/
|
||||
float getY();
|
||||
|
||||
/**
|
||||
* Gets the current angle (deg) of the Body.
|
||||
**/
|
||||
float getAngle();
|
||||
|
||||
/**
|
||||
* Gets the current position of the Body.
|
||||
* @returns The current position.
|
||||
**/
|
||||
void getPosition(float &x_o, float &y_o);
|
||||
|
||||
/**
|
||||
* Gets the velocity in the current center of mass.
|
||||
* @returns The velocity in the current center of mass.
|
||||
**/
|
||||
void getLinearVelocity(float &x_o, float &y_o);
|
||||
|
||||
/**
|
||||
* The current center of mass for the Body in world
|
||||
* coordinates.
|
||||
* @returns The x-component of the point.
|
||||
* @returns The y-component of the point.
|
||||
**/
|
||||
void getWorldCenter(float &x_o, float &y_o);
|
||||
|
||||
/**
|
||||
* The current center of mass for the Body in local
|
||||
* coordinates.
|
||||
* @returns The x-component of the point.
|
||||
* @returns The y-component of the point.
|
||||
**/
|
||||
void getLocalCenter(float &x_o, float &y_o);
|
||||
|
||||
/**
|
||||
* Get the current Body spin. (Angular velocity).
|
||||
**/
|
||||
float getAngularVelocity() const;
|
||||
|
||||
/**
|
||||
* Gets the Body's mass.
|
||||
**/
|
||||
float getMass() const;
|
||||
|
||||
/**
|
||||
* Gets the Body's intertia.
|
||||
**/
|
||||
float getInertia() const;
|
||||
|
||||
/**
|
||||
* Gets mass properties.
|
||||
**/
|
||||
int getMassData(lua_State *L);
|
||||
|
||||
/**
|
||||
* Gets the Body's angular damping.
|
||||
**/
|
||||
float getAngularDamping() const;
|
||||
|
||||
/**
|
||||
* Gets the Body's linear damping.
|
||||
**/
|
||||
float getLinearDamping() const;
|
||||
|
||||
/**
|
||||
* Gets the Body's gravity scale.
|
||||
**/
|
||||
float getGravityScale() const;
|
||||
|
||||
/**
|
||||
* Gets the type of body this is.
|
||||
**/
|
||||
Type getType() const;
|
||||
|
||||
/**
|
||||
* Apply an impulse (jx, jy) with offset (0, 0).
|
||||
**/
|
||||
void applyLinearImpulse(float jx, float jy);
|
||||
|
||||
/**
|
||||
* Apply an impulse (jx, jy) with offset (rx, ry).
|
||||
**/
|
||||
void applyLinearImpulse(float jx, float jy, float rx, float ry);
|
||||
|
||||
/**
|
||||
* Apply an angular impulse to the body.
|
||||
**/
|
||||
void applyAngularImpulse(float impulse);
|
||||
|
||||
/**
|
||||
* Apply torque (t).
|
||||
**/
|
||||
void applyTorque(float t);
|
||||
|
||||
/**
|
||||
* Apply force (fx, fy) with offset (0, 0).
|
||||
**/
|
||||
void applyForce(float fx, float fy);
|
||||
|
||||
/**
|
||||
* Apply force (fx, fy) with offset (rx, ry).
|
||||
**/
|
||||
void applyForce(float fx, float fy, float rx, float ry);
|
||||
|
||||
/**
|
||||
* Sets the x-position of the Body.
|
||||
**/
|
||||
void setX(float x);
|
||||
|
||||
/**
|
||||
* Sets the Y-position of the Body.
|
||||
**/
|
||||
void setY(float y);
|
||||
|
||||
/**
|
||||
* Sets the current velocity of the Body.
|
||||
**/
|
||||
void setLinearVelocity(float x, float y);
|
||||
|
||||
/**
|
||||
* Sets the angle of the Body.
|
||||
**/
|
||||
void setAngle(float d);
|
||||
|
||||
/**
|
||||
* Sets the current spin of the Body.
|
||||
**/
|
||||
void setAngularVelocity(float r);
|
||||
|
||||
/**
|
||||
* Sets the current position of the Body.
|
||||
**/
|
||||
void setPosition(float x, float y);
|
||||
|
||||
/**
|
||||
* Sets the mass from the currently attatched shapes.
|
||||
**/
|
||||
void resetMassData();
|
||||
|
||||
/**
|
||||
* Sets mass properties.
|
||||
* @param x The x-coordinate for the local center of mass.
|
||||
* @param y The y-coordinate for the local center of mass.
|
||||
* @param m The mass.
|
||||
* @param i The inertia.
|
||||
**/
|
||||
void setMassData(float x, float y, float m, float i);
|
||||
|
||||
/**
|
||||
* Sets just the mass. This is provided as a LOVE bonus. Lovely!
|
||||
* @param m The mass.
|
||||
**/
|
||||
void setMass(float m);
|
||||
|
||||
/**
|
||||
* Sets the inertia while keeping the other properties
|
||||
* (mass and local center).
|
||||
* @param i The inertia.
|
||||
**/
|
||||
void setInertia(float i);
|
||||
|
||||
/**
|
||||
* Sets the Body's angular damping.
|
||||
**/
|
||||
void setAngularDamping(float d);
|
||||
|
||||
/**
|
||||
* Sets the Body's linear damping.
|
||||
**/
|
||||
void setLinearDamping(float d);
|
||||
|
||||
/**
|
||||
* Sets the Body's gravity scale.
|
||||
**/
|
||||
void setGravityScale(float scale);
|
||||
|
||||
/**
|
||||
* Sets the type of body this is.
|
||||
**/
|
||||
void setType(Type type);
|
||||
|
||||
/**
|
||||
* Transforms a point (x, y) from local coordinates
|
||||
* to world coordinates.
|
||||
* @param x The x-coordinate of the local point.
|
||||
* @param y The y-coordinate of the local point.
|
||||
* @returns The x-coordinate of the point in world coordinates.
|
||||
* @returns The y-coordinate of the point in world coordinates.
|
||||
**/
|
||||
void getWorldPoint(float x, float y, float &x_o, float &y_o);
|
||||
|
||||
/**
|
||||
* Transforms a vector (x, y) from local coordinates
|
||||
* to world coordinates.
|
||||
* @param x The x-coordinate of the local vector.
|
||||
* @param y The y-coordinate of the local vector.
|
||||
* @returns The x-coordinate of the vector in world coordinates.
|
||||
* @returns The y-coordinate of the vector in world coordinates.
|
||||
**/
|
||||
void getWorldVector(float x, float y, float &x_o, float &y_o);
|
||||
|
||||
/**
|
||||
* Transforms a series of points (x, y) from local coordinates
|
||||
* to world coordinates.
|
||||
**/
|
||||
int getWorldPoints(lua_State *L);
|
||||
|
||||
/**
|
||||
* Transforms a point (x, y) from world coordinates
|
||||
* to local coordinates.
|
||||
* @param x The x-coordinate of the world point.
|
||||
* @param y The y-coordinate of the world point.
|
||||
* @returns The x-coordinate of the point in local coordinates.
|
||||
* @returns The y-coordinate of the point in local coordinates.
|
||||
**/
|
||||
void getLocalPoint(float x, float y, float &x_o, float &y_o);
|
||||
|
||||
/**
|
||||
* Transforms a vector (x, y) from world coordinates
|
||||
* to local coordinates.
|
||||
* @param x The x-coordinate of the world vector.
|
||||
* @param y The y-coordinate of the world vector.
|
||||
* @returns The x-coordinate of the vector in local coordinates.
|
||||
* @returns The y-coordinate of the vector in local coordinates.
|
||||
**/
|
||||
void getLocalVector(float x, float y, float &x_o, float &y_o);
|
||||
|
||||
/**
|
||||
* Gets the velocity on the Body for the given world point.
|
||||
* @param x The x-coordinate of the world point.
|
||||
* @param y The y-coordinate of the world point.
|
||||
* @returns The x-component of the velocity vector.
|
||||
* @returns The y-component of the velocity vector.
|
||||
**/
|
||||
void getLinearVelocityFromWorldPoint(float x, float y, float &x_o, float &y_o);
|
||||
|
||||
/**
|
||||
* Gets the velocity on the Body for the given local point.
|
||||
* @param x The x-coordinate of the local point.
|
||||
* @param y The y-coordinate of the local point.
|
||||
* @returns The x-component of the velocity vector.
|
||||
* @returns The y-component of the velocity vector.
|
||||
**/
|
||||
void getLinearVelocityFromLocalPoint(float x, float y, float &x_o, float &y_o);
|
||||
|
||||
/**
|
||||
* Returns true if the Body is a bullet, false otherwise.
|
||||
**/
|
||||
bool isBullet() const;
|
||||
|
||||
/**
|
||||
* Set whether this Body should be treated as a bullet.
|
||||
* Bullets require more processing power than normal shapes.
|
||||
**/
|
||||
void setBullet(bool bullet);
|
||||
|
||||
/**
|
||||
* Checks whether a Body is active or not. An inactive body
|
||||
* cannot be interacted with.
|
||||
**/
|
||||
bool isActive() const;
|
||||
|
||||
/**
|
||||
* Checks whether a Body is awake or not. A Body
|
||||
* will fall to sleep if nothing happens to it for while.
|
||||
**/
|
||||
bool isAwake() const;
|
||||
|
||||
/**
|
||||
* Controls whether this Body should be allowed to sleep.
|
||||
**/
|
||||
void setSleepingAllowed(bool allow);
|
||||
bool isSleepingAllowed() const;
|
||||
|
||||
/**
|
||||
* Changes the body's active state.
|
||||
**/
|
||||
void setActive(bool active);
|
||||
|
||||
/**
|
||||
* Changes the body's sleep state.
|
||||
**/
|
||||
void setAwake(bool awake);
|
||||
|
||||
void setFixedRotation(bool fixed);
|
||||
bool isFixedRotation() const;
|
||||
|
||||
/**
|
||||
* Get the World this Body resides in.
|
||||
*/
|
||||
World *getWorld() const;
|
||||
|
||||
/**
|
||||
* Get an array of all the Fixtures attached to this Body.
|
||||
* @return An array of Fixtures.
|
||||
**/
|
||||
int getFixtureList(lua_State *L) const;
|
||||
|
||||
/**
|
||||
* Destroy this body.
|
||||
**/
|
||||
void destroy();
|
||||
|
||||
private:
|
||||
|
||||
/**
|
||||
* Gets a 2d vector from the arguments on the stack.
|
||||
**/
|
||||
b2Vec2 getVector(lua_State *L);
|
||||
|
||||
/**
|
||||
* Pushed the x- and y-components of a vector on
|
||||
* the stack.
|
||||
**/
|
||||
int pushVector(lua_State *L, const b2Vec2 &v);
|
||||
|
||||
// We need a shared_ptr to the parent World,
|
||||
// because World can not be destroyed as long as
|
||||
// bodies exists in it.
|
||||
//
|
||||
// This ensures that a World only can be destroyed
|
||||
// once all bodies have been destroyed too.
|
||||
World *world;
|
||||
};
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_BODY_H
|
||||
|
||||
@@ -1,114 +1,114 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#include "ChainShape.h"
|
||||
|
||||
// Module
|
||||
#include "Body.h"
|
||||
#include "World.h"
|
||||
#include "Physics.h"
|
||||
|
||||
#include "common/Memoizer.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
ChainShape::ChainShape(b2ChainShape *c, bool loop, bool own)
|
||||
: Shape(c, own), loop(loop)
|
||||
{
|
||||
}
|
||||
|
||||
ChainShape::~ChainShape()
|
||||
{
|
||||
}
|
||||
|
||||
void ChainShape::setNextVertex(float x, float y)
|
||||
{
|
||||
if (loop)
|
||||
{
|
||||
throw love::Exception("Physics error: Can't call setNextVertex on a loop ChainShape");
|
||||
return;
|
||||
}
|
||||
b2Vec2 v(x, y);
|
||||
b2ChainShape *c = (b2ChainShape *)shape;
|
||||
c->SetNextVertex(Physics::scaleDown(v));
|
||||
}
|
||||
|
||||
void ChainShape::setPrevVertex(float x, float y)
|
||||
{
|
||||
if (loop)
|
||||
{
|
||||
throw love::Exception("Physics error: Can't call setPrevVertex on a loop ChainShape");
|
||||
return;
|
||||
}
|
||||
b2Vec2 v(x, y);
|
||||
b2ChainShape *c = (b2ChainShape *)shape;
|
||||
c->SetNextVertex(Physics::scaleDown(v));
|
||||
}
|
||||
|
||||
EdgeShape *ChainShape::getChildEdge(int index) const
|
||||
{
|
||||
b2ChainShape *c = (b2ChainShape *)shape;
|
||||
b2EdgeShape e;
|
||||
c->GetChildEdge(&e, index);
|
||||
EdgeShape *edge = (EdgeShape *)Memoizer::find(&e);
|
||||
if (!edge)
|
||||
return new EdgeShape(&e);
|
||||
else
|
||||
{
|
||||
edge->retain();
|
||||
return edge;
|
||||
}
|
||||
}
|
||||
|
||||
int ChainShape::getChildCount() const
|
||||
{
|
||||
b2ChainShape *c = (b2ChainShape *)shape;
|
||||
return c->GetChildCount();
|
||||
}
|
||||
|
||||
int ChainShape::getVertexCount() const
|
||||
{
|
||||
b2ChainShape *c = (b2ChainShape *)shape;
|
||||
return c->m_count;
|
||||
}
|
||||
|
||||
b2Vec2 ChainShape::getPoint(int index) const
|
||||
{
|
||||
b2ChainShape *c = (b2ChainShape *)shape;
|
||||
if (index < 0 || index >= c->m_count)
|
||||
throw love::Exception("Physics error: index out of bounds");
|
||||
const b2Vec2 &v = c->m_vertices[index];
|
||||
return Physics::scaleUp(v);
|
||||
}
|
||||
|
||||
const b2Vec2 *ChainShape::getPoints() const
|
||||
{
|
||||
b2ChainShape *c = (b2ChainShape *)shape;
|
||||
return c->m_vertices;
|
||||
}
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#include "ChainShape.h"
|
||||
|
||||
// Module
|
||||
#include "Body.h"
|
||||
#include "World.h"
|
||||
#include "Physics.h"
|
||||
|
||||
#include "common/Memoizer.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
ChainShape::ChainShape(b2ChainShape *c, bool loop, bool own)
|
||||
: Shape(c, own), loop(loop)
|
||||
{
|
||||
}
|
||||
|
||||
ChainShape::~ChainShape()
|
||||
{
|
||||
}
|
||||
|
||||
void ChainShape::setNextVertex(float x, float y)
|
||||
{
|
||||
if (loop)
|
||||
{
|
||||
throw love::Exception("Physics error: Can't call setNextVertex on a loop ChainShape");
|
||||
return;
|
||||
}
|
||||
b2Vec2 v(x, y);
|
||||
b2ChainShape *c = (b2ChainShape *)shape;
|
||||
c->SetNextVertex(Physics::scaleDown(v));
|
||||
}
|
||||
|
||||
void ChainShape::setPrevVertex(float x, float y)
|
||||
{
|
||||
if (loop)
|
||||
{
|
||||
throw love::Exception("Physics error: Can't call setPrevVertex on a loop ChainShape");
|
||||
return;
|
||||
}
|
||||
b2Vec2 v(x, y);
|
||||
b2ChainShape *c = (b2ChainShape *)shape;
|
||||
c->SetNextVertex(Physics::scaleDown(v));
|
||||
}
|
||||
|
||||
EdgeShape *ChainShape::getChildEdge(int index) const
|
||||
{
|
||||
b2ChainShape *c = (b2ChainShape *)shape;
|
||||
b2EdgeShape e;
|
||||
c->GetChildEdge(&e, index);
|
||||
EdgeShape *edge = (EdgeShape *)Memoizer::find(&e);
|
||||
if (!edge)
|
||||
return new EdgeShape(&e);
|
||||
else
|
||||
{
|
||||
edge->retain();
|
||||
return edge;
|
||||
}
|
||||
}
|
||||
|
||||
int ChainShape::getChildCount() const
|
||||
{
|
||||
b2ChainShape *c = (b2ChainShape *)shape;
|
||||
return c->GetChildCount();
|
||||
}
|
||||
|
||||
int ChainShape::getVertexCount() const
|
||||
{
|
||||
b2ChainShape *c = (b2ChainShape *)shape;
|
||||
return c->m_count;
|
||||
}
|
||||
|
||||
b2Vec2 ChainShape::getPoint(int index) const
|
||||
{
|
||||
b2ChainShape *c = (b2ChainShape *)shape;
|
||||
if (index < 0 || index >= c->m_count)
|
||||
throw love::Exception("Physics error: index out of bounds");
|
||||
const b2Vec2 &v = c->m_vertices[index];
|
||||
return Physics::scaleUp(v);
|
||||
}
|
||||
|
||||
const b2Vec2 *ChainShape::getPoints() const
|
||||
{
|
||||
b2ChainShape *c = (b2ChainShape *)shape;
|
||||
return c->m_vertices;
|
||||
}
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
@@ -1,106 +1,106 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_PHYSICS_BOX2D_CHAIN_SHAPE_H
|
||||
#define LOVE_PHYSICS_BOX2D_CHAIN_SHAPE_H
|
||||
|
||||
// Module
|
||||
#include "Shape.h"
|
||||
#include "EdgeShape.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
/**
|
||||
* A ChainShape is a freeform collection of line segments.
|
||||
**/
|
||||
class ChainShape : public Shape
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Create a new ChainShape from a Box2D chain shape.
|
||||
* @param c The chain shape.
|
||||
**/
|
||||
ChainShape(b2ChainShape *c, bool loop = false, bool own = true);
|
||||
|
||||
virtual ~ChainShape();
|
||||
|
||||
/**
|
||||
* Establish connectivity to a vertex that follows
|
||||
* the last vertex. Fails if called on a loop.
|
||||
* @param x The x-coordinate of the vertex.
|
||||
* @param y The y-coordinate of the vertex.
|
||||
**/
|
||||
void setNextVertex(float x, float y);
|
||||
|
||||
/**
|
||||
* Establish connectivity to a vertex that precedes
|
||||
* the first vertex. Fails if called on a loop.
|
||||
* @param x The x-coordinate of the vertex.
|
||||
* @param y The y-coordinate of the vertex.
|
||||
**/
|
||||
void setPrevVertex(float x, float y);
|
||||
|
||||
/**
|
||||
* Gets the number of children shapes.
|
||||
**/
|
||||
int getChildCount() const;
|
||||
|
||||
/**
|
||||
* Returns a child EdgeShape.
|
||||
* @param index The index of the child shape.
|
||||
* @returns The specified child.
|
||||
**/
|
||||
EdgeShape *getChildEdge(int index) const;
|
||||
|
||||
/**
|
||||
* Returns the number of vertices in the shape.
|
||||
* @returns The number of vertices in the shape.
|
||||
**/
|
||||
int getVertexCount() const;
|
||||
|
||||
/**
|
||||
* Returns the vertex at the given index.
|
||||
* @param index The index of the vertex.
|
||||
* @returns The specified vertex.
|
||||
**/
|
||||
b2Vec2 getPoint(int index) const;
|
||||
|
||||
/**
|
||||
* Returns all of the vertices.
|
||||
* @returns The vertices the shape comprises.
|
||||
**/
|
||||
const b2Vec2 *getPoints() const;
|
||||
|
||||
private:
|
||||
// True if this ChainShape is a loop.
|
||||
bool loop;
|
||||
};
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_CHAIN_SHAPE_H
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_PHYSICS_BOX2D_CHAIN_SHAPE_H
|
||||
#define LOVE_PHYSICS_BOX2D_CHAIN_SHAPE_H
|
||||
|
||||
// Module
|
||||
#include "Shape.h"
|
||||
#include "EdgeShape.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
/**
|
||||
* A ChainShape is a freeform collection of line segments.
|
||||
**/
|
||||
class ChainShape : public Shape
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Create a new ChainShape from a Box2D chain shape.
|
||||
* @param c The chain shape.
|
||||
**/
|
||||
ChainShape(b2ChainShape *c, bool loop = false, bool own = true);
|
||||
|
||||
virtual ~ChainShape();
|
||||
|
||||
/**
|
||||
* Establish connectivity to a vertex that follows
|
||||
* the last vertex. Fails if called on a loop.
|
||||
* @param x The x-coordinate of the vertex.
|
||||
* @param y The y-coordinate of the vertex.
|
||||
**/
|
||||
void setNextVertex(float x, float y);
|
||||
|
||||
/**
|
||||
* Establish connectivity to a vertex that precedes
|
||||
* the first vertex. Fails if called on a loop.
|
||||
* @param x The x-coordinate of the vertex.
|
||||
* @param y The y-coordinate of the vertex.
|
||||
**/
|
||||
void setPrevVertex(float x, float y);
|
||||
|
||||
/**
|
||||
* Gets the number of children shapes.
|
||||
**/
|
||||
int getChildCount() const;
|
||||
|
||||
/**
|
||||
* Returns a child EdgeShape.
|
||||
* @param index The index of the child shape.
|
||||
* @returns The specified child.
|
||||
**/
|
||||
EdgeShape *getChildEdge(int index) const;
|
||||
|
||||
/**
|
||||
* Returns the number of vertices in the shape.
|
||||
* @returns The number of vertices in the shape.
|
||||
**/
|
||||
int getVertexCount() const;
|
||||
|
||||
/**
|
||||
* Returns the vertex at the given index.
|
||||
* @param index The index of the vertex.
|
||||
* @returns The specified vertex.
|
||||
**/
|
||||
b2Vec2 getPoint(int index) const;
|
||||
|
||||
/**
|
||||
* Returns all of the vertices.
|
||||
* @returns The vertices the shape comprises.
|
||||
**/
|
||||
const b2Vec2 *getPoints() const;
|
||||
|
||||
private:
|
||||
// True if this ChainShape is a loop.
|
||||
bool loop;
|
||||
};
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_CHAIN_SHAPE_H
|
||||
|
||||
@@ -1,58 +1,58 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#include "CircleShape.h"
|
||||
|
||||
// Module
|
||||
#include "Body.h"
|
||||
#include "World.h"
|
||||
#include "Physics.h"
|
||||
|
||||
#include "common/Memoizer.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
CircleShape::CircleShape(b2CircleShape *c, bool own)
|
||||
: Shape(c, own)
|
||||
{
|
||||
}
|
||||
|
||||
CircleShape::~CircleShape()
|
||||
{
|
||||
}
|
||||
|
||||
float CircleShape::getRadius() const
|
||||
{
|
||||
return Physics::scaleUp(shape->m_radius);
|
||||
}
|
||||
|
||||
void CircleShape::setRadius(float r)
|
||||
{
|
||||
shape->m_radius = Physics::scaleDown(r);
|
||||
}
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#include "CircleShape.h"
|
||||
|
||||
// Module
|
||||
#include "Body.h"
|
||||
#include "World.h"
|
||||
#include "Physics.h"
|
||||
|
||||
#include "common/Memoizer.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
CircleShape::CircleShape(b2CircleShape *c, bool own)
|
||||
: Shape(c, own)
|
||||
{
|
||||
}
|
||||
|
||||
CircleShape::~CircleShape()
|
||||
{
|
||||
}
|
||||
|
||||
float CircleShape::getRadius() const
|
||||
{
|
||||
return Physics::scaleUp(shape->m_radius);
|
||||
}
|
||||
|
||||
void CircleShape::setRadius(float r)
|
||||
{
|
||||
shape->m_radius = Physics::scaleDown(r);
|
||||
}
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
@@ -1,72 +1,72 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_PHYSICS_BOX2D_CIRCLE_SHAPE_H
|
||||
#define LOVE_PHYSICS_BOX2D_CIRCLE_SHAPE_H
|
||||
|
||||
// Module
|
||||
#include "Shape.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
/**
|
||||
* A CircleShape represent a Circle which can
|
||||
* be used for collision detection and physics.
|
||||
*
|
||||
* The CircleShape is much faster than the PolygonShape,
|
||||
* and should generally be used where possible.
|
||||
**/
|
||||
class CircleShape : public Shape
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Create a new CircleShape from the parent body and a
|
||||
* Box2D CircleShape definition.
|
||||
* @param body The parent body.
|
||||
* @param def The CircleShape definition.
|
||||
**/
|
||||
CircleShape(b2CircleShape *c, bool own = true);
|
||||
|
||||
virtual ~CircleShape();
|
||||
|
||||
/**
|
||||
* Gets the radius for the circle.
|
||||
**/
|
||||
float getRadius() const;
|
||||
|
||||
/**
|
||||
* Sets the radius for the circle.
|
||||
**/
|
||||
void setRadius(float r);
|
||||
};
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_CIRCLE_SHAPE_H
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_PHYSICS_BOX2D_CIRCLE_SHAPE_H
|
||||
#define LOVE_PHYSICS_BOX2D_CIRCLE_SHAPE_H
|
||||
|
||||
// Module
|
||||
#include "Shape.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
/**
|
||||
* A CircleShape represent a Circle which can
|
||||
* be used for collision detection and physics.
|
||||
*
|
||||
* The CircleShape is much faster than the PolygonShape,
|
||||
* and should generally be used where possible.
|
||||
**/
|
||||
class CircleShape : public Shape
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Create a new CircleShape from the parent body and a
|
||||
* Box2D CircleShape definition.
|
||||
* @param body The parent body.
|
||||
* @param def The CircleShape definition.
|
||||
**/
|
||||
CircleShape(b2CircleShape *c, bool own = true);
|
||||
|
||||
virtual ~CircleShape();
|
||||
|
||||
/**
|
||||
* Gets the radius for the circle.
|
||||
**/
|
||||
float getRadius() const;
|
||||
|
||||
/**
|
||||
* Sets the radius for the circle.
|
||||
**/
|
||||
void setRadius(float r);
|
||||
};
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_CIRCLE_SHAPE_H
|
||||
|
||||
@@ -1,117 +1,117 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#include "Contact.h"
|
||||
#include "World.h"
|
||||
#include "Physics.h"
|
||||
|
||||
#include "common/Memoizer.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
Contact::Contact(b2Contact *contact)
|
||||
: contact(contact)
|
||||
{
|
||||
Memoizer::add(contact, this);
|
||||
}
|
||||
|
||||
Contact::~Contact()
|
||||
{
|
||||
Memoizer::remove(contact);
|
||||
}
|
||||
|
||||
int Contact::getPositions(lua_State *L)
|
||||
{
|
||||
love::luax_assert_argc(L, 1, 1);
|
||||
b2WorldManifold manifold;
|
||||
contact->GetWorldManifold(&manifold);
|
||||
int points = contact->GetManifold()->pointCount;
|
||||
for (int i = 0; i < points; i++)
|
||||
{
|
||||
b2Vec2 position = Physics::scaleUp(manifold.points[i]);
|
||||
lua_pushnumber(L, position.x);
|
||||
lua_pushnumber(L, position.y);
|
||||
}
|
||||
return points*2;
|
||||
}
|
||||
|
||||
int Contact::getNormal(lua_State *L)
|
||||
{
|
||||
love::luax_assert_argc(L, 1, 1);
|
||||
b2WorldManifold manifold;
|
||||
contact->GetWorldManifold(&manifold);
|
||||
lua_pushnumber(L, manifold.normal.x);
|
||||
lua_pushnumber(L, manifold.normal.y);
|
||||
return 2;
|
||||
}
|
||||
|
||||
float Contact::getFriction() const
|
||||
{
|
||||
return contact->GetFriction();
|
||||
}
|
||||
|
||||
float Contact::getRestitution() const
|
||||
{
|
||||
return contact->GetRestitution();
|
||||
}
|
||||
|
||||
bool Contact::isEnabled() const
|
||||
{
|
||||
return contact->IsEnabled();
|
||||
}
|
||||
|
||||
bool Contact::isTouching() const
|
||||
{
|
||||
return contact->IsTouching();
|
||||
}
|
||||
|
||||
void Contact::setFriction(float friction)
|
||||
{
|
||||
contact->SetFriction(friction);
|
||||
}
|
||||
|
||||
void Contact::setRestitution(float restitution)
|
||||
{
|
||||
contact->SetRestitution(restitution);
|
||||
}
|
||||
|
||||
void Contact::setEnabled(bool enabled)
|
||||
{
|
||||
contact->SetEnabled(enabled);
|
||||
}
|
||||
|
||||
void Contact::resetFriction()
|
||||
{
|
||||
contact->ResetFriction();
|
||||
}
|
||||
|
||||
void Contact::resetRestitution()
|
||||
{
|
||||
contact->ResetRestitution();
|
||||
}
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#include "Contact.h"
|
||||
#include "World.h"
|
||||
#include "Physics.h"
|
||||
|
||||
#include "common/Memoizer.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
Contact::Contact(b2Contact *contact)
|
||||
: contact(contact)
|
||||
{
|
||||
Memoizer::add(contact, this);
|
||||
}
|
||||
|
||||
Contact::~Contact()
|
||||
{
|
||||
Memoizer::remove(contact);
|
||||
}
|
||||
|
||||
int Contact::getPositions(lua_State *L)
|
||||
{
|
||||
love::luax_assert_argc(L, 1, 1);
|
||||
b2WorldManifold manifold;
|
||||
contact->GetWorldManifold(&manifold);
|
||||
int points = contact->GetManifold()->pointCount;
|
||||
for (int i = 0; i < points; i++)
|
||||
{
|
||||
b2Vec2 position = Physics::scaleUp(manifold.points[i]);
|
||||
lua_pushnumber(L, position.x);
|
||||
lua_pushnumber(L, position.y);
|
||||
}
|
||||
return points*2;
|
||||
}
|
||||
|
||||
int Contact::getNormal(lua_State *L)
|
||||
{
|
||||
love::luax_assert_argc(L, 1, 1);
|
||||
b2WorldManifold manifold;
|
||||
contact->GetWorldManifold(&manifold);
|
||||
lua_pushnumber(L, manifold.normal.x);
|
||||
lua_pushnumber(L, manifold.normal.y);
|
||||
return 2;
|
||||
}
|
||||
|
||||
float Contact::getFriction() const
|
||||
{
|
||||
return contact->GetFriction();
|
||||
}
|
||||
|
||||
float Contact::getRestitution() const
|
||||
{
|
||||
return contact->GetRestitution();
|
||||
}
|
||||
|
||||
bool Contact::isEnabled() const
|
||||
{
|
||||
return contact->IsEnabled();
|
||||
}
|
||||
|
||||
bool Contact::isTouching() const
|
||||
{
|
||||
return contact->IsTouching();
|
||||
}
|
||||
|
||||
void Contact::setFriction(float friction)
|
||||
{
|
||||
contact->SetFriction(friction);
|
||||
}
|
||||
|
||||
void Contact::setRestitution(float restitution)
|
||||
{
|
||||
contact->SetRestitution(restitution);
|
||||
}
|
||||
|
||||
void Contact::setEnabled(bool enabled)
|
||||
{
|
||||
contact->SetEnabled(enabled);
|
||||
}
|
||||
|
||||
void Contact::resetFriction()
|
||||
{
|
||||
contact->ResetFriction();
|
||||
}
|
||||
|
||||
void Contact::resetRestitution()
|
||||
{
|
||||
contact->ResetRestitution();
|
||||
}
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
+137
-137
@@ -1,137 +1,137 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_PHYSICS_BOX2D_CONTACT_H
|
||||
#define LOVE_PHYSICS_BOX2D_CONTACT_H
|
||||
|
||||
// LOVE
|
||||
#include "common/Object.h"
|
||||
#include "common/runtime.h"
|
||||
#include "World.h"
|
||||
|
||||
// Box2D
|
||||
#include <Box2D/Box2D.h>
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
class World;
|
||||
|
||||
/**
|
||||
* A Contact represents a collision point between
|
||||
* two shapes.
|
||||
**/
|
||||
class Contact : public Object
|
||||
{
|
||||
public:
|
||||
// Friends.
|
||||
friend class World;
|
||||
friend class World::ContactCallback;
|
||||
|
||||
/**
|
||||
* Creates a new Contact by copying a Box2D contact
|
||||
* point. It does not store the pointer, but copy the
|
||||
* data pointed to.
|
||||
* @param point Pointer to the Box2D contact.
|
||||
**/
|
||||
Contact(b2Contact *contact);
|
||||
|
||||
virtual ~Contact();
|
||||
|
||||
/**
|
||||
* Gets the position of each point of contact.
|
||||
* @return The position along the x-axis.
|
||||
* @return The position along the y-axis.
|
||||
**/
|
||||
int getPositions(lua_State *L);
|
||||
|
||||
/**
|
||||
* Gets the collision normal.
|
||||
* @return The x-component of the normal.
|
||||
* @return The y-component of the normal.
|
||||
**/
|
||||
int getNormal(lua_State *L);
|
||||
|
||||
/**
|
||||
* The mixed friction between the two fixtures at
|
||||
* the point of impact.
|
||||
**/
|
||||
float getFriction() const;
|
||||
|
||||
/**
|
||||
* The mixed restitution of the two fixtures
|
||||
* at the point of impact.
|
||||
**/
|
||||
float getRestitution() const;
|
||||
|
||||
/**
|
||||
* Check if the contact is enabled.
|
||||
**/
|
||||
bool isEnabled() const;
|
||||
|
||||
/**
|
||||
* Check if the contact is touching.
|
||||
**/
|
||||
bool isTouching() const;
|
||||
|
||||
// Only call the setters in PreSolve
|
||||
|
||||
/**
|
||||
* Override the default friction mixture.
|
||||
**/
|
||||
void setFriction(float friction);
|
||||
|
||||
/**
|
||||
* Override the default restitution mixture.
|
||||
**/
|
||||
void setRestitution(float restitution);
|
||||
|
||||
/**
|
||||
* Enable/disable this contact.
|
||||
**/
|
||||
void setEnabled(bool enabled);
|
||||
|
||||
/**
|
||||
* Reset the friction mixture to the default
|
||||
* value.
|
||||
**/
|
||||
void resetFriction();
|
||||
|
||||
/**
|
||||
* Reset the restitution mixture to the default
|
||||
* value.
|
||||
**/
|
||||
void resetRestitution();
|
||||
|
||||
private:
|
||||
|
||||
// The Box2D contact.
|
||||
b2Contact *contact;
|
||||
};
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_CONTACT_H
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_PHYSICS_BOX2D_CONTACT_H
|
||||
#define LOVE_PHYSICS_BOX2D_CONTACT_H
|
||||
|
||||
// LOVE
|
||||
#include "common/Object.h"
|
||||
#include "common/runtime.h"
|
||||
#include "World.h"
|
||||
|
||||
// Box2D
|
||||
#include <Box2D/Box2D.h>
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
class World;
|
||||
|
||||
/**
|
||||
* A Contact represents a collision point between
|
||||
* two shapes.
|
||||
**/
|
||||
class Contact : public Object
|
||||
{
|
||||
public:
|
||||
// Friends.
|
||||
friend class World;
|
||||
friend class World::ContactCallback;
|
||||
|
||||
/**
|
||||
* Creates a new Contact by copying a Box2D contact
|
||||
* point. It does not store the pointer, but copy the
|
||||
* data pointed to.
|
||||
* @param point Pointer to the Box2D contact.
|
||||
**/
|
||||
Contact(b2Contact *contact);
|
||||
|
||||
virtual ~Contact();
|
||||
|
||||
/**
|
||||
* Gets the position of each point of contact.
|
||||
* @return The position along the x-axis.
|
||||
* @return The position along the y-axis.
|
||||
**/
|
||||
int getPositions(lua_State *L);
|
||||
|
||||
/**
|
||||
* Gets the collision normal.
|
||||
* @return The x-component of the normal.
|
||||
* @return The y-component of the normal.
|
||||
**/
|
||||
int getNormal(lua_State *L);
|
||||
|
||||
/**
|
||||
* The mixed friction between the two fixtures at
|
||||
* the point of impact.
|
||||
**/
|
||||
float getFriction() const;
|
||||
|
||||
/**
|
||||
* The mixed restitution of the two fixtures
|
||||
* at the point of impact.
|
||||
**/
|
||||
float getRestitution() const;
|
||||
|
||||
/**
|
||||
* Check if the contact is enabled.
|
||||
**/
|
||||
bool isEnabled() const;
|
||||
|
||||
/**
|
||||
* Check if the contact is touching.
|
||||
**/
|
||||
bool isTouching() const;
|
||||
|
||||
// Only call the setters in PreSolve
|
||||
|
||||
/**
|
||||
* Override the default friction mixture.
|
||||
**/
|
||||
void setFriction(float friction);
|
||||
|
||||
/**
|
||||
* Override the default restitution mixture.
|
||||
**/
|
||||
void setRestitution(float restitution);
|
||||
|
||||
/**
|
||||
* Enable/disable this contact.
|
||||
**/
|
||||
void setEnabled(bool enabled);
|
||||
|
||||
/**
|
||||
* Reset the friction mixture to the default
|
||||
* value.
|
||||
**/
|
||||
void resetFriction();
|
||||
|
||||
/**
|
||||
* Reset the restitution mixture to the default
|
||||
* value.
|
||||
**/
|
||||
void resetRestitution();
|
||||
|
||||
private:
|
||||
|
||||
// The Box2D contact.
|
||||
b2Contact *contact;
|
||||
};
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_CONTACT_H
|
||||
|
||||
@@ -1,82 +1,82 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#include "DistanceJoint.h"
|
||||
|
||||
// Module
|
||||
#include "Body.h"
|
||||
#include "World.h"
|
||||
#include "Physics.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
DistanceJoint::DistanceJoint(Body *body1, Body *body2, float x1, float y1, float x2, float y2, bool collideConnected)
|
||||
: Joint(body1, body2)
|
||||
, joint(NULL)
|
||||
{
|
||||
b2DistanceJointDef def;
|
||||
def.Initialize(body1->body, body2->body, Physics::scaleDown(b2Vec2(x1,y1)), Physics::scaleDown(b2Vec2(x2,y2)));
|
||||
def.collideConnected = collideConnected;
|
||||
joint = (b2DistanceJoint *)createJoint(&def);
|
||||
}
|
||||
|
||||
DistanceJoint::~DistanceJoint()
|
||||
{
|
||||
}
|
||||
|
||||
void DistanceJoint::setLength(float length)
|
||||
{
|
||||
joint->SetLength(Physics::scaleDown(length));
|
||||
}
|
||||
|
||||
float DistanceJoint::getLength() const
|
||||
{
|
||||
return Physics::scaleUp(joint->GetLength());
|
||||
}
|
||||
|
||||
void DistanceJoint::setFrequency(float hz)
|
||||
{
|
||||
joint->SetFrequency(hz);
|
||||
}
|
||||
|
||||
float DistanceJoint::getFrequency() const
|
||||
{
|
||||
return joint->GetFrequency();
|
||||
}
|
||||
|
||||
void DistanceJoint::setDampingRatio(float d)
|
||||
{
|
||||
joint->SetDampingRatio(d);
|
||||
}
|
||||
|
||||
float DistanceJoint::getDampingRatio() const
|
||||
{
|
||||
return joint->GetDampingRatio();
|
||||
}
|
||||
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#include "DistanceJoint.h"
|
||||
|
||||
// Module
|
||||
#include "Body.h"
|
||||
#include "World.h"
|
||||
#include "Physics.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
DistanceJoint::DistanceJoint(Body *body1, Body *body2, float x1, float y1, float x2, float y2, bool collideConnected)
|
||||
: Joint(body1, body2)
|
||||
, joint(NULL)
|
||||
{
|
||||
b2DistanceJointDef def;
|
||||
def.Initialize(body1->body, body2->body, Physics::scaleDown(b2Vec2(x1,y1)), Physics::scaleDown(b2Vec2(x2,y2)));
|
||||
def.collideConnected = collideConnected;
|
||||
joint = (b2DistanceJoint *)createJoint(&def);
|
||||
}
|
||||
|
||||
DistanceJoint::~DistanceJoint()
|
||||
{
|
||||
}
|
||||
|
||||
void DistanceJoint::setLength(float length)
|
||||
{
|
||||
joint->SetLength(Physics::scaleDown(length));
|
||||
}
|
||||
|
||||
float DistanceJoint::getLength() const
|
||||
{
|
||||
return Physics::scaleUp(joint->GetLength());
|
||||
}
|
||||
|
||||
void DistanceJoint::setFrequency(float hz)
|
||||
{
|
||||
joint->SetFrequency(hz);
|
||||
}
|
||||
|
||||
float DistanceJoint::getFrequency() const
|
||||
{
|
||||
return joint->GetFrequency();
|
||||
}
|
||||
|
||||
void DistanceJoint::setDampingRatio(float d)
|
||||
{
|
||||
joint->SetDampingRatio(d);
|
||||
}
|
||||
|
||||
float DistanceJoint::getDampingRatio() const
|
||||
{
|
||||
return joint->GetDampingRatio();
|
||||
}
|
||||
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
@@ -1,90 +1,90 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_PHYSICS_BOX2D_DISTANCE_JOINT_H
|
||||
#define LOVE_PHYSICS_BOX2D_DISTANCE_JOINT_H
|
||||
|
||||
// Module
|
||||
#include "Joint.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
/**
|
||||
* The DistanceJoint keeps Bodies at a fixed distance
|
||||
* from eachother.
|
||||
**/
|
||||
class DistanceJoint : public Joint
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Creates a DistanceJoint connecting body1 to body2.
|
||||
**/
|
||||
DistanceJoint(Body *body1, Body *body2, float x1, float y1, float x2, float y2, bool collideConnected);
|
||||
|
||||
virtual ~DistanceJoint();
|
||||
|
||||
/**
|
||||
* Sets the equilibrium distance between the two bodies.
|
||||
**/
|
||||
void setLength(float length);
|
||||
|
||||
/**
|
||||
* Gets the equilibrium distance between the two bodies.
|
||||
**/
|
||||
float getLength() const;
|
||||
|
||||
/**
|
||||
* Sets the response speed.
|
||||
**/
|
||||
void setFrequency(float hz);
|
||||
|
||||
/**
|
||||
* Gets the response speed.
|
||||
**/
|
||||
float getFrequency() const;
|
||||
|
||||
/**
|
||||
* Sets the damping ratio.
|
||||
* 0 = no damping, 1 = critical damping.
|
||||
**/
|
||||
void setDampingRatio(float d);
|
||||
|
||||
/**
|
||||
* Gets the damping ratio.
|
||||
* 0 = no damping, 1 = critical damping.
|
||||
**/
|
||||
float getDampingRatio() const;
|
||||
|
||||
private:
|
||||
// The Box2D DistanceJoint object.
|
||||
b2DistanceJoint *joint;
|
||||
};
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_DISTANCE_JOINT_H
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_PHYSICS_BOX2D_DISTANCE_JOINT_H
|
||||
#define LOVE_PHYSICS_BOX2D_DISTANCE_JOINT_H
|
||||
|
||||
// Module
|
||||
#include "Joint.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
/**
|
||||
* The DistanceJoint keeps Bodies at a fixed distance
|
||||
* from eachother.
|
||||
**/
|
||||
class DistanceJoint : public Joint
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Creates a DistanceJoint connecting body1 to body2.
|
||||
**/
|
||||
DistanceJoint(Body *body1, Body *body2, float x1, float y1, float x2, float y2, bool collideConnected);
|
||||
|
||||
virtual ~DistanceJoint();
|
||||
|
||||
/**
|
||||
* Sets the equilibrium distance between the two bodies.
|
||||
**/
|
||||
void setLength(float length);
|
||||
|
||||
/**
|
||||
* Gets the equilibrium distance between the two bodies.
|
||||
**/
|
||||
float getLength() const;
|
||||
|
||||
/**
|
||||
* Sets the response speed.
|
||||
**/
|
||||
void setFrequency(float hz);
|
||||
|
||||
/**
|
||||
* Gets the response speed.
|
||||
**/
|
||||
float getFrequency() const;
|
||||
|
||||
/**
|
||||
* Sets the damping ratio.
|
||||
* 0 = no damping, 1 = critical damping.
|
||||
**/
|
||||
void setDampingRatio(float d);
|
||||
|
||||
/**
|
||||
* Gets the damping ratio.
|
||||
* 0 = no damping, 1 = critical damping.
|
||||
**/
|
||||
float getDampingRatio() const;
|
||||
|
||||
private:
|
||||
// The Box2D DistanceJoint object.
|
||||
b2DistanceJoint *joint;
|
||||
};
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_DISTANCE_JOINT_H
|
||||
|
||||
@@ -1,61 +1,61 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#include "EdgeShape.h"
|
||||
|
||||
// Module
|
||||
#include "Body.h"
|
||||
#include "World.h"
|
||||
#include "Physics.h"
|
||||
|
||||
#include "common/Memoizer.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
EdgeShape::EdgeShape(b2EdgeShape *e, bool own)
|
||||
: Shape(e, own)
|
||||
{
|
||||
}
|
||||
|
||||
EdgeShape::~EdgeShape()
|
||||
{
|
||||
}
|
||||
|
||||
int EdgeShape::getPoints(lua_State *L)
|
||||
{
|
||||
b2EdgeShape *e = (b2EdgeShape *)shape;
|
||||
b2Vec2 v1 = Physics::scaleUp(e->m_vertex1);
|
||||
b2Vec2 v2 = Physics::scaleUp(e->m_vertex2);
|
||||
lua_pushnumber(L, v1.x);
|
||||
lua_pushnumber(L, v1.y);
|
||||
lua_pushnumber(L, v2.x);
|
||||
lua_pushnumber(L, v2.y);
|
||||
return 4;
|
||||
|
||||
}
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#include "EdgeShape.h"
|
||||
|
||||
// Module
|
||||
#include "Body.h"
|
||||
#include "World.h"
|
||||
#include "Physics.h"
|
||||
|
||||
#include "common/Memoizer.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
EdgeShape::EdgeShape(b2EdgeShape *e, bool own)
|
||||
: Shape(e, own)
|
||||
{
|
||||
}
|
||||
|
||||
EdgeShape::~EdgeShape()
|
||||
{
|
||||
}
|
||||
|
||||
int EdgeShape::getPoints(lua_State *L)
|
||||
{
|
||||
b2EdgeShape *e = (b2EdgeShape *)shape;
|
||||
b2Vec2 v1 = Physics::scaleUp(e->m_vertex1);
|
||||
b2Vec2 v2 = Physics::scaleUp(e->m_vertex2);
|
||||
lua_pushnumber(L, v1.x);
|
||||
lua_pushnumber(L, v1.y);
|
||||
lua_pushnumber(L, v2.x);
|
||||
lua_pushnumber(L, v2.y);
|
||||
return 4;
|
||||
|
||||
}
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
@@ -1,63 +1,63 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_PHYSICS_BOX2D_EDGE_SHAPE_H
|
||||
#define LOVE_PHYSICS_BOX2D_EDGE_SHAPE_H
|
||||
|
||||
// Module
|
||||
#include "Shape.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
/**
|
||||
* An Edge is just a line segment. Edges are designed to
|
||||
* be connected and/or chained together.
|
||||
**/
|
||||
class EdgeShape : public Shape
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Create a new EdgeShape from a Box2D edge shape.
|
||||
* @param e The edge shape.
|
||||
**/
|
||||
EdgeShape(b2EdgeShape *e, bool own = true);
|
||||
|
||||
virtual ~EdgeShape();
|
||||
|
||||
/**
|
||||
* Returns the transformed points of the edge shape.
|
||||
* This function is useful for debug drawing and such.
|
||||
*
|
||||
* The result can be directly passed into love.graphics.line().
|
||||
**/
|
||||
int getPoints(lua_State *L);
|
||||
};
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_EDGE_SHAPE_H
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_PHYSICS_BOX2D_EDGE_SHAPE_H
|
||||
#define LOVE_PHYSICS_BOX2D_EDGE_SHAPE_H
|
||||
|
||||
// Module
|
||||
#include "Shape.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
/**
|
||||
* An Edge is just a line segment. Edges are designed to
|
||||
* be connected and/or chained together.
|
||||
**/
|
||||
class EdgeShape : public Shape
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Create a new EdgeShape from a Box2D edge shape.
|
||||
* @param e The edge shape.
|
||||
**/
|
||||
EdgeShape(b2EdgeShape *e, bool own = true);
|
||||
|
||||
virtual ~EdgeShape();
|
||||
|
||||
/**
|
||||
* Returns the transformed points of the edge shape.
|
||||
* This function is useful for debug drawing and such.
|
||||
*
|
||||
* The result can be directly passed into love.graphics.line().
|
||||
**/
|
||||
int getPoints(lua_State *L);
|
||||
};
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_EDGE_SHAPE_H
|
||||
|
||||
@@ -1,325 +1,325 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#include "Fixture.h"
|
||||
|
||||
// Module
|
||||
#include "Body.h"
|
||||
#include "World.h"
|
||||
#include "Physics.h"
|
||||
|
||||
#include "common/Memoizer.h"
|
||||
|
||||
// STD
|
||||
#include <bitset>
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
Fixture::Fixture(Body *body, Shape *shape, float density)
|
||||
: body(body)
|
||||
, fixture(NULL)
|
||||
{
|
||||
data = new fixtureudata();
|
||||
data->ref = 0;
|
||||
b2FixtureDef def;
|
||||
def.shape = shape->shape;
|
||||
def.userData = (void *)data;
|
||||
def.density = density;
|
||||
fixture = body->body->CreateFixture(&def);
|
||||
this->retain();
|
||||
Memoizer::add(fixture, this);
|
||||
}
|
||||
|
||||
Fixture::Fixture(b2Fixture *f)
|
||||
: fixture(f)
|
||||
{
|
||||
data = (fixtureudata *)f->GetUserData();
|
||||
body = (Body *)Memoizer::find(f->GetBody());
|
||||
if (!body)
|
||||
body = new Body(f->GetBody());
|
||||
this->retain();
|
||||
Memoizer::add(fixture, this);
|
||||
}
|
||||
|
||||
Fixture::~Fixture()
|
||||
{
|
||||
if (data->ref != 0)
|
||||
delete data->ref;
|
||||
|
||||
delete data;
|
||||
data = NULL;
|
||||
|
||||
fixture = NULL;
|
||||
}
|
||||
|
||||
Shape::Type Fixture::getType() const
|
||||
{
|
||||
return Shape(fixture->GetShape()).getType();
|
||||
}
|
||||
|
||||
void Fixture::setFriction(float friction)
|
||||
{
|
||||
fixture->SetFriction(friction);
|
||||
}
|
||||
|
||||
void Fixture::setRestitution(float restitution)
|
||||
{
|
||||
fixture->SetRestitution(restitution);
|
||||
}
|
||||
|
||||
void Fixture::setDensity(float density)
|
||||
{
|
||||
fixture->SetDensity(density);
|
||||
}
|
||||
|
||||
void Fixture::setSensor(bool sensor)
|
||||
{
|
||||
fixture->SetSensor(sensor);
|
||||
}
|
||||
|
||||
float Fixture::getFriction() const
|
||||
{
|
||||
return fixture->GetFriction();
|
||||
}
|
||||
|
||||
float Fixture::getRestitution() const
|
||||
{
|
||||
return fixture->GetRestitution();
|
||||
}
|
||||
|
||||
float Fixture::getDensity() const
|
||||
{
|
||||
return fixture->GetDensity();
|
||||
}
|
||||
|
||||
bool Fixture::isSensor() const
|
||||
{
|
||||
return fixture->IsSensor();
|
||||
}
|
||||
|
||||
Body *Fixture::getBody() const
|
||||
{
|
||||
return body;
|
||||
}
|
||||
|
||||
Shape *Fixture::getShape() const
|
||||
{
|
||||
if (!fixture->GetShape())
|
||||
return NULL;
|
||||
|
||||
return new Shape(fixture->GetShape(), false);
|
||||
}
|
||||
|
||||
bool Fixture::isValid() const
|
||||
{
|
||||
return fixture != 0;
|
||||
}
|
||||
|
||||
void Fixture::setFilterData(int *v)
|
||||
{
|
||||
b2Filter f;
|
||||
f.categoryBits = (unsigned short)v[0];
|
||||
f.maskBits = (unsigned short)v[1];
|
||||
f.groupIndex = v[2];
|
||||
fixture->SetFilterData(f);
|
||||
}
|
||||
|
||||
void Fixture::getFilterData(int *v)
|
||||
{
|
||||
b2Filter f = fixture->GetFilterData();
|
||||
v[0] = (int)f.categoryBits;
|
||||
v[1] = (int)f.maskBits;
|
||||
v[2] = f.groupIndex;
|
||||
}
|
||||
|
||||
int Fixture::setCategory(lua_State *L)
|
||||
{
|
||||
b2Filter f = fixture->GetFilterData();
|
||||
f.categoryBits = (uint16)getBits(L);
|
||||
fixture->SetFilterData(f);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Fixture::setMask(lua_State *L)
|
||||
{
|
||||
b2Filter f = fixture->GetFilterData();
|
||||
f.maskBits = ~(uint16)getBits(L);
|
||||
fixture->SetFilterData(f);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void Fixture::setGroupIndex(int index)
|
||||
{
|
||||
b2Filter f = fixture->GetFilterData();
|
||||
f.groupIndex = (uint16)index;
|
||||
fixture->SetFilterData(f);
|
||||
}
|
||||
|
||||
int Fixture::getGroupIndex() const
|
||||
{
|
||||
b2Filter f = fixture->GetFilterData();
|
||||
return f.groupIndex;
|
||||
}
|
||||
|
||||
int Fixture::getCategory(lua_State *L)
|
||||
{
|
||||
return pushBits(L, fixture->GetFilterData().categoryBits);
|
||||
}
|
||||
|
||||
int Fixture::getMask(lua_State *L)
|
||||
{
|
||||
return pushBits(L, ~(fixture->GetFilterData().maskBits));
|
||||
}
|
||||
|
||||
uint16 Fixture::getBits(lua_State *L)
|
||||
{
|
||||
// Get number of args.
|
||||
int argc = lua_gettop(L);
|
||||
|
||||
// The new bitset.
|
||||
std::bitset<16> b;
|
||||
|
||||
for (int i = 1; i<=argc; i++)
|
||||
{
|
||||
size_t bpos = (size_t)(lua_tointeger(L, i)-1);
|
||||
if (bpos >= 16)
|
||||
return luaL_error(L, "Values must be in range 1-16.");
|
||||
b.set(bpos, true);
|
||||
}
|
||||
|
||||
return (uint16)b.to_ulong();
|
||||
}
|
||||
|
||||
int Fixture::pushBits(lua_State *L, uint16 bits)
|
||||
{
|
||||
// Create a bitset.
|
||||
std::bitset<16> b((int)bits);
|
||||
|
||||
// Push all set bits.
|
||||
for (int i = 0; i<16; i++)
|
||||
if (b.test(i))
|
||||
lua_pushinteger(L, i+1);
|
||||
|
||||
// Count number of set bits.
|
||||
return (int)b.count();
|
||||
}
|
||||
|
||||
int Fixture::setUserData(lua_State *L)
|
||||
{
|
||||
love::luax_assert_argc(L, 1, 1);
|
||||
|
||||
if (data->ref != 0)
|
||||
{
|
||||
delete data->ref;
|
||||
data->ref = 0;
|
||||
}
|
||||
|
||||
data->ref = new Reference(L);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Fixture::getUserData(lua_State *L)
|
||||
{
|
||||
love::luax_assert_argc(L, 0, 0);
|
||||
if (data->ref != 0)
|
||||
data->ref->push();
|
||||
else
|
||||
lua_pushnil(L);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
bool Fixture::testPoint(float x, float y) const
|
||||
{
|
||||
return fixture->TestPoint(Physics::scaleDown(b2Vec2(x, y)));
|
||||
}
|
||||
|
||||
int Fixture::rayCast(lua_State *L) const
|
||||
{
|
||||
float p1x = Physics::scaleDown((float)luaL_checknumber(L, 1));
|
||||
float p1y = Physics::scaleDown((float)luaL_checknumber(L, 2));
|
||||
float p2x = Physics::scaleDown((float)luaL_checknumber(L, 3));
|
||||
float p2y = Physics::scaleDown((float)luaL_checknumber(L, 4));
|
||||
float maxFraction = (float)luaL_checknumber(L, 5);
|
||||
int childIndex = (int)luaL_optint(L, 6, 1) - 1; // Convert from 1-based index
|
||||
b2RayCastInput input;
|
||||
input.p1.Set(p1x, p1y);
|
||||
input.p2.Set(p2x, p2y);
|
||||
input.maxFraction = maxFraction;
|
||||
b2RayCastOutput output;
|
||||
if (!fixture->RayCast(&output, input, childIndex))
|
||||
return 0; // Nothing hit.
|
||||
lua_pushnumber(L, output.normal.x);
|
||||
lua_pushnumber(L, output.normal.y);
|
||||
lua_pushnumber(L, output.fraction);
|
||||
return 3;
|
||||
}
|
||||
|
||||
int Fixture::getBoundingBox(lua_State *L) const
|
||||
{
|
||||
int childIndex = (int)luaL_optint(L, 1, 1) - 1; // Convert from 1-based index
|
||||
b2AABB box = fixture->GetAABB(childIndex);
|
||||
box = Physics::scaleUp(box);
|
||||
lua_pushnumber(L, box.lowerBound.x);
|
||||
lua_pushnumber(L, box.lowerBound.y);
|
||||
lua_pushnumber(L, box.upperBound.x);
|
||||
lua_pushnumber(L, box.upperBound.y);
|
||||
return 4;
|
||||
}
|
||||
|
||||
int Fixture::getMassData(lua_State *L) const
|
||||
{
|
||||
b2MassData data;
|
||||
fixture->GetMassData(&data);
|
||||
b2Vec2 center = Physics::scaleUp(data.center);
|
||||
lua_pushnumber(L, center.x);
|
||||
lua_pushnumber(L, center.y);
|
||||
lua_pushnumber(L, data.mass);
|
||||
lua_pushnumber(L, data.I);
|
||||
return 4;
|
||||
}
|
||||
|
||||
void Fixture::destroy(bool implicit)
|
||||
{
|
||||
if (body->world->world->IsLocked())
|
||||
{
|
||||
// Called during time step. Save reference for destruction afterwards.
|
||||
this->retain();
|
||||
body->world->destructFixtures.push_back(this);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!implicit && fixture != 0)
|
||||
body->body->DestroyFixture(fixture);
|
||||
Memoizer::remove(fixture);
|
||||
fixture = NULL;
|
||||
|
||||
// Box2D fixture destroyed. Release its reference to the love Fixture.
|
||||
this->release();
|
||||
}
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#include "Fixture.h"
|
||||
|
||||
// Module
|
||||
#include "Body.h"
|
||||
#include "World.h"
|
||||
#include "Physics.h"
|
||||
|
||||
#include "common/Memoizer.h"
|
||||
|
||||
// STD
|
||||
#include <bitset>
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
Fixture::Fixture(Body *body, Shape *shape, float density)
|
||||
: body(body)
|
||||
, fixture(NULL)
|
||||
{
|
||||
data = new fixtureudata();
|
||||
data->ref = 0;
|
||||
b2FixtureDef def;
|
||||
def.shape = shape->shape;
|
||||
def.userData = (void *)data;
|
||||
def.density = density;
|
||||
fixture = body->body->CreateFixture(&def);
|
||||
this->retain();
|
||||
Memoizer::add(fixture, this);
|
||||
}
|
||||
|
||||
Fixture::Fixture(b2Fixture *f)
|
||||
: fixture(f)
|
||||
{
|
||||
data = (fixtureudata *)f->GetUserData();
|
||||
body = (Body *)Memoizer::find(f->GetBody());
|
||||
if (!body)
|
||||
body = new Body(f->GetBody());
|
||||
this->retain();
|
||||
Memoizer::add(fixture, this);
|
||||
}
|
||||
|
||||
Fixture::~Fixture()
|
||||
{
|
||||
if (data->ref != 0)
|
||||
delete data->ref;
|
||||
|
||||
delete data;
|
||||
data = NULL;
|
||||
|
||||
fixture = NULL;
|
||||
}
|
||||
|
||||
Shape::Type Fixture::getType() const
|
||||
{
|
||||
return Shape(fixture->GetShape()).getType();
|
||||
}
|
||||
|
||||
void Fixture::setFriction(float friction)
|
||||
{
|
||||
fixture->SetFriction(friction);
|
||||
}
|
||||
|
||||
void Fixture::setRestitution(float restitution)
|
||||
{
|
||||
fixture->SetRestitution(restitution);
|
||||
}
|
||||
|
||||
void Fixture::setDensity(float density)
|
||||
{
|
||||
fixture->SetDensity(density);
|
||||
}
|
||||
|
||||
void Fixture::setSensor(bool sensor)
|
||||
{
|
||||
fixture->SetSensor(sensor);
|
||||
}
|
||||
|
||||
float Fixture::getFriction() const
|
||||
{
|
||||
return fixture->GetFriction();
|
||||
}
|
||||
|
||||
float Fixture::getRestitution() const
|
||||
{
|
||||
return fixture->GetRestitution();
|
||||
}
|
||||
|
||||
float Fixture::getDensity() const
|
||||
{
|
||||
return fixture->GetDensity();
|
||||
}
|
||||
|
||||
bool Fixture::isSensor() const
|
||||
{
|
||||
return fixture->IsSensor();
|
||||
}
|
||||
|
||||
Body *Fixture::getBody() const
|
||||
{
|
||||
return body;
|
||||
}
|
||||
|
||||
Shape *Fixture::getShape() const
|
||||
{
|
||||
if (!fixture->GetShape())
|
||||
return NULL;
|
||||
|
||||
return new Shape(fixture->GetShape(), false);
|
||||
}
|
||||
|
||||
bool Fixture::isValid() const
|
||||
{
|
||||
return fixture != 0;
|
||||
}
|
||||
|
||||
void Fixture::setFilterData(int *v)
|
||||
{
|
||||
b2Filter f;
|
||||
f.categoryBits = (unsigned short)v[0];
|
||||
f.maskBits = (unsigned short)v[1];
|
||||
f.groupIndex = v[2];
|
||||
fixture->SetFilterData(f);
|
||||
}
|
||||
|
||||
void Fixture::getFilterData(int *v)
|
||||
{
|
||||
b2Filter f = fixture->GetFilterData();
|
||||
v[0] = (int)f.categoryBits;
|
||||
v[1] = (int)f.maskBits;
|
||||
v[2] = f.groupIndex;
|
||||
}
|
||||
|
||||
int Fixture::setCategory(lua_State *L)
|
||||
{
|
||||
b2Filter f = fixture->GetFilterData();
|
||||
f.categoryBits = (uint16)getBits(L);
|
||||
fixture->SetFilterData(f);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Fixture::setMask(lua_State *L)
|
||||
{
|
||||
b2Filter f = fixture->GetFilterData();
|
||||
f.maskBits = ~(uint16)getBits(L);
|
||||
fixture->SetFilterData(f);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void Fixture::setGroupIndex(int index)
|
||||
{
|
||||
b2Filter f = fixture->GetFilterData();
|
||||
f.groupIndex = (uint16)index;
|
||||
fixture->SetFilterData(f);
|
||||
}
|
||||
|
||||
int Fixture::getGroupIndex() const
|
||||
{
|
||||
b2Filter f = fixture->GetFilterData();
|
||||
return f.groupIndex;
|
||||
}
|
||||
|
||||
int Fixture::getCategory(lua_State *L)
|
||||
{
|
||||
return pushBits(L, fixture->GetFilterData().categoryBits);
|
||||
}
|
||||
|
||||
int Fixture::getMask(lua_State *L)
|
||||
{
|
||||
return pushBits(L, ~(fixture->GetFilterData().maskBits));
|
||||
}
|
||||
|
||||
uint16 Fixture::getBits(lua_State *L)
|
||||
{
|
||||
// Get number of args.
|
||||
int argc = lua_gettop(L);
|
||||
|
||||
// The new bitset.
|
||||
std::bitset<16> b;
|
||||
|
||||
for (int i = 1; i<=argc; i++)
|
||||
{
|
||||
size_t bpos = (size_t)(lua_tointeger(L, i)-1);
|
||||
if (bpos >= 16)
|
||||
return luaL_error(L, "Values must be in range 1-16.");
|
||||
b.set(bpos, true);
|
||||
}
|
||||
|
||||
return (uint16)b.to_ulong();
|
||||
}
|
||||
|
||||
int Fixture::pushBits(lua_State *L, uint16 bits)
|
||||
{
|
||||
// Create a bitset.
|
||||
std::bitset<16> b((int)bits);
|
||||
|
||||
// Push all set bits.
|
||||
for (int i = 0; i<16; i++)
|
||||
if (b.test(i))
|
||||
lua_pushinteger(L, i+1);
|
||||
|
||||
// Count number of set bits.
|
||||
return (int)b.count();
|
||||
}
|
||||
|
||||
int Fixture::setUserData(lua_State *L)
|
||||
{
|
||||
love::luax_assert_argc(L, 1, 1);
|
||||
|
||||
if (data->ref != 0)
|
||||
{
|
||||
delete data->ref;
|
||||
data->ref = 0;
|
||||
}
|
||||
|
||||
data->ref = new Reference(L);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Fixture::getUserData(lua_State *L)
|
||||
{
|
||||
love::luax_assert_argc(L, 0, 0);
|
||||
if (data->ref != 0)
|
||||
data->ref->push();
|
||||
else
|
||||
lua_pushnil(L);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
bool Fixture::testPoint(float x, float y) const
|
||||
{
|
||||
return fixture->TestPoint(Physics::scaleDown(b2Vec2(x, y)));
|
||||
}
|
||||
|
||||
int Fixture::rayCast(lua_State *L) const
|
||||
{
|
||||
float p1x = Physics::scaleDown((float)luaL_checknumber(L, 1));
|
||||
float p1y = Physics::scaleDown((float)luaL_checknumber(L, 2));
|
||||
float p2x = Physics::scaleDown((float)luaL_checknumber(L, 3));
|
||||
float p2y = Physics::scaleDown((float)luaL_checknumber(L, 4));
|
||||
float maxFraction = (float)luaL_checknumber(L, 5);
|
||||
int childIndex = (int)luaL_optint(L, 6, 1) - 1; // Convert from 1-based index
|
||||
b2RayCastInput input;
|
||||
input.p1.Set(p1x, p1y);
|
||||
input.p2.Set(p2x, p2y);
|
||||
input.maxFraction = maxFraction;
|
||||
b2RayCastOutput output;
|
||||
if (!fixture->RayCast(&output, input, childIndex))
|
||||
return 0; // Nothing hit.
|
||||
lua_pushnumber(L, output.normal.x);
|
||||
lua_pushnumber(L, output.normal.y);
|
||||
lua_pushnumber(L, output.fraction);
|
||||
return 3;
|
||||
}
|
||||
|
||||
int Fixture::getBoundingBox(lua_State *L) const
|
||||
{
|
||||
int childIndex = (int)luaL_optint(L, 1, 1) - 1; // Convert from 1-based index
|
||||
b2AABB box = fixture->GetAABB(childIndex);
|
||||
box = Physics::scaleUp(box);
|
||||
lua_pushnumber(L, box.lowerBound.x);
|
||||
lua_pushnumber(L, box.lowerBound.y);
|
||||
lua_pushnumber(L, box.upperBound.x);
|
||||
lua_pushnumber(L, box.upperBound.y);
|
||||
return 4;
|
||||
}
|
||||
|
||||
int Fixture::getMassData(lua_State *L) const
|
||||
{
|
||||
b2MassData data;
|
||||
fixture->GetMassData(&data);
|
||||
b2Vec2 center = Physics::scaleUp(data.center);
|
||||
lua_pushnumber(L, center.x);
|
||||
lua_pushnumber(L, center.y);
|
||||
lua_pushnumber(L, data.mass);
|
||||
lua_pushnumber(L, data.I);
|
||||
return 4;
|
||||
}
|
||||
|
||||
void Fixture::destroy(bool implicit)
|
||||
{
|
||||
if (body->world->world->IsLocked())
|
||||
{
|
||||
// Called during time step. Save reference for destruction afterwards.
|
||||
this->retain();
|
||||
body->world->destructFixtures.push_back(this);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!implicit && fixture != 0)
|
||||
body->body->DestroyFixture(fixture);
|
||||
Memoizer::remove(fixture);
|
||||
fixture = NULL;
|
||||
|
||||
// Box2D fixture destroyed. Release its reference to the love Fixture.
|
||||
this->release();
|
||||
}
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
+225
-225
@@ -1,225 +1,225 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_PHYSICS_BOX2D_FIXTURE_H
|
||||
#define LOVE_PHYSICS_BOX2D_FIXTURE_H
|
||||
|
||||
// LOVE
|
||||
#include "physics/Shape.h"
|
||||
#include "physics/box2d/Body.h"
|
||||
#include "physics/box2d/Shape.h"
|
||||
#include "common/Object.h"
|
||||
#include "common/Reference.h"
|
||||
|
||||
// Box2D
|
||||
#include <Box2D/Box2D.h>
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
/**
|
||||
* This struct is stored in a void pointer
|
||||
* in the Box2D Fixture class. For now, all we
|
||||
* need is a Lua reference to arbitrary data,
|
||||
* but we might need more later.
|
||||
**/
|
||||
struct fixtureudata
|
||||
{
|
||||
// Reference to arbitrary data.
|
||||
Reference *ref;
|
||||
};
|
||||
|
||||
/**
|
||||
* A Fixture is used to attach a shape to a body for collision detection.
|
||||
* A Fixture inherits its transform from its parent. Fixtures hold
|
||||
* additional non-geometric data such as friction, collision filters,
|
||||
* etc.
|
||||
**/
|
||||
class Fixture : public Object
|
||||
{
|
||||
public:
|
||||
friend class Physics;
|
||||
|
||||
/**
|
||||
* Creates a Fixture.
|
||||
**/
|
||||
Fixture(Body *body, Shape *shape, float density);
|
||||
|
||||
/**
|
||||
* Creates a Fixture.
|
||||
**/
|
||||
Fixture(b2Fixture *f);
|
||||
|
||||
virtual ~Fixture();
|
||||
|
||||
/**
|
||||
* Gets the type of the Fixture's Shape. Useful for
|
||||
* debug drawing.
|
||||
**/
|
||||
Shape::Type getType() const;
|
||||
|
||||
/**
|
||||
* Gets the Shape attached to this Fixture.
|
||||
**/
|
||||
Shape *getShape() const;
|
||||
|
||||
/**
|
||||
* Returns true if the fixture is active in a Box2D world.
|
||||
**/
|
||||
bool isValid() const;
|
||||
|
||||
/**
|
||||
* Checks whether this Fixture acts as a sensor.
|
||||
* @return True if sensor, false otherwise.
|
||||
**/
|
||||
bool isSensor() const;
|
||||
|
||||
/**
|
||||
* Set whether this Fixture should be a sensor or not.
|
||||
* @param sensor True if sensor, false if not.
|
||||
**/
|
||||
void setSensor(bool sensor);
|
||||
|
||||
/**
|
||||
* Gets the Body this Fixture is attached to.
|
||||
**/
|
||||
Body *getBody() const;
|
||||
|
||||
/**
|
||||
* Sets the filter data. An integer array is used even though the
|
||||
* first two elements are unsigned shorts. The elements are:
|
||||
* category (16-bits), mask (16-bits) and group (32-bits/int).
|
||||
**/
|
||||
void setFilterData(int *v);
|
||||
|
||||
/**
|
||||
* Gets the filter data. An integer array is used even though the
|
||||
* first two elements are unsigned shorts. The elements are:
|
||||
* category (16-bits), mask (16-bits) and group (32-bits/int).
|
||||
**/
|
||||
void getFilterData(int *v);
|
||||
|
||||
/**
|
||||
* This function stores an in-C reference to
|
||||
* arbitrary Lua data in the Box2D Fixture object.
|
||||
*
|
||||
* The data set here will be passed to the collision
|
||||
* handler when collisions occur.
|
||||
**/
|
||||
int setUserData(lua_State *L);
|
||||
|
||||
/**
|
||||
* Gets the data set with setData. If no
|
||||
* data is set, nil is returned.
|
||||
**/
|
||||
int getUserData(lua_State *L);
|
||||
|
||||
/**
|
||||
* Sets the friction of the Fixture.
|
||||
* @param friction The new friction.
|
||||
**/
|
||||
void setFriction(float friction);
|
||||
|
||||
/**
|
||||
* Sets the restitution for the Fixture.
|
||||
* @param restitution The restitution.
|
||||
**/
|
||||
void setRestitution(float restitution);
|
||||
|
||||
/**
|
||||
* Sets the density of the Fixture.
|
||||
* @param density The density of the Fixture.
|
||||
**/
|
||||
void setDensity(float density);
|
||||
|
||||
/**
|
||||
* Gets the friction of the Fixture.
|
||||
* @returns The friction.
|
||||
**/
|
||||
float getFriction() const;
|
||||
|
||||
/**
|
||||
* Gets the restitution of the Fixture.
|
||||
* @return The restitution of the Fixture.
|
||||
**/
|
||||
float getRestitution() const;
|
||||
|
||||
/**
|
||||
* Gets the density of the Fixture.
|
||||
* @return The density.
|
||||
**/
|
||||
float getDensity() const;
|
||||
|
||||
/**
|
||||
* Checks if a point is inside the Fixture.
|
||||
* @param x The x-component of the point.
|
||||
* @param y The y-component of the point.
|
||||
**/
|
||||
bool testPoint(float x, float y) const;
|
||||
|
||||
/**
|
||||
* Cast a ray against this Fixture.
|
||||
**/
|
||||
int rayCast(lua_State *L) const;
|
||||
|
||||
void setGroupIndex(int index);
|
||||
int getGroupIndex() const;
|
||||
|
||||
int setCategory(lua_State *L);
|
||||
int setMask(lua_State *L);
|
||||
int getCategory(lua_State *L);
|
||||
int getMask(lua_State *L);
|
||||
uint16 getBits(lua_State *L);
|
||||
int pushBits(lua_State *L, uint16 bits);
|
||||
|
||||
/**
|
||||
* Gets the bounding box for this Fixture.
|
||||
* The function returns eight values which can be
|
||||
* passed directly to love.graphics.polygon.
|
||||
**/
|
||||
int getBoundingBox(lua_State *L) const;
|
||||
|
||||
/**
|
||||
* Gets the mass data for this Fixture.
|
||||
* This operation may be expensive.
|
||||
**/
|
||||
int getMassData(lua_State *L) const;
|
||||
|
||||
/**
|
||||
* Destroys this fixture.
|
||||
**/
|
||||
void destroy(bool implicit = false);
|
||||
|
||||
protected:
|
||||
|
||||
Body *body;
|
||||
fixtureudata *data;
|
||||
b2Fixture *fixture;
|
||||
};
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_FIXTURE_H
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_PHYSICS_BOX2D_FIXTURE_H
|
||||
#define LOVE_PHYSICS_BOX2D_FIXTURE_H
|
||||
|
||||
// LOVE
|
||||
#include "physics/Shape.h"
|
||||
#include "physics/box2d/Body.h"
|
||||
#include "physics/box2d/Shape.h"
|
||||
#include "common/Object.h"
|
||||
#include "common/Reference.h"
|
||||
|
||||
// Box2D
|
||||
#include <Box2D/Box2D.h>
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
/**
|
||||
* This struct is stored in a void pointer
|
||||
* in the Box2D Fixture class. For now, all we
|
||||
* need is a Lua reference to arbitrary data,
|
||||
* but we might need more later.
|
||||
**/
|
||||
struct fixtureudata
|
||||
{
|
||||
// Reference to arbitrary data.
|
||||
Reference *ref;
|
||||
};
|
||||
|
||||
/**
|
||||
* A Fixture is used to attach a shape to a body for collision detection.
|
||||
* A Fixture inherits its transform from its parent. Fixtures hold
|
||||
* additional non-geometric data such as friction, collision filters,
|
||||
* etc.
|
||||
**/
|
||||
class Fixture : public Object
|
||||
{
|
||||
public:
|
||||
friend class Physics;
|
||||
|
||||
/**
|
||||
* Creates a Fixture.
|
||||
**/
|
||||
Fixture(Body *body, Shape *shape, float density);
|
||||
|
||||
/**
|
||||
* Creates a Fixture.
|
||||
**/
|
||||
Fixture(b2Fixture *f);
|
||||
|
||||
virtual ~Fixture();
|
||||
|
||||
/**
|
||||
* Gets the type of the Fixture's Shape. Useful for
|
||||
* debug drawing.
|
||||
**/
|
||||
Shape::Type getType() const;
|
||||
|
||||
/**
|
||||
* Gets the Shape attached to this Fixture.
|
||||
**/
|
||||
Shape *getShape() const;
|
||||
|
||||
/**
|
||||
* Returns true if the fixture is active in a Box2D world.
|
||||
**/
|
||||
bool isValid() const;
|
||||
|
||||
/**
|
||||
* Checks whether this Fixture acts as a sensor.
|
||||
* @return True if sensor, false otherwise.
|
||||
**/
|
||||
bool isSensor() const;
|
||||
|
||||
/**
|
||||
* Set whether this Fixture should be a sensor or not.
|
||||
* @param sensor True if sensor, false if not.
|
||||
**/
|
||||
void setSensor(bool sensor);
|
||||
|
||||
/**
|
||||
* Gets the Body this Fixture is attached to.
|
||||
**/
|
||||
Body *getBody() const;
|
||||
|
||||
/**
|
||||
* Sets the filter data. An integer array is used even though the
|
||||
* first two elements are unsigned shorts. The elements are:
|
||||
* category (16-bits), mask (16-bits) and group (32-bits/int).
|
||||
**/
|
||||
void setFilterData(int *v);
|
||||
|
||||
/**
|
||||
* Gets the filter data. An integer array is used even though the
|
||||
* first two elements are unsigned shorts. The elements are:
|
||||
* category (16-bits), mask (16-bits) and group (32-bits/int).
|
||||
**/
|
||||
void getFilterData(int *v);
|
||||
|
||||
/**
|
||||
* This function stores an in-C reference to
|
||||
* arbitrary Lua data in the Box2D Fixture object.
|
||||
*
|
||||
* The data set here will be passed to the collision
|
||||
* handler when collisions occur.
|
||||
**/
|
||||
int setUserData(lua_State *L);
|
||||
|
||||
/**
|
||||
* Gets the data set with setData. If no
|
||||
* data is set, nil is returned.
|
||||
**/
|
||||
int getUserData(lua_State *L);
|
||||
|
||||
/**
|
||||
* Sets the friction of the Fixture.
|
||||
* @param friction The new friction.
|
||||
**/
|
||||
void setFriction(float friction);
|
||||
|
||||
/**
|
||||
* Sets the restitution for the Fixture.
|
||||
* @param restitution The restitution.
|
||||
**/
|
||||
void setRestitution(float restitution);
|
||||
|
||||
/**
|
||||
* Sets the density of the Fixture.
|
||||
* @param density The density of the Fixture.
|
||||
**/
|
||||
void setDensity(float density);
|
||||
|
||||
/**
|
||||
* Gets the friction of the Fixture.
|
||||
* @returns The friction.
|
||||
**/
|
||||
float getFriction() const;
|
||||
|
||||
/**
|
||||
* Gets the restitution of the Fixture.
|
||||
* @return The restitution of the Fixture.
|
||||
**/
|
||||
float getRestitution() const;
|
||||
|
||||
/**
|
||||
* Gets the density of the Fixture.
|
||||
* @return The density.
|
||||
**/
|
||||
float getDensity() const;
|
||||
|
||||
/**
|
||||
* Checks if a point is inside the Fixture.
|
||||
* @param x The x-component of the point.
|
||||
* @param y The y-component of the point.
|
||||
**/
|
||||
bool testPoint(float x, float y) const;
|
||||
|
||||
/**
|
||||
* Cast a ray against this Fixture.
|
||||
**/
|
||||
int rayCast(lua_State *L) const;
|
||||
|
||||
void setGroupIndex(int index);
|
||||
int getGroupIndex() const;
|
||||
|
||||
int setCategory(lua_State *L);
|
||||
int setMask(lua_State *L);
|
||||
int getCategory(lua_State *L);
|
||||
int getMask(lua_State *L);
|
||||
uint16 getBits(lua_State *L);
|
||||
int pushBits(lua_State *L, uint16 bits);
|
||||
|
||||
/**
|
||||
* Gets the bounding box for this Fixture.
|
||||
* The function returns eight values which can be
|
||||
* passed directly to love.graphics.polygon.
|
||||
**/
|
||||
int getBoundingBox(lua_State *L) const;
|
||||
|
||||
/**
|
||||
* Gets the mass data for this Fixture.
|
||||
* This operation may be expensive.
|
||||
**/
|
||||
int getMassData(lua_State *L) const;
|
||||
|
||||
/**
|
||||
* Destroys this fixture.
|
||||
**/
|
||||
void destroy(bool implicit = false);
|
||||
|
||||
protected:
|
||||
|
||||
Body *body;
|
||||
fixtureudata *data;
|
||||
b2Fixture *fixture;
|
||||
};
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_FIXTURE_H
|
||||
|
||||
@@ -1,75 +1,75 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#include "FrictionJoint.h"
|
||||
|
||||
#include "common/math.h"
|
||||
|
||||
// Module
|
||||
#include "Body.h"
|
||||
#include "World.h"
|
||||
#include "Physics.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
FrictionJoint::FrictionJoint(Body *body1, Body *body2, float xA, float yA, float xB, float yB, bool collideConnected)
|
||||
: Joint(body1, body2)
|
||||
, joint(NULL)
|
||||
{
|
||||
b2FrictionJointDef def;
|
||||
def.Initialize(body1->body, body2->body, Physics::scaleDown(b2Vec2(xA,yA)));
|
||||
def.localAnchorB = body2->body->GetLocalPoint(Physics::scaleDown(b2Vec2(xB, yB)));
|
||||
def.collideConnected = collideConnected;
|
||||
joint = (b2FrictionJoint *)createJoint(&def);
|
||||
}
|
||||
|
||||
FrictionJoint::~FrictionJoint()
|
||||
{
|
||||
}
|
||||
|
||||
void FrictionJoint::setMaxForce(float force)
|
||||
{
|
||||
joint->SetMaxForce(Physics::scaleDown(force));
|
||||
}
|
||||
|
||||
float FrictionJoint::getMaxForce() const
|
||||
{
|
||||
return Physics::scaleUp(joint->GetMaxForce());
|
||||
}
|
||||
|
||||
void FrictionJoint::setMaxTorque(float torque)
|
||||
{
|
||||
joint->SetMaxTorque(Physics::scaleDown(Physics::scaleDown(torque)));
|
||||
}
|
||||
|
||||
float FrictionJoint::getMaxTorque() const
|
||||
{
|
||||
return Physics::scaleUp(Physics::scaleUp(joint->GetMaxTorque()));
|
||||
}
|
||||
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#include "FrictionJoint.h"
|
||||
|
||||
#include "common/math.h"
|
||||
|
||||
// Module
|
||||
#include "Body.h"
|
||||
#include "World.h"
|
||||
#include "Physics.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
FrictionJoint::FrictionJoint(Body *body1, Body *body2, float xA, float yA, float xB, float yB, bool collideConnected)
|
||||
: Joint(body1, body2)
|
||||
, joint(NULL)
|
||||
{
|
||||
b2FrictionJointDef def;
|
||||
def.Initialize(body1->body, body2->body, Physics::scaleDown(b2Vec2(xA,yA)));
|
||||
def.localAnchorB = body2->body->GetLocalPoint(Physics::scaleDown(b2Vec2(xB, yB)));
|
||||
def.collideConnected = collideConnected;
|
||||
joint = (b2FrictionJoint *)createJoint(&def);
|
||||
}
|
||||
|
||||
FrictionJoint::~FrictionJoint()
|
||||
{
|
||||
}
|
||||
|
||||
void FrictionJoint::setMaxForce(float force)
|
||||
{
|
||||
joint->SetMaxForce(Physics::scaleDown(force));
|
||||
}
|
||||
|
||||
float FrictionJoint::getMaxForce() const
|
||||
{
|
||||
return Physics::scaleUp(joint->GetMaxForce());
|
||||
}
|
||||
|
||||
void FrictionJoint::setMaxTorque(float torque)
|
||||
{
|
||||
joint->SetMaxTorque(Physics::scaleDown(Physics::scaleDown(torque)));
|
||||
}
|
||||
|
||||
float FrictionJoint::getMaxTorque() const
|
||||
{
|
||||
return Physics::scaleUp(Physics::scaleUp(joint->GetMaxTorque()));
|
||||
}
|
||||
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
@@ -1,78 +1,78 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_PHYSICS_BOX2D_FRICTION_JOINT_H
|
||||
#define LOVE_PHYSICS_BOX2D_FRICTION_JOINT_H
|
||||
|
||||
// Module
|
||||
#include "Joint.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
/**
|
||||
* A FrictionJoint applies friction to a body.
|
||||
**/
|
||||
class FrictionJoint : public Joint
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Creates a new FrictionJoint connecting body1 and body2.
|
||||
**/
|
||||
FrictionJoint(Body *body1, Body *body2, float xA, float yA, float xB, float yB, bool collideConnected);
|
||||
|
||||
virtual ~FrictionJoint();
|
||||
|
||||
/**
|
||||
* Sets the maximum friction force in Newtons.
|
||||
**/
|
||||
void setMaxForce(float force);
|
||||
|
||||
/**
|
||||
* Gets the maximum friction force in Newtons.
|
||||
**/
|
||||
float getMaxForce() const;
|
||||
|
||||
/**
|
||||
* Sets the maximum friction torque in Newton-meters.
|
||||
**/
|
||||
void setMaxTorque(float torque);
|
||||
|
||||
/**
|
||||
* Gets the maximum friction torque in Newton-meters.
|
||||
**/
|
||||
float getMaxTorque() const;
|
||||
|
||||
private:
|
||||
|
||||
// The Box2D friction joint object.
|
||||
b2FrictionJoint *joint;
|
||||
};
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_FRICTION_JOINT_H
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_PHYSICS_BOX2D_FRICTION_JOINT_H
|
||||
#define LOVE_PHYSICS_BOX2D_FRICTION_JOINT_H
|
||||
|
||||
// Module
|
||||
#include "Joint.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
/**
|
||||
* A FrictionJoint applies friction to a body.
|
||||
**/
|
||||
class FrictionJoint : public Joint
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Creates a new FrictionJoint connecting body1 and body2.
|
||||
**/
|
||||
FrictionJoint(Body *body1, Body *body2, float xA, float yA, float xB, float yB, bool collideConnected);
|
||||
|
||||
virtual ~FrictionJoint();
|
||||
|
||||
/**
|
||||
* Sets the maximum friction force in Newtons.
|
||||
**/
|
||||
void setMaxForce(float force);
|
||||
|
||||
/**
|
||||
* Gets the maximum friction force in Newtons.
|
||||
**/
|
||||
float getMaxForce() const;
|
||||
|
||||
/**
|
||||
* Sets the maximum friction torque in Newton-meters.
|
||||
**/
|
||||
void setMaxTorque(float torque);
|
||||
|
||||
/**
|
||||
* Gets the maximum friction torque in Newton-meters.
|
||||
**/
|
||||
float getMaxTorque() const;
|
||||
|
||||
private:
|
||||
|
||||
// The Box2D friction joint object.
|
||||
b2FrictionJoint *joint;
|
||||
};
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_FRICTION_JOINT_H
|
||||
|
||||
@@ -1,65 +1,65 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#include "GearJoint.h"
|
||||
|
||||
// Module
|
||||
#include "Body.h"
|
||||
#include "World.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
GearJoint::GearJoint(Joint *joint1, Joint *joint2, float ratio, bool collideConnected)
|
||||
: Joint(joint1->body2, joint2->body2)
|
||||
, joint(NULL)
|
||||
{
|
||||
b2GearJointDef def;
|
||||
def.joint1 = joint1->joint;
|
||||
def.joint2 = joint2->joint;
|
||||
def.bodyA = joint1->body2->body;
|
||||
def.bodyB = joint2->body2->body;
|
||||
def.ratio = ratio;
|
||||
def.collideConnected = collideConnected;
|
||||
|
||||
joint = (b2GearJoint *)createJoint(&def);
|
||||
}
|
||||
|
||||
GearJoint::~GearJoint()
|
||||
{
|
||||
}
|
||||
|
||||
void GearJoint::setRatio(float ratio)
|
||||
{
|
||||
joint->SetRatio(ratio);
|
||||
}
|
||||
|
||||
float GearJoint::getRatio() const
|
||||
{
|
||||
return joint->GetRatio();
|
||||
}
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#include "GearJoint.h"
|
||||
|
||||
// Module
|
||||
#include "Body.h"
|
||||
#include "World.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
GearJoint::GearJoint(Joint *joint1, Joint *joint2, float ratio, bool collideConnected)
|
||||
: Joint(joint1->body2, joint2->body2)
|
||||
, joint(NULL)
|
||||
{
|
||||
b2GearJointDef def;
|
||||
def.joint1 = joint1->joint;
|
||||
def.joint2 = joint2->joint;
|
||||
def.bodyA = joint1->body2->body;
|
||||
def.bodyB = joint2->body2->body;
|
||||
def.ratio = ratio;
|
||||
def.collideConnected = collideConnected;
|
||||
|
||||
joint = (b2GearJoint *)createJoint(&def);
|
||||
}
|
||||
|
||||
GearJoint::~GearJoint()
|
||||
{
|
||||
}
|
||||
|
||||
void GearJoint::setRatio(float ratio)
|
||||
{
|
||||
joint->SetRatio(ratio);
|
||||
}
|
||||
|
||||
float GearJoint::getRatio() const
|
||||
{
|
||||
return joint->GetRatio();
|
||||
}
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
@@ -1,76 +1,76 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_PHYSICS_BOX2D_GEAR_JOINT_H
|
||||
#define LOVE_PHYSICS_BOX2D_GEAR_JOINT_H
|
||||
|
||||
// Module
|
||||
#include "Joint.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
/**
|
||||
* A gear joint is used to connect two joints together. Either joint
|
||||
* can be a revolute or prismatic joint. You specify a gear ratio
|
||||
* to bind the motions together:
|
||||
* coordinate1 + ratio * coordinate2 = constant
|
||||
*
|
||||
* The ratio can be negative or positive. If one joint is a revolute joint
|
||||
* and the other joint is a prismatic joint, then the ratio will have units
|
||||
* of length or units of 1/length.
|
||||
* Warning: The revolute and prismatic joints must be attached to
|
||||
* fixed bodies (which must be body1 on those joints).
|
||||
**/
|
||||
class GearJoint : public Joint
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Creates a GearJoint connecting joint1 to joint2.
|
||||
**/
|
||||
GearJoint(Joint *joint1, Joint *joint2, float ratio, bool collideConnected);
|
||||
|
||||
virtual ~GearJoint();
|
||||
|
||||
/**
|
||||
* Sets the ratio.
|
||||
**/
|
||||
void setRatio(float ratio);
|
||||
|
||||
/**
|
||||
* Gets the ratio.
|
||||
**/
|
||||
float getRatio() const;
|
||||
|
||||
private:
|
||||
// The Box2D GearJoint object.
|
||||
b2GearJoint *joint;
|
||||
};
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_GEAR_JOINT_H
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_PHYSICS_BOX2D_GEAR_JOINT_H
|
||||
#define LOVE_PHYSICS_BOX2D_GEAR_JOINT_H
|
||||
|
||||
// Module
|
||||
#include "Joint.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
/**
|
||||
* A gear joint is used to connect two joints together. Either joint
|
||||
* can be a revolute or prismatic joint. You specify a gear ratio
|
||||
* to bind the motions together:
|
||||
* coordinate1 + ratio * coordinate2 = constant
|
||||
*
|
||||
* The ratio can be negative or positive. If one joint is a revolute joint
|
||||
* and the other joint is a prismatic joint, then the ratio will have units
|
||||
* of length or units of 1/length.
|
||||
* Warning: The revolute and prismatic joints must be attached to
|
||||
* fixed bodies (which must be body1 on those joints).
|
||||
**/
|
||||
class GearJoint : public Joint
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Creates a GearJoint connecting joint1 to joint2.
|
||||
**/
|
||||
GearJoint(Joint *joint1, Joint *joint2, float ratio, bool collideConnected);
|
||||
|
||||
virtual ~GearJoint();
|
||||
|
||||
/**
|
||||
* Sets the ratio.
|
||||
**/
|
||||
void setRatio(float ratio);
|
||||
|
||||
/**
|
||||
* Gets the ratio.
|
||||
**/
|
||||
float getRatio() const;
|
||||
|
||||
private:
|
||||
// The Box2D GearJoint object.
|
||||
b2GearJoint *joint;
|
||||
};
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_GEAR_JOINT_H
|
||||
|
||||
+156
-156
@@ -1,156 +1,156 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#include "Joint.h"
|
||||
|
||||
// STD
|
||||
#include <bitset>
|
||||
|
||||
// LOVE
|
||||
#include "common/Memoizer.h"
|
||||
|
||||
// Module
|
||||
#include "Body.h"
|
||||
#include "World.h"
|
||||
#include "Physics.h"
|
||||
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
Joint::Joint(Body *body1)
|
||||
: body1(body1)
|
||||
, body2(0)
|
||||
, world(body1->world)
|
||||
{
|
||||
}
|
||||
|
||||
Joint::Joint(Body *body1, Body *body2)
|
||||
: body1(body1)
|
||||
, body2(body2)
|
||||
, world(body1->world)
|
||||
{
|
||||
}
|
||||
|
||||
Joint::~Joint()
|
||||
{
|
||||
}
|
||||
|
||||
Joint::Type Joint::getType() const
|
||||
{
|
||||
switch (joint->GetType())
|
||||
{
|
||||
case e_revoluteJoint:
|
||||
return JOINT_REVOLUTE;
|
||||
case e_prismaticJoint:
|
||||
return JOINT_PRISMATIC;
|
||||
case e_distanceJoint:
|
||||
return JOINT_DISTANCE;
|
||||
case e_pulleyJoint:
|
||||
return JOINT_PULLEY;
|
||||
case e_mouseJoint:
|
||||
return JOINT_MOUSE;
|
||||
case e_gearJoint:
|
||||
return JOINT_GEAR;
|
||||
case e_frictionJoint:
|
||||
return JOINT_FRICTION;
|
||||
case e_weldJoint:
|
||||
return JOINT_WELD;
|
||||
case e_wheelJoint:
|
||||
return JOINT_WHEEL;
|
||||
case e_ropeJoint:
|
||||
return JOINT_ROPE;
|
||||
default:
|
||||
return JOINT_INVALID;
|
||||
}
|
||||
}
|
||||
|
||||
bool Joint::isValid() const
|
||||
{
|
||||
return joint != 0;
|
||||
}
|
||||
|
||||
int Joint::getAnchors(lua_State *L)
|
||||
{
|
||||
lua_pushnumber(L, Physics::scaleUp(joint->GetAnchorA().x));
|
||||
lua_pushnumber(L, Physics::scaleUp(joint->GetAnchorA().y));
|
||||
lua_pushnumber(L, Physics::scaleUp(joint->GetAnchorB().x));
|
||||
lua_pushnumber(L, Physics::scaleUp(joint->GetAnchorB().y));
|
||||
return 4;
|
||||
}
|
||||
|
||||
int Joint::getReactionForce(lua_State *L)
|
||||
{
|
||||
float dt = (float)luaL_checknumber(L, 1);
|
||||
b2Vec2 v = Physics::scaleUp(joint->GetReactionForce(dt));
|
||||
lua_pushnumber(L, v.x);
|
||||
lua_pushnumber(L, v.y);
|
||||
return 2;
|
||||
}
|
||||
|
||||
float Joint::getReactionTorque(float dt)
|
||||
{
|
||||
return Physics::scaleUp(Physics::scaleUp(joint->GetReactionTorque(dt)));
|
||||
}
|
||||
|
||||
b2Joint *Joint::createJoint(b2JointDef *def)
|
||||
{
|
||||
joint = world->world->CreateJoint(def);
|
||||
Memoizer::add(joint, this);
|
||||
// Box2D joint has a reference to this love Joint.
|
||||
this->retain();
|
||||
return joint;
|
||||
}
|
||||
|
||||
void Joint::destroyJoint(bool implicit)
|
||||
{
|
||||
if (world->world->IsLocked())
|
||||
{
|
||||
// Called during time step. Save reference for destruction afterwards.
|
||||
this->retain();
|
||||
world->destructJoints.push_back(this);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!implicit && joint != 0)
|
||||
world->world->DestroyJoint(joint);
|
||||
Memoizer::remove(joint);
|
||||
joint = NULL;
|
||||
// Release the reference of the Box2D joint.
|
||||
this->release();
|
||||
}
|
||||
|
||||
bool Joint::isActive() const
|
||||
{
|
||||
return joint->IsActive();
|
||||
}
|
||||
|
||||
bool Joint::getCollideConnected() const
|
||||
{
|
||||
return joint->GetCollideConnected();
|
||||
}
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#include "Joint.h"
|
||||
|
||||
// STD
|
||||
#include <bitset>
|
||||
|
||||
// LOVE
|
||||
#include "common/Memoizer.h"
|
||||
|
||||
// Module
|
||||
#include "Body.h"
|
||||
#include "World.h"
|
||||
#include "Physics.h"
|
||||
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
Joint::Joint(Body *body1)
|
||||
: body1(body1)
|
||||
, body2(0)
|
||||
, world(body1->world)
|
||||
{
|
||||
}
|
||||
|
||||
Joint::Joint(Body *body1, Body *body2)
|
||||
: body1(body1)
|
||||
, body2(body2)
|
||||
, world(body1->world)
|
||||
{
|
||||
}
|
||||
|
||||
Joint::~Joint()
|
||||
{
|
||||
}
|
||||
|
||||
Joint::Type Joint::getType() const
|
||||
{
|
||||
switch (joint->GetType())
|
||||
{
|
||||
case e_revoluteJoint:
|
||||
return JOINT_REVOLUTE;
|
||||
case e_prismaticJoint:
|
||||
return JOINT_PRISMATIC;
|
||||
case e_distanceJoint:
|
||||
return JOINT_DISTANCE;
|
||||
case e_pulleyJoint:
|
||||
return JOINT_PULLEY;
|
||||
case e_mouseJoint:
|
||||
return JOINT_MOUSE;
|
||||
case e_gearJoint:
|
||||
return JOINT_GEAR;
|
||||
case e_frictionJoint:
|
||||
return JOINT_FRICTION;
|
||||
case e_weldJoint:
|
||||
return JOINT_WELD;
|
||||
case e_wheelJoint:
|
||||
return JOINT_WHEEL;
|
||||
case e_ropeJoint:
|
||||
return JOINT_ROPE;
|
||||
default:
|
||||
return JOINT_INVALID;
|
||||
}
|
||||
}
|
||||
|
||||
bool Joint::isValid() const
|
||||
{
|
||||
return joint != 0;
|
||||
}
|
||||
|
||||
int Joint::getAnchors(lua_State *L)
|
||||
{
|
||||
lua_pushnumber(L, Physics::scaleUp(joint->GetAnchorA().x));
|
||||
lua_pushnumber(L, Physics::scaleUp(joint->GetAnchorA().y));
|
||||
lua_pushnumber(L, Physics::scaleUp(joint->GetAnchorB().x));
|
||||
lua_pushnumber(L, Physics::scaleUp(joint->GetAnchorB().y));
|
||||
return 4;
|
||||
}
|
||||
|
||||
int Joint::getReactionForce(lua_State *L)
|
||||
{
|
||||
float dt = (float)luaL_checknumber(L, 1);
|
||||
b2Vec2 v = Physics::scaleUp(joint->GetReactionForce(dt));
|
||||
lua_pushnumber(L, v.x);
|
||||
lua_pushnumber(L, v.y);
|
||||
return 2;
|
||||
}
|
||||
|
||||
float Joint::getReactionTorque(float dt)
|
||||
{
|
||||
return Physics::scaleUp(Physics::scaleUp(joint->GetReactionTorque(dt)));
|
||||
}
|
||||
|
||||
b2Joint *Joint::createJoint(b2JointDef *def)
|
||||
{
|
||||
joint = world->world->CreateJoint(def);
|
||||
Memoizer::add(joint, this);
|
||||
// Box2D joint has a reference to this love Joint.
|
||||
this->retain();
|
||||
return joint;
|
||||
}
|
||||
|
||||
void Joint::destroyJoint(bool implicit)
|
||||
{
|
||||
if (world->world->IsLocked())
|
||||
{
|
||||
// Called during time step. Save reference for destruction afterwards.
|
||||
this->retain();
|
||||
world->destructJoints.push_back(this);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!implicit && joint != 0)
|
||||
world->world->DestroyJoint(joint);
|
||||
Memoizer::remove(joint);
|
||||
joint = NULL;
|
||||
// Release the reference of the Box2D joint.
|
||||
this->release();
|
||||
}
|
||||
|
||||
bool Joint::isActive() const
|
||||
{
|
||||
return joint->IsActive();
|
||||
}
|
||||
|
||||
bool Joint::getCollideConnected() const
|
||||
{
|
||||
return joint->GetCollideConnected();
|
||||
}
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
+137
-137
@@ -1,137 +1,137 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_PHYSICS_BOX2D_JOINT_H
|
||||
#define LOVE_PHYSICS_BOX2D_JOINT_H
|
||||
|
||||
// LOVE
|
||||
#include "common/runtime.h"
|
||||
#include "physics/Joint.h"
|
||||
|
||||
// Box2D
|
||||
#include <Box2D/Box2D.h>
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
// Forward declarations.
|
||||
class Body;
|
||||
class World;
|
||||
|
||||
/**
|
||||
* A Joint acts as positioning constraints on Bodies.
|
||||
* A Joint can be used to prevent Bodies from going to
|
||||
* far apart, or coming too close together.
|
||||
**/
|
||||
class Joint : public love::physics::Joint
|
||||
{
|
||||
public:
|
||||
friend class GearJoint;
|
||||
|
||||
/**
|
||||
* This constructor will connect one end of the joint to body1,
|
||||
* and the other one to the default ground body.
|
||||
*
|
||||
* This constructor is mainly used by MouseJoint.
|
||||
**/
|
||||
Joint(Body *body1);
|
||||
|
||||
/**
|
||||
* Create a joint between body1 and body2.
|
||||
**/
|
||||
Joint(Body *body1, Body *body2);
|
||||
|
||||
virtual ~Joint();
|
||||
|
||||
/**
|
||||
* Returns true if the joint is active in a Box2D world.
|
||||
**/
|
||||
bool isValid() const;
|
||||
|
||||
|
||||
/**
|
||||
* Gets the type of joint.
|
||||
**/
|
||||
Type getType() const;
|
||||
|
||||
/**
|
||||
* Gets the anchor positions of the Joint in world
|
||||
* coordinates. This is useful for debugdrawing the joint.
|
||||
**/
|
||||
int getAnchors(lua_State *L);
|
||||
|
||||
/**
|
||||
* Gets the reaction force on body2 at the joint anchor.
|
||||
**/
|
||||
int getReactionForce(lua_State *L);
|
||||
|
||||
/**
|
||||
* Gets the reaction torque on body2.
|
||||
**/
|
||||
float getReactionTorque(float dt);
|
||||
|
||||
bool isActive() const;
|
||||
|
||||
bool getCollideConnected() const;
|
||||
|
||||
/**
|
||||
* Joints require pointers to a Box2D joint objects at
|
||||
* different polymorphic levels, which is why these function
|
||||
* were created.
|
||||
**/
|
||||
|
||||
/**
|
||||
* Destroys the joint. This function was created just to
|
||||
* get some cinsistency.
|
||||
**/
|
||||
void destroyJoint(bool implicit = false);
|
||||
|
||||
protected:
|
||||
|
||||
/**
|
||||
* Creates a Joint, and ensures that the parent class
|
||||
* gets a copy of the pointer.
|
||||
**/
|
||||
b2Joint *createJoint(b2JointDef *def);
|
||||
|
||||
World *world;
|
||||
|
||||
private:
|
||||
|
||||
// A Joint must be destroyed *before* the bodies it acts upon,
|
||||
// and the world they reside in. We therefore need refs
|
||||
// parents and associations to prevent wrong destruction order.
|
||||
Body *body1, * body2;
|
||||
|
||||
|
||||
// The Box2D joint object.
|
||||
b2Joint *joint;
|
||||
|
||||
};
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_JOINT_H
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_PHYSICS_BOX2D_JOINT_H
|
||||
#define LOVE_PHYSICS_BOX2D_JOINT_H
|
||||
|
||||
// LOVE
|
||||
#include "common/runtime.h"
|
||||
#include "physics/Joint.h"
|
||||
|
||||
// Box2D
|
||||
#include <Box2D/Box2D.h>
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
// Forward declarations.
|
||||
class Body;
|
||||
class World;
|
||||
|
||||
/**
|
||||
* A Joint acts as positioning constraints on Bodies.
|
||||
* A Joint can be used to prevent Bodies from going to
|
||||
* far apart, or coming too close together.
|
||||
**/
|
||||
class Joint : public love::physics::Joint
|
||||
{
|
||||
public:
|
||||
friend class GearJoint;
|
||||
|
||||
/**
|
||||
* This constructor will connect one end of the joint to body1,
|
||||
* and the other one to the default ground body.
|
||||
*
|
||||
* This constructor is mainly used by MouseJoint.
|
||||
**/
|
||||
Joint(Body *body1);
|
||||
|
||||
/**
|
||||
* Create a joint between body1 and body2.
|
||||
**/
|
||||
Joint(Body *body1, Body *body2);
|
||||
|
||||
virtual ~Joint();
|
||||
|
||||
/**
|
||||
* Returns true if the joint is active in a Box2D world.
|
||||
**/
|
||||
bool isValid() const;
|
||||
|
||||
|
||||
/**
|
||||
* Gets the type of joint.
|
||||
**/
|
||||
Type getType() const;
|
||||
|
||||
/**
|
||||
* Gets the anchor positions of the Joint in world
|
||||
* coordinates. This is useful for debugdrawing the joint.
|
||||
**/
|
||||
int getAnchors(lua_State *L);
|
||||
|
||||
/**
|
||||
* Gets the reaction force on body2 at the joint anchor.
|
||||
**/
|
||||
int getReactionForce(lua_State *L);
|
||||
|
||||
/**
|
||||
* Gets the reaction torque on body2.
|
||||
**/
|
||||
float getReactionTorque(float dt);
|
||||
|
||||
bool isActive() const;
|
||||
|
||||
bool getCollideConnected() const;
|
||||
|
||||
/**
|
||||
* Joints require pointers to a Box2D joint objects at
|
||||
* different polymorphic levels, which is why these function
|
||||
* were created.
|
||||
**/
|
||||
|
||||
/**
|
||||
* Destroys the joint. This function was created just to
|
||||
* get some cinsistency.
|
||||
**/
|
||||
void destroyJoint(bool implicit = false);
|
||||
|
||||
protected:
|
||||
|
||||
/**
|
||||
* Creates a Joint, and ensures that the parent class
|
||||
* gets a copy of the pointer.
|
||||
**/
|
||||
b2Joint *createJoint(b2JointDef *def);
|
||||
|
||||
World *world;
|
||||
|
||||
private:
|
||||
|
||||
// A Joint must be destroyed *before* the bodies it acts upon,
|
||||
// and the world they reside in. We therefore need refs
|
||||
// parents and associations to prevent wrong destruction order.
|
||||
Body *body1, * body2;
|
||||
|
||||
|
||||
// The Box2D joint object.
|
||||
b2Joint *joint;
|
||||
|
||||
};
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_JOINT_H
|
||||
|
||||
@@ -1,96 +1,96 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#include "MouseJoint.h"
|
||||
|
||||
// Module
|
||||
#include "Body.h"
|
||||
#include "World.h"
|
||||
#include "Physics.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
MouseJoint::MouseJoint(Body *body1, float x, float y)
|
||||
: Joint(body1)
|
||||
, joint(NULL)
|
||||
{
|
||||
b2MouseJointDef def;
|
||||
|
||||
def.bodyA = body1->world->getGroundBody();
|
||||
def.bodyB = body1->body;
|
||||
def.maxForce = 1000.0f * body1->body->GetMass();
|
||||
def.target = Physics::scaleDown(b2Vec2(x,y));
|
||||
joint = (b2MouseJoint *)createJoint(&def);
|
||||
}
|
||||
|
||||
MouseJoint::~MouseJoint()
|
||||
{
|
||||
}
|
||||
|
||||
void MouseJoint::setTarget(float x, float y)
|
||||
{
|
||||
joint->SetTarget(Physics::scaleDown(b2Vec2(x, y)));
|
||||
}
|
||||
|
||||
int MouseJoint::getTarget(lua_State *L)
|
||||
{
|
||||
lua_pushnumber(L, Physics::scaleUp(joint->GetTarget().x));
|
||||
lua_pushnumber(L, Physics::scaleUp(joint->GetTarget().y));
|
||||
return 2;
|
||||
}
|
||||
|
||||
void MouseJoint::setMaxForce(float force)
|
||||
{
|
||||
joint->SetMaxForce(Physics::scaleDown(force));
|
||||
}
|
||||
|
||||
float MouseJoint::getMaxForce() const
|
||||
{
|
||||
return Physics::scaleUp(joint->GetMaxForce());
|
||||
}
|
||||
|
||||
void MouseJoint::setFrequency(float hz)
|
||||
{
|
||||
joint->SetFrequency(hz);
|
||||
}
|
||||
|
||||
float MouseJoint::getFrequency() const
|
||||
{
|
||||
return joint->GetFrequency();
|
||||
}
|
||||
|
||||
void MouseJoint::setDampingRatio(float d)
|
||||
{
|
||||
joint->SetDampingRatio(d);
|
||||
}
|
||||
|
||||
float MouseJoint::getDampingRatio() const
|
||||
{
|
||||
return joint->GetDampingRatio();
|
||||
}
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#include "MouseJoint.h"
|
||||
|
||||
// Module
|
||||
#include "Body.h"
|
||||
#include "World.h"
|
||||
#include "Physics.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
MouseJoint::MouseJoint(Body *body1, float x, float y)
|
||||
: Joint(body1)
|
||||
, joint(NULL)
|
||||
{
|
||||
b2MouseJointDef def;
|
||||
|
||||
def.bodyA = body1->world->getGroundBody();
|
||||
def.bodyB = body1->body;
|
||||
def.maxForce = 1000.0f * body1->body->GetMass();
|
||||
def.target = Physics::scaleDown(b2Vec2(x,y));
|
||||
joint = (b2MouseJoint *)createJoint(&def);
|
||||
}
|
||||
|
||||
MouseJoint::~MouseJoint()
|
||||
{
|
||||
}
|
||||
|
||||
void MouseJoint::setTarget(float x, float y)
|
||||
{
|
||||
joint->SetTarget(Physics::scaleDown(b2Vec2(x, y)));
|
||||
}
|
||||
|
||||
int MouseJoint::getTarget(lua_State *L)
|
||||
{
|
||||
lua_pushnumber(L, Physics::scaleUp(joint->GetTarget().x));
|
||||
lua_pushnumber(L, Physics::scaleUp(joint->GetTarget().y));
|
||||
return 2;
|
||||
}
|
||||
|
||||
void MouseJoint::setMaxForce(float force)
|
||||
{
|
||||
joint->SetMaxForce(Physics::scaleDown(force));
|
||||
}
|
||||
|
||||
float MouseJoint::getMaxForce() const
|
||||
{
|
||||
return Physics::scaleUp(joint->GetMaxForce());
|
||||
}
|
||||
|
||||
void MouseJoint::setFrequency(float hz)
|
||||
{
|
||||
joint->SetFrequency(hz);
|
||||
}
|
||||
|
||||
float MouseJoint::getFrequency() const
|
||||
{
|
||||
return joint->GetFrequency();
|
||||
}
|
||||
|
||||
void MouseJoint::setDampingRatio(float d)
|
||||
{
|
||||
joint->SetDampingRatio(d);
|
||||
}
|
||||
|
||||
float MouseJoint::getDampingRatio() const
|
||||
{
|
||||
return joint->GetDampingRatio();
|
||||
}
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
@@ -1,108 +1,108 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_PHYSICS_BOX2D_MOUSE_JOINT_H
|
||||
#define LOVE_PHYSICS_BOX2D_MOUSE_JOINT_H
|
||||
|
||||
// Module
|
||||
#include "Joint.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
/**
|
||||
* The MouseJoint is a joint type that
|
||||
* is suitable for controlling objects with the mouse.
|
||||
*
|
||||
* One end is anchored in the dynamic body, and the other id
|
||||
* anchor to a static ground body. The anchor offset can then be
|
||||
* moved to the current mouse position.
|
||||
**/
|
||||
class MouseJoint : public Joint
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Creates a MouseJoint which connects body1 to the target point.
|
||||
**/
|
||||
MouseJoint(Body *body1, float x, float y);
|
||||
|
||||
virtual ~MouseJoint();
|
||||
|
||||
/**
|
||||
* Sets the target of anchor2. (You usually want
|
||||
* to set this to the current mouse.)
|
||||
**/
|
||||
void setTarget(float x, float y);
|
||||
|
||||
/**
|
||||
* Gets the current anchor2 target.
|
||||
**/
|
||||
int getTarget(lua_State *L);
|
||||
|
||||
/**
|
||||
* Sets the maximum constraint force that can be exerted
|
||||
* to move the candidate body.
|
||||
**/
|
||||
void setMaxForce(float force);
|
||||
|
||||
/**
|
||||
* Gets the maximum constraint force that can be exerted
|
||||
* to move the candidate body.
|
||||
**/
|
||||
float getMaxForce() const;
|
||||
|
||||
/**
|
||||
* Sets the response speed.
|
||||
**/
|
||||
void setFrequency(float hz);
|
||||
|
||||
/**
|
||||
* Gets the response speed.
|
||||
**/
|
||||
float getFrequency() const;
|
||||
|
||||
/**
|
||||
* Sets the damping ratio.
|
||||
* 0 = no damping, 1 = critical damping.
|
||||
**/
|
||||
void setDampingRatio(float d);
|
||||
|
||||
/**
|
||||
* Gets the damping ratio.
|
||||
* 0 = no damping, 1 = critical damping.
|
||||
**/
|
||||
float getDampingRatio() const;
|
||||
|
||||
private:
|
||||
// The Box2D MouseJoint object.
|
||||
b2MouseJoint *joint;
|
||||
};
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_MOUSE_JOINT_H
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_PHYSICS_BOX2D_MOUSE_JOINT_H
|
||||
#define LOVE_PHYSICS_BOX2D_MOUSE_JOINT_H
|
||||
|
||||
// Module
|
||||
#include "Joint.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
/**
|
||||
* The MouseJoint is a joint type that
|
||||
* is suitable for controlling objects with the mouse.
|
||||
*
|
||||
* One end is anchored in the dynamic body, and the other id
|
||||
* anchor to a static ground body. The anchor offset can then be
|
||||
* moved to the current mouse position.
|
||||
**/
|
||||
class MouseJoint : public Joint
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Creates a MouseJoint which connects body1 to the target point.
|
||||
**/
|
||||
MouseJoint(Body *body1, float x, float y);
|
||||
|
||||
virtual ~MouseJoint();
|
||||
|
||||
/**
|
||||
* Sets the target of anchor2. (You usually want
|
||||
* to set this to the current mouse.)
|
||||
**/
|
||||
void setTarget(float x, float y);
|
||||
|
||||
/**
|
||||
* Gets the current anchor2 target.
|
||||
**/
|
||||
int getTarget(lua_State *L);
|
||||
|
||||
/**
|
||||
* Sets the maximum constraint force that can be exerted
|
||||
* to move the candidate body.
|
||||
**/
|
||||
void setMaxForce(float force);
|
||||
|
||||
/**
|
||||
* Gets the maximum constraint force that can be exerted
|
||||
* to move the candidate body.
|
||||
**/
|
||||
float getMaxForce() const;
|
||||
|
||||
/**
|
||||
* Sets the response speed.
|
||||
**/
|
||||
void setFrequency(float hz);
|
||||
|
||||
/**
|
||||
* Gets the response speed.
|
||||
**/
|
||||
float getFrequency() const;
|
||||
|
||||
/**
|
||||
* Sets the damping ratio.
|
||||
* 0 = no damping, 1 = critical damping.
|
||||
**/
|
||||
void setDampingRatio(float d);
|
||||
|
||||
/**
|
||||
* Gets the damping ratio.
|
||||
* 0 = no damping, 1 = critical damping.
|
||||
**/
|
||||
float getDampingRatio() const;
|
||||
|
||||
private:
|
||||
// The Box2D MouseJoint object.
|
||||
b2MouseJoint *joint;
|
||||
};
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_MOUSE_JOINT_H
|
||||
|
||||
@@ -1,338 +1,338 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#include "Physics.h"
|
||||
|
||||
// LOVE
|
||||
#include "common/math.h"
|
||||
#include "wrap_Body.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
int Physics::meter = Physics::DEFAULT_METER;
|
||||
|
||||
const char *Physics::getName() const
|
||||
{
|
||||
return "love.physics.box2d";
|
||||
}
|
||||
|
||||
World *Physics::newWorld(float gx, float gy, bool sleep)
|
||||
{
|
||||
return new World(b2Vec2(gx, gy), sleep);
|
||||
}
|
||||
|
||||
Body *Physics::newBody(World *world, float x, float y, Body::Type type)
|
||||
{
|
||||
return new Body(world, b2Vec2(x, y), type);
|
||||
}
|
||||
|
||||
Body *Physics::newBody(World *world, Body::Type type)
|
||||
{
|
||||
return new Body(world, b2Vec2(0, 0), type);
|
||||
}
|
||||
|
||||
CircleShape *Physics::newCircleShape(float radius)
|
||||
{
|
||||
return newCircleShape(0, 0, radius);
|
||||
}
|
||||
|
||||
CircleShape *Physics::newCircleShape(float x, float y, float radius)
|
||||
{
|
||||
b2CircleShape *s = new b2CircleShape();
|
||||
s->m_p = Physics::scaleDown(b2Vec2(x, y));
|
||||
s->m_radius = Physics::scaleDown(radius);
|
||||
return new CircleShape(s);
|
||||
}
|
||||
|
||||
PolygonShape *Physics::newRectangleShape(float w, float h)
|
||||
{
|
||||
return newRectangleShape(0, 0, w, h, 0);
|
||||
}
|
||||
|
||||
PolygonShape *Physics::newRectangleShape(float x, float y, float w, float h)
|
||||
{
|
||||
return newRectangleShape(x, y, w, h, 0);
|
||||
}
|
||||
|
||||
PolygonShape *Physics::newRectangleShape(float x, float y, float w, float h, float angle)
|
||||
{
|
||||
b2PolygonShape *s = new b2PolygonShape();
|
||||
s->SetAsBox(Physics::scaleDown(w/2.0f), Physics::scaleDown(h/2.0f), Physics::scaleDown(b2Vec2(x, y)), angle);
|
||||
return new PolygonShape(s);
|
||||
}
|
||||
|
||||
EdgeShape *Physics::newEdgeShape(float x1, float y1, float x2, float y2)
|
||||
{
|
||||
b2EdgeShape *s = new b2EdgeShape();
|
||||
s->Set(Physics::scaleDown(b2Vec2(x1, y1)), Physics::scaleDown(b2Vec2(x2, y2)));
|
||||
return new EdgeShape(s);
|
||||
}
|
||||
|
||||
int Physics::newPolygonShape(lua_State *L)
|
||||
{
|
||||
int argc = lua_gettop(L);
|
||||
if (argc%2 != 0)
|
||||
return luaL_error(L, "Number of vertices must be a multiple of two.");
|
||||
// 3 to 8 (b2_maxPolygonVertices) vertices
|
||||
int vcount = argc / 2;
|
||||
if (vcount < 3)
|
||||
luaL_error(L, "Expected a minimum of 3 vertices, got %d.", vcount);
|
||||
else if (vcount > b2_maxPolygonVertices)
|
||||
luaL_error(L, "Expected a maximum of %d vertices, got %d.", b2_maxPolygonVertices, vcount);
|
||||
|
||||
b2PolygonShape *s = new b2PolygonShape();
|
||||
|
||||
bool reverse = false;
|
||||
b2Vec2 edge1;
|
||||
b2Vec2 vecs[b2_maxPolygonVertices];
|
||||
|
||||
for (int i = 0; i < vcount; i++)
|
||||
{
|
||||
float x = (float)luaL_checknumber(L, -2);
|
||||
float y = (float)luaL_checknumber(L, -1);
|
||||
vecs[i] = Physics::scaleDown(b2Vec2(x, y));
|
||||
lua_pop(L, 2);
|
||||
|
||||
if (!reverse)
|
||||
{
|
||||
// Detect clockwise winding.
|
||||
if (i == 1)
|
||||
{
|
||||
edge1 = vecs[1] - vecs[0];
|
||||
}
|
||||
else if (i == vcount - 1)
|
||||
{
|
||||
b2Vec2 edge2 = vecs[i] - vecs[i-1];
|
||||
// Also check the edge from the last and first point.
|
||||
b2Vec2 edge3 = vecs[0] - vecs[i];
|
||||
if (b2Cross(edge1, edge2) < 0.0f || b2Cross(edge2, edge3) < 0.0f)
|
||||
reverse = true;
|
||||
}
|
||||
else if (i > 1)
|
||||
{
|
||||
b2Vec2 edge2 = vecs[i] - vecs[i-1];
|
||||
if (b2Cross(edge1, edge2) < 0.0f)
|
||||
reverse = true;
|
||||
edge1 = edge2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (reverse)
|
||||
{
|
||||
for (int i = 0, j = vcount-1; i < j; ++i, --j)
|
||||
{
|
||||
b2Vec2 swap = vecs[i];
|
||||
vecs[i] = vecs[j];
|
||||
vecs[j] = swap;
|
||||
}
|
||||
}
|
||||
|
||||
s->Set(vecs, vcount);
|
||||
PolygonShape *p = new PolygonShape(s);
|
||||
|
||||
luax_newtype(L, "PolygonShape", PHYSICS_POLYGON_SHAPE_T, (void *)p);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int Physics::newChainShape(lua_State *L)
|
||||
{
|
||||
int argc = lua_gettop(L)-1; // first argument is looping
|
||||
int vcount = (int)argc/2;
|
||||
|
||||
b2ChainShape *s = new b2ChainShape();
|
||||
|
||||
bool loop = luax_toboolean(L, 1);
|
||||
|
||||
b2Vec2 *vecs = new b2Vec2[vcount];
|
||||
|
||||
for (int i = 0; i<vcount; i++)
|
||||
{
|
||||
float x = (float)lua_tonumber(L, -2);
|
||||
float y = (float)lua_tonumber(L, -1);
|
||||
vecs[i].Set(x, y);
|
||||
vecs[i] = Physics::scaleDown(vecs[i]);
|
||||
lua_pop(L, 2);
|
||||
}
|
||||
|
||||
if (loop)
|
||||
s->CreateLoop(vecs, vcount);
|
||||
else
|
||||
s->CreateChain(vecs, vcount);
|
||||
|
||||
ChainShape *c = new ChainShape(s);
|
||||
delete[] vecs;
|
||||
|
||||
luax_newtype(L, "ChainShape", PHYSICS_CHAIN_SHAPE_T, (void *)c);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
DistanceJoint *Physics::newDistanceJoint(Body *body1, Body *body2, float x1, float y1, float x2, float y2, bool collideConnected)
|
||||
{
|
||||
return new DistanceJoint(body1, body2, x1, y1, x2, y2, collideConnected);
|
||||
}
|
||||
|
||||
MouseJoint *Physics::newMouseJoint(Body *body, float x, float y)
|
||||
{
|
||||
return new MouseJoint(body, x, y);
|
||||
}
|
||||
|
||||
RevoluteJoint *Physics::newRevoluteJoint(Body *body1, Body *body2, float x, float y, bool collideConnected)
|
||||
{
|
||||
return new RevoluteJoint(body1, body2, x, y, collideConnected);
|
||||
}
|
||||
|
||||
PrismaticJoint *Physics::newPrismaticJoint(Body *body1, Body *body2, float xA, float yA, float xB, float yB, float ax, float ay, bool collideConnected)
|
||||
{
|
||||
return new PrismaticJoint(body1, body2, xA, yA, xB, yB, ax, ay, collideConnected);
|
||||
}
|
||||
|
||||
PulleyJoint *Physics::newPulleyJoint(Body *body1, Body *body2, b2Vec2 groundAnchor1, b2Vec2 groundAnchor2, b2Vec2 anchor1, b2Vec2 anchor2, float ratio, bool collideConnected)
|
||||
{
|
||||
return new PulleyJoint(body1, body2, groundAnchor1, groundAnchor2, anchor1, anchor2, ratio, collideConnected);
|
||||
}
|
||||
|
||||
GearJoint *Physics::newGearJoint(Joint *joint1, Joint *joint2, float ratio, bool collideConnected)
|
||||
{
|
||||
return new GearJoint(joint1, joint2, ratio, collideConnected);
|
||||
}
|
||||
|
||||
FrictionJoint *Physics::newFrictionJoint(Body *body1, Body *body2, float xA, float yA, float xB, float yB, bool collideConnected)
|
||||
{
|
||||
return new FrictionJoint(body1, body2, xA, yA, xB, yB, collideConnected);
|
||||
}
|
||||
|
||||
WeldJoint *Physics::newWeldJoint(Body *body1, Body *body2, float xA, float yA, float xB, float yB, bool collideConnected)
|
||||
{
|
||||
return new WeldJoint(body1, body2, xA, yA, xB, yB, collideConnected);
|
||||
}
|
||||
|
||||
WheelJoint *Physics::newWheelJoint(Body *body1, Body *body2, float xA, float yA, float xB, float yB, float ax, float ay, bool collideConnected)
|
||||
{
|
||||
return new WheelJoint(body1, body2, xA, yA, xB, yB, ax, ay, collideConnected);
|
||||
}
|
||||
|
||||
RopeJoint *Physics::newRopeJoint(Body *body1, Body *body2, float x1, float y1, float x2, float y2, float maxLength, bool collideConnected)
|
||||
{
|
||||
return new RopeJoint(body1, body2, x1, y1, x2, y2, maxLength, collideConnected);
|
||||
}
|
||||
|
||||
Fixture *Physics::newFixture(Body *body, Shape *shape, float density)
|
||||
{
|
||||
return new Fixture(body, shape, density);
|
||||
}
|
||||
|
||||
int Physics::getDistance(lua_State *L)
|
||||
{
|
||||
Fixture *fixtureA = luax_checktype<Fixture>(L, 1, "Fixture", PHYSICS_FIXTURE_T);
|
||||
Fixture *fixtureB = luax_checktype<Fixture>(L, 2, "Fixture", PHYSICS_FIXTURE_T);
|
||||
b2DistanceInput i;
|
||||
b2DistanceProxy pA;
|
||||
pA.Set(fixtureA->fixture->GetShape(), 0);
|
||||
b2DistanceProxy pB;
|
||||
pB.Set(fixtureB->fixture->GetShape(), 0);
|
||||
i.proxyA = pA;
|
||||
i.proxyB = pB;
|
||||
i.transformA = fixtureA->fixture->GetBody()->GetTransform();
|
||||
i.transformB = fixtureB->fixture->GetBody()->GetTransform();
|
||||
i.useRadii = true;
|
||||
b2DistanceOutput o;
|
||||
b2SimplexCache c;
|
||||
b2Distance(&o, &c, &i);
|
||||
lua_pushnumber(L, Physics::scaleUp(o.distance));
|
||||
lua_pushnumber(L, Physics::scaleUp(o.pointA.x));
|
||||
lua_pushnumber(L, Physics::scaleUp(o.pointA.y));
|
||||
lua_pushnumber(L, Physics::scaleUp(o.pointB.x));
|
||||
lua_pushnumber(L, Physics::scaleUp(o.pointB.y));
|
||||
return 5;
|
||||
}
|
||||
|
||||
void Physics::setMeter(int meter)
|
||||
{
|
||||
if (meter < 1) throw love::Exception("Physics error: invalid meter");
|
||||
Physics::meter = meter;
|
||||
}
|
||||
|
||||
int Physics::getMeter()
|
||||
{
|
||||
return meter;
|
||||
}
|
||||
|
||||
void Physics::scaleDown(float &x, float &y)
|
||||
{
|
||||
x /= (float)meter;
|
||||
y /= (float)meter;
|
||||
}
|
||||
|
||||
void Physics::scaleUp(float &x, float &y)
|
||||
{
|
||||
x *= (float)meter;
|
||||
y *= (float)meter;
|
||||
}
|
||||
|
||||
float Physics::scaleDown(float f)
|
||||
{
|
||||
return f/(float)meter;
|
||||
}
|
||||
|
||||
float Physics::scaleUp(float f)
|
||||
{
|
||||
return f*(float)meter;
|
||||
}
|
||||
|
||||
b2Vec2 Physics::scaleDown(const b2Vec2 &v)
|
||||
{
|
||||
b2Vec2 t = v;
|
||||
scaleDown(t.x, t.y);
|
||||
return t;
|
||||
}
|
||||
|
||||
b2Vec2 Physics::scaleUp(const b2Vec2 &v)
|
||||
{
|
||||
b2Vec2 t = v;
|
||||
scaleUp(t.x, t.y);
|
||||
return t;
|
||||
}
|
||||
|
||||
b2AABB Physics::scaleDown(const b2AABB &aabb)
|
||||
{
|
||||
b2AABB t;
|
||||
t.lowerBound = scaleDown(aabb.lowerBound);
|
||||
t.upperBound = scaleDown(aabb.upperBound);
|
||||
return t;
|
||||
}
|
||||
|
||||
b2AABB Physics::scaleUp(const b2AABB &aabb)
|
||||
{
|
||||
b2AABB t;
|
||||
t.lowerBound = scaleUp(aabb.lowerBound);
|
||||
t.upperBound = scaleUp(aabb.upperBound);
|
||||
return t;
|
||||
}
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#include "Physics.h"
|
||||
|
||||
// LOVE
|
||||
#include "common/math.h"
|
||||
#include "wrap_Body.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
int Physics::meter = Physics::DEFAULT_METER;
|
||||
|
||||
const char *Physics::getName() const
|
||||
{
|
||||
return "love.physics.box2d";
|
||||
}
|
||||
|
||||
World *Physics::newWorld(float gx, float gy, bool sleep)
|
||||
{
|
||||
return new World(b2Vec2(gx, gy), sleep);
|
||||
}
|
||||
|
||||
Body *Physics::newBody(World *world, float x, float y, Body::Type type)
|
||||
{
|
||||
return new Body(world, b2Vec2(x, y), type);
|
||||
}
|
||||
|
||||
Body *Physics::newBody(World *world, Body::Type type)
|
||||
{
|
||||
return new Body(world, b2Vec2(0, 0), type);
|
||||
}
|
||||
|
||||
CircleShape *Physics::newCircleShape(float radius)
|
||||
{
|
||||
return newCircleShape(0, 0, radius);
|
||||
}
|
||||
|
||||
CircleShape *Physics::newCircleShape(float x, float y, float radius)
|
||||
{
|
||||
b2CircleShape *s = new b2CircleShape();
|
||||
s->m_p = Physics::scaleDown(b2Vec2(x, y));
|
||||
s->m_radius = Physics::scaleDown(radius);
|
||||
return new CircleShape(s);
|
||||
}
|
||||
|
||||
PolygonShape *Physics::newRectangleShape(float w, float h)
|
||||
{
|
||||
return newRectangleShape(0, 0, w, h, 0);
|
||||
}
|
||||
|
||||
PolygonShape *Physics::newRectangleShape(float x, float y, float w, float h)
|
||||
{
|
||||
return newRectangleShape(x, y, w, h, 0);
|
||||
}
|
||||
|
||||
PolygonShape *Physics::newRectangleShape(float x, float y, float w, float h, float angle)
|
||||
{
|
||||
b2PolygonShape *s = new b2PolygonShape();
|
||||
s->SetAsBox(Physics::scaleDown(w/2.0f), Physics::scaleDown(h/2.0f), Physics::scaleDown(b2Vec2(x, y)), angle);
|
||||
return new PolygonShape(s);
|
||||
}
|
||||
|
||||
EdgeShape *Physics::newEdgeShape(float x1, float y1, float x2, float y2)
|
||||
{
|
||||
b2EdgeShape *s = new b2EdgeShape();
|
||||
s->Set(Physics::scaleDown(b2Vec2(x1, y1)), Physics::scaleDown(b2Vec2(x2, y2)));
|
||||
return new EdgeShape(s);
|
||||
}
|
||||
|
||||
int Physics::newPolygonShape(lua_State *L)
|
||||
{
|
||||
int argc = lua_gettop(L);
|
||||
if (argc%2 != 0)
|
||||
return luaL_error(L, "Number of vertices must be a multiple of two.");
|
||||
// 3 to 8 (b2_maxPolygonVertices) vertices
|
||||
int vcount = argc / 2;
|
||||
if (vcount < 3)
|
||||
luaL_error(L, "Expected a minimum of 3 vertices, got %d.", vcount);
|
||||
else if (vcount > b2_maxPolygonVertices)
|
||||
luaL_error(L, "Expected a maximum of %d vertices, got %d.", b2_maxPolygonVertices, vcount);
|
||||
|
||||
b2PolygonShape *s = new b2PolygonShape();
|
||||
|
||||
bool reverse = false;
|
||||
b2Vec2 edge1;
|
||||
b2Vec2 vecs[b2_maxPolygonVertices];
|
||||
|
||||
for (int i = 0; i < vcount; i++)
|
||||
{
|
||||
float x = (float)luaL_checknumber(L, -2);
|
||||
float y = (float)luaL_checknumber(L, -1);
|
||||
vecs[i] = Physics::scaleDown(b2Vec2(x, y));
|
||||
lua_pop(L, 2);
|
||||
|
||||
if (!reverse)
|
||||
{
|
||||
// Detect clockwise winding.
|
||||
if (i == 1)
|
||||
{
|
||||
edge1 = vecs[1] - vecs[0];
|
||||
}
|
||||
else if (i == vcount - 1)
|
||||
{
|
||||
b2Vec2 edge2 = vecs[i] - vecs[i-1];
|
||||
// Also check the edge from the last and first point.
|
||||
b2Vec2 edge3 = vecs[0] - vecs[i];
|
||||
if (b2Cross(edge1, edge2) < 0.0f || b2Cross(edge2, edge3) < 0.0f)
|
||||
reverse = true;
|
||||
}
|
||||
else if (i > 1)
|
||||
{
|
||||
b2Vec2 edge2 = vecs[i] - vecs[i-1];
|
||||
if (b2Cross(edge1, edge2) < 0.0f)
|
||||
reverse = true;
|
||||
edge1 = edge2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (reverse)
|
||||
{
|
||||
for (int i = 0, j = vcount-1; i < j; ++i, --j)
|
||||
{
|
||||
b2Vec2 swap = vecs[i];
|
||||
vecs[i] = vecs[j];
|
||||
vecs[j] = swap;
|
||||
}
|
||||
}
|
||||
|
||||
s->Set(vecs, vcount);
|
||||
PolygonShape *p = new PolygonShape(s);
|
||||
|
||||
luax_newtype(L, "PolygonShape", PHYSICS_POLYGON_SHAPE_T, (void *)p);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int Physics::newChainShape(lua_State *L)
|
||||
{
|
||||
int argc = lua_gettop(L)-1; // first argument is looping
|
||||
int vcount = (int)argc/2;
|
||||
|
||||
b2ChainShape *s = new b2ChainShape();
|
||||
|
||||
bool loop = luax_toboolean(L, 1);
|
||||
|
||||
b2Vec2 *vecs = new b2Vec2[vcount];
|
||||
|
||||
for (int i = 0; i<vcount; i++)
|
||||
{
|
||||
float x = (float)lua_tonumber(L, -2);
|
||||
float y = (float)lua_tonumber(L, -1);
|
||||
vecs[i].Set(x, y);
|
||||
vecs[i] = Physics::scaleDown(vecs[i]);
|
||||
lua_pop(L, 2);
|
||||
}
|
||||
|
||||
if (loop)
|
||||
s->CreateLoop(vecs, vcount);
|
||||
else
|
||||
s->CreateChain(vecs, vcount);
|
||||
|
||||
ChainShape *c = new ChainShape(s);
|
||||
delete[] vecs;
|
||||
|
||||
luax_newtype(L, "ChainShape", PHYSICS_CHAIN_SHAPE_T, (void *)c);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
DistanceJoint *Physics::newDistanceJoint(Body *body1, Body *body2, float x1, float y1, float x2, float y2, bool collideConnected)
|
||||
{
|
||||
return new DistanceJoint(body1, body2, x1, y1, x2, y2, collideConnected);
|
||||
}
|
||||
|
||||
MouseJoint *Physics::newMouseJoint(Body *body, float x, float y)
|
||||
{
|
||||
return new MouseJoint(body, x, y);
|
||||
}
|
||||
|
||||
RevoluteJoint *Physics::newRevoluteJoint(Body *body1, Body *body2, float x, float y, bool collideConnected)
|
||||
{
|
||||
return new RevoluteJoint(body1, body2, x, y, collideConnected);
|
||||
}
|
||||
|
||||
PrismaticJoint *Physics::newPrismaticJoint(Body *body1, Body *body2, float xA, float yA, float xB, float yB, float ax, float ay, bool collideConnected)
|
||||
{
|
||||
return new PrismaticJoint(body1, body2, xA, yA, xB, yB, ax, ay, collideConnected);
|
||||
}
|
||||
|
||||
PulleyJoint *Physics::newPulleyJoint(Body *body1, Body *body2, b2Vec2 groundAnchor1, b2Vec2 groundAnchor2, b2Vec2 anchor1, b2Vec2 anchor2, float ratio, bool collideConnected)
|
||||
{
|
||||
return new PulleyJoint(body1, body2, groundAnchor1, groundAnchor2, anchor1, anchor2, ratio, collideConnected);
|
||||
}
|
||||
|
||||
GearJoint *Physics::newGearJoint(Joint *joint1, Joint *joint2, float ratio, bool collideConnected)
|
||||
{
|
||||
return new GearJoint(joint1, joint2, ratio, collideConnected);
|
||||
}
|
||||
|
||||
FrictionJoint *Physics::newFrictionJoint(Body *body1, Body *body2, float xA, float yA, float xB, float yB, bool collideConnected)
|
||||
{
|
||||
return new FrictionJoint(body1, body2, xA, yA, xB, yB, collideConnected);
|
||||
}
|
||||
|
||||
WeldJoint *Physics::newWeldJoint(Body *body1, Body *body2, float xA, float yA, float xB, float yB, bool collideConnected)
|
||||
{
|
||||
return new WeldJoint(body1, body2, xA, yA, xB, yB, collideConnected);
|
||||
}
|
||||
|
||||
WheelJoint *Physics::newWheelJoint(Body *body1, Body *body2, float xA, float yA, float xB, float yB, float ax, float ay, bool collideConnected)
|
||||
{
|
||||
return new WheelJoint(body1, body2, xA, yA, xB, yB, ax, ay, collideConnected);
|
||||
}
|
||||
|
||||
RopeJoint *Physics::newRopeJoint(Body *body1, Body *body2, float x1, float y1, float x2, float y2, float maxLength, bool collideConnected)
|
||||
{
|
||||
return new RopeJoint(body1, body2, x1, y1, x2, y2, maxLength, collideConnected);
|
||||
}
|
||||
|
||||
Fixture *Physics::newFixture(Body *body, Shape *shape, float density)
|
||||
{
|
||||
return new Fixture(body, shape, density);
|
||||
}
|
||||
|
||||
int Physics::getDistance(lua_State *L)
|
||||
{
|
||||
Fixture *fixtureA = luax_checktype<Fixture>(L, 1, "Fixture", PHYSICS_FIXTURE_T);
|
||||
Fixture *fixtureB = luax_checktype<Fixture>(L, 2, "Fixture", PHYSICS_FIXTURE_T);
|
||||
b2DistanceInput i;
|
||||
b2DistanceProxy pA;
|
||||
pA.Set(fixtureA->fixture->GetShape(), 0);
|
||||
b2DistanceProxy pB;
|
||||
pB.Set(fixtureB->fixture->GetShape(), 0);
|
||||
i.proxyA = pA;
|
||||
i.proxyB = pB;
|
||||
i.transformA = fixtureA->fixture->GetBody()->GetTransform();
|
||||
i.transformB = fixtureB->fixture->GetBody()->GetTransform();
|
||||
i.useRadii = true;
|
||||
b2DistanceOutput o;
|
||||
b2SimplexCache c;
|
||||
b2Distance(&o, &c, &i);
|
||||
lua_pushnumber(L, Physics::scaleUp(o.distance));
|
||||
lua_pushnumber(L, Physics::scaleUp(o.pointA.x));
|
||||
lua_pushnumber(L, Physics::scaleUp(o.pointA.y));
|
||||
lua_pushnumber(L, Physics::scaleUp(o.pointB.x));
|
||||
lua_pushnumber(L, Physics::scaleUp(o.pointB.y));
|
||||
return 5;
|
||||
}
|
||||
|
||||
void Physics::setMeter(int meter)
|
||||
{
|
||||
if (meter < 1) throw love::Exception("Physics error: invalid meter");
|
||||
Physics::meter = meter;
|
||||
}
|
||||
|
||||
int Physics::getMeter()
|
||||
{
|
||||
return meter;
|
||||
}
|
||||
|
||||
void Physics::scaleDown(float &x, float &y)
|
||||
{
|
||||
x /= (float)meter;
|
||||
y /= (float)meter;
|
||||
}
|
||||
|
||||
void Physics::scaleUp(float &x, float &y)
|
||||
{
|
||||
x *= (float)meter;
|
||||
y *= (float)meter;
|
||||
}
|
||||
|
||||
float Physics::scaleDown(float f)
|
||||
{
|
||||
return f/(float)meter;
|
||||
}
|
||||
|
||||
float Physics::scaleUp(float f)
|
||||
{
|
||||
return f*(float)meter;
|
||||
}
|
||||
|
||||
b2Vec2 Physics::scaleDown(const b2Vec2 &v)
|
||||
{
|
||||
b2Vec2 t = v;
|
||||
scaleDown(t.x, t.y);
|
||||
return t;
|
||||
}
|
||||
|
||||
b2Vec2 Physics::scaleUp(const b2Vec2 &v)
|
||||
{
|
||||
b2Vec2 t = v;
|
||||
scaleUp(t.x, t.y);
|
||||
return t;
|
||||
}
|
||||
|
||||
b2AABB Physics::scaleDown(const b2AABB &aabb)
|
||||
{
|
||||
b2AABB t;
|
||||
t.lowerBound = scaleDown(aabb.lowerBound);
|
||||
t.upperBound = scaleDown(aabb.upperBound);
|
||||
return t;
|
||||
}
|
||||
|
||||
b2AABB Physics::scaleUp(const b2AABB &aabb)
|
||||
{
|
||||
b2AABB t;
|
||||
t.lowerBound = scaleUp(aabb.lowerBound);
|
||||
t.upperBound = scaleUp(aabb.upperBound);
|
||||
return t;
|
||||
}
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
+351
-351
@@ -1,351 +1,351 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_PHYSICS_BOX2D_PHYSICS_H
|
||||
#define LOVE_PHYSICS_BOX2D_PHYSICS_H
|
||||
|
||||
// LOVE
|
||||
#include "common/Module.h"
|
||||
#include "World.h"
|
||||
#include "Contact.h"
|
||||
#include "Body.h"
|
||||
#include "Fixture.h"
|
||||
#include "Shape.h"
|
||||
#include "CircleShape.h"
|
||||
#include "PolygonShape.h"
|
||||
#include "EdgeShape.h"
|
||||
#include "ChainShape.h"
|
||||
#include "Joint.h"
|
||||
#include "MouseJoint.h"
|
||||
#include "DistanceJoint.h"
|
||||
#include "PrismaticJoint.h"
|
||||
#include "RevoluteJoint.h"
|
||||
#include "PulleyJoint.h"
|
||||
#include "GearJoint.h"
|
||||
#include "FrictionJoint.h"
|
||||
#include "WeldJoint.h"
|
||||
#include "WheelJoint.h"
|
||||
#include "RopeJoint.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
class Physics : public Module
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* 30 pixels in one meter by default.
|
||||
**/
|
||||
static const int DEFAULT_METER = 30;
|
||||
|
||||
// Implements Module.
|
||||
const char *getName() const;
|
||||
|
||||
/**
|
||||
* Creates a new World.
|
||||
* @param gx Gravity along x-axis.
|
||||
* @param gy Gravity along y-axis.
|
||||
* @param sleep Whether the World allows sleep.
|
||||
**/
|
||||
World *newWorld(float gx, float gy, bool sleep);
|
||||
|
||||
/**
|
||||
* Creates a new Body at the specified position.
|
||||
* @param world The world to create the Body in.
|
||||
* @param x The position along the x-axis.
|
||||
* @param x The position along the y-axis.
|
||||
* @param type The type of body to create.
|
||||
**/
|
||||
Body *newBody(World *world, float x, float y, Body::Type type);
|
||||
|
||||
/**
|
||||
* Creates a new Body at (0, 0)
|
||||
* @param world The world to create the Body in.
|
||||
* @param type The type of Body to create.
|
||||
**/
|
||||
Body *newBody(World *world, Body::Type type);
|
||||
|
||||
/**
|
||||
* Creates a new CircleShape at (0, 0).
|
||||
* @param radius The radius of the circle.
|
||||
**/
|
||||
CircleShape *newCircleShape(float radius);
|
||||
|
||||
/**
|
||||
* Creates a new CircleShape at (x,y) in local coordinates.
|
||||
* @param x The offset along the x-axis.
|
||||
* @param y The offset along the y-axis.
|
||||
* @param radius The radius of the circle.
|
||||
**/
|
||||
CircleShape *newCircleShape(float x, float y, float radius);
|
||||
|
||||
/**
|
||||
* Shorthand for creating rectangular PolygonShapes. The rectangle
|
||||
* will be created at the local origin.
|
||||
* @param w The width of the rectangle.
|
||||
* @param h The height of the rectangle.
|
||||
**/
|
||||
PolygonShape *newRectangleShape(float w, float h);
|
||||
|
||||
/**
|
||||
* Shorthand for creating rectangular PolygonShapes. The rectangle
|
||||
* will be created at (x,y) in local coordinates.
|
||||
* @param x The offset along the x-axis.
|
||||
* @param y The offset along the y-axis.
|
||||
* @param w The width of the rectangle.
|
||||
* @param h The height of the rectangle.
|
||||
**/
|
||||
PolygonShape *newRectangleShape(float x, float y, float w, float h);
|
||||
|
||||
/**
|
||||
* Shorthand for creating rectangular PolygonShapes. The rectangle
|
||||
* will be created at (x,y) in local coordinates.
|
||||
* @param x The offset along the x-axis.
|
||||
* @param y The offset along the y-axis.
|
||||
* @param w The width of the rectangle.
|
||||
* @param h The height of the rectangle.
|
||||
* @param angle The angle of the rectangle. (rad)
|
||||
**/
|
||||
PolygonShape *newRectangleShape(float x, float y, float w, float h, float angle);
|
||||
|
||||
/**
|
||||
* Creates a new EdgeShape. The edge will be created from
|
||||
* (x1,y1) to (x2,y2) in local coordinates.
|
||||
* @param x1 The x coordinate of the first point.
|
||||
* @param y1 The y coordinate of the first point.
|
||||
* @param x2 The x coordinate of the second point.
|
||||
* @param y2 The y coordinate of the second point.
|
||||
**/
|
||||
EdgeShape *newEdgeShape(float x1, float y1, float x2, float y2);
|
||||
|
||||
/**
|
||||
* Creates a new PolygonShape.
|
||||
* @param ... A variable number of vertices.
|
||||
**/
|
||||
int newPolygonShape(lua_State *L);
|
||||
|
||||
/**
|
||||
* Creates a new ChainShape.
|
||||
* @param ... A variable number of vertices.
|
||||
**/
|
||||
int newChainShape(lua_State *L);
|
||||
|
||||
/**
|
||||
* Creates a new DistanceJoint connecting body1 with body2.
|
||||
* @param x1 Anchor1 along the x-axis. (World coordinates)
|
||||
* @param y1 Anchor1 along the y-axis. (World coordinates)
|
||||
* @param x2 Anchor2 along the x-axis. (World coordinates)
|
||||
* @param y2 Anchor2 along the y-axis. (World coordinates)
|
||||
* @param collideConnected Whether the connected bodies should collide with each other. Defaults to false.
|
||||
**/
|
||||
DistanceJoint *newDistanceJoint(Body *body1, Body *body2, float x1, float y1, float x2, float y2, bool collideConnected);
|
||||
|
||||
/**
|
||||
* Creates a new MouseJoint connecting the body with an arbitrary point.
|
||||
* @param x Anchor along the x-axis. (World coordinates)
|
||||
* @param y Anchor along the y-axis. (World coordinates)
|
||||
**/
|
||||
MouseJoint *newMouseJoint(Body *body, float x, float y);
|
||||
|
||||
/**
|
||||
* Creates a new RevoluteJoint connecting body1 with body2.
|
||||
* @param x Anchor along the x-axis. (World coordinates)
|
||||
* @param y Anchor along the y-axis. (World coordinates)
|
||||
* @param collideConnected Whether the connected bodies should collide with each other. Defaults to false.
|
||||
**/
|
||||
RevoluteJoint *newRevoluteJoint(Body *body1, Body *body2, float x, float y, bool collideConnected);
|
||||
|
||||
/**
|
||||
* Creates a new PrismaticJoint connecting body1 with body2.
|
||||
* @param xA World-anchor for body1 along the x-axis.
|
||||
* @param yA World-anchor for body1 along the y-axis.
|
||||
* @param xB World-anchor for body2 along the x-axis.
|
||||
* @param yB World-anchor for body2 along the y-axis.
|
||||
* @param ax The x-component of the world-axis.
|
||||
* @param ay The y-component of the world-axis.
|
||||
* @param collideConnected Whether the connected bodies should collide with each other. Defaults to false.
|
||||
**/
|
||||
PrismaticJoint *newPrismaticJoint(Body *body1, Body *body2, float xA, float yA, float xB, float yB, float ax, float ay, bool collideConnected);
|
||||
|
||||
/**
|
||||
* Creates a new PulleyJoint connecting body1 with body2.
|
||||
* @param groundAnchor1 World ground-anchor for body1.
|
||||
* @param groundAnchor2 World ground-anchor for body2.
|
||||
* @param anchor1 World anchor on body1.
|
||||
* @param anchor2 World anchor on body2.
|
||||
* @param ratio The pulley ratio.
|
||||
* @param collideConnected Whether the connected bodies should collide with each other. Defaults to true.
|
||||
**/
|
||||
PulleyJoint *newPulleyJoint(Body *body1, Body *body2, b2Vec2 groundAnchor1, b2Vec2 groundAnchor2, b2Vec2 anchor1, b2Vec2 anchor2, float ratio, bool collideConnected);
|
||||
|
||||
/**
|
||||
* Creates a new GearJoint connecting joint1 with joint2.
|
||||
* @param joint1 The first joint.
|
||||
* @param joint2 The second joint.
|
||||
* @param ratio The gear ratio.
|
||||
* @param collideConnected Whether the connected bodies should collide with each other. Defaults to false.
|
||||
**/
|
||||
GearJoint *newGearJoint(Joint *joint1, Joint *joint2, float ratio, bool collideConnected);
|
||||
|
||||
/**
|
||||
* Creates a new FrictionJoint connecting body1 with body2.
|
||||
* @param xA Anchor for body 1 along the x-axis. (World coordinates)
|
||||
* @param yA Anchor for body 1 along the y-axis. (World coordinates)
|
||||
* @param xB Anchor for body 2 along the x-axis. (World coordinates)
|
||||
* @param yB Anchor for body 2 along the y-axis. (World coordinates)
|
||||
* @param collideConnected Whether the connected bodies should collide with each other. Defaults to false.
|
||||
**/
|
||||
FrictionJoint *newFrictionJoint(Body *body1, Body *body2, float xA, float yA, float xB, float yB, bool collideConnected);
|
||||
|
||||
/**
|
||||
* Creates a new WeldJoint connecting body1 with body2.
|
||||
* @param xA Anchor for body 1 along the x-axis. (World coordinates)
|
||||
* @param yA Anchor for body 1 along the y-axis. (World coordinates)
|
||||
* @param xB Anchor for body 2 along the x-axis. (World coordinates)
|
||||
* @param yB Anchor for body 2 along the y-axis. (World coordinates)
|
||||
* @param collideConnected Whether the connected bodies should collide with each other. Defaults to false.
|
||||
**/
|
||||
WeldJoint *newWeldJoint(Body *body1, Body *body2, float xA, float yA, float xB, float yB, bool collideConnected);
|
||||
|
||||
/**
|
||||
* Creates a new WheelJoint connecting body1 with body2.
|
||||
* @param xA Anchor for body 1 along the x-axis. (World coordinates)
|
||||
* @param yA Anchor for body 1 along the y-axis. (World coordinates)
|
||||
* @param xB Anchor for body 2 along the x-axis. (World coordinates)
|
||||
* @param yB Anchor for body 2 along the y-axis. (World coordinates)
|
||||
* @param ax The x-component of the world-axis.
|
||||
* @param ay The y-component of the world-axis.
|
||||
* @param collideConnected Whether the connected bodies should collide with each other. Defaults to false.
|
||||
**/
|
||||
WheelJoint *newWheelJoint(Body *body1, Body *body2, float xA, float yA, float xB, float yB, float ax, float ay, bool collideConnected);
|
||||
|
||||
/**
|
||||
* Creates a new RopeJoint connecting body1 with body2.
|
||||
* @param x1 Anchor1 along the x-axis. (Local coordinates)
|
||||
* @param y1 Anchor1 along the y-axis. (Local coordinates)
|
||||
* @param x2 Anchor2 along the x-axis. (Local coordinates)
|
||||
* @param y2 Anchor2 along the y-axis. (Local coordinates)
|
||||
* @param maxLength The maximum distance for the bodies.
|
||||
* @param collideConnected Whether the connected bodies should collide with each other. Defaults to false.
|
||||
**/
|
||||
RopeJoint *newRopeJoint(Body *body1, Body *body2, float x1, float y1, float x2, float y2, float maxLength, bool collideConnected);
|
||||
|
||||
/**
|
||||
* Creates a new Fixture attaching shape to body.
|
||||
* @param body The body to attach the Fixture to.
|
||||
* @param shape The shape to attach to the Fixture,
|
||||
* @param density The density of the Fixture.
|
||||
**/
|
||||
|
||||
Fixture *newFixture(Body *body, Shape *shape, float density);
|
||||
|
||||
/**
|
||||
* Calculates the distance between two Fixtures.
|
||||
* @param fixtureA The first Fixture.
|
||||
* @param fixtureB The sceond Fixture.
|
||||
* @return The distance between them, and the two points closest
|
||||
* to each other.
|
||||
**/
|
||||
int getDistance(lua_State *L);
|
||||
|
||||
/**
|
||||
* Sets the number of pixels in one meter.
|
||||
* @param pixels The number of pixels in one meter. (1m ~= 3.3ft).
|
||||
**/
|
||||
static void setMeter(int meter);
|
||||
|
||||
/**
|
||||
* Gets the number of pixels in one meter.
|
||||
* @param pixels The number of pixels in one meter. (1m ~= 3.3ft).
|
||||
**/
|
||||
static int getMeter();
|
||||
|
||||
/**
|
||||
* Scales a value down according to the current meter in pixels.
|
||||
* @param f The unscaled input value.
|
||||
**/
|
||||
static float scaleDown(float f);
|
||||
|
||||
/**
|
||||
* Scales a value up according to the current meter in pixels.
|
||||
* @param f The unscaled input value.
|
||||
**/
|
||||
static float scaleUp(float f);
|
||||
|
||||
/**
|
||||
* Scales a point down according to the current meter
|
||||
* in pixels, for instance x = x0/meter, y = x0/meter.
|
||||
* @param x The x-coordinate of the point to scale.
|
||||
* @param y The y-coordinate of the point to scale.
|
||||
**/
|
||||
static void scaleDown(float &x, float &y);
|
||||
|
||||
/**
|
||||
* Scales a point up according to the current meter
|
||||
* in pixels, for instance x = x0/meter, y = x0/meter.
|
||||
* @param x The x-coordinate of the point to scale.
|
||||
* @param y The y-coordinate of the point to scale.
|
||||
**/
|
||||
static void scaleUp(float &x, float &y);
|
||||
|
||||
/**
|
||||
* Scales a b2Vec2 down according to the current meter in pixels.
|
||||
* @param v The unscaled input vector.
|
||||
* @return The scaled vector.
|
||||
**/
|
||||
static b2Vec2 scaleDown(const b2Vec2 &v);
|
||||
|
||||
/**
|
||||
* Scales a b2Vec up according to the current meter in pixels.
|
||||
* @param v The unscaled input vector.
|
||||
* @return The scaled vector.
|
||||
**/
|
||||
static b2Vec2 scaleUp(const b2Vec2 &v);
|
||||
|
||||
/**
|
||||
* Scales a b2AABB down according to the current meter in pixels.
|
||||
* @param v The unscaled input AABB.
|
||||
* @return The scaled AABB.
|
||||
**/
|
||||
static b2AABB scaleDown(const b2AABB &aabb);
|
||||
|
||||
/**
|
||||
* Scales a b2AABB up according to the current meter in pixels.
|
||||
* @param v The unscaled input AABB.
|
||||
* @return The scaled AABB.
|
||||
**/
|
||||
static b2AABB scaleUp(const b2AABB &aabb);
|
||||
|
||||
private:
|
||||
|
||||
// The length of one meter in pixels.
|
||||
static int meter;
|
||||
}; // Physics
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_PHYSICS_H
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_PHYSICS_BOX2D_PHYSICS_H
|
||||
#define LOVE_PHYSICS_BOX2D_PHYSICS_H
|
||||
|
||||
// LOVE
|
||||
#include "common/Module.h"
|
||||
#include "World.h"
|
||||
#include "Contact.h"
|
||||
#include "Body.h"
|
||||
#include "Fixture.h"
|
||||
#include "Shape.h"
|
||||
#include "CircleShape.h"
|
||||
#include "PolygonShape.h"
|
||||
#include "EdgeShape.h"
|
||||
#include "ChainShape.h"
|
||||
#include "Joint.h"
|
||||
#include "MouseJoint.h"
|
||||
#include "DistanceJoint.h"
|
||||
#include "PrismaticJoint.h"
|
||||
#include "RevoluteJoint.h"
|
||||
#include "PulleyJoint.h"
|
||||
#include "GearJoint.h"
|
||||
#include "FrictionJoint.h"
|
||||
#include "WeldJoint.h"
|
||||
#include "WheelJoint.h"
|
||||
#include "RopeJoint.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
class Physics : public Module
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* 30 pixels in one meter by default.
|
||||
**/
|
||||
static const int DEFAULT_METER = 30;
|
||||
|
||||
// Implements Module.
|
||||
const char *getName() const;
|
||||
|
||||
/**
|
||||
* Creates a new World.
|
||||
* @param gx Gravity along x-axis.
|
||||
* @param gy Gravity along y-axis.
|
||||
* @param sleep Whether the World allows sleep.
|
||||
**/
|
||||
World *newWorld(float gx, float gy, bool sleep);
|
||||
|
||||
/**
|
||||
* Creates a new Body at the specified position.
|
||||
* @param world The world to create the Body in.
|
||||
* @param x The position along the x-axis.
|
||||
* @param x The position along the y-axis.
|
||||
* @param type The type of body to create.
|
||||
**/
|
||||
Body *newBody(World *world, float x, float y, Body::Type type);
|
||||
|
||||
/**
|
||||
* Creates a new Body at (0, 0)
|
||||
* @param world The world to create the Body in.
|
||||
* @param type The type of Body to create.
|
||||
**/
|
||||
Body *newBody(World *world, Body::Type type);
|
||||
|
||||
/**
|
||||
* Creates a new CircleShape at (0, 0).
|
||||
* @param radius The radius of the circle.
|
||||
**/
|
||||
CircleShape *newCircleShape(float radius);
|
||||
|
||||
/**
|
||||
* Creates a new CircleShape at (x,y) in local coordinates.
|
||||
* @param x The offset along the x-axis.
|
||||
* @param y The offset along the y-axis.
|
||||
* @param radius The radius of the circle.
|
||||
**/
|
||||
CircleShape *newCircleShape(float x, float y, float radius);
|
||||
|
||||
/**
|
||||
* Shorthand for creating rectangular PolygonShapes. The rectangle
|
||||
* will be created at the local origin.
|
||||
* @param w The width of the rectangle.
|
||||
* @param h The height of the rectangle.
|
||||
**/
|
||||
PolygonShape *newRectangleShape(float w, float h);
|
||||
|
||||
/**
|
||||
* Shorthand for creating rectangular PolygonShapes. The rectangle
|
||||
* will be created at (x,y) in local coordinates.
|
||||
* @param x The offset along the x-axis.
|
||||
* @param y The offset along the y-axis.
|
||||
* @param w The width of the rectangle.
|
||||
* @param h The height of the rectangle.
|
||||
**/
|
||||
PolygonShape *newRectangleShape(float x, float y, float w, float h);
|
||||
|
||||
/**
|
||||
* Shorthand for creating rectangular PolygonShapes. The rectangle
|
||||
* will be created at (x,y) in local coordinates.
|
||||
* @param x The offset along the x-axis.
|
||||
* @param y The offset along the y-axis.
|
||||
* @param w The width of the rectangle.
|
||||
* @param h The height of the rectangle.
|
||||
* @param angle The angle of the rectangle. (rad)
|
||||
**/
|
||||
PolygonShape *newRectangleShape(float x, float y, float w, float h, float angle);
|
||||
|
||||
/**
|
||||
* Creates a new EdgeShape. The edge will be created from
|
||||
* (x1,y1) to (x2,y2) in local coordinates.
|
||||
* @param x1 The x coordinate of the first point.
|
||||
* @param y1 The y coordinate of the first point.
|
||||
* @param x2 The x coordinate of the second point.
|
||||
* @param y2 The y coordinate of the second point.
|
||||
**/
|
||||
EdgeShape *newEdgeShape(float x1, float y1, float x2, float y2);
|
||||
|
||||
/**
|
||||
* Creates a new PolygonShape.
|
||||
* @param ... A variable number of vertices.
|
||||
**/
|
||||
int newPolygonShape(lua_State *L);
|
||||
|
||||
/**
|
||||
* Creates a new ChainShape.
|
||||
* @param ... A variable number of vertices.
|
||||
**/
|
||||
int newChainShape(lua_State *L);
|
||||
|
||||
/**
|
||||
* Creates a new DistanceJoint connecting body1 with body2.
|
||||
* @param x1 Anchor1 along the x-axis. (World coordinates)
|
||||
* @param y1 Anchor1 along the y-axis. (World coordinates)
|
||||
* @param x2 Anchor2 along the x-axis. (World coordinates)
|
||||
* @param y2 Anchor2 along the y-axis. (World coordinates)
|
||||
* @param collideConnected Whether the connected bodies should collide with each other. Defaults to false.
|
||||
**/
|
||||
DistanceJoint *newDistanceJoint(Body *body1, Body *body2, float x1, float y1, float x2, float y2, bool collideConnected);
|
||||
|
||||
/**
|
||||
* Creates a new MouseJoint connecting the body with an arbitrary point.
|
||||
* @param x Anchor along the x-axis. (World coordinates)
|
||||
* @param y Anchor along the y-axis. (World coordinates)
|
||||
**/
|
||||
MouseJoint *newMouseJoint(Body *body, float x, float y);
|
||||
|
||||
/**
|
||||
* Creates a new RevoluteJoint connecting body1 with body2.
|
||||
* @param x Anchor along the x-axis. (World coordinates)
|
||||
* @param y Anchor along the y-axis. (World coordinates)
|
||||
* @param collideConnected Whether the connected bodies should collide with each other. Defaults to false.
|
||||
**/
|
||||
RevoluteJoint *newRevoluteJoint(Body *body1, Body *body2, float x, float y, bool collideConnected);
|
||||
|
||||
/**
|
||||
* Creates a new PrismaticJoint connecting body1 with body2.
|
||||
* @param xA World-anchor for body1 along the x-axis.
|
||||
* @param yA World-anchor for body1 along the y-axis.
|
||||
* @param xB World-anchor for body2 along the x-axis.
|
||||
* @param yB World-anchor for body2 along the y-axis.
|
||||
* @param ax The x-component of the world-axis.
|
||||
* @param ay The y-component of the world-axis.
|
||||
* @param collideConnected Whether the connected bodies should collide with each other. Defaults to false.
|
||||
**/
|
||||
PrismaticJoint *newPrismaticJoint(Body *body1, Body *body2, float xA, float yA, float xB, float yB, float ax, float ay, bool collideConnected);
|
||||
|
||||
/**
|
||||
* Creates a new PulleyJoint connecting body1 with body2.
|
||||
* @param groundAnchor1 World ground-anchor for body1.
|
||||
* @param groundAnchor2 World ground-anchor for body2.
|
||||
* @param anchor1 World anchor on body1.
|
||||
* @param anchor2 World anchor on body2.
|
||||
* @param ratio The pulley ratio.
|
||||
* @param collideConnected Whether the connected bodies should collide with each other. Defaults to true.
|
||||
**/
|
||||
PulleyJoint *newPulleyJoint(Body *body1, Body *body2, b2Vec2 groundAnchor1, b2Vec2 groundAnchor2, b2Vec2 anchor1, b2Vec2 anchor2, float ratio, bool collideConnected);
|
||||
|
||||
/**
|
||||
* Creates a new GearJoint connecting joint1 with joint2.
|
||||
* @param joint1 The first joint.
|
||||
* @param joint2 The second joint.
|
||||
* @param ratio The gear ratio.
|
||||
* @param collideConnected Whether the connected bodies should collide with each other. Defaults to false.
|
||||
**/
|
||||
GearJoint *newGearJoint(Joint *joint1, Joint *joint2, float ratio, bool collideConnected);
|
||||
|
||||
/**
|
||||
* Creates a new FrictionJoint connecting body1 with body2.
|
||||
* @param xA Anchor for body 1 along the x-axis. (World coordinates)
|
||||
* @param yA Anchor for body 1 along the y-axis. (World coordinates)
|
||||
* @param xB Anchor for body 2 along the x-axis. (World coordinates)
|
||||
* @param yB Anchor for body 2 along the y-axis. (World coordinates)
|
||||
* @param collideConnected Whether the connected bodies should collide with each other. Defaults to false.
|
||||
**/
|
||||
FrictionJoint *newFrictionJoint(Body *body1, Body *body2, float xA, float yA, float xB, float yB, bool collideConnected);
|
||||
|
||||
/**
|
||||
* Creates a new WeldJoint connecting body1 with body2.
|
||||
* @param xA Anchor for body 1 along the x-axis. (World coordinates)
|
||||
* @param yA Anchor for body 1 along the y-axis. (World coordinates)
|
||||
* @param xB Anchor for body 2 along the x-axis. (World coordinates)
|
||||
* @param yB Anchor for body 2 along the y-axis. (World coordinates)
|
||||
* @param collideConnected Whether the connected bodies should collide with each other. Defaults to false.
|
||||
**/
|
||||
WeldJoint *newWeldJoint(Body *body1, Body *body2, float xA, float yA, float xB, float yB, bool collideConnected);
|
||||
|
||||
/**
|
||||
* Creates a new WheelJoint connecting body1 with body2.
|
||||
* @param xA Anchor for body 1 along the x-axis. (World coordinates)
|
||||
* @param yA Anchor for body 1 along the y-axis. (World coordinates)
|
||||
* @param xB Anchor for body 2 along the x-axis. (World coordinates)
|
||||
* @param yB Anchor for body 2 along the y-axis. (World coordinates)
|
||||
* @param ax The x-component of the world-axis.
|
||||
* @param ay The y-component of the world-axis.
|
||||
* @param collideConnected Whether the connected bodies should collide with each other. Defaults to false.
|
||||
**/
|
||||
WheelJoint *newWheelJoint(Body *body1, Body *body2, float xA, float yA, float xB, float yB, float ax, float ay, bool collideConnected);
|
||||
|
||||
/**
|
||||
* Creates a new RopeJoint connecting body1 with body2.
|
||||
* @param x1 Anchor1 along the x-axis. (Local coordinates)
|
||||
* @param y1 Anchor1 along the y-axis. (Local coordinates)
|
||||
* @param x2 Anchor2 along the x-axis. (Local coordinates)
|
||||
* @param y2 Anchor2 along the y-axis. (Local coordinates)
|
||||
* @param maxLength The maximum distance for the bodies.
|
||||
* @param collideConnected Whether the connected bodies should collide with each other. Defaults to false.
|
||||
**/
|
||||
RopeJoint *newRopeJoint(Body *body1, Body *body2, float x1, float y1, float x2, float y2, float maxLength, bool collideConnected);
|
||||
|
||||
/**
|
||||
* Creates a new Fixture attaching shape to body.
|
||||
* @param body The body to attach the Fixture to.
|
||||
* @param shape The shape to attach to the Fixture,
|
||||
* @param density The density of the Fixture.
|
||||
**/
|
||||
|
||||
Fixture *newFixture(Body *body, Shape *shape, float density);
|
||||
|
||||
/**
|
||||
* Calculates the distance between two Fixtures.
|
||||
* @param fixtureA The first Fixture.
|
||||
* @param fixtureB The sceond Fixture.
|
||||
* @return The distance between them, and the two points closest
|
||||
* to each other.
|
||||
**/
|
||||
int getDistance(lua_State *L);
|
||||
|
||||
/**
|
||||
* Sets the number of pixels in one meter.
|
||||
* @param pixels The number of pixels in one meter. (1m ~= 3.3ft).
|
||||
**/
|
||||
static void setMeter(int meter);
|
||||
|
||||
/**
|
||||
* Gets the number of pixels in one meter.
|
||||
* @param pixels The number of pixels in one meter. (1m ~= 3.3ft).
|
||||
**/
|
||||
static int getMeter();
|
||||
|
||||
/**
|
||||
* Scales a value down according to the current meter in pixels.
|
||||
* @param f The unscaled input value.
|
||||
**/
|
||||
static float scaleDown(float f);
|
||||
|
||||
/**
|
||||
* Scales a value up according to the current meter in pixels.
|
||||
* @param f The unscaled input value.
|
||||
**/
|
||||
static float scaleUp(float f);
|
||||
|
||||
/**
|
||||
* Scales a point down according to the current meter
|
||||
* in pixels, for instance x = x0/meter, y = x0/meter.
|
||||
* @param x The x-coordinate of the point to scale.
|
||||
* @param y The y-coordinate of the point to scale.
|
||||
**/
|
||||
static void scaleDown(float &x, float &y);
|
||||
|
||||
/**
|
||||
* Scales a point up according to the current meter
|
||||
* in pixels, for instance x = x0/meter, y = x0/meter.
|
||||
* @param x The x-coordinate of the point to scale.
|
||||
* @param y The y-coordinate of the point to scale.
|
||||
**/
|
||||
static void scaleUp(float &x, float &y);
|
||||
|
||||
/**
|
||||
* Scales a b2Vec2 down according to the current meter in pixels.
|
||||
* @param v The unscaled input vector.
|
||||
* @return The scaled vector.
|
||||
**/
|
||||
static b2Vec2 scaleDown(const b2Vec2 &v);
|
||||
|
||||
/**
|
||||
* Scales a b2Vec up according to the current meter in pixels.
|
||||
* @param v The unscaled input vector.
|
||||
* @return The scaled vector.
|
||||
**/
|
||||
static b2Vec2 scaleUp(const b2Vec2 &v);
|
||||
|
||||
/**
|
||||
* Scales a b2AABB down according to the current meter in pixels.
|
||||
* @param v The unscaled input AABB.
|
||||
* @return The scaled AABB.
|
||||
**/
|
||||
static b2AABB scaleDown(const b2AABB &aabb);
|
||||
|
||||
/**
|
||||
* Scales a b2AABB up according to the current meter in pixels.
|
||||
* @param v The unscaled input AABB.
|
||||
* @return The scaled AABB.
|
||||
**/
|
||||
static b2AABB scaleUp(const b2AABB &aabb);
|
||||
|
||||
private:
|
||||
|
||||
// The length of one meter in pixels.
|
||||
static int meter;
|
||||
}; // Physics
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_PHYSICS_H
|
||||
|
||||
@@ -1,62 +1,62 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#include "PolygonShape.h"
|
||||
|
||||
// Module
|
||||
#include "Body.h"
|
||||
#include "World.h"
|
||||
#include "Physics.h"
|
||||
|
||||
#include "common/Memoizer.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
PolygonShape::PolygonShape(b2PolygonShape *p, bool own)
|
||||
: Shape(p, own)
|
||||
{
|
||||
}
|
||||
|
||||
PolygonShape::~PolygonShape()
|
||||
{
|
||||
}
|
||||
|
||||
int PolygonShape::getPoints(lua_State *L)
|
||||
{
|
||||
love::luax_assert_argc(L, 0);
|
||||
b2PolygonShape *p = (b2PolygonShape *)shape;
|
||||
int count = p->GetVertexCount();
|
||||
for (int i = 0; i<count; i++)
|
||||
{
|
||||
b2Vec2 v = Physics::scaleUp(p->GetVertex(i));
|
||||
lua_pushnumber(L, v.x);
|
||||
lua_pushnumber(L, v.y);
|
||||
}
|
||||
return count*2;
|
||||
}
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#include "PolygonShape.h"
|
||||
|
||||
// Module
|
||||
#include "Body.h"
|
||||
#include "World.h"
|
||||
#include "Physics.h"
|
||||
|
||||
#include "common/Memoizer.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
PolygonShape::PolygonShape(b2PolygonShape *p, bool own)
|
||||
: Shape(p, own)
|
||||
{
|
||||
}
|
||||
|
||||
PolygonShape::~PolygonShape()
|
||||
{
|
||||
}
|
||||
|
||||
int PolygonShape::getPoints(lua_State *L)
|
||||
{
|
||||
love::luax_assert_argc(L, 0);
|
||||
b2PolygonShape *p = (b2PolygonShape *)shape;
|
||||
int count = p->GetVertexCount();
|
||||
for (int i = 0; i<count; i++)
|
||||
{
|
||||
b2Vec2 v = Physics::scaleUp(p->GetVertex(i));
|
||||
lua_pushnumber(L, v.x);
|
||||
lua_pushnumber(L, v.y);
|
||||
}
|
||||
return count*2;
|
||||
}
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
@@ -1,68 +1,68 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_PHYSICS_BOX2D_POLYGON_SHAPE_H
|
||||
#define LOVE_PHYSICS_BOX2D_POLYGON_SHAPE_H
|
||||
|
||||
// Module
|
||||
#include "Shape.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
/**
|
||||
* You should know what a Polygon is. :)
|
||||
*
|
||||
* This class is needed so that we can easily get
|
||||
* the transformed points in Lua. By calling shape:getPoints(),
|
||||
* the result can be passed directly to love.graphics.polygon().
|
||||
**/
|
||||
class PolygonShape : public Shape
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Create a new PolygonShape from the parent Body and
|
||||
* a Box2D polygon definition.
|
||||
* @param body The parent Body.
|
||||
* @param def The polygon definition.
|
||||
**/
|
||||
PolygonShape(b2PolygonShape *p, bool own = true);
|
||||
|
||||
virtual ~PolygonShape();
|
||||
|
||||
/**
|
||||
* Returns the transformed points of the polygon.
|
||||
* This function is useful for debug drawing and such.
|
||||
*
|
||||
* The result can be directly passed into love.graphics.polygon().
|
||||
**/
|
||||
int getPoints(lua_State *L);
|
||||
};
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_POLYGON_SHAPE_H
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_PHYSICS_BOX2D_POLYGON_SHAPE_H
|
||||
#define LOVE_PHYSICS_BOX2D_POLYGON_SHAPE_H
|
||||
|
||||
// Module
|
||||
#include "Shape.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
/**
|
||||
* You should know what a Polygon is. :)
|
||||
*
|
||||
* This class is needed so that we can easily get
|
||||
* the transformed points in Lua. By calling shape:getPoints(),
|
||||
* the result can be passed directly to love.graphics.polygon().
|
||||
**/
|
||||
class PolygonShape : public Shape
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Create a new PolygonShape from the parent Body and
|
||||
* a Box2D polygon definition.
|
||||
* @param body The parent Body.
|
||||
* @param def The polygon definition.
|
||||
**/
|
||||
PolygonShape(b2PolygonShape *p, bool own = true);
|
||||
|
||||
virtual ~PolygonShape();
|
||||
|
||||
/**
|
||||
* Returns the transformed points of the polygon.
|
||||
* This function is useful for debug drawing and such.
|
||||
*
|
||||
* The result can be directly passed into love.graphics.polygon().
|
||||
**/
|
||||
int getPoints(lua_State *L);
|
||||
};
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_POLYGON_SHAPE_H
|
||||
|
||||
@@ -1,144 +1,144 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#include "PrismaticJoint.h"
|
||||
|
||||
// Module
|
||||
#include "Body.h"
|
||||
#include "World.h"
|
||||
#include "Physics.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
PrismaticJoint::PrismaticJoint(Body *body1, Body *body2, float xA, float yA, float xB, float yB, float ax, float ay, bool collideConnected)
|
||||
: Joint(body1, body2)
|
||||
, joint(NULL)
|
||||
{
|
||||
b2PrismaticJointDef def;
|
||||
|
||||
def.Initialize(body1->body, body2->body, Physics::scaleDown(b2Vec2(xA,yA)), b2Vec2(ax,ay));
|
||||
def.localAnchorB = body2->body->GetLocalPoint(Physics::scaleDown(b2Vec2(xB, yB)));
|
||||
def.lowerTranslation = 0.0f;
|
||||
def.upperTranslation = 100.0f;
|
||||
def.enableLimit = true;
|
||||
def.collideConnected = collideConnected;
|
||||
joint = (b2PrismaticJoint *)createJoint(&def);
|
||||
}
|
||||
|
||||
PrismaticJoint::~PrismaticJoint()
|
||||
{
|
||||
}
|
||||
|
||||
float PrismaticJoint::getJointTranslation() const
|
||||
{
|
||||
return Physics::scaleUp(joint->GetJointTranslation());
|
||||
}
|
||||
|
||||
float PrismaticJoint::getJointSpeed() const
|
||||
{
|
||||
return Physics::scaleUp(joint->GetJointSpeed());
|
||||
}
|
||||
|
||||
void PrismaticJoint::enableMotor(bool motor)
|
||||
{
|
||||
return joint->EnableMotor(motor);
|
||||
}
|
||||
|
||||
bool PrismaticJoint::isMotorEnabled() const
|
||||
{
|
||||
return joint->IsMotorEnabled();
|
||||
}
|
||||
|
||||
void PrismaticJoint::setMaxMotorForce(float force)
|
||||
{
|
||||
joint->SetMaxMotorForce(Physics::scaleDown(force));
|
||||
}
|
||||
|
||||
void PrismaticJoint::setMotorSpeed(float speed)
|
||||
{
|
||||
joint->SetMotorSpeed(Physics::scaleDown(speed));
|
||||
}
|
||||
|
||||
float PrismaticJoint::getMotorSpeed() const
|
||||
{
|
||||
return Physics::scaleUp(joint->GetMotorSpeed());
|
||||
}
|
||||
|
||||
float PrismaticJoint::getMotorForce(float inv_dt) const
|
||||
{
|
||||
return Physics::scaleUp(joint->GetMotorForce(inv_dt));
|
||||
}
|
||||
|
||||
float PrismaticJoint::getMaxMotorForce() const
|
||||
{
|
||||
return Physics::scaleUp(joint->GetMaxMotorForce());
|
||||
}
|
||||
|
||||
void PrismaticJoint::enableLimit(bool limit)
|
||||
{
|
||||
joint->EnableLimit(limit);
|
||||
}
|
||||
|
||||
bool PrismaticJoint::isLimitEnabled() const
|
||||
{
|
||||
return joint->IsLimitEnabled();
|
||||
}
|
||||
|
||||
void PrismaticJoint::setUpperLimit(float limit)
|
||||
{
|
||||
joint->SetLimits(joint->GetLowerLimit(), Physics::scaleDown(limit));
|
||||
}
|
||||
|
||||
void PrismaticJoint::setLowerLimit(float limit)
|
||||
{
|
||||
joint->SetLimits(Physics::scaleDown(limit), joint->GetUpperLimit());
|
||||
}
|
||||
|
||||
void PrismaticJoint::setLimits(float lower, float upper)
|
||||
{
|
||||
joint->SetLimits(Physics::scaleDown(lower), Physics::scaleDown(upper));
|
||||
}
|
||||
|
||||
float PrismaticJoint::getLowerLimit() const
|
||||
{
|
||||
return Physics::scaleUp(joint->GetLowerLimit());
|
||||
}
|
||||
|
||||
float PrismaticJoint::getUpperLimit() const
|
||||
{
|
||||
return Physics::scaleUp(joint->GetUpperLimit());
|
||||
}
|
||||
|
||||
int PrismaticJoint::getLimits(lua_State *L)
|
||||
{
|
||||
lua_pushnumber(L, Physics::scaleUp(joint->GetLowerLimit()));
|
||||
lua_pushnumber(L, Physics::scaleUp(joint->GetUpperLimit()));
|
||||
return 2;
|
||||
}
|
||||
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#include "PrismaticJoint.h"
|
||||
|
||||
// Module
|
||||
#include "Body.h"
|
||||
#include "World.h"
|
||||
#include "Physics.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
PrismaticJoint::PrismaticJoint(Body *body1, Body *body2, float xA, float yA, float xB, float yB, float ax, float ay, bool collideConnected)
|
||||
: Joint(body1, body2)
|
||||
, joint(NULL)
|
||||
{
|
||||
b2PrismaticJointDef def;
|
||||
|
||||
def.Initialize(body1->body, body2->body, Physics::scaleDown(b2Vec2(xA,yA)), b2Vec2(ax,ay));
|
||||
def.localAnchorB = body2->body->GetLocalPoint(Physics::scaleDown(b2Vec2(xB, yB)));
|
||||
def.lowerTranslation = 0.0f;
|
||||
def.upperTranslation = 100.0f;
|
||||
def.enableLimit = true;
|
||||
def.collideConnected = collideConnected;
|
||||
joint = (b2PrismaticJoint *)createJoint(&def);
|
||||
}
|
||||
|
||||
PrismaticJoint::~PrismaticJoint()
|
||||
{
|
||||
}
|
||||
|
||||
float PrismaticJoint::getJointTranslation() const
|
||||
{
|
||||
return Physics::scaleUp(joint->GetJointTranslation());
|
||||
}
|
||||
|
||||
float PrismaticJoint::getJointSpeed() const
|
||||
{
|
||||
return Physics::scaleUp(joint->GetJointSpeed());
|
||||
}
|
||||
|
||||
void PrismaticJoint::enableMotor(bool motor)
|
||||
{
|
||||
return joint->EnableMotor(motor);
|
||||
}
|
||||
|
||||
bool PrismaticJoint::isMotorEnabled() const
|
||||
{
|
||||
return joint->IsMotorEnabled();
|
||||
}
|
||||
|
||||
void PrismaticJoint::setMaxMotorForce(float force)
|
||||
{
|
||||
joint->SetMaxMotorForce(Physics::scaleDown(force));
|
||||
}
|
||||
|
||||
void PrismaticJoint::setMotorSpeed(float speed)
|
||||
{
|
||||
joint->SetMotorSpeed(Physics::scaleDown(speed));
|
||||
}
|
||||
|
||||
float PrismaticJoint::getMotorSpeed() const
|
||||
{
|
||||
return Physics::scaleUp(joint->GetMotorSpeed());
|
||||
}
|
||||
|
||||
float PrismaticJoint::getMotorForce(float inv_dt) const
|
||||
{
|
||||
return Physics::scaleUp(joint->GetMotorForce(inv_dt));
|
||||
}
|
||||
|
||||
float PrismaticJoint::getMaxMotorForce() const
|
||||
{
|
||||
return Physics::scaleUp(joint->GetMaxMotorForce());
|
||||
}
|
||||
|
||||
void PrismaticJoint::enableLimit(bool limit)
|
||||
{
|
||||
joint->EnableLimit(limit);
|
||||
}
|
||||
|
||||
bool PrismaticJoint::isLimitEnabled() const
|
||||
{
|
||||
return joint->IsLimitEnabled();
|
||||
}
|
||||
|
||||
void PrismaticJoint::setUpperLimit(float limit)
|
||||
{
|
||||
joint->SetLimits(joint->GetLowerLimit(), Physics::scaleDown(limit));
|
||||
}
|
||||
|
||||
void PrismaticJoint::setLowerLimit(float limit)
|
||||
{
|
||||
joint->SetLimits(Physics::scaleDown(limit), joint->GetUpperLimit());
|
||||
}
|
||||
|
||||
void PrismaticJoint::setLimits(float lower, float upper)
|
||||
{
|
||||
joint->SetLimits(Physics::scaleDown(lower), Physics::scaleDown(upper));
|
||||
}
|
||||
|
||||
float PrismaticJoint::getLowerLimit() const
|
||||
{
|
||||
return Physics::scaleUp(joint->GetLowerLimit());
|
||||
}
|
||||
|
||||
float PrismaticJoint::getUpperLimit() const
|
||||
{
|
||||
return Physics::scaleUp(joint->GetUpperLimit());
|
||||
}
|
||||
|
||||
int PrismaticJoint::getLimits(lua_State *L)
|
||||
{
|
||||
lua_pushnumber(L, Physics::scaleUp(joint->GetLowerLimit()));
|
||||
lua_pushnumber(L, Physics::scaleUp(joint->GetUpperLimit()));
|
||||
return 2;
|
||||
}
|
||||
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
@@ -1,147 +1,147 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_PHYSICS_BOX2D_PRISMATIC_JOINT_H
|
||||
#define LOVE_PHYSICS_BOX2D_PRISMATIC_JOINT_H
|
||||
|
||||
// Module
|
||||
#include "Joint.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
/**
|
||||
* PrismaticJoints allow shapes to move in relation to eachother
|
||||
* along a defined axis.
|
||||
**/
|
||||
class PrismaticJoint : public Joint
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Creates a new PrismaticJoint connecting body1 and body2.
|
||||
**/
|
||||
PrismaticJoint(Body *body1, Body *body2, float xA, float yA, float xB, float yB, float ax, float ay, bool collideConnected);
|
||||
|
||||
virtual ~PrismaticJoint();
|
||||
|
||||
/**
|
||||
* Get the current joint translation, usually in meters.
|
||||
**/
|
||||
float getJointTranslation() const;
|
||||
|
||||
/**
|
||||
* Get the current joint translation speed, usually in meters per second.
|
||||
**/
|
||||
float getJointSpeed() const;
|
||||
|
||||
/**
|
||||
* Enable/disable the joint motor.
|
||||
**/
|
||||
void enableMotor(bool motor);
|
||||
|
||||
/**
|
||||
* Checks whether the motor is enabled.
|
||||
**/
|
||||
bool isMotorEnabled() const;
|
||||
|
||||
/**
|
||||
* Set the maximum motor force, usually in N.
|
||||
**/
|
||||
void setMaxMotorForce(float force);
|
||||
|
||||
/**
|
||||
* Set the motor speed, usually in meters per second.
|
||||
**/
|
||||
void setMotorSpeed(float speed);
|
||||
|
||||
/**
|
||||
* Get the motor speed, usually in meters per second.
|
||||
**/
|
||||
float getMotorSpeed() const;
|
||||
|
||||
/**
|
||||
* Get the current motor force, usually in N.
|
||||
* @param inv_dt The inverse time step.
|
||||
**/
|
||||
float getMotorForce(float inv_dt) const;
|
||||
|
||||
/**
|
||||
* Get the maximum motor force, usually in N.
|
||||
**/
|
||||
float getMaxMotorForce() const;
|
||||
|
||||
/**
|
||||
* Enable/disable the joint limit.
|
||||
**/
|
||||
void enableLimit(bool limit);
|
||||
|
||||
/**
|
||||
* Checks whether limits are enabled.
|
||||
**/
|
||||
bool isLimitEnabled() const;
|
||||
|
||||
/**
|
||||
* Sets the upper limit, usually in meters.
|
||||
**/
|
||||
void setUpperLimit(float limit);
|
||||
|
||||
/**
|
||||
* Sets the lower limit, usually in meters.
|
||||
**/
|
||||
void setLowerLimit(float limit);
|
||||
|
||||
/**
|
||||
* Sets the limits, usually in meters.
|
||||
**/
|
||||
void setLimits(float lower, float upper);
|
||||
|
||||
/**
|
||||
* Gets the lower limit, usually in meters.
|
||||
**/
|
||||
float getLowerLimit() const;
|
||||
|
||||
/**
|
||||
* Gets the upper limit, usually in meters.
|
||||
**/
|
||||
float getUpperLimit() const;
|
||||
|
||||
/**
|
||||
* Gets the limits, usually in meters.
|
||||
* @returns The upper limit.
|
||||
* @returns The lower limit.
|
||||
**/
|
||||
int getLimits(lua_State *L);
|
||||
|
||||
private:
|
||||
|
||||
// The Box2D prismatic joint object.
|
||||
b2PrismaticJoint *joint;
|
||||
};
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_PRISMATIC_JOINT_H
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_PHYSICS_BOX2D_PRISMATIC_JOINT_H
|
||||
#define LOVE_PHYSICS_BOX2D_PRISMATIC_JOINT_H
|
||||
|
||||
// Module
|
||||
#include "Joint.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
/**
|
||||
* PrismaticJoints allow shapes to move in relation to eachother
|
||||
* along a defined axis.
|
||||
**/
|
||||
class PrismaticJoint : public Joint
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Creates a new PrismaticJoint connecting body1 and body2.
|
||||
**/
|
||||
PrismaticJoint(Body *body1, Body *body2, float xA, float yA, float xB, float yB, float ax, float ay, bool collideConnected);
|
||||
|
||||
virtual ~PrismaticJoint();
|
||||
|
||||
/**
|
||||
* Get the current joint translation, usually in meters.
|
||||
**/
|
||||
float getJointTranslation() const;
|
||||
|
||||
/**
|
||||
* Get the current joint translation speed, usually in meters per second.
|
||||
**/
|
||||
float getJointSpeed() const;
|
||||
|
||||
/**
|
||||
* Enable/disable the joint motor.
|
||||
**/
|
||||
void enableMotor(bool motor);
|
||||
|
||||
/**
|
||||
* Checks whether the motor is enabled.
|
||||
**/
|
||||
bool isMotorEnabled() const;
|
||||
|
||||
/**
|
||||
* Set the maximum motor force, usually in N.
|
||||
**/
|
||||
void setMaxMotorForce(float force);
|
||||
|
||||
/**
|
||||
* Set the motor speed, usually in meters per second.
|
||||
**/
|
||||
void setMotorSpeed(float speed);
|
||||
|
||||
/**
|
||||
* Get the motor speed, usually in meters per second.
|
||||
**/
|
||||
float getMotorSpeed() const;
|
||||
|
||||
/**
|
||||
* Get the current motor force, usually in N.
|
||||
* @param inv_dt The inverse time step.
|
||||
**/
|
||||
float getMotorForce(float inv_dt) const;
|
||||
|
||||
/**
|
||||
* Get the maximum motor force, usually in N.
|
||||
**/
|
||||
float getMaxMotorForce() const;
|
||||
|
||||
/**
|
||||
* Enable/disable the joint limit.
|
||||
**/
|
||||
void enableLimit(bool limit);
|
||||
|
||||
/**
|
||||
* Checks whether limits are enabled.
|
||||
**/
|
||||
bool isLimitEnabled() const;
|
||||
|
||||
/**
|
||||
* Sets the upper limit, usually in meters.
|
||||
**/
|
||||
void setUpperLimit(float limit);
|
||||
|
||||
/**
|
||||
* Sets the lower limit, usually in meters.
|
||||
**/
|
||||
void setLowerLimit(float limit);
|
||||
|
||||
/**
|
||||
* Sets the limits, usually in meters.
|
||||
**/
|
||||
void setLimits(float lower, float upper);
|
||||
|
||||
/**
|
||||
* Gets the lower limit, usually in meters.
|
||||
**/
|
||||
float getLowerLimit() const;
|
||||
|
||||
/**
|
||||
* Gets the upper limit, usually in meters.
|
||||
**/
|
||||
float getUpperLimit() const;
|
||||
|
||||
/**
|
||||
* Gets the limits, usually in meters.
|
||||
* @returns The upper limit.
|
||||
* @returns The lower limit.
|
||||
**/
|
||||
int getLimits(lua_State *L);
|
||||
|
||||
private:
|
||||
|
||||
// The Box2D prismatic joint object.
|
||||
b2PrismaticJoint *joint;
|
||||
};
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_PRISMATIC_JOINT_H
|
||||
|
||||
@@ -1,77 +1,77 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#include "PulleyJoint.h"
|
||||
|
||||
// Module
|
||||
#include "Body.h"
|
||||
#include "World.h"
|
||||
#include "Physics.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
PulleyJoint::PulleyJoint(Body *bodyA, Body *bodyB, b2Vec2 groundAnchorA, b2Vec2 groundAnchorB, b2Vec2 anchorA, b2Vec2 anchorB, float ratio, bool collideConnected)
|
||||
: Joint(bodyA, bodyB)
|
||||
, joint(NULL)
|
||||
{
|
||||
b2PulleyJointDef def;
|
||||
def.Initialize(bodyA->body, bodyB->body, Physics::scaleDown(groundAnchorA), Physics::scaleDown(groundAnchorB), \
|
||||
Physics::scaleDown(anchorA), Physics::scaleDown(anchorB), ratio);
|
||||
def.collideConnected = collideConnected;
|
||||
|
||||
joint = (b2PulleyJoint *)createJoint(&def);
|
||||
}
|
||||
|
||||
PulleyJoint::~PulleyJoint()
|
||||
{
|
||||
}
|
||||
|
||||
int PulleyJoint::getGroundAnchors(lua_State *L)
|
||||
{
|
||||
lua_pushnumber(L, Physics::scaleUp(joint->GetGroundAnchorA().x));
|
||||
lua_pushnumber(L, Physics::scaleUp(joint->GetGroundAnchorA().y));
|
||||
lua_pushnumber(L, Physics::scaleUp(joint->GetGroundAnchorB().x));
|
||||
lua_pushnumber(L, Physics::scaleUp(joint->GetGroundAnchorB().y));
|
||||
return 4;
|
||||
}
|
||||
|
||||
float PulleyJoint::getLengthA() const
|
||||
{
|
||||
return Physics::scaleUp(joint->GetLengthA());
|
||||
}
|
||||
|
||||
float PulleyJoint::getLengthB() const
|
||||
{
|
||||
return Physics::scaleUp(joint->GetLengthB());
|
||||
}
|
||||
|
||||
float PulleyJoint::getRatio() const
|
||||
{
|
||||
return joint->GetRatio();
|
||||
}
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#include "PulleyJoint.h"
|
||||
|
||||
// Module
|
||||
#include "Body.h"
|
||||
#include "World.h"
|
||||
#include "Physics.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
PulleyJoint::PulleyJoint(Body *bodyA, Body *bodyB, b2Vec2 groundAnchorA, b2Vec2 groundAnchorB, b2Vec2 anchorA, b2Vec2 anchorB, float ratio, bool collideConnected)
|
||||
: Joint(bodyA, bodyB)
|
||||
, joint(NULL)
|
||||
{
|
||||
b2PulleyJointDef def;
|
||||
def.Initialize(bodyA->body, bodyB->body, Physics::scaleDown(groundAnchorA), Physics::scaleDown(groundAnchorB), \
|
||||
Physics::scaleDown(anchorA), Physics::scaleDown(anchorB), ratio);
|
||||
def.collideConnected = collideConnected;
|
||||
|
||||
joint = (b2PulleyJoint *)createJoint(&def);
|
||||
}
|
||||
|
||||
PulleyJoint::~PulleyJoint()
|
||||
{
|
||||
}
|
||||
|
||||
int PulleyJoint::getGroundAnchors(lua_State *L)
|
||||
{
|
||||
lua_pushnumber(L, Physics::scaleUp(joint->GetGroundAnchorA().x));
|
||||
lua_pushnumber(L, Physics::scaleUp(joint->GetGroundAnchorA().y));
|
||||
lua_pushnumber(L, Physics::scaleUp(joint->GetGroundAnchorB().x));
|
||||
lua_pushnumber(L, Physics::scaleUp(joint->GetGroundAnchorB().y));
|
||||
return 4;
|
||||
}
|
||||
|
||||
float PulleyJoint::getLengthA() const
|
||||
{
|
||||
return Physics::scaleUp(joint->GetLengthA());
|
||||
}
|
||||
|
||||
float PulleyJoint::getLengthB() const
|
||||
{
|
||||
return Physics::scaleUp(joint->GetLengthB());
|
||||
}
|
||||
|
||||
float PulleyJoint::getRatio() const
|
||||
{
|
||||
return joint->GetRatio();
|
||||
}
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
@@ -1,81 +1,81 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_PHYSICS_BOX2D_PULLEY_JOINT_H
|
||||
#define LOVE_PHYSICS_BOX2D_PULLEY_JOINT_H
|
||||
|
||||
// Module
|
||||
#include "Joint.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
/**
|
||||
* The PulleyJoint The pulley connects two bodies to ground and
|
||||
* to each other. As one body goes up, the other goes down. The
|
||||
* total length of the pulley rope is conserved according to the
|
||||
* initial configuration: length1 + ratio * length2 <= constant.
|
||||
**/
|
||||
class PulleyJoint : public Joint
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Creates a PulleyJoint connecting bodyA to bodyB.
|
||||
**/
|
||||
PulleyJoint(Body *bodyA, Body *bodyB, b2Vec2 groundAnchorA, b2Vec2 groundAnchorB, b2Vec2 anchorA, b2Vec2 anchorB, float ratio, bool collideConnected);
|
||||
|
||||
virtual ~PulleyJoint();
|
||||
|
||||
/**
|
||||
* Gets the ground anchors position in world
|
||||
* coordinates.
|
||||
**/
|
||||
int getGroundAnchors(lua_State *L);
|
||||
|
||||
/**
|
||||
* Gets the current length of the segment attached to bodyA.
|
||||
**/
|
||||
float getLengthA() const;
|
||||
|
||||
/**
|
||||
* Gets the current length of the segment attached to bodyB.
|
||||
**/
|
||||
float getLengthB() const;
|
||||
|
||||
/**
|
||||
* Gets the pulley ratio.
|
||||
**/
|
||||
float getRatio() const;
|
||||
|
||||
private:
|
||||
// The Box2D DistanceJoint object.
|
||||
b2PulleyJoint *joint;
|
||||
};
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_PULLEY_JOINT_H
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_PHYSICS_BOX2D_PULLEY_JOINT_H
|
||||
#define LOVE_PHYSICS_BOX2D_PULLEY_JOINT_H
|
||||
|
||||
// Module
|
||||
#include "Joint.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
/**
|
||||
* The PulleyJoint The pulley connects two bodies to ground and
|
||||
* to each other. As one body goes up, the other goes down. The
|
||||
* total length of the pulley rope is conserved according to the
|
||||
* initial configuration: length1 + ratio * length2 <= constant.
|
||||
**/
|
||||
class PulleyJoint : public Joint
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Creates a PulleyJoint connecting bodyA to bodyB.
|
||||
**/
|
||||
PulleyJoint(Body *bodyA, Body *bodyB, b2Vec2 groundAnchorA, b2Vec2 groundAnchorB, b2Vec2 anchorA, b2Vec2 anchorB, float ratio, bool collideConnected);
|
||||
|
||||
virtual ~PulleyJoint();
|
||||
|
||||
/**
|
||||
* Gets the ground anchors position in world
|
||||
* coordinates.
|
||||
**/
|
||||
int getGroundAnchors(lua_State *L);
|
||||
|
||||
/**
|
||||
* Gets the current length of the segment attached to bodyA.
|
||||
**/
|
||||
float getLengthA() const;
|
||||
|
||||
/**
|
||||
* Gets the current length of the segment attached to bodyB.
|
||||
**/
|
||||
float getLengthB() const;
|
||||
|
||||
/**
|
||||
* Gets the pulley ratio.
|
||||
**/
|
||||
float getRatio() const;
|
||||
|
||||
private:
|
||||
// The Box2D DistanceJoint object.
|
||||
b2PulleyJoint *joint;
|
||||
};
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_PULLEY_JOINT_H
|
||||
|
||||
@@ -1,140 +1,140 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#include "RevoluteJoint.h"
|
||||
|
||||
#include "common/math.h"
|
||||
|
||||
// Module
|
||||
#include "Body.h"
|
||||
#include "World.h"
|
||||
#include "Physics.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
RevoluteJoint::RevoluteJoint(Body *body1, Body *body2, float x, float y, bool collideConnected)
|
||||
: Joint(body1, body2)
|
||||
, joint(NULL)
|
||||
{
|
||||
b2RevoluteJointDef def;
|
||||
def.Initialize(body1->body, body2->body, Physics::scaleDown(b2Vec2(x,y)));
|
||||
def.collideConnected = collideConnected;
|
||||
joint = (b2RevoluteJoint *)createJoint(&def);
|
||||
}
|
||||
|
||||
RevoluteJoint::~RevoluteJoint()
|
||||
{
|
||||
}
|
||||
|
||||
float RevoluteJoint::getJointAngle() const
|
||||
{
|
||||
return joint->GetJointAngle();
|
||||
}
|
||||
|
||||
float RevoluteJoint::getJointSpeed() const
|
||||
{
|
||||
return joint->GetJointSpeed();
|
||||
}
|
||||
|
||||
void RevoluteJoint::enableMotor(bool motor)
|
||||
{
|
||||
return joint->EnableMotor(motor);
|
||||
}
|
||||
|
||||
bool RevoluteJoint::isMotorEnabled() const
|
||||
{
|
||||
return joint->IsMotorEnabled();
|
||||
}
|
||||
|
||||
void RevoluteJoint::setMaxMotorTorque(float torque)
|
||||
{
|
||||
joint->SetMaxMotorTorque(Physics::scaleDown(Physics::scaleDown(torque)));
|
||||
}
|
||||
|
||||
void RevoluteJoint::setMotorSpeed(float speed)
|
||||
{
|
||||
joint->SetMotorSpeed(speed);
|
||||
}
|
||||
|
||||
float RevoluteJoint::getMotorSpeed() const
|
||||
{
|
||||
return joint->GetMotorSpeed();
|
||||
}
|
||||
|
||||
float RevoluteJoint::getMotorTorque(float inv_dt) const
|
||||
{
|
||||
return Physics::scaleUp(Physics::scaleUp(joint->GetMotorTorque(inv_dt)));
|
||||
}
|
||||
|
||||
float RevoluteJoint::getMaxMotorTorque() const
|
||||
{
|
||||
return Physics::scaleUp(Physics::scaleUp(joint->GetMaxMotorTorque()));
|
||||
}
|
||||
|
||||
void RevoluteJoint::enableLimit(bool limit)
|
||||
{
|
||||
joint->EnableLimit(limit);
|
||||
}
|
||||
|
||||
bool RevoluteJoint::isLimitEnabled() const
|
||||
{
|
||||
return joint->IsLimitEnabled();
|
||||
}
|
||||
|
||||
void RevoluteJoint::setUpperLimit(float limit)
|
||||
{
|
||||
joint->SetLimits(joint->GetLowerLimit(), limit);
|
||||
}
|
||||
|
||||
void RevoluteJoint::setLowerLimit(float limit)
|
||||
{
|
||||
joint->SetLimits(limit, joint->GetUpperLimit());
|
||||
}
|
||||
|
||||
void RevoluteJoint::setLimits(float lower, float upper)
|
||||
{
|
||||
joint->SetLimits(lower, upper);
|
||||
}
|
||||
|
||||
float RevoluteJoint::getLowerLimit() const
|
||||
{
|
||||
return joint->GetLowerLimit();
|
||||
}
|
||||
|
||||
float RevoluteJoint::getUpperLimit() const
|
||||
{
|
||||
return joint->GetUpperLimit();
|
||||
}
|
||||
|
||||
int RevoluteJoint::getLimits(lua_State *L)
|
||||
{
|
||||
lua_pushnumber(L, joint->GetLowerLimit());
|
||||
lua_pushnumber(L, joint->GetUpperLimit());
|
||||
return 2;
|
||||
}
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#include "RevoluteJoint.h"
|
||||
|
||||
#include "common/math.h"
|
||||
|
||||
// Module
|
||||
#include "Body.h"
|
||||
#include "World.h"
|
||||
#include "Physics.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
RevoluteJoint::RevoluteJoint(Body *body1, Body *body2, float x, float y, bool collideConnected)
|
||||
: Joint(body1, body2)
|
||||
, joint(NULL)
|
||||
{
|
||||
b2RevoluteJointDef def;
|
||||
def.Initialize(body1->body, body2->body, Physics::scaleDown(b2Vec2(x,y)));
|
||||
def.collideConnected = collideConnected;
|
||||
joint = (b2RevoluteJoint *)createJoint(&def);
|
||||
}
|
||||
|
||||
RevoluteJoint::~RevoluteJoint()
|
||||
{
|
||||
}
|
||||
|
||||
float RevoluteJoint::getJointAngle() const
|
||||
{
|
||||
return joint->GetJointAngle();
|
||||
}
|
||||
|
||||
float RevoluteJoint::getJointSpeed() const
|
||||
{
|
||||
return joint->GetJointSpeed();
|
||||
}
|
||||
|
||||
void RevoluteJoint::enableMotor(bool motor)
|
||||
{
|
||||
return joint->EnableMotor(motor);
|
||||
}
|
||||
|
||||
bool RevoluteJoint::isMotorEnabled() const
|
||||
{
|
||||
return joint->IsMotorEnabled();
|
||||
}
|
||||
|
||||
void RevoluteJoint::setMaxMotorTorque(float torque)
|
||||
{
|
||||
joint->SetMaxMotorTorque(Physics::scaleDown(Physics::scaleDown(torque)));
|
||||
}
|
||||
|
||||
void RevoluteJoint::setMotorSpeed(float speed)
|
||||
{
|
||||
joint->SetMotorSpeed(speed);
|
||||
}
|
||||
|
||||
float RevoluteJoint::getMotorSpeed() const
|
||||
{
|
||||
return joint->GetMotorSpeed();
|
||||
}
|
||||
|
||||
float RevoluteJoint::getMotorTorque(float inv_dt) const
|
||||
{
|
||||
return Physics::scaleUp(Physics::scaleUp(joint->GetMotorTorque(inv_dt)));
|
||||
}
|
||||
|
||||
float RevoluteJoint::getMaxMotorTorque() const
|
||||
{
|
||||
return Physics::scaleUp(Physics::scaleUp(joint->GetMaxMotorTorque()));
|
||||
}
|
||||
|
||||
void RevoluteJoint::enableLimit(bool limit)
|
||||
{
|
||||
joint->EnableLimit(limit);
|
||||
}
|
||||
|
||||
bool RevoluteJoint::isLimitEnabled() const
|
||||
{
|
||||
return joint->IsLimitEnabled();
|
||||
}
|
||||
|
||||
void RevoluteJoint::setUpperLimit(float limit)
|
||||
{
|
||||
joint->SetLimits(joint->GetLowerLimit(), limit);
|
||||
}
|
||||
|
||||
void RevoluteJoint::setLowerLimit(float limit)
|
||||
{
|
||||
joint->SetLimits(limit, joint->GetUpperLimit());
|
||||
}
|
||||
|
||||
void RevoluteJoint::setLimits(float lower, float upper)
|
||||
{
|
||||
joint->SetLimits(lower, upper);
|
||||
}
|
||||
|
||||
float RevoluteJoint::getLowerLimit() const
|
||||
{
|
||||
return joint->GetLowerLimit();
|
||||
}
|
||||
|
||||
float RevoluteJoint::getUpperLimit() const
|
||||
{
|
||||
return joint->GetUpperLimit();
|
||||
}
|
||||
|
||||
int RevoluteJoint::getLimits(lua_State *L)
|
||||
{
|
||||
lua_pushnumber(L, joint->GetLowerLimit());
|
||||
lua_pushnumber(L, joint->GetUpperLimit());
|
||||
return 2;
|
||||
}
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
@@ -1,147 +1,147 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_PHYSICS_BOX2D_REVOLUTE_JOINT_H
|
||||
#define LOVE_PHYSICS_BOX2D_REVOLUTE_JOINT_H
|
||||
|
||||
// Module
|
||||
#include "Joint.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
/**
|
||||
* A RevoluteJoint allows two bodies relative rotation
|
||||
* around a single point.
|
||||
**/
|
||||
class RevoluteJoint : public Joint
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Creates a new RevoluteJoint connecting body1 and body2.
|
||||
**/
|
||||
RevoluteJoint(Body *body1, Body *body2, float x, float y, bool collideConnected);
|
||||
|
||||
virtual ~RevoluteJoint();
|
||||
|
||||
/**
|
||||
* Get the current joint angle in degrees.
|
||||
**/
|
||||
float getJointAngle() const;
|
||||
|
||||
/**
|
||||
* Get the current joint angle speed in degrees per second.
|
||||
**/
|
||||
float getJointSpeed() const;
|
||||
|
||||
/**
|
||||
* Enable/disable the joint motor.
|
||||
**/
|
||||
void enableMotor(bool motor);
|
||||
|
||||
/**
|
||||
* Checks whether the motor is enabled.
|
||||
**/
|
||||
bool isMotorEnabled() const;
|
||||
|
||||
/**
|
||||
* Set the maximum motor torque, usually in N-m.
|
||||
**/
|
||||
void setMaxMotorTorque(float torque);
|
||||
|
||||
/**
|
||||
* Sets the motor speed in radians per second.
|
||||
**/
|
||||
void setMotorSpeed(float speed);
|
||||
|
||||
/**
|
||||
* Gets the motor speed in radians per second.
|
||||
**/
|
||||
float getMotorSpeed() const;
|
||||
|
||||
/**
|
||||
* Get the current motor torque, usually in N-m.
|
||||
* @param inv_dt The inverse timestep.
|
||||
**/
|
||||
float getMotorTorque(float inv_dt) const;
|
||||
|
||||
/**
|
||||
* Get the maximum motor torque, usually in N-m.
|
||||
**/
|
||||
float getMaxMotorTorque() const;
|
||||
|
||||
/**
|
||||
* Enable/disable the joint limit.
|
||||
**/
|
||||
void enableLimit(bool limit);
|
||||
|
||||
/**
|
||||
* Checks whether limits are enabled.
|
||||
**/
|
||||
bool isLimitEnabled() const;
|
||||
|
||||
/**
|
||||
* Sets the upper limit in degrees.
|
||||
**/
|
||||
void setUpperLimit(float limit);
|
||||
|
||||
/**
|
||||
* Sets the lower limit in degrees.
|
||||
**/
|
||||
void setLowerLimit(float limit);
|
||||
|
||||
/**
|
||||
* Sets the limits in degrees.
|
||||
**/
|
||||
void setLimits(float lower, float upper);
|
||||
|
||||
/**
|
||||
* Gets the lower limit in degrees.
|
||||
**/
|
||||
float getLowerLimit() const;
|
||||
|
||||
/**
|
||||
* Gets the upper limit in degrees.
|
||||
**/
|
||||
float getUpperLimit() const;
|
||||
|
||||
/**
|
||||
* Gets the limits in degrees.
|
||||
* @returns The lower limit.
|
||||
* @returns The upper limit.
|
||||
**/
|
||||
int getLimits(lua_State *L);
|
||||
|
||||
private:
|
||||
|
||||
// The Box2D revolute joint object.
|
||||
b2RevoluteJoint *joint;
|
||||
};
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_REVOLUTE_JOINT_H
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_PHYSICS_BOX2D_REVOLUTE_JOINT_H
|
||||
#define LOVE_PHYSICS_BOX2D_REVOLUTE_JOINT_H
|
||||
|
||||
// Module
|
||||
#include "Joint.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
/**
|
||||
* A RevoluteJoint allows two bodies relative rotation
|
||||
* around a single point.
|
||||
**/
|
||||
class RevoluteJoint : public Joint
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Creates a new RevoluteJoint connecting body1 and body2.
|
||||
**/
|
||||
RevoluteJoint(Body *body1, Body *body2, float x, float y, bool collideConnected);
|
||||
|
||||
virtual ~RevoluteJoint();
|
||||
|
||||
/**
|
||||
* Get the current joint angle in degrees.
|
||||
**/
|
||||
float getJointAngle() const;
|
||||
|
||||
/**
|
||||
* Get the current joint angle speed in degrees per second.
|
||||
**/
|
||||
float getJointSpeed() const;
|
||||
|
||||
/**
|
||||
* Enable/disable the joint motor.
|
||||
**/
|
||||
void enableMotor(bool motor);
|
||||
|
||||
/**
|
||||
* Checks whether the motor is enabled.
|
||||
**/
|
||||
bool isMotorEnabled() const;
|
||||
|
||||
/**
|
||||
* Set the maximum motor torque, usually in N-m.
|
||||
**/
|
||||
void setMaxMotorTorque(float torque);
|
||||
|
||||
/**
|
||||
* Sets the motor speed in radians per second.
|
||||
**/
|
||||
void setMotorSpeed(float speed);
|
||||
|
||||
/**
|
||||
* Gets the motor speed in radians per second.
|
||||
**/
|
||||
float getMotorSpeed() const;
|
||||
|
||||
/**
|
||||
* Get the current motor torque, usually in N-m.
|
||||
* @param inv_dt The inverse timestep.
|
||||
**/
|
||||
float getMotorTorque(float inv_dt) const;
|
||||
|
||||
/**
|
||||
* Get the maximum motor torque, usually in N-m.
|
||||
**/
|
||||
float getMaxMotorTorque() const;
|
||||
|
||||
/**
|
||||
* Enable/disable the joint limit.
|
||||
**/
|
||||
void enableLimit(bool limit);
|
||||
|
||||
/**
|
||||
* Checks whether limits are enabled.
|
||||
**/
|
||||
bool isLimitEnabled() const;
|
||||
|
||||
/**
|
||||
* Sets the upper limit in degrees.
|
||||
**/
|
||||
void setUpperLimit(float limit);
|
||||
|
||||
/**
|
||||
* Sets the lower limit in degrees.
|
||||
**/
|
||||
void setLowerLimit(float limit);
|
||||
|
||||
/**
|
||||
* Sets the limits in degrees.
|
||||
**/
|
||||
void setLimits(float lower, float upper);
|
||||
|
||||
/**
|
||||
* Gets the lower limit in degrees.
|
||||
**/
|
||||
float getLowerLimit() const;
|
||||
|
||||
/**
|
||||
* Gets the upper limit in degrees.
|
||||
**/
|
||||
float getUpperLimit() const;
|
||||
|
||||
/**
|
||||
* Gets the limits in degrees.
|
||||
* @returns The lower limit.
|
||||
* @returns The upper limit.
|
||||
**/
|
||||
int getLimits(lua_State *L);
|
||||
|
||||
private:
|
||||
|
||||
// The Box2D revolute joint object.
|
||||
b2RevoluteJoint *joint;
|
||||
};
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_REVOLUTE_JOINT_H
|
||||
|
||||
@@ -1,65 +1,65 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#include "RopeJoint.h"
|
||||
|
||||
// Module
|
||||
#include "Body.h"
|
||||
#include "World.h"
|
||||
#include "Physics.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
RopeJoint::RopeJoint(Body *body1, Body *body2, float x1, float y1, float x2, float y2, float maxLength, bool collideConnected)
|
||||
: Joint(body1, body2)
|
||||
, joint(NULL)
|
||||
{
|
||||
b2RopeJointDef def;
|
||||
def.bodyA = body1->body;
|
||||
def.bodyB = body2->body;
|
||||
body1->getLocalPoint(x1, y1, x1, y1);
|
||||
body2->getLocalPoint(x2, y2, x2, y2);
|
||||
def.localAnchorA.x = Physics::scaleDown(x1);
|
||||
def.localAnchorA.y = Physics::scaleDown(y1);
|
||||
def.localAnchorB.x = Physics::scaleDown(x2);
|
||||
def.localAnchorB.y = Physics::scaleDown(y2);
|
||||
def.maxLength = Physics::scaleDown(maxLength);
|
||||
def.collideConnected = collideConnected;
|
||||
joint = (b2RopeJoint *)createJoint(&def);
|
||||
}
|
||||
|
||||
RopeJoint::~RopeJoint()
|
||||
{
|
||||
}
|
||||
|
||||
float RopeJoint::getMaxLength() const
|
||||
{
|
||||
return Physics::scaleUp(joint->GetMaxLength());
|
||||
}
|
||||
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#include "RopeJoint.h"
|
||||
|
||||
// Module
|
||||
#include "Body.h"
|
||||
#include "World.h"
|
||||
#include "Physics.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
RopeJoint::RopeJoint(Body *body1, Body *body2, float x1, float y1, float x2, float y2, float maxLength, bool collideConnected)
|
||||
: Joint(body1, body2)
|
||||
, joint(NULL)
|
||||
{
|
||||
b2RopeJointDef def;
|
||||
def.bodyA = body1->body;
|
||||
def.bodyB = body2->body;
|
||||
body1->getLocalPoint(x1, y1, x1, y1);
|
||||
body2->getLocalPoint(x2, y2, x2, y2);
|
||||
def.localAnchorA.x = Physics::scaleDown(x1);
|
||||
def.localAnchorA.y = Physics::scaleDown(y1);
|
||||
def.localAnchorB.x = Physics::scaleDown(x2);
|
||||
def.localAnchorB.y = Physics::scaleDown(y2);
|
||||
def.maxLength = Physics::scaleDown(maxLength);
|
||||
def.collideConnected = collideConnected;
|
||||
joint = (b2RopeJoint *)createJoint(&def);
|
||||
}
|
||||
|
||||
RopeJoint::~RopeJoint()
|
||||
{
|
||||
}
|
||||
|
||||
float RopeJoint::getMaxLength() const
|
||||
{
|
||||
return Physics::scaleUp(joint->GetMaxLength());
|
||||
}
|
||||
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
@@ -1,63 +1,63 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_PHYSICS_BOX2D_ROPE_JOINT_H
|
||||
#define LOVE_PHYSICS_BOX2D_ROPE_JOINT_H
|
||||
|
||||
// Module
|
||||
#include "Joint.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
/**
|
||||
* The RopeJoint enforces a maximum distance between two points
|
||||
* on two bodies. It has no other effect.
|
||||
**/
|
||||
class RopeJoint : public Joint
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Creates a RopeJoint connecting body1 to body2.
|
||||
**/
|
||||
RopeJoint(Body *body1, Body *body2, float x1, float y1, float x2, float y2, float maxLength, bool collideConnected);
|
||||
|
||||
virtual ~RopeJoint();
|
||||
|
||||
/**
|
||||
* Gets the maximum length of the rope.
|
||||
**/
|
||||
float getMaxLength() const;
|
||||
|
||||
private:
|
||||
// The Box2D RopeJoint object.
|
||||
b2RopeJoint *joint;
|
||||
};
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_ROPE_JOINT_H
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_PHYSICS_BOX2D_ROPE_JOINT_H
|
||||
#define LOVE_PHYSICS_BOX2D_ROPE_JOINT_H
|
||||
|
||||
// Module
|
||||
#include "Joint.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
/**
|
||||
* The RopeJoint enforces a maximum distance between two points
|
||||
* on two bodies. It has no other effect.
|
||||
**/
|
||||
class RopeJoint : public Joint
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Creates a RopeJoint connecting body1 to body2.
|
||||
**/
|
||||
RopeJoint(Body *body1, Body *body2, float x1, float y1, float x2, float y2, float maxLength, bool collideConnected);
|
||||
|
||||
virtual ~RopeJoint();
|
||||
|
||||
/**
|
||||
* Gets the maximum length of the rope.
|
||||
**/
|
||||
float getMaxLength() const;
|
||||
|
||||
private:
|
||||
// The Box2D RopeJoint object.
|
||||
b2RopeJoint *joint;
|
||||
};
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_ROPE_JOINT_H
|
||||
|
||||
+155
-155
@@ -1,155 +1,155 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#include "Shape.h"
|
||||
|
||||
// Module
|
||||
#include "Body.h"
|
||||
#include "World.h"
|
||||
#include "Physics.h"
|
||||
|
||||
#include "common/Memoizer.h"
|
||||
|
||||
// STD
|
||||
#include <bitset>
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
Shape::Shape()
|
||||
: shape(NULL)
|
||||
, own(false)
|
||||
{
|
||||
}
|
||||
|
||||
Shape::Shape(b2Shape *shape, bool own)
|
||||
: shape(shape)
|
||||
, own(own)
|
||||
{
|
||||
if (own)
|
||||
Memoizer::add(shape, this);
|
||||
}
|
||||
|
||||
Shape::~Shape()
|
||||
{
|
||||
if (shape && own)
|
||||
{
|
||||
Memoizer::remove(shape);
|
||||
delete shape;
|
||||
}
|
||||
shape = 0;
|
||||
}
|
||||
|
||||
Shape::Type Shape::getType() const
|
||||
{
|
||||
switch (shape->GetType())
|
||||
{
|
||||
case b2Shape::e_circle:
|
||||
return SHAPE_CIRCLE;
|
||||
case b2Shape::e_polygon:
|
||||
return SHAPE_POLYGON;
|
||||
case b2Shape::e_edge:
|
||||
return SHAPE_EDGE;
|
||||
case b2Shape::e_chain:
|
||||
return SHAPE_CHAIN;
|
||||
default:
|
||||
return SHAPE_INVALID;
|
||||
}
|
||||
}
|
||||
|
||||
float Shape::getRadius() const
|
||||
{
|
||||
return Physics::scaleUp(shape->m_radius);
|
||||
}
|
||||
|
||||
int Shape::getChildCount() const
|
||||
{
|
||||
return shape->GetChildCount();
|
||||
}
|
||||
|
||||
bool Shape::testPoint(float x, float y, float r, float px, float py) const
|
||||
{
|
||||
b2Vec2 point(px, py);
|
||||
b2Transform transform(Physics::scaleDown(b2Vec2(x, y)), b2Rot(r));
|
||||
return shape->TestPoint(transform, Physics::scaleDown(point));
|
||||
}
|
||||
|
||||
int Shape::rayCast(lua_State *L) const
|
||||
{
|
||||
float p1x = Physics::scaleDown((float)luaL_checknumber(L, 1));
|
||||
float p1y = Physics::scaleDown((float)luaL_checknumber(L, 2));
|
||||
float p2x = Physics::scaleDown((float)luaL_checknumber(L, 3));
|
||||
float p2y = Physics::scaleDown((float)luaL_checknumber(L, 4));
|
||||
float maxFraction = (float)luaL_checknumber(L, 5);
|
||||
float x = Physics::scaleDown((float)luaL_checknumber(L, 6));
|
||||
float y = Physics::scaleDown((float)luaL_checknumber(L, 7));
|
||||
float r = (float)luaL_checknumber(L, 8);
|
||||
int childIndex = (int)luaL_optint(L, 9, 1) - 1; // Convert from 1-based index
|
||||
b2RayCastInput input;
|
||||
input.p1.Set(p1x, p1y);
|
||||
input.p2.Set(p2x, p2y);
|
||||
input.maxFraction = maxFraction;
|
||||
b2Transform transform(b2Vec2(x, y), b2Rot(r));
|
||||
b2RayCastOutput output;
|
||||
if (!shape->RayCast(&output, input, transform, childIndex))
|
||||
return 0; // No hit.
|
||||
lua_pushnumber(L, output.normal.x);
|
||||
lua_pushnumber(L, output.normal.y);
|
||||
lua_pushnumber(L, output.fraction);
|
||||
return 3;
|
||||
}
|
||||
|
||||
int Shape::computeAABB(lua_State *L) const
|
||||
{
|
||||
float x = Physics::scaleDown((float)luaL_checknumber(L, 1));
|
||||
float y = Physics::scaleDown((float)luaL_checknumber(L, 2));
|
||||
float r = (float)luaL_checknumber(L, 3);
|
||||
int childIndex = (int)luaL_optint(L, 4, 1) - 1; // Convert from 1-based index
|
||||
b2Transform transform(b2Vec2(x, y), b2Rot(r));
|
||||
b2AABB box;
|
||||
shape->ComputeAABB(&box, transform, childIndex);
|
||||
box = Physics::scaleUp(box);
|
||||
lua_pushnumber(L, box.lowerBound.x);
|
||||
lua_pushnumber(L, box.lowerBound.y);
|
||||
lua_pushnumber(L, box.upperBound.x);
|
||||
lua_pushnumber(L, box.upperBound.y);
|
||||
return 4;
|
||||
}
|
||||
|
||||
int Shape::computeMass(lua_State *L) const
|
||||
{
|
||||
float density = (float)luaL_checknumber(L, 1);
|
||||
b2MassData data;
|
||||
shape->ComputeMass(&data, density);
|
||||
b2Vec2 center = Physics::scaleUp(data.center);
|
||||
lua_pushnumber(L, center.x);
|
||||
lua_pushnumber(L, center.y);
|
||||
lua_pushnumber(L, data.mass);
|
||||
lua_pushnumber(L, Physics::scaleUp(Physics::scaleUp(data.I)));
|
||||
return 4;
|
||||
}
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#include "Shape.h"
|
||||
|
||||
// Module
|
||||
#include "Body.h"
|
||||
#include "World.h"
|
||||
#include "Physics.h"
|
||||
|
||||
#include "common/Memoizer.h"
|
||||
|
||||
// STD
|
||||
#include <bitset>
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
Shape::Shape()
|
||||
: shape(NULL)
|
||||
, own(false)
|
||||
{
|
||||
}
|
||||
|
||||
Shape::Shape(b2Shape *shape, bool own)
|
||||
: shape(shape)
|
||||
, own(own)
|
||||
{
|
||||
if (own)
|
||||
Memoizer::add(shape, this);
|
||||
}
|
||||
|
||||
Shape::~Shape()
|
||||
{
|
||||
if (shape && own)
|
||||
{
|
||||
Memoizer::remove(shape);
|
||||
delete shape;
|
||||
}
|
||||
shape = 0;
|
||||
}
|
||||
|
||||
Shape::Type Shape::getType() const
|
||||
{
|
||||
switch (shape->GetType())
|
||||
{
|
||||
case b2Shape::e_circle:
|
||||
return SHAPE_CIRCLE;
|
||||
case b2Shape::e_polygon:
|
||||
return SHAPE_POLYGON;
|
||||
case b2Shape::e_edge:
|
||||
return SHAPE_EDGE;
|
||||
case b2Shape::e_chain:
|
||||
return SHAPE_CHAIN;
|
||||
default:
|
||||
return SHAPE_INVALID;
|
||||
}
|
||||
}
|
||||
|
||||
float Shape::getRadius() const
|
||||
{
|
||||
return Physics::scaleUp(shape->m_radius);
|
||||
}
|
||||
|
||||
int Shape::getChildCount() const
|
||||
{
|
||||
return shape->GetChildCount();
|
||||
}
|
||||
|
||||
bool Shape::testPoint(float x, float y, float r, float px, float py) const
|
||||
{
|
||||
b2Vec2 point(px, py);
|
||||
b2Transform transform(Physics::scaleDown(b2Vec2(x, y)), b2Rot(r));
|
||||
return shape->TestPoint(transform, Physics::scaleDown(point));
|
||||
}
|
||||
|
||||
int Shape::rayCast(lua_State *L) const
|
||||
{
|
||||
float p1x = Physics::scaleDown((float)luaL_checknumber(L, 1));
|
||||
float p1y = Physics::scaleDown((float)luaL_checknumber(L, 2));
|
||||
float p2x = Physics::scaleDown((float)luaL_checknumber(L, 3));
|
||||
float p2y = Physics::scaleDown((float)luaL_checknumber(L, 4));
|
||||
float maxFraction = (float)luaL_checknumber(L, 5);
|
||||
float x = Physics::scaleDown((float)luaL_checknumber(L, 6));
|
||||
float y = Physics::scaleDown((float)luaL_checknumber(L, 7));
|
||||
float r = (float)luaL_checknumber(L, 8);
|
||||
int childIndex = (int)luaL_optint(L, 9, 1) - 1; // Convert from 1-based index
|
||||
b2RayCastInput input;
|
||||
input.p1.Set(p1x, p1y);
|
||||
input.p2.Set(p2x, p2y);
|
||||
input.maxFraction = maxFraction;
|
||||
b2Transform transform(b2Vec2(x, y), b2Rot(r));
|
||||
b2RayCastOutput output;
|
||||
if (!shape->RayCast(&output, input, transform, childIndex))
|
||||
return 0; // No hit.
|
||||
lua_pushnumber(L, output.normal.x);
|
||||
lua_pushnumber(L, output.normal.y);
|
||||
lua_pushnumber(L, output.fraction);
|
||||
return 3;
|
||||
}
|
||||
|
||||
int Shape::computeAABB(lua_State *L) const
|
||||
{
|
||||
float x = Physics::scaleDown((float)luaL_checknumber(L, 1));
|
||||
float y = Physics::scaleDown((float)luaL_checknumber(L, 2));
|
||||
float r = (float)luaL_checknumber(L, 3);
|
||||
int childIndex = (int)luaL_optint(L, 4, 1) - 1; // Convert from 1-based index
|
||||
b2Transform transform(b2Vec2(x, y), b2Rot(r));
|
||||
b2AABB box;
|
||||
shape->ComputeAABB(&box, transform, childIndex);
|
||||
box = Physics::scaleUp(box);
|
||||
lua_pushnumber(L, box.lowerBound.x);
|
||||
lua_pushnumber(L, box.lowerBound.y);
|
||||
lua_pushnumber(L, box.upperBound.x);
|
||||
lua_pushnumber(L, box.upperBound.y);
|
||||
return 4;
|
||||
}
|
||||
|
||||
int Shape::computeMass(lua_State *L) const
|
||||
{
|
||||
float density = (float)luaL_checknumber(L, 1);
|
||||
b2MassData data;
|
||||
shape->ComputeMass(&data, density);
|
||||
b2Vec2 center = Physics::scaleUp(data.center);
|
||||
lua_pushnumber(L, center.x);
|
||||
lua_pushnumber(L, center.y);
|
||||
lua_pushnumber(L, data.mass);
|
||||
lua_pushnumber(L, Physics::scaleUp(Physics::scaleUp(data.I)));
|
||||
return 4;
|
||||
}
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
@@ -1,82 +1,82 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_PHYSICS_BOX2D_SHAPE_H
|
||||
#define LOVE_PHYSICS_BOX2D_SHAPE_H
|
||||
|
||||
// LOVE
|
||||
#include "physics/Shape.h"
|
||||
#include "physics/box2d/Body.h"
|
||||
#include "common/Reference.h"
|
||||
|
||||
// Box2D
|
||||
#include <Box2D/Box2D.h>
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
/**
|
||||
* A Shape is geometry, attached to a Body via a Fixture.
|
||||
* A Body has position and orientation, and
|
||||
* a Shape's geometry will be affected by the parent
|
||||
* body's transformation.
|
||||
**/
|
||||
class Shape : public love::physics::Shape
|
||||
{
|
||||
public:
|
||||
|
||||
friend class Fixture;
|
||||
|
||||
/**
|
||||
* Creates a Shape.
|
||||
**/
|
||||
Shape();
|
||||
Shape(b2Shape *shape, bool own = true);
|
||||
|
||||
virtual ~Shape();
|
||||
|
||||
/**
|
||||
* Gets the type of Shape. Useful for
|
||||
* debug drawing.
|
||||
**/
|
||||
Type getType() const;
|
||||
float getRadius() const;
|
||||
int getChildCount() const;
|
||||
bool testPoint(float x, float y, float r, float px, float py) const;
|
||||
int rayCast(lua_State *L) const;
|
||||
int computeAABB(lua_State *L) const;
|
||||
int computeMass(lua_State *L) const;
|
||||
|
||||
protected:
|
||||
|
||||
// The Box2D shape.
|
||||
b2Shape *shape;
|
||||
bool own;
|
||||
};
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_SHAPE_H
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_PHYSICS_BOX2D_SHAPE_H
|
||||
#define LOVE_PHYSICS_BOX2D_SHAPE_H
|
||||
|
||||
// LOVE
|
||||
#include "physics/Shape.h"
|
||||
#include "physics/box2d/Body.h"
|
||||
#include "common/Reference.h"
|
||||
|
||||
// Box2D
|
||||
#include <Box2D/Box2D.h>
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
/**
|
||||
* A Shape is geometry, attached to a Body via a Fixture.
|
||||
* A Body has position and orientation, and
|
||||
* a Shape's geometry will be affected by the parent
|
||||
* body's transformation.
|
||||
**/
|
||||
class Shape : public love::physics::Shape
|
||||
{
|
||||
public:
|
||||
|
||||
friend class Fixture;
|
||||
|
||||
/**
|
||||
* Creates a Shape.
|
||||
**/
|
||||
Shape();
|
||||
Shape(b2Shape *shape, bool own = true);
|
||||
|
||||
virtual ~Shape();
|
||||
|
||||
/**
|
||||
* Gets the type of Shape. Useful for
|
||||
* debug drawing.
|
||||
**/
|
||||
Type getType() const;
|
||||
float getRadius() const;
|
||||
int getChildCount() const;
|
||||
bool testPoint(float x, float y, float r, float px, float py) const;
|
||||
int rayCast(lua_State *L) const;
|
||||
int computeAABB(lua_State *L) const;
|
||||
int computeMass(lua_State *L) const;
|
||||
|
||||
protected:
|
||||
|
||||
// The Box2D shape.
|
||||
b2Shape *shape;
|
||||
bool own;
|
||||
};
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_SHAPE_H
|
||||
|
||||
@@ -1,74 +1,74 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#include "WeldJoint.h"
|
||||
|
||||
#include "common/math.h"
|
||||
|
||||
// Module
|
||||
#include "Body.h"
|
||||
#include "World.h"
|
||||
#include "Physics.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
WeldJoint::WeldJoint(Body *body1, Body *body2, float xA, float yA, float xB, float yB, bool collideConnected)
|
||||
: Joint(body1, body2)
|
||||
, joint(NULL)
|
||||
{
|
||||
b2WeldJointDef def;
|
||||
def.Initialize(body1->body, body2->body, Physics::scaleDown(b2Vec2(xA,yA)));
|
||||
def.localAnchorB = body2->body->GetLocalPoint(Physics::scaleDown(b2Vec2(xB, yB)));
|
||||
def.collideConnected = collideConnected;
|
||||
joint = (b2WeldJoint *)createJoint(&def);
|
||||
}
|
||||
|
||||
WeldJoint::~WeldJoint()
|
||||
{
|
||||
}
|
||||
|
||||
void WeldJoint::setFrequency(float hz)
|
||||
{
|
||||
joint->SetFrequency(hz);
|
||||
}
|
||||
|
||||
float WeldJoint::getFrequency() const
|
||||
{
|
||||
return joint->GetFrequency();
|
||||
}
|
||||
|
||||
void WeldJoint::setDampingRatio(float d)
|
||||
{
|
||||
joint->SetDampingRatio(d);
|
||||
}
|
||||
|
||||
float WeldJoint::getDampingRatio() const
|
||||
{
|
||||
return joint->GetDampingRatio();
|
||||
}
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#include "WeldJoint.h"
|
||||
|
||||
#include "common/math.h"
|
||||
|
||||
// Module
|
||||
#include "Body.h"
|
||||
#include "World.h"
|
||||
#include "Physics.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
WeldJoint::WeldJoint(Body *body1, Body *body2, float xA, float yA, float xB, float yB, bool collideConnected)
|
||||
: Joint(body1, body2)
|
||||
, joint(NULL)
|
||||
{
|
||||
b2WeldJointDef def;
|
||||
def.Initialize(body1->body, body2->body, Physics::scaleDown(b2Vec2(xA,yA)));
|
||||
def.localAnchorB = body2->body->GetLocalPoint(Physics::scaleDown(b2Vec2(xB, yB)));
|
||||
def.collideConnected = collideConnected;
|
||||
joint = (b2WeldJoint *)createJoint(&def);
|
||||
}
|
||||
|
||||
WeldJoint::~WeldJoint()
|
||||
{
|
||||
}
|
||||
|
||||
void WeldJoint::setFrequency(float hz)
|
||||
{
|
||||
joint->SetFrequency(hz);
|
||||
}
|
||||
|
||||
float WeldJoint::getFrequency() const
|
||||
{
|
||||
return joint->GetFrequency();
|
||||
}
|
||||
|
||||
void WeldJoint::setDampingRatio(float d)
|
||||
{
|
||||
joint->SetDampingRatio(d);
|
||||
}
|
||||
|
||||
float WeldJoint::getDampingRatio() const
|
||||
{
|
||||
return joint->GetDampingRatio();
|
||||
}
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
@@ -1,80 +1,80 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_PHYSICS_BOX2D_WELD_JOINT_H
|
||||
#define LOVE_PHYSICS_BOX2D_WELD_JOINT_H
|
||||
|
||||
// Module
|
||||
#include "Joint.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
/**
|
||||
* A WeldJoint essentially glues two bodies together.
|
||||
**/
|
||||
class WeldJoint : public Joint
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Creates a new WeldJoint connecting body1 and body2.
|
||||
**/
|
||||
WeldJoint(Body *body1, Body *body2, float xA, float yA, float xB, float yB, bool collideConnected);
|
||||
|
||||
virtual ~WeldJoint();
|
||||
|
||||
/**
|
||||
* Sets the response speed.
|
||||
**/
|
||||
void setFrequency(float hz);
|
||||
|
||||
/**
|
||||
* Gets the response speed.
|
||||
**/
|
||||
float getFrequency() const;
|
||||
|
||||
/**
|
||||
* Sets the damping ratio.
|
||||
* 0 = no damping, 1 = critical damping.
|
||||
**/
|
||||
void setDampingRatio(float d);
|
||||
|
||||
/**
|
||||
* Gets the damping ratio.
|
||||
* 0 = no damping, 1 = critical damping.
|
||||
**/
|
||||
float getDampingRatio() const;
|
||||
|
||||
private:
|
||||
|
||||
// The Box2D weld joint object.
|
||||
b2WeldJoint *joint;
|
||||
};
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_WELD_JOINT_H
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_PHYSICS_BOX2D_WELD_JOINT_H
|
||||
#define LOVE_PHYSICS_BOX2D_WELD_JOINT_H
|
||||
|
||||
// Module
|
||||
#include "Joint.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
/**
|
||||
* A WeldJoint essentially glues two bodies together.
|
||||
**/
|
||||
class WeldJoint : public Joint
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Creates a new WeldJoint connecting body1 and body2.
|
||||
**/
|
||||
WeldJoint(Body *body1, Body *body2, float xA, float yA, float xB, float yB, bool collideConnected);
|
||||
|
||||
virtual ~WeldJoint();
|
||||
|
||||
/**
|
||||
* Sets the response speed.
|
||||
**/
|
||||
void setFrequency(float hz);
|
||||
|
||||
/**
|
||||
* Gets the response speed.
|
||||
**/
|
||||
float getFrequency() const;
|
||||
|
||||
/**
|
||||
* Sets the damping ratio.
|
||||
* 0 = no damping, 1 = critical damping.
|
||||
**/
|
||||
void setDampingRatio(float d);
|
||||
|
||||
/**
|
||||
* Gets the damping ratio.
|
||||
* 0 = no damping, 1 = critical damping.
|
||||
**/
|
||||
float getDampingRatio() const;
|
||||
|
||||
private:
|
||||
|
||||
// The Box2D weld joint object.
|
||||
b2WeldJoint *joint;
|
||||
};
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_WELD_JOINT_H
|
||||
|
||||
@@ -1,119 +1,119 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#include "WheelJoint.h"
|
||||
|
||||
// Module
|
||||
#include "Body.h"
|
||||
#include "World.h"
|
||||
#include "Physics.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
WheelJoint::WheelJoint(Body *body1, Body *body2, float xA, float yA, float xB, float yB, float ax, float ay, bool collideConnected)
|
||||
: Joint(body1, body2)
|
||||
, joint(NULL)
|
||||
{
|
||||
b2WheelJointDef def;
|
||||
|
||||
def.Initialize(body1->body, body2->body, Physics::scaleDown(b2Vec2(xA,yA)), b2Vec2(ax,ay));
|
||||
def.localAnchorB = body2->body->GetLocalPoint(Physics::scaleDown(b2Vec2(xB, yB)));
|
||||
def.collideConnected = collideConnected;
|
||||
joint = (b2WheelJoint *)createJoint(&def);
|
||||
}
|
||||
|
||||
WheelJoint::~WheelJoint()
|
||||
{
|
||||
}
|
||||
|
||||
float WheelJoint::getJointTranslation() const
|
||||
{
|
||||
return Physics::scaleUp(joint->GetJointTranslation());
|
||||
}
|
||||
|
||||
float WheelJoint::getJointSpeed() const
|
||||
{
|
||||
return Physics::scaleUp(joint->GetJointSpeed());
|
||||
}
|
||||
|
||||
void WheelJoint::enableMotor(bool motor)
|
||||
{
|
||||
return joint->EnableMotor(motor);
|
||||
}
|
||||
|
||||
bool WheelJoint::isMotorEnabled() const
|
||||
{
|
||||
return joint->IsMotorEnabled();
|
||||
}
|
||||
|
||||
void WheelJoint::setMotorSpeed(float speed)
|
||||
{
|
||||
joint->SetMotorSpeed(speed);
|
||||
}
|
||||
|
||||
float WheelJoint::getMotorSpeed() const
|
||||
{
|
||||
return joint->GetMotorSpeed();
|
||||
}
|
||||
|
||||
void WheelJoint::setMaxMotorTorque(float torque)
|
||||
{
|
||||
joint->SetMaxMotorTorque(Physics::scaleDown(Physics::scaleDown(torque)));
|
||||
}
|
||||
|
||||
float WheelJoint::getMaxMotorTorque() const
|
||||
{
|
||||
return Physics::scaleUp(Physics::scaleUp(joint->GetMaxMotorTorque()));
|
||||
}
|
||||
|
||||
float WheelJoint::getMotorTorque(float inv_dt) const
|
||||
{
|
||||
return Physics::scaleUp(Physics::scaleUp(joint->GetMotorTorque(inv_dt)));
|
||||
}
|
||||
|
||||
void WheelJoint::setSpringFrequency(float hz)
|
||||
{
|
||||
joint->SetSpringFrequencyHz(hz);
|
||||
}
|
||||
|
||||
float WheelJoint::getSpringFrequency() const
|
||||
{
|
||||
return joint->GetSpringFrequencyHz();
|
||||
}
|
||||
|
||||
void WheelJoint::setSpringDampingRatio(float ratio)
|
||||
{
|
||||
joint->SetSpringDampingRatio(ratio);
|
||||
}
|
||||
|
||||
float WheelJoint::getSpringDampingRatio() const
|
||||
{
|
||||
return joint->GetSpringDampingRatio();
|
||||
}
|
||||
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#include "WheelJoint.h"
|
||||
|
||||
// Module
|
||||
#include "Body.h"
|
||||
#include "World.h"
|
||||
#include "Physics.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
WheelJoint::WheelJoint(Body *body1, Body *body2, float xA, float yA, float xB, float yB, float ax, float ay, bool collideConnected)
|
||||
: Joint(body1, body2)
|
||||
, joint(NULL)
|
||||
{
|
||||
b2WheelJointDef def;
|
||||
|
||||
def.Initialize(body1->body, body2->body, Physics::scaleDown(b2Vec2(xA,yA)), b2Vec2(ax,ay));
|
||||
def.localAnchorB = body2->body->GetLocalPoint(Physics::scaleDown(b2Vec2(xB, yB)));
|
||||
def.collideConnected = collideConnected;
|
||||
joint = (b2WheelJoint *)createJoint(&def);
|
||||
}
|
||||
|
||||
WheelJoint::~WheelJoint()
|
||||
{
|
||||
}
|
||||
|
||||
float WheelJoint::getJointTranslation() const
|
||||
{
|
||||
return Physics::scaleUp(joint->GetJointTranslation());
|
||||
}
|
||||
|
||||
float WheelJoint::getJointSpeed() const
|
||||
{
|
||||
return Physics::scaleUp(joint->GetJointSpeed());
|
||||
}
|
||||
|
||||
void WheelJoint::enableMotor(bool motor)
|
||||
{
|
||||
return joint->EnableMotor(motor);
|
||||
}
|
||||
|
||||
bool WheelJoint::isMotorEnabled() const
|
||||
{
|
||||
return joint->IsMotorEnabled();
|
||||
}
|
||||
|
||||
void WheelJoint::setMotorSpeed(float speed)
|
||||
{
|
||||
joint->SetMotorSpeed(speed);
|
||||
}
|
||||
|
||||
float WheelJoint::getMotorSpeed() const
|
||||
{
|
||||
return joint->GetMotorSpeed();
|
||||
}
|
||||
|
||||
void WheelJoint::setMaxMotorTorque(float torque)
|
||||
{
|
||||
joint->SetMaxMotorTorque(Physics::scaleDown(Physics::scaleDown(torque)));
|
||||
}
|
||||
|
||||
float WheelJoint::getMaxMotorTorque() const
|
||||
{
|
||||
return Physics::scaleUp(Physics::scaleUp(joint->GetMaxMotorTorque()));
|
||||
}
|
||||
|
||||
float WheelJoint::getMotorTorque(float inv_dt) const
|
||||
{
|
||||
return Physics::scaleUp(Physics::scaleUp(joint->GetMotorTorque(inv_dt)));
|
||||
}
|
||||
|
||||
void WheelJoint::setSpringFrequency(float hz)
|
||||
{
|
||||
joint->SetSpringFrequencyHz(hz);
|
||||
}
|
||||
|
||||
float WheelJoint::getSpringFrequency() const
|
||||
{
|
||||
return joint->GetSpringFrequencyHz();
|
||||
}
|
||||
|
||||
void WheelJoint::setSpringDampingRatio(float ratio)
|
||||
{
|
||||
joint->SetSpringDampingRatio(ratio);
|
||||
}
|
||||
|
||||
float WheelJoint::getSpringDampingRatio() const
|
||||
{
|
||||
return joint->GetSpringDampingRatio();
|
||||
}
|
||||
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
@@ -1,127 +1,127 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_PHYSICS_BOX2D_WHEEL_JOINT_H
|
||||
#define LOVE_PHYSICS_BOX2D_WHEEL_JOINT_H
|
||||
|
||||
// Module
|
||||
#include "Joint.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
/**
|
||||
* WheelJoints provide two degrees of freedom: translation
|
||||
* along a defined axis and rotation in the plane. Designed
|
||||
* for vehicle suspensions.
|
||||
**/
|
||||
class WheelJoint : public Joint
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Creates a new WheelJoint connecting body1 and body2.
|
||||
**/
|
||||
WheelJoint(Body *body1, Body *body2, float xA, float yA, float xB, float yB, float ax, float ay, bool collideConnected);
|
||||
|
||||
virtual ~WheelJoint();
|
||||
|
||||
/**
|
||||
* Get the current joint translation, usually in meters.
|
||||
**/
|
||||
float getJointTranslation() const;
|
||||
|
||||
/**
|
||||
* Get the current joint translation speed, usually in meters per second.
|
||||
**/
|
||||
float getJointSpeed() const;
|
||||
|
||||
/**
|
||||
* Enable/disable the joint motor.
|
||||
**/
|
||||
void enableMotor(bool motor);
|
||||
|
||||
/**
|
||||
* Checks whether the motor is enabled.
|
||||
**/
|
||||
bool isMotorEnabled() const;
|
||||
|
||||
/**
|
||||
* Set the motor speed, usually in meters per second.
|
||||
**/
|
||||
void setMotorSpeed(float speed);
|
||||
|
||||
/**
|
||||
* Get the motor speed, usually in meters per second.
|
||||
**/
|
||||
float getMotorSpeed() const;
|
||||
|
||||
/**
|
||||
* Set the maximum motor torque, usually in N.
|
||||
**/
|
||||
void setMaxMotorTorque(float torque);
|
||||
|
||||
/**
|
||||
* Get the maximum motor torque, usually in N.
|
||||
**/
|
||||
float getMaxMotorTorque() const;
|
||||
|
||||
/**
|
||||
* Get the current motor torque, usually in N.
|
||||
* @param inv_dt The inverse time step.
|
||||
**/
|
||||
float getMotorTorque(float inv_dt) const;
|
||||
|
||||
/**
|
||||
* Set the spring frequency, in hertz. Setting the frequency to 0
|
||||
* disables the spring.
|
||||
**/
|
||||
void setSpringFrequency(float hz);
|
||||
|
||||
/**
|
||||
* Get the spring frequency, in hertz.
|
||||
**/
|
||||
float getSpringFrequency() const;
|
||||
|
||||
/**
|
||||
* Set the spring damping ratio.
|
||||
**/
|
||||
void setSpringDampingRatio(float ratio);
|
||||
|
||||
/**
|
||||
* Get the spring damping ratio.
|
||||
**/
|
||||
float getSpringDampingRatio() const;
|
||||
|
||||
private:
|
||||
|
||||
// The Box2D wheel joint object.
|
||||
b2WheelJoint *joint;
|
||||
};
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_WHEEL_JOINT_H
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_PHYSICS_BOX2D_WHEEL_JOINT_H
|
||||
#define LOVE_PHYSICS_BOX2D_WHEEL_JOINT_H
|
||||
|
||||
// Module
|
||||
#include "Joint.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
/**
|
||||
* WheelJoints provide two degrees of freedom: translation
|
||||
* along a defined axis and rotation in the plane. Designed
|
||||
* for vehicle suspensions.
|
||||
**/
|
||||
class WheelJoint : public Joint
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Creates a new WheelJoint connecting body1 and body2.
|
||||
**/
|
||||
WheelJoint(Body *body1, Body *body2, float xA, float yA, float xB, float yB, float ax, float ay, bool collideConnected);
|
||||
|
||||
virtual ~WheelJoint();
|
||||
|
||||
/**
|
||||
* Get the current joint translation, usually in meters.
|
||||
**/
|
||||
float getJointTranslation() const;
|
||||
|
||||
/**
|
||||
* Get the current joint translation speed, usually in meters per second.
|
||||
**/
|
||||
float getJointSpeed() const;
|
||||
|
||||
/**
|
||||
* Enable/disable the joint motor.
|
||||
**/
|
||||
void enableMotor(bool motor);
|
||||
|
||||
/**
|
||||
* Checks whether the motor is enabled.
|
||||
**/
|
||||
bool isMotorEnabled() const;
|
||||
|
||||
/**
|
||||
* Set the motor speed, usually in meters per second.
|
||||
**/
|
||||
void setMotorSpeed(float speed);
|
||||
|
||||
/**
|
||||
* Get the motor speed, usually in meters per second.
|
||||
**/
|
||||
float getMotorSpeed() const;
|
||||
|
||||
/**
|
||||
* Set the maximum motor torque, usually in N.
|
||||
**/
|
||||
void setMaxMotorTorque(float torque);
|
||||
|
||||
/**
|
||||
* Get the maximum motor torque, usually in N.
|
||||
**/
|
||||
float getMaxMotorTorque() const;
|
||||
|
||||
/**
|
||||
* Get the current motor torque, usually in N.
|
||||
* @param inv_dt The inverse time step.
|
||||
**/
|
||||
float getMotorTorque(float inv_dt) const;
|
||||
|
||||
/**
|
||||
* Set the spring frequency, in hertz. Setting the frequency to 0
|
||||
* disables the spring.
|
||||
**/
|
||||
void setSpringFrequency(float hz);
|
||||
|
||||
/**
|
||||
* Get the spring frequency, in hertz.
|
||||
**/
|
||||
float getSpringFrequency() const;
|
||||
|
||||
/**
|
||||
* Set the spring damping ratio.
|
||||
**/
|
||||
void setSpringDampingRatio(float ratio);
|
||||
|
||||
/**
|
||||
* Get the spring damping ratio.
|
||||
**/
|
||||
float getSpringDampingRatio() const;
|
||||
|
||||
private:
|
||||
|
||||
// The Box2D wheel joint object.
|
||||
b2WheelJoint *joint;
|
||||
};
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_WHEEL_JOINT_H
|
||||
|
||||
+551
-551
File diff suppressed because it is too large
Load Diff
+285
-285
@@ -1,285 +1,285 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_PHYSICS_BOX2D_WORLD_H
|
||||
#define LOVE_PHYSICS_BOX2D_WORLD_H
|
||||
|
||||
// LOVE
|
||||
#include "common/Object.h"
|
||||
#include "common/runtime.h"
|
||||
#include "common/Reference.h"
|
||||
|
||||
// STD
|
||||
#include <vector>
|
||||
|
||||
// Box2D
|
||||
#include <Box2D/Box2D.h>
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
class Contact;
|
||||
class Body;
|
||||
class Fixture;
|
||||
class Joint;
|
||||
|
||||
/**
|
||||
* The World is the "God" container class,
|
||||
* which contains all Bodies and Joints. Shapes
|
||||
* are contained in their associated Body.
|
||||
*
|
||||
* Bodies in different worlds can obviously not
|
||||
* collide.
|
||||
*
|
||||
* The world also controls global parameters, like
|
||||
* gravity.
|
||||
**/
|
||||
class World : public Object, public b2ContactListener, public b2ContactFilter, public b2DestructionListener
|
||||
{
|
||||
public:
|
||||
|
||||
// Friends.
|
||||
friend class Joint;
|
||||
friend class DistanceJoint;
|
||||
friend class MouseJoint;
|
||||
friend class Body;
|
||||
friend class Fixture;
|
||||
|
||||
class ContactCallback
|
||||
{
|
||||
public:
|
||||
Reference *ref;
|
||||
ContactCallback();
|
||||
~ContactCallback();
|
||||
void process(b2Contact *contact, const b2ContactImpulse *impulse = NULL);
|
||||
};
|
||||
|
||||
class ContactFilter
|
||||
{
|
||||
public:
|
||||
Reference *ref;
|
||||
ContactFilter();
|
||||
~ContactFilter();
|
||||
bool process(Fixture *a, Fixture *b);
|
||||
};
|
||||
|
||||
class QueryCallback : public b2QueryCallback
|
||||
{
|
||||
public:
|
||||
Reference *ref;
|
||||
QueryCallback();
|
||||
~QueryCallback();
|
||||
virtual bool ReportFixture(b2Fixture *fixture);
|
||||
};
|
||||
|
||||
class RayCastCallback : public b2RayCastCallback
|
||||
{
|
||||
public:
|
||||
Reference *ref;
|
||||
RayCastCallback();
|
||||
~RayCastCallback();
|
||||
virtual float32 ReportFixture(b2Fixture *fixture, const b2Vec2 &point, const b2Vec2 &normal, float32 fraction);
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates a new world.
|
||||
**/
|
||||
World();
|
||||
|
||||
/**
|
||||
* Creates a new world with the given gravity
|
||||
* and whether or not the bodies should sleep when appropriate.
|
||||
* @param gravity The gravity of the World.
|
||||
* @param sleep True if the bodies should be able to sleep,
|
||||
* false otherwise.
|
||||
**/
|
||||
World(b2Vec2 gravity, bool sleep);
|
||||
|
||||
virtual ~World();
|
||||
|
||||
/**
|
||||
* Updates everything in the world one timestep.
|
||||
* This is called update() and not step() to conform
|
||||
* with all other objects in LOVE.
|
||||
* @param dt The timestep.
|
||||
**/
|
||||
void update(float dt);
|
||||
|
||||
// From b2ContactListener
|
||||
void BeginContact(b2Contact *contact);
|
||||
void EndContact(b2Contact *contact);
|
||||
void PreSolve(b2Contact *contact, const b2Manifold *oldManifold);
|
||||
void PostSolve(b2Contact *contact, const b2ContactImpulse *impulse);
|
||||
|
||||
// From b2ContactFilter
|
||||
bool ShouldCollide(b2Fixture *fixtureA, b2Fixture *fixtureB);
|
||||
|
||||
// From b2DestructionListener
|
||||
void SayGoodbye(b2Fixture *fixture);
|
||||
void SayGoodbye(b2Joint *joint);
|
||||
|
||||
/**
|
||||
* Returns true if the Box2D world is alive.
|
||||
**/
|
||||
bool isValid() const;
|
||||
|
||||
/**
|
||||
* Receives up to four Lua functions as arguments. Each function is
|
||||
* collision callback for the four events (in order): begin, end,
|
||||
* presolve and postsolve. The value "nil" is accepted if one or
|
||||
* more events are uninteresting.
|
||||
**/
|
||||
int setCallbacks(lua_State *L);
|
||||
|
||||
/**
|
||||
* Returns the functions previously set by setCallbacks.
|
||||
**/
|
||||
int getCallbacks(lua_State *L);
|
||||
|
||||
/**
|
||||
* Sets the ContactFilter callback.
|
||||
**/
|
||||
int setContactFilter(lua_State *L);
|
||||
|
||||
/**
|
||||
* Gets the ContactFilter callback.
|
||||
**/
|
||||
int getContactFilter(lua_State *L);
|
||||
|
||||
/**
|
||||
* Sets the current gravity of the World.
|
||||
* @param x Gravity in the x-direction.
|
||||
* @param y Gravity in the y-direction.
|
||||
**/
|
||||
void setGravity(float x, float y);
|
||||
|
||||
/**
|
||||
* Gets the current gravity.
|
||||
* @returns Gravity in the x-direction.
|
||||
* @returns Gravity in the y-direction.
|
||||
**/
|
||||
int getGravity(lua_State *L);
|
||||
|
||||
/**
|
||||
* Sets whether this World allows sleep.
|
||||
* @param allow True to allow, false to disallow.
|
||||
**/
|
||||
void setAllowSleeping(bool allow);
|
||||
|
||||
/**
|
||||
* Returns whether this World allows sleep.
|
||||
* @return True if allowed, false if disallowed.
|
||||
**/
|
||||
bool getAllowSleeping() const;
|
||||
|
||||
/**
|
||||
* Returns whether this World is currently locked.
|
||||
* If it's locked, it's in the middle of a timestep.
|
||||
* @return Whether the World is locked.
|
||||
**/
|
||||
bool isLocked() const;
|
||||
|
||||
/**
|
||||
* Get the current body count.
|
||||
* @return The number of bodies.
|
||||
**/
|
||||
int getBodyCount() const;
|
||||
|
||||
/**
|
||||
* Get the current joint count.
|
||||
* @return The number of joints.
|
||||
**/
|
||||
int getJointCount() const;
|
||||
|
||||
/**
|
||||
* Get the current contact count.
|
||||
* @return The number of contacts.
|
||||
**/
|
||||
int getContactCount() const;
|
||||
|
||||
/**
|
||||
* Get an array of all the Bodies in the World.
|
||||
* @return An array of Bodies.
|
||||
**/
|
||||
int getBodyList(lua_State *L) const;
|
||||
|
||||
/**
|
||||
* Get an array of all the Joints in the World.
|
||||
* @return An array of Joints.
|
||||
**/
|
||||
int getJointList(lua_State *L) const;
|
||||
|
||||
/**
|
||||
* Get an array of all the Contacts in the World.
|
||||
* @return An array of Contacts.
|
||||
**/
|
||||
int getContactList(lua_State *L) const;
|
||||
|
||||
/**
|
||||
* Gets the ground body.
|
||||
* @return The ground body.
|
||||
**/
|
||||
b2Body *getGroundBody() const;
|
||||
|
||||
/**
|
||||
* Gets all fixtures that overlap a given bounding box.
|
||||
**/
|
||||
int queryBoundingBox(lua_State *L);
|
||||
|
||||
/**
|
||||
* Raycasts the World for all Fixtures in the path of the ray.
|
||||
**/
|
||||
int rayCast(lua_State *L);
|
||||
|
||||
/**
|
||||
* Destroy this world.
|
||||
**/
|
||||
void destroy();
|
||||
|
||||
private:
|
||||
|
||||
// Pointer to the Box2D world.
|
||||
b2World *world;
|
||||
|
||||
// Ground body
|
||||
b2Body *groundBody;
|
||||
|
||||
// The list of to be destructed bodies.
|
||||
std::vector<Body *> destructBodies;
|
||||
std::vector<Fixture *> destructFixtures;
|
||||
std::vector<Joint *> destructJoints;
|
||||
bool destructWorld;
|
||||
|
||||
// Contact callbacks.
|
||||
ContactCallback begin, end, presolve, postsolve;
|
||||
ContactFilter filter;
|
||||
QueryCallback query;
|
||||
RayCastCallback raycast;
|
||||
};
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_WORLD_H
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_PHYSICS_BOX2D_WORLD_H
|
||||
#define LOVE_PHYSICS_BOX2D_WORLD_H
|
||||
|
||||
// LOVE
|
||||
#include "common/Object.h"
|
||||
#include "common/runtime.h"
|
||||
#include "common/Reference.h"
|
||||
|
||||
// STD
|
||||
#include <vector>
|
||||
|
||||
// Box2D
|
||||
#include <Box2D/Box2D.h>
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
class Contact;
|
||||
class Body;
|
||||
class Fixture;
|
||||
class Joint;
|
||||
|
||||
/**
|
||||
* The World is the "God" container class,
|
||||
* which contains all Bodies and Joints. Shapes
|
||||
* are contained in their associated Body.
|
||||
*
|
||||
* Bodies in different worlds can obviously not
|
||||
* collide.
|
||||
*
|
||||
* The world also controls global parameters, like
|
||||
* gravity.
|
||||
**/
|
||||
class World : public Object, public b2ContactListener, public b2ContactFilter, public b2DestructionListener
|
||||
{
|
||||
public:
|
||||
|
||||
// Friends.
|
||||
friend class Joint;
|
||||
friend class DistanceJoint;
|
||||
friend class MouseJoint;
|
||||
friend class Body;
|
||||
friend class Fixture;
|
||||
|
||||
class ContactCallback
|
||||
{
|
||||
public:
|
||||
Reference *ref;
|
||||
ContactCallback();
|
||||
~ContactCallback();
|
||||
void process(b2Contact *contact, const b2ContactImpulse *impulse = NULL);
|
||||
};
|
||||
|
||||
class ContactFilter
|
||||
{
|
||||
public:
|
||||
Reference *ref;
|
||||
ContactFilter();
|
||||
~ContactFilter();
|
||||
bool process(Fixture *a, Fixture *b);
|
||||
};
|
||||
|
||||
class QueryCallback : public b2QueryCallback
|
||||
{
|
||||
public:
|
||||
Reference *ref;
|
||||
QueryCallback();
|
||||
~QueryCallback();
|
||||
virtual bool ReportFixture(b2Fixture *fixture);
|
||||
};
|
||||
|
||||
class RayCastCallback : public b2RayCastCallback
|
||||
{
|
||||
public:
|
||||
Reference *ref;
|
||||
RayCastCallback();
|
||||
~RayCastCallback();
|
||||
virtual float32 ReportFixture(b2Fixture *fixture, const b2Vec2 &point, const b2Vec2 &normal, float32 fraction);
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates a new world.
|
||||
**/
|
||||
World();
|
||||
|
||||
/**
|
||||
* Creates a new world with the given gravity
|
||||
* and whether or not the bodies should sleep when appropriate.
|
||||
* @param gravity The gravity of the World.
|
||||
* @param sleep True if the bodies should be able to sleep,
|
||||
* false otherwise.
|
||||
**/
|
||||
World(b2Vec2 gravity, bool sleep);
|
||||
|
||||
virtual ~World();
|
||||
|
||||
/**
|
||||
* Updates everything in the world one timestep.
|
||||
* This is called update() and not step() to conform
|
||||
* with all other objects in LOVE.
|
||||
* @param dt The timestep.
|
||||
**/
|
||||
void update(float dt);
|
||||
|
||||
// From b2ContactListener
|
||||
void BeginContact(b2Contact *contact);
|
||||
void EndContact(b2Contact *contact);
|
||||
void PreSolve(b2Contact *contact, const b2Manifold *oldManifold);
|
||||
void PostSolve(b2Contact *contact, const b2ContactImpulse *impulse);
|
||||
|
||||
// From b2ContactFilter
|
||||
bool ShouldCollide(b2Fixture *fixtureA, b2Fixture *fixtureB);
|
||||
|
||||
// From b2DestructionListener
|
||||
void SayGoodbye(b2Fixture *fixture);
|
||||
void SayGoodbye(b2Joint *joint);
|
||||
|
||||
/**
|
||||
* Returns true if the Box2D world is alive.
|
||||
**/
|
||||
bool isValid() const;
|
||||
|
||||
/**
|
||||
* Receives up to four Lua functions as arguments. Each function is
|
||||
* collision callback for the four events (in order): begin, end,
|
||||
* presolve and postsolve. The value "nil" is accepted if one or
|
||||
* more events are uninteresting.
|
||||
**/
|
||||
int setCallbacks(lua_State *L);
|
||||
|
||||
/**
|
||||
* Returns the functions previously set by setCallbacks.
|
||||
**/
|
||||
int getCallbacks(lua_State *L);
|
||||
|
||||
/**
|
||||
* Sets the ContactFilter callback.
|
||||
**/
|
||||
int setContactFilter(lua_State *L);
|
||||
|
||||
/**
|
||||
* Gets the ContactFilter callback.
|
||||
**/
|
||||
int getContactFilter(lua_State *L);
|
||||
|
||||
/**
|
||||
* Sets the current gravity of the World.
|
||||
* @param x Gravity in the x-direction.
|
||||
* @param y Gravity in the y-direction.
|
||||
**/
|
||||
void setGravity(float x, float y);
|
||||
|
||||
/**
|
||||
* Gets the current gravity.
|
||||
* @returns Gravity in the x-direction.
|
||||
* @returns Gravity in the y-direction.
|
||||
**/
|
||||
int getGravity(lua_State *L);
|
||||
|
||||
/**
|
||||
* Sets whether this World allows sleep.
|
||||
* @param allow True to allow, false to disallow.
|
||||
**/
|
||||
void setAllowSleeping(bool allow);
|
||||
|
||||
/**
|
||||
* Returns whether this World allows sleep.
|
||||
* @return True if allowed, false if disallowed.
|
||||
**/
|
||||
bool getAllowSleeping() const;
|
||||
|
||||
/**
|
||||
* Returns whether this World is currently locked.
|
||||
* If it's locked, it's in the middle of a timestep.
|
||||
* @return Whether the World is locked.
|
||||
**/
|
||||
bool isLocked() const;
|
||||
|
||||
/**
|
||||
* Get the current body count.
|
||||
* @return The number of bodies.
|
||||
**/
|
||||
int getBodyCount() const;
|
||||
|
||||
/**
|
||||
* Get the current joint count.
|
||||
* @return The number of joints.
|
||||
**/
|
||||
int getJointCount() const;
|
||||
|
||||
/**
|
||||
* Get the current contact count.
|
||||
* @return The number of contacts.
|
||||
**/
|
||||
int getContactCount() const;
|
||||
|
||||
/**
|
||||
* Get an array of all the Bodies in the World.
|
||||
* @return An array of Bodies.
|
||||
**/
|
||||
int getBodyList(lua_State *L) const;
|
||||
|
||||
/**
|
||||
* Get an array of all the Joints in the World.
|
||||
* @return An array of Joints.
|
||||
**/
|
||||
int getJointList(lua_State *L) const;
|
||||
|
||||
/**
|
||||
* Get an array of all the Contacts in the World.
|
||||
* @return An array of Contacts.
|
||||
**/
|
||||
int getContactList(lua_State *L) const;
|
||||
|
||||
/**
|
||||
* Gets the ground body.
|
||||
* @return The ground body.
|
||||
**/
|
||||
b2Body *getGroundBody() const;
|
||||
|
||||
/**
|
||||
* Gets all fixtures that overlap a given bounding box.
|
||||
**/
|
||||
int queryBoundingBox(lua_State *L);
|
||||
|
||||
/**
|
||||
* Raycasts the World for all Fixtures in the path of the ray.
|
||||
**/
|
||||
int rayCast(lua_State *L);
|
||||
|
||||
/**
|
||||
* Destroy this world.
|
||||
**/
|
||||
void destroy();
|
||||
|
||||
private:
|
||||
|
||||
// Pointer to the Box2D world.
|
||||
b2World *world;
|
||||
|
||||
// Ground body
|
||||
b2Body *groundBody;
|
||||
|
||||
// The list of to be destructed bodies.
|
||||
std::vector<Body *> destructBodies;
|
||||
std::vector<Fixture *> destructFixtures;
|
||||
std::vector<Joint *> destructJoints;
|
||||
bool destructWorld;
|
||||
|
||||
// Contact callbacks.
|
||||
ContactCallback begin, end, presolve, postsolve;
|
||||
ContactFilter filter;
|
||||
QueryCallback query;
|
||||
RayCastCallback raycast;
|
||||
};
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_WORLD_H
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,94 +1,94 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_PHYSICS_BOX2D_WRAP_BODY_H
|
||||
#define LOVE_PHYSICS_BOX2D_WRAP_BODY_H
|
||||
|
||||
// LOVE
|
||||
#include "common/runtime.h"
|
||||
#include "Body.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
Body *luax_checkbody(lua_State *L, int idx);
|
||||
int w_Body_getX(lua_State *L);
|
||||
int w_Body_getY(lua_State *L);
|
||||
int w_Body_getAngle(lua_State *L);
|
||||
int w_Body_getPosition(lua_State *L);
|
||||
int w_Body_getLinearVelocity(lua_State *L);
|
||||
int w_Body_getWorldCenter(lua_State *L);
|
||||
int w_Body_getLocalCenter(lua_State *L);
|
||||
int w_Body_getAngularVelocity(lua_State *L);
|
||||
int w_Body_getMass(lua_State *L);
|
||||
int w_Body_getInertia(lua_State *L);
|
||||
int w_Body_getMassData(lua_State *L);
|
||||
int w_Body_getAngularDamping(lua_State *L);
|
||||
int w_Body_getLinearDamping(lua_State *L);
|
||||
int w_Body_getGravityScale(lua_State *L);
|
||||
int w_Body_getType(lua_State *L);
|
||||
int w_Body_applyLinearImpulse(lua_State *L);
|
||||
int w_Body_applyAngularImpulse(lua_State *L);
|
||||
int w_Body_applyTorque(lua_State *L);
|
||||
int w_Body_applyForce(lua_State *L);
|
||||
int w_Body_setX(lua_State *L);
|
||||
int w_Body_setY(lua_State *L);
|
||||
int w_Body_setLinearVelocity(lua_State *L);
|
||||
int w_Body_setAngle(lua_State *L);
|
||||
int w_Body_setAngularVelocity(lua_State *L);
|
||||
int w_Body_setPosition(lua_State *L);
|
||||
int w_Body_resetMassData(lua_State *L);
|
||||
int w_Body_setMassData(lua_State *L);
|
||||
int w_Body_setMass(lua_State *L);
|
||||
int w_Body_setInertia(lua_State *L);
|
||||
int w_Body_setAngularDamping(lua_State *L);
|
||||
int w_Body_setLinearDamping(lua_State *L);
|
||||
int w_Body_setGravityScale(lua_State *L);
|
||||
int w_Body_setType(lua_State *L);
|
||||
int w_Body_getWorldPoint(lua_State *L);
|
||||
int w_Body_getWorldVector(lua_State *L);
|
||||
int w_Body_getWorldPoints(lua_State *L);
|
||||
int w_Body_getLocalPoint(lua_State *L);
|
||||
int w_Body_getLocalVector(lua_State *L);
|
||||
int w_Body_getLinearVelocityFromWorldPoint(lua_State *L);
|
||||
int w_Body_getLinearVelocityFromLocalPoint(lua_State *L);
|
||||
int w_Body_isBullet(lua_State *L);
|
||||
int w_Body_setBullet(lua_State *L);
|
||||
int w_Body_isActive(lua_State *L);
|
||||
int w_Body_isAwake(lua_State *L);
|
||||
int w_Body_setSleepingAllowed(lua_State *L);
|
||||
int w_Body_isSleepingAllowed(lua_State *L);
|
||||
int w_Body_setActive(lua_State *L);
|
||||
int w_Body_setAwake(lua_State *L);
|
||||
int w_Body_setFixedRotation(lua_State *L);
|
||||
int w_Body_isFixedRotation(lua_State *L);
|
||||
int w_Body_getFixtureList(lua_State *L);
|
||||
int w_Body_destroy(lua_State *L);
|
||||
extern "C" int luaopen_body(lua_State *L);
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_WRAP_BODY_H
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_PHYSICS_BOX2D_WRAP_BODY_H
|
||||
#define LOVE_PHYSICS_BOX2D_WRAP_BODY_H
|
||||
|
||||
// LOVE
|
||||
#include "common/runtime.h"
|
||||
#include "Body.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
Body *luax_checkbody(lua_State *L, int idx);
|
||||
int w_Body_getX(lua_State *L);
|
||||
int w_Body_getY(lua_State *L);
|
||||
int w_Body_getAngle(lua_State *L);
|
||||
int w_Body_getPosition(lua_State *L);
|
||||
int w_Body_getLinearVelocity(lua_State *L);
|
||||
int w_Body_getWorldCenter(lua_State *L);
|
||||
int w_Body_getLocalCenter(lua_State *L);
|
||||
int w_Body_getAngularVelocity(lua_State *L);
|
||||
int w_Body_getMass(lua_State *L);
|
||||
int w_Body_getInertia(lua_State *L);
|
||||
int w_Body_getMassData(lua_State *L);
|
||||
int w_Body_getAngularDamping(lua_State *L);
|
||||
int w_Body_getLinearDamping(lua_State *L);
|
||||
int w_Body_getGravityScale(lua_State *L);
|
||||
int w_Body_getType(lua_State *L);
|
||||
int w_Body_applyLinearImpulse(lua_State *L);
|
||||
int w_Body_applyAngularImpulse(lua_State *L);
|
||||
int w_Body_applyTorque(lua_State *L);
|
||||
int w_Body_applyForce(lua_State *L);
|
||||
int w_Body_setX(lua_State *L);
|
||||
int w_Body_setY(lua_State *L);
|
||||
int w_Body_setLinearVelocity(lua_State *L);
|
||||
int w_Body_setAngle(lua_State *L);
|
||||
int w_Body_setAngularVelocity(lua_State *L);
|
||||
int w_Body_setPosition(lua_State *L);
|
||||
int w_Body_resetMassData(lua_State *L);
|
||||
int w_Body_setMassData(lua_State *L);
|
||||
int w_Body_setMass(lua_State *L);
|
||||
int w_Body_setInertia(lua_State *L);
|
||||
int w_Body_setAngularDamping(lua_State *L);
|
||||
int w_Body_setLinearDamping(lua_State *L);
|
||||
int w_Body_setGravityScale(lua_State *L);
|
||||
int w_Body_setType(lua_State *L);
|
||||
int w_Body_getWorldPoint(lua_State *L);
|
||||
int w_Body_getWorldVector(lua_State *L);
|
||||
int w_Body_getWorldPoints(lua_State *L);
|
||||
int w_Body_getLocalPoint(lua_State *L);
|
||||
int w_Body_getLocalVector(lua_State *L);
|
||||
int w_Body_getLinearVelocityFromWorldPoint(lua_State *L);
|
||||
int w_Body_getLinearVelocityFromLocalPoint(lua_State *L);
|
||||
int w_Body_isBullet(lua_State *L);
|
||||
int w_Body_setBullet(lua_State *L);
|
||||
int w_Body_isActive(lua_State *L);
|
||||
int w_Body_isAwake(lua_State *L);
|
||||
int w_Body_setSleepingAllowed(lua_State *L);
|
||||
int w_Body_isSleepingAllowed(lua_State *L);
|
||||
int w_Body_setActive(lua_State *L);
|
||||
int w_Body_setAwake(lua_State *L);
|
||||
int w_Body_setFixedRotation(lua_State *L);
|
||||
int w_Body_isFixedRotation(lua_State *L);
|
||||
int w_Body_getFixtureList(lua_State *L);
|
||||
int w_Body_destroy(lua_State *L);
|
||||
extern "C" int luaopen_body(lua_State *L);
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_WRAP_BODY_H
|
||||
|
||||
@@ -1,131 +1,131 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#include "wrap_ChainShape.h"
|
||||
#include "wrap_Physics.h"
|
||||
#include "Physics.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
ChainShape *luax_checkchainshape(lua_State *L, int idx)
|
||||
{
|
||||
return luax_checktype<ChainShape>(L, idx, "ChainShape", PHYSICS_CHAIN_SHAPE_T);
|
||||
}
|
||||
|
||||
int w_ChainShape_setNextVertex(lua_State *L)
|
||||
{
|
||||
ChainShape *c = luax_checkchainshape(L, 1);
|
||||
float x = (float)luaL_checknumber(L, 2);
|
||||
float y = (float)luaL_checknumber(L, 3);
|
||||
c->setNextVertex(x, y);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_ChainShape_setPrevVertex(lua_State *L)
|
||||
{
|
||||
ChainShape *c = luax_checkchainshape(L, 1);
|
||||
float x = (float)luaL_checknumber(L, 2);
|
||||
float y = (float)luaL_checknumber(L, 3);
|
||||
c->setPrevVertex(x, y);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_ChainShape_getChildCount(lua_State *L)
|
||||
{
|
||||
ChainShape *c = luax_checkchainshape(L, 1);
|
||||
lua_pushinteger(L, c->getChildCount());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_ChainShape_getChildEdge(lua_State *L)
|
||||
{
|
||||
ChainShape *c = luax_checkchainshape(L, 1);
|
||||
int index = luaL_checkint(L, 2) - 1; // Convert from 1-based index
|
||||
EdgeShape *e = c->getChildEdge(index);
|
||||
luax_newtype(L, "EdgeShape", PHYSICS_EDGE_SHAPE_T, e);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_ChainShape_getVertexCount(lua_State *L)
|
||||
{
|
||||
ChainShape *c = luax_checkchainshape(L, 1);
|
||||
int count = c->getVertexCount();
|
||||
lua_pushinteger(L, count);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_ChainShape_getPoint(lua_State *L)
|
||||
{
|
||||
ChainShape *c = luax_checkchainshape(L, 1);
|
||||
int index = luaL_checkint(L, 2) - 1; // Convert from 1-based index
|
||||
b2Vec2 v;
|
||||
ASSERT_GUARD(v = c->getPoint(index);)
|
||||
lua_pushnumber(L, v.x);
|
||||
lua_pushnumber(L, v.y);
|
||||
return 2;
|
||||
}
|
||||
|
||||
int w_ChainShape_getPoints(lua_State *L)
|
||||
{
|
||||
ChainShape *c = luax_checkchainshape(L, 1);
|
||||
const b2Vec2 *verts = c->getPoints();
|
||||
int count = c->getVertexCount();
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
b2Vec2 v = Physics::scaleUp(verts[i]);
|
||||
lua_pushnumber(L, v.x);
|
||||
lua_pushnumber(L, v.y);
|
||||
}
|
||||
return count*2;
|
||||
}
|
||||
|
||||
static const luaL_Reg functions[] =
|
||||
{
|
||||
{ "setNextVertex", w_ChainShape_setNextVertex },
|
||||
{ "setPrevVertex", w_ChainShape_setPrevVertex },
|
||||
{ "getChildCount", w_ChainShape_getChildCount },
|
||||
{ "getChildEdge", w_ChainShape_getChildEdge },
|
||||
{ "getVertexCount", w_ChainShape_getVertexCount },
|
||||
{ "getPoint", w_ChainShape_getPoint },
|
||||
{ "getPoints", w_ChainShape_getPoints },
|
||||
// From Shape.
|
||||
{ "getType", w_Shape_getType },
|
||||
{ "getRadius", w_Shape_getRadius },
|
||||
{ "getChildCount", w_Shape_getChildCount },
|
||||
{ "testPoint", w_Shape_testPoint },
|
||||
{ "rayCast", w_Shape_rayCast },
|
||||
{ "computeAABB", w_Shape_computeAABB },
|
||||
{ "computeMass", w_Shape_computeMass },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
extern "C" int luaopen_chainshape(lua_State *L)
|
||||
{
|
||||
return luax_register_type(L, "ChainShape", functions);
|
||||
}
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#include "wrap_ChainShape.h"
|
||||
#include "wrap_Physics.h"
|
||||
#include "Physics.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
ChainShape *luax_checkchainshape(lua_State *L, int idx)
|
||||
{
|
||||
return luax_checktype<ChainShape>(L, idx, "ChainShape", PHYSICS_CHAIN_SHAPE_T);
|
||||
}
|
||||
|
||||
int w_ChainShape_setNextVertex(lua_State *L)
|
||||
{
|
||||
ChainShape *c = luax_checkchainshape(L, 1);
|
||||
float x = (float)luaL_checknumber(L, 2);
|
||||
float y = (float)luaL_checknumber(L, 3);
|
||||
c->setNextVertex(x, y);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_ChainShape_setPrevVertex(lua_State *L)
|
||||
{
|
||||
ChainShape *c = luax_checkchainshape(L, 1);
|
||||
float x = (float)luaL_checknumber(L, 2);
|
||||
float y = (float)luaL_checknumber(L, 3);
|
||||
c->setPrevVertex(x, y);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_ChainShape_getChildCount(lua_State *L)
|
||||
{
|
||||
ChainShape *c = luax_checkchainshape(L, 1);
|
||||
lua_pushinteger(L, c->getChildCount());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_ChainShape_getChildEdge(lua_State *L)
|
||||
{
|
||||
ChainShape *c = luax_checkchainshape(L, 1);
|
||||
int index = luaL_checkint(L, 2) - 1; // Convert from 1-based index
|
||||
EdgeShape *e = c->getChildEdge(index);
|
||||
luax_newtype(L, "EdgeShape", PHYSICS_EDGE_SHAPE_T, e);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_ChainShape_getVertexCount(lua_State *L)
|
||||
{
|
||||
ChainShape *c = luax_checkchainshape(L, 1);
|
||||
int count = c->getVertexCount();
|
||||
lua_pushinteger(L, count);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_ChainShape_getPoint(lua_State *L)
|
||||
{
|
||||
ChainShape *c = luax_checkchainshape(L, 1);
|
||||
int index = luaL_checkint(L, 2) - 1; // Convert from 1-based index
|
||||
b2Vec2 v;
|
||||
ASSERT_GUARD(v = c->getPoint(index);)
|
||||
lua_pushnumber(L, v.x);
|
||||
lua_pushnumber(L, v.y);
|
||||
return 2;
|
||||
}
|
||||
|
||||
int w_ChainShape_getPoints(lua_State *L)
|
||||
{
|
||||
ChainShape *c = luax_checkchainshape(L, 1);
|
||||
const b2Vec2 *verts = c->getPoints();
|
||||
int count = c->getVertexCount();
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
b2Vec2 v = Physics::scaleUp(verts[i]);
|
||||
lua_pushnumber(L, v.x);
|
||||
lua_pushnumber(L, v.y);
|
||||
}
|
||||
return count*2;
|
||||
}
|
||||
|
||||
static const luaL_Reg functions[] =
|
||||
{
|
||||
{ "setNextVertex", w_ChainShape_setNextVertex },
|
||||
{ "setPrevVertex", w_ChainShape_setPrevVertex },
|
||||
{ "getChildCount", w_ChainShape_getChildCount },
|
||||
{ "getChildEdge", w_ChainShape_getChildEdge },
|
||||
{ "getVertexCount", w_ChainShape_getVertexCount },
|
||||
{ "getPoint", w_ChainShape_getPoint },
|
||||
{ "getPoints", w_ChainShape_getPoints },
|
||||
// From Shape.
|
||||
{ "getType", w_Shape_getType },
|
||||
{ "getRadius", w_Shape_getRadius },
|
||||
{ "getChildCount", w_Shape_getChildCount },
|
||||
{ "testPoint", w_Shape_testPoint },
|
||||
{ "rayCast", w_Shape_rayCast },
|
||||
{ "computeAABB", w_Shape_computeAABB },
|
||||
{ "computeMass", w_Shape_computeMass },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
extern "C" int luaopen_chainshape(lua_State *L)
|
||||
{
|
||||
return luax_register_type(L, "ChainShape", functions);
|
||||
}
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
@@ -1,52 +1,52 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_PHYSICS_BOX2D_WRAP_CHAIN_SHAPE_H
|
||||
#define LOVE_PHYSICS_BOX2D_WRAP_CHAIN_SHAPE_H
|
||||
|
||||
// LOVE
|
||||
#include "common/runtime.h"
|
||||
#include "wrap_Shape.h"
|
||||
#include "ChainShape.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
ChainShape *luax_checkchainshape(lua_State *L, int idx);
|
||||
|
||||
int w_ChainShape_setNextVertex(lua_State *L);
|
||||
int w_ChainShape_setPrevVertex(lua_State *L);
|
||||
int w_ChainShape_getChildCount(lua_State *L);
|
||||
int w_ChainShape_getChildEdge(lua_State *L);
|
||||
int w_ChainShape_getVertexCount(lua_State *L);
|
||||
int w_ChainShape_getPoint(lua_State *L);
|
||||
int w_ChainShape_getPoints(lua_State *L);
|
||||
|
||||
extern "C" int luaopen_chainshape(lua_State *L);
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_WRAP_CHAIN_SHAPE_H
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_PHYSICS_BOX2D_WRAP_CHAIN_SHAPE_H
|
||||
#define LOVE_PHYSICS_BOX2D_WRAP_CHAIN_SHAPE_H
|
||||
|
||||
// LOVE
|
||||
#include "common/runtime.h"
|
||||
#include "wrap_Shape.h"
|
||||
#include "ChainShape.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
ChainShape *luax_checkchainshape(lua_State *L, int idx);
|
||||
|
||||
int w_ChainShape_setNextVertex(lua_State *L);
|
||||
int w_ChainShape_setPrevVertex(lua_State *L);
|
||||
int w_ChainShape_getChildCount(lua_State *L);
|
||||
int w_ChainShape_getChildEdge(lua_State *L);
|
||||
int w_ChainShape_getVertexCount(lua_State *L);
|
||||
int w_ChainShape_getPoint(lua_State *L);
|
||||
int w_ChainShape_getPoints(lua_State *L);
|
||||
|
||||
extern "C" int luaopen_chainshape(lua_State *L);
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_WRAP_CHAIN_SHAPE_H
|
||||
|
||||
@@ -1,72 +1,72 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#include "wrap_CircleShape.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
CircleShape *luax_checkcircleshape(lua_State *L, int idx)
|
||||
{
|
||||
return luax_checktype<CircleShape>(L, idx, "CircleShape", PHYSICS_CIRCLE_SHAPE_T);
|
||||
}
|
||||
|
||||
int w_CircleShape_getRadius(lua_State *L)
|
||||
{
|
||||
CircleShape *c = luax_checkcircleshape(L, 1);
|
||||
lua_pushnumber(L, c->getRadius());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_CircleShape_setRadius(lua_State *L)
|
||||
{
|
||||
CircleShape *c = luax_checkcircleshape(L, 1);
|
||||
float r = (float)luaL_checknumber(L, 2);
|
||||
c->setRadius(r);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const luaL_Reg functions[] =
|
||||
{
|
||||
{ "getRadius", w_CircleShape_getRadius },
|
||||
{ "setRadius", w_CircleShape_setRadius },
|
||||
// From Shape.
|
||||
{ "getType", w_Shape_getType },
|
||||
{ "getRadius", w_Shape_getRadius },
|
||||
{ "getChildCount", w_Shape_getChildCount },
|
||||
{ "testPoint", w_Shape_testPoint },
|
||||
{ "rayCast", w_Shape_rayCast },
|
||||
{ "computeAABB", w_Shape_computeAABB },
|
||||
{ "computeMass", w_Shape_computeMass },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
extern "C" int luaopen_circleshape(lua_State *L)
|
||||
{
|
||||
return luax_register_type(L, "CircleShape", functions);
|
||||
}
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#include "wrap_CircleShape.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
CircleShape *luax_checkcircleshape(lua_State *L, int idx)
|
||||
{
|
||||
return luax_checktype<CircleShape>(L, idx, "CircleShape", PHYSICS_CIRCLE_SHAPE_T);
|
||||
}
|
||||
|
||||
int w_CircleShape_getRadius(lua_State *L)
|
||||
{
|
||||
CircleShape *c = luax_checkcircleshape(L, 1);
|
||||
lua_pushnumber(L, c->getRadius());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_CircleShape_setRadius(lua_State *L)
|
||||
{
|
||||
CircleShape *c = luax_checkcircleshape(L, 1);
|
||||
float r = (float)luaL_checknumber(L, 2);
|
||||
c->setRadius(r);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const luaL_Reg functions[] =
|
||||
{
|
||||
{ "getRadius", w_CircleShape_getRadius },
|
||||
{ "setRadius", w_CircleShape_setRadius },
|
||||
// From Shape.
|
||||
{ "getType", w_Shape_getType },
|
||||
{ "getRadius", w_Shape_getRadius },
|
||||
{ "getChildCount", w_Shape_getChildCount },
|
||||
{ "testPoint", w_Shape_testPoint },
|
||||
{ "rayCast", w_Shape_rayCast },
|
||||
{ "computeAABB", w_Shape_computeAABB },
|
||||
{ "computeMass", w_Shape_computeMass },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
extern "C" int luaopen_circleshape(lua_State *L)
|
||||
{
|
||||
return luax_register_type(L, "CircleShape", functions);
|
||||
}
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
@@ -1,45 +1,45 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_PHYSICS_BOX2D_WRAP_CIRCLE_SHAPE_H
|
||||
#define LOVE_PHYSICS_BOX2D_WRAP_CIRCLE_SHAPE_H
|
||||
|
||||
// LOVE
|
||||
#include "common/runtime.h"
|
||||
#include "wrap_Shape.h"
|
||||
#include "CircleShape.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
CircleShape *luax_checkcircleshape(lua_State *L, int idx);
|
||||
int w_CircleShape_getRadius(lua_State *L);
|
||||
int w_CircleShape_setRadius(lua_State *L);
|
||||
extern "C" int luaopen_circleshape(lua_State *L);
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_WRAP_CIRCLE_SHAPE_H
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_PHYSICS_BOX2D_WRAP_CIRCLE_SHAPE_H
|
||||
#define LOVE_PHYSICS_BOX2D_WRAP_CIRCLE_SHAPE_H
|
||||
|
||||
// LOVE
|
||||
#include "common/runtime.h"
|
||||
#include "wrap_Shape.h"
|
||||
#include "CircleShape.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
CircleShape *luax_checkcircleshape(lua_State *L, int idx);
|
||||
int w_CircleShape_getRadius(lua_State *L);
|
||||
int w_CircleShape_setRadius(lua_State *L);
|
||||
extern "C" int luaopen_circleshape(lua_State *L);
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_WRAP_CIRCLE_SHAPE_H
|
||||
|
||||
@@ -1,136 +1,136 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#include "wrap_Contact.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
Contact *luax_checkcontact(lua_State *L, int idx)
|
||||
{
|
||||
return luax_checktype<Contact>(L, idx, "Contact", PHYSICS_CONTACT_T);
|
||||
}
|
||||
|
||||
int w_Contact_getPositions(lua_State *L)
|
||||
{
|
||||
Contact *t = luax_checkcontact(L, 1);
|
||||
return t->getPositions(L);
|
||||
}
|
||||
|
||||
int w_Contact_getNormal(lua_State *L)
|
||||
{
|
||||
Contact *t = luax_checkcontact(L, 1);
|
||||
return t->getNormal(L);
|
||||
}
|
||||
|
||||
int w_Contact_getFriction(lua_State *L)
|
||||
{
|
||||
Contact *t = luax_checkcontact(L, 1);
|
||||
lua_pushnumber(L, t->getFriction());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_Contact_getRestitution(lua_State *L)
|
||||
{
|
||||
Contact *t = luax_checkcontact(L, 1);
|
||||
lua_pushnumber(L, t->getRestitution());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_Contact_isEnabled(lua_State *L)
|
||||
{
|
||||
Contact *t = luax_checkcontact(L, 1);
|
||||
lua_pushboolean(L, t->isEnabled());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_Contact_isTouching(lua_State *L)
|
||||
{
|
||||
Contact *t = luax_checkcontact(L, 1);
|
||||
lua_pushboolean(L, t->isTouching());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_Contact_setFriction(lua_State *L)
|
||||
{
|
||||
Contact *t = luax_checkcontact(L, 1);
|
||||
float f = (float)luaL_checknumber(L, 2);
|
||||
t->setFriction(f);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_Contact_setRestitution(lua_State *L)
|
||||
{
|
||||
Contact *t = luax_checkcontact(L, 1);
|
||||
float r = (float)luaL_checknumber(L, 2);
|
||||
t->setRestitution(r);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_Contact_setEnabled(lua_State *L)
|
||||
{
|
||||
Contact *t = luax_checkcontact(L, 1);
|
||||
bool e = luax_toboolean(L, 2);
|
||||
t->setEnabled(e);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_Contact_resetFriction(lua_State *L)
|
||||
{
|
||||
Contact *t = luax_checkcontact(L, 1);
|
||||
t->resetFriction();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_Contact_resetRestitution(lua_State *L)
|
||||
{
|
||||
Contact *t = luax_checkcontact(L, 1);
|
||||
t->resetRestitution();
|
||||
return 0;
|
||||
}
|
||||
|
||||
extern "C" int luaopen_contact(lua_State *L)
|
||||
{
|
||||
static const luaL_Reg functions[] =
|
||||
{
|
||||
{ "getPositions", w_Contact_getPositions },
|
||||
{ "getNormal", w_Contact_getNormal },
|
||||
{ "getFriction", w_Contact_getFriction },
|
||||
{ "getRestitution", w_Contact_getRestitution },
|
||||
{ "isEnabled", w_Contact_isEnabled },
|
||||
{ "isTouching", w_Contact_isTouching },
|
||||
{ "setFriction", w_Contact_setFriction },
|
||||
{ "setRestitution", w_Contact_setRestitution },
|
||||
{ "setEnabled", w_Contact_setEnabled },
|
||||
{ "resetFriction", w_Contact_resetFriction },
|
||||
{ "resetRestitution", w_Contact_resetRestitution },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
return luax_register_type(L, "Contact", functions);
|
||||
}
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#include "wrap_Contact.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
Contact *luax_checkcontact(lua_State *L, int idx)
|
||||
{
|
||||
return luax_checktype<Contact>(L, idx, "Contact", PHYSICS_CONTACT_T);
|
||||
}
|
||||
|
||||
int w_Contact_getPositions(lua_State *L)
|
||||
{
|
||||
Contact *t = luax_checkcontact(L, 1);
|
||||
return t->getPositions(L);
|
||||
}
|
||||
|
||||
int w_Contact_getNormal(lua_State *L)
|
||||
{
|
||||
Contact *t = luax_checkcontact(L, 1);
|
||||
return t->getNormal(L);
|
||||
}
|
||||
|
||||
int w_Contact_getFriction(lua_State *L)
|
||||
{
|
||||
Contact *t = luax_checkcontact(L, 1);
|
||||
lua_pushnumber(L, t->getFriction());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_Contact_getRestitution(lua_State *L)
|
||||
{
|
||||
Contact *t = luax_checkcontact(L, 1);
|
||||
lua_pushnumber(L, t->getRestitution());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_Contact_isEnabled(lua_State *L)
|
||||
{
|
||||
Contact *t = luax_checkcontact(L, 1);
|
||||
lua_pushboolean(L, t->isEnabled());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_Contact_isTouching(lua_State *L)
|
||||
{
|
||||
Contact *t = luax_checkcontact(L, 1);
|
||||
lua_pushboolean(L, t->isTouching());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_Contact_setFriction(lua_State *L)
|
||||
{
|
||||
Contact *t = luax_checkcontact(L, 1);
|
||||
float f = (float)luaL_checknumber(L, 2);
|
||||
t->setFriction(f);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_Contact_setRestitution(lua_State *L)
|
||||
{
|
||||
Contact *t = luax_checkcontact(L, 1);
|
||||
float r = (float)luaL_checknumber(L, 2);
|
||||
t->setRestitution(r);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_Contact_setEnabled(lua_State *L)
|
||||
{
|
||||
Contact *t = luax_checkcontact(L, 1);
|
||||
bool e = luax_toboolean(L, 2);
|
||||
t->setEnabled(e);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_Contact_resetFriction(lua_State *L)
|
||||
{
|
||||
Contact *t = luax_checkcontact(L, 1);
|
||||
t->resetFriction();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_Contact_resetRestitution(lua_State *L)
|
||||
{
|
||||
Contact *t = luax_checkcontact(L, 1);
|
||||
t->resetRestitution();
|
||||
return 0;
|
||||
}
|
||||
|
||||
extern "C" int luaopen_contact(lua_State *L)
|
||||
{
|
||||
static const luaL_Reg functions[] =
|
||||
{
|
||||
{ "getPositions", w_Contact_getPositions },
|
||||
{ "getNormal", w_Contact_getNormal },
|
||||
{ "getFriction", w_Contact_getFriction },
|
||||
{ "getRestitution", w_Contact_getRestitution },
|
||||
{ "isEnabled", w_Contact_isEnabled },
|
||||
{ "isTouching", w_Contact_isTouching },
|
||||
{ "setFriction", w_Contact_setFriction },
|
||||
{ "setRestitution", w_Contact_setRestitution },
|
||||
{ "setEnabled", w_Contact_setEnabled },
|
||||
{ "resetFriction", w_Contact_resetFriction },
|
||||
{ "resetRestitution", w_Contact_resetRestitution },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
return luax_register_type(L, "Contact", functions);
|
||||
}
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
@@ -1,53 +1,53 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_PHYSICS_BOX2D_WRAP_CONTACT_H
|
||||
#define LOVE_PHYSICS_BOX2D_WRAP_CONTACT_H
|
||||
|
||||
// LOVE
|
||||
#include "common/runtime.h"
|
||||
#include "Contact.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
Contact *luax_checkcontact(lua_State *L, int idx);
|
||||
int w_Contact_getPositions(lua_State *L);
|
||||
int w_Contact_getNormal(lua_State *L);
|
||||
int w_Contact_getFriction(lua_State *L);
|
||||
int w_Contact_getRestitution(lua_State *L);
|
||||
int w_Contact_isEnabled(lua_State *L);
|
||||
int w_Contact_isTouching(lua_State *L);
|
||||
int w_Contact_setFriction(lua_State *L);
|
||||
int w_Contact_setRestitution(lua_State *L);
|
||||
int w_Contact_setEnabled(lua_State *L);
|
||||
int w_Contact_resetFriction(lua_State *L);
|
||||
int w_Contact_resetRestitution(lua_State *L);
|
||||
extern "C" int luaopen_contact(lua_State *L);
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_WRAP_CONTACT_H
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_PHYSICS_BOX2D_WRAP_CONTACT_H
|
||||
#define LOVE_PHYSICS_BOX2D_WRAP_CONTACT_H
|
||||
|
||||
// LOVE
|
||||
#include "common/runtime.h"
|
||||
#include "Contact.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
Contact *luax_checkcontact(lua_State *L, int idx);
|
||||
int w_Contact_getPositions(lua_State *L);
|
||||
int w_Contact_getNormal(lua_State *L);
|
||||
int w_Contact_getFriction(lua_State *L);
|
||||
int w_Contact_getRestitution(lua_State *L);
|
||||
int w_Contact_isEnabled(lua_State *L);
|
||||
int w_Contact_isTouching(lua_State *L);
|
||||
int w_Contact_setFriction(lua_State *L);
|
||||
int w_Contact_setRestitution(lua_State *L);
|
||||
int w_Contact_setEnabled(lua_State *L);
|
||||
int w_Contact_resetFriction(lua_State *L);
|
||||
int w_Contact_resetRestitution(lua_State *L);
|
||||
extern "C" int luaopen_contact(lua_State *L);
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_WRAP_CONTACT_H
|
||||
|
||||
@@ -1,108 +1,108 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#include "wrap_DistanceJoint.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
DistanceJoint *luax_checkdistancejoint(lua_State *L, int idx)
|
||||
{
|
||||
DistanceJoint *j = luax_checktype<DistanceJoint>(L, idx, "DistanceJoint", PHYSICS_DISTANCE_JOINT_T);
|
||||
if (!j->isValid())
|
||||
luaL_error(L, "Attempt to use destroyed joint.");
|
||||
return j;
|
||||
}
|
||||
|
||||
int w_DistanceJoint_setLength(lua_State *L)
|
||||
{
|
||||
DistanceJoint *t = luax_checkdistancejoint(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
t->setLength(arg1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_DistanceJoint_getLength(lua_State *L)
|
||||
{
|
||||
DistanceJoint *t = luax_checkdistancejoint(L, 1);
|
||||
lua_pushnumber(L, t->getLength());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_DistanceJoint_setFrequency(lua_State *L)
|
||||
{
|
||||
DistanceJoint *t = luax_checkdistancejoint(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
t->setFrequency(arg1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_DistanceJoint_getFrequency(lua_State *L)
|
||||
{
|
||||
DistanceJoint *t = luax_checkdistancejoint(L, 1);
|
||||
lua_pushnumber(L, t->getFrequency());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_DistanceJoint_setDampingRatio(lua_State *L)
|
||||
{
|
||||
DistanceJoint *t = luax_checkdistancejoint(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
t->setDampingRatio(arg1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_DistanceJoint_getDampingRatio(lua_State *L)
|
||||
{
|
||||
DistanceJoint *t = luax_checkdistancejoint(L, 1);
|
||||
lua_pushnumber(L, t->getDampingRatio());
|
||||
return 1;
|
||||
}
|
||||
|
||||
static const luaL_Reg functions[] =
|
||||
{
|
||||
{ "setLength", w_DistanceJoint_setLength },
|
||||
{ "getLength", w_DistanceJoint_getLength },
|
||||
{ "setFrequency", w_DistanceJoint_setFrequency },
|
||||
{ "getFrequency", w_DistanceJoint_getFrequency },
|
||||
{ "setDampingRatio", w_DistanceJoint_setDampingRatio },
|
||||
{ "getDampingRatio", w_DistanceJoint_getDampingRatio },
|
||||
// From Joint.
|
||||
{ "getType", w_Joint_getType },
|
||||
{ "getAnchors", w_Joint_getAnchors },
|
||||
{ "getReactionForce", w_Joint_getReactionForce },
|
||||
{ "getReactionTorque", w_Joint_getReactionTorque },
|
||||
{ "getCollideConnected", w_Joint_getCollideConnected },
|
||||
{ "destroy", w_Joint_destroy },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
extern "C" int luaopen_distancejoint(lua_State *L)
|
||||
{
|
||||
return luax_register_type(L, "DistanceJoint", functions);
|
||||
}
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#include "wrap_DistanceJoint.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
DistanceJoint *luax_checkdistancejoint(lua_State *L, int idx)
|
||||
{
|
||||
DistanceJoint *j = luax_checktype<DistanceJoint>(L, idx, "DistanceJoint", PHYSICS_DISTANCE_JOINT_T);
|
||||
if (!j->isValid())
|
||||
luaL_error(L, "Attempt to use destroyed joint.");
|
||||
return j;
|
||||
}
|
||||
|
||||
int w_DistanceJoint_setLength(lua_State *L)
|
||||
{
|
||||
DistanceJoint *t = luax_checkdistancejoint(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
t->setLength(arg1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_DistanceJoint_getLength(lua_State *L)
|
||||
{
|
||||
DistanceJoint *t = luax_checkdistancejoint(L, 1);
|
||||
lua_pushnumber(L, t->getLength());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_DistanceJoint_setFrequency(lua_State *L)
|
||||
{
|
||||
DistanceJoint *t = luax_checkdistancejoint(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
t->setFrequency(arg1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_DistanceJoint_getFrequency(lua_State *L)
|
||||
{
|
||||
DistanceJoint *t = luax_checkdistancejoint(L, 1);
|
||||
lua_pushnumber(L, t->getFrequency());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_DistanceJoint_setDampingRatio(lua_State *L)
|
||||
{
|
||||
DistanceJoint *t = luax_checkdistancejoint(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
t->setDampingRatio(arg1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_DistanceJoint_getDampingRatio(lua_State *L)
|
||||
{
|
||||
DistanceJoint *t = luax_checkdistancejoint(L, 1);
|
||||
lua_pushnumber(L, t->getDampingRatio());
|
||||
return 1;
|
||||
}
|
||||
|
||||
static const luaL_Reg functions[] =
|
||||
{
|
||||
{ "setLength", w_DistanceJoint_setLength },
|
||||
{ "getLength", w_DistanceJoint_getLength },
|
||||
{ "setFrequency", w_DistanceJoint_setFrequency },
|
||||
{ "getFrequency", w_DistanceJoint_getFrequency },
|
||||
{ "setDampingRatio", w_DistanceJoint_setDampingRatio },
|
||||
{ "getDampingRatio", w_DistanceJoint_getDampingRatio },
|
||||
// From Joint.
|
||||
{ "getType", w_Joint_getType },
|
||||
{ "getAnchors", w_Joint_getAnchors },
|
||||
{ "getReactionForce", w_Joint_getReactionForce },
|
||||
{ "getReactionTorque", w_Joint_getReactionTorque },
|
||||
{ "getCollideConnected", w_Joint_getCollideConnected },
|
||||
{ "destroy", w_Joint_destroy },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
extern "C" int luaopen_distancejoint(lua_State *L)
|
||||
{
|
||||
return luax_register_type(L, "DistanceJoint", functions);
|
||||
}
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
@@ -1,49 +1,49 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_PHYSICS_BOX2D_WRAP_DISTANCE_JOINT_H
|
||||
#define LOVE_PHYSICS_BOX2D_WRAP_DISTANCE_JOINT_H
|
||||
|
||||
// LOVE
|
||||
#include "common/runtime.h"
|
||||
#include "wrap_Joint.h"
|
||||
#include "DistanceJoint.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
DistanceJoint *luax_checkdistancejoint(lua_State *L, int idx);
|
||||
int w_DistanceJoint_setLength(lua_State *L);
|
||||
int w_DistanceJoint_getLength(lua_State *L);
|
||||
int w_DistanceJoint_setFrequency(lua_State *L);
|
||||
int w_DistanceJoint_getFrequency(lua_State *L);
|
||||
int w_DistanceJoint_setDampingRatio(lua_State *L);
|
||||
int w_DistanceJoint_getDampingRatio(lua_State *L);
|
||||
extern "C" int luaopen_distancejoint(lua_State *L);
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_WRAP_DISTANCE_JOINT_H
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_PHYSICS_BOX2D_WRAP_DISTANCE_JOINT_H
|
||||
#define LOVE_PHYSICS_BOX2D_WRAP_DISTANCE_JOINT_H
|
||||
|
||||
// LOVE
|
||||
#include "common/runtime.h"
|
||||
#include "wrap_Joint.h"
|
||||
#include "DistanceJoint.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
DistanceJoint *luax_checkdistancejoint(lua_State *L, int idx);
|
||||
int w_DistanceJoint_setLength(lua_State *L);
|
||||
int w_DistanceJoint_getLength(lua_State *L);
|
||||
int w_DistanceJoint_setFrequency(lua_State *L);
|
||||
int w_DistanceJoint_getFrequency(lua_State *L);
|
||||
int w_DistanceJoint_setDampingRatio(lua_State *L);
|
||||
int w_DistanceJoint_getDampingRatio(lua_State *L);
|
||||
extern "C" int luaopen_distancejoint(lua_State *L);
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_WRAP_DISTANCE_JOINT_H
|
||||
|
||||
@@ -1,63 +1,63 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#include "wrap_EdgeShape.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
EdgeShape *luax_checkedgeshape(lua_State *L, int idx)
|
||||
{
|
||||
return luax_checktype<EdgeShape>(L, idx, "EdgeShape", PHYSICS_EDGE_SHAPE_T);
|
||||
}
|
||||
|
||||
int w_EdgeShape_getPoints(lua_State *L)
|
||||
{
|
||||
EdgeShape *t = luax_checkedgeshape(L, 1);
|
||||
lua_remove(L, 1);
|
||||
return t->getPoints(L);
|
||||
}
|
||||
|
||||
static const luaL_Reg functions[] =
|
||||
{
|
||||
{ "getPoints", w_EdgeShape_getPoints },
|
||||
// From Shape.
|
||||
{ "getType", w_Shape_getType },
|
||||
{ "getRadius", w_Shape_getRadius },
|
||||
{ "getChildCount", w_Shape_getChildCount },
|
||||
{ "testPoint", w_Shape_testPoint },
|
||||
{ "rayCast", w_Shape_rayCast },
|
||||
{ "computeAABB", w_Shape_computeAABB },
|
||||
{ "computeMass", w_Shape_computeMass },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
extern "C" int luaopen_edgeshape(lua_State *L)
|
||||
{
|
||||
return luax_register_type(L, "EdgeShape", functions);
|
||||
}
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#include "wrap_EdgeShape.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
EdgeShape *luax_checkedgeshape(lua_State *L, int idx)
|
||||
{
|
||||
return luax_checktype<EdgeShape>(L, idx, "EdgeShape", PHYSICS_EDGE_SHAPE_T);
|
||||
}
|
||||
|
||||
int w_EdgeShape_getPoints(lua_State *L)
|
||||
{
|
||||
EdgeShape *t = luax_checkedgeshape(L, 1);
|
||||
lua_remove(L, 1);
|
||||
return t->getPoints(L);
|
||||
}
|
||||
|
||||
static const luaL_Reg functions[] =
|
||||
{
|
||||
{ "getPoints", w_EdgeShape_getPoints },
|
||||
// From Shape.
|
||||
{ "getType", w_Shape_getType },
|
||||
{ "getRadius", w_Shape_getRadius },
|
||||
{ "getChildCount", w_Shape_getChildCount },
|
||||
{ "testPoint", w_Shape_testPoint },
|
||||
{ "rayCast", w_Shape_rayCast },
|
||||
{ "computeAABB", w_Shape_computeAABB },
|
||||
{ "computeMass", w_Shape_computeMass },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
extern "C" int luaopen_edgeshape(lua_State *L)
|
||||
{
|
||||
return luax_register_type(L, "EdgeShape", functions);
|
||||
}
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
@@ -1,44 +1,44 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_PHYSICS_BOX2D_WRAP_EDGE_SHAPE_H
|
||||
#define LOVE_PHYSICS_BOX2D_WRAP_EDGE_SHAPE_H
|
||||
|
||||
// LOVE
|
||||
#include "common/runtime.h"
|
||||
#include "wrap_Shape.h"
|
||||
#include "EdgeShape.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
EdgeShape *luax_checkedgeshape(lua_State *L, int idx);
|
||||
int w_EdgeShape_getPoints(lua_State *L);
|
||||
extern "C" int luaopen_edgeshape(lua_State *L);
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_WRAP_EDGE_SHAPE_H
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_PHYSICS_BOX2D_WRAP_EDGE_SHAPE_H
|
||||
#define LOVE_PHYSICS_BOX2D_WRAP_EDGE_SHAPE_H
|
||||
|
||||
// LOVE
|
||||
#include "common/runtime.h"
|
||||
#include "wrap_Shape.h"
|
||||
#include "EdgeShape.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
EdgeShape *luax_checkedgeshape(lua_State *L, int idx);
|
||||
int w_EdgeShape_getPoints(lua_State *L);
|
||||
extern "C" int luaopen_edgeshape(lua_State *L);
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_WRAP_EDGE_SHAPE_H
|
||||
|
||||
@@ -1,309 +1,309 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#include "wrap_Fixture.h"
|
||||
#include "common/StringMap.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
Fixture *luax_checkfixture(lua_State *L, int idx)
|
||||
{
|
||||
Fixture *f = luax_checktype<Fixture>(L, idx, "Fixture", PHYSICS_FIXTURE_T);
|
||||
if (!f->isValid())
|
||||
luaL_error(L, "Attempt to use destroyed fixture.");
|
||||
return f;
|
||||
}
|
||||
|
||||
int w_Fixture_getType(lua_State *L)
|
||||
{
|
||||
Fixture *t = luax_checkfixture(L, 1);
|
||||
const char *type = "";
|
||||
Shape::getConstant(t->getType(), type);
|
||||
lua_pushstring(L, type);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_Fixture_setFriction(lua_State *L)
|
||||
{
|
||||
Fixture *t = luax_checkfixture(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
t->setFriction(arg1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_Fixture_setRestitution(lua_State *L)
|
||||
{
|
||||
Fixture *t = luax_checkfixture(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
t->setRestitution(arg1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_Fixture_setDensity(lua_State *L)
|
||||
{
|
||||
Fixture *t = luax_checkfixture(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
t->setDensity(arg1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_Fixture_setSensor(lua_State *L)
|
||||
{
|
||||
Fixture *t = luax_checkfixture(L, 1);
|
||||
bool arg1 = luax_toboolean(L, 2);
|
||||
t->setSensor(arg1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_Fixture_getFriction(lua_State *L)
|
||||
{
|
||||
Fixture *t = luax_checkfixture(L, 1);
|
||||
lua_pushnumber(L, t->getFriction());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_Fixture_getRestitution(lua_State *L)
|
||||
{
|
||||
Fixture *t = luax_checkfixture(L, 1);
|
||||
lua_pushnumber(L, t->getRestitution());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_Fixture_getDensity(lua_State *L)
|
||||
{
|
||||
Fixture *t = luax_checkfixture(L, 1);
|
||||
lua_pushnumber(L, t->getDensity());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_Fixture_isSensor(lua_State *L)
|
||||
{
|
||||
Fixture *t = luax_checkfixture(L, 1);
|
||||
luax_pushboolean(L, t->isSensor());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_Fixture_getBody(lua_State *L)
|
||||
{
|
||||
Fixture *t = luax_checkfixture(L, 1);
|
||||
Body *body = t->getBody();
|
||||
if (body == 0)
|
||||
return 0;
|
||||
body->retain();
|
||||
luax_newtype(L, "Body", PHYSICS_BODY_T, (void *)body);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_Fixture_getShape(lua_State *L)
|
||||
{
|
||||
Fixture *t = luax_checkfixture(L, 1);
|
||||
Shape *shape = t->getShape();
|
||||
if (shape == 0)
|
||||
return 0;
|
||||
switch (shape->getType())
|
||||
{
|
||||
case Shape::SHAPE_EDGE:
|
||||
luax_newtype(L, "EdgeShape", PHYSICS_EDGE_SHAPE_T, (void *)shape);
|
||||
break;
|
||||
case Shape::SHAPE_CHAIN:
|
||||
luax_newtype(L, "ChainShape", PHYSICS_CHAIN_SHAPE_T, (void *)shape);
|
||||
break;
|
||||
case Shape::SHAPE_CIRCLE:
|
||||
luax_newtype(L, "CircleShape", PHYSICS_CIRCLE_SHAPE_T, (void *)shape);
|
||||
break;
|
||||
case Shape::SHAPE_POLYGON:
|
||||
luax_newtype(L, "PolygonShape", PHYSICS_POLYGON_SHAPE_T, (void *)shape);
|
||||
break;
|
||||
default:
|
||||
luax_newtype(L, "Shape", PHYSICS_SHAPE_T, (void *)shape);
|
||||
break;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_Fixture_testPoint(lua_State *L)
|
||||
{
|
||||
Fixture *t = luax_checkfixture(L, 1);
|
||||
float x = (float)luaL_checknumber(L, 2);
|
||||
float y = (float)luaL_checknumber(L, 3);
|
||||
luax_pushboolean(L, t->testPoint(x, y));
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_Fixture_rayCast(lua_State *L)
|
||||
{
|
||||
Fixture *t = luax_checkfixture(L, 1);
|
||||
lua_remove(L, 1);
|
||||
ASSERT_GUARD(return t->rayCast(L);)
|
||||
}
|
||||
|
||||
int w_Fixture_setFilterData(lua_State *L)
|
||||
{
|
||||
Fixture *t = luax_checkfixture(L, 1);
|
||||
int v[3];
|
||||
v[0] = luaL_checkint(L, 2);
|
||||
v[1] = luaL_checkint(L, 3);
|
||||
v[2] = luaL_checkint(L, 4);
|
||||
t->setFilterData(v);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_Fixture_getFilterData(lua_State *L)
|
||||
{
|
||||
Fixture *t = luax_checkfixture(L, 1);
|
||||
int v[3];
|
||||
t->getFilterData(v);
|
||||
lua_pushinteger(L, v[0]);
|
||||
lua_pushinteger(L, v[1]);
|
||||
lua_pushinteger(L, v[2]);
|
||||
return 3;
|
||||
}
|
||||
|
||||
int w_Fixture_setCategory(lua_State *L)
|
||||
{
|
||||
Fixture *t = luax_checkfixture(L, 1);
|
||||
lua_remove(L, 1);
|
||||
return t->setCategory(L);
|
||||
}
|
||||
|
||||
int w_Fixture_getCategory(lua_State *L)
|
||||
{
|
||||
Fixture *t = luax_checkfixture(L, 1);
|
||||
lua_remove(L, 1);
|
||||
return t->getCategory(L);
|
||||
}
|
||||
|
||||
int w_Fixture_setMask(lua_State *L)
|
||||
{
|
||||
Fixture *t = luax_checkfixture(L, 1);
|
||||
lua_remove(L, 1);
|
||||
return t->setMask(L);
|
||||
}
|
||||
|
||||
int w_Fixture_getMask(lua_State *L)
|
||||
{
|
||||
Fixture *t = luax_checkfixture(L, 1);
|
||||
lua_remove(L, 1);
|
||||
return t->getMask(L);
|
||||
}
|
||||
|
||||
int w_Fixture_setUserData(lua_State *L)
|
||||
{
|
||||
Fixture *t = luax_checkfixture(L, 1);
|
||||
lua_remove(L, 1);
|
||||
return t->setUserData(L);
|
||||
}
|
||||
|
||||
int w_Fixture_getUserData(lua_State *L)
|
||||
{
|
||||
Fixture *t = luax_checkfixture(L, 1);
|
||||
lua_remove(L, 1);
|
||||
return t->getUserData(L);
|
||||
}
|
||||
|
||||
int w_Fixture_getBoundingBox(lua_State *L)
|
||||
{
|
||||
Fixture *t = luax_checkfixture(L, 1);
|
||||
lua_remove(L, 1);
|
||||
return t->getBoundingBox(L);
|
||||
}
|
||||
|
||||
int w_Fixture_getMassData(lua_State *L)
|
||||
{
|
||||
Fixture *t = luax_checkfixture(L, 1);
|
||||
lua_remove(L, 1);
|
||||
return t->getMassData(L);
|
||||
}
|
||||
|
||||
int w_Fixture_getGroupIndex(lua_State *L)
|
||||
{
|
||||
Fixture *t = luax_checkfixture(L, 1);
|
||||
int i = t->getGroupIndex();
|
||||
lua_pushinteger(L, i);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_Fixture_setGroupIndex(lua_State *L)
|
||||
{
|
||||
Fixture *t = luax_checkfixture(L, 1);
|
||||
int i = luaL_checkint(L, 2);
|
||||
t->setGroupIndex(i);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_Fixture_destroy(lua_State *L)
|
||||
{
|
||||
Fixture *t = luax_checkfixture(L, 1);
|
||||
try
|
||||
{
|
||||
t->destroy();
|
||||
}
|
||||
catch(love::Exception &e)
|
||||
{
|
||||
luaL_error(L, "%s", e.what());
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const luaL_Reg functions[] =
|
||||
{
|
||||
{ "getType", w_Fixture_getType },
|
||||
{ "setFriction", w_Fixture_setFriction },
|
||||
{ "setRestitution", w_Fixture_setRestitution },
|
||||
{ "setDensity", w_Fixture_setDensity },
|
||||
{ "setSensor", w_Fixture_setSensor },
|
||||
{ "getFriction", w_Fixture_getFriction },
|
||||
{ "getRestitution", w_Fixture_getRestitution },
|
||||
{ "getDensity", w_Fixture_getDensity },
|
||||
{ "getBody", w_Fixture_getBody },
|
||||
{ "getShape", w_Fixture_getShape },
|
||||
{ "isSensor", w_Fixture_isSensor },
|
||||
{ "testPoint", w_Fixture_testPoint },
|
||||
{ "rayCast", w_Fixture_rayCast },
|
||||
{ "setFilterData", w_Fixture_setFilterData },
|
||||
{ "getFilterData", w_Fixture_getFilterData },
|
||||
{ "setCategory", w_Fixture_setCategory },
|
||||
{ "getCategory", w_Fixture_getCategory },
|
||||
{ "setMask", w_Fixture_setMask },
|
||||
{ "getMask", w_Fixture_getMask },
|
||||
{ "setUserData", w_Fixture_setUserData },
|
||||
{ "getUserData", w_Fixture_getUserData },
|
||||
{ "getBoundingBox", w_Fixture_getBoundingBox },
|
||||
{ "getMassData", w_Fixture_getMassData },
|
||||
{ "getGroupIndex", w_Fixture_getGroupIndex },
|
||||
{ "setGroupIndex", w_Fixture_setGroupIndex },
|
||||
{ "destroy", w_Fixture_destroy },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
extern "C" int luaopen_fixture(lua_State *L)
|
||||
{
|
||||
return luax_register_type(L, "Fixture", functions);
|
||||
}
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#include "wrap_Fixture.h"
|
||||
#include "common/StringMap.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
Fixture *luax_checkfixture(lua_State *L, int idx)
|
||||
{
|
||||
Fixture *f = luax_checktype<Fixture>(L, idx, "Fixture", PHYSICS_FIXTURE_T);
|
||||
if (!f->isValid())
|
||||
luaL_error(L, "Attempt to use destroyed fixture.");
|
||||
return f;
|
||||
}
|
||||
|
||||
int w_Fixture_getType(lua_State *L)
|
||||
{
|
||||
Fixture *t = luax_checkfixture(L, 1);
|
||||
const char *type = "";
|
||||
Shape::getConstant(t->getType(), type);
|
||||
lua_pushstring(L, type);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_Fixture_setFriction(lua_State *L)
|
||||
{
|
||||
Fixture *t = luax_checkfixture(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
t->setFriction(arg1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_Fixture_setRestitution(lua_State *L)
|
||||
{
|
||||
Fixture *t = luax_checkfixture(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
t->setRestitution(arg1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_Fixture_setDensity(lua_State *L)
|
||||
{
|
||||
Fixture *t = luax_checkfixture(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
t->setDensity(arg1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_Fixture_setSensor(lua_State *L)
|
||||
{
|
||||
Fixture *t = luax_checkfixture(L, 1);
|
||||
bool arg1 = luax_toboolean(L, 2);
|
||||
t->setSensor(arg1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_Fixture_getFriction(lua_State *L)
|
||||
{
|
||||
Fixture *t = luax_checkfixture(L, 1);
|
||||
lua_pushnumber(L, t->getFriction());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_Fixture_getRestitution(lua_State *L)
|
||||
{
|
||||
Fixture *t = luax_checkfixture(L, 1);
|
||||
lua_pushnumber(L, t->getRestitution());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_Fixture_getDensity(lua_State *L)
|
||||
{
|
||||
Fixture *t = luax_checkfixture(L, 1);
|
||||
lua_pushnumber(L, t->getDensity());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_Fixture_isSensor(lua_State *L)
|
||||
{
|
||||
Fixture *t = luax_checkfixture(L, 1);
|
||||
luax_pushboolean(L, t->isSensor());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_Fixture_getBody(lua_State *L)
|
||||
{
|
||||
Fixture *t = luax_checkfixture(L, 1);
|
||||
Body *body = t->getBody();
|
||||
if (body == 0)
|
||||
return 0;
|
||||
body->retain();
|
||||
luax_newtype(L, "Body", PHYSICS_BODY_T, (void *)body);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_Fixture_getShape(lua_State *L)
|
||||
{
|
||||
Fixture *t = luax_checkfixture(L, 1);
|
||||
Shape *shape = t->getShape();
|
||||
if (shape == 0)
|
||||
return 0;
|
||||
switch (shape->getType())
|
||||
{
|
||||
case Shape::SHAPE_EDGE:
|
||||
luax_newtype(L, "EdgeShape", PHYSICS_EDGE_SHAPE_T, (void *)shape);
|
||||
break;
|
||||
case Shape::SHAPE_CHAIN:
|
||||
luax_newtype(L, "ChainShape", PHYSICS_CHAIN_SHAPE_T, (void *)shape);
|
||||
break;
|
||||
case Shape::SHAPE_CIRCLE:
|
||||
luax_newtype(L, "CircleShape", PHYSICS_CIRCLE_SHAPE_T, (void *)shape);
|
||||
break;
|
||||
case Shape::SHAPE_POLYGON:
|
||||
luax_newtype(L, "PolygonShape", PHYSICS_POLYGON_SHAPE_T, (void *)shape);
|
||||
break;
|
||||
default:
|
||||
luax_newtype(L, "Shape", PHYSICS_SHAPE_T, (void *)shape);
|
||||
break;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_Fixture_testPoint(lua_State *L)
|
||||
{
|
||||
Fixture *t = luax_checkfixture(L, 1);
|
||||
float x = (float)luaL_checknumber(L, 2);
|
||||
float y = (float)luaL_checknumber(L, 3);
|
||||
luax_pushboolean(L, t->testPoint(x, y));
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_Fixture_rayCast(lua_State *L)
|
||||
{
|
||||
Fixture *t = luax_checkfixture(L, 1);
|
||||
lua_remove(L, 1);
|
||||
ASSERT_GUARD(return t->rayCast(L);)
|
||||
}
|
||||
|
||||
int w_Fixture_setFilterData(lua_State *L)
|
||||
{
|
||||
Fixture *t = luax_checkfixture(L, 1);
|
||||
int v[3];
|
||||
v[0] = luaL_checkint(L, 2);
|
||||
v[1] = luaL_checkint(L, 3);
|
||||
v[2] = luaL_checkint(L, 4);
|
||||
t->setFilterData(v);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_Fixture_getFilterData(lua_State *L)
|
||||
{
|
||||
Fixture *t = luax_checkfixture(L, 1);
|
||||
int v[3];
|
||||
t->getFilterData(v);
|
||||
lua_pushinteger(L, v[0]);
|
||||
lua_pushinteger(L, v[1]);
|
||||
lua_pushinteger(L, v[2]);
|
||||
return 3;
|
||||
}
|
||||
|
||||
int w_Fixture_setCategory(lua_State *L)
|
||||
{
|
||||
Fixture *t = luax_checkfixture(L, 1);
|
||||
lua_remove(L, 1);
|
||||
return t->setCategory(L);
|
||||
}
|
||||
|
||||
int w_Fixture_getCategory(lua_State *L)
|
||||
{
|
||||
Fixture *t = luax_checkfixture(L, 1);
|
||||
lua_remove(L, 1);
|
||||
return t->getCategory(L);
|
||||
}
|
||||
|
||||
int w_Fixture_setMask(lua_State *L)
|
||||
{
|
||||
Fixture *t = luax_checkfixture(L, 1);
|
||||
lua_remove(L, 1);
|
||||
return t->setMask(L);
|
||||
}
|
||||
|
||||
int w_Fixture_getMask(lua_State *L)
|
||||
{
|
||||
Fixture *t = luax_checkfixture(L, 1);
|
||||
lua_remove(L, 1);
|
||||
return t->getMask(L);
|
||||
}
|
||||
|
||||
int w_Fixture_setUserData(lua_State *L)
|
||||
{
|
||||
Fixture *t = luax_checkfixture(L, 1);
|
||||
lua_remove(L, 1);
|
||||
return t->setUserData(L);
|
||||
}
|
||||
|
||||
int w_Fixture_getUserData(lua_State *L)
|
||||
{
|
||||
Fixture *t = luax_checkfixture(L, 1);
|
||||
lua_remove(L, 1);
|
||||
return t->getUserData(L);
|
||||
}
|
||||
|
||||
int w_Fixture_getBoundingBox(lua_State *L)
|
||||
{
|
||||
Fixture *t = luax_checkfixture(L, 1);
|
||||
lua_remove(L, 1);
|
||||
return t->getBoundingBox(L);
|
||||
}
|
||||
|
||||
int w_Fixture_getMassData(lua_State *L)
|
||||
{
|
||||
Fixture *t = luax_checkfixture(L, 1);
|
||||
lua_remove(L, 1);
|
||||
return t->getMassData(L);
|
||||
}
|
||||
|
||||
int w_Fixture_getGroupIndex(lua_State *L)
|
||||
{
|
||||
Fixture *t = luax_checkfixture(L, 1);
|
||||
int i = t->getGroupIndex();
|
||||
lua_pushinteger(L, i);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_Fixture_setGroupIndex(lua_State *L)
|
||||
{
|
||||
Fixture *t = luax_checkfixture(L, 1);
|
||||
int i = luaL_checkint(L, 2);
|
||||
t->setGroupIndex(i);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_Fixture_destroy(lua_State *L)
|
||||
{
|
||||
Fixture *t = luax_checkfixture(L, 1);
|
||||
try
|
||||
{
|
||||
t->destroy();
|
||||
}
|
||||
catch(love::Exception &e)
|
||||
{
|
||||
luaL_error(L, "%s", e.what());
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const luaL_Reg functions[] =
|
||||
{
|
||||
{ "getType", w_Fixture_getType },
|
||||
{ "setFriction", w_Fixture_setFriction },
|
||||
{ "setRestitution", w_Fixture_setRestitution },
|
||||
{ "setDensity", w_Fixture_setDensity },
|
||||
{ "setSensor", w_Fixture_setSensor },
|
||||
{ "getFriction", w_Fixture_getFriction },
|
||||
{ "getRestitution", w_Fixture_getRestitution },
|
||||
{ "getDensity", w_Fixture_getDensity },
|
||||
{ "getBody", w_Fixture_getBody },
|
||||
{ "getShape", w_Fixture_getShape },
|
||||
{ "isSensor", w_Fixture_isSensor },
|
||||
{ "testPoint", w_Fixture_testPoint },
|
||||
{ "rayCast", w_Fixture_rayCast },
|
||||
{ "setFilterData", w_Fixture_setFilterData },
|
||||
{ "getFilterData", w_Fixture_getFilterData },
|
||||
{ "setCategory", w_Fixture_setCategory },
|
||||
{ "getCategory", w_Fixture_getCategory },
|
||||
{ "setMask", w_Fixture_setMask },
|
||||
{ "getMask", w_Fixture_getMask },
|
||||
{ "setUserData", w_Fixture_setUserData },
|
||||
{ "getUserData", w_Fixture_getUserData },
|
||||
{ "getBoundingBox", w_Fixture_getBoundingBox },
|
||||
{ "getMassData", w_Fixture_getMassData },
|
||||
{ "getGroupIndex", w_Fixture_getGroupIndex },
|
||||
{ "setGroupIndex", w_Fixture_setGroupIndex },
|
||||
{ "destroy", w_Fixture_destroy },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
extern "C" int luaopen_fixture(lua_State *L)
|
||||
{
|
||||
return luax_register_type(L, "Fixture", functions);
|
||||
}
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
|
||||
@@ -1,69 +1,69 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_PHYSICS_BOX2D_WRAP_FIXTURE_H
|
||||
#define LOVE_PHYSICS_BOX2D_WRAP_FIXTURE_H
|
||||
|
||||
// LOVE
|
||||
#include "common/runtime.h"
|
||||
#include "Fixture.h"
|
||||
#include "wrap_Physics.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
Fixture *luax_checkfixture(lua_State *L, int idx);
|
||||
int w_Fixture_getType(lua_State *L);
|
||||
int w_Fixture_setFriction(lua_State *L);
|
||||
int w_Fixture_setRestitution(lua_State *L);
|
||||
int w_Fixture_setDensity(lua_State *L);
|
||||
int w_Fixture_setSensor(lua_State *L);
|
||||
int w_Fixture_getFriction(lua_State *L);
|
||||
int w_Fixture_getRestitution(lua_State *L);
|
||||
int w_Fixture_getDensity(lua_State *L);
|
||||
int w_Fixture_isSensor(lua_State *L);
|
||||
int w_Fixture_getBody(lua_State *L);
|
||||
int w_Fixture_getShape(lua_State *L);
|
||||
int w_Fixture_testPoint(lua_State *L);
|
||||
int w_Fixture_rayCast(lua_State *L);
|
||||
int w_Fixture_setFilterData(lua_State *L);
|
||||
int w_Fixture_getFilterData(lua_State *L);
|
||||
int w_Fixture_setCategory(lua_State *L);
|
||||
int w_Fixture_getCategory(lua_State *L);
|
||||
int w_Fixture_setMask(lua_State *L);
|
||||
int w_Fixture_getMask(lua_State *L);
|
||||
int w_Fixture_setUserData(lua_State *L);
|
||||
int w_Fixture_getUserData(lua_State *L);
|
||||
int w_Fixture_getBoundingBox(lua_State *L);
|
||||
int w_Fixture_getMassData(lua_State *L);
|
||||
int w_Fixture_getGroupIndex(lua_State *L);
|
||||
int w_Fixture_setGroupIndex(lua_State *L);
|
||||
int w_Fixture_destroy(lua_State *L);
|
||||
extern "C" int luaopen_fixture(lua_State *L);
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_WRAP_FIXTURE_H
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_PHYSICS_BOX2D_WRAP_FIXTURE_H
|
||||
#define LOVE_PHYSICS_BOX2D_WRAP_FIXTURE_H
|
||||
|
||||
// LOVE
|
||||
#include "common/runtime.h"
|
||||
#include "Fixture.h"
|
||||
#include "wrap_Physics.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
Fixture *luax_checkfixture(lua_State *L, int idx);
|
||||
int w_Fixture_getType(lua_State *L);
|
||||
int w_Fixture_setFriction(lua_State *L);
|
||||
int w_Fixture_setRestitution(lua_State *L);
|
||||
int w_Fixture_setDensity(lua_State *L);
|
||||
int w_Fixture_setSensor(lua_State *L);
|
||||
int w_Fixture_getFriction(lua_State *L);
|
||||
int w_Fixture_getRestitution(lua_State *L);
|
||||
int w_Fixture_getDensity(lua_State *L);
|
||||
int w_Fixture_isSensor(lua_State *L);
|
||||
int w_Fixture_getBody(lua_State *L);
|
||||
int w_Fixture_getShape(lua_State *L);
|
||||
int w_Fixture_testPoint(lua_State *L);
|
||||
int w_Fixture_rayCast(lua_State *L);
|
||||
int w_Fixture_setFilterData(lua_State *L);
|
||||
int w_Fixture_getFilterData(lua_State *L);
|
||||
int w_Fixture_setCategory(lua_State *L);
|
||||
int w_Fixture_getCategory(lua_State *L);
|
||||
int w_Fixture_setMask(lua_State *L);
|
||||
int w_Fixture_getMask(lua_State *L);
|
||||
int w_Fixture_setUserData(lua_State *L);
|
||||
int w_Fixture_getUserData(lua_State *L);
|
||||
int w_Fixture_getBoundingBox(lua_State *L);
|
||||
int w_Fixture_getMassData(lua_State *L);
|
||||
int w_Fixture_getGroupIndex(lua_State *L);
|
||||
int w_Fixture_setGroupIndex(lua_State *L);
|
||||
int w_Fixture_destroy(lua_State *L);
|
||||
extern "C" int luaopen_fixture(lua_State *L);
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_WRAP_FIXTURE_H
|
||||
|
||||
@@ -1,91 +1,91 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#include "wrap_FrictionJoint.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
FrictionJoint *luax_checkfrictionjoint(lua_State *L, int idx)
|
||||
{
|
||||
FrictionJoint *j = luax_checktype<FrictionJoint>(L, idx, "FrictionJoint", PHYSICS_FRICTION_JOINT_T);
|
||||
if (!j->isValid())
|
||||
luaL_error(L, "Attempt to use destroyed joint.");
|
||||
return j;
|
||||
}
|
||||
|
||||
int w_FrictionJoint_setMaxForce(lua_State *L)
|
||||
{
|
||||
FrictionJoint *t = luax_checkfrictionjoint(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
t->setMaxForce(arg1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_FrictionJoint_getMaxForce(lua_State *L)
|
||||
{
|
||||
FrictionJoint *t = luax_checkfrictionjoint(L, 1);
|
||||
lua_pushnumber(L, t->getMaxForce());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_FrictionJoint_setMaxTorque(lua_State *L)
|
||||
{
|
||||
FrictionJoint *t = luax_checkfrictionjoint(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
t->setMaxTorque(arg1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_FrictionJoint_getMaxTorque(lua_State *L)
|
||||
{
|
||||
FrictionJoint *t = luax_checkfrictionjoint(L, 1);
|
||||
lua_pushnumber(L, t->getMaxTorque());
|
||||
return 1;
|
||||
}
|
||||
|
||||
static const luaL_Reg functions[] =
|
||||
{
|
||||
{ "setMaxForce", w_FrictionJoint_setMaxForce },
|
||||
{ "getMaxForce", w_FrictionJoint_getMaxForce },
|
||||
{ "setMaxTorque", w_FrictionJoint_setMaxTorque },
|
||||
{ "getMaxTorque", w_FrictionJoint_getMaxTorque },
|
||||
// From Joint.
|
||||
{ "getType", w_Joint_getType },
|
||||
{ "getAnchors", w_Joint_getAnchors },
|
||||
{ "getReactionForce", w_Joint_getReactionForce },
|
||||
{ "getReactionTorque", w_Joint_getReactionTorque },
|
||||
{ "getCollideConnected", w_Joint_getCollideConnected },
|
||||
{ "destroy", w_Joint_destroy },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
extern "C" int luaopen_frictionjoint(lua_State *L)
|
||||
{
|
||||
return luax_register_type(L, "FrictionJoint", functions);
|
||||
}
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#include "wrap_FrictionJoint.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
FrictionJoint *luax_checkfrictionjoint(lua_State *L, int idx)
|
||||
{
|
||||
FrictionJoint *j = luax_checktype<FrictionJoint>(L, idx, "FrictionJoint", PHYSICS_FRICTION_JOINT_T);
|
||||
if (!j->isValid())
|
||||
luaL_error(L, "Attempt to use destroyed joint.");
|
||||
return j;
|
||||
}
|
||||
|
||||
int w_FrictionJoint_setMaxForce(lua_State *L)
|
||||
{
|
||||
FrictionJoint *t = luax_checkfrictionjoint(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
t->setMaxForce(arg1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_FrictionJoint_getMaxForce(lua_State *L)
|
||||
{
|
||||
FrictionJoint *t = luax_checkfrictionjoint(L, 1);
|
||||
lua_pushnumber(L, t->getMaxForce());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_FrictionJoint_setMaxTorque(lua_State *L)
|
||||
{
|
||||
FrictionJoint *t = luax_checkfrictionjoint(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
t->setMaxTorque(arg1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_FrictionJoint_getMaxTorque(lua_State *L)
|
||||
{
|
||||
FrictionJoint *t = luax_checkfrictionjoint(L, 1);
|
||||
lua_pushnumber(L, t->getMaxTorque());
|
||||
return 1;
|
||||
}
|
||||
|
||||
static const luaL_Reg functions[] =
|
||||
{
|
||||
{ "setMaxForce", w_FrictionJoint_setMaxForce },
|
||||
{ "getMaxForce", w_FrictionJoint_getMaxForce },
|
||||
{ "setMaxTorque", w_FrictionJoint_setMaxTorque },
|
||||
{ "getMaxTorque", w_FrictionJoint_getMaxTorque },
|
||||
// From Joint.
|
||||
{ "getType", w_Joint_getType },
|
||||
{ "getAnchors", w_Joint_getAnchors },
|
||||
{ "getReactionForce", w_Joint_getReactionForce },
|
||||
{ "getReactionTorque", w_Joint_getReactionTorque },
|
||||
{ "getCollideConnected", w_Joint_getCollideConnected },
|
||||
{ "destroy", w_Joint_destroy },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
extern "C" int luaopen_frictionjoint(lua_State *L)
|
||||
{
|
||||
return luax_register_type(L, "FrictionJoint", functions);
|
||||
}
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
@@ -1,47 +1,47 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_PHYSICS_BOX2D_WRAP_FRICTION_JOINT_H
|
||||
#define LOVE_PHYSICS_BOX2D_WRAP_FRICTION_JOINT_H
|
||||
|
||||
// LOVE
|
||||
#include "common/runtime.h"
|
||||
#include "wrap_Joint.h"
|
||||
#include "FrictionJoint.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
FrictionJoint *luax_checkfrictionjoint(lua_State *L, int idx);
|
||||
int w_FrictionJoint_setMaxForce(lua_State *L);
|
||||
int w_FrictionJoint_getMaxForce(lua_State *L);
|
||||
int w_FrictionJoint_setMaxTorque(lua_State *L);
|
||||
int w_FrictionJoint_getMaxTorque(lua_State *L);
|
||||
extern "C" int luaopen_frictionjoint(lua_State *L);
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_WRAP_FRICTION_JOINT_H
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_PHYSICS_BOX2D_WRAP_FRICTION_JOINT_H
|
||||
#define LOVE_PHYSICS_BOX2D_WRAP_FRICTION_JOINT_H
|
||||
|
||||
// LOVE
|
||||
#include "common/runtime.h"
|
||||
#include "wrap_Joint.h"
|
||||
#include "FrictionJoint.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
FrictionJoint *luax_checkfrictionjoint(lua_State *L, int idx);
|
||||
int w_FrictionJoint_setMaxForce(lua_State *L);
|
||||
int w_FrictionJoint_getMaxForce(lua_State *L);
|
||||
int w_FrictionJoint_setMaxTorque(lua_State *L);
|
||||
int w_FrictionJoint_getMaxTorque(lua_State *L);
|
||||
extern "C" int luaopen_frictionjoint(lua_State *L);
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_WRAP_FRICTION_JOINT_H
|
||||
|
||||
@@ -1,74 +1,74 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#include "wrap_GearJoint.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
GearJoint *luax_checkgearjoint(lua_State *L, int idx)
|
||||
{
|
||||
GearJoint *j = luax_checktype<GearJoint>(L, idx, "GearJoint", PHYSICS_GEAR_JOINT_T);
|
||||
if (!j->isValid())
|
||||
luaL_error(L, "Attempt to use destroyed joint.");
|
||||
return j;
|
||||
}
|
||||
|
||||
int w_GearJoint_setRatio(lua_State *L)
|
||||
{
|
||||
GearJoint *t = luax_checkgearjoint(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
t->setRatio(arg1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_GearJoint_getRatio(lua_State *L)
|
||||
{
|
||||
GearJoint *t = luax_checkgearjoint(L, 1);
|
||||
lua_pushnumber(L, t->getRatio());
|
||||
return 1;
|
||||
}
|
||||
|
||||
static const luaL_Reg functions[] =
|
||||
{
|
||||
{ "setRatio", w_GearJoint_setRatio },
|
||||
{ "getRatio", w_GearJoint_getRatio },
|
||||
// From Joint.
|
||||
{ "getType", w_Joint_getType },
|
||||
{ "getAnchors", w_Joint_getAnchors },
|
||||
{ "getReactionForce", w_Joint_getReactionForce },
|
||||
{ "getReactionTorque", w_Joint_getReactionTorque },
|
||||
{ "getCollideConnected", w_Joint_getCollideConnected },
|
||||
{ "destroy", w_Joint_destroy },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
extern "C" int luaopen_gearjoint(lua_State *L)
|
||||
{
|
||||
return luax_register_type(L, "GearJoint", functions);
|
||||
}
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#include "wrap_GearJoint.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
GearJoint *luax_checkgearjoint(lua_State *L, int idx)
|
||||
{
|
||||
GearJoint *j = luax_checktype<GearJoint>(L, idx, "GearJoint", PHYSICS_GEAR_JOINT_T);
|
||||
if (!j->isValid())
|
||||
luaL_error(L, "Attempt to use destroyed joint.");
|
||||
return j;
|
||||
}
|
||||
|
||||
int w_GearJoint_setRatio(lua_State *L)
|
||||
{
|
||||
GearJoint *t = luax_checkgearjoint(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
t->setRatio(arg1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_GearJoint_getRatio(lua_State *L)
|
||||
{
|
||||
GearJoint *t = luax_checkgearjoint(L, 1);
|
||||
lua_pushnumber(L, t->getRatio());
|
||||
return 1;
|
||||
}
|
||||
|
||||
static const luaL_Reg functions[] =
|
||||
{
|
||||
{ "setRatio", w_GearJoint_setRatio },
|
||||
{ "getRatio", w_GearJoint_getRatio },
|
||||
// From Joint.
|
||||
{ "getType", w_Joint_getType },
|
||||
{ "getAnchors", w_Joint_getAnchors },
|
||||
{ "getReactionForce", w_Joint_getReactionForce },
|
||||
{ "getReactionTorque", w_Joint_getReactionTorque },
|
||||
{ "getCollideConnected", w_Joint_getCollideConnected },
|
||||
{ "destroy", w_Joint_destroy },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
extern "C" int luaopen_gearjoint(lua_State *L)
|
||||
{
|
||||
return luax_register_type(L, "GearJoint", functions);
|
||||
}
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
@@ -1,45 +1,45 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_PHYSICS_BOX2D_WRAP_GEAR_JOINT_H
|
||||
#define LOVE_PHYSICS_BOX2D_WRAP_GEAR_JOINT_H
|
||||
|
||||
// LOVE
|
||||
#include "common/runtime.h"
|
||||
#include "wrap_Joint.h"
|
||||
#include "GearJoint.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
GearJoint *luax_checkgearjoint(lua_State *L, int idx);
|
||||
int w_GearJoint_setRatio(lua_State *L);
|
||||
int w_GearJoint_getRatio(lua_State *L);
|
||||
extern "C" int luaopen_gearjoint(lua_State *L);
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_WRAP_GEAR_JOINT_H
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_PHYSICS_BOX2D_WRAP_GEAR_JOINT_H
|
||||
#define LOVE_PHYSICS_BOX2D_WRAP_GEAR_JOINT_H
|
||||
|
||||
// LOVE
|
||||
#include "common/runtime.h"
|
||||
#include "wrap_Joint.h"
|
||||
#include "GearJoint.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
GearJoint *luax_checkgearjoint(lua_State *L, int idx);
|
||||
int w_GearJoint_setRatio(lua_State *L);
|
||||
int w_GearJoint_getRatio(lua_State *L);
|
||||
extern "C" int luaopen_gearjoint(lua_State *L);
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_WRAP_GEAR_JOINT_H
|
||||
|
||||
@@ -1,110 +1,110 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
// LOVE
|
||||
#include "wrap_Joint.h"
|
||||
#include "common/StringMap.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
Joint *luax_checkjoint(lua_State *L, int idx)
|
||||
{
|
||||
Joint *t = luax_checktype<Joint>(L, idx, "Joint", PHYSICS_JOINT_T);
|
||||
if (!t->isValid())
|
||||
luaL_error(L, "Attempt to use destroyed joint.");
|
||||
return t;
|
||||
}
|
||||
|
||||
int w_Joint_getType(lua_State *L)
|
||||
{
|
||||
Joint *t = luax_checkjoint(L, 1);
|
||||
const char *type = "";
|
||||
Joint::getConstant(t->getType(), type);
|
||||
lua_pushstring(L, type);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_Joint_getAnchors(lua_State *L)
|
||||
{
|
||||
Joint *t = luax_checkjoint(L, 1);
|
||||
lua_remove(L, 1);
|
||||
return t->getAnchors(L);
|
||||
}
|
||||
|
||||
int w_Joint_getReactionForce(lua_State *L)
|
||||
{
|
||||
Joint *t = luax_checkjoint(L, 1);
|
||||
lua_remove(L, 1);
|
||||
return t->getReactionForce(L);
|
||||
}
|
||||
|
||||
int w_Joint_getReactionTorque(lua_State *L)
|
||||
{
|
||||
Joint *t = luax_checkjoint(L, 1);
|
||||
float inv_dt = (float)luaL_checknumber(L, 2);
|
||||
lua_pushnumber(L, t->getReactionTorque(inv_dt));
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_Joint_getCollideConnected(lua_State *L)
|
||||
{
|
||||
Joint *t = luax_checkjoint(L, 1);
|
||||
luax_pushboolean(L, t->getCollideConnected());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_Joint_destroy(lua_State *L)
|
||||
{
|
||||
Joint *t = luax_checkjoint(L, 1);
|
||||
try
|
||||
{
|
||||
t->destroyJoint();
|
||||
}
|
||||
catch(love::Exception &e)
|
||||
{
|
||||
luaL_error(L, "%s", e.what());
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const luaL_Reg functions[] =
|
||||
{
|
||||
{ "getType", w_Joint_getType },
|
||||
{ "getAnchors", w_Joint_getAnchors },
|
||||
{ "getReactionForce", w_Joint_getReactionForce },
|
||||
{ "getReactionTorque", w_Joint_getReactionTorque },
|
||||
{ "getCollideConnected", w_Joint_getCollideConnected },
|
||||
{ "destroy", w_Joint_destroy },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
extern "C" int luaopen_joint(lua_State *L)
|
||||
{
|
||||
return luax_register_type(L, "Joint", functions);
|
||||
}
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
// LOVE
|
||||
#include "wrap_Joint.h"
|
||||
#include "common/StringMap.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
Joint *luax_checkjoint(lua_State *L, int idx)
|
||||
{
|
||||
Joint *t = luax_checktype<Joint>(L, idx, "Joint", PHYSICS_JOINT_T);
|
||||
if (!t->isValid())
|
||||
luaL_error(L, "Attempt to use destroyed joint.");
|
||||
return t;
|
||||
}
|
||||
|
||||
int w_Joint_getType(lua_State *L)
|
||||
{
|
||||
Joint *t = luax_checkjoint(L, 1);
|
||||
const char *type = "";
|
||||
Joint::getConstant(t->getType(), type);
|
||||
lua_pushstring(L, type);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_Joint_getAnchors(lua_State *L)
|
||||
{
|
||||
Joint *t = luax_checkjoint(L, 1);
|
||||
lua_remove(L, 1);
|
||||
return t->getAnchors(L);
|
||||
}
|
||||
|
||||
int w_Joint_getReactionForce(lua_State *L)
|
||||
{
|
||||
Joint *t = luax_checkjoint(L, 1);
|
||||
lua_remove(L, 1);
|
||||
return t->getReactionForce(L);
|
||||
}
|
||||
|
||||
int w_Joint_getReactionTorque(lua_State *L)
|
||||
{
|
||||
Joint *t = luax_checkjoint(L, 1);
|
||||
float inv_dt = (float)luaL_checknumber(L, 2);
|
||||
lua_pushnumber(L, t->getReactionTorque(inv_dt));
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_Joint_getCollideConnected(lua_State *L)
|
||||
{
|
||||
Joint *t = luax_checkjoint(L, 1);
|
||||
luax_pushboolean(L, t->getCollideConnected());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_Joint_destroy(lua_State *L)
|
||||
{
|
||||
Joint *t = luax_checkjoint(L, 1);
|
||||
try
|
||||
{
|
||||
t->destroyJoint();
|
||||
}
|
||||
catch(love::Exception &e)
|
||||
{
|
||||
luaL_error(L, "%s", e.what());
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const luaL_Reg functions[] =
|
||||
{
|
||||
{ "getType", w_Joint_getType },
|
||||
{ "getAnchors", w_Joint_getAnchors },
|
||||
{ "getReactionForce", w_Joint_getReactionForce },
|
||||
{ "getReactionTorque", w_Joint_getReactionTorque },
|
||||
{ "getCollideConnected", w_Joint_getCollideConnected },
|
||||
{ "destroy", w_Joint_destroy },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
extern "C" int luaopen_joint(lua_State *L)
|
||||
{
|
||||
return luax_register_type(L, "Joint", functions);
|
||||
}
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
@@ -1,48 +1,48 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_PHYSICS_BOX2D_WRAP_JOINT_H
|
||||
#define LOVE_PHYSICS_BOX2D_WRAP_JOINT_H
|
||||
|
||||
// LOVE
|
||||
#include "common/runtime.h"
|
||||
#include "Joint.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
Joint *luax_checkjoint(lua_State *L, int idx);
|
||||
int w_Joint_getType(lua_State *L);
|
||||
int w_Joint_getAnchors(lua_State *L);
|
||||
int w_Joint_getReactionForce(lua_State *L);
|
||||
int w_Joint_getReactionTorque(lua_State *L);
|
||||
int w_Joint_getCollideConnected(lua_State *L);
|
||||
int w_Joint_destroy(lua_State *L);
|
||||
extern "C" int luaopen_joint(lua_State *L);
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_WRAP_JOINT_H
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_PHYSICS_BOX2D_WRAP_JOINT_H
|
||||
#define LOVE_PHYSICS_BOX2D_WRAP_JOINT_H
|
||||
|
||||
// LOVE
|
||||
#include "common/runtime.h"
|
||||
#include "Joint.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
Joint *luax_checkjoint(lua_State *L, int idx);
|
||||
int w_Joint_getType(lua_State *L);
|
||||
int w_Joint_getAnchors(lua_State *L);
|
||||
int w_Joint_getReactionForce(lua_State *L);
|
||||
int w_Joint_getReactionTorque(lua_State *L);
|
||||
int w_Joint_getCollideConnected(lua_State *L);
|
||||
int w_Joint_destroy(lua_State *L);
|
||||
extern "C" int luaopen_joint(lua_State *L);
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_WRAP_JOINT_H
|
||||
|
||||
@@ -1,126 +1,126 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#include "wrap_MouseJoint.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
MouseJoint *luax_checkmousejoint(lua_State *L, int idx)
|
||||
{
|
||||
MouseJoint *j = luax_checktype<MouseJoint>(L, idx, "MouseJoint", PHYSICS_MOUSE_JOINT_T);
|
||||
if (!j->isValid())
|
||||
luaL_error(L, "Attempt to use destroyed joint.");
|
||||
return j;
|
||||
}
|
||||
|
||||
int w_MouseJoint_setTarget(lua_State *L)
|
||||
{
|
||||
MouseJoint *t = luax_checkmousejoint(L, 1);
|
||||
float x = (float)luaL_checknumber(L, 2);
|
||||
float y = (float)luaL_checknumber(L, 3);
|
||||
t->setTarget(x, y);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_MouseJoint_getTarget(lua_State *L)
|
||||
{
|
||||
MouseJoint *t = luax_checkmousejoint(L, 1);
|
||||
lua_remove(L, 1);
|
||||
return t->getTarget(L);
|
||||
}
|
||||
|
||||
int w_MouseJoint_setMaxForce(lua_State *L)
|
||||
{
|
||||
MouseJoint *t = luax_checkmousejoint(L, 1);
|
||||
float f = (float)luaL_checknumber(L, 2);
|
||||
t->setMaxForce(f);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_MouseJoint_getMaxForce(lua_State *L)
|
||||
{
|
||||
MouseJoint *t = luax_checkmousejoint(L, 1);
|
||||
lua_pushnumber(L, t->getMaxForce());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_MouseJoint_setFrequency(lua_State *L)
|
||||
{
|
||||
MouseJoint *t = luax_checkmousejoint(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
t->setFrequency(arg1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_MouseJoint_getFrequency(lua_State *L)
|
||||
{
|
||||
MouseJoint *t = luax_checkmousejoint(L, 1);
|
||||
lua_pushnumber(L, t->getFrequency());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_MouseJoint_setDampingRatio(lua_State *L)
|
||||
{
|
||||
MouseJoint *t = luax_checkmousejoint(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
t->setDampingRatio(arg1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_MouseJoint_getDampingRatio(lua_State *L)
|
||||
{
|
||||
MouseJoint *t = luax_checkmousejoint(L, 1);
|
||||
lua_pushnumber(L, t->getDampingRatio());
|
||||
return 1;
|
||||
}
|
||||
|
||||
static const luaL_Reg functions[] =
|
||||
{
|
||||
{ "setTarget", w_MouseJoint_setTarget },
|
||||
{ "getTarget", w_MouseJoint_getTarget },
|
||||
{ "setMaxForce", w_MouseJoint_setMaxForce },
|
||||
{ "getMaxForce", w_MouseJoint_getMaxForce },
|
||||
{ "setFrequency", w_MouseJoint_setFrequency },
|
||||
{ "getFrequency", w_MouseJoint_getFrequency },
|
||||
{ "setDampingRatio", w_MouseJoint_setDampingRatio },
|
||||
{ "getDampingRatio", w_MouseJoint_getDampingRatio },
|
||||
// From Joint.
|
||||
{ "getType", w_Joint_getType },
|
||||
{ "getAnchors", w_Joint_getAnchors },
|
||||
{ "getReactionForce", w_Joint_getReactionForce },
|
||||
{ "getReactionTorque", w_Joint_getReactionTorque },
|
||||
{ "getCollideConnected", w_Joint_getCollideConnected },
|
||||
{ "destroy", w_Joint_destroy },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
extern "C" int luaopen_mousejoint(lua_State *L)
|
||||
{
|
||||
return luax_register_type(L, "MouseJoint", functions);
|
||||
}
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#include "wrap_MouseJoint.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
MouseJoint *luax_checkmousejoint(lua_State *L, int idx)
|
||||
{
|
||||
MouseJoint *j = luax_checktype<MouseJoint>(L, idx, "MouseJoint", PHYSICS_MOUSE_JOINT_T);
|
||||
if (!j->isValid())
|
||||
luaL_error(L, "Attempt to use destroyed joint.");
|
||||
return j;
|
||||
}
|
||||
|
||||
int w_MouseJoint_setTarget(lua_State *L)
|
||||
{
|
||||
MouseJoint *t = luax_checkmousejoint(L, 1);
|
||||
float x = (float)luaL_checknumber(L, 2);
|
||||
float y = (float)luaL_checknumber(L, 3);
|
||||
t->setTarget(x, y);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_MouseJoint_getTarget(lua_State *L)
|
||||
{
|
||||
MouseJoint *t = luax_checkmousejoint(L, 1);
|
||||
lua_remove(L, 1);
|
||||
return t->getTarget(L);
|
||||
}
|
||||
|
||||
int w_MouseJoint_setMaxForce(lua_State *L)
|
||||
{
|
||||
MouseJoint *t = luax_checkmousejoint(L, 1);
|
||||
float f = (float)luaL_checknumber(L, 2);
|
||||
t->setMaxForce(f);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_MouseJoint_getMaxForce(lua_State *L)
|
||||
{
|
||||
MouseJoint *t = luax_checkmousejoint(L, 1);
|
||||
lua_pushnumber(L, t->getMaxForce());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_MouseJoint_setFrequency(lua_State *L)
|
||||
{
|
||||
MouseJoint *t = luax_checkmousejoint(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
t->setFrequency(arg1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_MouseJoint_getFrequency(lua_State *L)
|
||||
{
|
||||
MouseJoint *t = luax_checkmousejoint(L, 1);
|
||||
lua_pushnumber(L, t->getFrequency());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_MouseJoint_setDampingRatio(lua_State *L)
|
||||
{
|
||||
MouseJoint *t = luax_checkmousejoint(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
t->setDampingRatio(arg1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_MouseJoint_getDampingRatio(lua_State *L)
|
||||
{
|
||||
MouseJoint *t = luax_checkmousejoint(L, 1);
|
||||
lua_pushnumber(L, t->getDampingRatio());
|
||||
return 1;
|
||||
}
|
||||
|
||||
static const luaL_Reg functions[] =
|
||||
{
|
||||
{ "setTarget", w_MouseJoint_setTarget },
|
||||
{ "getTarget", w_MouseJoint_getTarget },
|
||||
{ "setMaxForce", w_MouseJoint_setMaxForce },
|
||||
{ "getMaxForce", w_MouseJoint_getMaxForce },
|
||||
{ "setFrequency", w_MouseJoint_setFrequency },
|
||||
{ "getFrequency", w_MouseJoint_getFrequency },
|
||||
{ "setDampingRatio", w_MouseJoint_setDampingRatio },
|
||||
{ "getDampingRatio", w_MouseJoint_getDampingRatio },
|
||||
// From Joint.
|
||||
{ "getType", w_Joint_getType },
|
||||
{ "getAnchors", w_Joint_getAnchors },
|
||||
{ "getReactionForce", w_Joint_getReactionForce },
|
||||
{ "getReactionTorque", w_Joint_getReactionTorque },
|
||||
{ "getCollideConnected", w_Joint_getCollideConnected },
|
||||
{ "destroy", w_Joint_destroy },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
extern "C" int luaopen_mousejoint(lua_State *L)
|
||||
{
|
||||
return luax_register_type(L, "MouseJoint", functions);
|
||||
}
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
@@ -1,51 +1,51 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_PHYSICS_BOX2D_WRAP_MOUSE_JOINT_H
|
||||
#define LOVE_PHYSICS_BOX2D_WRAP_MOUSE_JOINT_H
|
||||
|
||||
// LOVE
|
||||
#include "common/runtime.h"
|
||||
#include "wrap_Joint.h"
|
||||
#include "MouseJoint.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
MouseJoint *luax_checkmousejoint(lua_State *L, int idx);
|
||||
int w_MouseJoint_setTarget(lua_State *L);
|
||||
int w_MouseJoint_getTarget(lua_State *L);
|
||||
int w_MouseJoint_setMaxForce(lua_State *L);
|
||||
int w_MouseJoint_getMaxForce(lua_State *L);
|
||||
int w_MouseJoint_setFrequency(lua_State *L);
|
||||
int w_MouseJoint_getFrequency(lua_State *L);
|
||||
int w_MouseJoint_setDampingRatio(lua_State *L);
|
||||
int w_MouseJoint_getDampingRatio(lua_State *L);
|
||||
extern "C" int luaopen_mousejoint(lua_State *L);
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_WRAP_MOUSE_JOINT_H
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_PHYSICS_BOX2D_WRAP_MOUSE_JOINT_H
|
||||
#define LOVE_PHYSICS_BOX2D_WRAP_MOUSE_JOINT_H
|
||||
|
||||
// LOVE
|
||||
#include "common/runtime.h"
|
||||
#include "wrap_Joint.h"
|
||||
#include "MouseJoint.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
MouseJoint *luax_checkmousejoint(lua_State *L, int idx);
|
||||
int w_MouseJoint_setTarget(lua_State *L);
|
||||
int w_MouseJoint_getTarget(lua_State *L);
|
||||
int w_MouseJoint_setMaxForce(lua_State *L);
|
||||
int w_MouseJoint_getMaxForce(lua_State *L);
|
||||
int w_MouseJoint_setFrequency(lua_State *L);
|
||||
int w_MouseJoint_getFrequency(lua_State *L);
|
||||
int w_MouseJoint_setDampingRatio(lua_State *L);
|
||||
int w_MouseJoint_getDampingRatio(lua_State *L);
|
||||
extern "C" int luaopen_mousejoint(lua_State *L);
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_WRAP_MOUSE_JOINT_H
|
||||
|
||||
@@ -1,475 +1,475 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
// LOVE
|
||||
#include "wrap_Physics.h"
|
||||
#include "wrap_World.h"
|
||||
#include "wrap_Contact.h"
|
||||
#include "wrap_Body.h"
|
||||
#include "wrap_Fixture.h"
|
||||
#include "wrap_Shape.h"
|
||||
#include "wrap_CircleShape.h"
|
||||
#include "wrap_PolygonShape.h"
|
||||
#include "wrap_EdgeShape.h"
|
||||
#include "wrap_ChainShape.h"
|
||||
#include "wrap_Joint.h"
|
||||
#include "wrap_MouseJoint.h"
|
||||
#include "wrap_DistanceJoint.h"
|
||||
#include "wrap_PrismaticJoint.h"
|
||||
#include "wrap_RevoluteJoint.h"
|
||||
#include "wrap_PulleyJoint.h"
|
||||
#include "wrap_GearJoint.h"
|
||||
#include "wrap_FrictionJoint.h"
|
||||
#include "wrap_WeldJoint.h"
|
||||
#include "wrap_WheelJoint.h"
|
||||
#include "wrap_RopeJoint.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
static Physics *instance = 0;
|
||||
|
||||
int w_newWorld(lua_State *L)
|
||||
{
|
||||
float gx = (float)luaL_optnumber(L, 1, 0);
|
||||
float gy = (float)luaL_optnumber(L, 2, 0);
|
||||
bool sleep = luax_optboolean(L, 3, true);
|
||||
|
||||
World *w;
|
||||
ASSERT_GUARD(w = instance->newWorld(gx, gy, sleep);)
|
||||
luax_newtype(L, "World", PHYSICS_WORLD_T, (void *)w);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_newBody(lua_State *L)
|
||||
{
|
||||
World *world = luax_checktype<World>(L, 1, "World", PHYSICS_WORLD_T);
|
||||
float x = (float)luaL_optnumber(L, 2, 0.0);
|
||||
float y = (float)luaL_optnumber(L, 3, 0.0);
|
||||
const char *type = luaL_optstring(L, 4, "static");
|
||||
Body::Type bodyType;
|
||||
Body::getConstant(type, bodyType);
|
||||
Body *body;
|
||||
ASSERT_GUARD(body = instance->newBody(world, x, y, bodyType);)
|
||||
luax_newtype(L, "Body", PHYSICS_BODY_T, (void *)body);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_newFixture(lua_State *L)
|
||||
{
|
||||
Body *body = luax_checkbody(L, 1);
|
||||
Shape *shape = luax_checkshape(L, 2);
|
||||
float density = (float)luaL_optnumber(L, 3, 1.0f);
|
||||
Fixture *fixture;
|
||||
ASSERT_GUARD(fixture = instance->newFixture(body, shape, density);)
|
||||
luax_newtype(L, "Fixture", PHYSICS_FIXTURE_T, (void *)fixture);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_newCircleShape(lua_State *L)
|
||||
{
|
||||
int top = lua_gettop(L);
|
||||
|
||||
if (top == 1)
|
||||
{
|
||||
float radius = (float)luaL_checknumber(L, 1);
|
||||
CircleShape *shape;
|
||||
ASSERT_GUARD(shape = instance->newCircleShape(radius);)
|
||||
luax_newtype(L, "CircleShape", PHYSICS_CIRCLE_SHAPE_T, (void *)shape);
|
||||
return 1;
|
||||
}
|
||||
else if (top == 3)
|
||||
{
|
||||
float x = (float)luaL_checknumber(L, 1);
|
||||
float y = (float)luaL_checknumber(L, 2);
|
||||
float radius = (float)luaL_checknumber(L, 3);
|
||||
CircleShape *shape;
|
||||
ASSERT_GUARD(shape = instance->newCircleShape(x, y, radius);)
|
||||
luax_newtype(L, "CircleShape", PHYSICS_CIRCLE_SHAPE_T, (void *)shape);
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
return luaL_error(L, "Incorrect number of parameters");
|
||||
}
|
||||
|
||||
int w_newRectangleShape(lua_State *L)
|
||||
{
|
||||
int top = lua_gettop(L);
|
||||
|
||||
if (top == 2)
|
||||
{
|
||||
float w = (float)luaL_checknumber(L, 1);
|
||||
float h = (float)luaL_checknumber(L, 2);
|
||||
PolygonShape *shape;
|
||||
ASSERT_GUARD(shape = instance->newRectangleShape(w, h);)
|
||||
luax_newtype(L, "PolygonShape", PHYSICS_POLYGON_SHAPE_T, (void *)shape);
|
||||
return 1;
|
||||
}
|
||||
else if (top == 4 || top == 5)
|
||||
{
|
||||
float x = (float)luaL_checknumber(L, 1);
|
||||
float y = (float)luaL_checknumber(L, 2);
|
||||
float w = (float)luaL_checknumber(L, 3);
|
||||
float h = (float)luaL_checknumber(L, 4);
|
||||
float angle = (float)luaL_optnumber(L, 5, 0);
|
||||
PolygonShape *shape;
|
||||
ASSERT_GUARD(shape = instance->newRectangleShape(x, y, w, h, angle);)
|
||||
luax_newtype(L, "PolygonShape", PHYSICS_POLYGON_SHAPE_T, (void *)shape);
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
return luaL_error(L, "Incorrect number of parameters");
|
||||
}
|
||||
|
||||
int w_newEdgeShape(lua_State *L)
|
||||
{
|
||||
float x1 = (float)luaL_checknumber(L, 1);
|
||||
float y1 = (float)luaL_checknumber(L, 2);
|
||||
float x2 = (float)luaL_checknumber(L, 3);
|
||||
float y2 = (float)luaL_checknumber(L, 4);
|
||||
EdgeShape *shape;
|
||||
ASSERT_GUARD(shape = instance->newEdgeShape(x1, y1, x2, y2);)
|
||||
luax_newtype(L, "EdgeShape", PHYSICS_EDGE_SHAPE_T, (void *)shape);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_newPolygonShape(lua_State *L)
|
||||
{
|
||||
ASSERT_GUARD(return instance->newPolygonShape(L);)
|
||||
}
|
||||
|
||||
int w_newChainShape(lua_State *L)
|
||||
{
|
||||
ASSERT_GUARD(return instance->newChainShape(L);)
|
||||
}
|
||||
|
||||
int w_newDistanceJoint(lua_State *L)
|
||||
{
|
||||
Body *body1 = luax_checktype<Body>(L, 1, "Body", PHYSICS_BODY_T);
|
||||
Body *body2 = luax_checktype<Body>(L, 2, "Body", PHYSICS_BODY_T);
|
||||
float x1 = (float)luaL_checknumber(L, 3);
|
||||
float y1 = (float)luaL_checknumber(L, 4);
|
||||
float x2 = (float)luaL_checknumber(L, 5);
|
||||
float y2 = (float)luaL_checknumber(L, 6);
|
||||
bool collideConnected = luax_optboolean(L, 7, false);
|
||||
DistanceJoint *j;
|
||||
ASSERT_GUARD(j = instance->newDistanceJoint(body1, body2, x1, y1, x2, y2, collideConnected);)
|
||||
luax_newtype(L, "DistanceJoint", PHYSICS_DISTANCE_JOINT_T, (void *)j);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_newMouseJoint(lua_State *L)
|
||||
{
|
||||
Body *body = luax_checktype<Body>(L, 1, "Body", PHYSICS_BODY_T);
|
||||
float x = (float)luaL_checknumber(L, 2);
|
||||
float y = (float)luaL_checknumber(L, 3);
|
||||
MouseJoint *j;
|
||||
ASSERT_GUARD(j = instance->newMouseJoint(body, x, y);)
|
||||
luax_newtype(L, "MouseJoint", PHYSICS_MOUSE_JOINT_T, (void *)j);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_newRevoluteJoint(lua_State *L)
|
||||
{
|
||||
Body *body1 = luax_checktype<Body>(L, 1, "Body", PHYSICS_BODY_T);
|
||||
Body *body2 = luax_checktype<Body>(L, 2, "Body", PHYSICS_BODY_T);
|
||||
float x = (float)luaL_checknumber(L, 3);
|
||||
float y = (float)luaL_checknumber(L, 4);
|
||||
bool collideConnected = luax_optboolean(L, 5, false);
|
||||
RevoluteJoint *j;
|
||||
ASSERT_GUARD(j = instance->newRevoluteJoint(body1, body2, x, y, collideConnected);)
|
||||
luax_newtype(L, "RevoluteJoint", PHYSICS_REVOLUTE_JOINT_T, (void *)j);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_newPrismaticJoint(lua_State *L)
|
||||
{
|
||||
Body *body1 = luax_checktype<Body>(L, 1, "Body", PHYSICS_BODY_T);
|
||||
Body *body2 = luax_checktype<Body>(L, 2, "Body", PHYSICS_BODY_T);
|
||||
float xA = (float)luaL_checknumber(L, 3);
|
||||
float yA = (float)luaL_checknumber(L, 4);
|
||||
float xB, yB, ax, ay;
|
||||
bool collideConnected;
|
||||
if (lua_gettop(L) >= 8)
|
||||
{
|
||||
xB = (float)luaL_checknumber(L, 5);
|
||||
yB = (float)luaL_checknumber(L, 6);
|
||||
ax = (float)luaL_checknumber(L, 7);
|
||||
ay = (float)luaL_checknumber(L, 8);
|
||||
collideConnected = luax_optboolean(L, 9, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
xB = xA;
|
||||
yB = yA;
|
||||
ax = (float)luaL_checknumber(L, 5);
|
||||
ay = (float)luaL_checknumber(L, 6);
|
||||
collideConnected = luax_optboolean(L, 7, false);
|
||||
}
|
||||
PrismaticJoint *j;
|
||||
ASSERT_GUARD(j = instance->newPrismaticJoint(body1, body2, xA, yA, xB, yB, ax, ay, collideConnected);)
|
||||
luax_newtype(L, "PrismaticJoint", PHYSICS_PRISMATIC_JOINT_T, (void *)j);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_newPulleyJoint(lua_State *L)
|
||||
{
|
||||
Body *body1 = luax_checktype<Body>(L, 1, "Body", PHYSICS_BODY_T);
|
||||
Body *body2 = luax_checktype<Body>(L, 2, "Body", PHYSICS_BODY_T);
|
||||
float gx1 = (float)luaL_checknumber(L, 3);
|
||||
float gy1 = (float)luaL_checknumber(L, 4);
|
||||
float gx2 = (float)luaL_checknumber(L, 5);
|
||||
float gy2 = (float)luaL_checknumber(L, 6);
|
||||
float x1 = (float)luaL_checknumber(L, 7);
|
||||
float y1 = (float)luaL_checknumber(L, 8);
|
||||
float x2 = (float)luaL_checknumber(L, 9);
|
||||
float y2 = (float)luaL_checknumber(L, 10);
|
||||
float ratio = (float)luaL_optnumber(L, 11, 1.0);
|
||||
bool collideConnected = luax_optboolean(L, 12, true); // PulleyJoints default to colliding connected bodies, see b2PulleyJoint.h
|
||||
|
||||
PulleyJoint *j;
|
||||
ASSERT_GUARD(j = instance->newPulleyJoint(body1, body2, b2Vec2(gx1,gy1), b2Vec2(gx2,gy2), b2Vec2(x1,y1), b2Vec2(x2,y2), ratio, collideConnected);)
|
||||
luax_newtype(L, "PulleyJoint", PHYSICS_PULLEY_JOINT_T, (void *)j);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_newGearJoint(lua_State *L)
|
||||
{
|
||||
Joint *joint1 = luax_checktype<Joint>(L, 1, "Joint", PHYSICS_JOINT_T);
|
||||
Joint *joint2 = luax_checktype<Joint>(L, 2, "Joint", PHYSICS_JOINT_T);
|
||||
float ratio = (float)luaL_optnumber(L, 3, 1.0);
|
||||
bool collideConnected = luax_optboolean(L, 4, false);
|
||||
|
||||
GearJoint *j;
|
||||
ASSERT_GUARD(j = instance->newGearJoint(joint1, joint2, ratio, collideConnected);)
|
||||
luax_newtype(L, "GearJoint", PHYSICS_GEAR_JOINT_T, (void *)j);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_newFrictionJoint(lua_State *L)
|
||||
{
|
||||
Body *body1 = luax_checktype<Body>(L, 1, "Body", PHYSICS_BODY_T);
|
||||
Body *body2 = luax_checktype<Body>(L, 2, "Body", PHYSICS_BODY_T);
|
||||
float xA = (float)luaL_checknumber(L, 3);
|
||||
float yA = (float)luaL_checknumber(L, 4);
|
||||
float xB, yB;
|
||||
bool collideConnected;
|
||||
if (lua_gettop(L) >= 6)
|
||||
{
|
||||
xB = (float)luaL_checknumber(L, 5);
|
||||
yB = (float)luaL_checknumber(L, 6);
|
||||
collideConnected = luax_optboolean(L, 7, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
xB = xA;
|
||||
yB = yA;
|
||||
collideConnected = luax_optboolean(L, 5, false);
|
||||
}
|
||||
FrictionJoint *j;
|
||||
ASSERT_GUARD(j = instance->newFrictionJoint(body1, body2, xA, yA, xB, yB, collideConnected);)
|
||||
luax_newtype(L, "FrictionJoint", PHYSICS_FRICTION_JOINT_T, (void *)j);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_newWeldJoint(lua_State *L)
|
||||
{
|
||||
Body *body1 = luax_checktype<Body>(L, 1, "Body", PHYSICS_BODY_T);
|
||||
Body *body2 = luax_checktype<Body>(L, 2, "Body", PHYSICS_BODY_T);
|
||||
float xA = (float)luaL_checknumber(L, 3);
|
||||
float yA = (float)luaL_checknumber(L, 4);
|
||||
float xB, yB;
|
||||
bool collideConnected;
|
||||
if (lua_gettop(L) >= 6)
|
||||
{
|
||||
xB = (float)luaL_checknumber(L, 5);
|
||||
yB = (float)luaL_checknumber(L, 6);
|
||||
collideConnected = luax_optboolean(L, 7, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
xB = xA;
|
||||
yB = yA;
|
||||
collideConnected = luax_optboolean(L, 5, false);
|
||||
}
|
||||
WeldJoint *j;
|
||||
ASSERT_GUARD(j = instance->newWeldJoint(body1, body2, xA, yA, xB, yB, collideConnected);)
|
||||
luax_newtype(L, "WeldJoint", PHYSICS_WELD_JOINT_T, (void *)j);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_newWheelJoint(lua_State *L)
|
||||
{
|
||||
Body *body1 = luax_checktype<Body>(L, 1, "Body", PHYSICS_BODY_T);
|
||||
Body *body2 = luax_checktype<Body>(L, 2, "Body", PHYSICS_BODY_T);
|
||||
float xA = (float)luaL_checknumber(L, 3);
|
||||
float yA = (float)luaL_checknumber(L, 4);
|
||||
float xB, yB, ax, ay;
|
||||
bool collideConnected;
|
||||
if (lua_gettop(L) >= 8)
|
||||
{
|
||||
xB = (float)luaL_checknumber(L, 5);
|
||||
yB = (float)luaL_checknumber(L, 6);
|
||||
ax = (float)luaL_checknumber(L, 7);
|
||||
ay = (float)luaL_checknumber(L, 8);
|
||||
collideConnected = luax_optboolean(L, 9, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
xB = xA;
|
||||
yB = yA;
|
||||
ax = (float)luaL_checknumber(L, 5);
|
||||
ay = (float)luaL_checknumber(L, 6);
|
||||
collideConnected = luax_optboolean(L, 7, false);
|
||||
}
|
||||
|
||||
WheelJoint *j;
|
||||
ASSERT_GUARD(j = instance->newWheelJoint(body1, body2, xA, yA, xB, yB, ax, ay, collideConnected);)
|
||||
luax_newtype(L, "WheelJoint", PHYSICS_WHEEL_JOINT_T, (void *)j);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_newRopeJoint(lua_State *L)
|
||||
{
|
||||
Body *body1 = luax_checktype<Body>(L, 1, "Body", PHYSICS_BODY_T);
|
||||
Body *body2 = luax_checktype<Body>(L, 2, "Body", PHYSICS_BODY_T);
|
||||
float x1 = (float)luaL_checknumber(L, 3);
|
||||
float y1 = (float)luaL_checknumber(L, 4);
|
||||
float x2 = (float)luaL_checknumber(L, 5);
|
||||
float y2 = (float)luaL_checknumber(L, 6);
|
||||
float maxLength = (float)luaL_checknumber(L, 7);
|
||||
bool collideConnected = luax_optboolean(L, 8, false);
|
||||
RopeJoint *j;
|
||||
ASSERT_GUARD(j = instance->newRopeJoint(body1, body2, x1, y1, x2, y2, maxLength, collideConnected);)
|
||||
luax_newtype(L, "RopeJoint", PHYSICS_ROPE_JOINT_T, (void *)j);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_getDistance(lua_State *L)
|
||||
{
|
||||
return instance->getDistance(L);
|
||||
}
|
||||
|
||||
int w_setMeter(lua_State *L)
|
||||
{
|
||||
int arg1 = luaL_checkint(L, 1);
|
||||
try
|
||||
{
|
||||
Physics::setMeter(arg1);
|
||||
}
|
||||
catch(love::Exception &e)
|
||||
{
|
||||
return luaL_error(L, e.what());
|
||||
}
|
||||
return 0;
|
||||
|
||||
}
|
||||
int w_getMeter(lua_State *L)
|
||||
{
|
||||
lua_pushinteger(L, Physics::getMeter());
|
||||
return 1;
|
||||
}
|
||||
|
||||
// List of functions to wrap.
|
||||
static const luaL_Reg functions[] =
|
||||
{
|
||||
{ "newWorld", w_newWorld },
|
||||
{ "newBody", w_newBody },
|
||||
{ "newFixture", w_newFixture },
|
||||
{ "newCircleShape", w_newCircleShape },
|
||||
{ "newRectangleShape", w_newRectangleShape },
|
||||
{ "newPolygonShape", w_newPolygonShape },
|
||||
{ "newEdgeShape", w_newEdgeShape },
|
||||
{ "newChainShape", w_newChainShape },
|
||||
{ "newDistanceJoint", w_newDistanceJoint },
|
||||
{ "newMouseJoint", w_newMouseJoint },
|
||||
{ "newRevoluteJoint", w_newRevoluteJoint },
|
||||
{ "newPrismaticJoint", w_newPrismaticJoint },
|
||||
{ "newPulleyJoint", w_newPulleyJoint },
|
||||
{ "newGearJoint", w_newGearJoint },
|
||||
{ "newFrictionJoint", w_newFrictionJoint },
|
||||
{ "newWeldJoint", w_newWeldJoint },
|
||||
{ "newWheelJoint", w_newWheelJoint },
|
||||
{ "newRopeJoint", w_newRopeJoint },
|
||||
{ "getDistance", w_getDistance },
|
||||
{ "getMeter", w_getMeter },
|
||||
{ "setMeter", w_setMeter },
|
||||
{ 0, 0 },
|
||||
};
|
||||
|
||||
static const lua_CFunction types[] =
|
||||
{
|
||||
luaopen_world,
|
||||
luaopen_contact,
|
||||
luaopen_body,
|
||||
luaopen_fixture,
|
||||
luaopen_shape,
|
||||
luaopen_circleshape,
|
||||
luaopen_polygonshape,
|
||||
luaopen_edgeshape,
|
||||
luaopen_chainshape,
|
||||
luaopen_joint,
|
||||
luaopen_mousejoint,
|
||||
luaopen_distancejoint,
|
||||
luaopen_prismaticjoint,
|
||||
luaopen_revolutejoint,
|
||||
luaopen_pulleyjoint,
|
||||
luaopen_gearjoint,
|
||||
luaopen_frictionjoint,
|
||||
luaopen_weldjoint,
|
||||
luaopen_wheeljoint,
|
||||
luaopen_ropejoint,
|
||||
0
|
||||
};
|
||||
|
||||
extern "C" int luaopen_love_physics(lua_State *L)
|
||||
{
|
||||
if (instance == 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
instance = new Physics();
|
||||
}
|
||||
catch(Exception &e)
|
||||
{
|
||||
return luaL_error(L, e.what());
|
||||
}
|
||||
}
|
||||
else
|
||||
instance->retain();
|
||||
|
||||
WrappedModule w;
|
||||
w.module = instance;
|
||||
w.name = "physics";
|
||||
w.flags = MODULE_T;
|
||||
w.functions = functions;
|
||||
w.types = types;
|
||||
|
||||
return luax_register_module(L, w);
|
||||
}
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
// LOVE
|
||||
#include "wrap_Physics.h"
|
||||
#include "wrap_World.h"
|
||||
#include "wrap_Contact.h"
|
||||
#include "wrap_Body.h"
|
||||
#include "wrap_Fixture.h"
|
||||
#include "wrap_Shape.h"
|
||||
#include "wrap_CircleShape.h"
|
||||
#include "wrap_PolygonShape.h"
|
||||
#include "wrap_EdgeShape.h"
|
||||
#include "wrap_ChainShape.h"
|
||||
#include "wrap_Joint.h"
|
||||
#include "wrap_MouseJoint.h"
|
||||
#include "wrap_DistanceJoint.h"
|
||||
#include "wrap_PrismaticJoint.h"
|
||||
#include "wrap_RevoluteJoint.h"
|
||||
#include "wrap_PulleyJoint.h"
|
||||
#include "wrap_GearJoint.h"
|
||||
#include "wrap_FrictionJoint.h"
|
||||
#include "wrap_WeldJoint.h"
|
||||
#include "wrap_WheelJoint.h"
|
||||
#include "wrap_RopeJoint.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
static Physics *instance = 0;
|
||||
|
||||
int w_newWorld(lua_State *L)
|
||||
{
|
||||
float gx = (float)luaL_optnumber(L, 1, 0);
|
||||
float gy = (float)luaL_optnumber(L, 2, 0);
|
||||
bool sleep = luax_optboolean(L, 3, true);
|
||||
|
||||
World *w;
|
||||
ASSERT_GUARD(w = instance->newWorld(gx, gy, sleep);)
|
||||
luax_newtype(L, "World", PHYSICS_WORLD_T, (void *)w);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_newBody(lua_State *L)
|
||||
{
|
||||
World *world = luax_checktype<World>(L, 1, "World", PHYSICS_WORLD_T);
|
||||
float x = (float)luaL_optnumber(L, 2, 0.0);
|
||||
float y = (float)luaL_optnumber(L, 3, 0.0);
|
||||
const char *type = luaL_optstring(L, 4, "static");
|
||||
Body::Type bodyType;
|
||||
Body::getConstant(type, bodyType);
|
||||
Body *body;
|
||||
ASSERT_GUARD(body = instance->newBody(world, x, y, bodyType);)
|
||||
luax_newtype(L, "Body", PHYSICS_BODY_T, (void *)body);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_newFixture(lua_State *L)
|
||||
{
|
||||
Body *body = luax_checkbody(L, 1);
|
||||
Shape *shape = luax_checkshape(L, 2);
|
||||
float density = (float)luaL_optnumber(L, 3, 1.0f);
|
||||
Fixture *fixture;
|
||||
ASSERT_GUARD(fixture = instance->newFixture(body, shape, density);)
|
||||
luax_newtype(L, "Fixture", PHYSICS_FIXTURE_T, (void *)fixture);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_newCircleShape(lua_State *L)
|
||||
{
|
||||
int top = lua_gettop(L);
|
||||
|
||||
if (top == 1)
|
||||
{
|
||||
float radius = (float)luaL_checknumber(L, 1);
|
||||
CircleShape *shape;
|
||||
ASSERT_GUARD(shape = instance->newCircleShape(radius);)
|
||||
luax_newtype(L, "CircleShape", PHYSICS_CIRCLE_SHAPE_T, (void *)shape);
|
||||
return 1;
|
||||
}
|
||||
else if (top == 3)
|
||||
{
|
||||
float x = (float)luaL_checknumber(L, 1);
|
||||
float y = (float)luaL_checknumber(L, 2);
|
||||
float radius = (float)luaL_checknumber(L, 3);
|
||||
CircleShape *shape;
|
||||
ASSERT_GUARD(shape = instance->newCircleShape(x, y, radius);)
|
||||
luax_newtype(L, "CircleShape", PHYSICS_CIRCLE_SHAPE_T, (void *)shape);
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
return luaL_error(L, "Incorrect number of parameters");
|
||||
}
|
||||
|
||||
int w_newRectangleShape(lua_State *L)
|
||||
{
|
||||
int top = lua_gettop(L);
|
||||
|
||||
if (top == 2)
|
||||
{
|
||||
float w = (float)luaL_checknumber(L, 1);
|
||||
float h = (float)luaL_checknumber(L, 2);
|
||||
PolygonShape *shape;
|
||||
ASSERT_GUARD(shape = instance->newRectangleShape(w, h);)
|
||||
luax_newtype(L, "PolygonShape", PHYSICS_POLYGON_SHAPE_T, (void *)shape);
|
||||
return 1;
|
||||
}
|
||||
else if (top == 4 || top == 5)
|
||||
{
|
||||
float x = (float)luaL_checknumber(L, 1);
|
||||
float y = (float)luaL_checknumber(L, 2);
|
||||
float w = (float)luaL_checknumber(L, 3);
|
||||
float h = (float)luaL_checknumber(L, 4);
|
||||
float angle = (float)luaL_optnumber(L, 5, 0);
|
||||
PolygonShape *shape;
|
||||
ASSERT_GUARD(shape = instance->newRectangleShape(x, y, w, h, angle);)
|
||||
luax_newtype(L, "PolygonShape", PHYSICS_POLYGON_SHAPE_T, (void *)shape);
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
return luaL_error(L, "Incorrect number of parameters");
|
||||
}
|
||||
|
||||
int w_newEdgeShape(lua_State *L)
|
||||
{
|
||||
float x1 = (float)luaL_checknumber(L, 1);
|
||||
float y1 = (float)luaL_checknumber(L, 2);
|
||||
float x2 = (float)luaL_checknumber(L, 3);
|
||||
float y2 = (float)luaL_checknumber(L, 4);
|
||||
EdgeShape *shape;
|
||||
ASSERT_GUARD(shape = instance->newEdgeShape(x1, y1, x2, y2);)
|
||||
luax_newtype(L, "EdgeShape", PHYSICS_EDGE_SHAPE_T, (void *)shape);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_newPolygonShape(lua_State *L)
|
||||
{
|
||||
ASSERT_GUARD(return instance->newPolygonShape(L);)
|
||||
}
|
||||
|
||||
int w_newChainShape(lua_State *L)
|
||||
{
|
||||
ASSERT_GUARD(return instance->newChainShape(L);)
|
||||
}
|
||||
|
||||
int w_newDistanceJoint(lua_State *L)
|
||||
{
|
||||
Body *body1 = luax_checktype<Body>(L, 1, "Body", PHYSICS_BODY_T);
|
||||
Body *body2 = luax_checktype<Body>(L, 2, "Body", PHYSICS_BODY_T);
|
||||
float x1 = (float)luaL_checknumber(L, 3);
|
||||
float y1 = (float)luaL_checknumber(L, 4);
|
||||
float x2 = (float)luaL_checknumber(L, 5);
|
||||
float y2 = (float)luaL_checknumber(L, 6);
|
||||
bool collideConnected = luax_optboolean(L, 7, false);
|
||||
DistanceJoint *j;
|
||||
ASSERT_GUARD(j = instance->newDistanceJoint(body1, body2, x1, y1, x2, y2, collideConnected);)
|
||||
luax_newtype(L, "DistanceJoint", PHYSICS_DISTANCE_JOINT_T, (void *)j);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_newMouseJoint(lua_State *L)
|
||||
{
|
||||
Body *body = luax_checktype<Body>(L, 1, "Body", PHYSICS_BODY_T);
|
||||
float x = (float)luaL_checknumber(L, 2);
|
||||
float y = (float)luaL_checknumber(L, 3);
|
||||
MouseJoint *j;
|
||||
ASSERT_GUARD(j = instance->newMouseJoint(body, x, y);)
|
||||
luax_newtype(L, "MouseJoint", PHYSICS_MOUSE_JOINT_T, (void *)j);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_newRevoluteJoint(lua_State *L)
|
||||
{
|
||||
Body *body1 = luax_checktype<Body>(L, 1, "Body", PHYSICS_BODY_T);
|
||||
Body *body2 = luax_checktype<Body>(L, 2, "Body", PHYSICS_BODY_T);
|
||||
float x = (float)luaL_checknumber(L, 3);
|
||||
float y = (float)luaL_checknumber(L, 4);
|
||||
bool collideConnected = luax_optboolean(L, 5, false);
|
||||
RevoluteJoint *j;
|
||||
ASSERT_GUARD(j = instance->newRevoluteJoint(body1, body2, x, y, collideConnected);)
|
||||
luax_newtype(L, "RevoluteJoint", PHYSICS_REVOLUTE_JOINT_T, (void *)j);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_newPrismaticJoint(lua_State *L)
|
||||
{
|
||||
Body *body1 = luax_checktype<Body>(L, 1, "Body", PHYSICS_BODY_T);
|
||||
Body *body2 = luax_checktype<Body>(L, 2, "Body", PHYSICS_BODY_T);
|
||||
float xA = (float)luaL_checknumber(L, 3);
|
||||
float yA = (float)luaL_checknumber(L, 4);
|
||||
float xB, yB, ax, ay;
|
||||
bool collideConnected;
|
||||
if (lua_gettop(L) >= 8)
|
||||
{
|
||||
xB = (float)luaL_checknumber(L, 5);
|
||||
yB = (float)luaL_checknumber(L, 6);
|
||||
ax = (float)luaL_checknumber(L, 7);
|
||||
ay = (float)luaL_checknumber(L, 8);
|
||||
collideConnected = luax_optboolean(L, 9, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
xB = xA;
|
||||
yB = yA;
|
||||
ax = (float)luaL_checknumber(L, 5);
|
||||
ay = (float)luaL_checknumber(L, 6);
|
||||
collideConnected = luax_optboolean(L, 7, false);
|
||||
}
|
||||
PrismaticJoint *j;
|
||||
ASSERT_GUARD(j = instance->newPrismaticJoint(body1, body2, xA, yA, xB, yB, ax, ay, collideConnected);)
|
||||
luax_newtype(L, "PrismaticJoint", PHYSICS_PRISMATIC_JOINT_T, (void *)j);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_newPulleyJoint(lua_State *L)
|
||||
{
|
||||
Body *body1 = luax_checktype<Body>(L, 1, "Body", PHYSICS_BODY_T);
|
||||
Body *body2 = luax_checktype<Body>(L, 2, "Body", PHYSICS_BODY_T);
|
||||
float gx1 = (float)luaL_checknumber(L, 3);
|
||||
float gy1 = (float)luaL_checknumber(L, 4);
|
||||
float gx2 = (float)luaL_checknumber(L, 5);
|
||||
float gy2 = (float)luaL_checknumber(L, 6);
|
||||
float x1 = (float)luaL_checknumber(L, 7);
|
||||
float y1 = (float)luaL_checknumber(L, 8);
|
||||
float x2 = (float)luaL_checknumber(L, 9);
|
||||
float y2 = (float)luaL_checknumber(L, 10);
|
||||
float ratio = (float)luaL_optnumber(L, 11, 1.0);
|
||||
bool collideConnected = luax_optboolean(L, 12, true); // PulleyJoints default to colliding connected bodies, see b2PulleyJoint.h
|
||||
|
||||
PulleyJoint *j;
|
||||
ASSERT_GUARD(j = instance->newPulleyJoint(body1, body2, b2Vec2(gx1,gy1), b2Vec2(gx2,gy2), b2Vec2(x1,y1), b2Vec2(x2,y2), ratio, collideConnected);)
|
||||
luax_newtype(L, "PulleyJoint", PHYSICS_PULLEY_JOINT_T, (void *)j);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_newGearJoint(lua_State *L)
|
||||
{
|
||||
Joint *joint1 = luax_checktype<Joint>(L, 1, "Joint", PHYSICS_JOINT_T);
|
||||
Joint *joint2 = luax_checktype<Joint>(L, 2, "Joint", PHYSICS_JOINT_T);
|
||||
float ratio = (float)luaL_optnumber(L, 3, 1.0);
|
||||
bool collideConnected = luax_optboolean(L, 4, false);
|
||||
|
||||
GearJoint *j;
|
||||
ASSERT_GUARD(j = instance->newGearJoint(joint1, joint2, ratio, collideConnected);)
|
||||
luax_newtype(L, "GearJoint", PHYSICS_GEAR_JOINT_T, (void *)j);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_newFrictionJoint(lua_State *L)
|
||||
{
|
||||
Body *body1 = luax_checktype<Body>(L, 1, "Body", PHYSICS_BODY_T);
|
||||
Body *body2 = luax_checktype<Body>(L, 2, "Body", PHYSICS_BODY_T);
|
||||
float xA = (float)luaL_checknumber(L, 3);
|
||||
float yA = (float)luaL_checknumber(L, 4);
|
||||
float xB, yB;
|
||||
bool collideConnected;
|
||||
if (lua_gettop(L) >= 6)
|
||||
{
|
||||
xB = (float)luaL_checknumber(L, 5);
|
||||
yB = (float)luaL_checknumber(L, 6);
|
||||
collideConnected = luax_optboolean(L, 7, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
xB = xA;
|
||||
yB = yA;
|
||||
collideConnected = luax_optboolean(L, 5, false);
|
||||
}
|
||||
FrictionJoint *j;
|
||||
ASSERT_GUARD(j = instance->newFrictionJoint(body1, body2, xA, yA, xB, yB, collideConnected);)
|
||||
luax_newtype(L, "FrictionJoint", PHYSICS_FRICTION_JOINT_T, (void *)j);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_newWeldJoint(lua_State *L)
|
||||
{
|
||||
Body *body1 = luax_checktype<Body>(L, 1, "Body", PHYSICS_BODY_T);
|
||||
Body *body2 = luax_checktype<Body>(L, 2, "Body", PHYSICS_BODY_T);
|
||||
float xA = (float)luaL_checknumber(L, 3);
|
||||
float yA = (float)luaL_checknumber(L, 4);
|
||||
float xB, yB;
|
||||
bool collideConnected;
|
||||
if (lua_gettop(L) >= 6)
|
||||
{
|
||||
xB = (float)luaL_checknumber(L, 5);
|
||||
yB = (float)luaL_checknumber(L, 6);
|
||||
collideConnected = luax_optboolean(L, 7, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
xB = xA;
|
||||
yB = yA;
|
||||
collideConnected = luax_optboolean(L, 5, false);
|
||||
}
|
||||
WeldJoint *j;
|
||||
ASSERT_GUARD(j = instance->newWeldJoint(body1, body2, xA, yA, xB, yB, collideConnected);)
|
||||
luax_newtype(L, "WeldJoint", PHYSICS_WELD_JOINT_T, (void *)j);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_newWheelJoint(lua_State *L)
|
||||
{
|
||||
Body *body1 = luax_checktype<Body>(L, 1, "Body", PHYSICS_BODY_T);
|
||||
Body *body2 = luax_checktype<Body>(L, 2, "Body", PHYSICS_BODY_T);
|
||||
float xA = (float)luaL_checknumber(L, 3);
|
||||
float yA = (float)luaL_checknumber(L, 4);
|
||||
float xB, yB, ax, ay;
|
||||
bool collideConnected;
|
||||
if (lua_gettop(L) >= 8)
|
||||
{
|
||||
xB = (float)luaL_checknumber(L, 5);
|
||||
yB = (float)luaL_checknumber(L, 6);
|
||||
ax = (float)luaL_checknumber(L, 7);
|
||||
ay = (float)luaL_checknumber(L, 8);
|
||||
collideConnected = luax_optboolean(L, 9, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
xB = xA;
|
||||
yB = yA;
|
||||
ax = (float)luaL_checknumber(L, 5);
|
||||
ay = (float)luaL_checknumber(L, 6);
|
||||
collideConnected = luax_optboolean(L, 7, false);
|
||||
}
|
||||
|
||||
WheelJoint *j;
|
||||
ASSERT_GUARD(j = instance->newWheelJoint(body1, body2, xA, yA, xB, yB, ax, ay, collideConnected);)
|
||||
luax_newtype(L, "WheelJoint", PHYSICS_WHEEL_JOINT_T, (void *)j);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_newRopeJoint(lua_State *L)
|
||||
{
|
||||
Body *body1 = luax_checktype<Body>(L, 1, "Body", PHYSICS_BODY_T);
|
||||
Body *body2 = luax_checktype<Body>(L, 2, "Body", PHYSICS_BODY_T);
|
||||
float x1 = (float)luaL_checknumber(L, 3);
|
||||
float y1 = (float)luaL_checknumber(L, 4);
|
||||
float x2 = (float)luaL_checknumber(L, 5);
|
||||
float y2 = (float)luaL_checknumber(L, 6);
|
||||
float maxLength = (float)luaL_checknumber(L, 7);
|
||||
bool collideConnected = luax_optboolean(L, 8, false);
|
||||
RopeJoint *j;
|
||||
ASSERT_GUARD(j = instance->newRopeJoint(body1, body2, x1, y1, x2, y2, maxLength, collideConnected);)
|
||||
luax_newtype(L, "RopeJoint", PHYSICS_ROPE_JOINT_T, (void *)j);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_getDistance(lua_State *L)
|
||||
{
|
||||
return instance->getDistance(L);
|
||||
}
|
||||
|
||||
int w_setMeter(lua_State *L)
|
||||
{
|
||||
int arg1 = luaL_checkint(L, 1);
|
||||
try
|
||||
{
|
||||
Physics::setMeter(arg1);
|
||||
}
|
||||
catch(love::Exception &e)
|
||||
{
|
||||
return luaL_error(L, e.what());
|
||||
}
|
||||
return 0;
|
||||
|
||||
}
|
||||
int w_getMeter(lua_State *L)
|
||||
{
|
||||
lua_pushinteger(L, Physics::getMeter());
|
||||
return 1;
|
||||
}
|
||||
|
||||
// List of functions to wrap.
|
||||
static const luaL_Reg functions[] =
|
||||
{
|
||||
{ "newWorld", w_newWorld },
|
||||
{ "newBody", w_newBody },
|
||||
{ "newFixture", w_newFixture },
|
||||
{ "newCircleShape", w_newCircleShape },
|
||||
{ "newRectangleShape", w_newRectangleShape },
|
||||
{ "newPolygonShape", w_newPolygonShape },
|
||||
{ "newEdgeShape", w_newEdgeShape },
|
||||
{ "newChainShape", w_newChainShape },
|
||||
{ "newDistanceJoint", w_newDistanceJoint },
|
||||
{ "newMouseJoint", w_newMouseJoint },
|
||||
{ "newRevoluteJoint", w_newRevoluteJoint },
|
||||
{ "newPrismaticJoint", w_newPrismaticJoint },
|
||||
{ "newPulleyJoint", w_newPulleyJoint },
|
||||
{ "newGearJoint", w_newGearJoint },
|
||||
{ "newFrictionJoint", w_newFrictionJoint },
|
||||
{ "newWeldJoint", w_newWeldJoint },
|
||||
{ "newWheelJoint", w_newWheelJoint },
|
||||
{ "newRopeJoint", w_newRopeJoint },
|
||||
{ "getDistance", w_getDistance },
|
||||
{ "getMeter", w_getMeter },
|
||||
{ "setMeter", w_setMeter },
|
||||
{ 0, 0 },
|
||||
};
|
||||
|
||||
static const lua_CFunction types[] =
|
||||
{
|
||||
luaopen_world,
|
||||
luaopen_contact,
|
||||
luaopen_body,
|
||||
luaopen_fixture,
|
||||
luaopen_shape,
|
||||
luaopen_circleshape,
|
||||
luaopen_polygonshape,
|
||||
luaopen_edgeshape,
|
||||
luaopen_chainshape,
|
||||
luaopen_joint,
|
||||
luaopen_mousejoint,
|
||||
luaopen_distancejoint,
|
||||
luaopen_prismaticjoint,
|
||||
luaopen_revolutejoint,
|
||||
luaopen_pulleyjoint,
|
||||
luaopen_gearjoint,
|
||||
luaopen_frictionjoint,
|
||||
luaopen_weldjoint,
|
||||
luaopen_wheeljoint,
|
||||
luaopen_ropejoint,
|
||||
0
|
||||
};
|
||||
|
||||
extern "C" int luaopen_love_physics(lua_State *L)
|
||||
{
|
||||
if (instance == 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
instance = new Physics();
|
||||
}
|
||||
catch(Exception &e)
|
||||
{
|
||||
return luaL_error(L, e.what());
|
||||
}
|
||||
}
|
||||
else
|
||||
instance->retain();
|
||||
|
||||
WrappedModule w;
|
||||
w.module = instance;
|
||||
w.name = "physics";
|
||||
w.flags = MODULE_T;
|
||||
w.functions = functions;
|
||||
w.types = types;
|
||||
|
||||
return luax_register_module(L, w);
|
||||
}
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
@@ -1,64 +1,64 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_PHYSICS_BOX2D_WRAP_PHYSICS_H
|
||||
#define LOVE_PHYSICS_BOX2D_WRAP_PHYSICS_H
|
||||
|
||||
// LOVE
|
||||
#include "common/config.h"
|
||||
#include "Physics.h"
|
||||
|
||||
#define ASSERT_GUARD(A) try { A } catch (love::Exception & e) { return luaL_error(L, "%s", e.what()); }
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
int w_newWorld(lua_State *L);
|
||||
int w_newBody(lua_State *L);
|
||||
int w_newFixture(lua_State *L);
|
||||
int w_newCircleShape(lua_State *L);
|
||||
int w_newRectangleShape(lua_State *L);
|
||||
int w_newPolygonShape(lua_State *L);
|
||||
int w_newEdgeShape(lua_State *L);
|
||||
int w_newChainShape(lua_State *L);
|
||||
int w_newDistanceJoint(lua_State *L);
|
||||
int w_newMouseJoint(lua_State *L);
|
||||
int w_newRevoluteJoint(lua_State *L);
|
||||
int w_newPrismaticJoint(lua_State *L);
|
||||
int w_newPulleyJoint(lua_State *L);
|
||||
int w_newGearJoint(lua_State *L);
|
||||
int w_newFrictionJoint(lua_State *L);
|
||||
int w_newWeldJoint(lua_State *L);
|
||||
int w_newWheelJoint(lua_State *L);
|
||||
int w_newRopeJoint(lua_State *L);
|
||||
int w_getDistance(lua_State *L);
|
||||
int w_setMeter(lua_State *L);
|
||||
int w_getMeter(lua_State *L);
|
||||
extern "C" LOVE_EXPORT int luaopen_love_physics(lua_State *L);
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_WRAP_PHYSICS_H
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_PHYSICS_BOX2D_WRAP_PHYSICS_H
|
||||
#define LOVE_PHYSICS_BOX2D_WRAP_PHYSICS_H
|
||||
|
||||
// LOVE
|
||||
#include "common/config.h"
|
||||
#include "Physics.h"
|
||||
|
||||
#define ASSERT_GUARD(A) try { A } catch (love::Exception & e) { return luaL_error(L, "%s", e.what()); }
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
int w_newWorld(lua_State *L);
|
||||
int w_newBody(lua_State *L);
|
||||
int w_newFixture(lua_State *L);
|
||||
int w_newCircleShape(lua_State *L);
|
||||
int w_newRectangleShape(lua_State *L);
|
||||
int w_newPolygonShape(lua_State *L);
|
||||
int w_newEdgeShape(lua_State *L);
|
||||
int w_newChainShape(lua_State *L);
|
||||
int w_newDistanceJoint(lua_State *L);
|
||||
int w_newMouseJoint(lua_State *L);
|
||||
int w_newRevoluteJoint(lua_State *L);
|
||||
int w_newPrismaticJoint(lua_State *L);
|
||||
int w_newPulleyJoint(lua_State *L);
|
||||
int w_newGearJoint(lua_State *L);
|
||||
int w_newFrictionJoint(lua_State *L);
|
||||
int w_newWeldJoint(lua_State *L);
|
||||
int w_newWheelJoint(lua_State *L);
|
||||
int w_newRopeJoint(lua_State *L);
|
||||
int w_getDistance(lua_State *L);
|
||||
int w_setMeter(lua_State *L);
|
||||
int w_getMeter(lua_State *L);
|
||||
extern "C" LOVE_EXPORT int luaopen_love_physics(lua_State *L);
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_WRAP_PHYSICS_H
|
||||
|
||||
@@ -1,63 +1,63 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#include "wrap_PolygonShape.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
PolygonShape *luax_checkpolygonshape(lua_State *L, int idx)
|
||||
{
|
||||
return luax_checktype<PolygonShape>(L, idx, "PolygonShape", PHYSICS_POLYGON_SHAPE_T);
|
||||
}
|
||||
|
||||
int w_PolygonShape_getPoints(lua_State *L)
|
||||
{
|
||||
PolygonShape *t = luax_checkpolygonshape(L, 1);
|
||||
lua_remove(L, 1);
|
||||
return t->getPoints(L);
|
||||
}
|
||||
|
||||
static const luaL_Reg functions[] =
|
||||
{
|
||||
{ "getPoints", w_PolygonShape_getPoints },
|
||||
// From Shape.
|
||||
{ "getType", w_Shape_getType },
|
||||
{ "getRadius", w_Shape_getRadius },
|
||||
{ "getChildCount", w_Shape_getChildCount },
|
||||
{ "testPoint", w_Shape_testPoint },
|
||||
{ "rayCast", w_Shape_rayCast },
|
||||
{ "computeAABB", w_Shape_computeAABB },
|
||||
{ "computeMass", w_Shape_computeMass },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
extern "C" int luaopen_polygonshape(lua_State *L)
|
||||
{
|
||||
return luax_register_type(L, "PolygonShape", functions);
|
||||
}
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#include "wrap_PolygonShape.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
PolygonShape *luax_checkpolygonshape(lua_State *L, int idx)
|
||||
{
|
||||
return luax_checktype<PolygonShape>(L, idx, "PolygonShape", PHYSICS_POLYGON_SHAPE_T);
|
||||
}
|
||||
|
||||
int w_PolygonShape_getPoints(lua_State *L)
|
||||
{
|
||||
PolygonShape *t = luax_checkpolygonshape(L, 1);
|
||||
lua_remove(L, 1);
|
||||
return t->getPoints(L);
|
||||
}
|
||||
|
||||
static const luaL_Reg functions[] =
|
||||
{
|
||||
{ "getPoints", w_PolygonShape_getPoints },
|
||||
// From Shape.
|
||||
{ "getType", w_Shape_getType },
|
||||
{ "getRadius", w_Shape_getRadius },
|
||||
{ "getChildCount", w_Shape_getChildCount },
|
||||
{ "testPoint", w_Shape_testPoint },
|
||||
{ "rayCast", w_Shape_rayCast },
|
||||
{ "computeAABB", w_Shape_computeAABB },
|
||||
{ "computeMass", w_Shape_computeMass },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
extern "C" int luaopen_polygonshape(lua_State *L)
|
||||
{
|
||||
return luax_register_type(L, "PolygonShape", functions);
|
||||
}
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
@@ -1,44 +1,44 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_PHYSICS_BOX2D_WRAP_POLYGON_SHAPE_H
|
||||
#define LOVE_PHYSICS_BOX2D_WRAP_POLYGON_SHAPE_H
|
||||
|
||||
// LOVE
|
||||
#include "common/runtime.h"
|
||||
#include "wrap_Shape.h"
|
||||
#include "PolygonShape.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
PolygonShape *luax_checkpolygonshape(lua_State *L, int idx);
|
||||
int w_PolygonShape_getPoints(lua_State *L);
|
||||
extern "C" int luaopen_polygonshape(lua_State *L);
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_WRAP_POLYGON_SHAPE_H
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_PHYSICS_BOX2D_WRAP_POLYGON_SHAPE_H
|
||||
#define LOVE_PHYSICS_BOX2D_WRAP_POLYGON_SHAPE_H
|
||||
|
||||
// LOVE
|
||||
#include "common/runtime.h"
|
||||
#include "wrap_Shape.h"
|
||||
#include "PolygonShape.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
PolygonShape *luax_checkpolygonshape(lua_State *L, int idx);
|
||||
int w_PolygonShape_getPoints(lua_State *L);
|
||||
extern "C" int luaopen_polygonshape(lua_State *L);
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_WRAP_POLYGON_SHAPE_H
|
||||
|
||||
@@ -1,202 +1,202 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#include "wrap_PrismaticJoint.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
PrismaticJoint *luax_checkprismaticjoint(lua_State *L, int idx)
|
||||
{
|
||||
PrismaticJoint *j = luax_checktype<PrismaticJoint>(L, idx, "PrismaticJoint", PHYSICS_PRISMATIC_JOINT_T);
|
||||
if (!j->isValid())
|
||||
luaL_error(L, "Attempt to use destroyed joint.");
|
||||
return j;
|
||||
}
|
||||
|
||||
int w_PrismaticJoint_getJointTranslation(lua_State *L)
|
||||
{
|
||||
PrismaticJoint *t = luax_checkprismaticjoint(L, 1);
|
||||
lua_pushnumber(L, t->getJointTranslation());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_PrismaticJoint_getJointSpeed(lua_State *L)
|
||||
{
|
||||
PrismaticJoint *t = luax_checkprismaticjoint(L, 1);
|
||||
lua_pushnumber(L, t->getJointSpeed());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_PrismaticJoint_enableMotor(lua_State *L)
|
||||
{
|
||||
PrismaticJoint *t = luax_checkprismaticjoint(L, 1);
|
||||
bool arg1 = luax_toboolean(L, 2);
|
||||
t->enableMotor(arg1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_PrismaticJoint_isMotorEnabled(lua_State *L)
|
||||
{
|
||||
PrismaticJoint *t = luax_checkprismaticjoint(L, 1);
|
||||
luax_pushboolean(L, t->isMotorEnabled());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_PrismaticJoint_setMaxMotorForce(lua_State *L)
|
||||
{
|
||||
PrismaticJoint *t = luax_checkprismaticjoint(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
t->setMaxMotorForce(arg1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_PrismaticJoint_setMotorSpeed(lua_State *L)
|
||||
{
|
||||
PrismaticJoint *t = luax_checkprismaticjoint(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
t->setMotorSpeed(arg1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_PrismaticJoint_getMotorSpeed(lua_State *L)
|
||||
{
|
||||
PrismaticJoint *t = luax_checkprismaticjoint(L, 1);
|
||||
lua_pushnumber(L, t->getMotorSpeed());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_PrismaticJoint_getMotorForce(lua_State *L)
|
||||
{
|
||||
PrismaticJoint *t = luax_checkprismaticjoint(L, 1);
|
||||
float inv_dt = (float)luaL_checknumber(L, 2);
|
||||
lua_pushnumber(L, t->getMotorForce(inv_dt));
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_PrismaticJoint_getMaxMotorForce(lua_State *L)
|
||||
{
|
||||
PrismaticJoint *t = luax_checkprismaticjoint(L, 1);
|
||||
lua_pushnumber(L, t->getMaxMotorForce());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_PrismaticJoint_enableLimit(lua_State *L)
|
||||
{
|
||||
PrismaticJoint *t = luax_checkprismaticjoint(L, 1);
|
||||
bool arg1 = luax_toboolean(L, 2);
|
||||
t->enableLimit(arg1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_PrismaticJoint_isLimitEnabled(lua_State *L)
|
||||
{
|
||||
PrismaticJoint *t = luax_checkprismaticjoint(L, 1);
|
||||
luax_pushboolean(L, t->isLimitEnabled());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_PrismaticJoint_setUpperLimit(lua_State *L)
|
||||
{
|
||||
PrismaticJoint *t = luax_checkprismaticjoint(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
t->setUpperLimit(arg1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_PrismaticJoint_setLowerLimit(lua_State *L)
|
||||
{
|
||||
PrismaticJoint *t = luax_checkprismaticjoint(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
t->setLowerLimit(arg1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_PrismaticJoint_setLimits(lua_State *L)
|
||||
{
|
||||
PrismaticJoint *t = luax_checkprismaticjoint(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
float arg2 = (float)luaL_checknumber(L, 3);
|
||||
t->setLimits(arg1, arg2);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_PrismaticJoint_getLowerLimit(lua_State *L)
|
||||
{
|
||||
PrismaticJoint *t = luax_checkprismaticjoint(L, 1);
|
||||
lua_pushnumber(L, t->getLowerLimit());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_PrismaticJoint_getUpperLimit(lua_State *L)
|
||||
{
|
||||
PrismaticJoint *t = luax_checkprismaticjoint(L, 1);
|
||||
lua_pushnumber(L, t->getUpperLimit());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_PrismaticJoint_getLimits(lua_State *L)
|
||||
{
|
||||
PrismaticJoint *t = luax_checkprismaticjoint(L, 1);
|
||||
lua_remove(L, 1);
|
||||
return t->getLimits(L);
|
||||
}
|
||||
|
||||
static const luaL_Reg functions[] =
|
||||
{
|
||||
{ "getJointTranslation", w_PrismaticJoint_getJointTranslation },
|
||||
{ "getJointSpeed", w_PrismaticJoint_getJointSpeed },
|
||||
{ "enableMotor", w_PrismaticJoint_enableMotor },
|
||||
{ "isMotorEnabled", w_PrismaticJoint_isMotorEnabled },
|
||||
{ "setMaxMotorForce", w_PrismaticJoint_setMaxMotorForce },
|
||||
{ "setMotorSpeed", w_PrismaticJoint_setMotorSpeed },
|
||||
{ "getMotorSpeed", w_PrismaticJoint_getMotorSpeed },
|
||||
{ "getMotorForce", w_PrismaticJoint_getMotorForce },
|
||||
{ "getMaxMotorForce", w_PrismaticJoint_getMaxMotorForce },
|
||||
{ "enableLimit", w_PrismaticJoint_enableLimit },
|
||||
{ "isLimitEnabled", w_PrismaticJoint_isLimitEnabled },
|
||||
{ "setUpperLimit", w_PrismaticJoint_setUpperLimit },
|
||||
{ "setLowerLimit", w_PrismaticJoint_setLowerLimit },
|
||||
{ "setLimits", w_PrismaticJoint_setLimits },
|
||||
{ "getLowerLimit", w_PrismaticJoint_getLowerLimit },
|
||||
{ "getUpperLimit", w_PrismaticJoint_getUpperLimit },
|
||||
{ "getLimits", w_PrismaticJoint_getLimits },
|
||||
// From Joint.
|
||||
{ "getType", w_Joint_getType },
|
||||
{ "getAnchors", w_Joint_getAnchors },
|
||||
{ "getReactionForce", w_Joint_getReactionForce },
|
||||
{ "getReactionTorque", w_Joint_getReactionTorque },
|
||||
{ "getCollideConnected", w_Joint_getCollideConnected },
|
||||
{ "destroy", w_Joint_destroy },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
extern "C" int luaopen_prismaticjoint(lua_State *L)
|
||||
{
|
||||
return luax_register_type(L, "PrismaticJoint", functions);
|
||||
}
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#include "wrap_PrismaticJoint.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
PrismaticJoint *luax_checkprismaticjoint(lua_State *L, int idx)
|
||||
{
|
||||
PrismaticJoint *j = luax_checktype<PrismaticJoint>(L, idx, "PrismaticJoint", PHYSICS_PRISMATIC_JOINT_T);
|
||||
if (!j->isValid())
|
||||
luaL_error(L, "Attempt to use destroyed joint.");
|
||||
return j;
|
||||
}
|
||||
|
||||
int w_PrismaticJoint_getJointTranslation(lua_State *L)
|
||||
{
|
||||
PrismaticJoint *t = luax_checkprismaticjoint(L, 1);
|
||||
lua_pushnumber(L, t->getJointTranslation());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_PrismaticJoint_getJointSpeed(lua_State *L)
|
||||
{
|
||||
PrismaticJoint *t = luax_checkprismaticjoint(L, 1);
|
||||
lua_pushnumber(L, t->getJointSpeed());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_PrismaticJoint_enableMotor(lua_State *L)
|
||||
{
|
||||
PrismaticJoint *t = luax_checkprismaticjoint(L, 1);
|
||||
bool arg1 = luax_toboolean(L, 2);
|
||||
t->enableMotor(arg1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_PrismaticJoint_isMotorEnabled(lua_State *L)
|
||||
{
|
||||
PrismaticJoint *t = luax_checkprismaticjoint(L, 1);
|
||||
luax_pushboolean(L, t->isMotorEnabled());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_PrismaticJoint_setMaxMotorForce(lua_State *L)
|
||||
{
|
||||
PrismaticJoint *t = luax_checkprismaticjoint(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
t->setMaxMotorForce(arg1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_PrismaticJoint_setMotorSpeed(lua_State *L)
|
||||
{
|
||||
PrismaticJoint *t = luax_checkprismaticjoint(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
t->setMotorSpeed(arg1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_PrismaticJoint_getMotorSpeed(lua_State *L)
|
||||
{
|
||||
PrismaticJoint *t = luax_checkprismaticjoint(L, 1);
|
||||
lua_pushnumber(L, t->getMotorSpeed());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_PrismaticJoint_getMotorForce(lua_State *L)
|
||||
{
|
||||
PrismaticJoint *t = luax_checkprismaticjoint(L, 1);
|
||||
float inv_dt = (float)luaL_checknumber(L, 2);
|
||||
lua_pushnumber(L, t->getMotorForce(inv_dt));
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_PrismaticJoint_getMaxMotorForce(lua_State *L)
|
||||
{
|
||||
PrismaticJoint *t = luax_checkprismaticjoint(L, 1);
|
||||
lua_pushnumber(L, t->getMaxMotorForce());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_PrismaticJoint_enableLimit(lua_State *L)
|
||||
{
|
||||
PrismaticJoint *t = luax_checkprismaticjoint(L, 1);
|
||||
bool arg1 = luax_toboolean(L, 2);
|
||||
t->enableLimit(arg1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_PrismaticJoint_isLimitEnabled(lua_State *L)
|
||||
{
|
||||
PrismaticJoint *t = luax_checkprismaticjoint(L, 1);
|
||||
luax_pushboolean(L, t->isLimitEnabled());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_PrismaticJoint_setUpperLimit(lua_State *L)
|
||||
{
|
||||
PrismaticJoint *t = luax_checkprismaticjoint(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
t->setUpperLimit(arg1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_PrismaticJoint_setLowerLimit(lua_State *L)
|
||||
{
|
||||
PrismaticJoint *t = luax_checkprismaticjoint(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
t->setLowerLimit(arg1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_PrismaticJoint_setLimits(lua_State *L)
|
||||
{
|
||||
PrismaticJoint *t = luax_checkprismaticjoint(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
float arg2 = (float)luaL_checknumber(L, 3);
|
||||
t->setLimits(arg1, arg2);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_PrismaticJoint_getLowerLimit(lua_State *L)
|
||||
{
|
||||
PrismaticJoint *t = luax_checkprismaticjoint(L, 1);
|
||||
lua_pushnumber(L, t->getLowerLimit());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_PrismaticJoint_getUpperLimit(lua_State *L)
|
||||
{
|
||||
PrismaticJoint *t = luax_checkprismaticjoint(L, 1);
|
||||
lua_pushnumber(L, t->getUpperLimit());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_PrismaticJoint_getLimits(lua_State *L)
|
||||
{
|
||||
PrismaticJoint *t = luax_checkprismaticjoint(L, 1);
|
||||
lua_remove(L, 1);
|
||||
return t->getLimits(L);
|
||||
}
|
||||
|
||||
static const luaL_Reg functions[] =
|
||||
{
|
||||
{ "getJointTranslation", w_PrismaticJoint_getJointTranslation },
|
||||
{ "getJointSpeed", w_PrismaticJoint_getJointSpeed },
|
||||
{ "enableMotor", w_PrismaticJoint_enableMotor },
|
||||
{ "isMotorEnabled", w_PrismaticJoint_isMotorEnabled },
|
||||
{ "setMaxMotorForce", w_PrismaticJoint_setMaxMotorForce },
|
||||
{ "setMotorSpeed", w_PrismaticJoint_setMotorSpeed },
|
||||
{ "getMotorSpeed", w_PrismaticJoint_getMotorSpeed },
|
||||
{ "getMotorForce", w_PrismaticJoint_getMotorForce },
|
||||
{ "getMaxMotorForce", w_PrismaticJoint_getMaxMotorForce },
|
||||
{ "enableLimit", w_PrismaticJoint_enableLimit },
|
||||
{ "isLimitEnabled", w_PrismaticJoint_isLimitEnabled },
|
||||
{ "setUpperLimit", w_PrismaticJoint_setUpperLimit },
|
||||
{ "setLowerLimit", w_PrismaticJoint_setLowerLimit },
|
||||
{ "setLimits", w_PrismaticJoint_setLimits },
|
||||
{ "getLowerLimit", w_PrismaticJoint_getLowerLimit },
|
||||
{ "getUpperLimit", w_PrismaticJoint_getUpperLimit },
|
||||
{ "getLimits", w_PrismaticJoint_getLimits },
|
||||
// From Joint.
|
||||
{ "getType", w_Joint_getType },
|
||||
{ "getAnchors", w_Joint_getAnchors },
|
||||
{ "getReactionForce", w_Joint_getReactionForce },
|
||||
{ "getReactionTorque", w_Joint_getReactionTorque },
|
||||
{ "getCollideConnected", w_Joint_getCollideConnected },
|
||||
{ "destroy", w_Joint_destroy },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
extern "C" int luaopen_prismaticjoint(lua_State *L)
|
||||
{
|
||||
return luax_register_type(L, "PrismaticJoint", functions);
|
||||
}
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
@@ -1,60 +1,60 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_PHYSICS_BOX2D_WRAP_PRISMATIC_JOINT_H
|
||||
#define LOVE_PHYSICS_BOX2D_WRAP_PRISMATIC_JOINT_H
|
||||
|
||||
// LOVE
|
||||
#include "common/runtime.h"
|
||||
#include "wrap_Joint.h"
|
||||
#include "PrismaticJoint.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
PrismaticJoint *luax_checkprismaticjoint(lua_State *L, int idx);
|
||||
int w_PrismaticJoint_getJointTranslation(lua_State *L);
|
||||
int w_PrismaticJoint_getJointSpeed(lua_State *L);
|
||||
int w_PrismaticJoint_enableMotor(lua_State *L);
|
||||
int w_PrismaticJoint_isMotorEnabled(lua_State *L);
|
||||
int w_PrismaticJoint_setMaxMotorForce(lua_State *L);
|
||||
int w_PrismaticJoint_setMotorSpeed(lua_State *L);
|
||||
int w_PrismaticJoint_getMotorSpeed(lua_State *L);
|
||||
int w_PrismaticJoint_getMotorForce(lua_State *L);
|
||||
int w_PrismaticJoint_getMaxMotorForce(lua_State *L);
|
||||
int w_PrismaticJoint_enableLimit(lua_State *L);
|
||||
int w_PrismaticJoint_isLimitEnabled(lua_State *L);
|
||||
int w_PrismaticJoint_setUpperLimit(lua_State *L);
|
||||
int w_PrismaticJoint_setLowerLimit(lua_State *L);
|
||||
int w_PrismaticJoint_setLimits(lua_State *L);
|
||||
int w_PrismaticJoint_getLowerLimit(lua_State *L);
|
||||
int w_PrismaticJoint_getUpperLimit(lua_State *L);
|
||||
int w_PrismaticJoint_getLimits(lua_State *L);
|
||||
extern "C" int luaopen_prismaticjoint(lua_State *L);
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_WRAP_PRISMATIC_JOINT_H
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_PHYSICS_BOX2D_WRAP_PRISMATIC_JOINT_H
|
||||
#define LOVE_PHYSICS_BOX2D_WRAP_PRISMATIC_JOINT_H
|
||||
|
||||
// LOVE
|
||||
#include "common/runtime.h"
|
||||
#include "wrap_Joint.h"
|
||||
#include "PrismaticJoint.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
PrismaticJoint *luax_checkprismaticjoint(lua_State *L, int idx);
|
||||
int w_PrismaticJoint_getJointTranslation(lua_State *L);
|
||||
int w_PrismaticJoint_getJointSpeed(lua_State *L);
|
||||
int w_PrismaticJoint_enableMotor(lua_State *L);
|
||||
int w_PrismaticJoint_isMotorEnabled(lua_State *L);
|
||||
int w_PrismaticJoint_setMaxMotorForce(lua_State *L);
|
||||
int w_PrismaticJoint_setMotorSpeed(lua_State *L);
|
||||
int w_PrismaticJoint_getMotorSpeed(lua_State *L);
|
||||
int w_PrismaticJoint_getMotorForce(lua_State *L);
|
||||
int w_PrismaticJoint_getMaxMotorForce(lua_State *L);
|
||||
int w_PrismaticJoint_enableLimit(lua_State *L);
|
||||
int w_PrismaticJoint_isLimitEnabled(lua_State *L);
|
||||
int w_PrismaticJoint_setUpperLimit(lua_State *L);
|
||||
int w_PrismaticJoint_setLowerLimit(lua_State *L);
|
||||
int w_PrismaticJoint_setLimits(lua_State *L);
|
||||
int w_PrismaticJoint_getLowerLimit(lua_State *L);
|
||||
int w_PrismaticJoint_getUpperLimit(lua_State *L);
|
||||
int w_PrismaticJoint_getLimits(lua_State *L);
|
||||
extern "C" int luaopen_prismaticjoint(lua_State *L);
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_WRAP_PRISMATIC_JOINT_H
|
||||
|
||||
@@ -1,89 +1,89 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#include "wrap_PulleyJoint.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
PulleyJoint *luax_checkpulleyjoint(lua_State *L, int idx)
|
||||
{
|
||||
PulleyJoint *j = luax_checktype<PulleyJoint>(L, idx, "PulleyJoint", PHYSICS_PULLEY_JOINT_T);
|
||||
if (!j->isValid())
|
||||
luaL_error(L, "Attempt to use destroyed joint.");
|
||||
return j;
|
||||
}
|
||||
|
||||
int w_PulleyJoint_getGroundAnchors(lua_State *L)
|
||||
{
|
||||
PulleyJoint *t = luax_checkpulleyjoint(L, 1);
|
||||
lua_remove(L, 1);
|
||||
return t->getGroundAnchors(L);
|
||||
}
|
||||
|
||||
int w_PulleyJoint_getLengthA(lua_State *L)
|
||||
{
|
||||
PulleyJoint *t = luax_checkpulleyjoint(L, 1);
|
||||
lua_pushnumber(L, t->getLengthA());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_PulleyJoint_getLengthB(lua_State *L)
|
||||
{
|
||||
PulleyJoint *t = luax_checkpulleyjoint(L, 1);
|
||||
lua_pushnumber(L, t->getLengthB());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_PulleyJoint_getRatio(lua_State *L)
|
||||
{
|
||||
PulleyJoint *t = luax_checkpulleyjoint(L, 1);
|
||||
lua_pushnumber(L, t->getRatio());
|
||||
return 1;
|
||||
}
|
||||
|
||||
static const luaL_Reg functions[] =
|
||||
{
|
||||
{ "getGroundAnchors", w_PulleyJoint_getGroundAnchors },
|
||||
{ "getLengthA", w_PulleyJoint_getLengthA },
|
||||
{ "getLengthB", w_PulleyJoint_getLengthB },
|
||||
{ "getRatio", w_PulleyJoint_getRatio },
|
||||
// From Joint.
|
||||
{ "getType", w_Joint_getType },
|
||||
{ "getAnchors", w_Joint_getAnchors },
|
||||
{ "getReactionForce", w_Joint_getReactionForce },
|
||||
{ "getReactionTorque", w_Joint_getReactionTorque },
|
||||
{ "getCollideConnected", w_Joint_getCollideConnected },
|
||||
{ "destroy", w_Joint_destroy },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
extern "C" int luaopen_pulleyjoint(lua_State *L)
|
||||
{
|
||||
return luax_register_type(L, "PulleyJoint", functions);
|
||||
}
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#include "wrap_PulleyJoint.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
PulleyJoint *luax_checkpulleyjoint(lua_State *L, int idx)
|
||||
{
|
||||
PulleyJoint *j = luax_checktype<PulleyJoint>(L, idx, "PulleyJoint", PHYSICS_PULLEY_JOINT_T);
|
||||
if (!j->isValid())
|
||||
luaL_error(L, "Attempt to use destroyed joint.");
|
||||
return j;
|
||||
}
|
||||
|
||||
int w_PulleyJoint_getGroundAnchors(lua_State *L)
|
||||
{
|
||||
PulleyJoint *t = luax_checkpulleyjoint(L, 1);
|
||||
lua_remove(L, 1);
|
||||
return t->getGroundAnchors(L);
|
||||
}
|
||||
|
||||
int w_PulleyJoint_getLengthA(lua_State *L)
|
||||
{
|
||||
PulleyJoint *t = luax_checkpulleyjoint(L, 1);
|
||||
lua_pushnumber(L, t->getLengthA());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_PulleyJoint_getLengthB(lua_State *L)
|
||||
{
|
||||
PulleyJoint *t = luax_checkpulleyjoint(L, 1);
|
||||
lua_pushnumber(L, t->getLengthB());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_PulleyJoint_getRatio(lua_State *L)
|
||||
{
|
||||
PulleyJoint *t = luax_checkpulleyjoint(L, 1);
|
||||
lua_pushnumber(L, t->getRatio());
|
||||
return 1;
|
||||
}
|
||||
|
||||
static const luaL_Reg functions[] =
|
||||
{
|
||||
{ "getGroundAnchors", w_PulleyJoint_getGroundAnchors },
|
||||
{ "getLengthA", w_PulleyJoint_getLengthA },
|
||||
{ "getLengthB", w_PulleyJoint_getLengthB },
|
||||
{ "getRatio", w_PulleyJoint_getRatio },
|
||||
// From Joint.
|
||||
{ "getType", w_Joint_getType },
|
||||
{ "getAnchors", w_Joint_getAnchors },
|
||||
{ "getReactionForce", w_Joint_getReactionForce },
|
||||
{ "getReactionTorque", w_Joint_getReactionTorque },
|
||||
{ "getCollideConnected", w_Joint_getCollideConnected },
|
||||
{ "destroy", w_Joint_destroy },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
extern "C" int luaopen_pulleyjoint(lua_State *L)
|
||||
{
|
||||
return luax_register_type(L, "PulleyJoint", functions);
|
||||
}
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
@@ -1,47 +1,47 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_PHYSICS_BOX2D_WRAP_PULLEY_JOINT_H
|
||||
#define LOVE_PHYSICS_BOX2D_WRAP_PULLEY_JOINT_H
|
||||
|
||||
// LOVE
|
||||
#include "common/runtime.h"
|
||||
#include "wrap_Joint.h"
|
||||
#include "PulleyJoint.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
PulleyJoint *luax_checkpulleyjoint(lua_State *L, int idx);
|
||||
int w_PulleyJoint_getGroundAnchors(lua_State *L);
|
||||
int w_PulleyJoint_getLengthA(lua_State *L);
|
||||
int w_PulleyJoint_getLengthB(lua_State *L);
|
||||
int w_PulleyJoint_getRatio(lua_State *L);
|
||||
extern "C" int luaopen_pulleyjoint(lua_State *L);
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_WRAP_PULLEY_JOINT_H
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_PHYSICS_BOX2D_WRAP_PULLEY_JOINT_H
|
||||
#define LOVE_PHYSICS_BOX2D_WRAP_PULLEY_JOINT_H
|
||||
|
||||
// LOVE
|
||||
#include "common/runtime.h"
|
||||
#include "wrap_Joint.h"
|
||||
#include "PulleyJoint.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
PulleyJoint *luax_checkpulleyjoint(lua_State *L, int idx);
|
||||
int w_PulleyJoint_getGroundAnchors(lua_State *L);
|
||||
int w_PulleyJoint_getLengthA(lua_State *L);
|
||||
int w_PulleyJoint_getLengthB(lua_State *L);
|
||||
int w_PulleyJoint_getRatio(lua_State *L);
|
||||
extern "C" int luaopen_pulleyjoint(lua_State *L);
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_WRAP_PULLEY_JOINT_H
|
||||
|
||||
@@ -1,202 +1,202 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#include "wrap_RevoluteJoint.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
RevoluteJoint *luax_checkrevolutejoint(lua_State *L, int idx)
|
||||
{
|
||||
RevoluteJoint *j = luax_checktype<RevoluteJoint>(L, idx, "RevoluteJoint", PHYSICS_REVOLUTE_JOINT_T);
|
||||
if (!j->isValid())
|
||||
luaL_error(L, "Attempt to use destroyed joint.");
|
||||
return j;
|
||||
}
|
||||
|
||||
int w_RevoluteJoint_getJointAngle(lua_State *L)
|
||||
{
|
||||
RevoluteJoint *t = luax_checkrevolutejoint(L, 1);
|
||||
lua_pushnumber(L, t->getJointAngle());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_RevoluteJoint_getJointSpeed(lua_State *L)
|
||||
{
|
||||
RevoluteJoint *t = luax_checkrevolutejoint(L, 1);
|
||||
lua_pushnumber(L, t->getJointSpeed());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_RevoluteJoint_enableMotor(lua_State *L)
|
||||
{
|
||||
RevoluteJoint *t = luax_checkrevolutejoint(L, 1);
|
||||
bool arg1 = luax_toboolean(L, 2);
|
||||
t->enableMotor(arg1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_RevoluteJoint_isMotorEnabled(lua_State *L)
|
||||
{
|
||||
RevoluteJoint *t = luax_checkrevolutejoint(L, 1);
|
||||
luax_pushboolean(L, t->isMotorEnabled());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_RevoluteJoint_setMaxMotorTorque(lua_State *L)
|
||||
{
|
||||
RevoluteJoint *t = luax_checkrevolutejoint(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
t->setMaxMotorTorque(arg1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_RevoluteJoint_setMotorSpeed(lua_State *L)
|
||||
{
|
||||
RevoluteJoint *t = luax_checkrevolutejoint(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
t->setMotorSpeed(arg1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_RevoluteJoint_getMotorSpeed(lua_State *L)
|
||||
{
|
||||
RevoluteJoint *t = luax_checkrevolutejoint(L, 1);
|
||||
lua_pushnumber(L, t->getMotorSpeed());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_RevoluteJoint_getMotorTorque(lua_State *L)
|
||||
{
|
||||
RevoluteJoint *t = luax_checkrevolutejoint(L, 1);
|
||||
float inv_dt = (float)luaL_checknumber(L, 2);
|
||||
lua_pushnumber(L, t->getMotorTorque(inv_dt));
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_RevoluteJoint_getMaxMotorTorque(lua_State *L)
|
||||
{
|
||||
RevoluteJoint *t = luax_checkrevolutejoint(L, 1);
|
||||
lua_pushnumber(L, t->getMaxMotorTorque());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_RevoluteJoint_enableLimit(lua_State *L)
|
||||
{
|
||||
RevoluteJoint *t = luax_checkrevolutejoint(L, 1);
|
||||
bool arg1 = luax_toboolean(L, 2);
|
||||
t->enableLimit(arg1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_RevoluteJoint_isLimitEnabled(lua_State *L)
|
||||
{
|
||||
RevoluteJoint *t = luax_checkrevolutejoint(L, 1);
|
||||
luax_pushboolean(L, t->isLimitEnabled());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_RevoluteJoint_setUpperLimit(lua_State *L)
|
||||
{
|
||||
RevoluteJoint *t = luax_checkrevolutejoint(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
t->setUpperLimit(arg1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_RevoluteJoint_setLowerLimit(lua_State *L)
|
||||
{
|
||||
RevoluteJoint *t = luax_checkrevolutejoint(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
t->setLowerLimit(arg1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_RevoluteJoint_setLimits(lua_State *L)
|
||||
{
|
||||
RevoluteJoint *t = luax_checkrevolutejoint(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
float arg2 = (float)luaL_checknumber(L, 3);
|
||||
t->setLimits(arg1, arg2);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_RevoluteJoint_getLowerLimit(lua_State *L)
|
||||
{
|
||||
RevoluteJoint *t = luax_checkrevolutejoint(L, 1);
|
||||
lua_pushnumber(L, t->getLowerLimit());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_RevoluteJoint_getUpperLimit(lua_State *L)
|
||||
{
|
||||
RevoluteJoint *t = luax_checkrevolutejoint(L, 1);
|
||||
lua_pushnumber(L, t->getUpperLimit());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_RevoluteJoint_getLimits(lua_State *L)
|
||||
{
|
||||
RevoluteJoint *t = luax_checkrevolutejoint(L, 1);
|
||||
lua_remove(L, 1);
|
||||
return t->getLimits(L);
|
||||
}
|
||||
|
||||
static const luaL_Reg functions[] =
|
||||
{
|
||||
{ "getJointAngle", w_RevoluteJoint_getJointAngle },
|
||||
{ "getJointSpeed", w_RevoluteJoint_getJointSpeed },
|
||||
{ "enableMotor", w_RevoluteJoint_enableMotor },
|
||||
{ "isMotorEnabled", w_RevoluteJoint_isMotorEnabled },
|
||||
{ "setMaxMotorTorque", w_RevoluteJoint_setMaxMotorTorque },
|
||||
{ "setMotorSpeed", w_RevoluteJoint_setMotorSpeed },
|
||||
{ "getMotorSpeed", w_RevoluteJoint_getMotorSpeed },
|
||||
{ "getMotorTorque", w_RevoluteJoint_getMotorTorque },
|
||||
{ "getMaxMotorTorque", w_RevoluteJoint_getMaxMotorTorque },
|
||||
{ "enableLimit", w_RevoluteJoint_enableLimit },
|
||||
{ "isLimitEnabled", w_RevoluteJoint_isLimitEnabled },
|
||||
{ "setUpperLimit", w_RevoluteJoint_setUpperLimit },
|
||||
{ "setLowerLimit", w_RevoluteJoint_setLowerLimit },
|
||||
{ "setLimits", w_RevoluteJoint_setLimits },
|
||||
{ "getLowerLimit", w_RevoluteJoint_getLowerLimit },
|
||||
{ "getUpperLimit", w_RevoluteJoint_getUpperLimit },
|
||||
{ "getLimits", w_RevoluteJoint_getLimits },
|
||||
// From Joint.
|
||||
{ "getType", w_Joint_getType },
|
||||
{ "getAnchors", w_Joint_getAnchors },
|
||||
{ "getReactionForce", w_Joint_getReactionForce },
|
||||
{ "getReactionTorque", w_Joint_getReactionTorque },
|
||||
{ "getCollideConnected", w_Joint_getCollideConnected },
|
||||
{ "destroy", w_Joint_destroy },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
extern "C" int luaopen_revolutejoint(lua_State *L)
|
||||
{
|
||||
return luax_register_type(L, "RevoluteJoint", functions);
|
||||
}
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#include "wrap_RevoluteJoint.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
RevoluteJoint *luax_checkrevolutejoint(lua_State *L, int idx)
|
||||
{
|
||||
RevoluteJoint *j = luax_checktype<RevoluteJoint>(L, idx, "RevoluteJoint", PHYSICS_REVOLUTE_JOINT_T);
|
||||
if (!j->isValid())
|
||||
luaL_error(L, "Attempt to use destroyed joint.");
|
||||
return j;
|
||||
}
|
||||
|
||||
int w_RevoluteJoint_getJointAngle(lua_State *L)
|
||||
{
|
||||
RevoluteJoint *t = luax_checkrevolutejoint(L, 1);
|
||||
lua_pushnumber(L, t->getJointAngle());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_RevoluteJoint_getJointSpeed(lua_State *L)
|
||||
{
|
||||
RevoluteJoint *t = luax_checkrevolutejoint(L, 1);
|
||||
lua_pushnumber(L, t->getJointSpeed());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_RevoluteJoint_enableMotor(lua_State *L)
|
||||
{
|
||||
RevoluteJoint *t = luax_checkrevolutejoint(L, 1);
|
||||
bool arg1 = luax_toboolean(L, 2);
|
||||
t->enableMotor(arg1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_RevoluteJoint_isMotorEnabled(lua_State *L)
|
||||
{
|
||||
RevoluteJoint *t = luax_checkrevolutejoint(L, 1);
|
||||
luax_pushboolean(L, t->isMotorEnabled());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_RevoluteJoint_setMaxMotorTorque(lua_State *L)
|
||||
{
|
||||
RevoluteJoint *t = luax_checkrevolutejoint(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
t->setMaxMotorTorque(arg1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_RevoluteJoint_setMotorSpeed(lua_State *L)
|
||||
{
|
||||
RevoluteJoint *t = luax_checkrevolutejoint(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
t->setMotorSpeed(arg1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_RevoluteJoint_getMotorSpeed(lua_State *L)
|
||||
{
|
||||
RevoluteJoint *t = luax_checkrevolutejoint(L, 1);
|
||||
lua_pushnumber(L, t->getMotorSpeed());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_RevoluteJoint_getMotorTorque(lua_State *L)
|
||||
{
|
||||
RevoluteJoint *t = luax_checkrevolutejoint(L, 1);
|
||||
float inv_dt = (float)luaL_checknumber(L, 2);
|
||||
lua_pushnumber(L, t->getMotorTorque(inv_dt));
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_RevoluteJoint_getMaxMotorTorque(lua_State *L)
|
||||
{
|
||||
RevoluteJoint *t = luax_checkrevolutejoint(L, 1);
|
||||
lua_pushnumber(L, t->getMaxMotorTorque());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_RevoluteJoint_enableLimit(lua_State *L)
|
||||
{
|
||||
RevoluteJoint *t = luax_checkrevolutejoint(L, 1);
|
||||
bool arg1 = luax_toboolean(L, 2);
|
||||
t->enableLimit(arg1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_RevoluteJoint_isLimitEnabled(lua_State *L)
|
||||
{
|
||||
RevoluteJoint *t = luax_checkrevolutejoint(L, 1);
|
||||
luax_pushboolean(L, t->isLimitEnabled());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_RevoluteJoint_setUpperLimit(lua_State *L)
|
||||
{
|
||||
RevoluteJoint *t = luax_checkrevolutejoint(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
t->setUpperLimit(arg1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_RevoluteJoint_setLowerLimit(lua_State *L)
|
||||
{
|
||||
RevoluteJoint *t = luax_checkrevolutejoint(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
t->setLowerLimit(arg1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_RevoluteJoint_setLimits(lua_State *L)
|
||||
{
|
||||
RevoluteJoint *t = luax_checkrevolutejoint(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
float arg2 = (float)luaL_checknumber(L, 3);
|
||||
t->setLimits(arg1, arg2);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_RevoluteJoint_getLowerLimit(lua_State *L)
|
||||
{
|
||||
RevoluteJoint *t = luax_checkrevolutejoint(L, 1);
|
||||
lua_pushnumber(L, t->getLowerLimit());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_RevoluteJoint_getUpperLimit(lua_State *L)
|
||||
{
|
||||
RevoluteJoint *t = luax_checkrevolutejoint(L, 1);
|
||||
lua_pushnumber(L, t->getUpperLimit());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_RevoluteJoint_getLimits(lua_State *L)
|
||||
{
|
||||
RevoluteJoint *t = luax_checkrevolutejoint(L, 1);
|
||||
lua_remove(L, 1);
|
||||
return t->getLimits(L);
|
||||
}
|
||||
|
||||
static const luaL_Reg functions[] =
|
||||
{
|
||||
{ "getJointAngle", w_RevoluteJoint_getJointAngle },
|
||||
{ "getJointSpeed", w_RevoluteJoint_getJointSpeed },
|
||||
{ "enableMotor", w_RevoluteJoint_enableMotor },
|
||||
{ "isMotorEnabled", w_RevoluteJoint_isMotorEnabled },
|
||||
{ "setMaxMotorTorque", w_RevoluteJoint_setMaxMotorTorque },
|
||||
{ "setMotorSpeed", w_RevoluteJoint_setMotorSpeed },
|
||||
{ "getMotorSpeed", w_RevoluteJoint_getMotorSpeed },
|
||||
{ "getMotorTorque", w_RevoluteJoint_getMotorTorque },
|
||||
{ "getMaxMotorTorque", w_RevoluteJoint_getMaxMotorTorque },
|
||||
{ "enableLimit", w_RevoluteJoint_enableLimit },
|
||||
{ "isLimitEnabled", w_RevoluteJoint_isLimitEnabled },
|
||||
{ "setUpperLimit", w_RevoluteJoint_setUpperLimit },
|
||||
{ "setLowerLimit", w_RevoluteJoint_setLowerLimit },
|
||||
{ "setLimits", w_RevoluteJoint_setLimits },
|
||||
{ "getLowerLimit", w_RevoluteJoint_getLowerLimit },
|
||||
{ "getUpperLimit", w_RevoluteJoint_getUpperLimit },
|
||||
{ "getLimits", w_RevoluteJoint_getLimits },
|
||||
// From Joint.
|
||||
{ "getType", w_Joint_getType },
|
||||
{ "getAnchors", w_Joint_getAnchors },
|
||||
{ "getReactionForce", w_Joint_getReactionForce },
|
||||
{ "getReactionTorque", w_Joint_getReactionTorque },
|
||||
{ "getCollideConnected", w_Joint_getCollideConnected },
|
||||
{ "destroy", w_Joint_destroy },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
extern "C" int luaopen_revolutejoint(lua_State *L)
|
||||
{
|
||||
return luax_register_type(L, "RevoluteJoint", functions);
|
||||
}
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
@@ -1,60 +1,60 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_PHYSICS_BOX2D_WRAP_REVOLUTE_JOINT_H
|
||||
#define LOVE_PHYSICS_BOX2D_WRAP_REVOLUTE_JOINT_H
|
||||
|
||||
// LOVE
|
||||
#include "common/runtime.h"
|
||||
#include "wrap_Joint.h"
|
||||
#include "RevoluteJoint.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
RevoluteJoint *luax_checkrevolutejoint(lua_State *L, int idx);
|
||||
int w_RevoluteJoint_getJointAngle(lua_State *L);
|
||||
int w_RevoluteJoint_getJointSpeed(lua_State *L);
|
||||
int w_RevoluteJoint_enableMotor(lua_State *L);
|
||||
int w_RevoluteJoint_isMotorEnabled(lua_State *L);
|
||||
int w_RevoluteJoint_setMaxMotorTorque(lua_State *L);
|
||||
int w_RevoluteJoint_setMotorSpeed(lua_State *L);
|
||||
int w_RevoluteJoint_getMotorSpeed(lua_State *L);
|
||||
int w_RevoluteJoint_getMotorTorque(lua_State *L);
|
||||
int w_RevoluteJoint_getMaxMotorTorque(lua_State *L);
|
||||
int w_RevoluteJoint_enableLimit(lua_State *L);
|
||||
int w_RevoluteJoint_isLimitEnabled(lua_State *L);
|
||||
int w_RevoluteJoint_setUpperLimit(lua_State *L);
|
||||
int w_RevoluteJoint_setLowerLimit(lua_State *L);
|
||||
int w_RevoluteJoint_setLimits(lua_State *L);
|
||||
int w_RevoluteJoint_getLowerLimit(lua_State *L);
|
||||
int w_RevoluteJoint_getUpperLimit(lua_State *L);
|
||||
int w_RevoluteJoint_getLimits(lua_State *L);
|
||||
extern "C" int luaopen_revolutejoint(lua_State *L);
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_WRAP_REVOLUTE_JOINT_H
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_PHYSICS_BOX2D_WRAP_REVOLUTE_JOINT_H
|
||||
#define LOVE_PHYSICS_BOX2D_WRAP_REVOLUTE_JOINT_H
|
||||
|
||||
// LOVE
|
||||
#include "common/runtime.h"
|
||||
#include "wrap_Joint.h"
|
||||
#include "RevoluteJoint.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
RevoluteJoint *luax_checkrevolutejoint(lua_State *L, int idx);
|
||||
int w_RevoluteJoint_getJointAngle(lua_State *L);
|
||||
int w_RevoluteJoint_getJointSpeed(lua_State *L);
|
||||
int w_RevoluteJoint_enableMotor(lua_State *L);
|
||||
int w_RevoluteJoint_isMotorEnabled(lua_State *L);
|
||||
int w_RevoluteJoint_setMaxMotorTorque(lua_State *L);
|
||||
int w_RevoluteJoint_setMotorSpeed(lua_State *L);
|
||||
int w_RevoluteJoint_getMotorSpeed(lua_State *L);
|
||||
int w_RevoluteJoint_getMotorTorque(lua_State *L);
|
||||
int w_RevoluteJoint_getMaxMotorTorque(lua_State *L);
|
||||
int w_RevoluteJoint_enableLimit(lua_State *L);
|
||||
int w_RevoluteJoint_isLimitEnabled(lua_State *L);
|
||||
int w_RevoluteJoint_setUpperLimit(lua_State *L);
|
||||
int w_RevoluteJoint_setLowerLimit(lua_State *L);
|
||||
int w_RevoluteJoint_setLimits(lua_State *L);
|
||||
int w_RevoluteJoint_getLowerLimit(lua_State *L);
|
||||
int w_RevoluteJoint_getUpperLimit(lua_State *L);
|
||||
int w_RevoluteJoint_getLimits(lua_State *L);
|
||||
extern "C" int luaopen_revolutejoint(lua_State *L);
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_WRAP_REVOLUTE_JOINT_H
|
||||
|
||||
@@ -1,65 +1,65 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#include "wrap_RopeJoint.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
RopeJoint *luax_checkropejoint(lua_State *L, int idx)
|
||||
{
|
||||
RopeJoint *j = luax_checktype<RopeJoint>(L, idx, "RopeJoint", PHYSICS_ROPE_JOINT_T);
|
||||
if (!j->isValid())
|
||||
luaL_error(L, "Attempt to use destroyed joint.");
|
||||
return j;
|
||||
}
|
||||
|
||||
int w_RopeJoint_getMaxLength(lua_State *L)
|
||||
{
|
||||
RopeJoint *t = luax_checkropejoint(L, 1);
|
||||
lua_pushnumber(L, t->getMaxLength());
|
||||
return 1;
|
||||
}
|
||||
|
||||
static const luaL_Reg functions[] =
|
||||
{
|
||||
{ "getMaxLength", w_RopeJoint_getMaxLength },
|
||||
// From Joint.
|
||||
{ "getType", w_Joint_getType },
|
||||
{ "getAnchors", w_Joint_getAnchors },
|
||||
{ "getReactionForce", w_Joint_getReactionForce },
|
||||
{ "getReactionTorque", w_Joint_getReactionTorque },
|
||||
{ "getCollideConnected", w_Joint_getCollideConnected },
|
||||
{ "destroy", w_Joint_destroy },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
extern "C" int luaopen_ropejoint(lua_State *L)
|
||||
{
|
||||
return luax_register_type(L, "RopeJoint", functions);
|
||||
}
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#include "wrap_RopeJoint.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
RopeJoint *luax_checkropejoint(lua_State *L, int idx)
|
||||
{
|
||||
RopeJoint *j = luax_checktype<RopeJoint>(L, idx, "RopeJoint", PHYSICS_ROPE_JOINT_T);
|
||||
if (!j->isValid())
|
||||
luaL_error(L, "Attempt to use destroyed joint.");
|
||||
return j;
|
||||
}
|
||||
|
||||
int w_RopeJoint_getMaxLength(lua_State *L)
|
||||
{
|
||||
RopeJoint *t = luax_checkropejoint(L, 1);
|
||||
lua_pushnumber(L, t->getMaxLength());
|
||||
return 1;
|
||||
}
|
||||
|
||||
static const luaL_Reg functions[] =
|
||||
{
|
||||
{ "getMaxLength", w_RopeJoint_getMaxLength },
|
||||
// From Joint.
|
||||
{ "getType", w_Joint_getType },
|
||||
{ "getAnchors", w_Joint_getAnchors },
|
||||
{ "getReactionForce", w_Joint_getReactionForce },
|
||||
{ "getReactionTorque", w_Joint_getReactionTorque },
|
||||
{ "getCollideConnected", w_Joint_getCollideConnected },
|
||||
{ "destroy", w_Joint_destroy },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
extern "C" int luaopen_ropejoint(lua_State *L)
|
||||
{
|
||||
return luax_register_type(L, "RopeJoint", functions);
|
||||
}
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
@@ -1,44 +1,44 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_PHYSICS_BOX2D_WRAP_ROPE_JOINT_H
|
||||
#define LOVE_PHYSICS_BOX2D_WRAP_ROPE_JOINT_H
|
||||
|
||||
// LOVE
|
||||
#include "common/runtime.h"
|
||||
#include "wrap_Joint.h"
|
||||
#include "RopeJoint.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
RopeJoint *luax_checkropejoint(lua_State *L, int idx);
|
||||
int w_RopeJoint_getMaxLength(lua_State *L);
|
||||
extern "C" int luaopen_ropejoint(lua_State *L);
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_WRAP_ROPE_JOINT_H
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_PHYSICS_BOX2D_WRAP_ROPE_JOINT_H
|
||||
#define LOVE_PHYSICS_BOX2D_WRAP_ROPE_JOINT_H
|
||||
|
||||
// LOVE
|
||||
#include "common/runtime.h"
|
||||
#include "wrap_Joint.h"
|
||||
#include "RopeJoint.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
RopeJoint *luax_checkropejoint(lua_State *L, int idx);
|
||||
int w_RopeJoint_getMaxLength(lua_State *L);
|
||||
extern "C" int luaopen_ropejoint(lua_State *L);
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_WRAP_ROPE_JOINT_H
|
||||
|
||||
@@ -1,115 +1,115 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#include "wrap_Shape.h"
|
||||
#include "common/StringMap.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
Shape *luax_checkshape(lua_State *L, int idx)
|
||||
{
|
||||
return luax_checktype<Shape>(L, idx, "Shape", PHYSICS_SHAPE_T);
|
||||
}
|
||||
|
||||
int w_Shape_getType(lua_State *L)
|
||||
{
|
||||
Shape *t = luax_checkshape(L, 1);
|
||||
const char *type = "";
|
||||
Shape::getConstant(t->getType(), type);
|
||||
lua_pushstring(L, type);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_Shape_getRadius(lua_State *L)
|
||||
{
|
||||
Shape *t = luax_checkshape(L, 1);
|
||||
float radius = t->getRadius();
|
||||
lua_pushnumber(L, radius);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_Shape_getChildCount(lua_State *L)
|
||||
{
|
||||
Shape *t = luax_checkshape(L, 1);
|
||||
int childCount = t->getChildCount();
|
||||
lua_pushinteger(L, childCount);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_Shape_testPoint(lua_State *L)
|
||||
{
|
||||
Shape *t = luax_checkshape(L, 1);
|
||||
float x = (float)luaL_checknumber(L, 2);
|
||||
float y = (float)luaL_checknumber(L, 3);
|
||||
float r = (float)luaL_checknumber(L, 4);
|
||||
float px = (float)luaL_checknumber(L, 5);
|
||||
float py = (float)luaL_checknumber(L, 6);
|
||||
bool result = t->testPoint(x, y, r, px, py);
|
||||
lua_pushboolean(L, result);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_Shape_rayCast(lua_State *L)
|
||||
{
|
||||
Shape *t = luax_checkshape(L, 1);
|
||||
lua_remove(L, 1);
|
||||
ASSERT_GUARD(return t->rayCast(L);)
|
||||
}
|
||||
|
||||
int w_Shape_computeAABB(lua_State *L)
|
||||
{
|
||||
Shape *t = luax_checkshape(L, 1);
|
||||
lua_remove(L, 1);
|
||||
return t->computeAABB(L);
|
||||
}
|
||||
|
||||
int w_Shape_computeMass(lua_State *L)
|
||||
{
|
||||
Shape *t = luax_checkshape(L, 1);
|
||||
lua_remove(L, 1);
|
||||
return t->computeMass(L);
|
||||
}
|
||||
|
||||
static const luaL_Reg functions[] =
|
||||
{
|
||||
{ "getType", w_Shape_getType },
|
||||
{ "getRadius", w_Shape_getRadius },
|
||||
{ "getChildCount", w_Shape_getChildCount },
|
||||
{ "testPoint", w_Shape_testPoint },
|
||||
{ "rayCast", w_Shape_rayCast },
|
||||
{ "computeAABB", w_Shape_computeAABB },
|
||||
{ "computeMass", w_Shape_computeMass },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
extern "C" int luaopen_shape(lua_State *L)
|
||||
{
|
||||
return luax_register_type(L, "Shape", functions);
|
||||
}
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#include "wrap_Shape.h"
|
||||
#include "common/StringMap.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
Shape *luax_checkshape(lua_State *L, int idx)
|
||||
{
|
||||
return luax_checktype<Shape>(L, idx, "Shape", PHYSICS_SHAPE_T);
|
||||
}
|
||||
|
||||
int w_Shape_getType(lua_State *L)
|
||||
{
|
||||
Shape *t = luax_checkshape(L, 1);
|
||||
const char *type = "";
|
||||
Shape::getConstant(t->getType(), type);
|
||||
lua_pushstring(L, type);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_Shape_getRadius(lua_State *L)
|
||||
{
|
||||
Shape *t = luax_checkshape(L, 1);
|
||||
float radius = t->getRadius();
|
||||
lua_pushnumber(L, radius);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_Shape_getChildCount(lua_State *L)
|
||||
{
|
||||
Shape *t = luax_checkshape(L, 1);
|
||||
int childCount = t->getChildCount();
|
||||
lua_pushinteger(L, childCount);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_Shape_testPoint(lua_State *L)
|
||||
{
|
||||
Shape *t = luax_checkshape(L, 1);
|
||||
float x = (float)luaL_checknumber(L, 2);
|
||||
float y = (float)luaL_checknumber(L, 3);
|
||||
float r = (float)luaL_checknumber(L, 4);
|
||||
float px = (float)luaL_checknumber(L, 5);
|
||||
float py = (float)luaL_checknumber(L, 6);
|
||||
bool result = t->testPoint(x, y, r, px, py);
|
||||
lua_pushboolean(L, result);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_Shape_rayCast(lua_State *L)
|
||||
{
|
||||
Shape *t = luax_checkshape(L, 1);
|
||||
lua_remove(L, 1);
|
||||
ASSERT_GUARD(return t->rayCast(L);)
|
||||
}
|
||||
|
||||
int w_Shape_computeAABB(lua_State *L)
|
||||
{
|
||||
Shape *t = luax_checkshape(L, 1);
|
||||
lua_remove(L, 1);
|
||||
return t->computeAABB(L);
|
||||
}
|
||||
|
||||
int w_Shape_computeMass(lua_State *L)
|
||||
{
|
||||
Shape *t = luax_checkshape(L, 1);
|
||||
lua_remove(L, 1);
|
||||
return t->computeMass(L);
|
||||
}
|
||||
|
||||
static const luaL_Reg functions[] =
|
||||
{
|
||||
{ "getType", w_Shape_getType },
|
||||
{ "getRadius", w_Shape_getRadius },
|
||||
{ "getChildCount", w_Shape_getChildCount },
|
||||
{ "testPoint", w_Shape_testPoint },
|
||||
{ "rayCast", w_Shape_rayCast },
|
||||
{ "computeAABB", w_Shape_computeAABB },
|
||||
{ "computeMass", w_Shape_computeMass },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
extern "C" int luaopen_shape(lua_State *L)
|
||||
{
|
||||
return luax_register_type(L, "Shape", functions);
|
||||
}
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
|
||||
@@ -1,52 +1,52 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_PHYSICS_BOX2D_WRAP_SHAPE_H
|
||||
#define LOVE_PHYSICS_BOX2D_WRAP_SHAPE_H
|
||||
|
||||
// LOVE
|
||||
#include "common/runtime.h"
|
||||
#include "Shape.h"
|
||||
#include "wrap_Physics.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
Shape *luax_checkshape(lua_State *L, int idx);
|
||||
int w_Shape_getType(lua_State *L);
|
||||
int w_Shape_getRadius(lua_State *L);
|
||||
|
||||
int w_Shape_getChildCount(lua_State *L);
|
||||
int w_Shape_testPoint(lua_State *L);
|
||||
int w_Shape_rayCast(lua_State *L);
|
||||
int w_Shape_computeAABB(lua_State *L);
|
||||
int w_Shape_computeMass(lua_State *L);
|
||||
|
||||
extern "C" int luaopen_shape(lua_State *L);
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_WRAP_SHAPE_H
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_PHYSICS_BOX2D_WRAP_SHAPE_H
|
||||
#define LOVE_PHYSICS_BOX2D_WRAP_SHAPE_H
|
||||
|
||||
// LOVE
|
||||
#include "common/runtime.h"
|
||||
#include "Shape.h"
|
||||
#include "wrap_Physics.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
Shape *luax_checkshape(lua_State *L, int idx);
|
||||
int w_Shape_getType(lua_State *L);
|
||||
int w_Shape_getRadius(lua_State *L);
|
||||
|
||||
int w_Shape_getChildCount(lua_State *L);
|
||||
int w_Shape_testPoint(lua_State *L);
|
||||
int w_Shape_rayCast(lua_State *L);
|
||||
int w_Shape_computeAABB(lua_State *L);
|
||||
int w_Shape_computeMass(lua_State *L);
|
||||
|
||||
extern "C" int luaopen_shape(lua_State *L);
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_WRAP_SHAPE_H
|
||||
|
||||
@@ -1,91 +1,91 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#include "wrap_WeldJoint.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
WeldJoint *luax_checkweldjoint(lua_State *L, int idx)
|
||||
{
|
||||
WeldJoint *j = luax_checktype<WeldJoint>(L, idx, "WeldJoint", PHYSICS_WELD_JOINT_T);
|
||||
if (!j->isValid())
|
||||
luaL_error(L, "Attempt to use destroyed joint.");
|
||||
return j;
|
||||
}
|
||||
|
||||
int w_WeldJoint_setFrequency(lua_State *L)
|
||||
{
|
||||
WeldJoint *t = luax_checkweldjoint(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
t->setFrequency(arg1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_WeldJoint_getFrequency(lua_State *L)
|
||||
{
|
||||
WeldJoint *t = luax_checkweldjoint(L, 1);
|
||||
lua_pushnumber(L, t->getFrequency());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_WeldJoint_setDampingRatio(lua_State *L)
|
||||
{
|
||||
WeldJoint *t = luax_checkweldjoint(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
t->setDampingRatio(arg1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_WeldJoint_getDampingRatio(lua_State *L)
|
||||
{
|
||||
WeldJoint *t = luax_checkweldjoint(L, 1);
|
||||
lua_pushnumber(L, t->getDampingRatio());
|
||||
return 1;
|
||||
}
|
||||
|
||||
static const luaL_Reg functions[] =
|
||||
{
|
||||
{ "setFrequency", w_WeldJoint_setFrequency },
|
||||
{ "getFrequency", w_WeldJoint_getFrequency },
|
||||
{ "setDampingRatio", w_WeldJoint_setDampingRatio },
|
||||
{ "getDampingRatio", w_WeldJoint_getDampingRatio },
|
||||
// From Joint.
|
||||
{ "getType", w_Joint_getType },
|
||||
{ "getAnchors", w_Joint_getAnchors },
|
||||
{ "getReactionForce", w_Joint_getReactionForce },
|
||||
{ "getReactionTorque", w_Joint_getReactionTorque },
|
||||
{ "getCollideConnected", w_Joint_getCollideConnected },
|
||||
{ "destroy", w_Joint_destroy },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
extern "C" int luaopen_weldjoint(lua_State *L)
|
||||
{
|
||||
return luax_register_type(L, "WeldJoint", functions);
|
||||
}
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#include "wrap_WeldJoint.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
WeldJoint *luax_checkweldjoint(lua_State *L, int idx)
|
||||
{
|
||||
WeldJoint *j = luax_checktype<WeldJoint>(L, idx, "WeldJoint", PHYSICS_WELD_JOINT_T);
|
||||
if (!j->isValid())
|
||||
luaL_error(L, "Attempt to use destroyed joint.");
|
||||
return j;
|
||||
}
|
||||
|
||||
int w_WeldJoint_setFrequency(lua_State *L)
|
||||
{
|
||||
WeldJoint *t = luax_checkweldjoint(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
t->setFrequency(arg1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_WeldJoint_getFrequency(lua_State *L)
|
||||
{
|
||||
WeldJoint *t = luax_checkweldjoint(L, 1);
|
||||
lua_pushnumber(L, t->getFrequency());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_WeldJoint_setDampingRatio(lua_State *L)
|
||||
{
|
||||
WeldJoint *t = luax_checkweldjoint(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
t->setDampingRatio(arg1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_WeldJoint_getDampingRatio(lua_State *L)
|
||||
{
|
||||
WeldJoint *t = luax_checkweldjoint(L, 1);
|
||||
lua_pushnumber(L, t->getDampingRatio());
|
||||
return 1;
|
||||
}
|
||||
|
||||
static const luaL_Reg functions[] =
|
||||
{
|
||||
{ "setFrequency", w_WeldJoint_setFrequency },
|
||||
{ "getFrequency", w_WeldJoint_getFrequency },
|
||||
{ "setDampingRatio", w_WeldJoint_setDampingRatio },
|
||||
{ "getDampingRatio", w_WeldJoint_getDampingRatio },
|
||||
// From Joint.
|
||||
{ "getType", w_Joint_getType },
|
||||
{ "getAnchors", w_Joint_getAnchors },
|
||||
{ "getReactionForce", w_Joint_getReactionForce },
|
||||
{ "getReactionTorque", w_Joint_getReactionTorque },
|
||||
{ "getCollideConnected", w_Joint_getCollideConnected },
|
||||
{ "destroy", w_Joint_destroy },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
extern "C" int luaopen_weldjoint(lua_State *L)
|
||||
{
|
||||
return luax_register_type(L, "WeldJoint", functions);
|
||||
}
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
@@ -1,49 +1,49 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_PHYSICS_BOX2D_WRAP_WELD_JOINT_H
|
||||
#define LOVE_PHYSICS_BOX2D_WRAP_WELD_JOINT_H
|
||||
|
||||
// LOVE
|
||||
#include "common/runtime.h"
|
||||
#include "wrap_Joint.h"
|
||||
#include "WeldJoint.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
WeldJoint *luax_checkweldjoint(lua_State *L, int idx);
|
||||
|
||||
int w_WeldJoint_setFrequency(lua_State *L);
|
||||
int w_WeldJoint_getFrequency(lua_State *L);
|
||||
int w_WeldJoint_setDampingRatio(lua_State *L);
|
||||
int w_WeldJoint_getDampingRatio(lua_State *L);
|
||||
|
||||
extern "C" int luaopen_weldjoint(lua_State *L);
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_WRAP_WELD_JOINT_H
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_PHYSICS_BOX2D_WRAP_WELD_JOINT_H
|
||||
#define LOVE_PHYSICS_BOX2D_WRAP_WELD_JOINT_H
|
||||
|
||||
// LOVE
|
||||
#include "common/runtime.h"
|
||||
#include "wrap_Joint.h"
|
||||
#include "WeldJoint.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
WeldJoint *luax_checkweldjoint(lua_State *L, int idx);
|
||||
|
||||
int w_WeldJoint_setFrequency(lua_State *L);
|
||||
int w_WeldJoint_getFrequency(lua_State *L);
|
||||
int w_WeldJoint_setDampingRatio(lua_State *L);
|
||||
int w_WeldJoint_getDampingRatio(lua_State *L);
|
||||
|
||||
extern "C" int luaopen_weldjoint(lua_State *L);
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_WRAP_WELD_JOINT_H
|
||||
|
||||
@@ -1,167 +1,167 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#include "wrap_WheelJoint.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
WheelJoint *luax_checkwheeljoint(lua_State *L, int idx)
|
||||
{
|
||||
WheelJoint *j = luax_checktype<WheelJoint>(L, idx, "WheelJoint", PHYSICS_WHEEL_JOINT_T);
|
||||
if (!j->isValid())
|
||||
luaL_error(L, "Attempt to use destroyed joint.");
|
||||
return j;
|
||||
}
|
||||
|
||||
int w_WheelJoint_getJointTranslation(lua_State *L)
|
||||
{
|
||||
WheelJoint *t = luax_checkwheeljoint(L, 1);
|
||||
lua_pushnumber(L, t->getJointTranslation());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_WheelJoint_getJointSpeed(lua_State *L)
|
||||
{
|
||||
WheelJoint *t = luax_checkwheeljoint(L, 1);
|
||||
lua_pushnumber(L, t->getJointSpeed());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_WheelJoint_enableMotor(lua_State *L)
|
||||
{
|
||||
WheelJoint *t = luax_checkwheeljoint(L, 1);
|
||||
bool arg1 = luax_toboolean(L, 2);
|
||||
t->enableMotor(arg1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_WheelJoint_isMotorEnabled(lua_State *L)
|
||||
{
|
||||
WheelJoint *t = luax_checkwheeljoint(L, 1);
|
||||
luax_pushboolean(L, t->isMotorEnabled());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_WheelJoint_setMotorSpeed(lua_State *L)
|
||||
{
|
||||
WheelJoint *t = luax_checkwheeljoint(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
t->setMotorSpeed(arg1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_WheelJoint_getMotorSpeed(lua_State *L)
|
||||
{
|
||||
WheelJoint *t = luax_checkwheeljoint(L, 1);
|
||||
lua_pushnumber(L, t->getMotorSpeed());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_WheelJoint_setMaxMotorTorque(lua_State *L)
|
||||
{
|
||||
WheelJoint *t = luax_checkwheeljoint(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
t->setMaxMotorTorque(arg1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_WheelJoint_getMaxMotorTorque(lua_State *L)
|
||||
{
|
||||
WheelJoint *t = luax_checkwheeljoint(L, 1);
|
||||
lua_pushnumber(L, t->getMaxMotorTorque());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_WheelJoint_getMotorTorque(lua_State *L)
|
||||
{
|
||||
WheelJoint *t = luax_checkwheeljoint(L, 1);
|
||||
float inv_dt = (float)luaL_checknumber(L, 2);
|
||||
lua_pushnumber(L, t->getMotorTorque(inv_dt));
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_WheelJoint_setSpringFrequency(lua_State *L)
|
||||
{
|
||||
WheelJoint *t = luax_checkwheeljoint(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
t->setSpringFrequency(arg1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_WheelJoint_getSpringFrequency(lua_State *L)
|
||||
{
|
||||
WheelJoint *t = luax_checkwheeljoint(L, 1);
|
||||
lua_pushnumber(L, t->getSpringFrequency());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_WheelJoint_setSpringDampingRatio(lua_State *L)
|
||||
{
|
||||
WheelJoint *t = luax_checkwheeljoint(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
t->setSpringDampingRatio(arg1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_WheelJoint_getSpringDampingRatio(lua_State *L)
|
||||
{
|
||||
WheelJoint *t = luax_checkwheeljoint(L, 1);
|
||||
lua_pushnumber(L, t->getSpringDampingRatio());
|
||||
return 1;
|
||||
}
|
||||
|
||||
static const luaL_Reg functions[] =
|
||||
{
|
||||
{ "getJointTranslation", w_WheelJoint_getJointTranslation },
|
||||
{ "getJointSpeed", w_WheelJoint_getJointSpeed },
|
||||
{ "enableMotor", w_WheelJoint_enableMotor },
|
||||
{ "isMotorEnabled", w_WheelJoint_isMotorEnabled },
|
||||
{ "setMotorSpeed", w_WheelJoint_setMotorSpeed },
|
||||
{ "getMotorSpeed", w_WheelJoint_getMotorSpeed },
|
||||
{ "setMaxMotorTorque", w_WheelJoint_setMaxMotorTorque },
|
||||
{ "getMaxMotorTorque", w_WheelJoint_getMaxMotorTorque },
|
||||
{ "getMotorTorque", w_WheelJoint_getMotorTorque },
|
||||
{ "setSpringFrequency", w_WheelJoint_setSpringFrequency },
|
||||
{ "getSpringFrequency", w_WheelJoint_getSpringFrequency },
|
||||
{ "setSpringDampingRatio", w_WheelJoint_setSpringDampingRatio },
|
||||
{ "getSpringDampingRatio", w_WheelJoint_getSpringDampingRatio },
|
||||
// From Joint.
|
||||
{ "getType", w_Joint_getType },
|
||||
{ "getAnchors", w_Joint_getAnchors },
|
||||
{ "getReactionForce", w_Joint_getReactionForce },
|
||||
{ "getReactionTorque", w_Joint_getReactionTorque },
|
||||
{ "getCollideConnected", w_Joint_getCollideConnected },
|
||||
{ "destroy", w_Joint_destroy },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
extern "C" int luaopen_wheeljoint(lua_State *L)
|
||||
{
|
||||
return luax_register_type(L, "WheelJoint", functions);
|
||||
}
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#include "wrap_WheelJoint.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
WheelJoint *luax_checkwheeljoint(lua_State *L, int idx)
|
||||
{
|
||||
WheelJoint *j = luax_checktype<WheelJoint>(L, idx, "WheelJoint", PHYSICS_WHEEL_JOINT_T);
|
||||
if (!j->isValid())
|
||||
luaL_error(L, "Attempt to use destroyed joint.");
|
||||
return j;
|
||||
}
|
||||
|
||||
int w_WheelJoint_getJointTranslation(lua_State *L)
|
||||
{
|
||||
WheelJoint *t = luax_checkwheeljoint(L, 1);
|
||||
lua_pushnumber(L, t->getJointTranslation());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_WheelJoint_getJointSpeed(lua_State *L)
|
||||
{
|
||||
WheelJoint *t = luax_checkwheeljoint(L, 1);
|
||||
lua_pushnumber(L, t->getJointSpeed());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_WheelJoint_enableMotor(lua_State *L)
|
||||
{
|
||||
WheelJoint *t = luax_checkwheeljoint(L, 1);
|
||||
bool arg1 = luax_toboolean(L, 2);
|
||||
t->enableMotor(arg1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_WheelJoint_isMotorEnabled(lua_State *L)
|
||||
{
|
||||
WheelJoint *t = luax_checkwheeljoint(L, 1);
|
||||
luax_pushboolean(L, t->isMotorEnabled());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_WheelJoint_setMotorSpeed(lua_State *L)
|
||||
{
|
||||
WheelJoint *t = luax_checkwheeljoint(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
t->setMotorSpeed(arg1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_WheelJoint_getMotorSpeed(lua_State *L)
|
||||
{
|
||||
WheelJoint *t = luax_checkwheeljoint(L, 1);
|
||||
lua_pushnumber(L, t->getMotorSpeed());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_WheelJoint_setMaxMotorTorque(lua_State *L)
|
||||
{
|
||||
WheelJoint *t = luax_checkwheeljoint(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
t->setMaxMotorTorque(arg1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_WheelJoint_getMaxMotorTorque(lua_State *L)
|
||||
{
|
||||
WheelJoint *t = luax_checkwheeljoint(L, 1);
|
||||
lua_pushnumber(L, t->getMaxMotorTorque());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_WheelJoint_getMotorTorque(lua_State *L)
|
||||
{
|
||||
WheelJoint *t = luax_checkwheeljoint(L, 1);
|
||||
float inv_dt = (float)luaL_checknumber(L, 2);
|
||||
lua_pushnumber(L, t->getMotorTorque(inv_dt));
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_WheelJoint_setSpringFrequency(lua_State *L)
|
||||
{
|
||||
WheelJoint *t = luax_checkwheeljoint(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
t->setSpringFrequency(arg1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_WheelJoint_getSpringFrequency(lua_State *L)
|
||||
{
|
||||
WheelJoint *t = luax_checkwheeljoint(L, 1);
|
||||
lua_pushnumber(L, t->getSpringFrequency());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_WheelJoint_setSpringDampingRatio(lua_State *L)
|
||||
{
|
||||
WheelJoint *t = luax_checkwheeljoint(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
t->setSpringDampingRatio(arg1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_WheelJoint_getSpringDampingRatio(lua_State *L)
|
||||
{
|
||||
WheelJoint *t = luax_checkwheeljoint(L, 1);
|
||||
lua_pushnumber(L, t->getSpringDampingRatio());
|
||||
return 1;
|
||||
}
|
||||
|
||||
static const luaL_Reg functions[] =
|
||||
{
|
||||
{ "getJointTranslation", w_WheelJoint_getJointTranslation },
|
||||
{ "getJointSpeed", w_WheelJoint_getJointSpeed },
|
||||
{ "enableMotor", w_WheelJoint_enableMotor },
|
||||
{ "isMotorEnabled", w_WheelJoint_isMotorEnabled },
|
||||
{ "setMotorSpeed", w_WheelJoint_setMotorSpeed },
|
||||
{ "getMotorSpeed", w_WheelJoint_getMotorSpeed },
|
||||
{ "setMaxMotorTorque", w_WheelJoint_setMaxMotorTorque },
|
||||
{ "getMaxMotorTorque", w_WheelJoint_getMaxMotorTorque },
|
||||
{ "getMotorTorque", w_WheelJoint_getMotorTorque },
|
||||
{ "setSpringFrequency", w_WheelJoint_setSpringFrequency },
|
||||
{ "getSpringFrequency", w_WheelJoint_getSpringFrequency },
|
||||
{ "setSpringDampingRatio", w_WheelJoint_setSpringDampingRatio },
|
||||
{ "getSpringDampingRatio", w_WheelJoint_getSpringDampingRatio },
|
||||
// From Joint.
|
||||
{ "getType", w_Joint_getType },
|
||||
{ "getAnchors", w_Joint_getAnchors },
|
||||
{ "getReactionForce", w_Joint_getReactionForce },
|
||||
{ "getReactionTorque", w_Joint_getReactionTorque },
|
||||
{ "getCollideConnected", w_Joint_getCollideConnected },
|
||||
{ "destroy", w_Joint_destroy },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
extern "C" int luaopen_wheeljoint(lua_State *L)
|
||||
{
|
||||
return luax_register_type(L, "WheelJoint", functions);
|
||||
}
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
@@ -1,56 +1,56 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_PHYSICS_BOX2D_WRAP_WHEEL_JOINT_H
|
||||
#define LOVE_PHYSICS_BOX2D_WRAP_WHEEL_JOINT_H
|
||||
|
||||
// LOVE
|
||||
#include "common/runtime.h"
|
||||
#include "wrap_Joint.h"
|
||||
#include "WheelJoint.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
WheelJoint *luax_checkwheeljoint(lua_State *L, int idx);
|
||||
int w_WheelJoint_getJointTranslation(lua_State *L);
|
||||
int w_WheelJoint_getJointSpeed(lua_State *L);
|
||||
int w_WheelJoint_enableMotor(lua_State *L);
|
||||
int w_WheelJoint_isMotorEnabled(lua_State *L);
|
||||
int w_WheelJoint_setMotorSpeed(lua_State *L);
|
||||
int w_WheelJoint_getMotorSpeed(lua_State *L);
|
||||
int w_WheelJoint_setMaxMotorTorque(lua_State *L);
|
||||
int w_WheelJoint_getMaxMotorTorque(lua_State *L);
|
||||
int w_WheelJoint_getMotorTorque(lua_State *L);
|
||||
int w_WheelJoint_setSpringFrequency(lua_State *L);
|
||||
int w_WheelJoint_getSpringFrequency(lua_State *L);
|
||||
int w_WheelJoint_setSpringDampingRatio(lua_State *L);
|
||||
int w_WheelJoint_getSpringDampingRatio(lua_State *L);
|
||||
extern "C" int luaopen_wheeljoint(lua_State *L);
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_WRAP_WHEEL_JOINT_H
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_PHYSICS_BOX2D_WRAP_WHEEL_JOINT_H
|
||||
#define LOVE_PHYSICS_BOX2D_WRAP_WHEEL_JOINT_H
|
||||
|
||||
// LOVE
|
||||
#include "common/runtime.h"
|
||||
#include "wrap_Joint.h"
|
||||
#include "WheelJoint.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
WheelJoint *luax_checkwheeljoint(lua_State *L, int idx);
|
||||
int w_WheelJoint_getJointTranslation(lua_State *L);
|
||||
int w_WheelJoint_getJointSpeed(lua_State *L);
|
||||
int w_WheelJoint_enableMotor(lua_State *L);
|
||||
int w_WheelJoint_isMotorEnabled(lua_State *L);
|
||||
int w_WheelJoint_setMotorSpeed(lua_State *L);
|
||||
int w_WheelJoint_getMotorSpeed(lua_State *L);
|
||||
int w_WheelJoint_setMaxMotorTorque(lua_State *L);
|
||||
int w_WheelJoint_getMaxMotorTorque(lua_State *L);
|
||||
int w_WheelJoint_getMotorTorque(lua_State *L);
|
||||
int w_WheelJoint_setSpringFrequency(lua_State *L);
|
||||
int w_WheelJoint_getSpringFrequency(lua_State *L);
|
||||
int w_WheelJoint_setSpringDampingRatio(lua_State *L);
|
||||
int w_WheelJoint_getSpringDampingRatio(lua_State *L);
|
||||
extern "C" int luaopen_wheeljoint(lua_State *L);
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_WRAP_WHEEL_JOINT_H
|
||||
|
||||
@@ -1,214 +1,214 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#include "wrap_World.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
World *luax_checkworld(lua_State *L, int idx)
|
||||
{
|
||||
World *w = luax_checktype<World>(L, idx, "World", PHYSICS_WORLD_T);
|
||||
if (!w->isValid())
|
||||
luaL_error(L, "Attempt to use destroyed world.");
|
||||
return w;
|
||||
}
|
||||
|
||||
int w_World_update(lua_State *L)
|
||||
{
|
||||
World *t = luax_checkworld(L, 1);
|
||||
float dt = (float)luaL_checknumber(L, 2);
|
||||
t->update(dt);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_World_setCallbacks(lua_State *L)
|
||||
{
|
||||
World *t = luax_checkworld(L, 1);
|
||||
lua_remove(L, 1);
|
||||
return t->setCallbacks(L);
|
||||
}
|
||||
|
||||
int w_World_getCallbacks(lua_State *L)
|
||||
{
|
||||
World *t = luax_checkworld(L, 1);
|
||||
lua_remove(L, 1);
|
||||
return t->getCallbacks(L);
|
||||
}
|
||||
|
||||
int w_World_setContactFilter(lua_State *L)
|
||||
{
|
||||
World *t = luax_checkworld(L, 1);
|
||||
lua_remove(L, 1);
|
||||
return t->setContactFilter(L);
|
||||
}
|
||||
|
||||
int w_World_getContactFilter(lua_State *L)
|
||||
{
|
||||
World *t = luax_checkworld(L, 1);
|
||||
lua_remove(L, 1);
|
||||
return t->getContactFilter(L);
|
||||
}
|
||||
|
||||
int w_World_setGravity(lua_State *L)
|
||||
{
|
||||
World *t = luax_checkworld(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
float arg2 = (float)luaL_checknumber(L, 3);
|
||||
t->setGravity(arg1, arg2);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_World_getGravity(lua_State *L)
|
||||
{
|
||||
World *t = luax_checkworld(L, 1);
|
||||
lua_remove(L, 1);
|
||||
return t->getGravity(L);
|
||||
}
|
||||
|
||||
int w_World_setAllowSleeping(lua_State *L)
|
||||
{
|
||||
World *t = luax_checkworld(L, 1);
|
||||
bool b = luax_toboolean(L, 2);
|
||||
t->setAllowSleeping(b);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_World_getAllowSleeping(lua_State *L)
|
||||
{
|
||||
World *t = luax_checkworld(L, 1);
|
||||
luax_pushboolean(L, t->getAllowSleeping());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_World_isLocked(lua_State *L)
|
||||
{
|
||||
World *t = luax_checkworld(L, 1);
|
||||
luax_pushboolean(L, t->isLocked());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_World_getBodyCount(lua_State *L)
|
||||
{
|
||||
World *t = luax_checkworld(L, 1);
|
||||
lua_pushinteger(L, t->getBodyCount());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_World_getJointCount(lua_State *L)
|
||||
{
|
||||
World *t = luax_checkworld(L, 1);
|
||||
lua_pushinteger(L, t->getJointCount());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_World_getContactCount(lua_State *L)
|
||||
{
|
||||
World *t = luax_checkworld(L, 1);
|
||||
lua_pushinteger(L, t->getContactCount());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_World_getBodyList(lua_State *L)
|
||||
{
|
||||
World *t = luax_checkworld(L, 1);
|
||||
lua_remove(L, 1);
|
||||
return t->getBodyList(L);
|
||||
}
|
||||
|
||||
int w_World_getJointList(lua_State *L)
|
||||
{
|
||||
World *t = luax_checkworld(L, 1);
|
||||
lua_remove(L, 1);
|
||||
return t->getJointList(L);
|
||||
}
|
||||
|
||||
int w_World_getContactList(lua_State *L)
|
||||
{
|
||||
World *t = luax_checkworld(L, 1);
|
||||
lua_remove(L, 1);
|
||||
return t->getContactList(L);
|
||||
}
|
||||
|
||||
int w_World_queryBoundingBox(lua_State *L)
|
||||
{
|
||||
World *t = luax_checkworld(L, 1);
|
||||
lua_remove(L, 1);
|
||||
return t->queryBoundingBox(L);
|
||||
}
|
||||
|
||||
int w_World_rayCast(lua_State *L)
|
||||
{
|
||||
World *t = luax_checkworld(L, 1);
|
||||
lua_remove(L, 1);
|
||||
ASSERT_GUARD(return t->rayCast(L);)
|
||||
}
|
||||
|
||||
int w_World_destroy(lua_State *L)
|
||||
{
|
||||
World *t = luax_checkworld(L, 1);
|
||||
try
|
||||
{
|
||||
t->destroy();
|
||||
}
|
||||
catch(love::Exception &e)
|
||||
{
|
||||
luaL_error(L, "%s", e.what());
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static const luaL_Reg functions[] =
|
||||
{
|
||||
{ "update", w_World_update },
|
||||
{ "setCallbacks", w_World_setCallbacks },
|
||||
{ "getCallbacks", w_World_getCallbacks },
|
||||
{ "setContactFilter", w_World_setContactFilter },
|
||||
{ "getContactFilter", w_World_getContactFilter },
|
||||
{ "setGravity", w_World_setGravity },
|
||||
{ "getGravity", w_World_getGravity },
|
||||
{ "setAllowSleeping", w_World_setAllowSleeping },
|
||||
{ "getAllowSleeping", w_World_getAllowSleeping },
|
||||
{ "isLocked", w_World_isLocked },
|
||||
{ "getBodyCount", w_World_getBodyCount },
|
||||
{ "getJointCount", w_World_getJointCount },
|
||||
{ "getContactCount", w_World_getContactCount },
|
||||
{ "getBodyList", w_World_getBodyList },
|
||||
{ "getJointList", w_World_getJointList },
|
||||
{ "getContactList", w_World_getContactList },
|
||||
{ "queryBoundingBox", w_World_queryBoundingBox },
|
||||
{ "rayCast", w_World_rayCast },
|
||||
{ "destroy", w_World_destroy },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
extern "C" int luaopen_world(lua_State *L)
|
||||
{
|
||||
return luax_register_type(L, "World", functions);
|
||||
}
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#include "wrap_World.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
World *luax_checkworld(lua_State *L, int idx)
|
||||
{
|
||||
World *w = luax_checktype<World>(L, idx, "World", PHYSICS_WORLD_T);
|
||||
if (!w->isValid())
|
||||
luaL_error(L, "Attempt to use destroyed world.");
|
||||
return w;
|
||||
}
|
||||
|
||||
int w_World_update(lua_State *L)
|
||||
{
|
||||
World *t = luax_checkworld(L, 1);
|
||||
float dt = (float)luaL_checknumber(L, 2);
|
||||
t->update(dt);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_World_setCallbacks(lua_State *L)
|
||||
{
|
||||
World *t = luax_checkworld(L, 1);
|
||||
lua_remove(L, 1);
|
||||
return t->setCallbacks(L);
|
||||
}
|
||||
|
||||
int w_World_getCallbacks(lua_State *L)
|
||||
{
|
||||
World *t = luax_checkworld(L, 1);
|
||||
lua_remove(L, 1);
|
||||
return t->getCallbacks(L);
|
||||
}
|
||||
|
||||
int w_World_setContactFilter(lua_State *L)
|
||||
{
|
||||
World *t = luax_checkworld(L, 1);
|
||||
lua_remove(L, 1);
|
||||
return t->setContactFilter(L);
|
||||
}
|
||||
|
||||
int w_World_getContactFilter(lua_State *L)
|
||||
{
|
||||
World *t = luax_checkworld(L, 1);
|
||||
lua_remove(L, 1);
|
||||
return t->getContactFilter(L);
|
||||
}
|
||||
|
||||
int w_World_setGravity(lua_State *L)
|
||||
{
|
||||
World *t = luax_checkworld(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
float arg2 = (float)luaL_checknumber(L, 3);
|
||||
t->setGravity(arg1, arg2);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_World_getGravity(lua_State *L)
|
||||
{
|
||||
World *t = luax_checkworld(L, 1);
|
||||
lua_remove(L, 1);
|
||||
return t->getGravity(L);
|
||||
}
|
||||
|
||||
int w_World_setAllowSleeping(lua_State *L)
|
||||
{
|
||||
World *t = luax_checkworld(L, 1);
|
||||
bool b = luax_toboolean(L, 2);
|
||||
t->setAllowSleeping(b);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_World_getAllowSleeping(lua_State *L)
|
||||
{
|
||||
World *t = luax_checkworld(L, 1);
|
||||
luax_pushboolean(L, t->getAllowSleeping());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_World_isLocked(lua_State *L)
|
||||
{
|
||||
World *t = luax_checkworld(L, 1);
|
||||
luax_pushboolean(L, t->isLocked());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_World_getBodyCount(lua_State *L)
|
||||
{
|
||||
World *t = luax_checkworld(L, 1);
|
||||
lua_pushinteger(L, t->getBodyCount());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_World_getJointCount(lua_State *L)
|
||||
{
|
||||
World *t = luax_checkworld(L, 1);
|
||||
lua_pushinteger(L, t->getJointCount());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_World_getContactCount(lua_State *L)
|
||||
{
|
||||
World *t = luax_checkworld(L, 1);
|
||||
lua_pushinteger(L, t->getContactCount());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_World_getBodyList(lua_State *L)
|
||||
{
|
||||
World *t = luax_checkworld(L, 1);
|
||||
lua_remove(L, 1);
|
||||
return t->getBodyList(L);
|
||||
}
|
||||
|
||||
int w_World_getJointList(lua_State *L)
|
||||
{
|
||||
World *t = luax_checkworld(L, 1);
|
||||
lua_remove(L, 1);
|
||||
return t->getJointList(L);
|
||||
}
|
||||
|
||||
int w_World_getContactList(lua_State *L)
|
||||
{
|
||||
World *t = luax_checkworld(L, 1);
|
||||
lua_remove(L, 1);
|
||||
return t->getContactList(L);
|
||||
}
|
||||
|
||||
int w_World_queryBoundingBox(lua_State *L)
|
||||
{
|
||||
World *t = luax_checkworld(L, 1);
|
||||
lua_remove(L, 1);
|
||||
return t->queryBoundingBox(L);
|
||||
}
|
||||
|
||||
int w_World_rayCast(lua_State *L)
|
||||
{
|
||||
World *t = luax_checkworld(L, 1);
|
||||
lua_remove(L, 1);
|
||||
ASSERT_GUARD(return t->rayCast(L);)
|
||||
}
|
||||
|
||||
int w_World_destroy(lua_State *L)
|
||||
{
|
||||
World *t = luax_checkworld(L, 1);
|
||||
try
|
||||
{
|
||||
t->destroy();
|
||||
}
|
||||
catch(love::Exception &e)
|
||||
{
|
||||
luaL_error(L, "%s", e.what());
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static const luaL_Reg functions[] =
|
||||
{
|
||||
{ "update", w_World_update },
|
||||
{ "setCallbacks", w_World_setCallbacks },
|
||||
{ "getCallbacks", w_World_getCallbacks },
|
||||
{ "setContactFilter", w_World_setContactFilter },
|
||||
{ "getContactFilter", w_World_getContactFilter },
|
||||
{ "setGravity", w_World_setGravity },
|
||||
{ "getGravity", w_World_getGravity },
|
||||
{ "setAllowSleeping", w_World_setAllowSleeping },
|
||||
{ "getAllowSleeping", w_World_getAllowSleeping },
|
||||
{ "isLocked", w_World_isLocked },
|
||||
{ "getBodyCount", w_World_getBodyCount },
|
||||
{ "getJointCount", w_World_getJointCount },
|
||||
{ "getContactCount", w_World_getContactCount },
|
||||
{ "getBodyList", w_World_getBodyList },
|
||||
{ "getJointList", w_World_getJointList },
|
||||
{ "getContactList", w_World_getContactList },
|
||||
{ "queryBoundingBox", w_World_queryBoundingBox },
|
||||
{ "rayCast", w_World_rayCast },
|
||||
{ "destroy", w_World_destroy },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
extern "C" int luaopen_world(lua_State *L)
|
||||
{
|
||||
return luax_register_type(L, "World", functions);
|
||||
}
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
@@ -1,63 +1,63 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_PHYSICS_BOX2D_WRAP_WORLD_H
|
||||
#define LOVE_PHYSICS_BOX2D_WRAP_WORLD_H
|
||||
|
||||
// LOVE
|
||||
#include "common/runtime.h"
|
||||
#include "common/Exception.h"
|
||||
#include "World.h"
|
||||
#include "wrap_Physics.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
World *luax_checkworld(lua_State *L, int idx);
|
||||
int w_World_update(lua_State *L);
|
||||
int w_World_setCallbacks(lua_State *L);
|
||||
int w_World_getCallbacks(lua_State *L);
|
||||
int w_World_setContactFilter(lua_State *L);
|
||||
int w_World_getContactFilter(lua_State *L);
|
||||
int w_World_setGravity(lua_State *L);
|
||||
int w_World_getGravity(lua_State *L);
|
||||
int w_World_setAllowSleeping(lua_State *L);
|
||||
int w_World_getAllowSleeping(lua_State *L);
|
||||
int w_World_isLocked(lua_State *L);
|
||||
int w_World_getBodyCount(lua_State *L);
|
||||
int w_World_getJointCount(lua_State *L);
|
||||
int w_World_getContactCount(lua_State *L);
|
||||
int w_World_getBodyList(lua_State *L);
|
||||
int w_World_getJointList(lua_State *L);
|
||||
int w_World_getContactList(lua_State *L);
|
||||
int w_World_queryBoundingBox(lua_State *L);
|
||||
int w_World_rayCast(lua_State *L);
|
||||
int w_World_destroy(lua_State *L);
|
||||
extern "C" int luaopen_world(lua_State *L);
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_WRAP_WORLD_H
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_PHYSICS_BOX2D_WRAP_WORLD_H
|
||||
#define LOVE_PHYSICS_BOX2D_WRAP_WORLD_H
|
||||
|
||||
// LOVE
|
||||
#include "common/runtime.h"
|
||||
#include "common/Exception.h"
|
||||
#include "World.h"
|
||||
#include "wrap_Physics.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
World *luax_checkworld(lua_State *L, int idx);
|
||||
int w_World_update(lua_State *L);
|
||||
int w_World_setCallbacks(lua_State *L);
|
||||
int w_World_getCallbacks(lua_State *L);
|
||||
int w_World_setContactFilter(lua_State *L);
|
||||
int w_World_getContactFilter(lua_State *L);
|
||||
int w_World_setGravity(lua_State *L);
|
||||
int w_World_getGravity(lua_State *L);
|
||||
int w_World_setAllowSleeping(lua_State *L);
|
||||
int w_World_getAllowSleeping(lua_State *L);
|
||||
int w_World_isLocked(lua_State *L);
|
||||
int w_World_getBodyCount(lua_State *L);
|
||||
int w_World_getJointCount(lua_State *L);
|
||||
int w_World_getContactCount(lua_State *L);
|
||||
int w_World_getBodyList(lua_State *L);
|
||||
int w_World_getJointList(lua_State *L);
|
||||
int w_World_getContactList(lua_State *L);
|
||||
int w_World_queryBoundingBox(lua_State *L);
|
||||
int w_World_rayCast(lua_State *L);
|
||||
int w_World_destroy(lua_State *L);
|
||||
extern "C" int luaopen_world(lua_State *L);
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_WRAP_WORLD_H
|
||||
|
||||
Reference in New Issue
Block a user