Normalize Spherical at creation
This commit is contained in:
parent
800eb75e28
commit
28ee2254b8
@ -5,54 +5,33 @@
|
|||||||
|
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
template <typename T>
|
template <typename T> SphericalOf<T>::SphericalOf() {
|
||||||
SphericalOf<T>::SphericalOf() {
|
|
||||||
this->distance = 0.0f;
|
this->distance = 0.0f;
|
||||||
this->direction = DirectionOf<T>();
|
this->direction = DirectionOf<T>();
|
||||||
// this->horizontal = AngleOf<T>();
|
|
||||||
// this->vertical = AngleOf<T>();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// template <>
|
|
||||||
// SphericalOf<signed short>::SphericalOf() {
|
|
||||||
// this->distance = 0.0f;
|
|
||||||
// this->horizontal = AngleOf<signed short>(0);
|
|
||||||
// this->vertical = AngleOf<signed short>(0);
|
|
||||||
// }
|
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
SphericalOf<T>::SphericalOf(float distance,
|
SphericalOf<T>::SphericalOf(float distance, AngleOf<T> horizontal,
|
||||||
AngleOf<T> horizontal,
|
|
||||||
AngleOf<T> vertical) {
|
AngleOf<T> vertical) {
|
||||||
|
if (distance < 0) {
|
||||||
this->distance = distance;
|
this->distance = distance;
|
||||||
this->direction = DirectionOf<T>(horizontal, vertical);
|
this->direction = DirectionOf<T>(horizontal, vertical);
|
||||||
// this->horizontal = horizontal;
|
} else {
|
||||||
// this->vertical = vertical;
|
this->distance = -distance;
|
||||||
|
this->direction = -DirectionOf<T>(horizontal, vertical);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
SphericalOf<T>::SphericalOf(float distance, DirectionOf<T> direction) {
|
SphericalOf<T>::SphericalOf(float distance, DirectionOf<T> direction) {
|
||||||
|
if (distance < 0) {
|
||||||
|
this->distance = -distance;
|
||||||
|
this->direction = -direction;
|
||||||
|
} else {
|
||||||
this->distance = distance;
|
this->distance = distance;
|
||||||
this->direction = direction;
|
this->direction = direction;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// template <>
|
|
||||||
// SphericalOf<float>::SphericalOf(float distance,
|
|
||||||
// AngleOf<float> horizontal,
|
|
||||||
// AngleOf<float> vertical) {
|
|
||||||
// this->distance = distance;
|
|
||||||
// this->horizontal = horizontal;
|
|
||||||
// this->vertical = vertical;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// template <>
|
|
||||||
// SphericalOf<signed short>::SphericalOf(float distance,
|
|
||||||
// AngleOf<signed short> horizontal,
|
|
||||||
// AngleOf<signed short> vertical) {
|
|
||||||
// this->distance = distance;
|
|
||||||
// this->horizontal = horizontal;
|
|
||||||
// this->vertical = vertical;
|
|
||||||
// }
|
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
SphericalOf<T> SphericalOf<T>::FromPolar(PolarOf<T> polar) {
|
SphericalOf<T> SphericalOf<T>::FromPolar(PolarOf<T> polar) {
|
||||||
@ -62,8 +41,7 @@ SphericalOf<T> SphericalOf<T>::FromPolar(PolarOf<T> polar) {
|
|||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T> SphericalOf<T> SphericalOf<T>::FromVector3(Vector3 v) {
|
||||||
SphericalOf<T> SphericalOf<T>::FromVector3(Vector3 v) {
|
|
||||||
float distance = v.magnitude();
|
float distance = v.magnitude();
|
||||||
if (distance == 0.0f) {
|
if (distance == 0.0f) {
|
||||||
return SphericalOf(distance, AngleOf<T>(), AngleOf<T>());
|
return SphericalOf(distance, AngleOf<T>(), AngleOf<T>());
|
||||||
@ -76,8 +54,7 @@ SphericalOf<T> SphericalOf<T>::FromVector3(Vector3 v) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T> Vector3 SphericalOf<T>::ToVector3() const {
|
||||||
Vector3 SphericalOf<T>::ToVector3() const {
|
|
||||||
float verticalRad = (pi / 2) - this->direction.vertical.InRadians();
|
float verticalRad = (pi / 2) - this->direction.vertical.InRadians();
|
||||||
float horizontalRad = this->direction.horizontal.InRadians();
|
float horizontalRad = this->direction.horizontal.InRadians();
|
||||||
|
|
||||||
@ -122,8 +99,7 @@ SphericalOf<T> SphericalOf<T>::WithDistance(float distance) {
|
|||||||
return SphericalOf<T>();
|
return SphericalOf<T>();
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T> SphericalOf<T> SphericalOf<T>::operator-() const {
|
||||||
SphericalOf<T> SphericalOf<T>::operator-() const {
|
|
||||||
SphericalOf<T> v = SphericalOf<T>(
|
SphericalOf<T> v = SphericalOf<T>(
|
||||||
this->distance, this->direction.horizontal + AngleOf<T>::Degrees(180),
|
this->distance, this->direction.horizontal + AngleOf<T>::Degrees(180),
|
||||||
this->direction.vertical + AngleOf<T>::Degrees(180));
|
this->direction.vertical + AngleOf<T>::Degrees(180));
|
||||||
@ -206,14 +182,12 @@ SphericalOf<T> SphericalOf<T>::operator+=(const SphericalOf<T>& v) {
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T> SphericalOf<T> SphericalOf<T>::operator*=(float f) {
|
||||||
SphericalOf<T> SphericalOf<T>::operator*=(float f) {
|
|
||||||
this->distance *= f;
|
this->distance *= f;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T> SphericalOf<T> SphericalOf<T>::operator/=(float f) {
|
||||||
SphericalOf<T> SphericalOf<T>::operator/=(float f) {
|
|
||||||
this->distance /= f;
|
this->distance /= f;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
@ -256,8 +230,7 @@ AngleOf<T> SphericalOf<T>::AngleBetween(const SphericalOf& v1,
|
|||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
AngleOf<T> Passer::LinearAlgebra::SphericalOf<T>::SignedAngleBetween(
|
AngleOf<T> Passer::LinearAlgebra::SphericalOf<T>::SignedAngleBetween(
|
||||||
const SphericalOf<T>& v1,
|
const SphericalOf<T> &v1, const SphericalOf<T> &v2,
|
||||||
const SphericalOf<T>& v2,
|
|
||||||
const SphericalOf<T> &axis) {
|
const SphericalOf<T> &axis) {
|
||||||
Vector3 v1_vector = v1.ToVector3();
|
Vector3 v1_vector = v1.ToVector3();
|
||||||
Vector3 v2_vector = v2.ToVector3();
|
Vector3 v2_vector = v2.ToVector3();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user