Showing the changes to interface/src/MetavoxelSystem.cpp (1 of 8 files). Show all
Unified · Split
| @@ -33,6 +33,7 @@ · 32 unmodified lines | |||
| 33 | 33 | ||
| 34 | REGISTER_META_OBJECT(DefaultMetavoxelRendererImplementation) | 34 | REGISTER_META_OBJECT(DefaultMetavoxelRendererImplementation) |
| 35 | REGISTER_META_OBJECT(SphereRenderer) | 35 | REGISTER_META_OBJECT(SphereRenderer) |
| 36 | REGISTER_META_OBJECT(CuboidRenderer) | ||
| 36 | REGISTER_META_OBJECT(StaticModelRenderer) | 37 | REGISTER_META_OBJECT(StaticModelRenderer) |
| 37 | 38 | ||
| 38 | static int bufferPointVectorMetaTypeId = qRegisterMetaType<BufferPointVector>(); | 39 | static int bufferPointVectorMetaTypeId = qRegisterMetaType<BufferPointVector>(); |
| @@ -2116,7 +2117,8 @@ int SpannerRenderVisitor::visit(MetavoxelInfo& info) { · 2077 unmodified lines | |||
| 2116 | } | 2117 | } |
| 2117 | 2118 | ||
| 2118 | bool SpannerRenderVisitor::visit(Spanner* spanner, const glm::vec3& clipMinimum, float clipSize) { | 2119 | bool SpannerRenderVisitor::visit(Spanner* spanner, const glm::vec3& clipMinimum, float clipSize) { |
| 2119 | spanner->getRenderer()->render(1.0f, SpannerRenderer::DEFAULT_MODE, clipMinimum, clipSize); | 2120 | const glm::vec4 OPAQUE_WHITE(1.0f, 1.0f, 1.0f, 1.0f); |
| 2121 | spanner->getRenderer()->render(OPAQUE_WHITE, SpannerRenderer::DEFAULT_MODE, clipMinimum, clipSize); | ||
| 2120 | return true; | 2122 | return true; |
| 2121 | } | 2123 | } |
| 2122 | 2124 | ||
| @@ -2282,9 +2284,9 @@ static void enableClipPlane(GLenum plane, float x, float y, float z, float w) { · 159 unmodified lines | |||
| 2282 | glEnable(plane); | 2284 | glEnable(plane); |
| 2283 | } | 2285 | } |
| 2284 | 2286 | ||
| 2285 | void ClippedRenderer::render(float alpha, Mode mode, const glm::vec3& clipMinimum, float clipSize) { | 2287 | void ClippedRenderer::render(const glm::vec4& color, Mode mode, const glm::vec3& clipMinimum, float clipSize) { |
| 2286 | if (clipSize == 0.0f) { | 2288 | if (clipSize == 0.0f) { |
| 2287 | renderUnclipped(alpha, mode); | 2289 | renderUnclipped(color, mode); |
| 2288 | return; | 2290 | return; |
| 2289 | } | 2291 | } |
| 2290 | enableClipPlane(GL_CLIP_PLANE0, -1.0f, 0.0f, 0.0f, clipMinimum.x + clipSize); | 2292 | enableClipPlane(GL_CLIP_PLANE0, -1.0f, 0.0f, 0.0f, clipMinimum.x + clipSize); |
| @@ -2294,7 +2296,7 @@ void ClippedRenderer::render(float alpha, Mode mode, const glm::vec3& clipMinimu · 3 unmodified lines | |||
| 2294 | enableClipPlane(GL_CLIP_PLANE4, 0.0f, 0.0f, -1.0f, clipMinimum.z + clipSize); | 2296 | enableClipPlane(GL_CLIP_PLANE4, 0.0f, 0.0f, -1.0f, clipMinimum.z + clipSize); |
| 2295 | enableClipPlane(GL_CLIP_PLANE5, 0.0f, 0.0f, 1.0f, -clipMinimum.z); | 2297 | enableClipPlane(GL_CLIP_PLANE5, 0.0f, 0.0f, 1.0f, -clipMinimum.z); |
| 2296 | 2298 | ||
| 2297 | renderUnclipped(alpha, mode); | 2299 | renderUnclipped(color, mode); |
| 2298 | 2300 | ||
| 2299 | glDisable(GL_CLIP_PLANE0); | 2301 | glDisable(GL_CLIP_PLANE0); |
| 2300 | glDisable(GL_CLIP_PLANE1); | 2302 | glDisable(GL_CLIP_PLANE1); |
| @@ -2307,9 +2309,9 @@ void ClippedRenderer::render(float alpha, Mode mode, const glm::vec3& clipMinimu · 6 unmodified lines | |||
| 2307 | SphereRenderer::SphereRenderer() { | 2309 | SphereRenderer::SphereRenderer() { |
| 2308 | } | 2310 | } |
| 2309 | 2311 | ||
| 2310 | void SphereRenderer::render(float alpha, Mode mode, const glm::vec3& clipMinimum, float clipSize) { | 2312 | void SphereRenderer::render(const glm::vec4& color, Mode mode, const glm::vec3& clipMinimum, float clipSize) { |
| 2311 | if (clipSize == 0.0f) { | 2313 | if (clipSize == 0.0f) { |
| 2312 | renderUnclipped(alpha, mode); | 2314 | renderUnclipped(color, mode); |
| 2313 | return; | 2315 | return; |
| 2314 | } | 2316 | } |
| 2315 | // slight performance optimization: don't render if clip bounds are entirely within sphere | 2317 | // slight performance optimization: don't render if clip bounds are entirely within sphere |
| @@ -2318,29 +2320,49 @@ void SphereRenderer::render(float alpha, Mode mode, const glm::vec3& clipMinimum · 2 unmodified lines | |||
| 2318 | for (int i = 0; i < Box::VERTEX_COUNT; i++) { | 2320 | for (int i = 0; i < Box::VERTEX_COUNT; i++) { |
| 2319 | const float CLIP_PROPORTION = 0.95f; | 2321 | const float CLIP_PROPORTION = 0.95f; |
| 2320 | if (glm::distance(sphere->getTranslation(), clipBox.getVertex(i)) >= sphere->getScale() * CLIP_PROPORTION) { | 2322 | if (glm::distance(sphere->getTranslation(), clipBox.getVertex(i)) >= sphere->getScale() * CLIP_PROPORTION) { |
| 2321 | ClippedRenderer::render(alpha, mode, clipMinimum, clipSize); | 2323 | ClippedRenderer::render(color, mode, clipMinimum, clipSize); |
| 2322 | return; | 2324 | return; |
| 2323 | } | 2325 | } |
| 2324 | } | 2326 | } |
| 2325 | } | 2327 | } |
| 2326 | 2328 | ||
| 2327 | void SphereRenderer::renderUnclipped(float alpha, Mode mode) { | 2329 | void SphereRenderer::renderUnclipped(const glm::vec4& color, Mode mode) { |
| 2328 | Sphere* sphere = static_cast<Sphere*>(_spanner); | 2330 | Sphere* sphere = static_cast<Sphere*>(_spanner); |
| 2329 | const QColor& color = sphere->getColor(); | 2331 | const QColor& ownColor = sphere->getColor(); |
| 2330 | glColor4f(color.redF(), color.greenF(), color.blueF(), color.alphaF() * alpha); | 2332 | glColor4f(ownColor.redF() * color.r, ownColor.greenF() * color.g, ownColor.blueF() * color.b, ownColor.alphaF() * color.a); |
| 2331 | 2333 | ||
| 2332 | glPushMatrix(); | 2334 | glPushMatrix(); |
| 2333 | const glm::vec3& translation = sphere->getTranslation(); | 2335 | const glm::vec3& translation = sphere->getTranslation(); |
| 2334 | glTranslatef(translation.x, translation.y, translation.z); | 2336 | glTranslatef(translation.x, translation.y, translation.z); |
| 2335 | glm::quat rotation = sphere->getRotation(); | 2337 | glm::quat rotation = sphere->getRotation(); |
| 2336 | glm::vec3 axis = glm::axis(rotation); | 2338 | glm::vec3 axis = glm::axis(rotation); |
| 2337 | glRotatef(glm::angle(rotation), axis.x, axis.y, axis.z); | 2339 | glRotatef(glm::degrees(glm::angle(rotation)), axis.x, axis.y, axis.z); |
| 2338 | 2340 | ||
| 2339 | glutSolidSphere(sphere->getScale(), 10, 10); | 2341 | glutSolidSphere(sphere->getScale(), 10, 10); |
| 2340 | 2342 | ||
| 2341 | glPopMatrix(); | 2343 | glPopMatrix(); |
| 2342 | } | 2344 | } |
| 2343 | 2345 | ||
| 2346 | CuboidRenderer::CuboidRenderer() { | ||
| 2347 | } | ||
| 2348 | |||
| 2349 | void CuboidRenderer::renderUnclipped(const glm::vec4& color, Mode mode) { | ||
| 2350 | Cuboid* cuboid = static_cast<Cuboid*>(_spanner); | ||
| 2351 | const QColor& ownColor = cuboid->getColor(); | ||
| 2352 | glColor4f(ownColor.redF() * color.r, ownColor.greenF() * color.g, ownColor.blueF() * color.b, ownColor.alphaF() * color.a); | ||
| 2353 | |||
| 2354 | glPushMatrix(); | ||
| 2355 | const glm::vec3& translation = cuboid->getTranslation(); | ||
| 2356 | glTranslatef(translation.x, translation.y, translation.z); | ||
| 2357 | glm::quat rotation = cuboid->getRotation(); | ||
| 2358 | glm::vec3 axis = glm::axis(rotation); | ||
| 2359 | glRotatef(glm::degrees(glm::angle(rotation)), axis.x, axis.y, axis.z); | ||
| 2360 | |||
| 2361 | glutSolidCube(cuboid->getScale() * 2.0f); | ||
| 2362 | |||
| 2363 | glPopMatrix(); | ||
| 2364 | } | ||
| 2365 | |||
| 2344 | StaticModelRenderer::StaticModelRenderer() : | 2366 | StaticModelRenderer::StaticModelRenderer() : |
| 2345 | _model(new Model(this)) { | 2367 | _model(new Model(this)) { |
| 2346 | } | 2368 | } |
| @@ -2374,21 +2396,21 @@ void StaticModelRenderer::simulate(float deltaTime) { · 27 unmodified lines | |||
| 2374 | _model->simulate(deltaTime); | 2396 | _model->simulate(deltaTime); |
| 2375 | } | 2397 | } |
| 2376 | 2398 | ||
| 2377 | void StaticModelRenderer::renderUnclipped(float alpha, Mode mode) { | 2399 | void StaticModelRenderer::renderUnclipped(const glm::vec4& color, Mode mode) { |
| 2378 | switch (mode) { | 2400 | switch (mode) { |
| 2379 | case DIFFUSE_MODE: | 2401 | case DIFFUSE_MODE: |
| 2380 | _model->render(alpha, Model::DIFFUSE_RENDER_MODE); | 2402 | _model->render(color.a, Model::DIFFUSE_RENDER_MODE); |
| 2381 | break; | 2403 | break; |
| 2382 | 2404 | ||
| 2383 | case NORMAL_MODE: | 2405 | case NORMAL_MODE: |
| 2384 | _model->render(alpha, Model::NORMAL_RENDER_MODE); | 2406 | _model->render(color.a, Model::NORMAL_RENDER_MODE); |
| 2385 | break; | 2407 | break; |
| 2386 | 2408 | ||
| 2387 | default: | 2409 | default: |
| 2388 | _model->render(alpha); | 2410 | _model->render(color.a); |
| 2389 | break; | 2411 | break; |
| 2390 | } | 2412 | } |
| 2391 | _model->render(alpha); | 2413 | _model->render(color.a); |
| 2392 | } | 2414 | } |
| 2393 | 2415 | ||
| 2394 | bool StaticModelRenderer::findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, | 2416 | bool StaticModelRenderer::findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, |