Extended AngleAxis & Direction
This commit is contained in:
parent
09e25a8a21
commit
3363388a95
@ -5,44 +5,47 @@
|
||||
#include "AngleAxis.h"
|
||||
|
||||
template <typename T>
|
||||
AngleAxis<T>::AngleAxis() {
|
||||
this->angle = AngleOf<T>();
|
||||
this->axis = Direction<T>();
|
||||
AngleAxisOf<T>::AngleAxisOf() {
|
||||
this->angle = 0.0F;
|
||||
this->axis = DirectionOf<T>();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
AngleAxis<T>::AngleAxis(AngleOf<T> angle, Direction<T> axis) {
|
||||
AngleAxisOf<T>::AngleAxisOf(float angle, DirectionOf<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);
|
||||
AngleAxisOf<T>::AngleAxisOf(float angle, Vector3 axis) {
|
||||
this->angle = angle;
|
||||
this->axis = DirectionOf<T>(axis);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
AngleAxis<T>::AngleAxis(Quaternion q) {
|
||||
AngleAxisOf<T>::AngleAxisOf(Quaternion q) {
|
||||
float angle;
|
||||
Vector3 axis;
|
||||
q.ToAngleAxis(&angle, &axis);
|
||||
this->angle = AngleOf<T>(angle);
|
||||
this->axis = Direction<T>(axis);
|
||||
this->angle = angle;
|
||||
this->axis = DirectionOf<T>(axis);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
Quaternion AngleAxis<T>::ToQuaternion() {
|
||||
const AngleAxisOf<T> AngleAxisOf<T>::zero =
|
||||
AngleAxisOf<T>(0.0, DirectionOf<T>(0, 0));
|
||||
|
||||
template <typename T>
|
||||
Quaternion AngleAxisOf<T>::ToQuaternion() {
|
||||
Vector3 axisVector = this->axis.ToVector3();
|
||||
float angleFloat = this->angle.ToFloat();
|
||||
Quaternion q = Quaternion::AngleAxis(angleFloat, axisVector);
|
||||
Quaternion q = Quaternion::AngleAxis(this->angle, axisVector);
|
||||
return q;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
Direction<T> AngleAxis<T>::GetSwing() {
|
||||
DirectionOf<T> AngleAxisOf<T>::GetSwing() {
|
||||
return this->axis;
|
||||
}
|
||||
|
||||
template class AngleAxis<float>;
|
||||
template class AngleAxis<signed short>;
|
||||
template class AngleAxisOf<float>;
|
||||
template class AngleAxisOf<signed short>;
|
||||
|
28
AngleAxis.h
28
AngleAxis.h
@ -12,22 +12,30 @@
|
||||
namespace Passer {
|
||||
namespace LinearAlgebra {
|
||||
|
||||
template <typename T>
|
||||
class AngleAxis {
|
||||
public:
|
||||
AngleOf<T> angle;
|
||||
Direction<T> axis;
|
||||
// Isn't this the same as SphericalOf<T> ?????????????
|
||||
|
||||
AngleAxis();
|
||||
AngleAxis(AngleOf<T> angle, Direction<T> axis);
|
||||
AngleAxis(Quaternion q);
|
||||
AngleAxis(float angle, Vector3 axis);
|
||||
template <typename T>
|
||||
class AngleAxisOf {
|
||||
public:
|
||||
float angle;
|
||||
DirectionOf<T> axis;
|
||||
|
||||
AngleAxisOf();
|
||||
AngleAxisOf(float angle, DirectionOf<T> axis);
|
||||
AngleAxisOf(Quaternion q);
|
||||
AngleAxisOf(float angle, Vector3 axis);
|
||||
|
||||
const static AngleAxisOf<T> zero;
|
||||
|
||||
Quaternion ToQuaternion();
|
||||
|
||||
Direction<T> GetSwing();
|
||||
DirectionOf<T> GetSwing();
|
||||
};
|
||||
|
||||
using AngleAxisSingle = AngleAxisOf<float>;
|
||||
using AngleAxis16 = AngleAxisOf<signed short>;
|
||||
using AngleAxis = AngleAxisOf<float>;
|
||||
|
||||
} // namespace LinearAlgebra
|
||||
} // namespace Passer
|
||||
using namespace Passer::LinearAlgebra;
|
||||
|
@ -10,45 +10,61 @@
|
||||
#include <math.h>
|
||||
|
||||
template <typename T>
|
||||
Direction<T>::Direction() {
|
||||
this->horizontalAngle = AngleOf<T>(0.0f);
|
||||
this->verticalAngle = AngleOf<T>(0.0f);
|
||||
DirectionOf<T>::DirectionOf() {
|
||||
this->horizontal = AngleOf<T>(0.0f);
|
||||
this->vertical = AngleOf<T>(0.0f);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
Direction<T>::Direction(AngleOf<T> horizontal, AngleOf<T> vertical) {
|
||||
this->horizontalAngle = horizontal;
|
||||
this->verticalAngle = vertical;
|
||||
DirectionOf<T>::DirectionOf(AngleOf<T> horizontal, AngleOf<T> vertical) {
|
||||
this->horizontal = horizontal;
|
||||
this->vertical = vertical;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
Direction<T>::Direction(Vector3 v) {
|
||||
this->horizontalAngle =
|
||||
DirectionOf<T>::DirectionOf(Vector3 v) {
|
||||
this->horizontal =
|
||||
atan2f(v.Right(), v.Forward()) * Passer::LinearAlgebra::Rad2Deg;
|
||||
this->verticalAngle = 90 - acosf(v.Up()) * Passer::LinearAlgebra::Rad2Deg;
|
||||
this->vertical = 90 - acosf(v.Up()) * Passer::LinearAlgebra::Rad2Deg;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
const Direction<T> Direction<T>::forward = Direction<T>(0.0f, 0.0f);
|
||||
const DirectionOf<T> DirectionOf<T>::forward = DirectionOf<T>(0.0f, 0.0f);
|
||||
template <typename T>
|
||||
const Direction<T> Direction<T>::back = Direction<T>(180.0f, 0.0f);
|
||||
const DirectionOf<T> DirectionOf<T>::back = DirectionOf<T>(180.0f, 0.0f);
|
||||
template <typename T>
|
||||
const Direction<T> Direction<T>::up = Direction<T>(0.0f, 90.0f);
|
||||
const DirectionOf<T> DirectionOf<T>::up = DirectionOf<T>(0.0f, 90.0f);
|
||||
template <typename T>
|
||||
const Direction<T> Direction<T>::down = Direction<T>(0.0f, -90.0f);
|
||||
const DirectionOf<T> DirectionOf<T>::down = DirectionOf<T>(0.0f, -90.0f);
|
||||
template <typename T>
|
||||
const Direction<T> Direction<T>::left = Direction<T>(-90.0f, 0.0f);
|
||||
const DirectionOf<T> DirectionOf<T>::left = DirectionOf<T>(-90.0f, 0.0f);
|
||||
template <typename T>
|
||||
const Direction<T> Direction<T>::right = Direction<T>(90.0f, 0.0f);
|
||||
const DirectionOf<T> DirectionOf<T>::right = DirectionOf<T>(90.0f, 0.0f);
|
||||
|
||||
template <typename T>
|
||||
Vector3 Direction<T>::ToVector3() {
|
||||
Vector3 v = Quaternion::Euler(-(this->verticalAngle.ToFloat()),
|
||||
this->horizontalAngle.ToFloat(), 0) *
|
||||
DirectionOf<T> Passer::LinearAlgebra::DirectionOf<T>::operator+(
|
||||
const DirectionOf<T>& v) const {
|
||||
DirectionOf<T> r = DirectionOf<T>(this->horizontal + v.horizontal,
|
||||
this->vertical + v.vertical);
|
||||
return r;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
DirectionOf<T> Passer::LinearAlgebra::DirectionOf<T>::operator+=(
|
||||
const DirectionOf<T>& v) {
|
||||
this->horizontal += v.horizontal;
|
||||
this->vertical += v.vertical;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
Vector3 DirectionOf<T>::ToVector3() {
|
||||
Vector3 v = Quaternion::Euler(-(this->vertical.InDegrees()),
|
||||
this->horizontal.InDegrees(), 0) *
|
||||
Vector3::forward;
|
||||
return v;
|
||||
}
|
||||
|
||||
template class Direction<float>;
|
||||
template class Direction<signed short>;
|
||||
template class Direction<signed char>;
|
||||
template class DirectionOf<float>;
|
||||
template class DirectionOf<signed short>;
|
||||
template class DirectionOf<signed char>;
|
31
Direction.h
31
Direction.h
@ -13,25 +13,32 @@ namespace LinearAlgebra {
|
||||
struct Vector3;
|
||||
|
||||
template <typename T>
|
||||
class Direction {
|
||||
class DirectionOf {
|
||||
public:
|
||||
AngleOf<T> horizontalAngle;
|
||||
AngleOf<T> verticalAngle;
|
||||
AngleOf<T> horizontal;
|
||||
AngleOf<T> vertical;
|
||||
|
||||
Direction();
|
||||
Direction(AngleOf<T> horizontal, AngleOf<T> vertical);
|
||||
Direction(Vector3 v);
|
||||
DirectionOf<T>();
|
||||
DirectionOf<T>(AngleOf<T> horizontal, AngleOf<T> vertical);
|
||||
DirectionOf<T>(Vector3 v);
|
||||
|
||||
const static Direction forward;
|
||||
const static Direction back;
|
||||
const static Direction up;
|
||||
const static Direction down;
|
||||
const static Direction left;
|
||||
const static Direction right;
|
||||
const static DirectionOf forward;
|
||||
const static DirectionOf back;
|
||||
const static DirectionOf up;
|
||||
const static DirectionOf down;
|
||||
const static DirectionOf left;
|
||||
const static DirectionOf right;
|
||||
|
||||
DirectionOf<T> operator+(const DirectionOf<T>& v) const;
|
||||
DirectionOf<T> operator+=(const DirectionOf<T>& v);
|
||||
|
||||
Vector3 ToVector3();
|
||||
};
|
||||
|
||||
using DirectionSingle = DirectionOf<float>;
|
||||
using Direction16 = DirectionOf<signed short>;
|
||||
using Direction = DirectionOf<float>;
|
||||
|
||||
} // namespace LinearAlgebra
|
||||
} // namespace Passer
|
||||
using namespace Passer::LinearAlgebra;
|
||||
|
Loading…
x
Reference in New Issue
Block a user