From 505b2db9350044add489189afb1e70916d2b5420 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Fri, 12 Apr 2013 17:27:54 -0700 Subject: [PATCH 1/7] some spacing cleanup --- libraries/voxels/src/ViewFrustum.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/libraries/voxels/src/ViewFrustum.cpp b/libraries/voxels/src/ViewFrustum.cpp index 477e049e93..2d3899648d 100644 --- a/libraries/voxels/src/ViewFrustum.cpp +++ b/libraries/voxels/src/ViewFrustum.cpp @@ -28,16 +28,16 @@ void ViewFrustum::calculateViewFrustum(glm::vec3 position, glm::vec3 direction, glm::vec3 up, glm::vec3 right, float screenWidth, float screenHeight) { // Save the values we were passed... - this->_position=position; - this->_direction=direction; - this->_up=up; - this->_right=right; - this->_screenWidth=screenWidth; - this->_screenHeight=screenHeight; + this->_position = position; + this->_direction = direction; + this->_up = up; + this->_right = right; + this->_screenWidth = screenWidth; + this->_screenHeight = screenHeight; glm::vec3 front = direction; - float fovHalfAngle = 0.7854f*1.5; // 45 deg for half, so fov = 90 deg - float ratio = screenWidth/screenHeight; + float fovHalfAngle = 0.7854f * 1.5; // 45 deg and some hackery. Still trying to figure out our correct fov + float ratio = screenWidth / screenHeight; this->_nearDist = 0.1; this->_farDist = 10.0; From 093f489520f9024c5f6a88682f7c809021d6a8b8 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Sat, 13 Apr 2013 13:07:02 -0700 Subject: [PATCH 2/7] make menu columns render properly for menu items wider than 100 pixels --- interface/src/MenuColumn.cpp | 33 ++++++++++++++++++++++++--------- interface/src/MenuColumn.h | 1 + 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/interface/src/MenuColumn.cpp b/interface/src/MenuColumn.cpp index d3780b5710..8c8548ea05 100644 --- a/interface/src/MenuColumn.cpp +++ b/interface/src/MenuColumn.cpp @@ -41,7 +41,7 @@ void MenuColumn::mouseClickRow(int numberOfRowsIndex) { } bool MenuColumn::mouseClick(int x, int y, int leftPosition, int menuHeight, int lineHeight) { - int rightPosition = leftPosition + 200; + int rightPosition = leftPosition + 200; // XXXBHG - this looks like a hack? int topPosition = menuHeight; int bottomPosition = menuHeight; int columnWidth = 0; @@ -67,13 +67,14 @@ void MenuColumn::setMouseOver(int leftPosition, int rightPosition, int topPositi } bool MenuColumn::mouseOver(int x, int y, int leftPosition, int menuHeight, int lineHeight) { - int rightPosition = leftPosition + 100; + + int maxColumnWidth = this->getMaxRowWidth(); + + int rightPosition = leftPosition + maxColumnWidth; int topPosition = menuHeight; int bottomPosition = menuHeight; - int columnWidth = 0; bool overMenu = false; for (unsigned int i = 0; i < rows.size(); ++i) { - columnWidth = rows[i].getWidth(); topPosition = bottomPosition + lineHeight ; if (x > leftPosition && x < rightPosition && y > bottomPosition && y < topPosition) { setMouseOver(leftPosition, rightPosition, bottomPosition, topPosition); @@ -116,26 +117,40 @@ int MenuColumn::addRow(const char* rowName, MenuRowCallback callback) { return 0; } +int MenuColumn::getMaxRowWidth() { + float scale = 0.09; + int mono = 0; + int maxColumnWidth = 100 - (SPACE_BEFORE_ROW_NAME*2); // the minimum size we want + for (unsigned int i = 0; i < rows.size(); ++i) { + maxColumnWidth = std::max(maxColumnWidth,rows[i].getWidth(scale, mono, 0)); + } + + maxColumnWidth += SPACE_BEFORE_ROW_NAME*2; // space before and after!! + return maxColumnWidth; +} + void MenuColumn::render(int yOffset, int menuHeight, int lineHeight) { + float scale = 0.09; + int mono = 0; int numberOfRows = rows.size(); if (numberOfRows > 0) { + + int maxColumnWidth = this->getMaxRowWidth(); + glColor3f(0.9,0.9,0.9); glBegin(GL_QUADS); { glVertex2f(leftPosition, yOffset + menuHeight); - glVertex2f(leftPosition+100, yOffset + menuHeight); - glVertex2f(leftPosition+100, yOffset + menuHeight + numberOfRows*lineHeight); + glVertex2f(leftPosition+maxColumnWidth, yOffset + menuHeight); + glVertex2f(leftPosition+maxColumnWidth, yOffset + menuHeight + numberOfRows*lineHeight); glVertex2f(leftPosition , yOffset + menuHeight + numberOfRows* lineHeight); } glEnd(); } - float scale = 0.09; - int mono = 0; int y = menuHeight + lineHeight / 2 ; char* rowName; int columnWidth = 0; for (unsigned int i = 0; i < rows.size(); ++i) { rowName = rows[i].getName(); - columnWidth = rows[i].getWidth(scale, mono, 0); drawtext(leftPosition + SPACE_BEFORE_ROW_NAME, y+5 + yOffset, scale, 0, 1.0, mono, rowName, 0, 0, 0); y += lineHeight; } diff --git a/interface/src/MenuColumn.h b/interface/src/MenuColumn.h index 71c42eed7f..c712ac64a1 100644 --- a/interface/src/MenuColumn.h +++ b/interface/src/MenuColumn.h @@ -27,6 +27,7 @@ public: void render(int yOffset, int menuHeight, int lineHeight); void renderMouseOver(int yOffset); int addRow(const char* rowName, MenuRowCallback callback); + int getMaxRowWidth(); private: char columnName[MAX_COLUMN_NAME]; int columnWidth; From 4cb986b3f90ef7d3b05d2fdb11b7479cd3a4da63 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Sat, 13 Apr 2013 13:09:20 -0700 Subject: [PATCH 3/7] tweaks to ViewFrustum's default FOV, added comments --- libraries/voxels/src/ViewFrustum.cpp | 11 ++++++++++- libraries/voxels/src/ViewFrustum.h | 2 ++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/libraries/voxels/src/ViewFrustum.cpp b/libraries/voxels/src/ViewFrustum.cpp index 2d3899648d..d7e87d36b3 100644 --- a/libraries/voxels/src/ViewFrustum.cpp +++ b/libraries/voxels/src/ViewFrustum.cpp @@ -10,6 +10,8 @@ #include "ViewFrustum.h" +float ViewFrustum::fovAngleAdust=1.75; + ViewFrustum::ViewFrustum(glm::vec3 position, glm::vec3 direction, glm::vec3 up, glm::vec3 right, float screenWidth, float screenHeight) { this->calculateViewFrustum(position, direction, up, right, screenWidth, screenHeight); @@ -36,7 +38,14 @@ void ViewFrustum::calculateViewFrustum(glm::vec3 position, glm::vec3 direction, this->_screenHeight = screenHeight; glm::vec3 front = direction; - float fovHalfAngle = 0.7854f * 1.5; // 45 deg and some hackery. Still trying to figure out our correct fov + + // Calculating field of view. + // 0.7854f is 45 deg + // ViewFrustum::fovAngleAdust defaults to 1.75 + // Apparently our fov is around 1.75 times this value or 78.75 degrees + // you can adjust this in interface by using the "|" and "\" keys to tweak + // the adjustment and see effects of different FOVs + float fovHalfAngle = 0.7854f * ViewFrustum::fovAngleAdust; float ratio = screenWidth / screenHeight; this->_nearDist = 0.1; diff --git a/libraries/voxels/src/ViewFrustum.h b/libraries/voxels/src/ViewFrustum.h index 02c7c39bcc..9fb17ae339 100644 --- a/libraries/voxels/src/ViewFrustum.h +++ b/libraries/voxels/src/ViewFrustum.h @@ -61,6 +61,8 @@ public: glm::vec3 up, glm::vec3 right, float screenWidth, float screenHeight); void dump(); + + static float fovAngleAdust; }; From 27165be902537232adf3c3f94d4467de01f7e048 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Sat, 13 Apr 2013 13:19:48 -0700 Subject: [PATCH 4/7] tweak starting fov adjust to 1.65 which seems correct --- libraries/voxels/src/ViewFrustum.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libraries/voxels/src/ViewFrustum.cpp b/libraries/voxels/src/ViewFrustum.cpp index d7e87d36b3..73cce9baad 100644 --- a/libraries/voxels/src/ViewFrustum.cpp +++ b/libraries/voxels/src/ViewFrustum.cpp @@ -10,7 +10,7 @@ #include "ViewFrustum.h" -float ViewFrustum::fovAngleAdust=1.75; +float ViewFrustum::fovAngleAdust=1.65; ViewFrustum::ViewFrustum(glm::vec3 position, glm::vec3 direction, glm::vec3 up, glm::vec3 right, float screenWidth, float screenHeight) { @@ -41,8 +41,8 @@ void ViewFrustum::calculateViewFrustum(glm::vec3 position, glm::vec3 direction, // Calculating field of view. // 0.7854f is 45 deg - // ViewFrustum::fovAngleAdust defaults to 1.75 - // Apparently our fov is around 1.75 times this value or 78.75 degrees + // ViewFrustum::fovAngleAdust defaults to 1.65 + // Apparently our fov is around 1.75 times this value or 74.25 degrees // you can adjust this in interface by using the "|" and "\" keys to tweak // the adjustment and see effects of different FOVs float fovHalfAngle = 0.7854f * ViewFrustum::fovAngleAdust; From e921d068771fe03ea824e41052653e3277f78c22 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Sat, 13 Apr 2013 15:18:19 -0700 Subject: [PATCH 5/7] Added new feature to MenuRow to allow custom callback for State Note: there's some bug in the menu render code that doesn't like state strings that are longer than 4 characters + NULL. So, the current code will clip any state string that is longer than 4 characters. We need to look into this 5 character limit. It's a bug. --- interface/src/MenuColumn.cpp | 9 +++++- interface/src/MenuColumn.h | 1 + interface/src/MenuRow.cpp | 54 ++++++++++++++++++++++++++++-------- interface/src/MenuRow.h | 5 ++++ 4 files changed, 56 insertions(+), 13 deletions(-) diff --git a/interface/src/MenuColumn.cpp b/interface/src/MenuColumn.cpp index 8c8548ea05..94e8595c8b 100644 --- a/interface/src/MenuColumn.cpp +++ b/interface/src/MenuColumn.cpp @@ -117,6 +117,14 @@ int MenuColumn::addRow(const char* rowName, MenuRowCallback callback) { return 0; } +int MenuColumn::addRow(const char* rowName, MenuRowCallback callback, MenuStateNameCallback stateNameCallback) { + MenuRow* row; + row = new MenuRow(rowName, callback, stateNameCallback); + rows.push_back(*row); + delete row; + return 0; +} + int MenuColumn::getMaxRowWidth() { float scale = 0.09; int mono = 0; @@ -148,7 +156,6 @@ void MenuColumn::render(int yOffset, int menuHeight, int lineHeight) { } int y = menuHeight + lineHeight / 2 ; char* rowName; - int columnWidth = 0; for (unsigned int i = 0; i < rows.size(); ++i) { rowName = rows[i].getName(); drawtext(leftPosition + SPACE_BEFORE_ROW_NAME, y+5 + yOffset, scale, 0, 1.0, mono, rowName, 0, 0, 0); diff --git a/interface/src/MenuColumn.h b/interface/src/MenuColumn.h index c712ac64a1..3b1b59affd 100644 --- a/interface/src/MenuColumn.h +++ b/interface/src/MenuColumn.h @@ -27,6 +27,7 @@ public: void render(int yOffset, int menuHeight, int lineHeight); void renderMouseOver(int yOffset); int addRow(const char* rowName, MenuRowCallback callback); + int addRow(const char* rowName, MenuRowCallback callback, MenuStateNameCallback stateNameCallback); int getMaxRowWidth(); private: char columnName[MAX_COLUMN_NAME]; diff --git a/interface/src/MenuRow.cpp b/interface/src/MenuRow.cpp index 495ca29987..910edf07b7 100644 --- a/interface/src/MenuRow.cpp +++ b/interface/src/MenuRow.cpp @@ -16,14 +16,28 @@ #include "MenuColumn.h" #include "Menu.h" -MenuRow::MenuRow() { +MenuRow::MenuRow() : + callback(NULL), + stateNameCallback(NULL) { } -MenuRow::MenuRow(const char * columnName, MenuRowCallback callback) { +MenuRow::MenuRow(const char * columnName, MenuRowCallback callback) : + callback(callback), + stateNameCallback(NULL) { int length = std::min(MAX_COLUMN_NAME - 5,(int) strlen(columnName)); strncpy(this->rowName, columnName, length); memcpy(this->rowName + length, " \0", 5); - this->callback = callback; + rowWidth = 0; +} + +MenuRow::MenuRow(const char * columnName, MenuRowCallback callback, MenuStateNameCallback stateNameCallback) : + callback(callback), + stateNameCallback(stateNameCallback) { + int length = std::min(MAX_COLUMN_NAME - 5,(int) strlen(columnName)); + strncpy(this->rowName, columnName, length); + + // note: it would be good to also include the initial state + memcpy(this->rowName + length, " \0", 5); rowWidth = 0; } @@ -31,19 +45,35 @@ MenuRow::~MenuRow() { } void MenuRow::call() { - callback(-2); + callback(MENU_ROW_PICKED); } char* MenuRow::getName() { int length = (int) strlen(this->rowName) - 4; - int currentValue = callback(-1); - if (currentValue == 0) { - memcpy(this->rowName + length, " OFF\0", 5); - } else if (currentValue == 1) { - memcpy(this->rowName + length, " ON \0", 5); - } else { - memcpy(this->rowName + length, " \0", 5); - } + int currentValue = callback(MENU_ROW_GET_VALUE); + + // If the MenuRow has a custom stateNameCallback function, then call it to get a string + // to display in the menu. Otherwise, use the default implementation. + if (stateNameCallback != NULL) { + const char* stateName = stateNameCallback(currentValue); + int stateNameLength = strlen(stateName); + printf("MenuRow::getName() stateName=%s stateNameLength=%d\n",stateName,stateNameLength); + + // XXXBHG - BUG!!! - only 5 characters?? someplace else hard coded? for some reason, we end up + // with memory corruption down the line, if we allow these states to be longer than 5 characters + // including the NULL termination. + strncpy(this->rowName + length, stateName,4); // only 4 chars + memcpy(this->rowName + length + 5, "\0", 0); // null terminate!! + + } else { + if (currentValue == 0) { + memcpy(this->rowName + length, " OFF\0", 5); + } else if (currentValue == 1) { + memcpy(this->rowName + length, " ON \0", 5); + } else { + memcpy(this->rowName + length, " \0", 5); + } + } return this->rowName; } diff --git a/interface/src/MenuRow.h b/interface/src/MenuRow.h index 8bca2a462d..638ffde125 100644 --- a/interface/src/MenuRow.h +++ b/interface/src/MenuRow.h @@ -12,13 +12,17 @@ const int MAX_COLUMN_NAME = 50; const int SPACE_BETWEEN_COLUMNS = 20; const int SPACE_BEFORE_ROW_NAME = 10; +const int MENU_ROW_PICKED = -2; +const int MENU_ROW_GET_VALUE = -1; typedef int(*MenuRowCallback)(int); +typedef const char*(*MenuStateNameCallback)(int); class MenuRow { public: MenuRow(); MenuRow(const char* rowName, MenuRowCallback callback); + MenuRow(const char* rowName, MenuRowCallback callback, MenuStateNameCallback stateNameCallback); ~MenuRow(); void call(); char * getName(); @@ -28,6 +32,7 @@ private: char rowName[MAX_COLUMN_NAME]; int rowWidth; MenuRowCallback callback; + MenuStateNameCallback stateNameCallback; }; #endif /* defined(__hifi__MenuRow__) */ From 37322fcb73162934fbee2d88dc54c5fe826951fe Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Sat, 13 Apr 2013 15:20:21 -0700 Subject: [PATCH 6/7] Many menu improvements, and some render_view_frustum() improvements - Added menu items for Quit, Voxels, Stars, Frustum features, etc. - Added FrustomDrawMode enhancements to render_view_frustum() --- interface/src/main.cpp | 318 +++++++++++++++++++++++++++-------------- 1 file changed, 209 insertions(+), 109 deletions(-) diff --git a/interface/src/main.cpp b/interface/src/main.cpp index 23c89824de..5288eafd30 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -152,15 +152,6 @@ bool paintOn = false; // Whether to paint voxels as you fly around VoxelDetail paintingVoxel; // The voxel we're painting if we're painting unsigned char dominantColor = 0; // The dominant color of the voxel we're painting bool perfStatsOn = false; // Do we want to display perfStats? -bool frustumOn = false; // Whether or not to display the debug view frustum -bool cameraFrustum = true; // which frustum to look at - -bool viewFrustumFromOffset=false; // Wether or not to offset the view of the frustum -float viewFrustumOffsetYaw = -90.0; -float viewFrustumOffsetPitch = 7.5; -float viewFrustumOffsetRoll = 0.0; -float viewFrustumOffsetDistance = 0.0; -float viewFrustumOffsetUp = 0.0; int noiseOn = 0; // Whether to add random noise float noise = 1.0; // Overall magnitude scaling for random noise levels @@ -492,15 +483,46 @@ void simulateHead(float frametime) } } - - ///////////////////////////////////////////////////////////////////////////////////// // render_view_frustum() // // Description: this will render the view frustum bounds for EITHER the head -// or the "myCamera". It appears as if the orientation that comes -// from these two sources is in different coordinate spaces (namely) -// their axis orientations don't match. +// or the "myCamera". +// +// Frustum rendering mode. For debug purposes, we allow drawing the frustum in a couple of different ways. +// We can draw it with each of these parts: +// * Origin Direction/Up/Right vectors - these will be drawn at the point of the camera +// * Near plane - this plane is drawn very close to the origin point. +// * Right/Left planes - these two planes are drawn between the near and far planes. +// * Far plane - the plane is drawn in the distance. +// Modes - the following modes, will draw the following parts. +// * All - draws all the parts listed above +// * Planes - draws the planes but not the origin vectors +// * Origin Vectors - draws the origin vectors ONLY +// * Near Plane - draws only the near plane +// * Far Plane - draws only the far plane +#define FRUSTUM_DRAW_MODE_ALL 0 +#define FRUSTUM_DRAW_MODE_VECTORS 1 +#define FRUSTUM_DRAW_MODE_PLANES 2 +#define FRUSTUM_DRAW_MODE_NEAR_PLANE 3 +#define FRUSTUM_DRAW_MODE_FAR_PLANE 4 +#define FRUSTUM_DRAW_MODE_COUNT 5 + +// These global scoped variables are used by our render_view_frustum() function below, but are also available as globals +// so that the keyboard and menu can manipulate them. + +int frustumDrawingMode = FRUSTUM_DRAW_MODE_ALL; // the mode we're drawing the frustum in, see notes above + +bool frustumOn = false; // Whether or not to display the debug view frustum +bool cameraFrustum = true; // which frustum to look at + +bool viewFrustumFromOffset=false; // Wether or not to offset the view of the frustum +float viewFrustumOffsetYaw = -90.0; // the following variables control yaw, pitch, roll and distance form regular +float viewFrustumOffsetPitch = 7.5; // camera to the offset camera +float viewFrustumOffsetRoll = 0.0; +float viewFrustumOffsetDistance = 0.0; +float viewFrustumOffsetUp = 0.0; + void render_view_frustum() { glm::vec3 cameraPosition = ::myCamera.getPosition(); @@ -533,7 +555,7 @@ void render_view_frustum() { up = headUp; right = headRight; } - + // Ask the ViewFrustum class to calculate our corners ViewFrustum vf(position,direction,up,right,::WIDTH,::HEIGHT); @@ -543,102 +565,91 @@ void render_view_frustum() { glLineWidth(1.0); glBegin(GL_LINES); - // Drawing the head direction vectors - glm::vec3 headLookingAt = headPosition + (headDirection * 0.2f); - glm::vec3 headLookingAtUp = headPosition + (headUp * 0.2f); - glm::vec3 headLookingAtRight = headPosition + (headRight * 0.2f); + if (::frustumDrawingMode == FRUSTUM_DRAW_MODE_ALL || ::frustumDrawingMode == FRUSTUM_DRAW_MODE_VECTORS) { + // Calculate the origin direction vectors + glm::vec3 lookingAt = position + (direction * 0.2f); + glm::vec3 lookingAtUp = position + (up * 0.2f); + glm::vec3 lookingAtRight = position + (right * 0.2f); - // Looking At from head = white - glColor3f(1,1,1); - glVertex3f(headPosition.x, headPosition.y, headPosition.z); - glVertex3f(headLookingAt.x, headLookingAt.y, headLookingAt.z); + // Looking At = white + glColor3f(1,1,1); + glVertex3f(position.x, position.y, position.z); + glVertex3f(lookingAt.x, lookingAt.y, lookingAt.z); - // up from head = purple - glColor3f(1,0,1); - glVertex3f(headPosition.x, headPosition.y, headPosition.z); - glVertex3f(headLookingAtUp.x, headLookingAtUp.y, headLookingAtUp.z); + // Looking At Up = purple + glColor3f(1,0,1); + glVertex3f(position.x, position.y, position.z); + glVertex3f(lookingAtUp.x, lookingAtUp.y, lookingAtUp.z); - // right from head = cyan - glColor3f(0,1,1); - glVertex3f(headPosition.x, headPosition.y, headPosition.z); - glVertex3f(headLookingAtRight.x, headLookingAtRight.y, headLookingAtRight.z); + // Looking At Right = cyan + glColor3f(0,1,1); + glVertex3f(position.x, position.y, position.z); + glVertex3f(lookingAtRight.x, lookingAtRight.y, lookingAtRight.z); + } - // Drawing the camera direction vectors - glm::vec3 cameraLookingAt = cameraPosition + (cameraDirection * 0.2f); - glm::vec3 cameraLookingAtUp = cameraPosition + (cameraUp * 0.2f); - glm::vec3 cameraLookingAtRight = cameraPosition + (cameraRight * 0.2f); + if (::frustumDrawingMode == FRUSTUM_DRAW_MODE_ALL || ::frustumDrawingMode == FRUSTUM_DRAW_MODE_PLANES + || ::frustumDrawingMode == FRUSTUM_DRAW_MODE_NEAR_PLANE) { + // Drawing the bounds of the frustum + // vf.getNear plane - bottom edge + glColor3f(1,0,0); + glVertex3f(vf.getNearBottomLeft().x, vf.getNearBottomLeft().y, vf.getNearBottomLeft().z); + glVertex3f(vf.getNearBottomRight().x, vf.getNearBottomRight().y, vf.getNearBottomRight().z); - // Looking At from camera = white - glColor3f(1,1,1); - glVertex3f(cameraPosition.x,cameraPosition.y,cameraPosition.z); - glVertex3f(cameraLookingAt.x,cameraLookingAt.y,cameraLookingAt.z); + // vf.getNear plane - top edge + glVertex3f(vf.getNearTopLeft().x, vf.getNearTopLeft().y, vf.getNearTopLeft().z); + glVertex3f(vf.getNearTopRight().x, vf.getNearTopRight().y, vf.getNearTopRight().z); - // up from camera = purple - glColor3f(1,0,1); - glVertex3f(cameraPosition.x,cameraPosition.y,cameraPosition.z); - glVertex3f(cameraLookingAtUp.x,cameraLookingAtUp.y,cameraLookingAtUp.z); + // vf.getNear plane - right edge + glVertex3f(vf.getNearBottomRight().x, vf.getNearBottomRight().y, vf.getNearBottomRight().z); + glVertex3f(vf.getNearTopRight().x, vf.getNearTopRight().y, vf.getNearTopRight().z); - // right from camera = cyan - glColor3f(0,1,1); - glVertex3f(cameraPosition.x,cameraPosition.y,cameraPosition.z); - glVertex3f(cameraLookingAtRight.x,cameraLookingAtRight.y,cameraLookingAtRight.z); + // vf.getNear plane - left edge + glVertex3f(vf.getNearBottomLeft().x, vf.getNearBottomLeft().y, vf.getNearBottomLeft().z); + glVertex3f(vf.getNearTopLeft().x, vf.getNearTopLeft().y, vf.getNearTopLeft().z); + } + if (::frustumDrawingMode == FRUSTUM_DRAW_MODE_ALL || ::frustumDrawingMode == FRUSTUM_DRAW_MODE_PLANES + || ::frustumDrawingMode == FRUSTUM_DRAW_MODE_FAR_PLANE) { + // vf.getFar plane - bottom edge + glColor3f(0,1,0); // GREEN!!! + glVertex3f(vf.getFarBottomLeft().x, vf.getFarBottomLeft().y, vf.getFarBottomLeft().z); + glVertex3f(vf.getFarBottomRight().x, vf.getFarBottomRight().y, vf.getFarBottomRight().z); - // Drawing the bounds of the frustum - // vf.getNear plane - bottom edge - glColor3f(1,0,0); - glVertex3f(vf.getNearBottomLeft().x, vf.getNearBottomLeft().y, vf.getNearBottomLeft().z); - glVertex3f(vf.getNearBottomRight().x, vf.getNearBottomRight().y, vf.getNearBottomRight().z); + // vf.getFar plane - top edge + glVertex3f(vf.getFarTopLeft().x, vf.getFarTopLeft().y, vf.getFarTopLeft().z); + glVertex3f(vf.getFarTopRight().x, vf.getFarTopRight().y, vf.getFarTopRight().z); - // vf.getNear plane - top edge - glVertex3f(vf.getNearTopLeft().x, vf.getNearTopLeft().y, vf.getNearTopLeft().z); - glVertex3f(vf.getNearTopRight().x, vf.getNearTopRight().y, vf.getNearTopRight().z); + // vf.getFar plane - right edge + glVertex3f(vf.getFarBottomRight().x, vf.getFarBottomRight().y, vf.getFarBottomRight().z); + glVertex3f(vf.getFarTopRight().x, vf.getFarTopRight().y, vf.getFarTopRight().z); - // vf.getNear plane - right edge - glVertex3f(vf.getNearBottomRight().x, vf.getNearBottomRight().y, vf.getNearBottomRight().z); - glVertex3f(vf.getNearTopRight().x, vf.getNearTopRight().y, vf.getNearTopRight().z); + // vf.getFar plane - left edge + glVertex3f(vf.getFarBottomLeft().x, vf.getFarBottomLeft().y, vf.getFarBottomLeft().z); + glVertex3f(vf.getFarTopLeft().x, vf.getFarTopLeft().y, vf.getFarTopLeft().z); + } - // vf.getNear plane - left edge - glVertex3f(vf.getNearBottomLeft().x, vf.getNearBottomLeft().y, vf.getNearBottomLeft().z); - glVertex3f(vf.getNearTopLeft().x, vf.getNearTopLeft().y, vf.getNearTopLeft().z); + if (::frustumDrawingMode == FRUSTUM_DRAW_MODE_ALL || ::frustumDrawingMode == FRUSTUM_DRAW_MODE_PLANES) { + // RIGHT PLANE IS CYAN + // right plane - bottom edge - vf.getNear to distant + glColor3f(0,1,1); + glVertex3f(vf.getNearBottomRight().x, vf.getNearBottomRight().y, vf.getNearBottomRight().z); + glVertex3f(vf.getFarBottomRight().x, vf.getFarBottomRight().y, vf.getFarBottomRight().z); - // vf.getFar plane - bottom edge - glColor3f(0,1,0); // GREEN!!! - glVertex3f(vf.getFarBottomLeft().x, vf.getFarBottomLeft().y, vf.getFarBottomLeft().z); - glVertex3f(vf.getFarBottomRight().x, vf.getFarBottomRight().y, vf.getFarBottomRight().z); + // right plane - top edge - vf.getNear to distant + glVertex3f(vf.getNearTopRight().x, vf.getNearTopRight().y, vf.getNearTopRight().z); + glVertex3f(vf.getFarTopRight().x, vf.getFarTopRight().y, vf.getFarTopRight().z); - // vf.getFar plane - top edge - glVertex3f(vf.getFarTopLeft().x, vf.getFarTopLeft().y, vf.getFarTopLeft().z); - glVertex3f(vf.getFarTopRight().x, vf.getFarTopRight().y, vf.getFarTopRight().z); + // LEFT PLANE IS BLUE + // left plane - bottom edge - vf.getNear to distant + glColor3f(0,0,1); + glVertex3f(vf.getNearBottomLeft().x, vf.getNearBottomLeft().y, vf.getNearBottomLeft().z); + glVertex3f(vf.getFarBottomLeft().x, vf.getFarBottomLeft().y, vf.getFarBottomLeft().z); - // vf.getFar plane - right edge - glVertex3f(vf.getFarBottomRight().x, vf.getFarBottomRight().y, vf.getFarBottomRight().z); - glVertex3f(vf.getFarTopRight().x, vf.getFarTopRight().y, vf.getFarTopRight().z); - - // vf.getFar plane - left edge - glVertex3f(vf.getFarBottomLeft().x, vf.getFarBottomLeft().y, vf.getFarBottomLeft().z); - glVertex3f(vf.getFarTopLeft().x, vf.getFarTopLeft().y, vf.getFarTopLeft().z); - - // RIGHT PLANE IS CYAN - // right plane - bottom edge - vf.getNear to distant - glColor3f(0,1,1); - glVertex3f(vf.getNearBottomRight().x, vf.getNearBottomRight().y, vf.getNearBottomRight().z); - glVertex3f(vf.getFarBottomRight().x, vf.getFarBottomRight().y, vf.getFarBottomRight().z); - - // right plane - top edge - vf.getNear to distant - glVertex3f(vf.getNearTopRight().x, vf.getNearTopRight().y, vf.getNearTopRight().z); - glVertex3f(vf.getFarTopRight().x, vf.getFarTopRight().y, vf.getFarTopRight().z); - - // LEFT PLANE IS BLUE - // left plane - bottom edge - vf.getNear to distant - glColor3f(0,0,1); - glVertex3f(vf.getNearBottomLeft().x, vf.getNearBottomLeft().y, vf.getNearBottomLeft().z); - glVertex3f(vf.getFarBottomLeft().x, vf.getFarBottomLeft().y, vf.getFarBottomLeft().z); - - // left plane - top edge - vf.getNear to distant - glVertex3f(vf.getNearTopLeft().x, vf.getNearTopLeft().y, vf.getNearTopLeft().z); - glVertex3f(vf.getFarTopLeft().x, vf.getFarTopLeft().y, vf.getFarTopLeft().z); - + // left plane - top edge - vf.getNear to distant + glVertex3f(vf.getNearTopLeft().x, vf.getNearTopLeft().y, vf.getNearTopLeft().z); + glVertex3f(vf.getFarTopLeft().x, vf.getFarTopLeft().y, vf.getFarTopLeft().z); + } + glEnd(); } @@ -883,10 +894,23 @@ void display(void) } } +// int version of setValue() int setValue(int state, int *value) { - if (state == -2) { + if (state == MENU_ROW_PICKED) { *value = !(*value); - } else if (state == -1) { + } else if (state == MENU_ROW_GET_VALUE) { + return *value; + } else { + *value = state; + } + return *value; +} + +// bool version of setValue() +int setValue(int state, bool *value) { + if (state == MENU_ROW_PICKED) { + *value = !(*value); + } else if (state == MENU_ROW_GET_VALUE) { return *value; } else { *value = state; @@ -912,6 +936,14 @@ int setNoise(int state) { return iRet; } +int setVoxels(int state) { + return setValue(state, &::showingVoxels); +} + +int setStars(int state) { + return setValue(state, &::starsOn); +} + int setStats(int state) { return setValue(state, &statsOn); } @@ -924,18 +956,83 @@ int setMirror(int state) { return setValue(state, &headMirror); } +int setDisplayFrustum(int state) { + return setValue(state, &::frustumOn); +} + +int setFrustumOffset(int state) { + return setValue(state, &::viewFrustumFromOffset); +} + +int setFrustumOrigin(int state) { + return setValue(state, &::cameraFrustum); +} + +int quitApp(int state) { + if (state == MENU_ROW_PICKED) { + ::terminate(); + } + return 2; // non state so menu class doesn't add "state" +} + +int setFrustumRenderMode(int state) { + if (state == MENU_ROW_PICKED) { + ::frustumDrawingMode = (::frustumDrawingMode+1)%FRUSTUM_DRAW_MODE_COUNT; + } + return ::frustumDrawingMode; +} + +const char* modeAll = " All\0"; +const char* modeVectors = " Vector\0"; +const char* modePlanes = " Planes\0"; +const char* modeNear = " Near\0"; +const char* modeFar = " Far\0"; + +const char* getFrustumRenderModeName(int state) { + const char * mode; + switch (state) { + case FRUSTUM_DRAW_MODE_ALL: + mode = modeAll; + break; + case FRUSTUM_DRAW_MODE_VECTORS: + mode = modeVectors; + break; + case FRUSTUM_DRAW_MODE_PLANES: + mode = modePlanes; + break; + case FRUSTUM_DRAW_MODE_NEAR_PLANE: + mode = modeNear; + break; + case FRUSTUM_DRAW_MODE_FAR_PLANE: + mode = modeFar; + break; + } + return mode; +} + void initMenu() { - MenuColumn *menuColumnOptions, *menuColumnTools, *menuColumnDebug; + MenuColumn *menuColumnOptions, *menuColumnTools, *menuColumnDebug, *menuColumnFrustum; // Options menuColumnOptions = menu.addColumn("Options"); - menuColumnOptions->addRow("Head", setHead); - menuColumnOptions->addRow("Field", setField); - menuColumnOptions->addRow("Noise", setNoise); + menuColumnOptions->addRow("(H)ead", setHead); + menuColumnOptions->addRow("Field (f)", setField); + menuColumnOptions->addRow("(N)oise", setNoise); menuColumnOptions->addRow("Mirror", setMirror); + menuColumnOptions->addRow("(V)oxels", setVoxels); + menuColumnOptions->addRow("Stars (*)", setStars); + menuColumnOptions->addRow("(Q)uit", quitApp); // Tools menuColumnTools = menu.addColumn("Tools"); - menuColumnTools->addRow("Stats", setStats); - menuColumnTools->addRow("Menu", setMenu); + menuColumnTools->addRow("Stats (/)", setStats); + menuColumnTools->addRow("(M)enu", setMenu); + + // Debug + menuColumnFrustum = menu.addColumn("Frustum"); + menuColumnFrustum->addRow("Display (F)rustum", setDisplayFrustum); + menuColumnFrustum->addRow("Use (O)ffset Camera", setFrustumOffset); + menuColumnFrustum->addRow("Switch (C)amera", setFrustumOrigin); + menuColumnFrustum->addRow("(R)ender Mode", setFrustumRenderMode, getFrustumRenderModeName); + // Debug menuColumnDebug = menu.addColumn("Debug"); @@ -1079,13 +1176,13 @@ void key(unsigned char k, int x, int y) { // Process keypresses - if (k == 'q') ::terminate(); + if (k == 'q' || k == 'Q') ::terminate(); if (k == '/') statsOn = !statsOn; // toggle stats if (k == '*') ::starsOn = !::starsOn; // toggle stars - if (k == 'V') ::showingVoxels = !::showingVoxels; // toggle voxels + if (k == 'V' || k == 'v') ::showingVoxels = !::showingVoxels; // toggle voxels if (k == 'F') ::frustumOn = !::frustumOn; // toggle view frustum debugging if (k == 'C') ::cameraFrustum = !::cameraFrustum; // toggle which frustum to look at - if (k == 'G') ::viewFrustumFromOffset = !::viewFrustumFromOffset; // toggle view frustum from offset debugging + if (k == 'O' || k == 'G') ::viewFrustumFromOffset = !::viewFrustumFromOffset; // toggle view frustum offset debugging if (k == '[') ::viewFrustumOffsetYaw -= 0.5; if (k == ']') ::viewFrustumOffsetYaw += 0.5; @@ -1097,6 +1194,9 @@ void key(unsigned char k, int x, int y) if (k == '>') ::viewFrustumOffsetDistance += 0.5; if (k == ',') ::viewFrustumOffsetUp -= 0.05; if (k == '.') ::viewFrustumOffsetUp += 0.05; + if (k == '|') ViewFrustum::fovAngleAdust -= 0.05; + if (k == '\\') ViewFrustum::fovAngleAdust += 0.05; + if (k == 'R') setFrustumRenderMode(MENU_ROW_PICKED); if (k == '&') { ::paintOn = !::paintOn; // toggle paint @@ -1105,7 +1205,7 @@ void key(unsigned char k, int x, int y) if (k == '^') ::shiftPaintingColor(); // shifts randomize color between R,G,B dominant if (k == '-') ::sendVoxelServerEraseAll(); // sends erase all command to voxel server if (k == '%') ::sendVoxelServerAddScene(); // sends add scene command to voxel server - if (k == 'n') + if (k == 'n' || k == 'N') { noiseOn = !noiseOn; // Toggle noise if (noiseOn) @@ -1126,7 +1226,7 @@ void key(unsigned char k, int x, int y) #endif } - if (k == 'm') setMenu(-2); + if (k == 'm' || k == 'M') setMenu(MENU_ROW_PICKED); if (k == 'f') displayField = !displayField; if (k == 'l') displayLevels = !displayLevels; From e429dfe61f18ec4e48d78987ee2ed09cc4c27e39 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Sat, 13 Apr 2013 15:57:30 -0700 Subject: [PATCH 7/7] fixed bug in rendering menu rows where state was longer than 5 characters --- interface/src/MenuRow.cpp | 43 ++++++++++++++++----------------------- interface/src/MenuRow.h | 2 ++ 2 files changed, 20 insertions(+), 25 deletions(-) diff --git a/interface/src/MenuRow.cpp b/interface/src/MenuRow.cpp index 910edf07b7..09ee685a87 100644 --- a/interface/src/MenuRow.cpp +++ b/interface/src/MenuRow.cpp @@ -24,20 +24,18 @@ MenuRow::MenuRow() : MenuRow::MenuRow(const char * columnName, MenuRowCallback callback) : callback(callback), stateNameCallback(NULL) { - int length = std::min(MAX_COLUMN_NAME - 5,(int) strlen(columnName)); - strncpy(this->rowName, columnName, length); - memcpy(this->rowName + length, " \0", 5); + this->nameLength = strlen(columnName); + strncpy(this->rowName, columnName, MAX_COLUMN_NAME); // copy the base name + strncpy(this->rowName, this->getName(), MAX_COLUMN_NAME); // now add in state rowWidth = 0; } MenuRow::MenuRow(const char * columnName, MenuRowCallback callback, MenuStateNameCallback stateNameCallback) : callback(callback), stateNameCallback(stateNameCallback) { - int length = std::min(MAX_COLUMN_NAME - 5,(int) strlen(columnName)); - strncpy(this->rowName, columnName, length); - - // note: it would be good to also include the initial state - memcpy(this->rowName + length, " \0", 5); + this->nameLength = strlen(columnName); + strncpy(this->rowName, columnName, MAX_COLUMN_NAME); + strncpy(this->rowName, this->getName(), MAX_COLUMN_NAME); // now add in state rowWidth = 0; } @@ -48,32 +46,27 @@ void MenuRow::call() { callback(MENU_ROW_PICKED); } -char* MenuRow::getName() { - int length = (int) strlen(this->rowName) - 4; +const char* MenuRow::getStateName() { int currentValue = callback(MENU_ROW_GET_VALUE); - + const char* stateName; // If the MenuRow has a custom stateNameCallback function, then call it to get a string // to display in the menu. Otherwise, use the default implementation. if (stateNameCallback != NULL) { - const char* stateName = stateNameCallback(currentValue); - int stateNameLength = strlen(stateName); - printf("MenuRow::getName() stateName=%s stateNameLength=%d\n",stateName,stateNameLength); - - // XXXBHG - BUG!!! - only 5 characters?? someplace else hard coded? for some reason, we end up - // with memory corruption down the line, if we allow these states to be longer than 5 characters - // including the NULL termination. - strncpy(this->rowName + length, stateName,4); // only 4 chars - memcpy(this->rowName + length + 5, "\0", 0); // null terminate!! - + stateName = stateNameCallback(currentValue); } else { if (currentValue == 0) { - memcpy(this->rowName + length, " OFF\0", 5); + stateName = " OFF "; } else if (currentValue == 1) { - memcpy(this->rowName + length, " ON \0", 5); + stateName = " ON "; } else { - memcpy(this->rowName + length, " \0", 5); + stateName = " "; } - } + } + return stateName; +} + +char* MenuRow::getName() { + strcpy(this->rowName + nameLength, getStateName()); return this->rowName; } diff --git a/interface/src/MenuRow.h b/interface/src/MenuRow.h index 638ffde125..a371cec3f4 100644 --- a/interface/src/MenuRow.h +++ b/interface/src/MenuRow.h @@ -26,9 +26,11 @@ public: ~MenuRow(); void call(); char * getName(); + const char* getStateName(); int getWidth(float scale, int mono, int leftPosition); int getWidth(); private: + int nameLength; char rowName[MAX_COLUMN_NAME]; int rowWidth; MenuRowCallback callback;