Fix namespaces
This commit is contained in:
parent
64ca76830c
commit
8e7a8c6432
@ -3,6 +3,8 @@
|
|||||||
#include "Angle.h"
|
#include "Angle.h"
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
|
namespace Passer {
|
||||||
|
|
||||||
typedef AngleUsing<signed short> Angle16;
|
typedef AngleUsing<signed short> Angle16;
|
||||||
|
|
||||||
template <> Angle16::AngleUsing(float angle) {
|
template <> Angle16::AngleUsing(float angle) {
|
||||||
@ -19,3 +21,6 @@ template <> float Angle16::ToFloat() const {
|
|||||||
float f = ((this->value * 180) / 32768.0F);
|
float f = ((this->value * 180) / 32768.0F);
|
||||||
return f;
|
return f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace Passer
|
||||||
|
using namespace Passer;
|
@ -3,6 +3,7 @@
|
|||||||
#include "Angle.h"
|
#include "Angle.h"
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
|
namespace Passer {
|
||||||
typedef AngleUsing<signed long> Angle32;
|
typedef AngleUsing<signed long> Angle32;
|
||||||
|
|
||||||
template <> Angle32::AngleUsing(float angle) {
|
template <> Angle32::AngleUsing(float angle) {
|
||||||
@ -19,3 +20,6 @@ template <> float Angle32::ToFloat() const {
|
|||||||
float f = ((this->value * 180) / 2147483648.0F);
|
float f = ((this->value * 180) / 2147483648.0F);
|
||||||
return f;
|
return f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace Passer
|
||||||
|
using namespace Passer;
|
5
Angle8.h
5
Angle8.h
@ -3,6 +3,8 @@
|
|||||||
#include "Angle.h"
|
#include "Angle.h"
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
|
namespace Passer {
|
||||||
|
|
||||||
typedef AngleUsing<signed char> Angle8;
|
typedef AngleUsing<signed char> Angle8;
|
||||||
|
|
||||||
template <> Angle8::AngleUsing(float angle) {
|
template <> Angle8::AngleUsing(float angle) {
|
||||||
@ -20,3 +22,6 @@ template <> float Angle8::ToFloat() const {
|
|||||||
float f = (this->value * 180) / 128.0F;
|
float f = (this->value * 180) / 128.0F;
|
||||||
return f;
|
return f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace Passer
|
||||||
|
using namespace Passer;
|
@ -8,6 +8,8 @@
|
|||||||
#include "Angle.h"
|
#include "Angle.h"
|
||||||
#include "Axis.h"
|
#include "Axis.h"
|
||||||
|
|
||||||
|
namespace Passer {
|
||||||
|
|
||||||
class AngleAxis {
|
class AngleAxis {
|
||||||
public:
|
public:
|
||||||
Angle angle;
|
Angle angle;
|
||||||
@ -16,5 +18,7 @@ public:
|
|||||||
AngleAxis();
|
AngleAxis();
|
||||||
AngleAxis(Angle angle, Axis axis);
|
AngleAxis(Angle angle, Axis axis);
|
||||||
};
|
};
|
||||||
|
} // namespace Passer
|
||||||
|
using namespace Passer;
|
||||||
|
|
||||||
#endif
|
#endif
|
@ -4,6 +4,8 @@
|
|||||||
#include "Angle.h"
|
#include "Angle.h"
|
||||||
#include "Range.h"
|
#include "Range.h"
|
||||||
|
|
||||||
|
namespace Passer {
|
||||||
|
|
||||||
// A fixed angle between (-180..180]
|
// A fixed angle between (-180..180]
|
||||||
|
|
||||||
template <typename T> class AngleUsing {
|
template <typename T> class AngleUsing {
|
||||||
@ -38,5 +40,7 @@ public:
|
|||||||
// protected:
|
// protected:
|
||||||
T value;
|
T value;
|
||||||
};
|
};
|
||||||
|
} // namespace Passer
|
||||||
|
using namespace Passer;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
4
Axis.h
4
Axis.h
@ -7,6 +7,8 @@
|
|||||||
|
|
||||||
#include "Angle.h"
|
#include "Angle.h"
|
||||||
|
|
||||||
|
namespace Passer {
|
||||||
|
|
||||||
class Vector3;
|
class Vector3;
|
||||||
|
|
||||||
class Axis {
|
class Axis {
|
||||||
@ -27,5 +29,7 @@ public:
|
|||||||
|
|
||||||
Vector3 ToVector3();
|
Vector3 ToVector3();
|
||||||
};
|
};
|
||||||
|
} // namespace Passer
|
||||||
|
using namespace Passer;
|
||||||
|
|
||||||
#endif
|
#endif
|
@ -5,11 +5,16 @@
|
|||||||
#ifndef FLOAT_H
|
#ifndef FLOAT_H
|
||||||
#define FLOAT_H
|
#define FLOAT_H
|
||||||
|
|
||||||
|
namespace Passer {
|
||||||
|
|
||||||
class Float {
|
class Float {
|
||||||
public:
|
public:
|
||||||
static const float epsilon;
|
static const float epsilon;
|
||||||
static const float sqrEpsilon;
|
static const float sqrEpsilon;
|
||||||
|
|
||||||
static float Clamp(float f, float min, float max);
|
static float Clamp(float f, float min, float max);
|
||||||
};
|
};
|
||||||
|
} // namespace Passer
|
||||||
|
using namespace Passer;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
4
Matrix.h
4
Matrix.h
@ -3,6 +3,8 @@
|
|||||||
|
|
||||||
#include "Vector3.h"
|
#include "Vector3.h"
|
||||||
|
|
||||||
|
namespace Passer {
|
||||||
|
|
||||||
/// @brief Single precision float matrix
|
/// @brief Single precision float matrix
|
||||||
template <typename T> class MatrixOf {
|
template <typename T> class MatrixOf {
|
||||||
public:
|
public:
|
||||||
@ -110,5 +112,7 @@ private:
|
|||||||
unsigned int cols;
|
unsigned int cols;
|
||||||
T *data;
|
T *data;
|
||||||
};
|
};
|
||||||
|
} // namespace Passer
|
||||||
|
using namespace Passer;
|
||||||
|
|
||||||
#endif
|
#endif
|
12
Polar.h
12
Polar.h
@ -5,10 +5,9 @@
|
|||||||
#ifndef POLAR_H
|
#ifndef POLAR_H
|
||||||
#define POLAR_H
|
#define POLAR_H
|
||||||
|
|
||||||
struct Vector2;
|
|
||||||
|
|
||||||
namespace Passer {
|
namespace Passer {
|
||||||
|
|
||||||
|
struct Vector2;
|
||||||
struct Spherical;
|
struct Spherical;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -40,8 +39,16 @@ public:
|
|||||||
/// <param name="distance">The distance in meters</param>
|
/// <param name="distance">The distance in meters</param>
|
||||||
Polar(float angle, float distance);
|
Polar(float angle, float distance);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Convert a Vector2 to a Polar coordinate
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="v">The 2D carthesian vector</param>
|
||||||
Polar(Vector2 v);
|
Polar(Vector2 v);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Convert a Spherical coordinate to a Polar coordinate
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="s">The spherical coordinate</param>
|
||||||
Polar(Spherical s);
|
Polar(Spherical s);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -54,7 +61,6 @@ public:
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// This will rotate the vector by 180 degrees. Distance will stay the same.
|
/// This will rotate the vector by 180 degrees. Distance will stay the same.
|
||||||
/// <returns>The negated vector</returns>
|
/// <returns>The negated vector</returns>
|
||||||
|
|
||||||
Polar operator-();
|
Polar operator-();
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Substract a polar vector from this coordinate
|
/// Substract a polar vector from this coordinate
|
||||||
|
56
Quaternion.h
56
Quaternion.h
@ -7,6 +7,8 @@
|
|||||||
|
|
||||||
#include "Vector3.h"
|
#include "Vector3.h"
|
||||||
|
|
||||||
|
namespace Passer {
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// A quaternion
|
/// A quaternion
|
||||||
@ -36,7 +38,7 @@ typedef struct Quat {
|
|||||||
/// A quaternion
|
/// A quaternion
|
||||||
/// </summary>
|
/// </summary>
|
||||||
struct Quaternion : Quat {
|
struct Quaternion : Quat {
|
||||||
public:
|
public:
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Create a new identity quaternion
|
/// Create a new identity quaternion
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -54,6 +56,9 @@ struct Quaternion : Quat {
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="q"></param>
|
/// <param name="q"></param>
|
||||||
Quaternion(Quat q);
|
Quaternion(Quat q);
|
||||||
|
/// <summary>
|
||||||
|
/// Quaternion destructor
|
||||||
|
/// </summary>
|
||||||
~Quaternion();
|
~Quaternion();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -74,7 +79,7 @@ struct Quaternion : Quat {
|
|||||||
/// <returns>A unit quaternion</returns>
|
/// <returns>A unit quaternion</returns>
|
||||||
/// This will preserve the orientation,
|
/// This will preserve the orientation,
|
||||||
/// but ensures that it is a unit quaternion.
|
/// but ensures that it is a unit quaternion.
|
||||||
static Quaternion Normalize(const Quaternion& q);
|
static Quaternion Normalize(const Quaternion &q);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Convert to euler angles
|
/// Convert to euler angles
|
||||||
@ -82,14 +87,14 @@ struct Quaternion : Quat {
|
|||||||
/// <param name="q">The quaternion to convert</param>
|
/// <param name="q">The quaternion to convert</param>
|
||||||
/// <returns>A vector containing euler angles</returns>
|
/// <returns>A vector containing euler angles</returns>
|
||||||
/// The euler angles performed in the order: Z, X, Y
|
/// The euler angles performed in the order: Z, X, Y
|
||||||
static Vector3 ToAngles(const Quaternion& q);
|
static Vector3 ToAngles(const Quaternion &q);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Rotate a vector using this quaterion
|
/// Rotate a vector using this quaterion
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="vector">The vector to rotate</param>
|
/// <param name="vector">The vector to rotate</param>
|
||||||
/// <returns>The rotated vector</returns>
|
/// <returns>The rotated vector</returns>
|
||||||
Vector3 operator*(const Vector3& vector) const;
|
Vector3 operator*(const Vector3 &vector) const;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Multiply this quaternion with another quaternion
|
/// Multiply this quaternion with another quaternion
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -97,7 +102,7 @@ struct Quaternion : Quat {
|
|||||||
/// <returns>The resulting rotation</returns>
|
/// <returns>The resulting rotation</returns>
|
||||||
/// The result will be this quaternion rotated according to
|
/// The result will be this quaternion rotated according to
|
||||||
/// the give rotation.
|
/// the give rotation.
|
||||||
Quaternion operator*(const Quaternion& rotation) const;
|
Quaternion operator*(const Quaternion &rotation) const;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Check the equality of two quaternions
|
/// Check the equality of two quaternions
|
||||||
@ -108,7 +113,7 @@ struct Quaternion : Quat {
|
|||||||
/// themselves. Two quaternions with the same rotational effect may have
|
/// themselves. Two quaternions with the same rotational effect may have
|
||||||
/// different components. Use Quaternion::Angle to check if the rotations are
|
/// different components. Use Quaternion::Angle to check if the rotations are
|
||||||
/// the same.
|
/// the same.
|
||||||
bool operator==(const Quaternion& quaternion);
|
bool operator==(const Quaternion &quaternion);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The inverse of quaterion
|
/// The inverse of quaterion
|
||||||
@ -123,8 +128,8 @@ struct Quaternion : Quat {
|
|||||||
/// <param name="forward">The look direction</param>
|
/// <param name="forward">The look direction</param>
|
||||||
/// <param name="upwards">The up direction</param>
|
/// <param name="upwards">The up direction</param>
|
||||||
/// <returns>The look rotation</returns>
|
/// <returns>The look rotation</returns>
|
||||||
static Quaternion LookRotation(const Vector3& forward,
|
static Quaternion LookRotation(const Vector3 &forward,
|
||||||
const Vector3& upwards);
|
const Vector3 &upwards);
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a quaternion with the given forward direction with up =
|
/// Creates a quaternion with the given forward direction with up =
|
||||||
/// Vector3::up
|
/// Vector3::up
|
||||||
@ -134,7 +139,7 @@ struct Quaternion : Quat {
|
|||||||
/// For the rotation, Vector::up is used for the up direction.
|
/// For the rotation, Vector::up is used for the up direction.
|
||||||
/// Note: if the forward direction == Vector3::up, the result is
|
/// Note: if the forward direction == Vector3::up, the result is
|
||||||
/// Quaternion::identity
|
/// Quaternion::identity
|
||||||
static Quaternion LookRotation(const Vector3& forward);
|
static Quaternion LookRotation(const Vector3 &forward);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Calculat the rotation from on vector to another
|
/// Calculat the rotation from on vector to another
|
||||||
@ -151,8 +156,7 @@ struct Quaternion : Quat {
|
|||||||
/// <param name="to">The destination rotation</param>
|
/// <param name="to">The destination rotation</param>
|
||||||
/// <param name="maxDegreesDelta">The maximum amount of degrees to
|
/// <param name="maxDegreesDelta">The maximum amount of degrees to
|
||||||
/// rotate</param> <returns>The possibly limited rotation</returns>
|
/// rotate</param> <returns>The possibly limited rotation</returns>
|
||||||
static Quaternion RotateTowards(const Quaternion& from,
|
static Quaternion RotateTowards(const Quaternion &from, const Quaternion &to,
|
||||||
const Quaternion& to,
|
|
||||||
float maxDegreesDelta);
|
float maxDegreesDelta);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -161,13 +165,13 @@ struct Quaternion : Quat {
|
|||||||
/// <param name="angle">The angle</param>
|
/// <param name="angle">The angle</param>
|
||||||
/// <param name="axis">The axis</param>
|
/// <param name="axis">The axis</param>
|
||||||
/// <returns>The resulting quaternion</returns>
|
/// <returns>The resulting quaternion</returns>
|
||||||
static Quaternion AngleAxis(float angle, const Vector3& axis);
|
static Quaternion AngleAxis(float angle, const Vector3 &axis);
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Convert this quaternion to angle/axis representation
|
/// Convert this quaternion to angle/axis representation
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="angle">A pointer to the angle for the result</param>
|
/// <param name="angle">A pointer to the angle for the result</param>
|
||||||
/// <param name="axis">A pointer to the axis for the result</param>
|
/// <param name="axis">A pointer to the axis for the result</param>
|
||||||
void ToAngleAxis(float* angle, Vector3* axis);
|
void ToAngleAxis(float *angle, Vector3 *axis);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get the angle between two orientations
|
/// Get the angle between two orientations
|
||||||
@ -185,9 +189,8 @@ struct Quaternion : Quat {
|
|||||||
/// <param name="factor">The factor between 0 and 1.</param>
|
/// <param name="factor">The factor between 0 and 1.</param>
|
||||||
/// <returns>The resulting rotation</returns>
|
/// <returns>The resulting rotation</returns>
|
||||||
/// A factor 0 returns rotation1, factor1 returns rotation2.
|
/// A factor 0 returns rotation1, factor1 returns rotation2.
|
||||||
static Quaternion Slerp(const Quaternion& rotation1,
|
static Quaternion Slerp(const Quaternion &rotation1,
|
||||||
const Quaternion& rotation2,
|
const Quaternion &rotation2, float factor);
|
||||||
float factor);
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Unclamped sherical lerp between two rotations
|
/// Unclamped sherical lerp between two rotations
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -197,9 +200,8 @@ struct Quaternion : Quat {
|
|||||||
/// <returns>The resulting rotation</returns>
|
/// <returns>The resulting rotation</returns>
|
||||||
/// A factor 0 returns rotation1, factor1 returns rotation2.
|
/// A factor 0 returns rotation1, factor1 returns rotation2.
|
||||||
/// Values outside the 0..1 range will result in extrapolated rotations
|
/// Values outside the 0..1 range will result in extrapolated rotations
|
||||||
static Quaternion SlerpUnclamped(const Quaternion& rotation1,
|
static Quaternion SlerpUnclamped(const Quaternion &rotation1,
|
||||||
const Quaternion& rotation2,
|
const Quaternion &rotation2, float factor);
|
||||||
float factor);
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Create a rotation from euler angles
|
/// Create a rotation from euler angles
|
||||||
@ -257,10 +259,8 @@ struct Quaternion : Quat {
|
|||||||
/// <param name="swing">A pointer to the quaternion for the swing
|
/// <param name="swing">A pointer to the quaternion for the swing
|
||||||
/// result</param> <param name="twist">A pointer to the quaternion for the
|
/// result</param> <param name="twist">A pointer to the quaternion for the
|
||||||
/// twist result</param>
|
/// twist result</param>
|
||||||
static void GetSwingTwist(Vector3 axis,
|
static void GetSwingTwist(Vector3 axis, Quaternion rotation,
|
||||||
Quaternion rotation,
|
Quaternion *swing, Quaternion *twist);
|
||||||
Quaternion* swing,
|
|
||||||
Quaternion* twist);
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Calculate the dot product of two quaternions
|
/// Calculate the dot product of two quaternions
|
||||||
@ -270,16 +270,18 @@ struct Quaternion : Quat {
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
static float Dot(Quaternion rotation1, Quaternion rotation2);
|
static float Dot(Quaternion rotation1, Quaternion rotation2);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
float GetLength() const;
|
float GetLength() const;
|
||||||
float GetLengthSquared() const;
|
float GetLengthSquared() const;
|
||||||
static float GetLengthSquared(const Quaternion& q);
|
static float GetLengthSquared(const Quaternion &q);
|
||||||
|
|
||||||
void ToAxisAngleRad(const Quaternion& q, Vector3* const axis, float* angle);
|
void ToAxisAngleRad(const Quaternion &q, Vector3 *const axis, float *angle);
|
||||||
static Quaternion FromEulerRad(Vector3 euler);
|
static Quaternion FromEulerRad(Vector3 euler);
|
||||||
static Quaternion FromEulerRadXYZ(Vector3 euler);
|
static Quaternion FromEulerRadXYZ(Vector3 euler);
|
||||||
|
|
||||||
Vector3 xyz() const;
|
Vector3 xyz() const;
|
||||||
};
|
};
|
||||||
|
} // namespace Passer
|
||||||
|
using namespace Passer;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
4
Range.h
4
Range.h
@ -1,6 +1,8 @@
|
|||||||
#ifndef RANGE_H
|
#ifndef RANGE_H
|
||||||
#define RANGE_H
|
#define RANGE_H
|
||||||
|
|
||||||
|
namespace Passer {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
/// @brief Signed range. May be renamed to SignedRange later
|
/// @brief Signed range. May be renamed to SignedRange later
|
||||||
class Range16 {
|
class Range16 {
|
||||||
@ -39,5 +41,7 @@ public:
|
|||||||
|
|
||||||
T value;
|
T value;
|
||||||
};
|
};
|
||||||
|
} // namespace Passer
|
||||||
|
using namespace Passer;
|
||||||
|
|
||||||
#endif
|
#endif
|
@ -36,25 +36,25 @@ Spherical::Spherical(Vector3 v) {
|
|||||||
|
|
||||||
const Spherical Spherical::zero = Spherical(0.0F, (Angle)0.0F, (Angle)0.0F);
|
const Spherical Spherical::zero = Spherical(0.0F, (Angle)0.0F, (Angle)0.0F);
|
||||||
|
|
||||||
float Spherical::GetSwing() {
|
// float Spherical::GetSwing() {
|
||||||
// Not sure if this is correct
|
// // Not sure if this is correct
|
||||||
return sqrtf(horizontalAngle * horizontalAngle +
|
// return sqrtf(horizontalAngle * horizontalAngle +
|
||||||
verticalAngle * verticalAngle);
|
// verticalAngle * verticalAngle);
|
||||||
}
|
// }
|
||||||
|
|
||||||
Polar Spherical::ProjectOnHorizontalPlane() {
|
// Polar Spherical::ProjectOnHorizontalPlane() {
|
||||||
return Polar(horizontalAngle, distance);
|
// return Polar(horizontalAngle, distance);
|
||||||
}
|
// }
|
||||||
|
|
||||||
Vector3 Spherical::ToVector3() {
|
// Vector3 Spherical::ToVector3() {
|
||||||
float verticalRad = (90 - verticalAngle) * Angle::Deg2Rad;
|
// float verticalRad = (90 - verticalAngle) * Angle::Deg2Rad;
|
||||||
float horizontalRad = horizontalAngle * Angle::Deg2Rad;
|
// float horizontalRad = horizontalAngle * Angle::Deg2Rad;
|
||||||
float cosVertical = cosf(verticalRad);
|
// float cosVertical = cosf(verticalRad);
|
||||||
float sinVertical = sinf(verticalRad);
|
// float sinVertical = sinf(verticalRad);
|
||||||
float cosHorizontal = cosf(horizontalRad);
|
// float cosHorizontal = cosf(horizontalRad);
|
||||||
float sinHorizontal = sinf(horizontalRad);
|
// float sinHorizontal = sinf(horizontalRad);
|
||||||
Vector3 v = Vector3(this->distance * sinVertical * sinHorizontal,
|
// Vector3 v = Vector3(this->distance * sinVertical * sinHorizontal,
|
||||||
this->distance * cosVertical,
|
// this->distance * cosVertical,
|
||||||
this->distance * sinVertical * cosHorizontal);
|
// this->distance * sinVertical * cosHorizontal);
|
||||||
return v;
|
// return v;
|
||||||
}
|
// }
|
12
Spherical.h
12
Spherical.h
@ -9,10 +9,10 @@
|
|||||||
#include "Angle.h"
|
#include "Angle.h"
|
||||||
#include "Polar.h"
|
#include "Polar.h"
|
||||||
|
|
||||||
struct Vector3;
|
|
||||||
|
|
||||||
namespace Passer {
|
namespace Passer {
|
||||||
|
|
||||||
|
struct Vector3;
|
||||||
|
|
||||||
/// @brief A spherical vector
|
/// @brief A spherical vector
|
||||||
/// @details
|
/// @details
|
||||||
/// This is a vector in 3D space using a spherical coordinate system.
|
/// This is a vector in 3D space using a spherical coordinate system.
|
||||||
@ -39,7 +39,6 @@ public:
|
|||||||
/// zero is forward, positive is upward
|
/// zero is forward, positive is upward
|
||||||
/// @param distance The distance in meters
|
/// @param distance The distance in meters
|
||||||
// Spherical(float polarAngle, float elevationAngle, float distance);
|
// Spherical(float polarAngle, float elevationAngle, float distance);
|
||||||
|
|
||||||
Spherical(float distance, Angle horizontalAngle, Angle verticalAngle);
|
Spherical(float distance, Angle horizontalAngle, Angle verticalAngle);
|
||||||
|
|
||||||
/// @brief Convert polar coordinates to spherical coordinates
|
/// @brief Convert polar coordinates to spherical coordinates
|
||||||
@ -53,10 +52,11 @@ public:
|
|||||||
/// @brief A spherical vector with zero degree angles and distance
|
/// @brief A spherical vector with zero degree angles and distance
|
||||||
const static Spherical zero;
|
const static Spherical zero;
|
||||||
|
|
||||||
float GetSwing();
|
// float GetSwing();
|
||||||
|
|
||||||
Polar ProjectOnHorizontalPlane();
|
// Polar ProjectOnHorizontalPlane();
|
||||||
Vector3 ToVector3();
|
|
||||||
|
// Vector3 ToVector3();
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Passer
|
} // namespace Passer
|
||||||
|
13
Vector2.h
13
Vector2.h
@ -24,7 +24,9 @@ typedef struct Vec2 {
|
|||||||
} Vec2;
|
} Vec2;
|
||||||
}
|
}
|
||||||
|
|
||||||
class Vector3;
|
namespace Passer {
|
||||||
|
|
||||||
|
struct Vector3;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// A 2-dimensional vector
|
/// A 2-dimensional vector
|
||||||
@ -48,8 +50,15 @@ public:
|
|||||||
/// <param name="v">The C-style Vec</param>
|
/// <param name="v">The C-style Vec</param>
|
||||||
Vector2(Vec2 v);
|
Vector2(Vec2 v);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Convert a Vector3 to a Vector3
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="v">The 3D vector</param>
|
||||||
Vector2(Vector3 v);
|
Vector2(Vector3 v);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Vector2 destructor
|
||||||
|
/// </summary
|
||||||
~Vector2();
|
~Vector2();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -234,5 +243,5 @@ public:
|
|||||||
/// between *from* and *to* etc.
|
/// between *from* and *to* etc.
|
||||||
static Vector2 Lerp(Vector2 from, Vector2 to, float f);
|
static Vector2 Lerp(Vector2 from, Vector2 to, float f);
|
||||||
};
|
};
|
||||||
|
} // namespace Passer
|
||||||
#endif
|
#endif
|
20
Vector3.cpp
20
Vector3.cpp
@ -3,6 +3,9 @@
|
|||||||
// file, You can obtain one at https ://mozilla.org/MPL/2.0/.
|
// file, You can obtain one at https ://mozilla.org/MPL/2.0/.
|
||||||
|
|
||||||
#include "Vector3.h"
|
#include "Vector3.h"
|
||||||
|
#include "Angle.h"
|
||||||
|
#include "Spherical.h"
|
||||||
|
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
const float Deg2Rad = 0.0174532924F;
|
const float Deg2Rad = 0.0174532924F;
|
||||||
@ -27,6 +30,23 @@ Vector3::Vector3(Vec3 v) {
|
|||||||
z = v.z;
|
z = v.z;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Vector3::Vector3(Spherical s) {
|
||||||
|
float verticalRad = (90 - s.verticalAngle) * Angle::Deg2Rad;
|
||||||
|
float horizontalRad = s.horizontalAngle * Angle::Deg2Rad;
|
||||||
|
float cosVertical = cosf(verticalRad);
|
||||||
|
float sinVertical = sinf(verticalRad);
|
||||||
|
float cosHorizontal = cosf(horizontalRad);
|
||||||
|
float sinHorizontal = sinf(horizontalRad);
|
||||||
|
|
||||||
|
x = s.distance * sinVertical * sinHorizontal;
|
||||||
|
y = s.distance * cosVertical;
|
||||||
|
z = s.distance * sinVertical * cosHorizontal;
|
||||||
|
// Vector3 v = Vector3(s.distance * sinVertical * sinHorizontal,
|
||||||
|
// s.distance * cosVertical,
|
||||||
|
// );
|
||||||
|
// return v;
|
||||||
|
}
|
||||||
|
|
||||||
Vector3::~Vector3() {}
|
Vector3::~Vector3() {}
|
||||||
|
|
||||||
const Vector3 Vector3::zero = Vector3(0, 0, 0);
|
const Vector3 Vector3::zero = Vector3(0, 0, 0);
|
||||||
|
10
Vector3.h
10
Vector3.h
@ -7,6 +7,10 @@
|
|||||||
|
|
||||||
#include "Vector2.h"
|
#include "Vector2.h"
|
||||||
|
|
||||||
|
namespace Passer {
|
||||||
|
|
||||||
|
struct Spherical;
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 3-dimensional Vector representation
|
/// 3-dimensional Vector representation
|
||||||
@ -52,6 +56,10 @@ public:
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="v">The C-style Vec</param>
|
/// <param name="v">The C-style Vec</param>
|
||||||
Vector3(Vec3 v);
|
Vector3(Vec3 v);
|
||||||
|
/// <summary>
|
||||||
|
/// Vector3 destructor
|
||||||
|
/// </summary>
|
||||||
|
Vector3(Spherical s);
|
||||||
~Vector3();
|
~Vector3();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -267,5 +275,7 @@ public:
|
|||||||
/// between *from* and *to* etc.
|
/// between *from* and *to* etc.
|
||||||
static Vector3 Lerp(const Vector3 &from, const Vector3 &to, float f);
|
static Vector3 Lerp(const Vector3 &from, const Vector3 &to, float f);
|
||||||
};
|
};
|
||||||
|
} // namespace Passer
|
||||||
|
using namespace Passer;
|
||||||
|
|
||||||
#endif
|
#endif
|
Loading…
x
Reference in New Issue
Block a user