From bece35d2700e0f71a26bae2cc93474644538de1b Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Sun, 19 Dec 2010 00:11:37 -0500 Subject: [PATCH] added setPosition() for Quads --- Engine.cc | 4 ++++ Engine.h | 8 ++++++++ ag.cc | 21 +++++++++++++++++++++ ag.h | 1 + 4 files changed, 34 insertions(+) diff --git a/Engine.cc b/Engine.cc index 1a92832..fb1f455 100644 --- a/Engine.cc +++ b/Engine.cc @@ -1347,6 +1347,7 @@ Engine::Quad::Quad(float cx, float cy, float cz, m_texture = 0; m_enable_blending = false; m_color[0] = m_color[1] = m_color[2] = m_color[3] = 1.0f; + m_position[0] = m_position[1] = m_position[2] = 0.0f; render(); } @@ -1385,6 +1386,8 @@ int Engine::Quad::render() glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); } + glPushMatrix(); + glTranslatef(m_position[0], m_position[1], m_position[2]); glBegin(GL_QUADS); glNormal3f(m_normal[0], m_normal[1], m_normal[2]); glVertex3f(m_center[0] + m_v1[0] + m_v2[0], @@ -1400,6 +1403,7 @@ int Engine::Quad::render() m_center[1] + m_v1[1] - m_v2[1], m_center[2] + m_v1[2] - m_v2[2]); glEnd(); + glPopMatrix(); glPopAttrib(); glEndList(); return m_dl; diff --git a/Engine.h b/Engine.h index c21e36a..0ce6273 100644 --- a/Engine.h +++ b/Engine.h @@ -173,6 +173,13 @@ class Engine m_offset = f; render(); } + void setPosition(float x, float y, float z) + { + m_position[0] = x; + m_position[1] = y; + m_position[2] = z; + render(); + } void setTexture(int t) { m_texture = t; @@ -200,6 +207,7 @@ class Engine int m_texture; bool m_enable_blending; float m_color[4]; + float m_position[3]; }; Engine(const std::string & path, AV & av); diff --git a/ag.cc b/ag.cc index 52d19aa..3132854 100644 --- a/ag.cc +++ b/ag.cc @@ -740,6 +740,8 @@ fail: lua_setfield(L, -2, "setColor"); lua_pushcfunction(L, quad::setOffset); lua_setfield(L, -2, "setOffset"); + lua_pushcfunction(L, quad::setPosition); + lua_setfield(L, -2, "setPosition"); lua_pushcfunction(L, quad::setTexture); lua_setfield(L, -2, "setTexture"); lua_pushcfunction(L, quad::setVisible); @@ -1697,6 +1699,25 @@ fail: return 0; } + int setPosition(lua_State * L) + { + int argc = lua_gettop(L); + if (argc == 4 && lua_istable(L, 1) + && lua_isnumber(L, 2) + && lua_isnumber(L, 3) + && lua_isnumber(L, 4)) + { + Engine::Quad * q = getQuad(L, 1); + if (q != NULL) + { + q->setPosition(lua_tonumber(L, 2), + lua_tonumber(L, 3), + lua_tonumber(L, 4)); + } + } + return 0; + } + int setTexture(lua_State * L) { int argc = lua_gettop(L); diff --git a/ag.h b/ag.h index 4fe88c3..628ef62 100644 --- a/ag.h +++ b/ag.h @@ -104,6 +104,7 @@ namespace ag int setBlending(lua_State * L); int setColor(lua_State * L); int setOffset(lua_State * L); + int setPosition(lua_State * L); int setTexture(lua_State * L); int setVisible(lua_State * L); }