From 8a2295d6c1ba8efe3d91c04800908058e3c46f9c Mon Sep 17 00:00:00 2001 From: Thomas Harning Jr Date: Sun, 8 Jan 2012 01:01:55 -0500 Subject: [PATCH 1/7] MOAIBox2DWheelJoint: removes improper unit conversion of spring ratio (ratios have no units) --- src/moaicore/MOAIBox2DWheelJoint.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/moaicore/MOAIBox2DWheelJoint.cpp b/src/moaicore/MOAIBox2DWheelJoint.cpp index 3549926f90..a81b0509b4 100644 --- a/src/moaicore/MOAIBox2DWheelJoint.cpp +++ b/src/moaicore/MOAIBox2DWheelJoint.cpp @@ -127,7 +127,6 @@ int MOAIBox2DWheelJoint::_getMotorSpeed ( lua_State* L ) { */ int MOAIBox2DWheelJoint::_getSpringDampingRatio ( lua_State* L ) { MOAI_LUA_SETUP ( MOAIBox2DWheelJoint, "U" ) - float unitsToMeters = self->GetUnitsToMeters (); if ( !self->mJoint ) { MOAILog ( state, MOAILogMessages::MOAIBox2DJoint_MissingInstance ); @@ -135,7 +134,7 @@ int MOAIBox2DWheelJoint::_getSpringDampingRatio ( lua_State* L ) { } b2WheelJoint* joint = ( b2WheelJoint* )self->mJoint; - state.Push ( joint->GetSpringDampingRatio() / unitsToMeters); + state.Push ( joint->GetSpringDampingRatio() ); return 0; } From b430fd560f08045b45c32a25f13b845eb0c5dfdd Mon Sep 17 00:00:00 2001 From: Thomas Harning Jr Date: Sun, 8 Jan 2012 01:02:39 -0500 Subject: [PATCH 2/7] MOAIBox2DWheelJoint: updates setMotorSpeed to do so --- src/moaicore/MOAIBox2DWheelJoint.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/moaicore/MOAIBox2DWheelJoint.cpp b/src/moaicore/MOAIBox2DWheelJoint.cpp index a81b0509b4..c84484e1a8 100644 --- a/src/moaicore/MOAIBox2DWheelJoint.cpp +++ b/src/moaicore/MOAIBox2DWheelJoint.cpp @@ -217,11 +217,13 @@ int MOAIBox2DWheelJoint::_setMotorSpeed ( lua_State* L ) { MOAILog ( state, MOAILogMessages::MOAIBox2DJoint_MissingInstance ); return 0; } - + + float speed = state.GetValue < float >( 2, 0.0f ) * ( float )D2R; + b2WheelJoint* joint = ( b2WheelJoint* )self->mJoint; - state.Push ( joint->GetSpringFrequencyHz() ); - - return 1; + joint->SetMotorSpeed ( speed ); + + return 0; } //----------------------------------------------------------------// From 6127939aca5a39d65b80b6cf91f6386e9831652a Mon Sep 17 00:00:00 2001 From: Thomas Harning Jr Date: Sun, 8 Jan 2012 01:04:41 -0500 Subject: [PATCH 3/7] MOAIBox2DWheelJoint: fixes off-by-one errors in Lua stack value collection --- src/moaicore/MOAIBox2DWheelJoint.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/moaicore/MOAIBox2DWheelJoint.cpp b/src/moaicore/MOAIBox2DWheelJoint.cpp index c84484e1a8..d21aa8aee1 100644 --- a/src/moaicore/MOAIBox2DWheelJoint.cpp +++ b/src/moaicore/MOAIBox2DWheelJoint.cpp @@ -266,7 +266,7 @@ int MOAIBox2DWheelJoint::_setMaxMotorTorque ( lua_State* L ) { return 0; } - float maxMotorTorque = state.GetValue < float >( 1, 0.0f ) * ( float )D2R; + float maxMotorTorque = state.GetValue < float >( 2, 0.0f ) * ( float )D2R; b2WheelJoint* joint = ( b2WheelJoint* )self->mJoint; joint->SetMaxMotorTorque ( maxMotorTorque ); @@ -290,7 +290,7 @@ int MOAIBox2DWheelJoint::_setSpringDampingRatio ( lua_State* L ) { return 0; } - float dampingRatio = state.GetValue < float >( 1, 0.0f ); + float dampingRatio = state.GetValue < float >( 2, 0.0f ); b2WheelJoint* joint = ( b2WheelJoint* )self->mJoint; joint->SetSpringDampingRatio( dampingRatio ); @@ -314,7 +314,7 @@ int MOAIBox2DWheelJoint::_setSpringFrequencyHz ( lua_State* L ) { return 0; } - float springFrequencyHz = state.GetValue < float >( 1, 0.0f ); + float springFrequencyHz = state.GetValue < float >( 2, 0.0f ); b2WheelJoint* joint = ( b2WheelJoint* )self->mJoint; joint->SetSpringFrequencyHz( springFrequencyHz ); From ab4880f2e99a45d492197bf374891981d8b20b02 Mon Sep 17 00:00:00 2001 From: Thomas Harning Jr Date: Sun, 8 Jan 2012 01:05:10 -0500 Subject: [PATCH 4/7] MOAIBox2DWheelJoint: fixes function return values to properly manage Lua stack --- src/moaicore/MOAIBox2DWheelJoint.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/moaicore/MOAIBox2DWheelJoint.cpp b/src/moaicore/MOAIBox2DWheelJoint.cpp index d21aa8aee1..6be3278032 100644 --- a/src/moaicore/MOAIBox2DWheelJoint.cpp +++ b/src/moaicore/MOAIBox2DWheelJoint.cpp @@ -50,7 +50,7 @@ int MOAIBox2DWheelJoint::_getJointTranslation ( lua_State* L ) { b2WheelJoint* joint = ( b2WheelJoint* )self->mJoint; joint->SetMotorSpeed(speed); - return 1; + return 0; } //----------------------------------------------------------------// @@ -136,7 +136,7 @@ int MOAIBox2DWheelJoint::_getSpringDampingRatio ( lua_State* L ) { b2WheelJoint* joint = ( b2WheelJoint* )self->mJoint; state.Push ( joint->GetSpringDampingRatio() ); - return 0; + return 1; } //----------------------------------------------------------------// From 93d8d1491f1a99960b76289169aba47c6f4e41ce Mon Sep 17 00:00:00 2001 From: Thomas Harning Jr Date: Sun, 8 Jan 2012 01:12:09 -0500 Subject: [PATCH 5/7] MOAIBox2DWheelJoint: updates getJointTranslation to actually return translation --- src/moaicore/MOAIBox2DWheelJoint.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/moaicore/MOAIBox2DWheelJoint.cpp b/src/moaicore/MOAIBox2DWheelJoint.cpp index 6be3278032..ff8436acb6 100644 --- a/src/moaicore/MOAIBox2DWheelJoint.cpp +++ b/src/moaicore/MOAIBox2DWheelJoint.cpp @@ -40,15 +40,15 @@ MOAIBox2DWheelJoint::MOAIBox2DWheelJoint () { */ int MOAIBox2DWheelJoint::_getJointTranslation ( lua_State* L ) { MOAI_LUA_SETUP ( MOAIBox2DWheelJoint, "U" ) + float unitsToMeters = self->GetUnitsToMeters (); if ( !self->mJoint ) { MOAILog ( state, MOAILogMessages::MOAIBox2DJoint_MissingInstance ); return 0; } - float speed = state.GetValue < float >( 2, 0.0f ) * ( float )D2R; b2WheelJoint* joint = ( b2WheelJoint* )self->mJoint; - joint->SetMotorSpeed(speed); + state.Push ( joint->GetJointTranslation () / unitsToMeters ); return 0; } From 10f72d04fe857ef885e3e6bb56970ffb51d9c241 Mon Sep 17 00:00:00 2001 From: Thomas Harning Jr Date: Sun, 8 Jan 2012 01:14:01 -0500 Subject: [PATCH 6/7] MOAIBox2DWheelJoint: wheel motor speed is in radians / s^2 ... not m/s^2 --- src/moaicore/MOAIBox2DWheelJoint.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/moaicore/MOAIBox2DWheelJoint.cpp b/src/moaicore/MOAIBox2DWheelJoint.cpp index ff8436acb6..18514fa49d 100644 --- a/src/moaicore/MOAIBox2DWheelJoint.cpp +++ b/src/moaicore/MOAIBox2DWheelJoint.cpp @@ -104,7 +104,6 @@ int MOAIBox2DWheelJoint::_isMotorEnabled ( lua_State* L ) { */ int MOAIBox2DWheelJoint::_getMotorSpeed ( lua_State* L ) { MOAI_LUA_SETUP ( MOAIBox2DWheelJoint, "U" ) - float unitsToMeters = self->GetUnitsToMeters (); if ( !self->mJoint ) { MOAILog ( state, MOAILogMessages::MOAIBox2DJoint_MissingInstance ); @@ -112,7 +111,7 @@ int MOAIBox2DWheelJoint::_getMotorSpeed ( lua_State* L ) { } b2WheelJoint* joint = ( b2WheelJoint* )self->mJoint; - state.Push ( joint->GetMotorSpeed () / unitsToMeters ); + state.Push ( joint->GetMotorSpeed () * ( float ) R2D ); return 1; } From 409c69cf03cbd1d275de2a119f193f42809e9436 Mon Sep 17 00:00:00 2001 From: Thomas Harning Jr Date: Sun, 8 Jan 2012 01:21:10 -0500 Subject: [PATCH 7/7] MOAIBox2DWheelJoint: fixes unit conversion to match what box2d states it is meters typically except motor speed as angle/s^2 --- src/moaicore/MOAIBox2DWheelJoint.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/moaicore/MOAIBox2DWheelJoint.cpp b/src/moaicore/MOAIBox2DWheelJoint.cpp index 18514fa49d..4e1f1a7a6a 100644 --- a/src/moaicore/MOAIBox2DWheelJoint.cpp +++ b/src/moaicore/MOAIBox2DWheelJoint.cpp @@ -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; } @@ -168,7 +169,8 @@ 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; @@ -176,7 +178,7 @@ int MOAIBox2DWheelJoint::_getMotorTorque ( lua_State* L ) { 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; } @@ -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 );