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).


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

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.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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