Extend AngleOf support

This commit is contained in:
Pascal Serrarens 2024-07-31 11:44:23 +02:00
parent c70c079efc
commit b81b77b1c9
16 changed files with 441 additions and 268 deletions

View File

@ -3,8 +3,8 @@
// file, You can obtain one at https ://mozilla.org/MPL/2.0/.
#include "Angle.h"
#include "FloatSingle.h"
#include <math.h>
#include "FloatSingle.h"
/*
const float Angle::Rad2Deg = 57.29578F;
@ -73,17 +73,29 @@ float Angle::SineRuleAngle(float a, float beta, float b) {
*/
//----------------------
template <> AngleOf<float> AngleOf<float>::pi = 3.1415927410125732421875F;
template <>
AngleOf<float>::AngleOf(float angle) : value(angle) {}
template <> AngleOf<float> AngleOf<float>::Rad2Deg = 360.0f / (pi * 2);
template <> AngleOf<float> AngleOf<float>::Deg2Rad = (pi * 2) / 360.0f;
template <>
AngleOf<float>::operator float() const {
return value;
}
template <>
AngleOf<float> AngleOf<float>::pi = 3.1415927410125732421875F;
template <>
AngleOf<float> AngleOf<float>::Rad2Deg = 360.0f / (pi * 2);
template <>
AngleOf<float> AngleOf<float>::Deg2Rad = (pi * 2) / 360.0f;
template <>
bool Passer::LinearAlgebra::AngleOf<float>::operator==(AngleOf<float> a) {
return (float)*this == (float)a;
}
template <> AngleOf<float> AngleOf<float>::Normalize(AngleOf<float> angle) {
template <>
AngleOf<float> AngleOf<float>::Normalize(AngleOf<float> angle) {
float angleValue = angle;
if (!isfinite(angleValue))
return angleValue;
@ -96,7 +108,8 @@ template <> AngleOf<float> AngleOf<float>::Normalize(AngleOf<float> angle) {
}
template <>
AngleOf<float> AngleOf<float>::Clamp(AngleOf<float> angle, AngleOf<float> min,
AngleOf<float> AngleOf<float>::Clamp(AngleOf<float> angle,
AngleOf<float> min,
AngleOf<float> max) {
float normalizedAngle = Normalize(angle);
float r = Float::Clamp(normalizedAngle, min, max);
@ -120,7 +133,8 @@ AngleOf<float> AngleOf<float>::MoveTowards(AngleOf<float> fromAngle,
}
template <>
AngleOf<float> AngleOf<float>::CosineRuleSide(float a, float b,
AngleOf<float> AngleOf<float>::CosineRuleSide(float a,
float b,
AngleOf<float> gamma) {
float a2 = a * a;
float b2 = b * b;
@ -150,7 +164,8 @@ AngleOf<float> AngleOf<float>::CosineRuleAngle(float a, float b, float c) {
}
template <>
AngleOf<float> AngleOf<float>::SineRuleAngle(float a, AngleOf<float> beta,
AngleOf<float> AngleOf<float>::SineRuleAngle(float a,
AngleOf<float> beta,
float b) {
float alpha = asin(a * sin(beta * Angle::Deg2Rad) / b);
return alpha;

14
Angle.h
View File

@ -8,11 +8,15 @@
namespace Passer {
namespace LinearAlgebra {
template <typename T> class AngleOf {
template <typename T>
class AngleOf {
public:
AngleOf() {};
AngleOf(T v) : value(v) {}
operator T() const { return value; }
AngleOf(float f);
// AngleOf(T v) : value(v) {}
// operator T() const; // { return value; }
operator float() const;
inline T GetBinary() const { return this->value; }
static AngleOf<T> Rad2Deg;
static AngleOf<T> Deg2Rad;
@ -27,7 +31,8 @@ public:
AngleOf<T> r = Normalize(b - a);
return r;
};
static AngleOf<T> MoveTowards(AngleOf<T> fromAngle, AngleOf<T> toAngle,
static AngleOf<T> MoveTowards(AngleOf<T> fromAngle,
AngleOf<T> toAngle,
AngleOf<T> maxAngle);
static AngleOf<T> CosineRuleSide(float a, float b, AngleOf<T> gamma);
@ -40,6 +45,7 @@ private:
};
using Angle = AngleOf<float>;
// using Angle = AngleOf<signed short>;
} // namespace LinearAlgebra
} // namespace Passer

74
Angle16.cpp Normal file
View File

@ -0,0 +1,74 @@
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0.If a copy of the MPL was not distributed with this
// file, You can obtain one at https ://mozilla.org/MPL/2.0/.
#include <math.h>
#include "Angle.h"
template <>
AngleOf<signed short>::AngleOf(float angle) {
if (!isfinite(angle)) {
value = 0;
return;
}
// map float [-180..180) to integer [-32768..32767]
this->value = (signed short)((angle / 360.0F) * 65536.0F);
}
template <>
AngleOf<signed short>::operator float() const {
float f = ((this->value * 180) / 32768.0F);
return f;
}
// This should not exist...
// template <>
// AngleOf<signed short> AngleOf<signed short>::pi = 3.1415927410125732421875F;
// template <>
// AngleOf<signed short> AngleOf<signed short>::Rad2Deg = 360.0f / (pi * 2);
// template <>
// AngleOf<signed short> AngleOf<signed short>::Deg2Rad = (pi * 2) / 360.0f;
// template <>
// AngleOf<signed short> AngleOf<signed short>::Normalize(
// AngleOf<signed short> angle) {
// return angle;
// }
// Not correct!!! just for syntactical compilation ATM
template <>
AngleOf<signed short> AngleOf<signed short>::CosineRuleSide(
float a,
float b,
AngleOf<signed short> gamma) {
float a2 = a * a;
float b2 = b * b;
float d = a2 + b2 - 2 * a * b * cos(gamma * AngleOf<float>::Deg2Rad);
// Catch edge cases where float inacuracies lead tot nans
if (d < 0)
return 0;
float c = sqrtf(d);
return c;
}
// Not correct!!! just for syntactical compilation ATM
template <>
AngleOf<signed short> AngleOf<signed short>::CosineRuleAngle(float a,
float b,
float c) {
float a2 = a * a;
float b2 = b * b;
float c2 = c * c;
float d = (a2 + b2 - c2) / (2 * a * b);
// Catch edge cases where float inacuracies lead tot nans
if (d >= 1)
return 0;
if (d <= -1)
return 180;
float gamma = acos(d) * Angle::Rad2Deg;
return gamma;
}

View File

@ -1,27 +1,27 @@
#include "AngleUsing.h"
// #include "AngleUsing.h"
#include "Angle.h"
#include <math.h>
#include "Angle.h"
namespace Passer {
namespace LinearAlgebra {
typedef AngleUsing<signed short> Angle16;
typedef AngleOf<signed short> Angle16;
template <> Angle16::AngleUsing(float angle) {
if (!isfinite(angle)) {
value = 0;
return;
}
// template <> Angle16::AngleOf(float angle) {
// if (!isfinite(angle)) {
// value = 0;
// return;
// }
// map float [-180..180) to integer [-32768..32767]
this->value = (signed short)((angle / 360.0F) * 65536.0F);
}
// // map float [-180..180) to integer [-32768..32767]
// this->value = (signed short)((angle / 360.0F) * 65536.0F);
// }
template <> float Angle16::ToFloat() const {
float f = ((this->value * 180) / 32768.0F);
return f;
}
// template <> float Angle16::ToFloat() const {
// float f = ((this->value * 180) / 32768.0F);
// return f;
// }
} // namespace LinearAlgebra
} // namespace Passer

View File

@ -1,27 +1,29 @@
#include "AngleUsing.h"
// #include "AngleUsing.h"
#include "Angle.h"
#include <math.h>
#include "Angle.h"
namespace Passer {
namespace LinearAlgebra {
typedef AngleUsing<signed long> Angle32;
typedef AngleOf<signed long> Angle32;
template <> Angle32::AngleUsing(float angle) {
if (!isfinite(angle)) {
value = 0;
return;
}
// template <>
// Angle32::AngleOf(float angle) {
// if (!isfinite(angle)) {
// value = 0;
// return;
// }
// map float [-180..180) to integer [-2147483648..2147483647]
this->value = (signed long)((angle / 360.0F) * 4294967295.0F);
}
// // map float [-180..180) to integer [-2147483648..2147483647]
// this->value = (signed long)((angle / 360.0F) * 4294967295.0F);
// }
template <> float Angle32::ToFloat() const {
float f = ((this->value * 180) / 2147483648.0F);
return f;
}
// template <>
// float Angle32::ToFloat() const {
// float f = ((this->value * 180) / 2147483648.0F);
// return f;
// }
} // namespace LinearAlgebra
} // namespace Passer

24
Angle8.cpp Normal file
View File

@ -0,0 +1,24 @@
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0.If a copy of the MPL was not distributed with this
// file, You can obtain one at https ://mozilla.org/MPL/2.0/.
#include <math.h>
#include "Angle.h"
template <>
AngleOf<signed char>::AngleOf(float angle) {
if (!isfinite(angle)) {
value = 0;
return;
}
// map float [-180..180) to integer [-128..127]
float f = angle / 360.0F;
this->value = (signed char)(f * 256.0F);
}
template <>
AngleOf<signed char>::operator float() const {
float f = (this->value * 180) / 128.0F;
return f;
}

View File

@ -1,28 +1,28 @@
#include "AngleUsing.h"
// #include "AngleUsing.h"
#include "Angle.h"
#include <math.h>
#include "Angle.h"
namespace Passer {
namespace LinearAlgebra {
typedef AngleUsing<signed char> Angle8;
typedef AngleOf<signed char> Angle8;
template <> Angle8::AngleUsing(float angle) {
if (!isfinite(angle)) {
value = 0;
return;
}
// template <> Angle8::AngleOf(float angle) {
// if (!isfinite(angle)) {
// value = 0;
// return;
// }
// map float [-180..180) to integer [-128..127]
float f = angle / 360.0F;
this->value = (signed char)(f * 256.0F);
}
// // map float [-180..180) to integer [-128..127]
// float f = angle / 360.0F;
// this->value = (signed char)(f * 256.0F);
// }
template <> float Angle8::ToFloat() const {
float f = (this->value * 180) / 128.0F;
return f;
}
// template <> float Angle8::ToFloat() const {
// float f = (this->value * 180) / 128.0F;
// return f;
// }
} // namespace LinearAlgebra
} // namespace Passer

View File

@ -1,3 +1,4 @@
/*
#ifndef DISCRETEANGLE_H
#define DISCRETEANGLE_H
@ -9,7 +10,8 @@ namespace LinearAlgebra {
// A fixed angle between (-180..180]
template <typename T> class AngleUsing {
template <typename T>
class AngleUsing {
public:
AngleUsing(T sourceValue) { this->value = sourceValue; }
AngleUsing(float f);
@ -47,3 +49,4 @@ public:
using namespace Passer::LinearAlgebra;
#endif
*/

View File

@ -94,22 +94,22 @@ Polar Polar::operator+=(const Polar &v) {
return *this;
}
Polar Passer::LinearAlgebra::operator*(const Polar &v, float f) {
return Polar(v.distance * f, v.angle);
}
Polar Passer::LinearAlgebra::operator*(float f, const Polar &v) {
return Polar(v.distance * f, v.angle);
}
// Polar Passer::LinearAlgebra::operator*(const Polar &v, float f) {
// return Polar(v.distance * f, v.angle);
// }
// Polar Passer::LinearAlgebra::operator*(float f, const Polar &v) {
// return Polar(v.distance * f, v.angle);
// }
Polar Polar::operator*=(float f) {
this->distance *= f;
return *this;
}
Polar Passer::LinearAlgebra::operator/(const Polar &v, float f) {
return Polar(v.distance / f, v.angle);
}
Polar Passer::LinearAlgebra::operator/(float f, const Polar &v) {
return Polar(v.distance / f, v.angle);
}
// Polar Passer::LinearAlgebra::operator/(const Polar& v, float f) {
// return Polar(v.distance / f, v.angle);
// }
// Polar Passer::LinearAlgebra::operator/(float f, const Polar& v) {
// return Polar(v.distance / f, v.angle);
// }
Polar Polar::operator/=(float f) {
this->distance /= f;
return *this;

16
Polar.h
View File

@ -98,16 +98,24 @@ public:
/// @return The scaled vector
/// @remark This operation will scale the distance of the vector. The angle
/// will be unaffected.
friend Polar operator*(const Polar &v, float f);
friend Polar operator*(float f, const Polar &v);
friend Polar operator*(const Polar& v, float f) {
return Polar(v.distance * f, v.angle);
}
friend Polar operator*(float f, const Polar& v) {
return Polar(f * v.distance, v.angle);
}
Polar operator*=(float f);
/// @brief Scale the vector uniformly down
/// @param f The scaling factor
/// @return The scaled factor
/// @remark This operation will scale the distance of the vector. The angle
/// will be unaffected.
friend Polar operator/(const Polar &v, float f);
friend Polar operator/(float f, const Polar &v);
friend Polar operator/(const Polar& v, float f) {
return Polar(v.distance / f, v.angle);
}
friend Polar operator/(float f, const Polar& v) {
return Polar(f / v.distance, v.angle);
}
Polar operator/=(float f);
/// @brief The distance between two vectors

View File

@ -17,7 +17,8 @@ Spherical::Spherical(Polar polar) {
this->verticalAngle = 0.0f;
}
Spherical::Spherical(float distance, Angle horizontalAngle,
Spherical::Spherical(float distance,
Angle horizontalAngle,
Angle verticalAngle) {
if (distance < 0) {
this->distance = -distance;
@ -143,23 +144,23 @@ Spherical Spherical::operator+=(const Spherical &v) {
return *this;
}
Spherical Passer::LinearAlgebra::operator*(const Spherical &v, float f) {
return Spherical(v.distance * f, v.horizontalAngle, v.verticalAngle);
}
Spherical Passer::LinearAlgebra::operator*(float f, const Spherical &v) {
return Spherical(v.distance * f, v.horizontalAngle, v.verticalAngle);
}
// Spherical Passer::LinearAlgebra::operator*(const Spherical &v, float f) {
// return Spherical(v.distance * f, v.horizontalAngle, v.verticalAngle);
// }
// Spherical Passer::LinearAlgebra::operator*(float f, const Spherical &v) {
// return Spherical(v.distance * f, v.horizontalAngle, v.verticalAngle);
// }
Spherical Spherical::operator*=(float f) {
this->distance *= f;
return *this;
}
Spherical Passer::LinearAlgebra::operator/(const Spherical &v, float f) {
return Spherical(v.distance / f, v.horizontalAngle, v.verticalAngle);
}
Spherical Passer::LinearAlgebra::operator/(float f, const Spherical &v) {
return Spherical(v.distance / f, v.horizontalAngle, v.verticalAngle);
}
// Spherical Passer::LinearAlgebra::operator/(const Spherical &v, float f) {
// return Spherical(v.distance / f, v.horizontalAngle, v.verticalAngle);
// }
// Spherical Passer::LinearAlgebra::operator/(float f, const Spherical &v) {
// return Spherical(v.distance / f, v.horizontalAngle, v.verticalAngle);
// }
Spherical Spherical::operator/=(float f) {
this->distance /= f;
return *this;
@ -184,7 +185,6 @@ const float epsilon = 1E-05f;
const float Rad2Deg = 57.29578F;
Angle Spherical::AngleBetween(const Spherical& v1, const Spherical& v2) {
// float denominator = sqrtf(v1_3.sqrMagnitude() * v2_3.sqrMagnitude());
float denominator =
v1.distance * v2.distance; // sqrtf(v1.distance * v1.distance *
@ -204,7 +204,8 @@ Angle Spherical::AngleBetween(const Spherical &v1, const Spherical &v2) {
return r;
}
Spherical Spherical::Rotate(const Spherical &v, Angle horizontalAngle,
Spherical Spherical::Rotate(const Spherical& v,
Angle horizontalAngle,
Angle verticalAngle) {
Spherical r = Spherical(v.distance, v.horizontalAngle + horizontalAngle,
v.verticalAngle + verticalAngle);

View File

@ -106,16 +106,26 @@ public:
/// @return The scaled vector
/// @remark This operation will scale the distance of the vector. The angle
/// will be unaffected.
friend Spherical operator*(const Spherical &v, float f);
friend Spherical operator*(float f, const Spherical &v);
friend Spherical operator*(const Spherical& v, float f) {
return Spherical(v.distance * f, v.horizontalAngle, v.verticalAngle);
}
friend Spherical operator*(float f, const Spherical& v) {
return Spherical(v.distance * f, v.horizontalAngle,
v.verticalAngle); // not correct, should be f * v.distance
}
Spherical operator*=(float f);
/// @brief Scale the vector uniformly down
/// @param f The scaling factor
/// @return The scaled factor
/// @remark This operation will scale the distance of the vector. The angle
/// will be unaffected.
friend Spherical operator/(const Spherical &v, float f);
friend Spherical operator/(float f, const Spherical &v);
friend Spherical operator/(const Spherical& v, float f) {
return Spherical(v.distance / f, v.horizontalAngle, v.verticalAngle);
}
friend Spherical operator/(float f, const Spherical& v) {
return Spherical(v.distance / f, v.horizontalAngle,
v.verticalAngle); // not correct, should be f / v.distance
}
Spherical operator/=(float f);
/// <summary>
@ -128,7 +138,8 @@ public:
static Angle AngleBetween(const Spherical& v1, const Spherical& v2);
static Spherical Rotate(const Spherical &v, Angle horizontalAngle,
static Spherical Rotate(const Spherical& v,
Angle horizontalAngle,
Angle verticalAngle);
static Spherical RotateHorizontal(const Spherical& v, Angle angle);
static Spherical RotateVertical(const Spherical& v, Angle angle);

View File

@ -56,9 +56,15 @@ bool Vector2::operator==(const Vector2 &v) {
float Vector2::Magnitude(const Vector2& v) {
return sqrtf(v.x * v.x + v.y * v.y);
}
float Vector2::magnitude() const { return (float)sqrtf(x * x + y * y); }
float Vector2::SqrMagnitude(const Vector2 &v) { return v.x * v.x + v.y * v.y; }
float Vector2::sqrMagnitude() const { return (x * x + y * y); }
float Vector2::magnitude() const {
return (float)sqrtf(x * x + y * y);
}
float Vector2::SqrMagnitude(const Vector2& v) {
return v.x * v.x + v.y * v.y;
}
float Vector2::sqrMagnitude() const {
return (x * x + y * y);
}
Vector2 Vector2::Normalize(const Vector2& v) {
float num = Vector2::Magnitude(v);
@ -77,7 +83,9 @@ Vector2 Vector2::normalized() const {
return result;
}
Vector2 Vector2::operator-() { return Vector2(-this->x, -this->y); }
Vector2 Vector2::operator-() {
return Vector2(-this->x, -this->y);
}
Vector2 Vector2::operator-(const Vector2& v) const {
return Vector2(this->x - v.x, this->y - v.y);
@ -99,23 +107,23 @@ Vector2 Vector2::operator+=(const Vector2 &v) {
Vector2 Vector2::Scale(const Vector2& v1, const Vector2& v2) {
return Vector2(v1.x * v2.x, v1.y * v2.y);
}
Vector2 Passer::LinearAlgebra::operator*(const Vector2 &v, float f) {
return Vector2(v.x * f, v.y * f);
}
Vector2 Passer::LinearAlgebra::operator*(float f, const Vector2 &v) {
return Vector2(v.x * f, v.y * f);
}
// Vector2 Passer::LinearAlgebra::operator*(const Vector2 &v, float f) {
// return Vector2(v.x * f, v.y * f);
// }
// Vector2 Passer::LinearAlgebra::operator*(float f, const Vector2 &v) {
// return Vector2(v.x * f, v.y * f);
// }
Vector2 Vector2::operator*=(float f) {
this->x *= f;
this->y *= f;
return *this;
}
Vector2 Passer::LinearAlgebra::operator/(const Vector2 &v, float f) {
return Vector2(v.x / f, v.y / f);
}
Vector2 Passer::LinearAlgebra::operator/(float f, const Vector2 &v) {
return Vector2(v.x / f, v.y / f);
}
// Vector2 Passer::LinearAlgebra::operator/(const Vector2 &v, float f) {
// return Vector2(v.x / f, v.y / f);
// }
// Vector2 Passer::LinearAlgebra::operator/(float f, const Vector2 &v) {
// return Vector2(v.x / f, v.y / f);
// }
Vector2 Vector2::operator/=(float f) {
this->x /= f;
this->y /= f;

View File

@ -138,8 +138,13 @@ public:
/// @return The scaled vector
/// @remark Each component of the vector will be multipled with the same
/// factor f.
friend Vector2 operator*(const Vector2 &v, float f);
friend Vector2 operator*(float f, const Vector2 &v);
friend Vector2 operator*(const Vector2& v, float f) {
return Vector2(v.x * f, v.y * f);
}
friend Vector2 operator*(float f, const Vector2& v) {
return Vector2(v.x * f, v.y * f);
// return Vector2(f * v.x, f * v.y);
}
Vector2 operator*=(float f);
/// @brief Scale the vector uniformly down
/// @param f The scaling factor

View File

@ -68,12 +68,16 @@ const Vector3 Vector3::back = Vector3(0, 0, -1);
float Vector3::Magnitude(const Vector3& v) {
return sqrtf(v.x * v.x + v.y * v.y + v.z * v.z);
}
float Vector3::magnitude() const { return (float)sqrtf(x * x + y * y + z * z); }
float Vector3::magnitude() const {
return (float)sqrtf(x * x + y * y + z * z);
}
float Vector3::SqrMagnitude(const Vector3& v) {
return v.x * v.x + v.y * v.y + v.z * v.z;
}
float Vector3::sqrMagnitude() const { return (x * x + y * y + z * z); }
float Vector3::sqrMagnitude() const {
return (x * x + y * y + z * z);
}
Vector3 Vector3::Normalize(const Vector3& v) {
float num = Vector3::Magnitude(v);
@ -118,24 +122,24 @@ Vector3 Vector3::operator+=(const Vector3 &v) {
Vector3 Vector3::Scale(const Vector3& v1, const Vector3& v2) {
return Vector3(v1.x * v2.x, v1.y * v2.y, v1.z * v2.z);
}
Vector3 Passer::LinearAlgebra::operator*(const Vector3 &v, float f) {
return Vector3(v.x * f, v.y * f, v.z * f);
}
Vector3 Passer::LinearAlgebra::operator*(float f, const Vector3 &v) {
return Vector3(v.x * f, v.y * f, v.z * f);
}
// Vector3 Passer::LinearAlgebra::operator*(const Vector3 &v, float f) {
// return Vector3(v.x * f, v.y * f, v.z * f);
// }
// Vector3 Passer::LinearAlgebra::operator*(float f, const Vector3 &v) {
// return Vector3(v.x * f, v.y * f, v.z * f);
// }
Vector3 Vector3::operator*=(float f) {
this->x *= f;
this->y *= f;
this->z *= f;
return *this;
}
Vector3 Passer::LinearAlgebra::operator/(const Vector3 &v, float f) {
return Vector3(v.x / f, v.y / f, v.z / f);
}
Vector3 Passer::LinearAlgebra::operator/(float f, const Vector3 &v) {
return Vector3(v.x / f, v.y / f, v.z / f);
}
// Vector3 Passer::LinearAlgebra::operator/(const Vector3 &v, float f) {
// return Vector3(v.x / f, v.y / f, v.z / f);
// }
// Vector3 Passer::LinearAlgebra::operator/(float f, const Vector3 &v) {
// return Vector3(v.x / f, v.y / f, v.z / f);
// }
Vector3 Vector3::operator/=(float f) {
this->x /= f;
this->y /= f;
@ -197,7 +201,8 @@ float Vector3::Angle(const Vector3 &v1, const Vector3 &v2) {
return r;
}
float Vector3::SignedAngle(const Vector3 &v1, const Vector3 &v2,
float Vector3::SignedAngle(const Vector3& v1,
const Vector3& v2,
const Vector3& axis) {
// angle in [0,180]
float angle = Vector3::Angle(v1, v2);

View File

@ -146,15 +146,25 @@ public:
/// @return The scaled vector
/// @remark Each component of the vector will be multipled with the same
/// factor f.
friend Vector3 operator*(const Vector3 &v, float f);
friend Vector3 operator*(float f, const Vector3 &v);
friend Vector3 operator*(const Vector3& v, float f) {
return Vector3(v.x * f, v.y * f, v.z * f);
}
friend Vector3 operator*(float f, const Vector3& v) {
// return Vector3(f * v.x, f * v.y, f * v.z);
return Vector3(v.x * f, v.y * f, v.z * f);
}
Vector3 operator*=(float f);
/// @brief Scale the vector uniformly down
/// @param f The scaling factor
/// @return The scaled vector
/// @remark Each componet of the vector will be divided by the same factor.
friend Vector3 operator/(const Vector3 &v, float f);
friend Vector3 operator/(float f, const Vector3 &v);
friend Vector3 operator/(const Vector3& v, float f) {
return Vector3(v.x / f, v.y / f, v.z / f);
}
friend Vector3 operator/(float f, const Vector3& v) {
// return Vector3(f / v.x, f / v.y, f / v.z);
return Vector3(v.x / f, v.y / f, v.z / f);
}
Vector3 operator/=(float f);
/// @brief The distance between two vectors
@ -200,7 +210,8 @@ public:
/// @param v2 The ending vector
/// @param axis The axis to rotate around
/// @return The signed angle between the two vectors
static float SignedAngle(const Vector3 &v1, const Vector3 &v2,
static float SignedAngle(const Vector3& v1,
const Vector3& v2,
const Vector3& axis);
/// @brief Lerp (linear interpolation) between two vectors