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) :
|
||||
_degrees(a._degrees) {
|
||||
|
||||
}
|
||||
|
||||
Angle &Angle::normalize(float low) {
|
||||
|
|
|
@ -96,7 +96,6 @@ Common::StreamDebug &operator<<(Common::StreamDebug &dbg, const Math::Line2d &li
|
|||
|
||||
|
||||
Segment2d::Segment2d() {
|
||||
|
||||
}
|
||||
|
||||
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
|
||||
*/
|
||||
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);
|
||||
modelRight.normalize();
|
||||
Math::Vector3d worldRight = Math::Vector3d::crossProduct(worldUp, targetDirection);
|
||||
|
|
|
@ -50,7 +50,7 @@ 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);
|
||||
|
||||
inline Matrix<3, 3> operator*(const Matrix<3, 3> &m2) const {
|
||||
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
|
||||
*/
|
||||
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;
|
||||
rotation.buildFromTargetDir(modelForward, targetDirection, modelUp, worldUp);
|
||||
this->setRotation(rotation);
|
||||
|
@ -115,7 +114,7 @@ void Matrix<4, 4>::invertAffineOrthonormal() {
|
|||
setPosition(position);
|
||||
}
|
||||
|
||||
void swap (float &a, float &b);
|
||||
void swap(float &a, float &b);
|
||||
|
||||
void Matrix<4, 4>::transpose() {
|
||||
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.
|
||||
*/
|
||||
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
|
||||
* (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.
|
||||
* 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
|
||||
* (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.
|
||||
*/
|
||||
void invertAffineOrthonormal();
|
||||
|
||||
|
@ -82,10 +82,10 @@ public:
|
|||
|
||||
for (int i = 0; i < 16; i += 4) {
|
||||
for (int j = 0; j < 4; ++j) {
|
||||
r[i + j] = (d1[i + 0] * d2[j + 0])
|
||||
+ (d1[i + 1] * d2[j + 4])
|
||||
+ (d1[i + 2] * d2[j + 8])
|
||||
+ (d1[i + 3] * d2[j + 12]);
|
||||
r[i + j] = (d1[i + 0] * d2[j + 0]) +
|
||||
(d1[i + 1] * d2[j + 4]) +
|
||||
(d1[i + 2] * d2[j + 8]) +
|
||||
(d1[i + 3] * d2[j + 12]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -114,116 +114,116 @@ public:
|
|||
float *m = getData();
|
||||
|
||||
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[7] * m[10];
|
||||
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[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] +
|
||||
m[12] * m[7] * m[10];
|
||||
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] -
|
||||
m[12] * m[7] * m[9];
|
||||
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] +
|
||||
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[12] * m[6] * m[9];
|
||||
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[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] +
|
||||
m[13] * m[3] * m[10];
|
||||
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] -
|
||||
m[12] * m[3] * m[10];
|
||||
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] +
|
||||
m[12] * m[3] * m[9];
|
||||
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] -
|
||||
m[12] * m[2] * 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] -
|
||||
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] -
|
||||
m[13] * m[3] * m[6];
|
||||
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] +
|
||||
m[12] * m[3] * m[6];
|
||||
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] -
|
||||
m[12] * m[3] * m[5];
|
||||
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] +
|
||||
m[12] * m[2] * m[5];
|
||||
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] +
|
||||
m[9] * m[3] * m[6];
|
||||
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] -
|
||||
m[8] * m[3] * m[6];
|
||||
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] +
|
||||
m[8] * m[3] * m[5];
|
||||
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] -
|
||||
m[8] * m[2] * m[5];
|
||||
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];
|
||||
|
||||
|
|
|
@ -178,10 +178,10 @@ void Quaternion::toMatrix(Matrix4 &dst) const {
|
|||
float two_zz = z() * (z() + z());
|
||||
|
||||
float newMat[16] = {
|
||||
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_xz - two_wy, two_yz + two_wx, 1.0f - (two_xx + two_yy), 0.0f,
|
||||
0.0f, 0.0f, 0.0f, 1.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_xz - two_wy, two_yz + two_wx, 1.0f - (two_xx + two_yy), 0.0f,
|
||||
0.0f, 0.0f, 0.0f, 1.0f
|
||||
};
|
||||
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
|
||||
* The initial values should be normalized, otherwise call normalize() after creation
|
||||
* @param lx The X value of the Quaternion
|
||||
* @param ly The Y value of the Quaternion
|
||||
* @param lz The Z value of the Quaternion
|
||||
* @param lw The W value of the Quaternion
|
||||
* @param lx The X value of the Quaternion
|
||||
* @param ly The Y value of the Quaternion
|
||||
* @param lz The Z 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) {}
|
||||
|
||||
/**
|
||||
* Constructor from an existing Quaternion
|
||||
* @param q The existing quaternion
|
||||
* @return The new Quaternion
|
||||
* @param q The existing quaternion
|
||||
* @return The new Quaternion
|
||||
*/
|
||||
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
|
||||
* The initial values should be normalized, otherwise call normalize() after creation
|
||||
* @param vec The vector of floats comprising the quaternion
|
||||
* @return The new Quaternion
|
||||
* @param vec The vector of floats comprising the quaternion
|
||||
* @return The new Quaternion
|
||||
*/
|
||||
Quaternion(const Vector4d &vec) : Vector4d(vec.x(), vec.y(), vec.z(), vec.w()) {}
|
||||
|
||||
/**
|
||||
* Constructor from a rotation matrix
|
||||
* @param m The rotation matrix
|
||||
* @return The new Quaternion
|
||||
* @param m The rotation matrix
|
||||
* @return The new Quaternion
|
||||
*/
|
||||
Quaternion(const Matrix3 &m);
|
||||
|
||||
/**
|
||||
* Constructor from a rotation matrix
|
||||
* @param m The rotation matrix
|
||||
* @return The new Quaternion
|
||||
* @param m The rotation matrix
|
||||
* @return The new Quaternion
|
||||
*/
|
||||
Quaternion(const Matrix4 &m);
|
||||
|
||||
/** 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);
|
||||
|
||||
/**
|
||||
* Constructor from an axis vector and the angle to rotate on that axis
|
||||
* @param axis The axis to perform the rotation around
|
||||
* @param angle The angle amount to rotate
|
||||
* @return The new Quaternion
|
||||
* @param axis The axis to perform the rotation around
|
||||
* @param angle The angle amount to rotate
|
||||
* @return The new Quaternion
|
||||
*/
|
||||
Quaternion(const Vector3d &axis, const Angle &angle);
|
||||
|
||||
/**
|
||||
* Constructs a Quaternion from Euler Coordinates
|
||||
* @param first The Euler Angle for the first Axis
|
||||
* @param second The Euler Angle for the second Axis
|
||||
* @param third The Euler Angle for the third Axis
|
||||
* @param order The Euler Order, specified in Rotation3D
|
||||
* @return The new Quaternion
|
||||
* @param first The Euler Angle for the first Axis
|
||||
* @param second The Euler Angle for the second Axis
|
||||
* @param third The Euler Angle for the third Axis
|
||||
* @param order The Euler Order, specified in Rotation3D
|
||||
* @return The new Quaternion
|
||||
*/
|
||||
static Quaternion fromEuler(const Angle &first, const Angle &second, const Angle &third, EulerOrder order);
|
||||
|
||||
/**
|
||||
* Returns Euler Angles based on the Euler Order
|
||||
* @param first The Euler Angle for the first Axis
|
||||
* @param second The Euler Angle for the second Axis
|
||||
* @param third The Euler Angle for the third Axis
|
||||
* @param order The Euler Order, specified in Rotation3D
|
||||
* @return The new Quaternion
|
||||
* @param first The Euler Angle for the first Axis
|
||||
* @param second The Euler Angle for the second Axis
|
||||
* @param third The Euler Angle for the third Axis
|
||||
* @param order The Euler Order, specified in Rotation3D
|
||||
* @return The new Quaternion
|
||||
*/
|
||||
void getEuler(Angle *first, Angle *second, Angle *third, EulerOrder order) const;
|
||||
|
||||
/**
|
||||
* Create a Quaternion from a rotation around the X Axis
|
||||
* @param angle The Euler Angle for rotation
|
||||
* @return The resulting Quaternion
|
||||
* @param angle The Euler Angle for rotation
|
||||
* @return The resulting Quaternion
|
||||
*/
|
||||
static Quaternion xAxis(const Angle &angle);
|
||||
|
||||
/**
|
||||
* Create a Quaternion from a rotation around the Y Axis
|
||||
* @param angle The Euler Angle for rotation
|
||||
* @return The resulting Quaternion
|
||||
* @param angle The Euler Angle for rotation
|
||||
* @return The resulting Quaternion
|
||||
*/
|
||||
static Quaternion yAxis(const Angle &angle);
|
||||
|
||||
/**
|
||||
* Create a Quaternion from a rotation around the Z Axis
|
||||
* @param angle The Euler Angle for rotation
|
||||
* @return The resulting Quaternion
|
||||
* @param angle The Euler Angle for rotation
|
||||
* @return The resulting Quaternion
|
||||
*/
|
||||
static Quaternion zAxis(const Angle &angle);
|
||||
|
||||
/**
|
||||
* Normalize the Quaternion
|
||||
* @return A reference to this quaternion
|
||||
* @return A reference to this quaternion
|
||||
*/
|
||||
Quaternion &normalize();
|
||||
|
||||
|
@ -169,29 +169,29 @@ public:
|
|||
|
||||
/**
|
||||
* Make a new Quaternion that's the inverse of this Quaternion
|
||||
* @return The resulting Quaternion
|
||||
* @return The resulting Quaternion
|
||||
*/
|
||||
Quaternion inverse() const;
|
||||
|
||||
/**
|
||||
* Slerps between this quaternion and to by factor t
|
||||
* @param to the quaternion to slerp between
|
||||
* @param t factor to slerp by.
|
||||
* @return the resulting quaternion.
|
||||
* @param to the quaternion to slerp between
|
||||
* @param t factor to slerp by.
|
||||
* @return the resulting quaternion.
|
||||
*/
|
||||
Quaternion slerpQuat(const Quaternion& to, const float t) const;
|
||||
|
||||
/**
|
||||
* Get the direction vector specified by col
|
||||
* @param col Column in the rotation matrix to get the direction vector from
|
||||
* @return The resulting Vector3d
|
||||
* @param col Column in the rotation matrix to get the direction vector from
|
||||
* @return The resulting Vector3d
|
||||
*/
|
||||
Vector3d directionVector(const int col) const;
|
||||
|
||||
/**
|
||||
* Get the angle between two quaternions
|
||||
* @param to The quaternion we're comparing against
|
||||
* @return The angle between the two
|
||||
* @param to The quaternion we're comparing against
|
||||
* @return The angle between the two
|
||||
*/
|
||||
Angle getAngleBetween(const Quaternion &to);
|
||||
|
||||
|
@ -212,23 +212,23 @@ public:
|
|||
|
||||
/**
|
||||
* Multiply this Quaternion by a constant
|
||||
* @param quat The Quaternion multiplicand
|
||||
* @return The result of the multiplication
|
||||
* @param quat The Quaternion multiplicand
|
||||
* @return The result of the multiplication
|
||||
*/
|
||||
Quaternion operator*(const float c) const;
|
||||
|
||||
/**
|
||||
* Sum two quaternions
|
||||
* @param quat The Quaternion to be added
|
||||
* @return The result of the addition
|
||||
* @param quat The Quaternion to be added
|
||||
* @return The result of the addition
|
||||
*/
|
||||
Quaternion operator+(const Quaternion &o) const;
|
||||
Quaternion& operator+=(const Quaternion &o);
|
||||
|
||||
/**
|
||||
* Compare quaternions
|
||||
* @param quat The Quaternion to be compared
|
||||
* @return The result of the comparison
|
||||
* @param quat The Quaternion to be compared
|
||||
* @return The result of the comparison
|
||||
*/
|
||||
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,
|
||||
const Vector2d &bottomLeft, const Vector2d &bottomRight) :
|
||||
const Vector2d &bottomLeft, const Vector2d &bottomRight) :
|
||||
_topLeft(topLeft), _topRight(topRight),
|
||||
_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) +
|
||||
pow(circleDistance.getY() - h / 2.f, 2.f);
|
||||
pow(circleDistance.getY() - h / 2.f, 2.f);
|
||||
|
||||
return (cornerDistance_sq <= radius * radius);
|
||||
} else { //The rectangle was rotated
|
||||
|
|
|
@ -43,7 +43,7 @@ enum EulerOrder {
|
|||
EO_YXZ,
|
||||
EO_YZX,
|
||||
EO_YZY,
|
||||
EO_ZXY, // Original ScummVM implmentation
|
||||
EO_ZXY, // Original ScummVM implmentation
|
||||
EO_ZXZ,
|
||||
EO_ZYX,
|
||||
EO_ZYZ
|
||||
|
@ -56,46 +56,46 @@ public:
|
|||
|
||||
/**
|
||||
* Constructor and assignment from buildFromEuler
|
||||
* @param first Rotation on the first 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 order The Euler Order (specifies axis order)
|
||||
* @param first Rotation on the first 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 order The Euler Order (specifies axis order)
|
||||
*/
|
||||
Rotation3D(const Angle &first, const Angle &second, const Angle &third, EulerOrder order);
|
||||
|
||||
/**
|
||||
* Build a rotation matrix from Euler Angles
|
||||
* @param first Rotation on the first 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 order The Euler Order (specifies axis order)
|
||||
* @param first Rotation on the first 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 order The Euler Order (specifies axis 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
|
||||
* @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);
|
||||
|
||||
/**
|
||||
* 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);
|
||||
|
||||
/**
|
||||
* 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);
|
||||
|
||||
/**
|
||||
* Get Euler Angles from a rotation matrix
|
||||
* @param first Pointer to the storage for the first 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 order The Euler order (specifies axis order)
|
||||
* @param first Pointer to the storage for the first 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 order The Euler order (specifies axis order)
|
||||
*/
|
||||
void getEuler(Angle *first, Angle *second, Angle *third, EulerOrder order) const;
|
||||
};
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
*/
|
||||
|
||||
#include "math/vector2d.h"
|
||||
|
||||
#include "common/streamdebug.h"
|
||||
|
||||
namespace Math {
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
*/
|
||||
|
||||
#include "common/streamdebug.h"
|
||||
|
||||
#include "math/vector3d.h"
|
||||
|
||||
namespace Math {
|
||||
|
|
|
@ -50,48 +50,48 @@ public:
|
|||
|
||||
/**
|
||||
* Set the value of the vector using three floats
|
||||
* @param lx X Value
|
||||
* @param ly Y Value
|
||||
* @param lz Z Value
|
||||
* @param lx X Value
|
||||
* @param ly Y Value
|
||||
* @param lz Z Value
|
||||
*/
|
||||
void set(float lx, float ly, float lz);
|
||||
|
||||
/**
|
||||
* Get the angle of this vector around the unit circle
|
||||
* This operation ignores the z-component
|
||||
* @return The computed angle
|
||||
* @return The computed angle
|
||||
*/
|
||||
Angle unitCircleAngle() const;
|
||||
|
||||
/**
|
||||
* 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 {
|
||||
const float *d = m.getData();
|
||||
return Vector3d(x() * d[0] + y() * d[3] + z() * d[6],
|
||||
x() * d[1] + y() * d[4] + z() * d[7],
|
||||
x() * d[2] + y() * d[5] + z() * d[8]);
|
||||
x() * d[1] + y() * d[4] + z() * d[7],
|
||||
x() * d[2] + y() * d[5] + z() * d[8]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the cross product between two vectors
|
||||
* @param v1 The first vector
|
||||
* @param v2 The second vector
|
||||
* @return The resulting cross product
|
||||
* @param v1 The first vector
|
||||
* @param v2 The second vector
|
||||
* @return The resulting cross product
|
||||
*/
|
||||
inline static Vector3d crossProduct(const Vector3d& v1, const Vector3d& v2) {
|
||||
return Vector3d(v1.y() * v2.z() - v1.z() * v2.y(),
|
||||
v1.z() * v2.x() - v1.x() * v2.z(),
|
||||
v1.x() * v2.y() - v1.y() * v2.x());
|
||||
v1.z() * v2.x() - v1.x() * v2.z(),
|
||||
v1.x() * v2.y() - v1.y() * v2.x());
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the angle between two vectors
|
||||
* @param v1 The first vector
|
||||
* @param v2 The second vector
|
||||
* @return The computed angle
|
||||
* @param v1 The first vector
|
||||
* @param v2 The second vector
|
||||
* @return The computed angle
|
||||
*/
|
||||
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));
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
*/
|
||||
|
||||
#include "common/streamdebug.h"
|
||||
|
||||
#include "math/vector3d.h"
|
||||
#include "math/vector4d.h"
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue