• ### Popular Now

• 12
• 12
• 9
• 10
• 13

#### Archived

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

# collision with a heightmapped quad?

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

## Recommended Posts

i need to do collision detection with a heightmap, i can find the terrain ''cell'' that i am checking collision for in, so that leaves finding the heighth of the point between a h1, h2, h3 and h4. how do i do this?

hello?

##### Share on other sites
hey. so, here''s my solution to the same problem which i am working on as we speak (not fully implemented yet).

algorithm:

1. find out which quad you are in.

(if your quad is a level plane then you can skip this next part)
1b. figure out which triange of that quad you are in.

2a. find the normal to that triangle using the 3 vertices that compose it
2b. find k for the equation of the plane of that same triangle
go here to find how to play with plane equations:
http://www.geocities.com/SiliconValley/2151/math3d.html

3. use the x,z coords of the point you are trying to find the height of, and sub them into the equation of the plane you just calculated in step 2 and solve for y

there may be a more efficient way of doing it, but i haven''t figured one out yet.

-me

##### Share on other sites
I had the exact code on one way to do that, but I lost it a couple weeks ago.
It was basically just a series of cross multiplication questions.

Find the height along the top line of the cell by using the position from left-right.

   xpos         topHeight-------  = ---------------length      topRightCorner//where topHeight is what you are trying to find

Find the height along the bottom line like above.
Find the exact height by using those 2 positions to create a line through the center.

Probably some other, fancier way to do it, but I find that works just fine.

------------
aud.vze.com - The Audacious Engine <-- It''s not much, yet. But it''s mine... my own... my preciousssss...
MSN: nmaster42@hotmail.com, AIM: LockePick42, ICQ: 74128155

##### Share on other sites
quote:
Original post by Palidine
hey. so, here''s my solution to the same problem which i am working on as we speak (not fully implemented yet).

algorithm:

1. find out which quad you are in.

(if your quad is a level plane then you can skip this next part)
1b. figure out which triange of that quad you are in.

2a. find the normal to that triangle using the 3 vertices that compose it
2b. find k for the equation of the plane of that same triangle
go here to find how to play with plane equations:
http://www.geocities.com/SiliconValley/2151/math3d.html

3. use the x,z coords of the point you are trying to find the height of, and sub them into the equation of the plane you just calculated in step 2 and solve for y

there may be a more efficient way of doing it, but i haven''t figured one out yet.

-me

i like this idea, i don''t need it that accurate tho, its a racing game, i don'' tthink people will notice when the tire goes into the terrain slightly. oh well, the way i had it set up before was just a weighted average to the four points. if it was close to one of the points, that got the most ''share'' of the height average. but it would never get right to the corner of the polygon.