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