ProtoTracer  1.0
Real-time 3D rendering and animation engine
Loading...
Searching...
No Matches
RotationMatrix.cpp
Go to the documentation of this file.
1#include "RotationMatrix.h"
2
4 if (didRotate) {
5 return Vector3D((XAxis.X + YAxis.X + ZAxis.X), (XAxis.Y + YAxis.Y + ZAxis.Y), (XAxis.Z + YAxis.Z + ZAxis.Z));
6 }
7 else {
8 return InitialVector;
9 }
10}
11
13 float X = (XAxis.X + YAxis.X + ZAxis.X);
14 float Y = (XAxis.Y + YAxis.Y + ZAxis.Y);
15 float Z = (XAxis.Z + YAxis.Z + ZAxis.Z);
16
17 XAxis = Vector3D(X, X, X);
18 YAxis = Vector3D(Y, Y, Y);
19 ZAxis = Vector3D(Z, Z, Z);
20}
21
23 if (rotation.X != 0) {
24 RotateX(rotation.X);
25 didRotate = true;
26
27 if (rotation.Y != 0 || rotation.Z != 0) {
29 }
30 }
31
32 if (rotation.Y != 0) {
33 RotateY(rotation.Y);
34 didRotate = true;
35
36 if (rotation.Z != 0) {
38 }
39 }
40
41 if (rotation.Z != 0) {
42 RotateZ(rotation.Z);
43 didRotate = true;
44 }
45
47}
48
59
70
81
85
87 XAxis = Vector3D(1.0f, 0.0f, 0.0f);
88 YAxis = Vector3D(0.0f, 1.0f, 0.0f);
89 ZAxis = Vector3D(0.0f, 0.0f, 1.0f);
90}
91
97
99 XAxis = X;
100 YAxis = Y;
101 ZAxis = Z;
102}
103
105 return RotationMatrix {
106 XAxis.Multiply(d),
107 YAxis.Multiply(d),
108 ZAxis.Multiply(d)
109 };
110}
111
119
123
124 return RotationMatrix {
126 vy.UnitSphere(),
127 vz.UnitSphere()
128 };
129}
130
138
151
153 return XAxis.IsEqual(rM.XAxis) && YAxis.IsEqual(rM.YAxis) && ZAxis.IsEqual(rM.ZAxis);
154}
155
157 return XAxis.X * (YAxis.Y * ZAxis.Z - ZAxis.Y * YAxis.Z) -
158 YAxis.X * (ZAxis.Z * XAxis.Y - ZAxis.Y * XAxis.Z) +
159 ZAxis.X * (XAxis.Y * YAxis.Z - YAxis.Y * XAxis.Z);
160}
161
163 //calculate rotation matrix
164 RotationMatrix matrix = RotationMatrix(coordinates);
165
166 matrix.Rotate(rotate);
167
168 if (rotate.X == 0 && rotate.Y == 0 && rotate.Z == 0) {
169 return coordinates;
170 }
171 else {
172 return matrix.ConvertCoordinateToVector();
173 }
174}
175
180
181 return x + "\n" + y + "\n" + z + "\n";
182}
183
185 this->XAxis = rM.XAxis;
186 this->YAxis = rM.YAxis;
187 this->ZAxis = rM.ZAxis;
188
189 return *this;
190}
Defines the RotationMatrix class for representing and manipulating 3D rotation matrices.
Implements a generic Kalman Filter for 1D data.
static T DegreesToRadians(T degrees)
Converts degrees to radians.
Represents a 3D rotation matrix and provides operations for rotation and matrix manipulation.
String ToString()
Converts the rotation matrix to a string representation.
RotationMatrix()
Default constructor. Initializes the matrix to the identity matrix.
Vector3D RotateZ(float theta)
Rotates the matrix around the Z-axis.
Vector3D YAxis
Y-axis vector of the rotation matrix.
bool IsEqual(RotationMatrix rM)
Checks if two rotation matrices are equal.
Vector3D InitialVector
Initial vector used for transformations.
RotationMatrix operator=(RotationMatrix rM)
Assignment operator for rotation matrices.
Vector3D Rotate(Vector3D rotation)
Rotates the matrix by a given rotation vector.
void ReadjustMatrix()
Recalculates and adjusts the rotation matrix axes to maintain orthogonality.
RotationMatrix Multiply(float d)
Multiplies the rotation matrix by a scalar.
float Determinant()
Computes the determinant of the rotation matrix.
Vector3D RotateY(float theta)
Rotates the matrix around the Y-axis.
Vector3D ConvertCoordinateToVector()
Converts the current coordinate system to a vector representation.
RotationMatrix Normalize()
Normalizes the rotation matrix to ensure orthogonality.
RotationMatrix Transpose()
Transposes the rotation matrix.
RotationMatrix Inverse()
Inverts the rotation matrix.
bool didRotate
Tracks whether the matrix has been rotated.
Vector3D XAxis
X-axis vector of the rotation matrix.
Vector3D ZAxis
Z-axis vector of the rotation matrix.
void RotateRelative(RotationMatrix rM)
Rotates this matrix relative to another rotation matrix.
static Vector3D RotateVector(Vector3D rotate, Vector3D coordinates)
Rotates a vector using the rotation matrix.
Vector3D RotateX(float theta)
Rotates the matrix around the X-axis.
Represents a 3D vector (X, Y, Z) and provides methods for vector arithmetic.
Definition Vector3D.h:26
Vector3D CrossProduct(const Vector3D &vector) const
Computes the cross product of this vector with another Vector3D.
Definition Vector3D.cpp:98
String ToString() const
Converts the vector to a string representation.
Definition Vector3D.cpp:189
float Z
The Z-component of the 3D vector.
Definition Vector3D.h:30
Vector3D UnitSphere() const
Normalizes this vector such that its magnitude is 1 (if non-zero).
Definition Vector3D.cpp:106
Vector3D Multiply(const Vector3D &vector) const
Multiplies this vector by another Vector3D component-wise.
Definition Vector3D.cpp:66
float X
The X-component of the 3D vector.
Definition Vector3D.h:28
float Y
The Y-component of the 3D vector.
Definition Vector3D.h:29
bool IsEqual(const Vector3D &vector) const
Checks if this vector is equal to another Vector3D component-wise.
Definition Vector3D.cpp:184