working on rendering managed objects
git-svn-id: svn://anubis/anaglym/trunk@124 99a6e188-d820-4881-8870-2d33a10e2619
This commit is contained in:
parent
d1a57b673e
commit
869e6465cc
105
Engine.cc
105
Engine.cc
@ -613,6 +613,27 @@ Engine::Object::Object(bool is_static, OdeWorld & world, GLuint dl, float scale)
|
||||
m_is_visible = true;
|
||||
m_scale = scale;
|
||||
m_is_scaled = ! (fabs(scale - 1.0) < 0.0001);
|
||||
m_is_managed = false;
|
||||
}
|
||||
|
||||
Engine::Object::Object(bool is_static, OdeWorld & world,
|
||||
OdeWorld::GeomType geom_type,
|
||||
refptr< std::vector<float> > args)
|
||||
{
|
||||
m_is_visible = true;
|
||||
m_scale = 1.0f;
|
||||
m_is_scaled = false;
|
||||
m_display_list = -1;
|
||||
m_display_list_refcnt = NULL;
|
||||
m_ode_object = world.createObject(
|
||||
geom_type == OdeWorld::PLANE ? false : is_static,
|
||||
m_scale);
|
||||
m_is_managed = true;
|
||||
m_geom_type = geom_type;
|
||||
m_args = args;
|
||||
for (int i = 0; i < 4; i++)
|
||||
m_color[i] = 1.0f;
|
||||
createManagedObject();
|
||||
}
|
||||
|
||||
Engine::Object::Object(const Engine::Object & orig)
|
||||
@ -621,9 +642,15 @@ Engine::Object::Object(const Engine::Object & orig)
|
||||
m_ode_object = new OdeWorld::Object(*orig.m_ode_object);
|
||||
m_display_list = orig.m_display_list;
|
||||
m_display_list_refcnt = orig.m_display_list_refcnt;
|
||||
if (m_display_list_refcnt != NULL)
|
||||
(*m_display_list_refcnt)++;
|
||||
m_scale = orig.m_scale;
|
||||
m_is_scaled = orig.m_is_scaled;
|
||||
m_is_managed = orig.m_is_managed;
|
||||
m_geom_type = orig.m_geom_type;
|
||||
m_args = orig.m_args;
|
||||
for (int i = 0; i < 4; i++)
|
||||
m_color[i] = orig.m_color[i];
|
||||
}
|
||||
|
||||
Engine::Object::~Object()
|
||||
@ -638,6 +665,80 @@ Engine::Object::~Object()
|
||||
}
|
||||
}
|
||||
|
||||
void Engine::Object::createManagedObject()
|
||||
{
|
||||
switch (m_geom_type)
|
||||
{
|
||||
case OdeWorld::CUBE:
|
||||
m_ode_object->addCube(m_args);
|
||||
break;
|
||||
case OdeWorld::SPHERE:
|
||||
m_ode_object->addSphere(m_args);
|
||||
break;
|
||||
case OdeWorld::PLANE:
|
||||
m_ode_object->addPlane(m_args);
|
||||
break;
|
||||
case OdeWorld::CYLINDER:
|
||||
m_ode_object->addCylinder(m_args);
|
||||
break;
|
||||
case OdeWorld::CCYLINDER:
|
||||
m_ode_object->addCCylinder(m_args);
|
||||
break;
|
||||
}
|
||||
m_ode_object->finalize();
|
||||
render();
|
||||
}
|
||||
|
||||
/* render a managed object */
|
||||
void Engine::Object::render()
|
||||
{
|
||||
bool valid = false;
|
||||
switch (m_geom_type)
|
||||
{
|
||||
case OdeWorld::CUBE:
|
||||
if (m_args->size() >= 3) valid = true;
|
||||
break;
|
||||
case OdeWorld::SPHERE:
|
||||
if (m_args->size() == 4) valid = true;
|
||||
break;
|
||||
case OdeWorld::PLANE:
|
||||
if (m_args->size() == 6) valid = true;
|
||||
break;
|
||||
case OdeWorld::CYLINDER:
|
||||
if (m_args->size() == 8) valid = true;
|
||||
break;
|
||||
case OdeWorld::CCYLINDER:
|
||||
if (m_args->size() == 8) valid = true;
|
||||
break;
|
||||
}
|
||||
if (!valid)
|
||||
return;
|
||||
m_display_list = glGenLists(1);
|
||||
glNewList(m_display_list, GL_COMPILE);
|
||||
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, m_color);
|
||||
GLUquadric * quad = gluNewQuadric();
|
||||
/* TODO: finish */
|
||||
switch (m_geom_type)
|
||||
{
|
||||
case OdeWorld::CUBE:
|
||||
break;
|
||||
case OdeWorld::SPHERE:
|
||||
gluSphere(quad, (*m_args)[0], 16, 8);
|
||||
break;
|
||||
case OdeWorld::PLANE:
|
||||
break;
|
||||
case OdeWorld::CYLINDER:
|
||||
glPushMatrix();
|
||||
glTranslatef(0, 0, -(*m_args)[1] / 2.0);
|
||||
gluCylinder(quad, (*m_args)[0], (*m_args)[0], (*m_args)[1], 12, 1);
|
||||
glPopMatrix();
|
||||
break;
|
||||
case OdeWorld::CCYLINDER:
|
||||
break;
|
||||
}
|
||||
glEndList();
|
||||
}
|
||||
|
||||
void Engine::Object::loadPhy(const FileLoader::Path & path)
|
||||
{
|
||||
FileLoader::Buffer buff = g_engine->m_fileLoader->load(path);
|
||||
@ -664,7 +765,7 @@ void Engine::Object::loadPhy(const FileLoader::Path & path)
|
||||
continue;
|
||||
string name = line.substr(pos + 1, pos2 - pos - 1);
|
||||
pos = pos2 + 1;
|
||||
vector<float> args;
|
||||
refptr< vector<float> > args = new vector<float>();
|
||||
for (;;)
|
||||
{
|
||||
pos = line.find_first_not_of(WHITESPACE, pos);
|
||||
@ -673,7 +774,7 @@ void Engine::Object::loadPhy(const FileLoader::Path & path)
|
||||
pos2 = line.find_first_of(WHITESPACE, pos);
|
||||
string n = line.substr(pos, pos2 - pos);
|
||||
float f = atof(n.c_str());
|
||||
args.push_back(f);
|
||||
args->push_back(f);
|
||||
if (pos2 == string::npos)
|
||||
break;
|
||||
pos = pos2 + 1;
|
||||
|
13
Engine.h
13
Engine.h
@ -23,7 +23,7 @@ class Engine
|
||||
float scale = 1.0f);
|
||||
Object(bool is_static, OdeWorld & world,
|
||||
OdeWorld::GeomType geom_type,
|
||||
const std::vector<float> & args);
|
||||
refptr< std::vector<float> > args);
|
||||
Object(const Object & orig);
|
||||
~Object();
|
||||
|
||||
@ -62,14 +62,23 @@ class Engine
|
||||
void draw();
|
||||
|
||||
protected:
|
||||
void createManagedObject();
|
||||
void render();
|
||||
|
||||
OdeWorld::Object * m_ode_object;
|
||||
GLuint m_display_list;
|
||||
int * m_display_list_refcnt;
|
||||
bool m_is_visible;
|
||||
float m_scale;
|
||||
bool m_is_scaled;
|
||||
bool m_is_managed;
|
||||
|
||||
/* for "pre-loaded" objects */
|
||||
int * m_display_list_refcnt;
|
||||
|
||||
/* for "managed" objects */
|
||||
OdeWorld::GeomType m_geom_type;
|
||||
refptr< std::vector<float> > m_args;
|
||||
float m_color[4];
|
||||
};
|
||||
|
||||
class EngineFileLoader : public FileLoader
|
||||
|
Loading…
x
Reference in New Issue
Block a user