mat4 getMatFromPhysXTransform(PxTransform transform) { PxMat44 mat = PxMat44(transform); float m[16]; for (int i = 0; i < 16; ++i) m[i] = *(mat.front() + i); return mat4(m); }
void CTank::Update( float fDT ) { if( m_pActor ) { PxMat44 Matrix = physx::PxMat44( physx::PxMat33( m_pActor->getGlobalPose().q ), m_pActor->getGlobalPose().p ); D3DXMATRIX dxmat; memcpy( &dxmat._11, Matrix.front(), 4 * 4 * sizeof(float) ); if( GameObject* pBody = GetDetail( BODY ) ) pBody->SetReleaseMatrix( dxmat, true ); if( true ) { if( PxVehicleWheels* pDriveTank = CPhysX::GetPhysX()->GetTank() ) { PxShape* carShapes[ MAX_DETAIL ]; const PxU32 numShapes = m_pActor->getNbShapes(); m_pActor->getShapes( carShapes, numShapes ); for( PxU32 i = 0; i < numShapes - 1; ++i ) { const PxTransform& Trans = carShapes[ i ]->getLocalPose(); PxMat44 MatrixR = physx::PxMat44(physx::PxMat33( Trans.q ), Trans.p ); D3DXMATRIX dxmatR; memcpy( &dxmatR._11, MatrixR.front(), 4 * 4 * sizeof(float) ); if( GameObject* pObj = GetDetail( (EDetailTank)i ) ) pObj->SetReleaseMatrix( dxmatR * dxmat, true ); } PxVehicleDriveTank& vehDriveTank = static_cast< PxVehicleDriveTank& >( *pDriveTank ); PxVehicleDriveDynData& driveDynData = vehDriveTank.mDriveDynData; PxReal e = driveDynData.getEngineRotationSpeed(); m_fSpeedTank = pDriveTank->computeForwardSpeed(); static char t[ 256 ] = {0}; sprintf( t, "EngineRotationSpeed=%f, EngineRotationSpeed=%f", m_fSpeedTank, e ); //SetWindowText( GetForegroundWindow(), t ); PxVehicleDriveTankRawInputData carRawInputs( PxVehicleDriveTank::eDRIVE_MODEL_STANDARD ); carRawInputs.setDigitalAccel( m_bMoveForward || m_bMoveBack || m_bTurnLeft || m_bTurnRight ); carRawInputs.setDigitalLeftBrake( m_bTurnLeft ); // левая кнопка тормоза carRawInputs.setDigitalRightBrake( m_bTurnRight ); // правая кнопка тормоза carRawInputs.setDigitalLeftThrust( m_bMoveForward || !m_bTurnLeft ); carRawInputs.setDigitalRightThrust( m_bMoveForward || !m_bTurnRight ); if( !m_bMoveForward && !m_bMoveBack && !m_bTurnLeft && !m_bTurnRight ) { carRawInputs.setDigitalLeftBrake( true ); // левая кнопка тормоза carRawInputs.setDigitalRightBrake( true ); // правая кнопка тормоза } //carRawInputs.setGearUp( !m_bMoveForward && m_bMoveBack); //carRawInputs.setGearDown( !m_bMoveBack && m_bMoveForward ); // if( m_bMoveBack ) // { // carRawInputs.setDigitalLeftBrake( true ); // левая кнопка тормоза // carRawInputs.setDigitalRightBrake( true ); // правая кнопка тормоза // } static PxVehicleKeySmoothingData KeySmoothingData = { { 3.f, //rise rate eANALOG_INPUT_ACCEL 3.f, //rise rate eANALOG_INPUT_BRAKE 5.f, //rise rate eANALOG_INPUT_HANDBRAKE 2.f, //rise rate eANALOG_INPUT_STEER_LEFT 2.f, //rise rate eANALOG_INPUT_STEER_RIGHT }, { 5.f, //fall rate eANALOG_INPUT__ACCEL 5.f, //fall rate eANALOG_INPUT__BRAKE 10.f, //fall rate eANALOG_INPUT__HANDBRAKE 5.f, //fall rate eANALOG_INPUT_STEER_LEFT 5.f //fall rate eANALOG_INPUT_STEER_RIGHT } }; PxVehicleDriveTankSmoothDigitalRawInputsAndSetAnalogInputs( KeySmoothingData, carRawInputs, fDT, vehDriveTank ); } } } if( GameObject* pTankTrack = GetDetail( TRACK_L ) ) pTankTrack->SetOffsetUV( D3DXVECTOR4( 0.f, m_fSpeedTank*3, 0.f, 0.f ) ); if( GameObject* pTankTrack = GetDetail( TRACK_R ) ) pTankTrack->SetOffsetUV( D3DXVECTOR4( 0.f, m_fSpeedTank*3, 0.f, 0.f ) ); for( std::map< EDetailTank, GameObject* >::iterator iter = m_ObjectsTank.begin(), iter_end = m_ObjectsTank.end(); iter != iter_end; ++iter ) { GameObject* pObj = iter->second; pObj->Update( fDT ); } }
osg::Matrix toMatrix( const PxMat44& pmatrix ) { double m[16]; for ( int i=0; i<16; ++i ) m[i] = *(pmatrix.front() + i); return osg::Matrix(&m[0]); }