If anyone understands what I am doing (I hope someone does), if solution is zero (or near zero), then the camera has collided with the plane on which my_object (the triangle) lies. Although this is a step forward, now I need to figure out of the camera actually collides with the polygon itself, and not just the plane on which it lies. Anyone have any clues as to what step I should take next? Thanks in advance.

You could use the planes through the pairs of vertices of the triangle that are perpendicular to the triangle's plane, and check if the camera is in front of each of those planes to check whether it's within the triangle...

There may be better methods, of course, that's just off the top of my head. I'd try Google

take the vectors between the 3 vertices, V12, V13, V23, and the point and the vertices V1P, V2P, V3P

The point on the plane of the triangle is in the triangle
if V12.V13 > V12.V1P and V12.V1P > 0
and if -V23.V12 > V23.V2P and V23.V2P > 0
and if -V23.V13 > -V13.V2P and -V13.V2P > 0

This should be largely correct, the concept is that the angle of any pair of the edge vectors should be larger than the angle between one of the edge vectors and the vector to the point which originates from the common point of the edge pair in question.

You can get the vectors between the vertices, assuming they are numbered 1, 2, 3, by taking their coordinates and substracting them, so V12 = V2 - V1, and so on.

P is the camera's position mapped to the triangle and V1P = P - V1, etc.

You can project any point P0 to a plane if you know its normal, N, and a point on the plane, V. Simply project V-P0 onto N, and you get the vector pointing to the closest point on the plane. The procedure in my prev. post comes after this. You should check also that proj(V - P0, N).N is positive, in which case P0 is behind the triangle.

Quote:You can project any point P0 to a plane if you know its normal, N, and a point on the plane, V. Simply project V-P0 onto N, and you get the vector pointing to the closest point on the plane. The procedure in my prev. post comes after this. You should check also that proj(V - P0, N).N is positive, in which case P0 is behind the triangle

OK, DoooG, so should I be using the code I used in my first post in conjunction with the math in your 1st and 2nd post, or is the math in the quote above supposed to replace my code?

I initially tried your method in your 1st post along with my original code, and it doesn't appear to work. Here is what I am trying...

Oh yea, I'm assuming when you use "V12.V1P", the "." is supposed to represent Dot-Product, right?

It doesn't work possibly because dot_v12_v1p is negative for some reason, but then again, I probably just have something mixed up. Does your method take into account approximations? The way I am doing this doesn't actually place the camera position exactly on the plane of the triangle, just really close to it. Any ideas?

Inio, I am going to try your example once I make sense of all of it .

OneSadCookie:

Quote:You could use the planes through the pairs of vertices of the triangle that are perpendicular to the triangle's plane, and check if the camera is in front of each of those planes to check whether it's within the triangle...

Would I use cross-products to find triangles perpendicular to the plane? Sorry I keep asking all these questions, I failed Math 3 .

That should help you understand what it's doing. Also backface is to turn off collision checks against backface (points rotate clockwise around ray).

In general, how you would use this is set the start point to the position of the location of the camera in the previous frame, and the direction to the difference between the previous and current frame. If the value returned in t is in 0..1 (and the function returned true) then the movement of the camera passed through the triangle.

oh, and you probably want to take the "static" off the function, I forgot to delete that. (the codes as pasted is used as part of a larger mangle of bsp collision code, so static is appropriate.)

Well, I am not quite sure with the signs, but if you note, I did put some negative signs in my previous equations.

The pseudocode should be something like this:

if distance from point to plane < min_distance
if the point projected on the plane lies inside the triangle (by the dot product tests)
return true
else return false

I have just noticed I have not implemented this piece of code before, I will do it and test it to make sure, but I am sure the algorithm works, even if I made some sign mistakes.

Another thing is that it does matter which way the normal points. If it points the wrong way, eg. to the back of the tri, the test will obviously not work. And it should work even with an approximate projection to the triangle plane.

Quote:Originally posted by inio Two problems with that:
1. what if the camera moves more then 2*min_distance units in a single frame?
2. what about convex seams?

Convex seams? A triangle? I am lost

You have to consider the camera's position in the previous frame, draw a line segment to the current pos, find the intersection. If there is any, the camera collided, if there is none, it didn't. Additionally, you can test the end position, too.

Do you think you could possibly post an example using this method? I've tried several variations to it, but it doesn't seem to work properly. I can get it to sort of recognize a collision, but it's still not correct.

You aren't testing against a single triangle, you're testing against a mesh of triangles. where two triangles meet is called a seam. each seam can be classified as convex, concave, or planar depending on whether the triangles face away from each other, towards each other, or are coplanar. Your method works OK for situations where they're coplanar or face towards each other, but if the triangles face away from each other there's a sliver between the two triangles where you can get stuck.

Quote:Originally posted by inio You aren't testing against a single triangle, you're testing against a mesh of triangles. where two triangles meet is called a seam. each seam can be classified as convex, concave, or planar depending on whether the triangles face away from each other, towards each other, or are coplanar. Your method works OK for situations where they're coplanar or face towards each other, but if the triangles face away from each other there's a sliver between the two triangles where you can get stuck.

The method works for a single triangle, yes, that was asked, ircc. For a mesh, you obviously have to make some more assumptions, for example that the mesh is regular (a single surface). With a regular mesh, and allowing collisions with multiple triangles at the same time, things should work out just fine, since the proposed algorithm correctly determines collision with each individual triangle. Right? (i think)