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