Skip to content

Commit

Permalink
MOAIBox2DWheelJoint: fixes unit conversion to match what box2d states…
Browse files Browse the repository at this point in the history
… it is meters typically except motor speed as angle/s^2
  • Loading branch information
harningt committed Jan 8, 2012
1 parent 10f72d0 commit 409c69c
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/moaicore/MOAIBox2DWheelJoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,14 +147,15 @@ int MOAIBox2DWheelJoint::_getSpringDampingRatio ( lua_State* L ) {
*/
int MOAIBox2DWheelJoint::_getMaxMotorTorque ( lua_State* L ) {
MOAI_LUA_SETUP ( MOAIBox2DWheelJoint, "U" )

float unitsToMeters = self->GetUnitsToMeters ();

if ( !self->mJoint ) {
MOAILog ( state, MOAILogMessages::MOAIBox2DJoint_MissingInstance );
return 0;
}

b2WheelJoint* joint = ( b2WheelJoint* )self->mJoint;
state.Push ( joint->GetMaxMotorTorque () * ( float )R2D );
state.Push ( joint->GetMaxMotorTorque () / unitsToMeters );

return 1;
}
Expand All @@ -168,15 +169,16 @@ int MOAIBox2DWheelJoint::_getMaxMotorTorque ( lua_State* L ) {
*/
int MOAIBox2DWheelJoint::_getMotorTorque ( lua_State* L ) {
MOAI_LUA_SETUP ( MOAIBox2DWheelJoint, "U" )

float unitsToMeters = self->GetUnitsToMeters ();

if ( !self->mJoint ) {
MOAILog ( state, MOAILogMessages::MOAIBox2DJoint_MissingInstance );
return 0;
}

b2WheelJoint* joint = ( b2WheelJoint* )self->mJoint;
float step = ( float )( 1.0 / MOAISim::Get ().GetStep ());
state.Push ( joint->GetMotorTorque (step) * ( float )R2D );
state.Push ( joint->GetMotorTorque (step) / unitsToMeters );

return 1;
}
Expand Down Expand Up @@ -259,13 +261,14 @@ int MOAIBox2DWheelJoint::_setMotorEnabled ( lua_State* L ) {
*/
int MOAIBox2DWheelJoint::_setMaxMotorTorque ( lua_State* L ) {
MOAI_LUA_SETUP ( MOAIBox2DWheelJoint, "U" )

float unitsToMeters = self->GetUnitsToMeters ();

if ( !self->mJoint ) {
MOAILog ( state, MOAILogMessages::MOAIBox2DJoint_MissingInstance );
return 0;
}

float maxMotorTorque = state.GetValue < float >( 2, 0.0f ) * ( float )D2R;
float maxMotorTorque = state.GetValue < float >( 2, 0.0f ) * unitsToMeters;

b2WheelJoint* joint = ( b2WheelJoint* )self->mJoint;
joint->SetMaxMotorTorque ( maxMotorTorque );
Expand Down

0 comments on commit 409c69c

Please sign in to comment.