# XNA How to detect collision between 2d sprites and 3d primitives (not models)

My current status:
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:
Is there a way to transform primitive into 3d models so i can use Ray.Intersect?
Do I need to transform the vertices into 2d points and then check if any pixel from sprite is between these 3 lines?
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

-

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.

-
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? – Navy Seal Aug 16 '12 at 10:58
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? – Vaughan Hilts Aug 16 '12 at 13:43
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. – Seth Battin Aug 22 '12 at 16:01

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

-