From e2ec8245b0752b8b52cb2b05b8eb4f39ca072e09 Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Thu, 30 May 2013 14:56:12 -0700 Subject: [PATCH 1/7] Rather than adding Euler angles, compose quaternions for gyros. --- interface/src/Application.cpp | 2 +- interface/src/Avatar.cpp | 10 +++++----- interface/src/Avatar.h | 2 +- interface/src/Head.cpp | 7 +++++++ interface/src/Head.h | 1 + 5 files changed, 15 insertions(+), 7 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 1e9e119777..262bf6625a 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -1274,7 +1274,7 @@ void Application::init() { void Application::updateAvatar(float deltaTime) { // Update my avatar's head position from gyros - _myAvatar.updateHeadFromGyros(deltaTime, &_serialPort, &_gravity); + _myAvatar.updateHeadFromGyros(deltaTime, &_serialPort); // Grab latest readings from the gyros float measuredPitchRate = _serialPort.getLastPitchRate(); diff --git a/interface/src/Avatar.cpp b/interface/src/Avatar.cpp index 8f6ac7c991..9e41c32273 100644 --- a/interface/src/Avatar.cpp +++ b/interface/src/Avatar.cpp @@ -124,7 +124,7 @@ void Avatar::reset() { } // Update avatar head rotation with sensor data -void Avatar::updateHeadFromGyros(float deltaTime, SerialInterface* serialInterface, glm::vec3* gravity) { +void Avatar::updateHeadFromGyros(float deltaTime, SerialInterface* serialInterface) { const float AMPLIFY_PITCH = 2.f; const float AMPLIFY_YAW = 2.f; const float AMPLIFY_ROLL = 2.f; @@ -134,10 +134,10 @@ void Avatar::updateHeadFromGyros(float deltaTime, SerialInterface* serialInterfa float measuredRollRate = serialInterface->getLastRollRate(); // Update avatar head position based on measured gyro rates - - _head.addPitch(measuredPitchRate * AMPLIFY_PITCH * deltaTime); - _head.addYaw (measuredYawRate * AMPLIFY_YAW * deltaTime); - _head.addRoll (measuredRollRate * AMPLIFY_ROLL * deltaTime); + _head.setOrientation(_head.getOrientation() * glm::quat(glm::radians(glm::vec3( + measuredPitchRate * AMPLIFY_PITCH * deltaTime, + measuredYawRate * AMPLIFY_YAW * deltaTime, + measuredRollRate * AMPLIFY_ROLL * deltaTime)))); // Update head lean distance based on accelerometer data glm::vec3 headRotationRates(_head.getPitch(), _head.getYaw(), _head.getRoll()); diff --git a/interface/src/Avatar.h b/interface/src/Avatar.h index db8176898a..d272514ed1 100644 --- a/interface/src/Avatar.h +++ b/interface/src/Avatar.h @@ -48,7 +48,7 @@ public: void reset(); void simulate(float deltaTime, Transmitter* transmitter); - void updateHeadFromGyros(float frametime, SerialInterface * serialInterface, glm::vec3 * gravity); + void updateHeadFromGyros(float frametime, SerialInterface * serialInterface); void updateFromMouse(int mouseX, int mouseY, int screenWidth, int screenHeight); void addBodyYaw(float y) {_bodyYaw += y;}; void render(bool lookingInMirror); diff --git a/interface/src/Head.cpp b/interface/src/Head.cpp index d1ee699dc8..187fcc3e03 100644 --- a/interface/src/Head.cpp +++ b/interface/src/Head.cpp @@ -307,6 +307,13 @@ void Head::renderMohawk(glm::vec3 cameraPosition) { } } +void Head::setOrientation(const glm::quat& orientation) { + glm::vec3 eulerAngles = safeEulerAngles(glm::inverse(glm::quat(glm::radians(_bodyRotation))) * orientation); + _pitch = eulerAngles.x; + _yaw = eulerAngles.y; + _roll = eulerAngles.z; +} + glm::quat Head::getOrientation() const { return glm::quat(glm::radians(_bodyRotation)) * glm::quat(glm::radians(_lookingInMirror ? glm::vec3(_pitch, -_yaw, -_roll) : glm::vec3(_pitch, _yaw, _roll))); diff --git a/interface/src/Head.h b/interface/src/Head.h index f49e127caf..36da1b082f 100644 --- a/interface/src/Head.h +++ b/interface/src/Head.h @@ -45,6 +45,7 @@ public: void setAverageLoudness(float averageLoudness ) { _averageLoudness = averageLoudness; } void setReturnToCenter (bool returnHeadToCenter) { _returnHeadToCenter = returnHeadToCenter; } void setRenderLookatVectors(bool onOff ) { _renderLookatVectors = onOff; } + void setOrientation(const glm::quat& orientation); glm::quat getOrientation() const; glm::quat getWorldAlignedOrientation () const; From 3f6cf08b970969373e1513220c88f37b0fb365a7 Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Thu, 30 May 2013 15:15:12 -0700 Subject: [PATCH 2/7] Removed remaining Orientation bits (and class itself), enforce limits on head yaw/pitch/roll. --- interface/src/Camera.h | 1 - interface/src/Head.cpp | 6 +- interface/src/Util.cpp | 131 +------------------------- interface/src/Util.h | 40 +------- libraries/avatars/src/Orientation.cpp | 121 ------------------------ libraries/avatars/src/Orientation.h | 55 ----------- 6 files changed, 10 insertions(+), 344 deletions(-) delete mode 100755 libraries/avatars/src/Orientation.cpp delete mode 100644 libraries/avatars/src/Orientation.h diff --git a/interface/src/Camera.h b/interface/src/Camera.h index 4d56774326..1f36d33f58 100644 --- a/interface/src/Camera.h +++ b/interface/src/Camera.h @@ -8,7 +8,6 @@ #ifndef __interface__camera__ #define __interface__camera__ -#include "Orientation.h" #include #include diff --git a/interface/src/Head.cpp b/interface/src/Head.cpp index 187fcc3e03..b53519328b 100644 --- a/interface/src/Head.cpp +++ b/interface/src/Head.cpp @@ -309,9 +309,9 @@ void Head::renderMohawk(glm::vec3 cameraPosition) { void Head::setOrientation(const glm::quat& orientation) { glm::vec3 eulerAngles = safeEulerAngles(glm::inverse(glm::quat(glm::radians(_bodyRotation))) * orientation); - _pitch = eulerAngles.x; - _yaw = eulerAngles.y; - _roll = eulerAngles.z; + setPitch(eulerAngles.x); + setYaw(eulerAngles.y); + setRoll(eulerAngles.z); } glm::quat Head::getOrientation() const { diff --git a/interface/src/Util.cpp b/interface/src/Util.cpp index 41b25ea776..05dfc50502 100644 --- a/interface/src/Util.cpp +++ b/interface/src/Util.cpp @@ -12,8 +12,8 @@ #include #include -#include #include +#include #include #include "Log.h" @@ -393,10 +393,10 @@ void renderCircle(glm::vec3 position, float radius, glm::vec3 surfaceNormal, int } -void renderOrientationDirections(glm::vec3 position, Orientation orientation, float size) { - glm::vec3 pRight = position + orientation.getRight() * size; - glm::vec3 pUp = position + orientation.getUp () * size; - glm::vec3 pFront = position + orientation.getFront() * size; +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; glColor3f(1.0f, 0.0f, 0.0f); glBegin(GL_LINE_STRIP); @@ -424,126 +424,5 @@ bool closeEnoughForGovernmentWork(float a, float b) { } -void testOrientationClass() { - printLog("\n----------\ntestOrientationClass()\n----------\n\n"); - - oTestCase tests[] = { - // - inputs ------------, outputs -------------------- ------------------- ---------------------------- - // -- front -------------------, -- up -------------, -- right ------------------- - // ( yaw , pitch, roll , front.x , front.y , front.z , up.x , up.y , up.z , right.x , right.y , right.z ) - - // simple yaw tests - oTestCase( 0.f , 0.f , 0.f , 0.f , 0.f , 1.0f , 0.f , 1.0f , 0.f , -1.0f , 0.f , 0.f ), - oTestCase(45.0f , 0.f , 0.f , 0.707107f , 0.f , 0.707107f , 0.f , 1.0f , 0.f , -0.707107f, 0.f , 0.707107f), - oTestCase( 90.0f, 0.f , 0.f , 1.0f , 0.f , 0.f , 0.f , 1.0f , 0.f , 0.0f , 0.f , 1.0f ), - oTestCase(135.0f, 0.f , 0.f , 0.707107f , 0.f ,-0.707107f , 0.f , 1.0f , 0.f , 0.707107f, 0.f , 0.707107f), - oTestCase(180.0f, 0.f , 0.f , 0.f , 0.f , -1.0f , 0.f , 1.0f , 0.f , 1.0f , 0.f , 0.f ), - oTestCase(225.0f, 0.f , 0.f , -0.707107f , 0.f ,-0.707107f , 0.f , 1.0f , 0.f , 0.707107f, 0.f , -0.707107f), - oTestCase(270.0f, 0.f , 0.f , -1.0f , 0.f , 0.f , 0.f , 1.0f , 0.f , 0.0f , 0.f , -1.0f ), - oTestCase(315.0f, 0.f , 0.f , -0.707107f , 0.f , 0.707107f , 0.f , 1.0f , 0.f , -0.707107f, 0.f , -0.707107f), - oTestCase(-45.0f, 0.f , 0.f , -0.707107f , 0.f , 0.707107f , 0.f , 1.0f , 0.f , -0.707107f, 0.f , -0.707107f), - oTestCase(-90.0f, 0.f , 0.f , -1.0f , 0.f , 0.f , 0.f , 1.0f , 0.f , 0.0f , 0.f , -1.0f ), - oTestCase(-135.0f,0.f , 0.f , -0.707107f , 0.f ,-0.707107f , 0.f , 1.0f , 0.f , 0.707107f, 0.f , -0.707107f), - oTestCase(-180.0f,0.f , 0.f , 0.f , 0.f , -1.0f , 0.f , 1.0f , 0.f , 1.0f , 0.f , 0.f ), - oTestCase(-225.0f,0.f , 0.f , 0.707107f , 0.f ,-0.707107f , 0.f , 1.0f , 0.f , 0.707107f, 0.f , 0.707107f), - oTestCase(-270.0f,0.f , 0.f , 1.0f , 0.f , 0.f , 0.f , 1.0f , 0.f , 0.0f , 0.f , 1.0f ), - oTestCase(-315.0f,0.f , 0.f , 0.707107f , 0.f , 0.707107f , 0.f , 1.0f , 0.f , -0.707107f, 0.f , 0.707107f), - - // simple pitch tests - oTestCase( 0.f , 0.f , 0.f , 0.f, 0.f , 1.0f , 0.f , 1.0f , 0.f , -1.0f , 0.f , 0.f ), - oTestCase( 0.f ,45.0f , 0.f , 0.f, 0.707107f , 0.707107f, 0.f ,0.707107f, -0.707107f, -1.0f , 0.f , 0.f ), - oTestCase( 0.f ,90.f , 0.f , 0.f, 1.0f , 0.0f , 0.f ,0.0f , -1.0f , -1.0f , 0.f , 0.f ), - oTestCase( 0.f ,135.0f, 0.f , 0.f, 0.707107f , -0.707107f, 0.f ,-0.707107f, -0.707107f, -1.0f , 0.f , 0.f ), - oTestCase( 0.f ,180.f , 0.f , 0.f, 0.0f ,-1.0f , 0.f ,-1.0f , 0.f , -1.0f , 0.f , 0.f ), - oTestCase( 0.f ,225.0f, 0.f , 0.f,-0.707107f , -0.707107f, 0.f ,-0.707107f, 0.707107f, -1.0f , 0.f , 0.f ), - oTestCase( 0.f ,270.f , 0.f , 0.f,-1.0f , 0.0f , 0.f ,0.0f , 1.0f , -1.0f , 0.f , 0.f ), - oTestCase( 0.f ,315.0f, 0.f , 0.f,-0.707107f , 0.707107f, 0.f , 0.707107f, 0.707107f, -1.0f , 0.f , 0.f ), - - // simple roll tests - oTestCase( 0.f , 0.f , 0.f , 0.f , 0.f , 1.0f , 0.f , 1.0f ,0.0f , -1.0f , 0.f , 0.0f ), - oTestCase( 0.f , 0.f ,45.0f , 0.f , 0.f , 1.0f , 0.707107f , 0.707107f ,0.0f , -0.707107f, 0.707107f, 0.0f ), - oTestCase( 0.f , 0.f ,90.f , 0.f , 0.f , 1.0f , 1.0f , 0.0f ,0.0f , 0.0f , 1.0f , 0.0f ), - oTestCase( 0.f , 0.f ,135.0f , 0.f , 0.f , 1.0f , 0.707107f , -0.707107f,0.0f , 0.707107f , 0.707107f, 0.0f ), - oTestCase( 0.f , 0.f ,180.f , 0.f , 0.f , 1.0f , 0.0f , -1.0f ,0.0f , 1.0f , 0.0f , 0.0f ), - oTestCase( 0.f , 0.f ,225.0f , 0.f , 0.f , 1.0f , -0.707107f, -0.707107f,0.0f , 0.707107f ,-0.707107f, 0.0f ), - oTestCase( 0.f , 0.f ,270.f , 0.f , 0.f , 1.0f , -1.0f , 0.0f ,0.0f , 0.0f , -1.0f , 0.0f ), - oTestCase( 0.f , 0.f ,315.0f , 0.f , 0.f , 1.0f , -0.707107f, 0.707107f ,0.0f , -0.707107f,-0.707107f, 0.0f ), - - // yaw combo tests - oTestCase( 90.f , 90.f , 0.f , 0.f , 1.0f , 0.0f , -1.0f , 0.0f , 0.f , 0.0f , 0.f , 1.0f ), - oTestCase( 90.f , 0.f , 90.f , 1.0f , 0.0f, 0.f , 0.0f , 0.0f , -1.f , 0.0f , 1.0f , 0.0f ), - }; - - int failedCount = 0; - int totalTests = sizeof(tests)/sizeof(oTestCase); - - for (int i=0; i < totalTests; i++) { - - bool passed = true; // I'm an optimist! - - float yaw = tests[i].yaw; - float pitch = tests[i].pitch; - float roll = tests[i].roll; - - Orientation o1; - o1.setToIdentity(); - o1.yaw(yaw); - o1.pitch(pitch); - o1.roll(roll); - - glm::vec3 front = o1.getFront(); - glm::vec3 up = o1.getUp(); - glm::vec3 right = o1.getRight(); - - printLog("\n-----\nTest: %d - yaw=%f , pitch=%f , roll=%f \n",i+1,yaw,pitch,roll); - - printLog("\nFRONT\n"); - printLog(" + received: front.x=%f, front.y=%f, front.z=%f\n",front.x,front.y,front.z); - - if (closeEnoughForGovernmentWork(front.x, tests[i].frontX) - && closeEnoughForGovernmentWork(front.y, tests[i].frontY) - && closeEnoughForGovernmentWork(front.z, tests[i].frontZ)) { - printLog(" front vector PASSES!\n"); - } else { - printLog(" expected: front.x=%f, front.y=%f, front.z=%f\n",tests[i].frontX,tests[i].frontY,tests[i].frontZ); - printLog(" front vector FAILED! \n"); - passed = false; - } - - printLog("\nUP\n"); - printLog(" + received: up.x=%f, up.y=%f, up.z=%f\n",up.x,up.y,up.z); - if (closeEnoughForGovernmentWork(up.x, tests[i].upX) - && closeEnoughForGovernmentWork(up.y, tests[i].upY) - && closeEnoughForGovernmentWork(up.z, tests[i].upZ)) { - printLog(" up vector PASSES!\n"); - } else { - printLog(" expected: up.x=%f, up.y=%f, up.z=%f\n",tests[i].upX,tests[i].upY,tests[i].upZ); - printLog(" up vector FAILED!\n"); - passed = false; - } - - - printLog("\nRIGHT\n"); - printLog(" + received: right.x=%f, right.y=%f, right.z=%f\n",right.x,right.y,right.z); - if (closeEnoughForGovernmentWork(right.x, tests[i].rightX) - && closeEnoughForGovernmentWork(right.y, tests[i].rightY) - && closeEnoughForGovernmentWork(right.z, tests[i].rightZ)) { - printLog(" right vector PASSES!\n"); - } else { - printLog(" expected: right.x=%f, right.y=%f, right.z=%f\n",tests[i].rightX,tests[i].rightY,tests[i].rightZ); - printLog(" right vector FAILED!\n"); - passed = false; - } - - if (!passed) { - printLog("\n-----\nTest: %d - FAILED! \n----------\n\n",i+1); - failedCount++; - } - } - printLog("\n-----\nTotal Failed: %d out of %d \n----------\n\n",failedCount,totalTests); - printLog("\n----------DONE----------\n\n"); -} - - diff --git a/interface/src/Util.h b/interface/src/Util.h index d93267f175..0823ac405b 100644 --- a/interface/src/Util.h +++ b/interface/src/Util.h @@ -16,8 +16,7 @@ #endif #include - -#include +#include // the standard sans serif font family #define SANS_FONT_FAMILY "Helvetica" @@ -56,44 +55,9 @@ void drawGroundPlaneGrid(float size); void renderDiskShadow(glm::vec3 position, glm::vec3 upDirection, float radius, float darkness); -void renderOrientationDirections( glm::vec3 position, Orientation orientation, float size ); +void renderOrientationDirections( glm::vec3 position, const glm::quat& orientation, float size ); void renderSphereOutline(glm::vec3 position, float radius, int numSides, glm::vec3 cameraPosition); void renderCircle(glm::vec3 position, float radius, glm::vec3 surfaceNormal, int numSides ); - -class oTestCase { -public: - float yaw; - float pitch; - float roll; - - float frontX; - float frontY; - float frontZ; - - float upX; - float upY; - float upZ; - - float rightX; - float rightY; - float rightZ; - - oTestCase( - float yaw, float pitch, float roll, - float frontX, float frontY, float frontZ, - float upX, float upY, float upZ, - float rightX, float rightY, float rightZ - ) : - yaw(yaw),pitch(pitch),roll(roll), - frontX(frontX),frontY(frontY),frontZ(frontZ), - upX(upX),upY(upY),upZ(upZ), - rightX(rightX),rightY(rightY),rightZ(rightZ) - {}; -}; - - -void testOrientationClass(); - #endif diff --git a/libraries/avatars/src/Orientation.cpp b/libraries/avatars/src/Orientation.cpp deleted file mode 100755 index cae0f70201..0000000000 --- a/libraries/avatars/src/Orientation.cpp +++ /dev/null @@ -1,121 +0,0 @@ -//----------------------------------------------------------- -// -// Created by Jeffrey Ventrella -// Copyright (c) 2013 High Fidelity, Inc. All rights reserved. -// -//----------------------------------------------------------- - -#include "Orientation.h" -#include "SharedUtil.h" - -static const bool USING_QUATERNIONS = true; - -Orientation::Orientation() { - setToIdentity(); -} - -void Orientation::setToIdentity() { - - quat = glm::quat(); - right = glm::vec3(IDENTITY_RIGHT); - up = glm::vec3(IDENTITY_UP ); - front = glm::vec3(IDENTITY_FRONT); -} - -void Orientation::set(Orientation o) { - - quat = o.quat; - right = o.right; - up = o.up; - front = o.front; -} - -void Orientation::yaw(float angle) { - - float radian = angle * PI_OVER_180; - - if (USING_QUATERNIONS) { - rotateAndGenerateDirections(glm::quat(glm::vec3(0.0f, -radian, 0.0f))); - } else { - float s = sin(radian); - float c = cos(radian); - - glm::vec3 cosineFront = front * c; - glm::vec3 cosineRight = right * c; - glm::vec3 sineFront = front * s; - glm::vec3 sineRight = right * s; - - front = cosineFront - sineRight; - right = cosineRight + sineFront; - } -} - -void Orientation::pitch(float angle) { - - float radian = angle * PI_OVER_180; - - if (USING_QUATERNIONS) { - rotateAndGenerateDirections(glm::quat(glm::vec3(radian, 0.0f, 0.0f))); - } else { - float s = sin(radian); - float c = cos(radian); - - glm::vec3 cosineUp = up * c; - glm::vec3 cosineFront = front * c; - glm::vec3 sineUp = up * s; - glm::vec3 sineFront = front * s; - - up = cosineUp - sineFront; - front = cosineFront + sineUp; - } -} - -void Orientation::roll(float angle) { - - float radian = angle * PI_OVER_180; - - if (USING_QUATERNIONS) { - rotateAndGenerateDirections(glm::quat(glm::vec3(0.0f, 0.0f, radian))); - } else { - float s = sin(radian); - float c = cos(radian); - - glm::vec3 cosineUp = up * c; - glm::vec3 cosineRight = right * c; - glm::vec3 sineUp = up * s; - glm::vec3 sineRight = right * s; - - up = cosineUp - sineRight; - right = cosineRight + sineUp; - } -} - -void Orientation::rotate(float pitch_change, float yaw_change, float roll_change) { - pitch(pitch_change); - yaw (yaw_change); - roll (roll_change); -} - -void Orientation::rotate(glm::vec3 eulerAngles) { - -//this needs to be optimized! - pitch(eulerAngles.x); - yaw (eulerAngles.y); - roll (eulerAngles.z); -} - -void Orientation::rotate( glm::quat rotation ) { - rotateAndGenerateDirections(rotation); -} - - -void Orientation::rotateAndGenerateDirections(glm::quat rotation) { - - quat = quat * rotation; - - glm::mat4 rotationMatrix = glm::mat4_cast(quat); - - right = glm::vec3(glm::vec4(IDENTITY_RIGHT, 0.0f) * rotationMatrix); - up = glm::vec3(glm::vec4(IDENTITY_UP, 0.0f) * rotationMatrix); - front = glm::vec3(glm::vec4(IDENTITY_FRONT, 0.0f) * rotationMatrix); -} diff --git a/libraries/avatars/src/Orientation.h b/libraries/avatars/src/Orientation.h deleted file mode 100644 index 56209db934..0000000000 --- a/libraries/avatars/src/Orientation.h +++ /dev/null @@ -1,55 +0,0 @@ -//----------------------------------------------------------- -// -// Copyright (c) 2013 High Fidelity, Inc. All rights reserved. -// -//----------------------------------------------------------- - -#ifndef __interface__orientation__ -#define __interface__orientation__ - -#include -#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); - -class Orientation -{ -public: - Orientation(); - - void set(Orientation); - void setToIdentity(); - - void pitch(float pitch_change); - void yaw (float yaw_change); - void roll (float roll_change); - - void rotate(float pitch, float yaw, float roll); - void rotate(glm::vec3 EulerAngles); - void rotate(glm::quat quaternion); - - const glm::quat& getQuat() const {return quat;} - - const glm::vec3& getRight() const {return right;} - const glm::vec3& getUp () const {return up; } - const glm::vec3& getFront() const {return front;} - - const glm::vec3& getIdentityRight() const {return IDENTITY_RIGHT;} - const glm::vec3& getIdentityUp () const {return IDENTITY_UP;} - const glm::vec3& getIdentityFront() const {return IDENTITY_FRONT;} - -private: - - glm::quat quat; - glm::vec3 right; - glm::vec3 up; - glm::vec3 front; - - void rotateAndGenerateDirections(glm::quat rotation); -}; - -#endif From 826ef33d4b6842d6078f01fd2192b4adbf82238e Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Thu, 30 May 2013 15:20:20 -0700 Subject: [PATCH 3/7] Reverse angles for mirror mode. --- interface/src/Head.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/interface/src/Head.cpp b/interface/src/Head.cpp index b53519328b..19863f6fa4 100644 --- a/interface/src/Head.cpp +++ b/interface/src/Head.cpp @@ -309,9 +309,15 @@ void Head::renderMohawk(glm::vec3 cameraPosition) { void Head::setOrientation(const glm::quat& orientation) { glm::vec3 eulerAngles = safeEulerAngles(glm::inverse(glm::quat(glm::radians(_bodyRotation))) * orientation); - setPitch(eulerAngles.x); - setYaw(eulerAngles.y); - setRoll(eulerAngles.z); + if (_lookingInMirror) { + setPitch(eulerAngles.x); + setYaw(eulerAngles.y); + setRoll(eulerAngles.z); + } else { + setPitch(eulerAngles.x); + setYaw(-eulerAngles.y); + setRoll(-eulerAngles.z); + } } glm::quat Head::getOrientation() const { From 780b049f4b15798fb13e72a8c56fd79b8ea3adb4 Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Thu, 30 May 2013 15:21:54 -0700 Subject: [PATCH 4/7] I got these backwards. --- interface/src/Head.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/interface/src/Head.cpp b/interface/src/Head.cpp index 19863f6fa4..ffc518abcf 100644 --- a/interface/src/Head.cpp +++ b/interface/src/Head.cpp @@ -310,13 +310,13 @@ void Head::renderMohawk(glm::vec3 cameraPosition) { void Head::setOrientation(const glm::quat& orientation) { glm::vec3 eulerAngles = safeEulerAngles(glm::inverse(glm::quat(glm::radians(_bodyRotation))) * orientation); if (_lookingInMirror) { - setPitch(eulerAngles.x); - setYaw(eulerAngles.y); - setRoll(eulerAngles.z); - } else { setPitch(eulerAngles.x); setYaw(-eulerAngles.y); setRoll(-eulerAngles.z); + } else { + setPitch(eulerAngles.x); + setYaw(eulerAngles.y); + setRoll(eulerAngles.z); } } From 47bf5a2b773846602e395ca0ab5772b22c00757d Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Thu, 30 May 2013 15:43:07 -0700 Subject: [PATCH 5/7] Have the Head control how orientations are added. --- interface/src/Avatar.cpp | 4 ++-- interface/src/Head.cpp | 8 ++++++++ interface/src/Head.h | 2 ++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/interface/src/Avatar.cpp b/interface/src/Avatar.cpp index 9e41c32273..d1537b2145 100644 --- a/interface/src/Avatar.cpp +++ b/interface/src/Avatar.cpp @@ -134,10 +134,10 @@ void Avatar::updateHeadFromGyros(float deltaTime, SerialInterface* serialInterfa float measuredRollRate = serialInterface->getLastRollRate(); // Update avatar head position based on measured gyro rates - _head.setOrientation(_head.getOrientation() * glm::quat(glm::radians(glm::vec3( + _head.addOrientation( measuredPitchRate * AMPLIFY_PITCH * deltaTime, measuredYawRate * AMPLIFY_YAW * deltaTime, - measuredRollRate * AMPLIFY_ROLL * deltaTime)))); + measuredRollRate * AMPLIFY_ROLL * deltaTime); // Update head lean distance based on accelerometer data glm::vec3 headRotationRates(_head.getPitch(), _head.getYaw(), _head.getRoll()); diff --git a/interface/src/Head.cpp b/interface/src/Head.cpp index ffc518abcf..ff1fd12b78 100644 --- a/interface/src/Head.cpp +++ b/interface/src/Head.cpp @@ -307,6 +307,14 @@ void Head::renderMohawk(glm::vec3 cameraPosition) { } } +void Head::addOrientation(float pitch, float yaw, float roll) { + if (_lookingInMirror) { + yaw = -yaw; + roll = -roll; + } + setOrientation(getOrientation() * glm::quat(glm::radians(glm::vec3(pitch, yaw, roll)))); +} + void Head::setOrientation(const glm::quat& orientation) { glm::vec3 eulerAngles = safeEulerAngles(glm::inverse(glm::quat(glm::radians(_bodyRotation))) * orientation); if (_lookingInMirror) { diff --git a/interface/src/Head.h b/interface/src/Head.h index 36da1b082f..265bab51f1 100644 --- a/interface/src/Head.h +++ b/interface/src/Head.h @@ -47,6 +47,8 @@ public: void setRenderLookatVectors(bool onOff ) { _renderLookatVectors = onOff; } void setOrientation(const glm::quat& orientation); + void addOrientation(float pitch, float yaw, float roll); + glm::quat getOrientation() const; glm::quat getWorldAlignedOrientation () const; From 9213cfd0c23bfd9b9fb26f2db9cd25d1a272a875 Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Thu, 30 May 2013 15:48:00 -0700 Subject: [PATCH 6/7] Revert to simply adding the Eulers. --- interface/src/Avatar.cpp | 7 +++---- interface/src/Head.cpp | 21 --------------------- interface/src/Head.h | 3 --- 3 files changed, 3 insertions(+), 28 deletions(-) diff --git a/interface/src/Avatar.cpp b/interface/src/Avatar.cpp index d1537b2145..370e3b0107 100644 --- a/interface/src/Avatar.cpp +++ b/interface/src/Avatar.cpp @@ -134,10 +134,9 @@ void Avatar::updateHeadFromGyros(float deltaTime, SerialInterface* serialInterfa float measuredRollRate = serialInterface->getLastRollRate(); // Update avatar head position based on measured gyro rates - _head.addOrientation( - measuredPitchRate * AMPLIFY_PITCH * deltaTime, - measuredYawRate * AMPLIFY_YAW * deltaTime, - measuredRollRate * AMPLIFY_ROLL * deltaTime); + _head.addPitch(measuredPitchRate * AMPLIFY_PITCH * deltaTime); + _head.addYaw(measuredYawRate * AMPLIFY_YAW * deltaTime); + _head.addRoll(measuredRollRate * AMPLIFY_ROLL * deltaTime); // Update head lean distance based on accelerometer data glm::vec3 headRotationRates(_head.getPitch(), _head.getYaw(), _head.getRoll()); diff --git a/interface/src/Head.cpp b/interface/src/Head.cpp index ff1fd12b78..d1ee699dc8 100644 --- a/interface/src/Head.cpp +++ b/interface/src/Head.cpp @@ -307,27 +307,6 @@ void Head::renderMohawk(glm::vec3 cameraPosition) { } } -void Head::addOrientation(float pitch, float yaw, float roll) { - if (_lookingInMirror) { - yaw = -yaw; - roll = -roll; - } - setOrientation(getOrientation() * glm::quat(glm::radians(glm::vec3(pitch, yaw, roll)))); -} - -void Head::setOrientation(const glm::quat& orientation) { - glm::vec3 eulerAngles = safeEulerAngles(glm::inverse(glm::quat(glm::radians(_bodyRotation))) * orientation); - if (_lookingInMirror) { - setPitch(eulerAngles.x); - setYaw(-eulerAngles.y); - setRoll(-eulerAngles.z); - } else { - setPitch(eulerAngles.x); - setYaw(eulerAngles.y); - setRoll(eulerAngles.z); - } -} - glm::quat Head::getOrientation() const { return glm::quat(glm::radians(_bodyRotation)) * glm::quat(glm::radians(_lookingInMirror ? glm::vec3(_pitch, -_yaw, -_roll) : glm::vec3(_pitch, _yaw, _roll))); diff --git a/interface/src/Head.h b/interface/src/Head.h index 265bab51f1..f49e127caf 100644 --- a/interface/src/Head.h +++ b/interface/src/Head.h @@ -45,9 +45,6 @@ public: void setAverageLoudness(float averageLoudness ) { _averageLoudness = averageLoudness; } void setReturnToCenter (bool returnHeadToCenter) { _returnHeadToCenter = returnHeadToCenter; } void setRenderLookatVectors(bool onOff ) { _renderLookatVectors = onOff; } - void setOrientation(const glm::quat& orientation); - - void addOrientation(float pitch, float yaw, float roll); glm::quat getOrientation() const; glm::quat getWorldAlignedOrientation () const; From 86ae9dbe7c009662f5ed60bfddf367083899cdea Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Thu, 30 May 2013 15:51:31 -0700 Subject: [PATCH 7/7] Merged. --- avatar-mixer/src/main.cpp | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/avatar-mixer/src/main.cpp b/avatar-mixer/src/main.cpp index 97c431b408..caa9f609ce 100644 --- a/avatar-mixer/src/main.cpp +++ b/avatar-mixer/src/main.cpp @@ -51,19 +51,8 @@ void attachAvatarDataToAgent(Agent* newAgent) { } } -bool wantLocalDomain = false; - int main(int argc, const char* argv[]) { - // Handle Local Domain testing with the --local command line - const char* local = "--local"; - ::wantLocalDomain = cmdOptionExists(argc, argv,local); - if (::wantLocalDomain) { - printf("Local Domain MODE!\n"); - int ip = getLocalAddress(); - sprintf(DOMAIN_IP,"%d.%d.%d.%d", (ip & 0xFF), ((ip >> 8) & 0xFF),((ip >> 16) & 0xFF), ((ip >> 24) & 0xFF)); - } - AgentList* agentList = AgentList::createInstance(AGENT_TYPE_AVATAR_MIXER, AVATAR_LISTEN_PORT); setvbuf(stdout, NULL, _IOLBF, 0);