From 7f1ba5c73301f4f9999f6b7032ba419eebb19058 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Fri, 12 Apr 2013 11:26:32 -0700 Subject: [PATCH 01/12] 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 02/12] 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 03/12] 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 04/12] 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 05/12] 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 06/12] 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 84ca2dcb321c68f53c651929945c4d9fce148595 Mon Sep 17 00:00:00 2001 From: Jeffrey Ventrella Date: Fri, 12 Apr 2013 16:12:31 -0700 Subject: [PATCH 07/12] added get avatar bone --- interface/src/Head.cpp | 70 ++++++++++++++++++++++++++++++++++-------- interface/src/Head.h | 4 ++- interface/src/Util.h | 2 +- 3 files changed, 61 insertions(+), 15 deletions(-) diff --git a/interface/src/Head.cpp b/interface/src/Head.cpp index 600dc3f0ca..1a70ba9a13 100644 --- a/interface/src/Head.cpp +++ b/interface/src/Head.cpp @@ -95,7 +95,6 @@ Head::Head() { usingSprings = false; springForce = 6.0f; - springToBodyTightness = 4.0f; springVelocityDecay = 16.0f; hand = new Hand(glm::vec3(skinColor[0], skinColor[1], skinColor[2])); @@ -782,23 +781,27 @@ void Head::setHandMovement( glm::vec3 movement ) { void Head::initializeAvatar() { - //avatar.position = glm::vec3( 0.0, 0.0, 0.0 ); avatar.velocity = glm::vec3( 0.0, 0.0, 0.0 ); avatar.thrust = glm::vec3( 0.0, 0.0, 0.0 ); avatar.orientation.setToIdentity(); closestOtherAvatar = 0; - bodyYaw = -90.0; - bodyPitch = 0.0; - bodyRoll = 0.0; - - bodyYawDelta = 0.0; + bodyYaw = -90.0; + bodyPitch = 0.0; + bodyRoll = 0.0; + bodyYawDelta = 0.0; for (int b=0; b 0.0f ) { glm::vec3 springDirection = springVector / length; - float force = ( length - avatar.bone[b].length ) * springForce * deltaTime; + float force = ( length - avatar.bone[b].length ) * springForce * deltaTime; avatar.bone[ b ].springyVelocity -= springDirection * force; avatar.bone[ avatar.bone[b].parent ].springyVelocity += springDirection * force; } - avatar.bone[b].springyVelocity += ( avatar.bone[b].position - avatar.bone[b].springyPosition ) * springToBodyTightness * deltaTime; - + avatar.bone[b].springyVelocity += ( avatar.bone[b].position - avatar.bone[b].springyPosition ) * + avatar.bone[b].springBodyTightness * deltaTime; + float decay = 1.0 - springVelocityDecay * deltaTime; if ( decay > 0.0 ) { @@ -1000,6 +1039,11 @@ glm::vec3 Head::getHeadLookatDirectionUp() { ); } +glm::vec3 Head::getBonePosition( AvatarBones b ) +{ + return avatar.bone[b].position; +} + glm::vec3 Head::getHeadLookatDirectionRight() { return glm::vec3 ( diff --git a/interface/src/Head.h b/interface/src/Head.h index 2cda9a1af6..eeaa4ebee0 100644 --- a/interface/src/Head.h +++ b/interface/src/Head.h @@ -109,6 +109,7 @@ struct AvatarBone glm::vec3 defaultPosePosition; // the parent relative position when the avatar is in the "T-pose" glm::vec3 springyPosition; // used for special effects (a 'flexible' variant of position) glm::dvec3 springyVelocity; // used for special effects ( the velocity of the springy position) + float springBodyTightness; // how tightly (0 to 1) the springy position tries to stay on the position float yaw; // the yaw Euler angle of the bone rotation off the parent float pitch; // the pitch Euler angle of the bone rotation off the parent float roll; // the roll Euler angle of the bone rotation off the parent @@ -159,6 +160,7 @@ class Head : public AgentData { glm::vec3 getHeadLookatDirectionUp(); glm::vec3 getHeadLookatDirectionRight(); glm::vec3 getHeadPosition(); + glm::vec3 getBonePosition( AvatarBones b ); glm::vec3 getBodyPosition(); void render(int faceToFace, int isMine); @@ -254,7 +256,7 @@ class Head : public AgentData { float springVelocityDecay; float springForce; - float springToBodyTightness; + //float springToBodyTightness; int eyeContact; eyeContactTargets eyeContactTarget; diff --git a/interface/src/Util.h b/interface/src/Util.h index 0e0121e2da..5a6f6a96d6 100644 --- a/interface/src/Util.h +++ b/interface/src/Util.h @@ -24,7 +24,7 @@ static const double ONE_THIRD = 0.3333333; static const double PIE = 3.14159265359; static const double PI_TIMES_TWO = 3.14159265359 * 2.0; static const double PI_OVER_180 = 3.14159265359 / 180.0; -static const double EPSILON = 0.00001; //smallish number - used as margin of error for some values +static const double EPSILON = 0.00001; //smallish number - used as margin of error for some computations static const double SQUARE_ROOT_OF_2 = sqrt(2); static const double SQUARE_ROOT_OF_3 = sqrt(3); static const double METER = 1.0; From 6ddebd523cf2eeca02963ac2d122119fffa9b387 Mon Sep 17 00:00:00 2001 From: Jeffrey Ventrella Date: Fri, 12 Apr 2013 16:52:31 -0700 Subject: [PATCH 08/12] cleaned up Orientation calls to right, up, front --- interface/src/Head.cpp | 40 +++++++++++++++++------------------ interface/src/Orientation.cpp | 13 +++++++++--- interface/src/Orientation.h | 16 ++++++-------- 3 files changed, 36 insertions(+), 33 deletions(-) diff --git a/interface/src/Head.cpp b/interface/src/Head.cpp index 1a70ba9a13..37185d6442 100644 --- a/interface/src/Head.cpp +++ b/interface/src/Head.cpp @@ -353,27 +353,27 @@ void Head::simulate(float deltaTime) { //notice that the z values from avatar.orientation are flipped to accommodate different coordinate system if (driveKeys[FWD]) { - glm::vec3 front( avatar.orientation.getFront().x, avatar.orientation.getFront().y, avatar.orientation.getFront().z ); + glm::vec3 front( avatar.orientation.front.x, avatar.orientation.front.y, avatar.orientation.front.z ); avatar.thrust += front * THRUST_MAG; } if (driveKeys[BACK]) { - glm::vec3 front( avatar.orientation.getFront().x, avatar.orientation.getFront().y, avatar.orientation.getFront().z ); + glm::vec3 front( avatar.orientation.front.x, avatar.orientation.front.y, avatar.orientation.front.z ); avatar.thrust -= front * THRUST_MAG; } if (driveKeys[RIGHT]) { - glm::vec3 right( avatar.orientation.getRight().x, avatar.orientation.getRight().y, avatar.orientation.getRight().z ); + glm::vec3 right( avatar.orientation.right.x, avatar.orientation.right.y, avatar.orientation.right.z ); avatar.thrust -= right * THRUST_MAG; } if (driveKeys[LEFT]) { - glm::vec3 right( avatar.orientation.getRight().x, avatar.orientation.getRight().y, avatar.orientation.getRight().z ); + glm::vec3 right( avatar.orientation.right.x, avatar.orientation.right.y, avatar.orientation.right.z ); avatar.thrust += right * THRUST_MAG; } if (driveKeys[UP]) { - glm::vec3 up( avatar.orientation.getUp().x, avatar.orientation.getUp().y, avatar.orientation.getUp().z ); + glm::vec3 up( avatar.orientation.up.x, avatar.orientation.up.y, avatar.orientation.up.z ); avatar.thrust += up * THRUST_MAG; } if (driveKeys[DOWN]) { - glm::vec3 up( avatar.orientation.getUp().x, avatar.orientation.getUp().y, avatar.orientation.getUp().z ); + glm::vec3 up( avatar.orientation.up.x, avatar.orientation.up.y, avatar.orientation.up.z ); avatar.thrust -= up * THRUST_MAG; } if (driveKeys[ROT_RIGHT]) { @@ -573,7 +573,7 @@ void Head::render(int faceToFace, int isMine) { void Head::renderOrientationDirections( glm::vec3 position, Orientation orientation, float size ) { - glm::vec3 pRight = position + orientation.getRight () * size; + glm::vec3 pRight = position + orientation.right * size; glm::vec3 pUp = position + orientation.getUp () * size; glm::vec3 pFront = position + orientation.getFront () * size; @@ -1024,18 +1024,18 @@ float Head::getBodyYaw() { glm::vec3 Head::getHeadLookatDirection() { return glm::vec3 ( - avatar.orientation.getFront().x, - avatar.orientation.getFront().y, - avatar.orientation.getFront().z + avatar.orientation.front.x, + avatar.orientation.front.y, + avatar.orientation.front.z ); } glm::vec3 Head::getHeadLookatDirectionUp() { return glm::vec3 ( - avatar.orientation.getUp().x, - avatar.orientation.getUp().y, - avatar.orientation.getUp().z + avatar.orientation.up.x, + avatar.orientation.up.y, + avatar.orientation.up.z ); } @@ -1047,9 +1047,9 @@ glm::vec3 Head::getBonePosition( AvatarBones b ) glm::vec3 Head::getHeadLookatDirectionRight() { return glm::vec3 ( - avatar.orientation.getRight().x, - avatar.orientation.getRight().y, - avatar.orientation.getRight().z + avatar.orientation.right.x, + avatar.orientation.right.y, + avatar.orientation.right.z ); } @@ -1077,9 +1077,9 @@ void Head::updateHandMovement() { glm::vec3 transformedHandMovement; transformedHandMovement - = avatar.orientation.getRight() * -movedHandOffset.x - + avatar.orientation.getUp() * -movedHandOffset.y - + avatar.orientation.getFront() * -movedHandOffset.y * 0.4; + = avatar.orientation.right * -movedHandOffset.x + + avatar.orientation.up * -movedHandOffset.y + + avatar.orientation.front * -movedHandOffset.y * 0.4; //if holding hands, add a pull to the hand... if ( usingSprings ) { @@ -1123,7 +1123,7 @@ 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 ); + glm::vec3 perpendicular = glm::cross( avatar.orientation.front, armVector ); newElbowPosition += perpendicular * ( 1.0 - ( 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 439538ce8a..6545c2b806 100755 --- a/interface/src/Orientation.cpp +++ b/interface/src/Orientation.cpp @@ -1,3 +1,10 @@ +//----------------------------------------------------------- +// +// Created by Jeffrey Ventrella +// Copyright (c) 2013 High Fidelity, Inc. All rights reserved. +// +//----------------------------------------------------------- + #include "Orientation.h" #include "Util.h" @@ -16,9 +23,9 @@ void Orientation::setToIdentity() { void Orientation::set( Orientation o ) { - right = o.getRight(); - up = o.getUp(); - front = o.getFront(); + right = o.right; + up = o.up; + front = o.front; } diff --git a/interface/src/Orientation.h b/interface/src/Orientation.h index 77771b785c..ae209a5f47 100755 --- a/interface/src/Orientation.h +++ b/interface/src/Orientation.h @@ -1,7 +1,7 @@ //----------------------------------------------------------- // -// Created by Jeffrey Ventrella and added as a utility -// class for High Fidelity Code base, April 2013 +// Created by Jeffrey Ventrella +// Copyright (c) 2013 High Fidelity, Inc. All rights reserved. // //----------------------------------------------------------- @@ -20,14 +20,6 @@ enum Axis class Orientation { -private: - - glm::vec3 right; - glm::vec3 up; - glm::vec3 front; - - //void verifyValidOrientation(); - public: Orientation(); @@ -38,6 +30,10 @@ public: void set( Orientation ); void setToIdentity(); + glm::vec3 right; + glm::vec3 up; + glm::vec3 front; + glm::vec3 getRight() { return right; } glm::vec3 getUp() { return up; } glm::vec3 getFront() { return front; } From 5a8c5ff0114ae6058d30448e50b2d02433a5298c Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Fri, 12 Apr 2013 16:55:57 -0700 Subject: [PATCH 09/12] 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 10/12] 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 11/12] 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 12/12] 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); }