Esempio n. 1
0
static int quat_dot(lua_State* L)
{
    Quatf* a = check_quat(L, 1);
    Quatf* b = check_quat(L, 2);
    lua_pushnumber(L, Dot(*a, *b));
    return 1;
}
Esempio n. 2
0
static int quat_lerp(lua_State* L)
{
    Quatf* a = check_quat(L, 1);
    Quatf* b = check_quat(L, 2);
    lua_Number t = luaL_checknumber(L, 3);

    new_quat(L, result);
    *result = Lerp(*a, *b, (float)t);
    return 1;
}
Esempio n. 3
0
static int quat_conj(lua_State* L)
{
    Quatf* self = check_quat(L, 1);
    new_quat(L, result);
    *result = ~(*self);
    return 1;
}
Esempio n. 4
0
static int quat_unit(lua_State* L)
{
    Quatf* self = check_quat(L, 1);
    new_quat(L, result);
    *result = self->Unit();
    return 1;
}
Esempio n. 5
0
static int quat_log(lua_State* L)
{
    Quatf* x = check_quat(L, 1);
    new_quat(L, result);
    *result = Log(*x);
    return 1;
}
Esempio n. 6
0
static int quat_unm(lua_State* L)
{
    Quatf* a = check_quat(L, 1);
    new_quat(L, result);
    *result = -*a;
    return 1;
}
static int global_physics_test (lua_State *L)
{
TRY_START
        LuaTestCallback lcb;
        push_cfunction(L, my_lua_error_handler);
        int error_handler = lua_gettop(L);
        if (lua_gettop(L)==5) {
                float radius = lua_tonumber(L, 1);
                Vector3 pos = check_v3(L, 2);
                bool only_dyn = check_bool(L, 3);
                if (lua_type(L, 4) != LUA_TFUNCTION)
                        my_lua_error(L, "Parameter 4 should be a function.");

                physics_test_sphere(radius, pos, only_dyn, lcb);
                lcb.pushResults(L, 4, error_handler);
        } else {
                check_args(L, 6);
                std::string col_mesh_name = check_path(L, 1);
                DiskResource *col_mesh_ = disk_resource_get_or_make(col_mesh_name);
                CollisionMesh *col_mesh = dynamic_cast<CollisionMesh*>(col_mesh_);
                if (col_mesh==NULL) my_lua_error(L, "Not a collision mesh: \""+col_mesh_name+"\"");
                if (!col_mesh->isLoaded()) my_lua_error(L, "Not loaded: \""+col_mesh_name+"\"");
                Vector3 pos = check_v3(L, 2);
                Quaternion quat = check_quat(L, 3);
                bool only_dyn = check_bool(L, 4);
                if (lua_type(L, 5) != LUA_TFUNCTION)
                        my_lua_error(L, "Parameter 5 should be a function.");

                physics_test(col_mesh, pos, quat, only_dyn, lcb);
                lcb.pushResults(L, 5, error_handler);
        }
        lua_pop(L, 1); // error handler
        return 0;
TRY_END
}
static int global_physics_sweep_col_mesh (lua_State *L)
{
TRY_START
        int base_line = 7;
        check_args_min(L, base_line);

        std::string col_mesh_name = check_path(L, 1);
        DiskResource *col_mesh_ = disk_resource_get_or_make(col_mesh_name);
        CollisionMesh *col_mesh = dynamic_cast<CollisionMesh*>(col_mesh_);
        Quaternion q = check_quat(L, 2);
        Vector3 start = check_v3(L, 3);
        Vector3 ray = check_v3(L, 4);
        bool nearest_only = check_bool(L, 5);
        unsigned long flags = check_t<unsigned long>(L, 6);
        if (lua_type(L, 7) != LUA_TFUNCTION)
                my_lua_error(L, "Parameter 5 should be a function.");

        LuaSweepCallback lcb(nearest_only, flags);
        init_cast_blacklist(L, base_line, lcb);

        physics_sweep_col_mesh(start, q, start + ray, q, lcb, col_mesh);

        push_cfunction(L, my_lua_error_handler);
        int error_handler = lua_gettop(L);

        lcb.pushResults(L, 7, error_handler);
        return 0;
TRY_END
}
Esempio n. 9
0
static int quat_tostring(lua_State* L)
{
    Quatf* v = check_quat(L, 1);
    char temp[64];
    snprintf(temp, 64, "quat(%.5f, %.5f, %.5f, %.5f)", v->i, v->j, v->k, v->r);
    lua_pushstring(L, temp);
    return 1;
}
Esempio n. 10
0
static int quat_rotate(lua_State* L)
{
    Quatf* self = check_quat(L, 1);
    Vector3f* x = check_vec3(L, 2);
    new_vec3(L, result);
    *result = self->Rotate(*x);
    return 1;
}
Esempio n. 11
0
static int quat_newindex(lua_State* L)
{
    Quatf* v = check_quat(L, 1);
    luaL_checkany(L, 2);
    lua_Number value = luaL_checknumber(L, 3);

    int key_type = lua_type(L, 2);
    if (key_type == LUA_TNUMBER)
    {
        lua_Integer i = lua_tointeger(L, 2);
        if (i > 0 && i <= 4)
        {
            (*v)[i] = value;
            lua_pushnumber(L, (*v)[i-1]);
            return 0;
        }

        // error
        lua_pushstring(L, "quat: num index out of range, must be 1, 2, 3 or 4");
        lua_error(L);
    }
    else if (key_type == LUA_TSTRING)
    {
        size_t size;
        const char* s = lua_tolstring(L, 2, &size);
        if (size == 1)
        {
            switch (s[0])
            {
            case 'i':
                v->i = value;
                return 0;
            case 'j':
                v->j = value;
                return 0;
            case 'k':
                v->k = value;
                return 0;
            case 'r':
                v->r = value;
                return 0;
            }
        }

        // error
        lua_pushstring(L, "quat: unknown string key, must be i, j, k or r");
        lua_error(L);
    }
    else
    {
        // error
        lua_pushstring(L, "quat: unsupported key");
        lua_error(L);
    }

    return 0;
}
static int rbody_set_part_orientation_offset (lua_State *L)
{
TRY_START
        check_args(L, 3);
        GET_UD_MACRO(RigidBody, self, 1, RBODY_TAG);
        int i = (int)check_int(L, 2, 0, self.getNumElements()-1);
        Quaternion q = check_quat(L, 3);
        self.setElementOrientationOffset(i, q);
        return 0;
TRY_END
}
static int global_physics_body_make (lua_State *L)
{
TRY_START
        check_args(L, 3);
        std::string n = check_path(L, 1);
        Vector3 pos = check_v3(L, 2);
        Quaternion quat = check_quat(L, 3);
        push_rbody(L, new RigidBody(n, pos, quat));
        return 1;
TRY_END
}
static int global_physics_sweep_box (lua_State *L)
{
TRY_START
        int base_line = 6;
        check_args_min(L, base_line);

        Vector3 size = check_v3(L, 1);
        Quaternion q = check_quat(L, 2);
        Vector3 start = check_v3(L, 3);
        Vector3 ray = check_v3(L, 4);
        bool nearest_only = check_bool(L, 5);
        unsigned long flags = check_t<unsigned long>(L, 6);

        LuaSweepCallback lcb(nearest_only, flags);
        init_cast_blacklist(L, base_line, lcb);

        physics_sweep_box(start, q, start+ray, lcb, size);

        return lcb.pushResults(L);

TRY_END
}
Esempio n. 15
0
static int quat_len(lua_State* L)
{
    Quatf* self = check_quat(L, 1);
    lua_pushnumber(L, self->Len());
    return 1;
}
Esempio n. 16
0
static int quat_index(lua_State* L)
{
    Quatf* v = check_quat(L, 1);
    luaL_checkany(L, 2);

    int key_type = lua_type(L, 2);
    if (key_type == LUA_TNUMBER)
    {
        lua_Integer i = lua_tointeger(L, 2);
        if (i > 0 && i <= 4)
        {
            lua_pushnumber(L, (*v)[i-1]);
            return 1;
        }

        // error
        lua_pushstring(L, "quat: num index out of range, must be 1, 2, 3 or 4");
        lua_error(L);
    }
    else if (key_type == LUA_TSTRING)
    {
        size_t size;
        const char* s = lua_tolstring(L, 2, &size);
        if (size == 1)
        {
            switch (s[0])
            {
            case 'i':
                lua_pushnumber(L, v->i);
                return 1;
            case 'j':
                lua_pushnumber(L, v->j);
                return 1;
            case 'k':
                lua_pushnumber(L, v->k);
                return 1;
            case 'r':
                lua_pushnumber(L, v->r);
                return 1;
            }
        }
        else
        {
            // search for string key in quat_method_funcs array.
            int i = 0;
            while (quat_method_funcs[i].name)
            {
                if (!strcmp(s, quat_method_funcs[i].name))
                {
                    lua_pushcfunction(L, quat_method_funcs[i].func);
                    return 1;
                }
                i++;
            }
        }

        // error
        lua_pushstring(L, "quat: unknown string key");
        lua_error(L);
    }
    else
    {
        // error
        lua_pushstring(L, "vec4: unsupported key");
        lua_error(L);
    }

    return 0;
}
static int rbody_newindex (lua_State *L)
{
TRY_START
        check_args(L, 3);
        GET_UD_MACRO(RigidBody, self, 1, RBODY_TAG);
        const char *key = luaL_checkstring(L, 2);
        if (!::strcmp(key, "linearVelocity")) {
                Vector3 v = check_v3(L, 3);
                self.setLinearVelocity(v);
        } else if (!::strcmp(key, "angularVelocity")) {
                Vector3 v = check_v3(L, 3);
                self.setAngularVelocity(v);
        } else if (!::strcmp(key, "worldPosition")) {
                Vector3 v = check_v3(L, 3);
                self.setPosition(v);
        } else if (!::strcmp(key, "worldOrientation")) {
                Quaternion v = check_quat(L, 3);
                self.setOrientation(v);
        } else if (!::strcmp(key, "contactProcessingThreshold")) {
                float v = check_float(L, 3);
                self.setContactProcessingThreshold(v);
        } else if (!::strcmp(key, "linearDamping")) {
                float v = check_float(L, 3);
                self.setLinearDamping(v);
        } else if (!::strcmp(key, "angularDamping")) {
                float v = check_float(L, 3);
                self.setAngularDamping(v);
        } else if (!::strcmp(key, "linearSleepThreshold")) {
                float v = check_float(L, 3);
                self.setLinearSleepThreshold(v);
        } else if (!::strcmp(key, "angularSleepThreshold")) {
                float v = check_float(L, 3);
                self.setAngularSleepThreshold(v);
        } else if (!::strcmp(key, "mass")) {
                float v = check_float(L, 3);
                self.setMass(v);
        } else if (!::strcmp(key, "ghost")) {
                bool v = check_bool(L, 3);
                self.setGhost(v);
        } else if (!::strcmp(key, "updateCallback")) {
                self.updateCallbackPtr.set(L);
        } else if (!::strcmp(key, "stepCallback")) {
                self.stepCallbackPtr.set(L);
        } else if (!::strcmp(key, "collisionCallback")) {
                self.collisionCallbackPtr.set(L);
        } else if (!::strcmp(key, "stabiliseCallback")) {
                self.stabiliseCallbackPtr.set(L);
        } else if (!::strcmp(key, "inertia")) {
                Vector3 v = check_v3(L, 3);
                self.setInertia(v);
        } else if (!::strcmp(key, "owner")) {
                if (lua_isnil(L, 3)) {
                        self.owner.setNull();
                } else {
                        GET_UD_MACRO(GritObjectPtr, v, 3, GRITOBJ_TAG);
                        self.owner = v;
                }

        } else {
               my_lua_error(L, "Not a writeable RigidBody member: "+std::string(key));
        }
        return 0;
TRY_END
}