mirror of
https://github.com/VCMP-SqMod/SqMod.git
synced 2025-01-19 03:57:14 +01:00
Improve the Vector4 registration code to avoid using overloads where not necessary.
Also restructured the registration code a bit.
This commit is contained in:
parent
2857e0e4be
commit
d30e1210ac
@ -65,6 +65,7 @@ Vector4 & Vector4::operator = (Value s)
|
||||
return *this;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Vector4 & Vector4::operator = (const Vector3 & v)
|
||||
{
|
||||
x = v.x;
|
||||
@ -74,6 +75,7 @@ Vector4 & Vector4::operator = (const Vector3 & v)
|
||||
return *this;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Vector4 & Vector4::operator = (const Quaternion & q)
|
||||
{
|
||||
x = q.x;
|
||||
@ -93,6 +95,7 @@ Vector4 & Vector4::operator += (const Vector4 & v)
|
||||
return *this;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Vector4 & Vector4::operator -= (const Vector4 & v)
|
||||
{
|
||||
x -= v.x;
|
||||
@ -102,6 +105,7 @@ Vector4 & Vector4::operator -= (const Vector4 & v)
|
||||
return *this;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Vector4 & Vector4::operator *= (const Vector4 & v)
|
||||
{
|
||||
x *= v.x;
|
||||
@ -111,6 +115,7 @@ Vector4 & Vector4::operator *= (const Vector4 & v)
|
||||
return *this;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Vector4 & Vector4::operator /= (const Vector4 & v)
|
||||
{
|
||||
x /= v.x;
|
||||
@ -120,6 +125,7 @@ Vector4 & Vector4::operator /= (const Vector4 & v)
|
||||
return *this;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Vector4 & Vector4::operator %= (const Vector4 & v)
|
||||
{
|
||||
x = std::fmod(x, v.x);
|
||||
@ -139,6 +145,7 @@ Vector4 & Vector4::operator += (Value s)
|
||||
return *this;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Vector4 & Vector4::operator -= (Value s)
|
||||
{
|
||||
x -= s;
|
||||
@ -148,6 +155,7 @@ Vector4 & Vector4::operator -= (Value s)
|
||||
return *this;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Vector4 & Vector4::operator *= (Value s)
|
||||
{
|
||||
x *= s;
|
||||
@ -166,6 +174,7 @@ Vector4 & Vector4::operator /= (Value s)
|
||||
return *this;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Vector4 & Vector4::operator %= (Value s)
|
||||
{
|
||||
x = std::fmod(x, s);
|
||||
@ -185,6 +194,7 @@ Vector4 & Vector4::operator ++ ()
|
||||
return *this;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Vector4 & Vector4::operator -- ()
|
||||
{
|
||||
--x;
|
||||
@ -205,6 +215,7 @@ Vector4 Vector4::operator ++ (int)
|
||||
return state;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Vector4 Vector4::operator -- (int)
|
||||
{
|
||||
Vector4 state(*this);
|
||||
@ -221,21 +232,25 @@ Vector4 Vector4::operator + (const Vector4 & v) const
|
||||
return Vector4(x + v.x, y + v.y, z + v.z, w + v.w);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Vector4 Vector4::operator - (const Vector4 & v) const
|
||||
{
|
||||
return Vector4(x - v.x, y - v.y, z - v.z, w - v.w);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Vector4 Vector4::operator * (const Vector4 & v) const
|
||||
{
|
||||
return Vector4(x * v.x, y * v.y, z * v.z, w * v.w);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Vector4 Vector4::operator / (const Vector4 & v) const
|
||||
{
|
||||
return Vector4(x / v.x, y / v.y, z / v.z, w / v.w);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Vector4 Vector4::operator % (const Vector4 & v) const
|
||||
{
|
||||
return Vector4(std::fmod(x, v.x), std::fmod(y, v.y), std::fmod(z, v.z), std::fmod(w, v.w));
|
||||
@ -247,21 +262,25 @@ Vector4 Vector4::operator + (Value s) const
|
||||
return Vector4(x + s, y + s, z + s, w + s);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Vector4 Vector4::operator - (Value s) const
|
||||
{
|
||||
return Vector4(x - s, y - s, z - s, w - s);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Vector4 Vector4::operator * (Value s) const
|
||||
{
|
||||
return Vector4(x * s, y * s, z * s, w * s);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Vector4 Vector4::operator / (Value s) const
|
||||
{
|
||||
return Vector4(x / s, y / s, z / s, w / s);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Vector4 Vector4::operator % (Value s) const
|
||||
{
|
||||
return Vector4(std::fmod(x, s), std::fmod(y, s), std::fmod(z, s), std::fmod(w, s));
|
||||
@ -273,6 +292,7 @@ Vector4 Vector4::operator + () const
|
||||
return Vector4(std::fabs(x), std::fabs(y), std::fabs(z), std::fabs(w));
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Vector4 Vector4::operator - () const
|
||||
{
|
||||
return Vector4(-x, -y, -z, -w);
|
||||
@ -284,26 +304,31 @@ bool Vector4::operator == (const Vector4 & v) const
|
||||
return EpsEq(x, v.x) && EpsEq(y, v.y) && EpsEq(z, v.z) && EpsEq(w, v.w);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
bool Vector4::operator != (const Vector4 & v) const
|
||||
{
|
||||
return !EpsEq(x, v.x) && !EpsEq(y, v.y) && !EpsEq(z, v.z) && !EpsEq(w, v.w);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
bool Vector4::operator < (const Vector4 & v) const
|
||||
{
|
||||
return EpsLt(x, v.x) && EpsLt(y, v.y) && EpsLt(z, v.z) && EpsLt(w, v.w);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
bool Vector4::operator > (const Vector4 & v) const
|
||||
{
|
||||
return EpsGt(x, v.x) && EpsGt(y, v.y) && EpsGt(z, v.z) && EpsGt(w, v.w);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
bool Vector4::operator <= (const Vector4 & v) const
|
||||
{
|
||||
return EpsLtEq(x, v.x) && EpsLtEq(y, v.y) && EpsLtEq(z, v.z) && EpsLtEq(w, v.w);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
bool Vector4::operator >= (const Vector4 & v) const
|
||||
{
|
||||
return EpsGtEq(x, v.x) && EpsGtEq(y, v.y) && EpsGtEq(z, v.z) && EpsGtEq(w, v.w);
|
||||
@ -333,7 +358,7 @@ CSStr Vector4::ToString() const
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void Vector4::Set(Value ns)
|
||||
void Vector4::SetScalar(Value ns)
|
||||
{
|
||||
x = ns;
|
||||
y = ns;
|
||||
@ -341,14 +366,17 @@ void Vector4::Set(Value ns)
|
||||
w = ns;
|
||||
}
|
||||
|
||||
void Vector4::Set(Value nx, Value ny, Value nz)
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void Vector4::SetVector4(const Vector4 & v)
|
||||
{
|
||||
x = nx;
|
||||
y = ny;
|
||||
z = nz;
|
||||
x = v.x;
|
||||
y = v.y;
|
||||
z = v.z;
|
||||
w = v.w;
|
||||
}
|
||||
|
||||
void Vector4::Set(Value nx, Value ny, Value nz, Value nw)
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void Vector4::SetVector4Ex(Value nx, Value ny, Value nz, Value nw)
|
||||
{
|
||||
x = nx;
|
||||
y = ny;
|
||||
@ -357,15 +385,7 @@ void Vector4::Set(Value nx, Value ny, Value nz, Value nw)
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void Vector4::Set(const Vector4 & v)
|
||||
{
|
||||
x = v.x;
|
||||
y = v.y;
|
||||
z = v.z;
|
||||
w = v.w;
|
||||
}
|
||||
|
||||
void Vector4::Set(const Vector3 & v)
|
||||
void Vector4::SetVector3(const Vector3 & v)
|
||||
{
|
||||
x = v.x;
|
||||
y = v.y;
|
||||
@ -373,7 +393,16 @@ void Vector4::Set(const Vector3 & v)
|
||||
w = 0.0;
|
||||
}
|
||||
|
||||
void Vector4::Set(const Quaternion & q)
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void Vector4::SetVector3Ex(Value nx, Value ny, Value nz)
|
||||
{
|
||||
x = nx;
|
||||
y = ny;
|
||||
z = nz;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void Vector4::SetQuaternion(const Quaternion & q)
|
||||
{
|
||||
x = q.x;
|
||||
y = q.y;
|
||||
@ -382,9 +411,18 @@ void Vector4::Set(const Quaternion & q)
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void Vector4::Set(CSStr values, SQChar delim)
|
||||
void Vector4::SetQuaternionEx(Value nx, Value ny, Value nz, Value nw)
|
||||
{
|
||||
Set(Vector4::Get(values, delim));
|
||||
x = nx;
|
||||
y = ny;
|
||||
z = nz;
|
||||
w = nw;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void Vector4::SetStr(CSStr values, SQChar delim)
|
||||
{
|
||||
SetVector4(Vector4::Get(values, delim));
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@ -396,6 +434,7 @@ void Vector4::Generate()
|
||||
w = GetRandomFloat32();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void Vector4::Generate(Value min, Value max)
|
||||
{
|
||||
if (max < min)
|
||||
@ -409,6 +448,7 @@ void Vector4::Generate(Value min, Value max)
|
||||
y = GetRandomFloat32(min, max);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void Vector4::Generate(Value xmin, Value xmax, Value ymin, Value ymax, Value zmin, Value zmax, Value wmin, Value wmax)
|
||||
{
|
||||
if (EpsLt(xmax, xmin) || EpsLt(ymax, ymin) || EpsLt(zmax, zmin) || EpsLt(wmax, wmin))
|
||||
@ -465,31 +505,35 @@ const Vector4 & GetVector4()
|
||||
return vec;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
const Vector4 & GetVector4(Float32 sv)
|
||||
{
|
||||
static Vector4 vec;
|
||||
vec.Set(sv);
|
||||
vec.SetScalar(sv);
|
||||
return vec;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
const Vector4 & GetVector4(Float32 xv, Float32 yv, Float32 zv)
|
||||
{
|
||||
static Vector4 vec;
|
||||
vec.Set(xv, yv, zv);
|
||||
vec.SetVector3Ex(xv, yv, zv);
|
||||
return vec;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
const Vector4 & GetVector4(Float32 xv, Float32 yv, Float32 zv, Float32 wv)
|
||||
{
|
||||
static Vector4 vec;
|
||||
vec.Set(xv, yv, zv, wv);
|
||||
vec.SetVector4Ex(xv, yv, zv, wv);
|
||||
return vec;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
const Vector4 & GetVector4(const Vector4 & o)
|
||||
{
|
||||
static Vector4 vec;
|
||||
vec.Set(o);
|
||||
vec.SetVector4(o);
|
||||
return vec;
|
||||
}
|
||||
|
||||
@ -513,8 +557,6 @@ void Register_Vector4(HSQUIRRELVM vm)
|
||||
.Var(_SC("Y"), &Vector4::y)
|
||||
.Var(_SC("Z"), &Vector4::z)
|
||||
.Var(_SC("W"), &Vector4::w)
|
||||
// Properties
|
||||
.Prop(_SC("Abs"), &Vector4::Abs)
|
||||
// Core Meta-methods
|
||||
.Func(_SC("_tostring"), &Vector4::ToString)
|
||||
.SquirrelFunc(_SC("_typename"), &Vector4::Typename)
|
||||
@ -526,20 +568,22 @@ void Register_Vector4(HSQUIRRELVM vm)
|
||||
.Func< Vector4 (Vector4::*)(const Vector4 &) const >(_SC("_div"), &Vector4::operator /)
|
||||
.Func< Vector4 (Vector4::*)(const Vector4 &) const >(_SC("_modulo"), &Vector4::operator %)
|
||||
.Func< Vector4 (Vector4::*)(void) const >(_SC("_unm"), &Vector4::operator -)
|
||||
// Setters
|
||||
.Overload< void (Vector4::*)(Val) >(_SC("Set"), &Vector4::Set)
|
||||
.Overload< void (Vector4::*)(Val, Val, Val) >(_SC("Set"), &Vector4::Set)
|
||||
.Overload< void (Vector4::*)(Val, Val, Val, Val) >(_SC("Set"), &Vector4::Set)
|
||||
.Overload< void (Vector4::*)(const Vector4 &) >(_SC("SetVec4"), &Vector4::Set)
|
||||
.Overload< void (Vector4::*)(const Vector3 &) >(_SC("SetVec3"), &Vector4::Set)
|
||||
.Overload< void (Vector4::*)(const Quaternion &) >(_SC("SetQuat"), &Vector4::Set)
|
||||
.Overload< void (Vector4::*)(CSStr, SQChar) >(_SC("SetStr"), &Vector4::Set)
|
||||
// Random Generators
|
||||
// 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)
|
||||
.Func(_SC("SetStr"), &Vector4::SetStr)
|
||||
.Func(_SC("Clear"), &Vector4::Clear)
|
||||
// Member Overloads
|
||||
.Overload< void (Vector4::*)(void) >(_SC("Generate"), &Vector4::Generate)
|
||||
.Overload< void (Vector4::*)(Val, Val) >(_SC("Generate"), &Vector4::Generate)
|
||||
.Overload< void (Vector4::*)(Val, Val, Val, Val, Val, Val, Val, Val) >(_SC("Generate"), &Vector4::Generate)
|
||||
// Utility Methods
|
||||
.Func(_SC("Clear"), &Vector4::Clear)
|
||||
// Static Overloads
|
||||
.StaticOverload< const Vector4 & (*)(CSStr) >(_SC("FromStr"), &Vector4::Get)
|
||||
.StaticOverload< const Vector4 & (*)(CSStr, SQChar) >(_SC("FromStr"), &Vector4::Get)
|
||||
@ -552,33 +596,27 @@ void Register_Vector4(HSQUIRRELVM vm)
|
||||
.Func< Vector4 & (Vector4::*)(const Vector4 &) >(_SC("opMulAssign"), &Vector4::operator *=)
|
||||
.Func< Vector4 & (Vector4::*)(const Vector4 &) >(_SC("opDivAssign"), &Vector4::operator /=)
|
||||
.Func< Vector4 & (Vector4::*)(const Vector4 &) >(_SC("opModAssign"), &Vector4::operator %=)
|
||||
|
||||
.Func< Vector4 & (Vector4::*)(Vector4::Value) >(_SC("opAddAssignS"), &Vector4::operator +=)
|
||||
.Func< Vector4 & (Vector4::*)(Vector4::Value) >(_SC("opSubAssignS"), &Vector4::operator -=)
|
||||
.Func< Vector4 & (Vector4::*)(Vector4::Value) >(_SC("opMulAssignS"), &Vector4::operator *=)
|
||||
.Func< Vector4 & (Vector4::*)(Vector4::Value) >(_SC("opDivAssignS"), &Vector4::operator /=)
|
||||
.Func< Vector4 & (Vector4::*)(Vector4::Value) >(_SC("opModAssignS"), &Vector4::operator %=)
|
||||
|
||||
.Func< Vector4 & (Vector4::*)(void) >(_SC("opPreInc"), &Vector4::operator ++)
|
||||
.Func< Vector4 & (Vector4::*)(void) >(_SC("opPreDec"), &Vector4::operator --)
|
||||
.Func< Vector4 (Vector4::*)(int) >(_SC("opPostInc"), &Vector4::operator ++)
|
||||
.Func< Vector4 (Vector4::*)(int) >(_SC("opPostDec"), &Vector4::operator --)
|
||||
|
||||
.Func< Vector4 (Vector4::*)(const Vector4 &) const >(_SC("opAdd"), &Vector4::operator +)
|
||||
.Func< Vector4 (Vector4::*)(const Vector4 &) const >(_SC("opSub"), &Vector4::operator -)
|
||||
.Func< Vector4 (Vector4::*)(const Vector4 &) const >(_SC("opMul"), &Vector4::operator *)
|
||||
.Func< Vector4 (Vector4::*)(const Vector4 &) const >(_SC("opDiv"), &Vector4::operator /)
|
||||
.Func< Vector4 (Vector4::*)(const Vector4 &) const >(_SC("opMod"), &Vector4::operator %)
|
||||
|
||||
.Func< Vector4 (Vector4::*)(Vector4::Value) const >(_SC("opAddS"), &Vector4::operator +)
|
||||
.Func< Vector4 (Vector4::*)(Vector4::Value) const >(_SC("opSubS"), &Vector4::operator -)
|
||||
.Func< Vector4 (Vector4::*)(Vector4::Value) const >(_SC("opMulS"), &Vector4::operator *)
|
||||
.Func< Vector4 (Vector4::*)(Vector4::Value) const >(_SC("opDivS"), &Vector4::operator /)
|
||||
.Func< Vector4 (Vector4::*)(Vector4::Value) const >(_SC("opModS"), &Vector4::operator %)
|
||||
|
||||
.Func< Vector4 (Vector4::*)(void) const >(_SC("opUnPlus"), &Vector4::operator +)
|
||||
.Func< Vector4 (Vector4::*)(void) const >(_SC("opUnMinus"), &Vector4::operator -)
|
||||
|
||||
.Func< bool (Vector4::*)(const Vector4 &) const >(_SC("opEqual"), &Vector4::operator ==)
|
||||
.Func< bool (Vector4::*)(const Vector4 &) const >(_SC("opNotEqual"), &Vector4::operator !=)
|
||||
.Func< bool (Vector4::*)(const Vector4 &) const >(_SC("opLessThan"), &Vector4::operator <)
|
||||
|
@ -272,37 +272,42 @@ struct Vector4
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Set all components to the specified scalar value.
|
||||
*/
|
||||
void Set(Value ns);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Set all components to the specified values.
|
||||
*/
|
||||
void Set(Value nx, Value ny, Value nz);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Set all components to the specified values.
|
||||
*/
|
||||
void Set(Value nx, Value ny, Value nz, Value nw);
|
||||
void SetScalar(Value ns);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy the values from another instance of this type.
|
||||
*/
|
||||
void Set(const Vector4 & v);
|
||||
void SetVector4(const Vector4 & v);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Set all components to the specified values.
|
||||
*/
|
||||
void SetVector4Ex(Value nx, Value ny, Value nz, Value nw);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy the values from a three-dimensional vector.
|
||||
*/
|
||||
void Set(const Vector3 & v);
|
||||
void SetVector3(const Vector3 & v);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Set all components to the specified values.
|
||||
*/
|
||||
void SetVector3Ex(Value nx, Value ny, Value nz);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy the values from a quaternion rotation.
|
||||
*/
|
||||
void Set(const Quaternion & q);
|
||||
void SetQuaternion(const Quaternion & q);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy the values from a quaternion rotation.
|
||||
*/
|
||||
void SetQuaternionEx(Value nx, Value ny, Value nz, Value nw);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Set the values extracted from the specified string using the specified delimiter.
|
||||
*/
|
||||
void Set(CSStr values, SQChar delim);
|
||||
void SetStr(CSStr values, SQChar delim);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Generate random values for all components of this instance.
|
||||
|
Loading…
x
Reference in New Issue
Block a user