Commit 238afe3c authored by Patrik Huber's avatar Patrik Huber

Added a function that calculates the per-vertex normal

parent 681f89e9
...@@ -79,6 +79,24 @@ inline cv::Vec2f screen_to_clip_space(const cv::Vec2f& screen_coordinates, int s ...@@ -79,6 +79,24 @@ inline cv::Vec2f screen_to_clip_space(const cv::Vec2f& screen_coordinates, int s
return cv::Vec2f(x_cs, y_cs); return cv::Vec2f(x_cs, y_cs);
}; };
/**
* Calculates 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.
*/
cv::Vec3f calculate_face_normal(const cv::Vec3f& v0, const cv::Vec3f& v1, const cv::Vec3f& v2)
{
cv::Vec3f n = (v1 - v0).cross(v2 - v0); // v0-to-v1 x v0-to-v2
n /= cv::norm(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