diff --git a/interface/src/Camera.cpp b/interface/src/Camera.cpp index bafda75515..320acca51d 100644 --- a/interface/src/Camera.cpp +++ b/interface/src/Camera.cpp @@ -9,12 +9,11 @@ #include "Camera.h" -Camera::Camera() -{ +Camera::Camera() { _mode = CAMERA_MODE_THIRD_PERSON; _tightness = DEFAULT_CAMERA_TIGHTNESS; _fieldOfView = 60.0; // default - _nearClip = 0.01; // default + _nearClip = 0.08; // default _farClip = 50.0; // default _yaw = 0.0; _pitch = 0.0; @@ -28,26 +27,40 @@ Camera::Camera() _orientation.setToIdentity(); } -void Camera::update( float deltaTime ) + + +void Camera::update( float deltaTime ) { + //---------------------------------------- + // derive t from tightness + //---------------------------------------- + float t = _tightness * deltaTime; + + if ( t > 1.0 ){ + t = 1.0; + } + + //---------------------------------------- + // update _yaw (before position!) + //---------------------------------------- + _yaw += ( _idealYaw - _yaw ) * t; float radian = ( _yaw / 180.0 ) * PIE; + //---------------------------------------- + // update _position + //---------------------------------------- //these need to be checked to make sure they correspond to the coordinate system. double x = _distance * -sin( radian ); double z = _distance * cos( radian ); double y = _up; _idealPosition = _targetPosition + glm::vec3( x, y, z ); - float t = _tightness * deltaTime; - - if ( t > 1.0 ){ - t = 1.0; - } _position += ( _idealPosition - _position ) * t; - _yaw += ( _idealYaw - _yaw ) * t; + //------------------------------------------------------------------------------ // generate the ortho-normals for the orientation based on the Euler angles + //------------------------------------------------------------------------------ _orientation.setToIdentity(); _orientation.yaw ( _yaw ); _orientation.pitch ( _pitch ); diff --git a/interface/src/main.cpp b/interface/src/main.cpp index 0b1816cd96..b382184281 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -515,12 +515,12 @@ int frustumDrawingMode = FRUSTUM_DRAW_MODE_ALL; // the mode we're drawing the 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; +bool viewFrustumFromOffset =false; // Wether or not to offset the view of the frustum +float viewFrustumOffsetYaw = -135.0; // the following variables control yaw, pitch, roll and distance form regular +float viewFrustumOffsetPitch = 0.0; // camera to the offset camera +float viewFrustumOffsetRoll = 0.0; +float viewFrustumOffsetDistance = 25.0; +float viewFrustumOffsetUp = 0.0; void render_view_frustum() { @@ -742,24 +742,20 @@ void display(void) Camera viewFrustumOffsetCamera = myCamera; if (::viewFrustumFromOffset && ::frustumOn) { - //---------------------------------------------------- + // 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 + ::viewFrustumOffsetUp ); - viewFrustumOffsetCamera.setDistance ( 0.5 + ::viewFrustumOffsetDistance ); + viewFrustumOffsetCamera.setYaw ( 180.0 - myAvatar.getBodyYaw() + ::viewFrustumOffsetYaw ); + viewFrustumOffsetCamera.setPitch ( ::viewFrustumOffsetPitch ); + viewFrustumOffsetCamera.setRoll ( ::viewFrustumOffsetRoll ); + viewFrustumOffsetCamera.setUp ( ::viewFrustumOffsetUp ); + viewFrustumOffsetCamera.setDistance ( ::viewFrustumOffsetDistance ); viewFrustumOffsetCamera.update(1.f/FPS); whichCamera = viewFrustumOffsetCamera; } - //--------------------------------------------- // transform view according to whichCamera // could be myCamera (if in normal mode) // or could be viewFrustumOffsetCamera if in offset mode - //--------------------------------------------- - // I changed the ordering here - roll is FIRST (JJV) glRotatef ( whichCamera.getRoll(), 0, 0, 1 ); glRotatef ( whichCamera.getPitch(), 1, 0, 0 ); @@ -1305,7 +1301,10 @@ void *networkReceive(void *args) voxels.parseData(incomingPacket, bytesReceived); break; case PACKET_HEADER_BULK_AVATAR_DATA: - AgentList::getInstance()->processBulkAgentData(&senderAddress, incomingPacket, bytesReceived, sizeof(float) * 11); + AgentList::getInstance()->processBulkAgentData(&senderAddress, + incomingPacket, + bytesReceived, + (sizeof(float) * 3) + (sizeof(uint16_t) * 2)); break; default: AgentList::getInstance()->processAgentData(&senderAddress, incomingPacket, bytesReceived); diff --git a/libraries/avatars/src/Orientation.cpp b/libraries/avatars/src/Orientation.cpp index ed1500a506..ed4af46d25 100755 --- a/libraries/avatars/src/Orientation.cpp +++ b/libraries/avatars/src/Orientation.cpp @@ -8,6 +8,9 @@ #include "Orientation.h" #include + +static bool testingForNormalizationAndOrthogonality = false; + Orientation::Orientation() { right = glm::vec3( 1.0, 0.0, 0.0 ); up = glm::vec3( 0.0, 1.0, 0.0 ); @@ -41,6 +44,8 @@ void Orientation::yaw( float angle ) { front = cosineFront + sineRight; right = cosineRight - sineFront; + + if ( testingForNormalizationAndOrthogonality ) { testForOrthogonalAndNormalizedVectors( EPSILON ); } } @@ -56,6 +61,8 @@ void Orientation::pitch( float angle ) { up = cosineUp + sineFront; front = cosineFront - sineUp; + + if ( testingForNormalizationAndOrthogonality ) { testForOrthogonalAndNormalizedVectors( EPSILON ); } } @@ -71,6 +78,8 @@ void Orientation::roll( float angle ) { up = cosineUp + sineRight; right = cosineRight - sineUp; + + if ( testingForNormalizationAndOrthogonality ) { testForOrthogonalAndNormalizedVectors( EPSILON ); } } @@ -79,3 +88,75 @@ void Orientation::setRightUpFront( const glm::vec3 &r, const glm::vec3 &u, const up = u; front = f; } + + + +//---------------------------------------------------------------------- +void Orientation::testForOrthogonalAndNormalizedVectors( float epsilon ) { + + //---------------------------------------------------------------- + // make sure vectors are normalized (or close to length 1) + //---------------------------------------------------------------- + float rightLength = glm::length( right ); + float upLength = glm::length( up ); + float frontLength = glm::length( front ); + + if (( rightLength > 1.0f + epsilon ) + || ( rightLength < 1.0f - epsilon )) { + printf( "Error in Orientation class: right direction length is %f \n", rightLength ); + } + assert ( rightLength > 1.0f - epsilon ); + assert ( rightLength < 1.0f + epsilon ); + + + if (( upLength > 1.0f + epsilon ) + || ( upLength < 1.0f - epsilon )) { + printf( "Error in Orientation class: up direction length is %f \n", upLength ); + } + assert ( upLength > 1.0f - epsilon ); + assert ( upLength < 1.0f + epsilon ); + + + if (( frontLength > 1.0f + epsilon ) + || ( frontLength < 1.0f - epsilon )) { + printf( "Error in Orientation class: front direction length is %f \n", frontLength ); + } + assert ( frontLength > 1.0f - epsilon ); + assert ( frontLength < 1.0f + epsilon ); + + + + //---------------------------------------------------------------- + // make sure vectors are orthoginal (or close enough) + //---------------------------------------------------------------- + glm::vec3 rightCross = glm::cross( up, front ); + glm::vec3 upCross = glm::cross( front, right ); + glm::vec3 frontCross = glm::cross( right, up ); + + float rightDiff = glm::length( rightCross - right ); + float upDiff = glm::length( upCross - up ); + float frontDiff = glm::length( frontCross - front ); + + + if ( rightDiff > epsilon ) { + printf( "Error in Orientation class: right direction not orthogonal to up and/or front. " ); + printf( "The tested cross of up and front is off by %f \n", rightDiff ); + } + assert ( rightDiff < epsilon ); + + + if ( upDiff > epsilon ) { + printf( "Error in Orientation class: up direction not orthogonal to front and/or right. " ); + printf( "The tested cross of front and right is off by %f \n", upDiff ); + } + assert ( upDiff < epsilon ); + + + if ( frontDiff > epsilon ) { + printf( "Error in Orientation class: front direction not orthogonal to right and/or up. " ); + printf( "The tested cross of right and up is off by %f \n", frontDiff ); + } + assert ( frontDiff < epsilon ); +} + + diff --git a/libraries/avatars/src/Orientation.h b/libraries/avatars/src/Orientation.h index ae209a5f47..e088f40517 100755 --- a/libraries/avatars/src/Orientation.h +++ b/libraries/avatars/src/Orientation.h @@ -39,6 +39,9 @@ public: glm::vec3 getFront() { return front; } void setRightUpFront( const glm::vec3 &, const glm::vec3 &, const glm::vec3 & ); + +private: + void testForOrthogonalAndNormalizedVectors( float epsilon ); }; diff --git a/libraries/shared/src/SharedUtil.h b/libraries/shared/src/SharedUtil.h index 6941c74462..f7e639ba43 100644 --- a/libraries/shared/src/SharedUtil.h +++ b/libraries/shared/src/SharedUtil.h @@ -18,20 +18,20 @@ #include #endif -static const float ZERO = 0.0; -static const float ONE = 1.0; -static const float ONE_HALF = 0.5; -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 computations -static const double SQUARE_ROOT_OF_2 = sqrt(2); -static const double SQUARE_ROOT_OF_3 = sqrt(3); -static const float METER = 1.0; -static const float DECIMETER = 0.1; -static const float CENTIMETER = 0.01; -static const float MILLIIMETER = 0.001; +static const float ZERO = 0.0f; +static const float ONE = 1.0f; +static const float ONE_HALF = 0.5f; +static const float ONE_THIRD = 0.333333f; +static const float PIE = 3.141592f; +static const float PI_TIMES_TWO = 3.141592f * 2.0f; +static const float PI_OVER_180 = 3.141592f / 180.0f; +static const float EPSILON = 0.000001f; //smallish positive number - used as margin of error for some computations +static const float SQUARE_ROOT_OF_2 = (float)sqrt(2); +static const float SQUARE_ROOT_OF_3 = (float)sqrt(3); +static const float METER = 1.0f; +static const float DECIMETER = 0.1f; +static const float CENTIMETER = 0.01f; +static const float MILLIIMETER = 0.001f; double usecTimestamp(timeval *time); double usecTimestampNow();