added scaling support when creating Engine::Objects
git-svn-id: svn://anubis/anaglym/trunk@72 99a6e188-d820-4881-8870-2d33a10e2619
This commit is contained in:
parent
c4f07c6c93
commit
968a35bc36
19
anaglym.cc
19
anaglym.cc
@ -9,6 +9,7 @@
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <math.h> /* fabs() */
|
||||
#include <GL/gl.h>
|
||||
#include <GL/glu.h>
|
||||
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();
|
||||
}
|
||||
|
@ -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();
|
||||
|
Loading…
x
Reference in New Issue
Block a user