From 76e20eb4c8a16c540b37f46c8f730bcdb72f5d10 Mon Sep 17 00:00:00 2001 From: Jack Andersen Date: Thu, 30 Mar 2017 12:35:40 -1000 Subject: [PATCH] Add CLine --- CMakeLists.txt | 1 + include/zeus/CLine.hpp | 18 ++++++++++++++++++ include/zeus/CLineSeg.hpp | 10 +++++----- include/zeus/CMRay.hpp | 24 +++++++++++++----------- include/zeus/CPlane.hpp | 2 +- 5 files changed, 38 insertions(+), 17 deletions(-) create mode 100644 include/zeus/CLine.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 523c73f..0b02181 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -74,6 +74,7 @@ add_library(zeus include/zeus/CFrustum.hpp include/zeus/CAABox.hpp include/zeus/COBBox.hpp + include/zeus/CLine.hpp include/zeus/CLineSeg.hpp include/zeus/CSphere.hpp include/zeus/CUnitVector.hpp diff --git a/include/zeus/CLine.hpp b/include/zeus/CLine.hpp new file mode 100644 index 0000000..35b863c --- /dev/null +++ b/include/zeus/CLine.hpp @@ -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 diff --git a/include/zeus/CLineSeg.hpp b/include/zeus/CLineSeg.hpp index 6223233..8d16272 100644 --- a/include/zeus/CLineSeg.hpp +++ b/include/zeus/CLineSeg.hpp @@ -1,5 +1,5 @@ -#ifndef CLINE_HPP -#define CLINE_HPP +#ifndef CLINESEG_HPP +#define CLINESEG_HPP #include "Global.hpp" #include "zeus/CVector3f.hpp" @@ -13,12 +13,12 @@ public: { CVector3f tmp = (end - start).normalized(); if (tmp.x != 0 || tmp.y != 0 || tmp.z != 0) - normal = tmp.normalized(); + dir = tmp.normalized(); else - normal = CVector3f::skZero; + dir = CVector3f::skZero; } - CVector3f normal; + CVector3f dir; CVector3f start; CVector3f end; }; diff --git a/include/zeus/CMRay.hpp b/include/zeus/CMRay.hpp index 1df2aba..9f7434a 100644 --- a/include/zeus/CMRay.hpp +++ b/include/zeus/CMRay.hpp @@ -8,30 +8,32 @@ namespace zeus { 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); - delta = normal - start; + end = start + (len * dirin); + 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; - end = invD * delta; + delta = end - start; + dir = invLen * delta; } CMRay getInvUnscaledTransformRay(const CTransform& xfrm) const { 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 normal; // xc + CVector3f end; // xc CVector3f delta; // x18 - float d; // x24 - float invD; // x28 - CVector3f end; // x2c + float length; // x24 + float invLength; // x28 + CVector3f dir; // x2c }; } diff --git a/include/zeus/CPlane.hpp b/include/zeus/CPlane.hpp index 4e3b082..3fcc8fa 100644 --- a/include/zeus/CPlane.hpp +++ b/include/zeus/CPlane.hpp @@ -12,7 +12,7 @@ class alignas(16) CPlane public: 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(const CVector3f& a, const CVector3f& b, const CVector3f& c) {