From 88e2e3dd3fdbbd841e1cb3e85edba323deae31a1 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Tue, 6 Aug 2013 12:05:43 -0700 Subject: [PATCH] added visulization for voxel add/kill --- interface/src/Application.cpp | 31 ++++++++++++++ interface/src/Application.h | 3 ++ interface/src/VoxelFade.cpp | 59 +++++++++++++++++++++++++++ interface/src/VoxelFade.h | 43 +++++++++++++++++++ libraries/shared/src/OctalCode.h | 2 +- libraries/voxels/src/VoxelConstants.h | 1 + 6 files changed, 138 insertions(+), 1 deletion(-) create mode 100644 interface/src/VoxelFade.cpp create mode 100644 interface/src/VoxelFade.h diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index c00f514e05..d6d28726f7 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -3069,6 +3069,19 @@ void Application::displaySide(Camera& whichCamera) { // brad's frustum for debugging if (_frustumOn->isChecked()) renderViewFrustum(_viewFrustum); + + // render voxel fades if they exist + if (_voxelFades.size() > 0) { + for(std::vector::iterator fade = _voxelFades.begin(); fade != _voxelFades.end();) { + fade->render(); + if(fade->isDone()) { + fade = _voxelFades.erase(fade); + } else { + ++fade; + } + } + } + } void Application::displayOverlay() { @@ -3839,6 +3852,15 @@ void Application::nodeKilled(Node* node) { printf("voxel server going away...... v[%f, %f, %f, %f]\n", jurisditionDetails.x, jurisditionDetails.y, jurisditionDetails.z, jurisditionDetails.s); + + // Add the jurisditionDetails object to the list of "fade outs" + const float NODE_KILLED_RED = 1.0f; + const float NODE_KILLED_GREEN = 0.0f; + const float NODE_KILLED_BLUE = 0.0f; + + VoxelFade fade(VoxelFade::FADE_OUT, NODE_KILLED_RED, NODE_KILLED_GREEN, NODE_KILLED_BLUE); + fade.voxelDetails = jurisditionDetails; + _voxelFades.push_back(fade); } } } @@ -3860,6 +3882,15 @@ int Application::parseVoxelStats(unsigned char* messageData, ssize_t messageLeng if (_voxelServerJurisdictions.find(nodeID) == _voxelServerJurisdictions.end()) { printf("stats from new voxel server... v[%f, %f, %f, %f]\n", jurisditionDetails.x, jurisditionDetails.y, jurisditionDetails.z, jurisditionDetails.s); + + // Add the jurisditionDetails object to the list of "fade outs" + const float NODE_ADDED_RED = 0.0f; + const float NODE_ADDED_GREEN = 1.0f; + const float NODE_ADDED_BLUE = 0.0f; + + VoxelFade fade(VoxelFade::FADE_OUT, NODE_ADDED_RED, NODE_ADDED_GREEN, NODE_ADDED_BLUE); + fade.voxelDetails = jurisditionDetails; + _voxelFades.push_back(fade); } // store jurisdiction details for later use _voxelServerJurisdictions[nodeID] = jurisditionDetails; diff --git a/interface/src/Application.h b/interface/src/Application.h index 52299fac98..c4ae390797 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -37,6 +37,7 @@ #include "Swatch.h" #include "ToolsPalette.h" #include "ViewFrustum.h" +#include "VoxelFade.h" #include "VoxelSystem.h" #include "Webcam.h" #include "PieMenu.h" @@ -452,6 +453,8 @@ private: int parseVoxelStats(unsigned char* messageData, ssize_t messageLength, sockaddr senderAddress); std::map _voxelServerJurisdictions; + + std::vector _voxelFades; }; #endif /* defined(__interface__Application__) */ diff --git a/interface/src/VoxelFade.cpp b/interface/src/VoxelFade.cpp new file mode 100644 index 0000000000..9c102ba6c5 --- /dev/null +++ b/interface/src/VoxelFade.cpp @@ -0,0 +1,59 @@ +// +// VoxelFade.cpp +// interface +// +// Created by Brad Hefta-Gaub on 8/6/13. +// Copyright (c) 2013 High Fidelity, Inc. All rights reserved. +// + +#include // Header File For The OpenGL32 Library +#include + +#include + +#include "VoxelFade.h" + +const float VoxelFade::FADE_OUT_START = 0.5f; +const float VoxelFade::FADE_OUT_END = 0.0f; +const float VoxelFade::FADE_OUT_STEP = -0.005f; +const float VoxelFade::FADE_IN_START = 0.0f; +const float VoxelFade::FADE_IN_END = 0.5f; +const float VoxelFade::FADE_IN_STEP = 0.005f; +const float VoxelFade::DEFAULT_RED = 0.5f; +const float VoxelFade::DEFAULT_GREEN = 0.5f; +const float VoxelFade::DEFAULT_BLUE = 0.5f; + +VoxelFade::VoxelFade(FadeDirection direction, float red, float green, float blue) : + direction(direction), + red(red), + green(green), + blue(blue) +{ + opacity = (direction == FADE_OUT) ? FADE_OUT_START : FADE_IN_START; +} + +void VoxelFade::render() { + glDisable(GL_LIGHTING); + glPushMatrix(); + glScalef(TREE_SCALE, TREE_SCALE, TREE_SCALE); + glColor4f(red, green, blue, opacity); + glTranslatef(voxelDetails.x + voxelDetails.s * 0.5f, + voxelDetails.y + voxelDetails.s * 0.5f, + voxelDetails.z + voxelDetails.s * 0.5f); + glLineWidth(1.0f); + glutSolidCube(voxelDetails.s); + glLineWidth(1.0f); + glPopMatrix(); + glEnable(GL_LIGHTING); + + opacity += (direction == FADE_OUT) ? FADE_OUT_STEP : FADE_IN_STEP; +} + +bool VoxelFade::isDone() const { + if (direction == FADE_OUT) { + return opacity <= FADE_OUT_END; + } else { + return opacity >= FADE_IN_END; + } + return true; // unexpected case, assume we're done +} \ No newline at end of file diff --git a/interface/src/VoxelFade.h b/interface/src/VoxelFade.h new file mode 100644 index 0000000000..fd7a73135b --- /dev/null +++ b/interface/src/VoxelFade.h @@ -0,0 +1,43 @@ +// +// VoxelFade.h +// interface +// +// Created by Brad Hefta-Gaub on 8/6/13. +// Copyright (c) 2013 High Fidelity, Inc. All rights reserved. +// + +#ifndef __interface__VoxelFade__ +#define __interface__VoxelFade__ + +#include // for VoxelPositionSize + +class VoxelFade { +public: + + enum FadeDirection { FADE_OUT, FADE_IN}; + static const float FADE_OUT_START; + static const float FADE_OUT_END; + static const float FADE_OUT_STEP; + static const float FADE_IN_START; + static const float FADE_IN_END; + static const float FADE_IN_STEP; + static const float DEFAULT_RED; + static const float DEFAULT_GREEN; + static const float DEFAULT_BLUE; + + VoxelPositionSize voxelDetails; + FadeDirection direction; + float opacity; + + float red; + float green; + float blue; + + VoxelFade(FadeDirection direction = FADE_OUT, float red = DEFAULT_RED, + float green = DEFAULT_GREEN, float blue = DEFAULT_BLUE); + + void render(); + bool isDone() const; +}; + +#endif // __interface__VoxelFade__ diff --git a/libraries/shared/src/OctalCode.h b/libraries/shared/src/OctalCode.h index 297be6a137..405b85164d 100644 --- a/libraries/shared/src/OctalCode.h +++ b/libraries/shared/src/OctalCode.h @@ -37,7 +37,7 @@ float * firstVertexForCode(unsigned char * octalCode); void copyFirstVertexForCode(unsigned char * octalCode, float* output); struct VoxelPositionSize { - float x,y,z,s; + float x, y, z, s; }; void voxelDetailsForCode(unsigned char * octalCode, VoxelPositionSize& voxelPositionSize); diff --git a/libraries/voxels/src/VoxelConstants.h b/libraries/voxels/src/VoxelConstants.h index 4b971e9515..5a5815b6b3 100644 --- a/libraries/voxels/src/VoxelConstants.h +++ b/libraries/voxels/src/VoxelConstants.h @@ -14,6 +14,7 @@ #include #include +#include // this is where the coordinate system is represented const glm::vec3 IDENTITY_RIGHT = glm::vec3( 1.0f, 0.0f, 0.0f);