mirror of
https://github.com/love2d/love.git
synced 2026-08-16 16:20:42 +02:00
Updated box2d from 2.2.1 to 2.3.0
--HG-- branch : box2d-2.3
This commit is contained in:
@@ -168,36 +168,36 @@ Body::Type Body::getType() const
|
||||
}
|
||||
}
|
||||
|
||||
void Body::applyLinearImpulse(float jx, float jy)
|
||||
void Body::applyLinearImpulse(float jx, float jy, bool wake)
|
||||
{
|
||||
body->ApplyLinearImpulse(Physics::scaleDown(b2Vec2(jx, jy)), body->GetWorldCenter());
|
||||
body->ApplyLinearImpulse(Physics::scaleDown(b2Vec2(jx, jy)), body->GetWorldCenter(), wake);
|
||||
}
|
||||
|
||||
void Body::applyLinearImpulse(float jx, float jy, float rx, float ry)
|
||||
void Body::applyLinearImpulse(float jx, float jy, float rx, float ry, bool wake)
|
||||
{
|
||||
body->ApplyLinearImpulse(Physics::scaleDown(b2Vec2(jx, jy)), Physics::scaleDown(b2Vec2(rx, ry)));
|
||||
body->ApplyLinearImpulse(Physics::scaleDown(b2Vec2(jx, jy)), Physics::scaleDown(b2Vec2(rx, ry)), wake);
|
||||
}
|
||||
|
||||
void Body::applyAngularImpulse(float impulse)
|
||||
void Body::applyAngularImpulse(float impulse, bool wake)
|
||||
{
|
||||
// Angular impulse is in kg*m^2/s, meaning it needs to be scaled twice
|
||||
body->ApplyAngularImpulse(Physics::scaleDown(Physics::scaleDown(impulse)));
|
||||
body->ApplyAngularImpulse(Physics::scaleDown(Physics::scaleDown(impulse)), wake);
|
||||
}
|
||||
|
||||
void Body::applyTorque(float t)
|
||||
void Body::applyTorque(float t, bool wake)
|
||||
{
|
||||
// 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)));
|
||||
body->ApplyTorque(Physics::scaleDown(Physics::scaleDown(t)), wake);
|
||||
}
|
||||
|
||||
void Body::applyForce(float fx, float fy, float rx, float ry)
|
||||
void Body::applyForce(float fx, float fy, float rx, float ry, bool wake)
|
||||
{
|
||||
body->ApplyForce(Physics::scaleDown(b2Vec2(fx, fy)), Physics::scaleDown(b2Vec2(rx, ry)));
|
||||
body->ApplyForce(Physics::scaleDown(b2Vec2(fx, fy)), Physics::scaleDown(b2Vec2(rx, ry)), wake);
|
||||
}
|
||||
|
||||
void Body::applyForce(float fx, float fy)
|
||||
void Body::applyForce(float fx, float fy, bool wake)
|
||||
{
|
||||
body->ApplyForceToCenter(Physics::scaleDown(b2Vec2(fx, fy)));
|
||||
body->ApplyForceToCenter(Physics::scaleDown(b2Vec2(fx, fy)), wake);
|
||||
}
|
||||
|
||||
void Body::setX(float x)
|
||||
|
||||
@@ -162,32 +162,32 @@ public:
|
||||
/**
|
||||
* Apply an impulse (jx, jy) with offset (0, 0).
|
||||
**/
|
||||
void applyLinearImpulse(float jx, float jy);
|
||||
void applyLinearImpulse(float jx, float jy, bool wake);
|
||||
|
||||
/**
|
||||
* Apply an impulse (jx, jy) with offset (rx, ry).
|
||||
**/
|
||||
void applyLinearImpulse(float jx, float jy, float rx, float ry);
|
||||
void applyLinearImpulse(float jx, float jy, float rx, float ry, bool wake);
|
||||
|
||||
/**
|
||||
* Apply an angular impulse to the body.
|
||||
**/
|
||||
void applyAngularImpulse(float impulse);
|
||||
void applyAngularImpulse(float impulse, bool wake);
|
||||
|
||||
/**
|
||||
* Apply torque (t).
|
||||
**/
|
||||
void applyTorque(float t);
|
||||
void applyTorque(float t, bool wake);
|
||||
|
||||
/**
|
||||
* Apply force (fx, fy) with offset (0, 0).
|
||||
**/
|
||||
void applyForce(float fx, float fy);
|
||||
void applyForce(float fx, float fy, bool wake);
|
||||
|
||||
/**
|
||||
* Apply force (fx, fy) with offset (rx, ry).
|
||||
**/
|
||||
void applyForce(float fx, float fy, float rx, float ry);
|
||||
void applyForce(float fx, float fy, float rx, float ry, bool wake);
|
||||
|
||||
/**
|
||||
* Sets the x-position of the Body.
|
||||
|
||||
@@ -126,6 +126,16 @@ void Contact::resetRestitution()
|
||||
contact->ResetRestitution();
|
||||
}
|
||||
|
||||
void Contact::setTangentSpeed(float speed)
|
||||
{
|
||||
contact->SetTangentSpeed(speed);
|
||||
}
|
||||
|
||||
float Contact::getTangentSpeed() const
|
||||
{
|
||||
return contact->GetTangentSpeed();
|
||||
}
|
||||
|
||||
void Contact::getChildren(int &childA, int &childB)
|
||||
{
|
||||
childA = contact->GetChildIndexA();
|
||||
|
||||
@@ -136,6 +136,15 @@ public:
|
||||
**/
|
||||
void resetRestitution();
|
||||
|
||||
/**
|
||||
* Set the desired tangent speed.
|
||||
**/
|
||||
void setTangentSpeed(float speed);
|
||||
|
||||
/**
|
||||
* Get the desired tangent speed.
|
||||
**/
|
||||
float getTangentSpeed() const;
|
||||
|
||||
void getChildren(int &childA, int &childB);
|
||||
|
||||
|
||||
@@ -0,0 +1,115 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2013 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 "MotorJoint.h"
|
||||
|
||||
// Module
|
||||
#include "Body.h"
|
||||
#include "World.h"
|
||||
#include "Physics.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
MotorJoint::MotorJoint(Body *body1, Body *body2)
|
||||
: Joint(body1, body2)
|
||||
, joint(NULL)
|
||||
{
|
||||
b2MotorJointDef def;
|
||||
|
||||
def.Initialize(body1->body, body2->body);
|
||||
joint = (b2MotorJoint *) createJoint(&def);
|
||||
}
|
||||
|
||||
MotorJoint::MotorJoint(Body *body1, Body *body2, float correctionFactor)
|
||||
: Joint(body1, body2)
|
||||
, joint(NULL)
|
||||
{
|
||||
b2MotorJointDef def;
|
||||
|
||||
def.Initialize(body1->body, body2->body);
|
||||
def.correctionFactor = correctionFactor;
|
||||
|
||||
joint = (b2MotorJoint *) createJoint(&def);
|
||||
}
|
||||
|
||||
MotorJoint::~MotorJoint()
|
||||
{
|
||||
}
|
||||
|
||||
void MotorJoint::setLinearOffset(float x, float y)
|
||||
{
|
||||
joint->SetLinearOffset(Physics::scaleDown(b2Vec2(x, y)));
|
||||
}
|
||||
|
||||
int MotorJoint::getLinearOffset(lua_State *L) const
|
||||
{
|
||||
lua_pushnumber(L, Physics::scaleUp(joint->GetLinearOffset().x));
|
||||
lua_pushnumber(L, Physics::scaleUp(joint->GetLinearOffset().y));
|
||||
return 2;
|
||||
}
|
||||
|
||||
void MotorJoint::setAngularOffset(float angularOffset)
|
||||
{
|
||||
joint->SetAngularOffset(angularOffset);
|
||||
}
|
||||
|
||||
float MotorJoint::getAngularOffset() const
|
||||
{
|
||||
return joint->GetAngularOffset();
|
||||
}
|
||||
|
||||
void MotorJoint::setMaxForce(float force)
|
||||
{
|
||||
joint->SetMaxForce(Physics::scaleDown(force));
|
||||
}
|
||||
|
||||
float MotorJoint::getMaxForce() const
|
||||
{
|
||||
return Physics::scaleUp(joint->GetMaxForce());
|
||||
}
|
||||
|
||||
void MotorJoint::setMaxTorque(float torque)
|
||||
{
|
||||
joint->SetMaxTorque(Physics::scaleDown(Physics::scaleDown(torque)));
|
||||
}
|
||||
|
||||
float MotorJoint::getMaxTorque() const
|
||||
{
|
||||
return Physics::scaleUp(Physics::scaleUp(joint->GetMaxTorque()));
|
||||
}
|
||||
|
||||
void MotorJoint::setCorrectionFactor(float factor)
|
||||
{
|
||||
joint->SetCorrectionFactor(factor);
|
||||
}
|
||||
|
||||
float MotorJoint::getCorrectionFactor() const
|
||||
{
|
||||
return joint->GetCorrectionFactor();
|
||||
}
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
@@ -0,0 +1,85 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2013 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_MOTOR_JOINT_H
|
||||
#define LOVE_PHYSICS_BOX2D_MOTOR_JOINT_H
|
||||
|
||||
// Module
|
||||
#include "Joint.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
/**
|
||||
* A motor joint is used to control the relative motion
|
||||
* between two bodies. A typical usage is to control the movement
|
||||
* of a dynamic body with respect to the ground.
|
||||
*/
|
||||
class MotorJoint : public Joint
|
||||
{
|
||||
public:
|
||||
|
||||
MotorJoint(Body *body1, Body* body2);
|
||||
MotorJoint(Body *body1, Body* body2, float correctionFactor);
|
||||
virtual ~MotorJoint();
|
||||
|
||||
/// Set/get the target linear offset, in frame A, in meters.
|
||||
void setLinearOffset(float x, float y);
|
||||
int getLinearOffset(lua_State *L) const;
|
||||
|
||||
/// Set/get the target angular offset, in radians.
|
||||
void setAngularOffset(float angularOffset);
|
||||
float getAngularOffset() const;
|
||||
|
||||
/// Set the maximum friction force.
|
||||
void setMaxForce(float force);
|
||||
|
||||
/// Get the maximum friction force.
|
||||
float getMaxForce() const;
|
||||
|
||||
/// Set the maximum friction torque.
|
||||
void setMaxTorque(float torque);
|
||||
|
||||
/// Get the maximum friction torque.
|
||||
float getMaxTorque() const;
|
||||
|
||||
/// Set the position correction factor in the range [0,1].
|
||||
void setCorrectionFactor(float factor);
|
||||
|
||||
/// Get the position correction factor in the range [0,1].
|
||||
float getCorrectionFactor() const;
|
||||
|
||||
private:
|
||||
|
||||
// The Box2D MotorJoint object.
|
||||
b2MotorJoint *joint;
|
||||
|
||||
}; // MotorJoint
|
||||
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_MOTOR_JOINT_H
|
||||
@@ -104,53 +104,25 @@ int Physics::newPolygonShape(lua_State *L)
|
||||
|
||||
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);
|
||||
float x = (float)luaL_checknumber(L, 1 + i * 2);
|
||||
float y = (float)luaL_checknumber(L, 2 + i * 2);
|
||||
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)
|
||||
try
|
||||
{
|
||||
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);
|
||||
}
|
||||
catch (love::Exception &)
|
||||
{
|
||||
delete s;
|
||||
throw;
|
||||
}
|
||||
|
||||
s->Set(vecs, vcount);
|
||||
PolygonShape *p = new PolygonShape(s);
|
||||
|
||||
luax_pushtype(L, "PolygonShape", PHYSICS_POLYGON_SHAPE_T, p);
|
||||
@@ -240,6 +212,17 @@ RopeJoint *Physics::newRopeJoint(Body *body1, Body *body2, float x1, float y1, f
|
||||
return new RopeJoint(body1, body2, x1, y1, x2, y2, maxLength, collideConnected);
|
||||
}
|
||||
|
||||
MotorJoint *Physics::newMotorJoint(Body *body1, Body *body2)
|
||||
{
|
||||
return new MotorJoint(body1, body2);
|
||||
}
|
||||
|
||||
MotorJoint *Physics::newMotorJoint(Body *body1, Body *body2, float correctionFactor)
|
||||
{
|
||||
return new MotorJoint(body1, body2, correctionFactor);
|
||||
}
|
||||
|
||||
|
||||
Fixture *Physics::newFixture(Body *body, Shape *shape, float density)
|
||||
{
|
||||
return new Fixture(body, shape, density);
|
||||
|
||||
@@ -43,6 +43,7 @@
|
||||
#include "WeldJoint.h"
|
||||
#include "WheelJoint.h"
|
||||
#include "RopeJoint.h"
|
||||
#include "MotorJoint.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
@@ -250,6 +251,13 @@ public:
|
||||
**/
|
||||
RopeJoint *newRopeJoint(Body *body1, Body *body2, float x1, float y1, float x2, float y2, float maxLength, bool collideConnected);
|
||||
|
||||
/**
|
||||
* Creates a new MotorJoint controlling the relative motion between body1
|
||||
* and body2.
|
||||
**/
|
||||
MotorJoint *newMotorJoint(Body *body1, Body *body2);
|
||||
MotorJoint *newMotorJoint(Body *body1, Body *body2, float correctionFactor);
|
||||
|
||||
/**
|
||||
* Creates a new Fixture attaching shape to body.
|
||||
* @param body The body to attach the Fixture to.
|
||||
|
||||
@@ -57,6 +57,12 @@ int PolygonShape::getPoints(lua_State *L)
|
||||
return count*2;
|
||||
}
|
||||
|
||||
bool PolygonShape::validate() const
|
||||
{
|
||||
b2PolygonShape *p = (b2PolygonShape *)shape;
|
||||
return p->Validate();
|
||||
}
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
@@ -57,6 +57,11 @@ public:
|
||||
* The result can be directly passed into love.graphics.polygon().
|
||||
**/
|
||||
int getPoints(lua_State *L);
|
||||
|
||||
/**
|
||||
* Validate convexity.
|
||||
**/
|
||||
bool validate() const;
|
||||
};
|
||||
|
||||
} // box2d
|
||||
|
||||
@@ -396,6 +396,11 @@ int World::getGravity(lua_State *L)
|
||||
return 2;
|
||||
}
|
||||
|
||||
void World::translateOrigin(float x, float y)
|
||||
{
|
||||
world->ShiftOrigin(Physics::scaleDown(b2Vec2(x, y)));
|
||||
}
|
||||
|
||||
void World::setSleepingAllowed(bool allow)
|
||||
{
|
||||
world->SetAllowSleeping(allow);
|
||||
|
||||
@@ -181,6 +181,13 @@ public:
|
||||
**/
|
||||
int getGravity(lua_State *L);
|
||||
|
||||
/**
|
||||
* Translate the world origin.
|
||||
* @param x The new world origin's x-coordinate relative to the old origin.
|
||||
* @param y The new world origin's y-coordinate relative to the old origin.
|
||||
**/
|
||||
void translateOrigin(float x, float y);
|
||||
|
||||
/**
|
||||
* Sets whether this World allows sleep.
|
||||
* @param allow True to allow, false to disallow.
|
||||
|
||||
@@ -169,15 +169,19 @@ int w_Body_applyLinearImpulse(lua_State *L)
|
||||
float jx = (float)luaL_checknumber(L, 2);
|
||||
float jy = (float)luaL_checknumber(L, 3);
|
||||
|
||||
if (lua_gettop(L) == 3)
|
||||
int nargs = lua_gettop(L);
|
||||
|
||||
if (nargs <= 3 || (nargs == 4 && lua_type(L, 4) == LUA_TBOOLEAN))
|
||||
{
|
||||
t->applyLinearImpulse(jx, jy);
|
||||
bool awake = luax_optboolean(L, 4, true);
|
||||
t->applyLinearImpulse(jx, jy, awake);
|
||||
}
|
||||
else if (lua_gettop(L) == 5)
|
||||
else if (nargs >= 5)
|
||||
{
|
||||
float rx = (float)luaL_checknumber(L, 4);
|
||||
float ry = (float)luaL_checknumber(L, 5);
|
||||
t->applyLinearImpulse(jx, jy, rx, ry);
|
||||
bool awake = luax_optboolean(L, 6, true);
|
||||
t->applyLinearImpulse(jx, jy, rx, ry, awake);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -191,7 +195,8 @@ int w_Body_applyAngularImpulse(lua_State *L)
|
||||
{
|
||||
Body *t = luax_checkbody(L, 1);
|
||||
float i = (float)luaL_checknumber(L, 2);
|
||||
t->applyAngularImpulse(i);
|
||||
bool awake = luax_optboolean(L, 3, true);
|
||||
t->applyAngularImpulse(i, awake);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -199,7 +204,8 @@ int w_Body_applyTorque(lua_State *L)
|
||||
{
|
||||
Body *t = luax_checkbody(L, 1);
|
||||
float arg = (float)luaL_checknumber(L, 2);
|
||||
t->applyTorque(arg);
|
||||
bool awake = luax_optboolean(L, 3, true);
|
||||
t->applyTorque(arg, awake);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -209,16 +215,19 @@ int w_Body_applyForce(lua_State *L)
|
||||
float fx = (float)luaL_checknumber(L, 2);
|
||||
float fy = (float)luaL_checknumber(L, 3);
|
||||
|
||||
int nargs = lua_gettop(L);
|
||||
|
||||
if (lua_gettop(L) == 3)
|
||||
if (nargs <= 3 || (nargs == 4 && lua_type(L, 4) == LUA_TBOOLEAN))
|
||||
{
|
||||
t->applyForce(fx, fy);
|
||||
bool awake = luax_optboolean(L, 4, true);
|
||||
t->applyForce(fx, fy, awake);
|
||||
}
|
||||
else if (lua_gettop(L) == 5)
|
||||
else if (lua_gettop(L) >= 5)
|
||||
{
|
||||
float rx = (float)luaL_checknumber(L, 4);
|
||||
float ry = (float)luaL_checknumber(L, 5);
|
||||
t->applyForce(fx, fy, rx, ry);
|
||||
bool awake = luax_optboolean(L, 6, true);
|
||||
t->applyForce(fx, fy, rx, ry, awake);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -113,6 +113,21 @@ int w_Contact_resetRestitution(lua_State *L)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_Contact_setTangentSpeed(lua_State *L)
|
||||
{
|
||||
Contact *t = luax_checkcontact(L, 1);
|
||||
float speed = (float) luaL_checknumber(L, 2);
|
||||
t->setTangentSpeed(speed);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_Contact_getTangentSpeed(lua_State *L)
|
||||
{
|
||||
Contact *t = luax_checkcontact(L, 1);
|
||||
lua_pushnumber(L, t->getTangentSpeed());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_Contact_getChildren(lua_State *L)
|
||||
{
|
||||
Contact *t = luax_checkcontact(L, 1);
|
||||
@@ -138,6 +153,8 @@ extern "C" int luaopen_contact(lua_State *L)
|
||||
{ "setEnabled", w_Contact_setEnabled },
|
||||
{ "resetFriction", w_Contact_resetFriction },
|
||||
{ "resetRestitution", w_Contact_resetRestitution },
|
||||
{ "setTangentSpeed", w_Contact_setTangentSpeed },
|
||||
{ "getTangentSpeed", w_Contact_getTangentSpeed },
|
||||
{ "getChildren", w_Contact_getChildren },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
@@ -44,6 +44,8 @@ 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);
|
||||
int w_Contact_setTangentSpeed(lua_State *L);
|
||||
int w_Contact_getTangentSpeed(lua_State *L);
|
||||
int w_Contact_getChildren(lua_State *L);
|
||||
extern "C" int luaopen_contact(lua_State *L);
|
||||
|
||||
|
||||
@@ -0,0 +1,143 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2013 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_MotorJoint.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
MotorJoint *luax_checkmotorjoint(lua_State *L, int idx)
|
||||
{
|
||||
MotorJoint *j = luax_checktype<MotorJoint>(L, idx, "MotorJoint", PHYSICS_MOTOR_JOINT_T);
|
||||
if (!j->isValid())
|
||||
luaL_error(L, "Attempt to use destroyed joint.");
|
||||
return j;
|
||||
}
|
||||
|
||||
int w_MotorJoint_setLinearOffset(lua_State *L)
|
||||
{
|
||||
MotorJoint *t = luax_checkmotorjoint(L, 1);
|
||||
float x = (float) luaL_checknumber(L, 2);
|
||||
float y = (float) luaL_checknumber(L, 3);
|
||||
t->setLinearOffset(x, y);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_MotorJoint_getLinearOffset(lua_State *L)
|
||||
{
|
||||
MotorJoint *t = luax_checkmotorjoint(L, 1);
|
||||
return t->getLinearOffset(L);
|
||||
}
|
||||
|
||||
int w_MotorJoint_setAngularOffset(lua_State *L)
|
||||
{
|
||||
MotorJoint *t = luax_checkmotorjoint(L, 1);
|
||||
float arg1 = (float) luaL_checknumber(L, 2);
|
||||
t->setAngularOffset(arg1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_MotorJoint_getAngularOffset(lua_State *L)
|
||||
{
|
||||
MotorJoint *t = luax_checkmotorjoint(L, 1);
|
||||
lua_pushnumber(L, t->getAngularOffset());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_MotorJoint_setMaxForce(lua_State *L)
|
||||
{
|
||||
MotorJoint *t = luax_checkmotorjoint(L, 1);
|
||||
float arg1 = (float) luaL_checknumber(L, 2);
|
||||
EXCEPT_GUARD(t->setMaxForce(arg1);)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_MotorJoint_getMaxForce(lua_State *L)
|
||||
{
|
||||
MotorJoint *t = luax_checkmotorjoint(L, 1);
|
||||
lua_pushnumber(L, t->getMaxForce());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_MotorJoint_setMaxTorque(lua_State *L)
|
||||
{
|
||||
MotorJoint *t = luax_checkmotorjoint(L, 1);
|
||||
float arg1 = (float) luaL_checknumber(L, 2);
|
||||
EXCEPT_GUARD(t->setMaxTorque(arg1);)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_MotorJoint_getMaxTorque(lua_State *L)
|
||||
{
|
||||
MotorJoint *t = luax_checkmotorjoint(L, 1);
|
||||
lua_pushnumber(L, t->getMaxTorque());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_MotorJoint_setCorrectionFactor(lua_State *L)
|
||||
{
|
||||
MotorJoint *t = luax_checkmotorjoint(L, 1);
|
||||
float arg1 = (float) luaL_checknumber(L, 2);
|
||||
EXCEPT_GUARD(t->setCorrectionFactor(arg1);)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_MotorJoint_getCorrectionFactor(lua_State *L)
|
||||
{
|
||||
MotorJoint *t = luax_checkmotorjoint(L, 1);
|
||||
lua_pushnumber(L, t->getCorrectionFactor());
|
||||
return 1;
|
||||
}
|
||||
|
||||
static const luaL_Reg functions[] =
|
||||
{
|
||||
{ "setLinearOffset", w_MotorJoint_setLinearOffset },
|
||||
{ "getLinearOffset", w_MotorJoint_getLinearOffset },
|
||||
{ "setAngularOffset", w_MotorJoint_setAngularOffset },
|
||||
{ "getAngularOffset", w_MotorJoint_getAngularOffset },
|
||||
{ "setMaxForce", w_MotorJoint_setMaxForce },
|
||||
{ "getMaxForce", w_MotorJoint_getMaxForce },
|
||||
{ "setMaxTorque", w_MotorJoint_setMaxTorque },
|
||||
{ "getMaxTorque", w_MotorJoint_getMaxTorque },
|
||||
{ "setCorrectionFactor", w_MotorJoint_setCorrectionFactor },
|
||||
{ "getCorrectionFactor", w_MotorJoint_getCorrectionFactor },
|
||||
// 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_motorjoint(lua_State *L)
|
||||
{
|
||||
return luax_register_type(L, "MotorJoint", functions);
|
||||
}
|
||||
|
||||
|
||||
} // box2d
|
||||
} // phyics
|
||||
} // love
|
||||
@@ -0,0 +1,53 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2013 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_MOTOR_JOINT_H
|
||||
#define LOVE_PHYSICS_BOX2D_WRAP_MOTOR_JOINT_H
|
||||
|
||||
// LOVE
|
||||
#include "common/runtime.h"
|
||||
#include "wrap_Joint.h"
|
||||
#include "MotorJoint.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
MotorJoint *luax_checkmotorjoint(lua_State *L, int idx);
|
||||
int w_MotorJoint_setLinearOffset(lua_State *L);
|
||||
int w_MotorJoint_getLinearOffset(lua_State *L);
|
||||
int w_MotorJoint_setAngularOffset(lua_State *L);
|
||||
int w_MotorJoint_getAngularOffset(lua_State *L);
|
||||
int w_MotorJoint_setMaxForce(lua_State *L);
|
||||
int w_MotorJoint_getMaxForce(lua_State *L);
|
||||
int w_MotorJoint_setMaxTorque(lua_State *L);
|
||||
int w_MotorJoint_getMaxTorque(lua_State *L);
|
||||
int w_MotorJoint_setCorrectionFactor(lua_State *L);
|
||||
int w_MotorJoint_getCorrectionFactor(lua_State *L);
|
||||
extern "C" int luaopen_motorjoint(lua_State *L);
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_WRAP_MOTOR_JOINT_H
|
||||
@@ -40,6 +40,7 @@
|
||||
#include "wrap_WeldJoint.h"
|
||||
#include "wrap_WheelJoint.h"
|
||||
#include "wrap_RopeJoint.h"
|
||||
#include "wrap_MotorJoint.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
@@ -374,6 +375,24 @@ int w_newRopeJoint(lua_State *L)
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_newMotorJoint(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);
|
||||
MotorJoint *j = 0;
|
||||
if (!lua_isnoneornil(L, 3))
|
||||
{
|
||||
float correctionFactor = (float)luaL_checknumber(L, 3);
|
||||
EXCEPT_GUARD(j = instance->newMotorJoint(body1, body2, correctionFactor);)
|
||||
}
|
||||
else
|
||||
{
|
||||
EXCEPT_GUARD(j = instance->newMotorJoint(body1, body2);)
|
||||
}
|
||||
luax_pushtype(L, "MotorJoint", PHYSICS_MOTOR_JOINT_T, j);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_getDistance(lua_State *L)
|
||||
{
|
||||
return instance->getDistance(L);
|
||||
@@ -413,6 +432,7 @@ static const luaL_Reg functions[] =
|
||||
{ "newWeldJoint", w_newWeldJoint },
|
||||
{ "newWheelJoint", w_newWheelJoint },
|
||||
{ "newRopeJoint", w_newRopeJoint },
|
||||
{ "newMotorJoint", w_newMotorJoint },
|
||||
{ "getDistance", w_getDistance },
|
||||
{ "getMeter", w_getMeter },
|
||||
{ "setMeter", w_setMeter },
|
||||
@@ -441,6 +461,7 @@ static const lua_CFunction types[] =
|
||||
luaopen_weldjoint,
|
||||
luaopen_wheeljoint,
|
||||
luaopen_ropejoint,
|
||||
luaopen_motorjoint,
|
||||
0
|
||||
};
|
||||
|
||||
|
||||
@@ -50,6 +50,7 @@ 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_newMotorJoint(lua_State *L);
|
||||
int w_getDistance(lua_State *L);
|
||||
int w_setMeter(lua_State *L);
|
||||
int w_getMeter(lua_State *L);
|
||||
|
||||
@@ -39,9 +39,17 @@ int w_PolygonShape_getPoints(lua_State *L)
|
||||
return t->getPoints(L);
|
||||
}
|
||||
|
||||
int w_PolygonShape_validate(lua_State *L)
|
||||
{
|
||||
PolygonShape *t = luax_checkpolygonshape(L, 1);
|
||||
luax_pushboolean(L, t->validate());
|
||||
return 1;
|
||||
}
|
||||
|
||||
static const luaL_Reg functions[] =
|
||||
{
|
||||
{ "getPoints", w_PolygonShape_getPoints },
|
||||
{ "validate", w_PolygonShape_validate },
|
||||
// From Shape.
|
||||
{ "getType", w_Shape_getType },
|
||||
{ "getRadius", w_Shape_getRadius },
|
||||
|
||||
@@ -35,6 +35,7 @@ namespace box2d
|
||||
|
||||
PolygonShape *luax_checkpolygonshape(lua_State *L, int idx);
|
||||
int w_PolygonShape_getPoints(lua_State *L);
|
||||
int w_PolygonShape_validate(lua_State *L);
|
||||
extern "C" int luaopen_polygonshape(lua_State *L);
|
||||
|
||||
} // box2d
|
||||
|
||||
@@ -87,6 +87,15 @@ int w_World_getGravity(lua_State *L)
|
||||
return t->getGravity(L);
|
||||
}
|
||||
|
||||
int w_World_translateOrigin(lua_State *L)
|
||||
{
|
||||
World *t = luax_checkworld(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
float arg2 = (float)luaL_checknumber(L, 3);
|
||||
t->translateOrigin(arg1, arg2);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_World_setSleepingAllowed(lua_State *L)
|
||||
{
|
||||
World *t = luax_checkworld(L, 1);
|
||||
@@ -184,6 +193,7 @@ static const luaL_Reg functions[] =
|
||||
{ "getContactFilter", w_World_getContactFilter },
|
||||
{ "setGravity", w_World_setGravity },
|
||||
{ "getGravity", w_World_getGravity },
|
||||
{ "translateOrigin", w_World_translateOrigin },
|
||||
{ "setSleepingAllowed", w_World_setSleepingAllowed },
|
||||
{ "isSleepingAllowed", w_World_isSleepingAllowed },
|
||||
{ "isLocked", w_World_isLocked },
|
||||
|
||||
@@ -42,6 +42,7 @@ 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_translateOrigin(lua_State *L);
|
||||
int w_World_setSleepingAllowed(lua_State *L);
|
||||
int w_World_isSleepingAllowed(lua_State *L);
|
||||
int w_World_isLocked(lua_State *L);
|
||||
|
||||
Reference in New Issue
Block a user