Archived

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

ogracian

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

Recommended Posts

ogracian    180
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 this post


Link to post
Share on other sites
johnb    351
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 this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
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 this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
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 this post


Link to post
Share on other sites
ogracian    180
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

Share this post


Link to post
Share on other sites
freakchild    572
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 this post


Link to post
Share on other sites
johnb    351

> 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 this post


Link to post
Share on other sites
ogracian    180
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

Thanks
Oscar

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

Share this post


Link to post
Share on other sites
freakchild    572
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 this post


Link to post
Share on other sites
ogracian    180
Hello

FreakChild: about the normal interpolation method, could you be a little more specific about it, maybe some code would be a plus,
because I am doing LERP beetween my current normal and my desired plane normal, but it dose not work, so I really appreciate so much any help.

Ex:
a = MatrixGetUp(car_matrix);
b = collision_PlaneNormal;
p = lerp(a, b, DeltaTime);

//
// computes vehicle new orientation
// based in p (the interpolated normal)
up = &p;
CrossProduct(right, up, at);
Normalize(right, right);
CrossProduct(at, right, up);
Normalize(at, at);
MatrixUpdate(car_matrix);

Thanks!
Oscar


Share this post


Link to post
Share on other sites
freakchild    572
I can''t really see anything wrong with that. Without the lerp I guess your code more or less puts ''b'' as the up vector. b is the average of the normals taken from your wheels.

In the new function, it''s the desired orientation and you simply interpolate to the desired each frame. You''ve probably got the idea of that already, but no harm in being sure about it.

With the pseudo code you presented being okay, I suspect the problem is deeper. As the psuedo code is just your old code, which flicked between orientations and it worked, you might want to check that lerp function and be sure it''s working.

You mention what you''ve done so far with the lerp doesn''t work...what are the actual results though?

Share this post


Link to post
Share on other sites