diff --git a/avatar-mixer/src/main.cpp b/avatar-mixer/src/main.cpp index f59a2f8bcb..8aa57c0ad4 100644 --- a/avatar-mixer/src/main.cpp +++ b/avatar-mixer/src/main.cpp @@ -38,7 +38,7 @@ const int AVATAR_LISTEN_PORT = 55444; const unsigned short BROADCAST_INTERVAL_USECS = 20 * 1000 * 1000; unsigned char *addAgentToBroadcastPacket(unsigned char *currentPosition, Agent *agentToAdd) { - currentPosition += packSocket(currentPosition, agentToAdd->getPublicSocket()); + currentPosition += packAgentId(currentPosition, agentToAdd->getAgentId()); AvatarAgentData *agentData = (AvatarAgentData *)agentToAdd->getLinkedData(); diff --git a/interface/src/Cloud.cpp b/interface/src/Cloud.cpp index 5d68ecba75..ea27b40d49 100644 --- a/interface/src/Cloud.cpp +++ b/interface/src/Cloud.cpp @@ -43,20 +43,17 @@ Cloud::Cloud(int num, } } - void Cloud::render() { - + float particleAttenuationQuadratic[] = { 0.0f, 0.0f, 2.0f }; glEnable( GL_TEXTURE_2D ); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); - float maxSize = 0.0f; glGetFloatv( GL_POINT_SIZE_MAX_ARB, &maxSize ); glPointSize( maxSize ); - glPointParameterfvARB( GL_POINT_DISTANCE_ATTENUATION_ARB, particleAttenuationQuadratic ); glPointParameterfARB( GL_POINT_SIZE_MAX_ARB, maxSize ); glPointParameterfARB( GL_POINT_SIZE_MIN_ARB, 0.001f ); diff --git a/interface/src/Hand.cpp b/interface/src/Hand.cpp deleted file mode 100644 index 4cca3017dc..0000000000 --- a/interface/src/Hand.cpp +++ /dev/null @@ -1,225 +0,0 @@ -// -// Hand.cpp -// interface -// -// Created by Philip Rosedale on 10/13/12. -// Copyright (c) 2012 High Fidelity, Inc. All rights reserved. -// - -#include "Hand.h" - -#ifdef _WIN32 -#include "Systime.h" -#else -#include -#endif - -const float PHI = 1.618f; - -const float DEFAULT_X = 0; -const float DEFAULT_Y = -1.5; -const float DEFAULT_Z = 2.0; -const float DEFAULT_TRANSMITTER_HZ = 60.0; - -Hand::Hand(glm::vec3 initcolor) { - color = initcolor; - reset(); - noise = 0.0; //0.2; - scale.x = 0.07f; - scale.y = scale.x * 5.0f; - scale.z = scale.y * 1.0f; - renderPointer = true; -} - -Hand::Hand(const Hand &otherHand) { - color = otherHand.color; - noise = otherHand.noise; - scale = otherHand.scale; - position = otherHand.position; - target = otherHand.target; - velocity = otherHand.color; - pitch = otherHand.pitch; - yaw = otherHand.yaw; - roll = otherHand.roll; - pitchRate = otherHand.pitchRate; - yawRate = otherHand.yawRate; - rollRate = otherHand.rollRate; - transmitterTimer = otherHand.transmitterTimer; - transmitterHz = otherHand.transmitterHz; - transmitterPackets = otherHand.transmitterPackets; - renderPointer = otherHand.renderPointer; -} - -void Hand::reset() { - position.x = DEFAULT_X; - position.y = DEFAULT_Y; - position.z = DEFAULT_Z; - pitch = yaw = roll = 0; - pitchRate = yawRate = rollRate = 0; - setTarget(position); - velocity.x = velocity.y = velocity.z = 0; - transmitterPackets = 0; - transmitterHz = DEFAULT_TRANSMITTER_HZ; -} - -void Hand::render(int isMine) { - const float POINTER_LENGTH = 20.0; - glPushMatrix(); - glTranslatef(position.x, position.y, position.z); - glRotatef(yaw, 0, 1, 0); - glRotatef(pitch, 1, 0, 0); - glRotatef(roll, 0, 0, 1); - glColor3f(color.x, color.y, color.z); - glScalef(scale.x, scale.y, scale.z); - //glutSolidSphere(1.5, 20, 20); - glutSolidCube(1.0); - if (renderPointer) { - glBegin(GL_TRIANGLES); - glColor3f(1,0,0); - glNormal3f(0,-1,0); - glVertex3f(-0.4f,0,0); - glVertex3f(0.4f,0,0); - glVertex3f(0,0,-POINTER_LENGTH); - glEnd(); - glPushMatrix(); - glTranslatef(0,0,-POINTER_LENGTH); - glutSolidCube(1.0); - glPopMatrix(); - } - glPopMatrix(); -} - -void Hand::addAngularVelocity (float pRate, float yRate, float rRate) { - pitchRate += pRate; - yawRate += yRate; - rollRate += rRate; -} - -void Hand::processTransmitterData(char *packetData, int numBytes) { - // Read a packet from a transmitter app, process the data - float accX, accY, accZ, - graX, graY, graZ, - gyrX, gyrY, gyrZ, - linX, linY, linZ, - rot1, rot2, rot3, rot4; - sscanf((char *)packetData, "tacc %f %f %f gra %f %f %f gyr %f %f %f lin %f %f %f rot %f %f %f %f", - &accX, &accY, &accZ, - &graX, &graY, &graZ, - &gyrX, &gyrY, &gyrZ, - &linX, &linY, &linZ, - &rot1, &rot2, &rot3, &rot4); - - if (transmitterPackets++ == 0) { - gettimeofday(&transmitterTimer, NULL); - } - const int TRANSMITTER_COUNT = 100; - if (transmitterPackets % TRANSMITTER_COUNT == 0) { - // Every 100 packets, record the observed Hz of the transmitter data - timeval now; - gettimeofday(&now, NULL); - double msecsElapsed = diffclock(&transmitterTimer, &now); - transmitterHz = static_cast( (double)TRANSMITTER_COUNT/(msecsElapsed/1000.0) ); - //std::cout << "Transmitter Hz: " << (float)TRANSMITTER_COUNT/(msecsElapsed/1000.0) << "\n"; - //memcpy(&transmitterTimer, &now, sizeof(timeval)); - transmitterTimer = now; - } - // Add rotational forces to the hand - const float ANG_VEL_SENSITIVITY = 4.0; - const float ANG_VEL_THRESHOLD = 0.0; - float angVelScale = ANG_VEL_SENSITIVITY*(1.0f/getTransmitterHz()); - //addAngularVelocity(gyrX*angVelScale,gyrZ*angVelScale,-gyrY*angVelScale); - addAngularVelocity(fabs(gyrX*angVelScale)>ANG_VEL_THRESHOLD?gyrX*angVelScale:0, - fabs(gyrZ*angVelScale)>ANG_VEL_THRESHOLD?gyrZ*angVelScale:0, - fabs(-gyrY*angVelScale)>ANG_VEL_THRESHOLD?-gyrY*angVelScale:0); - - // Add linear forces to the hand - //const float LINEAR_VEL_SENSITIVITY = 50.0; - const float LINEAR_VEL_SENSITIVITY = 5.0; - float linVelScale = LINEAR_VEL_SENSITIVITY*(1.0f/getTransmitterHz()); - glm::vec3 linVel(linX*linVelScale, linZ*linVelScale, -linY*linVelScale); - addVelocity(linVel); - -} - -void Hand::simulate(float deltaTime) { - const float ANGULAR_SPRING_CONSTANT = 0.25; - const float ANGULAR_DAMPING_COEFFICIENT = 5*2.0f*powf(ANGULAR_SPRING_CONSTANT,0.5f); - const float LINEAR_SPRING_CONSTANT = 100; - const float LINEAR_DAMPING_COEFFICIENT = 2.0f*powf(LINEAR_SPRING_CONSTANT,0.5f); - - // If noise, add a bit of random velocity - const float RNOISE = 0.0; - const float VNOISE = 0.01f; - if (noise) { - - glm::vec3 nVel(randFloat() - 0.5f, randFloat() - 0.5f, randFloat() - 0.5f); - nVel *= VNOISE; - addVelocity(nVel); - - addAngularVelocity(RNOISE*(randFloat() - 0.5f), - RNOISE*(randFloat() - 0.5f), - RNOISE*(randFloat() - 0.5f)); - } - position += velocity*deltaTime; - - pitch += pitchRate; - yaw += yawRate; - roll += rollRate; - - // The spring method - if (0) { - // Use a linear spring to attempt to return the hand to the target position - glm::vec3 springForce = target - position; - springForce *= LINEAR_SPRING_CONSTANT; - addVelocity(springForce * deltaTime); - - // Critically damp the linear spring - glm::vec3 dampingForce(velocity); - dampingForce *= LINEAR_DAMPING_COEFFICIENT; - addVelocity(-dampingForce * deltaTime); - - // Use angular spring to return hand to target rotation (0,0,0) - addAngularVelocity(-pitch * ANGULAR_SPRING_CONSTANT * deltaTime, - -yaw * ANGULAR_SPRING_CONSTANT * deltaTime, - -roll * ANGULAR_SPRING_CONSTANT * deltaTime); - - // Critically damp angular spring - addAngularVelocity(-pitchRate*ANGULAR_DAMPING_COEFFICIENT*deltaTime, - -yawRate*ANGULAR_DAMPING_COEFFICIENT*deltaTime, - -rollRate*ANGULAR_DAMPING_COEFFICIENT*deltaTime); - } - - // The absolute limits method (no springs) - if (1) { - // Limit rotation - const float YAW_LIMIT = 20; - const float PITCH_LIMIT = 20; - - if (yaw > YAW_LIMIT) { yaw = YAW_LIMIT; yawRate = 0.0; } - if (yaw < -YAW_LIMIT) { yaw = -YAW_LIMIT; yawRate = 0.0; } - if (pitch > PITCH_LIMIT) { pitch = PITCH_LIMIT; pitchRate = 0.0; } - if (pitch < -PITCH_LIMIT) { pitch = -PITCH_LIMIT; pitchRate = 0.0; } - - // Damp Rotation Rates - yawRate *= 0.99f; - pitchRate *= 0.99f; - rollRate *= 0.99f; - - // Limit position - const float X_LIMIT = 1.0; - const float Y_LIMIT = 1.0; - const float Z_LIMIT = 1.0; - - if (position.x > DEFAULT_X + X_LIMIT) { position.x = DEFAULT_X + X_LIMIT; velocity.x = 0; } - if (position.x < DEFAULT_X - X_LIMIT) { position.x = DEFAULT_X - X_LIMIT; velocity.x = 0; } - if (position.y > DEFAULT_Y + Y_LIMIT) { position.y = DEFAULT_Y + Y_LIMIT; velocity.y = 0; } - if (position.y < DEFAULT_Y - Y_LIMIT) { position.y = DEFAULT_Y - Y_LIMIT; velocity.y = 0; } - if (position.z > DEFAULT_Z + Z_LIMIT) { position.z = DEFAULT_Z + Z_LIMIT; velocity.z = 0; } - if (position.z < DEFAULT_Z - Z_LIMIT) { position.z = DEFAULT_Z - Z_LIMIT; velocity.z = 0; } - - // Damp Velocity - velocity *= 0.99; - - } - -} \ No newline at end of file diff --git a/interface/src/Hand.h b/interface/src/Hand.h deleted file mode 100644 index cf887a897f..0000000000 --- a/interface/src/Hand.h +++ /dev/null @@ -1,47 +0,0 @@ -// -// Hand.h -// interface -// -// Created by Philip Rosedale on 10/13/12. -// Copyright (c) 2012 High Fidelity, Inc. All rights reserved. -// - -#ifndef __interface__Hand__ -#define __interface__Hand__ - -#include -#include -#include "Util.h" -#include "Field.h" -#include "world.h" -#include "InterfaceConfig.h" - -class Hand { -public: - Hand(glm::vec3 color); - Hand(const Hand &otherHand); - void simulate (float deltaTime); - void render (int isMine); - void reset (); - void setNoise (float mag) { noise = mag; }; - void addVelocity (glm::vec3 v) { velocity += v; }; - void addAngularVelocity (float pRate, float yRate, float rRate); - glm::vec3 getPos() { return position; }; - void setPos(glm::vec3 p) { position = p; }; - void setTarget(glm::vec3 t) { target = t; }; - void processTransmitterData(char * packetData, int numBytes); - float getTransmitterHz() { return transmitterHz; }; - void setRenderPointer(bool p) { renderPointer = p; }; -private: - glm::vec3 position, target, velocity, color, scale; - float pitch, yaw, roll, pitchRate, yawRate, rollRate; - float noise; - timeval transmitterTimer; - float transmitterHz; - int transmitterPackets; - bool renderPointer; - -}; - - -#endif diff --git a/interface/src/Head.cpp b/interface/src/Head.cpp index 41eac4bb8d..7674f36382 100644 --- a/interface/src/Head.cpp +++ b/interface/src/Head.cpp @@ -91,10 +91,9 @@ Head::Head() { usingSprings = false; springForce = 6.0f; + springToBodyTightness = 4.0f; springVelocityDecay = 16.0f; - hand = new Hand(glm::vec3(skinColor[0], skinColor[1], skinColor[2])); - if (iris_texture.size() == 0) { switchToResourcesIfRequired(); unsigned error = lodepng::decode(iris_texture, iris_texture_width, iris_texture_height, iris_texture_file); @@ -170,12 +169,8 @@ Head::Head(const Head &otherHead) { sphere = NULL; - Hand newHand = Hand(*otherHead.hand); - hand = &newHand; } - - Head::~Head() { if (sphere != NULL) { gluDeleteQuadric(sphere); @@ -349,27 +344,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.front.x, avatar.orientation.front.y, avatar.orientation.front.z ); + glm::vec3 front( avatar.orientation.getFront().x, avatar.orientation.getFront().y, avatar.orientation.getFront().z ); avatar.thrust += front * THRUST_MAG; } if (driveKeys[BACK]) { - glm::vec3 front( avatar.orientation.front.x, avatar.orientation.front.y, avatar.orientation.front.z ); + glm::vec3 front( avatar.orientation.getFront().x, avatar.orientation.getFront().y, avatar.orientation.getFront().z ); avatar.thrust -= front * THRUST_MAG; } if (driveKeys[RIGHT]) { - glm::vec3 right( avatar.orientation.right.x, avatar.orientation.right.y, avatar.orientation.right.z ); + glm::vec3 right( avatar.orientation.getRight().x, avatar.orientation.getRight().y, avatar.orientation.getRight().z ); avatar.thrust -= right * THRUST_MAG; } if (driveKeys[LEFT]) { - glm::vec3 right( avatar.orientation.right.x, avatar.orientation.right.y, avatar.orientation.right.z ); + glm::vec3 right( avatar.orientation.getRight().x, avatar.orientation.getRight().y, avatar.orientation.getRight().z ); avatar.thrust += right * THRUST_MAG; } if (driveKeys[UP]) { - glm::vec3 up( avatar.orientation.up.x, avatar.orientation.up.y, avatar.orientation.up.z ); + glm::vec3 up( avatar.orientation.getUp().x, avatar.orientation.getUp().y, avatar.orientation.getUp().z ); avatar.thrust += up * THRUST_MAG; } if (driveKeys[DOWN]) { - glm::vec3 up( avatar.orientation.up.x, avatar.orientation.up.y, avatar.orientation.up.z ); + glm::vec3 up( avatar.orientation.getUp().x, avatar.orientation.getUp().y, avatar.orientation.getUp().z ); avatar.thrust -= up * THRUST_MAG; } if (driveKeys[ROT_RIGHT]) { @@ -777,27 +772,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 ) { @@ -1020,32 +975,27 @@ float Head::getBodyYaw() { glm::vec3 Head::getHeadLookatDirection() { return glm::vec3 ( - avatar.orientation.front.x, - avatar.orientation.front.y, - avatar.orientation.front.z + avatar.orientation.getFront().x, + avatar.orientation.getFront().y, + avatar.orientation.getFront().z ); } glm::vec3 Head::getHeadLookatDirectionUp() { return glm::vec3 ( - avatar.orientation.up.x, - avatar.orientation.up.y, - avatar.orientation.up.z + avatar.orientation.getUp().x, + avatar.orientation.getUp().y, + avatar.orientation.getUp().z ); } -glm::vec3 Head::getBonePosition( AvatarBones b ) -{ - return avatar.bone[b].position; -} - glm::vec3 Head::getHeadLookatDirectionRight() { return glm::vec3 ( - avatar.orientation.right.x, - avatar.orientation.right.y, - avatar.orientation.right.z + avatar.orientation.getRight().x, + avatar.orientation.getRight().y, + avatar.orientation.getRight().z ); } @@ -1073,9 +1023,9 @@ void Head::updateHandMovement() { glm::vec3 transformedHandMovement; transformedHandMovement - = avatar.orientation.right * -movedHandOffset.x - + avatar.orientation.up * -movedHandOffset.y - + avatar.orientation.front * -movedHandOffset.y * 0.4; + = avatar.orientation.getRight() * -movedHandOffset.x + + avatar.orientation.getUp() * -movedHandOffset.y + + avatar.orientation.getFront() * -movedHandOffset.y * 0.4f; //if holding hands, add a pull to the hand... if ( usingSprings ) { @@ -1119,8 +1069,10 @@ 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.front, armVector ); - newElbowPosition += perpendicular * ( 1.0 - ( avatar.maxArmLength / distance ) ) * ONE_HALF; + glm::vec3 perpendicular = glm::cross( avatar.orientation.getFront(), armVector ); + + // 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; //----------------------------------------------------------------------------- @@ -1220,10 +1172,55 @@ void Head::parseData(void *data, int size) { handBeingMoved = true; } - - - void Head::SetNewHeadTarget(float pitch, float yaw) { PitchTarget = pitch; YawTarget = yaw; } + +void Head::processTransmitterData(char *packetData, int numBytes) { + // Read a packet from a transmitter app, process the data + float accX, accY, accZ, + graX, graY, graZ, + gyrX, gyrY, gyrZ, + linX, linY, linZ, + rot1, rot2, rot3, rot4; + sscanf((char *)packetData, "tacc %f %f %f gra %f %f %f gyr %f %f %f lin %f %f %f rot %f %f %f %f", + &accX, &accY, &accZ, + &graX, &graY, &graZ, + &gyrX, &gyrY, &gyrZ, + &linX, &linY, &linZ, + &rot1, &rot2, &rot3, &rot4); + + if (transmitterPackets++ == 0) { + gettimeofday(&transmitterTimer, NULL); + } + const int TRANSMITTER_COUNT = 100; + if (transmitterPackets % TRANSMITTER_COUNT == 0) { + // Every 100 packets, record the observed Hz of the transmitter data + timeval now; + gettimeofday(&now, NULL); + double msecsElapsed = diffclock(&transmitterTimer, &now); + transmitterHz = static_cast( (double)TRANSMITTER_COUNT/(msecsElapsed/1000.0) ); + transmitterTimer = now; + } + /* NOTE: PR: Will add back in when ready to animate avatar hand + + // Add rotational forces to the hand + const float ANG_VEL_SENSITIVITY = 4.0; + const float ANG_VEL_THRESHOLD = 0.0; + float angVelScale = ANG_VEL_SENSITIVITY*(1.0f/getTransmitterHz()); + + addAngularVelocity(fabs(gyrX*angVelScale)>ANG_VEL_THRESHOLD?gyrX*angVelScale:0, + fabs(gyrZ*angVelScale)>ANG_VEL_THRESHOLD?gyrZ*angVelScale:0, + fabs(-gyrY*angVelScale)>ANG_VEL_THRESHOLD?-gyrY*angVelScale:0); + + // Add linear forces to the hand + //const float LINEAR_VEL_SENSITIVITY = 50.0; + const float LINEAR_VEL_SENSITIVITY = 5.0; + float linVelScale = LINEAR_VEL_SENSITIVITY*(1.0f/getTransmitterHz()); + glm::vec3 linVel(linX*linVelScale, linZ*linVelScale, -linY*linVelScale); + addVelocity(linVel); + */ + +} + diff --git a/interface/src/Head.h b/interface/src/Head.h index 51b95ecaed..1680a5bdcf 100644 --- a/interface/src/Head.h +++ b/interface/src/Head.h @@ -13,7 +13,6 @@ #include "AgentData.h" #include "Field.h" #include "world.h" -#include "Hand.h" #include "Orientation.h" // added by Ventrella as a utility #include "InterfaceConfig.h" #include "SerialInterface.h" @@ -196,7 +195,12 @@ class Head : public AgentData { void addThrust(glm::vec3 newThrust) { avatar.thrust += newThrust; }; glm::vec3 getThrust() { return avatar.thrust; }; - Hand * hand; + // + // Related to getting transmitter UDP data used to animate the avatar hand + // + + void processTransmitterData(char * packetData, int numBytes); + float getTransmitterHz() { return transmitterHz; }; private: float noise; @@ -271,6 +275,13 @@ class Head : public AgentData { void readSensors(); float renderYaw, renderPitch; // Pitch from view frustum when this is own head. + // + // Related to getting transmitter UDP data used to animate the avatar hand + // + timeval transmitterTimer; + float transmitterHz; + int transmitterPackets; + }; #endif diff --git a/interface/src/MenuColumn.cpp b/interface/src/MenuColumn.cpp index d3780b5710..94e8595c8b 100644 --- a/interface/src/MenuColumn.cpp +++ b/interface/src/MenuColumn.cpp @@ -41,7 +41,7 @@ void MenuColumn::mouseClickRow(int numberOfRowsIndex) { } bool MenuColumn::mouseClick(int x, int y, int leftPosition, int menuHeight, int lineHeight) { - int rightPosition = leftPosition + 200; + int rightPosition = leftPosition + 200; // XXXBHG - this looks like a hack? int topPosition = menuHeight; int bottomPosition = menuHeight; int columnWidth = 0; @@ -67,13 +67,14 @@ void MenuColumn::setMouseOver(int leftPosition, int rightPosition, int topPositi } bool MenuColumn::mouseOver(int x, int y, int leftPosition, int menuHeight, int lineHeight) { - int rightPosition = leftPosition + 100; + + int maxColumnWidth = this->getMaxRowWidth(); + + int rightPosition = leftPosition + maxColumnWidth; int topPosition = menuHeight; int bottomPosition = menuHeight; - int columnWidth = 0; bool overMenu = false; for (unsigned int i = 0; i < rows.size(); ++i) { - columnWidth = rows[i].getWidth(); topPosition = bottomPosition + lineHeight ; if (x > leftPosition && x < rightPosition && y > bottomPosition && y < topPosition) { setMouseOver(leftPosition, rightPosition, bottomPosition, topPosition); @@ -116,26 +117,47 @@ int MenuColumn::addRow(const char* rowName, MenuRowCallback callback) { return 0; } +int MenuColumn::addRow(const char* rowName, MenuRowCallback callback, MenuStateNameCallback stateNameCallback) { + MenuRow* row; + row = new MenuRow(rowName, callback, stateNameCallback); + rows.push_back(*row); + delete row; + return 0; +} + +int MenuColumn::getMaxRowWidth() { + float scale = 0.09; + int mono = 0; + int maxColumnWidth = 100 - (SPACE_BEFORE_ROW_NAME*2); // the minimum size we want + for (unsigned int i = 0; i < rows.size(); ++i) { + maxColumnWidth = std::max(maxColumnWidth,rows[i].getWidth(scale, mono, 0)); + } + + maxColumnWidth += SPACE_BEFORE_ROW_NAME*2; // space before and after!! + return maxColumnWidth; +} + void MenuColumn::render(int yOffset, int menuHeight, int lineHeight) { + float scale = 0.09; + int mono = 0; int numberOfRows = rows.size(); if (numberOfRows > 0) { + + int maxColumnWidth = this->getMaxRowWidth(); + glColor3f(0.9,0.9,0.9); glBegin(GL_QUADS); { glVertex2f(leftPosition, yOffset + menuHeight); - glVertex2f(leftPosition+100, yOffset + menuHeight); - glVertex2f(leftPosition+100, yOffset + menuHeight + numberOfRows*lineHeight); + glVertex2f(leftPosition+maxColumnWidth, yOffset + menuHeight); + glVertex2f(leftPosition+maxColumnWidth, yOffset + menuHeight + numberOfRows*lineHeight); glVertex2f(leftPosition , yOffset + menuHeight + numberOfRows* lineHeight); } glEnd(); } - float scale = 0.09; - int mono = 0; int y = menuHeight + lineHeight / 2 ; char* rowName; - int columnWidth = 0; for (unsigned int i = 0; i < rows.size(); ++i) { rowName = rows[i].getName(); - columnWidth = rows[i].getWidth(scale, mono, 0); drawtext(leftPosition + SPACE_BEFORE_ROW_NAME, y+5 + yOffset, scale, 0, 1.0, mono, rowName, 0, 0, 0); y += lineHeight; } diff --git a/interface/src/MenuColumn.h b/interface/src/MenuColumn.h index 71c42eed7f..3b1b59affd 100644 --- a/interface/src/MenuColumn.h +++ b/interface/src/MenuColumn.h @@ -27,6 +27,8 @@ public: void render(int yOffset, int menuHeight, int lineHeight); void renderMouseOver(int yOffset); int addRow(const char* rowName, MenuRowCallback callback); + int addRow(const char* rowName, MenuRowCallback callback, MenuStateNameCallback stateNameCallback); + int getMaxRowWidth(); private: char columnName[MAX_COLUMN_NAME]; int columnWidth; diff --git a/interface/src/MenuRow.cpp b/interface/src/MenuRow.cpp index 495ca29987..09ee685a87 100644 --- a/interface/src/MenuRow.cpp +++ b/interface/src/MenuRow.cpp @@ -16,14 +16,26 @@ #include "MenuColumn.h" #include "Menu.h" -MenuRow::MenuRow() { +MenuRow::MenuRow() : + callback(NULL), + stateNameCallback(NULL) { } -MenuRow::MenuRow(const char * columnName, MenuRowCallback callback) { - int length = std::min(MAX_COLUMN_NAME - 5,(int) strlen(columnName)); - strncpy(this->rowName, columnName, length); - memcpy(this->rowName + length, " \0", 5); - this->callback = callback; +MenuRow::MenuRow(const char * columnName, MenuRowCallback callback) : + callback(callback), + stateNameCallback(NULL) { + this->nameLength = strlen(columnName); + strncpy(this->rowName, columnName, MAX_COLUMN_NAME); // copy the base name + strncpy(this->rowName, this->getName(), MAX_COLUMN_NAME); // now add in state + rowWidth = 0; +} + +MenuRow::MenuRow(const char * columnName, MenuRowCallback callback, MenuStateNameCallback stateNameCallback) : + callback(callback), + stateNameCallback(stateNameCallback) { + this->nameLength = strlen(columnName); + strncpy(this->rowName, columnName, MAX_COLUMN_NAME); + strncpy(this->rowName, this->getName(), MAX_COLUMN_NAME); // now add in state rowWidth = 0; } @@ -31,19 +43,30 @@ MenuRow::~MenuRow() { } void MenuRow::call() { - callback(-2); + callback(MENU_ROW_PICKED); +} + +const char* MenuRow::getStateName() { + int currentValue = callback(MENU_ROW_GET_VALUE); + const char* stateName; + // If the MenuRow has a custom stateNameCallback function, then call it to get a string + // to display in the menu. Otherwise, use the default implementation. + if (stateNameCallback != NULL) { + stateName = stateNameCallback(currentValue); + } else { + if (currentValue == 0) { + stateName = " OFF "; + } else if (currentValue == 1) { + stateName = " ON "; + } else { + stateName = " "; + } + } + return stateName; } char* MenuRow::getName() { - int length = (int) strlen(this->rowName) - 4; - int currentValue = callback(-1); - if (currentValue == 0) { - memcpy(this->rowName + length, " OFF\0", 5); - } else if (currentValue == 1) { - memcpy(this->rowName + length, " ON \0", 5); - } else { - memcpy(this->rowName + length, " \0", 5); - } + strcpy(this->rowName + nameLength, getStateName()); return this->rowName; } diff --git a/interface/src/MenuRow.h b/interface/src/MenuRow.h index 8bca2a462d..a371cec3f4 100644 --- a/interface/src/MenuRow.h +++ b/interface/src/MenuRow.h @@ -12,22 +12,29 @@ const int MAX_COLUMN_NAME = 50; const int SPACE_BETWEEN_COLUMNS = 20; const int SPACE_BEFORE_ROW_NAME = 10; +const int MENU_ROW_PICKED = -2; +const int MENU_ROW_GET_VALUE = -1; typedef int(*MenuRowCallback)(int); +typedef const char*(*MenuStateNameCallback)(int); class MenuRow { public: MenuRow(); MenuRow(const char* rowName, MenuRowCallback callback); + MenuRow(const char* rowName, MenuRowCallback callback, MenuStateNameCallback stateNameCallback); ~MenuRow(); void call(); char * getName(); + const char* getStateName(); int getWidth(float scale, int mono, int leftPosition); int getWidth(); private: + int nameLength; char rowName[MAX_COLUMN_NAME]; int rowWidth; MenuRowCallback callback; + MenuStateNameCallback stateNameCallback; }; #endif /* defined(__hifi__MenuRow__) */ diff --git a/interface/src/Orientation.cpp b/interface/src/Orientation.cpp index 6545c2b806..b42cba997c 100755 --- a/interface/src/Orientation.cpp +++ b/interface/src/Orientation.cpp @@ -8,6 +8,7 @@ #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 ); @@ -31,8 +32,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; @@ -46,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; @@ -60,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/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 93c5b8997c..369a52195c 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -60,9 +60,8 @@ #include "MenuRow.h" #include "MenuColumn.h" #include "Menu.h" -#include "Head.h" -#include "Hand.h" #include "Camera.h" +#include "Head.h" #include "Particle.h" #include "Texture.h" #include "Cloud.h" @@ -76,6 +75,8 @@ #include #include +#include "ViewFrustum.h" + using namespace std; pthread_t networkReceiveThread; @@ -151,14 +152,6 @@ bool paintOn = false; // Whether to paint voxels as you fly around VoxelDetail paintingVoxel; // The voxel we're painting if we're painting unsigned char dominantColor = 0; // The dominant color of the voxel we're painting bool perfStatsOn = false; // Do we want to display perfStats? -bool frustumOn = false; // Whether or not to display the debug view frustum -bool cameraFrustum = true; // which frustum to look at -bool 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; int noiseOn = 0; // Whether to add random noise float noise = 1.0; // Overall magnitude scaling for random noise levels @@ -372,12 +365,13 @@ void simulateHand(float deltaTime) { // If mouse is being dragged, send current force to the hand controller if (mousePressed == 1) { - // Add a velocity to the hand corresponding to the detected size of the drag vector + // NOTE--PER: Need to re-implement when ready for new avatar hand movements + const float MOUSE_HAND_FORCE = 1.5; float dx = mouseX - mouseStartX; float dy = mouseY - mouseStartY; glm::vec3 vel(dx*MOUSE_HAND_FORCE, -dy*MOUSE_HAND_FORCE*(WIDTH/HEIGHT), 0); - myAvatar.hand->addVelocity(vel*deltaTime); + //myAvatar.hand->addVelocity(vel*deltaTime); } } @@ -489,30 +483,47 @@ void simulateHead(float frametime) } } - - ///////////////////////////////////////////////////////////////////////////////////// // render_view_frustum() // // Description: this will render the view frustum bounds for EITHER the head -// or the "myCamera". It appears as if the orientation that comes -// from these two sources is in different coordinate spaces (namely) -// their axis orientations don't match. +// or the "myCamera". +// +// Frustum rendering mode. For debug purposes, we allow drawing the frustum in a couple of different ways. +// We can draw it with each of these parts: +// * Origin Direction/Up/Right vectors - these will be drawn at the point of the camera +// * Near plane - this plane is drawn very close to the origin point. +// * Right/Left planes - these two planes are drawn between the near and far planes. +// * Far plane - the plane is drawn in the distance. +// Modes - the following modes, will draw the following parts. +// * All - draws all the parts listed above +// * Planes - draws the planes but not the origin vectors +// * Origin Vectors - draws the origin vectors ONLY +// * Near Plane - draws only the near plane +// * Far Plane - draws only the far plane +#define FRUSTUM_DRAW_MODE_ALL 0 +#define FRUSTUM_DRAW_MODE_VECTORS 1 +#define FRUSTUM_DRAW_MODE_PLANES 2 +#define FRUSTUM_DRAW_MODE_NEAR_PLANE 3 +#define FRUSTUM_DRAW_MODE_FAR_PLANE 4 +#define FRUSTUM_DRAW_MODE_COUNT 5 + +// These global scoped variables are used by our render_view_frustum() function below, but are also available as globals +// so that the keyboard and menu can manipulate them. + +int frustumDrawingMode = FRUSTUM_DRAW_MODE_ALL; // the mode we're drawing the frustum in, see notes above + +bool frustumOn = false; // Whether or not to display the debug view frustum +bool cameraFrustum = true; // which frustum to look at + +bool viewFrustumFromOffset=false; // Wether or not to offset the view of the frustum +float viewFrustumOffsetYaw = -90.0; // the following variables control yaw, pitch, roll and distance form regular +float viewFrustumOffsetPitch = 7.5; // camera to the offset camera +float viewFrustumOffsetRoll = 0.0; +float viewFrustumOffsetDistance = 0.0; +float viewFrustumOffsetUp = 0.0; + void render_view_frustum() { - - //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,180 +531,127 @@ 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; } - float nearDist = 0.1; - float farDist = 1.0; + // Ask the ViewFrustum class to calculate our corners + ViewFrustum vf(position,direction,up,right,::WIDTH,::HEIGHT); - 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); + if (::frustumDrawingMode == FRUSTUM_DRAW_MODE_ALL || ::frustumDrawingMode == FRUSTUM_DRAW_MODE_VECTORS) { + // Calculate the origin direction vectors + glm::vec3 lookingAt = position + (direction * 0.2f); + glm::vec3 lookingAtUp = position + (up * 0.2f); + glm::vec3 lookingAtRight = position + (right * 0.2f); - // Looking At from head = white - glColor3f(1,1,1); - glVertex3f(headPosition.x,headPosition.y,headPosition.z); - glVertex3f(headLookingAt.x,headLookingAt.y,headLookingAt.z); + // Looking At = white + glColor3f(1,1,1); + glVertex3f(position.x, position.y, position.z); + glVertex3f(lookingAt.x, lookingAt.y, lookingAt.z); - // up from head = purple - glColor3f(1,0,1); - glVertex3f(headPosition.x,headPosition.y,headPosition.z); - glVertex3f(headLookingAtUp.x,headLookingAtUp.y,headLookingAtUp.z); + // Looking At Up = purple + glColor3f(1,0,1); + glVertex3f(position.x, position.y, position.z); + glVertex3f(lookingAtUp.x, lookingAtUp.y, lookingAtUp.z); - // right from head = cyan - glColor3f(0,1,1); - glVertex3f(headPosition.x,headPosition.y,headPosition.z); - glVertex3f(headLookingAtRight.x,headLookingAtRight.y,headLookingAtRight.z); + // Looking At Right = cyan + glColor3f(0,1,1); + glVertex3f(position.x, position.y, position.z); + glVertex3f(lookingAtRight.x, lookingAtRight.y, lookingAtRight.z); + } - glm::vec3 cameraLookingAt = cameraPosition+(cameraDirection*5.0); - glm::vec3 cameraLookingAtUp = cameraPosition+(cameraUp*5.0); - glm::vec3 cameraLookingAtRight = cameraPosition+(cameraRight*5.0); + if (::frustumDrawingMode == FRUSTUM_DRAW_MODE_ALL || ::frustumDrawingMode == FRUSTUM_DRAW_MODE_PLANES + || ::frustumDrawingMode == FRUSTUM_DRAW_MODE_NEAR_PLANE) { + // Drawing the bounds of the frustum + // vf.getNear plane - bottom edge + glColor3f(1,0,0); + glVertex3f(vf.getNearBottomLeft().x, vf.getNearBottomLeft().y, vf.getNearBottomLeft().z); + glVertex3f(vf.getNearBottomRight().x, vf.getNearBottomRight().y, vf.getNearBottomRight().z); - // Looking At from camera = white - glColor3f(1,1,1); - glVertex3f(cameraPosition.x,cameraPosition.y,cameraPosition.z); - glVertex3f(cameraLookingAt.x,cameraLookingAt.y,cameraLookingAt.z); + // vf.getNear plane - top edge + glVertex3f(vf.getNearTopLeft().x, vf.getNearTopLeft().y, vf.getNearTopLeft().z); + glVertex3f(vf.getNearTopRight().x, vf.getNearTopRight().y, vf.getNearTopRight().z); - // up from camera = purple - glColor3f(1,0,1); - glVertex3f(cameraPosition.x,cameraPosition.y,cameraPosition.z); - glVertex3f(cameraLookingAtUp.x,cameraLookingAtUp.y,cameraLookingAtUp.z); + // vf.getNear plane - right edge + glVertex3f(vf.getNearBottomRight().x, vf.getNearBottomRight().y, vf.getNearBottomRight().z); + glVertex3f(vf.getNearTopRight().x, vf.getNearTopRight().y, vf.getNearTopRight().z); - // right from camera = cyan - glColor3f(0,1,1); - glVertex3f(cameraPosition.x,cameraPosition.y,cameraPosition.z); - glVertex3f(cameraLookingAtRight.x,cameraLookingAtRight.y,cameraLookingAtRight.z); + // vf.getNear plane - left edge + glVertex3f(vf.getNearBottomLeft().x, vf.getNearBottomLeft().y, vf.getNearBottomLeft().z); + glVertex3f(vf.getNearTopLeft().x, vf.getNearTopLeft().y, vf.getNearTopLeft().z); + } - // The remaining lines are skinny - //glLineWidth(1.0); - // near plane - bottom edge - glColor3f(1,0,0); - glVertex3f(nearBottomLeft.x,nearBottomLeft.y,nearBottomLeft.z); - glVertex3f(nearBottomRight.x,nearBottomRight.y,nearBottomRight.z); + if (::frustumDrawingMode == FRUSTUM_DRAW_MODE_ALL || ::frustumDrawingMode == FRUSTUM_DRAW_MODE_PLANES + || ::frustumDrawingMode == FRUSTUM_DRAW_MODE_FAR_PLANE) { + // vf.getFar plane - bottom edge + glColor3f(0,1,0); // GREEN!!! + glVertex3f(vf.getFarBottomLeft().x, vf.getFarBottomLeft().y, vf.getFarBottomLeft().z); + glVertex3f(vf.getFarBottomRight().x, vf.getFarBottomRight().y, vf.getFarBottomRight().z); - // near plane - top edge - glVertex3f(nearTopLeft.x,nearTopLeft.y,nearTopLeft.z); - glVertex3f(nearTopRight.x,nearTopRight.y,nearTopRight.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); - // near plane - right edge - glVertex3f(nearBottomRight.x,nearBottomRight.y,nearBottomRight.z); - glVertex3f(nearTopRight.x,nearTopRight.y,nearTopRight.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); - // near plane - left edge - glVertex3f(nearBottomLeft.x,nearBottomLeft.y,nearBottomLeft.z); - glVertex3f(nearTopLeft.x,nearTopLeft.y,nearTopLeft.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); + } - // far plane - bottom edge - glColor3f(0,1,0); // GREEN!!! - glVertex3f(farBottomLeft.x,farBottomLeft.y,farBottomLeft.z); - glVertex3f(farBottomRight.x,farBottomRight.y,farBottomRight.z); + if (::frustumDrawingMode == FRUSTUM_DRAW_MODE_ALL || ::frustumDrawingMode == FRUSTUM_DRAW_MODE_PLANES) { + // RIGHT PLANE IS CYAN + // right plane - bottom edge - vf.getNear to distant + glColor3f(0,1,1); + glVertex3f(vf.getNearBottomRight().x, vf.getNearBottomRight().y, vf.getNearBottomRight().z); + glVertex3f(vf.getFarBottomRight().x, vf.getFarBottomRight().y, vf.getFarBottomRight().z); - // far plane - top edge - glVertex3f(farTopLeft.x,farTopLeft.y,farTopLeft.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); - // far plane - right edge - glVertex3f(farBottomRight.x,farBottomRight.y,farBottomRight.z); - glVertex3f(farTopRight.x,farTopRight.y,farTopRight.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); - // far plane - left edge - glVertex3f(farBottomLeft.x,farBottomLeft.y,farBottomLeft.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); + } - // RIGHT PLANE IS CYAN - // right plane - bottom edge - near to distant - glColor3f(0,1,1); - glVertex3f(nearBottomRight.x,nearBottomRight.y,nearBottomRight.z); - glVertex3f(farBottomRight.x,farBottomRight.y,farBottomRight.z); - - // right plane - top edge - near to distant - glVertex3f(nearTopRight.x,nearTopRight.y,nearTopRight.z); - glVertex3f(farTopRight.x,farTopRight.y,farTopRight.z); - - // LEFT PLANE IS BLUE - // left plane - bottom edge - near to distant - glColor3f(0,0,1); - glVertex3f(nearBottomLeft.x,nearBottomLeft.y,nearBottomLeft.z); - glVertex3f(farBottomLeft.x,farBottomLeft.y,farBottomLeft.z); - - // left plane - top edge - near to distant - glVertex3f(nearTopLeft.x,nearTopLeft.y,nearTopLeft.z); - glVertex3f(farTopLeft.x,farTopLeft.y,farTopLeft.z); - glEnd(); + glEnable(GL_LIGHTING); } @@ -797,6 +755,18 @@ void display(void) glEnable(GL_LIGHTING); glEnable(GL_DEPTH_TEST); + + /* + // Test - Draw a blue sphere around a body part of mine! + + glPushMatrix(); + glColor4f(0,0,1, 0.7); + glTranslatef(myAvatar.getBonePosition(AVATAR_BONE_RIGHT_HAND).x, + myAvatar.getBonePosition(AVATAR_BONE_RIGHT_HAND).y, + myAvatar.getBonePosition(AVATAR_BONE_RIGHT_HAND).z); + glutSolidSphere(0.03, 10, 10); + glPopMatrix(); + */ // draw a red sphere float sphereRadius = 0.25f; @@ -811,8 +781,6 @@ void display(void) // Draw cloud of dots - glDisable( GL_POINT_SPRITE_ARB ); - glDisable( GL_TEXTURE_2D ); if (!displayHead) cloud.render(); // Draw voxels @@ -928,10 +896,23 @@ void display(void) } } +// int version of setValue() int setValue(int state, int *value) { - if (state == -2) { + if (state == MENU_ROW_PICKED) { *value = !(*value); - } else if (state == -1) { + } else if (state == MENU_ROW_GET_VALUE) { + return *value; + } else { + *value = state; + } + return *value; +} + +// bool version of setValue() +int setValue(int state, bool *value) { + if (state == MENU_ROW_PICKED) { + *value = !(*value); + } else if (state == MENU_ROW_GET_VALUE) { return *value; } else { *value = state; @@ -957,6 +938,14 @@ int setNoise(int state) { return iRet; } +int setVoxels(int state) { + return setValue(state, &::showingVoxels); +} + +int setStars(int state) { + return setValue(state, &::starsOn); +} + int setStats(int state) { return setValue(state, &statsOn); } @@ -969,18 +958,83 @@ int setMirror(int state) { return setValue(state, &headMirror); } +int setDisplayFrustum(int state) { + return setValue(state, &::frustumOn); +} + +int setFrustumOffset(int state) { + return setValue(state, &::viewFrustumFromOffset); +} + +int setFrustumOrigin(int state) { + return setValue(state, &::cameraFrustum); +} + +int quitApp(int state) { + if (state == MENU_ROW_PICKED) { + ::terminate(); + } + return 2; // non state so menu class doesn't add "state" +} + +int setFrustumRenderMode(int state) { + if (state == MENU_ROW_PICKED) { + ::frustumDrawingMode = (::frustumDrawingMode+1)%FRUSTUM_DRAW_MODE_COUNT; + } + return ::frustumDrawingMode; +} + +const char* modeAll = " - All "; +const char* modeVectors = " - Vectors "; +const char* modePlanes = " - Planes "; +const char* modeNear = " - Near "; +const char* modeFar = " - Far "; + +const char* getFrustumRenderModeName(int state) { + const char * mode; + switch (state) { + case FRUSTUM_DRAW_MODE_ALL: + mode = modeAll; + break; + case FRUSTUM_DRAW_MODE_VECTORS: + mode = modeVectors; + break; + case FRUSTUM_DRAW_MODE_PLANES: + mode = modePlanes; + break; + case FRUSTUM_DRAW_MODE_NEAR_PLANE: + mode = modeNear; + break; + case FRUSTUM_DRAW_MODE_FAR_PLANE: + mode = modeFar; + break; + } + return mode; +} + void initMenu() { - MenuColumn *menuColumnOptions, *menuColumnTools, *menuColumnDebug; + MenuColumn *menuColumnOptions, *menuColumnTools, *menuColumnDebug, *menuColumnFrustum; // Options menuColumnOptions = menu.addColumn("Options"); - menuColumnOptions->addRow("Head", setHead); - menuColumnOptions->addRow("Field", setField); - menuColumnOptions->addRow("Noise", setNoise); + menuColumnOptions->addRow("(H)ead", setHead); + menuColumnOptions->addRow("Field (f)", setField); + menuColumnOptions->addRow("(N)oise", setNoise); menuColumnOptions->addRow("Mirror", setMirror); + menuColumnOptions->addRow("(V)oxels", setVoxels); + menuColumnOptions->addRow("Stars (*)", setStars); + menuColumnOptions->addRow("(Q)uit", quitApp); // Tools menuColumnTools = menu.addColumn("Tools"); - menuColumnTools->addRow("Stats", setStats); - menuColumnTools->addRow("Menu", setMenu); + menuColumnTools->addRow("Stats (/)", setStats); + menuColumnTools->addRow("(M)enu", setMenu); + + // Debug + menuColumnFrustum = menu.addColumn("Frustum"); + menuColumnFrustum->addRow("Display (F)rustum", setDisplayFrustum); + menuColumnFrustum->addRow("Use (O)ffset Camera", setFrustumOffset); + menuColumnFrustum->addRow("Switch (C)amera", setFrustumOrigin); + menuColumnFrustum->addRow("(R)ender Mode", setFrustumRenderMode, getFrustumRenderModeName); + // Debug menuColumnDebug = menu.addColumn("Debug"); @@ -1124,21 +1178,28 @@ void key(unsigned char k, int x, int y) { // Process keypresses - if (k == 'q') ::terminate(); + if (k == 'q' || k == 'Q') ::terminate(); if (k == '/') statsOn = !statsOn; // toggle stats if (k == '*') ::starsOn = !::starsOn; // toggle stars - if (k == 'V') ::showingVoxels = !::showingVoxels; // toggle voxels + if (k == 'V' || k == 'v') ::showingVoxels = !::showingVoxels; // toggle voxels if (k == 'F') ::frustumOn = !::frustumOn; // toggle view frustum debugging if (k == 'C') ::cameraFrustum = !::cameraFrustum; // toggle which frustum to look at - if (k == 'G') ::viewFrustumFromOffset = !::viewFrustumFromOffset; // toggle view frustum from offset debugging + if (k == 'O' || k == 'G') ::viewFrustumFromOffset = !::viewFrustumFromOffset; // toggle view frustum offset debugging - if (k == '[') ::viewFrustumOffsetYaw -= 0.5; - if (k == ']') ::viewFrustumOffsetYaw += 0.5; - 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 == '|') ViewFrustum::fovAngleAdust -= 0.05; + if (k == '\\') ViewFrustum::fovAngleAdust += 0.05; + if (k == 'R') setFrustumRenderMode(MENU_ROW_PICKED); + if (k == '&') { ::paintOn = !::paintOn; // toggle paint ::setupPaintingVoxel(); // also randomizes colors @@ -1146,7 +1207,7 @@ void key(unsigned char k, int x, int y) if (k == '^') ::shiftPaintingColor(); // shifts randomize color between R,G,B dominant if (k == '-') ::sendVoxelServerEraseAll(); // sends erase all command to voxel server if (k == '%') ::sendVoxelServerAddScene(); // sends add scene command to voxel server - if (k == 'n') + if (k == 'n' || k == 'N') { noiseOn = !noiseOn; // Toggle noise if (noiseOn) @@ -1167,7 +1228,7 @@ void key(unsigned char k, int x, int y) #endif } - if (k == 'm') setMenu(-2); + if (k == 'm' || k == 'M') setMenu(MENU_ROW_PICKED); if (k == 'f') displayField = !displayField; if (k == 'l') displayLevels = !displayLevels; @@ -1187,9 +1248,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! @@ -1206,7 +1264,7 @@ void *networkReceive(void *args) switch (incomingPacket[0]) { case PACKET_HEADER_TRANSMITTER_DATA: - myAvatar.hand->processTransmitterData(incomingPacket, bytesReceived); + myAvatar.processTransmitterData(incomingPacket, bytesReceived); break; case PACKET_HEADER_VOXEL_DATA: case PACKET_HEADER_Z_COMMAND: @@ -1403,7 +1461,6 @@ int main(int argc, const char * argv[]) initDisplay(); printf( "Initialized Display.\n" ); - glutDisplayFunc(display); glutReshapeFunc(reshape); glutKeyboardFunc(key); @@ -1415,11 +1472,9 @@ int main(int argc, const char * argv[]) glutMouseFunc(mouseFunc); glutIdleFunc(idle); - init(); printf( "Init() complete.\n" ); - // Check to see if the user passed in a command line option for randomizing colors if (cmdOptionExists(argc, argv, "--NoColorRandomizer")) { wantColorRandomizer = false; diff --git a/libraries/shared/src/AgentList.cpp b/libraries/shared/src/AgentList.cpp index f973b3de1d..4895e421cd 100644 --- a/libraries/shared/src/AgentList.cpp +++ b/libraries/shared/src/AgentList.cpp @@ -427,11 +427,11 @@ void AgentList::stopDomainServerCheckInThread() { } int unpackAgentId(unsigned char *packedData, uint16_t *agentId) { - memcpy(packedData, agentId, sizeof(uint16_t)); + memcpy(agentId, packedData, sizeof(uint16_t)); return sizeof(uint16_t); } int packAgentId(unsigned char *packStore, uint16_t agentId) { - memcpy(&agentId, packStore, sizeof(uint16_t)); + memcpy(packStore, &agentId, sizeof(uint16_t)); return sizeof(uint16_t); } 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..73cce9baad --- /dev/null +++ b/libraries/voxels/src/ViewFrustum.cpp @@ -0,0 +1,114 @@ +// +// ViewFrustum.cpp +// hifi +// +// Created by Brad Hefta-Gaub on 04/11/13. +// +// Simple view frustum class. +// +// + +#include "ViewFrustum.h" + +float ViewFrustum::fovAngleAdust=1.65; + +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; + + // Calculating field of view. + // 0.7854f is 45 deg + // ViewFrustum::fovAngleAdust defaults to 1.65 + // Apparently our fov is around 1.75 times this value or 74.25 degrees + // you can adjust this in interface by using the "|" and "\" keys to tweak + // the adjustment and see effects of different FOVs + float fovHalfAngle = 0.7854f * ViewFrustum::fovAngleAdust; + 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..9fb17ae339 --- /dev/null +++ b/libraries/voxels/src/ViewFrustum.h @@ -0,0 +1,69 @@ +// +// 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(); + + static float fovAngleAdust; +}; + + +#endif /* defined(__hifi__ViewFrustum__) */