Fix generic template functions

This commit is contained in:
Pascal Serrarens 2024-08-06 09:47:48 +02:00
parent 1ce7234d71
commit ea6894e05b
4 changed files with 120 additions and 33 deletions

View File

@ -4,14 +4,33 @@
#include "AngleAxis.h" #include "AngleAxis.h"
template <typename T> // template <typename T>
AngleAxis<T>::AngleAxis() { // AngleAxis<T>::AngleAxis() {
this->angle = Angle(); // this->angle = Angle();
this->axis = Direction<T>(); // this->axis = Direction<T>();
} // }
template <typename T> // template <typename T>
AngleAxis<T>::AngleAxis(AngleOf<T> angle, Direction<T> axis) { // AngleAxis<T>::AngleAxis(AngleOf<T> angle, Direction<T> axis) {
this->angle = angle; // this->angle = angle;
this->axis = axis; // this->axis = axis;
} // }
// template <typename T>
// AngleAxis<T>::AngleAxis(float angle, Vector3 axis) {
// this->angle = AngleOf<T>(angle);
// this->axis = Direction<T>(axis);
// }
// template <typename T>
// Quaternion AngleAxis<T>::ToQuaternion() {
// Vector3 axisVector = this->axis.ToVector3();
// float angleFloat = this->angle.ToFloat();
// Quaternion q = Quaternion::AngleAxis(angleFloat, axisVector);
// return q;
// }
// template <typename T>
// Direction<T> AngleAxis<T>::GetSwing() {
// return this->axis;
// }

View File

@ -7,6 +7,7 @@
#include "Angle.h" #include "Angle.h"
#include "Direction.h" #include "Direction.h"
#include "Quaternion.h"
namespace Passer { namespace Passer {
namespace LinearAlgebra { namespace LinearAlgebra {
@ -19,10 +20,46 @@ class AngleAxis {
AngleAxis(); AngleAxis();
AngleAxis(AngleOf<T> angle, Direction<T> axis); AngleAxis(AngleOf<T> angle, Direction<T> axis);
AngleAxis(float angle, Vector3 axis);
Quaternion ToQuaternion();
Direction<T> GetSwing();
}; };
template <typename T>
Quaternion AngleAxis<T>::ToQuaternion() {
Vector3 axisVector = this->axis.ToVector3();
float angleFloat = this->angle.ToFloat();
Quaternion q = Quaternion::AngleAxis(angleFloat, axisVector);
return q;
}
} // namespace LinearAlgebra } // namespace LinearAlgebra
} // namespace Passer } // namespace Passer
using namespace Passer::LinearAlgebra; using namespace Passer::LinearAlgebra;
template <typename T>
AngleAxis<T>::AngleAxis() {
this->angle = Angle();
this->axis = Direction<T>();
}
template <typename T>
AngleAxis<T>::AngleAxis(AngleOf<T> angle, Direction<T> axis) {
this->angle = angle;
this->axis = axis;
}
template <typename T>
AngleAxis<T>::AngleAxis(float angle, Vector3 axis) {
this->angle = AngleOf<T>(angle);
this->axis = Direction<T>(axis);
}
template <typename T>
Direction<T> AngleAxis<T>::GetSwing() {
return this->axis;
}
#endif #endif

View File

@ -9,24 +9,24 @@
#include <math.h> #include <math.h>
template <typename T> // template <typename T>
Direction<T>::Direction() { // Direction<T>::Direction() {
this->horizontalAngle = AngleOf<T>(0.0f); // this->horizontalAngle = AngleOf<T>(0.0f);
this->verticalAngle = AngleOf<T>(0.0f); // this->verticalAngle = AngleOf<T>(0.0f);
} // }
template <typename T> // template <typename T>
Direction<T>::Direction(AngleOf<T> horizontal, AngleOf<T> vertical) { // Direction<T>::Direction(AngleOf<T> horizontal, AngleOf<T> vertical) {
this->horizontalAngle = horizontal; // this->horizontalAngle = horizontal;
this->verticalAngle = vertical; // this->verticalAngle = vertical;
}; // };
template <typename T> // template <typename T>
Direction<T>::Direction(Vector3 v) { // Direction<T>::Direction(Vector3 v) {
this->horizontalAngle = // this->horizontalAngle =
atan2f(v.Right(), v.Forward()) * Passer::LinearAlgebra::Rad2Deg; // atan2f(v.Right(), v.Forward()) * Passer::LinearAlgebra::Rad2Deg;
this->verticalAngle = 90 - acosf(v.Up()) * Passer::LinearAlgebra::Rad2Deg; // this->verticalAngle = 90 - acosf(v.Up()) * Passer::LinearAlgebra::Rad2Deg;
} // }
template <typename T> template <typename T>
const Direction<T> Direction<T>::forward = Direction<T>(0.0f, 0.0f); const Direction<T> Direction<T>::forward = Direction<T>(0.0f, 0.0f);
@ -41,10 +41,10 @@ const Direction<T> Direction<T>::left = Direction<T>(-90.0f, 0.0f);
template <typename T> template <typename T>
const Direction<T> Direction<T>::right = Direction<T>(90.0f, 0.0f); const Direction<T> Direction<T>::right = Direction<T>(90.0f, 0.0f);
template <typename T> // template <typename T>
Vector3 Direction<T>::ToVector3() { // Vector3 Direction<T>::ToVector3() {
Vector3 v = Quaternion::Euler(-(this->verticalAngle.ToFloat()), // Vector3 v = Quaternion::Euler(-(this->verticalAngle.ToFloat()),
this->horizontalAngle.ToFloat(), 0) * // this->horizontalAngle.ToFloat(), 0) *
Vector3::forward; // Vector3::forward;
return v; // return v;
} // }

View File

@ -36,4 +36,35 @@ class Direction {
} // namespace Passer } // namespace Passer
using namespace Passer::LinearAlgebra; using namespace Passer::LinearAlgebra;
#include <math.h>
#include "Quaternion.h"
#include "Vector3.h"
template <typename T>
Direction<T>::Direction() {
this->horizontalAngle = AngleOf<T>(0.0f);
this->verticalAngle = AngleOf<T>(0.0f);
}
template <typename T>
Direction<T>::Direction(AngleOf<T> horizontal, AngleOf<T> vertical) {
this->horizontalAngle = horizontal;
this->verticalAngle = vertical;
};
template <typename T>
Direction<T>::Direction(Vector3 v) {
this->horizontalAngle =
atan2f(v.Right(), v.Forward()) * Passer::LinearAlgebra::Rad2Deg;
this->verticalAngle = 90 - acosf(v.Up()) * Passer::LinearAlgebra::Rad2Deg;
}
template <typename T>
Vector3 Direction<T>::ToVector3() {
Vector3 v = Quaternion::Euler(-(this->verticalAngle.ToFloat()),
this->horizontalAngle.ToFloat(), 0) *
Vector3::forward;
return v;
}
#endif #endif