diff --git a/math/angle.cpp b/math/angle.cpp index c40bad399d2..67071466b06 100644 --- a/math/angle.cpp +++ b/math/angle.cpp @@ -28,11 +28,11 @@ namespace Math { Angle::Angle(float degrees) : - _degrees(degrees) { + _degrees(degrees) { } Angle::Angle(const Angle &a) : - _degrees(a._degrees) { + _degrees(a._degrees) { } @@ -43,13 +43,13 @@ Angle &Angle::normalize(float low) { } Angle &Angle::clampDegrees(float mag) { - _degrees = getDegrees(-180.f); - if (_degrees >= mag) + _degrees = getDegrees(-180.f); + if (_degrees >= mag) setDegrees(mag); if (_degrees <= -mag) setDegrees(-mag); - - return *this; + + return *this; } Angle &Angle::clampDegrees(float min, float max) { diff --git a/math/angle.h b/math/angle.h index 157b203d9db..4b138c43d47 100644 --- a/math/angle.h +++ b/math/angle.h @@ -112,7 +112,6 @@ public: private: float _degrees; - }; inline Angle operator-(const Angle &a) { @@ -151,7 +150,6 @@ inline bool operator!=(const Angle &a1, const Angle &a2) { } - inline bool operator<(const Angle &a1, const Angle &a2) { return a1.getDegrees() < a2.getDegrees(); } diff --git a/math/frustum.cpp b/math/frustum.cpp index e6f810b645e..8def86e48c5 100644 --- a/math/frustum.cpp +++ b/math/frustum.cpp @@ -61,7 +61,7 @@ void Frustum::setup(const Math::Matrix4 &matrix) { _planes[5]._normal.y() = matrix.getValue(3, 1) - matrix.getValue(2, 1); _planes[5]._normal.z() = matrix.getValue(3, 2) - matrix.getValue(2, 2); _planes[5]._d = matrix.getValue(3, 3) - matrix.getValue(2, 3); - + for (int i = 0; i < 6; ++i) { _planes[i].normalize(); } @@ -70,7 +70,7 @@ void Frustum::setup(const Math::Matrix4 &matrix) { bool Frustum::isInside(const Math::AABB &aabb) const { Math::Vector3d min = aabb.getMin(); Math::Vector3d max = aabb.getMax(); - + for (int i = 0; i < 6; ++i) { const Plane &plane = _planes[i]; Math::Vector3d positive = min; diff --git a/math/line2d.cpp b/math/line2d.cpp index 2c1665b784a..665dd92436b 100644 --- a/math/line2d.cpp +++ b/math/line2d.cpp @@ -31,7 +31,6 @@ namespace Math { * */ - Line2d::Line2d(const Vector2d &direction, const Vector2d &point) { _a = direction.getX(); _b = direction.getY(); @@ -97,15 +96,12 @@ Common::StreamDebug &operator<<(Common::StreamDebug &dbg, const Math::Line2d &li } - - Segment2d::Segment2d() { } Segment2d::Segment2d(const Vector2d &b, const Vector2d &e) : _begin(b), _end(e) { - } Segment2d::Segment2d(const Segment2d &other) { diff --git a/math/line2d.h b/math/line2d.h index 310ecb871bf..2a0ccd96a5d 100644 --- a/math/line2d.h +++ b/math/line2d.h @@ -42,7 +42,6 @@ public: private: float _a, _b, _c; - }; class Segment2d { @@ -66,7 +65,6 @@ public: private: Math::Vector2d _begin, _end; - }; } diff --git a/math/line3d.cpp b/math/line3d.cpp index 8a7bfdc1c61..fc467db585c 100644 --- a/math/line3d.cpp +++ b/math/line3d.cpp @@ -25,12 +25,10 @@ namespace Math { Line3d::Line3d() { - } Line3d::Line3d(const Vector3d &b, const Vector3d &e) : _begin(b), _end(e) { - } Line3d::Line3d(const Line3d &other) { @@ -50,7 +48,6 @@ Math::Vector3d Line3d::middle() const { } bool Line3d::intersectLine2d(const Line3d &other, Math::Vector3d *pos, bool useXZ) { - float denom, nume_a, nume_b; if (useXZ) { denom = ((other._end.z() - other._begin.z()) * (_end.x() - _begin.x())) - diff --git a/math/matrix3.cpp b/math/matrix3.cpp index e212923b04b..16663f61cbe 100644 --- a/math/matrix3.cpp +++ b/math/matrix3.cpp @@ -26,49 +26,46 @@ namespace Math { Matrix<3, 3>::Matrix() : MatrixType<3, 3>(), Rotation3D >() { - } Matrix<3, 3>::Matrix(const MatrixBase<3, 3> &m) : MatrixType<3, 3>(m), Rotation3D >() { - } void swap (float &a, float &b) { - float c=a; a=b; b=c; + float c = a; a = b; b = c; } void Matrix<3, 3>::transpose() { - swap(operator()(0,1), operator()(1,0)); - swap(operator()(0,2), operator()(2,0)); - swap(operator()(1,2), operator()(2,1)); + swap(operator()(0, 1), operator()(1, 0)); + swap(operator()(0, 2), operator()(2, 0)); + swap(operator()(1, 2), operator()(2, 1)); } -/** - * Generates a lookat matrix. For reference, see - * http://clb.demon.fi/MathGeoLib/docs/float3x3_LookAt.php +/** + * Generates a lookat matrix. For reference, see + * http://clb.demon.fi/MathGeoLib/docs/float3x3_LookAt.php */ -void Matrix<3, 3>::buildFromTargetDir(const Math::Vector3d &modelForward, const Math::Vector3d &targetDirection, - const Math::Vector3d &modelUp, const Math::Vector3d &worldUp) -{ - Math::Vector3d modelRight = Math::Vector3d::crossProduct(modelUp, modelForward); +void Matrix<3, 3>::buildFromTargetDir(const Math::Vector3d &modelForward, const Math::Vector3d &targetDirection, + const Math::Vector3d &modelUp, const Math::Vector3d &worldUp) { + Math::Vector3d modelRight = Math::Vector3d::crossProduct(modelUp, modelForward); modelRight.normalize(); Math::Vector3d worldRight = Math::Vector3d::crossProduct(worldUp, targetDirection); worldRight.normalize(); Math::Vector3d perpWorldUp = Math::Vector3d::crossProduct(targetDirection, worldRight); perpWorldUp.normalize(); - + Math::Matrix3 m1; m1.getRow(0) << worldRight.x() << worldRight.y() << worldRight.z(); m1.getRow(1) << perpWorldUp.x() << perpWorldUp.y() << perpWorldUp.z(); m1.getRow(2) << targetDirection.x() << targetDirection.y() << targetDirection.z(); m1.transpose(); - + Math::Matrix3 m2; m2.getRow(0) << modelRight.x() << modelRight.y() << modelRight.z(); m2.getRow(1) << modelUp.x() << modelUp.y() << modelUp.z(); m2.getRow(2) << modelForward.x() << modelForward.y() << modelForward.z(); - + this->operator=(m1 * m2); } diff --git a/math/matrix3.h b/math/matrix3.h index 270e76b5b33..f80c1740cb9 100644 --- a/math/matrix3.h +++ b/math/matrix3.h @@ -35,7 +35,7 @@ public: Matrix(); Matrix(const MatrixBase<3, 3> &m); - void transpose(); + void transpose(); /** @@ -50,8 +50,8 @@ public: * vectors cannot be collinear, but they do not need to be perpendicular either. * All the parameters MUST be normalized. */ - void buildFromTargetDir(const Math::Vector3d &modelForward, const Math::Vector3d &targetDirection, - const Math::Vector3d &modelUp, const Math::Vector3d &worldUp); + void buildFromTargetDir(const Math::Vector3d &modelForward, const Math::Vector3d &targetDirection, + const Math::Vector3d &modelUp, const Math::Vector3d &worldUp); inline Matrix<3, 3> operator*(const Matrix<3, 3> &m2) const { Matrix<3, 3> result; @@ -62,8 +62,8 @@ public: for (int i = 0; i < 9; i += 3) { for (int j = 0; j < 3; ++j) { r[i + j] = (d1[i + 0] * d2[j + 0]) - + (d1[i + 1] * d2[j + 3]) - + (d1[i + 2] * d2[j + 6]); + + (d1[i + 1] * d2[j + 3]) + + (d1[i + 2] * d2[j + 6]); } } diff --git a/math/matrix4.cpp b/math/matrix4.cpp index d1e8c173d81..6f32dbc76fb 100644 --- a/math/matrix4.cpp +++ b/math/matrix4.cpp @@ -41,12 +41,10 @@ namespace Math { Matrix<4, 4>::Matrix() : MatrixType<4, 4>(), Rotation3D() { - } Matrix<4, 4>::Matrix(const MatrixBase<4, 4> &m) : MatrixType<4, 4>(m), Rotation3D() { - } void Matrix<4, 4>::transform(Vector3d *v, bool trans) const { @@ -72,9 +70,9 @@ void Matrix<4, 4>::setPosition(const Vector3d &v) { } Matrix3 Matrix<4, 4>::getRotation() const{ - Matrix3 m2; - - m2.setValue(0, 0, getValue(0, 0)); + Matrix3 m2; + + m2.setValue(0, 0, getValue(0, 0)); m2.setValue(0, 1, getValue(0, 1)); m2.setValue(0, 2, getValue(0, 2)); m2.setValue(1, 0, getValue(1, 0)); @@ -88,7 +86,7 @@ Matrix3 Matrix<4, 4>::getRotation() const{ } void Matrix<4, 4>::setRotation(const Matrix3 &m) { - setValue(0, 0, m.getValue(0, 0)); + setValue(0, 0, m.getValue(0, 0)); setValue(0, 1, m.getValue(0, 1)); setValue(0, 2, m.getValue(0, 2)); setValue(1, 0, m.getValue(1, 0)); @@ -108,27 +106,27 @@ void Matrix<4, 4>::translate(const Vector3d &vec) { operator()(2, 3) += v.z(); } -/** - * Generates a lookat matrix. For reference, see - * http://clb.demon.fi/MathGeoLib/docs/float3x3_LookAt.php +/** + * Generates a lookat matrix. For reference, see + * http://clb.demon.fi/MathGeoLib/docs/float3x3_LookAt.php */ -void Matrix<4, 4>::buildFromTargetDir(const Math::Vector3d &modelForward, const Math::Vector3d &targetDirection, - const Math::Vector3d &modelUp, const Math::Vector3d &worldUp) +void Matrix<4, 4>::buildFromTargetDir(const Math::Vector3d &modelForward, const Math::Vector3d &targetDirection, + const Math::Vector3d &modelUp, const Math::Vector3d &worldUp) { - Matrix3 rotation; - rotation.buildFromTargetDir(modelForward, targetDirection, modelUp, worldUp); - this->setRotation(rotation); + Matrix3 rotation; + rotation.buildFromTargetDir(modelForward, targetDirection, modelUp, worldUp); + this->setRotation(rotation); } void Matrix<4, 4>::invertAffineOrthonormal() { - Matrix3 rotation(getRotation()); - rotation.transpose(); - - Vector3d position(getPosition().getNegative()); - - rotation.transformVector(&position); - setRotation(rotation); - setPosition(position); + Matrix3 rotation(getRotation()); + rotation.transpose(); + + Vector3d position(getPosition().getNegative()); + + rotation.transformVector(&position); + setRotation(rotation); + setPosition(position); } void Matrix<4, 4>::inverseTranslate(Vector3d *v) const { @@ -139,17 +137,16 @@ void Matrix<4, 4>::inverseTranslate(Vector3d *v) const { void Matrix<4, 4>::inverseRotate(Vector3d *v) const { Vector3d temp; - + temp.x() = v->x() * getValue(0, 0) + v->y() * getValue(1, 0) + v->z() * getValue(2, 0); temp.y() = v->x() * getValue(0, 1) + v->y() * getValue(1, 1) + v->z() * getValue(2, 1); temp.z() = v->x() * getValue(0, 2) + v->y() * getValue(1, 2) + v->z() * getValue(2, 2); - + *v = temp; } void swap (float &a, float &b); - void Matrix<4, 4>::transpose() { swap(operator ()(0,1), operator ()(1,0)); swap(operator ()(0,2), operator ()(2,0)); diff --git a/math/matrix4.h b/math/matrix4.h index d4ad0b300e2..cc67346696d 100644 --- a/math/matrix4.h +++ b/math/matrix4.h @@ -64,9 +64,9 @@ public: * All the parameters MUST be normalized. */ void buildFromTargetDir(const Math::Vector3d &modelForward, const Math::Vector3d &targetDirection, - const Math::Vector3d &modelUp, const Math::Vector3d &worldUp); + const Math::Vector3d &modelUp, const Math::Vector3d &worldUp); - /** + /** * Inverts a matrix in place. * This function avoid having to do generic Gaussian elimination on the matrix * by assuming that the top-left 3x3 part of the matrix is orthonormal @@ -116,116 +116,116 @@ public: float *inv = invMatrix.getData(); float *m = getData(); - inv[0] = m[5] * m[10] * m[15] - - m[5] * m[11] * m[14] - - m[9] * m[6] * m[15] + + inv[0] = m[5] * m[10] * m[15] - + m[5] * m[11] * m[14] - + m[9] * m[6] * m[15] + m[9] * m[7] * m[14] + - m[13] * m[6] * m[11] - + m[13] * m[6] * m[11] - m[13] * m[7] * m[10]; - inv[4] = -m[4] * m[10] * m[15] + - m[4] * m[11] * m[14] + - m[8] * m[6] * m[15] - - m[8] * m[7] * m[14] - - m[12] * m[6] * m[11] + + inv[4] = -m[4] * m[10] * m[15] + + m[4] * m[11] * m[14] + + m[8] * m[6] * m[15] - + m[8] * m[7] * m[14] - + m[12] * m[6] * m[11] + m[12] * m[7] * m[10]; - inv[8] = m[4] * m[9] * m[15] - - m[4] * m[11] * m[13] - - m[8] * m[5] * m[15] + - m[8] * m[7] * m[13] + - m[12] * m[5] * m[11] - + inv[8] = m[4] * m[9] * m[15] - + m[4] * m[11] * m[13] - + m[8] * m[5] * m[15] + + m[8] * m[7] * m[13] + + m[12] * m[5] * m[11] - m[12] * m[7] * m[9]; - inv[12] = -m[4] * m[9] * m[14] + + inv[12] = -m[4] * m[9] * m[14] + m[4] * m[10] * m[13] + - m[8] * m[5] * m[14] - - m[8] * m[6] * m[13] - - m[12] * m[5] * m[10] + + m[8] * m[5] * m[14] - + m[8] * m[6] * m[13] - + m[12] * m[5] * m[10] + m[12] * m[6] * m[9]; - inv[1] = -m[1] * m[10] * m[15] + - m[1] * m[11] * m[14] + - m[9] * m[2] * m[15] - - m[9] * m[3] * m[14] - - m[13] * m[2] * m[11] + + inv[1] = -m[1] * m[10] * m[15] + + m[1] * m[11] * m[14] + + m[9] * m[2] * m[15] - + m[9] * m[3] * m[14] - + m[13] * m[2] * m[11] + m[13] * m[3] * m[10]; - inv[5] = m[0] * m[10] * m[15] - - m[0] * m[11] * m[14] - - m[8] * m[2] * m[15] + - m[8] * m[3] * m[14] + - m[12] * m[2] * m[11] - + inv[5] = m[0] * m[10] * m[15] - + m[0] * m[11] * m[14] - + m[8] * m[2] * m[15] + + m[8] * m[3] * m[14] + + m[12] * m[2] * m[11] - m[12] * m[3] * m[10]; - inv[9] = -m[0] * m[9] * m[15] + - m[0] * m[11] * m[13] + - m[8] * m[1] * m[15] - - m[8] * m[3] * m[13] - - m[12] * m[1] * m[11] + + inv[9] = -m[0] * m[9] * m[15] + + m[0] * m[11] * m[13] + + m[8] * m[1] * m[15] - + m[8] * m[3] * m[13] - + m[12] * m[1] * m[11] + m[12] * m[3] * m[9]; - inv[13] = m[0] * m[9] * m[14] - - m[0] * m[10] * m[13] - - m[8] * m[1] * m[14] + - m[8] * m[2] * m[13] + - m[12] * m[1] * m[10] - + inv[13] = m[0] * m[9] * m[14] - + m[0] * m[10] * m[13] - + m[8] * m[1] * m[14] + + m[8] * m[2] * m[13] + + m[12] * m[1] * m[10] - m[12] * m[2] * m[9]; - inv[2] = m[1] * m[6] * m[15] - - m[1] * m[7] * m[14] - - m[5] * m[2] * m[15] + - m[5] * m[3] * m[14] + - m[13] * m[2] * m[7] - + inv[2] = m[1] * m[6] * m[15] - + m[1] * m[7] * m[14] - + m[5] * m[2] * m[15] + + m[5] * m[3] * m[14] + + m[13] * m[2] * m[7] - m[13] * m[3] * m[6]; - inv[6] = -m[0] * m[6] * m[15] + - m[0] * m[7] * m[14] + - m[4] * m[2] * m[15] - - m[4] * m[3] * m[14] - - m[12] * m[2] * m[7] + + inv[6] = -m[0] * m[6] * m[15] + + m[0] * m[7] * m[14] + + m[4] * m[2] * m[15] - + m[4] * m[3] * m[14] - + m[12] * m[2] * m[7] + m[12] * m[3] * m[6]; - inv[10] = m[0] * m[5] * m[15] - - m[0] * m[7] * m[13] - - m[4] * m[1] * m[15] + - m[4] * m[3] * m[13] + - m[12] * m[1] * m[7] - + inv[10] = m[0] * m[5] * m[15] - + m[0] * m[7] * m[13] - + m[4] * m[1] * m[15] + + m[4] * m[3] * m[13] + + m[12] * m[1] * m[7] - m[12] * m[3] * m[5]; - inv[14] = -m[0] * m[5] * m[14] + - m[0] * m[6] * m[13] + - m[4] * m[1] * m[14] - - m[4] * m[2] * m[13] - - m[12] * m[1] * m[6] + + inv[14] = -m[0] * m[5] * m[14] + + m[0] * m[6] * m[13] + + m[4] * m[1] * m[14] - + m[4] * m[2] * m[13] - + m[12] * m[1] * m[6] + m[12] * m[2] * m[5]; - inv[3] = -m[1] * m[6] * m[11] + - m[1] * m[7] * m[10] + - m[5] * m[2] * m[11] - - m[5] * m[3] * m[10] - - m[9] * m[2] * m[7] + + inv[3] = -m[1] * m[6] * m[11] + + m[1] * m[7] * m[10] + + m[5] * m[2] * m[11] - + m[5] * m[3] * m[10] - + m[9] * m[2] * m[7] + m[9] * m[3] * m[6]; - inv[7] = m[0] * m[6] * m[11] - - m[0] * m[7] * m[10] - - m[4] * m[2] * m[11] + - m[4] * m[3] * m[10] + - m[8] * m[2] * m[7] - + inv[7] = m[0] * m[6] * m[11] - + m[0] * m[7] * m[10] - + m[4] * m[2] * m[11] + + m[4] * m[3] * m[10] + + m[8] * m[2] * m[7] - m[8] * m[3] * m[6]; - inv[11] = -m[0] * m[5] * m[11] + - m[0] * m[7] * m[9] + - m[4] * m[1] * m[11] - - m[4] * m[3] * m[9] - - m[8] * m[1] * m[7] + + inv[11] = -m[0] * m[5] * m[11] + + m[0] * m[7] * m[9] + + m[4] * m[1] * m[11] - + m[4] * m[3] * m[9] - + m[8] * m[1] * m[7] + m[8] * m[3] * m[5]; - inv[15] = m[0] * m[5] * m[10] - - m[0] * m[6] * m[9] - - m[4] * m[1] * m[10] + - m[4] * m[2] * m[9] + - m[8] * m[1] * m[6] - + inv[15] = m[0] * m[5] * m[10] - + m[0] * m[6] * m[9] - + m[4] * m[1] * m[10] + + m[4] * m[2] * m[9] + + m[8] * m[1] * m[6] - m[8] * m[2] * m[5]; float det = m[0] * inv[0] + m[1] * inv[4] + m[2] * inv[8] + m[3] * inv[12]; diff --git a/math/ray.cpp b/math/ray.cpp index 9b05befa293..4d0900fb0cd 100644 --- a/math/ray.cpp +++ b/math/ray.cpp @@ -50,7 +50,6 @@ void Ray::translate(const Vector3d &v) { _origin += v; } - bool Ray::intersectAABB(const AABB &aabb) const { Vector3d dirFrac; dirFrac.x() = 1.0f / _direction.x(); diff --git a/math/rect2d.cpp b/math/rect2d.cpp index dd59ba00193..ebf6f445619 100644 --- a/math/rect2d.cpp +++ b/math/rect2d.cpp @@ -28,7 +28,6 @@ namespace Math { Rect2d::Rect2d() { - } Rect2d::Rect2d(const Vector2d &topLeft, const Vector2d &bottomRight) { diff --git a/math/rect2d.h b/math/rect2d.h index 03bcbdbcfd7..875bc613f44 100644 --- a/math/rect2d.h +++ b/math/rect2d.h @@ -35,7 +35,7 @@ public: Rect2d(); Rect2d(const Vector2d &topLeft, const Vector2d &bottomRight); Rect2d(const Vector2d &topLeft, const Vector2d &topRight, - const Vector2d &bottomLeft, const Vector2d &bottomRight); + const Vector2d &bottomLeft, const Vector2d &bottomRight); void rotateAround(const Vector2d &point, const Angle &angle); void rotateAroundCenter(const Angle &angle); diff --git a/math/vector2d.cpp b/math/vector2d.cpp index dd11beb8fb4..1b72108fbd2 100644 --- a/math/vector2d.cpp +++ b/math/vector2d.cpp @@ -27,7 +27,6 @@ namespace Math { Vector2d::Matrix() : MatrixType<2, 1>() { - } Vector2d::Matrix(float x, float y) : @@ -38,7 +37,6 @@ Vector2d::Matrix(float x, float y) : Vector2d::Matrix(const MatrixBase<2, 1> &vec) : MatrixType<2, 1>(vec) { - } Vector2d::Matrix(const float *data) : diff --git a/math/vector3d.cpp b/math/vector3d.cpp index ff7b6f27169..012047beb4c 100644 --- a/math/vector3d.cpp +++ b/math/vector3d.cpp @@ -27,7 +27,6 @@ namespace Math { Vector3d::Matrix() : MatrixType<3, 1>() { - } Vector3d::Matrix(float lx, float ly, float lz) : diff --git a/math/vector3d.h b/math/vector3d.h index 2c5c06cdea0..e1e1f26ae65 100644 --- a/math/vector3d.h +++ b/math/vector3d.h @@ -84,7 +84,6 @@ public: inline static Angle angle(const Vector3d& v1, const Vector3d& v2) { return Angle::arcCosine(fminf(fmaxf(dotProduct(v1, v2) / (v1.getMagnitude() * v2.getMagnitude()), -1.0f), 1.0f)); } - }; } // end of namespace Math diff --git a/math/vector4d.cpp b/math/vector4d.cpp index 10357fd8a30..c8dd9b666c0 100644 --- a/math/vector4d.cpp +++ b/math/vector4d.cpp @@ -28,7 +28,6 @@ namespace Math { Vector4d::Matrix() : MatrixType<4, 1>() { - } Vector4d::Matrix(float lx, float ly, float lz, float lw) :