working on bowling demo -- problem with destroying first instance of a loaded model
git-svn-id: svn://anubis/anaglym/trunk@206 99a6e188-d820-4881-8870-2d33a10e2619
This commit is contained in:
parent
bb76eb6e9b
commit
81738dec8a
17
Engine.cc
17
Engine.cc
@ -510,6 +510,23 @@ GLuint Engine::loadTexture(const char * name)
|
|||||||
return m_textureCache.load(path, *m_fileLoader);
|
return m_textureCache.load(path, *m_fileLoader);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GLuint Engine::startList()
|
||||||
|
{
|
||||||
|
GLuint list = glGenLists(1);
|
||||||
|
glNewList(list, GL_COMPILE);
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Engine::endList()
|
||||||
|
{
|
||||||
|
glEndList();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Engine::callList(GLuint list)
|
||||||
|
{
|
||||||
|
glCallList(list);
|
||||||
|
}
|
||||||
|
|
||||||
void Engine::debug_hook(lua_Debug * debug)
|
void Engine::debug_hook(lua_Debug * debug)
|
||||||
{
|
{
|
||||||
Uint32 ticks = SDL_GetTicks();
|
Uint32 ticks = SDL_GetTicks();
|
||||||
|
4
Engine.h
4
Engine.h
@ -144,6 +144,10 @@ class Engine
|
|||||||
{
|
{
|
||||||
m_world.setGravity(gx, gy, gz);
|
m_world.setGravity(gx, gy, gz);
|
||||||
}
|
}
|
||||||
|
GLuint startList();
|
||||||
|
void endList();
|
||||||
|
void drawList(GLuint list);
|
||||||
|
void callList(GLuint list);
|
||||||
|
|
||||||
void getScreenSize(int * width, int * height);
|
void getScreenSize(int * width, int * height);
|
||||||
void drawText(const char * text, GLfloat r, GLfloat g, GLfloat b,
|
void drawText(const char * text, GLfloat r, GLfloat g, GLfloat b,
|
||||||
|
26
ag.cc
26
ag.cc
@ -21,6 +21,7 @@ namespace ag
|
|||||||
void register_functions(lua_State * L)
|
void register_functions(lua_State * L)
|
||||||
{
|
{
|
||||||
static const luaL_Reg functions[] = {
|
static const luaL_Reg functions[] = {
|
||||||
|
{ "callList", callList },
|
||||||
{ "clearEventHandler", clearEventHandler },
|
{ "clearEventHandler", clearEventHandler },
|
||||||
{ "doPhysics", doPhysics },
|
{ "doPhysics", doPhysics },
|
||||||
{ "drawArc", drawArc },
|
{ "drawArc", drawArc },
|
||||||
@ -33,6 +34,7 @@ namespace ag
|
|||||||
{ "drawText", drawText },
|
{ "drawText", drawText },
|
||||||
{ "elapsedTime", elapsedTime },
|
{ "elapsedTime", elapsedTime },
|
||||||
{ "endFrame", endFrame },
|
{ "endFrame", endFrame },
|
||||||
|
{ "endList", endList },
|
||||||
{ "exit", exit },
|
{ "exit", exit },
|
||||||
{ "fillRect", fillRect },
|
{ "fillRect", fillRect },
|
||||||
{ "getCamera", getCamera },
|
{ "getCamera", getCamera },
|
||||||
@ -54,6 +56,7 @@ namespace ag
|
|||||||
{ "setGravity", setGravity },
|
{ "setGravity", setGravity },
|
||||||
// { "sleep", sleep },
|
// { "sleep", sleep },
|
||||||
{ "startFrame", startFrame },
|
{ "startFrame", startFrame },
|
||||||
|
{ "startList", startList },
|
||||||
|
|
||||||
/* managed object functions */
|
/* managed object functions */
|
||||||
{ "createBox", createBox },
|
{ "createBox", createBox },
|
||||||
@ -753,6 +756,29 @@ namespace ag
|
|||||||
return createCapsuleSpecify(L, true);
|
return createCapsuleSpecify(L, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int startList(lua_State * L)
|
||||||
|
{
|
||||||
|
GLuint list = g_engine->startList();
|
||||||
|
lua_pushnumber(L, list);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int endList(lua_State * L)
|
||||||
|
{
|
||||||
|
g_engine->endList();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int callList(lua_State * L)
|
||||||
|
{
|
||||||
|
int argc = lua_gettop(L);
|
||||||
|
if (argc == 1 && lua_isnumber(L, 1))
|
||||||
|
{
|
||||||
|
g_engine->callList(lua_tointeger(L, 1));
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
namespace object
|
namespace object
|
||||||
{
|
{
|
||||||
static Engine::Object * getObject(lua_State * L, int index)
|
static Engine::Object * getObject(lua_State * L, int index)
|
||||||
|
3
ag.h
3
ag.h
@ -9,11 +9,13 @@ namespace ag
|
|||||||
void register_functions(lua_State * L);
|
void register_functions(lua_State * L);
|
||||||
|
|
||||||
/* Lua interfaces */
|
/* Lua interfaces */
|
||||||
|
int callList(lua_State * L);
|
||||||
int clearEventHandler(lua_State * L);
|
int clearEventHandler(lua_State * L);
|
||||||
int doPhysics(lua_State * L);
|
int doPhysics(lua_State * L);
|
||||||
int drawObjects(lua_State * L);
|
int drawObjects(lua_State * L);
|
||||||
int elapsedTime(lua_State * L);
|
int elapsedTime(lua_State * L);
|
||||||
int endFrame(lua_State * L);
|
int endFrame(lua_State * L);
|
||||||
|
int endList(lua_State * L);
|
||||||
int exit(lua_State * L);
|
int exit(lua_State * L);
|
||||||
int getCamera(lua_State * L);
|
int getCamera(lua_State * L);
|
||||||
int getScreenSize(lua_State * L);
|
int getScreenSize(lua_State * L);
|
||||||
@ -33,6 +35,7 @@ namespace ag
|
|||||||
int setGravity(lua_State * L);
|
int setGravity(lua_State * L);
|
||||||
int sleep(lua_State * L);
|
int sleep(lua_State * L);
|
||||||
int startFrame(lua_State * L);
|
int startFrame(lua_State * L);
|
||||||
|
int startList(lua_State * L);
|
||||||
|
|
||||||
/* 2D overlay functions */
|
/* 2D overlay functions */
|
||||||
int drawArc(lua_State * L);
|
int drawArc(lua_State * L);
|
||||||
|
@ -1,41 +1,59 @@
|
|||||||
|
|
||||||
function setupPins()
|
ag.import("std")
|
||||||
|
|
||||||
|
function resetPins()
|
||||||
|
local head_x = 0
|
||||||
|
local head_y = 15
|
||||||
|
local spacing = 0.7
|
||||||
for i = 1, 10 do
|
for i = 1, 10 do
|
||||||
if (pins[i] ~= nil) then
|
if (pins[i] ~= nil) then
|
||||||
pins[i]:destroy()
|
pins[i]:destroy()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
local n = 1
|
||||||
|
for row = 0, 4 do
|
||||||
|
for j = 0, row do
|
||||||
|
pins[n] = reference_pin:clone()
|
||||||
|
pins[n]:setPosition(head_x - row * spacing / 2 + j * spacing,
|
||||||
|
head_y + 0.866 * spacing * row,
|
||||||
|
1 - pin_minz)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function setupStars()
|
function setupStars()
|
||||||
stars = {}
|
stars = ag.startList()
|
||||||
local dist = 500
|
local dist = 500
|
||||||
for i = 1, 1000 do
|
for i = 1, 500 do
|
||||||
local star = {}
|
|
||||||
local rx = math.random() * math.pi * 2
|
local rx = math.random() * math.pi * 2
|
||||||
local ry = (math.random() - 0.5) * math.pi
|
local ry = (math.random() - 0.5) * math.pi
|
||||||
star.x = dist * math.cos(ry) * math.cos(rx)
|
local x = dist * math.cos(ry) * math.cos(rx)
|
||||||
star.y = dist * math.cos(ry) * math.sin(rx)
|
local y = dist * math.cos(ry) * math.sin(rx)
|
||||||
star.z = dist * math.sin(ry)
|
local z = dist * math.sin(ry)
|
||||||
star.size = math.random(2, 8)
|
local size = math.random(1, 6)
|
||||||
stars[i] = star
|
ag.drawPoint(size, 1, 1, 1, x, y, z)
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function drawStars()
|
|
||||||
for i = 1, #stars do
|
|
||||||
ag.drawPoint(stars[i].size, 1, 1, 1, stars[i].x, stars[i].y, stars[i].z)
|
|
||||||
end
|
end
|
||||||
|
ag.endList()
|
||||||
end
|
end
|
||||||
|
|
||||||
function init_event()
|
function init_event()
|
||||||
pins = {}
|
|
||||||
lane = ag.loadModelStatic("bowling_lane")
|
lane = ag.loadModelStatic("bowling_lane")
|
||||||
setupPins()
|
local minx, miny, minz, maxx, maxy, maxz = lane:getAABB()
|
||||||
|
local lane_bottom = minz
|
||||||
|
pins = {}
|
||||||
|
reference_pin = ag.loadModel("bowling_pin", 1.0/4.3)
|
||||||
|
minx, miny, minz, maxx, maxy, maxz = reference_pin:getAABB()
|
||||||
|
pin_minz = minz
|
||||||
|
pin_maxz = maxz
|
||||||
|
local box = ag.createBoxStatic(1, 1, 0.1)
|
||||||
|
box:setColor(0, 0, 0)
|
||||||
|
box:setPosition(0, 0, lane_bottom - (maxz - minz) - 0.4)
|
||||||
|
reference_pin:setPosition(0, 0, lane_bottom - maxz - 0.1)
|
||||||
|
resetPins()
|
||||||
setupStars()
|
setupStars()
|
||||||
ag.setCamera(0, -20, 5, 0, 20, 0)
|
ag.setCamera(0, -10, 5, 0, 20, 0)
|
||||||
end
|
end
|
||||||
|
|
||||||
function update_event()
|
function update_event()
|
||||||
drawStars()
|
ag.callList(stars)
|
||||||
end
|
end
|
||||||
|
@ -74,19 +74,23 @@ std.loadModelBounds = function(model_name, max_x, max_y, max_z)
|
|||||||
local sx, sy, sz = tmp_model:getSize()
|
local sx, sy, sz = tmp_model:getSize()
|
||||||
tmp_model:destroy()
|
tmp_model:destroy()
|
||||||
local scale = 1.0
|
local scale = 1.0
|
||||||
|
local scale_set = false
|
||||||
if (max_x > 0 and sx > 0) then
|
if (max_x > 0 and sx > 0) then
|
||||||
scale = max_x / sx
|
scale = max_x / sx
|
||||||
|
scale_set = true
|
||||||
end
|
end
|
||||||
if (max_y > 0 and sy > 0) then
|
if (max_y > 0 and sy > 0) then
|
||||||
local s = max_y / sy
|
local s = max_y / sy
|
||||||
if (s < scale) then
|
if (s < scale or not scale_set) then
|
||||||
scale = s
|
scale = s
|
||||||
|
scale_set = true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if (max_z > 0 and sz > 0) then
|
if (max_z > 0 and sz > 0) then
|
||||||
local s = max_z / sz
|
local s = max_z / sz
|
||||||
if (s < scale) then
|
if (s < scale or not scale_set) then
|
||||||
scale = s
|
scale = s
|
||||||
|
scale_set = true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return ag.loadModel(model_name, scale)
|
return ag.loadModel(model_name, scale)
|
||||||
|
8
tests/destroy.lua
Normal file
8
tests/destroy.lua
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
|
||||||
|
ag.setCamera(0, -5, 0)
|
||||||
|
pin = ag.loadModel("bowling_pin")
|
||||||
|
pin:setPosition(-1.5, 0, 0)
|
||||||
|
pin2 = ag.loadModel("bowling_pin")
|
||||||
|
pin3 = ag.loadModel("bowling_pin")
|
||||||
|
pin3:setPosition(1.5, 0, 0)
|
||||||
|
pin:destroy()
|
Loading…
x
Reference in New Issue
Block a user