void RageMatrixMultiply( RageMatrix* pOut, const RageMatrix* pA, const RageMatrix* pB ) { //#if defined(_WINDOWS) || defined(_XBOX) // // <30 cycles for theirs versus >100 for ours. // D3DXMatrixMultiply( (D3DMATRIX*)pOut, (D3DMATRIX*)pA, (D3DMATRIX*)pB ); //#else const RageMatrix &a = *pA; const RageMatrix &b = *pB; *pOut = RageMatrix( b.m00*a.m00+b.m01*a.m10+b.m02*a.m20+b.m03*a.m30, b.m00*a.m01+b.m01*a.m11+b.m02*a.m21+b.m03*a.m31, b.m00*a.m02+b.m01*a.m12+b.m02*a.m22+b.m03*a.m32, b.m00*a.m03+b.m01*a.m13+b.m02*a.m23+b.m03*a.m33, b.m10*a.m00+b.m11*a.m10+b.m12*a.m20+b.m13*a.m30, b.m10*a.m01+b.m11*a.m11+b.m12*a.m21+b.m13*a.m31, b.m10*a.m02+b.m11*a.m12+b.m12*a.m22+b.m13*a.m32, b.m10*a.m03+b.m11*a.m13+b.m12*a.m23+b.m13*a.m33, b.m20*a.m00+b.m21*a.m10+b.m22*a.m20+b.m23*a.m30, b.m20*a.m01+b.m21*a.m11+b.m22*a.m21+b.m23*a.m31, b.m20*a.m02+b.m21*a.m12+b.m22*a.m22+b.m23*a.m32, b.m20*a.m03+b.m21*a.m13+b.m22*a.m23+b.m23*a.m33, b.m30*a.m00+b.m31*a.m10+b.m32*a.m20+b.m33*a.m30, b.m30*a.m01+b.m31*a.m11+b.m32*a.m21+b.m33*a.m31, b.m30*a.m02+b.m31*a.m12+b.m32*a.m22+b.m33*a.m32, b.m30*a.m03+b.m31*a.m13+b.m32*a.m23+b.m33*a.m33 ); // phew! //#endif }
void RageDisplay_D3D::SetSphereEnvironmentMapping( bool b ) { if( g_iCurrentTextureIndex >= (int) g_DeviceCaps.MaxSimultaneousTextures ) // not supported return; // http://www.gamasutra.com/features/20000811/wyatt_03.htm if( b ) { RageMatrix tex = RageMatrix ( 0.40f, 0.0f, 0.0f, 0.0f, 0.0f, -0.40f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.50, -0.50, 0.0f, 1.0f ); g_pd3dDevice->SetTransform((D3DTRANSFORMSTATETYPE)(D3DTS_TEXTURE0+g_iCurrentTextureIndex), (D3DMATRIX*)&tex); } // Tell D3D to use transformed reflection vectors as texture co-ordinate 0 // and then transform this coordinate by the specified texture matrix, also // tell D3D that only the first two coordinates of the output are valid. g_pd3dDevice->SetTextureStageState( g_iCurrentTextureIndex, D3DTSS_TEXTURETRANSFORMFLAGS, b ? D3DTTFF_COUNT2 : D3DTTFF_DISABLE ); g_pd3dDevice->SetTextureStageState( g_iCurrentTextureIndex, D3DTSS_TEXCOORDINDEX, b ? D3DTSS_TCI_CAMERASPACEREFLECTIONVECTOR : D3DTSS_TCI_PASSTHRU ); }
void RageMatrixIdentity( RageMatrix* pOut ) { *pOut = RageMatrix( 1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1 ); }
void RageMatrixFromQuat( RageMatrix* pOut, const RageVector4 q ) { float xx = q.x * (q.x + q.x); float xy = q.x * (q.y + q.y); float xz = q.x * (q.z + q.z); float wx = q.w * (q.x + q.x); float wy = q.w * (q.y + q.y); float wz = q.w * (q.z + q.z); float yy = q.y * (q.y + q.y); float yz = q.y * (q.z + q.z); float zz = q.z * (q.z + q.z); // careful. The param order is row-major, which is the // transpose of the order shown in the OpenGL docs. *pOut = RageMatrix( 1-(yy+zz), xy+wz, xz-wy, 0, xy-wz, 1-(xx+zz), yz+wx, 0, xz+wy, yz-wx, 1-(xx+yy), 0, 0, 0, 0, 1 ); }
void RageDisplay_D3D::SendCurrentMatrices() { RageMatrix m; RageMatrixMultiply( &m, GetCentering(), GetProjectionTop() ); /* Convert to OpenGL-style "pixel-centered" coords */ RageMatrix m2 = GetCenteringMatrix( -0.5f, -0.5f, 0, 0 ); RageMatrix projection; RageMatrixMultiply( &projection, &m2, &m ); g_pd3dDevice->SetTransform( D3DTS_PROJECTION, (D3DMATRIX*)&projection ); g_pd3dDevice->SetTransform( D3DTS_VIEW, (D3DMATRIX*)GetViewTop() ); g_pd3dDevice->SetTransform( D3DTS_WORLD, (D3DMATRIX*)GetWorldTop() ); for( unsigned tu = 0; tu < 2; tu++ ) { // Optimization opportunity: Turn off texture transform if not using texture coords. g_pd3dDevice->SetTextureStageState( tu, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT2 ); // If no texture is set for this texture unit, don't bother setting it up. IDirect3DBaseTexture9* pTexture = NULL; g_pd3dDevice->GetTexture( tu, &pTexture ); if( pTexture == NULL ) continue; pTexture->Release(); if( g_bSphereMapping[tu] ) { static const RageMatrix tex = RageMatrix ( 0.5f, 0.0f, 0.0f, 0.0f, 0.0f, -0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.5f, -0.5f, 0.0f, 1.0f ); g_pd3dDevice->SetTransform( (D3DTRANSFORMSTATETYPE)(D3DTS_TEXTURE0+tu), (D3DMATRIX*)&tex ); // Tell D3D to use transformed reflection vectors as texture co-ordinate 0 // and then transform this coordinate by the specified texture matrix. g_pd3dDevice->SetTextureStageState( tu, D3DTSS_TEXCOORDINDEX, D3DTSS_TCI_CAMERASPACEREFLECTIONVECTOR ); } else { /* * Direct3D is expecting a 3x3 matrix loaded into the 4x4 in order to transform * the 2-component texture coordinates. We currently only use translate and scale, * and ignore the z component entirely, so convert the texture matrix from * 4x4 to 3x3 by dropping z. */ const RageMatrix &tex1 = *GetTextureTop(); const RageMatrix tex2 = RageMatrix ( tex1.m[0][0], tex1.m[0][1], tex1.m[0][3], 0, tex1.m[1][0], tex1.m[1][1], tex1.m[1][3], 0, tex1.m[3][0], tex1.m[3][1], tex1.m[3][3], 0, 0, 0, 0, 0 ); g_pd3dDevice->SetTransform( D3DTRANSFORMSTATETYPE(D3DTS_TEXTURE0+tu), (D3DMATRIX*)&tex2 ); g_pd3dDevice->SetTextureStageState( tu, D3DTSS_TEXCOORDINDEX, D3DTSS_TCI_PASSTHRU ); } } }
RageMatrix RageMatrix::GetTranspose() const { return RageMatrix(m00,m10,m20,m30,m01,m11,m21,m31,m02,m12,m22,m32,m03,m13,m23,m33); }