bounding sphere colission detection with a wall that is not a straight line

Started by
2 comments, last by DrGUI 19 years, 4 months ago
ok, i created a room in 3DS max and exported it as a .x file for directX. i have , in my application a simulation of a person moving through this room, the problem is the colission detection between the person and the walls. i cant do a simple plain/sphere intersection test, as the walls are not straight, they are curvy and in parts are made of semi-circles. i heard of a method where i compare each triangle in the mesh to see if it is inside the bounding sphere of my charachter. is there a function to do this in directX9? can anyone give me details of this method?.
I currently only use c# and directX9, in case its relivant and i didnt mention it in the post
Advertisement
I'm not sure if directX has a built in tri-sphere collision detection routine but writing your own isn't that difficult. Take a look at Magic Software for some source code for this as well as many other useful snippets. As far as implementing the collision detection in your game goes, I don't recomend testing every tri against your sphere if you want to keep that framerate up. Remember: the quickest algorithm is the one that never executes. For your situation I'd create a grid around the room and have each grid square contain pointers to the tris that overlap it. Then simply collide the sphere with only the tris in the same grid squares that the sphere overlaps. This way you'll be eliminating most of the tris straight away without having to collide them. For more complex environments with more dynamic objects you may even want to consider using multi-resolution grids or trees. Have fun.

edit: One last thing. Capsules are usualy better to use that spheres for characters since it'll give you a tighter fit whilst still being simple to use.
[size="1"] [size="4"]:: SHMUP-DEV ::
dude. this is all way over my head. the code, in magic software is all c++ code, and i find it almost impossible to read, as im a c# head. can you explain how you would place a grid around the room and then only have one check for each square? i have never implemented colission detection before so it seems very daunting
I currently only use c# and directX9, in case its relivant and i didnt mention it in the post
I use C# now, look at my siggy for other languages.
If you are using a vertex/index buffer, references to triangles might be difficult.
Instead of pointers, I suggest indices into the index buffer for the triangles.
I have never written any C++, but I learnt it when I was 11 (started programming at 9) and found it invaluable because all books and articles use it.
I think what MotorHerp was suggesting was a quad tree, or oct tree if your characters can fly or whatever. Search for that.
Hope this helps,

This topic is closed to new replies.

Advertisement