Showing the changes to interface/src/MetavoxelSystem.cpp (1 of 9 files). Show all
Unified · Split
| @@ -167,14 +167,14 @@ void MetavoxelSystem::maybeAttachClient(const SharedNodePointer& node) { · 166 unmodified lines | ||
| 167 | 167 | |
| 168 | 168 | MetavoxelSystem::SimulateVisitor::SimulateVisitor(QVector<Point>& points) : |
| 169 | 169 | SpannerVisitor(QVector<AttributePointer>() << AttributeRegistry::getInstance()->getSpannersAttribute(), |
| 170 | − QVector<AttributePointer>() << AttributeRegistry::getInstance()->getColorAttribute() << | |
| 170 | + QVector<AttributePointer>(), QVector<AttributePointer>() << AttributeRegistry::getInstance()->getColorAttribute() << | |
| 171 | 171 | AttributeRegistry::getInstance()->getNormalAttribute() << |
| 172 | 172 | AttributeRegistry::getInstance()->getSpannerColorAttribute() << |
| 173 | 173 | AttributeRegistry::getInstance()->getSpannerNormalAttribute()), |
| 174 | 174 | _points(points) { |
| 175 | 175 | } |
| 176 | 176 | |
| 177 | −bool MetavoxelSystem::SimulateVisitor::visit(Spanner* spanner) { | |
| 177 | +bool MetavoxelSystem::SimulateVisitor::visit(Spanner* spanner, const glm::vec3& clipMinimum, float clipSize) { | |
| 178 | 178 | spanner->getRenderer()->simulate(_deltaTime); |
| 179 | 179 | return true; |
| 180 | 180 | } |
| @@ -223,11 +223,12 @@ int MetavoxelSystem::SimulateVisitor::visit(MetavoxelInfo& info) { · 42 unmodified lines | ||
| 223 | 223 | } |
| 224 | 224 | |
| 225 | 225 | MetavoxelSystem::RenderVisitor::RenderVisitor() : |
| 226 | − SpannerVisitor(QVector<AttributePointer>() << AttributeRegistry::getInstance()->getSpannersAttribute()) { | |
| 226 | + SpannerVisitor(QVector<AttributePointer>() << AttributeRegistry::getInstance()->getSpannersAttribute(), | |
| 227 | + QVector<AttributePointer>() << AttributeRegistry::getInstance()->getSpannerMaskAttribute()) { | |
| 227 | 228 | } |
| 228 | 229 | |
| 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); | |
| 231 | 232 | return true; |
| 232 | 233 | } |
| 233 | 234 | |
| @@ -333,10 +334,55 @@ void MetavoxelClient::handleMessage(const QVariant& message, Bitstream& in) { · 99 unmodified lines | ||
| 333 | 334 | } |
| 334 | 335 | } |
| 335 | 336 | |
| 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 | + | |
| 336 | 365 | SphereRenderer::SphereRenderer() { |
| 337 | 366 | } |
| 338 | 367 | |
| 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) { | |
| 340 | 386 | Sphere* sphere = static_cast<Sphere*>(parent()); |
| 341 | 387 | const QColor& color = sphere->getColor(); |
| 342 | 388 | glColor4f(color.redF(), color.greenF(), color.blueF(), color.alphaF() * alpha); |
| @@ -384,11 +430,12 @@ void StaticModelRenderer::simulate(float deltaTime) { · 41 unmodified lines | ||
| 384 | 430 | _model->simulate(deltaTime); |
| 385 | 431 | } |
| 386 | 432 | |
| 387 | −void StaticModelRenderer::render(float alpha) { | |
| 433 | +void StaticModelRenderer::renderUnclipped(float alpha) { | |
| 388 | 434 | _model->render(alpha); |
| 389 | 435 | } |
| 390 | 436 | |
| 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 { | |
| 392 | 439 | return _model->findRayIntersection(origin, direction, distance); |
| 393 | 440 | } |
| 394 | 441 | |