Solved

Aligning Vehicle to terrain in OpenGL

Posted on 2003-11-04
12
1,210 Views
Last Modified: 2013-12-26
Hi all,

Im writing a 3D game which is written in C++ OpenGL, and in short is a bunch of tanks driving around a terrain.

(more info @ http://www.extremesolutions.asheltie.com/Latest.html )

Ok my problem is that i want to have the vehicles alligned to the ground.

Now under any given tank, the ground may consist of ~ 20 vertices.

I can get the x,y,z info of each of these vertices, as well as the polygon normals.

What i need to do is have it so the tank is aligned across the vertices in a realistic fashion.

Im happy to treat the Tanks chassis as a single plane right now, if thats any help...

Hard code or Algorithms welcome :)

Thanks,

-Rob-

0
Comment
Question by:Excalibur81
  • 6
  • 5
12 Comments
 
LVL 45

Expert Comment

by:sunnycoder
ID: 9685912
Hi Rob,

I am not into 3d graphics, but here are my two cents ...

what I could gather from your description was that you have an uneven terrain and you want tank to be placed on that terrain in such a way that it looks as if it is on an uneven terrain indeed... am I right?... If so, read further :o)

to get realistic alignment of tanks


              +----------------------------------+
              |        |                          |        |
              |____|                          |____|
              |                                            |
              |                                            |
              |                                            |
              |                                            |
              |                                            |
              |                                            |
              |                                            |
              |                                            |
              |                                            |
              |                                            |
              +----------------------------------+

assume that the outer big box is your tank chasis ... get terrain elevation at the boxes shown  ... similarly get terrain elevation at the lower left and right corners...

with respect to terrain, your tank can be inclined in two different ways (up or down and left or right) ...
to get the up/down alignment
take max of two front boxes ( F) and max of two rear boxes (R) and find F-R

to get right/left inclination, use the same process with two left boxes and two right boxes

NOTE::: The solution I suggested is purely intutive and I have no idea if it would really work

Cheers:o)
Sunny
0
 

Author Comment

by:Excalibur81
ID: 9690352
Thanks for the idea,

However, ive already implemented a similar idea to this (take a look at the latest news link :P )

The problem with this idea is....
What happens if say the height at the left of the tank is 20, and the height of the right is 30.

Now the tank will nicely incline it self with a small angle right?

Yes thats fine, but now imagine that in the middle of the tank is a higher piece of terrain, say 60 high.

The tank will dissappear into the mountain :)

So you see my quandry?!

I suspect the real answer will be an extension of your algorithm described above,


I posted a possible collision algorithm on my site, Have a read and see if you can come up with anything better,
http://www.extremesolutions.asheltie.com/Latest.html

Thanks,

-Rob-


0
 
LVL 45

Expert Comment

by:sunnycoder
ID: 9694073
the scenario you described was on my mind when I posted... If such a scenario arises, you tank should ideally be stuck on top of the mountain since none of its wheels will ever reach ground :p

anyway... the way out of this dilemma seems to be this

             +----------------------------------+
             |                                            |
             |______________________|
             |                                            |
             |                                            |
             |                                            |
             |                                            |
             |                                            |
             |                                            |
             |                                            |
             |                                            |
             |                                            |
             |                                            |
             +----------------------------------+

apply same method with a small front strip in additionto the two boxes... that way such elevation wont go unnoticed (you will be taking the maximum value )
0
 

Expert Comment

by:arudson
ID: 9695318
A quick and dirty way to do this would be to setup an "oriented bounding box" (OBB) that encompasses the tank. Then, you could test whether any terrain vertices are inside the bounding box. If you are familiar with the plane equation, this should be pretty routine:

Basically the idea here is you want to find the distance between each landscape vertex, and all 6 sides of the OBB. The plane equation does just that, it gives you the distance from a point to a plane.

Plane equation: Ax + By + Cz = D
Where: A,B,C are are the xyz components of the plane normal, and x,y,z are the components of the point (vertex) location. D is the resulting distance from the point (vertex) to the plane. Look closely, and you'll see this is literally just a dot product of the point and the plane normal.

Calculate that for each side of the OBB, and if you get all negative distance (D) values, the vertex is on the inside of the plane. Otherwise the point is outside the OBB.

SOOOoooo....

Since we're only concerned with the bottom of the tank (assuming your terrain has no caves) we will use the distance of the highest "breached" vertex from the bottom plane (the D value from the OBB's bottom-side plane equation). Raise the tank up by THAT value, and BOOM.. Your tank is now sitting ontop of your terrain. Of course, it won't be *aligned* to the terrain. That's a little more work, but this should at least spark some ideas in your mind about how that's accomplished.

Good luck!
0
 

Author Comment

by:Excalibur81
ID: 9696900
Arudson:

Thanks for your input !
I understand what you are saying, and i have already implemented an idea like this too.
But as you say,  
"Your tank is now sitting ontop of your terrain. Of course, it won't be *aligned* to the terrain. That's a little more work,"......

My original question was just how to align to terrain :)

Sunnycoder:

I see how this new front section would stop the tank from being able to drive 'through' a section of terrain,
But what about in the horizontal direction? The tank can still slide into the terrain (These are particularly "arcady" tanks :P )

I was thinking about your original idea, and then i thought about the center of gravity..

What if you extend the 4 boxes to all align at the center of the tank?

1 - Divide tank into 4 parts:
--------------
|       |       |
|------------|
|       |       |
--------------

2 - Get highest point in each sector

3 - Get highest point of 2 front sectors of tank, and same for to rear sectors.

4 - Determine angle from the difference in these heights, position tank at height = (some value relative to that point from the center line)

5 - Repeat 3 & 4 for left and right sectors

This way, the tank will be oriented against the terrain, and also with the center as the point at which orientaion takes place, making it the actual center of Gravity....

What do u think?
0
 

Author Comment

by:Excalibur81
ID: 9696934
Since i cant edit my post, let me correct a few things....

"But what about in the horizontal direction? The tank can still slide into the terrain ".....
I realise that puting a similar box across the sides of the tank will also solve this problem, but im merely suggesting a possible alternative....

Extension of steps in my alg...

4 - Determine angle from the difference in these heights, position tank at height = (some value relative to that point from the center line)

4a - Rotate tank about center point to this angle found at (4)

5 - Repeat 3, 4, & 4a for left and right sectors
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 45

Accepted Solution

by:
sunnycoder earned 200 total points
ID: 9700295
that's a good idea ... however, thinking about centre of gravity I have an idea too

your tank touches the ground on left and right throughout its length ...

find the highest elevation in the left and right strip and their respective position with respect to the centre of gravity

next find the ground highest elevation under tank chasis... If this is not included in the left and right strips and is high enough to touch the tank, use it for calculating alignment otherwise reject it...

your realistic alignment will be function of these values ...

you can assign some weight to elevation depending on its distance from COG. You are right in your algorithm about taking angles and stuff, but I feel that left and right strips with entire plane will give a better alignment. What do you say?
0
 

Author Comment

by:Excalibur81
ID: 9703757
hmmmm, thats a good idea.
I think your algorithm will give a more accurate alignment...

I only just finished uni exams yesterday (so haven't had much time to actually code this :P), so im going to spend today implementing both your algorithm and mine, and see which works best/runs fastest

I'll get back to you when i manage to sort out an answer.

Thanks for the dedication to my problem!

-Rob-
0
 

Author Comment

by:Excalibur81
ID: 9712607
Well thanks!

I tried both yours and my alg, and actually i had a few probs coding each, what with trying to determine if a particular height was more important than another, with respect to its distance from the C of G....

In any case, i have a solution that works *ok* for now, ill upload it to my web site, so u can see if u are interested.

(bare in mind, that the physics does not yet allow for the fact that a tank cannot scale a vertical cliff :D )

I went with my one for now, (i.e the 4 sectors) but i will definitly advance to your one later on,  Thanks heaps!

-Rob-
0
 
LVL 45

Expert Comment

by:sunnycoder
ID: 9712621
thats great ...
post back if you need more suggestions... If you are satisfied with the answers to current question then pls close it

Good luck
0
 
LVL 45

Expert Comment

by:sunnycoder
ID: 9712634
oops .. sorry, I mistook you to be a new user... just checked your profile ... you are familiar with closing questions and do not seem to abandon questions ... take your time but make sure that you do close it ;o)
0
 
LVL 45

Expert Comment

by:sunnycoder
ID: 9712636
what a timing :-D
thanks
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

As game developers, we quickly learn that Artificial Intelligence (AI) doesn’t need to be so tough.  To reference Space Ghost: “Moltar, I have a giant brain that is able to reduce any complex machine into a simple yes or no answer. (http://www.youtu…
Recently, in one of the tech-blogs I usually read, I saw a post about the best-selling video games through history. The first place in the list is for the classic, extremely addictive Tetris. Well, a long time ago, in a galaxy far far away, I was…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now