#include "GL_PointSet.h" #include "X3D_PointSet.h" #include "X3D_Coordinate.h" #include "X3D_Color.h" #include "X3D_ColorRGBA.h" #include using namespace std; namespace X3DTK { namespace GL { PointSet::PointSet() : X3DGeometryNode(), _color(false) { define(Recorder::getTypeName("PointSet", "Rendering")); } PointSet::~PointSet() { } void PointSet::setColor(const SFBool &color) { _color = color; } void PointSet::setC4UB_V3F_vertexArray(const std::vector &C4UB_V3F_vertexArray) { _C4UB_V3F_vertexArray = C4UB_V3F_vertexArray; } void PointSet::setV3F_vertexArray(const MFVec3f &V3F_vertexArray) { _V3F_vertexArray = V3F_vertexArray; } void PointSet::update() { if (x3dReference == 0) return; X3D::PointSet *P = static_cast(x3dReference); // emptying the arrays _V3F_vertexArray.clear(); _C4UB_V3F_vertexArray.clear(); X3D::Coordinate *CoordNode = static_cast(P->getCoord()); if (CoordNode == 0) return; const MFVec3f &pointArray = CoordNode->getPoint(); if (P->getColor() != 0) { _color = true; MFColorRGBA colorRGBA; if (P->getColor()->getTypeName() == "ColorRGBA") colorRGBA = dynamic_cast(P->getColor())->getColor(); else colorRGBA = dynamic_cast(P->getColor())->getColor(); MFVec3f::const_iterator itPoint = pointArray.begin(); MFColorRGBA::const_iterator itColor = colorRGBA.begin(); while (itPoint != pointArray.end()) { C4UB_V3F element; SFColorRGBA currentColor = *itColor; element.r = (unsigned char)floorf(255.0f*currentColor.r); element.g = (unsigned char)floorf(255.0f*currentColor.g); element.b = (unsigned char)floorf(255.0f*currentColor.b); element.a = (unsigned char)floorf(255.0f*currentColor.a); element.vertex = *itPoint; _C4UB_V3F_vertexArray.push_back(element); ++itPoint; ++itColor; } } else { _V3F_vertexArray = pointArray; } } void PointSet::draw() const { glDisable(GL_LIGHTING); glPointSize(4.0f); if (getColor()) { glEnable(GL_COLOR_MATERIAL); glInterleavedArrays(GL_C4UB_V3F, 0, &_C4UB_V3F_vertexArray.front()); glDrawArrays(GL_POINTS, 0, _C4UB_V3F_vertexArray.size()); glDisable(GL_COLOR_MATERIAL); } else { //drawing the point set glInterleavedArrays(GL_V3F, 0, &_V3F_vertexArray.front()); glDrawArrays(GL_POINTS, 0, _V3F_vertexArray.size()); } glEnable(GL_LIGHTING); } } }