From 4f2af717f29baed7906ff732c0ac9a887d7560e8 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Tue, 4 Jun 2013 17:27:40 -0700 Subject: [PATCH] Fixed merge issue with new orientation vectors, migrated to common identity names --- interface/src/Avatar.cpp | 16 ++++----- interface/src/Avatar.h | 6 ++-- interface/src/Head.cpp | 47 +++++++++++++-------------- interface/src/Head.h | 6 ++-- interface/src/Util.cpp | 8 +++-- libraries/avatars/src/AvatarData.cpp | 4 +-- libraries/avatars/src/AvatarData.h | 5 --- libraries/voxels/src/ViewFrustum.cpp | 17 +++------- libraries/voxels/src/VoxelConstants.h | 5 +++ 9 files changed, 52 insertions(+), 62 deletions(-) diff --git a/interface/src/Avatar.cpp b/interface/src/Avatar.cpp index 4a3e8db2bc..dde6bca334 100644 --- a/interface/src/Avatar.cpp +++ b/interface/src/Avatar.cpp @@ -427,9 +427,9 @@ void Avatar::simulate(float deltaTime, Transmitter* transmitter) { } glm::quat orientation = getOrientation(); - glm::vec3 front = orientation * AVATAR_FRONT; - glm::vec3 right = orientation * AVATAR_RIGHT; - glm::vec3 up = orientation * AVATAR_UP; + glm::vec3 front = orientation * IDENTITY_FRONT; + glm::vec3 right = orientation * IDENTITY_RIGHT; + glm::vec3 up = orientation * IDENTITY_UP; // driving the avatar around should only apply if this is my avatar (as opposed to an avatar being driven remotely) const float THRUST_MAG = 600.0f; @@ -649,9 +649,9 @@ void Avatar::updateHandMovementAndTouching(float deltaTime) { glm::quat orientation = getOrientation(); // reset hand and arm positions according to hand movement - glm::vec3 right = orientation * AVATAR_RIGHT; - glm::vec3 up = orientation * AVATAR_UP; - glm::vec3 front = orientation * AVATAR_FRONT; + glm::vec3 right = orientation * IDENTITY_RIGHT; + glm::vec3 up = orientation * IDENTITY_UP; + glm::vec3 front = orientation * IDENTITY_FRONT; glm::vec3 transformedHandMovement = right * _movedHandOffset.x * 2.0f @@ -1123,14 +1123,14 @@ void Avatar::updateArmIKAndConstraints(float deltaTime) { glm::quat Avatar::computeRotationFromBodyToWorldUp(float proportion) const { glm::quat orientation = getOrientation(); - glm::vec3 currentUp = orientation * AVATAR_UP; + glm::vec3 currentUp = orientation * IDENTITY_UP; float angle = glm::degrees(acosf(glm::clamp(glm::dot(currentUp, _worldUpDirection), -1.0f, 1.0f))); if (angle < EPSILON) { return glm::quat(); } glm::vec3 axis; if (angle > 179.99f) { // 180 degree rotation; must use another axis - axis = orientation * AVATAR_RIGHT; + axis = orientation * IDENTITY_RIGHT; } else { axis = glm::normalize(glm::cross(currentUp, _worldUpDirection)); } diff --git a/interface/src/Avatar.h b/interface/src/Avatar.h index 20c431ef82..58e7127957 100644 --- a/interface/src/Avatar.h +++ b/interface/src/Avatar.h @@ -106,9 +106,9 @@ public: bool getIsNearInteractingOther () const { return _avatarTouch.getAbleToReachOtherAvatar();} const glm::vec3& getHeadJointPosition () const { return _skeleton.joint[ AVATAR_JOINT_HEAD_BASE ].position;} const glm::vec3& getBallPosition (AvatarJointID j) const { return _bodyBall[j].position;} - glm::vec3 getBodyRightDirection () const { return getOrientation() * AVATAR_RIGHT; } - glm::vec3 getBodyUpDirection () const { return getOrientation() * AVATAR_UP; } - glm::vec3 getBodyFrontDirection () const { return getOrientation() * AVATAR_FRONT; } + glm::vec3 getBodyRightDirection () const { return getOrientation() * IDENTITY_RIGHT; } + glm::vec3 getBodyUpDirection () const { return getOrientation() * IDENTITY_UP; } + glm::vec3 getBodyFrontDirection () const { return getOrientation() * IDENTITY_FRONT; } const glm::vec3& getVelocity () const { return _velocity;} float getSpeed () const { return _speed;} float getHeight () const { return _height;} diff --git a/interface/src/Head.cpp b/interface/src/Head.cpp index 21df933416..98e5c57cb1 100644 --- a/interface/src/Head.cpp +++ b/interface/src/Head.cpp @@ -171,9 +171,9 @@ void Head::determineIfLookingAtSomething() { void Head::calculateGeometry() { //generate orientation directions glm::quat orientation = getOrientation(); - glm::vec3 right = orientation * AVATAR_RIGHT; - glm::vec3 up = orientation * AVATAR_UP; - glm::vec3 front = orientation * AVATAR_FRONT; + glm::vec3 right = orientation * IDENTITY_RIGHT; + glm::vec3 up = orientation * IDENTITY_UP; + glm::vec3 front = orientation * IDENTITY_FRONT; //calculate the eye positions _leftEyePosition = _position @@ -346,9 +346,9 @@ void Head::renderMouth() { float s = sqrt(_averageLoudness); glm::quat orientation = getOrientation(); - glm::vec3 right = orientation * AVATAR_RIGHT; - glm::vec3 up = orientation * AVATAR_UP; - glm::vec3 front = orientation * AVATAR_FRONT; + glm::vec3 right = orientation * IDENTITY_RIGHT; + glm::vec3 up = orientation * IDENTITY_UP; + glm::vec3 front = orientation * IDENTITY_FRONT; glm::vec3 r = right * _scale * (0.30f + s * 0.0014f ); glm::vec3 u = up * _scale * (0.05f + s * 0.0040f ); @@ -414,9 +414,9 @@ void Head::renderEyeBrows() { glm::vec3 rightBottom = _leftEyePosition; glm::quat orientation = getOrientation(); - glm::vec3 right = orientation * AVATAR_RIGHT; - glm::vec3 up = orientation * AVATAR_UP; - glm::vec3 front = orientation * AVATAR_FRONT; + glm::vec3 right = orientation * IDENTITY_RIGHT; + glm::vec3 up = orientation * IDENTITY_UP; + glm::vec3 front = orientation * IDENTITY_FRONT; glm::vec3 r = right * length; glm::vec3 u = up * height; @@ -501,20 +501,20 @@ void Head::renderEyeBalls() { //rotate the eyeball to aim towards the lookat position glm::vec3 targetLookatAxis = glm::normalize(_lookAtPosition - _leftEyePosition); // the lookat direction - glm::vec3 rotationAxis = glm::cross(targetLookatAxis, AVATAR_UP); - float angle = 180.0f - angleBetween(targetLookatAxis, AVATAR_UP); + glm::vec3 rotationAxis = glm::cross(targetLookatAxis, IDENTITY_UP); + float angle = 180.0f - angleBetween(targetLookatAxis, IDENTITY_UP); glRotatef(angle, rotationAxis.x, rotationAxis.y, rotationAxis.z); glRotatef(180.0, 0.0f, 1.0f, 0.0f); //adjust roll to correct after previous rotations } else { //rotate the eyeball to aim straight ahead - glm::vec3 rotationAxisToHeadFront = glm::cross(front, AVATAR_UP); - float angleToHeadFront = 180.0f - angleBetween(front, AVATAR_UP); + glm::vec3 rotationAxisToHeadFront = glm::cross(front, IDENTITY_UP); + float angleToHeadFront = 180.0f - angleBetween(front, IDENTITY_UP); glRotatef(angleToHeadFront, rotationAxisToHeadFront.x, rotationAxisToHeadFront.y, rotationAxisToHeadFront.z); //set the amount of roll (for correction after previous rotations) - float rollRotation = angleBetween(front, AVATAR_FRONT); - float dot = glm::dot(front, -AVATAR_RIGHT); + float rollRotation = angleBetween(front, IDENTITY_FRONT); + float dot = glm::dot(front, -IDENTITY_RIGHT); if ( dot < 0.0f ) { rollRotation = -rollRotation; } glRotatef(rollRotation, 0.0f, 1.0f, 0.0f); //roll the iris or correct roll about the lookat vector } @@ -545,21 +545,21 @@ void Head::renderEyeBalls() { //rotate the eyeball to aim towards the lookat position glm::vec3 targetLookatAxis = glm::normalize(_lookAtPosition - _rightEyePosition); - glm::vec3 rotationAxis = glm::cross(targetLookatAxis, AVATAR_UP); - float angle = 180.0f - angleBetween(targetLookatAxis, AVATAR_UP); + glm::vec3 rotationAxis = glm::cross(targetLookatAxis, IDENTITY_UP); + float angle = 180.0f - angleBetween(targetLookatAxis, IDENTITY_UP); glRotatef(angle, rotationAxis.x, rotationAxis.y, rotationAxis.z); glRotatef(180.0f, 0.0f, 1.0f, 0.0f); //adjust roll to correct after previous rotations } else { //rotate the eyeball to aim straight ahead - glm::vec3 rotationAxisToHeadFront = glm::cross(front, AVATAR_UP); - float angleToHeadFront = 180.0f - angleBetween(front, AVATAR_UP); + glm::vec3 rotationAxisToHeadFront = glm::cross(front, IDENTITY_UP); + float angleToHeadFront = 180.0f - angleBetween(front, IDENTITY_UP); glRotatef(angleToHeadFront, rotationAxisToHeadFront.x, rotationAxisToHeadFront.y, rotationAxisToHeadFront.z); //set the amount of roll (for correction after previous rotations) - float rollRotation = angleBetween(front, AVATAR_FRONT); - float dot = glm::dot(front, -AVATAR_RIGHT); + float rollRotation = angleBetween(front, IDENTITY_FRONT); + float dot = glm::dot(front, -IDENTITY_RIGHT); if ( dot < 0.0f ) { rollRotation = -rollRotation; } glRotatef(rollRotation, 0.0f, 1.0f, 0.0f); //roll the iris or correct roll about the lookat vector } @@ -595,9 +595,8 @@ void Head::renderLookatVectors(glm::vec3 leftEyePosition, glm::vec3 rightEyePosi void Head::updateHairPhysics(float deltaTime) { glm::quat orientation = getOrientation(); - //glm::vec3 right = orientation * AVATAR_RIGHT; // not used for now - glm::vec3 up = orientation * AVATAR_UP; - glm::vec3 front = orientation * AVATAR_FRONT; + glm::vec3 up = orientation * IDENTITY_UP; + glm::vec3 front = orientation * IDENTITY_FRONT; for (int t = 0; t < NUM_HAIR_TUFTS; t ++) { diff --git a/interface/src/Head.h b/interface/src/Head.h index f49e127caf..66ce07d133 100644 --- a/interface/src/Head.h +++ b/interface/src/Head.h @@ -49,9 +49,9 @@ public: glm::quat getOrientation() const; glm::quat getWorldAlignedOrientation () const; - glm::vec3 getRightDirection() const { return getOrientation() * AVATAR_RIGHT; } - glm::vec3 getUpDirection () const { return getOrientation() * AVATAR_UP; } - glm::vec3 getFrontDirection() const { return getOrientation() * AVATAR_FRONT; } + glm::vec3 getRightDirection() const { return getOrientation() * IDENTITY_RIGHT; } + glm::vec3 getUpDirection () const { return getOrientation() * IDENTITY_UP; } + glm::vec3 getFrontDirection() const { return getOrientation() * IDENTITY_FRONT; } const bool getReturnToCenter() const { return _returnHeadToCenter; } // Do you want head to try to return to center (depends on interface detected) float getAverageLoudness() {return _averageLoudness;}; diff --git a/interface/src/Util.cpp b/interface/src/Util.cpp index 08ec6cf011..d16e6d36bb 100644 --- a/interface/src/Util.cpp +++ b/interface/src/Util.cpp @@ -21,6 +21,8 @@ #include "world.h" #include "Util.h" +#include "VoxelConstants.h" + using namespace std; // no clue which versions are affected... @@ -415,9 +417,9 @@ void renderCircle(glm::vec3 position, float radius, glm::vec3 surfaceNormal, int void renderOrientationDirections(glm::vec3 position, const glm::quat& orientation, float size) { - glm::vec3 pRight = position + orientation * AVATAR_RIGHT * size; - glm::vec3 pUp = position + orientation * AVATAR_UP * size; - glm::vec3 pFront = position + orientation * AVATAR_FRONT * size; + glm::vec3 pRight = position + orientation * IDENTITY_RIGHT * size; + glm::vec3 pUp = position + orientation * IDENTITY_UP * size; + glm::vec3 pFront = position + orientation * IDENTITY_FRONT * size; glColor3f(1.0f, 0.0f, 0.0f); glBegin(GL_LINE_STRIP); diff --git a/libraries/avatars/src/AvatarData.cpp b/libraries/avatars/src/AvatarData.cpp index 6ff6967b61..afb43f75ea 100644 --- a/libraries/avatars/src/AvatarData.cpp +++ b/libraries/avatars/src/AvatarData.cpp @@ -205,9 +205,7 @@ int AvatarData::parseData(unsigned char* sourceBuffer, int numBytes) { } glm::vec3 AvatarData::calculateCameraDirection() const { - const glm::vec3 IDENTITY_FRONT = glm::vec3( 0.0f, 0.0f, 1.0f); - glm::mat4 rotationMatrix = glm::mat4_cast(_cameraOrientation); - glm::vec3 direction = glm::vec3(glm::vec4(IDENTITY_FRONT, 0.0f) * rotationMatrix); + glm::vec3 direction = glm::vec3(_cameraOrientation * glm::vec4(IDENTITY_FRONT, 0.0f)); return direction; } diff --git a/libraries/avatars/src/AvatarData.h b/libraries/avatars/src/AvatarData.h index 0fc1104a0a..cf9845ab4c 100644 --- a/libraries/avatars/src/AvatarData.h +++ b/libraries/avatars/src/AvatarData.h @@ -27,11 +27,6 @@ const int HAND_STATE_START_BIT = 5; // 6th and 7th bits const float MAX_AUDIO_LOUDNESS = 1000.0; // close enough for mouth animation -// this is where the coordinate system is represented -const glm::vec3 AVATAR_RIGHT = glm::vec3(1.0f, 0.0f, 0.0f); -const glm::vec3 AVATAR_UP = glm::vec3(0.0f, 1.0f, 0.0f); -const glm::vec3 AVATAR_FRONT = glm::vec3(0.0f, 0.0f, -1.0f); - enum KeyState { NO_KEY_DOWN = 0, diff --git a/libraries/voxels/src/ViewFrustum.cpp b/libraries/voxels/src/ViewFrustum.cpp index 0f10428b23..b3c890ed07 100644 --- a/libraries/voxels/src/ViewFrustum.cpp +++ b/libraries/voxels/src/ViewFrustum.cpp @@ -13,6 +13,7 @@ #include #include "ViewFrustum.h" +#include "VoxelConstants.h" #include "SharedUtil.h" #include "Log.h" @@ -38,20 +39,10 @@ ViewFrustum::ViewFrustum() : _nearBottomRight(0,0,0) { } void ViewFrustum::setOrientation(const glm::quat& orientationAsQuaternion) { - glm::quat quat; - quat = quat * orientationAsQuaternion; - - // this is where the coordinate system is represented - const glm::vec3 IDENTITY_RIGHT = glm::vec3(-1.0f, 0.0f, 0.0f); - const glm::vec3 IDENTITY_UP = glm::vec3( 0.0f, 1.0f, 0.0f); - const glm::vec3 IDENTITY_FRONT = glm::vec3( 0.0f, 0.0f, 1.0f); - - glm::mat4 rotationMatrix = glm::mat4_cast(quat); - _orientation = orientationAsQuaternion; - _right = glm::vec3(glm::vec4(IDENTITY_RIGHT, 0.0f) * rotationMatrix); - _up = glm::vec3(glm::vec4(IDENTITY_UP, 0.0f) * rotationMatrix); - _direction = glm::vec3(glm::vec4(IDENTITY_FRONT, 0.0f) * rotationMatrix); + _right = glm::vec3(orientationAsQuaternion * glm::vec4(IDENTITY_RIGHT, 0.0f)); + _up = glm::vec3(orientationAsQuaternion * glm::vec4(IDENTITY_UP, 0.0f)); + _direction = glm::vec3(orientationAsQuaternion * glm::vec4(IDENTITY_FRONT, 0.0f)); } ///////////////////////////////////////////////////////////////////////////////////// diff --git a/libraries/voxels/src/VoxelConstants.h b/libraries/voxels/src/VoxelConstants.h index 5bf1345d73..d0ae6f538a 100644 --- a/libraries/voxels/src/VoxelConstants.h +++ b/libraries/voxels/src/VoxelConstants.h @@ -15,6 +15,11 @@ #include #include +// this is where the coordinate system is represented +const glm::vec3 IDENTITY_RIGHT = glm::vec3( 1.0f, 0.0f, 0.0f); +const glm::vec3 IDENTITY_UP = glm::vec3( 0.0f, 1.0f, 0.0f); +const glm::vec3 IDENTITY_FRONT = glm::vec3( 0.0f, 0.0f,-1.0f); + const int TREE_SCALE = 128; const int NUMBER_OF_CHILDREN = 8;