Skip to content

Commit

Permalink
Merge branch 'partner/pi-develop' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Patrick Meehan committed Dec 6, 2018
2 parents e22a532 + 81f951f commit 21006a5
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 9 deletions.
21 changes: 15 additions & 6 deletions src/moai-sim/MOAIGraphicsPropBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
}

Expand Down
24 changes: 24 additions & 0 deletions src/zl-util/ZLMatrix4x4.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -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 {

Expand Down
2 changes: 2 additions & 0 deletions src/zl-util/ZLVec4D.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 );
Expand Down
3 changes: 0 additions & 3 deletions xcode/libmoai/libmoai.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 21006a5

Please sign in to comment.