2016-02-20 23:25:00 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-09-30 02:56:11 +02:00
|
|
|
#include "Base/Vector4.hpp"
|
|
|
|
#include "Base/Vector3.hpp"
|
|
|
|
#include "Base/Quaternion.hpp"
|
2016-08-24 22:18:19 +02:00
|
|
|
#include "Base/DynArg.hpp"
|
2021-01-30 07:51:39 +01:00
|
|
|
#include "Core/Buffer.hpp"
|
|
|
|
#include "Core/Utility.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-11-15 20:21:31 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2021-01-30 07:51:39 +01:00
|
|
|
SQMOD_DECL_TYPENAME(Typename, _SC("Vector4"))
|
2016-11-15 20:21:31 +01:00
|
|
|
|
2015-09-30 02:56:11 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
const Vector4 Vector4::NIL = Vector4(0);
|
2016-03-22 01:05:50 +01:00
|
|
|
const Vector4 Vector4::MIN = Vector4(std::numeric_limits< Vector4::Value >::min());
|
|
|
|
const Vector4 Vector4::MAX = Vector4(std::numeric_limits< Vector4::Value >::max());
|
2015-09-30 02:56:11 +02:00
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
SQChar Vector4::Delim = ',';
|
|
|
|
|
2016-02-20 23:25:00 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2020-03-22 08:16:40 +01:00
|
|
|
Vector4::Vector4(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
|
|
|
Vector4::Vector4(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
|
|
|
Vector4::Vector4(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
|
|
|
Vector4 & Vector4::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:28:37 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
Vector4 & Vector4::operator = (const Vector3 & v)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
x = v.x;
|
|
|
|
y = v.y;
|
|
|
|
z = v.z;
|
|
|
|
w = 0.0;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2016-07-24 23:28:37 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
Vector4 & Vector4::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;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
Vector4 & Vector4::operator += (const Vector4 & v)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
x += v.x;
|
|
|
|
y += v.y;
|
|
|
|
z += v.z;
|
|
|
|
w += v.w;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2016-07-24 23:28:37 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
Vector4 & Vector4::operator -= (const Vector4 & v)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
x -= v.x;
|
|
|
|
y -= v.y;
|
|
|
|
z -= v.z;
|
|
|
|
w -= v.w;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2016-07-24 23:28:37 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
Vector4 & Vector4::operator *= (const Vector4 & v)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
x *= v.x;
|
|
|
|
y *= v.y;
|
|
|
|
z *= v.z;
|
|
|
|
w *= v.w;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2016-07-24 23:28:37 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
Vector4 & Vector4::operator /= (const Vector4 & v)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
x /= v.x;
|
|
|
|
y /= v.y;
|
|
|
|
z /= v.z;
|
|
|
|
w /= v.w;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2016-07-24 23:28:37 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
Vector4 & Vector4::operator %= (const Vector4 & v)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2021-01-30 07:51:39 +01:00
|
|
|
x = fmodf(x, v.x);
|
|
|
|
y = fmodf(y, v.y);
|
|
|
|
z = fmodf(z, v.z);
|
|
|
|
w = fmodf(w, v.w);
|
2015-09-30 02:56:11 +02:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
Vector4 & Vector4::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:28:37 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
Vector4 & Vector4::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:28:37 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
Vector4 & Vector4::operator *= (Value s)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
x *= s;
|
|
|
|
y *= s;
|
|
|
|
z *= s;
|
|
|
|
w *= s;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2015-11-01 04:48:01 +01:00
|
|
|
Vector4 & Vector4::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:28:37 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
Vector4 & Vector4::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
|
|
|
Vector4 & Vector4::operator ++ ()
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
++x;
|
|
|
|
++y;
|
|
|
|
++z;
|
|
|
|
++w;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2016-07-24 23:28:37 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
Vector4 & Vector4::operator -- ()
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
--x;
|
|
|
|
--y;
|
|
|
|
--z;
|
|
|
|
--w;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2020-03-22 08:16:40 +01:00
|
|
|
Vector4 Vector4::operator ++ (int) // NOLINT(cert-dcl21-cpp)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
Vector4 state(*this);
|
|
|
|
++x;
|
|
|
|
++y;
|
|
|
|
++z;
|
|
|
|
++w;
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
2016-07-24 23:28:37 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2020-03-22 08:16:40 +01:00
|
|
|
Vector4 Vector4::operator -- (int) // NOLINT(cert-dcl21-cpp)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
Vector4 state(*this);
|
|
|
|
--x;
|
|
|
|
--y;
|
|
|
|
--z;
|
|
|
|
--w;
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
Vector4 Vector4::operator + (const Vector4 & v) const
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2020-03-22 08:16:40 +01:00
|
|
|
return {x + v.x, y + v.y, z + v.z, w + v.w};
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2016-07-24 23:28:37 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
Vector4 Vector4::operator - (const Vector4 & v) const
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2020-03-22 08:16:40 +01:00
|
|
|
return {x - v.x, y - v.y, z - v.z, w - v.w};
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2016-07-24 23:28:37 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
Vector4 Vector4::operator * (const Vector4 & v) const
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2020-03-22 08:16:40 +01:00
|
|
|
return {x * v.x, y * v.y, z * v.z, w * v.w};
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2016-07-24 23:28:37 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
Vector4 Vector4::operator / (const Vector4 & v) const
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2020-03-22 08:16:40 +01:00
|
|
|
return {x / v.x, y / v.y, z / v.z, w / v.w};
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2016-07-24 23:28:37 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
Vector4 Vector4::operator % (const Vector4 & v) const
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2021-01-30 07:51:39 +01:00
|
|
|
return {fmodf(x, v.x), fmodf(y, v.y), fmodf(z, v.z), fmodf(w, v.w)};
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
Vector4 Vector4::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
|
|
|
}
|
|
|
|
|
2016-07-24 23:28:37 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
Vector4 Vector4::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
|
|
|
}
|
|
|
|
|
2016-07-24 23:28:37 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
Vector4 Vector4::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
|
|
|
}
|
|
|
|
|
2016-07-24 23:28:37 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
Vector4 Vector4::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
|
|
|
}
|
|
|
|
|
2016-07-24 23:28:37 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
Vector4 Vector4::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
|
|
|
Vector4 Vector4::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:28:37 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
Vector4 Vector4::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 Vector4::operator == (const Vector4 & v) const
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
return EpsEq(x, v.x) && EpsEq(y, v.y) && EpsEq(z, v.z) && EpsEq(w, v.w);
|
|
|
|
}
|
|
|
|
|
2016-07-24 23:28:37 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
bool Vector4::operator != (const Vector4 & v) const
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2016-07-29 17:00:10 +02:00
|
|
|
return !EpsEq(x, v.x) || !EpsEq(y, v.y) || !EpsEq(z, v.z) || !EpsEq(w, v.w);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2016-07-24 23:28:37 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
bool Vector4::operator < (const Vector4 & v) const
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2016-02-20 23:25:00 +01:00
|
|
|
return EpsLt(x, v.x) && EpsLt(y, v.y) && EpsLt(z, v.z) && EpsLt(w, v.w);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2016-07-24 23:28:37 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
bool Vector4::operator > (const Vector4 & v) const
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2016-02-20 23:25:00 +01:00
|
|
|
return EpsGt(x, v.x) && EpsGt(y, v.y) && EpsGt(z, v.z) && EpsGt(w, v.w);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2016-07-24 23:28:37 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
bool Vector4::operator <= (const Vector4 & v) const
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2016-02-20 23:25:00 +01:00
|
|
|
return EpsLtEq(x, v.x) && EpsLtEq(y, v.y) && EpsLtEq(z, v.z) && EpsLtEq(w, v.w);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2016-07-24 23:28:37 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
bool Vector4::operator >= (const Vector4 & v) const
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2016-02-20 23:25:00 +01:00
|
|
|
return EpsGtEq(x, v.x) && EpsGtEq(y, v.y) && EpsGtEq(z, v.z) && EpsGtEq(w, v.w);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2021-01-30 07:51:39 +01:00
|
|
|
int32_t Vector4::Cmp(const Vector4 & 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 Vector4::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
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-07-24 23:28:37 +02:00
|
|
|
void Vector4::SetScalar(Value ns)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
x = ns;
|
|
|
|
y = ns;
|
|
|
|
z = ns;
|
|
|
|
w = ns;
|
|
|
|
}
|
|
|
|
|
2016-07-24 23:28:37 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void Vector4::SetVector4(const Vector4 & v)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2016-07-24 23:28:37 +02:00
|
|
|
x = v.x;
|
|
|
|
y = v.y;
|
|
|
|
z = v.z;
|
|
|
|
w = v.w;
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2016-07-24 23:28:37 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void Vector4::SetVector4Ex(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:28:37 +02:00
|
|
|
void Vector4::SetVector3(const Vector3 & v)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
x = v.x;
|
|
|
|
y = v.y;
|
|
|
|
z = v.z;
|
2016-07-24 23:28:37 +02:00
|
|
|
w = 0.0;
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2016-07-24 23:28:37 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void Vector4::SetVector3Ex(Value nx, Value ny, Value nz)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2016-07-24 23:28:37 +02:00
|
|
|
x = nx;
|
|
|
|
y = ny;
|
|
|
|
z = nz;
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2016-07-24 23:28:37 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void Vector4::SetQuaternion(const Quaternion & q)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
x = q.x;
|
|
|
|
y = q.y;
|
|
|
|
z = q.z;
|
|
|
|
w = q.w;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-07-24 23:28:37 +02:00
|
|
|
void Vector4::SetQuaternionEx(Value nx, Value ny, Value nz, Value nw)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2016-07-24 23:28:37 +02:00
|
|
|
x = nx;
|
|
|
|
y = ny;
|
|
|
|
z = nz;
|
|
|
|
w = nw;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2019-02-17 16:23:59 +01:00
|
|
|
void Vector4::SetStr(SQChar delim, StackStrF & values)
|
2016-07-24 23:28:37 +02:00
|
|
|
{
|
2016-11-16 15:20:11 +01:00
|
|
|
SetVector4(Vector4::GetEx(delim, values));
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2021-03-20 16:56:38 +01:00
|
|
|
Vector4 & Vector4::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:28:37 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2021-03-20 16:56:38 +01:00
|
|
|
Vector4 & Vector4::GenerateB(Value min, Value max)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
if (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:28:37 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2021-03-20 16:56:38 +01:00
|
|
|
Vector4 & Vector4::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
|
|
|
Vector4 Vector4::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-03-21 21:37:58 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2019-02-17 16:23:59 +01:00
|
|
|
const Vector4 & Vector4::Get(StackStrF & str)
|
2016-03-21 21:37:58 +01:00
|
|
|
{
|
2016-11-16 15:20:11 +01:00
|
|
|
return Vector4::GetEx(Vector4::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 Vector4::Format(StackStrF & str) const
|
2020-09-03 19:33:51 +02:00
|
|
|
{
|
2021-01-30 07:51:39 +01:00
|
|
|
return fmt::format(str.ToStr()
|
|
|
|
, 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 Vector4 & Vector4::GetEx(SQChar delim, StackStrF & str)
|
2016-03-21 21:37:58 +01:00
|
|
|
{
|
|
|
|
static Vector4 vec;
|
|
|
|
// Clear previous values, if any
|
|
|
|
vec.Clear();
|
|
|
|
// Is the specified string empty?
|
2016-11-16 15:20:11 +01:00
|
|
|
if (str.mLen <= 0)
|
2016-03-21 21:37:58 +01:00
|
|
|
{
|
|
|
|
return vec; // 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:20:11 +01:00
|
|
|
std::sscanf(str.mPtr, &fs[0], &vec.x, &vec.y, &vec.z, &vec.w);
|
2016-03-21 21:37:58 +01:00
|
|
|
// Return the resulted value
|
|
|
|
return vec;
|
|
|
|
}
|
|
|
|
|
2015-09-30 02:56:11 +02:00
|
|
|
// ================================================================================================
|
2016-02-20 23:25:00 +01:00
|
|
|
void Register_Vector4(HSQUIRRELVM vm)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
typedef Vector4::Value Val;
|
|
|
|
|
2016-11-15 20:55:03 +01:00
|
|
|
RootTable(vm).Bind(Typename::Str,
|
|
|
|
Class< Vector4 >(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
|
2015-09-30 02:56:11 +02:00
|
|
|
.Var(_SC("x"), &Vector4::x)
|
|
|
|
.Var(_SC("y"), &Vector4::y)
|
|
|
|
.Var(_SC("z"), &Vector4::z)
|
|
|
|
.Var(_SC("w"), &Vector4::w)
|
2016-07-17 14:39:59 +02:00
|
|
|
.Var(_SC("X"), &Vector4::x)
|
|
|
|
.Var(_SC("Y"), &Vector4::y)
|
|
|
|
.Var(_SC("Z"), &Vector4::z)
|
|
|
|
.Var(_SC("W"), &Vector4::w)
|
2016-06-03 20:26:19 +02:00
|
|
|
// Core Meta-methods
|
2016-08-24 22:18:19 +02:00
|
|
|
.SquirrelFunc(_SC("cmp"), &SqDynArgFwd< SqDynArgCmpFn< Vector4 >, SQFloat, SQInteger, bool, std::nullptr_t, Vector4 >)
|
2016-11-15 20:21:31 +01:00
|
|
|
.SquirrelFunc(_SC("_typename"), &Typename::Fn)
|
|
|
|
.Func(_SC("_tostring"), &Vector4::ToString)
|
2016-06-03 20:26:19 +02:00
|
|
|
// Meta-methods
|
2016-08-24 22:18:19 +02:00
|
|
|
.SquirrelFunc(_SC("_add"), &SqDynArgFwd< SqDynArgAddFn< Vector4 >, SQFloat, SQInteger, bool, std::nullptr_t, Vector4 >)
|
|
|
|
.SquirrelFunc(_SC("_sub"), &SqDynArgFwd< SqDynArgSubFn< Vector4 >, SQFloat, SQInteger, bool, std::nullptr_t, Vector4 >)
|
|
|
|
.SquirrelFunc(_SC("_mul"), &SqDynArgFwd< SqDynArgMulFn< Vector4 >, SQFloat, SQInteger, bool, std::nullptr_t, Vector4 >)
|
|
|
|
.SquirrelFunc(_SC("_div"), &SqDynArgFwd< SqDynArgDivFn< Vector4 >, SQFloat, SQInteger, bool, std::nullptr_t, Vector4 >)
|
|
|
|
.SquirrelFunc(_SC("_modulo"), &SqDynArgFwd< SqDynArgModFn< Vector4 >, SQFloat, SQInteger, bool, std::nullptr_t, Vector4 >)
|
2016-05-22 05:20:38 +02:00
|
|
|
.Func< Vector4 (Vector4::*)(void) const >(_SC("_unm"), &Vector4::operator -)
|
2016-07-24 23:28:37 +02:00
|
|
|
// Properties
|
|
|
|
.Prop(_SC("Abs"), &Vector4::Abs)
|
|
|
|
// Member Methods
|
|
|
|
.Func(_SC("SetScalar"), &Vector4::SetScalar)
|
|
|
|
.Func(_SC("SetVector4"), &Vector4::SetVector4)
|
|
|
|
.Func(_SC("SetVector4Ex"), &Vector4::SetVector4Ex)
|
|
|
|
.Func(_SC("SetVector3"), &Vector4::SetVector3)
|
|
|
|
.Func(_SC("SetVector3Ex"), &Vector4::SetVector3Ex)
|
|
|
|
.Func(_SC("SetQuaternion"), &Vector4::SetQuaternion)
|
|
|
|
.Func(_SC("SetQuaternionEx"), &Vector4::SetQuaternionEx)
|
2016-11-16 15:20:11 +01:00
|
|
|
.FmtFunc(_SC("SetStr"), &Vector4::SetStr)
|
2016-07-24 23:28:37 +02:00
|
|
|
.Func(_SC("Clear"), &Vector4::Clear)
|
2020-09-03 19:33:51 +02:00
|
|
|
.FmtFunc(_SC("Format"), &Vector4::Format)
|
2016-07-24 23:28:37 +02:00
|
|
|
// Member Overloads
|
2021-03-20 16:56:38 +01:00
|
|
|
.Overload(_SC("Generate"), &Vector4::Generate)
|
|
|
|
.Overload(_SC("Generate"), &Vector4::GenerateB)
|
|
|
|
.Overload(_SC("Generate"), &Vector4::GenerateR)
|
2016-07-24 20:29:37 +02:00
|
|
|
// Static Functions
|
|
|
|
.StaticFunc(_SC("GetDelimiter"), &SqGetDelimiter< Vector4 >)
|
|
|
|
.StaticFunc(_SC("SetDelimiter"), &SqSetDelimiter< Vector4 >)
|
2016-11-16 15:20:11 +01:00
|
|
|
.StaticFmtFunc(_SC("FromStr"), &Vector4::Get)
|
|
|
|
.StaticFmtFunc(_SC("FromStrEx"), &Vector4::GetEx)
|
2015-09-30 02:56:11 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-03-22 01:05:50 +01:00
|
|
|
} // Namespace:: SqMod
|