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:
parent
e0d20f1a2b
commit
1d97d948fc
24
Engine.cc
24
Engine.cc
@ -682,18 +682,28 @@ void Engine::Object::createManagedObject()
|
||||
switch (m_geom_type)
|
||||
{
|
||||
case OdeWorld::BOX:
|
||||
while (m_args->size() < 9)
|
||||
m_args->push_back(0);
|
||||
m_ode_object->addBox(m_args);
|
||||
break;
|
||||
case OdeWorld::SPHERE:
|
||||
while (m_args->size() < 4)
|
||||
m_args->push_back(0);
|
||||
m_ode_object->addSphere(m_args);
|
||||
break;
|
||||
case OdeWorld::PLANE:
|
||||
while (m_args->size() < 6)
|
||||
m_args->push_back(0);
|
||||
m_ode_object->addPlane(m_args);
|
||||
break;
|
||||
case OdeWorld::CYLINDER:
|
||||
while (m_args->size() < 8)
|
||||
m_args->push_back(0);
|
||||
m_ode_object->addCylinder(m_args);
|
||||
break;
|
||||
case OdeWorld::CCYLINDER:
|
||||
while (m_args->size() < 8)
|
||||
m_args->push_back(0);
|
||||
m_ode_object->addCCylinder(m_args);
|
||||
break;
|
||||
}
|
||||
@ -725,8 +735,7 @@ void Engine::Object::render()
|
||||
}
|
||||
if (!valid)
|
||||
return;
|
||||
if (m_display_list > 0)
|
||||
glDeleteLists(m_display_list, 1);
|
||||
if (m_display_list <= 0)
|
||||
m_display_list = glGenLists(1);
|
||||
glNewList(m_display_list, GL_COMPILE);
|
||||
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, m_color);
|
||||
@ -786,7 +795,7 @@ void Engine::Object::render()
|
||||
/* plane equation: ax + by + cz = d, plane normal: (a, b, c) */
|
||||
|
||||
const int num_sections = 10;
|
||||
const float section_size = 10.0f;
|
||||
const float section_size = 100.0f;
|
||||
float x_o = (*m_args)[0];
|
||||
float y_o = (*m_args)[1];
|
||||
float z_o = (*m_args)[2];
|
||||
@ -811,11 +820,16 @@ void Engine::Object::render()
|
||||
}
|
||||
}
|
||||
break;
|
||||
case OdeWorld::CYLINDER:
|
||||
case OdeWorld::CYLINDER: {
|
||||
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);
|
||||
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();
|
||||
}
|
||||
break;
|
||||
case OdeWorld::CCYLINDER: {
|
||||
glPushAttrib(GL_TRANSFORM_BIT); /* save current clip planes */
|
||||
|
1
Engine.h
1
Engine.h
@ -63,6 +63,7 @@ class Engine
|
||||
m_color[0] = r;
|
||||
m_color[1] = g;
|
||||
m_color[2] = b;
|
||||
render();
|
||||
}
|
||||
|
||||
void draw();
|
||||
|
25
tests/managed_objects.lua
Normal file
25
tests/managed_objects.lua
Normal 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
|
Loading…
x
Reference in New Issue
Block a user