- 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
// distribution.
//
//-----------------------------------------------------------------------------
//
// DESCRIPTION: Binary file operations
//
//-----------------------------------------------------------------------------
#include "framework/binfile.h"

View file

@ -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"

View file

@ -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"

View file

@ -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"

View file

@ -24,11 +24,6 @@
// 3. This notice may not be removed or altered from any source
// distribution.
//
//-----------------------------------------------------------------------------
//
// DESCRIPTION: Angle operations
//
//-----------------------------------------------------------------------------
#include <math.h>
#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<const Vec3*>(&yaw);
}
//
// Angle::ToVec3
//
Vec3 &Angle::ToVec3()
{
return *reinterpret_cast<Vec3*>(&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);

View file

@ -24,49 +24,28 @@
// 3. This notice may not be removed or altered from any source
// distribution.
//
//-----------------------------------------------------------------------------
//
// DESCRIPTION: Bounding box operations
//
//-----------------------------------------------------------------------------
#include <math.h>
#include "mathlib.h"
#include <assert.h>
//
// 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];

View file

@ -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];

View file

@ -76,10 +76,8 @@ public:
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
@ -218,9 +216,7 @@ public:
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 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;
@ -329,9 +325,7 @@ public:
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);
void SetOrtho(float left, float right, float bottom, float top, float zNear, float zFar);
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; }
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;

View file

@ -73,19 +73,11 @@
#include <math.h>
#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<float*>(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++)

View file

@ -24,19 +24,10 @@
// 3. This notice may not be removed or altered from any source
// distribution.
//
//-----------------------------------------------------------------------------
//
// DESCRIPTION: Plane operations
//
//-----------------------------------------------------------------------------
#include <math.h>
#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<const Vec3*>(&a);
}
//
// Plane::Normal
//
Vec3 &Plane::Normal()
{
return *reinterpret_cast<Vec3*>(&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<const Vec4*>(&a);
}
//
// Plane::ToVec4
//
Vec4 &Plane::ToVec4()
{
return *reinterpret_cast<Vec4*>(&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());

View file

@ -24,28 +24,15 @@
// 3. This notice may not be removed or altered from any source
// distribution.
//
//-----------------------------------------------------------------------------
//
// DESCRIPTION: Quaternion operations
//
//-----------------------------------------------------------------------------
#include <math.h>
#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<const Vec3*>(this);
}
//
// Quat::ToVec3
//
Vec3 &Quat::ToVec3()
{
return *reinterpret_cast<Vec3*>(this);

View file

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