From 7ec64bf912a41e4b3858f16d894a049d42000717 Mon Sep 17 00:00:00 2001 From: Bill Meltsner Date: Sun, 4 Sep 2011 13:21:57 -0400 Subject: [PATCH] Add basic EdgeShape (todo: all edge-related functionality) and further integrated the new Joints --HG-- branch : box2d-update --- .../macosx/love.xcodeproj/project.pbxproj | 12 ++ src/modules/physics/box2d/CircleShape.cpp | 5 +- src/modules/physics/box2d/EdgeShape.cpp | 44 +++++ src/modules/physics/box2d/EdgeShape.h | 54 ++++++ src/modules/physics/box2d/Physics.cpp | 39 ++-- src/modules/physics/box2d/Physics.h | 43 +++-- src/modules/physics/box2d/Shape.cpp | 4 + src/modules/physics/box2d/wrap_EdgeShape.cpp | 48 +++++ src/modules/physics/box2d/wrap_EdgeShape.h | 42 +++++ src/modules/physics/box2d/wrap_Physics.cpp | 33 +++- src/modules/physics/box2d/wrap_Physics.h | 7 +- src/modules/physics/box2d/wrap_WheelJoint.cpp | 168 ++++++++---------- src/modules/physics/box2d/wrap_WheelJoint.h | 41 ++--- 13 files changed, 384 insertions(+), 156 deletions(-) create mode 100644 src/modules/physics/box2d/EdgeShape.cpp create mode 100644 src/modules/physics/box2d/EdgeShape.h create mode 100644 src/modules/physics/box2d/wrap_EdgeShape.cpp create mode 100644 src/modules/physics/box2d/wrap_EdgeShape.h diff --git a/platform/macosx/love.xcodeproj/project.pbxproj b/platform/macosx/love.xcodeproj/project.pbxproj index 77cba2653..0b351b637 100644 --- a/platform/macosx/love.xcodeproj/project.pbxproj +++ b/platform/macosx/love.xcodeproj/project.pbxproj @@ -163,6 +163,8 @@ A96F41861412AFF80067FE9A /* WeldJoint.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A96F41841412AFEB0067FE9A /* WeldJoint.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 */; }; + 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 */; }; A986DEB6113249A800810279 /* wrap_Thread.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A986DEB3113249A800810279 /* wrap_Thread.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 = ""; }; A96F418A1412B3A30067FE9A /* WheelJoint.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WheelJoint.cpp; sourceTree = ""; }; A96F418B1412B3A80067FE9A /* WheelJoint.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WheelJoint.h; sourceTree = ""; }; + A96F41A21412C91E0067FE9A /* EdgeShape.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = EdgeShape.cpp; sourceTree = ""; }; + A96F41A31412C91E0067FE9A /* EdgeShape.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EdgeShape.h; sourceTree = ""; }; + A96F41A51412C92B0067FE9A /* wrap_EdgeShape.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = wrap_EdgeShape.cpp; sourceTree = ""; }; + A96F41A61412C92B0067FE9A /* wrap_EdgeShape.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = wrap_EdgeShape.h; sourceTree = ""; }; A97E3842132A9EDE00198A2F /* love-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "love-Info.plist"; sourceTree = ""; }; A986DEB1113249A800810279 /* Thread.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Thread.cpp; sourceTree = ""; }; A986DEB2113249A800810279 /* Thread.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Thread.h; sourceTree = ""; }; @@ -1195,6 +1201,8 @@ A93E6AF010420AC7007D418B /* Contact.h */, A93E6AF110420AC7007D418B /* DistanceJoint.cpp */, A93E6AF210420AC7007D418B /* DistanceJoint.h */, + A96F41A21412C91E0067FE9A /* EdgeShape.cpp */, + A96F41A31412C91E0067FE9A /* EdgeShape.h */, A986ECAD132CEB9300F048C8 /* Fixture.cpp */, A986ECAE132CEB9B00F048C8 /* Fixture.h */, A9B6432A13BF833900DC3C7E /* FrictionJoint.cpp */, @@ -1232,6 +1240,8 @@ A93E6B5510420ACA007D418B /* wrap_Contact.h */, A93E6B5610420ACA007D418B /* wrap_DistanceJoint.cpp */, A93E6B5710420ACA007D418B /* wrap_DistanceJoint.h */, + A96F41A51412C92B0067FE9A /* wrap_EdgeShape.cpp */, + A96F41A61412C92B0067FE9A /* wrap_EdgeShape.h */, A9B6432D13BF87E400DC3C7E /* wrap_FrictionJoint.cpp */, A9B6432E13BF87EA00DC3C7E /* wrap_FrictionJoint.h */, A93E6B5810420ACA007D418B /* wrap_GearJoint.cpp */, @@ -1786,6 +1796,8 @@ A96F41861412AFF80067FE9A /* WeldJoint.cpp in Sources */, A96F41891412B36D0067FE9A /* wrap_WheelJoint.cpp in Sources */, A96F418C1412B3AD0067FE9A /* WheelJoint.cpp in Sources */, + A96F41A41412C91F0067FE9A /* EdgeShape.cpp in Sources */, + A96F41A71412C92B0067FE9A /* wrap_EdgeShape.cpp in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/src/modules/physics/box2d/CircleShape.cpp b/src/modules/physics/box2d/CircleShape.cpp index 3fa88e1d0..d8b619799 100644 --- a/src/modules/physics/box2d/CircleShape.cpp +++ b/src/modules/physics/box2d/CircleShape.cpp @@ -44,10 +44,7 @@ namespace box2d { return shape->m_radius; } - - /** - * Gets the radius for the circle. - **/ + void CircleShape::setRadius(float r) { shape->m_radius = r; diff --git a/src/modules/physics/box2d/EdgeShape.cpp b/src/modules/physics/box2d/EdgeShape.cpp new file mode 100644 index 000000000..196ea9940 --- /dev/null +++ b/src/modules/physics/box2d/EdgeShape.cpp @@ -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 diff --git a/src/modules/physics/box2d/EdgeShape.h b/src/modules/physics/box2d/EdgeShape.h new file mode 100644 index 000000000..67569b51b --- /dev/null +++ b/src/modules/physics/box2d/EdgeShape.h @@ -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 diff --git a/src/modules/physics/box2d/Physics.cpp b/src/modules/physics/box2d/Physics.cpp index 40fd67f12..20a584021 100644 --- a/src/modules/physics/box2d/Physics.cpp +++ b/src/modules/physics/box2d/Physics.cpp @@ -62,30 +62,27 @@ namespace box2d 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; - def.density = 1.0f; - def.localPosition.Set(x, y); - def.friction = 0.5f; - def.restitution = 0.1f; - def.radius = radius; - return new CircleShape(body, &def); + b2CircleShape s; + s.m_p = b2Vec2(x, y); + s.m_radius = radius; + return new CircleShape(&s); } 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) { - 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) @@ -95,11 +92,11 @@ namespace box2d 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; - s.SetAsEdge(b2vec2(x1, y1), b2vec2(x2, y2)); - return new PolygonShape(&s); + b2EdgeShape s; + s.Set(b2Vec2(x1, y1), b2Vec2(x2, y2)); + return new EdgeShape(&s); } int Physics::newPolygonShape(lua_State * L) @@ -181,6 +178,16 @@ namespace box2d { 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 } // physics diff --git a/src/modules/physics/box2d/Physics.h b/src/modules/physics/box2d/Physics.h index 6f631cd97..9e78e14de 100644 --- a/src/modules/physics/box2d/Physics.h +++ b/src/modules/physics/box2d/Physics.h @@ -29,6 +29,7 @@ #include "Shape.h" #include "CircleShape.h" #include "PolygonShape.h" +#include "EdgeShape.h" #include "Joint.h" #include "MouseJoint.h" #include "DistanceJoint.h" @@ -37,6 +38,8 @@ #include "PulleyJoint.h" #include "GearJoint.h" #include "FrictionJoint.h" +#include "WeldJoint.h" +#include "WheelJoint.h" namespace love { @@ -89,15 +92,13 @@ namespace box2d Body * newBody(World * world); /** - * Creates a new CircleShape at the Body origin. - * @param body The Body to create the Shape on. + * Creates a new CircleShape at (0, 0). * @param radius The radius of the circle. **/ CircleShape * newCircleShape(float radius); /** - * Creates a new CircleShape at (x,y) in local coorinates. - * @param body The Body to create the Shape on. + * Creates a new CircleShape at (x,y) in local coordinates. * @param x The offset along the x-axis. * @param y The offset along the y-axis. * @param radius The radius of the circle. @@ -134,19 +135,17 @@ namespace box2d PolygonShape * newRectangleShape(float x, float y, float w, float h, float angle); /** - * Shorthand for creating edge PolygonShapes. The edge - * will be created at (x,y) in local coordinates. - * @param x The offset along the x-axis. - * @param y The offset along the y-axis. - * @param w The width of the rectangle. - * @param h The height of the rectangle. - * @param angle The angle of the rectangle. (rad) - **/ - PolygonShape * newEdgeShape(float x1, float y1, float x2, float y2); + * Creates a new EdgeShape. The edge will be created from + * (x1,y1) to (x2,y2) in local coordinates. + * @param x1 The x coordinate of the first point. + * @param y1 The y coordinate of the first point. + * @param x2 The x coordinate of the second point. + * @param y2 The y coordinate of the second point. + **/ + EdgeShape * newEdgeShape(float x1, float y1, float x2, float y2); /** * Creates a new PolygonShape. - * @param body The body to create this shape on. * @param ... A variable number of vertices. **/ int newPolygonShape(lua_State * L); @@ -207,6 +206,22 @@ namespace box2d * @param y Anchor along the y-axis. (World coordinates) **/ 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 diff --git a/src/modules/physics/box2d/Shape.cpp b/src/modules/physics/box2d/Shape.cpp index c3d30854c..e5ab9f7c7 100644 --- a/src/modules/physics/box2d/Shape.cpp +++ b/src/modules/physics/box2d/Shape.cpp @@ -51,6 +51,10 @@ namespace box2d return SHAPE_CIRCLE; case b2Shape::e_polygon: return SHAPE_POLYGON; + case b2Shape::e_edge: + return SHAPE_EDGE; + case b2Shape::e_chain: + return SHAPE_CHAIN; default: return SHAPE_INVALID; } diff --git a/src/modules/physics/box2d/wrap_EdgeShape.cpp b/src/modules/physics/box2d/wrap_EdgeShape.cpp new file mode 100644 index 000000000..be64c4feb --- /dev/null +++ b/src/modules/physics/box2d/wrap_EdgeShape.cpp @@ -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(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 diff --git a/src/modules/physics/box2d/wrap_EdgeShape.h b/src/modules/physics/box2d/wrap_EdgeShape.h new file mode 100644 index 000000000..4b9cba3b4 --- /dev/null +++ b/src/modules/physics/box2d/wrap_EdgeShape.h @@ -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 +#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 diff --git a/src/modules/physics/box2d/wrap_Physics.cpp b/src/modules/physics/box2d/wrap_Physics.cpp index 434b4fa61..78508fe3c 100644 --- a/src/modules/physics/box2d/wrap_Physics.cpp +++ b/src/modules/physics/box2d/wrap_Physics.cpp @@ -118,8 +118,8 @@ namespace box2d float y1 = (float)luaL_checknumber(L, 2); float x2 = (float)luaL_checknumber(L, 3); float y2 = (float)luaL_checknumber(L, 4); - PolygonShape * shape = instance->newEdgeShape(x1, y1, x2, y2); - luax_newtype(L, "PolygonShape", PHYSICS_POLYGON_SHAPE_T, (void*)shape); + EdgeShape * shape = instance->newEdgeShape(x1, y1, x2, y2); + luax_newtype(L, "EdgeShape", PHYSICS_EDGE_SHAPE_T, (void*)shape); return 1; } @@ -215,6 +215,30 @@ namespace box2d luax_newtype(L, "FrictionJoint", PHYSICS_FRICTION_JOINT_T, (void*)j); return 1; } + + int w_newWeldJoint(lua_State * L) + { + Body * body1 = luax_checktype(L, 1, "Body", PHYSICS_BODY_T); + Body * body2 = luax_checktype(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(L, 1, "Body", PHYSICS_BODY_T); + Body * body2 = luax_checktype(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. static const luaL_Reg functions[] = { @@ -223,6 +247,7 @@ namespace box2d { "newCircleShape", w_newCircleShape }, { "newRectangleShape", w_newRectangleShape }, { "newPolygonShape", w_newPolygonShape }, + { "newEdgeShape", w_newEdgeShape }, { "newDistanceJoint", w_newDistanceJoint }, { "newMouseJoint", w_newMouseJoint }, { "newRevoluteJoint", w_newRevoluteJoint }, @@ -230,6 +255,8 @@ namespace box2d { "newPulleyJoint", w_newPulleyJoint }, { "newGearJoint", w_newGearJoint }, { "newFrictionJoint", w_newFrictionJoint }, + { "newWeldJoint", w_newWeldJoint }, + { "newWheelJoint", w_newWheelJoint }, { 0, 0 }, }; @@ -240,6 +267,7 @@ namespace box2d luaopen_shape, luaopen_circleshape, luaopen_polygonshape, + luaopen_edgeshape, luaopen_joint, luaopen_mousejoint, luaopen_distancejoint, @@ -248,6 +276,7 @@ namespace box2d luaopen_pulleyjoint, luaopen_gearjoint, luaopen_frictionjoint, + luaopen_weldjoint, 0 }; diff --git a/src/modules/physics/box2d/wrap_Physics.h b/src/modules/physics/box2d/wrap_Physics.h index bdf1bfee3..fb715d32b 100644 --- a/src/modules/physics/box2d/wrap_Physics.h +++ b/src/modules/physics/box2d/wrap_Physics.h @@ -30,6 +30,7 @@ #include "wrap_Shape.h" #include "wrap_CircleShape.h" #include "wrap_PolygonShape.h" +#include "wrap_EdgeShape.h" #include "wrap_Joint.h" #include "wrap_MouseJoint.h" #include "wrap_DistanceJoint.h" @@ -38,6 +39,8 @@ #include "wrap_PulleyJoint.h" #include "wrap_GearJoint.h" #include "wrap_FrictionJoint.h" +#include "wrap_WeldJoint.h" +#include "wrap_WheelJoint.h" namespace love { @@ -49,8 +52,8 @@ namespace box2d int w_newBody(lua_State * L); int w_newCircleShape(lua_State * L); int w_newRectangleShape(lua_State * L); - int w_newEdgeShape(lua_State * L); int w_newPolygonShape(lua_State * L); + int w_newEdgeShape(lua_State * L); int w_newDistanceJoint(lua_State * L); int w_newMouseJoint(lua_State * L); int w_newRevoluteJoint(lua_State * L); @@ -58,6 +61,8 @@ namespace box2d int w_newPulleyJoint(lua_State * L); int w_newGearJoint(lua_State * L); int w_newFrictionJoint(lua_State * L); + int w_newWeldJoint(lua_State * L); + int w_newWheelJoint(lua_State * L); extern "C" LOVE_EXPORT int luaopen_love_physics(lua_State * L); } // box2d diff --git a/src/modules/physics/box2d/wrap_WheelJoint.cpp b/src/modules/physics/box2d/wrap_WheelJoint.cpp index bffd37a56..abd4561ba 100644 --- a/src/modules/physics/box2d/wrap_WheelJoint.cpp +++ b/src/modules/physics/box2d/wrap_WheelJoint.cpp @@ -18,7 +18,7 @@ * 3. This notice may not be removed or altered from any source distribution. **/ -#include "wrap_PrismaticJoint.h" +#include "wrap_WheelJoint.h" namespace love { @@ -26,148 +26,122 @@ namespace physics { namespace box2d { - PrismaticJoint * luax_checkprismaticjoint(lua_State * L, int idx) + WheelJoint * luax_checkwheeljoint(lua_State * L, int idx) { - return luax_checktype(L, idx, "PrismaticJoint", PHYSICS_PRISMATIC_JOINT_T); + return luax_checktype(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()); 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()); 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); t->enableMotor(arg1); 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()); return 1; } - int w_PrismaticJoint_setMaxMotorForce(lua_State * L) + int w_WheelJoint_setMotorSpeed(lua_State * L) { - PrismaticJoint * t = luax_checkprismaticjoint(L, 1); - float arg1 = (float)luaL_checknumber(L, 2); - t->setMaxMotorForce(arg1); - return 0; - } - - int w_PrismaticJoint_setMotorSpeed(lua_State * L) - { - PrismaticJoint * t = luax_checkprismaticjoint(L, 1); + WheelJoint * t = luax_checkwheeljoint(L, 1); float arg1 = (float)luaL_checknumber(L, 2); t->setMotorSpeed(arg1); 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()); return 1; } - - int w_PrismaticJoint_getMotorForce(lua_State * L) + + int w_WheelJoint_setMaxMotorTorque(lua_State * L) { - PrismaticJoint * t = luax_checkprismaticjoint(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); + WheelJoint * t = luax_checkwheeljoint(L, 1); float arg1 = (float)luaL_checknumber(L, 2); - t->setUpperLimit(arg1); + t->setMaxMotorTorque(arg1); return 0; } - - int w_PrismaticJoint_setLowerLimit(lua_State * L) + + int w_WheelJoint_getMaxMotorTorque(lua_State * L) { - PrismaticJoint * t = luax_checkprismaticjoint(L, 1); - float arg1 = (float)luaL_checknumber(L, 2); - t->setLowerLimit(arg1); - return 0; - } - - int w_PrismaticJoint_setLimits(lua_State * L) - { - PrismaticJoint * t = luax_checkprismaticjoint(L, 1); - float arg1 = (float)luaL_checknumber(L, 2); - float arg2 = (float)luaL_checknumber(L, 3); - t->setLimits(arg1, arg2); - return 0; - } - - int w_PrismaticJoint_getLowerLimit(lua_State * L) - { - PrismaticJoint * t = luax_checkprismaticjoint(L, 1); - lua_pushnumber(L, t->getLowerLimit()); + WheelJoint * t = luax_checkwheeljoint(L, 1); + lua_pushnumber(L, t->getMaxMotorTorque()); return 1; } - - int w_PrismaticJoint_getUpperLimit(lua_State * L) + + int w_WheelJoint_getMotorTorque(lua_State * L) { - PrismaticJoint * t = luax_checkprismaticjoint(L, 1); - lua_pushnumber(L, t->getUpperLimit()); + WheelJoint * t = luax_checkwheeljoint(L, 1); + float inv_dt = (float)luaL_checknumber(L, 2); + lua_pushnumber(L, t->getMotorTorque(inv_dt)); return 1; } - - int w_PrismaticJoint_getLimits(lua_State * L) + + int w_WheelJoint_setSpringFrequencyHz(lua_State * L) { - PrismaticJoint * t = luax_checkprismaticjoint(L, 1); - lua_remove(L, 1); - return t->getLimits(L); + WheelJoint * t = luax_checkwheeljoint(L, 1); + float arg1 = (float)luaL_checknumber(L, 2); + 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[] = { - { "getJointTranslation", w_PrismaticJoint_getJointTranslation }, - { "getJointSpeed", w_PrismaticJoint_getJointSpeed }, - { "enableMotor", w_PrismaticJoint_enableMotor }, - { "isMotorEnabled", w_PrismaticJoint_isMotorEnabled }, - { "setMaxMotorForce", w_PrismaticJoint_setMaxMotorForce }, - { "setMotorSpeed", w_PrismaticJoint_setMotorSpeed }, - { "getMotorSpeed", w_PrismaticJoint_getMotorSpeed }, - { "getMotorForce", w_PrismaticJoint_getMotorForce }, - { "enableLimit", w_PrismaticJoint_enableLimit }, - { "isLimitEnabled", w_PrismaticJoint_isLimitEnabled }, - { "setUpperLimit", w_PrismaticJoint_setUpperLimit }, - { "setLowerLimit", w_PrismaticJoint_setLowerLimit }, - { "setLimits", w_PrismaticJoint_setLimits }, - { "getLowerLimit", w_PrismaticJoint_getLowerLimit }, - { "getUpperLimit", w_PrismaticJoint_getUpperLimit }, - { "getLimits", w_PrismaticJoint_getLimits }, + { "getJointTranslation", w_WheelJoint_getJointTranslation }, + { "getJointSpeed", w_WheelJoint_getJointSpeed }, + { "enableMotor", w_WheelJoint_enableMotor }, + { "isMotorEnabled", w_WheelJoint_isMotorEnabled }, + { "setMotorSpeed", w_WheelJoint_setMotorSpeed }, + { "getMotorSpeed", w_WheelJoint_getMotorSpeed }, + { "setMaxMotorTorque", w_WheelJoint_setMaxMotorTorque }, + { "getMaxMotorTorque", w_WheelJoint_getMaxMotorTorque }, + { "getMotorTorque", w_WheelJoint_getMotorTorque }, + { "setSpringFrequencyHz", w_WheelJoint_setSpringFrequencyHz }, + { "getSpringFrequencyHz", w_WheelJoint_getSpringFrequencyHz }, + { "setSpringDampingRatio", w_WheelJoint_setSpringDampingRatio }, + { "getSpringDampingRatio", w_WheelJoint_getSpringDampingRatio }, // From Joint. { "getType", w_Joint_getType }, { "getAnchors", w_Joint_getAnchors }, @@ -178,9 +152,9 @@ namespace box2d { 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 diff --git a/src/modules/physics/box2d/wrap_WheelJoint.h b/src/modules/physics/box2d/wrap_WheelJoint.h index 203edaea7..b31a5be87 100644 --- a/src/modules/physics/box2d/wrap_WheelJoint.h +++ b/src/modules/physics/box2d/wrap_WheelJoint.h @@ -18,13 +18,13 @@ * 3. This notice may not be removed or altered from any source distribution. **/ -#ifndef LOVE_PHYSICS_BOX2D_WRAP_PRISMATIC_JOINT_H -#define LOVE_PHYSICS_BOX2D_WRAP_PRISMATIC_JOINT_H +#ifndef LOVE_PHYSICS_BOX2D_WRAP_WHEEL_JOINT_H +#define LOVE_PHYSICS_BOX2D_WRAP_WHEEL_JOINT_H // LOVE #include #include "wrap_Joint.h" -#include "PrismaticJoint.h" +#include "WheelJoint.h" namespace love { @@ -32,27 +32,24 @@ namespace physics { namespace box2d { - PrismaticJoint * luax_checkprismaticjoint(lua_State * L, int idx); - int w_PrismaticJoint_getJointTranslation(lua_State * L); - int w_PrismaticJoint_getJointSpeed(lua_State * L); - int w_PrismaticJoint_enableMotor(lua_State * L); - int w_PrismaticJoint_isMotorEnabled(lua_State * L); - int w_PrismaticJoint_setMaxMotorForce(lua_State * L); - int w_PrismaticJoint_setMotorSpeed(lua_State * L); - int w_PrismaticJoint_getMotorSpeed(lua_State * L); - int w_PrismaticJoint_getMotorForce(lua_State * L); - int w_PrismaticJoint_enableLimit(lua_State * L); - int w_PrismaticJoint_isLimitEnabled(lua_State * L); - int w_PrismaticJoint_setUpperLimit(lua_State * L); - int w_PrismaticJoint_setLowerLimit(lua_State * L); - int w_PrismaticJoint_setLimits(lua_State * L); - int w_PrismaticJoint_getLowerLimit(lua_State * L); - int w_PrismaticJoint_getUpperLimit(lua_State * L); - int w_PrismaticJoint_getLimits(lua_State * L); - int luaopen_prismaticjoint(lua_State * L); + WheelJoint * luax_checkwheeljoint(lua_State * L, int idx); + int w_WheelJoint_getJointTranslation(lua_State * L); + int w_WheelJoint_getJointSpeed(lua_State * L); + int w_WheelJoint_enableMotor(lua_State * L); + int w_WheelJoint_isMotorEnabled(lua_State * L); + int w_WheelJoint_setMotorSpeed(lua_State * L); + int w_WheelJoint_getMotorSpeed(lua_State * L); + int w_WheelJoint_setMaxMotorTorque(lua_State * L); + int w_WheelJoint_getMaxMotorTorque(lua_State * L); + int w_WheelJoint_getMotorTorque(lua_State * L); + int w_WheelJoint_setSpringFrequencyHz(lua_State * L); + int w_WheelJoint_getSpringFrequencyHz(lua_State * L); + int w_WheelJoint_setSpringDampingRatio(lua_State * L); + int w_WheelJoint_getSpringDampingRatio(lua_State * L); + int luaopen_wheeljoint(lua_State * L); } // box2d } // physics } // love -#endif // LOVE_PHYSICS_BOX2D_WRAP_PRISMATIC_JOINT_H +#endif // LOVE_PHYSICS_BOX2D_WRAP_WHEEL_JOINT_H