History

Working on spanner metavoxel edits.

Andrzej Kapolka committed 12 years ago

Commit 42e95f21 parent 1ca212f8 files · +330 −344Browse files

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

Unified · Split

interface/src/MetavoxelSystem.cpp+38−16
@@ -33,6 +33,7 @@ · 32 unmodified lines
3333
3434 REGISTER_META_OBJECT(DefaultMetavoxelRendererImplementation)
3535 REGISTER_META_OBJECT(SphereRenderer)
36+REGISTER_META_OBJECT(CuboidRenderer)
3637 REGISTER_META_OBJECT(StaticModelRenderer)
3738
3839 static int bufferPointVectorMetaTypeId = qRegisterMetaType<BufferPointVector>();
@@ -2116,7 +2117,8 @@ int SpannerRenderVisitor::visit(MetavoxelInfo& info) { · 2077 unmodified lines
21162117 }
21172118
21182119 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);
21202122 return true;
21212123 }
21222124
@@ -2282,9 +2284,9 @@ static void enableClipPlane(GLenum plane, float x, float y, float z, float w) { · 159 unmodified lines
22822284 glEnable(plane);
22832285 }
22842286
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) {
22862288 if (clipSize == 0.0f) {
2287− renderUnclipped(alpha, mode);
2289+ renderUnclipped(color, mode);
22882290 return;
22892291 }
22902292 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
22942296 enableClipPlane(GL_CLIP_PLANE4, 0.0f, 0.0f, -1.0f, clipMinimum.z + clipSize);
22952297 enableClipPlane(GL_CLIP_PLANE5, 0.0f, 0.0f, 1.0f, -clipMinimum.z);
22962298
2297− renderUnclipped(alpha, mode);
2299+ renderUnclipped(color, mode);
22982300
22992301 glDisable(GL_CLIP_PLANE0);
23002302 glDisable(GL_CLIP_PLANE1);
@@ -2307,9 +2309,9 @@ void ClippedRenderer::render(float alpha, Mode mode, const glm::vec3& clipMinimu · 6 unmodified lines
23072309 SphereRenderer::SphereRenderer() {
23082310 }
23092311
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) {
23112313 if (clipSize == 0.0f) {
2312− renderUnclipped(alpha, mode);
2314+ renderUnclipped(color, mode);
23132315 return;
23142316 }
23152317 // 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
23182320 for (int i = 0; i < Box::VERTEX_COUNT; i++) {
23192321 const float CLIP_PROPORTION = 0.95f;
23202322 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);
23222324 return;
23232325 }
23242326 }
23252327 }
23262328
2327−void SphereRenderer::renderUnclipped(float alpha, Mode mode) {
2329+void SphereRenderer::renderUnclipped(const glm::vec4& color, Mode mode) {
23282330 Sphere* sphere = static_cast<Sphere*>(_spanner);
2329− const QColor& color = sphere->getColor();
2330− glColor4f(color.redF(), color.greenF(), color.blueF(), color.alphaF() * alpha);
2331+ const QColor& ownColor = sphere->getColor();
2332+ glColor4f(ownColor.redF() * color.r, ownColor.greenF() * color.g, ownColor.blueF() * color.b, ownColor.alphaF() * color.a);
23312333
23322334 glPushMatrix();
23332335 const glm::vec3& translation = sphere->getTranslation();
23342336 glTranslatef(translation.x, translation.y, translation.z);
23352337 glm::quat rotation = sphere->getRotation();
23362338 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);
23382340
23392341 glutSolidSphere(sphere->getScale(), 10, 10);
23402342
23412343 glPopMatrix();
23422344 }
23432345
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+
23442366 StaticModelRenderer::StaticModelRenderer() :
23452367 _model(new Model(this)) {
23462368 }
@@ -2374,21 +2396,21 @@ void StaticModelRenderer::simulate(float deltaTime) { · 27 unmodified lines
23742396 _model->simulate(deltaTime);
23752397 }
23762398
2377−void StaticModelRenderer::renderUnclipped(float alpha, Mode mode) {
2399+void StaticModelRenderer::renderUnclipped(const glm::vec4& color, Mode mode) {
23782400 switch (mode) {
23792401 case DIFFUSE_MODE:
2380− _model->render(alpha, Model::DIFFUSE_RENDER_MODE);
2402+ _model->render(color.a, Model::DIFFUSE_RENDER_MODE);
23812403 break;
23822404
23832405 case NORMAL_MODE:
2384− _model->render(alpha, Model::NORMAL_RENDER_MODE);
2406+ _model->render(color.a, Model::NORMAL_RENDER_MODE);
23852407 break;
23862408
23872409 default:
2388− _model->render(alpha);
2410+ _model->render(color.a);
23892411 break;
23902412 }
2391− _model->render(alpha);
2413+ _model->render(color.a);
23922414 }
23932415
23942416 bool StaticModelRenderer::findRayIntersection(const glm::vec3& origin, const glm::vec3& direction,