diff --git a/src/framework/binfile.cpp b/src/framework/binfile.cpp index 20d2046..7f647d1 100644 --- a/src/framework/binfile.cpp +++ b/src/framework/binfile.cpp @@ -24,11 +24,6 @@ // 3. This notice may not be removed or altered from any source // distribution. // -//----------------------------------------------------------------------------- -// -// DESCRIPTION: Binary file operations -// -//----------------------------------------------------------------------------- #include "framework/binfile.h" diff --git a/src/level/level_light.cpp b/src/level/level_light.cpp index c164520..fbb02d5 100644 --- a/src/level/level_light.cpp +++ b/src/level/level_light.cpp @@ -24,11 +24,6 @@ // 3. This notice may not be removed or altered from any source // distribution. // -//----------------------------------------------------------------------------- -// -// DESCRIPTION: General doom map utilities and data preperation -// -//----------------------------------------------------------------------------- #include "math/mathlib.h" #include "level/level.h" diff --git a/src/lightmap/lightmap.cpp b/src/lightmap/lightmap.cpp index 62bd69d..452abe4 100644 --- a/src/lightmap/lightmap.cpp +++ b/src/lightmap/lightmap.cpp @@ -24,11 +24,6 @@ // 3. This notice may not be removed or altered from any source // distribution. // -//----------------------------------------------------------------------------- -// -// DESCRIPTION: Lightmap and lightgrid building module -// -//----------------------------------------------------------------------------- #include "math/mathlib.h" #include "surfaces.h" diff --git a/src/lightmap/lightsurface.cpp b/src/lightmap/lightsurface.cpp index fb8b1e1..187523c 100644 --- a/src/lightmap/lightsurface.cpp +++ b/src/lightmap/lightsurface.cpp @@ -24,13 +24,6 @@ // 3. This notice may not be removed or altered from any source // distribution. // -//----------------------------------------------------------------------------- -// -// DESCRIPTION: Special surfaces that contains origin points used for -// emitting light. Surfaces can be subdivided for more -// accurate light casting -// -//----------------------------------------------------------------------------- #include "math/mathlib.h" #include "level/level.h" diff --git a/src/math/angle.cpp b/src/math/angle.cpp index 15a25e1..45cad40 100644 --- a/src/math/angle.cpp +++ b/src/math/angle.cpp @@ -24,11 +24,6 @@ // 3. This notice may not be removed or altered from any source // distribution. // -//----------------------------------------------------------------------------- -// -// DESCRIPTION: Angle operations -// -//----------------------------------------------------------------------------- #include #include "mathlib.h" @@ -36,10 +31,6 @@ #define FULLCIRCLE (M_PI * 2) -// -// Angle::Angle -// - Angle::Angle() { this->yaw = 0; @@ -47,10 +38,6 @@ Angle::Angle() this->roll = 0; } -// -// Angle::Angle -// - Angle::Angle(const float yaw, const float pitch, const float roll) { this->yaw = yaw; @@ -58,10 +45,6 @@ Angle::Angle(const float yaw, const float pitch, const float roll) this->roll = roll; } -// -// Angle::Angle -// - Angle::Angle(const Vec3 &vector) { this->yaw = vector.x; @@ -71,10 +54,6 @@ Angle::Angle(const Vec3 &vector) Clamp180(); } -// -// Angle::Angle -// - Angle::Angle(const Angle &an) { this->yaw = an.yaw; @@ -82,10 +61,6 @@ Angle::Angle(const Angle &an) this->roll = an.roll; } -// -// Angle::Clamp180 -// - Angle &Angle::Clamp180() { #define CLAMP180(x) \ @@ -99,10 +74,6 @@ Angle &Angle::Clamp180() return *this; } -// -// Angle::Clamp180Invert -// - Angle &Angle::Clamp180Invert() { #define CLAMP180(x) \ @@ -120,10 +91,6 @@ Angle &Angle::Clamp180Invert() return *this; } -// -// Angle::Clamp180InvertSum -// - Angle &Angle::Clamp180InvertSum(const Angle &angle) { Angle an = angle; @@ -143,10 +110,6 @@ Angle &Angle::Clamp180InvertSum(const Angle &angle) return *this; } -// -// Angle::Round -// - Angle &Angle::Round() { #define ROUND(x) \ @@ -160,10 +123,6 @@ Angle &Angle::Round() return Clamp180(); } -// -// Angle::Diff -// - Angle Angle::Diff(Angle &angle) { float an; @@ -199,10 +158,6 @@ Angle Angle::Diff(Angle &angle) return out; } -// -// Angle::ToAxis -// - void Angle::ToAxis(Vec3 *forward, Vec3 *up, Vec3 *right) { float sy = Math::Sin(yaw); @@ -232,10 +187,6 @@ void Angle::ToAxis(Vec3 *forward, Vec3 *up, Vec3 *right) } } -// -// Angle::ToForwardAxis -// - Vec3 Angle::ToForwardAxis() { Vec3 vec; @@ -244,10 +195,6 @@ Vec3 Angle::ToForwardAxis() return vec; } -// -// Angle::ToUpAxis -// - Vec3 Angle::ToUpAxis() { Vec3 vec; @@ -256,10 +203,6 @@ Vec3 Angle::ToUpAxis() return vec; } -// -// Angle::ToRightAxis -// - Vec3 Angle::ToRightAxis() { Vec3 vec; @@ -268,28 +211,16 @@ Vec3 Angle::ToRightAxis() return vec; } -// -// Angle::ToVec3 -// - const Vec3 &Angle::ToVec3() const { return *reinterpret_cast(&yaw); } -// -// Angle::ToVec3 -// - Vec3 &Angle::ToVec3() { return *reinterpret_cast(&yaw); } -// -// Angle::ToQuat -// - Quat Angle::ToQuat() { return @@ -298,37 +229,21 @@ Quat Angle::ToQuat() Quat(roll, Vec3::vecForward))); } -// -// Angle::operator+ -// - Angle Angle::operator+(const Angle &angle) { return Angle(yaw + angle.yaw, pitch + angle.pitch, roll + angle.roll); } -// -// Angle::operator- -// - Angle Angle::operator-(const Angle &angle) { return Angle(yaw - angle.yaw, pitch - angle.pitch, roll - angle.roll); } -// -// Angle::operator- -// - Angle Angle::operator-() { return Angle(-yaw, -pitch, -roll); } -// -// Angle::operator+= -// - Angle &Angle::operator+=(const Angle &angle) { yaw += angle.yaw; @@ -337,10 +252,6 @@ Angle &Angle::operator+=(const Angle &angle) return *this; } -// -// Angle::operator-= -// - Angle &Angle::operator-=(const Angle &angle) { yaw -= angle.yaw; @@ -349,10 +260,6 @@ Angle &Angle::operator-=(const Angle &angle) return *this; } -// -// Angle::operator= -// - Angle &Angle::operator=(const Angle &angle) { yaw = angle.yaw; @@ -361,10 +268,6 @@ Angle &Angle::operator=(const Angle &angle) return *this; } -// -// Angle::operator= -// - Angle &Angle::operator=(const Vec3 &vector) { yaw = vector.x; @@ -373,10 +276,6 @@ Angle &Angle::operator=(const Vec3 &vector) return *this; } -// -// Angle::operator= -// - Angle &Angle::operator=(const float *vecs) { yaw = vecs[0]; @@ -385,20 +284,12 @@ Angle &Angle::operator=(const float *vecs) return *this; } -// -// Angle::operator[] -// - float Angle::operator[](int index) const { assert(index >= 0 && index < 3); return (&yaw)[index]; } -// -// Angle::operator[] -// - float &Angle::operator[](int index) { assert(index >= 0 && index < 3); diff --git a/src/math/bounds.cpp b/src/math/bounds.cpp index c70801b..da0adea 100644 --- a/src/math/bounds.cpp +++ b/src/math/bounds.cpp @@ -24,49 +24,28 @@ // 3. This notice may not be removed or altered from any source // distribution. // -//----------------------------------------------------------------------------- -// -// DESCRIPTION: Bounding box operations -// -//----------------------------------------------------------------------------- #include #include "mathlib.h" #include -// -// BBox::BBox -// - BBox::BBox() { Clear(); } -// -// BBox::BBox -// - BBox::BBox(const Vec3 &vMin, const Vec3 &vMax) { this->min = vMin; this->max = vMax; } -// -// BBox::Clear -// - void BBox::Clear() { min.Set(M_INFINITY, M_INFINITY, M_INFINITY); max.Set(-M_INFINITY, -M_INFINITY, -M_INFINITY); } -// -// BBox::AddPoint -// - void BBox::AddPoint(const Vec3 &vec) { float lowx = min.x; @@ -87,10 +66,6 @@ void BBox::AddPoint(const Vec3 &vec) max.Set(hix, hiy, hiz); } -// -// BBox::Radius -// - float BBox::Radius() const { int i; @@ -116,40 +91,24 @@ float BBox::Radius() const return Math::Sqrt(r); } -// -// BBox::PointInside -// - bool BBox::PointInside(const Vec3 &vec) const { return !(vec[0] < min[0] || vec[1] < min[1] || vec[2] < min[2] || vec[0] > max[0] || vec[1] > max[1] || vec[2] > max[2]); } -// -// BBox::IntersectingBox -// - bool BBox::IntersectingBox(const BBox &box) const { return !(box.max[0] < min[0] || box.max[1] < min[1] || box.max[2] < min[2] || box.min[0] > max[0] || box.min[1] > max[1] || box.min[2] > max[2]); } -// -// BBox::IntersectingBox2D -// - bool BBox::IntersectingBox2D(const BBox &box) const { return !(box.max[0] < min[0] || box.max[2] < min[2] || box.min[0] > max[0] || box.min[2] > max[2]); } -// -// BBox::DistanceToPlane -// - float BBox::DistanceToPlane(Plane &plane) { Vec3 c; @@ -183,10 +142,6 @@ float BBox::DistanceToPlane(Plane &plane) return 0; } -// -// BBox::operator+ -// - BBox BBox::operator+(const float radius) const { Vec3 vmin = min; @@ -203,10 +158,6 @@ BBox BBox::operator+(const float radius) const return BBox(vmin, vmax); } -// -// BBox::operator+= -// - BBox &BBox::operator+=(const float radius) { min.x -= radius; @@ -218,10 +169,6 @@ BBox &BBox::operator+=(const float radius) return *this; } -// -// BBox::operator+ -// - BBox BBox::operator+(const Vec3 &vec) const { Vec3 vmin = min; @@ -238,10 +185,6 @@ BBox BBox::operator+(const Vec3 &vec) const return BBox(vmin, vmax); } -// -// BBox::operator- -// - BBox BBox::operator-(const float radius) const { Vec3 vmin = min; @@ -258,10 +201,6 @@ BBox BBox::operator-(const float radius) const return BBox(vmin, vmax); } -// -// BBox::operator- -// - BBox BBox::operator-(const Vec3 &vec) const { Vec3 vmin = min; @@ -278,10 +217,6 @@ BBox BBox::operator-(const Vec3 &vec) const return BBox(vmin, vmax); } -// -// BBox::operator-= -// - BBox &BBox::operator-=(const float radius) { min.x += radius; @@ -293,10 +228,6 @@ BBox &BBox::operator-=(const float radius) return *this; } -// -// BBox::operator* -// - BBox BBox::operator*(const Mat4 &matrix) const { Vec3 c = Center(); @@ -319,10 +250,6 @@ BBox BBox::operator*(const Mat4 &matrix) const return box; } -// -// BBox::operator*= -// - BBox &BBox::operator*=(const Mat4 &matrix) { Vec3 c = Center(); @@ -345,10 +272,6 @@ BBox &BBox::operator*=(const Mat4 &matrix) return *this; } -// -// BBox::operator* -// - BBox BBox::operator*(const Vec3 &vec) const { BBox box = *this; @@ -363,10 +286,6 @@ BBox BBox::operator*(const Vec3 &vec) const return box; } -// -// BBox::operator*= -// - BBox &BBox::operator*=(const Vec3 &vec) { if (vec.x < 0) { min.x += (vec.x - 1); } @@ -379,10 +298,6 @@ BBox &BBox::operator*=(const Vec3 &vec) return *this; } -// -// BBox::operator= -// - BBox &BBox::operator=(const BBox &bbox) { min = bbox.min; @@ -391,30 +306,18 @@ BBox &BBox::operator=(const BBox &bbox) return *this; } -// -// BBox::operator[] -// - Vec3 BBox::operator[](int index) const { assert(index >= 0 && index < 2); return index == 0 ? min : max; } -// -// BBox::operator[] -// - Vec3 &BBox::operator[](int index) { assert(index >= 0 && index < 2); return index == 0 ? min : max; } -// -// BBox:LineIntersect -// - bool BBox::LineIntersect(const Vec3 &start, const Vec3 &end) { float ld[3]; @@ -440,12 +343,7 @@ bool BBox::LineIntersect(const Vec3 &start, const Vec3 &end) return true; } -// -// BBox::ToPoints -// // Assumes points is an array of 24 -// - void BBox::ToPoints(float *points) const { points[0 * 3 + 0] = max[0]; @@ -474,12 +372,7 @@ void BBox::ToPoints(float *points) const points[7 * 3 + 2] = min[2]; } -// -// BBox::ToVectors -// // Assumes vectors is an array of 8 -// - void BBox::ToVectors(Vec3 *vectors) const { vectors[0][0] = max[0]; diff --git a/src/math/mathlib.cpp b/src/math/mathlib.cpp index ce09349..4f453be 100644 --- a/src/math/mathlib.cpp +++ b/src/math/mathlib.cpp @@ -24,18 +24,9 @@ // 3. This notice may not be removed or altered from any source // distribution. // -//----------------------------------------------------------------------------- -// -// DESCRIPTION: Math functions -// -//----------------------------------------------------------------------------- #include "mathlib.h" -// -// Math::RoundPowerOfTwo -// - int Math::RoundPowerOfTwo(int x) { int mask = 1; @@ -53,12 +44,7 @@ int Math::RoundPowerOfTwo(int x) return x; } -// -// Math::CubicCurve -// - -void Math::CubicCurve(const Vec3 &start, const Vec3 &end, const float time, - const Vec3 &point, Vec3 *vec) +void Math::CubicCurve(const Vec3 &start, const Vec3 &end, const float time, const Vec3 &point, Vec3 *vec) { int i; float xyz[3]; @@ -74,12 +60,7 @@ void Math::CubicCurve(const Vec3 &start, const Vec3 &end, const float time, vec->z = xyz[2]; } -// -// Math::QuadraticCurve -// - -void Math::QuadraticCurve(const Vec3 &start, const Vec3 &end, const float time, - const Vec3 &pt1, const Vec3 &pt2, Vec3 *vec) +void Math::QuadraticCurve(const Vec3 &start, const Vec3 &end, const float time, const Vec3 &pt1, const Vec3 &pt2, Vec3 *vec) { int i; float xyz[3]; diff --git a/src/math/mathlib.h b/src/math/mathlib.h index 9edfceb..4f2be91 100644 --- a/src/math/mathlib.h +++ b/src/math/mathlib.h @@ -35,15 +35,15 @@ #undef M_PI #endif -#define M_PI 3.1415926535897932384626433832795f -#define M_RAD (M_PI / 180.0f) -#define M_DEG (180.0f / M_PI) -#define M_INFINITY 1e30f +#define M_PI 3.1415926535897932384626433832795f +#define M_RAD (M_PI / 180.0f) +#define M_DEG (180.0f / M_PI) +#define M_INFINITY 1e30f #define DEG2RAD(x) ((x) * M_RAD) #define RAD2DEG(x) ((x) * M_DEG) -#define FLOATSIGNBIT(f) (reinterpret_cast(f) >> 31) +#define FLOATSIGNBIT(f) (reinterpret_cast(f) >> 31) class Vec2; class Vec3; @@ -54,32 +54,30 @@ class Angle; class Math { public: - static float Sin(float x); - static float Cos(float x); - static float Tan(float x); - static float ATan2(float x, float y); - static float ACos(float x); - static float Sqrt(float x); - static float Pow(float x, float y); - static float Log(float x); - static float Floor(float x); - static float Ceil(float x); - static float Deg2Rad(float x); - static float Rad2Deg(float x); + static float Sin(float x); + static float Cos(float x); + static float Tan(float x); + static float ATan2(float x, float y); + static float ACos(float x); + static float Sqrt(float x); + static float Pow(float x, float y); + static float Log(float x); + static float Floor(float x); + static float Ceil(float x); + static float Deg2Rad(float x); + static float Rad2Deg(float x); - static int Abs(int x); - static float Fabs(float x); - static int RoundPowerOfTwo(int x); - static float InvSqrt(float x); - static void Clamp(float &f, const float min, const float max); - static void Clamp(int &i, const int min, const int max); - static void Clamp(uint8_t &b, const uint8_t min, const uint8_t max); - static void Clamp(Vec3 &f, const float min, const float max); + static int Abs(int x); + static float Fabs(float x); + static int RoundPowerOfTwo(int x); + static float InvSqrt(float x); + static void Clamp(float &f, const float min, const float max); + static void Clamp(int &i, const int min, const int max); + static void Clamp(uint8_t &b, const uint8_t min, const uint8_t max); + static void Clamp(Vec3 &f, const float min, const float max); - static void CubicCurve(const Vec3 &start, const Vec3 &end, const float time, - const Vec3 &point, Vec3 *vec); - static void QuadraticCurve(const Vec3 &start, const Vec3 &end, const float time, - const Vec3 &pt1, const Vec3 &pt2, Vec3 *vec); + static void CubicCurve(const Vec3 &start, const Vec3 &end, const float time, const Vec3 &point, Vec3 *vec); + static void QuadraticCurve(const Vec3 &start, const Vec3 &end, const float time, const Vec3 &pt1, const Vec3 &pt2, Vec3 *vec); }; class Quat @@ -91,36 +89,36 @@ public: Quat(const float angle, Vec3 &vector); Quat(const float angle, const Vec3 &vector); - void Set(const float x, const float y, const float z, const float w); - void Clear(); - float Dot(const Quat &quat) const; - float UnitSq() const; - float Unit() const; - Quat &Normalize(); - Quat Slerp(const Quat &quat, float movement) const; - Quat RotateFrom(const Vec3 &location, const Vec3 &target, float maxAngle); - Quat Inverse() const; + void Set(const float x, const float y, const float z, const float w); + void Clear(); + float Dot(const Quat &quat) const; + float UnitSq() const; + float Unit() const; + Quat &Normalize(); + Quat Slerp(const Quat &quat, float movement) const; + Quat RotateFrom(const Vec3 &location, const Vec3 &target, float maxAngle); + Quat Inverse() const; - Quat operator+(const Quat &quat); - Quat &operator+=(const Quat &quat); - Quat operator-(const Quat &quat); - Quat &operator-=(const Quat &quat); - Quat operator*(const Quat &quat); - Quat operator*(const float val) const; - Quat &operator*=(const Quat &quat); - Quat &operator*=(const float val); - Quat &operator=(const Quat &quat); - Quat &operator=(const Vec4 &vec); - Quat &operator=(const float *vecs); - Vec3 operator|(const Vec3 &vector); + Quat operator+(const Quat &quat); + Quat &operator+=(const Quat &quat); + Quat operator-(const Quat &quat); + Quat &operator-=(const Quat &quat); + Quat operator*(const Quat &quat); + Quat operator*(const float val) const; + Quat &operator*=(const Quat &quat); + Quat &operator*=(const float val); + Quat &operator=(const Quat &quat); + Quat &operator=(const Vec4 &vec); + Quat &operator=(const float *vecs); + Vec3 operator|(const Vec3 &vector); - const Vec3 &ToVec3() const; - Vec3 &ToVec3(); + const Vec3 &ToVec3() const; + Vec3 &ToVec3(); - float x; - float y; - float z; - float w; + float x; + float y; + float z; + float w; }; class Vec2 @@ -129,64 +127,64 @@ public: Vec2(); Vec2(const float x, const float y); - void Set(const float x, const float y); - void Clear(); - float Dot(const Vec2 &vec) const; - static float Dot(const Vec2 &vec1, const Vec2 &vec2); - float CrossScalar(const Vec2 &vec) const; - Vec2 Cross(const Vec2 &vec) const; - Vec2 &Cross(const Vec2 &vec1, const Vec2 &vec2); - float Dot(const Vec3 &vec) const; - static float Dot(const Vec3 &vec1, const Vec3 &vec2); - Vec2 Cross(const Vec3 &vec) const; - Vec2 &Cross(const Vec3 &vec1, const Vec3 &vec2); - float UnitSq() const; - float Unit() const; - float DistanceSq(const Vec2 &vec) const; - float Distance(const Vec2 &vec) const; - Vec2 &Normalize(); - Vec2 Lerp(const Vec2 &next, float movement) const; - Vec2 &Lerp(const Vec2 &next, const float movement); - Vec2 &Lerp(const Vec2 &start, const Vec2 &next, float movement); - float ToYaw() const; - float *ToFloatPtr(); - Vec3 ToVec3(); + void Set(const float x, const float y); + void Clear(); + float Dot(const Vec2 &vec) const; + static float Dot(const Vec2 &vec1, const Vec2 &vec2); + float CrossScalar(const Vec2 &vec) const; + Vec2 Cross(const Vec2 &vec) const; + Vec2 &Cross(const Vec2 &vec1, const Vec2 &vec2); + float Dot(const Vec3 &vec) const; + static float Dot(const Vec3 &vec1, const Vec3 &vec2); + Vec2 Cross(const Vec3 &vec) const; + Vec2 &Cross(const Vec3 &vec1, const Vec3 &vec2); + float UnitSq() const; + float Unit() const; + float DistanceSq(const Vec2 &vec) const; + float Distance(const Vec2 &vec) const; + Vec2 &Normalize(); + Vec2 Lerp(const Vec2 &next, float movement) const; + Vec2 &Lerp(const Vec2 &next, const float movement); + Vec2 &Lerp(const Vec2 &start, const Vec2 &next, float movement); + float ToYaw() const; + float *ToFloatPtr(); + Vec3 ToVec3(); - Vec2 operator+(const Vec2 &vec); - Vec2 operator+(const Vec2 &vec) const; - Vec2 operator+(Vec2 &vec); - Vec2 operator-() const; - Vec2 operator-(const Vec2 &vec) const; - Vec2 operator*(const Vec2 &vec); - Vec2 operator*(const float val); - Vec2 operator*(const float val) const; - Vec2 operator/(const Vec2 &vec); - Vec2 operator/(const float val); - Vec2 &operator=(Vec3 &vec); - Vec2 &operator=(const Vec2 &vec); - Vec2 &operator=(const Vec3 &vec); - Vec2 &operator=(const float *vecs); - Vec2 &operator+=(const Vec2 &vec); - Vec2 &operator-=(const Vec2 &vec); - Vec2 &operator*=(const Vec2 &vec); - Vec2 &operator*=(const float val); - Vec2 &operator/=(const Vec2 &vec); - Vec2 &operator/=(const float val); - Vec2 operator*(const Mat4 &mtx); - Vec2 operator*(const Mat4 &mtx) const; - Vec2 &operator*=(const Mat4 &mtx); - float operator[](int index) const; - float &operator[](int index); - bool operator==(const Vec2 &vec); + Vec2 operator+(const Vec2 &vec); + Vec2 operator+(const Vec2 &vec) const; + Vec2 operator+(Vec2 &vec); + Vec2 operator-() const; + Vec2 operator-(const Vec2 &vec) const; + Vec2 operator*(const Vec2 &vec); + Vec2 operator*(const float val); + Vec2 operator*(const float val) const; + Vec2 operator/(const Vec2 &vec); + Vec2 operator/(const float val); + Vec2 &operator=(Vec3 &vec); + Vec2 &operator=(const Vec2 &vec); + Vec2 &operator=(const Vec3 &vec); + Vec2 &operator=(const float *vecs); + Vec2 &operator+=(const Vec2 &vec); + Vec2 &operator-=(const Vec2 &vec); + Vec2 &operator*=(const Vec2 &vec); + Vec2 &operator*=(const float val); + Vec2 &operator/=(const Vec2 &vec); + Vec2 &operator/=(const float val); + Vec2 operator*(const Mat4 &mtx); + Vec2 operator*(const Mat4 &mtx) const; + Vec2 &operator*=(const Mat4 &mtx); + float operator[](int index) const; + float &operator[](int index); + bool operator==(const Vec2 &vec); operator float *() { return reinterpret_cast(&x); } - static Vec2 vecZero; - static const Vec2 vecRight; - static const Vec2 vecUp; + static Vec2 vecZero; + static const Vec2 vecRight; + static const Vec2 vecUp; - float x; - float y; + float x; + float y; }; class Vec3 @@ -195,72 +193,70 @@ public: Vec3(); Vec3(const float x, const float y, const float z); - void Set(const float x, const float y, const float z); - void Clear(); - float Dot(const Vec3 &vec) const; - static float Dot(const Vec3 &vec1, const Vec3 &vec2); - Vec3 Cross(const Vec3 &vec) const; - static Vec3 Cross(const Vec3 &vec1, const Vec3 &vec2); - float UnitSq() const; - float Unit() const; - float LengthSq() const { return UnitSq(); } - float Length() const { return Unit(); } - float DistanceSq(const Vec3 &vec) const; - float Distance(const Vec3 &vec) const; - Vec3 &Normalize(); - static Vec3 Normalize(Vec3 a); - Angle PointAt(Vec3 &location) const; - Vec3 Lerp(const Vec3 &next, float movement) const; - Vec3 &Lerp(const Vec3 &start, const Vec3 &next, float movement); - Quat ToQuat(); - float ToYaw() const; - float ToPitch() const; - float *ToFloatPtr(); - Vec2 ToVec2(); - Vec2 ToVec2() const; - Vec3 ScreenProject(Mat4 &proj, Mat4 &model, - const int width, const int height, - const int wx, const int wy); + void Set(const float x, const float y, const float z); + void Clear(); + float Dot(const Vec3 &vec) const; + static float Dot(const Vec3 &vec1, const Vec3 &vec2); + Vec3 Cross(const Vec3 &vec) const; + static Vec3 Cross(const Vec3 &vec1, const Vec3 &vec2); + float UnitSq() const; + float Unit() const; + float LengthSq() const { return UnitSq(); } + float Length() const { return Unit(); } + float DistanceSq(const Vec3 &vec) const; + float Distance(const Vec3 &vec) const; + Vec3 &Normalize(); + static Vec3 Normalize(Vec3 a); + Angle PointAt(Vec3 &location) const; + Vec3 Lerp(const Vec3 &next, float movement) const; + Vec3 &Lerp(const Vec3 &start, const Vec3 &next, float movement); + Quat ToQuat(); + float ToYaw() const; + float ToPitch() const; + float *ToFloatPtr(); + Vec2 ToVec2(); + Vec2 ToVec2() const; + Vec3 ScreenProject(Mat4 &proj, Mat4 &model, const int width, const int height, const int wx, const int wy); - Vec3 operator+(const Vec3 &vec); - Vec3 operator+(const Vec3 &vec) const; - Vec3 operator+(Vec3 &vec); - Vec3 operator+(const float val) const; - Vec3 operator-() const; - Vec3 operator-(const float val) const; - Vec3 operator-(const Vec3 &vec) const; - Vec3 operator*(const Vec3 &vec); - Vec3 operator*(const float val); - Vec3 operator*(const float val) const; - Vec3 operator/(const Vec3 &vec); - Vec3 operator/(const float val); - Vec3 operator*(const Quat &quat); - Vec3 operator*(const Mat4 &mtx); - Vec3 operator*(const Mat4 &mtx) const; - Vec3 &operator=(const Vec3 &vec); - Vec3 &operator=(const float *vecs); - Vec3 &operator+=(const Vec3 &vec); - Vec3 &operator+=(const float val); - Vec3 &operator-=(const Vec3 &vec); - Vec3 &operator-=(const float val); - Vec3 &operator*=(const Vec3 &vec); - Vec3 &operator*=(const float val); - Vec3 &operator/=(const Vec3 &vec); - Vec3 &operator/=(const float val); - Vec3 &operator*=(const Quat &quat); - Vec3 &operator*=(const Mat4 &mtx); - float operator[](int index) const; - float &operator[](int index); + Vec3 operator+(const Vec3 &vec); + Vec3 operator+(const Vec3 &vec) const; + Vec3 operator+(Vec3 &vec); + Vec3 operator+(const float val) const; + Vec3 operator-() const; + Vec3 operator-(const float val) const; + Vec3 operator-(const Vec3 &vec) const; + Vec3 operator*(const Vec3 &vec); + Vec3 operator*(const float val); + Vec3 operator*(const float val) const; + Vec3 operator/(const Vec3 &vec); + Vec3 operator/(const float val); + Vec3 operator*(const Quat &quat); + Vec3 operator*(const Mat4 &mtx); + Vec3 operator*(const Mat4 &mtx) const; + Vec3 &operator=(const Vec3 &vec); + Vec3 &operator=(const float *vecs); + Vec3 &operator+=(const Vec3 &vec); + Vec3 &operator+=(const float val); + Vec3 &operator-=(const Vec3 &vec); + Vec3 &operator-=(const float val); + Vec3 &operator*=(const Vec3 &vec); + Vec3 &operator*=(const float val); + Vec3 &operator/=(const Vec3 &vec); + Vec3 &operator/=(const float val); + Vec3 &operator*=(const Quat &quat); + Vec3 &operator*=(const Mat4 &mtx); + float operator[](int index) const; + float &operator[](int index); operator float *() { return reinterpret_cast(&x); } - static const Vec3 vecForward; - static const Vec3 vecUp; - static const Vec3 vecRight; + static const Vec3 vecForward; + static const Vec3 vecUp; + static const Vec3 vecRight; - float x; - float y; - float z; + float x; + float y; + float z; }; class Vec4 @@ -270,39 +266,39 @@ public: Vec4(const float x, const float y, const float z, const float w); Vec4(const Vec3 &v, const float w); - void Set(const float x, const float y, const float z, const float w); - void Clear(); - float *ToFloatPtr(); + void Set(const float x, const float y, const float z, const float w); + void Clear(); + float *ToFloatPtr(); static float Dot(const Vec4 &a, const Vec4 &b) { return a.x * b.x + a.y * b.y + a.z * b.z + a.w * b.w; } - const Vec3 &ToVec3() const; - Vec3 &ToVec3(); - Vec4 operator|(const Mat4 &mtx); - Vec4 &operator|=(const Mat4 &mtx); - Vec4 operator+(const Vec4 &vec) const; - Vec4 operator+(const float val) const; - Vec4 operator-(const Vec4 &vec) const; - Vec4 operator-(const float val) const; - Vec4 operator*(const Vec4 &vec) const; - Vec4 operator*(const float val) const; - Vec4 operator/(const Vec4 &vec) const; - Vec4 operator/(const float val) const; - Vec4 &operator+=(const Vec4 &vec); - Vec4 &operator+=(const float val); - Vec4 &operator-=(const Vec4 &vec); - Vec4 &operator-=(const float val); - Vec4 &operator*=(const Vec4 &vec); - Vec4 &operator*=(const float val); - Vec4 &operator/=(const Vec4 &vec); - Vec4 &operator/=(const float val); - float operator[](int index) const; - float &operator[](int index); + const Vec3 &ToVec3() const; + Vec3 &ToVec3(); + Vec4 operator|(const Mat4 &mtx); + Vec4 &operator|=(const Mat4 &mtx); + Vec4 operator+(const Vec4 &vec) const; + Vec4 operator+(const float val) const; + Vec4 operator-(const Vec4 &vec) const; + Vec4 operator-(const float val) const; + Vec4 operator*(const Vec4 &vec) const; + Vec4 operator*(const float val) const; + Vec4 operator/(const Vec4 &vec) const; + Vec4 operator/(const float val) const; + Vec4 &operator+=(const Vec4 &vec); + Vec4 &operator+=(const float val); + Vec4 &operator-=(const Vec4 &vec); + Vec4 &operator-=(const float val); + Vec4 &operator*=(const Vec4 &vec); + Vec4 &operator*=(const float val); + Vec4 &operator/=(const Vec4 &vec); + Vec4 &operator/=(const float val); + float operator[](int index) const; + float &operator[](int index); - float x; - float y; - float z; - float w; + float x; + float y; + float z; + float w; }; class Mat4 @@ -314,38 +310,36 @@ public: Mat4(const Quat &quat); Mat4(const float angle, const int axis); - Mat4 &Identity(); - Mat4 &Identity(const float x, const float y, const float z); - Mat4 &SetTranslation(const float x, const float y, const float z); - Mat4 &SetTranslation(const Vec3 &vector); - Mat4 &AddTranslation(const float x, const float y, const float z); - Mat4 &AddTranslation(const Vec3 &vector); - Mat4 &Scale(const float x, const float y, const float z); - Mat4 &Scale(const Vec3 &vector); - static Mat4 Scale(const Mat4 &mtx, const float x, const float y, const float z); - Mat4 &Transpose(); - static Mat4 Transpose(const Mat4 &mtx); - static Mat4 Invert(Mat4 &mtx); - Quat ToQuat(); - float *ToFloatPtr(); - void SetViewProjection(float aspect, float fov, float zNear, float zFar); - void SetOrtho(float left, float right, - float bottom, float top, - float zNear, float zFar); + Mat4 &Identity(); + Mat4 &Identity(const float x, const float y, const float z); + Mat4 &SetTranslation(const float x, const float y, const float z); + Mat4 &SetTranslation(const Vec3 &vector); + Mat4 &AddTranslation(const float x, const float y, const float z); + Mat4 &AddTranslation(const Vec3 &vector); + Mat4 &Scale(const float x, const float y, const float z); + Mat4 &Scale(const Vec3 &vector); + static Mat4 Scale(const Mat4 &mtx, const float x, const float y, const float z); + Mat4 &Transpose(); + static Mat4 Transpose(const Mat4 &mtx); + static Mat4 Invert(Mat4 &mtx); + Quat ToQuat(); + float *ToFloatPtr(); + void SetViewProjection(float aspect, float fov, float zNear, float zFar); + void SetOrtho(float left, float right, float bottom, float top, float zNear, float zFar); - Mat4 operator*(const Vec3 &vector); - Mat4 &operator*=(const Vec3 &vector); - Mat4 operator*(const Mat4 &matrix); - Mat4 &operator*=(const Mat4 &matrix); - friend Mat4 operator*(const Mat4 &m1, const Mat4 &m2); - Mat4 &operator=(const Mat4 &matrix); - Mat4 &operator=(const float *m); - Mat4 operator|(const Mat4 &matrix); + Mat4 operator*(const Vec3 &vector); + Mat4 &operator*=(const Vec3 &vector); + Mat4 operator*(const Mat4 &matrix); + Mat4 &operator*=(const Mat4 &matrix); + friend Mat4 operator*(const Mat4 &m1, const Mat4 &m2); + Mat4 &operator=(const Mat4 &matrix); + Mat4 &operator=(const float *m); + Mat4 operator|(const Mat4 &matrix); float operator[](size_t i) const { return vectors[i >> 2][i & 3]; } float &operator[](size_t i) { return vectors[i >> 2][i & 3]; } - Vec4 vectors[4]; + Vec4 vectors[4]; }; class Plane @@ -364,34 +358,29 @@ public: AXIS_XY }; - const Vec3 &Normal() const; - Vec3 &Normal(); - Plane &SetNormal(const Vec3 &normal); - Plane &SetNormal(const Vec3 &pt1, const Vec3 &pt2, const Vec3 &pt3); - float Distance(const Vec3 &point); - Plane &SetDistance(const Vec3 &point); - bool IsFacing(const float yaw); - float ToYaw(); - float ToPitch(); - Quat ToQuat(); - const Vec4 &ToVec4() const; - Vec4 &ToVec4(); - const planeAxis_t BestAxis() const; - Vec3 GetInclination(); + const Vec3 &Normal() const; + Vec3 &Normal(); + Plane &SetNormal(const Vec3 &normal); + Plane &SetNormal(const Vec3 &pt1, const Vec3 &pt2, const Vec3 &pt3); + float Distance(const Vec3 &point); + Plane &SetDistance(const Vec3 &point); + bool IsFacing(const float yaw); + float ToYaw(); + float ToPitch(); + Quat ToQuat(); + const Vec4 &ToVec4() const; + Vec4 &ToVec4(); + const planeAxis_t BestAxis() const; + Vec3 GetInclination(); static Plane Inverse(const Plane &p) { return Plane(-p.a, -p.b, -p.c, -p.d); } float zAt(float x, float y) const { return (d - a * x - b * y) / c; } - Plane &operator|(const Quat &quat); - Plane &operator|=(const Quat &quat); - Plane &operator|(const Mat4 &mtx); - Plane &operator|=(const Mat4 &mtx); - - float a; - float b; - float c; - float d; + float a; + float b; + float c; + float d; }; class Angle @@ -402,33 +391,33 @@ public: Angle(const Vec3 &vector); Angle(const Angle &an); - Angle &Round(); - Angle &Clamp180(); - Angle &Clamp180Invert(); - Angle &Clamp180InvertSum(const Angle &angle); - Angle Diff(Angle &angle); - void ToAxis(Vec3 *forward, Vec3 *up, Vec3 *right); - Vec3 ToForwardAxis(); - Vec3 ToUpAxis(); - Vec3 ToRightAxis(); - const Vec3 &ToVec3() const; - Vec3 &ToVec3(); - Quat ToQuat(); + Angle &Round(); + Angle &Clamp180(); + Angle &Clamp180Invert(); + Angle &Clamp180InvertSum(const Angle &angle); + Angle Diff(Angle &angle); + void ToAxis(Vec3 *forward, Vec3 *up, Vec3 *right); + Vec3 ToForwardAxis(); + Vec3 ToUpAxis(); + Vec3 ToRightAxis(); + const Vec3 &ToVec3() const; + Vec3 &ToVec3(); + Quat ToQuat(); - Angle operator+(const Angle &angle); - Angle operator-(const Angle &angle); - Angle &operator+=(const Angle &angle); - Angle &operator-=(const Angle &angle); - Angle &operator=(const Angle &angle); - Angle &operator=(const Vec3 &vector); - Angle &operator=(const float *vecs); - Angle operator-(); - float operator[](int index) const; - float &operator[](int index); + Angle operator+(const Angle &angle); + Angle operator-(const Angle &angle); + Angle &operator+=(const Angle &angle); + Angle &operator-=(const Angle &angle); + Angle &operator=(const Angle &angle); + Angle &operator=(const Vec3 &vector); + Angle &operator=(const float *vecs); + Angle operator-(); + float operator[](int index) const; + float &operator[](int index); - float yaw; - float pitch; - float roll; + float yaw; + float pitch; + float roll; }; class BBox @@ -437,35 +426,35 @@ public: BBox(); BBox(const Vec3 &vMin, const Vec3 &vMax); - void Clear(); - Vec3 Center() const; - Vec3 Extents() const; - float Radius() const; - void AddPoint(const Vec3 &vec); - bool PointInside(const Vec3 &vec) const; - bool IntersectingBox(const BBox &box) const; - bool IntersectingBox2D(const BBox &box) const; - float DistanceToPlane(Plane &plane); - bool LineIntersect(const Vec3 &start, const Vec3 &end); - void ToPoints(float *points) const; - void ToVectors(Vec3 *vectors) const; + void Clear(); + Vec3 Center() const; + Vec3 Extents() const; + float Radius() const; + void AddPoint(const Vec3 &vec); + bool PointInside(const Vec3 &vec) const; + bool IntersectingBox(const BBox &box) const; + bool IntersectingBox2D(const BBox &box) const; + float DistanceToPlane(Plane &plane); + bool LineIntersect(const Vec3 &start, const Vec3 &end); + void ToPoints(float *points) const; + void ToVectors(Vec3 *vectors) const; - BBox operator+(const float radius) const; - BBox &operator+=(const float radius); - BBox operator+(const Vec3 &vec) const; - BBox operator-(const float radius) const; - BBox operator-(const Vec3 &vec) const; - BBox &operator-=(const float radius); - BBox operator*(const Mat4 &matrix) const; - BBox &operator*=(const Mat4 &matrix); - BBox operator*(const Vec3 &vec) const; - BBox &operator*=(const Vec3 &vec); - BBox &operator=(const BBox &bbox); - Vec3 operator[](int index) const; - Vec3 &operator[](int index); + BBox operator+(const float radius) const; + BBox &operator+=(const float radius); + BBox operator+(const Vec3 &vec) const; + BBox operator-(const float radius) const; + BBox operator-(const Vec3 &vec) const; + BBox &operator-=(const float radius); + BBox operator*(const Mat4 &matrix) const; + BBox &operator*=(const Mat4 &matrix); + BBox operator*(const Vec3 &vec) const; + BBox &operator*=(const Vec3 &vec); + BBox &operator=(const BBox &bbox); + Vec3 operator[](int index) const; + Vec3 &operator[](int index); - Vec3 min; - Vec3 max; + Vec3 min; + Vec3 max; }; ///////////////////////////////////////////////////////////////////////////// diff --git a/src/math/matrix.cpp b/src/math/matrix.cpp index b5426d1..f39ffb4 100644 --- a/src/math/matrix.cpp +++ b/src/math/matrix.cpp @@ -73,19 +73,11 @@ #include #include "mathlib.h" -// -// Mat4::Mat4 -// - Mat4::Mat4() { Identity(); } -// -// Mat4::Mat4 -// - Mat4::Mat4(const Mat4 &mtx) { for (int i = 0; i < 4; i++) @@ -97,19 +89,11 @@ Mat4::Mat4(const Mat4 &mtx) } } -// -// Mat4::Mat4 -// - Mat4::Mat4(const float x, const float y, const float z) { Identity(x, y, z); } -// -// Mat4::Mat4 -// - Mat4::Mat4(const Quat &quat) { float xx = quat.x * quat.x; @@ -141,10 +125,6 @@ Mat4::Mat4(const Quat &quat) vectors[3].Set(0, 0, 0, 1); } -// -// Mat4::Mat4 -// - Mat4::Mat4(const float angle, const int axis) { float s; @@ -178,10 +158,6 @@ Mat4::Mat4(const float angle, const int axis) } } -// -// Mat4::Identity -// - Mat4 &Mat4::Identity() { vectors[0].Set(1, 0, 0, 0); @@ -192,10 +168,6 @@ Mat4 &Mat4::Identity() return *this; } -// -// Mat4::Identity -// - Mat4 &Mat4::Identity(const float x, const float y, const float z) { vectors[0].Set(x, 0, 0, 0); @@ -206,30 +178,18 @@ Mat4 &Mat4::Identity(const float x, const float y, const float z) return *this; } -// -// Mat4::SetTranslation -// - Mat4 &Mat4::SetTranslation(const float x, const float y, const float z) { vectors[3].ToVec3().Set(x, y, z); return *this; } -// -// Mat4::SetTranslation -// - Mat4 &Mat4::SetTranslation(const Vec3 &vector) { vectors[3].ToVec3() = vector; return *this; } -// -// Mat4::AddTranslation -// - Mat4 &Mat4::AddTranslation(const float x, const float y, const float z) { vectors[3].x += x; @@ -238,20 +198,12 @@ Mat4 &Mat4::AddTranslation(const float x, const float y, const float z) return *this; } -// -// Mat4::AddTranslation -// - Mat4 &Mat4::AddTranslation(const Vec3 &vector) { vectors[3].ToVec3() += vector; return *this; } -// -// Mat4::Scale -// - Mat4 &Mat4::Scale(const float x, const float y, const float z) { vectors[0].ToVec3() *= x; @@ -261,10 +213,6 @@ Mat4 &Mat4::Scale(const float x, const float y, const float z) return *this; } -// -// Mat4::Scale -// - Mat4 &Mat4::Scale(const Vec3 &vector) { vectors[0].ToVec3() *= vector.x; @@ -274,10 +222,6 @@ Mat4 &Mat4::Scale(const Vec3 &vector) return *this; } -// -// Mat4::Scale -// - Mat4 Mat4::Scale(const Mat4 &mtx, const float x, const float y, const float z) { Mat4 out; @@ -289,10 +233,6 @@ Mat4 Mat4::Scale(const Mat4 &mtx, const float x, const float y, const float z) return out; } -// -// Mat4::Transpose -// - Mat4 &Mat4::Transpose() { Vec3 v1 = vectors[1].ToVec3(); @@ -303,10 +243,6 @@ Mat4 &Mat4::Transpose() return *this; } -// -// Mat4::Transpose -// - Mat4 Mat4::Transpose(const Mat4 &mtx) { Mat4 out; @@ -319,10 +255,6 @@ Mat4 Mat4::Transpose(const Mat4 &mtx) return out; } -// -// Mat4::Invert -// - Mat4 Mat4::Invert(Mat4 &mtx) { float d; @@ -383,10 +315,6 @@ Mat4 Mat4::Invert(Mat4 &mtx) return mtx; } -// -// Mat4::SetViewProjection -// - void Mat4::SetViewProjection(float aspect, float fov, float zNear, float zFar) { float top = zNear * Math::Tan(fov * M_PI / 360.0f); @@ -414,13 +342,7 @@ void Mat4::SetViewProjection(float aspect, float fov, float zNear, float zFar) vectors[3].w = 0; } -// -// Mat4::SetOrtho -// - -void Mat4::SetOrtho(float left, float right, - float bottom, float top, - float zNear, float zFar) +void Mat4::SetOrtho(float left, float right, float bottom, float top, float zNear, float zFar) { vectors[0].x = 2 / (right - left); vectors[1].y = 2 / (top - bottom); @@ -442,10 +364,6 @@ void Mat4::SetOrtho(float left, float right, vectors[2].w = 0; } -// -// Mat4::ToQuat -// - Quat Mat4::ToQuat() { float t; @@ -505,10 +423,6 @@ Quat Mat4::ToQuat() return q; } -// -// Mat4::operator* -// - Mat4 Mat4::operator*(const Vec3 &vector) { Mat4 out(*this); @@ -520,10 +434,6 @@ Mat4 Mat4::operator*(const Vec3 &vector) return out; } -// -// Mat4::operator*= -// - Mat4 &Mat4::operator*=(const Vec3 &vector) { vectors[3].ToVec3() += @@ -533,19 +443,11 @@ Mat4 &Mat4::operator*=(const Vec3 &vector) return *this; } -// -// Mat4::ToFloatPtr -// - float *Mat4::ToFloatPtr() { return reinterpret_cast(vectors); } -// -// Mat4::operator* -// - Mat4 Mat4::operator*(const Mat4 &matrix) { Mat4 out; @@ -577,10 +479,6 @@ Mat4 Mat4::operator*(const Mat4 &matrix) return out; } -// -// Mat4::operator*= -// - Mat4 &Mat4::operator*=(const Mat4 &matrix) { for (int i = 0; i < 4; i++) @@ -610,10 +508,6 @@ Mat4 &Mat4::operator*=(const Mat4 &matrix) return *this; } -// -// Mat4::operator* -// - Mat4 operator*(const Mat4 &m1, const Mat4 &m2) { Mat4 out; @@ -645,10 +539,6 @@ Mat4 operator*(const Mat4 &m1, const Mat4 &m2) return out; } -// -// Mat4::operator| -// - Mat4 Mat4::operator|(const Mat4 &matrix) { Mat4 out; @@ -685,10 +575,6 @@ Mat4 Mat4::operator|(const Mat4 &matrix) return out; } -// -// Mat4::operator= -// - Mat4 &Mat4::operator=(const Mat4 &matrix) { vectors[0] = matrix.vectors[0]; @@ -699,10 +585,6 @@ Mat4 &Mat4::operator=(const Mat4 &matrix) return *this; } -// -// Mat4::operator= -// - Mat4 &Mat4::operator=(const float *m) { for (int i = 0; i < 4; i++) diff --git a/src/math/plane.cpp b/src/math/plane.cpp index 85de794..f655626 100644 --- a/src/math/plane.cpp +++ b/src/math/plane.cpp @@ -24,19 +24,10 @@ // 3. This notice may not be removed or altered from any source // distribution. // -//----------------------------------------------------------------------------- -// -// DESCRIPTION: Plane operations -// -//----------------------------------------------------------------------------- #include #include "mathlib.h" -// -// Plane::Plane -// - Plane::Plane() { this->a = 0; @@ -45,10 +36,6 @@ Plane::Plane() this->d = 0; } -// -// Plane::Plane -// - Plane::Plane(const float a, const float b, const float c, const float d) { this->a = a; @@ -57,20 +44,12 @@ Plane::Plane(const float a, const float b, const float c, const float d) this->d = d; } -// -// Plane::Plane -// - Plane::Plane(const Vec3 &pt1, const Vec3 &pt2, const Vec3 &pt3) { SetNormal(pt1, pt2, pt3); this->d = Vec3::Dot(pt1, Normal()); } -// -// Plane::Plane -// - Plane::Plane(const Vec3 &normal, const Vec3 &point) { this->a = normal.x; @@ -79,10 +58,6 @@ Plane::Plane(const Vec3 &normal, const Vec3 &point) this->d = point.Dot(normal); } -// -// Plane::Plane -// - Plane::Plane(const Plane &plane) { this->a = plane.a; @@ -91,76 +66,44 @@ Plane::Plane(const Plane &plane) this->d = plane.d; } -// -// Plane::SetNormal -// - Plane &Plane::SetNormal(const Vec3 &normal) { Normal() = normal; return *this; } -// -// Plane::SetNormal -// - Plane &Plane::SetNormal(const Vec3 &pt1, const Vec3 &pt2, const Vec3 &pt3) { Normal() = (pt2 - pt1).Cross(pt3 - pt2).Normalize(); return *this; } -// -// Plane::Normal -// - Vec3 const &Plane::Normal() const { return *reinterpret_cast(&a); } -// -// Plane::Normal -// - Vec3 &Plane::Normal() { return *reinterpret_cast(&a); } -// -// Plane::Distance -// - float Plane::Distance(const Vec3 &point) { return point.Dot(Normal()); } -// -// Plane::SetDistance -// - Plane &Plane::SetDistance(const Vec3 &point) { this->d = point.Dot(Normal()); return *this; } -// -// Plane::IsFacing -// - bool Plane::IsFacing(const float yaw) { return -Math::Sin(yaw) * a + -Math::Cos(yaw) * b < 0; } -// -// Plane::ToYaw -// - float Plane::ToYaw() { float d = Normal().Unit(); @@ -180,47 +123,27 @@ float Plane::ToYaw() return 0; } -// -// Plane::ToPitch -// - float Plane::ToPitch() { return Math::ACos(Vec3::vecUp.Dot(Normal())); } -// -// Plane::ToQuat -// - Quat Plane::ToQuat() { Vec3 cross = Vec3::vecUp.Cross(Normal()).Normalize(); return Quat(Math::ACos(Vec3::vecUp.Dot(Normal())), cross); } -// -// Plane::ToVec4 -// - Vec4 const &Plane::ToVec4() const { return *reinterpret_cast(&a); } -// -// Plane::ToVec4 -// - Vec4 &Plane::ToVec4() { return *reinterpret_cast(&a); } -// -// Plane::BestAxis -// - const Plane::planeAxis_t Plane::BestAxis() const { float na = Math::Fabs(a); @@ -240,10 +163,6 @@ const Plane::planeAxis_t Plane::BestAxis() const return AXIS_XY; } -// -// Plane::GetInclination -// - Vec3 Plane::GetInclination() { Vec3 dir = Normal() * Vec3::vecUp.Dot(Normal()); diff --git a/src/math/quaternion.cpp b/src/math/quaternion.cpp index 2e91489..10c6e7b 100644 --- a/src/math/quaternion.cpp +++ b/src/math/quaternion.cpp @@ -24,28 +24,15 @@ // 3. This notice may not be removed or altered from any source // distribution. // -//----------------------------------------------------------------------------- -// -// DESCRIPTION: Quaternion operations -// -//----------------------------------------------------------------------------- #include #include "mathlib.h" -// -// Quat::Quat -// - Quat::Quat() { Clear(); } -// -// Quat::Quat -// - Quat::Quat(const float angle, const float x, const float y, const float z) { float s = Math::Sin(angle * 0.5f); @@ -57,10 +44,6 @@ Quat::Quat(const float angle, const float x, const float y, const float z) this->w = c; } -// -// Quat::Quat -// - Quat::Quat(const float angle, Vec3 &vector) { float s = Math::Sin(angle * 0.5f); @@ -72,10 +55,6 @@ Quat::Quat(const float angle, Vec3 &vector) this->w = c; } -// -// Quat::Quat -// - Quat::Quat(const float angle, const Vec3 &vector) { float s = Math::Sin(angle * 0.5f); @@ -87,10 +66,6 @@ Quat::Quat(const float angle, const Vec3 &vector) this->w = c; } -// -// Quat::Set -// - void Quat::Set(const float x, const float y, const float z, const float w) { this->x = x; @@ -99,38 +74,22 @@ void Quat::Set(const float x, const float y, const float z, const float w) this->w = w; } -// -// Quat::Clear -// - void Quat::Clear() { x = y = z = 0.0f; w = 1.0f; } -// -// Vec3::UnitSq -// - float Quat::UnitSq() const { return x * x + y * y + z * z + w * w; } -// -// Vec3::Unit -// - float Quat::Unit() const { return Math::Sqrt(UnitSq()); } -// -// Quat::Normalize -// - Quat &Quat::Normalize() { float d = Unit(); @@ -142,10 +101,6 @@ Quat &Quat::Normalize() return *this; } -// -// Quat::Inverse -// - Quat Quat::Inverse() const { Quat out; @@ -153,10 +108,6 @@ Quat Quat::Inverse() const return out; } -// -// Quat::operator+ -// - Quat Quat::operator+(const Quat &quat) { Quat out; @@ -167,10 +118,6 @@ Quat Quat::operator+(const Quat &quat) return out; } -// -// Quat::operator+= -// - Quat &Quat::operator+=(const Quat &quat) { x += quat.x; @@ -180,10 +127,6 @@ Quat &Quat::operator+=(const Quat &quat) return *this; } -// -// Quat::operator- -// - Quat Quat::operator-(const Quat &quat) { Quat out; @@ -194,10 +137,6 @@ Quat Quat::operator-(const Quat &quat) return out; } -// -// Quat::operator-= -// - Quat &Quat::operator-=(const Quat &quat) { x -= quat.x; @@ -207,10 +146,6 @@ Quat &Quat::operator-=(const Quat &quat) return *this; } -// -// Quat::operator* -// - Quat Quat::operator*(const Quat &quat) { Quat out; @@ -223,10 +158,6 @@ Quat Quat::operator*(const Quat &quat) return out; } -// -// Quat::operator*= -// - Quat &Quat::operator*=(const Quat &quat) { float tx = x; @@ -242,10 +173,6 @@ Quat &Quat::operator*=(const Quat &quat) return *this; } -// -// Quat::operator* -// - Quat Quat::operator*(const float val) const { Quat out; @@ -256,10 +183,6 @@ Quat Quat::operator*(const float val) const return out; } -// -// Quat::operator*= -// - Quat &Quat::operator*=(const float val) { x *= val; @@ -270,10 +193,6 @@ Quat &Quat::operator*=(const float val) return *this; } -// -// Quat::operator| -// - Vec3 Quat::operator|(const Vec3 &vector) { float xx = x * x; @@ -300,19 +219,11 @@ Vec3 Quat::operator|(const Vec3 &vector) ); } -// -// Quat::Dot -// - float Quat::Dot(const Quat &quat) const { return (x * quat.x + y * quat.y + z * quat.z + w * quat.w); } -// -// Quat::Slerp -// - Quat Quat::Slerp(const Quat &quat, float movement) const { Quat rdest = quat; @@ -362,10 +273,6 @@ Quat Quat::Slerp(const Quat &quat, float movement) const } } -// -// Quat::RotateFrom -// - Quat Quat::RotateFrom(const Vec3 &location, const Vec3 &target, float maxAngle) { Vec3 axis; @@ -388,10 +295,6 @@ Quat Quat::RotateFrom(const Vec3 &location, const Vec3 &target, float maxAngle) return (*this * Quat(an, cp)); } -// -// Quat::operator= -// - Quat &Quat::operator=(const Quat &quat) { x = quat.x; @@ -401,10 +304,6 @@ Quat &Quat::operator=(const Quat &quat) return *this; } -// -// Quat::operator= -// - Quat &Quat::operator=(const Vec4 &vec) { x = vec.x; @@ -414,10 +313,6 @@ Quat &Quat::operator=(const Vec4 &vec) return *this; } -// -// Quat::operator= -// - Quat &Quat::operator=(const float *vecs) { x = vecs[0]; @@ -427,19 +322,11 @@ Quat &Quat::operator=(const float *vecs) return *this; } -// -// Quat::ToVec3 -// - Vec3 const &Quat::ToVec3() const { return *reinterpret_cast(this); } -// -// Quat::ToVec3 -// - Vec3 &Quat::ToVec3() { return *reinterpret_cast(this); diff --git a/src/math/vector.cpp b/src/math/vector.cpp index 1a73e0c..94b9eff 100644 --- a/src/math/vector.cpp +++ b/src/math/vector.cpp @@ -24,11 +24,6 @@ // 3. This notice may not be removed or altered from any source // distribution. // -//----------------------------------------------------------------------------- -// -// DESCRIPTION: Vector operations -// -//----------------------------------------------------------------------------- #include #include "mathlib.h"