History

Various fixes and what-not, got the basic spanner clipping working.

Andrzej Kapolka committed 12 years ago

Commit 005ae791 parent 10588cf9 files · +363 −65Browse files

Showing the changes to interface/src/MetavoxelSystem.cpp (1 of 9 files). Show all

Unified · Split

interface/src/MetavoxelSystem.cpp+55−8
@@ -167,14 +167,14 @@ void MetavoxelSystem::maybeAttachClient(const SharedNodePointer& node) { · 166 unmodified lines
167167
168168 MetavoxelSystem::SimulateVisitor::SimulateVisitor(QVector<Point>& points) :
169169 SpannerVisitor(QVector<AttributePointer>() << AttributeRegistry::getInstance()->getSpannersAttribute(),
170− QVector<AttributePointer>() << AttributeRegistry::getInstance()->getColorAttribute() <<
170+ QVector<AttributePointer>(), QVector<AttributePointer>() << AttributeRegistry::getInstance()->getColorAttribute() <<
171171 AttributeRegistry::getInstance()->getNormalAttribute() <<
172172 AttributeRegistry::getInstance()->getSpannerColorAttribute() <<
173173 AttributeRegistry::getInstance()->getSpannerNormalAttribute()),
174174 _points(points) {
175175 }
176176
177−bool MetavoxelSystem::SimulateVisitor::visit(Spanner* spanner) {
177+bool MetavoxelSystem::SimulateVisitor::visit(Spanner* spanner, const glm::vec3& clipMinimum, float clipSize) {
178178 spanner->getRenderer()->simulate(_deltaTime);
179179 return true;
180180 }
@@ -223,11 +223,12 @@ int MetavoxelSystem::SimulateVisitor::visit(MetavoxelInfo& info) { · 42 unmodified lines
223223 }
224224
225225 MetavoxelSystem::RenderVisitor::RenderVisitor() :
226− SpannerVisitor(QVector<AttributePointer>() << AttributeRegistry::getInstance()->getSpannersAttribute()) {
226+ SpannerVisitor(QVector<AttributePointer>() << AttributeRegistry::getInstance()->getSpannersAttribute(),
227+ QVector<AttributePointer>() << AttributeRegistry::getInstance()->getSpannerMaskAttribute()) {
227228 }
228229
229−bool MetavoxelSystem::RenderVisitor::visit(Spanner* spanner) {
230− spanner->getRenderer()->render(1.0f);
230+bool MetavoxelSystem::RenderVisitor::visit(Spanner* spanner, const glm::vec3& clipMinimum, float clipSize) {
231+ spanner->getRenderer()->render(1.0f, clipMinimum, clipSize);
231232 return true;
232233 }
233234
@@ -333,10 +334,55 @@ void MetavoxelClient::handleMessage(const QVariant& message, Bitstream& in) { · 99 unmodified lines
333334 }
334335 }
335336
337+static void enableClipPlane(GLenum plane, float x, float y, float z, float w) {
338+ GLdouble coefficients[] = { x, y, z, w };
339+ glClipPlane(plane, coefficients);
340+ glEnable(plane);
341+}
342+
343+void ClippedRenderer::render(float alpha, const glm::vec3& clipMinimum, float clipSize) {
344+ if (clipSize == 0.0f) {
345+ renderUnclipped(alpha);
346+ return;
347+ }
348+ enableClipPlane(GL_CLIP_PLANE0, -1.0f, 0.0f, 0.0f, clipMinimum.x + clipSize);
349+ enableClipPlane(GL_CLIP_PLANE1, 1.0f, 0.0f, 0.0f, -clipMinimum.x);
350+ enableClipPlane(GL_CLIP_PLANE2, 0.0f, -1.0f, 0.0f, clipMinimum.y + clipSize);
351+ enableClipPlane(GL_CLIP_PLANE3, 0.0f, 1.0f, 0.0f, -clipMinimum.y);
352+ enableClipPlane(GL_CLIP_PLANE4, 0.0f, 0.0f, -1.0f, clipMinimum.z + clipSize);
353+ enableClipPlane(GL_CLIP_PLANE5, 0.0f, 0.0f, 1.0f, -clipMinimum.z);
354+
355+ renderUnclipped(alpha);
356+
357+ glDisable(GL_CLIP_PLANE0);
358+ glDisable(GL_CLIP_PLANE1);
359+ glDisable(GL_CLIP_PLANE2);
360+ glDisable(GL_CLIP_PLANE3);
361+ glDisable(GL_CLIP_PLANE4);
362+ glDisable(GL_CLIP_PLANE5);
363+}
364+
336365 SphereRenderer::SphereRenderer() {
337366 }
338367
339−void SphereRenderer::render(float alpha) {
368+void SphereRenderer::render(float alpha, const glm::vec3& clipMinimum, float clipSize) {
369+ if (clipSize == 0.0f) {
370+ renderUnclipped(alpha);
371+ return;
372+ }
373+ // slight performance optimization: don't render if clip bounds are entirely within sphere
374+ Sphere* sphere = static_cast<Sphere*>(parent());
375+ Box clipBox(clipMinimum, clipMinimum + glm::vec3(clipSize, clipSize, clipSize));
376+ for (int i = 0; i < Box::VERTEX_COUNT; i++) {
377+ const float CLIP_PROPORTION = 0.95f;
378+ if (glm::distance(sphere->getTranslation(), clipBox.getVertex(i)) >= sphere->getScale() * CLIP_PROPORTION) {
379+ ClippedRenderer::render(alpha, clipMinimum, clipSize);
380+ return;
381+ }
382+ }
383+}
384+
385+void SphereRenderer::renderUnclipped(float alpha) {
340386 Sphere* sphere = static_cast<Sphere*>(parent());
341387 const QColor& color = sphere->getColor();
342388 glColor4f(color.redF(), color.greenF(), color.blueF(), color.alphaF() * alpha);
@@ -384,11 +430,12 @@ void StaticModelRenderer::simulate(float deltaTime) { · 41 unmodified lines
384430 _model->simulate(deltaTime);
385431 }
386432
387−void StaticModelRenderer::render(float alpha) {
433+void StaticModelRenderer::renderUnclipped(float alpha) {
388434 _model->render(alpha);
389435 }
390436
391−bool StaticModelRenderer::findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, float& distance) const {
437+bool StaticModelRenderer::findRayIntersection(const glm::vec3& origin, const glm::vec3& direction,
438+ const glm::vec3& clipMinimum, float clipSize, float& distance) const {
392439 return _model->findRayIntersection(origin, direction, distance);
393440 }
394441