As you may be able to tell from this screenshot, I am trying to make a physics engine for a platformer I am working on, but I have run into a definite problem: I need to be able to find out the angle of any one of the triangles that you can see make up this mesh, so that I can work out the rotation and therefore angular acceleration of the player on that triangle.
I can use an algorithm that I created to find the locations of all 3 points of any triangle that the player is in contact with, but I don't know how to use those points to work out the rotation of the triangle.
By the rotation, I mean the direction of the normal away from the centre of the face, i.e., the angle at which a person would be leaning if they stood on that surface. Can someone come up with a series of equations that will allow for this problem to be solved?
If you take the cross product of the two vectors:
p1 - p0
and
p2 - p0
where p0
, p1
and p2
are three vertices of the triangle, you'll get the normal. A triangle is considered to be pointing towards you if the vertices are ordered clockwise with respect to its outward normal. This is called the left hand rule. Imagine holding your left hand with your fingers curled from p0
to p1
, your thumb sticks out in the direction of the face normal: