#### Archived

This topic is now archived and is closed to further replies.

This topic is 5753 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

can someone write me a few lines of code showing how to do collision detection using dot products and cross products. the collision detection like in the book open gl game programming. i want to write my own collision detection functions but can''t figure out exactly what i need to do. please?

##### Share on other sites
Well, I don''t have my own collision detection code handy, but there are tons of tutorials for simpler stuff on the internet.

For example:
http://www.gamasutra.com/features/20020118/vandenhuevel_01.htm

##### Share on other sites
Uhm... give us an example of the object pair(s) that you need to check collisions for... a lot of collision detection doesn''t even need dot/cross products (unless you consider Projection a use of Dot).

##### Share on other sites
i'm checking against walls. i have an array of triangle data like so:

struct triangle
{
float point1[3];
float point2[3];
float point3[3];
};

triangle currentscene[10000];

don't know if that's a good way of doing it but it'll do for now.

after that i want a function that checks to see if you collide with the triangles. btw can you tell me how to check the distance from your position to the triangle so i don't have to check for collision if it to far away.

[edited by - hello_there on January 22, 2003 8:25:09 PM]

[edited by - hello_there on January 22, 2003 12:33:15 AM]

##### Share on other sites
Ahh... triangles vs. triangles. yes, I have seen dot and cross product used for that...

I believe the theory is that you find out where the 3 lines from one triangle intersect the plane of the other triangle, and then use dot products to see if any of those points are inside the second triangle.

And since I don''t remember the equations off the top of my head, I guess it''s google time!

Also, you probably don''t want to use a distance check to see if any triangle is too far away. What you want is a system where if you are on one side of a plane, then you don''t have to check any of the triangles on the other side... These are called BSPs, quadtrees or octtrees.

1. 1
Rutin
46
2. 2
3. 3
4. 4
5. 5
JoeJ
19

• 11
• 15
• 9
• 10
• 13
• ### Forum Statistics

• Total Topics
633004
• Total Posts
3009836
• ### Who's Online (See full list)

There are no registered users currently online

×