fixed drawing of cylinders (physics with ODE doesn' work anyway), fixed re-rendering managed object when the color changes, added managed_objects demo

git-svn-id: svn://anubis/anaglym/trunk@134 99a6e188-d820-4881-8870-2d33a10e2619
This commit is contained in:
Josh Holtrop 2009-10-28 03:32:07 +00:00
parent e0d20f1a2b
commit 1d97d948fc
3 changed files with 46 additions and 6 deletions

View File

@ -682,18 +682,28 @@ void Engine::Object::createManagedObject()
switch (m_geom_type) switch (m_geom_type)
{ {
case OdeWorld::BOX: case OdeWorld::BOX:
while (m_args->size() < 9)
m_args->push_back(0);
m_ode_object->addBox(m_args); m_ode_object->addBox(m_args);
break; break;
case OdeWorld::SPHERE: case OdeWorld::SPHERE:
while (m_args->size() < 4)
m_args->push_back(0);
m_ode_object->addSphere(m_args); m_ode_object->addSphere(m_args);
break; break;
case OdeWorld::PLANE: case OdeWorld::PLANE:
while (m_args->size() < 6)
m_args->push_back(0);
m_ode_object->addPlane(m_args); m_ode_object->addPlane(m_args);
break; break;
case OdeWorld::CYLINDER: case OdeWorld::CYLINDER:
while (m_args->size() < 8)
m_args->push_back(0);
m_ode_object->addCylinder(m_args); m_ode_object->addCylinder(m_args);
break; break;
case OdeWorld::CCYLINDER: case OdeWorld::CCYLINDER:
while (m_args->size() < 8)
m_args->push_back(0);
m_ode_object->addCCylinder(m_args); m_ode_object->addCCylinder(m_args);
break; break;
} }
@ -725,9 +735,8 @@ void Engine::Object::render()
} }
if (!valid) if (!valid)
return; return;
if (m_display_list > 0) if (m_display_list <= 0)
glDeleteLists(m_display_list, 1); m_display_list = glGenLists(1);
m_display_list = glGenLists(1);
glNewList(m_display_list, GL_COMPILE); glNewList(m_display_list, GL_COMPILE);
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, m_color); glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, m_color);
GLUquadric * quad = gluNewQuadric(); GLUquadric * quad = gluNewQuadric();
@ -786,7 +795,7 @@ void Engine::Object::render()
/* plane equation: ax + by + cz = d, plane normal: (a, b, c) */ /* plane equation: ax + by + cz = d, plane normal: (a, b, c) */
const int num_sections = 10; const int num_sections = 10;
const float section_size = 10.0f; const float section_size = 100.0f;
float x_o = (*m_args)[0]; float x_o = (*m_args)[0];
float y_o = (*m_args)[1]; float y_o = (*m_args)[1];
float z_o = (*m_args)[2]; float z_o = (*m_args)[2];
@ -811,11 +820,16 @@ void Engine::Object::render()
} }
} }
break; break;
case OdeWorld::CYLINDER: case OdeWorld::CYLINDER: {
glPushMatrix(); glPushMatrix();
glTranslatef(0, 0, -(*m_args)[1] / 2.0); float half_span = (*m_args)[1] / 2.0;
glTranslatef(0, 0, -half_span);
gluCylinder(quad, (*m_args)[0], (*m_args)[0], (*m_args)[1], 12, 1); gluCylinder(quad, (*m_args)[0], (*m_args)[0], (*m_args)[1], 12, 1);
gluDisk(quad, 0.0, (*m_args)[0], 12, 4);
glTranslatef(0, 0, 2 * half_span);
gluDisk(quad, 0.0, (*m_args)[0], 12, 4);
glPopMatrix(); glPopMatrix();
}
break; break;
case OdeWorld::CCYLINDER: { case OdeWorld::CCYLINDER: {
glPushAttrib(GL_TRANSFORM_BIT); /* save current clip planes */ glPushAttrib(GL_TRANSFORM_BIT); /* save current clip planes */

View File

@ -63,6 +63,7 @@ class Engine
m_color[0] = r; m_color[0] = r;
m_color[1] = g; m_color[1] = g;
m_color[2] = b; m_color[2] = b;
render();
} }
void draw(); void draw();

25
tests/managed_objects.lua Normal file
View File

@ -0,0 +1,25 @@
ground = ag.createStaticPlane(0, 0, 0, 0, 0, 0)
ground:setColor(0.2, 1.0, 0.2)
ag.setCamera(10, -10, 10, 0, 0, 0)
function init(obj)
obj:setColor(math.random(), math.random(), math.random())
obj:setPosition((math.random() - 0.5) * 10, (math.random() - 0.5) * 10, 10)
end
function key_down_event(key)
if (key == "b") then
box = ag.createBox(1, 1, 1)
init(box)
-- elseif (key == "c") then
-- cyl = ag.createCylinder(0.5, 1)
-- init(cyl)
elseif (key == "a") then
ccyl = ag.createCCylinder(0.5, 1)
init(ccyl)
elseif (key == "s") then
sphere = ag.createSphere(0.8)
init(sphere)
end
end