Skip to main content
GameDev.net gamedev.net
🔒 Locked

collision detection

Started by dawid Mar 1, 2004 at 4:12 PM 2 replies 450+ views
Original Post
dawid
dawid
how do i detect the colision between a plane(2 triangles Sharing 4 vertices) and my camera (which would be one point) what would be the best :-)
Spy
adam17
adam17
if its only those five points then (what i would do) check the angle of the camera''s point and one of the points on the plane. only do this if its a flat plane. if the angle is negative then its below. if its positive then the camera is on top and youre in the green.

its just an idea.
-adam
Bobby-D
Bobby-D
Firstly, you need to get the cameras motion as a line. The position before the move is one end of the line, and the position after the move is another point of the line.

To determine if there was a collision with the plane, you can get the distance of each point from the plane using the plane equation Ax +By+ Cz + D = DistanceFromPlane. Use this for each end, and then multiply the two results together. There is only a collision with the plane if the result of the multiplication is < 0.

You then need to get the point of collsion. This is a bit tricky. Perhaps the easiest way to understand would be to get the distance from the plane of the StartPoint of the line. Then divide this distance by the length of the line to get a ratio. You can multiply the Motion vector (line) by the ratio for to get an offset vector. The CollisionPoint the equals the StartPoint + the Offset vector.

The final step is then to determin if the collision point is within the polygon. If vectors are created from the Collsion Point to each vert of the polygon, we can add the angles between them. If the sum of the internal angles is less then 360 degrees then the point is inside the triangle and a collision did occur. You may have to test if the Sum of the angles are less than 359 or some number no quite 360 because of rounding errors. It all depends on the accuracy you require.

I would recommend adding a radius test for the camera, but this is a bit more complicated.

One by one, the peguins steal my sanity.
One by one, the peguins steal my sanity.
dawid
dawid
means nothing to me - dude im dumn (and young 14)
Spy

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.