diff options
Diffstat (limited to 'src/Quaternions.h')
-rw-r--r-- | src/Quaternions.h | 92 |
1 files changed, 59 insertions, 33 deletions
diff --git a/src/Quaternions.h b/src/Quaternions.h index c41dfe8..8cf1eff 100644 --- a/src/Quaternions.h +++ b/src/Quaternions.h @@ -1,39 +1,65 @@ -#ifndef _QUATERNIONS_H_ -#define _QUATERNIONS_H_ +#ifndef BLACKSHADES_QUATERNIONS_H +#define BLACKSHADES_QUATERNIONS_H using namespace std; -class XYZ{ - public: - float x; - float y; - float z; - XYZ operator+(XYZ add); - XYZ operator-(XYZ add); - XYZ operator*(float add); - XYZ operator*(XYZ add); - XYZ operator/(float add); - void operator+=(XYZ add); - void operator-=(XYZ add); - void operator*=(float add); - void operator*=(XYZ add); - void operator/=(float add); - void operator=(float add); - bool operator==(XYZ add); +struct XYZ { + float x, y, z; }; -void CrossProduct(XYZ P, XYZ Q, XYZ *V); -void Normalise(XYZ *vectory); -bool PointInTriangle(XYZ *p, XYZ normal, XYZ *p1, XYZ *p2, XYZ *p3); -float LineFacetd(XYZ p1,XYZ p2,XYZ pa,XYZ pb,XYZ pc,XYZ n, XYZ *p); -float LineFacetd(XYZ *p1,XYZ *p2,XYZ *pa,XYZ *pb,XYZ *pc,XYZ *n, XYZ *p); -void ReflectVector(XYZ *vel, XYZ *n); -XYZ DoRotation(XYZ thePoint, float xang, float yang, float zang); -float findDistance(XYZ point1, XYZ point2); -float findLengthfast(XYZ point1); -float findDistancefast(XYZ point1, XYZ point2); -float dotproduct(XYZ point1, XYZ point2); -bool sphere_line_intersection(float x1, float y1, float z1, - float x2, float y2, float z2, float x3, float y3, float z3, float r); +#ifdef __cplusplus +constexpr bool operator==(const XYZ& u, const XYZ& v) +{ + return u.x == v.x && u.y == v.y && u.z == v.z; +} +constexpr XYZ operator+(XYZ u, const XYZ& v) +{ + return {u.x + v.x, u.y + v.y, u.z + v.z}; +} +constexpr XYZ operator-(XYZ u, const XYZ& v) +{ + return {u.x - v.x, u.y - v.y, u.z - v.z}; +} +constexpr XYZ operator*(XYZ u, const XYZ& v) +{ + return {u.x * v.x, u.y * v.y, u.z * v.z}; +} +constexpr XYZ operator*(XYZ u, float k) +{ + return {u.x * k, u.y * k, u.z * k}; +} +constexpr XYZ operator/(XYZ u, float k) +{ + return {u.x / k, u.y / k, u.z / k}; +} -#endif +constexpr XYZ& operator+=(XYZ& u, const XYZ& v) { return u = u + v; } +constexpr XYZ& operator-=(XYZ& u, const XYZ& v) { return u = u - v; } +constexpr XYZ& operator*=(XYZ& u, const XYZ& v) { return u = u * v; } +constexpr XYZ& operator*=(XYZ& u, float k) { return u = u * k; } +constexpr XYZ& operator/=(XYZ& u, float k) { return u = u / k; } + +float LineFacetd(XYZ p1, XYZ p2, XYZ pa, XYZ pb, XYZ pc, XYZ n, XYZ* p); +float LineFacetd(XYZ* p1, XYZ* p2, XYZ* pa, XYZ* pb, XYZ* pc, XYZ* n, XYZ* p); +#endif // __cplusplus + +#ifdef __cplusplus +extern "C" { +#endif // __cplusplus + void CrossProduct(XYZ P, XYZ Q, XYZ *V); + void Normalise(XYZ *vectory); + bool PointInTriangle(XYZ *p, XYZ normal, XYZ *p1, XYZ *p2, XYZ *p3); + void ReflectVector(XYZ *vel, XYZ *n); + XYZ DoRotation(XYZ thePoint, float xang, float yang, float zang); + float findDistance(XYZ point1, XYZ point2); + float findLengthfast(XYZ point1); + float findDistancefast(XYZ point1, XYZ point2); + float dotproduct(XYZ point1, XYZ point2); + bool sphere_line_intersection(float x1, float y1, float z1, + float x2, float y2, float z2, + float x3, float y3, float z3, float r); +#ifdef __cplusplus +} // extern "C" +#endif // __cplusplus + +#endif // BLACKSHADES_QUATERNIONS_H |