Add CLine

This commit is contained in:
Jack Andersen 2017-03-30 12:35:40 -10:00
parent 726fff8299
commit 76e20eb4c8
5 changed files with 38 additions and 17 deletions

View File

@ -74,6 +74,7 @@ add_library(zeus
include/zeus/CFrustum.hpp include/zeus/CFrustum.hpp
include/zeus/CAABox.hpp include/zeus/CAABox.hpp
include/zeus/COBBox.hpp include/zeus/COBBox.hpp
include/zeus/CLine.hpp
include/zeus/CLineSeg.hpp include/zeus/CLineSeg.hpp
include/zeus/CSphere.hpp include/zeus/CSphere.hpp
include/zeus/CUnitVector.hpp include/zeus/CUnitVector.hpp

18
include/zeus/CLine.hpp Normal file
View File

@ -0,0 +1,18 @@
#ifndef CLINE_HPP
#define CLINE_HPP
#include "Global.hpp"
#include "zeus/CVector3f.hpp"
namespace zeus
{
class CLine
{
public:
CLine(const CVector3f& origin, const CVector3f& dir) : origin(origin), dir(dir) {}
CVector3f origin;
CVector3f dir;
};
}
#endif

View File

@ -1,5 +1,5 @@
#ifndef CLINE_HPP #ifndef CLINESEG_HPP
#define CLINE_HPP #define CLINESEG_HPP
#include "Global.hpp" #include "Global.hpp"
#include "zeus/CVector3f.hpp" #include "zeus/CVector3f.hpp"
@ -13,12 +13,12 @@ public:
{ {
CVector3f tmp = (end - start).normalized(); CVector3f tmp = (end - start).normalized();
if (tmp.x != 0 || tmp.y != 0 || tmp.z != 0) if (tmp.x != 0 || tmp.y != 0 || tmp.z != 0)
normal = tmp.normalized(); dir = tmp.normalized();
else else
normal = CVector3f::skZero; dir = CVector3f::skZero;
} }
CVector3f normal; CVector3f dir;
CVector3f start; CVector3f start;
CVector3f end; CVector3f end;
}; };

View File

@ -8,30 +8,32 @@ namespace zeus
{ {
struct CMRay struct CMRay
{ {
CMRay(const CVector3f& start, const CVector3f& end, float d) : start(start), d(d), invD(1.f / d), end(end) CMRay(const CVector3f& start, const CVector3f& dirin, float len)
: start(start), length(len), invLength(1.f / len), dir(dirin)
{ {
normal = start + (d * end); end = start + (len * dirin);
delta = normal - start; delta = dirin - start;
} }
CMRay(const CVector3f& start, const CVector3f& norm, float d, float invD) : start(start), normal(norm), d(d), invD(invD) CMRay(const CVector3f& start, const CVector3f& end, float len, float invLen)
: start(start), end(end), length(len), invLength(invLen)
{ {
delta = normal - start; delta = end - start;
end = invD * delta; dir = invLen * delta;
} }
CMRay getInvUnscaledTransformRay(const CTransform& xfrm) const CMRay getInvUnscaledTransformRay(const CTransform& xfrm) const
{ {
const CTransform inv = xfrm.inverse(); const CTransform inv = xfrm.inverse();
return CMRay(inv * start, inv * normal, d, invD); return CMRay(inv * start, inv * end, length, invLength);
} }
CVector3f start; // x0 CVector3f start; // x0
CVector3f normal; // xc CVector3f end; // xc
CVector3f delta; // x18 CVector3f delta; // x18
float d; // x24 float length; // x24
float invD; // x28 float invLength; // x28
CVector3f end; // x2c CVector3f dir; // x2c
}; };
} }

View File

@ -12,7 +12,7 @@ class alignas(16) CPlane
public: public:
ZE_DECLARE_ALIGNED_ALLOCATOR(); ZE_DECLARE_ALIGNED_ALLOCATOR();
inline CPlane() {} inline CPlane() : a(1.f), d(0.f) {}
CPlane(float a, float b, float c, float d) : a(a), b(b), c(c), d(d) {} CPlane(float a, float b, float c, float d) : a(a), b(b), c(c), d(d) {}
CPlane(const CVector3f& a, const CVector3f& b, const CVector3f& c) CPlane(const CVector3f& a, const CVector3f& b, const CVector3f& c)
{ {