added autoStartFrame and autoEndFrame
git-svn-id: svn://anubis/anaglym/trunk@87 99a6e188-d820-4881-8870-2d33a10e2619
This commit is contained in:
parent
3d5a5b1ecb
commit
53e98eb57a
12
Engine.cc
12
Engine.cc
@ -31,6 +31,8 @@ Engine::Engine(const string & path)
|
||||
m_up[2] = 1;
|
||||
m_drawing = false;
|
||||
m_autoPhysics = true;
|
||||
m_autoStartFrame = true;
|
||||
m_autoEndFrame = true;
|
||||
|
||||
size_t pos = path.find_last_of("\\/");
|
||||
m_engine_path = (pos != string::npos) ? string(path, 0, pos) : ".";
|
||||
@ -165,7 +167,7 @@ Engine::Object * Engine::getObject(int id)
|
||||
return m_objects.find(id) != m_objects.end() ? m_objects[id] : NULL;
|
||||
}
|
||||
|
||||
int Engine::startFrame(lua_State * L)
|
||||
void Engine::startFrame()
|
||||
{
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
@ -173,13 +175,11 @@ int Engine::startFrame(lua_State * L)
|
||||
gluLookAt(m_eye[0], m_eye[1], m_eye[2],
|
||||
m_center[0], m_center[1], m_center[2],
|
||||
m_up[0], m_up[1], m_up[2]);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Engine::endFrame(lua_State * L)
|
||||
void Engine::endFrame()
|
||||
{
|
||||
SDL_GL_SwapBuffers();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Engine::setCamera(lua_State * L)
|
||||
@ -272,6 +272,8 @@ void Engine::update()
|
||||
m_drawing = true;
|
||||
if (m_autoPhysics)
|
||||
doPhysics();
|
||||
if (m_autoStartFrame)
|
||||
startFrame();
|
||||
lua_getfield(m_luaState, LUA_GLOBALSINDEX, "update");
|
||||
if (lua_type(m_luaState, -1) == LUA_TFUNCTION)
|
||||
{
|
||||
@ -283,6 +285,8 @@ void Engine::update()
|
||||
{
|
||||
lua_pop(m_luaState, 1);
|
||||
}
|
||||
if (m_autoEndFrame)
|
||||
endFrame();
|
||||
m_drawing = false;
|
||||
}
|
||||
|
||||
|
10
Engine.h
10
Engine.h
@ -62,10 +62,14 @@ class Engine
|
||||
void drawObjects();
|
||||
void setAutoPhysics(bool autoPhysics) { m_autoPhysics = autoPhysics; }
|
||||
bool getAutoPhysics() { return m_autoPhysics; }
|
||||
void setAutoStartFrame(bool asf) { m_autoStartFrame = asf; }
|
||||
bool getAutoStartFrame() { return m_autoStartFrame; }
|
||||
void setAutoEndFrame(bool asf) { m_autoEndFrame = asf; }
|
||||
bool getAutoEndFrame() { return m_autoEndFrame; }
|
||||
void startFrame();
|
||||
void endFrame();
|
||||
|
||||
/* lua services */
|
||||
int startFrame(lua_State * L);
|
||||
int endFrame(lua_State * L);
|
||||
int setCamera(lua_State * L);
|
||||
|
||||
protected:
|
||||
@ -93,6 +97,8 @@ class Engine
|
||||
GLdouble m_up[3];
|
||||
bool m_drawing;
|
||||
bool m_autoPhysics;
|
||||
bool m_autoStartFrame;
|
||||
bool m_autoEndFrame;
|
||||
};
|
||||
|
||||
extern Engine * g_engine;
|
||||
|
31
ag.cc
31
ag.cc
@ -33,6 +33,8 @@ namespace ag
|
||||
{ "doPhysics", doPhysics },
|
||||
{ "drawObjects", drawObjects },
|
||||
{ "setAutoPhysics", setAutoPhysics },
|
||||
{ "setAutoStartFrame", setAutoStartFrame },
|
||||
{ "setAutoEndFrame", setAutoEndFrame },
|
||||
{ NULL, NULL }
|
||||
};
|
||||
luaL_register(L, "ag", functions);
|
||||
@ -201,12 +203,14 @@ namespace ag
|
||||
|
||||
int startFrame(lua_State * L)
|
||||
{
|
||||
return g_engine->startFrame(L);
|
||||
g_engine->startFrame();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int endFrame(lua_State * L)
|
||||
{
|
||||
return g_engine->endFrame(L);
|
||||
g_engine->endFrame();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int setCamera(lua_State * L)
|
||||
@ -235,15 +239,24 @@ namespace ag
|
||||
int setAutoPhysics(lua_State * L)
|
||||
{
|
||||
int argc = lua_gettop(L);
|
||||
if (argc == 1 && lua_isboolean(L, 1))
|
||||
g_engine->setAutoPhysics(lua_toboolean(L, 1));
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (argc == 1)
|
||||
{
|
||||
if (lua_isboolean(L, 1))
|
||||
{
|
||||
g_engine->setAutoPhysics(lua_toboolean(L, 1));
|
||||
}
|
||||
}
|
||||
int setAutoStartFrame(lua_State * L)
|
||||
{
|
||||
int argc = lua_gettop(L);
|
||||
if (argc == 1 && lua_isboolean(L, 1))
|
||||
g_engine->setAutoStartFrame(lua_toboolean(L, 1));
|
||||
return 0;
|
||||
}
|
||||
|
||||
int setAutoEndFrame(lua_State * L)
|
||||
{
|
||||
int argc = lua_gettop(L);
|
||||
if (argc == 1 && lua_isboolean(L, 1))
|
||||
g_engine->setAutoEndFrame(lua_toboolean(L, 1));
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
2
ag.h
2
ag.h
@ -19,6 +19,8 @@ namespace ag
|
||||
int doPhysics(lua_State * L);
|
||||
int drawObjects(lua_State * L);
|
||||
int setAutoPhysics(lua_State * L);
|
||||
int setAutoStartFrame(lua_State * L);
|
||||
int setAutoEndFrame(lua_State * L);
|
||||
|
||||
namespace object
|
||||
{
|
||||
|
@ -2,9 +2,7 @@
|
||||
function update()
|
||||
ballx, bally, ballz = ball:getPosition()
|
||||
ag.setCamera(7, -6, 15, ballx, bally, ballz, 0, 0, 1)
|
||||
ag.startFrame()
|
||||
ag.drawObjects()
|
||||
ag.endFrame()
|
||||
end
|
||||
|
||||
--ag.setCamera(8, -8, 15, -8, 8, 4, 0, 0, 1)
|
||||
|
Loading…
x
Reference in New Issue
Block a user