- normalize some whitespace and remove useless "documentation" comments

This commit is contained in:
Magnus Norddahl 2018-11-09 21:46:34 +01:00
parent 7756bba61f
commit 75e18b10e1
12 changed files with 293 additions and 878 deletions

View file

@ -24,11 +24,6 @@
// 3. This notice may not be removed or altered from any source // 3. This notice may not be removed or altered from any source
// distribution. // distribution.
// //
//-----------------------------------------------------------------------------
//
// DESCRIPTION: Binary file operations
//
//-----------------------------------------------------------------------------
#include "framework/binfile.h" #include "framework/binfile.h"

View file

@ -24,11 +24,6 @@
// 3. This notice may not be removed or altered from any source // 3. This notice may not be removed or altered from any source
// distribution. // distribution.
// //
//-----------------------------------------------------------------------------
//
// DESCRIPTION: General doom map utilities and data preperation
//
//-----------------------------------------------------------------------------
#include "math/mathlib.h" #include "math/mathlib.h"
#include "level/level.h" #include "level/level.h"

View file

@ -24,11 +24,6 @@
// 3. This notice may not be removed or altered from any source // 3. This notice may not be removed or altered from any source
// distribution. // distribution.
// //
//-----------------------------------------------------------------------------
//
// DESCRIPTION: Lightmap and lightgrid building module
//
//-----------------------------------------------------------------------------
#include "math/mathlib.h" #include "math/mathlib.h"
#include "surfaces.h" #include "surfaces.h"

View file

@ -24,13 +24,6 @@
// 3. This notice may not be removed or altered from any source // 3. This notice may not be removed or altered from any source
// distribution. // 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 "math/mathlib.h"
#include "level/level.h" #include "level/level.h"

View file

@ -24,11 +24,6 @@
// 3. This notice may not be removed or altered from any source // 3. This notice may not be removed or altered from any source
// distribution. // distribution.
// //
//-----------------------------------------------------------------------------
//
// DESCRIPTION: Angle operations
//
//-----------------------------------------------------------------------------
#include <math.h> #include <math.h>
#include "mathlib.h" #include "mathlib.h"
@ -36,10 +31,6 @@
#define FULLCIRCLE (M_PI * 2) #define FULLCIRCLE (M_PI * 2)
//
// Angle::Angle
//
Angle::Angle() Angle::Angle()
{ {
this->yaw = 0; this->yaw = 0;
@ -47,10 +38,6 @@ Angle::Angle()
this->roll = 0; this->roll = 0;
} }
//
// Angle::Angle
//
Angle::Angle(const float yaw, const float pitch, const float roll) Angle::Angle(const float yaw, const float pitch, const float roll)
{ {
this->yaw = yaw; this->yaw = yaw;
@ -58,10 +45,6 @@ Angle::Angle(const float yaw, const float pitch, const float roll)
this->roll = roll; this->roll = roll;
} }
//
// Angle::Angle
//
Angle::Angle(const Vec3 &vector) Angle::Angle(const Vec3 &vector)
{ {
this->yaw = vector.x; this->yaw = vector.x;
@ -71,10 +54,6 @@ Angle::Angle(const Vec3 &vector)
Clamp180(); Clamp180();
} }
//
// Angle::Angle
//
Angle::Angle(const Angle &an) Angle::Angle(const Angle &an)
{ {
this->yaw = an.yaw; this->yaw = an.yaw;
@ -82,10 +61,6 @@ Angle::Angle(const Angle &an)
this->roll = an.roll; this->roll = an.roll;
} }
//
// Angle::Clamp180
//
Angle &Angle::Clamp180() Angle &Angle::Clamp180()
{ {
#define CLAMP180(x) \ #define CLAMP180(x) \
@ -99,10 +74,6 @@ Angle &Angle::Clamp180()
return *this; return *this;
} }
//
// Angle::Clamp180Invert
//
Angle &Angle::Clamp180Invert() Angle &Angle::Clamp180Invert()
{ {
#define CLAMP180(x) \ #define CLAMP180(x) \
@ -120,10 +91,6 @@ Angle &Angle::Clamp180Invert()
return *this; return *this;
} }
//
// Angle::Clamp180InvertSum
//
Angle &Angle::Clamp180InvertSum(const Angle &angle) Angle &Angle::Clamp180InvertSum(const Angle &angle)
{ {
Angle an = angle; Angle an = angle;
@ -143,10 +110,6 @@ Angle &Angle::Clamp180InvertSum(const Angle &angle)
return *this; return *this;
} }
//
// Angle::Round
//
Angle &Angle::Round() Angle &Angle::Round()
{ {
#define ROUND(x) \ #define ROUND(x) \
@ -160,10 +123,6 @@ Angle &Angle::Round()
return Clamp180(); return Clamp180();
} }
//
// Angle::Diff
//
Angle Angle::Diff(Angle &angle) Angle Angle::Diff(Angle &angle)
{ {
float an; float an;
@ -199,10 +158,6 @@ Angle Angle::Diff(Angle &angle)
return out; return out;
} }
//
// Angle::ToAxis
//
void Angle::ToAxis(Vec3 *forward, Vec3 *up, Vec3 *right) void Angle::ToAxis(Vec3 *forward, Vec3 *up, Vec3 *right)
{ {
float sy = Math::Sin(yaw); float sy = Math::Sin(yaw);
@ -232,10 +187,6 @@ void Angle::ToAxis(Vec3 *forward, Vec3 *up, Vec3 *right)
} }
} }
//
// Angle::ToForwardAxis
//
Vec3 Angle::ToForwardAxis() Vec3 Angle::ToForwardAxis()
{ {
Vec3 vec; Vec3 vec;
@ -244,10 +195,6 @@ Vec3 Angle::ToForwardAxis()
return vec; return vec;
} }
//
// Angle::ToUpAxis
//
Vec3 Angle::ToUpAxis() Vec3 Angle::ToUpAxis()
{ {
Vec3 vec; Vec3 vec;
@ -256,10 +203,6 @@ Vec3 Angle::ToUpAxis()
return vec; return vec;
} }
//
// Angle::ToRightAxis
//
Vec3 Angle::ToRightAxis() Vec3 Angle::ToRightAxis()
{ {
Vec3 vec; Vec3 vec;
@ -268,28 +211,16 @@ Vec3 Angle::ToRightAxis()
return vec; return vec;
} }
//
// Angle::ToVec3
//
const Vec3 &Angle::ToVec3() const const Vec3 &Angle::ToVec3() const
{ {
return *reinterpret_cast<const Vec3*>(&yaw); return *reinterpret_cast<const Vec3*>(&yaw);
} }
//
// Angle::ToVec3
//
Vec3 &Angle::ToVec3() Vec3 &Angle::ToVec3()
{ {
return *reinterpret_cast<Vec3*>(&yaw); return *reinterpret_cast<Vec3*>(&yaw);
} }
//
// Angle::ToQuat
//
Quat Angle::ToQuat() Quat Angle::ToQuat()
{ {
return return
@ -298,37 +229,21 @@ Quat Angle::ToQuat()
Quat(roll, Vec3::vecForward))); Quat(roll, Vec3::vecForward)));
} }
//
// Angle::operator+
//
Angle Angle::operator+(const Angle &angle) Angle Angle::operator+(const Angle &angle)
{ {
return Angle(yaw + angle.yaw, pitch + angle.pitch, roll + angle.roll); return Angle(yaw + angle.yaw, pitch + angle.pitch, roll + angle.roll);
} }
//
// Angle::operator-
//
Angle Angle::operator-(const Angle &angle) Angle Angle::operator-(const Angle &angle)
{ {
return Angle(yaw - angle.yaw, pitch - angle.pitch, roll - angle.roll); return Angle(yaw - angle.yaw, pitch - angle.pitch, roll - angle.roll);
} }
//
// Angle::operator-
//
Angle Angle::operator-() Angle Angle::operator-()
{ {
return Angle(-yaw, -pitch, -roll); return Angle(-yaw, -pitch, -roll);
} }
//
// Angle::operator+=
//
Angle &Angle::operator+=(const Angle &angle) Angle &Angle::operator+=(const Angle &angle)
{ {
yaw += angle.yaw; yaw += angle.yaw;
@ -337,10 +252,6 @@ Angle &Angle::operator+=(const Angle &angle)
return *this; return *this;
} }
//
// Angle::operator-=
//
Angle &Angle::operator-=(const Angle &angle) Angle &Angle::operator-=(const Angle &angle)
{ {
yaw -= angle.yaw; yaw -= angle.yaw;
@ -349,10 +260,6 @@ Angle &Angle::operator-=(const Angle &angle)
return *this; return *this;
} }
//
// Angle::operator=
//
Angle &Angle::operator=(const Angle &angle) Angle &Angle::operator=(const Angle &angle)
{ {
yaw = angle.yaw; yaw = angle.yaw;
@ -361,10 +268,6 @@ Angle &Angle::operator=(const Angle &angle)
return *this; return *this;
} }
//
// Angle::operator=
//
Angle &Angle::operator=(const Vec3 &vector) Angle &Angle::operator=(const Vec3 &vector)
{ {
yaw = vector.x; yaw = vector.x;
@ -373,10 +276,6 @@ Angle &Angle::operator=(const Vec3 &vector)
return *this; return *this;
} }
//
// Angle::operator=
//
Angle &Angle::operator=(const float *vecs) Angle &Angle::operator=(const float *vecs)
{ {
yaw = vecs[0]; yaw = vecs[0];
@ -385,20 +284,12 @@ Angle &Angle::operator=(const float *vecs)
return *this; return *this;
} }
//
// Angle::operator[]
//
float Angle::operator[](int index) const float Angle::operator[](int index) const
{ {
assert(index >= 0 && index < 3); assert(index >= 0 && index < 3);
return (&yaw)[index]; return (&yaw)[index];
} }
//
// Angle::operator[]
//
float &Angle::operator[](int index) float &Angle::operator[](int index)
{ {
assert(index >= 0 && index < 3); assert(index >= 0 && index < 3);

View file

@ -24,49 +24,28 @@
// 3. This notice may not be removed or altered from any source // 3. This notice may not be removed or altered from any source
// distribution. // distribution.
// //
//-----------------------------------------------------------------------------
//
// DESCRIPTION: Bounding box operations
//
//-----------------------------------------------------------------------------
#include <math.h> #include <math.h>
#include "mathlib.h" #include "mathlib.h"
#include <assert.h> #include <assert.h>
//
// BBox::BBox
//
BBox::BBox() BBox::BBox()
{ {
Clear(); Clear();
} }
//
// BBox::BBox
//
BBox::BBox(const Vec3 &vMin, const Vec3 &vMax) BBox::BBox(const Vec3 &vMin, const Vec3 &vMax)
{ {
this->min = vMin; this->min = vMin;
this->max = vMax; this->max = vMax;
} }
//
// BBox::Clear
//
void BBox::Clear() void BBox::Clear()
{ {
min.Set(M_INFINITY, M_INFINITY, M_INFINITY); min.Set(M_INFINITY, M_INFINITY, M_INFINITY);
max.Set(-M_INFINITY, -M_INFINITY, -M_INFINITY); max.Set(-M_INFINITY, -M_INFINITY, -M_INFINITY);
} }
//
// BBox::AddPoint
//
void BBox::AddPoint(const Vec3 &vec) void BBox::AddPoint(const Vec3 &vec)
{ {
float lowx = min.x; float lowx = min.x;
@ -87,10 +66,6 @@ void BBox::AddPoint(const Vec3 &vec)
max.Set(hix, hiy, hiz); max.Set(hix, hiy, hiz);
} }
//
// BBox::Radius
//
float BBox::Radius() const float BBox::Radius() const
{ {
int i; int i;
@ -116,40 +91,24 @@ float BBox::Radius() const
return Math::Sqrt(r); return Math::Sqrt(r);
} }
//
// BBox::PointInside
//
bool BBox::PointInside(const Vec3 &vec) const bool BBox::PointInside(const Vec3 &vec) const
{ {
return !(vec[0] < min[0] || vec[1] < min[1] || vec[2] < min[2] || 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]); vec[0] > max[0] || vec[1] > max[1] || vec[2] > max[2]);
} }
//
// BBox::IntersectingBox
//
bool BBox::IntersectingBox(const BBox &box) const bool BBox::IntersectingBox(const BBox &box) const
{ {
return !(box.max[0] < min[0] || box.max[1] < min[1] || box.max[2] < min[2] || 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]); box.min[0] > max[0] || box.min[1] > max[1] || box.min[2] > max[2]);
} }
//
// BBox::IntersectingBox2D
//
bool BBox::IntersectingBox2D(const BBox &box) const bool BBox::IntersectingBox2D(const BBox &box) const
{ {
return !(box.max[0] < min[0] || box.max[2] < min[2] || return !(box.max[0] < min[0] || box.max[2] < min[2] ||
box.min[0] > max[0] || box.min[2] > max[2]); box.min[0] > max[0] || box.min[2] > max[2]);
} }
//
// BBox::DistanceToPlane
//
float BBox::DistanceToPlane(Plane &plane) float BBox::DistanceToPlane(Plane &plane)
{ {
Vec3 c; Vec3 c;
@ -183,10 +142,6 @@ float BBox::DistanceToPlane(Plane &plane)
return 0; return 0;
} }
//
// BBox::operator+
//
BBox BBox::operator+(const float radius) const BBox BBox::operator+(const float radius) const
{ {
Vec3 vmin = min; Vec3 vmin = min;
@ -203,10 +158,6 @@ BBox BBox::operator+(const float radius) const
return BBox(vmin, vmax); return BBox(vmin, vmax);
} }
//
// BBox::operator+=
//
BBox &BBox::operator+=(const float radius) BBox &BBox::operator+=(const float radius)
{ {
min.x -= radius; min.x -= radius;
@ -218,10 +169,6 @@ BBox &BBox::operator+=(const float radius)
return *this; return *this;
} }
//
// BBox::operator+
//
BBox BBox::operator+(const Vec3 &vec) const BBox BBox::operator+(const Vec3 &vec) const
{ {
Vec3 vmin = min; Vec3 vmin = min;
@ -238,10 +185,6 @@ BBox BBox::operator+(const Vec3 &vec) const
return BBox(vmin, vmax); return BBox(vmin, vmax);
} }
//
// BBox::operator-
//
BBox BBox::operator-(const float radius) const BBox BBox::operator-(const float radius) const
{ {
Vec3 vmin = min; Vec3 vmin = min;
@ -258,10 +201,6 @@ BBox BBox::operator-(const float radius) const
return BBox(vmin, vmax); return BBox(vmin, vmax);
} }
//
// BBox::operator-
//
BBox BBox::operator-(const Vec3 &vec) const BBox BBox::operator-(const Vec3 &vec) const
{ {
Vec3 vmin = min; Vec3 vmin = min;
@ -278,10 +217,6 @@ BBox BBox::operator-(const Vec3 &vec) const
return BBox(vmin, vmax); return BBox(vmin, vmax);
} }
//
// BBox::operator-=
//
BBox &BBox::operator-=(const float radius) BBox &BBox::operator-=(const float radius)
{ {
min.x += radius; min.x += radius;
@ -293,10 +228,6 @@ BBox &BBox::operator-=(const float radius)
return *this; return *this;
} }
//
// BBox::operator*
//
BBox BBox::operator*(const Mat4 &matrix) const BBox BBox::operator*(const Mat4 &matrix) const
{ {
Vec3 c = Center(); Vec3 c = Center();
@ -319,10 +250,6 @@ BBox BBox::operator*(const Mat4 &matrix) const
return box; return box;
} }
//
// BBox::operator*=
//
BBox &BBox::operator*=(const Mat4 &matrix) BBox &BBox::operator*=(const Mat4 &matrix)
{ {
Vec3 c = Center(); Vec3 c = Center();
@ -345,10 +272,6 @@ BBox &BBox::operator*=(const Mat4 &matrix)
return *this; return *this;
} }
//
// BBox::operator*
//
BBox BBox::operator*(const Vec3 &vec) const BBox BBox::operator*(const Vec3 &vec) const
{ {
BBox box = *this; BBox box = *this;
@ -363,10 +286,6 @@ BBox BBox::operator*(const Vec3 &vec) const
return box; return box;
} }
//
// BBox::operator*=
//
BBox &BBox::operator*=(const Vec3 &vec) BBox &BBox::operator*=(const Vec3 &vec)
{ {
if (vec.x < 0) { min.x += (vec.x - 1); } if (vec.x < 0) { min.x += (vec.x - 1); }
@ -379,10 +298,6 @@ BBox &BBox::operator*=(const Vec3 &vec)
return *this; return *this;
} }
//
// BBox::operator=
//
BBox &BBox::operator=(const BBox &bbox) BBox &BBox::operator=(const BBox &bbox)
{ {
min = bbox.min; min = bbox.min;
@ -391,30 +306,18 @@ BBox &BBox::operator=(const BBox &bbox)
return *this; return *this;
} }
//
// BBox::operator[]
//
Vec3 BBox::operator[](int index) const Vec3 BBox::operator[](int index) const
{ {
assert(index >= 0 && index < 2); assert(index >= 0 && index < 2);
return index == 0 ? min : max; return index == 0 ? min : max;
} }
//
// BBox::operator[]
//
Vec3 &BBox::operator[](int index) Vec3 &BBox::operator[](int index)
{ {
assert(index >= 0 && index < 2); assert(index >= 0 && index < 2);
return index == 0 ? min : max; return index == 0 ? min : max;
} }
//
// BBox:LineIntersect
//
bool BBox::LineIntersect(const Vec3 &start, const Vec3 &end) bool BBox::LineIntersect(const Vec3 &start, const Vec3 &end)
{ {
float ld[3]; float ld[3];
@ -440,12 +343,7 @@ bool BBox::LineIntersect(const Vec3 &start, const Vec3 &end)
return true; return true;
} }
//
// BBox::ToPoints
//
// Assumes points is an array of 24 // Assumes points is an array of 24
//
void BBox::ToPoints(float *points) const void BBox::ToPoints(float *points) const
{ {
points[0 * 3 + 0] = max[0]; points[0 * 3 + 0] = max[0];
@ -474,12 +372,7 @@ void BBox::ToPoints(float *points) const
points[7 * 3 + 2] = min[2]; points[7 * 3 + 2] = min[2];
} }
//
// BBox::ToVectors
//
// Assumes vectors is an array of 8 // Assumes vectors is an array of 8
//
void BBox::ToVectors(Vec3 *vectors) const void BBox::ToVectors(Vec3 *vectors) const
{ {
vectors[0][0] = max[0]; vectors[0][0] = max[0];

View file

@ -24,18 +24,9 @@
// 3. This notice may not be removed or altered from any source // 3. This notice may not be removed or altered from any source
// distribution. // distribution.
// //
//-----------------------------------------------------------------------------
//
// DESCRIPTION: Math functions
//
//-----------------------------------------------------------------------------
#include "mathlib.h" #include "mathlib.h"
//
// Math::RoundPowerOfTwo
//
int Math::RoundPowerOfTwo(int x) int Math::RoundPowerOfTwo(int x)
{ {
int mask = 1; int mask = 1;
@ -53,12 +44,7 @@ int Math::RoundPowerOfTwo(int x)
return x; return x;
} }
// void Math::CubicCurve(const Vec3 &start, const Vec3 &end, const float time, const Vec3 &point, Vec3 *vec)
// Math::CubicCurve
//
void Math::CubicCurve(const Vec3 &start, const Vec3 &end, const float time,
const Vec3 &point, Vec3 *vec)
{ {
int i; int i;
float xyz[3]; float xyz[3];
@ -74,12 +60,7 @@ void Math::CubicCurve(const Vec3 &start, const Vec3 &end, const float time,
vec->z = xyz[2]; vec->z = xyz[2];
} }
// void Math::QuadraticCurve(const Vec3 &start, const Vec3 &end, const float time, const Vec3 &pt1, const Vec3 &pt2, Vec3 *vec)
// Math::QuadraticCurve
//
void Math::QuadraticCurve(const Vec3 &start, const Vec3 &end, const float time,
const Vec3 &pt1, const Vec3 &pt2, Vec3 *vec)
{ {
int i; int i;
float xyz[3]; float xyz[3];

View file

@ -76,10 +76,8 @@ public:
static void Clamp(uint8_t &b, const uint8_t min, const uint8_t 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 Clamp(Vec3 &f, const float min, const float max);
static void CubicCurve(const Vec3 &start, const Vec3 &end, const float time, static void CubicCurve(const Vec3 &start, const Vec3 &end, const float time, const Vec3 &point, Vec3 *vec);
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 QuadraticCurve(const Vec3 &start, const Vec3 &end, const float time,
const Vec3 &pt1, const Vec3 &pt2, Vec3 *vec);
}; };
class Quat class Quat
@ -218,9 +216,7 @@ public:
float *ToFloatPtr(); float *ToFloatPtr();
Vec2 ToVec2(); Vec2 ToVec2();
Vec2 ToVec2() const; Vec2 ToVec2() const;
Vec3 ScreenProject(Mat4 &proj, Mat4 &model, Vec3 ScreenProject(Mat4 &proj, Mat4 &model, const int width, const int height, const int wx, const int wy);
const int width, const int height,
const int wx, const int wy);
Vec3 operator+(const Vec3 &vec); Vec3 operator+(const Vec3 &vec);
Vec3 operator+(const Vec3 &vec) const; Vec3 operator+(const Vec3 &vec) const;
@ -329,9 +325,7 @@ public:
Quat ToQuat(); Quat ToQuat();
float *ToFloatPtr(); float *ToFloatPtr();
void SetViewProjection(float aspect, float fov, float zNear, float zFar); void SetViewProjection(float aspect, float fov, float zNear, float zFar);
void SetOrtho(float left, float right, void SetOrtho(float left, float right, float bottom, float top, float zNear, float zFar);
float bottom, float top,
float zNear, float zFar);
Mat4 operator*(const Vec3 &vector); Mat4 operator*(const Vec3 &vector);
Mat4 &operator*=(const Vec3 &vector); Mat4 &operator*=(const Vec3 &vector);
@ -383,11 +377,6 @@ public:
float zAt(float x, float y) const { return (d - a * x - b * y) / c; } 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 a;
float b; float b;
float c; float c;

View file

@ -73,19 +73,11 @@
#include <math.h> #include <math.h>
#include "mathlib.h" #include "mathlib.h"
//
// Mat4::Mat4
//
Mat4::Mat4() Mat4::Mat4()
{ {
Identity(); Identity();
} }
//
// Mat4::Mat4
//
Mat4::Mat4(const Mat4 &mtx) Mat4::Mat4(const Mat4 &mtx)
{ {
for (int i = 0; i < 4; i++) 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) Mat4::Mat4(const float x, const float y, const float z)
{ {
Identity(x, y, z); Identity(x, y, z);
} }
//
// Mat4::Mat4
//
Mat4::Mat4(const Quat &quat) Mat4::Mat4(const Quat &quat)
{ {
float xx = quat.x * quat.x; float xx = quat.x * quat.x;
@ -141,10 +125,6 @@ Mat4::Mat4(const Quat &quat)
vectors[3].Set(0, 0, 0, 1); vectors[3].Set(0, 0, 0, 1);
} }
//
// Mat4::Mat4
//
Mat4::Mat4(const float angle, const int axis) Mat4::Mat4(const float angle, const int axis)
{ {
float s; float s;
@ -178,10 +158,6 @@ Mat4::Mat4(const float angle, const int axis)
} }
} }
//
// Mat4::Identity
//
Mat4 &Mat4::Identity() Mat4 &Mat4::Identity()
{ {
vectors[0].Set(1, 0, 0, 0); vectors[0].Set(1, 0, 0, 0);
@ -192,10 +168,6 @@ Mat4 &Mat4::Identity()
return *this; return *this;
} }
//
// Mat4::Identity
//
Mat4 &Mat4::Identity(const float x, const float y, const float z) Mat4 &Mat4::Identity(const float x, const float y, const float z)
{ {
vectors[0].Set(x, 0, 0, 0); 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; return *this;
} }
//
// Mat4::SetTranslation
//
Mat4 &Mat4::SetTranslation(const float x, const float y, const float z) Mat4 &Mat4::SetTranslation(const float x, const float y, const float z)
{ {
vectors[3].ToVec3().Set(x, y, z); vectors[3].ToVec3().Set(x, y, z);
return *this; return *this;
} }
//
// Mat4::SetTranslation
//
Mat4 &Mat4::SetTranslation(const Vec3 &vector) Mat4 &Mat4::SetTranslation(const Vec3 &vector)
{ {
vectors[3].ToVec3() = vector; vectors[3].ToVec3() = vector;
return *this; return *this;
} }
//
// Mat4::AddTranslation
//
Mat4 &Mat4::AddTranslation(const float x, const float y, const float z) Mat4 &Mat4::AddTranslation(const float x, const float y, const float z)
{ {
vectors[3].x += x; vectors[3].x += x;
@ -238,20 +198,12 @@ Mat4 &Mat4::AddTranslation(const float x, const float y, const float z)
return *this; return *this;
} }
//
// Mat4::AddTranslation
//
Mat4 &Mat4::AddTranslation(const Vec3 &vector) Mat4 &Mat4::AddTranslation(const Vec3 &vector)
{ {
vectors[3].ToVec3() += vector; vectors[3].ToVec3() += vector;
return *this; return *this;
} }
//
// Mat4::Scale
//
Mat4 &Mat4::Scale(const float x, const float y, const float z) Mat4 &Mat4::Scale(const float x, const float y, const float z)
{ {
vectors[0].ToVec3() *= x; vectors[0].ToVec3() *= x;
@ -261,10 +213,6 @@ Mat4 &Mat4::Scale(const float x, const float y, const float z)
return *this; return *this;
} }
//
// Mat4::Scale
//
Mat4 &Mat4::Scale(const Vec3 &vector) Mat4 &Mat4::Scale(const Vec3 &vector)
{ {
vectors[0].ToVec3() *= vector.x; vectors[0].ToVec3() *= vector.x;
@ -274,10 +222,6 @@ Mat4 &Mat4::Scale(const Vec3 &vector)
return *this; return *this;
} }
//
// Mat4::Scale
//
Mat4 Mat4::Scale(const Mat4 &mtx, const float x, const float y, const float z) Mat4 Mat4::Scale(const Mat4 &mtx, const float x, const float y, const float z)
{ {
Mat4 out; Mat4 out;
@ -289,10 +233,6 @@ Mat4 Mat4::Scale(const Mat4 &mtx, const float x, const float y, const float z)
return out; return out;
} }
//
// Mat4::Transpose
//
Mat4 &Mat4::Transpose() Mat4 &Mat4::Transpose()
{ {
Vec3 v1 = vectors[1].ToVec3(); Vec3 v1 = vectors[1].ToVec3();
@ -303,10 +243,6 @@ Mat4 &Mat4::Transpose()
return *this; return *this;
} }
//
// Mat4::Transpose
//
Mat4 Mat4::Transpose(const Mat4 &mtx) Mat4 Mat4::Transpose(const Mat4 &mtx)
{ {
Mat4 out; Mat4 out;
@ -319,10 +255,6 @@ Mat4 Mat4::Transpose(const Mat4 &mtx)
return out; return out;
} }
//
// Mat4::Invert
//
Mat4 Mat4::Invert(Mat4 &mtx) Mat4 Mat4::Invert(Mat4 &mtx)
{ {
float d; float d;
@ -383,10 +315,6 @@ Mat4 Mat4::Invert(Mat4 &mtx)
return mtx; return mtx;
} }
//
// Mat4::SetViewProjection
//
void Mat4::SetViewProjection(float aspect, float fov, float zNear, float zFar) void Mat4::SetViewProjection(float aspect, float fov, float zNear, float zFar)
{ {
float top = zNear * Math::Tan(fov * M_PI / 360.0f); 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; vectors[3].w = 0;
} }
// void Mat4::SetOrtho(float left, float right, float bottom, float top, float zNear, float zFar)
// Mat4::SetOrtho
//
void Mat4::SetOrtho(float left, float right,
float bottom, float top,
float zNear, float zFar)
{ {
vectors[0].x = 2 / (right - left); vectors[0].x = 2 / (right - left);
vectors[1].y = 2 / (top - bottom); vectors[1].y = 2 / (top - bottom);
@ -442,10 +364,6 @@ void Mat4::SetOrtho(float left, float right,
vectors[2].w = 0; vectors[2].w = 0;
} }
//
// Mat4::ToQuat
//
Quat Mat4::ToQuat() Quat Mat4::ToQuat()
{ {
float t; float t;
@ -505,10 +423,6 @@ Quat Mat4::ToQuat()
return q; return q;
} }
//
// Mat4::operator*
//
Mat4 Mat4::operator*(const Vec3 &vector) Mat4 Mat4::operator*(const Vec3 &vector)
{ {
Mat4 out(*this); Mat4 out(*this);
@ -520,10 +434,6 @@ Mat4 Mat4::operator*(const Vec3 &vector)
return out; return out;
} }
//
// Mat4::operator*=
//
Mat4 &Mat4::operator*=(const Vec3 &vector) Mat4 &Mat4::operator*=(const Vec3 &vector)
{ {
vectors[3].ToVec3() += vectors[3].ToVec3() +=
@ -533,19 +443,11 @@ Mat4 &Mat4::operator*=(const Vec3 &vector)
return *this; return *this;
} }
//
// Mat4::ToFloatPtr
//
float *Mat4::ToFloatPtr() float *Mat4::ToFloatPtr()
{ {
return reinterpret_cast<float*>(vectors); return reinterpret_cast<float*>(vectors);
} }
//
// Mat4::operator*
//
Mat4 Mat4::operator*(const Mat4 &matrix) Mat4 Mat4::operator*(const Mat4 &matrix)
{ {
Mat4 out; Mat4 out;
@ -577,10 +479,6 @@ Mat4 Mat4::operator*(const Mat4 &matrix)
return out; return out;
} }
//
// Mat4::operator*=
//
Mat4 &Mat4::operator*=(const Mat4 &matrix) Mat4 &Mat4::operator*=(const Mat4 &matrix)
{ {
for (int i = 0; i < 4; i++) for (int i = 0; i < 4; i++)
@ -610,10 +508,6 @@ Mat4 &Mat4::operator*=(const Mat4 &matrix)
return *this; return *this;
} }
//
// Mat4::operator*
//
Mat4 operator*(const Mat4 &m1, const Mat4 &m2) Mat4 operator*(const Mat4 &m1, const Mat4 &m2)
{ {
Mat4 out; Mat4 out;
@ -645,10 +539,6 @@ Mat4 operator*(const Mat4 &m1, const Mat4 &m2)
return out; return out;
} }
//
// Mat4::operator|
//
Mat4 Mat4::operator|(const Mat4 &matrix) Mat4 Mat4::operator|(const Mat4 &matrix)
{ {
Mat4 out; Mat4 out;
@ -685,10 +575,6 @@ Mat4 Mat4::operator|(const Mat4 &matrix)
return out; return out;
} }
//
// Mat4::operator=
//
Mat4 &Mat4::operator=(const Mat4 &matrix) Mat4 &Mat4::operator=(const Mat4 &matrix)
{ {
vectors[0] = matrix.vectors[0]; vectors[0] = matrix.vectors[0];
@ -699,10 +585,6 @@ Mat4 &Mat4::operator=(const Mat4 &matrix)
return *this; return *this;
} }
//
// Mat4::operator=
//
Mat4 &Mat4::operator=(const float *m) Mat4 &Mat4::operator=(const float *m)
{ {
for (int i = 0; i < 4; i++) for (int i = 0; i < 4; i++)

View file

@ -24,19 +24,10 @@
// 3. This notice may not be removed or altered from any source // 3. This notice may not be removed or altered from any source
// distribution. // distribution.
// //
//-----------------------------------------------------------------------------
//
// DESCRIPTION: Plane operations
//
//-----------------------------------------------------------------------------
#include <math.h> #include <math.h>
#include "mathlib.h" #include "mathlib.h"
//
// Plane::Plane
//
Plane::Plane() Plane::Plane()
{ {
this->a = 0; this->a = 0;
@ -45,10 +36,6 @@ Plane::Plane()
this->d = 0; this->d = 0;
} }
//
// Plane::Plane
//
Plane::Plane(const float a, const float b, const float c, const float d) Plane::Plane(const float a, const float b, const float c, const float d)
{ {
this->a = a; this->a = a;
@ -57,20 +44,12 @@ Plane::Plane(const float a, const float b, const float c, const float d)
this->d = d; this->d = d;
} }
//
// Plane::Plane
//
Plane::Plane(const Vec3 &pt1, const Vec3 &pt2, const Vec3 &pt3) Plane::Plane(const Vec3 &pt1, const Vec3 &pt2, const Vec3 &pt3)
{ {
SetNormal(pt1, pt2, pt3); SetNormal(pt1, pt2, pt3);
this->d = Vec3::Dot(pt1, Normal()); this->d = Vec3::Dot(pt1, Normal());
} }
//
// Plane::Plane
//
Plane::Plane(const Vec3 &normal, const Vec3 &point) Plane::Plane(const Vec3 &normal, const Vec3 &point)
{ {
this->a = normal.x; this->a = normal.x;
@ -79,10 +58,6 @@ Plane::Plane(const Vec3 &normal, const Vec3 &point)
this->d = point.Dot(normal); this->d = point.Dot(normal);
} }
//
// Plane::Plane
//
Plane::Plane(const Plane &plane) Plane::Plane(const Plane &plane)
{ {
this->a = plane.a; this->a = plane.a;
@ -91,76 +66,44 @@ Plane::Plane(const Plane &plane)
this->d = plane.d; this->d = plane.d;
} }
//
// Plane::SetNormal
//
Plane &Plane::SetNormal(const Vec3 &normal) Plane &Plane::SetNormal(const Vec3 &normal)
{ {
Normal() = normal; Normal() = normal;
return *this; return *this;
} }
//
// Plane::SetNormal
//
Plane &Plane::SetNormal(const Vec3 &pt1, const Vec3 &pt2, const Vec3 &pt3) Plane &Plane::SetNormal(const Vec3 &pt1, const Vec3 &pt2, const Vec3 &pt3)
{ {
Normal() = (pt2 - pt1).Cross(pt3 - pt2).Normalize(); Normal() = (pt2 - pt1).Cross(pt3 - pt2).Normalize();
return *this; return *this;
} }
//
// Plane::Normal
//
Vec3 const &Plane::Normal() const Vec3 const &Plane::Normal() const
{ {
return *reinterpret_cast<const Vec3*>(&a); return *reinterpret_cast<const Vec3*>(&a);
} }
//
// Plane::Normal
//
Vec3 &Plane::Normal() Vec3 &Plane::Normal()
{ {
return *reinterpret_cast<Vec3*>(&a); return *reinterpret_cast<Vec3*>(&a);
} }
//
// Plane::Distance
//
float Plane::Distance(const Vec3 &point) float Plane::Distance(const Vec3 &point)
{ {
return point.Dot(Normal()); return point.Dot(Normal());
} }
//
// Plane::SetDistance
//
Plane &Plane::SetDistance(const Vec3 &point) Plane &Plane::SetDistance(const Vec3 &point)
{ {
this->d = point.Dot(Normal()); this->d = point.Dot(Normal());
return *this; return *this;
} }
//
// Plane::IsFacing
//
bool Plane::IsFacing(const float yaw) bool Plane::IsFacing(const float yaw)
{ {
return -Math::Sin(yaw) * a + -Math::Cos(yaw) * b < 0; return -Math::Sin(yaw) * a + -Math::Cos(yaw) * b < 0;
} }
//
// Plane::ToYaw
//
float Plane::ToYaw() float Plane::ToYaw()
{ {
float d = Normal().Unit(); float d = Normal().Unit();
@ -180,47 +123,27 @@ float Plane::ToYaw()
return 0; return 0;
} }
//
// Plane::ToPitch
//
float Plane::ToPitch() float Plane::ToPitch()
{ {
return Math::ACos(Vec3::vecUp.Dot(Normal())); return Math::ACos(Vec3::vecUp.Dot(Normal()));
} }
//
// Plane::ToQuat
//
Quat Plane::ToQuat() Quat Plane::ToQuat()
{ {
Vec3 cross = Vec3::vecUp.Cross(Normal()).Normalize(); Vec3 cross = Vec3::vecUp.Cross(Normal()).Normalize();
return Quat(Math::ACos(Vec3::vecUp.Dot(Normal())), cross); return Quat(Math::ACos(Vec3::vecUp.Dot(Normal())), cross);
} }
//
// Plane::ToVec4
//
Vec4 const &Plane::ToVec4() const Vec4 const &Plane::ToVec4() const
{ {
return *reinterpret_cast<const Vec4*>(&a); return *reinterpret_cast<const Vec4*>(&a);
} }
//
// Plane::ToVec4
//
Vec4 &Plane::ToVec4() Vec4 &Plane::ToVec4()
{ {
return *reinterpret_cast<Vec4*>(&a); return *reinterpret_cast<Vec4*>(&a);
} }
//
// Plane::BestAxis
//
const Plane::planeAxis_t Plane::BestAxis() const const Plane::planeAxis_t Plane::BestAxis() const
{ {
float na = Math::Fabs(a); float na = Math::Fabs(a);
@ -240,10 +163,6 @@ const Plane::planeAxis_t Plane::BestAxis() const
return AXIS_XY; return AXIS_XY;
} }
//
// Plane::GetInclination
//
Vec3 Plane::GetInclination() Vec3 Plane::GetInclination()
{ {
Vec3 dir = Normal() * Vec3::vecUp.Dot(Normal()); Vec3 dir = Normal() * Vec3::vecUp.Dot(Normal());

View file

@ -24,28 +24,15 @@
// 3. This notice may not be removed or altered from any source // 3. This notice may not be removed or altered from any source
// distribution. // distribution.
// //
//-----------------------------------------------------------------------------
//
// DESCRIPTION: Quaternion operations
//
//-----------------------------------------------------------------------------
#include <math.h> #include <math.h>
#include "mathlib.h" #include "mathlib.h"
//
// Quat::Quat
//
Quat::Quat() Quat::Quat()
{ {
Clear(); Clear();
} }
//
// Quat::Quat
//
Quat::Quat(const float angle, const float x, const float y, const float z) Quat::Quat(const float angle, const float x, const float y, const float z)
{ {
float s = Math::Sin(angle * 0.5f); 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; this->w = c;
} }
//
// Quat::Quat
//
Quat::Quat(const float angle, Vec3 &vector) Quat::Quat(const float angle, Vec3 &vector)
{ {
float s = Math::Sin(angle * 0.5f); float s = Math::Sin(angle * 0.5f);
@ -72,10 +55,6 @@ Quat::Quat(const float angle, Vec3 &vector)
this->w = c; this->w = c;
} }
//
// Quat::Quat
//
Quat::Quat(const float angle, const Vec3 &vector) Quat::Quat(const float angle, const Vec3 &vector)
{ {
float s = Math::Sin(angle * 0.5f); float s = Math::Sin(angle * 0.5f);
@ -87,10 +66,6 @@ Quat::Quat(const float angle, const Vec3 &vector)
this->w = c; this->w = c;
} }
//
// Quat::Set
//
void Quat::Set(const float x, const float y, const float z, const float w) void Quat::Set(const float x, const float y, const float z, const float w)
{ {
this->x = x; 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; this->w = w;
} }
//
// Quat::Clear
//
void Quat::Clear() void Quat::Clear()
{ {
x = y = z = 0.0f; x = y = z = 0.0f;
w = 1.0f; w = 1.0f;
} }
//
// Vec3::UnitSq
//
float Quat::UnitSq() const float Quat::UnitSq() const
{ {
return x * x + y * y + z * z + w * w; return x * x + y * y + z * z + w * w;
} }
//
// Vec3::Unit
//
float Quat::Unit() const float Quat::Unit() const
{ {
return Math::Sqrt(UnitSq()); return Math::Sqrt(UnitSq());
} }
//
// Quat::Normalize
//
Quat &Quat::Normalize() Quat &Quat::Normalize()
{ {
float d = Unit(); float d = Unit();
@ -142,10 +101,6 @@ Quat &Quat::Normalize()
return *this; return *this;
} }
//
// Quat::Inverse
//
Quat Quat::Inverse() const Quat Quat::Inverse() const
{ {
Quat out; Quat out;
@ -153,10 +108,6 @@ Quat Quat::Inverse() const
return out; return out;
} }
//
// Quat::operator+
//
Quat Quat::operator+(const Quat &quat) Quat Quat::operator+(const Quat &quat)
{ {
Quat out; Quat out;
@ -167,10 +118,6 @@ Quat Quat::operator+(const Quat &quat)
return out; return out;
} }
//
// Quat::operator+=
//
Quat &Quat::operator+=(const Quat &quat) Quat &Quat::operator+=(const Quat &quat)
{ {
x += quat.x; x += quat.x;
@ -180,10 +127,6 @@ Quat &Quat::operator+=(const Quat &quat)
return *this; return *this;
} }
//
// Quat::operator-
//
Quat Quat::operator-(const Quat &quat) Quat Quat::operator-(const Quat &quat)
{ {
Quat out; Quat out;
@ -194,10 +137,6 @@ Quat Quat::operator-(const Quat &quat)
return out; return out;
} }
//
// Quat::operator-=
//
Quat &Quat::operator-=(const Quat &quat) Quat &Quat::operator-=(const Quat &quat)
{ {
x -= quat.x; x -= quat.x;
@ -207,10 +146,6 @@ Quat &Quat::operator-=(const Quat &quat)
return *this; return *this;
} }
//
// Quat::operator*
//
Quat Quat::operator*(const Quat &quat) Quat Quat::operator*(const Quat &quat)
{ {
Quat out; Quat out;
@ -223,10 +158,6 @@ Quat Quat::operator*(const Quat &quat)
return out; return out;
} }
//
// Quat::operator*=
//
Quat &Quat::operator*=(const Quat &quat) Quat &Quat::operator*=(const Quat &quat)
{ {
float tx = x; float tx = x;
@ -242,10 +173,6 @@ Quat &Quat::operator*=(const Quat &quat)
return *this; return *this;
} }
//
// Quat::operator*
//
Quat Quat::operator*(const float val) const Quat Quat::operator*(const float val) const
{ {
Quat out; Quat out;
@ -256,10 +183,6 @@ Quat Quat::operator*(const float val) const
return out; return out;
} }
//
// Quat::operator*=
//
Quat &Quat::operator*=(const float val) Quat &Quat::operator*=(const float val)
{ {
x *= val; x *= val;
@ -270,10 +193,6 @@ Quat &Quat::operator*=(const float val)
return *this; return *this;
} }
//
// Quat::operator|
//
Vec3 Quat::operator|(const Vec3 &vector) Vec3 Quat::operator|(const Vec3 &vector)
{ {
float xx = x * x; float xx = x * x;
@ -300,19 +219,11 @@ Vec3 Quat::operator|(const Vec3 &vector)
); );
} }
//
// Quat::Dot
//
float Quat::Dot(const Quat &quat) const float Quat::Dot(const Quat &quat) const
{ {
return (x * quat.x + y * quat.y + z * quat.z + w * quat.w); 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 Quat::Slerp(const Quat &quat, float movement) const
{ {
Quat rdest = quat; 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) Quat Quat::RotateFrom(const Vec3 &location, const Vec3 &target, float maxAngle)
{ {
Vec3 axis; Vec3 axis;
@ -388,10 +295,6 @@ Quat Quat::RotateFrom(const Vec3 &location, const Vec3 &target, float maxAngle)
return (*this * Quat(an, cp)); return (*this * Quat(an, cp));
} }
//
// Quat::operator=
//
Quat &Quat::operator=(const Quat &quat) Quat &Quat::operator=(const Quat &quat)
{ {
x = quat.x; x = quat.x;
@ -401,10 +304,6 @@ Quat &Quat::operator=(const Quat &quat)
return *this; return *this;
} }
//
// Quat::operator=
//
Quat &Quat::operator=(const Vec4 &vec) Quat &Quat::operator=(const Vec4 &vec)
{ {
x = vec.x; x = vec.x;
@ -414,10 +313,6 @@ Quat &Quat::operator=(const Vec4 &vec)
return *this; return *this;
} }
//
// Quat::operator=
//
Quat &Quat::operator=(const float *vecs) Quat &Quat::operator=(const float *vecs)
{ {
x = vecs[0]; x = vecs[0];
@ -427,19 +322,11 @@ Quat &Quat::operator=(const float *vecs)
return *this; return *this;
} }
//
// Quat::ToVec3
//
Vec3 const &Quat::ToVec3() const Vec3 const &Quat::ToVec3() const
{ {
return *reinterpret_cast<const Vec3*>(this); return *reinterpret_cast<const Vec3*>(this);
} }
//
// Quat::ToVec3
//
Vec3 &Quat::ToVec3() Vec3 &Quat::ToVec3()
{ {
return *reinterpret_cast<Vec3*>(this); return *reinterpret_cast<Vec3*>(this);

View file

@ -24,11 +24,6 @@
// 3. This notice may not be removed or altered from any source // 3. This notice may not be removed or altered from any source
// distribution. // distribution.
// //
//-----------------------------------------------------------------------------
//
// DESCRIPTION: Vector operations
//
//-----------------------------------------------------------------------------
#include <math.h> #include <math.h>
#include "mathlib.h" #include "mathlib.h"