From a857250ccf3ac6d086b676f5195ce0becbfc8ed7 Mon Sep 17 00:00:00 2001 From: Jack Andersen Date: Wed, 17 Feb 2016 16:40:58 -1000 Subject: [PATCH] Routines to support line rendering --- include/CVector2f.hpp | 5 +++++ include/CVector3f.hpp | 9 +++++++++ src/Math.cpp | 2 +- 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/include/CVector2f.hpp b/include/CVector2f.hpp index 0673e46..7f35e3b 100644 --- a/include/CVector2f.hpp +++ b/include/CVector2f.hpp @@ -255,6 +255,11 @@ public: return *this * mag; } + inline CVector2f perpendicularVector() const + { + return {-y, x}; + } + inline float cross(const CVector2f& rhs) const { return (x * rhs.y) - (y * rhs.x); diff --git a/include/CVector3f.hpp b/include/CVector3f.hpp index 3be42cb..07d37bb 100644 --- a/include/CVector3f.hpp +++ b/include/CVector3f.hpp @@ -91,6 +91,15 @@ public: v[3] = 0.0f; } + inline CVector2f toVec2f() const + { +#if __SSE__ + return CVector2f(mVec128); +#else + return CVector2f(x, y); +#endif + } + inline bool operator ==(const CVector3f& rhs) const {return (x == rhs.x && y == rhs.y && z == rhs.z);} inline bool operator !=(const CVector3f& rhs) const diff --git a/src/Math.cpp b/src/Math.cpp index 30c8f50..9b00d44 100644 --- a/src/Math.cpp +++ b/src/Math.cpp @@ -134,7 +134,6 @@ double sqrtD(double val) p.v *= (1.5f - (x * p.v * p.v)); p.v *= (1.5f - (x * p.v * p.v)); q = p.v; -#endif static const double half = 0.5; static const double three = 3.0; @@ -155,6 +154,7 @@ double sqrtD(double val) sq = -((val * three) - sq); sq = q * sq; q = val * sq; +#endif return q; }