#include "GL_Cylinder.h" #include "X3D_Cylinder.h" #include "CylinderDrawArray.h" namespace X3DTK { namespace GL { Cylinder::Cylinder() : X3DGeometryNode(), _cylinderArray(0) { define(Recorder::getTypeName("Cylinder", "Geometry3D")); define(Recorder::getAttribute("radius", &Cylinder::_radius, 0.0f)); define(Recorder::getAttribute("height", &Cylinder::_height, 0.0f)); define(Recorder::getAttribute("side", &Cylinder::_side, false)); define(Recorder::getAttribute("bottom", &Cylinder::_bottom, false)); define(Recorder::getAttribute("top", &Cylinder::_top, false)); } Cylinder::~Cylinder() { _cylinderArray->removeInstance(); } void Cylinder::setRadius(const SFFloat &radius) { _radius = radius; } void Cylinder::setHeight(const SFFloat &height) { _height = height; } void Cylinder::setSide(const SFBool &side) { _side = side; } void Cylinder::setBottom(const SFBool &bottom) { _bottom = bottom; } void Cylinder::setTop(const SFBool &top) { _top = top; } void Cylinder::setCylinderArray(CylinderDrawArray *cylinderArray) { _cylinderArray = cylinderArray; } void Cylinder::update() { if (x3dReference == 0) return; X3D::Cylinder *C = static_cast(x3dReference); _bottom = C->getBottom(); _radius = C->getRadius(); _height = C->getHeight(); _side = C->getSide(); _top = C->getTop(); _cylinderArray = CylinderDrawArray::getInstanceOfSection(32); } void Cylinder::draw() const { glEnable(GL_CULL_FACE); glFrontFace(GL_CW); glCullFace(GL_BACK); glPushMatrix(); glScalef(_radius, _height, _radius); //test the attributes if (_bottom) { glInterleavedArrays(GL_N3F_V3F, 0, _cylinderArray->getCylinderBottomVertexArrayAddress()); glDrawElements(GL_TRIANGLE_FAN, _cylinderArray->getCylinderBottomSize(), GL_UNSIGNED_INT, _cylinderArray->getCylinderBottomIndexArrayAddress()); } if (_side) { glInterleavedArrays(GL_N3F_V3F, 0, _cylinderArray->getCylinderSideVertexArrayAddress()); glDrawElements(GL_TRIANGLE_STRIP, _cylinderArray->getCylinderSideSize(), GL_UNSIGNED_INT, _cylinderArray->getCylinderSideIndexArrayAddress()); } if (_top) { glInterleavedArrays(GL_N3F_V3F, 0, _cylinderArray->getCylinderTopVertexArrayAddress()); glDrawElements(GL_TRIANGLE_FAN, _cylinderArray->getCylinderTopSize(), GL_UNSIGNED_INT, _cylinderArray->getCylinderTopIndexArrayAddress()); } glPopMatrix(); glDisable(GL_CULL_FACE); } } }