Minor improvements
This commit is contained in:
parent
95a6fb3a4b
commit
8286c1ca85
15
Angle.cpp
15
Angle.cpp
@ -76,9 +76,8 @@ AngleOf<signed short> AngleOf<signed short>::Degrees(float angle) {
|
|||||||
|
|
||||||
template <>
|
template <>
|
||||||
AngleOf<signed short> AngleOf<signed short>::Radians(float angle) {
|
AngleOf<signed short> AngleOf<signed short>::Radians(float angle) {
|
||||||
if (!isfinite(angle)) {
|
if (!isfinite(angle))
|
||||||
return AngleOf<signed short>(0);
|
return AngleOf<signed short>(0);
|
||||||
}
|
|
||||||
|
|
||||||
// map float [-PI..PI) to integer [-32768..32767]
|
// map float [-PI..PI) to integer [-32768..32767]
|
||||||
signed short value = (signed short)(angle / pi * 32768.0F);
|
signed short value = (signed short)(angle / pi * 32768.0F);
|
||||||
@ -130,6 +129,13 @@ float AngleOf<signed char>::InRadians() const {
|
|||||||
|
|
||||||
//===== Generic
|
//===== Generic
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
const AngleOf<T> AngleOf<T>::zero = AngleOf<T>();
|
||||||
|
template <typename T>
|
||||||
|
const AngleOf<T> AngleOf<T>::deg90 = AngleOf<T>::Degrees(90);
|
||||||
|
template <typename T>
|
||||||
|
const AngleOf<T> AngleOf<T>::deg180 = AngleOf<T>::Degrees(180);
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
bool AngleOf<T>::operator==(const AngleOf<T> a) const {
|
bool AngleOf<T>::operator==(const AngleOf<T> a) const {
|
||||||
return this->value == a.value;
|
return this->value == a.value;
|
||||||
@ -267,6 +273,11 @@ AngleOf<T> AngleOf<T>::Atan(float f) {
|
|||||||
return AngleOf<T>::Radians(atanf(f));
|
return AngleOf<T>::Radians(atanf(f));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
AngleOf<T> Passer::LinearAlgebra::AngleOf<T>::Atan2(float f1, float f2) {
|
||||||
|
return AngleOf<T>::Radians(atan2f(f1, f2));
|
||||||
|
}
|
||||||
|
|
||||||
// template <>
|
// template <>
|
||||||
// float AngleOf<float>::CosineRuleSide(float a, float b, AngleOf<float> gamma)
|
// float AngleOf<float>::CosineRuleSide(float a, float b, AngleOf<float> gamma)
|
||||||
// {
|
// {
|
||||||
|
5
Angle.h
5
Angle.h
@ -21,6 +21,10 @@ class AngleOf {
|
|||||||
static AngleOf<T> Degrees(float f);
|
static AngleOf<T> Degrees(float f);
|
||||||
static AngleOf<T> Radians(float f);
|
static AngleOf<T> Radians(float f);
|
||||||
|
|
||||||
|
const static AngleOf<T> zero;
|
||||||
|
const static AngleOf<T> deg90;
|
||||||
|
const static AngleOf<T> deg180;
|
||||||
|
|
||||||
float InDegrees() const;
|
float InDegrees() const;
|
||||||
float InRadians() const;
|
float InRadians() const;
|
||||||
|
|
||||||
@ -64,6 +68,7 @@ class AngleOf {
|
|||||||
static AngleOf<T> Acos(float f);
|
static AngleOf<T> Acos(float f);
|
||||||
static AngleOf<T> Asin(float f);
|
static AngleOf<T> Asin(float f);
|
||||||
static AngleOf<T> Atan(float f);
|
static AngleOf<T> Atan(float f);
|
||||||
|
static AngleOf<T> Atan2(float f1, float f2);
|
||||||
|
|
||||||
static float CosineRuleSide(float a, float b, AngleOf<T> gamma);
|
static float CosineRuleSide(float a, float b, AngleOf<T> gamma);
|
||||||
static AngleOf<T> CosineRuleAngle(float a, float b, float c);
|
static AngleOf<T> CosineRuleAngle(float a, float b, float c);
|
||||||
|
@ -24,8 +24,13 @@ DirectionOf<T>::DirectionOf(AngleOf<T> horizontal, AngleOf<T> vertical) {
|
|||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
DirectionOf<T>::DirectionOf(Vector3 v) {
|
DirectionOf<T>::DirectionOf(Vector3 v) {
|
||||||
this->horizontal = AngleOf<T>::Radians(atan2f(v.Right(), v.Forward()));
|
this->horizontal = AngleOf<T>::Atan2(
|
||||||
this->vertical = AngleOf<T>::Radians(-(0.5f * pi) - acosf(v.Up()));
|
v.Right(),
|
||||||
|
v.Forward()); // AngleOf<T>::Radians(atan2f(v.Right(), v.Forward()));
|
||||||
|
this->vertical =
|
||||||
|
-AngleOf<T>::deg90 -
|
||||||
|
AngleOf<T>::Acos(
|
||||||
|
v.Up()); // AngleOf<T>::Radians(-(0.5f * pi) - acosf(v.Up()));
|
||||||
Normalize();
|
Normalize();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -34,19 +39,19 @@ const DirectionOf<T> DirectionOf<T>::forward =
|
|||||||
DirectionOf<T>(AngleOf<T>(), AngleOf<T>());
|
DirectionOf<T>(AngleOf<T>(), AngleOf<T>());
|
||||||
template <typename T>
|
template <typename T>
|
||||||
const DirectionOf<T> DirectionOf<T>::back =
|
const DirectionOf<T> DirectionOf<T>::back =
|
||||||
DirectionOf<T>(AngleOf<T>::Degrees(180), AngleOf<T>());
|
DirectionOf<T>(AngleOf<T>::deg180, AngleOf<T>());
|
||||||
template <typename T>
|
template <typename T>
|
||||||
const DirectionOf<T> DirectionOf<T>::up =
|
const DirectionOf<T> DirectionOf<T>::up =
|
||||||
DirectionOf<T>(AngleOf<T>(), AngleOf<T>::Degrees(90));
|
DirectionOf<T>(AngleOf<T>(), AngleOf<T>::deg90);
|
||||||
template <typename T>
|
template <typename T>
|
||||||
const DirectionOf<T> DirectionOf<T>::down =
|
const DirectionOf<T> DirectionOf<T>::down =
|
||||||
DirectionOf<T>(AngleOf<T>(), AngleOf<T>::Degrees(-90));
|
DirectionOf<T>(AngleOf<T>(), -AngleOf<T>::deg90);
|
||||||
template <typename T>
|
template <typename T>
|
||||||
const DirectionOf<T> DirectionOf<T>::left =
|
const DirectionOf<T> DirectionOf<T>::left =
|
||||||
DirectionOf<T>(AngleOf<T>::Degrees(-90), AngleOf<T>());
|
DirectionOf<T>(-AngleOf<T>::deg90, AngleOf<T>());
|
||||||
template <typename T>
|
template <typename T>
|
||||||
const DirectionOf<T> DirectionOf<T>::right =
|
const DirectionOf<T> DirectionOf<T>::right =
|
||||||
DirectionOf<T>(AngleOf<T>::Degrees(90), AngleOf<T>());
|
DirectionOf<T>(AngleOf<T>::deg90, AngleOf<T>());
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
DirectionOf<T> Passer::LinearAlgebra::DirectionOf<T>::Degrees(float horizontal,
|
DirectionOf<T> Passer::LinearAlgebra::DirectionOf<T>::Degrees(float horizontal,
|
||||||
@ -70,14 +75,14 @@ bool Passer::LinearAlgebra::DirectionOf<T>::operator==(
|
|||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
DirectionOf<T> Passer::LinearAlgebra::DirectionOf<T>::operator-() const {
|
DirectionOf<T> Passer::LinearAlgebra::DirectionOf<T>::operator-() const {
|
||||||
DirectionOf<T> r = DirectionOf<T>(this->horizontal + AngleOf<T>::Degrees(180),
|
DirectionOf<T> r =
|
||||||
-this->vertical);
|
DirectionOf<T>(this->horizontal + AngleOf<T>::deg180, -this->vertical);
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
Vector3 DirectionOf<T>::ToVector3() {
|
Vector3 DirectionOf<T>::ToVector3() {
|
||||||
Vector3 v = Quaternion::Euler(-(this->vertical.InDegrees()),
|
Vector3 v = Quaternion::Euler(-this->vertical.InDegrees(),
|
||||||
this->horizontal.InDegrees(), 0) *
|
this->horizontal.InDegrees(), 0) *
|
||||||
Vector3::forward;
|
Vector3::forward;
|
||||||
return v;
|
return v;
|
||||||
@ -85,10 +90,10 @@ Vector3 DirectionOf<T>::ToVector3() {
|
|||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
void DirectionOf<T>::Normalize() {
|
void DirectionOf<T>::Normalize() {
|
||||||
if (this->vertical > AngleOf<T>::Degrees(90) ||
|
if (this->vertical > AngleOf<T>::deg90 ||
|
||||||
this->vertical < AngleOf<T>::Degrees(-90)) {
|
this->vertical < -AngleOf<T>::deg90) {
|
||||||
this->horizontal += AngleOf<T>::Degrees(180);
|
this->horizontal += AngleOf<T>::deg180;
|
||||||
this->vertical = AngleOf<T>::Degrees(180) - this->vertical;
|
this->vertical = AngleOf<T>::deg180 - this->vertical;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,8 +31,7 @@ template <typename T>
|
|||||||
SwingTwistOf<T> SwingTwistOf<T>::Degrees(float horizontal,
|
SwingTwistOf<T> SwingTwistOf<T>::Degrees(float horizontal,
|
||||||
float vertical,
|
float vertical,
|
||||||
float twist) {
|
float twist) {
|
||||||
DirectionOf<T> swing = DirectionOf<T>(AngleOf<T>::Degrees(horizontal),
|
DirectionOf<T> swing = DirectionOf<T>::Degrees(horizontal, vertical);
|
||||||
AngleOf<T>::Degrees(vertical));
|
|
||||||
AngleOf<T> twistAngle = AngleOf<T>::Degrees(twist);
|
AngleOf<T> twistAngle = AngleOf<T>::Degrees(twist);
|
||||||
SwingTwistOf<T> orientation = SwingTwistOf(swing, twistAngle);
|
SwingTwistOf<T> orientation = SwingTwistOf(swing, twistAngle);
|
||||||
return orientation;
|
return orientation;
|
||||||
@ -50,9 +49,8 @@ template <typename T>
|
|||||||
SwingTwistOf<T> Passer::LinearAlgebra::SwingTwistOf<T>::FromQuaternion(
|
SwingTwistOf<T> Passer::LinearAlgebra::SwingTwistOf<T>::FromQuaternion(
|
||||||
Quaternion q) {
|
Quaternion q) {
|
||||||
Vector3 angles = Quaternion::ToAngles(q);
|
Vector3 angles = Quaternion::ToAngles(q);
|
||||||
SwingTwistOf<T> r = SwingTwistOf<T>(AngleOf<T>::Degrees(angles.Up()),
|
SwingTwistOf<T> r =
|
||||||
AngleOf<T>::Degrees(angles.Right()),
|
SwingTwistOf<T>::Degrees(angles.Up(), angles.Right(), angles.Forward());
|
||||||
AngleOf<T>::Degrees(angles.Forward()));
|
|
||||||
|
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user