#### Archived

This topic is now archived and is closed to further replies.

# How to find a Vehicle orientation over a 3D terrain?

This topic is 6057 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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

##### Share on other sites
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.

##### Share on other sites
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

##### Share on other sites
oh, forgot something
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[i].Y;   AvNormal.Z += TerrNormal[i].Z;}AvNormal.X /= 4;   // Average normal, but not normalized!AvNormal.Y /= 4;AvNormal.Z /= 4;

Robert
developer of "Crashday" - http://www.moonbyte.de

##### Share on other sites
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.

Oscar

##### Share on other sites
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.

##### Share on other sites

> 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.

##### Share on other sites

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

Thanks
Oscar

Edited by - ogracian on October 17, 2001 4:14:16 PM

##### Share on other sites
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.

##### Share on other sites
Hello

Tank you all for your posts, it has been a valuable info!!

Best Regards!
Oscar

• 17
• 10
• 19
• 14
• 19