From f961a40d1c100b6e1e60be2a79503e6169c5e8dc Mon Sep 17 00:00:00 2001 From: Philip Rosedale Date: Fri, 24 May 2013 10:55:26 -0700 Subject: [PATCH 1/4] Chat message height doubled to clear mohawk --- interface/src/Avatar.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interface/src/Avatar.cpp b/interface/src/Avatar.cpp index bdfd7c8691..5edf677ea3 100644 --- a/interface/src/Avatar.cpp +++ b/interface/src/Avatar.cpp @@ -67,7 +67,7 @@ float lightBlue [] = {0.7, 0.8, 1.0 }; bool usingBigSphereCollisionTest = true; float chatMessageScale = 0.0015; -float chatMessageHeight = 0.10; +float chatMessageHeight = 0.20; Avatar::Avatar(bool isMine) : _isMine(isMine), From 59ac5ebd6638ab98e8def7a88a37fa4ab83b7215 Mon Sep 17 00:00:00 2001 From: Philip Rosedale Date: Fri, 24 May 2013 11:07:19 -0700 Subject: [PATCH 2/4] Head will always render when body does - no decapitation --- interface/src/Avatar.cpp | 2 +- interface/src/Head.cpp | 33 ++++++++++++++++++++------------- interface/src/Head.h | 1 + 3 files changed, 22 insertions(+), 14 deletions(-) diff --git a/interface/src/Avatar.cpp b/interface/src/Avatar.cpp index 5edf677ea3..37b612d41d 100644 --- a/interface/src/Avatar.cpp +++ b/interface/src/Avatar.cpp @@ -1135,7 +1135,7 @@ void Avatar::renderBody(bool lookingInMirror) { float distanceToCamera = glm::length(getCameraPosition() - _joint[b].position); // Always render other people, and render myself when beyond threshold distance if (b == AVATAR_JOINT_HEAD_BASE) { // the head is rendered as a special case - if (lookingInMirror || !_isMine || distanceToCamera > RENDER_OPAQUE_BEYOND) { + if (lookingInMirror || !_isMine || distanceToCamera > RENDER_TRANSLUCENT_BEYOND) { _head.render(lookingInMirror); } } else if (!_isMine || distanceToCamera > RENDER_TRANSLUCENT_BEYOND) { diff --git a/interface/src/Head.cpp b/interface/src/Head.cpp index cc628a448f..22b82b2ff4 100644 --- a/interface/src/Head.cpp +++ b/interface/src/Head.cpp @@ -8,6 +8,7 @@ #include "Util.h" #include #include +#include using namespace std; @@ -55,8 +56,9 @@ Head::Head() : _returnSpringScale(1.0f), _bodyRotation(0.0f, 0.0f, 0.0f), _headRotation(0.0f, 0.0f, 0.0f), - _renderLookatVectors(false) { - createMohawk(); + _renderLookatVectors(false), + _mohawkExists(false) +{ } void Head::reset() { @@ -190,6 +192,7 @@ void Head::render(bool lookingInMirror) { } void Head::createMohawk() { +// int agentId = AgentList::getInstance() float height = 0.05f + randFloat() * 0.10f; float variance = 0.05 + randFloat() * 0.05f; const float RAD_PER_TRIANGLE = (2.3f + randFloat() * 0.2f) / (float)MOHAWK_TRIANGLES; @@ -207,21 +210,25 @@ void Head::createMohawk() { _mohawkColors[i] = randFloat() * basicColor; } - + _mohawkExists = true; } void Head::renderMohawk() { - glPushMatrix(); - glTranslatef(_position.x, _position.y, _position.z); - glRotatef(_bodyRotation.y, 0, 1, 0); - glBegin(GL_TRIANGLE_FAN); - for (int i = 0; i < MOHAWK_TRIANGLES; i++) { - glColor3f(_mohawkColors[i].x, _mohawkColors[i].y, _mohawkColors[i].z); - glVertex3fv(&_mohawkTriangleFan[i].x); - glNormal3fv(&_mohawkColors[i].x); + if (!_mohawkExists) { + createMohawk(); + } else { + glPushMatrix(); + glTranslatef(_position.x, _position.y, _position.z); + glRotatef(_bodyRotation.y, 0, 1, 0); + glBegin(GL_TRIANGLE_FAN); + for (int i = 0; i < MOHAWK_TRIANGLES; i++) { + glColor3f(_mohawkColors[i].x, _mohawkColors[i].y, _mohawkColors[i].z); + glVertex3fv(&_mohawkTriangleFan[i].x); + glNormal3fv(&_mohawkColors[i].x); + } + glEnd(); + glPopMatrix(); } - glEnd(); - glPopMatrix(); } diff --git a/interface/src/Head.h b/interface/src/Head.h index 3b97361e3f..e7cf3c1bce 100644 --- a/interface/src/Head.h +++ b/interface/src/Head.h @@ -83,6 +83,7 @@ private: bool _renderLookatVectors; glm::vec3* _mohawkTriangleFan; glm::vec3* _mohawkColors; + bool _mohawkExists; // private methods void createMohawk(); From 17c898c151ec1e21b8c47ad3712f964b98c64396 Mon Sep 17 00:00:00 2001 From: Philip Rosedale Date: Fri, 24 May 2013 11:33:00 -0700 Subject: [PATCH 3/4] Long term averaging of the gyros for better stability --- interface/src/Application.cpp | 2 +- interface/src/SerialInterface.cpp | 43 ++++++++++++++++++++++--------- interface/src/SerialInterface.h | 6 +++-- 3 files changed, 36 insertions(+), 15 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 37b8cf31b6..7652c60461 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -884,7 +884,7 @@ void Application::idle() { // Read serial port interface devices if (_serialPort.active) { - _serialPort.readData(); + _serialPort.readData(deltaTime); } // Sample hardware, update view frustum if needed, and send avatar data to mixer/agents diff --git a/interface/src/SerialInterface.cpp b/interface/src/SerialInterface.cpp index 1989736bf8..b730d2a907 100644 --- a/interface/src/SerialInterface.cpp +++ b/interface/src/SerialInterface.cpp @@ -15,6 +15,7 @@ const short NO_READ_MAXIMUM_MSECS = 3000; const int GRAVITY_SAMPLES = 60; // Use the first few samples to baseline values +const int LONG_TERM_RATE_SAMPLES = 1000; const bool USING_INVENSENSE_MPU9150 = 1; @@ -136,6 +137,16 @@ void SerialInterface::renderLevels(int width, int height) { glVertex2f(LEVEL_CORNER_X + LEVEL_CENTER + getLastPitchRate(), LEVEL_CORNER_Y + 12); glVertex2f(LEVEL_CORNER_X + LEVEL_CENTER, LEVEL_CORNER_Y + 27); glVertex2f(LEVEL_CORNER_X + LEVEL_CENTER + getLastRollRate(), LEVEL_CORNER_Y + 27); + // Gyro Estimated Rotation + glColor4f(0, 1, 1, 1); + glVertex2f(LEVEL_CORNER_X + LEVEL_CENTER, LEVEL_CORNER_Y - 1); + glVertex2f(LEVEL_CORNER_X + LEVEL_CENTER + _estimatedRotation.y, LEVEL_CORNER_Y - 1); + glVertex2f(LEVEL_CORNER_X + LEVEL_CENTER, LEVEL_CORNER_Y + 14); + glVertex2f(LEVEL_CORNER_X + LEVEL_CENTER + _estimatedRotation.z, LEVEL_CORNER_Y + 14); + glVertex2f(LEVEL_CORNER_X + LEVEL_CENTER, LEVEL_CORNER_Y + 29); + glVertex2f(LEVEL_CORNER_X + LEVEL_CENTER + _estimatedRotation.x, LEVEL_CORNER_Y + 29); + + // Acceleration glVertex2f(LEVEL_CORNER_X + LEVEL_CENTER, LEVEL_CORNER_Y + 42); glVertex2f(LEVEL_CORNER_X + LEVEL_CENTER + (int)((_lastAccelX - _gravity.x)* ACCEL_VIEW_SCALING), @@ -169,7 +180,7 @@ void convertHexToInt(unsigned char* sourceBuffer, int& destinationInt) { destinationInt = result; } -void SerialInterface::readData() { +void SerialInterface::readData(float deltaTime) { #ifdef __APPLE__ int initialSamples = totalSamples; @@ -207,6 +218,11 @@ void SerialInterface::readData() { _lastYawRate = ((float) -yawRate) * LSB_TO_DEGREES_PER_SECOND; _lastPitchRate = ((float) -pitchRate) * LSB_TO_DEGREES_PER_SECOND; + // Update raw rotation estimates + _estimatedRotation += deltaTime * glm::vec3(_lastRollRate - _averageGyroRates[0], + _lastYawRate - _averageGyroRates[1], + _lastPitchRate - _averageGyroRates[2]); + // Accumulate a set of initial baseline readings for setting gravity if (totalSamples == 0) { _averageGyroRates[0] = _lastRollRate; @@ -216,17 +232,20 @@ void SerialInterface::readData() { _gravity.y = _lastAccelY; _gravity.z = _lastAccelZ; - } - else if (totalSamples < GRAVITY_SAMPLES) { - _gravity = (1.f - 1.f/(float)GRAVITY_SAMPLES) * _gravity + - 1.f/(float)GRAVITY_SAMPLES * glm::vec3(_lastAccelX, _lastAccelY, _lastAccelZ); - - _averageGyroRates[0] = (1.f - 1.f/(float)GRAVITY_SAMPLES) * _averageGyroRates[0] + - 1.f/(float)GRAVITY_SAMPLES * _lastRollRate; - _averageGyroRates[1] = (1.f - 1.f/(float)GRAVITY_SAMPLES) * _averageGyroRates[1] + - 1.f/(float)GRAVITY_SAMPLES * _lastYawRate; - _averageGyroRates[2] = (1.f - 1.f/(float)GRAVITY_SAMPLES) * _averageGyroRates[2] + - 1.f/(float)GRAVITY_SAMPLES * _lastPitchRate; + } + else { + // Cumulate long term average to (hopefully) take DC bias out of rotation rates + _averageGyroRates[0] = (1.f - 1.f/(float)LONG_TERM_RATE_SAMPLES) * _averageGyroRates[0] + + 1.f/(float)LONG_TERM_RATE_SAMPLES * _lastRollRate; + _averageGyroRates[1] = (1.f - 1.f/(float)LONG_TERM_RATE_SAMPLES) * _averageGyroRates[1] + + 1.f/(float)LONG_TERM_RATE_SAMPLES * _lastYawRate; + _averageGyroRates[2] = (1.f - 1.f/(float)LONG_TERM_RATE_SAMPLES) * _averageGyroRates[2] + + 1.f/(float)LONG_TERM_RATE_SAMPLES * _lastPitchRate; + + if (totalSamples < GRAVITY_SAMPLES) { + _gravity = (1.f - 1.f/(float)GRAVITY_SAMPLES) * _gravity + + 1.f/(float)GRAVITY_SAMPLES * glm::vec3(_lastAccelX, _lastAccelY, _lastAccelZ); + } } totalSamples++; diff --git a/interface/src/SerialInterface.h b/interface/src/SerialInterface.h index 9aa7bccf04..42d24367f6 100644 --- a/interface/src/SerialInterface.h +++ b/interface/src/SerialInterface.h @@ -38,7 +38,8 @@ class SerialInterface { public: SerialInterface() : active(false), _gravity(0,0,0), - _averageGyroRates(0,0,0), + _averageGyroRates(0, 0, 0), + _estimatedRotation(0, 0, 0), _lastAccelX(0), _lastAccelY(0), _lastAccelZ(0), @@ -47,7 +48,7 @@ public: _lastRollRate(0) {} void pair(); - void readData(); + void readData(float deltaTime); float getLastYawRate() const { return _lastYawRate - _averageGyroRates[1]; } float getLastPitchRate() const { return _lastPitchRate - _averageGyroRates[2]; } @@ -68,6 +69,7 @@ private: timeval lastGoodRead; glm::vec3 _gravity; glm::vec3 _averageGyroRates; + glm::vec3 _estimatedRotation; float _lastAccelX; float _lastAccelY; float _lastAccelZ; From 8b5901d904a81527c3569bf2601c84a3962abb2c Mon Sep 17 00:00:00 2001 From: Philip Rosedale Date: Fri, 24 May 2013 12:04:17 -0700 Subject: [PATCH 4/4] simplified per stephens code review --- interface/src/Head.cpp | 6 +++--- interface/src/Head.h | 1 - 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/interface/src/Head.cpp b/interface/src/Head.cpp index 22b82b2ff4..d25b9de9ea 100644 --- a/interface/src/Head.cpp +++ b/interface/src/Head.cpp @@ -57,7 +57,8 @@ Head::Head() : _bodyRotation(0.0f, 0.0f, 0.0f), _headRotation(0.0f, 0.0f, 0.0f), _renderLookatVectors(false), - _mohawkExists(false) + _mohawkTriangleFan(NULL), + _mohawkColors(NULL) { } @@ -210,11 +211,10 @@ void Head::createMohawk() { _mohawkColors[i] = randFloat() * basicColor; } - _mohawkExists = true; } void Head::renderMohawk() { - if (!_mohawkExists) { + if (!_mohawkTriangleFan) { createMohawk(); } else { glPushMatrix(); diff --git a/interface/src/Head.h b/interface/src/Head.h index e7cf3c1bce..3b97361e3f 100644 --- a/interface/src/Head.h +++ b/interface/src/Head.h @@ -83,7 +83,6 @@ private: bool _renderLookatVectors; glm::vec3* _mohawkTriangleFan; glm::vec3* _mohawkColors; - bool _mohawkExists; // private methods void createMohawk();