Vehicle wheel mesh rotation problem

Started by
0 comments, last by KOzymandias 15 years, 4 months ago
I'm working with vehicles in Physx and I'm having a problem rotating the wheels correctly. Physx gives you a world matrix for the wheel as if the wheel was a fixed part of the vehicle's body and it's up to you to rotate your wheel mesh to the correct steering angle and pitch as the wheel rolls along the ground. I can add the steering rotation (Yaw) and everthing works correctly but the wheel doesn't look like its rolling along the ground, this is as far as the Physx vehicle demo goes. When I try to add the pitch rotation the wheel mesh wobbles around and makes it look like the wheel is loose and about to fall off. I'm guessing I'm not rotating on the correct axis, but I havn't been able to figure it out. I would appreciate and help you can give. Thanks.


m_pSUVTireMesh->m_fPitch += NxAllVehicles::getActiveVehicle()->getWheel(0)->getRpm() / 35 * m_dElpasedTime;
if (m_pSUVTireMesh->m_fPitch >= D3DXToRadian(360))
	m_pSUVTireMesh->m_fPitch = 0;

if (m_pSUVTireMesh->m_fPitch < 0)
	m_pSUVTireMesh->m_fPitch = D3DXToRadian(360);



NxAllVehicles::getActiveVehicle()->getActor()->getShapes()[1]->getGlobalPose().getColumnMajor44(m_pSUVTireMesh->m_matWorld);

	
float fRadius = NxAllVehicles::getActiveVehicle()->getWheel(0)->getRadius();
float fSteerAngle = NxAllVehicles::getActiveVehicle()->getWheel(0)->getAngle();

NxVec3 vTirePos = NxAllVehicles::getActiveVehicle()->getActor()->getShapes()[1]->getGlobalPosition();


NxMat33 matRotation = NxAllVehicles::getActiveVehicle()->getActor()->getShapes()[1]->getGlobalOrientation();


m_pSUVTireMesh->Translate(vTirePos.x,vTirePos.y,vTirePos.z);

	
D3DXMATRIX matSteer,matRotScale,matPitch,matPitchSteer,matRoll;


D3DXMatrixTranslation(&m_pSUVTireMesh->m_matTranslation,vTirePos.x,vTirePos.y,vTirePos.z);
D3DXMatrixScaling(&m_pSUVTireMesh->m_matScale,1,1,1);



D3DXVECTOR3 vAxis(0,1,0);	

D3DXVECTOR3 vAxis2(m_pSUVTireMesh->m_matWorld._31,0,m_pSUVTireMesh->m_matWorld._33);

D3DXVECTOR3 vRight;

D3DXVECTOR3 vUp(0,1,0);


D3DXVec3Cross( &vRight, &vUp, &vAxis2);


D3DXMatrixRotationAxis(&m_pSUVTireMesh->m_matRotation,&vAxis,0);

D3DXMATRIX matPitch2,matPitch3,matSteerPitch;

D3DXMatrixRotationAxis(&matSteer,&vAxis,fSteerAngle);
D3DXMatrixRotationAxis(&matPitch,&vRight,m_pSUVTireMesh->m_fPitch);	
D3DXMatrixMultiply(&matSteerPitch,&matPitch,&matSteer);




D3DXMatrixMultiply(&m_pSUVTireMesh->m_matRotation,&m_pSUVTireMesh->m_matRotation,&matSteer);
D3DXMatrixMultiply(&m_pSUVTireMesh->m_matRotation,&m_pSUVTireMesh->m_matRotation,&matPitch);	
D3DXMatrixMultiply(&matRotScale,&m_pSUVTireMesh->m_matRotation,&m_pSUVTireMesh->m_matScale);


D3DXVECTOR3 vPos;
vPos.x = m_pSUVTireMesh->m_matWorld._41;
vPos.y = m_pSUVTireMesh->m_matWorld._42;
vPos.z = m_pSUVTireMesh->m_matWorld._43;

D3DXMatrixMultiply(&m_pSUVTireMesh->m_matWorld,&m_pSUVTireMesh->m_matWorld,&matRotScale);

m_pSUVTireMesh->m_matWorld._41 = vPos.x;
m_pSUVTireMesh->m_matWorld._42 = vPos.y;
m_pSUVTireMesh->m_matWorld._43 = vPos.z;


Advertisement
Maybe it's just the order in which rotations are applied : yaw then pitch or pitch then yaw will give different results.

This topic is closed to new replies.

Advertisement