Pārlūkot izejas kodu

Add plane::from_point_and_normal

Daniele Bartolini 10 gadi atpakaļ
vecāks
revīzija
0aa85f8d8b
1 mainītis faili ar 11 papildinājumiem un 0 dzēšanām
  1. 11 0
      src/core/math/plane.h

+ 11 - 0
src/core/math/plane.h

@@ -21,6 +21,9 @@ const Plane PLANE_ZAXIS = { VECTOR3_ZAXIS, 0.0f };
 /// @ingroup Math
 namespace plane
 {
+	/// Returns the plane defined by @a point and @a normal.
+	Plane from_point_and_normal(const Vector3& point, const Vector3& normal);
+
 	/// Normalizes the plane @a p and returns its result.
 	Plane& normalize(Plane& p);
 
@@ -31,6 +34,14 @@ namespace plane
 
 namespace plane
 {
+	inline Plane from_point_and_normal(const Vector3& point, const Vector3& normal)
+	{
+		Plane p;
+		p.n = normal;
+		p.d = -dot(normal, point);
+		return p;
+	}
+
 	inline Plane& normalize(Plane& p)
 	{
 		const float len = length(p.n);