Simple game engine with complete export to scripting language
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

138 lines
3.3 KiB

#ifndef BLUECORE_SCRIPTING_MATH_H
#define BLUECORE_SCRIPTING_MATH_H
#include "ScriptSystem.h"
namespace BlueCore
{
//------------------------------------------------------------------------------
inline void _setvectorvalues(HSQUIRRELVM &v, const SQInteger &idx,
const SQFloat &x, const SQFloat &y, const SQFloat &z)
{
sq_pushstring (v, "x", 1);
sq_pushfloat (v, x );
sq_rawset (v, idx );
sq_pushstring (v, "y", 1);
sq_pushfloat (v, y );
sq_rawset (v, idx );
sq_pushstring (v, "z", 1);
sq_pushfloat (v, z );
sq_rawset (v, idx );
}
//------------------------------------------------------------------------------
inline void _getvectorvalues(HSQUIRRELVM &v, const SQInteger &idx, SQFloat &x,
SQFloat &y, SQFloat &z)
{
sq_pushstring (v, "x", 1);
sq_rawget (v, idx );
sq_getfloat (v, -1, &x );
sq_pushstring (v, "y", 1);
sq_rawget (v, idx );
sq_getfloat (v, -1, &y );
sq_pushstring (v, "z", 1);
sq_rawget (v, idx );
sq_getfloat (v, -1, &z );
sq_pop (v, 3);
}
//------------------------------------------------------------------------------
inline void _pushvector(HSQUIRRELVM &v, const SQFloat &x, const SQFloat &y,
const SQFloat &z)
{
// get closure/class
// TODO: use SQObject rfom creation
sq_pushroottable (v );
sq_pushstring (v, "Vector", -1);
sq_get (v, -2);
sq_remove (v, -2);
// call constructor
sq_pushroottable (v );
sq_pushfloat (v, x );
sq_pushfloat (v, y );
sq_pushfloat (v, z );
sq_call (v, 4, SQTrue, SQTrue );
// remove class, leave instance
sq_remove (v, -2);
}
//------------------------------------------------------------------------------
inline void _pushquaternion(HSQUIRRELVM &v, const SQFloat &w, const SQFloat &x,
const SQFloat &y, const SQFloat &z)
{
// get closure/class
// TODO: use SQObject rfom creation!!!!!!
sq_pushroottable (v );
sq_pushstring (v, "Quaternion", -1);
sq_get (v, -2);
sq_remove (v, -2);
// call constructor
sq_pushroottable (v );
sq_pushfloat (v, w );
sq_pushfloat (v, x );
sq_pushfloat (v, y );
sq_pushfloat (v, z );
sq_call (v, 5, SQTrue, SQTrue );
// remove class, leave instance
sq_remove (v, -2);
}
//------------------------------------------------------------------------------
inline void _setquaternionvalues(HSQUIRRELVM &v, const SQInteger &idx,
const SQFloat &w, const SQFloat &x, const SQFloat &y, const SQFloat &z)
{
sq_pushstring (v, "w", -1);
sq_pushfloat (v, w );
sq_rawset (v, idx );
sq_pushstring (v, "x", -1);
sq_pushfloat (v, x );
sq_rawset (v, idx );
sq_pushstring (v, "y", -1);
sq_pushfloat (v, y );
sq_rawset (v, idx );
sq_pushstring (v, "z", -1);
sq_pushfloat (v, z );
sq_rawset (v, idx );
}
//------------------------------------------------------------------------------
inline void _getquaternionvalues(HSQUIRRELVM &v, const SQInteger &idx,
SQFloat &w, SQFloat &x, SQFloat &y, SQFloat &z)
{
sq_pushstring (v, "w", -1);
sq_get (v, idx );
sq_getfloat (v, -1, &w );
sq_pushstring (v, "x", -1);
sq_get (v, idx );
sq_getfloat (v, -1, &x );
sq_pushstring (v, "y", -1);
sq_get (v, idx );
sq_getfloat (v, -1, &y );
sq_pushstring (v, "z", -1);
sq_get (v, idx );
sq_getfloat (v, -1, &z );
sq_pop (v, 3);
}
void setupScriptSystem_Math(ScriptSystem* scriptsystem);
} // namespace BlueCore
#endif