2016-02-20 23:25:00 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-09-30 02:56:11 +02:00
|
|
|
#include "Base/Quaternion.hpp"
|
|
|
|
#include "Base/Vector3.hpp"
|
|
|
|
#include "Base/Vector4.hpp"
|
2016-08-24 22:17:29 +02:00
|
|
|
#include "Base/DynArg.hpp"
|
2021-01-30 07:51:39 +01:00
|
|
|
#include "Core/Buffer.hpp"
|
|
|
|
#include "Core/Utility.hpp"
|
2022-09-18 14:02:39 +02:00
|
|
|
#include "Library/JSON.hpp"
|
2016-06-05 03:15:23 +02:00
|
|
|
#include "Library/Numeric/Random.hpp"
|
2015-09-30 02:56:11 +02:00
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
namespace SqMod {
|
|
|
|
|
2016-08-23 22:02:19 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
#define STOVAL(v) static_cast< Quaternion::Value >(v)
|
|
|
|
|
2016-11-15 20:20:42 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2021-01-30 07:51:39 +01:00
|
|
|
SQMOD_DECL_TYPENAME(Typename, _SC("Quaternion"))
|
2016-11-15 20:20:42 +01:00
|
|
|
|
2015-09-30 02:56:11 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-08-04 02:09:43 +02:00
|
|
|
const Quaternion Quaternion::NIL(0);
|
|
|
|
const Quaternion Quaternion::MIN(std::numeric_limits< Quaternion::Value >::min());
|
|
|
|
const Quaternion Quaternion::MAX(std::numeric_limits< Quaternion::Value >::max());
|
|
|
|
const Quaternion Quaternion::IDENTITY(1.0, 0.0, 0.0, 0.0);
|
2015-09-30 02:56:11 +02:00
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
SQChar Quaternion::Delim = ',';
|
|
|
|
|
2016-02-20 23:25:00 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2020-03-22 08:16:40 +01:00
|
|
|
Quaternion::Quaternion(Value sv) noexcept
|
2016-02-20 23:25:00 +01:00
|
|
|
: x(sv), y(sv), z(sv), w(sv)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2016-02-20 23:25:00 +01:00
|
|
|
/* ... */
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2016-02-20 23:25:00 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2020-03-22 08:16:40 +01:00
|
|
|
Quaternion::Quaternion(Value xv, Value yv, Value zv) noexcept
|
2015-09-30 02:56:11 +02:00
|
|
|
: x(xv), y(yv), z(zv), w(0.0)
|
|
|
|
{
|
2016-02-20 23:25:00 +01:00
|
|
|
/* ... */
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2016-02-20 23:25:00 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2020-03-22 08:16:40 +01:00
|
|
|
Quaternion::Quaternion(Value xv, Value yv, Value zv, Value wv) noexcept
|
2015-09-30 02:56:11 +02:00
|
|
|
: x(xv), y(yv), z(zv), w(wv)
|
|
|
|
{
|
2016-02-20 23:25:00 +01:00
|
|
|
/* ... */
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
Quaternion & Quaternion::operator = (Value s)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
x = s;
|
|
|
|
y = s;
|
|
|
|
z = s;
|
|
|
|
w = s;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2016-07-24 23:08:28 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
Quaternion & Quaternion::operator = (const Vector3 & q)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
x = q.x;
|
|
|
|
y = q.y;
|
|
|
|
z = q.z;
|
|
|
|
w = 0.0;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2016-07-24 23:08:28 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
Quaternion & Quaternion::operator = (const Vector4 & q)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
x = q.x;
|
|
|
|
y = q.y;
|
|
|
|
z = q.z;
|
|
|
|
w = q.w;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
Quaternion & Quaternion::operator += (const Quaternion & q)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
x += q.x;
|
|
|
|
y += q.y;
|
|
|
|
z += q.z;
|
|
|
|
w += q.w;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2016-07-24 23:08:28 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
Quaternion & Quaternion::operator -= (const Quaternion & q)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
x -= q.x;
|
|
|
|
y -= q.y;
|
|
|
|
z -= q.z;
|
|
|
|
w -= q.w;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2016-07-24 23:08:28 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
Quaternion & Quaternion::operator *= (const Quaternion & q)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
x *= q.x;
|
|
|
|
y *= q.y;
|
|
|
|
z *= q.z;
|
|
|
|
w *= q.w;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2016-07-24 23:08:28 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
Quaternion & Quaternion::operator /= (const Quaternion & q)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
x /= q.x;
|
|
|
|
y /= q.y;
|
|
|
|
z /= q.z;
|
|
|
|
w /= q.w;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2016-07-24 23:08:28 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
Quaternion & Quaternion::operator %= (const Quaternion & q)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2021-01-30 07:51:39 +01:00
|
|
|
x = fmodf(x, q.x);
|
|
|
|
y = fmodf(y, q.y);
|
|
|
|
z = fmodf(z, q.z);
|
|
|
|
w = fmodf(w, q.w);
|
2015-09-30 02:56:11 +02:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
Quaternion & Quaternion::operator += (Value s)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
x += s;
|
|
|
|
y += s;
|
|
|
|
z += s;
|
|
|
|
w += s;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2016-07-24 23:08:28 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
Quaternion & Quaternion::operator -= (Value s)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
x -= s;
|
|
|
|
y -= s;
|
|
|
|
z -= s;
|
|
|
|
w -= s;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2016-07-24 23:08:28 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
Quaternion & Quaternion::operator *= (Value s)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
x *= s;
|
|
|
|
y *= s;
|
|
|
|
z *= s;
|
|
|
|
w *= s;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2016-07-24 23:08:28 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
Quaternion & Quaternion::operator /= (Value s)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
x /= s;
|
|
|
|
y /= s;
|
|
|
|
z /= s;
|
|
|
|
w /= s;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2016-07-24 23:08:28 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
Quaternion & Quaternion::operator %= (Value s)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2021-01-30 07:51:39 +01:00
|
|
|
x = fmodf(x, s);
|
|
|
|
y = fmodf(y, s);
|
|
|
|
z = fmodf(z, s);
|
|
|
|
w = fmodf(w, s);
|
2015-09-30 02:56:11 +02:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
Quaternion & Quaternion::operator ++ ()
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
++x;
|
|
|
|
++y;
|
|
|
|
++z;
|
|
|
|
++w;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2016-07-24 23:08:28 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
Quaternion & Quaternion::operator -- ()
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
--x;
|
|
|
|
--y;
|
|
|
|
--z;
|
|
|
|
--w;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2020-03-22 08:16:40 +01:00
|
|
|
Quaternion Quaternion::operator ++ (int) // NOLINT(cert-dcl21-cpp)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
Quaternion state(*this);
|
|
|
|
++x;
|
|
|
|
++y;
|
|
|
|
++z;
|
|
|
|
++w;
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
2016-07-24 23:08:28 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2020-03-22 08:16:40 +01:00
|
|
|
Quaternion Quaternion::operator -- (int) // NOLINT(cert-dcl21-cpp)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
Quaternion state(*this);
|
|
|
|
--x;
|
|
|
|
--y;
|
|
|
|
--z;
|
|
|
|
--w;
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
Quaternion Quaternion::operator + (const Quaternion & q) const
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2020-03-22 08:16:40 +01:00
|
|
|
return {x + q.x, y + q.y, z + q.z, w + q.w};
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2016-07-24 23:08:28 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
Quaternion Quaternion::operator + (Value s) const
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2020-03-22 08:16:40 +01:00
|
|
|
return {x + s, y + s, z + s, w + s};
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
Quaternion Quaternion::operator - (const Quaternion & q) const
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2020-03-22 08:16:40 +01:00
|
|
|
return {x - q.x, y - q.y, z - q.z, w - q.w};
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2016-07-24 23:08:28 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
Quaternion Quaternion::operator - (Value s) const
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2020-03-22 08:16:40 +01:00
|
|
|
return {x - s, y - s, z - s, w - s};
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
Quaternion Quaternion::operator * (const Quaternion & q) const
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2020-03-22 08:16:40 +01:00
|
|
|
return {x * q.x, y * q.y, z * q.z, w * q.w};
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2016-07-24 23:08:28 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
Quaternion Quaternion::operator * (Value s) const
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2020-03-22 08:16:40 +01:00
|
|
|
return {x * s, y * s, z * s, w * s};
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
Quaternion Quaternion::operator / (const Quaternion & q) const
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2020-03-22 08:16:40 +01:00
|
|
|
return {x / q.x, y / q.y, z / q.z, w / q.w};
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2016-07-24 23:08:28 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
Quaternion Quaternion::operator / (Value s) const
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2020-03-22 08:16:40 +01:00
|
|
|
return {x / s, y / s, z / s, w / s};
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
Quaternion Quaternion::operator % (const Quaternion & q) const
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2021-01-30 07:51:39 +01:00
|
|
|
return {fmodf(x, q.x), fmodf(y, q.y), fmodf(z, q.z), fmodf(w, q.w)};
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2016-07-24 23:08:28 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
Quaternion Quaternion::operator % (Value s) const
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2021-01-30 07:51:39 +01:00
|
|
|
return {fmodf(x, s), fmodf(y, s), fmodf(z, s), fmodf(w, s)};
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
Quaternion Quaternion::operator + () const
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2021-01-30 07:51:39 +01:00
|
|
|
return {fabsf(x), fabsf(y), fabsf(z), fabsf(w)};
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2016-07-24 23:08:28 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
Quaternion Quaternion::operator - () const
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2020-03-22 08:16:40 +01:00
|
|
|
return {-x, -y, -z, -w};
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
bool Quaternion::operator == (const Quaternion & q) const
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
return EpsEq(x, q.x) && EpsEq(y, q.y) && EpsEq(z, q.z) && EpsEq(w, q.w);
|
|
|
|
}
|
|
|
|
|
2016-07-24 23:08:28 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
bool Quaternion::operator != (const Quaternion & q) const
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2016-07-29 17:00:10 +02:00
|
|
|
return !EpsEq(x, q.x) || !EpsEq(y, q.y) || !EpsEq(z, q.z) || !EpsEq(w, q.w);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2016-07-24 23:08:28 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
bool Quaternion::operator < (const Quaternion & q) const
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2016-02-20 23:25:00 +01:00
|
|
|
return EpsLt(x, q.x) && EpsLt(y, q.y) && EpsLt(z, q.z) && EpsLt(w, q.w);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2016-07-24 23:08:28 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
bool Quaternion::operator > (const Quaternion & q) const
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2016-02-20 23:25:00 +01:00
|
|
|
return EpsGt(x, q.x) && EpsGt(y, q.y) && EpsGt(z, q.z) && EpsGt(w, q.w);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2016-07-24 23:08:28 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
bool Quaternion::operator <= (const Quaternion & q) const
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2016-02-20 23:25:00 +01:00
|
|
|
return EpsLtEq(x, q.x) && EpsLtEq(y, q.y) && EpsLtEq(z, q.z) && EpsLtEq(w, q.w);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2016-07-24 23:08:28 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
bool Quaternion::operator >= (const Quaternion & q) const
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2016-02-20 23:25:00 +01:00
|
|
|
return EpsGtEq(x, q.x) && EpsGtEq(y, q.y) && EpsGtEq(z, q.z) && EpsGtEq(w, q.w);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2021-01-30 07:51:39 +01:00
|
|
|
int32_t Quaternion::Cmp(const Quaternion & o) const
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2016-02-20 23:25:00 +01:00
|
|
|
if (*this == o)
|
2016-05-22 05:20:38 +02:00
|
|
|
{
|
2016-02-20 23:25:00 +01:00
|
|
|
return 0;
|
2016-05-22 05:20:38 +02:00
|
|
|
}
|
2016-02-20 23:25:00 +01:00
|
|
|
else if (*this > o)
|
2016-05-22 05:20:38 +02:00
|
|
|
{
|
2016-02-20 23:25:00 +01:00
|
|
|
return 1;
|
2016-05-22 05:20:38 +02:00
|
|
|
}
|
2016-02-20 23:25:00 +01:00
|
|
|
else
|
2016-05-22 05:20:38 +02:00
|
|
|
{
|
2016-02-20 23:25:00 +01:00
|
|
|
return -1;
|
2016-05-22 05:20:38 +02:00
|
|
|
}
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2021-01-30 07:51:39 +01:00
|
|
|
String Quaternion::ToString() const
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2021-01-30 07:51:39 +01:00
|
|
|
return fmt::format("{},{},{},{}", x, y, z, w);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2022-09-18 14:02:39 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void Quaternion::ToJSON(CtxJSON & ctx) const
|
|
|
|
{
|
|
|
|
if (ctx.mObjectOverArray)
|
|
|
|
{
|
|
|
|
fmt::format_to(std::back_inserter(ctx.mOutput), "{{x:{},y:{},z:{},w:{}}},", x, y, z, w);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fmt::format_to(std::back_inserter(ctx.mOutput), "[{},{},{},{}],", x, y, z, w);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-30 02:56:11 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-07-24 23:08:28 +02:00
|
|
|
void Quaternion::SetScalar(Value ns)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
x = ns;
|
|
|
|
y = ns;
|
|
|
|
z = ns;
|
|
|
|
w = ns;
|
|
|
|
}
|
|
|
|
|
2016-07-24 23:08:28 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void Quaternion::SetQuaternion(const Quaternion & q)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2016-07-24 23:08:28 +02:00
|
|
|
x = q.x;
|
|
|
|
y = q.y;
|
|
|
|
z = q.z;
|
|
|
|
w = q.w;
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2016-07-24 23:08:28 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void Quaternion::SetQuaternionEx(Value nx, Value ny, Value nz, Value nw)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
x = nx;
|
|
|
|
y = ny;
|
|
|
|
z = nz;
|
|
|
|
w = nw;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-07-24 23:08:28 +02:00
|
|
|
void Quaternion::SetVector3(const Vector3 & v)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2016-08-23 22:02:19 +02:00
|
|
|
SetVector3Ex(v.x, v.y, v.z);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2016-07-24 23:08:28 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void Quaternion::SetVector3Ex(Value nx, Value ny, Value nz)
|
|
|
|
{
|
2021-01-30 07:51:39 +01:00
|
|
|
double angle;
|
2016-08-23 22:02:19 +02:00
|
|
|
|
|
|
|
angle = (nx * 0.5);
|
2021-01-30 07:51:39 +01:00
|
|
|
const double sr = sin(angle);
|
|
|
|
const double cr = cos(angle);
|
2016-08-23 22:02:19 +02:00
|
|
|
|
|
|
|
angle = (ny * 0.5);
|
2021-01-30 07:51:39 +01:00
|
|
|
const double sp = sin(angle);
|
|
|
|
const double cp = cos(angle);
|
2016-08-23 22:02:19 +02:00
|
|
|
|
|
|
|
angle = (nz * 0.5);
|
2021-01-30 07:51:39 +01:00
|
|
|
const double sy = sin(angle);
|
|
|
|
const double cy = cos(angle);
|
2016-08-23 22:02:19 +02:00
|
|
|
|
2021-01-30 07:51:39 +01:00
|
|
|
const double cpcy = (cp * cy);
|
|
|
|
const double spcy = (sp * cy);
|
|
|
|
const double cpsy = (cp * sy);
|
|
|
|
const double spsy = (sp * sy);
|
2016-08-23 22:02:19 +02:00
|
|
|
|
|
|
|
x = STOVAL(sr * cpcy - cr * spsy);
|
|
|
|
y = STOVAL(cr * spcy + sr * cpsy);
|
|
|
|
z = STOVAL(cr * cpsy - sr * spcy);
|
|
|
|
w = STOVAL(cr * cpcy + sr * spsy);
|
|
|
|
|
|
|
|
Normalize();
|
2016-07-24 23:08:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void Quaternion::SetVector4(const Vector4 & v)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
x = v.x;
|
|
|
|
y = v.y;
|
|
|
|
z = v.z;
|
|
|
|
w = v.w;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2019-02-17 16:23:59 +01:00
|
|
|
void Quaternion::SetStr(SQChar delim, StackStrF & values)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2016-11-16 15:19:13 +01:00
|
|
|
SetQuaternion(Quaternion::GetEx(delim, values));
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2021-03-20 16:56:38 +01:00
|
|
|
Quaternion & Quaternion::Generate()
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2016-02-20 23:25:00 +01:00
|
|
|
x = GetRandomFloat32();
|
|
|
|
y = GetRandomFloat32();
|
|
|
|
z = GetRandomFloat32();
|
|
|
|
w = GetRandomFloat32();
|
2021-03-20 16:56:38 +01:00
|
|
|
// Allow chaining
|
|
|
|
return *this;
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2016-07-24 23:08:28 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2021-03-20 16:56:38 +01:00
|
|
|
Quaternion & Quaternion::GenerateB(Value min, Value max)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2016-02-20 23:25:00 +01:00
|
|
|
if (EpsLt(max, min))
|
2016-05-22 05:20:38 +02:00
|
|
|
{
|
2016-03-21 21:37:58 +01:00
|
|
|
STHROWF("max value is lower than min value");
|
2016-05-22 05:20:38 +02:00
|
|
|
}
|
2016-03-10 04:57:13 +01:00
|
|
|
|
|
|
|
x = GetRandomFloat32(min, max);
|
|
|
|
y = GetRandomFloat32(min, max);
|
|
|
|
z = GetRandomFloat32(min, max);
|
|
|
|
y = GetRandomFloat32(min, max);
|
2021-03-20 16:56:38 +01:00
|
|
|
// Allow chaining
|
|
|
|
return *this;
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2016-07-24 23:08:28 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2021-03-20 16:56:38 +01:00
|
|
|
Quaternion & Quaternion::GenerateR(Value xmin, Value xmax, Value ymin, Value ymax, Value zmin, Value zmax, Value wmin, Value wmax)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2016-02-20 23:25:00 +01:00
|
|
|
if (EpsLt(xmax, xmin) || EpsLt(ymax, ymin) || EpsLt(zmax, zmin) || EpsLt(wmax, wmin))
|
2016-05-22 05:20:38 +02:00
|
|
|
{
|
2016-03-21 21:37:58 +01:00
|
|
|
STHROWF("max value is lower than min value");
|
2016-05-22 05:20:38 +02:00
|
|
|
}
|
2016-03-10 04:57:13 +01:00
|
|
|
|
|
|
|
x = GetRandomFloat32(xmin, xmax);
|
|
|
|
y = GetRandomFloat32(ymin, ymax);
|
|
|
|
z = GetRandomFloat32(zmin, zmax);
|
|
|
|
y = GetRandomFloat32(ymin, ymax);
|
2021-03-20 16:56:38 +01:00
|
|
|
// Allow chaining
|
|
|
|
return *this;
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
Quaternion Quaternion::Abs() const
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2021-01-30 07:51:39 +01:00
|
|
|
return {fabsf(x), fabsf(y), fabsf(z), fabsf(w)};
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2016-08-23 22:02:19 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
bool Quaternion::IsNaN() const
|
|
|
|
{
|
2021-01-30 07:51:39 +01:00
|
|
|
return isnanf(w) || isnanf(x) || isnanf(y) || isnanf(z);
|
2016-08-23 22:02:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
Quaternion::Quaternion::Value Quaternion::LengthSquared() const
|
|
|
|
{
|
|
|
|
return (x * x) + (y * y) + (z * z) + (w * w);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
Quaternion::Value Quaternion::DotProduct(const Quaternion & quat) const
|
|
|
|
{
|
|
|
|
return (x * quat.x) + (y * quat.y) + (z * quat.z) + (w * quat.w);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
Quaternion Quaternion::Conjugate() const
|
|
|
|
{
|
2020-03-22 08:16:40 +01:00
|
|
|
return {-x, -y, -z, w};
|
2016-08-23 22:02:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void Quaternion::Normalize()
|
|
|
|
{
|
|
|
|
const Value len_squared = LengthSquared();
|
|
|
|
|
|
|
|
if (!EpsEq(len_squared, STOVAL(1.0)) && EpsGt(len_squared, STOVAL(0.0)))
|
|
|
|
{
|
2021-01-30 07:51:39 +01:00
|
|
|
const Value inv_len = STOVAL(1.0) / sqrtf(len_squared);
|
2016-08-23 22:02:19 +02:00
|
|
|
|
|
|
|
x *= inv_len;
|
|
|
|
y *= inv_len;
|
|
|
|
z *= inv_len;
|
|
|
|
w *= inv_len;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
Quaternion Quaternion::Normalized() const
|
|
|
|
{
|
|
|
|
const Value len_squared = LengthSquared();
|
|
|
|
|
|
|
|
if (!EpsEq(len_squared, STOVAL(1.0)) && EpsGt(len_squared, STOVAL(0.0)))
|
|
|
|
{
|
|
|
|
Value inv_len = 1.0f / sqrtf(len_squared);
|
|
|
|
|
|
|
|
return ((*this) * inv_len);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return (*this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void Quaternion::FromAngleAxis(Value angle, const Vector3 & axis)
|
|
|
|
{
|
|
|
|
const Vector3 norm_axis = axis.Normalized();
|
|
|
|
angle *= SQMOD_DEGTORAD_2;
|
2021-01-30 07:51:39 +01:00
|
|
|
const Value sin_angle = sinf(angle);
|
2016-08-23 22:02:19 +02:00
|
|
|
x = norm_axis.x * sin_angle;
|
|
|
|
y = norm_axis.y * sin_angle;
|
|
|
|
z = norm_axis.z * sin_angle;
|
2021-01-30 07:51:39 +01:00
|
|
|
w = cosf(angle);
|
2016-08-23 22:02:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void Quaternion::FromRotationTo(const Vector3 & start, const Vector3 & end)
|
|
|
|
{
|
|
|
|
const Vector3 norm_start = start.Normalized();
|
|
|
|
const Vector3 norm_end = end.Normalized();
|
|
|
|
const Value d = norm_start.DotProduct(norm_end);
|
|
|
|
|
|
|
|
if (EpsGt(d, STOVAL(-1.0)))
|
|
|
|
{
|
|
|
|
const Vector3 c = norm_start.CrossProduct(norm_end);
|
2021-01-30 07:51:39 +01:00
|
|
|
const Value s = sqrtf((STOVAL(1.0) + d) * STOVAL(2.0));
|
2016-08-23 22:02:19 +02:00
|
|
|
const Value inv_s = STOVAL(1.0) / s;
|
|
|
|
|
|
|
|
x = c.x * inv_s;
|
|
|
|
y = c.y * inv_s;
|
|
|
|
z = c.z * inv_s;
|
|
|
|
w = STOVAL(0.5) * s;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Vector3 axis = Vector3::RIGHT.CrossProduct(norm_start);
|
|
|
|
|
|
|
|
if (EpsLt(axis.GetLength(), STOVAL(0.0)))
|
|
|
|
{
|
|
|
|
FromAngleAxis(STOVAL(180), Vector3::UP.CrossProduct(norm_start));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
FromAngleAxis(STOVAL(180), axis);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
Quaternion Quaternion::Inverse() const
|
|
|
|
{
|
|
|
|
const Value len_squared = LengthSquared();
|
|
|
|
if (EpsEq(len_squared, STOVAL(1.0)))
|
|
|
|
{
|
|
|
|
return Conjugate();
|
|
|
|
}
|
|
|
|
else if (EpsGtEq(len_squared, STOVAL(0.0)))
|
|
|
|
{
|
|
|
|
return Conjugate() * (STOVAL(1.0) / len_squared);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return IDENTITY;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
Vector3 Quaternion::ToEuler() const
|
|
|
|
{
|
2021-01-30 07:51:39 +01:00
|
|
|
const double sqw = (w * w);
|
|
|
|
const double sqx = (x * x);
|
|
|
|
const double sqy = (y * y);
|
|
|
|
const double sqz = (z * z);
|
|
|
|
const double test = 2.0 * ((y * w) - (x * z));
|
2016-08-23 22:02:19 +02:00
|
|
|
|
|
|
|
if (EpsEq(test, 1.0))
|
|
|
|
{
|
2020-03-22 08:16:40 +01:00
|
|
|
return {
|
2016-08-23 22:02:19 +02:00
|
|
|
// bank = rotation about x-axis
|
|
|
|
STOVAL(0.0),
|
|
|
|
// attitude = rotation about y-axis
|
|
|
|
STOVAL(SQMOD_PI64 / 2.0),
|
|
|
|
// heading = rotation about z-axis
|
2021-01-30 07:51:39 +01:00
|
|
|
STOVAL(-2.0 * atan2f(x, w))
|
2020-03-22 08:16:40 +01:00
|
|
|
};
|
2016-08-23 22:02:19 +02:00
|
|
|
}
|
|
|
|
else if (EpsEq(test, -1.0))
|
|
|
|
{
|
2020-03-22 08:16:40 +01:00
|
|
|
return {
|
2016-08-23 22:02:19 +02:00
|
|
|
// bank = rotation about x-axis
|
|
|
|
STOVAL(0.0),
|
|
|
|
// attitude = rotation about y-axis
|
|
|
|
STOVAL(SQMOD_PI64 / -2.0),
|
|
|
|
// heading = rotation about z-axis
|
2021-01-30 07:51:39 +01:00
|
|
|
STOVAL(2.0 * atan2f(x, w))
|
2020-03-22 08:16:40 +01:00
|
|
|
};
|
2016-08-23 22:02:19 +02:00
|
|
|
}
|
|
|
|
|
2020-03-22 08:16:40 +01:00
|
|
|
return {
|
2016-08-23 22:02:19 +02:00
|
|
|
// bank = rotation about x-axis
|
2021-01-30 07:51:39 +01:00
|
|
|
STOVAL(atan2(2.0 * ((y * z) + (x * w)), (-sqx - sqy + sqz + sqw))),
|
2016-08-23 22:02:19 +02:00
|
|
|
// attitude = rotation about y-axis
|
2021-01-30 07:51:39 +01:00
|
|
|
STOVAL(asin(Clamp(test, -1.0, 1.0))),
|
2016-08-23 22:02:19 +02:00
|
|
|
// heading = rotation about z-axis
|
2021-01-30 07:51:39 +01:00
|
|
|
STOVAL(atan2(2.0 * ((x * y) + (z * w)), (sqx - sqy - sqz + sqw)))
|
2020-03-22 08:16:40 +01:00
|
|
|
};
|
2016-08-23 22:02:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
Quaternion::Value Quaternion::YawAngle() const
|
|
|
|
{
|
|
|
|
return ToEuler().y;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
Quaternion::Value Quaternion::PitchAngle() const
|
|
|
|
{
|
|
|
|
return ToEuler().x;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
Quaternion::Value Quaternion::RollAngle() const
|
|
|
|
{
|
|
|
|
return ToEuler().z;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
Quaternion Quaternion::Slerp(Quaternion quat, Value t) const
|
|
|
|
{
|
|
|
|
// Favor accuracy for native code builds
|
|
|
|
Value cos_angle = DotProduct(quat);
|
|
|
|
// Enable shortest path rotation
|
|
|
|
if (EpsLt(cos_angle, STOVAL(0.0)))
|
|
|
|
{
|
|
|
|
cos_angle = -cos_angle;
|
|
|
|
quat = -quat;
|
|
|
|
}
|
|
|
|
|
2021-01-30 07:51:39 +01:00
|
|
|
const Value angle = acosf(cos_angle);
|
|
|
|
Value sin_angle = sinf(angle);
|
2016-08-23 22:02:19 +02:00
|
|
|
Value t1, t2;
|
|
|
|
|
|
|
|
if (sin_angle > STOVAL(0.001))
|
|
|
|
{
|
|
|
|
Value inv_sin_angle = STOVAL(1.0) / sin_angle;
|
2021-01-30 07:51:39 +01:00
|
|
|
t1 = sinf((STOVAL(1.0) - t) * angle) * inv_sin_angle;
|
|
|
|
t2 = sinf(t * angle) * inv_sin_angle;
|
2016-08-23 22:02:19 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
t1 = STOVAL(1.0) - t;
|
|
|
|
t2 = t;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ((*this) * t1 + quat * t2);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
Quaternion Quaternion::Nlerp(const Quaternion & quat, Value t) const
|
|
|
|
{
|
|
|
|
return NlerpEx(quat, t, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
Quaternion Quaternion::NlerpEx(const Quaternion & quat, Value t, bool shortest_path) const
|
|
|
|
{
|
|
|
|
Quaternion result;
|
|
|
|
const Value fcos = DotProduct(quat);
|
|
|
|
if (EpsLt(fcos, STOVAL(0.0)) && shortest_path)
|
|
|
|
{
|
|
|
|
result = (*this) + (((-quat) - (*this)) * t);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
result = (*this) + ((quat - (*this)) * t);
|
|
|
|
}
|
|
|
|
result.Normalize();
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2016-03-21 21:37:58 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2019-02-17 16:23:59 +01:00
|
|
|
const Quaternion & Quaternion::Get(StackStrF & str)
|
2016-03-21 21:37:58 +01:00
|
|
|
{
|
2016-11-16 15:19:13 +01:00
|
|
|
return Quaternion::GetEx(Quaternion::Delim, str);
|
2016-03-21 21:37:58 +01:00
|
|
|
}
|
|
|
|
|
2020-09-03 19:33:51 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2021-01-30 07:51:39 +01:00
|
|
|
String Quaternion::Format(StackStrF & str) const
|
2020-09-03 19:33:51 +02:00
|
|
|
{
|
2021-07-03 13:09:58 +02:00
|
|
|
return fmt::format(fmt::runtime(str.ToStr())
|
2021-01-30 07:51:39 +01:00
|
|
|
, fmt::arg("x", x)
|
|
|
|
, fmt::arg("y", y)
|
|
|
|
, fmt::arg("z", z)
|
|
|
|
, fmt::arg("w", w)
|
|
|
|
);
|
2020-09-03 19:33:51 +02:00
|
|
|
}
|
|
|
|
|
2016-03-21 21:37:58 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2019-02-17 16:23:59 +01:00
|
|
|
const Quaternion & Quaternion::GetEx(SQChar delim, StackStrF & str)
|
2016-03-21 21:37:58 +01:00
|
|
|
{
|
|
|
|
static Quaternion quat;
|
|
|
|
// Clear previous values, if any
|
|
|
|
quat.Clear();
|
|
|
|
// Is the specified string empty?
|
2016-11-16 15:19:13 +01:00
|
|
|
if (str.mLen <= 0)
|
2016-03-21 21:37:58 +01:00
|
|
|
{
|
|
|
|
return quat; // Return the value as is!
|
|
|
|
}
|
2020-09-03 17:26:24 +02:00
|
|
|
// The format specifications that will be used to scan the string
|
|
|
|
SQChar fs[] = _SC(" %f , %f , %f , %f ");
|
2016-03-21 21:37:58 +01:00
|
|
|
// Assign the specified delimiter
|
|
|
|
fs[4] = delim;
|
|
|
|
fs[9] = delim;
|
|
|
|
fs[14] = delim;
|
|
|
|
// Attempt to extract the component values from the specified string
|
2016-11-16 15:19:13 +01:00
|
|
|
std::sscanf(str.mPtr, fs, &quat.x, &quat.y, &quat.z, &quat.w);
|
2016-03-21 21:37:58 +01:00
|
|
|
// Return the resulted value
|
|
|
|
return quat;
|
|
|
|
}
|
|
|
|
|
2015-09-30 02:56:11 +02:00
|
|
|
// ================================================================================================
|
2016-02-20 23:25:00 +01:00
|
|
|
void Register_Quaternion(HSQUIRRELVM vm)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
typedef Quaternion::Value Val;
|
|
|
|
|
2016-11-15 20:55:03 +01:00
|
|
|
RootTable(vm).Bind(Typename::Str,
|
|
|
|
Class< Quaternion >(vm, Typename::Str)
|
2016-05-22 05:20:38 +02:00
|
|
|
// Constructors
|
2015-09-30 02:56:11 +02:00
|
|
|
.Ctor()
|
2016-02-20 23:25:00 +01:00
|
|
|
.Ctor< Val >()
|
|
|
|
.Ctor< Val, Val, Val >()
|
|
|
|
.Ctor< Val, Val, Val, Val >()
|
2016-05-22 05:20:38 +02:00
|
|
|
// Member Variables
|
2016-07-17 14:39:59 +02:00
|
|
|
.Var(_SC("x"), &Quaternion::x)
|
|
|
|
.Var(_SC("y"), &Quaternion::y)
|
|
|
|
.Var(_SC("z"), &Quaternion::z)
|
|
|
|
.Var(_SC("w"), &Quaternion::w)
|
2016-05-22 05:20:38 +02:00
|
|
|
.Var(_SC("X"), &Quaternion::x)
|
|
|
|
.Var(_SC("Y"), &Quaternion::y)
|
|
|
|
.Var(_SC("Z"), &Quaternion::z)
|
|
|
|
.Var(_SC("W"), &Quaternion::w)
|
2016-06-03 20:26:19 +02:00
|
|
|
// Core Meta-methods
|
2016-08-24 22:17:29 +02:00
|
|
|
.SquirrelFunc(_SC("cmp"), &SqDynArgFwd< SqDynArgCmpFn< Quaternion >, SQFloat, SQInteger, bool, std::nullptr_t, Quaternion >)
|
2016-11-15 20:20:42 +01:00
|
|
|
.SquirrelFunc(_SC("_typename"), &Typename::Fn)
|
|
|
|
.Func(_SC("_tostring"), &Quaternion::ToString)
|
2022-09-18 14:02:39 +02:00
|
|
|
.Func(_SC("_tojson"), &Quaternion::ToJSON)
|
2016-06-03 20:26:19 +02:00
|
|
|
// Meta-methods
|
2016-08-24 22:17:29 +02:00
|
|
|
.SquirrelFunc(_SC("_add"), &SqDynArgFwd< SqDynArgAddFn< Quaternion >, SQFloat, SQInteger, bool, std::nullptr_t, Quaternion >)
|
|
|
|
.SquirrelFunc(_SC("_sub"), &SqDynArgFwd< SqDynArgSubFn< Quaternion >, SQFloat, SQInteger, bool, std::nullptr_t, Quaternion >)
|
|
|
|
.SquirrelFunc(_SC("_mul"), &SqDynArgFwd< SqDynArgMulFn< Quaternion >, SQFloat, SQInteger, bool, std::nullptr_t, Quaternion >)
|
|
|
|
.SquirrelFunc(_SC("_div"), &SqDynArgFwd< SqDynArgDivFn< Quaternion >, SQFloat, SQInteger, bool, std::nullptr_t, Quaternion >)
|
|
|
|
.SquirrelFunc(_SC("_modulo"), &SqDynArgFwd< SqDynArgModFn< Quaternion >, SQFloat, SQInteger, bool, std::nullptr_t, Quaternion >)
|
2016-05-22 05:20:38 +02:00
|
|
|
.Func< Quaternion (Quaternion::*)(void) const >(_SC("_unm"), &Quaternion::operator -)
|
2016-07-24 23:08:28 +02:00
|
|
|
// Properties
|
|
|
|
.Prop(_SC("Abs"), &Quaternion::Abs)
|
2016-08-23 22:02:19 +02:00
|
|
|
.Prop(_SC("NaN"), &Quaternion::IsNaN)
|
|
|
|
.Prop(_SC("LengthSq"), &Quaternion::LengthSquared)
|
|
|
|
.Prop(_SC("Conjugate"), &Quaternion::Conjugate)
|
|
|
|
.Prop(_SC("Normalized"), &Quaternion::Normalized)
|
|
|
|
.Prop(_SC("Inverse"), &Quaternion::Inverse)
|
|
|
|
.Prop(_SC("Euler"), &Quaternion::ToEuler, &Quaternion::SetVector3)
|
|
|
|
.Prop(_SC("YawAngle"), &Quaternion::YawAngle)
|
|
|
|
.Prop(_SC("PitchAngle"), &Quaternion::PitchAngle)
|
|
|
|
.Prop(_SC("RollAngle"), &Quaternion::RollAngle)
|
2016-07-24 23:08:28 +02:00
|
|
|
// Member Methods
|
|
|
|
.Func(_SC("SetScalar"), &Quaternion::SetScalar)
|
|
|
|
.Func(_SC("SetQuaternion"), &Quaternion::SetQuaternion)
|
|
|
|
.Func(_SC("SetQuaternionEx"), &Quaternion::SetQuaternionEx)
|
|
|
|
.Func(_SC("SetVector3"), &Quaternion::SetVector3)
|
|
|
|
.Func(_SC("SetVector3Ex"), &Quaternion::SetVector3Ex)
|
|
|
|
.Func(_SC("SetVector4"), &Quaternion::SetVector4)
|
2016-11-16 15:19:13 +01:00
|
|
|
.FmtFunc(_SC("SetStr"), &Quaternion::SetStr)
|
2016-07-24 23:08:28 +02:00
|
|
|
.Func(_SC("Clear"), &Quaternion::Clear)
|
2020-09-03 19:33:51 +02:00
|
|
|
.FmtFunc(_SC("Format"), &Quaternion::Format)
|
2016-08-23 22:02:19 +02:00
|
|
|
.Func(_SC("DotProduct"), &Quaternion::DotProduct)
|
|
|
|
.Func(_SC("Normalize"), &Quaternion::Normalize)
|
|
|
|
.Func(_SC("FromAngleAxis"), &Quaternion::FromAngleAxis)
|
|
|
|
.Func(_SC("FromRotationTo"), &Quaternion::FromRotationTo)
|
|
|
|
.Func(_SC("Slerp"), &Quaternion::Slerp)
|
|
|
|
.Func(_SC("Nlerp"), &Quaternion::Nlerp)
|
|
|
|
.Func(_SC("NlerpEx"), &Quaternion::NlerpEx)
|
2016-07-24 23:08:28 +02:00
|
|
|
// Member Overloads
|
2021-03-20 16:56:38 +01:00
|
|
|
.Overload(_SC("Generate"), &Quaternion::Generate)
|
|
|
|
.Overload(_SC("Generate"), &Quaternion::GenerateB)
|
|
|
|
.Overload(_SC("Generate"), &Quaternion::GenerateR)
|
2016-07-24 20:29:37 +02:00
|
|
|
// Static Functions
|
|
|
|
.StaticFunc(_SC("GetDelimiter"), &SqGetDelimiter< Quaternion >)
|
|
|
|
.StaticFunc(_SC("SetDelimiter"), &SqSetDelimiter< Quaternion >)
|
2016-11-16 15:19:13 +01:00
|
|
|
.StaticFmtFunc(_SC("FromStr"), &Quaternion::Get)
|
|
|
|
.StaticFmtFunc(_SC("FromStrEx"), &Quaternion::GetEx)
|
2015-09-30 02:56:11 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-03-22 01:05:50 +01:00
|
|
|
} // Namespace:: SqMod
|