67 lines
1.3 KiB
C++
67 lines
1.3 KiB
C++
namespace math
|
|
{
|
|
|
|
template <class T>
|
|
inline plane<T>::plane()
|
|
: normal(0, 0, 1)
|
|
, offset(0)
|
|
{
|
|
}
|
|
|
|
template <class T>
|
|
inline plane<T>::plane(ZUninitialized tag) : normal(tag)
|
|
{
|
|
}
|
|
|
|
template <class T>
|
|
inline plane<T>::plane(const vec3<T>& ipoint, const vec3<T>& inormal)
|
|
: normal(inormal)
|
|
, offset(-dot(ipoint, normal))
|
|
{
|
|
TL_PLAIN_ASSERT(is_normalized(inormal));
|
|
}
|
|
|
|
template <class T>
|
|
inline plane<T>::plane(const vec3<T>& point1, const vec3<T>& point2, const vec3<T>& point3)
|
|
{
|
|
normal = normalized(cross(point2 - point1, point3 - point1));
|
|
TL_PLAIN_ASSERT(is_normalized(normal));
|
|
offset = -dot(point1, normal);
|
|
}
|
|
|
|
template <class T>
|
|
inline bool plane<T>::operator==(const plane<T>& other) const
|
|
{
|
|
return offset == other.offset && normal == other.normal;
|
|
}
|
|
|
|
template <class T>
|
|
inline bool plane<T>::operator!=(const plane<T>& other) const
|
|
{
|
|
return !(*this == other);
|
|
}
|
|
|
|
template <class T>
|
|
inline vec3<T> plane<T>::get_member_point() const
|
|
{
|
|
return normal * -offset;
|
|
}
|
|
|
|
template <class T>
|
|
plane<T>& plane<T>::invert()
|
|
{
|
|
this_t tmp = *this;
|
|
tmp.normal = -normal;
|
|
tmp.offset = -dot(tmp.normal, get_member_point());
|
|
*this = tmp;
|
|
return *this;
|
|
}
|
|
|
|
template <class T>
|
|
T plane<T>::signed_distance(const vec3<T>& point) const
|
|
{
|
|
return dot(normal, point) + offset;
|
|
}
|
|
|
|
}
|