Skip to content

Commit 21006a5

Browse files
author
Patrick Meehan
committed
Merge branch 'partner/pi-develop' into develop
2 parents e22a532 + 81f951f commit 21006a5

File tree

4 files changed

+41
-9
lines changed

4 files changed

+41
-9
lines changed

src/moai-sim/MOAIGraphicsPropBase.cpp

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,6 @@ void MOAIGraphicsPropBase::MOAIDrawable_DrawDebug ( int subPrimID ) {
452452
ZLMatrix4x4 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

src/zl-util/ZLMatrix4x4.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,20 @@ class ZLMetaMatrix4x4 {
180180
m [ C3_R3 ] = 0;
181181
}
182182

183+
//----------------------------------------------------------------//
184+
ZLMetaVec4D < TYPE > GetColumn ( int c ) const {
185+
186+
ZLMetaVec4D < TYPE > col;
187+
188+
c *= 4;
189+
col.mX = this->m [ c++ ];
190+
col.mY = this->m [ c++ ];
191+
col.mZ = this->m [ c++ ];
192+
col.mW = this->m [ c ];
193+
194+
return col;
195+
}
196+
183197
//----------------------------------------------------------------//
184198
TYPE GetElement ( int c, int r ) const {
185199

@@ -772,6 +786,16 @@ class ZLMetaMatrix4x4 {
772786
m[C3_R3] = 1;
773787
}
774788

789+
//----------------------------------------------------------------//
790+
void SetColumn ( int c, const ZLMetaVec4D < TYPE >& col ) {
791+
792+
c *= 4;
793+
this->m [ c++ ] = col.mX;
794+
this->m [ c++ ] = col.mY;
795+
this->m [ c++ ] = col.mZ;
796+
this->m [ c ] = col.mW;
797+
}
798+
775799
//----------------------------------------------------------------//
776800
void SetElement ( int c, int r, float value ) const {
777801

src/zl-util/ZLVec4D.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class ZLMetaVec4D :
1414
public ZLMetaVec3D < TYPE > {
1515
public:
1616

17+
static const ZLMetaVec4D < TYPE > ORIGIN;
1718
static const ZLMetaVec4D < TYPE > ZERO;
1819
static const ZLMetaVec4D < TYPE > X_AXIS;
1920
static const ZLMetaVec4D < TYPE > Y_AXIS;
@@ -68,6 +69,7 @@ class ZLMetaVec4D :
6869
}
6970
};
7071

72+
template < typename TYPE > const ZLMetaVec4D < TYPE > ZLMetaVec4D < TYPE >::ORIGIN ( 0.0f, 0.0f, 0.0f, 1.0f );
7173
template < typename TYPE > const ZLMetaVec4D < TYPE > ZLMetaVec4D < TYPE >::ZERO ( 0.0f, 0.0f, 0.0f, 0.0f );
7274
template < typename TYPE > const ZLMetaVec4D < TYPE > ZLMetaVec4D < TYPE >::X_AXIS ( 1.0f, 0.0f, 0.0f, 0.0f );
7375
template < typename TYPE > const ZLMetaVec4D < TYPE > ZLMetaVec4D < TYPE >::Y_AXIS ( 0.0f, 2.0f, 0.0f, 0.0f );

xcode/libmoai/libmoai.xcodeproj/project.pbxproj

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22728,7 +22728,6 @@
2272822728
isa = XCBuildConfiguration;
2272922729
buildSettings = {
2273022730
CLANG_CXX_LANGUAGE_STANDARD = "c++0x";
22731-
CLANG_CXX_LIBRARY = "libc++";
2273222731
CLANG_ENABLE_OBJC_WEAK = YES;
2273322732
CLANG_WARN_CXX0X_EXTENSIONS = NO;
2273422733
GCC_ENABLE_CPP_EXCEPTIONS = YES;
@@ -22775,7 +22774,6 @@
2277522774
isa = XCBuildConfiguration;
2277622775
buildSettings = {
2277722776
CLANG_CXX_LANGUAGE_STANDARD = "c++0x";
22778-
CLANG_CXX_LIBRARY = "libc++";
2277922777
CLANG_ENABLE_OBJC_WEAK = YES;
2278022778
CLANG_WARN_CXX0X_EXTENSIONS = NO;
2278122779
GCC_ENABLE_CPP_EXCEPTIONS = YES;
@@ -22822,7 +22820,6 @@
2282222820
isa = XCBuildConfiguration;
2282322821
buildSettings = {
2282422822
CLANG_CXX_LANGUAGE_STANDARD = "c++0x";
22825-
CLANG_CXX_LIBRARY = "libc++";
2282622823
CLANG_ENABLE_OBJC_WEAK = YES;
2282722824
CLANG_WARN_CXX0X_EXTENSIONS = NO;
2282822825
GCC_ENABLE_CPP_EXCEPTIONS = YES;

0 commit comments

Comments
 (0)