#include "Base/AABB.hpp" #include "Base/Vector4.hpp" #include "Base/Shared.hpp" #include "Register.hpp" // ------------------------------------------------------------------------------------------------ namespace SqMod { // ------------------------------------------------------------------------------------------------ const AABB AABB::NIL = AABB(0); const AABB AABB::MIN = AABB(-1, -1, -1, 1, 1, 1); const AABB AABB::MAX = AABB(Vector3::MIN, Vector3::MAX); // ------------------------------------------------------------------------------------------------ SQChar AABB::Delim = ','; // ------------------------------------------------------------------------------------------------ AABB::AABB() : min(-1), max(1) { } AABB::AABB(Value s) : min(-s), max(std::fabs(s)) { } AABB::AABB(Value xv, Value yv, Value zv) : min(-xv, -yv, -zv), max(std::fabs(xv), std::fabs(yv), std::fabs(zv)) { } AABB::AABB(Value xmin, Value ymin, Value zmin, Value xmax, Value ymax, Value zmax) : min(xmin, ymin, zmin), max(xmax, ymax, zmax) { } // ------------------------------------------------------------------------------------------------ AABB::AABB(const Vector3 & v) : min(-v), max(v.Abs()) { } AABB::AABB(const Vector3 & vmin, const Vector3 & vmax) : min(vmin), max(vmax) { } // ------------------------------------------------------------------------------------------------ AABB::AABB(const Vector4 & v) : min(-v), max(v.Abs()) { } AABB::AABB(const Vector4 & vmin, const Vector4 & vmax) : min(vmin), max(vmax) { } // ------------------------------------------------------------------------------------------------ AABB::AABB(const SQChar * values, SQChar delim) : AABB(GetAABB(values, delim)) { } // ------------------------------------------------------------------------------------------------ AABB::AABB(const AABB & b) : min(b.min), max(b.max) { } AABB::AABB(AABB && b) : min(b.min), max(b.max) { } // ------------------------------------------------------------------------------------------------ AABB::~AABB() { } // ------------------------------------------------------------------------------------------------ AABB & AABB::operator = (const AABB & b) { min = b.min; max = b.max; return *this; } AABB & AABB::operator = (AABB && b) { min = b.min; max = b.max; return *this; } // ------------------------------------------------------------------------------------------------ AABB & AABB::operator = (Value s) { min.Set(-s); max.Set(std::fabs(s)); return *this; } AABB & AABB::operator = (const Vector3 & v) { min.Set(-v); max.Set(v.Abs()); return *this; } AABB & AABB::operator = (const Vector4 & v) { min.Set(-v); max.Set(v.Abs()); return *this; } // ------------------------------------------------------------------------------------------------ AABB & AABB::operator += (const AABB & b) { min += b.min; max += b.max; return *this; } AABB & AABB::operator -= (const AABB & b) { min -= b.min; max -= b.max; return *this; } AABB & AABB::operator *= (const AABB & b) { min *= b.min; max *= b.max; return *this; } AABB & AABB::operator /= (const AABB & b) { min /= b.min; max /= b.max; return *this; } AABB & AABB::operator %= (const AABB & b) { min %= b.min; max %= b.max; return *this; } // ------------------------------------------------------------------------------------------------ AABB & AABB::operator += (Value s) { min += s; max += s; return *this; } AABB & AABB::operator -= (Value s) { min -= s; max -= s; return *this; } AABB & AABB::operator *= (Value s) { min *= s; max *= s; return *this; } AABB & AABB::operator /= (Value s) { min /= s; max /= s; return *this; } AABB & AABB::operator %= (Value s) { min %= s; max %= s; return *this; } // ------------------------------------------------------------------------------------------------ AABB & AABB::operator ++ () { ++min; ++max; return *this; } AABB & AABB::operator -- () { --min; --max; return *this; } // ------------------------------------------------------------------------------------------------ AABB AABB::operator ++ (int) { AABB state(*this); ++min; ++max; return state; } AABB AABB::operator -- (int) { AABB state(*this); --min; --max; return state; } // ------------------------------------------------------------------------------------------------ AABB AABB::operator + (const AABB & b) const { return AABB(min + b.min, max + b.max); } AABB AABB::operator - (const AABB & b) const { return AABB(min - b.min, max - b.max); } AABB AABB::operator * (const AABB & b) const { return AABB(min * b.min, max * b.max); } AABB AABB::operator / (const AABB & b) const { return AABB(min / b.min, max / b.max); } AABB AABB::operator % (const AABB & b) const { return AABB(min % b.min, max % b.max); } // ------------------------------------------------------------------------------------------------ AABB AABB::operator + (Value s) const { return AABB(min + s, max + s); } AABB AABB::operator - (Value s) const { return AABB(min - s, max - s); } AABB AABB::operator * (Value s) const { return AABB(min * s, max * s); } AABB AABB::operator / (Value s) const { return AABB(min / s, max / s); } AABB AABB::operator % (Value s) const { return AABB(min % s, max % s); } // ------------------------------------------------------------------------------------------------ AABB AABB::operator + () const { return AABB(min.Abs(), max.Abs()); } AABB AABB::operator - () const { return AABB(-min, -max); } // ------------------------------------------------------------------------------------------------ bool AABB::operator == (const AABB & b) const { return (min == b.min) && (max == b.max); } bool AABB::operator != (const AABB & b) const { return (min != b.min) && (max != b.max); } bool AABB::operator < (const AABB & b) const { return (min < b.min) && (max < b.max); } bool AABB::operator > (const AABB & b) const { return (min > b.min) && (max > b.max); } bool AABB::operator <= (const AABB & b) const { return (min <= b.min) && (max <= b.max); } bool AABB::operator >= (const AABB & b) const { return (min >= b.min) && (max >= b.max); } // ------------------------------------------------------------------------------------------------ SQInteger AABB::Cmp(const AABB & b) const { return *this == b ? 0 : (*this > b ? 1 : -1); } // ------------------------------------------------------------------------------------------------ const SQChar * AABB::ToString() const { return ToStringF("%f,%f,%f,%f,%f,%f", min.x, min.y, min.z, max.x, max.y, max.z); } // ------------------------------------------------------------------------------------------------ void AABB::Set(Value ns) { min = -ns; max = std::fabs(ns); } void AABB::Set(Value nx, Value ny, Value nz) { min.Set(-nx, -ny, -nz); max.Set(std::fabs(nx), std::fabs(ny), std::fabs(nz)); } void AABB::Set(Value xmin, Value ymin, Value zmin, Value xmax, Value ymax, Value zmax) { min.Set(xmin, ymin, zmin); max.Set(xmax, ymax, zmax); } // ------------------------------------------------------------------------------------------------ void AABB::Set(const AABB & b) { min = b.min; max = b.max; } // ------------------------------------------------------------------------------------------------ void AABB::Set(const Vector3 & v) { min = -v; max = v.Abs(); } void AABB::Set(const Vector3 & nmin, const Vector3 & nmax) { min = nmin; max = nmax; } // ------------------------------------------------------------------------------------------------ void AABB::Set(const Vector4 & v) { min = -v; max = v.Abs(); } void AABB::Set(const Vector4 & nmin, const Vector4 & nmax) { min = nmin; max = nmax; } // ------------------------------------------------------------------------------------------------ void AABB::Set(const SQChar * values, SQChar delim) { Set(GetAABB(values, delim)); } // ------------------------------------------------------------------------------------------------ AABB AABB::Abs() const { return AABB(min.Abs(), max.Abs()); } // ================================================================================================ bool Register_AABB(HSQUIRRELVM vm) { LogDbg("Beginning registration of type"); typedef AABB::Value Val; Sqrat::RootTable(vm).Bind(_SC("AABB"), Sqrat::Class(vm, _SC("AABB")) .Ctor() .Ctor() .Ctor() .Ctor() .Ctor() .SetStaticValue(_SC("delim"), &AABB::Delim) .Var(_SC("min"), &AABB::min) .Var(_SC("max"), &AABB::max) .Prop(_SC("abs"), &AABB::Abs) .Func(_SC("_tostring"), &AABB::ToString) .Func(_SC("_cmp"), &AABB::Cmp) .Func(_SC("_add"), &AABB::operator +) .Func(_SC("_sub"), &AABB::operator -) .Func(_SC("_mul"), &AABB::operator *) .Func(_SC("_div"), &AABB::operator /) .Func(_SC("_modulo"), &AABB::operator %) .Func(_SC("_unm"), &AABB::operator -) .Overload(_SC("set"), &AABB::Set) .Overload(_SC("set"), &AABB::Set) .Overload(_SC("set"), &AABB::Set) .Overload(_SC("set_box"), &AABB::Set) .Overload(_SC("set_vec3"), &AABB::Set) .Overload(_SC("set_vec3"), &AABB::Set) .Overload(_SC("set_vec4"), &AABB::Set) .Overload(_SC("set_vec4"), &AABB::Set) .Overload(_SC("set_str"), &AABB::Set) .Func(_SC("clear"), &AABB::Clear) .Func(_SC("opAddAssign"), &AABB::operator +=) .Func(_SC("opSubAssign"), &AABB::operator -=) .Func(_SC("opMulAssign"), &AABB::operator *=) .Func(_SC("opDivAssign"), &AABB::operator /=) .Func(_SC("opModAssign"), &AABB::operator %=) .Func(_SC("opAddAssignS"), &AABB::operator +=) .Func(_SC("opSubAssignS"), &AABB::operator -=) .Func(_SC("opMulAssignS"), &AABB::operator *=) .Func(_SC("opDivAssignS"), &AABB::operator /=) .Func(_SC("opModAssignS"), &AABB::operator %=) .Func(_SC("opPreInc"), &AABB::operator ++) .Func(_SC("opPreDec"), &AABB::operator --) .Func(_SC("opPostInc"), &AABB::operator ++) .Func(_SC("opPostDec"), &AABB::operator --) .Func(_SC("opAdd"), &AABB::operator +) .Func(_SC("opAddS"), &AABB::operator +) .Func(_SC("opSub"), &AABB::operator -) .Func(_SC("opSubS"), &AABB::operator -) .Func(_SC("opMul"), &AABB::operator *) .Func(_SC("opMulS"), &AABB::operator *) .Func(_SC("opDiv"), &AABB::operator /) .Func(_SC("opDivS"), &AABB::operator /) .Func(_SC("opMod"), &AABB::operator %) .Func(_SC("opModS"), &AABB::operator %) .Func(_SC("opUnPlus"), &AABB::operator +) .Func(_SC("opUnMinus"), &AABB::operator -) .Func(_SC("opEqual"), &AABB::operator ==) .Func(_SC("opNotEqual"), &AABB::operator !=) .Func(_SC("opLessThan"), &AABB::operator <) .Func(_SC("opGreaterThan"), &AABB::operator >) .Func(_SC("opLessEqual"), &AABB::operator <=) .Func(_SC("opGreaterEqual"), &AABB::operator >=) ); LogDbg("Registration of type was successful"); return true; } } // Namespace:: SqMod