#include "GL_Box.h" #include "X3D_Box.h" #include "BoxDrawArray.h" namespace X3DTK { namespace GL { Box::Box() : X3DGeometryNode(), _size(SFVec3f(0.0f, 0.0f, 0.0f)), _boxArray(0) { define(Recorder::getTypeName("Box", "Geometry3D")); define(Recorder::getAttribute("size", &Box::_size, SFVec3f(0.0f, 0.0f, 0.0f))); } Box::~Box() { _boxArray->removeInstance(); } void Box::setSize(const SFVec3f &size) { _size = size; } void Box::setBoxArray(BoxDrawArray *boxArray) { _boxArray = boxArray; } void Box::update() { if (x3dReference == 0) return; X3D::Box *B = static_cast(x3dReference); _size = B->getSize(); _boxArray = BoxDrawArray::getInstance(); } void Box::draw() const { glEnable(GL_CULL_FACE); glFrontFace(GL_CW); glCullFace(GL_BACK); glPushMatrix(); glScalef(_size.x, _size.y, _size.z); glInterleavedArrays(GL_N3F_V3F, 0, _boxArray->getBoxVertexArrayAddress()); glDrawElements(GL_TRIANGLES, _boxArray->getBoxSize(), GL_UNSIGNED_INT, _boxArray->getBoxIndexArrayAddress()); glPopMatrix(); glDisable(GL_CULL_FACE); } } }