diff --git a/src/moai-sim/MOAIGraphicsPropBase.cpp b/src/moai-sim/MOAIGraphicsPropBase.cpp index 83c3edd0dc..2c957318f8 100644 --- a/src/moai-sim/MOAIGraphicsPropBase.cpp +++ b/src/moai-sim/MOAIGraphicsPropBase.cpp @@ -452,7 +452,6 @@ void MOAIGraphicsPropBase::MOAIDrawable_DrawDebug ( int subPrimID ) { ZLMatrix4x4 MOAIGraphicsPropBase::MOAIGraphicsPropBase_GetWorldDrawingMtx () { MOAIGfxState& gfxState = MOAIGfxMgr::Get ().mGfxState; - //MOAIRenderMgr& renderMgr = MOAIRenderMgr::Get (); ZLMatrix4x4 worldDrawingMtx; @@ -521,9 +520,9 @@ ZLMatrix4x4 MOAIGraphicsPropBase::MOAIGraphicsPropBase_GetWorldDrawingMtx () { case BILLBOARD_COMPASS: { - //const ZLAffine3D& cameraMtx = camera->GetLocalToWorldMtx (); // inv view mtx + + ZLAffine3D cameraMtx ( gfxState.GetMtx ( MOAIGfxState::VIEW_TO_WORLD_MTX )); - //ZLVec3D cameraZ = cameraMtx.GetZAxis (); ZLVec3D cameraY = cameraMtx.GetYAxis (); cameraY.mZ = 0.0f; @@ -532,7 +531,7 @@ ZLMatrix4x4 MOAIGraphicsPropBase::MOAIGraphicsPropBase_GetWorldDrawingMtx () { ZLVec2D mapY ( cameraY.mX, cameraY.mY ); ZLVec2D worldY ( 0.0f, 1.0f ); - float radians = mapY.Radians ( worldY ); + float radians = -mapY.Radians ( worldY ); if ( cameraY.mX < 0.0f ) { radians = -radians; @@ -548,9 +547,19 @@ ZLMatrix4x4 MOAIGraphicsPropBase::MOAIGraphicsPropBase_GetWorldDrawingMtx () { mtx.Translate ( this->mPiv.mX, this->mPiv.mY, this->mPiv.mZ ); billboardMtx.Append ( mtx ); + // now that we've calculated the compass billboard, here's the tricky part. + // we need to sandwich it into the local-to-world matrix, after the scale and rotate, + // but before the translation. it's not sufficient just to prepend as we'd wind up + // with compass-scale-rotate-translate. in that scenario, if scale != 1, then it will + // mess up the compass transform. so we need to do scale-rotate-compass-translate instead. + worldDrawingMtx = ZLMatrix4x4 ( this->GetLocalToWorldMtx ()); - worldDrawingMtx.Prepend ( billboardMtx ); - + + ZLVec4D localToWorldTranslation = worldDrawingMtx.GetColumn ( 3 ); // extract the translation + worldDrawingMtx.SetColumn ( 3, ZLVec4D::ORIGIN ); // set translation back to origin + worldDrawingMtx.Append ( billboardMtx ); // this gives us scale-rotate-billboard + worldDrawingMtx.SetColumn ( 3, localToWorldTranslation ); // scale-rotate-billboard-translation + break; } diff --git a/src/zl-util/ZLMatrix4x4.h b/src/zl-util/ZLMatrix4x4.h index f205257f49..92909f6445 100644 --- a/src/zl-util/ZLMatrix4x4.h +++ b/src/zl-util/ZLMatrix4x4.h @@ -180,6 +180,20 @@ class ZLMetaMatrix4x4 { m [ C3_R3 ] = 0; } + //----------------------------------------------------------------// + ZLMetaVec4D < TYPE > GetColumn ( int c ) const { + + ZLMetaVec4D < TYPE > col; + + c *= 4; + col.mX = this->m [ c++ ]; + col.mY = this->m [ c++ ]; + col.mZ = this->m [ c++ ]; + col.mW = this->m [ c ]; + + return col; + } + //----------------------------------------------------------------// TYPE GetElement ( int c, int r ) const { @@ -772,6 +786,16 @@ class ZLMetaMatrix4x4 { m[C3_R3] = 1; } + //----------------------------------------------------------------// + void SetColumn ( int c, const ZLMetaVec4D < TYPE >& col ) { + + c *= 4; + this->m [ c++ ] = col.mX; + this->m [ c++ ] = col.mY; + this->m [ c++ ] = col.mZ; + this->m [ c ] = col.mW; + } + //----------------------------------------------------------------// void SetElement ( int c, int r, float value ) const { diff --git a/src/zl-util/ZLVec4D.h b/src/zl-util/ZLVec4D.h index 78803bd2ac..4ff4b01ec3 100644 --- a/src/zl-util/ZLVec4D.h +++ b/src/zl-util/ZLVec4D.h @@ -14,6 +14,7 @@ class ZLMetaVec4D : public ZLMetaVec3D < TYPE > { public: + static const ZLMetaVec4D < TYPE > ORIGIN; static const ZLMetaVec4D < TYPE > ZERO; static const ZLMetaVec4D < TYPE > X_AXIS; static const ZLMetaVec4D < TYPE > Y_AXIS; @@ -68,6 +69,7 @@ class ZLMetaVec4D : } }; +template < typename TYPE > const ZLMetaVec4D < TYPE > ZLMetaVec4D < TYPE >::ORIGIN ( 0.0f, 0.0f, 0.0f, 1.0f ); template < typename TYPE > const ZLMetaVec4D < TYPE > ZLMetaVec4D < TYPE >::ZERO ( 0.0f, 0.0f, 0.0f, 0.0f ); template < typename TYPE > const ZLMetaVec4D < TYPE > ZLMetaVec4D < TYPE >::X_AXIS ( 1.0f, 0.0f, 0.0f, 0.0f ); template < typename TYPE > const ZLMetaVec4D < TYPE > ZLMetaVec4D < TYPE >::Y_AXIS ( 0.0f, 2.0f, 0.0f, 0.0f ); diff --git a/xcode/libmoai/libmoai.xcodeproj/project.pbxproj b/xcode/libmoai/libmoai.xcodeproj/project.pbxproj index 5a2868c200..37aa6f01d1 100644 --- a/xcode/libmoai/libmoai.xcodeproj/project.pbxproj +++ b/xcode/libmoai/libmoai.xcodeproj/project.pbxproj @@ -22728,7 +22728,6 @@ isa = XCBuildConfiguration; buildSettings = { CLANG_CXX_LANGUAGE_STANDARD = "c++0x"; - CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_OBJC_WEAK = YES; CLANG_WARN_CXX0X_EXTENSIONS = NO; GCC_ENABLE_CPP_EXCEPTIONS = YES; @@ -22775,7 +22774,6 @@ isa = XCBuildConfiguration; buildSettings = { CLANG_CXX_LANGUAGE_STANDARD = "c++0x"; - CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_OBJC_WEAK = YES; CLANG_WARN_CXX0X_EXTENSIONS = NO; GCC_ENABLE_CPP_EXCEPTIONS = YES; @@ -22822,7 +22820,6 @@ isa = XCBuildConfiguration; buildSettings = { CLANG_CXX_LANGUAGE_STANDARD = "c++0x"; - CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_OBJC_WEAK = YES; CLANG_WARN_CXX0X_EXTENSIONS = NO; GCC_ENABLE_CPP_EXCEPTIONS = YES;