diff --git a/interface/src/Head.cpp b/interface/src/Head.cpp index e8ab9d6add..2e9933fb57 100644 --- a/interface/src/Head.cpp +++ b/interface/src/Head.cpp @@ -95,6 +95,7 @@ Head::Head() { usingSprings = false; springForce = 6.0f; + springToBodyTightness = 4.0f; springVelocityDecay = 16.0f; if (iris_texture.size() == 0) { @@ -775,27 +776,23 @@ 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 ) * - avatar.bone[b].springBodyTightness * deltaTime; - + avatar.bone[b].springyVelocity += ( avatar.bone[b].position - avatar.bone[b].springyPosition ) * springToBodyTightness * deltaTime; + float decay = 1.0 - springVelocityDecay * deltaTime; if ( decay > 0.0 ) { @@ -1033,11 +994,6 @@ glm::vec3 Head::getHeadLookatDirectionUp() { ); } -glm::vec3 Head::getBonePosition( AvatarBones b ) -{ - return avatar.bone[b].position; -} - glm::vec3 Head::getHeadLookatDirectionRight() { return glm::vec3 ( @@ -1073,7 +1029,7 @@ void Head::updateHandMovement() { transformedHandMovement = avatar.orientation.getRight() * -movedHandOffset.x + avatar.orientation.getUp() * -movedHandOffset.y - + avatar.orientation.getFront() * -movedHandOffset.y * 0.4; + + avatar.orientation.getFront() * -movedHandOffset.y * 0.4f; //if holding hands, add a pull to the hand... if ( usingSprings ) { @@ -1118,7 +1074,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 * ( 1.0 - ( avatar.maxArmLength / distance ) ) * ONE_HALF; + + // 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/Head.h b/interface/src/Head.h index 5041133c29..9ee8b28367 100644 --- a/interface/src/Head.h +++ b/interface/src/Head.h @@ -260,7 +260,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; diff --git a/interface/src/Orientation.cpp b/interface/src/Orientation.cpp index 439538ce8a..b42cba997c 100755 --- a/interface/src/Orientation.cpp +++ b/interface/src/Orientation.cpp @@ -1,6 +1,14 @@ +//----------------------------------------------------------- +// +// Created by Jeffrey Ventrella +// Copyright (c) 2013 High Fidelity, Inc. All rights reserved. +// +//----------------------------------------------------------- + #include "Orientation.h" #include "Util.h" + Orientation::Orientation() { right = glm::vec3( 1.0, 0.0, 0.0 ); up = glm::vec3( 0.0, 1.0, 0.0 ); @@ -16,16 +24,16 @@ 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; } 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; @@ -39,8 +47,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; @@ -53,9 +61,9 @@ void Orientation::pitch( float angle ) { void Orientation::roll( float angle ) { - double r = angle * PI_OVER_180; - double s = sin( r ); - double c = cos( r ); + float r = angle * PI_OVER_180; + float s = sin(r); + float c = cos(r); glm::vec3 cosineUp = up * c; glm::vec3 cosineRight = right * c; 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; } 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 5a6f6a96d6..56bc16f5d1 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 8f254a8946..ed9a9b4782 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -75,6 +75,8 @@ #include #include +#include "ViewFrustum.h" + using namespace std; pthread_t networkReceiveThread; @@ -152,12 +154,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 @@ -499,20 +502,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(); @@ -520,107 +509,64 @@ 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; } + + // Ask the ViewFrustum class to calculate our corners + ViewFrustum vf(position,direction,up,right,::WIDTH,::HEIGHT); - float nearDist = 0.1; - float farDist = 1.0; - - float fovHalfAngle = 0.7854f; // 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); - - // 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.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); - 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.2f); + glm::vec3 cameraLookingAtUp = cameraPosition + (cameraUp * 0.2f); + glm::vec3 cameraLookingAtRight = cameraPosition + (cameraRight * 0.2f); // Looking At from camera = white glColor3f(1,1,1); @@ -637,61 +583,61 @@ 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(); } @@ -769,10 +715,10 @@ 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.setDistance( 0.5 + 0.2 ); + viewFrustumOffsetCamera.setPitch ( 0.0 + ::viewFrustumOffsetPitch ); + viewFrustumOffsetCamera.setRoll ( 0.0 + ::viewFrustumOffsetRoll ); + viewFrustumOffsetCamera.setUp ( 0.2 + ::viewFrustumOffsetUp ); + viewFrustumOffsetCamera.setDistance ( 0.5 + ::viewFrustumOffsetDistance ); viewFrustumOffsetCamera.update(); whichCamera = viewFrustumOffsetCamera; @@ -1139,13 +1085,17 @@ 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 ::setupPaintingVoxel(); // also randomizes colors @@ -1194,9 +1144,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/shared/src/CounterStats.cpp b/libraries/shared/src/CounterStats.cpp index 050ee6159b..b86cfd37f2 100644 --- a/libraries/shared/src/CounterStats.cpp +++ b/libraries/shared/src/CounterStats.cpp @@ -33,6 +33,53 @@ // int sampleAt; +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) : + 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) : + name(myName), + currentCount(initialCount), + currentDelta(0), + currentTime(initialTime), + lastCount(initialCount), + lastTime(initialTime), + totalTime(initialTime), + sampleAt(-1), + sampleCount(0) { +} + +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; diff --git a/libraries/shared/src/SharedUtil.cpp b/libraries/shared/src/SharedUtil.cpp index fddcca6cd7..8fb8645730 100644 --- a/libraries/shared/src/SharedUtil.cpp +++ b/libraries/shared/src/SharedUtil.cpp @@ -351,3 +351,4 @@ void printVoxelCode(unsigned char* voxelCode) { } while( (time2 - time1) < waitTime); } #endif + diff --git a/libraries/shared/src/SharedUtil.h b/libraries/shared/src/SharedUtil.h index 34ac6d8b86..24517c9a68 100644 --- a/libraries/shared/src/SharedUtil.h +++ b/libraries/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/libraries/voxels/src/ViewFrustum.cpp b/libraries/voxels/src/ViewFrustum.cpp new file mode 100644 index 0000000000..477e049e93 --- /dev/null +++ b/libraries/voxels/src/ViewFrustum.cpp @@ -0,0 +1,105 @@ +// +// ViewFrustum.cpp +// hifi +// +// Created by Brad Hefta-Gaub on 04/11/13. +// +// Simple view frustum class. +// +// + +#include "ViewFrustum.h" + +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); +} + +///////////////////////////////////////////////////////////////////////////////////// +// ViewFrustum::calculateViewFrustum() +// +// Description: this will calculate the view frustum bounds for a given position +// and direction +// +// 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) { + + // Save the values we were passed... + 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; + + this->_nearDist = 0.1; + this->_farDist = 10.0; + + this->_nearHeight = 2 * tan(fovHalfAngle) * this->_nearDist; + this->_nearWidth = this->_nearHeight * ratio; + this->_farHeight = 2 * tan(fovHalfAngle) * this->_farDist; + this->_farWidth = this->_farHeight * ratio; + + 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); + + 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("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("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 new file mode 100644 index 0000000000..02c7c39bcc --- /dev/null +++ b/libraries/voxels/src/ViewFrustum.h @@ -0,0 +1,67 @@ +// +// 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 _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; + glm::vec3 _farBottomLeft; + glm::vec3 _farBottomRight; + + glm::vec3 _nearCenter; + glm::vec3 _nearTopLeft; + glm::vec3 _nearTopRight; + glm::vec3 _nearBottomLeft; + glm::vec3 _nearBottomRight; +public: + 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; }; + + 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, + 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(); +}; + + +#endif /* defined(__hifi__ViewFrustum__) */