Update Body API.

--HG--
branch : box2d-update
This commit is contained in:
Bill Meltsner
2011-09-23 22:21:14 -04:00
parent 0678eac453
commit 367dbc2ecc
14 changed files with 416 additions and 195 deletions
@@ -140,6 +140,7 @@
A946D85610425002002BF36C /* Timer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A93E6B8F10420ACC007D418B /* Timer.cpp */; };
A95684F7125D3555001B276B /* b64.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A95684F5125D3555001B276B /* b64.cpp */; };
A958F911142D364C007F320F /* wrap_Fixture.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A958F910142D3627007F320F /* wrap_Fixture.cpp */; };
A958F917142D6B3A007F320F /* Body.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A958F916142D6B37007F320F /* Body.cpp */; };
A968F0CF1083A9A900A895AA /* Event.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A968F0CE1083A9A900A895AA /* Event.cpp */; };
A968F0D11083A9B900A895AA /* File.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A968F0D01083A9B900A895AA /* File.cpp */; };
A968F0D31083A9D400A895AA /* Graphics.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A968F0D21083A9D400A895AA /* Graphics.cpp */; };
@@ -538,6 +539,8 @@
A95684F6125D3555001B276B /* b64.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b64.h; sourceTree = "<group>"; };
A958F910142D3627007F320F /* wrap_Fixture.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = wrap_Fixture.cpp; sourceTree = "<group>"; };
A958F912142D3687007F320F /* wrap_Fixture.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = wrap_Fixture.h; sourceTree = "<group>"; };
A958F916142D6B37007F320F /* Body.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Body.cpp; sourceTree = "<group>"; };
A958F918142D6B60007F320F /* Body.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Body.h; sourceTree = "<group>"; };
A968F0C61083A07B00A895AA /* EnumMap.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EnumMap.h; sourceTree = "<group>"; };
A968F0C71083A07C00A895AA /* StringMap.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StringMap.h; sourceTree = "<group>"; };
A968F0CE1083A9A900A895AA /* Event.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Event.cpp; sourceTree = "<group>"; };
@@ -1195,6 +1198,8 @@
A93E6AE910420AC7007D418B /* physics */ = {
isa = PBXGroup;
children = (
A958F916142D6B37007F320F /* Body.cpp */,
A958F918142D6B60007F320F /* Body.h */,
A93E6AEA10420AC7007D418B /* box2d */,
A968F0DC1083AA6600A895AA /* Joint.cpp */,
A93E6B6C10420ACB007D418B /* Joint.h */,
@@ -1828,6 +1833,7 @@
A9D1D20A1422959100A8BC2F /* ChainShape.cpp in Sources */,
A9D1D20D14229B6500A8BC2F /* wrap_ChainShape.cpp in Sources */,
A958F911142D364C007F320F /* wrap_Fixture.cpp in Sources */,
A958F917142D6B3A007F320F /* Body.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
+51
View File
@@ -0,0 +1,51 @@
/**
* Copyright (c) 2006-2011 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
+59
View File
@@ -0,0 +1,59 @@
/**
* Copyright (c) 2006-2011 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
+110 -51
View File
@@ -22,6 +22,8 @@
#include <common/math.h>
#include "Shape.h"
#include "Fixture.h"
#include "World.h"
#include "Physics.h"
@@ -31,14 +33,12 @@ namespace physics
{
namespace box2d
{
Body::Body(World * world, b2Vec2 p, float m, float i)
Body::Body(World * world, b2Vec2 p)
: world(world)
{
world->retain();
b2BodyDef def;
def.position = Physics::scaleDown(p);
def.massData.mass = m;
def.massData.I = i;
body = world->world->CreateBody(&def);
}
@@ -106,25 +106,65 @@ namespace box2d
{
return 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, data.I);
return 4;
}
float Body::getAngularDamping() const
{
return body->m_angularDamping;
return body->GetAngularDamping();
}
float Body::getLinearDamping() const
{
return body->m_linearDamping;
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::applyImpulse(float jx, float jy)
void Body::applyLinearImpulse(float jx, float jy)
{
body->ApplyImpulse(b2Vec2(jx, jy), body->GetWorldCenter());
body->ApplyLinearImpulse(Physics::scaleDown(b2Vec2(jx, jy)), body->GetWorldCenter());
}
void Body::applyImpulse(float jx, float jy, float rx, float ry)
void Body::applyLinearImpulse(float jx, float jy, float rx, float ry)
{
body->ApplyImpulse(b2Vec2(jx, jy), Physics::scaleDown(b2Vec2(rx, ry)));
body->ApplyLinearImpulse(Physics::scaleDown(b2Vec2(jx, jy)), Physics::scaleDown(b2Vec2(rx, ry)));
}
void Body::applyAngularImpulse(float impulse)
{
body->ApplyAngularImpulse(Physics::scaleDown(impulse));
}
void Body::applyTorque(float t)
@@ -144,12 +184,12 @@ namespace box2d
void Body::setX(float x)
{
body->SetXForm(Physics::scaleDown(b2Vec2(x, getY())), getAngle());
body->SetTransform(Physics::scaleDown(b2Vec2(x, getY())), getAngle());
}
void Body::setY(float y)
{
body->SetXForm(Physics::scaleDown(b2Vec2(getX(), y)), getAngle());
body->SetTransform(Physics::scaleDown(b2Vec2(getX(), y)), getAngle());
}
void Body::setLinearVelocity(float x, float y)
@@ -159,7 +199,7 @@ namespace box2d
void Body::setAngle(float d)
{
body->SetXForm(body->GetPosition(), d);
body->SetTransform(body->GetPosition(), d);
}
void Body::setAngularVelocity(float r)
@@ -169,31 +209,31 @@ namespace box2d
void Body::setPosition(float x, float y)
{
body->SetXForm(Physics::scaleDown(b2Vec2(x, y)), body->GetAngle());
body->SetTransform(Physics::scaleDown(b2Vec2(x, y)), body->GetAngle());
}
void Body::setAngularDamping(float d)
{
body->m_angularDamping = d;
body->SetAngularDamping(d);
}
void Body::setLinearDamping(float d)
{
body->m_linearDamping = d;
body->SetLinearDamping(d);
}
void Body::setMassFromShapes()
void Body::resetMassData()
{
body->SetMassFromShapes();
body->ResetMassData();
}
void Body::setMass(float x, float y, float m, float i)
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 = i;
body->SetMass(&massData);
body->SetMassData(&massData);
}
void Body::setInertia(float i)
@@ -202,7 +242,29 @@ namespace box2d
massData.center = body->GetLocalCenter();
massData.mass = body->GetMass();
massData.I = i;
body->SetMass(&massData);
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)
@@ -257,63 +319,60 @@ namespace box2d
return body->SetBullet(bullet);
}
bool Body::isStatic() const
bool Body::isActive() const
{
return body->IsStatic();
return body->IsActive();
}
bool Body::isDynamic() const
bool Body::isAwake() const
{
return body->IsDynamic();
return body->IsAwake();
}
bool Body::isFrozen() const
void Body::setSleepingAllowed(bool allow)
{
return body->IsFrozen();
body->SetSleepingAllowed(allow);
}
bool Body::isSleeping() const
bool Body::isSleepingAllowed() const
{
return body->IsSleeping();
return body->IsSleepingAllowed();
}
void Body::setActive(bool active)
{
body->SetActive(active);
}
void Body::setAllowSleeping(bool allow)
void Body::setAwake(bool awake)
{
body->AllowSleeping(allow);
}
bool Body::getAllowSleeping()
{
return (body->m_flags & b2Body::e_allowSleepFlag) != 0;
}
void Body::putToSleep()
{
body->PutToSleep();
}
void Body::wakeUp()
{
body->WakeUp();
body->SetAwake(awake);
}
void Body::setFixedRotation(bool fixed)
{
if(fixed)
body->m_flags |= b2Body::e_fixedRotationFlag;
else
body->m_flags &= ~(b2Body::e_fixedRotationFlag);
body->SetFixedRotation(fixed);
}
bool Body::getFixedRotation() const
bool Body::isFixedRotation() const
{
return (body->m_flags & b2Body::e_fixedRotationFlag) != 0;
return body->IsFixedRotation();
}
World * Body::getWorld() const
{
return world;
}
Fixture * Body::createFixture(Shape * shape)
{
return new Fixture(this, shape);
}
void Body::destroyFixture(Fixture * fixture)
{
fixture->release();
}
b2Vec2 Body::getVector(lua_State * L)
{
+58 -33
View File
@@ -25,7 +25,7 @@
#include <common/math.h>
#include <common/runtime.h>
#include <common/Object.h>
#include <physics/Body.h>
// Box2D
#include <Box2D/Box2D.h>
@@ -38,6 +38,8 @@ namespace box2d
{
// Forward declarations.
class World;
class Shape;
class Fixture;
/**
* A Body is an entity which has position and orientation
@@ -45,7 +47,7 @@ namespace box2d
* by itself, but depend on an arbitrary number of child Shape objects
* which together constitute the final geometry for the Body.
**/
class Body : public Object
class Body : public love::physics::Body
{
// Friends.
friend class Joint;
@@ -73,7 +75,7 @@ namespace box2d
/**
* Create a Body at position p.
**/
Body(World * world, b2Vec2 p, float m, float i);
Body(World * world, b2Vec2 p);
virtual ~Body();
@@ -134,6 +136,11 @@ namespace box2d
* Gets the Body's intertia.
**/
float getInertia() const;
/**
* Gets mass properties.
**/
int getMassData(lua_State * L);
/**
* Gets the Body's angular damping.
@@ -144,16 +151,31 @@ namespace box2d
* 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 applyImpulse(float jx, float jy);
void applyLinearImpulse(float jx, float jy);
/**
* Apply an impulse (jx, jy) with offset (rx, ry).
**/
void applyImpulse(float jx, float jy, float rx, float 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).
@@ -203,7 +225,7 @@ namespace box2d
/**
* Sets the mass from the currently attatched shapes.
**/
void setMassFromShapes();
void resetMassData();
/**
* Sets mass properties.
@@ -212,7 +234,7 @@ namespace box2d
* @param m The mass.
* @param i The inertia.
**/
void setMass(float x, float y, float m, float i);
void setMassData(float x, float y, float m, float i);
/**
* Sets the inertia while keeping the other properties
@@ -230,6 +252,16 @@ namespace box2d
* 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
@@ -301,51 +333,44 @@ namespace box2d
void setBullet(bool bullet);
/**
* Checks whether a Body is static or not, i.e. terrain
* or not.
* Checks whether a Body is active or not. An inactive body
* cannot be interacted with.
**/
bool isStatic() const;
bool isActive() const;
/**
* The opposite of isStatic.
**/
bool isDynamic() const;
/**
* Checks whether a Body is frozen or not.
* A Body will freeze if hits the world bounding box.
**/
bool isFrozen() const;
/**
* Checks whether a Body is sleeping or nor. A Body
* Checks whether a Body is awake or not. A Body
* will fall to sleep if nothing happens to it for while.
**/
bool isSleeping() const;
bool isAwake() const;
/**
* Controls whether this Body should be allowed to sleep.
**/
void setAllowSleeping(bool allow);
bool getAllowSleeping();
void setSleepingAllowed(bool allow);
bool isSleepingAllowed() const;
/**
* Changes the body's active state.
**/
void setActive(bool active);
/**
* Puts the body to sleep.
* Changes the body's sleep state.
**/
void putToSleep();
/**
* Wakes the Body up.
**/
void wakeUp();
void setAwake(bool awake);
void setFixedRotation(bool fixed);
bool getFixedRotation() const;
bool isFixedRotation() const;
/**
* Get the World this Body resides in.
*/
World * getWorld() const;
Fixture * createFixture(Shape * shape);
void destroyFixture(Fixture * fixture);
private:
/**
-7
View File
@@ -101,13 +101,6 @@ namespace box2d
**/
Body * getBody() const;
/**
* Gets the next Fixture attached to the parent Body.
**/
Fixture * getNext() const;
/**
* Sets the filter data. An integer array is used even though the
* first two elements are unsigned shorts. The elements are:
+2 -12
View File
@@ -45,26 +45,16 @@ namespace box2d
return new World(b2Vec2(gx, gy), sleep);
}
Body * Physics::newBody(World * world, float x, float y, float mass, float i)
{
return new Body(world, b2Vec2(x, y), mass, i);
}
Body * Physics::newBody(World * world, float x, float y)
{
return new Body(world, b2Vec2(x, y), 1, 1);
return new Body(world, b2Vec2(x, y));
}
Body * Physics::newBody(World * world)
{
return new Body(world, b2Vec2(0, 0), 1, 1);
return new Body(world, b2Vec2(0, 0));
}
Fixture * Physics::newFixture(Body * body, Shape * shape)
{
return new Fixture(body, shape);
}
CircleShape * Physics::newCircleShape(float radius)
{
return newCircleShape(0, 0, radius);
-17
View File
@@ -76,16 +76,6 @@ namespace box2d
**/
World * newWorld(float gx, float gy, bool sleep, int meter);
/**
* 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 m The mass.
* @param i The rotational inertia.
**/
Body * newBody(World * world, float x, float y, float m, float i);
/**
* Creates a new Body at the specified position.
* @param world The world to create the Body in.
@@ -99,13 +89,6 @@ namespace box2d
* @param world The world to create the Body in.
**/
Body * newBody(World * world);
/**
* Creates a new Fixture.
* @param body The body to attach the Fixture to.
* @param shape The shape to attach to the Fixture.
**/
Fixture * newFixture(Body * body, Shape * shape);
/**
* Creates a new CircleShape at (0, 0).
+2 -1
View File
@@ -162,8 +162,9 @@ namespace box2d
end.add(contact);
}
void World::PreSolve(b2Contact* contact)
void World::PreSolve(b2Contact* contact, const b2Manifold* oldManifold)
{
B2_NOT_USED(oldManifold); // not sure what to do with this
presolve.add(contact);
}
+1 -1
View File
@@ -117,7 +117,7 @@ namespace box2d
// From b2ContactListener
void BeginContact(b2Contact* contact);
void EndContact(b2Contact* contact);
void PreSolve(b2Contact* contact);
void PreSolve(b2Contact* contact, const b2Manifold* oldManifold);
void PostSolve(b2Contact* contact, const b2ContactImpulse* impulse);
/**
+107 -47
View File
@@ -120,6 +120,13 @@ namespace box2d
lua_pushnumber(L, t->getInertia());
return 1;
}
int w_Body_getMassData(lua_State * L)
{
Body * t = luax_checkbody(L, 1);
lua_remove(L, 1);
return t->getMassData(L);
}
int w_Body_getAngularDamping(lua_State * L)
{
@@ -134,8 +141,24 @@ namespace box2d
lua_pushnumber(L, t->getLinearDamping());
return 1;
}
int w_Body_getGravityScale(lua_State * L)
{
Body * t = luax_checkbody(L, 1);
lua_pushnumber(L, t->getGravityScale());
return 1;
}
int w_Body_getType(lua_State * L)
{
Body * t = luax_checkbody(L, 1);
const char * type = "";
Body::getConstant(t->getType(), type);
lua_pushstring(L, type);
return 1;
}
int w_Body_applyImpulse(lua_State * L)
int w_Body_applyLinearImpulse(lua_State * L)
{
Body * t = luax_checkbody(L, 1);
float jx = (float)luaL_checknumber(L, 2);
@@ -143,13 +166,13 @@ namespace box2d
if(lua_gettop(L) == 3)
{
t->applyImpulse(jx, jy);
t->applyLinearImpulse(jx, jy);
}
else if(lua_gettop(L) == 5)
{
float rx = (float)luaL_checknumber(L, 4);
float ry = (float)luaL_checknumber(L, 5);
t->applyImpulse(jx, jy, rx, ry);
t->applyLinearImpulse(jx, jy, rx, ry);
}
else
{
@@ -158,6 +181,14 @@ namespace box2d
return 0;
}
int w_Body_applyAngularImpulse(lua_State * L)
{
Body * t = luax_checkbody(L, 1);
float i = (float)luaL_checknumber(L, 2);
t->applyAngularImpulse(i);
return 0;
}
int w_Body_applyTorque(lua_State * L)
{
@@ -242,21 +273,21 @@ namespace box2d
return 0;
}
int w_Body_setMassFromShapes(lua_State * L)
int w_Body_resetMassData(lua_State * L)
{
Body * t = luax_checkbody(L, 1);
t->setMassFromShapes();
t->resetMassData();
return 0;
}
int w_Body_setMass(lua_State * L)
int w_Body_setMassData(lua_State * L)
{
Body * t = luax_checkbody(L, 1);
float x = (float)luaL_checknumber(L, 2);
float y = (float)luaL_checknumber(L, 3);
float m = (float)luaL_checknumber(L, 4);
float i = (float)luaL_checknumber(L, 5);
t->setMass(x, y, m, i);
t->setMassData(x, y, m, i);
return 0;
}
@@ -283,6 +314,24 @@ namespace box2d
t->setLinearDamping(arg1);
return 0;
}
int w_Body_setGravityScale(lua_State * L)
{
Body * t = luax_checkbody(L, 1);
float arg1 = (float)luaL_checknumber(L, 2);
t->setGravityScale(arg1);
return 0;
}
int w_Body_setType(lua_State * L)
{
Body * t = luax_checkbody(L, 1);
const char * typeStr = luaL_checkstring(L, 2);
Body::Type type;
Body::getConstant(typeStr, type);
t->setType(type);
return 0;
}
int w_Body_getWorldPoint(lua_State * L)
{
@@ -383,60 +432,48 @@ namespace box2d
return 0;
}
int w_Body_isStatic(lua_State * L)
int w_Body_isActive(lua_State * L)
{
Body * t = luax_checkbody(L, 1);
luax_pushboolean(L, t->isStatic());
luax_pushboolean(L, t->isActive());
return 1;
}
int w_Body_isDynamic(lua_State * L)
int w_Body_isAwake(lua_State * L)
{
Body * t = luax_checkbody(L, 1);
luax_pushboolean(L, t->isDynamic());
luax_pushboolean(L, t->isAwake());
return 1;
}
int w_Body_isFrozen(lua_State * L)
{
Body * t = luax_checkbody(L, 1);
luax_pushboolean(L, t->isFrozen());
return 1;
}
int w_Body_isSleeping(lua_State * L)
{
Body * t = luax_checkbody(L, 1);
luax_pushboolean(L, t->isSleeping());
return 1;
}
int w_Body_setAllowSleeping(lua_State * L)
int w_Body_setSleepingAllowed(lua_State * L)
{
Body * t = luax_checkbody(L, 1);
bool b = luax_toboolean(L, 2);
t->setAllowSleeping(b);
t->setSleepingAllowed(b);
return 0;
}
int w_Body_getAllowSleeping(lua_State * L)
int w_Body_isSleepingAllowed(lua_State * L)
{
Body * t = luax_checkbody(L, 1);
lua_pushboolean(L, t->getAllowSleeping());
lua_pushboolean(L, t->isSleepingAllowed());
return 1;
}
int w_Body_putToSleep(lua_State * L)
int w_Body_setActive(lua_State * L)
{
Body * t = luax_checkbody(L, 1);
t->putToSleep();
bool b = luax_toboolean(L, 2);
t->setActive(b);
return 0;
}
int w_Body_wakeUp(lua_State * L)
int w_Body_setAwake(lua_State * L)
{
Body * t = luax_checkbody(L, 1);
t->wakeUp();
bool b = luax_toboolean(L, 2);
t->setAwake(b);
return 0;
}
@@ -448,13 +485,30 @@ namespace box2d
return 0;
}
int w_Body_getFixedRotation(lua_State * L)
int w_Body_isFixedRotation(lua_State * L)
{
Body * t = luax_checkbody(L, 1);
bool b = t->getFixedRotation();
bool b = t->isFixedRotation();
luax_pushboolean(L, b);
return 1;
}
int w_Body_createFixture(lua_State * L)
{
Body * t = luax_checkbody(L, 1);
Shape * s = luax_checktype<Shape>(L, 2, "Shape", PHYSICS_SHAPE_T);
Fixture * f = t->createFixture(s);
luax_newtype(L, "Fixture", PHYSICS_FIXTURE_T, (void*)f);
return 1;
}
int w_Body_destroyFixture(lua_State * L)
{
Body * t = luax_checkbody(L, 1);
Fixture * f = luax_checktype<Fixture>(L, 2, "Fixture", PHYSICS_FIXTURE_T);
t->destroyFixture(f);
return 0;
}
int w_Body_destroy(lua_State * L)
{
@@ -478,9 +532,13 @@ namespace box2d
{ "getAngularVelocity", w_Body_getAngularVelocity },
{ "getMass", w_Body_getMass },
{ "getInertia", w_Body_getInertia },
{ "getMassData", w_Body_getMassData },
{ "getAngularDamping", w_Body_getAngularDamping },
{ "getLinearDamping", w_Body_getLinearDamping },
{ "applyImpulse", w_Body_applyImpulse },
{ "getGravityScale", w_Body_getGravityScale },
{ "getType", w_Body_getType },
{ "applyLinearImpulse", w_Body_applyLinearImpulse },
{ "applyAngularImpulse", w_Body_applyAngularImpulse },
{ "applyTorque", w_Body_applyTorque },
{ "applyForce", w_Body_applyForce },
{ "setX", w_Body_setX },
@@ -489,11 +547,13 @@ namespace box2d
{ "setAngle", w_Body_setAngle },
{ "setAngularVelocity", w_Body_setAngularVelocity },
{ "setPosition", w_Body_setPosition },
{ "setMassFromShapes", w_Body_setMassFromShapes },
{ "setMass", w_Body_setMass },
{ "resetMassData", w_Body_resetMassData },
{ "setMassData", w_Body_setMassData },
{ "setInertia", w_Body_setInertia },
{ "setAngularDamping", w_Body_setAngularDamping },
{ "setLinearDamping", w_Body_setLinearDamping },
{ "setGravityScale", w_Body_setGravityScale },
{ "setType", w_Body_setType },
{ "getWorldPoint", w_Body_getWorldPoint },
{ "getWorldVector", w_Body_getWorldVector },
{ "getLocalPoint", w_Body_getLocalPoint },
@@ -502,16 +562,16 @@ namespace box2d
{ "getLinearVelocityFromLocalPoint", w_Body_getLinearVelocityFromLocalPoint },
{ "isBullet", w_Body_isBullet },
{ "setBullet", w_Body_setBullet },
{ "isStatic", w_Body_isStatic },
{ "isDynamic", w_Body_isDynamic },
{ "isFrozen", w_Body_isFrozen },
{ "isSleeping", w_Body_isSleeping },
{ "setAllowSleeping", w_Body_setAllowSleeping },
{ "getAllowSleeping", w_Body_getAllowSleeping },
{ "putToSleep", w_Body_putToSleep },
{ "wakeUp", w_Body_wakeUp },
{ "isActive", w_Body_isActive },
{ "isAwake", w_Body_isAwake },
{ "setSleepingAllowed", w_Body_setSleepingAllowed },
{ "isSleepingAllowde", w_Body_isSleepingAllowed },
{ "setActive", w_Body_setActive },
{ "setAwake", w_Body_setAwake },
{ "setFixedRotation", w_Body_setFixedRotation },
{ "getFixedRotation", w_Body_getFixedRotation },
{ "isFixedRotation", w_Body_isFixedRotation },
{ "createFixture", w_Body_createFixture },
{ "destroyFixture", w_Body_destroyFixture },
{ "destroy", w_Body_destroy },
{ 0, 0 }
};
+19 -13
View File
@@ -43,22 +43,28 @@ namespace box2d
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_applyImpulse(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_setVelocity(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_setMassFromShapes(lua_State * L);
int w_Body_setMass(lua_State * L);
int w_Body_resetMassData(lua_State * L);
int w_Body_setMassData(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_getLocalPoint(lua_State * L);
@@ -67,16 +73,16 @@ namespace box2d
int w_Body_getLinearVelocityFromLocalPoint(lua_State * L);
int w_Body_isBullet(lua_State * L);
int w_Body_setBullet(lua_State * L);
int w_Body_isStatic(lua_State * L);
int w_Body_isDynamic(lua_State * L);
int w_Body_isFrozen(lua_State * L);
int w_Body_isSleeping(lua_State * L);
int w_Body_setAllowSleeping(lua_State * L);
int w_Body_getAllowSleeping(lua_State * L);
int w_Body_putToSleep(lua_State * L);
int w_Body_wakeUp(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_getFixedRotation(lua_State * L);
int w_Body_isFixedRotation(lua_State * L);
int w_Body_createFixture(lua_State * L);
int w_Body_destroyFixture(lua_State * L);
int w_Body_destroy(lua_State * L);
int luaopen_body(lua_State * L);
+1 -12
View File
@@ -47,21 +47,10 @@ namespace box2d
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);
float m = (float)luaL_optnumber(L, 4, 0.0);
float i = (float)luaL_optnumber(L, 5, 0.0);
Body * body = instance->newBody(world, x, y, m, i);
Body * body = instance->newBody(world, x, y);
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);
Fixture * fixture = instance->newFixture(body, shape);
luax_newtype(L, "Fixture", PHYSICS_FIXTURE_T, (void*)fixture);
return 1;
}
int w_newCircleShape(lua_State * L)
{
-1
View File
@@ -52,7 +52,6 @@ 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);