Triangle - Triangle Intersection/Collision Detection
Author |
Message |
ncvitak
|
Posted: Wed Jun 05, 2013 9:28 pm Post subject: Triangle - Triangle Intersection/Collision Detection |
|
|
I am working on a game, and I am going to use triangle - triangle collision detection, since all 3d meshes are made out of triangles. However I can't seem to find out how to do it. Please help me if you can. Thanks!
I have the following:
// Vector3f: a class i created to represent a 3D vector with public numeric variables x,y,z
class Vector3f {
public:
float x;
float y;
float z;
//additional operator overloads for vector3f - vector3f, or vector3f - scalar operations
//Ex: +, -, *, /, etc...
};
Vector3f Tri1[3]; //3 Verticies, which can be interpreted as 3D vectors for Triangle 1
Vector3f Tri2[3]; //3 Verticies, which can be interpreted as 3D vectors for Triangle 2
bool TriangleTriangleCollisionDetected(Vector3f T1[3], Vector3f T2[3]) {
//code to check if the 2 triangles intersect
//returns true if the intersect
//returns false if they do not intersect
} |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Insectoid
|
Posted: Wed Jun 05, 2013 9:55 pm Post subject: RE:Triangle - Triangle Intersection/Collision Detection |
|
|
I was reading through this StackOverflow thread, which has a good solution, but then I got to the bottom and it links to this thread on compsci.ca.
Basically, you need to check all the lines against each other to see if they intersect, and if they don't, then check to see if any corner is inside the other triangle. If they aren't, then they haven't collided. Otherwise, they have. |
|
|
|
|
|
Tony
|
|
|
|
|
ncvitak
|
|
|
|
|
|
|