Add basic EdgeShape (todo: all edge-related functionality) and further integrated the new Joints

--HG--
branch : box2d-update
This commit is contained in:
Bill Meltsner
2011-09-04 13:21:57 -04:00
parent 551cf591e2
commit 7ec64bf912
13 changed files with 384 additions and 156 deletions
@@ -163,6 +163,8 @@
A96F41861412AFF80067FE9A /* WeldJoint.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A96F41841412AFEB0067FE9A /* WeldJoint.cpp */; }; A96F41861412AFF80067FE9A /* WeldJoint.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A96F41841412AFEB0067FE9A /* WeldJoint.cpp */; };
A96F41891412B36D0067FE9A /* wrap_WheelJoint.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A96F41871412B35B0067FE9A /* wrap_WheelJoint.cpp */; }; A96F41891412B36D0067FE9A /* wrap_WheelJoint.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A96F41871412B35B0067FE9A /* wrap_WheelJoint.cpp */; };
A96F418C1412B3AD0067FE9A /* WheelJoint.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A96F418A1412B3A30067FE9A /* WheelJoint.cpp */; }; A96F418C1412B3AD0067FE9A /* WheelJoint.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A96F418A1412B3A30067FE9A /* WheelJoint.cpp */; };
A96F41A41412C91F0067FE9A /* EdgeShape.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A96F41A21412C91E0067FE9A /* EdgeShape.cpp */; };
A96F41A71412C92B0067FE9A /* wrap_EdgeShape.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A96F41A51412C92B0067FE9A /* wrap_EdgeShape.cpp */; };
A986DEB5113249A800810279 /* Thread.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A986DEB1113249A800810279 /* Thread.cpp */; }; A986DEB5113249A800810279 /* Thread.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A986DEB1113249A800810279 /* Thread.cpp */; };
A986DEB6113249A800810279 /* wrap_Thread.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A986DEB3113249A800810279 /* wrap_Thread.cpp */; }; A986DEB6113249A800810279 /* wrap_Thread.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A986DEB3113249A800810279 /* wrap_Thread.cpp */; };
A986EC64132CE6DB00F048C8 /* b2BroadPhase.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A986EBC8132CE6D800F048C8 /* b2BroadPhase.cpp */; }; A986EC64132CE6DB00F048C8 /* b2BroadPhase.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A986EBC8132CE6D800F048C8 /* b2BroadPhase.cpp */; };
@@ -571,6 +573,10 @@
A96F41881412B3610067FE9A /* wrap_WheelJoint.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = wrap_WheelJoint.h; sourceTree = "<group>"; }; A96F41881412B3610067FE9A /* wrap_WheelJoint.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = wrap_WheelJoint.h; sourceTree = "<group>"; };
A96F418A1412B3A30067FE9A /* WheelJoint.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WheelJoint.cpp; sourceTree = "<group>"; }; A96F418A1412B3A30067FE9A /* WheelJoint.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WheelJoint.cpp; sourceTree = "<group>"; };
A96F418B1412B3A80067FE9A /* WheelJoint.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WheelJoint.h; sourceTree = "<group>"; }; A96F418B1412B3A80067FE9A /* WheelJoint.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WheelJoint.h; sourceTree = "<group>"; };
A96F41A21412C91E0067FE9A /* EdgeShape.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = EdgeShape.cpp; sourceTree = "<group>"; };
A96F41A31412C91E0067FE9A /* EdgeShape.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EdgeShape.h; sourceTree = "<group>"; };
A96F41A51412C92B0067FE9A /* wrap_EdgeShape.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = wrap_EdgeShape.cpp; sourceTree = "<group>"; };
A96F41A61412C92B0067FE9A /* wrap_EdgeShape.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = wrap_EdgeShape.h; sourceTree = "<group>"; };
A97E3842132A9EDE00198A2F /* love-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "love-Info.plist"; sourceTree = "<group>"; }; A97E3842132A9EDE00198A2F /* love-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "love-Info.plist"; sourceTree = "<group>"; };
A986DEB1113249A800810279 /* Thread.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Thread.cpp; sourceTree = "<group>"; }; A986DEB1113249A800810279 /* Thread.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Thread.cpp; sourceTree = "<group>"; };
A986DEB2113249A800810279 /* Thread.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Thread.h; sourceTree = "<group>"; }; A986DEB2113249A800810279 /* Thread.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Thread.h; sourceTree = "<group>"; };
@@ -1195,6 +1201,8 @@
A93E6AF010420AC7007D418B /* Contact.h */, A93E6AF010420AC7007D418B /* Contact.h */,
A93E6AF110420AC7007D418B /* DistanceJoint.cpp */, A93E6AF110420AC7007D418B /* DistanceJoint.cpp */,
A93E6AF210420AC7007D418B /* DistanceJoint.h */, A93E6AF210420AC7007D418B /* DistanceJoint.h */,
A96F41A21412C91E0067FE9A /* EdgeShape.cpp */,
A96F41A31412C91E0067FE9A /* EdgeShape.h */,
A986ECAD132CEB9300F048C8 /* Fixture.cpp */, A986ECAD132CEB9300F048C8 /* Fixture.cpp */,
A986ECAE132CEB9B00F048C8 /* Fixture.h */, A986ECAE132CEB9B00F048C8 /* Fixture.h */,
A9B6432A13BF833900DC3C7E /* FrictionJoint.cpp */, A9B6432A13BF833900DC3C7E /* FrictionJoint.cpp */,
@@ -1232,6 +1240,8 @@
A93E6B5510420ACA007D418B /* wrap_Contact.h */, A93E6B5510420ACA007D418B /* wrap_Contact.h */,
A93E6B5610420ACA007D418B /* wrap_DistanceJoint.cpp */, A93E6B5610420ACA007D418B /* wrap_DistanceJoint.cpp */,
A93E6B5710420ACA007D418B /* wrap_DistanceJoint.h */, A93E6B5710420ACA007D418B /* wrap_DistanceJoint.h */,
A96F41A51412C92B0067FE9A /* wrap_EdgeShape.cpp */,
A96F41A61412C92B0067FE9A /* wrap_EdgeShape.h */,
A9B6432D13BF87E400DC3C7E /* wrap_FrictionJoint.cpp */, A9B6432D13BF87E400DC3C7E /* wrap_FrictionJoint.cpp */,
A9B6432E13BF87EA00DC3C7E /* wrap_FrictionJoint.h */, A9B6432E13BF87EA00DC3C7E /* wrap_FrictionJoint.h */,
A93E6B5810420ACA007D418B /* wrap_GearJoint.cpp */, A93E6B5810420ACA007D418B /* wrap_GearJoint.cpp */,
@@ -1786,6 +1796,8 @@
A96F41861412AFF80067FE9A /* WeldJoint.cpp in Sources */, A96F41861412AFF80067FE9A /* WeldJoint.cpp in Sources */,
A96F41891412B36D0067FE9A /* wrap_WheelJoint.cpp in Sources */, A96F41891412B36D0067FE9A /* wrap_WheelJoint.cpp in Sources */,
A96F418C1412B3AD0067FE9A /* WheelJoint.cpp in Sources */, A96F418C1412B3AD0067FE9A /* WheelJoint.cpp in Sources */,
A96F41A41412C91F0067FE9A /* EdgeShape.cpp in Sources */,
A96F41A71412C92B0067FE9A /* wrap_EdgeShape.cpp in Sources */,
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
}; };
@@ -45,9 +45,6 @@ namespace box2d
return shape->m_radius; return shape->m_radius;
} }
/**
* Gets the radius for the circle.
**/
void CircleShape::setRadius(float r) void CircleShape::setRadius(float r)
{ {
shape->m_radius = r; shape->m_radius = r;
+44
View File
@@ -0,0 +1,44 @@
/**
* 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 "EdgeShape.h"
// Module
#include "Body.h"
#include "World.h"
namespace love
{
namespace physics
{
namespace box2d
{
EdgeShape::EdgeShape(b2EdgeShape * e)
{
shape = e;
}
EdgeShape::~EdgeShape()
{
}
} // box2d
} // physics
} // love
+54
View File
@@ -0,0 +1,54 @@
/**
* 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_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);
virtual ~EdgeShape();
};
} // box2d
} // physics
} // love
#endif // LOVE_PHYSICS_BOX2D_EDGE_SHAPE_H
+23 -16
View File
@@ -62,30 +62,27 @@ namespace box2d
return new Body(world, b2Vec2(0, 0), 1, 1); return new Body(world, b2Vec2(0, 0), 1, 1);
} }
CircleShape * Physics::newCircleShape(Body * body, float radius) CircleShape * Physics::newCircleShape(float radius)
{ {
return newCircleShape(body, 0, 0, radius); return newCircleShape(0, 0, radius);
} }
CircleShape * Physics::newCircleShape(Body * body, float x, float y, float radius) CircleShape * Physics::newCircleShape(float x, float y, float radius)
{ {
b2CircleDef def; b2CircleShape s;
def.density = 1.0f; s.m_p = b2Vec2(x, y);
def.localPosition.Set(x, y); s.m_radius = radius;
def.friction = 0.5f; return new CircleShape(&s);
def.restitution = 0.1f;
def.radius = radius;
return new CircleShape(body, &def);
} }
PolygonShape * Physics::newRectangleShape(float w, float h) PolygonShape * Physics::newRectangleShape(float w, float h)
{ {
return newRectangleShape(body, 0, 0, w, h, 0); return newRectangleShape(0, 0, w, h, 0);
} }
PolygonShape * Physics::newRectangleShape(float x, float y, float w, float h) PolygonShape * Physics::newRectangleShape(float x, float y, float w, float h)
{ {
return newRectangleShape(body, x, y, w, h, 0); return newRectangleShape(x, y, w, h, 0);
} }
PolygonShape * Physics::newRectangleShape(float x, float y, float w, float h, float angle) PolygonShape * Physics::newRectangleShape(float x, float y, float w, float h, float angle)
@@ -95,11 +92,11 @@ namespace box2d
return new PolygonShape(&s); return new PolygonShape(&s);
} }
PolygonShape * Physics::newEdgeShape(float x1, float y1, float x2, float y2) EdgeShape * Physics::newEdgeShape(float x1, float y1, float x2, float y2)
{ {
b2PolygonShape s; b2EdgeShape s;
s.SetAsEdge(b2vec2(x1, y1), b2vec2(x2, y2)); s.Set(b2Vec2(x1, y1), b2Vec2(x2, y2));
return new PolygonShape(&s); return new EdgeShape(&s);
} }
int Physics::newPolygonShape(lua_State * L) int Physics::newPolygonShape(lua_State * L)
@@ -182,6 +179,16 @@ namespace box2d
return new FrictionJoint(body1, body2, x, y); return new FrictionJoint(body1, body2, x, y);
} }
WeldJoint * Physics::newWeldJoint(Body * body1, Body * body2, float x, float y)
{
return new WeldJoint(body1, body2, x, y);
}
WheelJoint * Physics::newWheelJoint(Body * body1, Body * body2, float x, float y, float ax, float ay)
{
return new WheelJoint(body1, body2, x, y, ax, ay);
}
} // box2d } // box2d
} // physics } // physics
} // love } // love
+29 -14
View File
@@ -29,6 +29,7 @@
#include "Shape.h" #include "Shape.h"
#include "CircleShape.h" #include "CircleShape.h"
#include "PolygonShape.h" #include "PolygonShape.h"
#include "EdgeShape.h"
#include "Joint.h" #include "Joint.h"
#include "MouseJoint.h" #include "MouseJoint.h"
#include "DistanceJoint.h" #include "DistanceJoint.h"
@@ -37,6 +38,8 @@
#include "PulleyJoint.h" #include "PulleyJoint.h"
#include "GearJoint.h" #include "GearJoint.h"
#include "FrictionJoint.h" #include "FrictionJoint.h"
#include "WeldJoint.h"
#include "WheelJoint.h"
namespace love namespace love
{ {
@@ -89,15 +92,13 @@ namespace box2d
Body * newBody(World * world); Body * newBody(World * world);
/** /**
* Creates a new CircleShape at the Body origin. * Creates a new CircleShape at (0, 0).
* @param body The Body to create the Shape on.
* @param radius The radius of the circle. * @param radius The radius of the circle.
**/ **/
CircleShape * newCircleShape(float radius); CircleShape * newCircleShape(float radius);
/** /**
* Creates a new CircleShape at (x,y) in local coorinates. * Creates a new CircleShape at (x,y) in local coordinates.
* @param body The Body to create the Shape on.
* @param x The offset along the x-axis. * @param x The offset along the x-axis.
* @param y The offset along the y-axis. * @param y The offset along the y-axis.
* @param radius The radius of the circle. * @param radius The radius of the circle.
@@ -134,19 +135,17 @@ namespace box2d
PolygonShape * newRectangleShape(float x, float y, float w, float h, float angle); PolygonShape * newRectangleShape(float x, float y, float w, float h, float angle);
/** /**
* Shorthand for creating edge PolygonShapes. The edge * Creates a new EdgeShape. The edge will be created from
* will be created at (x,y) in local coordinates. * (x1,y1) to (x2,y2) in local coordinates.
* @param x The offset along the x-axis. * @param x1 The x coordinate of the first point.
* @param y The offset along the y-axis. * @param y1 The y coordinate of the first point.
* @param w The width of the rectangle. * @param x2 The x coordinate of the second point.
* @param h The height of the rectangle. * @param y2 The y coordinate of the second point.
* @param angle The angle of the rectangle. (rad) **/
**/ EdgeShape * newEdgeShape(float x1, float y1, float x2, float y2);
PolygonShape * newEdgeShape(float x1, float y1, float x2, float y2);
/** /**
* Creates a new PolygonShape. * Creates a new PolygonShape.
* @param body The body to create this shape on.
* @param ... A variable number of vertices. * @param ... A variable number of vertices.
**/ **/
int newPolygonShape(lua_State * L); int newPolygonShape(lua_State * L);
@@ -208,6 +207,22 @@ namespace box2d
**/ **/
FrictionJoint * newFrictionJoint(Body * body1, Body * body2, float x, float y); FrictionJoint * newFrictionJoint(Body * body1, Body * body2, float x, float y);
/**
* Creates a new WeldJoint connecting body1 with body2.
* @param x Anchor along the x-axis. (World coordinates)
* @param y Anchor along the y-axis. (World coordinates)
**/
WeldJoint * newWeldJoint(Body * body1, Body * body2, float x, float y);
/**
* Creates a new WheelJoint connecting body1 with body2.
* @param x Anchor along the x-axis. (World coordinates)
* @param y Anchor along the y-axis. (World coordinates)
* @param ax The x-component of the world-axis.
* @param ay The y-component of the world-axis.
**/
WheelJoint * newWheelJoint(Body * body1, Body * body2, float x, float y, float ax, float ay);
}; // Physics }; // Physics
+4
View File
@@ -51,6 +51,10 @@ namespace box2d
return SHAPE_CIRCLE; return SHAPE_CIRCLE;
case b2Shape::e_polygon: case b2Shape::e_polygon:
return SHAPE_POLYGON; return SHAPE_POLYGON;
case b2Shape::e_edge:
return SHAPE_EDGE;
case b2Shape::e_chain:
return SHAPE_CHAIN;
default: default:
return SHAPE_INVALID; return SHAPE_INVALID;
} }
@@ -0,0 +1,48 @@
/**
* 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 "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);
}
static const luaL_Reg functions[] = {
// From Shape.
{ "getType", w_Shape_getType },
{ "destroy", w_Shape_destroy },
{ 0, 0 }
};
int luaopen_edgeshape(lua_State * L)
{
return luax_register_type(L, "EdgeShape", functions);
}
} // box2d
} // physics
} // love
@@ -0,0 +1,42 @@
/**
* 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_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 luaopen_edgeshape(lua_State * L);
} // box2d
} // physics
} // love
#endif // LOVE_PHYSICS_BOX2D_WRAP_EDGE_SHAPE_H
+31 -2
View File
@@ -118,8 +118,8 @@ namespace box2d
float y1 = (float)luaL_checknumber(L, 2); float y1 = (float)luaL_checknumber(L, 2);
float x2 = (float)luaL_checknumber(L, 3); float x2 = (float)luaL_checknumber(L, 3);
float y2 = (float)luaL_checknumber(L, 4); float y2 = (float)luaL_checknumber(L, 4);
PolygonShape * shape = instance->newEdgeShape(x1, y1, x2, y2); EdgeShape * shape = instance->newEdgeShape(x1, y1, x2, y2);
luax_newtype(L, "PolygonShape", PHYSICS_POLYGON_SHAPE_T, (void*)shape); luax_newtype(L, "EdgeShape", PHYSICS_EDGE_SHAPE_T, (void*)shape);
return 1; return 1;
} }
@@ -216,6 +216,30 @@ namespace box2d
return 1; 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 x = (float)luaL_checknumber(L, 3);
float y = (float)luaL_checknumber(L, 4);
WeldJoint * j = instance->newWeldJoint(body1, body2, x, y);
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 x = (float)luaL_checknumber(L, 3);
float y = (float)luaL_checknumber(L, 4);
float ax = (float)luaL_checknumber(L, 5);
float ay = (float)luaL_checknumber(L, 6);
WheelJoint * j = instance->newWheelJoint(body1, body2, x, y, ax, ay);
luax_newtype(L, "WheelJoint", PHYSICS_WHEEL_JOINT_T, (void*)j);
return 1;
}
// List of functions to wrap. // List of functions to wrap.
static const luaL_Reg functions[] = { static const luaL_Reg functions[] = {
{ "newWorld", w_newWorld }, { "newWorld", w_newWorld },
@@ -223,6 +247,7 @@ namespace box2d
{ "newCircleShape", w_newCircleShape }, { "newCircleShape", w_newCircleShape },
{ "newRectangleShape", w_newRectangleShape }, { "newRectangleShape", w_newRectangleShape },
{ "newPolygonShape", w_newPolygonShape }, { "newPolygonShape", w_newPolygonShape },
{ "newEdgeShape", w_newEdgeShape },
{ "newDistanceJoint", w_newDistanceJoint }, { "newDistanceJoint", w_newDistanceJoint },
{ "newMouseJoint", w_newMouseJoint }, { "newMouseJoint", w_newMouseJoint },
{ "newRevoluteJoint", w_newRevoluteJoint }, { "newRevoluteJoint", w_newRevoluteJoint },
@@ -230,6 +255,8 @@ namespace box2d
{ "newPulleyJoint", w_newPulleyJoint }, { "newPulleyJoint", w_newPulleyJoint },
{ "newGearJoint", w_newGearJoint }, { "newGearJoint", w_newGearJoint },
{ "newFrictionJoint", w_newFrictionJoint }, { "newFrictionJoint", w_newFrictionJoint },
{ "newWeldJoint", w_newWeldJoint },
{ "newWheelJoint", w_newWheelJoint },
{ 0, 0 }, { 0, 0 },
}; };
@@ -240,6 +267,7 @@ namespace box2d
luaopen_shape, luaopen_shape,
luaopen_circleshape, luaopen_circleshape,
luaopen_polygonshape, luaopen_polygonshape,
luaopen_edgeshape,
luaopen_joint, luaopen_joint,
luaopen_mousejoint, luaopen_mousejoint,
luaopen_distancejoint, luaopen_distancejoint,
@@ -248,6 +276,7 @@ namespace box2d
luaopen_pulleyjoint, luaopen_pulleyjoint,
luaopen_gearjoint, luaopen_gearjoint,
luaopen_frictionjoint, luaopen_frictionjoint,
luaopen_weldjoint,
0 0
}; };
+6 -1
View File
@@ -30,6 +30,7 @@
#include "wrap_Shape.h" #include "wrap_Shape.h"
#include "wrap_CircleShape.h" #include "wrap_CircleShape.h"
#include "wrap_PolygonShape.h" #include "wrap_PolygonShape.h"
#include "wrap_EdgeShape.h"
#include "wrap_Joint.h" #include "wrap_Joint.h"
#include "wrap_MouseJoint.h" #include "wrap_MouseJoint.h"
#include "wrap_DistanceJoint.h" #include "wrap_DistanceJoint.h"
@@ -38,6 +39,8 @@
#include "wrap_PulleyJoint.h" #include "wrap_PulleyJoint.h"
#include "wrap_GearJoint.h" #include "wrap_GearJoint.h"
#include "wrap_FrictionJoint.h" #include "wrap_FrictionJoint.h"
#include "wrap_WeldJoint.h"
#include "wrap_WheelJoint.h"
namespace love namespace love
{ {
@@ -49,8 +52,8 @@ namespace box2d
int w_newBody(lua_State * L); int w_newBody(lua_State * L);
int w_newCircleShape(lua_State * L); int w_newCircleShape(lua_State * L);
int w_newRectangleShape(lua_State * L); int w_newRectangleShape(lua_State * L);
int w_newEdgeShape(lua_State * L);
int w_newPolygonShape(lua_State * L); int w_newPolygonShape(lua_State * L);
int w_newEdgeShape(lua_State * L);
int w_newDistanceJoint(lua_State * L); int w_newDistanceJoint(lua_State * L);
int w_newMouseJoint(lua_State * L); int w_newMouseJoint(lua_State * L);
int w_newRevoluteJoint(lua_State * L); int w_newRevoluteJoint(lua_State * L);
@@ -58,6 +61,8 @@ namespace box2d
int w_newPulleyJoint(lua_State * L); int w_newPulleyJoint(lua_State * L);
int w_newGearJoint(lua_State * L); int w_newGearJoint(lua_State * L);
int w_newFrictionJoint(lua_State * L); int w_newFrictionJoint(lua_State * L);
int w_newWeldJoint(lua_State * L);
int w_newWheelJoint(lua_State * L);
extern "C" LOVE_EXPORT int luaopen_love_physics(lua_State * L); extern "C" LOVE_EXPORT int luaopen_love_physics(lua_State * L);
} // box2d } // box2d
+67 -93
View File
@@ -18,7 +18,7 @@
* 3. This notice may not be removed or altered from any source distribution. * 3. This notice may not be removed or altered from any source distribution.
**/ **/
#include "wrap_PrismaticJoint.h" #include "wrap_WheelJoint.h"
namespace love namespace love
{ {
@@ -26,148 +26,122 @@ namespace physics
{ {
namespace box2d namespace box2d
{ {
PrismaticJoint * luax_checkprismaticjoint(lua_State * L, int idx) WheelJoint * luax_checkwheeljoint(lua_State * L, int idx)
{ {
return luax_checktype<PrismaticJoint>(L, idx, "PrismaticJoint", PHYSICS_PRISMATIC_JOINT_T); return luax_checktype<WheelJoint>(L, idx, "WheelJoint", PHYSICS_WHEEL_JOINT_T);
} }
int w_PrismaticJoint_getJointTranslation(lua_State * L) int w_WheelJoint_getJointTranslation(lua_State * L)
{ {
PrismaticJoint * t = luax_checkprismaticjoint(L, 1); WheelJoint * t = luax_checkwheeljoint(L, 1);
lua_pushnumber(L, t->getJointTranslation()); lua_pushnumber(L, t->getJointTranslation());
return 1; return 1;
} }
int w_PrismaticJoint_getJointSpeed(lua_State * L) int w_WheelJoint_getJointSpeed(lua_State * L)
{ {
PrismaticJoint * t = luax_checkprismaticjoint(L, 1); WheelJoint * t = luax_checkwheeljoint(L, 1);
lua_pushnumber(L, t->getJointSpeed()); lua_pushnumber(L, t->getJointSpeed());
return 1; return 1;
} }
int w_PrismaticJoint_enableMotor(lua_State * L) int w_WheelJoint_enableMotor(lua_State * L)
{ {
PrismaticJoint * t = luax_checkprismaticjoint(L, 1); WheelJoint * t = luax_checkwheeljoint(L, 1);
bool arg1 = luax_toboolean(L, 2); bool arg1 = luax_toboolean(L, 2);
t->enableMotor(arg1); t->enableMotor(arg1);
return 0; return 0;
} }
int w_PrismaticJoint_isMotorEnabled(lua_State * L) int w_WheelJoint_isMotorEnabled(lua_State * L)
{ {
PrismaticJoint * t = luax_checkprismaticjoint(L, 1); WheelJoint * t = luax_checkwheeljoint(L, 1);
luax_pushboolean(L, t->isMotorEnabled()); luax_pushboolean(L, t->isMotorEnabled());
return 1; return 1;
} }
int w_PrismaticJoint_setMaxMotorForce(lua_State * L) int w_WheelJoint_setMotorSpeed(lua_State * L)
{ {
PrismaticJoint * t = luax_checkprismaticjoint(L, 1); WheelJoint * t = luax_checkwheeljoint(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); float arg1 = (float)luaL_checknumber(L, 2);
t->setMotorSpeed(arg1); t->setMotorSpeed(arg1);
return 0; return 0;
} }
int w_PrismaticJoint_getMotorSpeed(lua_State * L) int w_WheelJoint_getMotorSpeed(lua_State * L)
{ {
PrismaticJoint * t = luax_checkprismaticjoint(L, 1); WheelJoint * t = luax_checkwheeljoint(L, 1);
lua_pushnumber(L, t->getMotorSpeed()); lua_pushnumber(L, t->getMotorSpeed());
return 1; return 1;
} }
int w_PrismaticJoint_getMotorForce(lua_State * L) int w_WheelJoint_setMaxMotorTorque(lua_State * L)
{ {
PrismaticJoint * t = luax_checkprismaticjoint(L, 1); WheelJoint * t = luax_checkwheeljoint(L, 1);
lua_pushnumber(L, t->getMotorForce());
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); float arg1 = (float)luaL_checknumber(L, 2);
t->setUpperLimit(arg1); t->setMaxMotorTorque(arg1);
return 0; return 0;
} }
int w_PrismaticJoint_setLowerLimit(lua_State * L) int w_WheelJoint_getMaxMotorTorque(lua_State * L)
{ {
PrismaticJoint * t = luax_checkprismaticjoint(L, 1); WheelJoint * t = luax_checkwheeljoint(L, 1);
float arg1 = (float)luaL_checknumber(L, 2); lua_pushnumber(L, t->getMaxMotorTorque());
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; return 1;
} }
int w_PrismaticJoint_getUpperLimit(lua_State * L) int w_WheelJoint_getMotorTorque(lua_State * L)
{ {
PrismaticJoint * t = luax_checkprismaticjoint(L, 1); WheelJoint * t = luax_checkwheeljoint(L, 1);
lua_pushnumber(L, t->getUpperLimit()); float inv_dt = (float)luaL_checknumber(L, 2);
lua_pushnumber(L, t->getMotorTorque(inv_dt));
return 1; return 1;
} }
int w_PrismaticJoint_getLimits(lua_State * L) int w_WheelJoint_setSpringFrequencyHz(lua_State * L)
{ {
PrismaticJoint * t = luax_checkprismaticjoint(L, 1); WheelJoint * t = luax_checkwheeljoint(L, 1);
lua_remove(L, 1); float arg1 = (float)luaL_checknumber(L, 2);
return t->getLimits(L); t->setSpringFrequencyHz(arg1);
return 0;
}
int w_WheelJoint_getSpringFrequencyHz(lua_State * L)
{
WheelJoint * t = luax_checkwheeljoint(L, 1);
lua_pushnumber(L, t->getSpringFrequencyHz());
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[] = { static const luaL_Reg functions[] = {
{ "getJointTranslation", w_PrismaticJoint_getJointTranslation }, { "getJointTranslation", w_WheelJoint_getJointTranslation },
{ "getJointSpeed", w_PrismaticJoint_getJointSpeed }, { "getJointSpeed", w_WheelJoint_getJointSpeed },
{ "enableMotor", w_PrismaticJoint_enableMotor }, { "enableMotor", w_WheelJoint_enableMotor },
{ "isMotorEnabled", w_PrismaticJoint_isMotorEnabled }, { "isMotorEnabled", w_WheelJoint_isMotorEnabled },
{ "setMaxMotorForce", w_PrismaticJoint_setMaxMotorForce }, { "setMotorSpeed", w_WheelJoint_setMotorSpeed },
{ "setMotorSpeed", w_PrismaticJoint_setMotorSpeed }, { "getMotorSpeed", w_WheelJoint_getMotorSpeed },
{ "getMotorSpeed", w_PrismaticJoint_getMotorSpeed }, { "setMaxMotorTorque", w_WheelJoint_setMaxMotorTorque },
{ "getMotorForce", w_PrismaticJoint_getMotorForce }, { "getMaxMotorTorque", w_WheelJoint_getMaxMotorTorque },
{ "enableLimit", w_PrismaticJoint_enableLimit }, { "getMotorTorque", w_WheelJoint_getMotorTorque },
{ "isLimitEnabled", w_PrismaticJoint_isLimitEnabled }, { "setSpringFrequencyHz", w_WheelJoint_setSpringFrequencyHz },
{ "setUpperLimit", w_PrismaticJoint_setUpperLimit }, { "getSpringFrequencyHz", w_WheelJoint_getSpringFrequencyHz },
{ "setLowerLimit", w_PrismaticJoint_setLowerLimit }, { "setSpringDampingRatio", w_WheelJoint_setSpringDampingRatio },
{ "setLimits", w_PrismaticJoint_setLimits }, { "getSpringDampingRatio", w_WheelJoint_getSpringDampingRatio },
{ "getLowerLimit", w_PrismaticJoint_getLowerLimit },
{ "getUpperLimit", w_PrismaticJoint_getUpperLimit },
{ "getLimits", w_PrismaticJoint_getLimits },
// From Joint. // From Joint.
{ "getType", w_Joint_getType }, { "getType", w_Joint_getType },
{ "getAnchors", w_Joint_getAnchors }, { "getAnchors", w_Joint_getAnchors },
@@ -178,9 +152,9 @@ namespace box2d
{ 0, 0 } { 0, 0 }
}; };
int luaopen_prismaticjoint(lua_State * L) int luaopen_wheeljoint(lua_State * L)
{ {
return luax_register_type(L, "PrismaticJoint", functions); return luax_register_type(L, "WheelJoint", functions);
} }
} // box2d } // box2d
+19 -22
View File
@@ -18,13 +18,13 @@
* 3. This notice may not be removed or altered from any source distribution. * 3. This notice may not be removed or altered from any source distribution.
**/ **/
#ifndef LOVE_PHYSICS_BOX2D_WRAP_PRISMATIC_JOINT_H #ifndef LOVE_PHYSICS_BOX2D_WRAP_WHEEL_JOINT_H
#define LOVE_PHYSICS_BOX2D_WRAP_PRISMATIC_JOINT_H #define LOVE_PHYSICS_BOX2D_WRAP_WHEEL_JOINT_H
// LOVE // LOVE
#include <common/runtime.h> #include <common/runtime.h>
#include "wrap_Joint.h" #include "wrap_Joint.h"
#include "PrismaticJoint.h" #include "WheelJoint.h"
namespace love namespace love
{ {
@@ -32,27 +32,24 @@ namespace physics
{ {
namespace box2d namespace box2d
{ {
PrismaticJoint * luax_checkprismaticjoint(lua_State * L, int idx); WheelJoint * luax_checkwheeljoint(lua_State * L, int idx);
int w_PrismaticJoint_getJointTranslation(lua_State * L); int w_WheelJoint_getJointTranslation(lua_State * L);
int w_PrismaticJoint_getJointSpeed(lua_State * L); int w_WheelJoint_getJointSpeed(lua_State * L);
int w_PrismaticJoint_enableMotor(lua_State * L); int w_WheelJoint_enableMotor(lua_State * L);
int w_PrismaticJoint_isMotorEnabled(lua_State * L); int w_WheelJoint_isMotorEnabled(lua_State * L);
int w_PrismaticJoint_setMaxMotorForce(lua_State * L); int w_WheelJoint_setMotorSpeed(lua_State * L);
int w_PrismaticJoint_setMotorSpeed(lua_State * L); int w_WheelJoint_getMotorSpeed(lua_State * L);
int w_PrismaticJoint_getMotorSpeed(lua_State * L); int w_WheelJoint_setMaxMotorTorque(lua_State * L);
int w_PrismaticJoint_getMotorForce(lua_State * L); int w_WheelJoint_getMaxMotorTorque(lua_State * L);
int w_PrismaticJoint_enableLimit(lua_State * L); int w_WheelJoint_getMotorTorque(lua_State * L);
int w_PrismaticJoint_isLimitEnabled(lua_State * L); int w_WheelJoint_setSpringFrequencyHz(lua_State * L);
int w_PrismaticJoint_setUpperLimit(lua_State * L); int w_WheelJoint_getSpringFrequencyHz(lua_State * L);
int w_PrismaticJoint_setLowerLimit(lua_State * L); int w_WheelJoint_setSpringDampingRatio(lua_State * L);
int w_PrismaticJoint_setLimits(lua_State * L); int w_WheelJoint_getSpringDampingRatio(lua_State * L);
int w_PrismaticJoint_getLowerLimit(lua_State * L); int luaopen_wheeljoint(lua_State * L);
int w_PrismaticJoint_getUpperLimit(lua_State * L);
int w_PrismaticJoint_getLimits(lua_State * L);
int luaopen_prismaticjoint(lua_State * L);
} // box2d } // box2d
} // physics } // physics
} // love } // love
#endif // LOVE_PHYSICS_BOX2D_WRAP_PRISMATIC_JOINT_H #endif // LOVE_PHYSICS_BOX2D_WRAP_WHEEL_JOINT_H