D3DX9 Vehicle Trouble
-
- Posts: 4
- Joined: Mon Dec 21, 2009 2:28 am
D3DX9 Vehicle Trouble
Hello, I am having difficulty getting a simple raycast vehicle to work in my application. It appears to be a coordinate problem because, among other things, the wheels face the wrong direction and apparently rotate on the wrong axis. It took me a while to realize that if I don't make the car's chassis into a compound it floats away opposite of gravity.
I've tried tweaking the wheel direction and axis vectors with no luck. Having tweaked every value available, I am finally at my wit's end.
See attachment.
I've tried tweaking the wheel direction and axis vectors with no luck. Having tweaked every value available, I am finally at my wit's end.
See attachment.
You do not have the required permissions to view the files attached to this post.
-
- Posts: 4
- Joined: Mon Dec 21, 2009 2:28 am
Re: D3DX9 Vehicle Trouble
Alternatively, I've flirted with using a hinge constraint and cylinder system but the car pops wildly while traversing a perfectly even and flat plane. This is fascinatingly frustrating for me.
Is there another way to go about this?
I perused the forklift demo of 2.75 breifly and it appears to be another raycast vehicle implementation. Am I right?
Surely there's another way and maybe there could be demo of that method also.
Sorry for double posting, I'm on my PSP which disallows proper productivity.
Is there another way to go about this?
I perused the forklift demo of 2.75 breifly and it appears to be another raycast vehicle implementation. Am I right?
Surely there's another way and maybe there could be demo of that method also.
Sorry for double posting, I'm on my PSP which disallows proper productivity.
-
- Posts: 4
- Joined: Mon Dec 21, 2009 2:28 am
Re: D3DX9 Vehicle Trouble
Spheres... using spheres as wheels seems to work. The sideward sliding is an issue, though.
Since this thread is mainly my own rhetoric, I'll post my progress.
A very rough vehicle simulation w/o raycasts. NOTHING spectacular.
Since this thread is mainly my own rhetoric, I'll post my progress.
A very rough vehicle simulation w/o raycasts. NOTHING spectacular.
You do not have the required permissions to view the files attached to this post.
-
- Posts: 17
- Joined: Tue Aug 18, 2009 2:48 pm
Re: D3DX9 Vehicle Trouble
I think you are having the same trouble as I had.
I think it is a bug:
http://bulletphysics.org/Bullet/phpBB3/ ... f=9&t=3963
I think it is a bug:
http://bulletphysics.org/Bullet/phpBB3/ ... f=9&t=3963
-
- Site Admin
- Posts: 4221
- Joined: Sun Jun 26, 2005 6:43 pm
- Location: California, USA
Re: D3DX9 Vehicle Trouble
Currently only two configurations are supported, as shown in the Bullet/Demos/VehicleDemo: either Z axis up with X as right axis and Y forward
or Y axis up with X axis right and Z axis forward:
You will need to modify the btRaycastVehicle source code for other configurations.
Thanks,
Erwin
Code: Select all
int rightIndex = 0;
int upIndex = 2;
int forwardIndex = 1;
btVector3 wheelDirectionCS0(0,0,-1);
btVector3 wheelAxleCS(1,0,0);
Code: Select all
int rightIndex = 0;
int upIndex = 1;
int forwardIndex = 2;
btVector3 wheelDirectionCS0(0,-1,0);
btVector3 wheelAxleCS(-1,0,0);
Thanks,
Erwin
-
- Posts: 17
- Joined: Tue Aug 18, 2009 2:48 pm
Re: D3DX9 Vehicle Trouble
If the change suggested in this post:
http://bulletphysics.org/Bullet/phpBB3/ ... f=9&t=3963
is made I don't think there would be a need for such a requirement.
Thanks,
John
http://bulletphysics.org/Bullet/phpBB3/ ... f=9&t=3963
is made I don't think there would be a need for such a requirement.
Thanks,
John
-
- Site Admin
- Posts: 4221
- Joined: Sun Jun 26, 2005 6:43 pm
- Location: California, USA
Re: D3DX9 Vehicle Trouble
Unfortunately this change breaks the Bullet vehicle demos.
Do you have a solution with backwards compatibility?
Thanks,
Erwin
Do you have a solution with backwards compatibility?
Thanks,
Erwin
-
- Posts: 17
- Joined: Tue Aug 18, 2009 2:48 pm
Re: D3DX9 Vehicle Trouble
Ooops
Sorry, I thought I checked this and it didn't break the demos.
My bad, I should not have called this a "bug fix".
I'll look at it again, and maybe have a fix that does not break demos.

Sorry, I thought I checked this and it didn't break the demos.
My bad, I should not have called this a "bug fix".
I'll look at it again, and maybe have a fix that does not break demos.
-
- Posts: 17
- Joined: Tue Aug 18, 2009 2:48 pm
Re: D3DX9 Vehicle Trouble
I think that I've fixed it.
Here is the diff.
< //wheel.m_worldTransform.setBasis(steeringMat * rotatingMat * basis2);
< wheel.m_worldTransform.setBasis(steeringMat * rotatingMat * btMatrix3x3(m_chassisBody->getOrientation()));
---
> wheel.m_worldTransform.setBasis(steeringMat * rotatingMat * basis2);
565,566c564,565
< wheelBasis0[2][m_indexRightAxis]);
<
---
> wheelBasis0[2][m_indexRightAxis]);
>
568,572c567,571
< //btScalar proj = m_axle.dot(surfNormalWS);
< //m_axle -= surfNormalWS * proj;
< //m_axle = m_axle.normalize();
<
< m_forwardWS = m_axle.cross( surfNormalWS );
---
> btScalar proj = m_axle.dot(surfNormalWS);
> m_axle -= surfNormalWS * proj;
> m_axle = m_axle.normalize();
>
> m_forwardWS[i] = surfNormalWS.cross(m_axle[i]);
574a574
>
Pertaining to the changes I made:
I can't understand why the surface normal times "proj" would be subtracted from the original axle direction.
Once you have the axle (right) and normal, the forward is the cross of the axle with the up.
My guess is the original author talked himself into needing the erroneous changes because the first error (described above) was missed.
I did run the vehicle & forklift demo and they work.
(Before forward was back and back was forward, I didn't notice)
All changes were made in btRaycastVehicle.cpp.
I tried to attach a patch file but the forum post wouldn't let attach it, so here it is in the post:
***************
*** 118,124 ****
right[2],fwd[2],up[2]
);
! wheel.m_worldTransform.setBasis(steeringMat * rotatingMat * basis2);
wheel.m_worldTransform.setOrigin(
wheel.m_raycastInfo.m_hardPointWS + wheel.m_raycastInfo.m_wheelDirectionWS * wheel.m_raycastInfo.m_suspensionLength
);
--- 118,125 ----
right[2],fwd[2],up[2]
);
! //wheel.m_worldTransform.setBasis(steeringMat * rotatingMat * basis2);
! wheel.m_worldTransform.setBasis(steeringMat * rotatingMat * btMatrix3x3(m_chassisBody->getOrientation()));
wheel.m_worldTransform.setOrigin(
wheel.m_raycastInfo.m_hardPointWS + wheel.m_raycastInfo.m_wheelDirectionWS * wheel.m_raycastInfo.m_suspensionLength
);
***************
*** 561,577 ****
m_axle[i] = btVector3(
wheelBasis0[0][m_indexRightAxis],
wheelBasis0[1][m_indexRightAxis],
! wheelBasis0[2][m_indexRightAxis]);
!
const btVector3& surfNormalWS = wheelInfo.m_raycastInfo.m_contactNormalWS;
! btScalar proj = m_axle[i].dot(surfNormalWS);
! m_axle[i] -= surfNormalWS * proj;
! m_axle[i] = m_axle[i].normalize();
!
! m_forwardWS[i] = surfNormalWS.cross(m_axle[i]);
m_forwardWS[i].normalize();
-
resolveSingleBilateral(*m_chassisBody, wheelInfo.m_raycastInfo.m_contactPointWS,
*groundObject, wheelInfo.m_raycastInfo.m_contactPointWS,
btScalar(0.), m_axle[i],m_sideImpulse[i],timeStep);
--- 562,577 ----
m_axle[i] = btVector3(
wheelBasis0[0][m_indexRightAxis],
wheelBasis0[1][m_indexRightAxis],
! wheelBasis0[2][m_indexRightAxis]);
!
const btVector3& surfNormalWS = wheelInfo.m_raycastInfo.m_contactNormalWS;
! //btScalar proj = m_axle[i].dot(surfNormalWS);
! //m_axle[i] -= surfNormalWS * proj;
! //m_axle[i] = m_axle[i].normalize();
!
! m_forwardWS[i] = m_axle[i].cross( surfNormalWS );
m_forwardWS[i].normalize();
resolveSingleBilateral(*m_chassisBody, wheelInfo.m_raycastInfo.m_contactPointWS,
*groundObject, wheelInfo.m_raycastInfo.m_contactPointWS,
btScalar(0.), m_axle[i],m_sideImpulse[i],timeStep);
Here is the diff.
< //wheel.m_worldTransform.setBasis(steeringMat * rotatingMat * basis2);
< wheel.m_worldTransform.setBasis(steeringMat * rotatingMat * btMatrix3x3(m_chassisBody->getOrientation()));
---
> wheel.m_worldTransform.setBasis(steeringMat * rotatingMat * basis2);
565,566c564,565
< wheelBasis0[2][m_indexRightAxis]);
<
---
> wheelBasis0[2][m_indexRightAxis]);
>
568,572c567,571
< //btScalar proj = m_axle.dot(surfNormalWS);
< //m_axle -= surfNormalWS * proj;
< //m_axle = m_axle.normalize();
<
< m_forwardWS = m_axle.cross( surfNormalWS );
---
> btScalar proj = m_axle.dot(surfNormalWS);
> m_axle -= surfNormalWS * proj;
> m_axle = m_axle.normalize();
>
> m_forwardWS[i] = surfNormalWS.cross(m_axle[i]);
574a574
>
Pertaining to the changes I made:
I can't understand why the surface normal times "proj" would be subtracted from the original axle direction.
Once you have the axle (right) and normal, the forward is the cross of the axle with the up.
My guess is the original author talked himself into needing the erroneous changes because the first error (described above) was missed.
I did run the vehicle & forklift demo and they work.
(Before forward was back and back was forward, I didn't notice)
All changes were made in btRaycastVehicle.cpp.
I tried to attach a patch file but the forum post wouldn't let attach it, so here it is in the post:
***************
*** 118,124 ****
right[2],fwd[2],up[2]
);
! wheel.m_worldTransform.setBasis(steeringMat * rotatingMat * basis2);
wheel.m_worldTransform.setOrigin(
wheel.m_raycastInfo.m_hardPointWS + wheel.m_raycastInfo.m_wheelDirectionWS * wheel.m_raycastInfo.m_suspensionLength
);
--- 118,125 ----
right[2],fwd[2],up[2]
);
! //wheel.m_worldTransform.setBasis(steeringMat * rotatingMat * basis2);
! wheel.m_worldTransform.setBasis(steeringMat * rotatingMat * btMatrix3x3(m_chassisBody->getOrientation()));
wheel.m_worldTransform.setOrigin(
wheel.m_raycastInfo.m_hardPointWS + wheel.m_raycastInfo.m_wheelDirectionWS * wheel.m_raycastInfo.m_suspensionLength
);
***************
*** 561,577 ****
m_axle[i] = btVector3(
wheelBasis0[0][m_indexRightAxis],
wheelBasis0[1][m_indexRightAxis],
! wheelBasis0[2][m_indexRightAxis]);
!
const btVector3& surfNormalWS = wheelInfo.m_raycastInfo.m_contactNormalWS;
! btScalar proj = m_axle[i].dot(surfNormalWS);
! m_axle[i] -= surfNormalWS * proj;
! m_axle[i] = m_axle[i].normalize();
!
! m_forwardWS[i] = surfNormalWS.cross(m_axle[i]);
m_forwardWS[i].normalize();
-
resolveSingleBilateral(*m_chassisBody, wheelInfo.m_raycastInfo.m_contactPointWS,
*groundObject, wheelInfo.m_raycastInfo.m_contactPointWS,
btScalar(0.), m_axle[i],m_sideImpulse[i],timeStep);
--- 562,577 ----
m_axle[i] = btVector3(
wheelBasis0[0][m_indexRightAxis],
wheelBasis0[1][m_indexRightAxis],
! wheelBasis0[2][m_indexRightAxis]);
!
const btVector3& surfNormalWS = wheelInfo.m_raycastInfo.m_contactNormalWS;
! //btScalar proj = m_axle[i].dot(surfNormalWS);
! //m_axle[i] -= surfNormalWS * proj;
! //m_axle[i] = m_axle[i].normalize();
!
! m_forwardWS[i] = m_axle[i].cross( surfNormalWS );
m_forwardWS[i].normalize();
resolveSingleBilateral(*m_chassisBody, wheelInfo.m_raycastInfo.m_contactPointWS,
*groundObject, wheelInfo.m_raycastInfo.m_contactPointWS,
btScalar(0.), m_axle[i],m_sideImpulse[i],timeStep);
-
- Site Admin
- Posts: 4221
- Joined: Sun Jun 26, 2005 6:43 pm
- Location: California, USA
Re: D3DX9 Vehicle Trouble
Can you attach a zipped patch (preferably using svn, for example tortoisesvn), or use the issue tracker at http://bullet.googlecode.com?
Thanks a lot,
Erwin
Thanks a lot,
Erwin
-
- Posts: 17
- Joined: Tue Aug 18, 2009 2:48 pm
Re: D3DX9 Vehicle Trouble
Here it is:


You do not have the required permissions to view the files attached to this post.
-
- Posts: 4
- Joined: Mon Dec 21, 2009 2:28 am
Re: D3DX9 Vehicle Trouble
Thank you, Erwin and jrk, for your interest in solving my problem. I will look into this patch you've presented ASAP.
Bullet's working a lot better for me since my last posts here, though I had moved on without the satisfaction of a decent vehicle simulation, perhaps I can continue with my project. Thanks again.
Bullet's working a lot better for me since my last posts here, though I had moved on without the satisfaction of a decent vehicle simulation, perhaps I can continue with my project. Thanks again.
-
- Posts: 178
- Joined: Fri Apr 18, 2008 2:20 pm
Re: D3DX9 Vehicle Trouble
Hi,
I am experiencing an issue that might be linked with that one... My coordinate system is D3D-like, so I am using the following :
int rightIndex = 0;
int upIndex = 1;
int forwardIndex = 2;
btVector3 vWheelDirectionCS0(0.0f, -1.0f, 0.0f);
btVector3 vWheelAxleCS(-1.0f, 0.0f, 0.0f);
m_pVehicle->setCoordinateSystem(rightIndex,upIndex,forwardIndex);
So basically this should be a supported system...
See the video below, and see how the wheel orientation jumps...
http://www.youtube.com/watch?v=k4eZFxR7Las
Is it related to the issue mentioned above ? should I apply the patch, even if the coords system used should be supported ?
Thanks
Greg
I am experiencing an issue that might be linked with that one... My coordinate system is D3D-like, so I am using the following :
int rightIndex = 0;
int upIndex = 1;
int forwardIndex = 2;
btVector3 vWheelDirectionCS0(0.0f, -1.0f, 0.0f);
btVector3 vWheelAxleCS(-1.0f, 0.0f, 0.0f);
m_pVehicle->setCoordinateSystem(rightIndex,upIndex,forwardIndex);
So basically this should be a supported system...
See the video below, and see how the wheel orientation jumps...
http://www.youtube.com/watch?v=k4eZFxR7Las
Is it related to the issue mentioned above ? should I apply the patch, even if the coords system used should be supported ?
Thanks
Greg
-
- Posts: 178
- Joined: Fri Apr 18, 2008 2:20 pm
Re: D3DX9 Vehicle Trouble
Hi, it seems the issue came from some of my other code.
Now, the only issue is that I need to rotate the wheel by 180° around Y, but I can live with that
Now, the only issue is that I need to rotate the wheel by 180° around Y, but I can live with that

-
- Posts: 7
- Joined: Wed May 16, 2012 1:30 pm
Re: D3DX9 Vehicle Trouble
I applied this patch just in case it was related to the issue I was having but no luck.
If I turn the steering left and right they seem to rotate correctly but if i move forward or backwards the wheels rotate on the wrong axis,
Any ideas?
I'm using
int rightIndex = 0;
int upIndex = 1;
int forwardIndex = 2;
m_vehicle->setCoordinateSystem(rightIndex, upIndex, forwardIndex);
and
btVector3 wheelDirectionCS0(0,-1,0);
btVector3 wheelAxleCS(-1,0,0);
Duncan.
If I turn the steering left and right they seem to rotate correctly but if i move forward or backwards the wheels rotate on the wrong axis,
Any ideas?
I'm using
int rightIndex = 0;
int upIndex = 1;
int forwardIndex = 2;
m_vehicle->setCoordinateSystem(rightIndex, upIndex, forwardIndex);
and
btVector3 wheelDirectionCS0(0,-1,0);
btVector3 wheelAxleCS(-1,0,0);
Duncan.