1
\$\begingroup\$

My current status

I have already read some tutorials about 3d collision. I know how ray trace works and how to convert mouse follow a vector to track the closest object that collides with out vector I have also worked with 2d collisions before and I've seen some collision samples from "apphub".

My Problem

My problem is mainly because all the tutorials I have read are about collisions over 3d models on .fbx format but I don't use model files... I use simple primitives... So what methods do I need to check to be able to know if a 2d sprite has collided with my 3d isometric triangle? Also bounding box will have blank spaces outside my triangle borders that will return a false positive.

Main Questions

  1. Is there a way to transform primitive into 3d models so i can use Ray.Intersect?
  2. Do I need to transform the vertices into 2d points and then check if any pixel from sprite is between these 3 lines?
  3. I'm also aware of boundingbox but it doesnt seems to be a good solution since we are talking about a triangle not a square. Or should I create a bounding box around the 2d sprite and then try to collide over all the Z's?

If you need clarification please let me know. I'm not very good in explaining myself.

thanks

\$\endgroup\$

2 Answers 2

1
\$\begingroup\$

Why not making a BoundingBox and/or Triangle with the 2D volume being with the Z dimension at 0? Then use XNAs built in intersects methods.

\$\endgroup\$
3
  • \$\begingroup\$ I haven't used BoundingBox before so I'm not aware of its limitations. I think I understand what you mean but my question is since I'm working with a triangle inside a "box" Won't I have many false positives? \$\endgroup\$
    – Navy Seal
    Commented Aug 16, 2012 at 10:58
  • 1
    \$\begingroup\$ If you're looking for good approximations, create a trianglular prism volume and write an intersects method for that. If you need fine control of detections for physics, why not use a physics engine? \$\endgroup\$ Commented Aug 16, 2012 at 13:43
  • 2
    \$\begingroup\$ I think this is the right answer, but it needs elaboration. The built-in bounding box is world-orthoganal, and it definitely wouldn't work. \$\endgroup\$ Commented Aug 22, 2012 at 16:01
0
\$\begingroup\$

I tried using the bounding box but as I suspected this method lacks of precision to be used with triangles.

So what I did was... instead using a bounding box I choose doing the collision in 2d. I used Viewport.unproject to convert the vertices from the triangle which was generated in 3d world and then instead using the whole 2d sprite I picked a point in the center of the sprite.

After some research I chosen to use this method to improve the collision to triangle.

http://www.gamespp.com/algorithms/CollisionDetectionTutorial.html

This algorithm connects a chosen point to all the vertices and it creates vectors. Then it tries to sum the angle made by the pair of each vertices. If the sum of the angles is 360 then the point is inside the triangle.

The samples in apphub for 3d collision use another algorithm developed by Tomas Moller and Ben Trumbore http://www.graphics.cornell.edu/pubs/1997/MT97.html

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .