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.

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:
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

share|improve this question
add comment

2 Answers 2

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.

share|improve this answer
    
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
1  
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
2  
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
add comment
up vote 0 down vote accepted

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

share|improve this answer
add comment

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.