From 3ee41bfa9fbea6a97bb498b74681104f99af934c Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Tue, 27 Oct 2009 14:56:06 +0000 Subject: [PATCH] drawing capped cylinders now (i think) git-svn-id: svn://anubis/anaglym/trunk@125 99a6e188-d820-4881-8870-2d33a10e2619 --- Engine.cc | 20 +++++++++++++++++++- tests/cannon.lua | 7 +++++-- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/Engine.cc b/Engine.cc index 6846aba..b1a6051 100644 --- a/Engine.cc +++ b/Engine.cc @@ -733,9 +733,27 @@ void Engine::Object::render() gluCylinder(quad, (*m_args)[0], (*m_args)[0], (*m_args)[1], 12, 1); glPopMatrix(); break; - case OdeWorld::CCYLINDER: + case OdeWorld::CCYLINDER: { + glPushAttrib(GL_TRANSFORM_BIT); /* save current clip planes */ + double halfheight = (*m_args)[1] / 2.0; + glPushMatrix(); + glTranslatef(0, 0, -halfheight); + gluCylinder(quad, (*m_args)[0], (*m_args)[0], (*m_args)[1], 12, 1); + + double clip_plane[] = {0, 0, -1, halfheight}; + glClipPlane(GL_CLIP_PLANE0, clip_plane); + glEnable(GL_CLIP_PLANE0); + gluSphere(quad, (*m_args)[0], 12, 8); + glTranslatef(0, 0, 2*halfheight); + clip_plane[2] = 1.0; + glClipPlane(GL_CLIP_PLANE0, clip_plane); + gluSphere(quad, (*m_args)[0], 12, 8); + glPopMatrix(); + glPopAttrib(); + } break; } + gluDeleteQuadric(quad); glEndList(); } diff --git a/tests/cannon.lua b/tests/cannon.lua index 42f18e4..a3dbf44 100644 --- a/tests/cannon.lua +++ b/tests/cannon.lua @@ -19,11 +19,14 @@ camx, camy, camz, cx, cy, cz = ag.getCamera() ball = ag.loadModel("checkerball") ball:setPosition(2*camx - cx, 2*camy - cy, 2*camz - cz) -function key_down_event(key) - if (key == "space") then +function mousebutton_down_event(button) + local function button1() local newball = ball:clone() newball:setPosition(camx, camy, camz) force = 10000 newball:addForce(force * (cx-camx), force * (cy-camy), force * (cz-camz)) end + if (button == 1) then + button1() + end end