How to find a Vehicle orientation over a 3D terrain?
Hello
I am working in a simple 3D car simulation where I drive a car over a unflat 3D terrain with slopes, currently I have implemented my collision detection routine between my car and the 3D terrain, I got 4 points exactly below my car's wheels, and also the plane's normal for each triengle below my car's wheel, but my trouble is how can I orient my car to match the terrain orientation?
PS: Dose anyone know if is possible to compute an average normal form all my intersected triangles?
Thanks in advance!
Oscar
Edited by - ogracian on October 16, 2001 3:32:13 AM
Add a proper suspension, i.e. put damped springs between the car body and wheels. Then drop it onto the surface. It will naturally settle down parallel to the surface, if the springs are balanced and the centre of gravity is between the four wheels. This copes well with an uneven surface or weight shift due e.g. to motion, as the springs can compress by different amounts to allow for the different forces on them.
John BlackburneProgrammer, The Pitbull Syndicate
October 16, 2001 04:06 PM
I think you should have built in a physics system with gravity and rigid bodies, not only a mathematical collision test. The body of the car would orient itself after some time.
Robert
developer of "Crashday" - http://www.moonbyte.de
Robert
developer of "Crashday" - http://www.moonbyte.de
October 16, 2001 04:09 PM
oh, forgot something ![](smile.gif)
an average normal is simply an average vector
![](smile.gif)
an average normal is simply an average vector
vector AvNormal;AvNormal.X = 0;AvNormal.Y = 0;AvNormal.Z = 0;for( int i = 0; i < 4; i++ ){ AvNormal.X += TerrNormal.X; AvNormal.Y += TerrNormal.Y;<br> AvNormal.Z += TerrNormal.Z;<br>}<br><br>AvNormal.X /= 4; // Average normal, but not normalized!<br>AvNormal.Y /= 4;<br>AvNormal.Z /= 4;<br><br> </pre> <br><br>Robert<br>developer of "Crashday" - http://www.moonbyte.de </i>
Hello
Thank you for your help, well I have implemented the terrain following in the following way (orient my veichle in terrain orientation):
- Get the collision triangle normal (for each wheel).
- computes the average normal from this 4 collision normals.
- use the Average Normal as my UP vector.
- Cross product of UP and AT(vehicle''s direction) to get my RIGHT Vector.
- Cross the new AT vector with UP to get my new AT Vector.
- Update''s vehicle matrix
And this works fine but the trouble is that the veichles dose not orient in a smoth way, I mean it change its orientation abruptly.
Thanks for your help
Oscar
Thank you for your help, well I have implemented the terrain following in the following way (orient my veichle in terrain orientation):
- Get the collision triangle normal (for each wheel).
- computes the average normal from this 4 collision normals.
- use the Average Normal as my UP vector.
- Cross product of UP and AT(vehicle''s direction) to get my RIGHT Vector.
- Cross the new AT vector with UP to get my new AT Vector.
- Update''s vehicle matrix
And this works fine but the trouble is that the veichles dose not orient in a smoth way, I mean it change its orientation abruptly.
Thanks for your help
Oscar
The basic solution to the original post is actually unsolvable. Think about it...your four wheels make up one plane (well, even just three wheels do that) and your terrain is of unpredictable height at each of those wheels. How on earth can you guarantee that the four points your wheel would rest on make a plane for your car to happily sit on? They can''t.
This has been a problem in many commercial games for years and it was previously solved simply by approximating it as best as possible and not really worry about exactly placing the vehicle on the terrain, or at least if one or more wheels is slightly off the ground. The effect can be hidden somewhat by cunning use of the car shadow and manipulating the camera so that the flaw is never exposed.
It seems you''ve already figured out one of the imprecise solutions yourself, but to get around the problem you have with it not orienting in a smooth way you could choose to interpolate between orientations rather than flick to them. You''d probably find this gives quite a nice effect.
Of course, the more modern solution is described by the other posters (springs and dampers) and acts almost as a normal car would anyway.
This has been a problem in many commercial games for years and it was previously solved simply by approximating it as best as possible and not really worry about exactly placing the vehicle on the terrain, or at least if one or more wheels is slightly off the ground. The effect can be hidden somewhat by cunning use of the car shadow and manipulating the camera so that the flaw is never exposed.
It seems you''ve already figured out one of the imprecise solutions yourself, but to get around the problem you have with it not orienting in a smooth way you could choose to interpolate between orientations rather than flick to them. You''d probably find this gives quite a nice effect.
Of course, the more modern solution is described by the other posters (springs and dampers) and acts almost as a normal car would anyway.
> Of course, the more modern solution is described by the other
> posters (springs and dampers) and acts almost as a normal car
> would anyway.
It''s up to you how it acts: A basic damped spring has two parameters, it''s bounce(elasticity) and damping. You can vary these to produce different dynamics, from monster-truck bouncyness to track-racing stiffness, or to simulate things like active supension and damage to suspension.
The nice thing about springs is they give you averaging and smoothness at the same time. If on all the time they produce such things as body roll in response to weight shift, e.g. when cornering or under heaving braking. And the force in each spring determines the weight on each wheel, needed for friction calculations.
John BlackburneProgrammer, The Pitbull Syndicate
Thanks for your help.
Well about damped spring method, sounds really good, but seems to be a little complicated and currently I am implementing the interpolation method (SLERP) but I am having troubles with it, so I really appreciate if anyone could tell me how can I convert my orientation matrix to a quaternion, then compute the new orientation, interpolate between old and new orient an convert the new orientation(interpolated quat) to a matrix?
PS: I have the original orientation and the new orient in differnts matrices, but I need interpolate it.
It seems really complicated to me![](sad.gif)
Thanks
Oscar
Edited by - ogracian on October 17, 2001 4:14:16 PM
Well about damped spring method, sounds really good, but seems to be a little complicated and currently I am implementing the interpolation method (SLERP) but I am having troubles with it, so I really appreciate if anyone could tell me how can I convert my orientation matrix to a quaternion, then compute the new orientation, interpolate between old and new orient an convert the new orientation(interpolated quat) to a matrix?
PS: I have the original orientation and the new orient in differnts matrices, but I need interpolate it.
It seems really complicated to me
![](sad.gif)
Thanks
Oscar
Edited by - ogracian on October 17, 2001 4:14:16 PM
To do the interpolation, don''t worry about quarternions. At the moment you''ve used an average normal. Just interpolate between the average normals and it should fit quite easily into what you have now.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement