43 */ |
43 */ |
44 glm::vec3 geom::normalVector(const geom::Triangle& triangle) |
44 glm::vec3 geom::normalVector(const geom::Triangle& triangle) |
45 { |
45 { |
46 return glm::normalize( |
46 return glm::normalize( |
47 glm::cross( |
47 glm::cross( |
48 triangle.points[1] - triangle.points[0], |
48 triangle.p2 - triangle.p1, |
49 triangle.points[2] - triangle.points[0])); |
49 triangle.p3 - triangle.p1)); |
50 } |
50 } |
51 |
51 |
52 /** |
52 /** |
53 * @brief Extracts the scaling component of the specified matrix into a vector and returns both the scaling |
53 * @brief Extracts the scaling component of the specified matrix into a vector and returns both the scaling |
54 * components as well as the unscaled matrix. |
54 * components as well as the unscaled matrix. |
105 |
105 |
106 std::optional<glm::vec2> geom::rayLineSegmentIntersection(const Ray<2>& ray, const LineSegment2D& line) |
106 std::optional<glm::vec2> geom::rayLineSegmentIntersection(const Ray<2>& ray, const LineSegment2D& line) |
107 { |
107 { |
108 std::optional<glm::vec2> result = lineLineIntersection( |
108 std::optional<glm::vec2> result = lineLineIntersection( |
109 rayToLine(ray), |
109 rayToLine(ray), |
110 lineFromPoints(line.points[0], line.points[1])); |
110 lineFromPoints(line.p1, line.p2)); |
111 if (result.has_value()) |
111 if (result.has_value()) |
112 { |
112 { |
113 const float d1 = glm::dot(*result - ray.anchor, ray.direction); |
113 const float d1 = glm::dot(*result - ray.anchor, ray.direction); |
114 if (d1 < 0) |
114 if (d1 < 0) |
115 { |
115 { |
116 result.reset(); |
116 result.reset(); |
117 } |
117 } |
118 else |
118 else |
119 { |
119 { |
120 const float d2 = glm::dot(*result - line.points[0], *result - line.points[1]); |
120 const float d2 = glm::dot(*result - line.p1, *result - line.p2); |
121 if (d2 > 0) |
121 if (d2 > 0) |
122 { |
122 { |
123 result.reset(); |
123 result.reset(); |
124 } |
124 } |
125 } |
125 } |