void CTest5Section::Reaction( long in_SrcSectionID, const CRenderSection_CreateVertexBuffer_Response& in_rCmd ) { CLog::Print("CTest5Section::Reaction( const CRenderSection_CreateVertexBuffer_Response& in_rCmd )\n"); CLog::Print(" VB handle = %lu\n",in_rCmd.m_VBHandle); assert( in_rCmd.m_VBHandle > 0 ); m_VBHandle = in_rCmd.m_VBHandle; // set lights CTCommandSender<CRenderSection_SetAmbient>::SendCommand( m_RenderSectionID, CRenderSection_SetAmbient( 0x404040 ) ); CTCommandSender<CRenderSection_SetDirectionalLight>::SendCommand( m_RenderSectionID, CRenderSection_SetDirectionalLight( CVector(-1.0f,-1.0f,-1.0f), 1.0f, 1.0f, 1.0f ) ); // set object positions m_M0.ConstructScaling( CVector(2,2,2) ); m_M1.ConstructRotationY( 0 ); m_M1 *= CMatrix().ConstructTranslation( CVector(4,0,0) ); m_M2.ConstructRotationY( CONST_PI_2 ); m_M2 *= CMatrix().ConstructTranslation( CVector(0,0,4) ); m_M3.ConstructRotationY( CONST_PI_2*2 ); m_M3 *= CMatrix().ConstructTranslation( CVector(-4,0,0) ); m_M4.ConstructRotationY( CONST_PI_2*3 ); m_M4 *= CMatrix().ConstructTranslation( CVector(0,0,-4) ); // start rendering m_NFramesToRender = 2; RenderFrame(); CTCommandSender<CTest5Section_Render>::SendCommand( GetThisID(), CTest5Section_Render() ); CLog::Print("CTest5Section::Reaction( const CRenderSection_CreateVertexBuffer_Response& in_rCmd ) end\n"); }
// 描画 void CPlankton::Draw( const LPDIRECT3DDEVICE9 lpdevice, const CCamera* camera ) { if( IsCulling( &CMatrix( m_vPos ) ) ) { // ビルボードの為の回転行列獲得 D3DXMATRIX mRot; camera->GetBillboard( &mRot, &CMatrix( m_vPos ) ); lpdevice->SetTransform( D3DTS_WORLD, &( mRot * CMatrix( m_vPos ) ) ); // 描画 m_Board.Draw( lpdevice ); } }
//=========================================================================== CMatrix CMatrix::Transpose() { if(Data == NULL) { DEBUG_BREAK(); return CMatrix(); } // CMatrix Result(Columns, Rows); if(Result.Data == NULL) return CMatrix(); // for(int i = 0; i < Rows; i++) for(int j = 0; j < Columns; j++) { Result.Data[j][i] = Data[i][j]; } // return Result; }
//=========================================================================== CMatrix CMatrix::operator / (const double s) { if ( Data == NULL) { DEBUG_BREAK(); return CMatrix(); } if ( s == 0 ) { DEBUG_BREAK(); return CMatrix(); } // --- CMatrix Result(Rows, Columns); if(Result.Data == NULL) return CMatrix(); // --- for (int i = 0; i < Rows; i++) for (int k = 0; k < Columns; k++){ Result.Data[i][k] = Data[i][k] / s; } // --- return Result; }
CMatrix operator*( const double& scalar_in, const CMatrix& matrix_in ) { return CMatrix( scalar_in * matrix_in.value_[0][0], scalar_in * matrix_in.value_[0][1], scalar_in * matrix_in.value_[0][2], scalar_in * matrix_in.value_[0][3], scalar_in * matrix_in.value_[1][0], scalar_in * matrix_in.value_[1][1], scalar_in * matrix_in.value_[1][2], scalar_in * matrix_in.value_[1][3], scalar_in * matrix_in.value_[2][0], scalar_in * matrix_in.value_[2][1], scalar_in * matrix_in.value_[2][2], scalar_in * matrix_in.value_[2][3], scalar_in * matrix_in.value_[3][0], scalar_in * matrix_in.value_[3][1], scalar_in * matrix_in.value_[3][2], scalar_in * matrix_in.value_[3][3] ); }
CMatrix operator*( const CMatrix& matrix_in, const double& scalar_in ) { return CMatrix( matrix_in.value_[0][0] * scalar_in, matrix_in.value_[0][1] * scalar_in, matrix_in.value_[0][2] * scalar_in, matrix_in.value_[0][3] * scalar_in, matrix_in.value_[1][0] * scalar_in, matrix_in.value_[1][1] * scalar_in, matrix_in.value_[1][2] * scalar_in, matrix_in.value_[1][3] * scalar_in, matrix_in.value_[2][0] * scalar_in, matrix_in.value_[2][1] * scalar_in, matrix_in.value_[2][2] * scalar_in, matrix_in.value_[2][3] * scalar_in, matrix_in.value_[3][0] * scalar_in, matrix_in.value_[3][1] * scalar_in, matrix_in.value_[3][2] * scalar_in, matrix_in.value_[3][3] * scalar_in ); }
CBone_DX8* CStaticMesh_DX8::CreateBoneShadowRecurse( CBone* pSrcBone, const CBone* pSrcParentBone ) { assert( pSrcBone ); CBone_DX8* pResult; const CBonePosition& rPosition = pSrcBone->m_Position; if( pSrcParentBone ) { const CBonePosition& rParentPosition = pSrcParentBone->m_Position; pResult = new CBone_DX8( rPosition.GetPosition(), rParentPosition.GetPosition(), pSrcBone->m_InvBoneSkin ); } else { pResult = new CBone_DX8( rPosition.GetPosition(), CMatrix(), pSrcBone->m_InvBoneSkin ); } pResult->m_BoneID = pSrcBone->GetID(); m_Skeleton.m_BoneIDs[ pResult->m_BoneID ] = pResult; pResult->m_Children.resize( pSrcBone->GetChildren().size() ); for( size_t i=0; i<pSrcBone->GetChildren().size(); ++i ) { pResult->m_Children[i] = CreateBoneShadowRecurse( pSrcBone->GetChildren()[i], pSrcBone ); } pSrcBone->m_Position.ConnectLink( &(pResult->m_CurrentPosition) ); pResult->m_CurrentPosition.ConnectLink( &(pSrcBone->m_Position) ); return pResult; }
CMatrix * CCameraSA::GetMatrix ( CMatrix * matrix ) { DEBUG_TRACE("CMatrix * CCameraSA::GetMatrix ( CMatrix * matrix )"); //_asm int 3 //CCameraSAInterface * pCamInterface = this->GetInterface(); CMatrix_Padded * pCamMatrix = &this->GetInterface()->m_cameraMatrix; // ->Placeable.matrix; if ( pCamMatrix ) { matrix->vFront = pCamMatrix->vFront; matrix->vPos = pCamMatrix->vPos; matrix->vUp = pCamMatrix->vUp; matrix->vRight = pCamMatrix->vRight; if ( !IsValidMatrix ( *matrix ) ) { RestoreLastGoodState (); pCamMatrix->ConvertToMatrix ( *matrix ); } } else { *matrix = CMatrix (); } return matrix; }
// --[ Method ]--------------------------------------------------------------- // // - Class : CSplineTCB // - Prototype : CMatrix GetMatrix() const; // // - Purpose : Returns the TCB matrix (the Hermite one). // // ----------------------------------------------------------------------------- CMatrix CSplineTCB::GetMatrix() const { return CMatrix( 2.0f, -2.0f, 1.0f, 1.0f, -3.0f, 3.0f, -2.0f, -1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f); }
void CTransformation::rotate(CPoint u,CPoint v,CPoint w) //Cambio de base { CMatrix t = !CMatrix(u,v,w); t.e[0][3]=t.e[1][3]=t.e[2][3]=0.0f; CMatrix::operator=((*this)*(t)); }
CMatrix CMatrix::operator * (const CMatrix &arg) { auto rows = getRowCount(), cols = arg.getColCount(), p = getColCount(), // = RowCount у второй матрицы p2 = arg.getRowCount(); /* избыточно, ввести обработчик */ if (p == p2) // ширина первой матрицы равна высоте второй? { CMatrix Res(rows, cols); for (auto i = 0; i < rows; i++) { for (auto j = 0; j < cols; j++) { for (auto k = 0; k < p; k++) { Res[i][j] += (*this)[i][k] * arg[k][j]; } } } return Res; } else // не равна { return CMatrix(rows, cols); // возвращаем нулевую матрицу } }
void CMatrix::Mult(const CMatrix& source1, const CMatrix& source2, CMatrix& destination) { auto rows = source1.getRowCount(), cols = source2.getColCount(), p = source1.getColCount(), // = RowCount у второй матрицы p2 = source2.getRowCount(); /* избыточно, ввести обработчик */ if (p == p2) // ширина первой матрицы равна высоте второй? { destination.resize(rows); for (auto i = 0; i < rows; i++) { destination[i].assign(cols, 0); for (auto j = 0; j < cols; j++) { for (auto k = 0; k < p; k++) { destination[i][j] += source1[i][k] * source2[k][j]; } } } } else // не равна { destination = CMatrix(rows, cols); // возвращаем нулевую матрицу } }
//=========================================================================== CMatrix CMatrix::operator - (const CMatrix &m) { if ( Data == NULL ) { DEBUG_BREAK(); return CMatrix(); } if (m.Data == NULL ) { DEBUG_BREAK(); return CMatrix(); } if (m.Rows < Rows ) { DEBUG_BREAK(); return CMatrix(); } if (m.Columns < Columns) { DEBUG_BREAK(); return CMatrix(); } // CMatrix Result(Rows, Columns); // for (int i = 0; i < Rows; i++) for (int k = 0; k < Columns; k++) { Result.Data[i][k] = Data[i][k] - m.Data[i][k]; } // return Result; }
CMatrix CMatrix::getInverse( ) const { double det; det = getDeterminant(); if(fabs(det) < _EPSILON) throw; return CMatrix( getSubDeterminant(0,0) / det, -getSubDeterminant(1,0) / det, getSubDeterminant(2,0) / det, -getSubDeterminant(3,0) / det, -getSubDeterminant(0,1) / det, getSubDeterminant(1,1) / det, -getSubDeterminant(2,1) / det, getSubDeterminant(3,1) / det, getSubDeterminant(0,2) / det, -getSubDeterminant(1,2) / det, getSubDeterminant(2,2) / det, -getSubDeterminant(3,2) / det, -getSubDeterminant(0,3) / det, getSubDeterminant(1,3) / det, -getSubDeterminant(2,3) / det, getSubDeterminant(3,3) / det ); }
CMatrix CMatrix::subByElement( const CMatrix &other ) const { CMatrix Result = CMatrix(*this); Result.subByElement_I(other); return Result; }
CMatrix operator+( const CMatrix& matrix0_in, const CMatrix& matrix1_in ) { return CMatrix( matrix0_in.value_[0][0] + matrix1_in.value_[0][0], matrix0_in.value_[0][1] + matrix1_in.value_[0][1], matrix0_in.value_[0][2] + matrix1_in.value_[0][2], matrix0_in.value_[0][3] + matrix1_in.value_[0][3], matrix0_in.value_[1][0] + matrix1_in.value_[1][0], matrix0_in.value_[1][1] + matrix1_in.value_[1][1], matrix0_in.value_[1][2] + matrix1_in.value_[1][2], matrix0_in.value_[1][3] + matrix1_in.value_[1][3], matrix0_in.value_[2][0] + matrix1_in.value_[2][0], matrix0_in.value_[2][1] + matrix1_in.value_[2][1], matrix0_in.value_[2][2] + matrix1_in.value_[2][2], matrix0_in.value_[2][3] + matrix1_in.value_[2][3], matrix0_in.value_[3][0] + matrix1_in.value_[3][0], matrix0_in.value_[3][1] + matrix1_in.value_[3][1], matrix0_in.value_[3][2] + matrix1_in.value_[3][2], matrix0_in.value_[3][3] + matrix1_in.value_[3][3] ); }
//=========================================================================== CMatrix CMatrix::Inverse_Zhordan_0() { if ( Data == NULL ) return CMatrix(); if ( Rows != Columns) return CMatrix(); CMatrix Result = CMatrix(Rows, Rows); // ----------- опирование матрици ---- for (int i = 0; i < Rows; i++) for (int k = 0; k < Rows; k++) Result.Data[i][k] = Data[i][k]; // ----------- int i, k, j; double d1, d2; for(i = 0; i < Rows; i++) { d1 = -((double)1.0 / Result.Data[i][i]); for (k = 0; k < Rows; k++) Result.Data[k][i] *= d1; d1 = -d1; Result.Data[i][i] = d1; for(j = i-1; j >= 0; j--) { d2 = Result.Data[i][j]; for (k = i - 1; k >= 0; k--) Result.Data[k][j] += Result.Data[k][i] * d2; for (k = i + 1; k < Rows; k++) Result.Data[k][j] += Result.Data[k][i] * d2; Result.Data[i][j] *= d1; } for(j = i + 1; j < Rows; j++) { d2 = Result.Data[i][j]; for (k = i - 1; k >= 0; k--) Result.Data[k][j] += Result.Data[k][i] * d2; for (k = i + 1; k < Rows; k++) Result.Data[k][j] += Result.Data[k][i] * d2; Result.Data[i][j] *= d1; } } // --------- return Result; }
// LSOD recovery void CCameraSA::RestoreLastGoodState ( void ) { CMatrix defmat; SetMatrix ( &defmat ); CCameraSAInterface* pCameraInterface = GetInterface (); pCameraInterface->m_CameraAverageSpeed = 0; pCameraInterface->m_CameraSpeedSoFar = 0; pCameraInterface->m_PreviousCameraPosition = CVector (); pCameraInterface->m_vecGameCamPos = CVector (); pCameraInterface->m_cameraMatrix.SetFromMatrixSkipPadding ( CMatrix () ); pCameraInterface->m_cameraMatrixOld.SetFromMatrixSkipPadding ( CMatrix () ); pCameraInterface->m_viewMatrix.SetFromMatrixSkipPadding ( CMatrix () ); pCameraInterface->m_matInverse.SetFromMatrixSkipPadding ( CMatrix () ); pCameraInterface->m_vecBottomFrustumNormal = CVector ( 0, -1, -1 ); pCameraInterface->m_vecTopFrustumNormal = CVector ( -1, -1, 0 ); for ( uint i = 0 ; i < MAX_CAMS ; i++ ) { CCamSA* pCam = Cams[i]; if ( !pCam ) continue; CCamSAInterface* pCamInterface = pCam->GetInterface (); if ( !pCamInterface ) continue; pCamInterface->m_fAlphaSpeedOverOneFrame = 0; pCamInterface->m_fBetaSpeedOverOneFrame = 0; pCamInterface->m_fTrueBeta = 1; pCamInterface->m_fTrueAlpha = 1; pCamInterface->m_fVerticalAngle = 1; pCamInterface->m_fHorizontalAngle = 1; pCamInterface->BetaSpeed = 0; pCamInterface->SpeedVar = 0; pCamInterface->m_cvecSourceSpeedOverOneFrame = CVector ( 0, 0, 0 ); pCamInterface->m_cvecTargetSpeedOverOneFrame = CVector ( 0, 0, 0 ); pCamInterface->Front = CVector ( 1, 0, 0 ); pCamInterface->Source = CVector ( 1, 0, 0 ); pCamInterface->SourceBeforeLookBehind = CVector ( 1, 0, 0 ); pCamInterface->Up = CVector ( 0, 0, 1 ); for ( uint i = 0 ; i < CAM_NUM_TARGET_HISTORY ; i++ ) pCamInterface->m_aTargetHistoryPos[i] = CVector ( 1, 0, 0 ); } }
// --[ Method ]--------------------------------------------------------------- // // - Class : CMatrix // // - prototype : CMatrix Transposed() // // - Purpose : Returns the transposed matrix. // // ----------------------------------------------------------------------------- CMatrix CMatrix::Transposed() const { return CMatrix( m_fM[0][0], m_fM[1][0], m_fM[2][0], m_fM[3][0], m_fM[0][1], m_fM[1][1], m_fM[2][1], m_fM[3][1], m_fM[0][2], m_fM[1][2], m_fM[2][2], m_fM[3][2], m_fM[0][3], m_fM[1][3], m_fM[2][3], m_fM[3][3] ); }
//=========================================================================== CMatrix CMatrix::operator * (const CMatrix& m) { // - умножение двух матриц A (MxN) и B (KxL), определено только дл¤ N=K. C=AB. => C Ц матрица размерности MxL. if ( Data == NULL ) { DEBUG_BREAK(); return CMatrix(); } if (m.Data == NULL ) { DEBUG_BREAK(); return CMatrix(); } if (m.Rows != Columns) { DEBUG_BREAK(); return CMatrix(); } // CMatrix Result(Rows, m.Columns); // for(int i = 0; i < Rows; i++) for(int j = 0; j < m.Columns; j++) { for(int k = 0; k < Columns; k++) Result.Data[i][j] += Data[i][k]*m.Data[k][j]; } // return Result; }
//=========================================================================== CMatrix diad(const CVector& v1, const CVector& v2) { double aRes[9]; aRes[0] = v1.Data[0][0] * v2.Data[0][0]; aRes[1] = v1.Data[0][0] * v2.Data[1][0]; aRes[2] = v1.Data[0][0] * v2.Data[2][0]; aRes[3] = v1.Data[1][0] * v2.Data[0][0]; aRes[4] = v1.Data[1][0] * v2.Data[1][0]; aRes[5] = v1.Data[1][0] * v2.Data[2][0]; aRes[6] = v1.Data[2][0] * v2.Data[0][0]; aRes[7] = v1.Data[2][0] * v2.Data[1][0]; aRes[8] = v1.Data[2][0] * v2.Data[2][0]; return CMatrix(3, 3, aRes); }
//=========================================================================== CMatrix CSop(const CVector& v) { double aRes[9]; aRes[0] = 0.0; aRes[1] = -v.Data[2][0]; aRes[2] = v.Data[1][0]; aRes[3] = v.Data[2][0]; aRes[4] = 0.0; aRes[5] = -v.Data[0][0]; aRes[6] = -v.Data[1][0]; aRes[7] = v.Data[0][0]; aRes[8] = 0.0; return CMatrix(3, 3, aRes); }
// Corrects errors in the physics engine that cause projectiles to be far away from the objects they attached to // issue #8122 bool CProjectileSA::CorrectPhysics ( void ) { // make sure we have an interface for our bomb/satchel CPhysicalSAInterface * pInterface = static_cast < CPhysicalSAInterface * > ( m_pInterface ); // make sure we have an interface if ( pInterface != NULL ) { // make sure we have an attached entity if ( pInterface->m_pAttachedEntity ) { // get our position CVector vecStart = *GetPosition ( ); // get the entity we collided with CEntitySAInterface * pCollidedWithInterface = pInterface->m_pAttachedEntity; // get our end position by projecting forward a few velocities more CVector vecEnd = vecStart - ( pInterface->m_vecCollisionImpactVelocity * 3 ); // process forward another 1 unit if ( pGame->GetWorld ( )->CalculateImpactPosition ( vecStart, vecEnd ) ) { // setup some variables CVector vecRotation; CVector vecTemp; CVector vecCollisionOffset; // get our current offset ( we want the rotation! ) GetAttachedOffsets ( vecTemp, vecRotation ); // create a matrix variable CMatrix attachedToMatrix; if ( pCollidedWithInterface->Placeable.matrix != NULL ) { // get our matrix pCollidedWithInterface->Placeable.matrix->ConvertToMatrix ( attachedToMatrix ); } else { // get our matrix attachedToMatrix = CMatrix ( pCollidedWithInterface->Placeable.m_transform.m_translate ); } // transform our matrix into local (attached) space CVector vecPosition = attachedToMatrix.Inverse ().TransformVector ( vecEnd ); // offset by enough that it isn't sticking inside anything vecPosition += attachedToMatrix.Inverse () * ( pInterface->m_vecCollisionImpactVelocity * CVector ( 0.2f, 0.2f, 0.3f ) ); // set our attached offsets SetAttachedOffsets ( vecPosition, vecRotation ); } return true; } } return false; }
CMatrix CMatrix::getTransposed( ) const { return CMatrix( value_[0][0], value_[1][0], value_[2][0], value_[3][0], value_[0][1], value_[1][1], value_[2][1], value_[3][1], value_[0][2], value_[1][2], value_[2][2], value_[3][2], value_[0][3], value_[1][3], value_[2][3], value_[3][3] ); }
CCameraInfo& CWorld::GetCameraInfo() { g_CameraInfo.m_CameraOrg = m_CamOrg; float Q = m_ZFar/(m_ZFar-m_ZNear); g_CameraInfo.m_ProjectionMatrix = CMatrix( 1.0f/tan(0.5f*m_FOVX), 0, 0, 0, 0, 1.0f/tan(0.5f*m_FOVY), 0, 0, 0, 0, Q, 1, 0, 0, -Q*m_ZNear, 0 ); CVector CamUp = m_CamRight*m_CamDir; g_CameraInfo.m_ViewMatrix = CMatrix( m_CamRight.x, CamUp.x, m_CamDir.x, 0, m_CamRight.y, CamUp.y, m_CamDir.y, 0, m_CamRight.z, CamUp.z, m_CamDir.z, 0, -(m_CamRight^m_CamOrg), -(CamUp^m_CamOrg), -(m_CamDir^m_CamOrg), 1 ); return g_CameraInfo; }
CMatrix CMatrix::operator-( ) const { return CMatrix( -value_[0][0], -value_[0][1], -value_[0][2], -value_[0][3], -value_[1][0], -value_[1][1], -value_[1][2], -value_[1][3], -value_[2][0], -value_[2][1], -value_[2][2], -value_[2][3], -value_[3][0], -value_[3][1], -value_[3][2], -value_[3][3] ); }
CMatrix CMatrix::identityMatrix( ) { return CMatrix( 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0 ); }
CMatrix CMatrix::zeroMatrix( ) { return CMatrix( 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ); }
// 描画 void CSunLine::Draw(const LPDIRECT3DDEVICE9 lp_device) const { // レンダーステートやテクスチャなどは // マネージャーに任せる m_Borad.Draw( lp_device ); CMatrix mScale, mRotZ, mRotY; mScale.SetScale( 2.f, 12.f, 2.f ); mRotZ.SetRotZ( 15 ); mRotY.SetRotY( timeGetTime() / 50 % 360 ); lp_device->SetTransform( D3DTS_WORLD, &(mScale * mRotY * mRotZ * CMatrix( m_Pos )) ); CSXfileManager::GetInst()->GetData( "SpotLight.x" )->Draw( lp_device ); }
void CRenderSection::Reaction( long in_SrcSectionID, const CRenderSection_RenderObject_Request& in_rCmd ) { //CLog::Print(" CRenderSection::Reaction( const CRenderSection_RenderObject_Request& )\n"); if(m_Layer2.IsActive()) { CShadow* pShadow = in_rCmd.m_pShadow; RenderShadowRecurse( in_rCmd.m_pShadow, CMatrix() ); CRenderSection_RenderObject_Response Resp; Resp.m_pShadows.push_back(pShadow); CTCommandSender<CRenderSection_RenderObject_Response>::SendCommand( in_SrcSectionID, Resp ); } }