Commit 30a65230 authored by Patrik Huber's avatar Patrik Huber

Added compute_face_normal function for glm vectors

We have two of these functions now, one for glm::vec3 and one for cv::Vec3f. At some point, this needs clean-up!
parent 92c1d843
...@@ -99,6 +99,24 @@ cv::Vec3f calculate_face_normal(const cv::Vec3f& v0, const cv::Vec3f& v1, const ...@@ -99,6 +99,24 @@ cv::Vec3f calculate_face_normal(const cv::Vec3f& v0, const cv::Vec3f& v1, const
return n; return n;
}; };
/**
* Computes the normal of a face (or triangle), i.e. the
* per-face normal. Return normal will be normalised.
* Assumes the triangle is given in CCW order, i.e. vertices
* in counterclockwise order on the screen are front-facing.
*
* @param[in] v0 First vertex.
* @param[in] v1 Second vertex.
* @param[in] v2 Third vertex.
* @return The unit-length normal of the given triangle.
*/
glm::vec3 compute_face_normal(const glm::vec3& v0, const glm::vec3& v1, const glm::vec3& v2)
{
glm::vec3 n = glm::cross(v1 - v0, v2 - v0); // v0-to-v1 x v0-to-v2
n = glm::normalize(n);
return n;
};
/** /**
* Draws the texture coordinates (uv-coords) of the given mesh * Draws the texture coordinates (uv-coords) of the given mesh
* into an image by looping over the triangles and drawing each * into an image by looping over the triangles and drawing each
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment