Math/Plane: Fix construction from 3 points

This commit is contained in:
SirLynix 2023-06-23 13:23:26 +02:00
parent b2538028b4
commit 2f1e2f94d7
3 changed files with 5 additions and 3 deletions

View File

@ -460,7 +460,7 @@ namespace Nz
T farW = farH * ratio; T farW = farH * ratio;
Vector3<T> f = Vector3<T>::Normalize(target - eye); Vector3<T> f = Vector3<T>::Normalize(target - eye);
Vector3<T> u(up.GetNormal()); Vector3<T> u = Vector3<T>::Normalize(up);
Vector3<T> s = Vector3<T>::Normalize(f.CrossProduct(u)); Vector3<T> s = Vector3<T>::Normalize(f.CrossProduct(u));
u = s.CrossProduct(f); u = s.CrossProduct(f);

View File

@ -17,6 +17,8 @@ namespace Nz
template<typename T> template<typename T>
class Plane class Plane
{ {
// Note: this class follows the ax + by + cz + d = 0 equation, which means d is the distance from origin
public: public:
constexpr Plane() = default; constexpr Plane() = default;
constexpr Plane(T normalX, T normalY, T normalZ, T Distance); constexpr Plane(T normalX, T normalY, T normalZ, T Distance);

View File

@ -88,7 +88,7 @@ namespace Nz
normal = edge1.CrossProduct(edge2); normal = edge1.CrossProduct(edge2);
normal.Normalize(); normal.Normalize();
distance = normal.DotProduct(point3); distance = -normal.DotProduct(point3);
} }
/*! /*!
@ -139,7 +139,7 @@ namespace Nz
template<typename T> template<typename T>
constexpr T Plane<T>::SignedDistance(const Vector3<T>& point) const constexpr T Plane<T>::SignedDistance(const Vector3<T>& point) const
{ {
return normal.DotProduct(point) + distance; // ax + by + cz + d = 0. return normal.DotProduct(point) + distance; // ax + by + cz + d = 0
} }
/*! /*!