void RageMatrixCommand( CString sCommandString, RageMatrix &mat ) { CStringArray asCommands; split( sCommandString, ";", asCommands, true ); for( unsigned c=0; c<asCommands.size(); c++ ) { CStringArray asTokens; split( asCommands[c], ",", asTokens, true ); int iMaxIndexAccessed = 0; #define sParam(i) (GetParam(asTokens,i,iMaxIndexAccessed)) #define fParam(i) (strtof(sParam(i),NULL)) #define iParam(i) (atoi(sParam(i))) #define bParam(i) (iParam(i)!=0) CString& sName = asTokens[0]; sName.MakeLower(); RageMatrix b; // Act on command if( sName=="x" ) RageMatrixTranslation( &b, fParam(1),0,0 ); else if( sName=="y" ) RageMatrixTranslation( &b, 0,fParam(1),0 ); else if( sName=="z" ) RageMatrixTranslation( &b, 0,0,fParam(1) ); else if( sName=="zoomx" ) RageMatrixScaling(&b, fParam(1),1,1 ); else if( sName=="zoomy" ) RageMatrixScaling(&b, 1,fParam(1),1 ); else if( sName=="zoomz" ) RageMatrixScaling(&b, 1,1,fParam(1) ); else if( sName=="rotationx" ) RageMatrixRotationX( &b, fParam(1) ); else if( sName=="rotationy" ) RageMatrixRotationY( &b, fParam(1) ); else if( sName=="rotationz" ) RageMatrixRotationZ( &b, fParam(1) ); else { CString sError = ssprintf( "MatrixCommand: Unrecognized matrix command name '%s' in command string '%s'.", sName.c_str(), sCommandString.c_str() ); LOG->Warn( sError ); Dialog::OK( sError ); continue; } if( iMaxIndexAccessed != (int)asTokens.size()-1 ) { CString sError = ssprintf( "MatrixCommand: Wrong number of parameters in command '%s'. Expected %d but there are %d.", join(",",asTokens).c_str(), iMaxIndexAccessed+1, (int)asTokens.size() ); LOG->Warn( sError ); Dialog::OK( sError ); continue; } RageMatrix a(mat); RageMatrixMultiply(&mat, &a, &b); } }
RageMatrix RageDisplay::GetCenteringMatrix( float fTranslateX, float fTranslateY, float fAddWidth, float fAddHeight ) const { // in screen space, left edge = -1, right edge = 1, bottom edge = -1. top edge = 1 float fWidth = (float) GetActualVideoModeParams().width; float fHeight = (float) GetActualVideoModeParams().height; float fPercentShiftX = SCALE( fTranslateX, 0, fWidth, 0, +2.0f ); float fPercentShiftY = SCALE( fTranslateY, 0, fHeight, 0, -2.0f ); float fPercentScaleX = SCALE( fAddWidth, 0, fWidth, 1.0f, 2.0f ); float fPercentScaleY = SCALE( fAddHeight, 0, fHeight, 1.0f, 2.0f ); RageMatrix m1; RageMatrix m2; RageMatrixTranslation( &m1, fPercentShiftX, fPercentShiftY, 0 ); RageMatrixScaling( &m2, fPercentScaleX, fPercentScaleY, 1 ); RageMatrix mOut; RageMatrixMultiply( &mOut, &m1, &m2 ); return mOut; }
RageMatrix RageDisplay_D3D::GetOrthoMatrix( float l, float r, float b, float t, float zn, float zf ) { RageMatrix m = RageDisplay::GetOrthoMatrix( l, r, b, t, zn, zf ); /* Convert from OpenGL's [-1,+1] Z values to D3D's [0,+1]. */ RageMatrix tmp; RageMatrixScaling( &tmp, 1, 1, 0.5f ); RageMatrixMultiply( &m, &tmp, &m ); RageMatrixTranslation( &tmp, 0, 0, 0.5f ); RageMatrixMultiply( &m, &tmp, &m ); return m; }
void RageDisplay_D3D::SendCurrentMatrices() { RageMatrix projection; RageMatrixMultiply( &projection, GetCentering(), GetProjectionTop() ); g_pd3dDevice->SetTransform( D3DTS_PROJECTION, (D3DMATRIX*)&projection ); g_pd3dDevice->SetTransform( D3DTS_VIEW, (D3DMATRIX*)GetViewTop() ); /* Convert to OpenGL-style "pixel-centered" coords */ RageMatrix m; RageMatrixTranslation( &m, -0.5f, -0.5f, 0 ); RageMatrixMultiply( &m, &m, GetWorldTop() ); g_pd3dDevice->SetTransform( D3DTS_WORLD, (D3DMATRIX*)&m ); g_pd3dDevice->SetTransform( D3DTS_TEXTURE0, (D3DMATRIX*)GetTextureTop() ); }
void RageDisplay::ChangeCentering( int trans_x, int trans_y, int add_width, int add_height ) { // in screen space, left edge = -1, right edge = 1, bottom edge = -1. top edge = 1 float fPercentShiftX = 2*trans_x/640.f; float fPercentShiftY = -2*trans_y/480.f; float fPercentScaleX = (640.f+add_width)/640.f; float fPercentScaleY = (480.f+add_height)/480.f; RageMatrix m1; RageMatrix m2; RageMatrixTranslation( &m1, fPercentShiftX, fPercentShiftY, 0 ); RageMatrixScaling( &m2, fPercentScaleX, fPercentScaleY, 1 ); RageMatrixMultiply( &m_Centering, &m1, &m2 ); }
RageMatrix RageLookAt( float eyex, float eyey, float eyez, float centerx, float centery, float centerz, float upx, float upy, float upz ) { RageVector3 Z(eyex - centerx, eyey - centery, eyez - centerz); RageVec3Normalize(&Z, &Z); RageVector3 Y(upx, upy, upz); RageVector3 X( Y[1] * Z[2] - Y[2] * Z[1], -Y[0] * Z[2] + Y[2] * Z[0], Y[0] * Z[1] - Y[1] * Z[0]); Y = RageVector3( Z[1] * X[2] - Z[2] * X[1], -Z[0] * X[2] + Z[2] * X[0], Z[0] * X[1] - Z[1] * X[0] ); RageVec3Normalize(&X, &X); RageVec3Normalize(&Y, &Y); RageMatrix mat( X[0], Y[0], Z[0], 0, X[1], Y[1], Z[1], 0, X[2], Y[2], Z[2], 0, 0, 0, 0, 1 ); RageMatrix mat2; RageMatrixTranslation(&mat2, -eyex, -eyey, -eyez); RageMatrix ret; RageMatrixMultiply(&ret, &mat, &mat2); return ret; }
// Left multiply the current matrix with the computed translation // matrix. (transformation is about the local origin of the object) void TranslateLocal( float x, float y, float z ) { RageMatrix m; RageMatrixTranslation( &m, x, y, z ); MultMatrixLocal( m ); }