Browse Source

Expose axis vector of PrismaticJoint and WheelJoint (fixes #1176)

airstruck 9 years ago
parent
commit
24da8433d0

+ 1 - 0
changes.txt

@@ -6,6 +6,7 @@ Released: N/A
   * Added lovec.exe in Windows. It is the same as love.exe but built with the Console subsystem, so it always uses or provides a console.
   * Added 'shaderswitches' field to the table returned by love.graphics.getStats.
   * Added Quad:getTextureDimensions.
+  * Added PrismaticJoint:getAxis and WheelJoint:getAxis.
 
   * Fixed love on iOS 6.
   * Fixed os.execute always returning -1 on Linux.

+ 6 - 0
src/modules/physics/box2d/PrismaticJoint.cpp

@@ -138,6 +138,12 @@ int PrismaticJoint::getLimits(lua_State *L)
 	return 2;
 }
 
+int PrismaticJoint::getAxis(lua_State *L)
+{
+	lua_pushnumber(L, joint->GetLocalAxisA().x);
+	lua_pushnumber(L, joint->GetLocalAxisA().y);
+	return 2;
+}
 
 } // box2d
 } // physics

+ 7 - 0
src/modules/physics/box2d/PrismaticJoint.h

@@ -134,6 +134,13 @@ public:
 	 **/
 	int getLimits(lua_State *L);
 
+	/**
+	 * Gets the axis unit vector, relative to body1.
+	 * @returns The X component of the axis unit vector.
+	 * @returns The Y component of the axis unit vector.
+	 **/
+	int getAxis(lua_State *L);
+
 private:
 
 	// The Box2D prismatic joint object.

+ 6 - 0
src/modules/physics/box2d/WheelJoint.cpp

@@ -113,6 +113,12 @@ float WheelJoint::getSpringDampingRatio() const
 	return joint->GetSpringDampingRatio();
 }
 
+int WheelJoint::getAxis(lua_State *L)
+{
+	lua_pushnumber(L, joint->GetLocalAxisA().x);
+	lua_pushnumber(L, joint->GetLocalAxisA().y);
+	return 2;
+}
 
 } // box2d
 } // physics

+ 7 - 0
src/modules/physics/box2d/WheelJoint.h

@@ -114,6 +114,13 @@ public:
 	 **/
 	float getSpringDampingRatio() const;
 
+	/**
+	 * Gets the axis unit vector, relative to body1.
+	 * @returns The X component of the axis unit vector.
+	 * @returns The Y component of the axis unit vector.
+	 **/
+	int getAxis(lua_State *L);
+
 private:
 
 	// The Box2D wheel joint object.

+ 8 - 0
src/modules/physics/box2d/wrap_PrismaticJoint.cpp

@@ -164,6 +164,13 @@ int w_PrismaticJoint_getLimits(lua_State *L)
 	return t->getLimits(L);
 }
 
+int w_PrismaticJoint_getAxis(lua_State *L)
+{
+	PrismaticJoint *t = luax_checkprismaticjoint(L, 1);
+	lua_remove(L, 1);
+	return t->getAxis(L);
+}
+
 static const luaL_Reg w_PrismaticJoint_functions[] =
 {
 	{ "getJointTranslation", w_PrismaticJoint_getJointTranslation },
@@ -183,6 +190,7 @@ static const luaL_Reg w_PrismaticJoint_functions[] =
 	{ "getLowerLimit", w_PrismaticJoint_getLowerLimit },
 	{ "getUpperLimit", w_PrismaticJoint_getUpperLimit },
 	{ "getLimits", w_PrismaticJoint_getLimits },
+	{ "getAxis", w_PrismaticJoint_getAxis },
 	{ 0, 0 }
 };
 

+ 8 - 0
src/modules/physics/box2d/wrap_WheelJoint.cpp

@@ -132,6 +132,13 @@ int w_WheelJoint_getSpringDampingRatio(lua_State *L)
 	return 1;
 }
 
+int w_WheelJoint_getAxis(lua_State *L)
+{
+	WheelJoint *t = luax_checkwheeljoint(L, 1);
+	lua_remove(L, 1);
+	return t->getAxis(L);
+}
+
 static const luaL_Reg w_WheelJoint_functions[] =
 {
 	{ "getJointTranslation", w_WheelJoint_getJointTranslation },
@@ -147,6 +154,7 @@ static const luaL_Reg w_WheelJoint_functions[] =
 	{ "getSpringFrequency", w_WheelJoint_getSpringFrequency },
 	{ "setSpringDampingRatio", w_WheelJoint_setSpringDampingRatio },
 	{ "getSpringDampingRatio", w_WheelJoint_getSpringDampingRatio },
+	{ "getAxis", w_WheelJoint_getAxis },
 	{ 0, 0 }
 };