2020-12-11 16:56:27 -05:00
|
|
|
/*
|
|
|
|
Classes which define rotations about the x, y, and z axes. Using these,
|
|
|
|
any arbitrary orientation can be described. Methods implemented for vector multiplication
|
|
|
|
as well as generating the inverse of the rotation.
|
|
|
|
*/
|
|
|
|
#ifndef ROTATION_H
|
|
|
|
#define ROTATION_H
|
2020-12-09 17:07:58 -05:00
|
|
|
|
2020-12-11 16:56:27 -05:00
|
|
|
#include "Vec3.h"
|
2020-12-09 17:07:58 -05:00
|
|
|
|
2020-12-11 16:56:27 -05:00
|
|
|
namespace Mask {
|
|
|
|
|
|
|
|
class XRotation {
|
2020-12-09 17:07:58 -05:00
|
|
|
public:
|
2020-12-11 16:56:27 -05:00
|
|
|
XRotation();
|
|
|
|
XRotation(double ang);
|
|
|
|
~XRotation();
|
|
|
|
Vec3 Rotate(const Vec3& vector);
|
2020-12-09 17:07:58 -05:00
|
|
|
inline void SetAngle(double ang) { m_angle = ang; GenerateMatrix(); };
|
2020-12-11 16:56:27 -05:00
|
|
|
inline XRotation GetInverse() { return XRotation(-m_angle); };
|
|
|
|
inline Vec3 operator*(const Vec3& vector) {
|
2020-12-09 17:07:58 -05:00
|
|
|
double x = m_matrix[0][0]*vector[0] + m_matrix[0][1]*vector[1] + m_matrix[0][2]*vector[2];
|
|
|
|
double y = m_matrix[1][0]*vector[0] + m_matrix[1][1]*vector[1] + m_matrix[1][2]*vector[2];
|
|
|
|
double z = m_matrix[2][0]*vector[0] + m_matrix[2][1]*vector[1] + m_matrix[2][2]*vector[2];
|
2020-12-11 16:56:27 -05:00
|
|
|
return Vec3(x, y, z);
|
2020-12-09 17:07:58 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
private:
|
|
|
|
void GenerateMatrix();
|
|
|
|
double m_angle;
|
|
|
|
double m_matrix[3][3];
|
|
|
|
};
|
|
|
|
|
2020-12-11 16:56:27 -05:00
|
|
|
class YRotation {
|
2020-12-09 17:07:58 -05:00
|
|
|
public:
|
2020-12-11 16:56:27 -05:00
|
|
|
YRotation();
|
|
|
|
YRotation(double ang);
|
|
|
|
~YRotation();
|
|
|
|
Vec3 Rotate(const Vec3& vector);
|
2020-12-09 17:07:58 -05:00
|
|
|
inline void SetAngle(double ang) { m_angle = ang; GenerateMatrix(); };
|
2020-12-11 16:56:27 -05:00
|
|
|
inline YRotation GetInverse() { return YRotation(-m_angle); };
|
|
|
|
inline Vec3 operator*(const Vec3& vector) {
|
2020-12-09 17:07:58 -05:00
|
|
|
double x = m_matrix[0][0]*vector[0] + m_matrix[0][1]*vector[1] + m_matrix[0][2]*vector[2];
|
|
|
|
double y = m_matrix[1][0]*vector[0] + m_matrix[1][1]*vector[1] + m_matrix[1][2]*vector[2];
|
|
|
|
double z = m_matrix[2][0]*vector[0] + m_matrix[2][1]*vector[1] + m_matrix[2][2]*vector[2];
|
2020-12-11 16:56:27 -05:00
|
|
|
return Vec3(x, y, z);
|
2020-12-09 17:07:58 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
private:
|
|
|
|
void GenerateMatrix();
|
|
|
|
double m_angle;
|
|
|
|
double m_matrix[3][3];
|
|
|
|
};
|
|
|
|
|
2020-12-11 16:56:27 -05:00
|
|
|
class ZRotation {
|
2020-12-09 17:07:58 -05:00
|
|
|
public:
|
2020-12-11 16:56:27 -05:00
|
|
|
ZRotation();
|
|
|
|
ZRotation(double ang);
|
|
|
|
~ZRotation();
|
|
|
|
Vec3 Rotate(const Vec3& vector);
|
2020-12-09 17:07:58 -05:00
|
|
|
inline void SetAngle(double ang) { m_angle = ang; GenerateMatrix();};
|
2020-12-11 16:56:27 -05:00
|
|
|
inline ZRotation GetInverse() { return ZRotation(-m_angle); };
|
|
|
|
inline Vec3 operator*(const Vec3& vector) {
|
2020-12-09 17:07:58 -05:00
|
|
|
double x = m_matrix[0][0]*vector[0] + m_matrix[0][1]*vector[1] + m_matrix[0][2]*vector[2];
|
|
|
|
double y = m_matrix[1][0]*vector[0] + m_matrix[1][1]*vector[1] + m_matrix[1][2]*vector[2];
|
|
|
|
double z = m_matrix[2][0]*vector[0] + m_matrix[2][1]*vector[1] + m_matrix[2][2]*vector[2];
|
2020-12-11 16:56:27 -05:00
|
|
|
return Vec3(x, y, z);
|
2020-12-09 17:07:58 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
private:
|
|
|
|
void GenerateMatrix();
|
|
|
|
double m_angle;
|
|
|
|
double m_matrix[3][3];
|
|
|
|
};
|
|
|
|
|
2020-12-11 16:56:27 -05:00
|
|
|
};
|
|
|
|
|
2020-12-09 17:07:58 -05:00
|
|
|
#endif
|