Driving Over Terrain

Started by
5 comments, last by TimesOldRoman 21 years, 1 month ago
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)
Advertisement
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.
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.
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.
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
do it with a collision detection. i think it will work.
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.
RIP GameDev.net: launched 2 unusably-broken forum engines in as many years, and now has ceased operating as a forum at all, happy to remain naught but an advertising platform with an attached social media presense, headed by a staff who by their own admission have no idea what their userbase wants or expects.Here's to the good times; shame they exist in the past.

This topic is closed to new replies.

Advertisement