Save hours in development time and avoid common mistakes by learning the best practices to use for JavaScript.

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-

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-

Experts Exchange Solution brought to you by

Enjoy your complimentary solution view.

Get every solution instantly with Premium.
Start your 7-day free trial.

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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-

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 )

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!

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?

"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

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?

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trialI 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-

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-

post back if you need more suggestions... If you are satisfied with the answers to current question then pls close it

Good luck

Game Programming

From novice to tech pro — start learning today.

Experts Exchange Solution brought to you by

Enjoy your complimentary solution view.

Get every solution instantly with Premium.
Start your 7-day free trial.

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