mirror of
https://github.com/VCMP-SqMod/SqMod.git
synced 2025-07-22 16:57:12 +02:00
Dumped the old implementation. Started with a more simple approach.
This commit is contained in:
@@ -1,16 +1,17 @@
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Base/Vector3.hpp"
|
||||
#include "Base/Vector4.hpp"
|
||||
#include "Base/Quaternion.hpp"
|
||||
#include "Base/Shared.hpp"
|
||||
#include "Register.hpp"
|
||||
#include "Library/Random.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
const Vector3 Vector3::NIL = Vector3(0);
|
||||
const Vector3 Vector3::MIN = Vector3(std::numeric_limits<Vector3::Value>::min());
|
||||
const Vector3 Vector3::MAX = Vector3(std::numeric_limits<Vector3::Value>::max());
|
||||
const Vector3 Vector3::MIN = Vector3(NumLimit< Vector3::Value >::Min);
|
||||
const Vector3 Vector3::MAX = Vector3(NumLimit< Vector3::Value >::Max);
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
SQChar Vector3::Delim = ',';
|
||||
@@ -19,74 +20,42 @@ SQChar Vector3::Delim = ',';
|
||||
Vector3::Vector3()
|
||||
: x(0.0), y(0.0), z(0.0)
|
||||
{
|
||||
|
||||
/* ... */
|
||||
}
|
||||
|
||||
Vector3::Vector3(Value s)
|
||||
: x(s), y(s), z(s)
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Vector3::Vector3(Value sv)
|
||||
: x(sv), y(sv), z(sv)
|
||||
{
|
||||
|
||||
/* ... */
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Vector3::Vector3(Value xv, Value yv, Value zv)
|
||||
: x(xv), y(yv), z(zv)
|
||||
{
|
||||
|
||||
/* ... */
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Vector3::Vector3(const Vector4 & v)
|
||||
: x(v.x), y(v.y), z(v.z)
|
||||
Vector3::Vector3(const Vector3 & o)
|
||||
: x(o.x), y(o.y), z(o.z)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Vector3::Vector3(const Quaternion & q)
|
||||
: x(q.x), y(q.y), z(q.z)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Vector3::Vector3(const SQChar * values, char delim)
|
||||
: Vector3(GetVector3(values, delim))
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Vector3::Vector3(const Vector3 & v)
|
||||
: x(v.x), y(v.y), z(v.z)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Vector3::Vector3(Vector3 && v)
|
||||
: x(v.x), y(v.y), z(v.z)
|
||||
{
|
||||
|
||||
/* ... */
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Vector3::~Vector3()
|
||||
{
|
||||
|
||||
/* ... */
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Vector3 & Vector3::operator = (const Vector3 & v)
|
||||
Vector3 & Vector3::operator = (const Vector3 & o)
|
||||
{
|
||||
x = v.x;
|
||||
y = v.y;
|
||||
z = v.z;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Vector3 & Vector3::operator = (Vector3 && v)
|
||||
{
|
||||
x = v.x;
|
||||
y = v.y;
|
||||
z = v.z;
|
||||
x = o.x;
|
||||
y = o.y;
|
||||
z = o.z;
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -150,9 +119,9 @@ Vector3 & Vector3::operator /= (const Vector3 & v)
|
||||
|
||||
Vector3 & Vector3::operator %= (const Vector3 & v)
|
||||
{
|
||||
x = std::fmod(x, v.x);
|
||||
y = std::fmod(y, v.y);
|
||||
z = std::fmod(z, v.z);
|
||||
x = fmod(x, v.x);
|
||||
y = fmod(y, v.y);
|
||||
z = fmod(z, v.z);
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -191,9 +160,9 @@ Vector3 & Vector3::operator /= (Value s)
|
||||
|
||||
Vector3 & Vector3::operator %= (Value s)
|
||||
{
|
||||
x = std::fmod(x, s);
|
||||
y = std::fmod(y, s);
|
||||
z = std::fmod(z, s);
|
||||
x = fmod(x, s);
|
||||
y = fmod(y, s);
|
||||
z = fmod(z, s);
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -256,7 +225,7 @@ Vector3 Vector3::operator / (const Vector3 & v) const
|
||||
|
||||
Vector3 Vector3::operator % (const Vector3 & v) const
|
||||
{
|
||||
return Vector3(std::fmod(x, v.x), std::fmod(y, v.y), std::fmod(z, v.z));
|
||||
return Vector3(fmod(x, v.x), fmod(y, v.y), fmod(z, v.z));
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@@ -282,13 +251,13 @@ Vector3 Vector3::operator / (Value s) const
|
||||
|
||||
Vector3 Vector3::operator % (Value s) const
|
||||
{
|
||||
return Vector3(std::fmod(x, s), std::fmod(y, s), std::fmod(z, s));
|
||||
return Vector3(fmod(x, s), fmod(y, s), fmod(z, s));
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Vector3 Vector3::operator + () const
|
||||
{
|
||||
return Vector3(std::fabs(x), std::fabs(y), std::fabs(z));
|
||||
return Vector3(fabs(x), fabs(y), fabs(z));
|
||||
}
|
||||
|
||||
Vector3 Vector3::operator - () const
|
||||
@@ -309,32 +278,37 @@ bool Vector3::operator != (const Vector3 & v) const
|
||||
|
||||
bool Vector3::operator < (const Vector3 & v) const
|
||||
{
|
||||
return std::isless(x, v.x) && std::isless(y, v.y) && std::isless(z, v.z);
|
||||
return EpsLt(x, v.x) && EpsLt(y, v.y) && EpsLt(z, v.z);
|
||||
}
|
||||
|
||||
bool Vector3::operator > (const Vector3 & v) const
|
||||
{
|
||||
return std::isgreater(x, v.x) && std::isgreater(y, v.y) && std::isgreater(z, v.z);
|
||||
return EpsGt(x, v.x) && EpsGt(y, v.y) && EpsGt(z, v.z);
|
||||
}
|
||||
|
||||
bool Vector3::operator <= (const Vector3 & v) const
|
||||
{
|
||||
return std::islessequal(x, v.x) && std::islessequal(y, v.y) && std::islessequal(z, v.z);
|
||||
return EpsLtEq(x, v.x) && EpsLtEq(y, v.y) && EpsLtEq(z, v.z);
|
||||
}
|
||||
|
||||
bool Vector3::operator >= (const Vector3 & v) const
|
||||
{
|
||||
return std::isgreaterequal(x, v.x) && std::isgreaterequal(y, v.y) && std::isgreaterequal(z, v.z);
|
||||
return EpsGtEq(x, v.x) && EpsGtEq(y, v.y) && EpsGtEq(z, v.z);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
SQInteger Vector3::Cmp(const Vector3 & v) const
|
||||
Int32 Vector3::Cmp(const Vector3 & o) const
|
||||
{
|
||||
return *this == v ? 0 : (*this > v ? 1 : -1);
|
||||
if (*this == o)
|
||||
return 0;
|
||||
else if (*this > o)
|
||||
return 1;
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
const SQChar * Vector3::ToString() const
|
||||
CSStr Vector3::ToString() const
|
||||
{
|
||||
return ToStringF("%f,%f,%f", x, y, z);
|
||||
}
|
||||
@@ -377,7 +351,7 @@ void Vector3::Set(const Quaternion & q)
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void Vector3::Set(const SQChar * values, char delim)
|
||||
void Vector3::Set(CSStr values, SQChar delim)
|
||||
{
|
||||
Set(GetVector3(values, delim));
|
||||
}
|
||||
@@ -385,89 +359,87 @@ void Vector3::Set(const SQChar * values, char delim)
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void Vector3::Generate()
|
||||
{
|
||||
x = RandomVal<Value>::Get();
|
||||
y = RandomVal<Value>::Get();
|
||||
z = RandomVal<Value>::Get();
|
||||
x = GetRandomFloat32();
|
||||
y = GetRandomFloat32();
|
||||
z = GetRandomFloat32();
|
||||
}
|
||||
|
||||
void Vector3::Generate(Value min, Value max)
|
||||
{
|
||||
if (max < min)
|
||||
if (EpsLt(max, min))
|
||||
{
|
||||
LogErr("max value is lower than min value");
|
||||
SqThrow("max value is lower than min value");
|
||||
}
|
||||
else
|
||||
{
|
||||
x = RandomVal<Value>::Get(min, max);
|
||||
y = RandomVal<Value>::Get(min, max);
|
||||
z = RandomVal<Value>::Get(min, max);
|
||||
x = GetRandomFloat32(min, max);
|
||||
y = GetRandomFloat32(min, max);
|
||||
z = GetRandomFloat32(min, max);
|
||||
}
|
||||
}
|
||||
|
||||
void Vector3::Generate(Value xmin, Value xmax, Value ymin, Value ymax, Value zmin, Value zmax)
|
||||
{
|
||||
if (std::isless(xmax, xmin) || std::isless(ymax, ymin) || std::isless(zmax, zmin))
|
||||
if (EpsLt(xmax, xmin) || EpsLt(ymax, ymin) || EpsLt(zmax, zmin))
|
||||
{
|
||||
LogErr("max value is lower than min value");
|
||||
SqThrow("max value is lower than min value");
|
||||
}
|
||||
else
|
||||
{
|
||||
x = RandomVal<Value>::Get(xmin, xmax);
|
||||
y = RandomVal<Value>::Get(ymin, ymax);
|
||||
z = RandomVal<Value>::Get(zmin, zmax);
|
||||
x = GetRandomFloat32(xmin, xmax);
|
||||
y = GetRandomFloat32(ymin, ymax);
|
||||
z = GetRandomFloat32(zmin, zmax);
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Vector3 Vector3::Abs() const
|
||||
{
|
||||
return Vector3(std::fabs(x), std::fabs(y), std::fabs(z));
|
||||
return Vector3(fabs(x), fabs(y), fabs(z));
|
||||
}
|
||||
|
||||
// ================================================================================================
|
||||
bool Register_Vector3(HSQUIRRELVM vm)
|
||||
void Register_Vector3(HSQUIRRELVM vm)
|
||||
{
|
||||
LogDbg("Beginning registration of <Vector3> type");
|
||||
|
||||
typedef Vector3::Value Val;
|
||||
|
||||
Sqrat::RootTable(vm).Bind(_SC("Vector3"), Sqrat::Class<Vector3>(vm, _SC("Vector3"))
|
||||
RootTable(vm).Bind(_SC("Vector3"), Class< Vector3 >(vm, _SC("Vector3"))
|
||||
/* Constructors */
|
||||
.Ctor()
|
||||
.Ctor<Val>()
|
||||
.Ctor<Val, Val, Val>()
|
||||
.Ctor<const SQChar *, SQChar>()
|
||||
|
||||
.SetStaticValue(_SC("delim"), &Vector3::Delim)
|
||||
|
||||
.Ctor< Val >()
|
||||
.Ctor< Val, Val, Val >()
|
||||
/* Static Members */
|
||||
.SetStaticValue(_SC("Delim"), &Vector3::Delim)
|
||||
/* Member Variables */
|
||||
.Var(_SC("x"), &Vector3::x)
|
||||
.Var(_SC("y"), &Vector3::y)
|
||||
.Var(_SC("z"), &Vector3::z)
|
||||
|
||||
/* Properties */
|
||||
.Prop(_SC("abs"), &Vector3::Abs)
|
||||
|
||||
/* Core Metamethods */
|
||||
.Func(_SC("_tostring"), &Vector3::ToString)
|
||||
.Func(_SC("_cmp"), &Vector3::Cmp)
|
||||
|
||||
/* Metamethods */
|
||||
.Func<Vector3 (Vector3::*)(const Vector3 &) const>(_SC("_add"), &Vector3::operator +)
|
||||
.Func<Vector3 (Vector3::*)(const Vector3 &) const>(_SC("_sub"), &Vector3::operator -)
|
||||
.Func<Vector3 (Vector3::*)(const Vector3 &) const>(_SC("_mul"), &Vector3::operator *)
|
||||
.Func<Vector3 (Vector3::*)(const Vector3 &) const>(_SC("_div"), &Vector3::operator /)
|
||||
.Func<Vector3 (Vector3::*)(const Vector3 &) const>(_SC("_modulo"), &Vector3::operator %)
|
||||
.Func<Vector3 (Vector3::*)(void) const>(_SC("_unm"), &Vector3::operator -)
|
||||
|
||||
.Overload<void (Vector3::*)(Val)>(_SC("set"), &Vector3::Set)
|
||||
.Overload<void (Vector3::*)(Val, Val, Val)>(_SC("set"), &Vector3::Set)
|
||||
.Overload<void (Vector3::*)(const Vector3 &)>(_SC("set_vec3"), &Vector3::Set)
|
||||
.Overload<void (Vector3::*)(const Vector4 &)>(_SC("set_vec4"), &Vector3::Set)
|
||||
.Overload<void (Vector3::*)(const Quaternion &)>(_SC("set_quat"), &Vector3::Set)
|
||||
.Overload<void (Vector3::*)(const SQChar *, SQChar)>(_SC("set_str"), &Vector3::Set)
|
||||
|
||||
.Overload<void (Vector3::*)(void)>(_SC("generate"), &Vector3::Generate)
|
||||
.Overload<void (Vector3::*)(Val, Val)>(_SC("generate"), &Vector3::Generate)
|
||||
.Overload<void (Vector3::*)(Val, Val, Val, Val, Val, Val)>(_SC("generate"), &Vector3::Generate)
|
||||
|
||||
.Func(_SC("clear"), &Vector3::Clear)
|
||||
|
||||
/* Setters */
|
||||
.Overload<void (Vector3::*)(Val)>(_SC("Set"), &Vector3::Set)
|
||||
.Overload<void (Vector3::*)(Val, Val, Val)>(_SC("Set"), &Vector3::Set)
|
||||
.Overload<void (Vector3::*)(const Vector3 &)>(_SC("SetVec3"), &Vector3::Set)
|
||||
.Overload<void (Vector3::*)(const Vector4 &)>(_SC("SetVec4"), &Vector3::Set)
|
||||
.Overload<void (Vector3::*)(const Quaternion &)>(_SC("SetQuat"), &Vector3::Set)
|
||||
.Overload<void (Vector3::*)(CSStr, SQChar)>(_SC("SetStr"), &Vector3::Set)
|
||||
/* Random Generators */
|
||||
.Overload<void (Vector3::*)(void)>(_SC("Generate"), &Vector3::Generate)
|
||||
.Overload<void (Vector3::*)(Val, Val)>(_SC("Generate"), &Vector3::Generate)
|
||||
.Overload<void (Vector3::*)(Val, Val, Val, Val, Val, Val)>(_SC("Generate"), &Vector3::Generate)
|
||||
/* Utility Methods */
|
||||
.Func(_SC("Clear"), &Vector3::Clear)
|
||||
/* Operator Exposure */
|
||||
.Func<Vector3 & (Vector3::*)(const Vector3 &)>(_SC("opAddAssign"), &Vector3::operator +=)
|
||||
.Func<Vector3 & (Vector3::*)(const Vector3 &)>(_SC("opSubAssign"), &Vector3::operator -=)
|
||||
.Func<Vector3 & (Vector3::*)(const Vector3 &)>(_SC("opMulAssign"), &Vector3::operator *=)
|
||||
@@ -507,10 +479,6 @@ bool Register_Vector3(HSQUIRRELVM vm)
|
||||
.Func<bool (Vector3::*)(const Vector3 &) const>(_SC("opLessEqual"), &Vector3::operator <=)
|
||||
.Func<bool (Vector3::*)(const Vector3 &) const>(_SC("opGreaterEqual"), &Vector3::operator >=)
|
||||
);
|
||||
|
||||
LogDbg("Registration of <Vector3> type was successful");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
} // Namespace:: SqMod
|
||||
|
Reference in New Issue
Block a user