@@ -452,7 +452,6 @@ void MOAIGraphicsPropBase::MOAIDrawable_DrawDebug ( int subPrimID ) {
452452ZLMatrix4x4 MOAIGraphicsPropBase::MOAIGraphicsPropBase_GetWorldDrawingMtx () {
453453
454454 MOAIGfxState& gfxState = MOAIGfxMgr::Get ().mGfxState ;
455- // MOAIRenderMgr& renderMgr = MOAIRenderMgr::Get ();
456455
457456 ZLMatrix4x4 worldDrawingMtx;
458457
@@ -521,9 +520,9 @@ ZLMatrix4x4 MOAIGraphicsPropBase::MOAIGraphicsPropBase_GetWorldDrawingMtx () {
521520
522521 case BILLBOARD_COMPASS : {
523522
524- // const ZLAffine3D& cameraMtx = camera->GetLocalToWorldMtx (); // inv view mtx
523+
524+
525525 ZLAffine3D cameraMtx ( gfxState.GetMtx ( MOAIGfxState::VIEW_TO_WORLD_MTX ));
526- // ZLVec3D cameraZ = cameraMtx.GetZAxis ();
527526 ZLVec3D cameraY = cameraMtx.GetYAxis ();
528527
529528 cameraY.mZ = 0 .0f ;
@@ -532,7 +531,7 @@ ZLMatrix4x4 MOAIGraphicsPropBase::MOAIGraphicsPropBase_GetWorldDrawingMtx () {
532531 ZLVec2D mapY ( cameraY.mX , cameraY.mY );
533532 ZLVec2D worldY ( 0 .0f , 1 .0f );
534533
535- float radians = mapY.Radians ( worldY );
534+ float radians = - mapY.Radians ( worldY );
536535
537536 if ( cameraY.mX < 0 .0f ) {
538537 radians = -radians;
@@ -548,9 +547,19 @@ ZLMatrix4x4 MOAIGraphicsPropBase::MOAIGraphicsPropBase_GetWorldDrawingMtx () {
548547 mtx.Translate ( this ->mPiv .mX , this ->mPiv .mY , this ->mPiv .mZ );
549548 billboardMtx.Append ( mtx );
550549
550+ // now that we've calculated the compass billboard, here's the tricky part.
551+ // we need to sandwich it into the local-to-world matrix, after the scale and rotate,
552+ // but before the translation. it's not sufficient just to prepend as we'd wind up
553+ // with compass-scale-rotate-translate. in that scenario, if scale != 1, then it will
554+ // mess up the compass transform. so we need to do scale-rotate-compass-translate instead.
555+
551556 worldDrawingMtx = ZLMatrix4x4 ( this ->GetLocalToWorldMtx ());
552- worldDrawingMtx.Prepend ( billboardMtx );
553-
557+
558+ ZLVec4D localToWorldTranslation = worldDrawingMtx.GetColumn ( 3 ); // extract the translation
559+ worldDrawingMtx.SetColumn ( 3 , ZLVec4D::ORIGIN ); // set translation back to origin
560+ worldDrawingMtx.Append ( billboardMtx ); // this gives us scale-rotate-billboard
561+ worldDrawingMtx.SetColumn ( 3 , localToWorldTranslation ); // scale-rotate-billboard-translation
562+
554563 break ;
555564 }
556565
0 commit comments