From 968a35bc36a376ce97cf14a168f82fd9124438e6 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Mon, 12 Oct 2009 21:30:56 +0000 Subject: [PATCH] added scaling support when creating Engine::Objects git-svn-id: svn://anubis/anaglym/trunk@72 99a6e188-d820-4881-8870-2d33a10e2619 --- anaglym.cc | 19 +++++++++++++++++-- anaglym.h | 5 ++++- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/anaglym.cc b/anaglym.cc index 4006e62..8403149 100644 --- a/anaglym.cc +++ b/anaglym.cc @@ -9,6 +9,7 @@ #include #include #include +#include /* fabs() */ #include #include using namespace std; @@ -373,13 +374,15 @@ void Engine::drawObjects() } } -Engine::Object::Object(bool is_static, OdeWorld & world, GLuint dl) +Engine::Object::Object(bool is_static, OdeWorld & world, GLuint dl, float scale) { - m_ode_object = world.createObject(is_static); + m_ode_object = world.createObject(is_static, scale); m_display_list = dl; m_display_list_refcnt = new int; *m_display_list_refcnt = 1; m_is_visible = true; + m_scale = scale; + m_is_scaled = ! (fabs(scale - 1.0) < 0.0001); } Engine::Object::Object(const Engine::Object & orig) @@ -389,6 +392,8 @@ Engine::Object::Object(const Engine::Object & orig) m_display_list = orig.m_display_list; m_display_list_refcnt = orig.m_display_list_refcnt; (*m_display_list_refcnt)++; + m_scale = orig.m_scale; + m_is_scaled = orig.m_is_scaled; } Engine::Object::~Object() @@ -414,8 +419,18 @@ void Engine::Object::draw() if (transform) OdeWorld::pushTransform(pos, rot); + if (m_is_scaled) + { + glPushAttrib(GL_TRANSFORM_BIT); + glEnable(GL_NORMALIZE); + glScalef(m_scale, m_scale, m_scale); + } + glCallList(m_display_list); + if (m_is_scaled) + glPopAttrib(); + if (transform) glPopMatrix(); } diff --git a/anaglym.h b/anaglym.h index 8926254..c5e1810 100644 --- a/anaglym.h +++ b/anaglym.h @@ -17,7 +17,8 @@ class Engine class Object { public: - Object(bool is_static, OdeWorld & world, GLuint dl); + Object(bool is_static, OdeWorld & world, GLuint dl, + float scale = 1.0f); Object(const Object & orig); ~Object(); @@ -43,6 +44,8 @@ class Engine GLuint m_display_list; int * m_display_list_refcnt; bool m_is_visible; + float m_scale; + bool m_is_scaled; }; Engine();