#include "GL_Sphere.h" #include "X3D_Sphere.h" #include "SphereDrawArray.h" namespace X3DTK { namespace GL { Sphere::Sphere() : X3DGeometryNode(), _sphereArray(0) { define(Recorder::getTypeName("Sphere", "Geometry3D")); define(Recorder::getAttribute("radius", &Sphere::_radius, 0.0f)); } Sphere::~Sphere() { _sphereArray->removeInstance(); } void Sphere::setRadius(const SFFloat &radius) { _radius = radius; } void Sphere::setSphereDrawArray(SphereDrawArray *sphereArray) { _sphereArray = sphereArray; } void Sphere::update() { if (x3dReference == 0) return; X3D::Sphere *S = static_cast(x3dReference); _radius = S->getRadius(); _sphereArray = SphereDrawArray::getInstanceOfSection(64); } void Sphere::draw() const { glEnable(GL_CULL_FACE); glFrontFace(GL_CW); glCullFace(GL_BACK); glPushMatrix(); glScalef(_radius, _radius, _radius); glInterleavedArrays(GL_N3F_V3F, 0, _sphereArray->getSphereVertexArrayAddress()); glDrawElements(GL_TRIANGLES, _sphereArray->getSphereSize(), GL_UNSIGNED_INT, _sphereArray->getSphereIndexArrayAddress()); glPopMatrix(); glDisable(GL_CULL_FACE); } } }