Browse Source

Do the same for WheelJoint

--HG--
branch : box2d-update
Bill Meltsner 14 years ago
parent
commit
d4703960a4

+ 2 - 2
src/modules/physics/box2d/Physics.cpp

@@ -192,9 +192,9 @@ namespace box2d
 		return new WeldJoint(body1, body2, x, y, collideConnected);
 	}
 	
-	WheelJoint * Physics::newWheelJoint(Body * body1, Body * body2, float x, float y, float ax, float ay, bool collideConnected)
+	WheelJoint * Physics::newWheelJoint(Body * body1, Body * body2, float xA, float yA, float xB, float yB, float ax, float ay, bool collideConnected)
 	{
-		return new WheelJoint(body1, body2, x, y, ax, ay, collideConnected);
+		return new WheelJoint(body1, body2, xA, yA, xB, yB, ax, ay, collideConnected);
 	}
 	
 	RopeJoint * Physics::newRopeJoint(Body * body1, Body * body2, float x1, float y1, float x2, float y2, float maxLength, bool collideConnected)

+ 5 - 3
src/modules/physics/box2d/Physics.h

@@ -231,13 +231,15 @@ namespace box2d
 		
 		/**
 		* 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 xA Anchor for body 1 along the x-axis. (World coordinates)
+		* @param yA Anchor for body 1 along the y-axis. (World coordinates)
+		* @param xB Anchor for body 2 along the x-axis. (World coordinates)
+		* @param yB Anchor for body 2 along the y-axis. (World coordinates)
 		* @param ax The x-component of the world-axis.
 		* @param ay The y-component of the world-axis.
 		* @param collideConnected Whether the connected bodies should collide with each other. Defaults to false.
 		**/
-		WheelJoint * newWheelJoint(Body * body1, Body * body2, float x, float y, float ax, float ay, bool collideConnected);
+		WheelJoint * newWheelJoint(Body * body1, Body * body2, float xA, float yA, float xB, float yB, float ax, float ay, bool collideConnected);
 		
 		/**
 		* Creates a new RopeJoint connecting body1 with body2.

+ 5 - 4
src/modules/physics/box2d/WheelJoint.cpp

@@ -31,12 +31,13 @@ namespace physics
 {
 namespace box2d
 {
-	WheelJoint::WheelJoint(Body * body1, Body * body2, float x, float y, float ax, float ay, bool collideConnected)
+	WheelJoint::WheelJoint(Body * body1, Body * body2, float xA, float yA, float xB, float yB, float ax, float ay, bool collideConnected)
 		: Joint(body1, body2), joint(NULL)
 	{
 		b2WheelJointDef def;
 		
-		def.Initialize(body1->body, body2->body, Physics::scaleDown(b2Vec2(x,y)), b2Vec2(ax,ay));
+		def.Initialize(body1->body, body2->body, Physics::scaleDown(b2Vec2(xA,yA)), b2Vec2(ax,ay));
+		def.localAnchorB = body2->body->GetLocalPoint(Physics::scaleDown(b2Vec2(xB, yB)));
 		def.collideConnected = collideConnected;
 		joint = (b2WheelJoint*)createJoint(&def);
 	}
@@ -49,12 +50,12 @@ namespace box2d
 
 	float WheelJoint::getJointTranslation() const
 	{
-		return Physics::scaleDown(joint->GetJointTranslation());
+		return Physics::scaleUp(joint->GetJointTranslation());
 	}
 
 	float WheelJoint::getJointSpeed() const
 	{
-		return Physics::scaleDown(joint->GetJointSpeed());
+		return Physics::scaleUp(joint->GetJointSpeed());
 	}
 
 	void WheelJoint::enableMotor(bool motor)

+ 1 - 1
src/modules/physics/box2d/WheelJoint.h

@@ -47,7 +47,7 @@ namespace box2d
 		/**
 		* Creates a new WheelJoint connecting body1 and body2.
 		**/
-		WheelJoint(Body * body1, Body * body2, float x, float y, float ax, float ay, bool collideConnected);
+		WheelJoint(Body * body1, Body * body2, float xA, float yA, float xB, float yB, float ax, float ay, bool collideConnected);
 
 		virtual ~WheelJoint();
 

+ 19 - 6
src/modules/physics/box2d/wrap_Physics.cpp

@@ -258,12 +258,25 @@ namespace box2d
 	{
 		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);
-		bool collideConnected = luax_optboolean(L, 7, false);
-		WheelJoint * j = instance->newWheelJoint(body1, body2, x, y, ax, ay, collideConnected);
+		float xA = (float)luaL_checknumber(L, 3);
+		float yA = (float)luaL_checknumber(L, 4);
+		float xB, yB, ax, ay;
+		bool collideConnected;
+		if (lua_gettop(L) >= 8) {
+			xB = (float)luaL_checknumber(L, 5);
+			yB = (float)luaL_checknumber(L, 6);
+			ax = (float)luaL_checknumber(L, 7);
+			ay = (float)luaL_checknumber(L, 8);
+			collideConnected = luax_optboolean(L, 9, false);
+		} else {
+			xB = xA;
+			yB = yA;
+			ax = (float)luaL_checknumber(L, 5);
+			ay = (float)luaL_checknumber(L, 6);
+			collideConnected = luax_optboolean(L, 7, false);
+		}
+
+		WheelJoint * j = instance->newWheelJoint(body1, body2, xA, yA, xB, yB, ax, ay, collideConnected);
 		luax_newtype(L, "WheelJoint", PHYSICS_WHEEL_JOINT_T, (void*)j);
 		return 1;
 	}