How the triangles/polygons are handled may be overkill but it allows for further growth when dealing with the triangles. The triangle structure includes float3 center, normal[4], point[3]; with float3 being a variable with 3 floats - x, y and z. In this case we have a center which helps with calculations, point[3] for the 3 points in the triangle and normal[4] which is for the main normal [0] and the 3 sides [1..3]. To calculate all the normals, all we have to do is first calculate the main normal. Once we get that value which shows the direction the plane is facing, we can normalize the value, which again sets the length to 1.
Now we can create a new triangles for the boundaries by using the base triangle and the normal to setup three other triangles:
newPoint1 = baseTrianglePoint1; newPoint2 = baseTrianglePoint2; newPoint3 = baseTrianglePoint1 + normal; |  |
This will allow a new triangle in which we can calculate a normal for. After doing this for all three edges we end up with four normals - one for the base triangle and three more for the sides. As can be seen in the picture, the green triangle is the original, the blue triangle is the newly formed triangle and the red line is new normal. With all four normals we can then calculate if a collision occurs within the boundaries:
1 - Does collision occur with main triangle? 2 - If so, calculate the collision point. 3 - Does the collision point occur within the boundaries? 4 - If so, calculate collision.
|