MATH: Janitorial
This commit is contained in:
parent
29e4b87fdb
commit
78d4217ddb
14 changed files with 184 additions and 184 deletions
|
@ -32,7 +32,6 @@ Angle::Angle(float degrees) :
|
||||||
|
|
||||||
Angle::Angle(const Angle &a) :
|
Angle::Angle(const Angle &a) :
|
||||||
_degrees(a._degrees) {
|
_degrees(a._degrees) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Angle &Angle::normalize(float low) {
|
Angle &Angle::normalize(float low) {
|
||||||
|
|
|
@ -96,7 +96,6 @@ Common::StreamDebug &operator<<(Common::StreamDebug &dbg, const Math::Line2d &li
|
||||||
|
|
||||||
|
|
||||||
Segment2d::Segment2d() {
|
Segment2d::Segment2d() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Segment2d::Segment2d(const Vector2d &b, const Vector2d &e) :
|
Segment2d::Segment2d(const Vector2d &b, const Vector2d &e) :
|
||||||
|
|
|
@ -46,7 +46,7 @@ void Matrix<3, 3>::transpose() {
|
||||||
* http://clb.confined.space/MathGeoLib/nightly/docs/float3x3_LookAt.php
|
* http://clb.confined.space/MathGeoLib/nightly/docs/float3x3_LookAt.php
|
||||||
*/
|
*/
|
||||||
void Matrix<3, 3>::buildFromTargetDir(const Math::Vector3d &modelForward, const Math::Vector3d &targetDirection,
|
void Matrix<3, 3>::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) {
|
||||||
Math::Vector3d modelRight = Math::Vector3d::crossProduct(modelUp, modelForward);
|
Math::Vector3d modelRight = Math::Vector3d::crossProduct(modelUp, modelForward);
|
||||||
modelRight.normalize();
|
modelRight.normalize();
|
||||||
Math::Vector3d worldRight = Math::Vector3d::crossProduct(worldUp, targetDirection);
|
Math::Vector3d worldRight = Math::Vector3d::crossProduct(worldUp, targetDirection);
|
||||||
|
|
|
@ -50,7 +50,7 @@ public:
|
||||||
* All the parameters MUST be normalized.
|
* All the parameters MUST be normalized.
|
||||||
*/
|
*/
|
||||||
void buildFromTargetDir(const Math::Vector3d &modelForward, const Math::Vector3d &targetDirection,
|
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);
|
||||||
|
|
||||||
inline Matrix<3, 3> operator*(const Matrix<3, 3> &m2) const {
|
inline Matrix<3, 3> operator*(const Matrix<3, 3> &m2) const {
|
||||||
Matrix<3, 3> result;
|
Matrix<3, 3> result;
|
||||||
|
|
|
@ -97,8 +97,7 @@ void Matrix<4, 4>::translate(const Vector3d &vec) {
|
||||||
* http://clb.confined.space/MathGeoLib/nightly/docs/float3x3_LookAt.php
|
* http://clb.confined.space/MathGeoLib/nightly/docs/float3x3_LookAt.php
|
||||||
*/
|
*/
|
||||||
void Matrix<4, 4>::buildFromTargetDir(const Math::Vector3d &modelForward, const Math::Vector3d &targetDirection,
|
void Matrix<4, 4>::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) {
|
||||||
{
|
|
||||||
Matrix3 rotation;
|
Matrix3 rotation;
|
||||||
rotation.buildFromTargetDir(modelForward, targetDirection, modelUp, worldUp);
|
rotation.buildFromTargetDir(modelForward, targetDirection, modelUp, worldUp);
|
||||||
this->setRotation(rotation);
|
this->setRotation(rotation);
|
||||||
|
@ -115,7 +114,7 @@ void Matrix<4, 4>::invertAffineOrthonormal() {
|
||||||
setPosition(position);
|
setPosition(position);
|
||||||
}
|
}
|
||||||
|
|
||||||
void swap (float &a, float &b);
|
void swap(float &a, float &b);
|
||||||
|
|
||||||
void Matrix<4, 4>::transpose() {
|
void Matrix<4, 4>::transpose() {
|
||||||
swap(operator ()(0,1), operator ()(1,0));
|
swap(operator ()(0,1), operator ()(1,0));
|
||||||
|
|
186
math/matrix4.h
186
math/matrix4.h
|
@ -61,14 +61,14 @@ public:
|
||||||
* All the parameters MUST be normalized.
|
* All the parameters MUST be normalized.
|
||||||
*/
|
*/
|
||||||
void buildFromTargetDir(const Math::Vector3d &modelForward, const Math::Vector3d &targetDirection,
|
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.
|
* Inverts a matrix in place.
|
||||||
* This function avoid having to do generic Gaussian elimination on the matrix
|
* 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
|
* by assuming that the top-left 3x3 part of the matrix is orthonormal
|
||||||
* (columns and rows 0, 1 and 2 orthogonal and unit length).
|
* (columns and rows 0, 1 and 2 orthogonal and unit length).
|
||||||
* See e.g. Eric Lengyel's Mathematics for 3D Game Programming and Computer Graphics, p. 82.
|
* See e.g. Eric Lengyel's Mathematics for 3D Game Programming and Computer Graphics, p. 82.
|
||||||
*/
|
*/
|
||||||
void invertAffineOrthonormal();
|
void invertAffineOrthonormal();
|
||||||
|
|
||||||
|
@ -82,10 +82,10 @@ public:
|
||||||
|
|
||||||
for (int i = 0; i < 16; i += 4) {
|
for (int i = 0; i < 16; i += 4) {
|
||||||
for (int j = 0; j < 4; ++j) {
|
for (int j = 0; j < 4; ++j) {
|
||||||
r[i + j] = (d1[i + 0] * d2[j + 0])
|
r[i + j] = (d1[i + 0] * d2[j + 0]) +
|
||||||
+ (d1[i + 1] * d2[j + 4])
|
(d1[i + 1] * d2[j + 4]) +
|
||||||
+ (d1[i + 2] * d2[j + 8])
|
(d1[i + 2] * d2[j + 8]) +
|
||||||
+ (d1[i + 3] * d2[j + 12]);
|
(d1[i + 3] * d2[j + 12]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -114,116 +114,116 @@ public:
|
||||||
float *m = getData();
|
float *m = getData();
|
||||||
|
|
||||||
inv[0] = m[5] * m[10] * m[15] -
|
inv[0] = m[5] * m[10] * m[15] -
|
||||||
m[5] * m[11] * m[14] -
|
m[5] * m[11] * m[14] -
|
||||||
m[9] * m[6] * m[15] +
|
m[9] * m[6] * m[15] +
|
||||||
m[9] * m[7] * m[14] +
|
m[9] * m[7] * m[14] +
|
||||||
m[13] * m[6] * m[11] -
|
m[13] * m[6] * m[11] -
|
||||||
m[13] * m[7] * m[10];
|
m[13] * m[7] * m[10];
|
||||||
|
|
||||||
inv[4] = -m[4] * m[10] * m[15] +
|
inv[4] = -m[4] * m[10] * m[15] +
|
||||||
m[4] * m[11] * m[14] +
|
m[4] * m[11] * m[14] +
|
||||||
m[8] * m[6] * m[15] -
|
m[8] * m[6] * m[15] -
|
||||||
m[8] * m[7] * m[14] -
|
m[8] * m[7] * m[14] -
|
||||||
m[12] * m[6] * m[11] +
|
m[12] * m[6] * m[11] +
|
||||||
m[12] * m[7] * m[10];
|
m[12] * m[7] * m[10];
|
||||||
|
|
||||||
inv[8] = m[4] * m[9] * m[15] -
|
inv[8] = m[4] * m[9] * m[15] -
|
||||||
m[4] * m[11] * m[13] -
|
m[4] * m[11] * m[13] -
|
||||||
m[8] * m[5] * m[15] +
|
m[8] * m[5] * m[15] +
|
||||||
m[8] * m[7] * m[13] +
|
m[8] * m[7] * m[13] +
|
||||||
m[12] * m[5] * m[11] -
|
m[12] * m[5] * m[11] -
|
||||||
m[12] * m[7] * m[9];
|
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[4] * m[10] * m[13] +
|
||||||
m[8] * m[5] * m[14] -
|
m[8] * m[5] * m[14] -
|
||||||
m[8] * m[6] * m[13] -
|
m[8] * m[6] * m[13] -
|
||||||
m[12] * m[5] * m[10] +
|
m[12] * m[5] * m[10] +
|
||||||
m[12] * m[6] * m[9];
|
m[12] * m[6] * m[9];
|
||||||
|
|
||||||
inv[1] = -m[1] * m[10] * m[15] +
|
inv[1] = -m[1] * m[10] * m[15] +
|
||||||
m[1] * m[11] * m[14] +
|
m[1] * m[11] * m[14] +
|
||||||
m[9] * m[2] * m[15] -
|
m[9] * m[2] * m[15] -
|
||||||
m[9] * m[3] * m[14] -
|
m[9] * m[3] * m[14] -
|
||||||
m[13] * m[2] * m[11] +
|
m[13] * m[2] * m[11] +
|
||||||
m[13] * m[3] * m[10];
|
m[13] * m[3] * m[10];
|
||||||
|
|
||||||
inv[5] = m[0] * m[10] * m[15] -
|
inv[5] = m[0] * m[10] * m[15] -
|
||||||
m[0] * m[11] * m[14] -
|
m[0] * m[11] * m[14] -
|
||||||
m[8] * m[2] * m[15] +
|
m[8] * m[2] * m[15] +
|
||||||
m[8] * m[3] * m[14] +
|
m[8] * m[3] * m[14] +
|
||||||
m[12] * m[2] * m[11] -
|
m[12] * m[2] * m[11] -
|
||||||
m[12] * m[3] * m[10];
|
m[12] * m[3] * m[10];
|
||||||
|
|
||||||
inv[9] = -m[0] * m[9] * m[15] +
|
inv[9] = -m[0] * m[9] * m[15] +
|
||||||
m[0] * m[11] * m[13] +
|
m[0] * m[11] * m[13] +
|
||||||
m[8] * m[1] * m[15] -
|
m[8] * m[1] * m[15] -
|
||||||
m[8] * m[3] * m[13] -
|
m[8] * m[3] * m[13] -
|
||||||
m[12] * m[1] * m[11] +
|
m[12] * m[1] * m[11] +
|
||||||
m[12] * m[3] * m[9];
|
m[12] * m[3] * m[9];
|
||||||
|
|
||||||
inv[13] = m[0] * m[9] * m[14] -
|
inv[13] = m[0] * m[9] * m[14] -
|
||||||
m[0] * m[10] * m[13] -
|
m[0] * m[10] * m[13] -
|
||||||
m[8] * m[1] * m[14] +
|
m[8] * m[1] * m[14] +
|
||||||
m[8] * m[2] * m[13] +
|
m[8] * m[2] * m[13] +
|
||||||
m[12] * m[1] * m[10] -
|
m[12] * m[1] * m[10] -
|
||||||
m[12] * m[2] * m[9];
|
m[12] * m[2] * m[9];
|
||||||
|
|
||||||
inv[2] = m[1] * m[6] * m[15] -
|
inv[2] = m[1] * m[6] * m[15] -
|
||||||
m[1] * m[7] * m[14] -
|
m[1] * m[7] * m[14] -
|
||||||
m[5] * m[2] * m[15] +
|
m[5] * m[2] * m[15] +
|
||||||
m[5] * m[3] * m[14] +
|
m[5] * m[3] * m[14] +
|
||||||
m[13] * m[2] * m[7] -
|
m[13] * m[2] * m[7] -
|
||||||
m[13] * m[3] * m[6];
|
m[13] * m[3] * m[6];
|
||||||
|
|
||||||
inv[6] = -m[0] * m[6] * m[15] +
|
inv[6] = -m[0] * m[6] * m[15] +
|
||||||
m[0] * m[7] * m[14] +
|
m[0] * m[7] * m[14] +
|
||||||
m[4] * m[2] * m[15] -
|
m[4] * m[2] * m[15] -
|
||||||
m[4] * m[3] * m[14] -
|
m[4] * m[3] * m[14] -
|
||||||
m[12] * m[2] * m[7] +
|
m[12] * m[2] * m[7] +
|
||||||
m[12] * m[3] * m[6];
|
m[12] * m[3] * m[6];
|
||||||
|
|
||||||
inv[10] = m[0] * m[5] * m[15] -
|
inv[10] = m[0] * m[5] * m[15] -
|
||||||
m[0] * m[7] * m[13] -
|
m[0] * m[7] * m[13] -
|
||||||
m[4] * m[1] * m[15] +
|
m[4] * m[1] * m[15] +
|
||||||
m[4] * m[3] * m[13] +
|
m[4] * m[3] * m[13] +
|
||||||
m[12] * m[1] * m[7] -
|
m[12] * m[1] * m[7] -
|
||||||
m[12] * m[3] * m[5];
|
m[12] * m[3] * m[5];
|
||||||
|
|
||||||
inv[14] = -m[0] * m[5] * m[14] +
|
inv[14] = -m[0] * m[5] * m[14] +
|
||||||
m[0] * m[6] * m[13] +
|
m[0] * m[6] * m[13] +
|
||||||
m[4] * m[1] * m[14] -
|
m[4] * m[1] * m[14] -
|
||||||
m[4] * m[2] * m[13] -
|
m[4] * m[2] * m[13] -
|
||||||
m[12] * m[1] * m[6] +
|
m[12] * m[1] * m[6] +
|
||||||
m[12] * m[2] * m[5];
|
m[12] * m[2] * m[5];
|
||||||
|
|
||||||
inv[3] = -m[1] * m[6] * m[11] +
|
inv[3] = -m[1] * m[6] * m[11] +
|
||||||
m[1] * m[7] * m[10] +
|
m[1] * m[7] * m[10] +
|
||||||
m[5] * m[2] * m[11] -
|
m[5] * m[2] * m[11] -
|
||||||
m[5] * m[3] * m[10] -
|
m[5] * m[3] * m[10] -
|
||||||
m[9] * m[2] * m[7] +
|
m[9] * m[2] * m[7] +
|
||||||
m[9] * m[3] * m[6];
|
m[9] * m[3] * m[6];
|
||||||
|
|
||||||
inv[7] = m[0] * m[6] * m[11] -
|
inv[7] = m[0] * m[6] * m[11] -
|
||||||
m[0] * m[7] * m[10] -
|
m[0] * m[7] * m[10] -
|
||||||
m[4] * m[2] * m[11] +
|
m[4] * m[2] * m[11] +
|
||||||
m[4] * m[3] * m[10] +
|
m[4] * m[3] * m[10] +
|
||||||
m[8] * m[2] * m[7] -
|
m[8] * m[2] * m[7] -
|
||||||
m[8] * m[3] * m[6];
|
m[8] * m[3] * m[6];
|
||||||
|
|
||||||
inv[11] = -m[0] * m[5] * m[11] +
|
inv[11] = -m[0] * m[5] * m[11] +
|
||||||
m[0] * m[7] * m[9] +
|
m[0] * m[7] * m[9] +
|
||||||
m[4] * m[1] * m[11] -
|
m[4] * m[1] * m[11] -
|
||||||
m[4] * m[3] * m[9] -
|
m[4] * m[3] * m[9] -
|
||||||
m[8] * m[1] * m[7] +
|
m[8] * m[1] * m[7] +
|
||||||
m[8] * m[3] * m[5];
|
m[8] * m[3] * m[5];
|
||||||
|
|
||||||
inv[15] = m[0] * m[5] * m[10] -
|
inv[15] = m[0] * m[5] * m[10] -
|
||||||
m[0] * m[6] * m[9] -
|
m[0] * m[6] * m[9] -
|
||||||
m[4] * m[1] * m[10] +
|
m[4] * m[1] * m[10] +
|
||||||
m[4] * m[2] * m[9] +
|
m[4] * m[2] * m[9] +
|
||||||
m[8] * m[1] * m[6] -
|
m[8] * m[1] * m[6] -
|
||||||
m[8] * m[2] * m[5];
|
m[8] * m[2] * m[5];
|
||||||
|
|
||||||
float det = m[0] * inv[0] + m[1] * inv[4] + m[2] * inv[8] + m[3] * inv[12];
|
float det = m[0] * inv[0] + m[1] * inv[4] + m[2] * inv[8] + m[3] * inv[12];
|
||||||
|
|
||||||
|
|
|
@ -178,10 +178,10 @@ void Quaternion::toMatrix(Matrix4 &dst) const {
|
||||||
float two_zz = z() * (z() + z());
|
float two_zz = z() * (z() + z());
|
||||||
|
|
||||||
float newMat[16] = {
|
float newMat[16] = {
|
||||||
1.0f - (two_yy + two_zz), two_xy - two_wz, two_xz + two_wy, 0.0f,
|
1.0f - (two_yy + two_zz), two_xy - two_wz, two_xz + two_wy, 0.0f,
|
||||||
two_xy + two_wz, 1.0f - (two_xx + two_zz), two_yz - two_wx, 0.0f,
|
two_xy + two_wz, 1.0f - (two_xx + two_zz), two_yz - two_wx, 0.0f,
|
||||||
two_xz - two_wy, two_yz + two_wx, 1.0f - (two_xx + two_yy), 0.0f,
|
two_xz - two_wy, two_yz + two_wx, 1.0f - (two_xx + two_yy), 0.0f,
|
||||||
0.0f, 0.0f, 0.0f, 1.0f
|
0.0f, 0.0f, 0.0f, 1.0f
|
||||||
};
|
};
|
||||||
dst.setData(newMat);
|
dst.setData(newMat);
|
||||||
}
|
}
|
||||||
|
|
94
math/quat.h
94
math/quat.h
|
@ -53,99 +53,99 @@ public:
|
||||||
/**
|
/**
|
||||||
* Constructor from four floats in the order X,Y,Z,W
|
* Constructor from four floats in the order X,Y,Z,W
|
||||||
* The initial values should be normalized, otherwise call normalize() after creation
|
* The initial values should be normalized, otherwise call normalize() after creation
|
||||||
* @param lx The X value of the Quaternion
|
* @param lx The X value of the Quaternion
|
||||||
* @param ly The Y value of the Quaternion
|
* @param ly The Y value of the Quaternion
|
||||||
* @param lz The Z value of the Quaternion
|
* @param lz The Z value of the Quaternion
|
||||||
* @param lw The W value of the Quaternion
|
* @param lw The W value of the Quaternion
|
||||||
*/
|
*/
|
||||||
Quaternion(float lx, float ly, float lz, float lw) : Vector4d(lx, ly, lz, lw) {}
|
Quaternion(float lx, float ly, float lz, float lw) : Vector4d(lx, ly, lz, lw) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor from an existing Quaternion
|
* Constructor from an existing Quaternion
|
||||||
* @param q The existing quaternion
|
* @param q The existing quaternion
|
||||||
* @return The new Quaternion
|
* @return The new Quaternion
|
||||||
*/
|
*/
|
||||||
Quaternion(const Quaternion &q) : Vector4d(q.x(), q.y(), q.z(), q.w()) {}
|
Quaternion(const Quaternion &q) : Vector4d(q.x(), q.y(), q.z(), q.w()) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor from a vector of four floats in the order X,Y,Z,W
|
* Constructor from a vector of four floats in the order X,Y,Z,W
|
||||||
* The initial values should be normalized, otherwise call normalize() after creation
|
* The initial values should be normalized, otherwise call normalize() after creation
|
||||||
* @param vec The vector of floats comprising the quaternion
|
* @param vec The vector of floats comprising the quaternion
|
||||||
* @return The new Quaternion
|
* @return The new Quaternion
|
||||||
*/
|
*/
|
||||||
Quaternion(const Vector4d &vec) : Vector4d(vec.x(), vec.y(), vec.z(), vec.w()) {}
|
Quaternion(const Vector4d &vec) : Vector4d(vec.x(), vec.y(), vec.z(), vec.w()) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor from a rotation matrix
|
* Constructor from a rotation matrix
|
||||||
* @param m The rotation matrix
|
* @param m The rotation matrix
|
||||||
* @return The new Quaternion
|
* @return The new Quaternion
|
||||||
*/
|
*/
|
||||||
Quaternion(const Matrix3 &m);
|
Quaternion(const Matrix3 &m);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor from a rotation matrix
|
* Constructor from a rotation matrix
|
||||||
* @param m The rotation matrix
|
* @param m The rotation matrix
|
||||||
* @return The new Quaternion
|
* @return The new Quaternion
|
||||||
*/
|
*/
|
||||||
Quaternion(const Matrix4 &m);
|
Quaternion(const Matrix4 &m);
|
||||||
|
|
||||||
/** Set the Quaternion from a rotation matrix
|
/** Set the Quaternion from a rotation matrix
|
||||||
* @param m The matrix used to set the Quaternion
|
* @param m The matrix used to set the Quaternion
|
||||||
*/
|
*/
|
||||||
void fromMatrix(const Matrix3 &m);
|
void fromMatrix(const Matrix3 &m);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor from an axis vector and the angle to rotate on that axis
|
* Constructor from an axis vector and the angle to rotate on that axis
|
||||||
* @param axis The axis to perform the rotation around
|
* @param axis The axis to perform the rotation around
|
||||||
* @param angle The angle amount to rotate
|
* @param angle The angle amount to rotate
|
||||||
* @return The new Quaternion
|
* @return The new Quaternion
|
||||||
*/
|
*/
|
||||||
Quaternion(const Vector3d &axis, const Angle &angle);
|
Quaternion(const Vector3d &axis, const Angle &angle);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a Quaternion from Euler Coordinates
|
* Constructs a Quaternion from Euler Coordinates
|
||||||
* @param first The Euler Angle for the first Axis
|
* @param first The Euler Angle for the first Axis
|
||||||
* @param second The Euler Angle for the second Axis
|
* @param second The Euler Angle for the second Axis
|
||||||
* @param third The Euler Angle for the third Axis
|
* @param third The Euler Angle for the third Axis
|
||||||
* @param order The Euler Order, specified in Rotation3D
|
* @param order The Euler Order, specified in Rotation3D
|
||||||
* @return The new Quaternion
|
* @return The new Quaternion
|
||||||
*/
|
*/
|
||||||
static Quaternion fromEuler(const Angle &first, const Angle &second, const Angle &third, EulerOrder order);
|
static Quaternion fromEuler(const Angle &first, const Angle &second, const Angle &third, EulerOrder order);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns Euler Angles based on the Euler Order
|
* Returns Euler Angles based on the Euler Order
|
||||||
* @param first The Euler Angle for the first Axis
|
* @param first The Euler Angle for the first Axis
|
||||||
* @param second The Euler Angle for the second Axis
|
* @param second The Euler Angle for the second Axis
|
||||||
* @param third The Euler Angle for the third Axis
|
* @param third The Euler Angle for the third Axis
|
||||||
* @param order The Euler Order, specified in Rotation3D
|
* @param order The Euler Order, specified in Rotation3D
|
||||||
* @return The new Quaternion
|
* @return The new Quaternion
|
||||||
*/
|
*/
|
||||||
void getEuler(Angle *first, Angle *second, Angle *third, EulerOrder order) const;
|
void getEuler(Angle *first, Angle *second, Angle *third, EulerOrder order) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a Quaternion from a rotation around the X Axis
|
* Create a Quaternion from a rotation around the X Axis
|
||||||
* @param angle The Euler Angle for rotation
|
* @param angle The Euler Angle for rotation
|
||||||
* @return The resulting Quaternion
|
* @return The resulting Quaternion
|
||||||
*/
|
*/
|
||||||
static Quaternion xAxis(const Angle &angle);
|
static Quaternion xAxis(const Angle &angle);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a Quaternion from a rotation around the Y Axis
|
* Create a Quaternion from a rotation around the Y Axis
|
||||||
* @param angle The Euler Angle for rotation
|
* @param angle The Euler Angle for rotation
|
||||||
* @return The resulting Quaternion
|
* @return The resulting Quaternion
|
||||||
*/
|
*/
|
||||||
static Quaternion yAxis(const Angle &angle);
|
static Quaternion yAxis(const Angle &angle);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a Quaternion from a rotation around the Z Axis
|
* Create a Quaternion from a rotation around the Z Axis
|
||||||
* @param angle The Euler Angle for rotation
|
* @param angle The Euler Angle for rotation
|
||||||
* @return The resulting Quaternion
|
* @return The resulting Quaternion
|
||||||
*/
|
*/
|
||||||
static Quaternion zAxis(const Angle &angle);
|
static Quaternion zAxis(const Angle &angle);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Normalize the Quaternion
|
* Normalize the Quaternion
|
||||||
* @return A reference to this quaternion
|
* @return A reference to this quaternion
|
||||||
*/
|
*/
|
||||||
Quaternion &normalize();
|
Quaternion &normalize();
|
||||||
|
|
||||||
|
@ -169,29 +169,29 @@ public:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Make a new Quaternion that's the inverse of this Quaternion
|
* Make a new Quaternion that's the inverse of this Quaternion
|
||||||
* @return The resulting Quaternion
|
* @return The resulting Quaternion
|
||||||
*/
|
*/
|
||||||
Quaternion inverse() const;
|
Quaternion inverse() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Slerps between this quaternion and to by factor t
|
* Slerps between this quaternion and to by factor t
|
||||||
* @param to the quaternion to slerp between
|
* @param to the quaternion to slerp between
|
||||||
* @param t factor to slerp by.
|
* @param t factor to slerp by.
|
||||||
* @return the resulting quaternion.
|
* @return the resulting quaternion.
|
||||||
*/
|
*/
|
||||||
Quaternion slerpQuat(const Quaternion& to, const float t) const;
|
Quaternion slerpQuat(const Quaternion& to, const float t) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the direction vector specified by col
|
* Get the direction vector specified by col
|
||||||
* @param col Column in the rotation matrix to get the direction vector from
|
* @param col Column in the rotation matrix to get the direction vector from
|
||||||
* @return The resulting Vector3d
|
* @return The resulting Vector3d
|
||||||
*/
|
*/
|
||||||
Vector3d directionVector(const int col) const;
|
Vector3d directionVector(const int col) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the angle between two quaternions
|
* Get the angle between two quaternions
|
||||||
* @param to The quaternion we're comparing against
|
* @param to The quaternion we're comparing against
|
||||||
* @return The angle between the two
|
* @return The angle between the two
|
||||||
*/
|
*/
|
||||||
Angle getAngleBetween(const Quaternion &to);
|
Angle getAngleBetween(const Quaternion &to);
|
||||||
|
|
||||||
|
@ -212,23 +212,23 @@ public:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Multiply this Quaternion by a constant
|
* Multiply this Quaternion by a constant
|
||||||
* @param quat The Quaternion multiplicand
|
* @param quat The Quaternion multiplicand
|
||||||
* @return The result of the multiplication
|
* @return The result of the multiplication
|
||||||
*/
|
*/
|
||||||
Quaternion operator*(const float c) const;
|
Quaternion operator*(const float c) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sum two quaternions
|
* Sum two quaternions
|
||||||
* @param quat The Quaternion to be added
|
* @param quat The Quaternion to be added
|
||||||
* @return The result of the addition
|
* @return The result of the addition
|
||||||
*/
|
*/
|
||||||
Quaternion operator+(const Quaternion &o) const;
|
Quaternion operator+(const Quaternion &o) const;
|
||||||
Quaternion& operator+=(const Quaternion &o);
|
Quaternion& operator+=(const Quaternion &o);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Compare quaternions
|
* Compare quaternions
|
||||||
* @param quat The Quaternion to be compared
|
* @param quat The Quaternion to be compared
|
||||||
* @return The result of the comparison
|
* @return The result of the comparison
|
||||||
*/
|
*/
|
||||||
bool operator==(const Quaternion &o) const;
|
bool operator==(const Quaternion &o) const;
|
||||||
bool operator!=(const Quaternion &o) const;
|
bool operator!=(const Quaternion &o) const;
|
||||||
|
|
|
@ -42,7 +42,7 @@ Rect2d::Rect2d(const Vector2d &topLeft, const Vector2d &bottomRight) {
|
||||||
}
|
}
|
||||||
|
|
||||||
Rect2d::Rect2d(const Vector2d &topLeft, const Vector2d &topRight,
|
Rect2d::Rect2d(const Vector2d &topLeft, const Vector2d &topRight,
|
||||||
const Vector2d &bottomLeft, const Vector2d &bottomRight) :
|
const Vector2d &bottomLeft, const Vector2d &bottomRight) :
|
||||||
_topLeft(topLeft), _topRight(topRight),
|
_topLeft(topLeft), _topRight(topRight),
|
||||||
_bottomLeft(bottomLeft), _bottomRight(bottomRight) {
|
_bottomLeft(bottomLeft), _bottomRight(bottomRight) {
|
||||||
|
|
||||||
|
@ -115,7 +115,7 @@ bool Rect2d::intersectsCircle(const Vector2d ¢er, float radius) const {
|
||||||
}
|
}
|
||||||
|
|
||||||
float cornerDistance_sq = pow(circleDistance.getX() - w / 2.f, 2.f) +
|
float cornerDistance_sq = pow(circleDistance.getX() - w / 2.f, 2.f) +
|
||||||
pow(circleDistance.getY() - h / 2.f, 2.f);
|
pow(circleDistance.getY() - h / 2.f, 2.f);
|
||||||
|
|
||||||
return (cornerDistance_sq <= radius * radius);
|
return (cornerDistance_sq <= radius * radius);
|
||||||
} else { //The rectangle was rotated
|
} else { //The rectangle was rotated
|
||||||
|
|
|
@ -43,7 +43,7 @@ enum EulerOrder {
|
||||||
EO_YXZ,
|
EO_YXZ,
|
||||||
EO_YZX,
|
EO_YZX,
|
||||||
EO_YZY,
|
EO_YZY,
|
||||||
EO_ZXY, // Original ScummVM implmentation
|
EO_ZXY, // Original ScummVM implmentation
|
||||||
EO_ZXZ,
|
EO_ZXZ,
|
||||||
EO_ZYX,
|
EO_ZYX,
|
||||||
EO_ZYZ
|
EO_ZYZ
|
||||||
|
@ -56,46 +56,46 @@ public:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor and assignment from buildFromEuler
|
* Constructor and assignment from buildFromEuler
|
||||||
* @param first Rotation on the first Axis, angle in degrees
|
* @param first Rotation on the first Axis, angle in degrees
|
||||||
* @param second Rotation on the second Axis, angle in degrees
|
* @param second Rotation on the second Axis, angle in degrees
|
||||||
* @param third Rotation on the third Axis, angle in degrees
|
* @param third Rotation on the third Axis, angle in degrees
|
||||||
* @param order The Euler Order (specifies axis order)
|
* @param order The Euler Order (specifies axis order)
|
||||||
*/
|
*/
|
||||||
Rotation3D(const Angle &first, const Angle &second, const Angle &third, EulerOrder order);
|
Rotation3D(const Angle &first, const Angle &second, const Angle &third, EulerOrder order);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Build a rotation matrix from Euler Angles
|
* Build a rotation matrix from Euler Angles
|
||||||
* @param first Rotation on the first Axis, angle in degrees
|
* @param first Rotation on the first Axis, angle in degrees
|
||||||
* @param second Rotation on the second Axis, angle in degrees
|
* @param second Rotation on the second Axis, angle in degrees
|
||||||
* @param third Rotation on the third Axis, angle in degrees
|
* @param third Rotation on the third Axis, angle in degrees
|
||||||
* @param order The Euler Order (specifies axis order)
|
* @param order The Euler Order (specifies axis order)
|
||||||
*/
|
*/
|
||||||
void buildFromEuler(const Angle &first, const Angle &second, const Angle &third, EulerOrder order);
|
void buildFromEuler(const Angle &first, const Angle &second, const Angle &third, EulerOrder order);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Build a rotation matrix on the X Axis from an angle
|
* Build a rotation matrix on the X Axis from an angle
|
||||||
* @param rotX Rotation on the X Axis angle in degrees
|
* @param rotX Rotation on the X Axis angle in degrees
|
||||||
*/
|
*/
|
||||||
void buildAroundX(const Angle &rotX);
|
void buildAroundX(const Angle &rotX);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Build a rotation matrix on the Y Axis from an angle
|
* Build a rotation matrix on the Y Axis from an angle
|
||||||
* @param rotY Rotation on the Y Axis angle in degrees
|
* @param rotY Rotation on the Y Axis angle in degrees
|
||||||
*/
|
*/
|
||||||
void buildAroundY(const Angle &rotY);
|
void buildAroundY(const Angle &rotY);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Build a rotation matrix on the Z Axis from an angle
|
* Build a rotation matrix on the Z Axis from an angle
|
||||||
* @param rotZ Rotation on the Z Axis angle in degrees
|
* @param rotZ Rotation on the Z Axis angle in degrees
|
||||||
*/
|
*/
|
||||||
void buildAroundZ(const Angle &rotZ);
|
void buildAroundZ(const Angle &rotZ);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get Euler Angles from a rotation matrix
|
* Get Euler Angles from a rotation matrix
|
||||||
* @param first Pointer to the storage for the first axis angle
|
* @param first Pointer to the storage for the first axis angle
|
||||||
* @param second Pointer to the storage for the second axis angle
|
* @param second Pointer to the storage for the second axis angle
|
||||||
* @param third Pointer to the storage for the third axis angle
|
* @param third Pointer to the storage for the third axis angle
|
||||||
* @param order The Euler order (specifies axis order)
|
* @param order The Euler order (specifies axis order)
|
||||||
*/
|
*/
|
||||||
void getEuler(Angle *first, Angle *second, Angle *third, EulerOrder order) const;
|
void getEuler(Angle *first, Angle *second, Angle *third, EulerOrder order) const;
|
||||||
};
|
};
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "math/vector2d.h"
|
#include "math/vector2d.h"
|
||||||
|
|
||||||
#include "common/streamdebug.h"
|
#include "common/streamdebug.h"
|
||||||
|
|
||||||
namespace Math {
|
namespace Math {
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "common/streamdebug.h"
|
#include "common/streamdebug.h"
|
||||||
|
|
||||||
#include "math/vector3d.h"
|
#include "math/vector3d.h"
|
||||||
|
|
||||||
namespace Math {
|
namespace Math {
|
||||||
|
|
|
@ -50,48 +50,48 @@ public:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the value of the vector using three floats
|
* Set the value of the vector using three floats
|
||||||
* @param lx X Value
|
* @param lx X Value
|
||||||
* @param ly Y Value
|
* @param ly Y Value
|
||||||
* @param lz Z Value
|
* @param lz Z Value
|
||||||
*/
|
*/
|
||||||
void set(float lx, float ly, float lz);
|
void set(float lx, float ly, float lz);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the angle of this vector around the unit circle
|
* Get the angle of this vector around the unit circle
|
||||||
* This operation ignores the z-component
|
* This operation ignores the z-component
|
||||||
* @return The computed angle
|
* @return The computed angle
|
||||||
*/
|
*/
|
||||||
Angle unitCircleAngle() const;
|
Angle unitCircleAngle() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Multiply vector XYZ with Matrix 3x3
|
* Multiply vector XYZ with Matrix 3x3
|
||||||
*
|
*
|
||||||
* @return The result of multiplication
|
* @return The result of multiplication
|
||||||
*/
|
*/
|
||||||
inline Vector3d operator*(const MatrixType<3, 3> &m) const {
|
inline Vector3d operator*(const MatrixType<3, 3> &m) const {
|
||||||
const float *d = m.getData();
|
const float *d = m.getData();
|
||||||
return Vector3d(x() * d[0] + y() * d[3] + z() * d[6],
|
return Vector3d(x() * d[0] + y() * d[3] + z() * d[6],
|
||||||
x() * d[1] + y() * d[4] + z() * d[7],
|
x() * d[1] + y() * d[4] + z() * d[7],
|
||||||
x() * d[2] + y() * d[5] + z() * d[8]);
|
x() * d[2] + y() * d[5] + z() * d[8]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Find the cross product between two vectors
|
* Find the cross product between two vectors
|
||||||
* @param v1 The first vector
|
* @param v1 The first vector
|
||||||
* @param v2 The second vector
|
* @param v2 The second vector
|
||||||
* @return The resulting cross product
|
* @return The resulting cross product
|
||||||
*/
|
*/
|
||||||
inline static Vector3d crossProduct(const Vector3d& v1, const Vector3d& v2) {
|
inline static Vector3d crossProduct(const Vector3d& v1, const Vector3d& v2) {
|
||||||
return Vector3d(v1.y() * v2.z() - v1.z() * v2.y(),
|
return Vector3d(v1.y() * v2.z() - v1.z() * v2.y(),
|
||||||
v1.z() * v2.x() - v1.x() * v2.z(),
|
v1.z() * v2.x() - v1.x() * v2.z(),
|
||||||
v1.x() * v2.y() - v1.y() * v2.x());
|
v1.x() * v2.y() - v1.y() * v2.x());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Find the angle between two vectors
|
* Find the angle between two vectors
|
||||||
* @param v1 The first vector
|
* @param v1 The first vector
|
||||||
* @param v2 The second vector
|
* @param v2 The second vector
|
||||||
* @return The computed angle
|
* @return The computed angle
|
||||||
*/
|
*/
|
||||||
inline static Angle angle(const Vector3d& v1, const Vector3d& v2) {
|
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));
|
return Angle::arcCosine(fminf(fmaxf(dotProduct(v1, v2) / (v1.getMagnitude() * v2.getMagnitude()), -1.0f), 1.0f));
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "common/streamdebug.h"
|
#include "common/streamdebug.h"
|
||||||
|
|
||||||
#include "math/vector3d.h"
|
#include "math/vector3d.h"
|
||||||
#include "math/vector4d.h"
|
#include "math/vector4d.h"
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue