コード例 #1
0
int luaopen_physics_collider(lua_State *L)
{
    unsigned short group_mask = 1;
    unsigned short collision_mask = 1;

    // get named arguments
    luaL_checktype(L, 1, LUA_TTABLE);

    lua_getfield(L, 1, "collision_shape");
    check_collision_shape(L, -1);
    int collision_shape_ref = luaL_ref(L, LUA_REGISTRYINDEX);

    lua_getfield(L, 1, "group_mask");
    if(!lua_isnil(L, -1))
    {
        group_mask = lua_tonumber(L, -1);
        lua_pop(L, 1);
    }

    lua_getfield(L, 1, "collision_mask");
    if(!lua_isnil(L, -1))
    {
        collision_mask = lua_tonumber(L, -1);
        lua_pop(L, 1);
    }

    // get collision world
    get_by_field_path(L, LUA_ENVIRONINDEX, "game.collision.get_udata");
    lua_call(L, 0, 1);
    collision_component *world = *(collision_component **) lua_touserdata(L, -1);
    lua_pop(L, 1);

    // get self
    lua_getfield(L, LUA_ENVIRONINDEX, "self");
    int self_ref = luaL_ref(L, LUA_REGISTRYINDEX);
    
    // make collision obect and leave it on top of the stack
    collider *c = new collider(
        L, world, self_ref, collision_shape_ref, group_mask, collision_mask);
    *(collider **)lua_newuserdata(L, sizeof(collision_component *)) = c;

    // methods
    register_closure(L, "set_collision_shape", collider_set_collision_shape);
    register_closure(L, "get_udata", collider_get_udata);
    register_closure(L, "on_removal", collider_on_removal);

    return 0;
}
コード例 #2
0
void ShadingSystem::register_builtin_closures()
{
    for (int cid = 0; cid < NBUILTIN_CLOSURES; ++cid)
    {
        BuiltinClosure *clinfo = &builtin_closures[cid];
        ASSERT(clinfo->id == cid);
        register_closure (clinfo->name, cid, clinfo->params, clinfo->prepare, generic_closure_setup, generic_closure_compare);
    }
}
コード例 #3
0
ファイル: physics.cpp プロジェクト: henkboom/dokidoki-physics
int luaopen_physics_physics(lua_State *L)
{
    physics_component_s *physics_component =
        (physics_component_s *)lua_newuserdata(L, sizeof(physics_component_s));

    register_closure(L, "draw", physics_draw);
    register_closure(L, "update", physics_update);
    //register_closure(L, "add_rigid_body", physics_add_rigid_body);
    register_closure(L, "get_udata", physics_get_udata);

    physics_component->broadphase = new btDbvtBroadphase();
    physics_component->collision_configuration =
        new btDefaultCollisionConfiguration();
    physics_component->collision_dispatcher =
        new btCollisionDispatcher(physics_component->collision_configuration);
    physics_component->constraint_solver =
        new btSequentialImpulseConstraintSolver();
    physics_component->world = new btDiscreteDynamicsWorld(
        physics_component->collision_dispatcher,
        physics_component->broadphase,
        physics_component->constraint_solver,
        physics_component->collision_configuration);
    physics_component->world->setGravity(btVector3(0, -10, 0));

    physics_component->world->setDebugDrawer(new DebugDraw());

    // ground
    btCollisionShape *ground_shape =
        new btStaticPlaneShape(btVector3(0, 1, 0), 0);
    btDefaultMotionState *ground_motion_state = new btDefaultMotionState(
        btTransform(btQuaternion(0, 0, 0, 1), btVector3(0, 0, 0)));
    btRigidBody::btRigidBodyConstructionInfo ground_rigid_body_ci(
        0, ground_motion_state, ground_shape, btVector3(0, 0, 0));
    btRigidBody *ground_rigid_body = new btRigidBody(ground_rigid_body_ci);
    physics_component->world->addRigidBody(ground_rigid_body);

    return 0;
}