#include "GL_Cone.h" #include "X3D_Cone.h" #include "ConeDrawArray.h" namespace X3DTK { namespace GL { Cone::Cone() : X3DGeometryNode(), _coneArray(0) { define(Recorder::getTypeName("Cone", "Geometry3D")); define(Recorder::getAttribute("bottomRadius", &Cone::_bottomRadius, 0.0f)); define(Recorder::getAttribute("height", &Cone::_height, 0.0f)); define(Recorder::getAttribute("side", &Cone::_side, false)); define(Recorder::getAttribute("bottom", &Cone::_bottom, false)); } Cone::~Cone() { _coneArray->removeInstance(); } void Cone::setBottomRadius(const SFFloat &bottomRadius) { _bottomRadius = bottomRadius; } void Cone::setHeight(const SFFloat &height) { _height = height; } void Cone::setSide(const SFBool &side) { _side = side; } void Cone::setBottom(const SFBool &bottom) { _bottom = bottom; } void Cone::setConeArray(ConeDrawArray *coneArray) { _coneArray = coneArray; } void Cone::update() { if (x3dReference == 0) return; X3D::Cone *C = static_cast(x3dReference); _bottomRadius = C->getBottomRadius(); _height = C->getHeight(); _side = C->getSide(); _bottom = C->getBottom(); _coneArray = ConeDrawArray::getInstanceOfSection(64); } void Cone::draw() const { glEnable(GL_CULL_FACE); glFrontFace(GL_CW); glCullFace(GL_BACK); glPushMatrix(); glScalef(_bottomRadius, _height, _bottomRadius); //test the attributes if (_side) { glInterleavedArrays(GL_N3F_V3F, 0, _coneArray->getConeSideVertexArrayAddress()); glDrawElements(GL_TRIANGLE_FAN, _coneArray->getConeSideSize(), GL_UNSIGNED_INT, _coneArray->getConeSideIndexArrayAddress()); } if (_bottom) { glInterleavedArrays(GL_N3F_V3F, 0, _coneArray->getConeBottomVertexArrayAddress()); glDrawElements(GL_TRIANGLE_FAN, _coneArray->getConeBottomSize(), GL_UNSIGNED_INT, _coneArray->getConeBottomIndexArrayAddress()); } glPopMatrix(); glDisable(GL_CULL_FACE); } } }