#### Archived

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

# Driving Over Terrain

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

## Recommended Posts

Hey, I''m working on a driving simulator. What are the various ways to make an object drive over a 3D terrain with hills? I want to compare the x,z position of the car, with that corresponding x,z position with the map, and find the height of the map, then raise the car to that position. Has anyone tried to do this. I''m having a tough time trying to triangulate the height from the position. Any help would be greatly appreciated. (The terrain is going to be a flat 3D smax model, set up in OpenGL just as primitive triangles, in vertex linked list)

##### Share on other sites
Well, first off, you can''t just get a point. I would find the center of the car, and find out where each wheel is. Then I''d compute the height at each wheel point, this defines a plane, and you can compute where the wheels touch. (watch out, jagged edges can go through the car this way)

To get the point there are different ways. You can always just shoot a vertical ray through the polygon directly under the wheel/car and the intersection is the terrain height. There must be a better way to do this though.

##### Share on other sites
quote:
Well, first off, you can''t just get a point. I would find the center of the car, and find out where each wheel is. Then I''d compute the height at each wheel point, this defines a plane, and you can compute where the wheels touch.

The problem with that approach is that it''ll only work on 3 wheeled vehicles, as you''re not guaranteed to have a perfectly flat plane when you have 4 points.

quote:

I want to compare the x,z position of the car, with that corresponding x,z position with the map, and find the height of the map, then raise the car to that position.
...
(The terrain is going to be a flat 3D smax model, set up in OpenGL just as primitive triangles, in vertex linked list)

If you''re going to take this approach (which is fine, there''s nothing wrong with it), there arent really any tricks you can use to find the height of a point on the map -- you''ll just have to use standard collision detection techniques (checking if a ray collides with a triangle, and if so where, etc.). It''d be a bit easier if you were to use a standard heightmap, but then you lose the ability to have overpasses and steep cliffs.

----------------------------------------
"Before criticizing someone, walk a mile in their shoes.
Then, when you do criticize them, you will be a mile away and have their shoes." -- Deep Thoughts
"If you have any trouble sounding condescending, find a Unix user to show you how it''s done." - Scott Adams
FaceHat Software -- Wear the hat.

##### Share on other sites
Well, you still have to compute 4 points, one for each wheel. The thing is, you also have to write some sort of spring code to your wheel so that it''s not always a flat plane, and have some sort of physics so that if the car drives and one wheel is over a cliff, the thing topples.

One way to do it, also is to make it a flying car ala star wars

then you just need to have 3 points, and you get the plane, and it''s easy.

##### Share on other sites
Great, thanks for the help guys.
I''m not worried about the wheels just yet, I simply want the car to follow the ground and roll over the hills. I will set up gravity and inertia eventually so the car will fly off of the cliffs and bounce, etc. But I just wanted to get an idea of how I can do this.

Now, the next big question...
How do you perform ray tracing/collision detection in OpenGL?
Is there a gl function call where I just specify which direction I want and the position of the vector, and it returns what it hits?

Thanks,
Sean

##### Share on other sites
do it with a collision detection. i think it will work.

##### Share on other sites
quote:
Is there a gl function call where I just specify which direction I want and the position of the vector, and it returns what it hits?

No, you''ll find that it is computationally faster if you just figure out a way to extract the Z coordinate from your terrain when given the X,Y coordinates. Or, for more specific people, find the next Z-hit down (and maybe next hit up?) from a given X,Y,Z coordinate.

1. 1
2. 2
Rutin
26
3. 3
4. 4
5. 5

• 9
• 13
• 19
• 14
• 9
• ### Forum Statistics

• Total Topics
632940
• Total Posts
3009329
• ### Who's Online (See full list)

There are no registered users currently online

×