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