mirror of https://github.com/AxioDL/zeus.git
Add CPlane::rayPlaneIntersection
This commit is contained in:
parent
9d40c78f6e
commit
16985b0e9b
|
@ -48,11 +48,13 @@ public:
|
|||
d = nd * mag;
|
||||
}
|
||||
|
||||
float pointToPlaneDist(const zeus::CVector3f& pos) const
|
||||
float pointToPlaneDist(const CVector3f& pos) const
|
||||
{
|
||||
return pos.dot(vec) - d;
|
||||
}
|
||||
|
||||
bool rayPlaneIntersection(const CVector3f& from, const CVector3f& to, CVector3f& point) const;
|
||||
|
||||
const CVector3f& normal() const { return vec; }
|
||||
|
||||
inline float& operator[](size_t idx) { return p[idx]; }
|
||||
|
|
|
@ -1 +1,18 @@
|
|||
#include "zeus/CPlane.hpp"
|
||||
|
||||
namespace zeus
|
||||
{
|
||||
|
||||
bool CPlane::rayPlaneIntersection(const CVector3f& from, const CVector3f& to, CVector3f& point) const
|
||||
{
|
||||
zeus::CVector3f delta = to - from;
|
||||
if (std::fabs(delta.normalized().dot(vec)) < 0.01f)
|
||||
return false;
|
||||
float tmp = -pointToPlaneDist(from) / delta.dot(vec);
|
||||
if (tmp < -0.f || tmp > 1.0001f)
|
||||
return false;
|
||||
point = delta * tmp + from;
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue