Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

In the 3d fps in java I'm working on, I need a bullet to be fired and to tell if it hit someone. All visual objects in the game are defined through OpenGL, so the object it can be colliding with can be any drawable polygon (although they will most likely be triangles and rectangles anyways). The bullet is not an object, but will be treated as a vector that instantaneously moves all the way across the map (like the snipper riffle in Halo). What's the best way to detect/test collisions with the polygon and the vector. I have access to OpenCL, however I have absolutely no experience with it. I am very early in the developmental stage, so if you think there's a better way of going about this, feel free to tell me (I barley have a player model to collide with anyways, so I'm flexible with it).

Thanks

share|improve this question
    
-1 There are tons of material about it in the net, didn't do research. –  Maik Semder Jul 1 '11 at 6:22
    
keywords to search for starters "ray triangle intersection" –  Maik Semder Jul 1 '11 at 10:00
    
agreed; -1 also. –  TravisG Jul 1 '11 at 14:34
    
Also check out bounding spheres and ray - bounding sphere intersection. –  Roy T. Jul 1 '11 at 15:44

1 Answer 1

You will probably want to define the types of polygons that you support. The easiest would be triangles since they can be rendered by OpenGL, and they also have a wealth of literature on the topic of "Ray/Triangle Intersection".

Once you pick your set of supported shapes, you will need to implement the required Ray/Shape intersection tests for each shape.

Assuming you are there, and that you implement a method for shape that is: double GetIntersectionT(Ray r) - Returns -1.0 if the intersection test fails.

You iterate over all of your scene shapes (Yes there are spatial partitioning schemes, but you obviously aren't there yet), and call this method on each of them. Store the smallest positive result along with the shape that returned it. Once all shapes have been tested, you know the first object to get hit.

The beauty of this method is that it also allows you to constrain T in such a way that you can ignore shapes that are too far out if you wanted to.

Also, if you are asking how to do this with OpenGL, you should know (At least this is as much as I know) that OpenGL is only a rendering engine, and not a physics engine (what you are trying to build), and therefore you will need your own API to test these things.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.