Merge branch 'master' of github.com:worklist/hifi into reorganize

This commit is contained in:
Stephen Birarda 2013-04-12 17:25:41 -07:00
commit cb233e843c
11 changed files with 286 additions and 184 deletions

View file

@ -1035,7 +1035,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 ) {
@ -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 * ( 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;
//-----------------------------------------------------------------------------

View file

@ -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; // XXXBHG - this had been commented out, but build breaks without it.
int eyeContact;
eyeContactTargets eyeContactTarget;

View file

@ -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;

View file

@ -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; }

View file

@ -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 )
{

View file

@ -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;
@ -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

View file

@ -76,6 +76,8 @@
#include <SharedUtil.h>
#include <PacketHeaders.h>
#include "ViewFrustum.h"
using namespace std;
pthread_t networkReceiveThread;
@ -153,12 +155,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;
@ -1131,13 +1077,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
@ -1186,9 +1136,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!

View file

@ -351,3 +351,4 @@ void printVoxelCode(unsigned char* voxelCode) {
} while( (time2 - time1) < waitTime);
}
#endif

View file

@ -54,4 +54,5 @@ bool createVoxelEditMessage(unsigned char command, short int sequence,
void usleep(int waitTime);
#endif
#endif /* defined(__hifi__SharedUtil__) */

View file

@ -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);
}

View file

@ -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 <glm/glm.hpp>
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__) */