I am having an issue with selecting a coordinate system for my raycast vehicle.
I would like to use an X-forward, Y-left, Z-up system to match the rest of our code, however, when I use:
m_vehicle->setCoordinateSystem(-1, 2, 0); (or 1, 2 0)
with my axles set to:
btVector3 wheelAxle(0,-1,0);
Though the wheels are aligned with the vehicle correctly and spin correctly, the vehicle moves sideways. When I say "spin correctly" I mean the wheels rotate with vehicle forwards/back motion. They do not spin when shifting sideways.
When I use:
m_vehicle->setCoordinateSystem(0, 2, 1)
with
btVector3 wheelAxle(0,-1,0);
The wheels are aligned properly and the vehicle moves properly, but the wheel rotation corresponds to vehicle sideways motion (that is, the wheels do not spin when driving forward, only when sliding sideways, though they spin as through the vehicle was moving forward).
Thanks,
Nick
RaycastVehicle coordinate system problem
-
wazootyman
- Posts: 2
- Joined: Wed Aug 11, 2010 3:18 pm
Re: RaycastVehicle coordinate system problem
Nothing? Is it not currently possible to create a vehicle with an X-forward coordinate system?
I am currently running with a Y-forward coordinate system and it works:
m_vehicle->setCoordinateSystem(0, 2, 1);
btVector3 wheelDirection(0, 0, -1);
but I am still hoping for an X-forward solution.
-Nick
I am currently running with a Y-forward coordinate system and it works:
m_vehicle->setCoordinateSystem(0, 2, 1);
btVector3 wheelDirection(0, 0, -1);
but I am still hoping for an X-forward solution.
-Nick
-
fido
- Posts: 14
- Joined: Sun Mar 22, 2009 5:57 pm
Re: RaycastVehicle coordinate system problem
I have the same problem and I need to solve it very quickly. I'll try to fix the btRaycastVehicle code, if nobody else did it 
-
fido
- Posts: 14
- Joined: Sun Mar 22, 2009 5:57 pm
Re: RaycastVehicle coordinate system problem
the first problem is in this method:
void btRaycastVehicle::updateWheelTransform( int wheelIndex , bool interpolatedTransform)
on the start of computations there are fwd/right/up axes which seems to be OK
and they correctly reflect any coordinate system. After multiplying them with rotations from
wheel rotation and steer rotation, they are completely wrong. As they are used for
friction computation, impulses etc., it's clear that there is root of all problems.
I'll try to rearrange these computations. They seems to be over-complicated anyway.
void btRaycastVehicle::updateWheelTransform( int wheelIndex , bool interpolatedTransform)
on the start of computations there are fwd/right/up axes which seems to be OK
and they correctly reflect any coordinate system. After multiplying them with rotations from
wheel rotation and steer rotation, they are completely wrong. As they are used for
friction computation, impulses etc., it's clear that there is root of all problems.
I'll try to rearrange these computations. They seems to be over-complicated anyway.
-
fido
- Posts: 14
- Joined: Sun Mar 22, 2009 5:57 pm
Re: RaycastVehicle coordinate system problem
Well, I've working RaycastVehicle for X-axis case. I had no time to implement it compatible with
other cases, so it's not final solution.
Here is the first change:
void btRaycastVehicle::updateWheelTransform( int wheelIndex , bool interpolatedTransform)
{
btWheelInfo& wheel = m_wheelInfo[ wheelIndex ];
updateWheelTransformsWS(wheel,interpolatedTransform);
btVector3 up = -wheel.m_raycastInfo.m_wheelDirectionWS;
const btVector3& right = wheel.m_raycastInfo.m_wheelAxleWS;
btVector3 fwd = up.cross(right);
fwd = fwd.normalize();
//rotate around steering over de wheelAxleWS
btScalar steering = wheel.m_steering;
btMatrix3x3 rotatingMat;
rotatingMat.setEulerYPR(-steering,-wheel.m_rotation,0);
btMatrix3x3 basis2;
basis2[0][m_indexForwardAxis] = fwd.x();
basis2[1][m_indexForwardAxis] = fwd.y();
basis2[2][m_indexForwardAxis] = fwd.z();
basis2[0][m_indexRightAxis] = right.x();
basis2[1][m_indexRightAxis] = right.y();
basis2[2][m_indexRightAxis] = right.z();
basis2[0][m_indexUpAxis] = up.x();
basis2[1][m_indexUpAxis] = up.y();
basis2[2][m_indexUpAxis] = up.z();
wheel.m_worldTransform.setBasis(basis2 * rotatingMat);
wheel.m_worldTransform.setOrigin(
wheel.m_raycastInfo.m_hardPointWS + wheel.m_raycastInfo.m_wheelDirectionWS * wheel.m_raycastInfo.m_suspensionLength
);
}
and second change is in this method:
void btRaycastVehicle::updateFriction(btScalar timeStep)
this line:
rollingFriction = wheelInfo.m_engineForce* timeStep;
must be changed to this:
rollingFriction = -wheelInfo.m_engineForce* timeStep;
I hope it will help someone.
other cases, so it's not final solution.
Here is the first change:
void btRaycastVehicle::updateWheelTransform( int wheelIndex , bool interpolatedTransform)
{
btWheelInfo& wheel = m_wheelInfo[ wheelIndex ];
updateWheelTransformsWS(wheel,interpolatedTransform);
btVector3 up = -wheel.m_raycastInfo.m_wheelDirectionWS;
const btVector3& right = wheel.m_raycastInfo.m_wheelAxleWS;
btVector3 fwd = up.cross(right);
fwd = fwd.normalize();
//rotate around steering over de wheelAxleWS
btScalar steering = wheel.m_steering;
btMatrix3x3 rotatingMat;
rotatingMat.setEulerYPR(-steering,-wheel.m_rotation,0);
btMatrix3x3 basis2;
basis2[0][m_indexForwardAxis] = fwd.x();
basis2[1][m_indexForwardAxis] = fwd.y();
basis2[2][m_indexForwardAxis] = fwd.z();
basis2[0][m_indexRightAxis] = right.x();
basis2[1][m_indexRightAxis] = right.y();
basis2[2][m_indexRightAxis] = right.z();
basis2[0][m_indexUpAxis] = up.x();
basis2[1][m_indexUpAxis] = up.y();
basis2[2][m_indexUpAxis] = up.z();
wheel.m_worldTransform.setBasis(basis2 * rotatingMat);
wheel.m_worldTransform.setOrigin(
wheel.m_raycastInfo.m_hardPointWS + wheel.m_raycastInfo.m_wheelDirectionWS * wheel.m_raycastInfo.m_suspensionLength
);
}
and second change is in this method:
void btRaycastVehicle::updateFriction(btScalar timeStep)
this line:
rollingFriction = wheelInfo.m_engineForce* timeStep;
must be changed to this:
rollingFriction = -wheelInfo.m_engineForce* timeStep;
I hope it will help someone.