collission detect inside a mesh

Started by
3 comments, last by fguihen 19 years, 4 months ago
i created a room mesh in 3DS max, and exported it as a .x file. i have a simulation of a person running round in it in my c# app. the problem is i dont know how to make the person detect when he hits a wall and not pass through it. i have my charachters bounding sphere, but i cant see how to get the bounding sphere of a each wall, and that wouldnt help anyway. anyone advise me on how to solve this problem?
I currently only use c# and directX9, in case its relivant and i didnt mention it in the post
Advertisement
I'm a newbie with physics myself, but maybe this might help:

You can probably model this in 2D because I'm assuming your walls are all vertical planes... So for each wall, get 2 points, P1 and P2. Using those points you can define a line. How to actually get those points, I'm not sure :/

For your person running around, you can define his collision attributes as his position X and some radius R. Now, write or google for a "distance from point to line" function.

Now you code will look like this:


while( game is not over ){   oldPos = guy.Position   MoveGuy()      collisionOccurred = false   for each ( wall )   {      if( GetDistance( guy.Position, wall.Line ) < guy.Radius )      {         collisionOccurred = true      }   }   if( collisionOccurred )      guy.Position = oldPos}


This is a really simple and crappy way, but oh well hope it helps :)


EDIT: also I just thought, if your room is a simple rectangular solid, you could simply get the bounding box of the room and then compare the character against the boundaries directly...
What I would do is just check every triangle in the mesh against the person's bounding sphere. I think D3DX has a function for this (and if it doesn't there should be plenty of references online). If this becomes to slow (to many triangles to check against), you could probably implement some octree type culling for your collision detection.
There shouldn't be a need for a bounding sphere on your wall. Your looking at an intersection test between a Sphere and a plane. check out

http://www.gamasutra.com/features/19991018/Gomez_1.htm

Shadx
i cant use intersection between a sphere and a plain as my walls are not straight. they have curves and big semi circles along their length. i think il try comparing each triangle in the wall mesh with my persons bounding sphere. one question though. will the floor part of the mesh that my person is walking on not interfere, as the floor will always be inside the bounding sphere, from what id imagine?
I currently only use c# and directX9, in case its relivant and i didnt mention it in the post

This topic is closed to new replies.

Advertisement