From dcacad3755aa364d0557b3df8cdae47314589109 Mon Sep 17 00:00:00 2001 From: Philip Rosedale Date: Fri, 12 Apr 2013 10:02:41 -0700 Subject: [PATCH 01/27] Removed unneeded GLenable cruft --- interface/src/Cloud.cpp | 5 +---- interface/src/main.cpp | 2 -- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/interface/src/Cloud.cpp b/interface/src/Cloud.cpp index 5d68ecba75..ea27b40d49 100644 --- a/interface/src/Cloud.cpp +++ b/interface/src/Cloud.cpp @@ -43,20 +43,17 @@ Cloud::Cloud(int num, } } - void Cloud::render() { - + float particleAttenuationQuadratic[] = { 0.0f, 0.0f, 2.0f }; glEnable( GL_TEXTURE_2D ); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); - float maxSize = 0.0f; glGetFloatv( GL_POINT_SIZE_MAX_ARB, &maxSize ); glPointSize( maxSize ); - glPointParameterfvARB( GL_POINT_DISTANCE_ATTENUATION_ARB, particleAttenuationQuadratic ); glPointParameterfARB( GL_POINT_SIZE_MAX_ARB, maxSize ); glPointParameterfARB( GL_POINT_SIZE_MIN_ARB, 0.001f ); diff --git a/interface/src/main.cpp b/interface/src/main.cpp index 5b11d9e34e..0a4f06cc06 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -810,8 +810,6 @@ void display(void) // Draw cloud of dots - glDisable( GL_POINT_SPRITE_ARB ); - glDisable( GL_TEXTURE_2D ); if (!displayHead) cloud.render(); // Draw voxels From 7f1ba5c73301f4f9999f6b7032ba419eebb19058 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Fri, 12 Apr 2013 11:26:32 -0700 Subject: [PATCH 02/27] playing around with fov angle --- interface/src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interface/src/main.cpp b/interface/src/main.cpp index 99beac33ae..0ef8f29128 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -565,7 +565,7 @@ void render_view_frustum() { float nearDist = 0.1; float farDist = 1.0; - float fovHalfAngle = 0.7854f; // 45 deg for half, so fov = 90 deg + float fovHalfAngle = 0.7854f*1.5; // 45 deg for half, so fov = 90 deg float screenWidth = ::WIDTH; // These values come from reshape() float screenHeight = ::HEIGHT; From 76d22f1b2b437780b4a7d14ad06f6f540cee7481 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Fri, 12 Apr 2013 11:34:10 -0700 Subject: [PATCH 03/27] more angle tweaks --- interface/src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interface/src/main.cpp b/interface/src/main.cpp index 0ef8f29128..7d3598fd3c 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -565,7 +565,7 @@ void render_view_frustum() { float nearDist = 0.1; float farDist = 1.0; - float fovHalfAngle = 0.7854f*1.5; // 45 deg for half, so fov = 90 deg + float fovHalfAngle = 0.7854f*1.7; // 45 deg for half, so fov = 90 deg float screenWidth = ::WIDTH; // These values come from reshape() float screenHeight = ::HEIGHT; From d01d1164ca3e7e7fbf71aee94e4b98dcbbd2b3ec Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Fri, 12 Apr 2013 13:36:44 -0700 Subject: [PATCH 04/27] latest view frustum work --- interface/src/Orientation.cpp | 2 + interface/src/Util.cpp | 24 ------------ interface/src/Util.h | 3 -- interface/src/main.cpp | 23 +++++++++--- shared/src/SharedUtil.cpp | 1 + shared/src/SharedUtil.h | 1 + voxellib/src/ViewFrustum.cpp | 69 +++++++++++++++++++++++++++++++++++ voxellib/src/ViewFrustum.h | 50 +++++++++++++++++++++++++ voxellib/src/glmUtils.cpp | 33 +++++++++++++++++ voxellib/src/glmUtils.h | 18 +++++++++ 10 files changed, 192 insertions(+), 32 deletions(-) create mode 100644 voxellib/src/ViewFrustum.cpp create mode 100644 voxellib/src/ViewFrustum.h create mode 100644 voxellib/src/glmUtils.cpp create mode 100644 voxellib/src/glmUtils.h diff --git a/interface/src/Orientation.cpp b/interface/src/Orientation.cpp index 439538ce8a..48befa76a4 100755 --- a/interface/src/Orientation.cpp +++ b/interface/src/Orientation.cpp @@ -1,5 +1,7 @@ #include "Orientation.h" #include "Util.h" +#include "glmUtils.h" + Orientation::Orientation() { right = glm::vec3( 1.0, 0.0, 0.0 ); diff --git a/interface/src/Util.cpp b/interface/src/Util.cpp index 3d58c6faa5..637204dc83 100644 --- a/interface/src/Util.cpp +++ b/interface/src/Util.cpp @@ -168,30 +168,6 @@ void drawvec3(int x, int y, float scale, float rotate, float thick, int mono, gl } -// XXXBHG - These handy operators should probably go somewhere else, I'm surprised they don't -// already exist somewhere in OpenGL. Maybe someone can point me to them if they do exist! -glm::vec3 operator* (float lhs, const glm::vec3& rhs) -{ - glm::vec3 result = rhs; - result.x *= lhs; - result.y *= lhs; - result.z *= lhs; - return result; -} - -// XXXBHG - These handy operators should probably go somewhere else, I'm surprised they don't -// already exist somewhere in OpenGL. Maybe someone can point me to them if they do exist! -glm::vec3 operator* (const glm::vec3& lhs, float rhs) -{ - glm::vec3 result = lhs; - result.x *= rhs; - result.y *= rhs; - result.z *= rhs; - return result; -} - - - void drawGroundPlaneGrid( float size, int resolution ) { diff --git a/interface/src/Util.h b/interface/src/Util.h index 0e0121e2da..5a9c53e74f 100644 --- a/interface/src/Util.h +++ b/interface/src/Util.h @@ -46,9 +46,6 @@ void drawvec3(int x, int y, float scale, float rotate, float thick, int mono, gl double diffclock(timeval *clock1,timeval *clock2); -glm::vec3 operator* (float lhs, const glm::vec3& rhs); -glm::vec3 operator* (const glm::vec3& lhs, float rhs); - void drawGroundPlaneGrid( float size, int resolution ); #endif diff --git a/interface/src/main.cpp b/interface/src/main.cpp index 7d3598fd3c..350825e7eb 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -75,6 +75,9 @@ #include #include #include +#include + +#include "ViewFrustum.h" using namespace std; @@ -159,6 +162,7 @@ bool viewFrustumFromOffset=false; // Wether or not to offset the view of the float viewFrustumOffsetYaw = -90.0; float viewFrustumOffsetPitch = 7.5; float viewFrustumOffsetRoll = 0.0; +float viewFrustumOffsetDistance = 0.0; int noiseOn = 0; // Whether to add random noise float noise = 1.0; // Overall magnitude scaling for random noise levels @@ -561,11 +565,14 @@ void render_view_frustum() { up = headUp; right = headRight; } + + ViewFrustum vf(viewFrustumPosition,viewFrustumDirection); + vf.dump(); float nearDist = 0.1; - float farDist = 1.0; + float farDist = 10.0; - float fovHalfAngle = 0.7854f*1.7; // 45 deg for half, so fov = 90 deg + float fovHalfAngle = 0.7854f*1.5; // 45 deg for half, so fov = 90 deg float screenWidth = ::WIDTH; // These values come from reshape() float screenHeight = ::HEIGHT; @@ -577,7 +584,7 @@ void render_view_frustum() { float farWidth = farHeight * ratio; glm::vec3 farCenter = viewFrustumPosition+viewFrustumDirection*farDist; - glm::vec3 farTopLeft = farCenter + (up*farHeight*0.5) - (right*farWidth*0.5); + glm::vec3 farTopLeft = farCenter + (up*farHeight*0.5) - (right*farWidth*0.5); glm::vec3 farTopRight = farCenter + (up*farHeight*0.5) + (right*farWidth*0.5); glm::vec3 farBottomLeft = farCenter - (up*farHeight*0.5) - (right*farWidth*0.5); glm::vec3 farBottomRight = farCenter - (up*farHeight*0.5) + (right*farWidth*0.5); @@ -587,6 +594,9 @@ void render_view_frustum() { glm::vec3 nearTopRight = nearCenter + (up*nearHeight*0.5) + (right*nearWidth*0.5); glm::vec3 nearBottomLeft = nearCenter - (up*nearHeight*0.5) - (right*nearWidth*0.5); glm::vec3 nearBottomRight = nearCenter - (up*nearHeight*0.5) + (right*nearWidth*0.5); + + //printf("farCenter.x=%f, farCenter.y=%f, farCenter.z=%f\n",farCenter.x,farCenter.y,farCenter.z); + //printf("farTopLeft.x=%f, farTopLeft.y=%f, farTopLeft.z=%f\n",farTopLeft.x,farTopLeft.y,farTopLeft.z); // At this point we have all the corners for our frustum... we could use these to // calculate various things... @@ -770,9 +780,9 @@ void display(void) //---------------------------------------------------- viewFrustumOffsetCamera.setYaw ( 180.0 - myAvatar.getBodyYaw() + ::viewFrustumOffsetYaw ); viewFrustumOffsetCamera.setPitch ( 0.0 + ::viewFrustumOffsetPitch ); - viewFrustumOffsetCamera.setRoll ( 0.0 + ::viewFrustumOffsetRoll ); + viewFrustumOffsetCamera.setRoll ( 0.0 + ::viewFrustumOffsetRoll ); viewFrustumOffsetCamera.setUp ( 0.2 + 0.2 ); - viewFrustumOffsetCamera.setDistance( 0.5 + 0.2 ); + viewFrustumOffsetCamera.setDistance ( 0.5 + ::viewFrustumOffsetDistance ); viewFrustumOffsetCamera.update(); whichCamera = viewFrustumOffsetCamera; @@ -1138,6 +1148,9 @@ void key(unsigned char k, int x, int y) if (k == '(') ::viewFrustumOffsetRoll -= 0.5; if (k == ')') ::viewFrustumOffsetRoll += 0.5; + if (k == '<') ::viewFrustumOffsetDistance -= 0.5; + if (k == '>') ::viewFrustumOffsetDistance += 0.5; + if (k == '&') { ::paintOn = !::paintOn; // toggle paint ::setupPaintingVoxel(); // also randomizes colors diff --git a/shared/src/SharedUtil.cpp b/shared/src/SharedUtil.cpp index fddcca6cd7..8fb8645730 100644 --- a/shared/src/SharedUtil.cpp +++ b/shared/src/SharedUtil.cpp @@ -351,3 +351,4 @@ void printVoxelCode(unsigned char* voxelCode) { } while( (time2 - time1) < waitTime); } #endif + diff --git a/shared/src/SharedUtil.h b/shared/src/SharedUtil.h index 34ac6d8b86..24517c9a68 100644 --- a/shared/src/SharedUtil.h +++ b/shared/src/SharedUtil.h @@ -54,4 +54,5 @@ bool createVoxelEditMessage(unsigned char command, short int sequence, void usleep(int waitTime); #endif + #endif /* defined(__hifi__SharedUtil__) */ diff --git a/voxellib/src/ViewFrustum.cpp b/voxellib/src/ViewFrustum.cpp new file mode 100644 index 0000000000..060585c015 --- /dev/null +++ b/voxellib/src/ViewFrustum.cpp @@ -0,0 +1,69 @@ +// +// ViewFrustum.cpp +// hifi +// +// Created by Brad Hefta-Gaub on 04/11/13. +// +// Simple view frustum class. +// +// + +#include "ViewFrustum.h" +#include "glmUtils.h" + +ViewFrustum::ViewFrustum(glm::vec3 position, glm::vec3 direction) { + this->calculateViewFrustum(position, direction); +} + +///////////////////////////////////////////////////////////////////////////////////// +// ViewFrustum::calculateViewFrustum() +// +// Description: this will calculate the view frustum bounds for a given position +// and direction +void ViewFrustum::calculateViewFrustum(glm::vec3 position, glm::vec3 direction) { + float nearDist = 0.1; + float farDist = 1.0; + + glm::vec3 front = direction; + glm::vec3 up = glm::vec3(0,direction.y,0); // up is always this way + glm::vec3 right = glm::vec3(direction.z,direction.y,direction.x); // up is + + float fovHalfAngle = 0.7854f; // 45 deg for half, so fov = 90 deg + + float screenWidth = 800;//::WIDTH; // These values come from reshape() + float screenHeight = 600; //::HEIGHT; + float ratio = screenWidth/screenHeight; + + float nearHeight = 2 * tan(fovHalfAngle) * nearDist; + float nearWidth = nearHeight * ratio; + float farHeight = 2 * tan(fovHalfAngle) * farDist; + float farWidth = farHeight * ratio; + + this->_farCenter = position+front*farDist; + this->_farTopLeft = this->_farCenter + (up*farHeight*0.5) - (right*farWidth*0.5); + this->_farTopRight = this->_farCenter + (up*farHeight*0.5) + (right*farWidth*0.5); + this->_farBottomLeft = this->_farCenter - (up*farHeight*0.5) - (right*farWidth*0.5); + this->_farBottomRight = this->_farCenter - (up*farHeight*0.5) + (right*farWidth*0.5); + + this->_nearCenter = position+front*nearDist; + this->_nearTopLeft = this->_nearCenter + (up*nearHeight*0.5) - (right*nearWidth*0.5); + this->_nearTopRight = this->_nearCenter + (up*nearHeight*0.5) + (right*nearWidth*0.5); + this->_nearBottomLeft = this->_nearCenter - (up*nearHeight*0.5) - (right*nearWidth*0.5); + this->_nearBottomRight = this->_nearCenter - (up*nearHeight*0.5) + (right*nearWidth*0.5); +} + +void ViewFrustum::dump() { + printf("farCenter.x=%f, farCenter.y=%f, farCenter.z=%f\n",this->_farCenter.x,this->_farCenter.y,this->_farCenter.z); + printf("farTopLeft.x=%f, farTopLeft.y=%f, farTopLeft.z=%f\n",this->_farTopLeft.x,this->_farTopLeft.y,this->_farTopLeft.z); + printf("farTopRight.x=%f, farTopRight.y=%f, farTopRight.z=%f\n",this->_farTopRight.x,this->_farTopRight.y,this->_farTopRight.z); + printf("farBottomLeft.x=%f, farBottomLeft.y=%f, farBottomLeft.z=%f\n",this->_farBottomLeft.x,this->_farBottomLeft.y,this->_farBottomLeft.z); + printf("farBottomRight.x=%f, farBottomRight.y=%f, farBottomRight.z=%f\n",this->_farBottomRight.x,this->_farBottomRight.y,this->_farBottomRight.z); + + printf("nearCenter.x=%f, nearCenter.y=%f, nearCenter.z=%f\n",this->_nearCenter.x,this->_nearCenter.y,this->_nearCenter.z); + printf("nearTopLeft.x=%f, nearTopLeft.y=%f, nearTopLeft.z=%f\n",this->_nearTopLeft.x,this->_nearTopLeft.y,this->_nearTopLeft.z); + printf("nearTopRight.x=%f, nearTopRight.y=%f, nearTopRight.z=%f\n",this->_nearTopRight.x,this->_nearTopRight.y,this->_nearTopRight.z); + printf("nearBottomLeft.x=%f, nearBottomLeft.y=%f, nearBottomLeft.z=%f\n",this->_nearBottomLeft.x,this->_nearBottomLeft.y,this->_nearBottomLeft.z); + printf("nearBottomRight.x=%f, nearBottomRight.y=%f, nearBottomRight.z=%f\n",this->_nearBottomRight.x,this->_nearBottomRight.y,this->_nearBottomRight.z); +} + + diff --git a/voxellib/src/ViewFrustum.h b/voxellib/src/ViewFrustum.h new file mode 100644 index 0000000000..f3600e5716 --- /dev/null +++ b/voxellib/src/ViewFrustum.h @@ -0,0 +1,50 @@ +// +// ViewFrustum.h +// hifi +// +// Created by Brad Hefta-Gaub on 04/11/13. +// +// Simple view frustum class. +// +// + +#ifndef __hifi__ViewFrustum__ +#define __hifi__ViewFrustum__ + +#include + +class ViewFrustum { +private: + glm::vec3 _farCenter; + glm::vec3 _farTopLeft; + glm::vec3 _farTopRight; + glm::vec3 _farBottomLeft; + glm::vec3 _farBottomRight; + + glm::vec3 _nearCenter; + glm::vec3 _nearTopLeft; + glm::vec3 _nearTopRight; + glm::vec3 _nearBottomLeft; + glm::vec3 _nearBottomRight; +public: + glm::vec3 getFarCenter() const { return _farCenter; }; + glm::vec3 getFarTopLeft() const { return _farTopLeft; }; + glm::vec3 getFarTopRight() const { return _farTopRight; }; + glm::vec3 getFarBottomLeft() const { return _farBottomLeft; }; + glm::vec3 getFarBottomRight() const { return _farBottomRight; }; + + glm::vec3 getNearCenter() const { return _nearCenter; }; + glm::vec3 getNearTopLeft() const { return _nearTopLeft; }; + glm::vec3 getNearTopRight() const { return _nearTopRight; }; + glm::vec3 getNearBottomLeft() const { return _nearBottomLeft; }; + glm::vec3 getNearBottomRight() const { return _nearBottomRight; }; + + void calculateViewFrustum(glm::vec3 position, glm::vec3 direction); + + ViewFrustum(glm::vec3 position, glm::vec3 direction); + + void dump(); +}; + + +#endif /* defined(__hifi__ViewFrustum__) */ diff --git a/voxellib/src/glmUtils.cpp b/voxellib/src/glmUtils.cpp new file mode 100644 index 0000000000..67e6642c98 --- /dev/null +++ b/voxellib/src/glmUtils.cpp @@ -0,0 +1,33 @@ +// +// glmUtils.cpp +// hifi +// +// Created by Brad Hefta-Gaub on 4/12/13. +// +// + +#include + + +// XXXBHG - These handy operators should probably go somewhere else, I'm surprised they don't +// already exist somewhere in OpenGL. Maybe someone can point me to them if they do exist! +glm::vec3 operator* (float lhs, const glm::vec3& rhs) +{ + glm::vec3 result = rhs; + result.x *= lhs; + result.y *= lhs; + result.z *= lhs; + return result; +} + +// XXXBHG - These handy operators should probably go somewhere else, I'm surprised they don't +// already exist somewhere in OpenGL. Maybe someone can point me to them if they do exist! +glm::vec3 operator* (const glm::vec3& lhs, float rhs) +{ + glm::vec3 result = lhs; + result.x *= rhs; + result.y *= rhs; + result.z *= rhs; + return result; +} + diff --git a/voxellib/src/glmUtils.h b/voxellib/src/glmUtils.h new file mode 100644 index 0000000000..45f4bb20ff --- /dev/null +++ b/voxellib/src/glmUtils.h @@ -0,0 +1,18 @@ +// +// glmUtils.h +// hifi +// +// Created by Brad Hefta-Gaub on 4/12/13. +// +// + +#ifndef __hifi__glmUtils__ +#define __hifi__glmUtils__ + +#include + +glm::vec3 operator* (float lhs, const glm::vec3& rhs); +glm::vec3 operator* (const glm::vec3& lhs, float rhs); + + +#endif // __hifi__glmUtils__ \ No newline at end of file From 862ee47fbb1be8c6ca440d0d2bb326389ddd3479 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Fri, 12 Apr 2013 13:40:33 -0700 Subject: [PATCH 05/27] moving voxellib to libraries/voxels --- {voxellib => libraries/voxels}/src/ViewFrustum.cpp | 0 {voxellib => libraries/voxels}/src/ViewFrustum.h | 0 {voxellib => libraries/voxels}/src/glmUtils.cpp | 0 {voxellib => libraries/voxels}/src/glmUtils.h | 0 4 files changed, 0 insertions(+), 0 deletions(-) rename {voxellib => libraries/voxels}/src/ViewFrustum.cpp (100%) rename {voxellib => libraries/voxels}/src/ViewFrustum.h (100%) rename {voxellib => libraries/voxels}/src/glmUtils.cpp (100%) rename {voxellib => libraries/voxels}/src/glmUtils.h (100%) diff --git a/voxellib/src/ViewFrustum.cpp b/libraries/voxels/src/ViewFrustum.cpp similarity index 100% rename from voxellib/src/ViewFrustum.cpp rename to libraries/voxels/src/ViewFrustum.cpp diff --git a/voxellib/src/ViewFrustum.h b/libraries/voxels/src/ViewFrustum.h similarity index 100% rename from voxellib/src/ViewFrustum.h rename to libraries/voxels/src/ViewFrustum.h diff --git a/voxellib/src/glmUtils.cpp b/libraries/voxels/src/glmUtils.cpp similarity index 100% rename from voxellib/src/glmUtils.cpp rename to libraries/voxels/src/glmUtils.cpp diff --git a/voxellib/src/glmUtils.h b/libraries/voxels/src/glmUtils.h similarity index 100% rename from voxellib/src/glmUtils.h rename to libraries/voxels/src/glmUtils.h From d568cce0cd6c63d8a5b4960ed36be861e8993b74 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Fri, 12 Apr 2013 15:01:48 -0700 Subject: [PATCH 06/27] changed interface to use ViewFrustum class for rendering view frustum - updated ViewFrustum class to work correctly - added new keyboard interface to adjust offset camera position and up - removed keyboard interface for local add sphere, since we don't need that anymore --- interface/src/main.cpp | 201 ++++++++++----------------- libraries/voxels/src/ViewFrustum.cpp | 91 +++++++----- libraries/voxels/src/ViewFrustum.h | 39 ++++-- 3 files changed, 153 insertions(+), 178 deletions(-) diff --git a/interface/src/main.cpp b/interface/src/main.cpp index 350825e7eb..6fd09f8339 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -156,13 +156,13 @@ unsigned char dominantColor = 0; // The dominant color of the voxel we're painti 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 wantFrustumDebugging = false; // enable for some stdout debugging output 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 @@ -503,20 +503,6 @@ void simulateHead(float frametime) // from these two sources is in different coordinate spaces (namely) // their axis orientations don't match. void render_view_frustum() { - - //printf("frustum low.x=%f, low.y=%f, low.z=%f, high.x=%f, high.y=%f, high.z=%f\n",low.x,low.y,low.z,high.x,high.y,high.z); - - // p – the camera position - // d – a vector with the direction of the camera's view ray. In here it is assumed that this vector has been normalized - // nearDist – the distance from the camera to the near plane - // nearHeight – the height of the near plane - // nearWidth – the width of the near plane - // farDist – the distance from the camera to the far plane - // farHeight – the height of the far plane - // farWidth – the width of the far plane - - - // Some explanation here. glm::vec3 cameraPosition = ::myCamera.getPosition(); glm::vec3 headPosition = ::myAvatar.getHeadPosition(); @@ -524,94 +510,46 @@ void render_view_frustum() { glm::vec3 cameraDirection = ::myCamera.getOrientation().getFront() * glm::vec3(1,1,-1); glm::vec3 headDirection = myAvatar.getHeadLookatDirection(); // direction still backwards - glm::vec3 cameraUp = myCamera.getOrientation().getUp() * glm::vec3(1,1,1); glm::vec3 headUp = myAvatar.getHeadLookatDirectionUp(); glm::vec3 cameraRight = myCamera.getOrientation().getRight() * glm::vec3(1,1,-1); glm::vec3 headRight = myAvatar.getHeadLookatDirectionRight() * glm::vec3(-1,1,-1); // z is flipped! - // Debug these vectors! - if (::wantFrustumDebugging) { - printf("\nPosition:\n"); - printf("cameraPosition=%f, cameraPosition=%f, cameraPosition=%f\n",cameraPosition.x,cameraPosition.y,cameraPosition.z); - printf("headPosition.x=%f, headPosition.y=%f, headPosition.z=%f\n",headPosition.x,headPosition.y,headPosition.z); - printf("\nDirection:\n"); - printf("cameraDirection.x=%f, cameraDirection.y=%f, cameraDirection.z=%f\n",cameraDirection.x,cameraDirection.y,cameraDirection.z); - printf("headDirection.x=%f, headDirection.y=%f, headDirection.z=%f\n",headDirection.x,headDirection.y,headDirection.z); - printf("\nUp:\n"); - printf("cameraUp.x=%f, cameraUp.y=%f, cameraUp.z=%f\n",cameraUp.x,cameraUp.y,cameraUp.z); - printf("headUp.x=%f, headUp.y=%f, headUp.z=%f\n",headUp.x,headUp.y,headUp.z); - printf("\nRight:\n"); - printf("cameraRight.x=%f, cameraRight.y=%f, cameraRight.z=%f\n",cameraRight.x,cameraRight.y,cameraRight.z); - printf("headRight.x=%f, headRight.y=%f, headRight.z=%f\n",headRight.x,headRight.y,headRight.z); - } - // We will use these below, from either the camera or head vectors calculated above - glm::vec3 viewFrustumPosition; - glm::vec3 viewFrustumDirection; + glm::vec3 position; + glm::vec3 direction; glm::vec3 up; glm::vec3 right; // Camera or Head? if (::cameraFrustum) { - viewFrustumPosition = cameraPosition; - viewFrustumDirection = cameraDirection; + position = cameraPosition; + direction = cameraDirection; up = cameraUp; right = cameraRight; } else { - viewFrustumPosition = headPosition; - viewFrustumDirection = headDirection; + position = headPosition; + direction = headDirection; up = headUp; right = headRight; } - ViewFrustum vf(viewFrustumPosition,viewFrustumDirection); - vf.dump(); + //////////////////////////////////////// + // Ask the ViewFrustum class to calculate our corners + ViewFrustum vf(position,direction,up,right,::WIDTH,::HEIGHT); - float nearDist = 0.1; - float farDist = 10.0; - - float fovHalfAngle = 0.7854f*1.5; // 45 deg for half, so fov = 90 deg - - float screenWidth = ::WIDTH; // These values come from reshape() - float screenHeight = ::HEIGHT; - float ratio = screenWidth/screenHeight; - - float nearHeight = 2 * tan(fovHalfAngle) * nearDist; - float nearWidth = nearHeight * ratio; - float farHeight = 2 * tan(fovHalfAngle) * farDist; - float farWidth = farHeight * ratio; - - glm::vec3 farCenter = viewFrustumPosition+viewFrustumDirection*farDist; - glm::vec3 farTopLeft = farCenter + (up*farHeight*0.5) - (right*farWidth*0.5); - glm::vec3 farTopRight = farCenter + (up*farHeight*0.5) + (right*farWidth*0.5); - glm::vec3 farBottomLeft = farCenter - (up*farHeight*0.5) - (right*farWidth*0.5); - glm::vec3 farBottomRight = farCenter - (up*farHeight*0.5) + (right*farWidth*0.5); - - glm::vec3 nearCenter = viewFrustumPosition+viewFrustumDirection*nearDist; - glm::vec3 nearTopLeft = nearCenter + (up*nearHeight*0.5) - (right*nearWidth*0.5); - glm::vec3 nearTopRight = nearCenter + (up*nearHeight*0.5) + (right*nearWidth*0.5); - glm::vec3 nearBottomLeft = nearCenter - (up*nearHeight*0.5) - (right*nearWidth*0.5); - glm::vec3 nearBottomRight = nearCenter - (up*nearHeight*0.5) + (right*nearWidth*0.5); - - //printf("farCenter.x=%f, farCenter.y=%f, farCenter.z=%f\n",farCenter.x,farCenter.y,farCenter.z); - //printf("farTopLeft.x=%f, farTopLeft.y=%f, farTopLeft.z=%f\n",farTopLeft.x,farTopLeft.y,farTopLeft.z); - - // At this point we have all the corners for our frustum... we could use these to - // calculate various things... - - // But, here we're just going to draw them for now - // Get ready to draw some lines glDisable(GL_LIGHTING); glColor4f(1.0, 1.0, 1.0, 1.0); glLineWidth(1.0); glBegin(GL_LINES); - glm::vec3 headLookingAt = headPosition+(headDirection*5.0); - glm::vec3 headLookingAtUp = headPosition+(headUp*5.0); - glm::vec3 headLookingAtRight = headPosition+(headRight*5.0); + //////////////////////////////////////// + // Drawing the head direction vectors + glm::vec3 headLookingAt = headPosition+(headDirection*0.2); + glm::vec3 headLookingAtUp = headPosition+(headUp*0.2); + glm::vec3 headLookingAtRight = headPosition+(headRight*0.2); // Looking At from head = white glColor3f(1,1,1); @@ -628,9 +566,11 @@ void render_view_frustum() { glVertex3f(headPosition.x,headPosition.y,headPosition.z); glVertex3f(headLookingAtRight.x,headLookingAtRight.y,headLookingAtRight.z); - glm::vec3 cameraLookingAt = cameraPosition+(cameraDirection*5.0); - glm::vec3 cameraLookingAtUp = cameraPosition+(cameraUp*5.0); - glm::vec3 cameraLookingAtRight = cameraPosition+(cameraRight*5.0); + //////////////////////////////////////// + // Drawing the camera direction vectors + glm::vec3 cameraLookingAt = cameraPosition+(cameraDirection*0.2); + glm::vec3 cameraLookingAtUp = cameraPosition+(cameraUp*0.2); + glm::vec3 cameraLookingAtRight = cameraPosition+(cameraRight*0.2); // Looking At from camera = white glColor3f(1,1,1); @@ -647,61 +587,62 @@ void render_view_frustum() { glVertex3f(cameraPosition.x,cameraPosition.y,cameraPosition.z); glVertex3f(cameraLookingAtRight.x,cameraLookingAtRight.y,cameraLookingAtRight.z); - // The remaining lines are skinny - //glLineWidth(1.0); - // near plane - bottom edge + + //////////////////////////////////////// + // Drawing the bounds of the frustum + // vf.getNear plane - bottom edge glColor3f(1,0,0); - glVertex3f(nearBottomLeft.x,nearBottomLeft.y,nearBottomLeft.z); - glVertex3f(nearBottomRight.x,nearBottomRight.y,nearBottomRight.z); + glVertex3f(vf.getNearBottomLeft().x,vf.getNearBottomLeft().y,vf.getNearBottomLeft().z); + glVertex3f(vf.getNearBottomRight().x,vf.getNearBottomRight().y,vf.getNearBottomRight().z); - // near plane - top edge - glVertex3f(nearTopLeft.x,nearTopLeft.y,nearTopLeft.z); - glVertex3f(nearTopRight.x,nearTopRight.y,nearTopRight.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); - // near plane - right edge - glVertex3f(nearBottomRight.x,nearBottomRight.y,nearBottomRight.z); - glVertex3f(nearTopRight.x,nearTopRight.y,nearTopRight.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); - // near plane - left edge - glVertex3f(nearBottomLeft.x,nearBottomLeft.y,nearBottomLeft.z); - glVertex3f(nearTopLeft.x,nearTopLeft.y,nearTopLeft.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); - // far plane - bottom edge + // vf.getFar plane - bottom edge glColor3f(0,1,0); // GREEN!!! - glVertex3f(farBottomLeft.x,farBottomLeft.y,farBottomLeft.z); - glVertex3f(farBottomRight.x,farBottomRight.y,farBottomRight.z); + glVertex3f(vf.getFarBottomLeft().x,vf.getFarBottomLeft().y,vf.getFarBottomLeft().z); + glVertex3f(vf.getFarBottomRight().x,vf.getFarBottomRight().y,vf.getFarBottomRight().z); - // far plane - top edge - glVertex3f(farTopLeft.x,farTopLeft.y,farTopLeft.z); - glVertex3f(farTopRight.x,farTopRight.y,farTopRight.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); - // far plane - right edge - glVertex3f(farBottomRight.x,farBottomRight.y,farBottomRight.z); - glVertex3f(farTopRight.x,farTopRight.y,farTopRight.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); - // far plane - left edge - glVertex3f(farBottomLeft.x,farBottomLeft.y,farBottomLeft.z); - glVertex3f(farTopLeft.x,farTopLeft.y,farTopLeft.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 - near to distant + // right plane - bottom edge - vf.getNear to distant glColor3f(0,1,1); - glVertex3f(nearBottomRight.x,nearBottomRight.y,nearBottomRight.z); - glVertex3f(farBottomRight.x,farBottomRight.y,farBottomRight.z); + glVertex3f(vf.getNearBottomRight().x,vf.getNearBottomRight().y,vf.getNearBottomRight().z); + glVertex3f(vf.getFarBottomRight().x,vf.getFarBottomRight().y,vf.getFarBottomRight().z); - // right plane - top edge - near to distant - glVertex3f(nearTopRight.x,nearTopRight.y,nearTopRight.z); - glVertex3f(farTopRight.x,farTopRight.y,farTopRight.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 - near to distant + // left plane - bottom edge - vf.getNear to distant glColor3f(0,0,1); - glVertex3f(nearBottomLeft.x,nearBottomLeft.y,nearBottomLeft.z); - glVertex3f(farBottomLeft.x,farBottomLeft.y,farBottomLeft.z); + glVertex3f(vf.getNearBottomLeft().x,vf.getNearBottomLeft().y,vf.getNearBottomLeft().z); + glVertex3f(vf.getFarBottomLeft().x,vf.getFarBottomLeft().y,vf.getFarBottomLeft().z); - // left plane - top edge - near to distant - glVertex3f(nearTopLeft.x,nearTopLeft.y,nearTopLeft.z); - glVertex3f(farTopLeft.x,farTopLeft.y,farTopLeft.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(); } @@ -779,9 +720,9 @@ void display(void) // set the camera to third-person view but offset so we can see the frustum //---------------------------------------------------- viewFrustumOffsetCamera.setYaw ( 180.0 - myAvatar.getBodyYaw() + ::viewFrustumOffsetYaw ); - viewFrustumOffsetCamera.setPitch ( 0.0 + ::viewFrustumOffsetPitch ); - viewFrustumOffsetCamera.setRoll ( 0.0 + ::viewFrustumOffsetRoll ); - viewFrustumOffsetCamera.setUp ( 0.2 + 0.2 ); + viewFrustumOffsetCamera.setPitch ( 0.0 + ::viewFrustumOffsetPitch ); + viewFrustumOffsetCamera.setRoll ( 0.0 + ::viewFrustumOffsetRoll ); + viewFrustumOffsetCamera.setUp ( 0.2 + ::viewFrustumOffsetUp ); viewFrustumOffsetCamera.setDistance ( 0.5 + ::viewFrustumOffsetDistance ); viewFrustumOffsetCamera.update(); @@ -1141,15 +1082,16 @@ void key(unsigned char k, int x, int y) if (k == 'C') ::cameraFrustum = !::cameraFrustum; // toggle which frustum to look at if (k == 'G') ::viewFrustumFromOffset = !::viewFrustumFromOffset; // toggle view frustum from offset debugging - if (k == '[') ::viewFrustumOffsetYaw -= 0.5; - if (k == ']') ::viewFrustumOffsetYaw += 0.5; - if (k == '{') ::viewFrustumOffsetPitch -= 0.5; - if (k == '}') ::viewFrustumOffsetPitch += 0.5; - if (k == '(') ::viewFrustumOffsetRoll -= 0.5; - if (k == ')') ::viewFrustumOffsetRoll += 0.5; - + if (k == '[') ::viewFrustumOffsetYaw -= 0.5; + if (k == ']') ::viewFrustumOffsetYaw += 0.5; + if (k == '{') ::viewFrustumOffsetPitch -= 0.5; + if (k == '}') ::viewFrustumOffsetPitch += 0.5; + if (k == '(') ::viewFrustumOffsetRoll -= 0.5; + if (k == ')') ::viewFrustumOffsetRoll += 0.5; if (k == '<') ::viewFrustumOffsetDistance -= 0.5; if (k == '>') ::viewFrustumOffsetDistance += 0.5; + if (k == ',') ::viewFrustumOffsetUp -= 0.05; + if (k == '.') ::viewFrustumOffsetUp += 0.05; if (k == '&') { ::paintOn = !::paintOn; // toggle paint @@ -1199,9 +1141,6 @@ void key(unsigned char k, int x, int y) #endif if (k == 'a') myAvatar.setDriveKeys(ROT_LEFT, 1); if (k == 'd') myAvatar.setDriveKeys(ROT_RIGHT, 1); - - // press the . key to get a new random sphere of voxels added - if (k == '.') addRandomSphere(wantColorRandomizer); } // Receive packets from other agents/servers and decide what to do with them! diff --git a/libraries/voxels/src/ViewFrustum.cpp b/libraries/voxels/src/ViewFrustum.cpp index 060585c015..aa1de5abd6 100644 --- a/libraries/voxels/src/ViewFrustum.cpp +++ b/libraries/voxels/src/ViewFrustum.cpp @@ -11,8 +11,8 @@ #include "ViewFrustum.h" #include "glmUtils.h" -ViewFrustum::ViewFrustum(glm::vec3 position, glm::vec3 direction) { - this->calculateViewFrustum(position, direction); +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); } ///////////////////////////////////////////////////////////////////////////////////// @@ -20,49 +20,70 @@ ViewFrustum::ViewFrustum(glm::vec3 position, glm::vec3 direction) { // // Description: this will calculate the view frustum bounds for a given position // and direction -void ViewFrustum::calculateViewFrustum(glm::vec3 position, glm::vec3 direction) { - float nearDist = 0.1; - float farDist = 1.0; +// +// Notes on how/why this works: +// http://www.lighthouse3d.com/tutorials/view-frustum-culling/view-frustums-shape/ +// +void ViewFrustum::calculateViewFrustum(glm::vec3 position, glm::vec3 direction, glm::vec3 up, glm::vec3 right, float screenWidth, float screenHeight) { - glm::vec3 front = direction; - glm::vec3 up = glm::vec3(0,direction.y,0); // up is always this way - glm::vec3 right = glm::vec3(direction.z,direction.y,direction.x); // up is + // Save the values we were passed... + this->_position=position; + this->_direction=direction; + this->_up=up; + this->_right=right; + this->_screenWidth=screenWidth; + this->_screenHeight=screenHeight; - float fovHalfAngle = 0.7854f; // 45 deg for half, so fov = 90 deg + glm::vec3 front = direction; + float fovHalfAngle = 0.7854f*1.5; // 45 deg for half, so fov = 90 deg + float ratio = screenWidth/screenHeight; - float screenWidth = 800;//::WIDTH; // These values come from reshape() - float screenHeight = 600; //::HEIGHT; - float ratio = screenWidth/screenHeight; + this->_nearDist = 0.1; + this->_farDist = 10.0; - float nearHeight = 2 * tan(fovHalfAngle) * nearDist; - float nearWidth = nearHeight * ratio; - float farHeight = 2 * tan(fovHalfAngle) * farDist; - float farWidth = farHeight * ratio; - - this->_farCenter = position+front*farDist; - this->_farTopLeft = this->_farCenter + (up*farHeight*0.5) - (right*farWidth*0.5); - this->_farTopRight = this->_farCenter + (up*farHeight*0.5) + (right*farWidth*0.5); - this->_farBottomLeft = this->_farCenter - (up*farHeight*0.5) - (right*farWidth*0.5); - this->_farBottomRight = this->_farCenter - (up*farHeight*0.5) + (right*farWidth*0.5); + this->_nearHeight = 2 * tan(fovHalfAngle) * this->_nearDist; + this->_nearWidth = this->_nearHeight * ratio; + this->_farHeight = 2 * tan(fovHalfAngle) * this->_farDist; + this->_farWidth = this->_farHeight * ratio; - this->_nearCenter = position+front*nearDist; - this->_nearTopLeft = this->_nearCenter + (up*nearHeight*0.5) - (right*nearWidth*0.5); - this->_nearTopRight = this->_nearCenter + (up*nearHeight*0.5) + (right*nearWidth*0.5); - this->_nearBottomLeft = this->_nearCenter - (up*nearHeight*0.5) - (right*nearWidth*0.5); - this->_nearBottomRight = this->_nearCenter - (up*nearHeight*0.5) + (right*nearWidth*0.5); + this->_farCenter = this->_position+front*this->_farDist; + this->_farTopLeft = this->_farCenter + (this->_up*this->_farHeight*0.5) - (this->_right*this->_farWidth*0.5); + this->_farTopRight = this->_farCenter + (this->_up*this->_farHeight*0.5) + (this->_right*this->_farWidth*0.5); + this->_farBottomLeft = this->_farCenter - (this->_up*this->_farHeight*0.5) - (this->_right*this->_farWidth*0.5); + this->_farBottomRight = this->_farCenter - (this->_up*this->_farHeight*0.5) + (this->_right*this->_farWidth*0.5); + + this->_nearCenter = this->_position+front*this->_nearDist; + this->_nearTopLeft = this->_nearCenter + (this->_up*this->_nearHeight*0.5) - (this->_right*this->_nearWidth*0.5); + this->_nearTopRight = this->_nearCenter + (this->_up*this->_nearHeight*0.5) + (this->_right*this->_nearWidth*0.5); + this->_nearBottomLeft = this->_nearCenter - (this->_up*this->_nearHeight*0.5) - (this->_right*this->_nearWidth*0.5); + this->_nearBottomRight = this->_nearCenter - (this->_up*this->_nearHeight*0.5) + (this->_right*this->_nearWidth*0.5); } void ViewFrustum::dump() { - printf("farCenter.x=%f, farCenter.y=%f, farCenter.z=%f\n",this->_farCenter.x,this->_farCenter.y,this->_farCenter.z); - printf("farTopLeft.x=%f, farTopLeft.y=%f, farTopLeft.z=%f\n",this->_farTopLeft.x,this->_farTopLeft.y,this->_farTopLeft.z); - printf("farTopRight.x=%f, farTopRight.y=%f, farTopRight.z=%f\n",this->_farTopRight.x,this->_farTopRight.y,this->_farTopRight.z); - printf("farBottomLeft.x=%f, farBottomLeft.y=%f, farBottomLeft.z=%f\n",this->_farBottomLeft.x,this->_farBottomLeft.y,this->_farBottomLeft.z); + + printf("position.x=%f, position.y=%f, position.z=%f\n",this->_position.x,this->_position.y,this->_position.z); + printf("direction.x=%f, direction.y=%f, direction.z=%f\n",this->_direction.x,this->_direction.y,this->_direction.z); + printf("up.x=%f, up.y=%f, up.z=%f\n",this->_up.x,this->_up.y,this->_up.z); + printf("right.x=%f, right.y=%f, right.z=%f\n",this->_right.x,this->_right.y,this->_right.z); + + printf("farDist=%f\n",this->_farDist); + printf("farHeight=%f\n",this->_farHeight); + printf("farWidth=%f\n",this->_farWidth); + + printf("nearDist=%f\n",this->_nearDist); + printf("nearHeight=%f\n",this->_nearHeight); + printf("nearWidth=%f\n",this->_nearWidth); + + printf("farCenter.x=%f, farCenter.y=%f, farCenter.z=%f\n",this->_farCenter.x,this->_farCenter.y,this->_farCenter.z); + printf("farTopLeft.x=%f, farTopLeft.y=%f, farTopLeft.z=%f\n",this->_farTopLeft.x,this->_farTopLeft.y,this->_farTopLeft.z); + printf("farTopRight.x=%f, farTopRight.y=%f, farTopRight.z=%f\n",this->_farTopRight.x,this->_farTopRight.y,this->_farTopRight.z); + printf("farBottomLeft.x=%f, farBottomLeft.y=%f, farBottomLeft.z=%f\n",this->_farBottomLeft.x,this->_farBottomLeft.y,this->_farBottomLeft.z); printf("farBottomRight.x=%f, farBottomRight.y=%f, farBottomRight.z=%f\n",this->_farBottomRight.x,this->_farBottomRight.y,this->_farBottomRight.z); - printf("nearCenter.x=%f, nearCenter.y=%f, nearCenter.z=%f\n",this->_nearCenter.x,this->_nearCenter.y,this->_nearCenter.z); - printf("nearTopLeft.x=%f, nearTopLeft.y=%f, nearTopLeft.z=%f\n",this->_nearTopLeft.x,this->_nearTopLeft.y,this->_nearTopLeft.z); - printf("nearTopRight.x=%f, nearTopRight.y=%f, nearTopRight.z=%f\n",this->_nearTopRight.x,this->_nearTopRight.y,this->_nearTopRight.z); - printf("nearBottomLeft.x=%f, nearBottomLeft.y=%f, nearBottomLeft.z=%f\n",this->_nearBottomLeft.x,this->_nearBottomLeft.y,this->_nearBottomLeft.z); + printf("nearCenter.x=%f, nearCenter.y=%f, nearCenter.z=%f\n",this->_nearCenter.x,this->_nearCenter.y,this->_nearCenter.z); + printf("nearTopLeft.x=%f, nearTopLeft.y=%f, nearTopLeft.z=%f\n",this->_nearTopLeft.x,this->_nearTopLeft.y,this->_nearTopLeft.z); + printf("nearTopRight.x=%f, nearTopRight.y=%f, nearTopRight.z=%f\n",this->_nearTopRight.x,this->_nearTopRight.y,this->_nearTopRight.z); + printf("nearBottomLeft.x=%f, nearBottomLeft.y=%f, nearBottomLeft.z=%f\n",this->_nearBottomLeft.x,this->_nearBottomLeft.y,this->_nearBottomLeft.z); printf("nearBottomRight.x=%f, nearBottomRight.y=%f, nearBottomRight.z=%f\n",this->_nearBottomRight.x,this->_nearBottomRight.y,this->_nearBottomRight.z); } diff --git a/libraries/voxels/src/ViewFrustum.h b/libraries/voxels/src/ViewFrustum.h index f3600e5716..586553412e 100644 --- a/libraries/voxels/src/ViewFrustum.h +++ b/libraries/voxels/src/ViewFrustum.h @@ -15,6 +15,21 @@ class ViewFrustum { private: + glm::vec3 _position; + glm::vec3 _direction; + glm::vec3 _up; + glm::vec3 _right; + float _screenWidth; + float _screenHeight; + + float _nearDist; + float _farDist; + + float _nearHeight; + float _nearWidth; + float _farHeight; + float _farWidth; + glm::vec3 _farCenter; glm::vec3 _farTopLeft; glm::vec3 _farTopRight; @@ -27,21 +42,21 @@ private: glm::vec3 _nearBottomLeft; glm::vec3 _nearBottomRight; public: - glm::vec3 getFarCenter() const { return _farCenter; }; - glm::vec3 getFarTopLeft() const { return _farTopLeft; }; - glm::vec3 getFarTopRight() const { return _farTopRight; }; - glm::vec3 getFarBottomLeft() const { return _farBottomLeft; }; - glm::vec3 getFarBottomRight() const { return _farBottomRight; }; + const glm::vec3& getFarCenter() const { return _farCenter; }; + const glm::vec3& getFarTopLeft() const { return _farTopLeft; }; + const glm::vec3& getFarTopRight() const { return _farTopRight; }; + const glm::vec3& getFarBottomLeft() const { return _farBottomLeft; }; + const glm::vec3& getFarBottomRight() const { return _farBottomRight; }; - glm::vec3 getNearCenter() const { return _nearCenter; }; - glm::vec3 getNearTopLeft() const { return _nearTopLeft; }; - glm::vec3 getNearTopRight() const { return _nearTopRight; }; - glm::vec3 getNearBottomLeft() const { return _nearBottomLeft; }; - glm::vec3 getNearBottomRight() const { return _nearBottomRight; }; + const glm::vec3& getNearCenter() const { return _nearCenter; }; + const glm::vec3& getNearTopLeft() const { return _nearTopLeft; }; + const glm::vec3& getNearTopRight() const { return _nearTopRight; }; + const glm::vec3& getNearBottomLeft() const { return _nearBottomLeft; }; + const glm::vec3& getNearBottomRight() const { return _nearBottomRight; }; - void calculateViewFrustum(glm::vec3 position, glm::vec3 direction); + void calculateViewFrustum(glm::vec3 position, glm::vec3 direction, glm::vec3 up, glm::vec3 right, float screenWidth, float screenHeight); - ViewFrustum(glm::vec3 position, glm::vec3 direction); + ViewFrustum(glm::vec3 position, glm::vec3 direction, glm::vec3 up, glm::vec3 right, float screenWidth, float screenHeight); void dump(); }; From 25f1f1ae3f1b0b5b6a14d47337b7919a483b5d26 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Fri, 12 Apr 2013 15:08:57 -0700 Subject: [PATCH 07/27] include glmUtils.h so that we get vec3 opertator* --- interface/src/Head.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/interface/src/Head.cpp b/interface/src/Head.cpp index 600dc3f0ca..895f666981 100644 --- a/interface/src/Head.cpp +++ b/interface/src/Head.cpp @@ -17,6 +17,7 @@ #include "Head.h" #include #include +#include using namespace std; From 6d7f343be83392d110445f6b463c894a9b244e6c Mon Sep 17 00:00:00 2001 From: Philip Rosedale Date: Fri, 12 Apr 2013 16:13:40 -0700 Subject: [PATCH 08/27] draw a test sphere around my hand in orldspace --- interface/src/main.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/interface/src/main.cpp b/interface/src/main.cpp index e0b5ebcd15..909227a91f 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -796,6 +796,11 @@ void display(void) glEnable(GL_LIGHTING); glEnable(GL_DEPTH_TEST); + // Test - Draw a blue sphere around a body part of mine! + + glPushMatrix(); + //glTranslate3f(myAvatar.GetRight + glPopMatrix(); // draw a red sphere float sphereRadius = 0.25f; From 1415a2530229660ea5c580aaa9964db0d1857a9a Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Fri, 12 Apr 2013 16:22:35 -0700 Subject: [PATCH 09/27] fix for warnings produced by CounterStats refactor --- libraries/shared/src/CounterStats.cpp | 27 +++++++++++++++++++++++++++ libraries/shared/src/CounterStats.h | 22 +++++----------------- 2 files changed, 32 insertions(+), 17 deletions(-) diff --git a/libraries/shared/src/CounterStats.cpp b/libraries/shared/src/CounterStats.cpp index 050ee6159b..20281c113e 100644 --- a/libraries/shared/src/CounterStats.cpp +++ b/libraries/shared/src/CounterStats.cpp @@ -33,6 +33,33 @@ // int sampleAt; +CounterStatHistory::CounterStatHistory() { + init(); +} + +CounterStatHistory::CounterStatHistory(std::string myName) { + init(); + name = myName; +} + +CounterStatHistory::CounterStatHistory(std::string myName, double initialTime, long initialCount) { + init(); + lastCount = currentCount = initialCount; + lastTime = currentTime = totalTime = initialTime; + name = myName; +} + +void CounterStatHistory::init() { + currentCount = 0; + currentDelta = 0; + currentTime = 0.0; + lastCount = 0; + lastTime = 0.0; + totalTime = 0.0; + sampleAt = -1; + sampleCount = 0; +} + void CounterStatHistory::recordSample(long thisCount) { timeval now; gettimeofday(&now,NULL); diff --git a/libraries/shared/src/CounterStats.h b/libraries/shared/src/CounterStats.h index 7d698d0970..81e34853ef 100644 --- a/libraries/shared/src/CounterStats.h +++ b/libraries/shared/src/CounterStats.h @@ -25,23 +25,9 @@ class CounterStatHistory { public: std::string name; - CounterStatHistory(std::string myName): - currentCount(0), currentDelta(0),currentTime(0.0), - lastCount(0),lastTime(0.0), - totalTime(0.0), - sampleAt(-1), sampleCount(0), name(myName) {}; - - CounterStatHistory(): - currentCount(0), currentDelta(0),currentTime(0.0), - lastCount(0),lastTime(0.0), - totalTime(0.0), - sampleAt(-1), sampleCount(0) {}; - - CounterStatHistory(std::string myName, double initialTime, long initialCount) : - currentCount(initialCount), currentDelta(0), currentTime(initialTime), - lastCount(initialCount),lastTime(initialTime), - totalTime(initialTime), - sampleAt(-1), sampleCount(0), name(myName) {}; + CounterStatHistory(); + CounterStatHistory(std::string myName); + CounterStatHistory(std::string myName, double initialTime, long initialCount); void recordSample(long thisCount); void recordSample(double thisTime, long thisCount); @@ -58,6 +44,8 @@ public: return currentCount; }; private: + void init(); + long currentCount; long currentDelta; double currentTime; From 787bebb5fc66d7a8c575977afd4cf4a97e5a8193 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Fri, 12 Apr 2013 16:51:59 -0700 Subject: [PATCH 10/27] don't call constructor and assignment operator --- libraries/shared/src/CounterStats.cpp | 40 ++++++++++++++++++++------- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/libraries/shared/src/CounterStats.cpp b/libraries/shared/src/CounterStats.cpp index 20281c113e..b86cfd37f2 100644 --- a/libraries/shared/src/CounterStats.cpp +++ b/libraries/shared/src/CounterStats.cpp @@ -33,20 +33,40 @@ // int sampleAt; -CounterStatHistory::CounterStatHistory() { - init(); +CounterStatHistory::CounterStatHistory() : + currentCount(0), + currentDelta(0), + currentTime(0.0), + lastCount(0), + lastTime(0.0), + totalTime(0.0), + sampleAt(-1), + sampleCount(0) { } -CounterStatHistory::CounterStatHistory(std::string myName) { - init(); - name = myName; +CounterStatHistory::CounterStatHistory(std::string myName) : + name(myName), + currentCount(0), + currentDelta(0), + currentTime(0.0), + lastCount(0), + lastTime(0.0), + totalTime(0.0), + sampleAt(-1), + sampleCount(0) { } -CounterStatHistory::CounterStatHistory(std::string myName, double initialTime, long initialCount) { - init(); - lastCount = currentCount = initialCount; - lastTime = currentTime = totalTime = initialTime; - name = myName; + +CounterStatHistory::CounterStatHistory(std::string myName, double initialTime, long initialCount) : + name(myName), + currentCount(initialCount), + currentDelta(0), + currentTime(initialTime), + lastCount(initialCount), + lastTime(initialTime), + totalTime(initialTime), + sampleAt(-1), + sampleCount(0) { } void CounterStatHistory::init() { From 5a8c5ff0114ae6058d30448e50b2d02433a5298c Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Fri, 12 Apr 2013 16:55:57 -0700 Subject: [PATCH 11/27] coding standards clean up --- interface/src/Head.cpp | 4 +- interface/src/Orientation.cpp | 12 ++--- interface/src/main.cpp | 76 +++++++++++++--------------- libraries/voxels/src/ViewFrustum.cpp | 36 ++++++++----- 4 files changed, 69 insertions(+), 59 deletions(-) diff --git a/interface/src/Head.cpp b/interface/src/Head.cpp index b4f67411e8..85050de2a1 100644 --- a/interface/src/Head.cpp +++ b/interface/src/Head.cpp @@ -1080,7 +1080,9 @@ void Head::updateHandMovement() { glm::vec3 newElbowPosition = avatar.bone[ AVATAR_BONE_RIGHT_SHOULDER ].position; newElbowPosition += armVector * (float)ONE_HALF; glm::vec3 perpendicular = glm::cross( avatar.orientation.getFront(), armVector ); - newElbowPosition += perpendicular * (float)(( 1.0f - ( avatar.maxArmLength / distance ) ) * ONE_HALF); // XXXBHG - Jeffery, you should clean this up. You can't multiple glm::vec3's by doubles, only floats + + // XXXBHG - Jeffery, you should clean this up. You can't multiple glm::vec3's by doubles, only floats + newElbowPosition += perpendicular * (float)(( 1.0f - ( avatar.maxArmLength / distance ) ) * ONE_HALF); avatar.bone[ AVATAR_BONE_RIGHT_UPPER_ARM ].position = newElbowPosition; //----------------------------------------------------------------------------- diff --git a/interface/src/Orientation.cpp b/interface/src/Orientation.cpp index da46ed3e47..f82ced6630 100755 --- a/interface/src/Orientation.cpp +++ b/interface/src/Orientation.cpp @@ -25,8 +25,8 @@ void Orientation::set( Orientation o ) { void Orientation::yaw( float angle ) { float r = angle * PI_OVER_180; - float s = sin( r ); - float c = cos( r ); + float s = sin(r); + float c = cos(r); glm::vec3 cosineFront = front * c; glm::vec3 cosineRight = right * c; @@ -40,8 +40,8 @@ void Orientation::yaw( float angle ) { void Orientation::pitch( float angle ) { float r = angle * PI_OVER_180; - float s = sin( r ); - float c = cos( r ); + float s = sin(r); + float c = cos(r); glm::vec3 cosineUp = up * c; glm::vec3 cosineFront = front * c; @@ -55,8 +55,8 @@ void Orientation::pitch( float angle ) { void Orientation::roll( float angle ) { float r = angle * PI_OVER_180; - float s = sin( r ); - float c = cos( r ); + float s = sin(r); + float c = cos(r); glm::vec3 cosineUp = up * c; glm::vec3 cosineRight = right * c; diff --git a/interface/src/main.cpp b/interface/src/main.cpp index b5c7dd75c2..4fef28d587 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -534,7 +534,6 @@ void render_view_frustum() { right = headRight; } - //////////////////////////////////////// // Ask the ViewFrustum class to calculate our corners ViewFrustum vf(position,direction,up,right,::WIDTH,::HEIGHT); @@ -544,32 +543,30 @@ 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); + glm::vec3 headLookingAt = headPosition + (headDirection * 0.2f); + glm::vec3 headLookingAtUp = headPosition + (headUp * 0.2f); + glm::vec3 headLookingAtRight = headPosition + (headRight * 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); + glVertex3f(headPosition.x, headPosition.y, headPosition.z); + glVertex3f(headLookingAt.x, headLookingAt.y, headLookingAt.z); // up from head = purple glColor3f(1,0,1); - glVertex3f(headPosition.x,headPosition.y,headPosition.z); - glVertex3f(headLookingAtUp.x,headLookingAtUp.y,headLookingAtUp.z); + glVertex3f(headPosition.x, headPosition.y, headPosition.z); + glVertex3f(headLookingAtUp.x, headLookingAtUp.y, headLookingAtUp.z); // right from head = cyan glColor3f(0,1,1); - glVertex3f(headPosition.x,headPosition.y,headPosition.z); - glVertex3f(headLookingAtRight.x,headLookingAtRight.y,headLookingAtRight.z); + glVertex3f(headPosition.x, headPosition.y, headPosition.z); + glVertex3f(headLookingAtRight.x, headLookingAtRight.y, headLookingAtRight.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); + glm::vec3 cameraLookingAt = cameraPosition + (cameraDirection * 0.2f); + glm::vec3 cameraLookingAtUp = cameraPosition + (cameraUp * 0.2f); + glm::vec3 cameraLookingAtRight = cameraPosition + (cameraRight * 0.2f); // Looking At from camera = white glColor3f(1,1,1); @@ -587,61 +584,60 @@ void render_view_frustum() { glVertex3f(cameraLookingAtRight.x,cameraLookingAtRight.y,cameraLookingAtRight.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); + glVertex3f(vf.getNearBottomLeft().x, vf.getNearBottomLeft().y, vf.getNearBottomLeft().z); + glVertex3f(vf.getNearBottomRight().x, vf.getNearBottomRight().y, vf.getNearBottomRight().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); + glVertex3f(vf.getNearTopLeft().x, vf.getNearTopLeft().y, vf.getNearTopLeft().z); + glVertex3f(vf.getNearTopRight().x, vf.getNearTopRight().y, vf.getNearTopRight().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); + glVertex3f(vf.getNearBottomRight().x, vf.getNearBottomRight().y, vf.getNearBottomRight().z); + glVertex3f(vf.getNearTopRight().x, vf.getNearTopRight().y, vf.getNearTopRight().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); + glVertex3f(vf.getNearBottomLeft().x, vf.getNearBottomLeft().y, vf.getNearBottomLeft().z); + glVertex3f(vf.getNearTopLeft().x, vf.getNearTopLeft().y, vf.getNearTopLeft().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); + glVertex3f(vf.getFarBottomLeft().x, vf.getFarBottomLeft().y, vf.getFarBottomLeft().z); + glVertex3f(vf.getFarBottomRight().x, vf.getFarBottomRight().y, vf.getFarBottomRight().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); + glVertex3f(vf.getFarTopLeft().x, vf.getFarTopLeft().y, vf.getFarTopLeft().z); + glVertex3f(vf.getFarTopRight().x, vf.getFarTopRight().y, vf.getFarTopRight().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); + 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); + 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); + 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); + 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); + 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); + glVertex3f(vf.getNearTopLeft().x, vf.getNearTopLeft().y, vf.getNearTopLeft().z); + glVertex3f(vf.getFarTopLeft().x, vf.getFarTopLeft().y, vf.getFarTopLeft().z); glEnd(); } diff --git a/libraries/voxels/src/ViewFrustum.cpp b/libraries/voxels/src/ViewFrustum.cpp index 29ed92fb9e..b7fae39ca5 100644 --- a/libraries/voxels/src/ViewFrustum.cpp +++ b/libraries/voxels/src/ViewFrustum.cpp @@ -10,7 +10,8 @@ #include "ViewFrustum.h" -ViewFrustum::ViewFrustum(glm::vec3 position, glm::vec3 direction, glm::vec3 up, glm::vec3 right, float screenWidth, float screenHeight) { +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); } @@ -23,7 +24,8 @@ ViewFrustum::ViewFrustum(glm::vec3 position, glm::vec3 direction, glm::vec3 up, // Notes on how/why this works: // http://www.lighthouse3d.com/tutorials/view-frustum-culling/view-frustums-shape/ // -void ViewFrustum::calculateViewFrustum(glm::vec3 position, glm::vec3 direction, glm::vec3 up, glm::vec3 right, float screenWidth, float screenHeight) { +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; @@ -73,17 +75,27 @@ void ViewFrustum::dump() { printf("nearHeight=%f\n",this->_nearHeight); printf("nearWidth=%f\n",this->_nearWidth); - printf("farCenter.x=%f, farCenter.y=%f, farCenter.z=%f\n",this->_farCenter.x,this->_farCenter.y,this->_farCenter.z); - printf("farTopLeft.x=%f, farTopLeft.y=%f, farTopLeft.z=%f\n",this->_farTopLeft.x,this->_farTopLeft.y,this->_farTopLeft.z); - printf("farTopRight.x=%f, farTopRight.y=%f, farTopRight.z=%f\n",this->_farTopRight.x,this->_farTopRight.y,this->_farTopRight.z); - printf("farBottomLeft.x=%f, farBottomLeft.y=%f, farBottomLeft.z=%f\n",this->_farBottomLeft.x,this->_farBottomLeft.y,this->_farBottomLeft.z); - printf("farBottomRight.x=%f, farBottomRight.y=%f, farBottomRight.z=%f\n",this->_farBottomRight.x,this->_farBottomRight.y,this->_farBottomRight.z); + printf("farCenter.x=%f, farCenter.y=%f, farCenter.z=%f\n", + this->_farCenter.x,this->_farCenter.y,this->_farCenter.z); + printf("farTopLeft.x=%f, farTopLeft.y=%f, farTopLeft.z=%f\n", + this->_farTopLeft.x,this->_farTopLeft.y,this->_farTopLeft.z); + printf("farTopRight.x=%f, farTopRight.y=%f, farTopRight.z=%f\n", + this->_farTopRight.x,this->_farTopRight.y,this->_farTopRight.z); + printf("farBottomLeft.x=%f, farBottomLeft.y=%f, farBottomLeft.z=%f\n", + this->_farBottomLeft.x,this->_farBottomLeft.y,this->_farBottomLeft.z); + printf("farBottomRight.x=%f, farBottomRight.y=%f, farBottomRight.z=%f\n", + this->_farBottomRight.x,this->_farBottomRight.y,this->_farBottomRight.z); - printf("nearCenter.x=%f, nearCenter.y=%f, nearCenter.z=%f\n",this->_nearCenter.x,this->_nearCenter.y,this->_nearCenter.z); - printf("nearTopLeft.x=%f, nearTopLeft.y=%f, nearTopLeft.z=%f\n",this->_nearTopLeft.x,this->_nearTopLeft.y,this->_nearTopLeft.z); - printf("nearTopRight.x=%f, nearTopRight.y=%f, nearTopRight.z=%f\n",this->_nearTopRight.x,this->_nearTopRight.y,this->_nearTopRight.z); - printf("nearBottomLeft.x=%f, nearBottomLeft.y=%f, nearBottomLeft.z=%f\n",this->_nearBottomLeft.x,this->_nearBottomLeft.y,this->_nearBottomLeft.z); - printf("nearBottomRight.x=%f, nearBottomRight.y=%f, nearBottomRight.z=%f\n",this->_nearBottomRight.x,this->_nearBottomRight.y,this->_nearBottomRight.z); + printf("nearCenter.x=%f, nearCenter.y=%f, nearCenter.z=%f\n", + this->_nearCenter.x,this->_nearCenter.y,this->_nearCenter.z); + printf("nearTopLeft.x=%f, nearTopLeft.y=%f, nearTopLeft.z=%f\n", + this->_nearTopLeft.x,this->_nearTopLeft.y,this->_nearTopLeft.z); + printf("nearTopRight.x=%f, nearTopRight.y=%f, nearTopRight.z=%f\n", + this->_nearTopRight.x,this->_nearTopRight.y,this->_nearTopRight.z); + printf("nearBottomLeft.x=%f, nearBottomLeft.y=%f, nearBottomLeft.z=%f\n", + this->_nearBottomLeft.x,this->_nearBottomLeft.y,this->_nearBottomLeft.z); + printf("nearBottomRight.x=%f, nearBottomRight.y=%f, nearBottomRight.z=%f\n", + this->_nearBottomRight.x,this->_nearBottomRight.y,this->_nearBottomRight.z); } From 7c7c931e8384a398b39c1e3e168624049a5206fa Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Fri, 12 Apr 2013 17:10:04 -0700 Subject: [PATCH 12/27] fixed build buster after merge --- interface/src/Head.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interface/src/Head.h b/interface/src/Head.h index eeaa4ebee0..74026aac79 100644 --- a/interface/src/Head.h +++ b/interface/src/Head.h @@ -256,7 +256,7 @@ class Head : public AgentData { float springVelocityDecay; float springForce; - //float springToBodyTightness; + float springToBodyTightness; // XXXBHG - this had been commented out, but build breaks without it. int eyeContact; eyeContactTargets eyeContactTarget; From ca4286590e170dda6a52b99f75115ee6c3a9c475 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Fri, 12 Apr 2013 17:14:08 -0700 Subject: [PATCH 13/27] fixed column width to match codeing standard --- libraries/voxels/src/ViewFrustum.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/libraries/voxels/src/ViewFrustum.h b/libraries/voxels/src/ViewFrustum.h index 586553412e..02c7c39bcc 100644 --- a/libraries/voxels/src/ViewFrustum.h +++ b/libraries/voxels/src/ViewFrustum.h @@ -54,9 +54,11 @@ public: const glm::vec3& getNearBottomLeft() const { return _nearBottomLeft; }; const glm::vec3& getNearBottomRight() const { return _nearBottomRight; }; - void calculateViewFrustum(glm::vec3 position, glm::vec3 direction, glm::vec3 up, glm::vec3 right, float screenWidth, float screenHeight); + void calculateViewFrustum(glm::vec3 position, glm::vec3 direction, + glm::vec3 up, glm::vec3 right, float screenWidth, float screenHeight); - ViewFrustum(glm::vec3 position, glm::vec3 direction, glm::vec3 up, glm::vec3 right, float screenWidth, float screenHeight); + ViewFrustum(glm::vec3 position, glm::vec3 direction, + glm::vec3 up, glm::vec3 right, float screenWidth, float screenHeight); void dump(); }; From 54ba0d022446abc510d510db894ac9c9cfa335ec Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Fri, 12 Apr 2013 17:23:23 -0700 Subject: [PATCH 14/27] cleaned up spacing for code review --- libraries/voxels/src/ViewFrustum.cpp | 64 +++++++++++++++------------- 1 file changed, 34 insertions(+), 30 deletions(-) diff --git a/libraries/voxels/src/ViewFrustum.cpp b/libraries/voxels/src/ViewFrustum.cpp index b7fae39ca5..477e049e93 100644 --- a/libraries/voxels/src/ViewFrustum.cpp +++ b/libraries/voxels/src/ViewFrustum.cpp @@ -47,55 +47,59 @@ void ViewFrustum::calculateViewFrustum(glm::vec3 position, glm::vec3 direction, this->_farHeight = 2 * tan(fovHalfAngle) * this->_farDist; this->_farWidth = this->_farHeight * ratio; - this->_farCenter = this->_position+front*this->_farDist; - this->_farTopLeft = this->_farCenter + (this->_up*this->_farHeight*0.5f) - (this->_right*this->_farWidth*0.5f); - this->_farTopRight = this->_farCenter + (this->_up*this->_farHeight*0.5f) + (this->_right*this->_farWidth*0.5f); - this->_farBottomLeft = this->_farCenter - (this->_up*this->_farHeight*0.5f) - (this->_right*this->_farWidth*0.5f); - this->_farBottomRight = this->_farCenter - (this->_up*this->_farHeight*0.5f) + (this->_right*this->_farWidth*0.5f); + float farHalfHeight = this->_farHeight * 0.5f; + float farHalfWidth = this->_farWidth * 0.5f; + this->_farCenter = this->_position+front * this->_farDist; + this->_farTopLeft = this->_farCenter + (this->_up * farHalfHeight) - (this->_right * farHalfWidth); + this->_farTopRight = this->_farCenter + (this->_up * farHalfHeight) + (this->_right * farHalfWidth); + this->_farBottomLeft = this->_farCenter - (this->_up * farHalfHeight) - (this->_right * farHalfWidth); + this->_farBottomRight = this->_farCenter - (this->_up * farHalfHeight) + (this->_right * farHalfWidth); - this->_nearCenter = this->_position+front*this->_nearDist; - this->_nearTopLeft = this->_nearCenter + (this->_up*this->_nearHeight*0.5f) - (this->_right*this->_nearWidth*0.5f); - this->_nearTopRight = this->_nearCenter + (this->_up*this->_nearHeight*0.5f) + (this->_right*this->_nearWidth*0.5f); - this->_nearBottomLeft = this->_nearCenter - (this->_up*this->_nearHeight*0.5f) - (this->_right*this->_nearWidth*0.5f); - this->_nearBottomRight = this->_nearCenter - (this->_up*this->_nearHeight*0.5f) + (this->_right*this->_nearWidth*0.5f); + float nearHalfHeight = this->_nearHeight * 0.5f; + float nearHalfWidth = this->_nearWidth * 0.5f; + this->_nearCenter = this->_position+front * this->_nearDist; + this->_nearTopLeft = this->_nearCenter + (this->_up * nearHalfHeight) - (this->_right * nearHalfWidth); + this->_nearTopRight = this->_nearCenter + (this->_up * nearHalfHeight) + (this->_right * nearHalfWidth); + this->_nearBottomLeft = this->_nearCenter - (this->_up * nearHalfHeight) - (this->_right * nearHalfWidth); + this->_nearBottomRight = this->_nearCenter - (this->_up * nearHalfHeight) + (this->_right * nearHalfWidth); } void ViewFrustum::dump() { - printf("position.x=%f, position.y=%f, position.z=%f\n",this->_position.x,this->_position.y,this->_position.z); - printf("direction.x=%f, direction.y=%f, direction.z=%f\n",this->_direction.x,this->_direction.y,this->_direction.z); - printf("up.x=%f, up.y=%f, up.z=%f\n",this->_up.x,this->_up.y,this->_up.z); - printf("right.x=%f, right.y=%f, right.z=%f\n",this->_right.x,this->_right.y,this->_right.z); + printf("position.x=%f, position.y=%f, position.z=%f\n", this->_position.x, this->_position.y, this->_position.z); + printf("direction.x=%f, direction.y=%f, direction.z=%f\n", this->_direction.x, this->_direction.y, this->_direction.z); + printf("up.x=%f, up.y=%f, up.z=%f\n", this->_up.x, this->_up.y, this->_up.z); + printf("right.x=%f, right.y=%f, right.z=%f\n", this->_right.x, this->_right.y, this->_right.z); - printf("farDist=%f\n",this->_farDist); - printf("farHeight=%f\n",this->_farHeight); - printf("farWidth=%f\n",this->_farWidth); + printf("farDist=%f\n", this->_farDist); + printf("farHeight=%f\n", this->_farHeight); + printf("farWidth=%f\n", this->_farWidth); - printf("nearDist=%f\n",this->_nearDist); - printf("nearHeight=%f\n",this->_nearHeight); - printf("nearWidth=%f\n",this->_nearWidth); + printf("nearDist=%f\n", this->_nearDist); + printf("nearHeight=%f\n", this->_nearHeight); + printf("nearWidth=%f\n", this->_nearWidth); printf("farCenter.x=%f, farCenter.y=%f, farCenter.z=%f\n", - this->_farCenter.x,this->_farCenter.y,this->_farCenter.z); + this->_farCenter.x, this->_farCenter.y, this->_farCenter.z); printf("farTopLeft.x=%f, farTopLeft.y=%f, farTopLeft.z=%f\n", - this->_farTopLeft.x,this->_farTopLeft.y,this->_farTopLeft.z); + this->_farTopLeft.x, this->_farTopLeft.y, this->_farTopLeft.z); printf("farTopRight.x=%f, farTopRight.y=%f, farTopRight.z=%f\n", - this->_farTopRight.x,this->_farTopRight.y,this->_farTopRight.z); + this->_farTopRight.x, this->_farTopRight.y, this->_farTopRight.z); printf("farBottomLeft.x=%f, farBottomLeft.y=%f, farBottomLeft.z=%f\n", - this->_farBottomLeft.x,this->_farBottomLeft.y,this->_farBottomLeft.z); + this->_farBottomLeft.x, this->_farBottomLeft.y, this->_farBottomLeft.z); printf("farBottomRight.x=%f, farBottomRight.y=%f, farBottomRight.z=%f\n", - this->_farBottomRight.x,this->_farBottomRight.y,this->_farBottomRight.z); + this->_farBottomRight.x, this->_farBottomRight.y, this->_farBottomRight.z); printf("nearCenter.x=%f, nearCenter.y=%f, nearCenter.z=%f\n", - this->_nearCenter.x,this->_nearCenter.y,this->_nearCenter.z); + this->_nearCenter.x, this->_nearCenter.y, this->_nearCenter.z); printf("nearTopLeft.x=%f, nearTopLeft.y=%f, nearTopLeft.z=%f\n", - this->_nearTopLeft.x,this->_nearTopLeft.y,this->_nearTopLeft.z); + this->_nearTopLeft.x, this->_nearTopLeft.y, this->_nearTopLeft.z); printf("nearTopRight.x=%f, nearTopRight.y=%f, nearTopRight.z=%f\n", - this->_nearTopRight.x,this->_nearTopRight.y,this->_nearTopRight.z); + this->_nearTopRight.x, this->_nearTopRight.y, this->_nearTopRight.z); printf("nearBottomLeft.x=%f, nearBottomLeft.y=%f, nearBottomLeft.z=%f\n", - this->_nearBottomLeft.x,this->_nearBottomLeft.y,this->_nearBottomLeft.z); + this->_nearBottomLeft.x, this->_nearBottomLeft.y, this->_nearBottomLeft.z); printf("nearBottomRight.x=%f, nearBottomRight.y=%f, nearBottomRight.z=%f\n", - this->_nearBottomRight.x,this->_nearBottomRight.y,this->_nearBottomRight.z); + this->_nearBottomRight.x, this->_nearBottomRight.y, this->_nearBottomRight.z); } From 505b2db9350044add489189afb1e70916d2b5420 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Fri, 12 Apr 2013 17:27:54 -0700 Subject: [PATCH 15/27] 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 1d69acef56729be19f2267565a1206d815fe7b44 Mon Sep 17 00:00:00 2001 From: Philip Rosedale Date: Fri, 12 Apr 2013 21:01:01 -0700 Subject: [PATCH 16/27] Removed hand class files, relocated transmitter receiver function to Head.h --- interface/src/Hand.cpp | 225 ----------------------------------------- interface/src/Hand.h | 47 --------- interface/src/Head.cpp | 57 +++++++++-- interface/src/Head.h | 15 ++- interface/src/main.cpp | 20 ++-- 5 files changed, 72 insertions(+), 292 deletions(-) delete mode 100644 interface/src/Hand.cpp delete mode 100644 interface/src/Hand.h diff --git a/interface/src/Hand.cpp b/interface/src/Hand.cpp deleted file mode 100644 index 4cca3017dc..0000000000 --- a/interface/src/Hand.cpp +++ /dev/null @@ -1,225 +0,0 @@ -// -// Hand.cpp -// interface -// -// Created by Philip Rosedale on 10/13/12. -// Copyright (c) 2012 High Fidelity, Inc. All rights reserved. -// - -#include "Hand.h" - -#ifdef _WIN32 -#include "Systime.h" -#else -#include -#endif - -const float PHI = 1.618f; - -const float DEFAULT_X = 0; -const float DEFAULT_Y = -1.5; -const float DEFAULT_Z = 2.0; -const float DEFAULT_TRANSMITTER_HZ = 60.0; - -Hand::Hand(glm::vec3 initcolor) { - color = initcolor; - reset(); - noise = 0.0; //0.2; - scale.x = 0.07f; - scale.y = scale.x * 5.0f; - scale.z = scale.y * 1.0f; - renderPointer = true; -} - -Hand::Hand(const Hand &otherHand) { - color = otherHand.color; - noise = otherHand.noise; - scale = otherHand.scale; - position = otherHand.position; - target = otherHand.target; - velocity = otherHand.color; - pitch = otherHand.pitch; - yaw = otherHand.yaw; - roll = otherHand.roll; - pitchRate = otherHand.pitchRate; - yawRate = otherHand.yawRate; - rollRate = otherHand.rollRate; - transmitterTimer = otherHand.transmitterTimer; - transmitterHz = otherHand.transmitterHz; - transmitterPackets = otherHand.transmitterPackets; - renderPointer = otherHand.renderPointer; -} - -void Hand::reset() { - position.x = DEFAULT_X; - position.y = DEFAULT_Y; - position.z = DEFAULT_Z; - pitch = yaw = roll = 0; - pitchRate = yawRate = rollRate = 0; - setTarget(position); - velocity.x = velocity.y = velocity.z = 0; - transmitterPackets = 0; - transmitterHz = DEFAULT_TRANSMITTER_HZ; -} - -void Hand::render(int isMine) { - const float POINTER_LENGTH = 20.0; - glPushMatrix(); - glTranslatef(position.x, position.y, position.z); - glRotatef(yaw, 0, 1, 0); - glRotatef(pitch, 1, 0, 0); - glRotatef(roll, 0, 0, 1); - glColor3f(color.x, color.y, color.z); - glScalef(scale.x, scale.y, scale.z); - //glutSolidSphere(1.5, 20, 20); - glutSolidCube(1.0); - if (renderPointer) { - glBegin(GL_TRIANGLES); - glColor3f(1,0,0); - glNormal3f(0,-1,0); - glVertex3f(-0.4f,0,0); - glVertex3f(0.4f,0,0); - glVertex3f(0,0,-POINTER_LENGTH); - glEnd(); - glPushMatrix(); - glTranslatef(0,0,-POINTER_LENGTH); - glutSolidCube(1.0); - glPopMatrix(); - } - glPopMatrix(); -} - -void Hand::addAngularVelocity (float pRate, float yRate, float rRate) { - pitchRate += pRate; - yawRate += yRate; - rollRate += rRate; -} - -void Hand::processTransmitterData(char *packetData, int numBytes) { - // Read a packet from a transmitter app, process the data - float accX, accY, accZ, - graX, graY, graZ, - gyrX, gyrY, gyrZ, - linX, linY, linZ, - rot1, rot2, rot3, rot4; - sscanf((char *)packetData, "tacc %f %f %f gra %f %f %f gyr %f %f %f lin %f %f %f rot %f %f %f %f", - &accX, &accY, &accZ, - &graX, &graY, &graZ, - &gyrX, &gyrY, &gyrZ, - &linX, &linY, &linZ, - &rot1, &rot2, &rot3, &rot4); - - if (transmitterPackets++ == 0) { - gettimeofday(&transmitterTimer, NULL); - } - const int TRANSMITTER_COUNT = 100; - if (transmitterPackets % TRANSMITTER_COUNT == 0) { - // Every 100 packets, record the observed Hz of the transmitter data - timeval now; - gettimeofday(&now, NULL); - double msecsElapsed = diffclock(&transmitterTimer, &now); - transmitterHz = static_cast( (double)TRANSMITTER_COUNT/(msecsElapsed/1000.0) ); - //std::cout << "Transmitter Hz: " << (float)TRANSMITTER_COUNT/(msecsElapsed/1000.0) << "\n"; - //memcpy(&transmitterTimer, &now, sizeof(timeval)); - transmitterTimer = now; - } - // Add rotational forces to the hand - const float ANG_VEL_SENSITIVITY = 4.0; - const float ANG_VEL_THRESHOLD = 0.0; - float angVelScale = ANG_VEL_SENSITIVITY*(1.0f/getTransmitterHz()); - //addAngularVelocity(gyrX*angVelScale,gyrZ*angVelScale,-gyrY*angVelScale); - addAngularVelocity(fabs(gyrX*angVelScale)>ANG_VEL_THRESHOLD?gyrX*angVelScale:0, - fabs(gyrZ*angVelScale)>ANG_VEL_THRESHOLD?gyrZ*angVelScale:0, - fabs(-gyrY*angVelScale)>ANG_VEL_THRESHOLD?-gyrY*angVelScale:0); - - // Add linear forces to the hand - //const float LINEAR_VEL_SENSITIVITY = 50.0; - const float LINEAR_VEL_SENSITIVITY = 5.0; - float linVelScale = LINEAR_VEL_SENSITIVITY*(1.0f/getTransmitterHz()); - glm::vec3 linVel(linX*linVelScale, linZ*linVelScale, -linY*linVelScale); - addVelocity(linVel); - -} - -void Hand::simulate(float deltaTime) { - const float ANGULAR_SPRING_CONSTANT = 0.25; - const float ANGULAR_DAMPING_COEFFICIENT = 5*2.0f*powf(ANGULAR_SPRING_CONSTANT,0.5f); - const float LINEAR_SPRING_CONSTANT = 100; - const float LINEAR_DAMPING_COEFFICIENT = 2.0f*powf(LINEAR_SPRING_CONSTANT,0.5f); - - // If noise, add a bit of random velocity - const float RNOISE = 0.0; - const float VNOISE = 0.01f; - if (noise) { - - glm::vec3 nVel(randFloat() - 0.5f, randFloat() - 0.5f, randFloat() - 0.5f); - nVel *= VNOISE; - addVelocity(nVel); - - addAngularVelocity(RNOISE*(randFloat() - 0.5f), - RNOISE*(randFloat() - 0.5f), - RNOISE*(randFloat() - 0.5f)); - } - position += velocity*deltaTime; - - pitch += pitchRate; - yaw += yawRate; - roll += rollRate; - - // The spring method - if (0) { - // Use a linear spring to attempt to return the hand to the target position - glm::vec3 springForce = target - position; - springForce *= LINEAR_SPRING_CONSTANT; - addVelocity(springForce * deltaTime); - - // Critically damp the linear spring - glm::vec3 dampingForce(velocity); - dampingForce *= LINEAR_DAMPING_COEFFICIENT; - addVelocity(-dampingForce * deltaTime); - - // Use angular spring to return hand to target rotation (0,0,0) - addAngularVelocity(-pitch * ANGULAR_SPRING_CONSTANT * deltaTime, - -yaw * ANGULAR_SPRING_CONSTANT * deltaTime, - -roll * ANGULAR_SPRING_CONSTANT * deltaTime); - - // Critically damp angular spring - addAngularVelocity(-pitchRate*ANGULAR_DAMPING_COEFFICIENT*deltaTime, - -yawRate*ANGULAR_DAMPING_COEFFICIENT*deltaTime, - -rollRate*ANGULAR_DAMPING_COEFFICIENT*deltaTime); - } - - // The absolute limits method (no springs) - if (1) { - // Limit rotation - const float YAW_LIMIT = 20; - const float PITCH_LIMIT = 20; - - if (yaw > YAW_LIMIT) { yaw = YAW_LIMIT; yawRate = 0.0; } - if (yaw < -YAW_LIMIT) { yaw = -YAW_LIMIT; yawRate = 0.0; } - if (pitch > PITCH_LIMIT) { pitch = PITCH_LIMIT; pitchRate = 0.0; } - if (pitch < -PITCH_LIMIT) { pitch = -PITCH_LIMIT; pitchRate = 0.0; } - - // Damp Rotation Rates - yawRate *= 0.99f; - pitchRate *= 0.99f; - rollRate *= 0.99f; - - // Limit position - const float X_LIMIT = 1.0; - const float Y_LIMIT = 1.0; - const float Z_LIMIT = 1.0; - - if (position.x > DEFAULT_X + X_LIMIT) { position.x = DEFAULT_X + X_LIMIT; velocity.x = 0; } - if (position.x < DEFAULT_X - X_LIMIT) { position.x = DEFAULT_X - X_LIMIT; velocity.x = 0; } - if (position.y > DEFAULT_Y + Y_LIMIT) { position.y = DEFAULT_Y + Y_LIMIT; velocity.y = 0; } - if (position.y < DEFAULT_Y - Y_LIMIT) { position.y = DEFAULT_Y - Y_LIMIT; velocity.y = 0; } - if (position.z > DEFAULT_Z + Z_LIMIT) { position.z = DEFAULT_Z + Z_LIMIT; velocity.z = 0; } - if (position.z < DEFAULT_Z - Z_LIMIT) { position.z = DEFAULT_Z - Z_LIMIT; velocity.z = 0; } - - // Damp Velocity - velocity *= 0.99; - - } - -} \ No newline at end of file diff --git a/interface/src/Hand.h b/interface/src/Hand.h deleted file mode 100644 index cf887a897f..0000000000 --- a/interface/src/Hand.h +++ /dev/null @@ -1,47 +0,0 @@ -// -// Hand.h -// interface -// -// Created by Philip Rosedale on 10/13/12. -// Copyright (c) 2012 High Fidelity, Inc. All rights reserved. -// - -#ifndef __interface__Hand__ -#define __interface__Hand__ - -#include -#include -#include "Util.h" -#include "Field.h" -#include "world.h" -#include "InterfaceConfig.h" - -class Hand { -public: - Hand(glm::vec3 color); - Hand(const Hand &otherHand); - void simulate (float deltaTime); - void render (int isMine); - void reset (); - void setNoise (float mag) { noise = mag; }; - void addVelocity (glm::vec3 v) { velocity += v; }; - void addAngularVelocity (float pRate, float yRate, float rRate); - glm::vec3 getPos() { return position; }; - void setPos(glm::vec3 p) { position = p; }; - void setTarget(glm::vec3 t) { target = t; }; - void processTransmitterData(char * packetData, int numBytes); - float getTransmitterHz() { return transmitterHz; }; - void setRenderPointer(bool p) { renderPointer = p; }; -private: - glm::vec3 position, target, velocity, color, scale; - float pitch, yaw, roll, pitchRate, yawRate, rollRate; - float noise; - timeval transmitterTimer; - float transmitterHz; - int transmitterPackets; - bool renderPointer; - -}; - - -#endif diff --git a/interface/src/Head.cpp b/interface/src/Head.cpp index 1a70ba9a13..e8ab9d6add 100644 --- a/interface/src/Head.cpp +++ b/interface/src/Head.cpp @@ -97,8 +97,6 @@ Head::Head() { springForce = 6.0f; springVelocityDecay = 16.0f; - hand = new Hand(glm::vec3(skinColor[0], skinColor[1], skinColor[2])); - if (iris_texture.size() == 0) { switchToResourcesIfRequired(); unsigned error = lodepng::decode(iris_texture, iris_texture_width, iris_texture_height, iris_texture_file); @@ -174,12 +172,8 @@ Head::Head(const Head &otherHead) { sphere = NULL; - Hand newHand = Hand(*otherHead.hand); - hand = &newHand; } - - Head::~Head() { if (sphere != NULL) { gluDeleteQuadric(sphere); @@ -1224,10 +1218,55 @@ void Head::parseData(void *data, int size) { handBeingMoved = true; } - - - void Head::SetNewHeadTarget(float pitch, float yaw) { PitchTarget = pitch; YawTarget = yaw; } + +void Head::processTransmitterData(char *packetData, int numBytes) { + // Read a packet from a transmitter app, process the data + float accX, accY, accZ, + graX, graY, graZ, + gyrX, gyrY, gyrZ, + linX, linY, linZ, + rot1, rot2, rot3, rot4; + sscanf((char *)packetData, "tacc %f %f %f gra %f %f %f gyr %f %f %f lin %f %f %f rot %f %f %f %f", + &accX, &accY, &accZ, + &graX, &graY, &graZ, + &gyrX, &gyrY, &gyrZ, + &linX, &linY, &linZ, + &rot1, &rot2, &rot3, &rot4); + + if (transmitterPackets++ == 0) { + gettimeofday(&transmitterTimer, NULL); + } + const int TRANSMITTER_COUNT = 100; + if (transmitterPackets % TRANSMITTER_COUNT == 0) { + // Every 100 packets, record the observed Hz of the transmitter data + timeval now; + gettimeofday(&now, NULL); + double msecsElapsed = diffclock(&transmitterTimer, &now); + transmitterHz = static_cast( (double)TRANSMITTER_COUNT/(msecsElapsed/1000.0) ); + transmitterTimer = now; + } + /* NOTE: PR: Will add back in when ready to animate avatar hand + + // Add rotational forces to the hand + const float ANG_VEL_SENSITIVITY = 4.0; + const float ANG_VEL_THRESHOLD = 0.0; + float angVelScale = ANG_VEL_SENSITIVITY*(1.0f/getTransmitterHz()); + + addAngularVelocity(fabs(gyrX*angVelScale)>ANG_VEL_THRESHOLD?gyrX*angVelScale:0, + fabs(gyrZ*angVelScale)>ANG_VEL_THRESHOLD?gyrZ*angVelScale:0, + fabs(-gyrY*angVelScale)>ANG_VEL_THRESHOLD?-gyrY*angVelScale:0); + + // Add linear forces to the hand + //const float LINEAR_VEL_SENSITIVITY = 50.0; + const float LINEAR_VEL_SENSITIVITY = 5.0; + float linVelScale = LINEAR_VEL_SENSITIVITY*(1.0f/getTransmitterHz()); + glm::vec3 linVel(linX*linVelScale, linZ*linVelScale, -linY*linVelScale); + addVelocity(linVel); + */ + +} + diff --git a/interface/src/Head.h b/interface/src/Head.h index eeaa4ebee0..5041133c29 100644 --- a/interface/src/Head.h +++ b/interface/src/Head.h @@ -13,7 +13,6 @@ #include "AgentData.h" #include "Field.h" #include "world.h" -#include "Hand.h" #include "Orientation.h" // added by Ventrella as a utility #include "InterfaceConfig.h" #include "SerialInterface.h" @@ -196,7 +195,12 @@ class Head : public AgentData { void addThrust(glm::vec3 newThrust) { avatar.thrust += newThrust; }; glm::vec3 getThrust() { return avatar.thrust; }; - Hand * hand; + // + // Related to getting transmitter UDP data used to animate the avatar hand + // + + void processTransmitterData(char * packetData, int numBytes); + float getTransmitterHz() { return transmitterHz; }; private: float noise; @@ -273,6 +277,13 @@ class Head : public AgentData { void readSensors(); float renderYaw, renderPitch; // Pitch from view frustum when this is own head. + // + // Related to getting transmitter UDP data used to animate the avatar hand + // + timeval transmitterTimer; + float transmitterHz; + int transmitterPackets; + }; #endif diff --git a/interface/src/main.cpp b/interface/src/main.cpp index 909227a91f..8f254a8946 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -60,9 +60,8 @@ #include "MenuRow.h" #include "MenuColumn.h" #include "Menu.h" -#include "Head.h" -#include "Hand.h" #include "Camera.h" +#include "Head.h" #include "Particle.h" #include "Texture.h" #include "Cloud.h" @@ -372,12 +371,13 @@ void simulateHand(float deltaTime) { // If mouse is being dragged, send current force to the hand controller if (mousePressed == 1) { - // Add a velocity to the hand corresponding to the detected size of the drag vector + // NOTE--PER: Need to re-implement when ready for new avatar hand movements + const float MOUSE_HAND_FORCE = 1.5; float dx = mouseX - mouseStartX; float dy = mouseY - mouseStartY; glm::vec3 vel(dx*MOUSE_HAND_FORCE, -dy*MOUSE_HAND_FORCE*(WIDTH/HEIGHT), 0); - myAvatar.hand->addVelocity(vel*deltaTime); + //myAvatar.hand->addVelocity(vel*deltaTime); } } @@ -799,7 +799,12 @@ void display(void) // Test - Draw a blue sphere around a body part of mine! glPushMatrix(); - //glTranslate3f(myAvatar.GetRight + glColor4f(0,0,1, 0.7); + glTranslatef(myAvatar.getBonePosition(AVATAR_BONE_RIGHT_HAND).x, + myAvatar.getBonePosition(AVATAR_BONE_RIGHT_HAND).y, + myAvatar.getBonePosition(AVATAR_BONE_RIGHT_HAND).z); + glutSolidSphere(0.03, 10, 10); + glPopMatrix(); // draw a red sphere @@ -1208,7 +1213,7 @@ void *networkReceive(void *args) switch (incomingPacket[0]) { case PACKET_HEADER_TRANSMITTER_DATA: - myAvatar.hand->processTransmitterData(incomingPacket, bytesReceived); + myAvatar.processTransmitterData(incomingPacket, bytesReceived); break; case PACKET_HEADER_VOXEL_DATA: case PACKET_HEADER_Z_COMMAND: @@ -1405,7 +1410,6 @@ int main(int argc, const char * argv[]) initDisplay(); printf( "Initialized Display.\n" ); - glutDisplayFunc(display); glutReshapeFunc(reshape); glutKeyboardFunc(key); @@ -1417,11 +1421,9 @@ int main(int argc, const char * argv[]) glutMouseFunc(mouseFunc); glutIdleFunc(idle); - init(); printf( "Init() complete.\n" ); - // Check to see if the user passed in a command line option for randomizing colors if (cmdOptionExists(argc, argv, "--NoColorRandomizer")) { wantColorRandomizer = false; From 98c82281617024be851f916a3d2087be0fc2b7f6 Mon Sep 17 00:00:00 2001 From: Philip Rosedale Date: Fri, 12 Apr 2013 21:11:03 -0700 Subject: [PATCH 17/27] had to take out call to myAvatar.getBonePosition - unclear why it now isn't working. --- interface/src/main.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/interface/src/main.cpp b/interface/src/main.cpp index ed9a9b4782..23c89824de 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -742,6 +742,8 @@ void display(void) glEnable(GL_LIGHTING); glEnable(GL_DEPTH_TEST); + + /* // Test - Draw a blue sphere around a body part of mine! glPushMatrix(); @@ -750,8 +752,8 @@ void display(void) myAvatar.getBonePosition(AVATAR_BONE_RIGHT_HAND).y, myAvatar.getBonePosition(AVATAR_BONE_RIGHT_HAND).z); glutSolidSphere(0.03, 10, 10); - glPopMatrix(); + */ // draw a red sphere float sphereRadius = 0.25f; From 093f489520f9024c5f6a88682f7c809021d6a8b8 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Sat, 13 Apr 2013 13:07:02 -0700 Subject: [PATCH 18/27] 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 19/27] 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 20/27] 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 21/27] 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 22/27] 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 23/27] 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; From e6a1fb416d26fd8cb8550e8a24fffca83edfb19a Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Sat, 13 Apr 2013 15:58:10 -0700 Subject: [PATCH 24/27] improved the menu states names for frustum rendering modes --- interface/src/main.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/interface/src/main.cpp b/interface/src/main.cpp index 5288eafd30..4ad4537c4a 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -982,11 +982,11 @@ int setFrustumRenderMode(int state) { 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* modeAll = " - All "; +const char* modeVectors = " - Vectors "; +const char* modePlanes = " - Planes "; +const char* modeNear = " - Near "; +const char* modeFar = " - Far "; const char* getFrustumRenderModeName(int state) { const char * mode; From bd837862deac502b09d6f987f0a38da5093c08ef Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Sat, 13 Apr 2013 16:16:10 -0700 Subject: [PATCH 25/27] fixed lighting when in frustum render mode --- interface/src/main.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/interface/src/main.cpp b/interface/src/main.cpp index 4ad4537c4a..afbff94616 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -649,8 +649,9 @@ void render_view_frustum() { glVertex3f(vf.getNearTopLeft().x, vf.getNearTopLeft().y, vf.getNearTopLeft().z); glVertex3f(vf.getFarTopLeft().x, vf.getFarTopLeft().y, vf.getFarTopLeft().z); } - + glEnd(); + glEnable(GL_LIGHTING); } From 24689e97ab5217bdad74917aa10a3a2138f7a617 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Mon, 15 Apr 2013 11:12:31 -0700 Subject: [PATCH 26/27] fix packing and unpacking of agent IDs --- libraries/shared/src/AgentList.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/shared/src/AgentList.cpp b/libraries/shared/src/AgentList.cpp index f973b3de1d..4895e421cd 100644 --- a/libraries/shared/src/AgentList.cpp +++ b/libraries/shared/src/AgentList.cpp @@ -427,11 +427,11 @@ void AgentList::stopDomainServerCheckInThread() { } int unpackAgentId(unsigned char *packedData, uint16_t *agentId) { - memcpy(packedData, agentId, sizeof(uint16_t)); + memcpy(agentId, packedData, sizeof(uint16_t)); return sizeof(uint16_t); } int packAgentId(unsigned char *packStore, uint16_t agentId) { - memcpy(&agentId, packStore, sizeof(uint16_t)); + memcpy(packStore, &agentId, sizeof(uint16_t)); return sizeof(uint16_t); } From 613d5ab5f6fa5ac39a5a8a678ceef0b352adf0d1 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Mon, 15 Apr 2013 11:27:27 -0700 Subject: [PATCH 27/27] pack agent ID, not socket, from avatar mixer --- avatar-mixer/src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/avatar-mixer/src/main.cpp b/avatar-mixer/src/main.cpp index f59a2f8bcb..8aa57c0ad4 100644 --- a/avatar-mixer/src/main.cpp +++ b/avatar-mixer/src/main.cpp @@ -38,7 +38,7 @@ const int AVATAR_LISTEN_PORT = 55444; const unsigned short BROADCAST_INTERVAL_USECS = 20 * 1000 * 1000; unsigned char *addAgentToBroadcastPacket(unsigned char *currentPosition, Agent *agentToAdd) { - currentPosition += packSocket(currentPosition, agentToAdd->getPublicSocket()); + currentPosition += packAgentId(currentPosition, agentToAdd->getAgentId()); AvatarAgentData *agentData = (AvatarAgentData *)agentToAdd->getLinkedData();