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
50 float c = cosf(Mathematics::DegreesToRadians(theta));
51 float s = sinf(Mathematics::DegreesToRadians(theta));
52
53 XAxis = Vector3D(1, 0, 0).Multiply(XAxis);
54 YAxis = Vector3D(0, c, -s).Multiply(YAxis);
55 ZAxis = Vector3D(0, s, c).Multiply(ZAxis);
56
58}
59
61 float c = cosf(Mathematics::DegreesToRadians(theta));
62 float s = sinf(Mathematics::DegreesToRadians(theta));
63
64 XAxis = Vector3D( c, 0, s).Multiply(XAxis);
65 YAxis = Vector3D( 0, 1, 0).Multiply(YAxis);
66 ZAxis = Vector3D(-s, 0, c).Multiply(ZAxis);
67
69}
70
72 float c = cosf(Mathematics::DegreesToRadians(theta));
73 float s = sinf(Mathematics::DegreesToRadians(theta));
74
75 XAxis = Vector3D(c, -s, 0).Multiply(XAxis);
76 YAxis = Vector3D(s, c, 0).Multiply(YAxis);
77 ZAxis = Vector3D(0, 0, 1).Multiply(ZAxis);
78
80}
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
93 XAxis = Vector3D(axes.X, axes.X, axes.X);
94 YAxis = Vector3D(axes.Y, axes.Y, axes.Y);
95 ZAxis = Vector3D(axes.Z, axes.Z, axes.Z);
96}
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
113 return RotationMatrix {
114 XAxis.Multiply(rM.XAxis),
115 YAxis.Multiply(rM.YAxis),
116 ZAxis.Multiply(rM.ZAxis)
117 };
118}
119
123
124 return RotationMatrix {
125 XAxis.UnitSphere(),
126 vy.UnitSphere(),
127 vz.UnitSphere()
128 };
129}
130
132 XAxis = Vector3D(XAxis.X, YAxis.X, ZAxis.X);
133 YAxis = Vector3D(XAxis.Y, YAxis.Y, ZAxis.Y);
134 ZAxis = Vector3D(XAxis.Z, YAxis.Z, ZAxis.Z);
135
136 return *this;
137}
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
177 String x = XAxis.ToString();
178 String y = YAxis.ToString();
179 String z = ZAxis.ToString();
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.
static T DegreesToRadians(T degrees)
Converts degrees to radians.
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
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