commit x64 compilation from lulu cause the other branch dont seems to compile properly at home
This commit is contained in:
103
include/modules/script_squirrel/cobject/cobject.cpp
Normal file
103
include/modules/script_squirrel/cobject/cobject.cpp
Normal file
@ -0,0 +1,103 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
GSFramework
|
||||
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
|
||||
----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
#include "script_squirrel/cobject/cobject.h"
|
||||
#include "script_squirrel/engine_vm.h"
|
||||
#include "raytracer/raytracer_core.h"
|
||||
#include "automation/automation_source_group.h"
|
||||
#include "scene3d/scene.h"
|
||||
#include "scene3d/group.h"
|
||||
#include "scene3d/memitter.h"
|
||||
#include "scene3d/mcamera.h"
|
||||
#include "scene3d/mobject.h"
|
||||
#include "scene3d/mtrigger.h"
|
||||
#include "scene3d/mlight.h"
|
||||
#include "scene3d/instance.h"
|
||||
#include "ui/ui_cursor.h"
|
||||
#include "core/raster_font.h"
|
||||
#include "input/input_device.h"
|
||||
|
||||
using namespace GS;
|
||||
using namespace GS::Script;
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void CObject::Initialize(CObjectType t, void *o, bool m)
|
||||
{
|
||||
Release();
|
||||
|
||||
type = t;
|
||||
native = o;
|
||||
managed = m;
|
||||
|
||||
if (native)
|
||||
switch (type)
|
||||
{
|
||||
case typetag_Picture: ((Picture *)native)->AddRef(); break;
|
||||
case typetag_Texture: ((Render::Texture *)native)->AddRef(); break;
|
||||
case typetag_Geometry: ((Render::Geometry *)native)->AddRef(); break;
|
||||
case typetag_Material: ((Render::Material *)native)->AddRef(); break;
|
||||
case typetag_InputDevice: ((Input::Device *)native)->AddRef(); break;
|
||||
case typetag_AutomationSource: ((Automation::Source *)native)->AddRef(); break;
|
||||
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
void CObject::Release()
|
||||
{
|
||||
if (native == NULL)
|
||||
return;
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case typetag_Picture: ((Picture *)native)->RemoveRef(); break;
|
||||
case typetag_Texture: ((Render::Texture *)native)->RemoveRef(); break;
|
||||
case typetag_Geometry: ((Render::Geometry *)native)->RemoveRef(); break;
|
||||
case typetag_Material: ((Render::Material *)native)->RemoveRef(); break;
|
||||
case typetag_InputDevice: ((Input::Device *)native)->RemoveRef(); break;
|
||||
case typetag_AutomationSource: ((Automation::Source *)native)->RemoveRef(); break;
|
||||
|
||||
default: break;
|
||||
}
|
||||
|
||||
if (managed)
|
||||
switch (type)
|
||||
{
|
||||
case typetag_Metafile: delete ((NML::File *)native); break;
|
||||
case typetag_Raytracer: delete ((Raytrace::Raytracer *)native); break;
|
||||
case typetag_RasterFont: delete ((Render::RasterFont *)native); break;
|
||||
case typetag_AutomationSourceGroup: delete ((Automation::SourceGroup *)native); break;
|
||||
case typetag_Group: delete ((S3D::Group *)native); break;
|
||||
case typetag_Scene3d: delete ((S3D::Scene *)native); break;
|
||||
case typetag_UICursor: delete ((S2D::Cursor *)native); break;
|
||||
|
||||
default:
|
||||
__LOG_E__ << "Type " << CObjectTypeToString(type) << " should not be managed by the VM.\n";
|
||||
break;
|
||||
}
|
||||
|
||||
native = NULL;
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
CObject::CObject(EngineVM *v, CObjectType t, void *o, bool managed) : vm(v)
|
||||
{
|
||||
list_item = vm->cobjects.Add(this);
|
||||
|
||||
native = NULL;
|
||||
Initialize(t, o, managed);
|
||||
}
|
||||
CObject::~CObject()
|
||||
{
|
||||
if (list_item)
|
||||
{
|
||||
vm->cobjects.Remove(list_item);
|
||||
// g_flog << "Native object alive count: " << vm->cobjects.GetCount() << "\n";
|
||||
}
|
||||
Release();
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
154
include/modules/script_squirrel/cobject/cobject_impl.cpp
Normal file
154
include/modules/script_squirrel/cobject/cobject_impl.cpp
Normal file
@ -0,0 +1,154 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
GSFramework
|
||||
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
|
||||
----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
#include "script_squirrel/cobject/cobject_decl.h"
|
||||
#include "script_squirrel/cobject/cobject.h"
|
||||
#include "script_squirrel/squirrel_vm.h"
|
||||
#include "log/log.h"
|
||||
|
||||
using namespace GS::Script;
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
bool CObject::GetBase(HSQUIRRELVM vm, int idx, void **o, CObjectType *types)
|
||||
{
|
||||
// get object type
|
||||
CObjectType type;
|
||||
if (!GetType(vm, idx, type))
|
||||
return false;
|
||||
|
||||
// cast to target type if compatible
|
||||
for (int n = 0; types[n] != typetag_Undefined; ++n)
|
||||
if (type == types[n])
|
||||
return Get(vm, idx, (void **)o);
|
||||
|
||||
return false;
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
static SQInteger CObject_release_hook(SQUserPointer p, SQInteger size)
|
||||
{
|
||||
if (CObject *pv = (CObject *)p)
|
||||
delete pv;
|
||||
return 0;
|
||||
}
|
||||
bool push_CObject(HSQUIRRELVM vm, const CObject &quat)
|
||||
{
|
||||
CObject *newquat = new CObject((EngineVM *)sq_getforeignptr(vm));
|
||||
*newquat = quat;
|
||||
if (!CreateNativeClassInstance(vm, "CObject", newquat, CObject_release_hook))
|
||||
{
|
||||
delete newquat;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
::SquirrelObject new_CObject(HSQUIRRELVM vm, const CObject &quat)
|
||||
{
|
||||
::SquirrelObject ret(vm);
|
||||
if (push_CObject(vm, quat))
|
||||
{
|
||||
ret.AttachToStackObject(-1);
|
||||
sq_pop(vm, 1);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
int construct_CObject(HSQUIRRELVM vm, CObject *p)
|
||||
{
|
||||
sq_setinstanceup(vm, 1, p);
|
||||
sq_setreleasehook(vm, 1, CObject_release_hook);
|
||||
return 1;
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
bool CObject::Push(HSQUIRRELVM v, void *_ptr, CObjectType _type, bool managed)
|
||||
{
|
||||
CObject *o = new CObject((EngineVM *)sq_getforeignptr(v), _type, _ptr, managed);
|
||||
|
||||
if (!CreateNativeClassInstance(v, "CObject", o, CObject_release_hook))
|
||||
{
|
||||
__LOG_E__ << "Could not allocate native reference.\n";
|
||||
_safe_delete(o);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
bool CObject::GetType(HSQUIRRELVM v, int idx, CObjectType &type)
|
||||
{
|
||||
StackHandler sa(v);
|
||||
|
||||
CObject *self;
|
||||
if (SQ_FAILED(sq_getinstanceup(v, idx, (SQUserPointer*)&self, (SQUserPointer)&__CObject_decl)))
|
||||
return false;
|
||||
|
||||
__ASSERT__(self != NULL);
|
||||
|
||||
type = self->type;
|
||||
return true;
|
||||
}
|
||||
bool CObject::Get(HSQUIRRELVM v, int idx, void **p, CObjectType type)
|
||||
{
|
||||
__ASSERT__(p != NULL);
|
||||
|
||||
StackHandler sa(v);
|
||||
|
||||
CObject *self;
|
||||
if (SQ_FAILED(sq_getinstanceup(v, idx, (SQUserPointer*)&self, (SQUserPointer)&__CObject_decl)))
|
||||
return false;
|
||||
|
||||
__ASSERT__(self != NULL);
|
||||
|
||||
if ((type != typetag_Undefined) && (self->type != type))
|
||||
{
|
||||
sq_throwerror(v, String::Format("Native reference to '%s' expected, got '%s'", CObjectTypeToString(type), CObjectTypeToString(self->type)));
|
||||
return false;
|
||||
}
|
||||
|
||||
p[0] = self->native;
|
||||
return true;
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
_MEMBER_FUNCTION_IMPL(CObject, constructor)
|
||||
return construct_CObject(v, new CObject((EngineVM *)sq_getforeignptr(v)));
|
||||
_END_IMPL
|
||||
|
||||
_MEMBER_FUNCTION_IMPL(CObject, _cmp)
|
||||
_GetSelf(CObject, CObject);
|
||||
_GetTypedParam(object, 2, CObject, CObject);
|
||||
return sa.Return(asbool(self->native == object->native));
|
||||
_END_IMPL
|
||||
|
||||
_MEMBER_FUNCTION_IMPL(CObject, type)
|
||||
_GetSelf(CObject, CObject);
|
||||
return sa.Return((int)self->type);
|
||||
_END_IMPL
|
||||
_MEMBER_FUNCTION_IMPL(CObject, isValid)
|
||||
_GetSelf(CObject, CObject);
|
||||
return sa.Return(asbool(self->native));
|
||||
_END_IMPL
|
||||
_MEMBER_FUNCTION_IMPL(CObject, isNull)
|
||||
_GetSelf(CObject, CObject);
|
||||
return sa.Return(!asbool(self->native));
|
||||
_END_IMPL
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
_BEGIN_CLASS(CObject)
|
||||
|
||||
_MEMBER_FUNCTION(CObject, constructor, -1, ".")
|
||||
_MEMBER_FUNCTION(CObject, _cmp, 2, ".xx")
|
||||
|
||||
_MEMBER_FUNCTION(CObject, isValid, 1, _SC("."))
|
||||
_MEMBER_FUNCTION(CObject, isNull, 1, _SC("."))
|
||||
_MEMBER_FUNCTION(CObject, type, 1, _SC("."))
|
||||
|
||||
_END_CLASS(CObject)
|
||||
//------------------------------------------------------------------------------
|
||||
@ -0,0 +1,206 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
GSFramework
|
||||
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
|
||||
----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
#ifndef __COBJECT_GEOMETRY_TEMPLATE_IMPL__
|
||||
#define __COBJECT_GEOMETRY_TEMPLATE_IMPL__
|
||||
|
||||
|
||||
#include "script_squirrel/cobject/geometry_template_decl.h"
|
||||
#include "script_squirrel/cobject/cobject_decl.h"
|
||||
#include "script_squirrel/cobject/vector_decl.h"
|
||||
#include "script_squirrel/cobject/uv_decl.h"
|
||||
#include "script_squirrel/cobject/cobject.h"
|
||||
#include "core/geometry_template.h"
|
||||
#include "core/resource_factories.h"
|
||||
#include "core/render_resource_factory.h"
|
||||
#include "core/render_data.h"
|
||||
#include "core/renderer.h"
|
||||
#include "core/engine.h"
|
||||
|
||||
using namespace GS;
|
||||
using namespace GS::Core;
|
||||
using namespace GS::Script;
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
#define _GetGeometryTemplate(_VAR, _IDX) _GetTypedParam(_VAR, _IDX, GeometryTemplate, GeometryTemplate)
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
_IMPL_NATIVE_CONSTRUCTION(GeometryTemplate, GeometryTemplate);
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
_MEMBER_FUNCTION_IMPL(GeometryTemplate, constructor)
|
||||
return construct_GeometryTemplate(v, new GeometryTemplate);
|
||||
_END_IMPL
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
_MEMBER_FUNCTION_IMPL(GeometryTemplate, clearMaterial)
|
||||
_GetGeometryTemplate(t, 1)
|
||||
t->ClearMaterials();
|
||||
return 0;
|
||||
_END_IMPL
|
||||
|
||||
_MEMBER_FUNCTION_IMPL(GeometryTemplate, pushMaterial)
|
||||
_GetGeometryTemplate(t, 1)
|
||||
const SQChar *name = sa.GetString(2);
|
||||
t->PushMaterial(name);
|
||||
return 0;
|
||||
_END_IMPL
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
_MEMBER_FUNCTION_IMPL(GeometryTemplate, clear)
|
||||
_GetGeometryTemplate(t, 1)
|
||||
t->Clear();
|
||||
return 0;
|
||||
_END_IMPL
|
||||
|
||||
_MEMBER_FUNCTION_IMPL(GeometryTemplate, beginPolygon)
|
||||
_GetGeometryTemplate(t, 1)
|
||||
t->BeginPolygon();
|
||||
return 0;
|
||||
_END_IMPL
|
||||
|
||||
_MEMBER_FUNCTION_IMPL(GeometryTemplate, pushVertex)
|
||||
_GetGeometryTemplate(t, 1)
|
||||
_GetTypedParam(_v, 2, Vector4, Vector)
|
||||
t->PushVertex(*_v);
|
||||
return 0;
|
||||
_END_IMPL
|
||||
_MEMBER_FUNCTION_IMPL(GeometryTemplate, pushNormal)
|
||||
_GetGeometryTemplate(t, 1)
|
||||
_GetTypedParam(n, 2, Vector4, Vector)
|
||||
t->PushNormal(*n);
|
||||
return 0;
|
||||
_END_IMPL
|
||||
_MEMBER_FUNCTION_IMPL(GeometryTemplate, pushColor)
|
||||
_GetGeometryTemplate(t, 1)
|
||||
_GetTypedParam(c, 2, Vector4, Vector)
|
||||
t->PushColor(Color(*c));
|
||||
return 0;
|
||||
_END_IMPL
|
||||
_MEMBER_FUNCTION_IMPL(GeometryTemplate, pushUV)
|
||||
_GetGeometryTemplate(t, 1)
|
||||
_GetTypedParam(uv, 3, Vector2, UV)
|
||||
t->PushUV(sa.GetInt(2), *uv);
|
||||
return 0;
|
||||
_END_IMPL
|
||||
|
||||
_MEMBER_FUNCTION_IMPL(GeometryTemplate, endPolygon)
|
||||
_GetGeometryTemplate(t, 1)
|
||||
t->EndPolygon((ushort)sa.GetInt(2));
|
||||
return 0;
|
||||
_END_IMPL
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
_MEMBER_FUNCTION_IMPL(GeometryTemplate, setVertexMergeThreshold)
|
||||
_GetGeometryTemplate(t, 1)
|
||||
t->SetVertexMergeThreshold(sa.GetFloat(2));
|
||||
return 0;
|
||||
_END_IMPL
|
||||
_MEMBER_FUNCTION_IMPL(GeometryTemplate, instantiate)
|
||||
_GetGeometryTemplate(t, 1)
|
||||
_GetCObject(ResourceFactories, typetag_ResourceFactories, f, 2)
|
||||
AutoPtr <Geometry> g(t->Instantiate(sa.GetString(3)));
|
||||
Render::Geometry *r = f->render->NewGeometry();
|
||||
r->Create(*f->render, *g);
|
||||
_ReturnCObject(r, typetag_Geometry)
|
||||
_END_IMPL
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
|
||||
//# Class: GeometryTemplate
|
||||
_BEGIN_CLASS(GeometryTemplate)
|
||||
|
||||
_MEMBER_FUNCTION(GeometryTemplate, constructor, 1, _SC("."))
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
//# Topic: Polygon creation
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/*#
|
||||
Func: beginPolygon
|
||||
Proto: void:
|
||||
Desc: Begin declaration of a new polygon.
|
||||
#*/
|
||||
_MEMBER_FUNCTION(GeometryTemplate, beginPolygon, 1, _SC("."))
|
||||
/*#
|
||||
Func: pushVertex
|
||||
Proto: void:Vector
|
||||
Desc: Push a vertex on the current polygon declaration.
|
||||
#*/
|
||||
_MEMBER_FUNCTION(GeometryTemplate, pushVertex, 2, _SC(".x"))
|
||||
/*#
|
||||
Func: pushNormal
|
||||
Proto: void:Vector
|
||||
Desc: Push a normal on the current polygon declaration.
|
||||
#*/
|
||||
_MEMBER_FUNCTION(GeometryTemplate, pushNormal, 2, _SC(".x"))
|
||||
/*#
|
||||
Func: pushColor
|
||||
Proto: void:Vector
|
||||
Desc: Push a color on the current polygon declaration.
|
||||
#*/
|
||||
_MEMBER_FUNCTION(GeometryTemplate, pushColor, 2, _SC(".x"))
|
||||
/*#
|
||||
Func: pushUV
|
||||
Proto: void:int channel, UV
|
||||
Desc: Push an UV on a channel of the current polygon declaration.
|
||||
#*/
|
||||
_MEMBER_FUNCTION(GeometryTemplate, pushUV, 3, _SC(".ix"))
|
||||
/*#
|
||||
Func: endPolygon
|
||||
Proto: void:int material
|
||||
Desc: End declaration of the current polygon and specify its material index.
|
||||
#*/
|
||||
_MEMBER_FUNCTION(GeometryTemplate, endPolygon, 2, _SC(".i"))
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
//# Topic: Geometry creation
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/*#
|
||||
Func: clear
|
||||
Proto: void:
|
||||
Desc: Clear current template definition, keep the current material table.
|
||||
#*/
|
||||
_MEMBER_FUNCTION(GeometryTemplate, clear, 1, _SC("."))
|
||||
|
||||
/*#
|
||||
Func: instantiate
|
||||
Proto: Geometry:Engine engine, string name
|
||||
Desc: Instantiate the current template as a named geometry.
|
||||
Note: If the geometry name is already found in the current engine cache, a
|
||||
cached copy will be returned instead of a new instantiation.
|
||||
#*/
|
||||
_MEMBER_FUNCTION(GeometryTemplate, instantiate, 3, _SC(".xs"))
|
||||
|
||||
/*#
|
||||
Func: clearMaterial
|
||||
Proto: void:
|
||||
Desc: Push a material on the template material table.
|
||||
#*/
|
||||
_MEMBER_FUNCTION(GeometryTemplate, clearMaterial, 1, _SC("."))
|
||||
/*#
|
||||
Func: pushMaterial
|
||||
Proto: void:String path
|
||||
Desc: Push a material path on the template material table.
|
||||
#*/
|
||||
_MEMBER_FUNCTION(GeometryTemplate, pushMaterial, 2, _SC(".s"))
|
||||
|
||||
/*#
|
||||
Func: setVertexMergeThreshold
|
||||
Proto: void:float threshold
|
||||
Desc: Set the vertex merging algorithm threshold.
|
||||
#*/
|
||||
_MEMBER_FUNCTION(GeometryTemplate, setVertexMergeThreshold, 2, _SC(".n"))
|
||||
|
||||
_END_CLASS(GeometryTemplate)
|
||||
|
||||
|
||||
#endif // __COBJECT_GEOMETRY_TEMPLATE_IMPL__
|
||||
643
include/modules/script_squirrel/cobject/matrix_impl.cpp
Normal file
643
include/modules/script_squirrel/cobject/matrix_impl.cpp
Normal file
@ -0,0 +1,643 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
GSFramework
|
||||
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
|
||||
------------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
#include "script_squirrel/cobject/matrix_decl.h"
|
||||
#include "script_squirrel/cobject/vector_decl.h"
|
||||
#include "math/matrix4.h"
|
||||
#include "math/matrix3.h"
|
||||
#include "math/quaternion.h"
|
||||
#include "nstring/nstring.h"
|
||||
#include "log/log.h"
|
||||
|
||||
using namespace GS;
|
||||
|
||||
|
||||
#ifndef _T
|
||||
#define _T
|
||||
#endif
|
||||
|
||||
_DECL_CLASS(Matrix4)
|
||||
_IMPL_NATIVE_CONSTRUCTION(Matrix4, Matrix4)
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
_MEMBER_FUNCTION_IMPL(Matrix4, constructor)
|
||||
Matrix4 temp;
|
||||
int nparams = sa.GetParamCount();
|
||||
|
||||
switch (nparams)
|
||||
{
|
||||
case 1: temp.Set(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1); break;
|
||||
case 5:
|
||||
{
|
||||
_GetTypedParam(_u, 2, Vector4, Vector);
|
||||
_GetTypedParam(_v, 3, Vector4, Vector);
|
||||
_GetTypedParam(_w, 4, Vector4, Vector);
|
||||
_GetTypedParam(_x, 5, Vector4, Vector);
|
||||
|
||||
if (_u && _v && _w && _x)
|
||||
{ temp.Set(_u->x, _u->y, _u->z, _u->w, _v->x, _v->y, _v->z, _v->w, _w->x, _w->y, _w->z, _w->w, _x->x, _x->y, _x->z, _x->w); }
|
||||
else
|
||||
return sa.ThrowError("Matrix4() invalid parameters");
|
||||
}
|
||||
break;
|
||||
|
||||
case 17:
|
||||
temp.Set(
|
||||
sa.GetFloat(2), sa.GetFloat(3), sa.GetFloat(4), sa.GetFloat(5),
|
||||
sa.GetFloat(6), sa.GetFloat(7), sa.GetFloat(8), sa.GetFloat(9),
|
||||
sa.GetFloat(10), sa.GetFloat(11), sa.GetFloat(12), sa.GetFloat(13),
|
||||
sa.GetFloat(14), sa.GetFloat(15), sa.GetFloat(16), sa.GetFloat(17)
|
||||
);
|
||||
break;
|
||||
|
||||
default:
|
||||
return sa.ThrowError("Matrix4() wrong parameter count");
|
||||
}
|
||||
return construct_Matrix4(v, new Matrix4(temp));
|
||||
_END_IMPL
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// The string class is used to speed up comparison as it uses a hash-based early
|
||||
// rejection.
|
||||
static String uc_m00("m00"), uc_m10("m10"), uc_m20("m20"), uc_m30("m30"),
|
||||
uc_m01("m01"), uc_m11("m11"), uc_m21("m21"), uc_m31("m31"),
|
||||
uc_m02("m02"), uc_m12("m12"), uc_m22("m22"), uc_m32("m32"),
|
||||
uc_m03("m03"), uc_m13("m13"), uc_m23("m23"), uc_m33("m33");
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
_MEMBER_FUNCTION_IMPL(Matrix4, _set)
|
||||
_GetSelf(Matrix4, Matrix4);
|
||||
|
||||
switch (sa.GetType(2))
|
||||
{
|
||||
case OT_STRING:
|
||||
{
|
||||
String idx(sa.GetString(2));
|
||||
|
||||
if (idx == uc_m00) return sa.Return(self->m[0][0] = sa.GetFloat(3));
|
||||
if (idx == uc_m10) return sa.Return(self->m[1][0] = sa.GetFloat(3));
|
||||
if (idx == uc_m20) return sa.Return(self->m[2][0] = sa.GetFloat(3));
|
||||
if (idx == uc_m30) return sa.Return(self->m[3][0] = sa.GetFloat(3));
|
||||
if (idx == uc_m01) return sa.Return(self->m[0][1] = sa.GetFloat(3));
|
||||
if (idx == uc_m11) return sa.Return(self->m[1][1] = sa.GetFloat(3));
|
||||
if (idx == uc_m21) return sa.Return(self->m[2][1] = sa.GetFloat(3));
|
||||
if (idx == uc_m31) return sa.Return(self->m[3][1] = sa.GetFloat(3));
|
||||
if (idx == uc_m02) return sa.Return(self->m[0][2] = sa.GetFloat(3));
|
||||
if (idx == uc_m12) return sa.Return(self->m[1][2] = sa.GetFloat(3));
|
||||
if (idx == uc_m22) return sa.Return(self->m[2][2] = sa.GetFloat(3));
|
||||
if (idx == uc_m32) return sa.Return(self->m[3][2] = sa.GetFloat(3));
|
||||
if (idx == uc_m03) return sa.Return(self->m[0][3] = sa.GetFloat(3));
|
||||
if (idx == uc_m13) return sa.Return(self->m[1][3] = sa.GetFloat(3));
|
||||
if (idx == uc_m23) return sa.Return(self->m[2][3] = sa.GetFloat(3));
|
||||
if (idx == uc_m33) return sa.Return(self->m[3][3] = sa.GetFloat(3));
|
||||
}
|
||||
break;
|
||||
}
|
||||
return SQ_ERROR;
|
||||
_END_IMPL
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
_MEMBER_FUNCTION_IMPL(Matrix4, _get)
|
||||
_GetSelf(Matrix4, Matrix4);
|
||||
|
||||
switch (sa.GetType(2))
|
||||
{
|
||||
case OT_STRING:
|
||||
{
|
||||
String idx(sa.GetString(2));
|
||||
|
||||
if (idx == uc_m00) return sa.Return(self->m[0][0]);
|
||||
if (idx == uc_m10) return sa.Return(self->m[1][0]);
|
||||
if (idx == uc_m20) return sa.Return(self->m[2][0]);
|
||||
if (idx == uc_m30) return sa.Return(self->m[3][0]);
|
||||
if (idx == uc_m01) return sa.Return(self->m[0][1]);
|
||||
if (idx == uc_m11) return sa.Return(self->m[1][1]);
|
||||
if (idx == uc_m21) return sa.Return(self->m[2][1]);
|
||||
if (idx == uc_m31) return sa.Return(self->m[3][1]);
|
||||
if (idx == uc_m02) return sa.Return(self->m[0][2]);
|
||||
if (idx == uc_m12) return sa.Return(self->m[1][2]);
|
||||
if (idx == uc_m22) return sa.Return(self->m[2][2]);
|
||||
if (idx == uc_m32) return sa.Return(self->m[3][2]);
|
||||
if (idx == uc_m03) return sa.Return(self->m[0][3]);
|
||||
if (idx == uc_m13) return sa.Return(self->m[1][3]);
|
||||
if (idx == uc_m23) return sa.Return(self->m[2][3]);
|
||||
if (idx == uc_m33) return sa.Return(self->m[3][3]);
|
||||
}
|
||||
break;
|
||||
}
|
||||
return SQ_ERROR;
|
||||
_END_IMPL
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
_MEMBER_FUNCTION_IMPL(Matrix4, GetRow)
|
||||
_GetSelf(Matrix4, Matrix4);
|
||||
_SA_RETURN_OBJECT(new_Vector(v, self->GetRow(sa.GetInt(2))));
|
||||
_END_IMPL
|
||||
_MEMBER_FUNCTION_IMPL(Matrix4, SetRow)
|
||||
_GetSelf(Matrix4, Matrix4);
|
||||
_GetTypedParam(row, 3, Vector4, Vector)
|
||||
self->SetRow(sa.GetInt(2), *row);
|
||||
return 0;
|
||||
_END_IMPL
|
||||
_MEMBER_FUNCTION_IMPL(Matrix4, GetColumn)
|
||||
_GetSelf(Matrix4, Matrix4);
|
||||
_SA_RETURN_OBJECT(new_Vector(v, self->GetColumn(sa.GetInt(2))));
|
||||
_END_IMPL
|
||||
_MEMBER_FUNCTION_IMPL(Matrix4, SetColumn)
|
||||
_GetSelf(Matrix4, Matrix4);
|
||||
_GetTypedParam(col, 3, Vector4, Vector)
|
||||
self->SetColumn(sa.GetInt(2), *col);
|
||||
return 0;
|
||||
_END_IMPL
|
||||
|
||||
_MEMBER_FUNCTION_IMPL(Matrix4, GetFront)
|
||||
_GetSelf(Matrix4, Matrix4);
|
||||
_SA_RETURN_OBJECT(new_Vector(v, self->GetRow(2)));
|
||||
_END_IMPL
|
||||
_MEMBER_FUNCTION_IMPL(Matrix4, GetBack)
|
||||
_GetSelf(Matrix4, Matrix4);
|
||||
_SA_RETURN_OBJECT(new_Vector(v, self->GetRow(2).Reversed()));
|
||||
_END_IMPL
|
||||
_MEMBER_FUNCTION_IMPL(Matrix4, GetUp)
|
||||
_GetSelf(Matrix4, Matrix4);
|
||||
_SA_RETURN_OBJECT(new_Vector(v, self->GetRow(1)));
|
||||
_END_IMPL
|
||||
_MEMBER_FUNCTION_IMPL(Matrix4, GetDown)
|
||||
_GetSelf(Matrix4, Matrix4);
|
||||
_SA_RETURN_OBJECT(new_Vector(v, self->GetRow(1).Reversed()));
|
||||
_END_IMPL
|
||||
_MEMBER_FUNCTION_IMPL(Matrix4, GetRight)
|
||||
_GetSelf(Matrix4, Matrix4);
|
||||
_SA_RETURN_OBJECT(new_Vector(v, self->GetRow(0)));
|
||||
_END_IMPL
|
||||
_MEMBER_FUNCTION_IMPL(Matrix4, GetLeft)
|
||||
_GetSelf(Matrix4, Matrix4);
|
||||
_SA_RETURN_OBJECT(new_Vector(v, self->GetRow(0).Reversed()));
|
||||
_END_IMPL
|
||||
_MEMBER_FUNCTION_IMPL(Matrix4, GetPosition)
|
||||
_GetSelf(Matrix4, Matrix4);
|
||||
_SA_RETURN_OBJECT(new_Vector(v, self->GetRow(3)));
|
||||
_END_IMPL
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
_MEMBER_FUNCTION_IMPL(Matrix4, _mul)
|
||||
_GetSelf(Matrix4, Matrix4);
|
||||
_GetTypedParam(mtx, 2, Matrix4, Matrix4)
|
||||
_SA_RETURN_OBJECT(new_Matrix4(v, *self * *mtx));
|
||||
_END_IMPL
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
_MEMBER_FUNCTION_IMPL(Matrix4, AsMatrix3)
|
||||
_GetSelf(Matrix4, Matrix4);
|
||||
_SA_RETURN_OBJECT(new_Matrix3(v, Matrix3::FromMatrix4(*self)));
|
||||
_END_IMPL
|
||||
//------------------------------------------------------------------------------
|
||||
_MEMBER_FUNCTION_IMPL(Matrix4, GetInverseMatrix)
|
||||
_GetSelf(Matrix4, Matrix4);
|
||||
_SA_RETURN_OBJECT(new_Matrix4(v, self->InversedFast()));
|
||||
_END_IMPL
|
||||
//-----------------------------------------------------------------------------
|
||||
_MEMBER_FUNCTION_IMPL(Matrix4, Print)
|
||||
_GetSelf(Matrix4, Matrix4);
|
||||
const char *label = "Matrix";
|
||||
if (sa.GetParamCount() == 2)
|
||||
label = sa.GetString(2);
|
||||
__LOG__ << "Dumping matrix '" << label << "':\n";
|
||||
for (int n = 0; n < 4; ++n)
|
||||
{
|
||||
Vector4 v = self->GetRow(n);
|
||||
__LOG__ << "Row " << n << ": { " << v.x << ", " << v.y << ", " << v.z << ", " << v.w << "}\n";
|
||||
}
|
||||
return 0;
|
||||
_END_IMPL
|
||||
|
||||
_MEMBER_FUNCTION_IMPL(Matrix4, RotationFromMatrix3)
|
||||
_GetSelf(Matrix4, Matrix4);
|
||||
_GetTypedParam(mtx, 2, Matrix3, Matrix3)
|
||||
self->m[0][0] = mtx->m[0][0]; self->m[1][0] = mtx->m[1][0]; self->m[2][0] = mtx->m[2][0];
|
||||
self->m[0][1] = mtx->m[0][1]; self->m[1][1] = mtx->m[1][1]; self->m[2][1] = mtx->m[2][1];
|
||||
self->m[0][2] = mtx->m[0][2]; self->m[1][2] = mtx->m[1][2]; self->m[2][2] = mtx->m[2][2];
|
||||
return 0;
|
||||
_END_IMPL
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/*#
|
||||
Topic: Matrix
|
||||
Type: Matrix3
|
||||
Type: Matrix4
|
||||
#*/
|
||||
|
||||
/*#
|
||||
Section: MatrixGeneric
|
||||
Desc: Global functions
|
||||
#*/
|
||||
/*#
|
||||
Func: Matrix3
|
||||
Proto: Matrix3:float m00...m33
|
||||
Desc: Create a new 3x3 matrix.
|
||||
Example:
|
||||
// Construct a default unity matrix.
|
||||
local a = Matrix3()
|
||||
// Vector based constructor.
|
||||
local b = Matrix3(v0, v1, v2)
|
||||
// Float based constructor.
|
||||
local c = Matrix3(m00, m10, m20, m01, m11, m21, m02, m12, m22)
|
||||
#*/
|
||||
/*#
|
||||
Func: Matrix4
|
||||
Proto: Matrix4:float m00...m44
|
||||
Desc: Create a new 4x4 matrix.
|
||||
Example:
|
||||
// Construct a default unity matrix.
|
||||
local a = Matrix4()
|
||||
// Vector based constructor.
|
||||
local b = Matrix4(v0, v1, v2, v3)
|
||||
// Float based constructor.
|
||||
local c = Matrix3(m00, m10, m20, m30, m01, m11, m21, m31, m02, m12, m22, m32, m03, m13, m23, m33)
|
||||
#*/
|
||||
/*#
|
||||
Func: RotationMatrixX
|
||||
Proto: Matrix3:float angle
|
||||
Desc: Create a 3x3 rotation matrix around the X axis, angle is in degree.
|
||||
Example: local m = RotationMatrixX(Deg(45))
|
||||
#*/
|
||||
/*#
|
||||
Func: RotationMatrixY
|
||||
Proto: Matrix3:float angle
|
||||
Desc: Create a 3x3 rotation matrix around the Y axis, angle is in degree.
|
||||
Example: local m = RotationMatrixY(Deg(45))
|
||||
#*/
|
||||
/*#
|
||||
Func: RotationMatrixZ
|
||||
Proto: Matrix3:float angle
|
||||
Desc: Create a 3x3 rotation matrix around the Z axis, angle is in degree.
|
||||
Example: local m = RotationMatrixZ(Deg(45))
|
||||
#*/
|
||||
/*#
|
||||
Func: MatrixToEuler
|
||||
Proto: Vector:Matrix3,RotationOrder
|
||||
Desc: Convert a world space matrix to Euler angles.
|
||||
#*/
|
||||
/*#
|
||||
Func: EulerFromDirection
|
||||
Proto: Vector:Vector direction
|
||||
Desc: Convert a world space direction vector to an Euler angle triplet (x, y, z).
|
||||
#*/
|
||||
/*#
|
||||
Func: EulerFromDirectionAndUp
|
||||
Proto: Vector:Vector direction,Vector up
|
||||
Desc: Convert a world space direction and up vectors to an Euler angle triplet (x, y, z).
|
||||
#*/
|
||||
/*#
|
||||
Func: RotationMatrixFromDirection
|
||||
Proto: Matrix3:Vector direction
|
||||
Desc: Convert a world space direction vector to a 3x3 rotation matrix.
|
||||
#*/
|
||||
/*#
|
||||
Func: RotationMatrixFromDirectionAndUp
|
||||
Proto: Matrix3:Vector direction,Vector up
|
||||
Desc: Convert a world space direction and up vectors to a 3x3 rotation matrix.
|
||||
#*/
|
||||
/*#
|
||||
Func: TransformationMatrix
|
||||
Proto: Matrix4:Vector position,Vector euler,Vector scale,Vector pivot
|
||||
Desc: Create a position, rotation, scale, offset 4x4 matrix.<br>The offset is applied first, scale second, rotation third and finally position is applied.
|
||||
#*/
|
||||
|
||||
/*#
|
||||
Section: Matrix4Generic
|
||||
Desc: Matrix 4x4
|
||||
#*/
|
||||
_BEGIN_CLASS(Matrix4)
|
||||
_MEMBER_FUNCTION(Matrix4, constructor, -1, _T(". n|x n|x n|x n|x nnnn nnnn"))
|
||||
_MEMBER_FUNCTION(Matrix4, _get, 2, _T("xs"))
|
||||
_MEMBER_FUNCTION(Matrix4, _set, 3, _T("xsn"))
|
||||
_MEMBER_FUNCTION(Matrix4, _mul, 2, _T("xx"))
|
||||
|
||||
/*#
|
||||
Func: GetRow
|
||||
Proto: Vector:int index
|
||||
Desc: Return a matrix row as a vector.
|
||||
#*/
|
||||
_MEMBER_FUNCTION(Matrix4, GetRow, 2, _T("xi"))
|
||||
/*#
|
||||
Func: SetRow
|
||||
Proto: void:int index, Vector row
|
||||
Desc: Set a matrix row from a vector.
|
||||
#*/
|
||||
_MEMBER_FUNCTION(Matrix4, SetRow, 3, _T("xix"))
|
||||
/*#
|
||||
Func: GetColumn
|
||||
Proto: Vector:int index
|
||||
Desc: Return a matrix column as a vector.
|
||||
#*/
|
||||
_MEMBER_FUNCTION(Matrix4, GetColumn, 2, _T("xi"))
|
||||
/*#
|
||||
Func: SetColumn
|
||||
Proto: void:int index, Vector column
|
||||
Desc: Set a matrix column from a vector.
|
||||
#*/
|
||||
_MEMBER_FUNCTION(Matrix4, SetColumn, 3, _T("xix"))
|
||||
/*#
|
||||
Func: AsMatrix3
|
||||
Proto: Matrix3:
|
||||
Desc: Return matrix as a 3x3 matrix.
|
||||
#*/
|
||||
_MEMBER_FUNCTION(Matrix4, AsMatrix3, 1, _T("x"))
|
||||
/*#
|
||||
Func: GetInverseMatrix
|
||||
Proto: Matrix4:
|
||||
Desc: Return inverse matrix.
|
||||
#*/
|
||||
_MEMBER_FUNCTION(Matrix4, GetInverseMatrix, 1, _T("x"))
|
||||
/*#
|
||||
Func: Print
|
||||
Proto: void:
|
||||
Desc: Output matrix content to the engine log.
|
||||
#*/
|
||||
_MEMBER_FUNCTION(Matrix4, Print, -1, _T("x"))
|
||||
/*#
|
||||
Func: RotationFromMatrix3
|
||||
Proto: void:Matrix3 orientation
|
||||
Desc: Set the rotation part of a 4x4 transformation matrix from a 3x3 matrix.
|
||||
#*/
|
||||
_MEMBER_FUNCTION(Matrix4, RotationFromMatrix3, 2, _T("xx"))
|
||||
|
||||
/*#
|
||||
Section: Matrix4Component
|
||||
Desc: Transformation matrix component
|
||||
#*/
|
||||
|
||||
/*#
|
||||
Func: GetFront
|
||||
Proto: Vector:
|
||||
Desc: Return the transformation matrix front axis vector.
|
||||
#*/
|
||||
_MEMBER_FUNCTION(Matrix4, GetFront, 1, _T("x"))
|
||||
/*#
|
||||
Func: GetBack
|
||||
Proto: Vector:
|
||||
Desc: Return the transformation matrix down axis vector.
|
||||
#*/
|
||||
_MEMBER_FUNCTION(Matrix4, GetBack, 1, _T("x"))
|
||||
/*#
|
||||
Func: GetRight
|
||||
Proto: Vector:
|
||||
Desc: Return the transformation matrix right axis vector.
|
||||
#*/
|
||||
_MEMBER_FUNCTION(Matrix4, GetRight, 1, _T("x"))
|
||||
/*#
|
||||
Func: GetLeft
|
||||
Proto: Vector:
|
||||
Desc: Return the transformation matrix left axis vector.
|
||||
#*/
|
||||
_MEMBER_FUNCTION(Matrix4, GetLeft, 1, _T("x"))
|
||||
/*#
|
||||
Func: GetUp
|
||||
Proto: Vector:
|
||||
Desc: Return the transformation matrix up axis vector.
|
||||
#*/
|
||||
_MEMBER_FUNCTION(Matrix4, GetUp, 1, _T("x"))
|
||||
/*#
|
||||
Func: GetDown
|
||||
Proto: Vector:
|
||||
Desc: Return the transformation matrix down axis vector.
|
||||
#*/
|
||||
_MEMBER_FUNCTION(Matrix4, GetDown, 1, _T("x"))
|
||||
/*#
|
||||
Func: GetPosition
|
||||
Proto: Vector:
|
||||
Desc: Return the transformation matrix position vector.
|
||||
#*/
|
||||
_MEMBER_FUNCTION(Matrix4, GetPosition, 1, _T("x"))
|
||||
|
||||
_END_CLASS(Matrix4)
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
_DECL_CLASS(Matrix3);
|
||||
_IMPL_NATIVE_CONSTRUCTION(Matrix3, Matrix3);
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
_MEMBER_FUNCTION_IMPL(Matrix3, constructor)
|
||||
Matrix3 temp, *newv = NULL;
|
||||
int nparams = sa.GetParamCount();
|
||||
|
||||
switch (nparams)
|
||||
{
|
||||
case 1: temp.Set(1, 0, 0, 0, 1, 0, 0, 0, 1); break;
|
||||
case 4:
|
||||
{
|
||||
_GetTypedParam(_u, 2, Vector4, Vector);
|
||||
_GetTypedParam(_v, 3, Vector4, Vector);
|
||||
_GetTypedParam(_w, 4, Vector4, Vector);
|
||||
|
||||
if (_u && _v && _w)
|
||||
{ temp.Set(*_u, *_v, *_w); }
|
||||
else
|
||||
return sa.ThrowError("Matrix3() invalid parameters");
|
||||
}
|
||||
break;
|
||||
|
||||
case 10:
|
||||
temp.Set(
|
||||
sa.GetFloat(2), sa.GetFloat(3), sa.GetFloat(4),
|
||||
sa.GetFloat(5), sa.GetFloat(6), sa.GetFloat(7),
|
||||
sa.GetFloat(8), sa.GetFloat(9), sa.GetFloat(10)
|
||||
);
|
||||
break;
|
||||
|
||||
default:
|
||||
return sa.ThrowError("Matrix3() wrong parameter count");
|
||||
}
|
||||
|
||||
newv = new Matrix3(temp);
|
||||
return construct_Matrix3(v, newv);
|
||||
_END_IMPL
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
_MEMBER_FUNCTION_IMPL(Matrix3, _set)
|
||||
_GetSelf(Matrix3, Matrix3);
|
||||
|
||||
switch (sa.GetType(2))
|
||||
{
|
||||
case OT_STRING:
|
||||
{
|
||||
String idx(sa.GetString(2));
|
||||
|
||||
if (idx == uc_m00) return sa.Return(self->m[0][0] = sa.GetFloat(3));
|
||||
if (idx == uc_m10) return sa.Return(self->m[1][0] = sa.GetFloat(3));
|
||||
if (idx == uc_m20) return sa.Return(self->m[2][0] = sa.GetFloat(3));
|
||||
if (idx == uc_m01) return sa.Return(self->m[0][1] = sa.GetFloat(3));
|
||||
if (idx == uc_m11) return sa.Return(self->m[1][1] = sa.GetFloat(3));
|
||||
if (idx == uc_m21) return sa.Return(self->m[2][1] = sa.GetFloat(3));
|
||||
if (idx == uc_m02) return sa.Return(self->m[0][2] = sa.GetFloat(3));
|
||||
if (idx == uc_m12) return sa.Return(self->m[1][2] = sa.GetFloat(3));
|
||||
if (idx == uc_m22) return sa.Return(self->m[2][2] = sa.GetFloat(3));
|
||||
}
|
||||
break;
|
||||
}
|
||||
return SQ_ERROR;
|
||||
_END_IMPL
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
_MEMBER_FUNCTION_IMPL(Matrix3, _get)
|
||||
_GetSelf(Matrix3, Matrix3);
|
||||
|
||||
switch (sa.GetType(2))
|
||||
{
|
||||
case OT_STRING:
|
||||
{
|
||||
String idx(sa.GetString(2));
|
||||
|
||||
if (idx == uc_m00) return sa.Return(self->m[0][0]);
|
||||
if (idx == uc_m10) return sa.Return(self->m[1][0]);
|
||||
if (idx == uc_m20) return sa.Return(self->m[2][0]);
|
||||
if (idx == uc_m01) return sa.Return(self->m[0][1]);
|
||||
if (idx == uc_m11) return sa.Return(self->m[1][1]);
|
||||
if (idx == uc_m21) return sa.Return(self->m[2][1]);
|
||||
if (idx == uc_m02) return sa.Return(self->m[0][2]);
|
||||
if (idx == uc_m12) return sa.Return(self->m[1][2]);
|
||||
if (idx == uc_m22) return sa.Return(self->m[2][2]);
|
||||
}
|
||||
break;
|
||||
}
|
||||
return SQ_ERROR;
|
||||
_END_IMPL
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
_MEMBER_FUNCTION_IMPL(Matrix3, GetRow)
|
||||
_GetSelf(Matrix3, Matrix3);
|
||||
_SA_RETURN_OBJECT(new_Vector(v, self->GetRow(sa.GetInt(2))));
|
||||
_END_IMPL
|
||||
_MEMBER_FUNCTION_IMPL(Matrix3, SetRow)
|
||||
_GetSelf(Matrix3, Matrix3);
|
||||
_GetTypedParam(row, 3, Vector4, Vector)
|
||||
self->SetRow(sa.GetInt(2), *row);
|
||||
return 0;
|
||||
_END_IMPL
|
||||
_MEMBER_FUNCTION_IMPL(Matrix3, GetColumn)
|
||||
_GetSelf(Matrix3, Matrix3);
|
||||
_SA_RETURN_OBJECT(new_Vector(v, self->GetColumn(sa.GetInt(2))));
|
||||
_END_IMPL
|
||||
_MEMBER_FUNCTION_IMPL(Matrix3, SetColumn)
|
||||
_GetSelf(Matrix3, Matrix3);
|
||||
_GetTypedParam(col, 3, Vector4, Vector)
|
||||
self->SetColumn(sa.GetInt(2), *col);
|
||||
return 0;
|
||||
_END_IMPL
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
_MEMBER_FUNCTION_IMPL(Matrix3, _mul)
|
||||
_GetSelf(Matrix3, Matrix3);
|
||||
_GetTypedParam(mtx, 2, Matrix3, Matrix3)
|
||||
_SA_RETURN_OBJECT(new_Matrix3(v, *self * *mtx));
|
||||
_END_IMPL
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
_MEMBER_FUNCTION_IMPL(Matrix3, AsMatrix4)
|
||||
_GetSelf(Matrix3, Matrix3);
|
||||
_SA_RETURN_OBJECT(new_Matrix4(v, Matrix4::FromMatrix3(*self)));
|
||||
_END_IMPL
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
_MEMBER_FUNCTION_IMPL(Matrix3, FromOrthonormalBasis)
|
||||
// _CHECK_SELF(Matrix3, Matrix3);
|
||||
_GetTypedParam(_w, 2, Vector4, Vector)
|
||||
Vector4 *_v = NULL;
|
||||
switch (sa.GetParamCount())
|
||||
{
|
||||
case 2:
|
||||
break;
|
||||
case 3:
|
||||
{ _GetTypedParam(__v, 3, Vector4, Vector)
|
||||
_v = __v; } break;
|
||||
default:
|
||||
return sa.ThrowError("Matrix3::FromOrthonormalBasis() wrong parameter count");
|
||||
}
|
||||
_SA_RETURN_OBJECT(new_Matrix3(v, Matrix3::FromOrthonormalBasis(*_w, _v)));
|
||||
_END_IMPL
|
||||
|
||||
_MEMBER_FUNCTION_IMPL(Matrix3, SlerpTo)
|
||||
_GetSelf(Matrix3, Matrix3);
|
||||
_GetTypedParam(to, 3, Matrix3, Matrix3)
|
||||
float t = sa.GetFloat(2);
|
||||
Matrix3 out = Quaternion::Slerp(t, Quaternion::FromMatrix3(*self), Quaternion::FromMatrix3(*to)).AsMatrix3();
|
||||
_SA_RETURN_OBJECT(new_Matrix3(v, out))
|
||||
_END_IMPL
|
||||
|
||||
_MEMBER_FUNCTION_IMPL(Matrix3, AsEuler)
|
||||
_GetSelf(Matrix3, Matrix3);
|
||||
Math::rOrder rorder = Math::rOrder_Default;
|
||||
if (sa.GetParamCount() == 2)
|
||||
rorder = (Math::rOrder)sa.GetInt(2);
|
||||
_SA_RETURN_OBJECT(new_Vector(v, self->AsEuler(rorder)));
|
||||
_END_IMPL
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/*#
|
||||
Section: Matrix3Generic
|
||||
Desc: Matrix 3x3
|
||||
#*/
|
||||
_BEGIN_CLASS(Matrix3)
|
||||
_MEMBER_FUNCTION(Matrix3, constructor, -1, _T(". n|x n|x n|x nnn nnn"))
|
||||
_MEMBER_FUNCTION(Matrix3, _get, 2, _T("xs"))
|
||||
_MEMBER_FUNCTION(Matrix3, _set, 3, _T("xsn"))
|
||||
_MEMBER_FUNCTION(Matrix3, _mul, 2, _T("xx"))
|
||||
/*#
|
||||
Func: GetRow
|
||||
Proto: Vector:int index
|
||||
Desc: Return a matrix row as a vector.
|
||||
#*/
|
||||
_MEMBER_FUNCTION(Matrix3, GetRow, 2, _T("xi"))
|
||||
/*#
|
||||
Func: SetRow
|
||||
Proto: void:int index, Vector row
|
||||
Desc: Set a matrix row from a vector.
|
||||
#*/
|
||||
_MEMBER_FUNCTION(Matrix3, SetRow, 3, _T("xix"))
|
||||
/*#
|
||||
Func: GetColumn
|
||||
Proto: Vector:int index
|
||||
Desc: Return a matrix column as a vector.
|
||||
#*/
|
||||
_MEMBER_FUNCTION(Matrix3, GetColumn, 2, _T("xi"))
|
||||
/*#
|
||||
Func: SetColumn
|
||||
Proto: void:int index, Vector column
|
||||
Desc: Set a matrix column from a vector.
|
||||
#*/
|
||||
_MEMBER_FUNCTION(Matrix3, SetColumn, 3, _T("xix"))
|
||||
/*#
|
||||
Func: AsMatrix4
|
||||
Proto: Matrix4:
|
||||
Desc: Return matrix as a 4x4 matrix.
|
||||
#*/
|
||||
_MEMBER_FUNCTION(Matrix3, AsMatrix4, 1, _T("x"))
|
||||
/*#
|
||||
Func: FromOrthonormalBasis
|
||||
Proto: Matrix3:Vector u,[Vector v]
|
||||
Desc: Build an orientation matrix from one or two basis vectors.
|
||||
#*/
|
||||
_MEMBER_FUNCTION(Matrix3, FromOrthonormalBasis, -2, _T(".xx"))
|
||||
/*#
|
||||
Func: SlerpTo
|
||||
Proto: Matrix3:float t,Matrix3 to
|
||||
Desc: Interpolate a 3x3 orientation matrix to another 3x3 orientation matrix using spherical linear interpolation.
|
||||
Example:
|
||||
local m_a = ItemGetRotationMatrix(item_a)
|
||||
local m_b = ItemGetRotationMatrix(item_b)
|
||||
|
||||
// m_c will store a rotation halfway between the rotation stored in the m_a and m_b matrices.
|
||||
local m_c = m_a.SlerpTo(0.5, m_b)
|
||||
#*/
|
||||
_MEMBER_FUNCTION(Matrix3, SlerpTo, 3, _T("xnx"))
|
||||
/*#
|
||||
Func: AsEuler
|
||||
Proto: Vector:[RotationOrder method]
|
||||
Desc: Return a 3x3 orientation matrix as an Euler triplet.
|
||||
#*/
|
||||
_MEMBER_FUNCTION(Matrix3, AsEuler, -1, _T("xi"))
|
||||
_END_CLASS(Matrix3)
|
||||
328
include/modules/script_squirrel/cobject/quaternion_impl.cpp
Normal file
328
include/modules/script_squirrel/cobject/quaternion_impl.cpp
Normal file
@ -0,0 +1,328 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
nEngine - GSFramework
|
||||
Copyright 2001-2012 Emmanuel Julien. All Rights Reserved.
|
||||
------------------------------------------------------------------------------*/
|
||||
|
||||
#include "script_squirrel/cobject/quaternion_decl.h"
|
||||
#include "script_squirrel/cobject/matrix_decl.h"
|
||||
#include "script_squirrel/cobject/vector_decl.h"
|
||||
#include "math/matrix3.h"
|
||||
#include "math/quaternion.h"
|
||||
#include "math/vector.h"
|
||||
#include "nstring/nstring.h"
|
||||
#include "log/log.h"
|
||||
|
||||
using namespace GS;
|
||||
|
||||
|
||||
_DECL_CLASS(Quaternion)
|
||||
_IMPL_NATIVE_CONSTRUCTION(Quaternion, Quaternion)
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
_MEMBER_FUNCTION_IMPL(Quaternion, constructor)
|
||||
Quaternion temp;
|
||||
int nparams = sa.GetParamCount();
|
||||
|
||||
switch (nparams)
|
||||
{
|
||||
case 1: temp.Set(); break;
|
||||
case 5:
|
||||
temp.Set(sa.GetFloat(2), sa.GetFloat(3), sa.GetFloat(4), sa.GetFloat(5));
|
||||
break;
|
||||
|
||||
default:
|
||||
return sa.ThrowError("Quaternion() wrong parameter count");
|
||||
}
|
||||
return construct_Quaternion(v, new Quaternion(temp));
|
||||
|
||||
_END_IMPL
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
_MEMBER_FUNCTION_IMPL(Quaternion, _cloned)
|
||||
_GetTypedParam(quat, 2, Quaternion, Quaternion);
|
||||
return construct_Quaternion(v, new Quaternion(*quat));
|
||||
_END_IMPL
|
||||
|
||||
_MEMBER_FUNCTION_IMPL(Quaternion, _set)
|
||||
_GetSelf(Quaternion, Quaternion);
|
||||
|
||||
const SQChar *s = sa.GetString(2);
|
||||
int index = s ? s[0] : sa.GetInt(2);
|
||||
|
||||
switch (index)
|
||||
{
|
||||
case 0: case 'x':
|
||||
return sa.Return(self->x = sa.GetFloat(3));
|
||||
case 1: case 'y':
|
||||
return sa.Return(self->y = sa.GetFloat(3));
|
||||
case 2: case 'z':
|
||||
return sa.Return(self->z = sa.GetFloat(3));
|
||||
case 3: case 'w':
|
||||
return sa.Return(self->w = sa.GetFloat(3));
|
||||
}
|
||||
return SQ_ERROR;
|
||||
_END_IMPL
|
||||
|
||||
_MEMBER_FUNCTION_IMPL(Quaternion, _get)
|
||||
_GetSelf(Quaternion, Quaternion);
|
||||
const SQChar *s = sa.GetString(2);
|
||||
if (s && (s[1] != 0))
|
||||
return SQ_ERROR;
|
||||
int index = s && (s[1] == 0) ? s[0] : sa.GetInt(2);
|
||||
|
||||
switch (index)
|
||||
{
|
||||
case 0: case 'x':
|
||||
return sa.Return(self->x);
|
||||
case 1: case 'y':
|
||||
return sa.Return(self->y);
|
||||
case 2: case 'z':
|
||||
return sa.Return(self->z);
|
||||
case 3: case 'w':
|
||||
return sa.Return(self->w);
|
||||
}
|
||||
return SQ_ERROR;
|
||||
_END_IMPL
|
||||
|
||||
_MEMBER_FUNCTION_IMPL(Quaternion, _mul)
|
||||
_GetSelf(Quaternion, Quaternion);
|
||||
switch (sa.GetType(2))
|
||||
{
|
||||
case OT_INSTANCE:
|
||||
{
|
||||
// Quaternion * Quaternion.
|
||||
_CHECK_INST_PARAM_RAW(quat, 2, Quaternion, Quaternion);
|
||||
if (quat)
|
||||
_SA_RETURN_OBJECT(new_Quaternion(v, *self * *quat));
|
||||
}
|
||||
break;
|
||||
|
||||
// Quaternion * Scalar
|
||||
case OT_INTEGER:
|
||||
_SA_RETURN_OBJECT(new_Quaternion(v, *self * (float)sa.GetInt(2)));
|
||||
case OT_FLOAT:
|
||||
_SA_RETURN_OBJECT(new_Quaternion(v, *self * sa.GetFloat(2)));
|
||||
}
|
||||
return sa.ThrowError("Quaternion * operator: Invalid argument type.\n");
|
||||
_END_IMPL
|
||||
|
||||
_MEMBER_FUNCTION_IMPL(Quaternion, _div)
|
||||
_GetSelf(Quaternion, Quaternion);
|
||||
switch (sa.GetType(2))
|
||||
{
|
||||
// Quaternion / Scalar
|
||||
case OT_INTEGER:
|
||||
_SA_RETURN_OBJECT(new_Quaternion(v, *self / (float)sa.GetInt(2)));
|
||||
case OT_FLOAT:
|
||||
_SA_RETURN_OBJECT(new_Quaternion(v, *self / sa.GetFloat(2)));
|
||||
}
|
||||
return sa.ThrowError("Quaternion / operator: Invalid argument type.\n");
|
||||
_END_IMPL
|
||||
|
||||
_MEMBER_FUNCTION_IMPL(Quaternion, _add)
|
||||
_GetSelf(Quaternion, Quaternion);
|
||||
switch (sa.GetType(2))
|
||||
{
|
||||
case OT_INSTANCE:
|
||||
{
|
||||
// Quaternion + Quaternion.
|
||||
_CHECK_INST_PARAM_RAW(quat, 2, Quaternion, Quaternion);
|
||||
if (quat)
|
||||
_SA_RETURN_OBJECT(new_Quaternion(v, *self + *quat));
|
||||
}
|
||||
break;
|
||||
|
||||
// Quaternion + Scalar
|
||||
case OT_INTEGER:
|
||||
_SA_RETURN_OBJECT(new_Quaternion(v, *self + (float)sa.GetInt(2)));
|
||||
case OT_FLOAT:
|
||||
_SA_RETURN_OBJECT(new_Quaternion(v, *self + sa.GetFloat(2)));
|
||||
}
|
||||
return sa.ThrowError("Quaternion + operator: Invalid argument type.\n");
|
||||
_END_IMPL
|
||||
|
||||
_MEMBER_FUNCTION_IMPL(Quaternion, _sub)
|
||||
_GetSelf(Quaternion, Quaternion);
|
||||
switch (sa.GetType(2))
|
||||
{
|
||||
case OT_INSTANCE:
|
||||
{
|
||||
// Quaternion - Quaternion.
|
||||
_CHECK_INST_PARAM_RAW(quat, 2, Quaternion, Quaternion);
|
||||
if (quat)
|
||||
_SA_RETURN_OBJECT(new_Quaternion(v, *self - *quat));
|
||||
}
|
||||
break;
|
||||
|
||||
// Quaternion - Scalar
|
||||
case OT_INTEGER:
|
||||
_SA_RETURN_OBJECT(new_Quaternion(v, *self - (float)sa.GetInt(2)));
|
||||
case OT_FLOAT:
|
||||
_SA_RETURN_OBJECT(new_Quaternion(v, *self - sa.GetFloat(2)));
|
||||
}
|
||||
return sa.ThrowError("Quaternion - operator: Invalid argument type.\n");
|
||||
_END_IMPL
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
_MEMBER_FUNCTION_IMPL(Quaternion, Set)
|
||||
_GetSelf(Quaternion, Quaternion);
|
||||
switch (sa.GetParamCount())
|
||||
{
|
||||
case 1: self->Set(); break;
|
||||
case 2: self->Set(sa.GetFloat(2)); break;
|
||||
case 3: self->Set(sa.GetFloat(2), sa.GetFloat(3)); break;
|
||||
case 4: self->Set(sa.GetFloat(2), sa.GetFloat(3), sa.GetFloat(4)); break;
|
||||
case 5: self->Set(sa.GetFloat(2), sa.GetFloat(3), sa.GetFloat(4), sa.GetFloat(5)); break;
|
||||
default:
|
||||
return sa.ThrowError("Quaternion Set() wrong parameters");
|
||||
}
|
||||
return 0;
|
||||
_END_IMPL
|
||||
|
||||
_MEMBER_FUNCTION_IMPL(Quaternion, Slerp)
|
||||
_GetSelf(Quaternion, Quaternion);
|
||||
float k = sa.GetFloat(2);
|
||||
_GetTypedParam(quat, 3, Quaternion, Quaternion)
|
||||
_SA_RETURN_OBJECT(new_Quaternion(v, Quaternion::Slerp(k, *self, *quat)));
|
||||
_END_IMPL
|
||||
|
||||
_MEMBER_FUNCTION_IMPL(Quaternion, Normalize)
|
||||
_GetSelf(Quaternion, Quaternion);
|
||||
_SA_RETURN_OBJECT(new_Quaternion(v, self->Normalize()));
|
||||
_END_IMPL
|
||||
|
||||
_MEMBER_FUNCTION_IMPL(Quaternion, Inverse)
|
||||
_GetSelf(Quaternion, Quaternion);
|
||||
_SA_RETURN_OBJECT(new_Quaternion(v, self->Inverse()));
|
||||
_END_IMPL
|
||||
|
||||
_MEMBER_FUNCTION_IMPL(Quaternion, Dot)
|
||||
_GetSelf(Quaternion, Quaternion);
|
||||
_GetTypedParam(quat, 2, Quaternion, Quaternion);
|
||||
return sa.Return(self->Dot(*quat));
|
||||
_END_IMPL
|
||||
|
||||
_MEMBER_FUNCTION_IMPL(Quaternion, AsMatrix3)
|
||||
_GetSelf(Quaternion, Quaternion);
|
||||
_SA_RETURN_OBJECT(new_Matrix3(v, self->AsMatrix3()));
|
||||
_END_IMPL
|
||||
|
||||
_MEMBER_FUNCTION_IMPL(Quaternion, QuaternionFromAxisAngle)
|
||||
_GetSelf(Quaternion, Quaternion);
|
||||
_GetTypedParam(vec, 3, Vector4, Vector);
|
||||
_SA_RETURN_OBJECT(new_Quaternion(v, Quaternion::FromAxisAngle(sa.GetFloat(2), vec->x, vec->y, vec->z)));
|
||||
_END_IMPL
|
||||
|
||||
_MEMBER_FUNCTION_IMPL(Quaternion, QuaternionFromMatrix3)
|
||||
_GetSelf(Quaternion, Quaternion);
|
||||
_GetTypedParam(mtx, 2, Matrix3, Matrix3);
|
||||
_SA_RETURN_OBJECT(new_Quaternion(v, Quaternion::FromMatrix3(*mtx)));
|
||||
_END_IMPL
|
||||
|
||||
_MEMBER_FUNCTION_IMPL(Quaternion, QuaternionLookAt)
|
||||
_GetSelf(Quaternion, Quaternion);
|
||||
_GetTypedParam(vec, 2, Vector4, Vector);
|
||||
_SA_RETURN_OBJECT(new_Quaternion(v, Quaternion::LookAt(*vec)));
|
||||
_END_IMPL
|
||||
|
||||
_MEMBER_FUNCTION_IMPL(Quaternion, Print)
|
||||
_GetSelf(Quaternion, Quaternion);
|
||||
const char *label = "Quaternion";
|
||||
if (sa.GetParamCount() == 2)
|
||||
label = sa.GetString(2);
|
||||
__LOG__ << label << ": { x = " << self->x << ", y = " << self->y << ", z = " << self->z << ", w = " << self->w << "}\n";
|
||||
return 0;
|
||||
_END_IMPL
|
||||
|
||||
/*#
|
||||
Topic: Quaternion
|
||||
Type: Quaternion
|
||||
#*/
|
||||
|
||||
/*#
|
||||
Section: QuaternionGeneric
|
||||
Desc: Generic
|
||||
#*/
|
||||
_BEGIN_CLASS(Quaternion)
|
||||
|
||||
/*#
|
||||
Func: Quaternion
|
||||
Proto: Quaternion:float x = 0,float y = 0,float z = 0,float w = 1
|
||||
Desc: Create a new quaternion.
|
||||
Example:
|
||||
local u = Quaternion()
|
||||
local v = Quaternion(0, 0, 0, 1)
|
||||
|
||||
u.Set(-1, 0, 0)
|
||||
#*/
|
||||
_MEMBER_FUNCTION(Quaternion, constructor, -1, _T(".n|xnnn"))
|
||||
_MEMBER_FUNCTION(Quaternion, _cloned, 2, _T(".x"))
|
||||
_MEMBER_FUNCTION(Quaternion, _set, 2, _T("xs|n"))
|
||||
_MEMBER_FUNCTION(Quaternion, _get, 2, _T("xs|n"))
|
||||
_MEMBER_FUNCTION(Quaternion, _add, 2, _T("xx|n"))
|
||||
_MEMBER_FUNCTION(Quaternion, _sub, 2, _T("xx|n"))
|
||||
_MEMBER_FUNCTION(Quaternion, _mul, 2, _T("xx|n"))
|
||||
_MEMBER_FUNCTION(Quaternion, _div, 2, _T("xn"))
|
||||
|
||||
/*#
|
||||
Func: Set
|
||||
Proto: void:float x = 0,float y = 0,float z = 0,float w = 1
|
||||
Desc: Set quaternion values.
|
||||
#*/
|
||||
_MEMBER_FUNCTION(Quaternion, Set, -1, _T("xnnnn"))
|
||||
/*#
|
||||
Func: Slerp
|
||||
Proto: Quaternion:float,Quaternion
|
||||
Desc: Returns a spherical linear interpolation.
|
||||
#*/
|
||||
_MEMBER_FUNCTION(Quaternion, Slerp, 3, _T("xnx"))
|
||||
/*#
|
||||
Func: Normalize
|
||||
Proto: Quaternion:void
|
||||
Desc: Returns the normalized quaternion.
|
||||
#*/
|
||||
_MEMBER_FUNCTION(Quaternion, Normalize, 1, _T("x"))
|
||||
/*#
|
||||
Func: Inverse
|
||||
Proto: Quaternion:void
|
||||
Desc: Returns the inverse quaternion.
|
||||
#*/
|
||||
_MEMBER_FUNCTION(Quaternion, Inverse, 1, _T("x"))
|
||||
/*#
|
||||
Func: Dot
|
||||
Proto: Quaternion:Quaternion
|
||||
Desc: Returns the Dot product.
|
||||
#*/
|
||||
_MEMBER_FUNCTION(Quaternion, Dot, 2, _T("xx"))
|
||||
/*#
|
||||
Func: AsMatrix3
|
||||
Proto: Matrix3:void
|
||||
Desc: Returns the Matrix3 from the quaternion.
|
||||
#*/
|
||||
_MEMBER_FUNCTION(Quaternion, AsMatrix3, 1, _T("x"))
|
||||
/*#
|
||||
Func: QuaternionFromAxisAngle
|
||||
Proto: Quaternion:float angle,Vector axis
|
||||
Desc: Returns a quaternion based on angle and axis.
|
||||
#*/
|
||||
_MEMBER_FUNCTION(Quaternion, QuaternionFromAxisAngle, 3, _T(".nx"))
|
||||
/*#
|
||||
Func: QuaternionFromMatrix3
|
||||
Proto: Quaternion:Matrix3
|
||||
Desc: Returns a quaternion based on a Matrix3.
|
||||
#*/
|
||||
_MEMBER_FUNCTION(Quaternion, QuaternionFromMatrix3, 2, _T(".x"))
|
||||
/*#
|
||||
Func: QuaternionLookAt
|
||||
Proto: Quaternion:Vector direction
|
||||
Desc: Returns a quaternion looking at direction.
|
||||
#*/
|
||||
_MEMBER_FUNCTION(Quaternion, QuaternionLookAt, 2, _T(".x"))
|
||||
/*#
|
||||
Func: Print
|
||||
Proto: void:
|
||||
Desc: Dump this quaternion components (x,y,z,w) to the engine log.
|
||||
#*/
|
||||
_MEMBER_FUNCTION(Quaternion, Print, -1, _T("x"))
|
||||
|
||||
_END_CLASS(Quaternion)
|
||||
@ -0,0 +1,113 @@
|
||||
#include "squirrel.h"
|
||||
#include "script_squirrel/cobject/squirrel_object.h"
|
||||
#include "script_squirrel/cobject/squirrel_bindings_utils.h"
|
||||
|
||||
bool CreateStaticNamespace(HSQUIRRELVM v,ScriptNamespaceDecl *sn)
|
||||
{
|
||||
int n = 0;
|
||||
sq_pushroottable(v);
|
||||
sq_pushstring(v,sn->name,-1);
|
||||
sq_newtable(v);
|
||||
const ScriptClassMemberDecl *members = sn->members;
|
||||
const ScriptClassMemberDecl *m = 0;
|
||||
while(members[n].name) {
|
||||
m = &members[n];
|
||||
sq_pushstring(v,m->name,-1);
|
||||
sq_newclosure(v,m->func,0);
|
||||
sq_setparamscheck(v,m->params,m->typemask);
|
||||
sq_setnativeclosurename(v,-1,m->name);
|
||||
sq_createslot(v,-3);
|
||||
n++;
|
||||
}
|
||||
const ScriptConstantDecl *consts = sn->constants;
|
||||
const ScriptConstantDecl *c = 0;
|
||||
n = 0;
|
||||
while(consts[n].name) {
|
||||
c = &consts[n];
|
||||
sq_pushstring(v,c->name,-1);
|
||||
switch(c->type) {
|
||||
case OT_STRING: sq_pushstring(v,c->val.s,-1);break;
|
||||
case OT_INTEGER: sq_pushinteger(v,c->val.i);break;
|
||||
case OT_FLOAT: sq_pushfloat(v,c->val.f);break;
|
||||
}
|
||||
sq_createslot(v,-3);
|
||||
n++;
|
||||
}
|
||||
if(sn->delegate) {
|
||||
const ScriptClassMemberDecl *members = sn->delegate;
|
||||
const ScriptClassMemberDecl *m = 0;
|
||||
sq_newtable(v);
|
||||
while(members[n].name) {
|
||||
m = &members[n];
|
||||
sq_pushstring(v,m->name,-1);
|
||||
sq_newclosure(v,m->func,0);
|
||||
sq_setparamscheck(v,m->params,m->typemask);
|
||||
sq_setnativeclosurename(v,-1,m->name);
|
||||
sq_createslot(v,-3);
|
||||
n++;
|
||||
}
|
||||
sq_setdelegate(v,-2);
|
||||
}
|
||||
sq_createslot(v,-3);
|
||||
sq_pop(v,1);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CreateClass(HSQUIRRELVM v,SquirrelClassDecl *cd)
|
||||
{
|
||||
int n = 0;
|
||||
int oldtop = sq_gettop(v);
|
||||
sq_pushroottable(v);
|
||||
sq_pushstring(v,cd->name,-1);
|
||||
if(cd->base) {
|
||||
sq_pushstring(v,cd->base,-1);
|
||||
if(SQ_FAILED(sq_get(v,-3))) {
|
||||
sq_settop(v,oldtop);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if(SQ_FAILED(sq_newclass(v,cd->base?1:0))) {
|
||||
sq_settop(v,oldtop);
|
||||
return false;
|
||||
}
|
||||
sq_settypetag(v,-1,(SQUserPointer)cd);
|
||||
const ScriptClassMemberDecl *members = cd->members;
|
||||
const ScriptClassMemberDecl *m = 0;
|
||||
while(members[n].name) {
|
||||
m = &members[n];
|
||||
sq_pushstring(v,m->name,-1);
|
||||
sq_newclosure(v,m->func,0);
|
||||
sq_setparamscheck(v,m->params,m->typemask);
|
||||
sq_setnativeclosurename(v,-1,m->name);
|
||||
sq_createslot(v,-3);
|
||||
n++;
|
||||
}
|
||||
sq_createslot(v,-3);
|
||||
sq_pop(v,1);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CreateNativeClassInstance(HSQUIRRELVM v,const SQChar *classname,SQUserPointer ud,SQRELEASEHOOK hook)
|
||||
{
|
||||
int oldtop = sq_gettop(v);
|
||||
sq_pushroottable(v);
|
||||
sq_pushstring(v,classname,-1);
|
||||
if(SQ_FAILED(sq_rawget(v,-2))){
|
||||
sq_settop(v,oldtop);
|
||||
return false;
|
||||
}
|
||||
//sq_pushroottable(v);
|
||||
if(SQ_FAILED(sq_createinstance(v,-1))) {
|
||||
sq_settop(v,oldtop);
|
||||
return false;
|
||||
}
|
||||
sq_remove(v,-3); //removes the root table
|
||||
sq_remove(v,-2); //removes the the class
|
||||
if(SQ_FAILED(sq_setinstanceup(v,-1,ud))) {
|
||||
sq_settop(v,oldtop);
|
||||
return false;
|
||||
}
|
||||
sq_setreleasehook(v,-1,hook);
|
||||
return true;
|
||||
}
|
||||
470
include/modules/script_squirrel/cobject/squirrel_object.cpp
Normal file
470
include/modules/script_squirrel/cobject/squirrel_object.cpp
Normal file
@ -0,0 +1,470 @@
|
||||
#include "squirrel.h"
|
||||
#include "squirrel_object.h"
|
||||
//#include "SquirrelVM.h"
|
||||
|
||||
SquirrelObject::SquirrelObject(HSQUIRRELVM v)
|
||||
{
|
||||
vm = v;
|
||||
sq_resetobject(&_o);
|
||||
}
|
||||
|
||||
SquirrelObject::~SquirrelObject()
|
||||
{
|
||||
if(vm)
|
||||
sq_release(vm,&_o);
|
||||
}
|
||||
|
||||
SquirrelObject::SquirrelObject(const SquirrelObject &o)
|
||||
{
|
||||
vm = o.vm;
|
||||
_o = o._o;
|
||||
sq_addref(vm,&_o);
|
||||
}
|
||||
|
||||
SquirrelObject::SquirrelObject(HSQOBJECT &o)
|
||||
{
|
||||
_o = o;
|
||||
sq_addref(vm,&_o);
|
||||
}
|
||||
|
||||
SquirrelObject SquirrelObject::Clone()
|
||||
{
|
||||
SquirrelObject ret(vm);
|
||||
if(GetType() == OT_TABLE || GetType() == OT_ARRAY)
|
||||
{
|
||||
sq_pushobject(vm,_o);
|
||||
sq_clone(vm,-1);
|
||||
ret.AttachToStackObject(-1);
|
||||
sq_pop(vm,2);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
SquirrelObject & SquirrelObject::operator =(const SquirrelObject &o)
|
||||
{
|
||||
HSQOBJECT t;
|
||||
t = o._o;
|
||||
sq_addref(vm,&t);
|
||||
sq_release(vm,&_o);
|
||||
_o = t;
|
||||
return *this;
|
||||
}
|
||||
|
||||
SquirrelObject & SquirrelObject::operator =(int n)
|
||||
{
|
||||
sq_pushinteger(vm,n);
|
||||
AttachToStackObject(-1);
|
||||
sq_pop(vm,1);
|
||||
return *this;
|
||||
}
|
||||
|
||||
void SquirrelObject::Append(const SquirrelObject &o)
|
||||
{
|
||||
if(sq_isarray(_o)) {
|
||||
sq_pushobject(vm,_o);
|
||||
sq_pushobject(vm,o._o);
|
||||
sq_arrayappend(vm,-2);
|
||||
sq_pop(vm,1);
|
||||
}
|
||||
}
|
||||
|
||||
void SquirrelObject::AttachToStackObject(int idx)
|
||||
{
|
||||
HSQOBJECT t;
|
||||
sq_getstackobj(vm,idx,&t);
|
||||
sq_addref(vm,&t);
|
||||
sq_release(vm,&_o);
|
||||
_o = t;
|
||||
}
|
||||
|
||||
bool SquirrelObject::SetDelegate(SquirrelObject &obj)
|
||||
{
|
||||
if(obj.GetType() == OT_TABLE ||
|
||||
obj.GetType() == OT_NULL) {
|
||||
switch(_o._type) {
|
||||
case OT_USERDATA:
|
||||
case OT_TABLE:
|
||||
sq_pushobject(vm,_o);
|
||||
sq_pushobject(vm,obj._o);
|
||||
if(SQ_SUCCEEDED(sq_setdelegate(vm,-2)))
|
||||
return true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
SquirrelObject SquirrelObject::GetDelegate()
|
||||
{
|
||||
SquirrelObject ret(vm);
|
||||
if(_o._type == OT_TABLE || _o._type == OT_USERDATA)
|
||||
{
|
||||
sq_pushobject(vm,_o);
|
||||
sq_getdelegate(vm,-1);
|
||||
ret.AttachToStackObject(-1);
|
||||
sq_pop(vm,2);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool SquirrelObject::IsNull() const
|
||||
{
|
||||
return sq_isnull(_o);
|
||||
}
|
||||
|
||||
bool SquirrelObject::IsNumeric() const
|
||||
{
|
||||
return sq_isnumeric(_o) ? true : false;
|
||||
}
|
||||
|
||||
int SquirrelObject::Len() const
|
||||
{
|
||||
int ret = 0;
|
||||
if(sq_isarray(_o) || sq_istable(_o) || sq_isstring(_o)) {
|
||||
sq_pushobject(vm,_o);
|
||||
ret = sq_getsize(vm,-1);
|
||||
sq_pop(vm,1);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
#define _SETVALUE_INT_BEGIN \
|
||||
bool ret = false; \
|
||||
int top = sq_gettop(vm); \
|
||||
sq_pushobject(vm,_o); \
|
||||
sq_pushinteger(vm,key);
|
||||
|
||||
#define _SETVALUE_INT_END \
|
||||
if(SQ_SUCCEEDED(sq_rawset(vm,-3))) { \
|
||||
ret = true; \
|
||||
} \
|
||||
sq_settop(vm,top); \
|
||||
return ret;
|
||||
|
||||
bool SquirrelObject::SetValue(SQInteger key,const SquirrelObject &val)
|
||||
{
|
||||
_SETVALUE_INT_BEGIN
|
||||
sq_pushobject(vm,val._o);
|
||||
_SETVALUE_INT_END
|
||||
}
|
||||
|
||||
bool SquirrelObject::SetValue(int key,int n)
|
||||
{
|
||||
_SETVALUE_INT_BEGIN
|
||||
sq_pushinteger(vm,n);
|
||||
_SETVALUE_INT_END
|
||||
}
|
||||
|
||||
bool SquirrelObject::SetValue(int key,float f)
|
||||
{
|
||||
_SETVALUE_INT_BEGIN
|
||||
sq_pushfloat(vm,f);
|
||||
_SETVALUE_INT_END
|
||||
}
|
||||
|
||||
bool SquirrelObject::SetValue(int key,const SQChar *s)
|
||||
{
|
||||
_SETVALUE_INT_BEGIN
|
||||
sq_pushstring(vm,s,-1);
|
||||
_SETVALUE_INT_END
|
||||
}
|
||||
|
||||
bool SquirrelObject::SetValue(int key,bool b)
|
||||
{
|
||||
_SETVALUE_INT_BEGIN
|
||||
sq_pushbool(vm,b);
|
||||
_SETVALUE_INT_END
|
||||
}
|
||||
|
||||
bool SquirrelObject::SetValue(const SquirrelObject &key,const SquirrelObject &val)
|
||||
{
|
||||
bool ret = false;
|
||||
int top = sq_gettop(vm);
|
||||
sq_pushobject(vm,_o);
|
||||
sq_pushobject(vm,key._o);
|
||||
sq_pushobject(vm,val._o);
|
||||
if(SQ_SUCCEEDED(sq_rawset(vm,-3))) {
|
||||
ret = true;
|
||||
}
|
||||
sq_settop(vm,top);
|
||||
return ret;
|
||||
}
|
||||
|
||||
#define _SETVALUE_STR_BEGIN \
|
||||
bool ret = false; \
|
||||
int top = sq_gettop(vm); \
|
||||
sq_pushobject(vm,_o); \
|
||||
sq_pushstring(vm,key,-1);
|
||||
|
||||
#define _SETVALUE_STR_END \
|
||||
if(SQ_SUCCEEDED(sq_rawset(vm,-3))) { \
|
||||
ret = true; \
|
||||
} \
|
||||
sq_settop(vm,top); \
|
||||
return ret;
|
||||
|
||||
bool SquirrelObject::SetValue(const SQChar *key,const SquirrelObject &val)
|
||||
{
|
||||
_SETVALUE_STR_BEGIN
|
||||
sq_pushobject(vm,val._o);
|
||||
_SETVALUE_STR_END
|
||||
}
|
||||
|
||||
bool SquirrelObject::SetValue(const SQChar *key,int n)
|
||||
{
|
||||
_SETVALUE_STR_BEGIN
|
||||
sq_pushinteger(vm,n);
|
||||
_SETVALUE_STR_END
|
||||
}
|
||||
|
||||
bool SquirrelObject::SetValue(const SQChar *key,float f)
|
||||
{
|
||||
_SETVALUE_STR_BEGIN
|
||||
sq_pushfloat(vm,f);
|
||||
_SETVALUE_STR_END
|
||||
}
|
||||
|
||||
bool SquirrelObject::SetValue(const SQChar *key,const SQChar *s)
|
||||
{
|
||||
_SETVALUE_STR_BEGIN
|
||||
sq_pushstring(vm,s,-1);
|
||||
_SETVALUE_STR_END
|
||||
}
|
||||
|
||||
bool SquirrelObject::SetValue(const SQChar *key,bool b)
|
||||
{
|
||||
_SETVALUE_STR_BEGIN
|
||||
sq_pushbool(vm,b);
|
||||
_SETVALUE_STR_END
|
||||
}
|
||||
|
||||
|
||||
SQObjectType SquirrelObject::GetType()
|
||||
{
|
||||
return _o._type;
|
||||
}
|
||||
|
||||
bool SquirrelObject::GetSlot(int key) const
|
||||
{
|
||||
sq_pushobject(vm,_o);
|
||||
sq_pushinteger(vm,key);
|
||||
if(SQ_SUCCEEDED(sq_get(vm,-2))) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
SquirrelObject SquirrelObject::GetValue(int key)const
|
||||
{
|
||||
SquirrelObject ret(vm);
|
||||
if(GetSlot(key)) {
|
||||
ret.AttachToStackObject(-1);
|
||||
sq_pop(vm,1);
|
||||
}
|
||||
sq_pop(vm,1);
|
||||
return ret;
|
||||
}
|
||||
|
||||
float SquirrelObject::GetFloat(int key) const
|
||||
{
|
||||
float ret = 0.0f;
|
||||
if(GetSlot(key)) {
|
||||
sq_getfloat(vm,-1,&ret);
|
||||
sq_pop(vm,1);
|
||||
}
|
||||
sq_pop(vm,1);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int SquirrelObject::GetInt(int key) const
|
||||
{
|
||||
SQInteger ret = 0;
|
||||
if(GetSlot(key)) {
|
||||
sq_getinteger(vm,-1,&ret);
|
||||
sq_pop(vm,1);
|
||||
}
|
||||
sq_pop(vm,1);
|
||||
return (int)ret;
|
||||
}
|
||||
|
||||
const SQChar *SquirrelObject::GetString(int key) const
|
||||
{
|
||||
const SQChar *ret = 0;
|
||||
if(GetSlot(key)) {
|
||||
sq_getstring(vm,-1,&ret);
|
||||
sq_pop(vm,1);
|
||||
}
|
||||
sq_pop(vm,1);
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool SquirrelObject::GetBool(int key) const
|
||||
{
|
||||
SQBool ret = false;
|
||||
if(GetSlot(key)) {
|
||||
sq_getbool(vm,-1,&ret);
|
||||
sq_pop(vm,1);
|
||||
}
|
||||
sq_pop(vm,1);
|
||||
return ret?true:false;
|
||||
}
|
||||
|
||||
bool SquirrelObject::Exists(const SQChar *key) const
|
||||
{
|
||||
bool ret = false;
|
||||
if(GetSlot(key)) {
|
||||
ret = true;
|
||||
}
|
||||
sq_pop(vm,1);
|
||||
return ret;
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool SquirrelObject::GetSlot(const SQChar *name) const
|
||||
{
|
||||
sq_pushobject(vm,_o);
|
||||
sq_pushstring(vm,name,-1);
|
||||
if(SQ_SUCCEEDED(sq_get(vm,-2))) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
SquirrelObject SquirrelObject::GetValue(const SQChar *key)const
|
||||
{
|
||||
SquirrelObject ret(vm);
|
||||
if(GetSlot(key)) {
|
||||
ret.AttachToStackObject(-1);
|
||||
sq_pop(vm,1);
|
||||
}
|
||||
sq_pop(vm,1);
|
||||
return ret;
|
||||
}
|
||||
|
||||
float SquirrelObject::GetFloat(const SQChar *key) const
|
||||
{
|
||||
float ret = 0.0f;
|
||||
if(GetSlot(key)) {
|
||||
sq_getfloat(vm,-1,&ret);
|
||||
sq_pop(vm,1);
|
||||
}
|
||||
sq_pop(vm,1);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int SquirrelObject::GetInt(const SQChar *key) const
|
||||
{
|
||||
SQInteger ret = 0;
|
||||
if(GetSlot(key)) {
|
||||
sq_getinteger(vm,-1,&ret);
|
||||
sq_pop(vm,1);
|
||||
}
|
||||
sq_pop(vm,1);
|
||||
return (int)ret;
|
||||
}
|
||||
|
||||
const SQChar *SquirrelObject::GetString(const SQChar *key) const
|
||||
{
|
||||
const SQChar *ret = 0;
|
||||
if(GetSlot(key)) {
|
||||
sq_getstring(vm,-1,&ret);
|
||||
sq_pop(vm,1);
|
||||
}
|
||||
sq_pop(vm,1);
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool SquirrelObject::GetBool(const SQChar *key) const
|
||||
{
|
||||
SQBool ret = false;
|
||||
if(GetSlot(key)) {
|
||||
sq_getbool(vm,-1,&ret);
|
||||
sq_pop(vm,1);
|
||||
}
|
||||
sq_pop(vm,1);
|
||||
return ret?true:false;
|
||||
}
|
||||
|
||||
SQUserPointer SquirrelObject::GetInstanceUP(SQUserPointer tag) const
|
||||
{
|
||||
SQUserPointer up = 0;
|
||||
sq_pushobject(vm,_o);
|
||||
sq_getinstanceup(vm,-1,(SQUserPointer*)&up,(SQUserPointer)tag);
|
||||
sq_pop(vm,1);
|
||||
return up;
|
||||
}
|
||||
|
||||
bool SquirrelObject::SetInstanceUP(SQUserPointer up)
|
||||
{
|
||||
if(!sq_isinstance(_o)) return false;
|
||||
sq_pushobject(vm,_o);
|
||||
sq_setinstanceup(vm,-1,up);
|
||||
sq_pop(vm,1);
|
||||
return true;
|
||||
}
|
||||
|
||||
SquirrelObject SquirrelObject::GetAttributes(const SQChar *key)
|
||||
{
|
||||
SquirrelObject ret(vm);
|
||||
int top = sq_gettop(vm);
|
||||
sq_pushobject(vm,_o);
|
||||
if(key)
|
||||
sq_pushstring(vm,key,-1);
|
||||
else
|
||||
sq_pushnull(vm);
|
||||
if(SQ_SUCCEEDED(sq_getattributes(vm,-2))) {
|
||||
ret.AttachToStackObject(-1);
|
||||
}
|
||||
sq_settop(vm,top);
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool SquirrelObject::BeginIteration()
|
||||
{
|
||||
if(!sq_istable(_o) && !sq_isarray(_o) && !sq_isclass(_o))
|
||||
return false;
|
||||
sq_pushobject(vm,_o);
|
||||
sq_pushnull(vm);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SquirrelObject::Next(SquirrelObject &key,SquirrelObject &val)
|
||||
{
|
||||
if(SQ_SUCCEEDED(sq_next(vm,-2))) {
|
||||
key.AttachToStackObject(-2);
|
||||
val.AttachToStackObject(-1);
|
||||
sq_pop(vm,2);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
const SQChar* SquirrelObject::ToString()
|
||||
{
|
||||
return sq_objtostring(&_o);
|
||||
}
|
||||
|
||||
SQInteger SquirrelObject::ToInteger()
|
||||
{
|
||||
return sq_objtointeger(&_o);
|
||||
}
|
||||
|
||||
SQFloat SquirrelObject::ToFloat()
|
||||
{
|
||||
return sq_objtofloat(&_o);
|
||||
}
|
||||
|
||||
bool SquirrelObject::ToBool()
|
||||
{
|
||||
//<<FIXME>>
|
||||
return _o._unVal.nInteger?true:false;
|
||||
}
|
||||
|
||||
void SquirrelObject::EndIteration()
|
||||
{
|
||||
sq_pop(vm,2);
|
||||
}
|
||||
29
include/modules/script_squirrel/cobject/uc_binding.cpp
Normal file
29
include/modules/script_squirrel/cobject/uc_binding.cpp
Normal file
@ -0,0 +1,29 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
GSFramework
|
||||
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
|
||||
----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
#include "script_squirrel/cobject/geometry_template_decl.h"
|
||||
#include "script_squirrel/cobject/cobject_decl.h"
|
||||
#include "script_squirrel/cobject/matrix_decl.h"
|
||||
#include "script_squirrel/cobject/vector_decl.h"
|
||||
#include "script_squirrel/cobject/uv_decl.h"
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void RegisterUCBinding(HSQUIRRELVM vm)
|
||||
{
|
||||
// Engine types wrapper object.
|
||||
_INIT_CLASS(vm, CObject)
|
||||
|
||||
// VM owned objects.
|
||||
_INIT_CLASS(vm, GeometryTemplate)
|
||||
|
||||
_INIT_CLASS(vm, Matrix3)
|
||||
_INIT_CLASS(vm, Matrix4)
|
||||
_INIT_CLASS(vm, Vector)
|
||||
|
||||
_INIT_CLASS(vm, UV)
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
122
include/modules/script_squirrel/cobject/uv_impl.cpp
Normal file
122
include/modules/script_squirrel/cobject/uv_impl.cpp
Normal file
@ -0,0 +1,122 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
GSFramework
|
||||
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
|
||||
----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
#include "script_squirrel/cobject/uv_decl.h"
|
||||
#include "script_squirrel/cobject/vector_decl.h"
|
||||
|
||||
using namespace GS;
|
||||
|
||||
#ifndef _T
|
||||
#define _T
|
||||
#endif
|
||||
|
||||
|
||||
_IMPL_NATIVE_CONSTRUCTION(UV, GS::Vector2);
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
_MEMBER_FUNCTION_IMPL(UV, constructor)
|
||||
Vector2 temp;
|
||||
int nparams = sa.GetParamCount();
|
||||
|
||||
switch (nparams)
|
||||
{
|
||||
case 1: temp.Set(0, 0); break;
|
||||
case 2:
|
||||
if (sa.GetType(2) == OT_INSTANCE)
|
||||
{
|
||||
_GetTypedParam(uv, 2, Vector2, UV);
|
||||
if (uv)
|
||||
temp = *uv;
|
||||
else return sa.ThrowError("Invalid instance type");
|
||||
}
|
||||
else temp.Set(sa.GetFloat(2), 0);
|
||||
break;
|
||||
case 3: temp.Set(sa.GetFloat(2), sa.GetFloat(3)); break;
|
||||
|
||||
default:
|
||||
return sa.ThrowError("Wrong parameter count");
|
||||
}
|
||||
return construct_UV(v, new Vector2(temp));
|
||||
_END_IMPL
|
||||
|
||||
_MEMBER_FUNCTION_IMPL(UV, _cloned)
|
||||
_GetTypedParam(uv, 2, Vector2, UV);
|
||||
return construct_UV(v, new Vector2(*uv));
|
||||
_END_IMPL
|
||||
|
||||
_MEMBER_FUNCTION_IMPL(UV, _set)
|
||||
_GetSelf(Vector2, UV);
|
||||
|
||||
const SQChar *s = sa.GetString(2);
|
||||
int index = s ? s[0] : sa.GetInt(2);
|
||||
|
||||
switch (index)
|
||||
{
|
||||
case 0: case 'u': case 'x':
|
||||
return sa.Return(self->x = sa.GetFloat(3));
|
||||
case 1: case 'v': case 'y':
|
||||
return sa.Return(self->y = sa.GetFloat(3));
|
||||
}
|
||||
return SQ_ERROR;
|
||||
_END_IMPL
|
||||
|
||||
_MEMBER_FUNCTION_IMPL(UV, _get)
|
||||
_GetSelf(Vector2, UV);
|
||||
const SQChar *s = sa.GetString(2);
|
||||
if (s && (s[1] != 0))
|
||||
return SQ_ERROR;
|
||||
int index = s && (s[1] == 0) ? s[0] : sa.GetInt(2);
|
||||
|
||||
switch (index)
|
||||
{
|
||||
case 0: case 'u': case 'x':
|
||||
return sa.Return(self->x);
|
||||
case 1: case 'v': case 'y':
|
||||
return sa.Return(self->y);
|
||||
}
|
||||
return SQ_ERROR;
|
||||
_END_IMPL
|
||||
|
||||
_MEMBER_FUNCTION_IMPL(UV, Set)
|
||||
_GetSelf(Vector2, UV);
|
||||
switch (sa.GetParamCount())
|
||||
{
|
||||
case 1: self->Set(0, 0); break;
|
||||
case 2: self->Set(sa.GetFloat(2), 0); break;
|
||||
case 3: self->Set(sa.GetFloat(2), sa.GetFloat(3)); break;
|
||||
default:
|
||||
return sa.ThrowError("Wrong parameter count");
|
||||
}
|
||||
return 0;
|
||||
_END_IMPL
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/*#
|
||||
Topic: UV
|
||||
Type: UV
|
||||
#*/
|
||||
|
||||
/*#
|
||||
Section: UVGeneric
|
||||
Desc: Generic
|
||||
#*/
|
||||
_BEGIN_CLASS(UV)
|
||||
|
||||
_MEMBER_FUNCTION(UV, constructor, -1, _T(".n|xn"))
|
||||
_MEMBER_FUNCTION(UV, _cloned, 2, _T(".x"))
|
||||
_MEMBER_FUNCTION(UV, _set, 3, _T("xs|n"))
|
||||
_MEMBER_FUNCTION(UV, _get, 2, _T("xs|n"))
|
||||
|
||||
/*#
|
||||
Func: Set
|
||||
Proto: void:float x = 0,float y = 0
|
||||
Desc: Set UV values.
|
||||
#*/
|
||||
_MEMBER_FUNCTION(UV, Set, -1, _T("xnn"))
|
||||
|
||||
_END_CLASS(UV)
|
||||
//------------------------------------------------------------------------------
|
||||
533
include/modules/script_squirrel/cobject/vector_impl.cpp
Normal file
533
include/modules/script_squirrel/cobject/vector_impl.cpp
Normal file
@ -0,0 +1,533 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
GSFramework
|
||||
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
|
||||
----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
#include <cmath>
|
||||
#include "script_squirrel/cobject/vector_decl.h"
|
||||
#include "script_squirrel/cobject/matrix_decl.h"
|
||||
#include "math/matrix4.h"
|
||||
#include "math/matrix3.h"
|
||||
#include "math/vector.h"
|
||||
#include "log/log.h"
|
||||
|
||||
using namespace GS;
|
||||
|
||||
|
||||
#ifndef _T
|
||||
#define _T
|
||||
#endif
|
||||
|
||||
_IMPL_NATIVE_CONSTRUCTION(Vector, Vector4);
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
_MEMBER_FUNCTION_IMPL(Vector, constructor)
|
||||
Vector4 temp;
|
||||
int nparams = sa.GetParamCount();
|
||||
|
||||
switch (nparams)
|
||||
{
|
||||
case 1: temp.Set(); break;
|
||||
case 2:
|
||||
if (sa.GetType(2) == OT_INSTANCE)
|
||||
{
|
||||
_GetTypedParam(vec, 2, Vector4, Vector);
|
||||
if (vec)
|
||||
temp = *vec;
|
||||
else return sa.ThrowError("Vector() invalid instance type");
|
||||
}
|
||||
else
|
||||
temp.Set(sa.GetFloat(2));
|
||||
break;
|
||||
case 3: temp.Set(sa.GetFloat(2), sa.GetFloat(3)); break;
|
||||
case 4: temp.Set(sa.GetFloat(2), sa.GetFloat(3), sa.GetFloat(4)); break;
|
||||
case 5: temp.Set(sa.GetFloat(2), sa.GetFloat(3), sa.GetFloat(4), sa.GetFloat(5)); break;
|
||||
|
||||
default:
|
||||
return sa.ThrowError("Vector wrong parameters");
|
||||
}
|
||||
return construct_Vector(v, new Vector4(temp));
|
||||
_END_IMPL
|
||||
|
||||
_MEMBER_FUNCTION_IMPL(Vector, _cloned)
|
||||
_GetTypedParam(vec, 2, Vector4, Vector);
|
||||
return construct_Vector(v, new Vector4(*vec));
|
||||
_END_IMPL
|
||||
|
||||
_MEMBER_FUNCTION_IMPL(Vector, _set)
|
||||
_GetSelf(Vector4, Vector);
|
||||
|
||||
const SQChar *s = sa.GetString(2);
|
||||
int index = s ? s[0] : sa.GetInt(2);
|
||||
|
||||
switch (index)
|
||||
{
|
||||
case 0: case 'x': case 'r':
|
||||
return sa.Return(self->x = sa.GetFloat(3));
|
||||
case 1: case 'y': case 'g':
|
||||
return sa.Return(self->y = sa.GetFloat(3));
|
||||
case 2: case 'z': case 'b':
|
||||
return sa.Return(self->z = sa.GetFloat(3));
|
||||
case 3: case 'w': case 'a':
|
||||
return sa.Return(self->w = sa.GetFloat(3));
|
||||
}
|
||||
return SQ_ERROR;
|
||||
_END_IMPL
|
||||
|
||||
_MEMBER_FUNCTION_IMPL(Vector, _get)
|
||||
_GetSelf(Vector4, Vector);
|
||||
const SQChar *s = sa.GetString(2);
|
||||
if (s && (s[1] != 0))
|
||||
return SQ_ERROR;
|
||||
int index = s && (s[1] == 0) ? s[0] : sa.GetInt(2);
|
||||
|
||||
switch (index)
|
||||
{
|
||||
case 0: case 'x': case 'r':
|
||||
return sa.Return(self->x);
|
||||
case 1: case 'y': case 'g':
|
||||
return sa.Return(self->y);
|
||||
case 2: case 'z': case 'b':
|
||||
return sa.Return(self->z);
|
||||
case 3: case 'w': case 'a':
|
||||
return sa.Return(self->w);
|
||||
}
|
||||
return SQ_ERROR;
|
||||
_END_IMPL
|
||||
|
||||
_MEMBER_FUNCTION_IMPL(Vector, _add)
|
||||
_GetSelf(Vector4, Vector);
|
||||
switch (sa.GetType(2))
|
||||
{
|
||||
case OT_INSTANCE:
|
||||
{ _GetTypedParam(vec, 2, Vector4, Vector);
|
||||
_SA_RETURN_OBJECT(new_Vector(v, *self + *vec)) }
|
||||
case OT_FLOAT:
|
||||
_SA_RETURN_OBJECT(new_Vector(v, *self + sa.GetFloat(2)));
|
||||
}
|
||||
return sa.ThrowError("Vector + operator: Invalid argument type.\n");
|
||||
_END_IMPL
|
||||
|
||||
_MEMBER_FUNCTION_IMPL(Vector, _sub)
|
||||
_GetSelf(Vector4, Vector);
|
||||
switch (sa.GetType(2))
|
||||
{
|
||||
case OT_INSTANCE:
|
||||
{ _GetTypedParam(vec, 2, Vector4, Vector);
|
||||
_SA_RETURN_OBJECT(new_Vector(v, *self - *vec)); }
|
||||
case OT_FLOAT:
|
||||
_SA_RETURN_OBJECT(new_Vector(v, *self - sa.GetFloat(2)));
|
||||
}
|
||||
return sa.ThrowError("Vector - operator: Invalid argument type.\n");
|
||||
_END_IMPL
|
||||
|
||||
_MEMBER_FUNCTION_IMPL(Vector, _mul)
|
||||
_GetSelf(Vector4, Vector);
|
||||
switch (sa.GetType(2))
|
||||
{
|
||||
case OT_INSTANCE:
|
||||
{
|
||||
// Vector * Vector.
|
||||
_CHECK_INST_PARAM_RAW(vec, 2, Vector4, Vector);
|
||||
if (vec)
|
||||
_SA_RETURN_OBJECT(new_Vector(v, *self * *vec));
|
||||
// Vector * Matrix3.
|
||||
_CHECK_INST_PARAM_RAW(m3, 2, Matrix3, Matrix3);
|
||||
if (m3)
|
||||
_SA_RETURN_OBJECT(new_Vector(v, *self * *m3));
|
||||
// Vector * Matrix4.
|
||||
_CHECK_INST_PARAM_RAW(m4, 2, Matrix4, Matrix4);
|
||||
if (m4)
|
||||
_SA_RETURN_OBJECT(new_Vector(v, *self * *m4));
|
||||
}
|
||||
break;
|
||||
|
||||
case OT_INTEGER:
|
||||
_SA_RETURN_OBJECT(new_Vector(v, *self * (float)sa.GetInt(2)));
|
||||
case OT_FLOAT:
|
||||
_SA_RETURN_OBJECT(new_Vector(v, *self * sa.GetFloat(2)));
|
||||
}
|
||||
return sa.ThrowError("Vector * operator: Invalid argument type.\n");
|
||||
_END_IMPL
|
||||
|
||||
_MEMBER_FUNCTION_IMPL(Vector,_div)
|
||||
_GetSelf(Vector4, Vector);
|
||||
switch (sa.GetType(2))
|
||||
{
|
||||
case OT_INSTANCE:
|
||||
{ _GetTypedParam(vec, 2, Vector4, Vector);
|
||||
_SA_RETURN_OBJECT(new_Vector(v, *self / *vec)); }
|
||||
case OT_FLOAT:
|
||||
_SA_RETURN_OBJECT(new_Vector(v, *self / sa.GetFloat(2)));
|
||||
}
|
||||
return sa.ThrowError("Vector / operator: Invalid argument type.\n");
|
||||
_END_IMPL
|
||||
|
||||
_MEMBER_FUNCTION_IMPL(Vector, Set)
|
||||
_GetSelf(Vector4, Vector);
|
||||
switch (sa.GetParamCount())
|
||||
{
|
||||
case 1: self->Set(); break;
|
||||
case 2: self->Set(sa.GetFloat(2)); break;
|
||||
case 3: self->Set(sa.GetFloat(2), sa.GetFloat(3)); break;
|
||||
case 4: self->Set(sa.GetFloat(2), sa.GetFloat(3), sa.GetFloat(4)); break;
|
||||
case 5: self->Set(sa.GetFloat(2), sa.GetFloat(3), sa.GetFloat(4), sa.GetFloat(5)); break;
|
||||
default:
|
||||
return sa.ThrowError("Vector Set() wrong parameters");
|
||||
}
|
||||
return 0;
|
||||
_END_IMPL
|
||||
|
||||
_MEMBER_FUNCTION_IMPL(Vector, Dot)
|
||||
_GetSelf(Vector4, Vector);
|
||||
_GetTypedParam(vec, 2, Vector4, Vector);
|
||||
return sa.Return(self->Dot(*vec));
|
||||
_END_IMPL
|
||||
|
||||
_MEMBER_FUNCTION_IMPL(Vector, Cross)
|
||||
_GetSelf(Vector4, Vector);
|
||||
_GetTypedParam(vec, 2, Vector4, Vector);
|
||||
_SA_RETURN_OBJECT(new_Vector(v, self->Cross(*vec)));
|
||||
_END_IMPL
|
||||
|
||||
_MEMBER_FUNCTION_IMPL(Vector, AngleWithVector)
|
||||
_GetSelf(Vector4, Vector);
|
||||
_GetTypedParam(vec, 2, Vector4, Vector);
|
||||
return sa.Return(acosf(Types::Clamp(self->Dot(*vec), -1.f, 1.f)));
|
||||
_END_IMPL
|
||||
|
||||
_MEMBER_FUNCTION_IMPL(Vector, Reverse)
|
||||
_GetSelf(Vector4, Vector);
|
||||
_SA_RETURN_OBJECT(new_Vector(v, self->Reversed()));
|
||||
_END_IMPL
|
||||
|
||||
_MEMBER_FUNCTION_IMPL(Vector, Dist)
|
||||
_GetSelf(Vector4, Vector);
|
||||
_GetTypedParam(vec, 2, Vector4, Vector);
|
||||
return sa.Return(Vector4::Dist(*self, *vec));
|
||||
_END_IMPL
|
||||
|
||||
_MEMBER_FUNCTION_IMPL(Vector, Dist2)
|
||||
_GetSelf(Vector4, Vector);
|
||||
_GetTypedParam(vec, 2, Vector4, Vector);
|
||||
return sa.Return(Vector4::Dist2(*self, *vec));
|
||||
_END_IMPL
|
||||
|
||||
_MEMBER_FUNCTION_IMPL(Vector, Len)
|
||||
_GetSelf(Vector4, Vector);
|
||||
return sa.Return(self->Len());
|
||||
_END_IMPL
|
||||
|
||||
_MEMBER_FUNCTION_IMPL(Vector, Len2)
|
||||
_GetSelf(Vector4, Vector);
|
||||
return sa.Return(self->Len2());
|
||||
_END_IMPL
|
||||
|
||||
_MEMBER_FUNCTION_IMPL(Vector, ClampMagnitude)
|
||||
_GetSelf(Vector4, Vector);
|
||||
_SA_RETURN_OBJECT(new_Vector(v, self->ClampedMagnitude(0, sa.GetFloat(2))));
|
||||
_END_IMPL
|
||||
|
||||
_MEMBER_FUNCTION_IMPL(Vector, clamp)
|
||||
_GetSelf(Vector4, Vector);
|
||||
Vector4 mn, mx;
|
||||
if (sa.GetType(2) == OT_INSTANCE)
|
||||
{ _GetTypedParam(_mn, 2, Vector4, Vector); mn = *_mn; }
|
||||
else mn.Set(sa.GetFloat(2), sa.GetFloat(2), sa.GetFloat(2));
|
||||
if (sa.GetType(3) == OT_INSTANCE)
|
||||
{ _GetTypedParam(_mx, 3, Vector4, Vector); mx = *_mx; }
|
||||
else mx.Set(sa.GetFloat(3), sa.GetFloat(3), sa.GetFloat(3));
|
||||
_SA_RETURN_OBJECT(new_Vector(v, self->Clamped(mn, mx)));
|
||||
_END_IMPL
|
||||
|
||||
_MEMBER_FUNCTION_IMPL(Vector, ApplyMatrix)
|
||||
_GetSelf(Vector4, Vector);
|
||||
_CHECK_INST_PARAM_RAW(m3, 2, Matrix3, Matrix3);
|
||||
if (m3) _SA_RETURN_OBJECT(new_Vector(v, *self * *m3));
|
||||
_CHECK_INST_PARAM_RAW(m4, 2, Matrix4, Matrix4);
|
||||
if (m4) _SA_RETURN_OBJECT(new_Vector(v, *self * *m4));
|
||||
return sa.ThrowError("Vector::ApplyMatrix(): Invalid parameter");
|
||||
_END_IMPL
|
||||
|
||||
_MEMBER_FUNCTION_IMPL(Vector, ApplyRotationMatrix)
|
||||
_GetSelf(Vector4, Vector);
|
||||
_CHECK_INST_PARAM_RAW(m3, 2, Matrix3, Matrix3);
|
||||
if (m3) _SA_RETURN_OBJECT(new_Vector(v, *self * *m3));
|
||||
_CHECK_INST_PARAM_RAW(m4, 2, Matrix4, Matrix4);
|
||||
if (m4) _SA_RETURN_OBJECT(new_Vector(v, *self * Matrix3::FromMatrix4(*m4)));
|
||||
return sa.ThrowError("Vector::ApplyRotationMatrix(): Invalid parameter");
|
||||
_END_IMPL
|
||||
|
||||
_MEMBER_FUNCTION_IMPL(Vector, Randomize)
|
||||
if (sa.GetParamCount() == 2)
|
||||
_SA_RETURN_OBJECT(new_Vector(v, Vector4::Random(0, sa.GetFloat(2))));
|
||||
_SA_RETURN_OBJECT(new_Vector(v, Vector4::Random(sa.GetFloat(2), sa.GetFloat(3))));
|
||||
_END_IMPL
|
||||
|
||||
_MEMBER_FUNCTION_IMPL(Vector, Normalize)
|
||||
_GetSelf(Vector4, Vector);
|
||||
if (sa.GetParamCount() == 1)
|
||||
_SA_RETURN_OBJECT(new_Vector(v, self->Normalized()))
|
||||
else _SA_RETURN_OBJECT(new_Vector(v, self->Normalized() * sa.GetFloat(2)))
|
||||
_END_IMPL
|
||||
|
||||
_MEMBER_FUNCTION_IMPL(Vector, Lerp)
|
||||
_GetSelf(Vector4, Vector);
|
||||
float k = sa.GetFloat(2), ik = 1.f - k;
|
||||
_GetTypedParam(vec, 3, Vector4, Vector);
|
||||
_SA_RETURN_OBJECT(new_Vector(v, *self * k + *vec * ik));
|
||||
_END_IMPL
|
||||
|
||||
_MEMBER_FUNCTION_IMPL(Vector, _cmp)
|
||||
_GetSelf(Vector4, Vector);
|
||||
_GetTypedParam(vec, 2, Vector4, Vector);
|
||||
return sa.Return((*self) == (*vec) ? true : false);
|
||||
_END_IMPL
|
||||
|
||||
_MEMBER_FUNCTION_IMPL(Vector, IsEqual)
|
||||
_GetSelf(Vector4, Vector);
|
||||
_GetTypedParam(vec, 2, Vector4, Vector);
|
||||
float d2 = 0.0001f;
|
||||
switch (sa.GetParamCount())
|
||||
{
|
||||
case 2: break;
|
||||
case 3: d2 = sa.GetFloat(3); break;
|
||||
default: return sa.ThrowError("Vector::IsEqual() wrong parameter count");
|
||||
}
|
||||
d2 *= d2;
|
||||
return sa.Return(Vector4::Dist2(*self, *vec) < d2 ? true : false);
|
||||
_END_IMPL
|
||||
|
||||
_MEMBER_FUNCTION_IMPL(Vector, Min)
|
||||
_GetSelf(Vector4, Vector);
|
||||
|
||||
if ((sa.GetParamCount() == 2) || (sa.GetParamCount() == 4))
|
||||
switch (sa.GetType(2))
|
||||
{
|
||||
case OT_INSTANCE:
|
||||
{ _GetTypedParam(vec, 2, Vector4, Vector);
|
||||
_SA_RETURN_OBJECT(new_Vector(v, Vector4(self->x < vec->x ? self->x : vec->x, self->y < vec->y ? self->y : vec->y, self->z < vec->z ? self->z : vec->z))); }
|
||||
case OT_FLOAT:
|
||||
{ float x = sa.GetFloat(2), y = sa.GetFloat(3), z = sa.GetFloat(4);
|
||||
_SA_RETURN_OBJECT(new_Vector(v, Vector4(self->x < x ? self->x : x, self->y < y ? self->y : y, self->z < z ? self->z : z))); }
|
||||
}
|
||||
return sa.ThrowError("Vector Min(): Invalid parameter list.\n");
|
||||
_END_IMPL
|
||||
|
||||
_MEMBER_FUNCTION_IMPL(Vector, Max)
|
||||
_GetSelf(Vector4, Vector);
|
||||
if ((sa.GetParamCount() == 2) || (sa.GetParamCount() == 4))
|
||||
switch (sa.GetType(2))
|
||||
{
|
||||
case OT_INSTANCE:
|
||||
{ _GetTypedParam(vec, 2, Vector4, Vector);
|
||||
_SA_RETURN_OBJECT(new_Vector(v, Vector4(self->x > vec->x ? self->x : vec->x, self->y > vec->y ? self->y : vec->y, self->z > vec->z ? self->z : vec->z))); }
|
||||
case OT_FLOAT:
|
||||
{ float x = sa.GetFloat(2), y = sa.GetFloat(3), z = sa.GetFloat(4);
|
||||
_SA_RETURN_OBJECT(new_Vector(v, Vector4(self->x > x ? self->x : x, self->y > y ? self->y : y, self->z > z ? self->z : z))); }
|
||||
}
|
||||
return sa.ThrowError("Vector Max(): Invalid parameter list.\n");
|
||||
_END_IMPL
|
||||
|
||||
_MEMBER_FUNCTION_IMPL(Vector, Scale)
|
||||
_GetSelf(Vector4, Vector);
|
||||
_SA_RETURN_OBJECT(new_Vector(v, *self * sa.GetFloat(2)));
|
||||
_END_IMPL
|
||||
|
||||
_MEMBER_FUNCTION_IMPL(Vector, AddReal)
|
||||
_GetSelf(Vector4, Vector);
|
||||
_SA_RETURN_OBJECT(new_Vector(v, *self + Vector4(sa.GetFloat(2), sa.GetFloat(2), sa.GetFloat(2))));
|
||||
_END_IMPL
|
||||
|
||||
_MEMBER_FUNCTION_IMPL(Vector, MulReal)
|
||||
_GetSelf(Vector4, Vector);
|
||||
_SA_RETURN_OBJECT(new_Vector(v, *self * Vector4(sa.GetFloat(2), sa.GetFloat(2), sa.GetFloat(2))));
|
||||
_END_IMPL
|
||||
|
||||
_MEMBER_FUNCTION_IMPL(Vector, SubReal)
|
||||
_GetSelf(Vector4, Vector);
|
||||
_SA_RETURN_OBJECT(new_Vector(v, *self - Vector4(sa.GetFloat(2), sa.GetFloat(2), sa.GetFloat(2))));
|
||||
_END_IMPL
|
||||
|
||||
_MEMBER_FUNCTION_IMPL(Vector, DivReal)
|
||||
_GetSelf(Vector4, Vector);
|
||||
const float ik = 1.f / sa.GetFloat(2);
|
||||
_SA_RETURN_OBJECT(new_Vector(v, *self * Vector4(ik, ik, ik)));
|
||||
_END_IMPL
|
||||
|
||||
_MEMBER_FUNCTION_IMPL(Vector, Print)
|
||||
_GetSelf(Vector4, Vector);
|
||||
const char *label = "Vector";
|
||||
if (sa.GetParamCount() == 2)
|
||||
label = sa.GetString(2);
|
||||
__LOG__ << label << ": { " << self->x << ", " << self->y << ", " << self->z << ", " << self->w << "}\n";
|
||||
return 0;
|
||||
_END_IMPL
|
||||
|
||||
/*#
|
||||
Topic: Vector
|
||||
Type: Vector
|
||||
#*/
|
||||
|
||||
/*#
|
||||
Section: VectorGeneric
|
||||
Desc: Generic
|
||||
#*/
|
||||
_BEGIN_CLASS(Vector)
|
||||
|
||||
/*#
|
||||
Func: Vector
|
||||
Proto: Vector:float x = 0,float y = 0,float z = 0,float w = 1
|
||||
Desc: Create a new vector.
|
||||
Example: local v = Vector(1, 0, 0)
|
||||
#*/
|
||||
_MEMBER_FUNCTION(Vector, constructor, -1, _T(".n|xnnn"))
|
||||
_MEMBER_FUNCTION(Vector, _cloned, 2, _T(".x"))
|
||||
_MEMBER_FUNCTION(Vector, _set, 3, _T("xs|n"))
|
||||
_MEMBER_FUNCTION(Vector, _get, 2, _T("xs|n"))
|
||||
_MEMBER_FUNCTION(Vector, _add, 2, _T("xx|n"))
|
||||
_MEMBER_FUNCTION(Vector, _sub, 2, _T("xx|n"))
|
||||
_MEMBER_FUNCTION(Vector, _mul, 2, _T("xx|n"))
|
||||
_MEMBER_FUNCTION(Vector, _div, 2, _T("xx|n"))
|
||||
_MEMBER_FUNCTION(Vector, _cmp, 2, _T("xx"))
|
||||
|
||||
/*#
|
||||
Func: Set
|
||||
Proto: void:float x = 0,float y = 0,float z = 0,float w = 1
|
||||
Desc: Set vector values.
|
||||
#*/
|
||||
_MEMBER_FUNCTION(Vector, Set, -1, _T("xnnnn"))
|
||||
/*#
|
||||
Func: ApplyMatrix
|
||||
Proto: Vector:[Matrix4|Matrix3] matrix
|
||||
Desc: Transform vector by a given matrix.
|
||||
#*/
|
||||
_MEMBER_FUNCTION(Vector, ApplyMatrix, 2, _T("xx"))
|
||||
/*#
|
||||
Func: ApplyRotationMatrix
|
||||
Proto: Vector:[Matrix4|Matrix3] matrix
|
||||
Desc: Transform vector by the rotation part of a given matrix.
|
||||
#*/
|
||||
_MEMBER_FUNCTION(Vector, ApplyRotationMatrix, 2, _T("xx"))
|
||||
|
||||
_MEMBER_FUNCTION(Vector, AddReal, 2, _T("xn"))
|
||||
_MEMBER_FUNCTION(Vector, MulReal, 2, _T("xn"))
|
||||
_MEMBER_FUNCTION(Vector, SubReal, 2, _T("xn"))
|
||||
_MEMBER_FUNCTION(Vector, DivReal, 2, _T("xn"))
|
||||
_MEMBER_FUNCTION(Vector, Scale, 2, _T("xn"))
|
||||
/*#
|
||||
Func: Clamp
|
||||
Proto: Vector:(Vector|float) min,(Vector|float) max
|
||||
Desc: Individually clamp vector components to a given range.
|
||||
#*/
|
||||
_MEMBER_FUNCTION(Vector, clamp, 3, _T("x x|n x|n"))
|
||||
/*#
|
||||
Func: ClampMagnitude
|
||||
Proto: Vector:float len
|
||||
Desc: Clamp vector magnitude to a specific length.
|
||||
#*/
|
||||
_MEMBER_FUNCTION(Vector, ClampMagnitude, 2, _T("xn"))
|
||||
/*#
|
||||
Func: Reverse
|
||||
Proto: Vector:
|
||||
Desc: Return the reverse vector.
|
||||
#*/
|
||||
_MEMBER_FUNCTION(Vector, Reverse, 1, _T("x"))
|
||||
|
||||
/*#
|
||||
Func: Min
|
||||
Proto: Vector:[Vector|float x,float y, float z] min
|
||||
Desc: Return the smallest value of the vector component or parameter for all the vector components.
|
||||
#*/
|
||||
_MEMBER_FUNCTION(Vector, Min, -2, _T("xn|xnn"))
|
||||
/*#
|
||||
Func: Max
|
||||
Proto: Vector:[Vector|float x,float y, float z] max
|
||||
Desc: Return the largest value of the vector component or parameter for all the vector components.
|
||||
#*/
|
||||
_MEMBER_FUNCTION(Vector, Max, -2, _T("xn|xnn"))
|
||||
|
||||
/*#
|
||||
Func: Dot
|
||||
Proto: float:Vector v
|
||||
Desc: Return the dot product between two vectors.
|
||||
#*/
|
||||
_MEMBER_FUNCTION(Vector, Dot, 2, _T("xx"))
|
||||
/*#
|
||||
Func: Cross
|
||||
Proto: Vector:Vector v
|
||||
Desc: Return the cross product between two vectors.
|
||||
#*/
|
||||
_MEMBER_FUNCTION(Vector, Cross, 2, _T("xx"))
|
||||
/*#
|
||||
Func: Len
|
||||
Proto: float:Vector v
|
||||
Desc: Return the length of this vector.
|
||||
#*/
|
||||
_MEMBER_FUNCTION(Vector, Len, 1, _T("x"))
|
||||
/*#
|
||||
Func: Len2
|
||||
Proto: float:Vector v
|
||||
Desc: Return the squared length of this vector.
|
||||
#*/
|
||||
_MEMBER_FUNCTION(Vector, Len2, 1, _T("x"))
|
||||
/*#
|
||||
Func: AngleWithVector
|
||||
Proto: float:Vector v
|
||||
Desc: Return the angle between two vectors.
|
||||
#*/
|
||||
_MEMBER_FUNCTION(Vector, AngleWithVector, 2, _T("xx"))
|
||||
|
||||
/*#
|
||||
Func: Normalize
|
||||
Proto: Vector:float length = 1
|
||||
Desc: Return a normalized version of this vector scaled to a constant.
|
||||
#*/
|
||||
_MEMBER_FUNCTION(Vector, Normalize, -1, _T("xn"))
|
||||
/*#
|
||||
Func: Dist
|
||||
Proto: float:Vector v
|
||||
Desc: Return the distance between two vectors.
|
||||
#*/
|
||||
_MEMBER_FUNCTION(Vector, Dist, 2, _T("xx"))
|
||||
/*#
|
||||
Func: Dist2
|
||||
Proto: float:Vector v
|
||||
Desc: Return the squared distance between two vectors.
|
||||
#*/
|
||||
_MEMBER_FUNCTION(Vector, Dist2, 2, _T("xx"))
|
||||
/*#
|
||||
Func: Lerp
|
||||
Proto: float:Vector v,float t
|
||||
Desc: Return a linearly interpolated vector between two vectors.
|
||||
#*/
|
||||
_MEMBER_FUNCTION(Vector, Lerp, 3, _T("xnx"))
|
||||
/*#
|
||||
Func: Randomize
|
||||
Proto: Vector:Vector v,float min,float max
|
||||
Desc: Return a random vector in a given range.
|
||||
#*/
|
||||
_MEMBER_FUNCTION(Vector, Randomize, -2, _T(".nn"))
|
||||
|
||||
/*#
|
||||
Func: IsEqual
|
||||
Proto: bool:Vector v,float epsilon = 0.0001
|
||||
Desc: Test vectors for equality with a given espilon tolerance.
|
||||
#*/
|
||||
_MEMBER_FUNCTION(Vector, IsEqual, -2, _T("xxn"))
|
||||
/*#
|
||||
Func: Print
|
||||
Proto: void:
|
||||
Desc: Dump this vector components to the engine log.
|
||||
#*/
|
||||
_MEMBER_FUNCTION(Vector, Print, -1, _T("x"))
|
||||
|
||||
_END_CLASS(Vector)
|
||||
|
||||
//-----------------------------------------------
|
||||
void UCBind_RegisterVector(HSQUIRRELVM vm)
|
||||
//-----------------------------------------------
|
||||
{
|
||||
_INIT_CLASS(vm, Vector);
|
||||
}
|
||||
Reference in New Issue
Block a user