View Full Version : Collision detection
Hi! I wonder how can i check collisions with non-simple objects. Being more precisly - i have 3d terrain map and i want to check if i am going through the ground or not. Any ways I could do it?
02-11-2003, 10:10 AM
If it's a heightmap, all you have to do is to check whether you're above the ground. Something like
if myHeight < heightmap[myX, myZ] then damnIHitTheGround();
In general, collision detection isn't opengl related, so you might more information on some game developement sites.
02-11-2003, 10:59 AM
Check out www.gametutorials.com (http://www.gametutorials.com) for some collision detection tuts.
Thanks. Indeed it is a way to that but it won't be any precise method I think. Collisions would look like that :
I mean that terrain isn't usually flat. Meaby i am thinking in a wrong way. Whatever...
Although thanks. Meaby I should check some game development site.
linearly interpolate the ground height based upon the surrounding height map data
heightmap data ( 0 or 1):
0 0 0
0 1 0
A X B
0 0 0
if you are at position (0.5,2.5) as shown by X find the height of the ground under X
1) find equation of line between known points AB as z = f(x)
1A) find gradient - note gradient cannot = infinity so we dont have to deal with that case
1B) find "b" (y=mx+b)
sub new X value into z = f(x) to find new Z value
im not sure if you need to repeat the process for the z=f(y) and average them. ive got a hunch that they will be the same in all cases. im not going to figure it out. http://www.opengl.org/discussion_boards/ubb/smile.gif
standard disclaimers for stupidity apply
I'll check it out! Thanks
Powered by vBulletin® Version 4.2.2 Copyright © 2015 vBulletin Solutions, Inc. All rights reserved.