From 95e73afc78d237ff421aa43b37ef6f966f6649e1 Mon Sep 17 00:00:00 2001 From: Philip Rosedale Date: Fri, 24 May 2013 00:16:52 -0700 Subject: [PATCH 01/15] Added the avatar mohawk --- interface/src/Head.cpp | 41 ++++++++++++++++++++++++++++++++++++++++- interface/src/Head.h | 4 ++++ 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/interface/src/Head.cpp b/interface/src/Head.cpp index cb42c6cc54..5d8ea1af57 100644 --- a/interface/src/Head.cpp +++ b/interface/src/Head.cpp @@ -10,7 +10,8 @@ #include using namespace std; - + +const int MOHAWK_TRIANGLES = 50; const float EYE_RIGHT_OFFSET = 0.27f; const float EYE_UP_OFFSET = 0.36f; const float EYE_FRONT_OFFSET = 0.8f; @@ -55,6 +56,7 @@ Head::Head() : _bodyRotation(0.0f, 0.0f, 0.0f), _headRotation(0.0f, 0.0f, 0.0f), _renderLookatVectors(false) { + createMohawk(); } void Head::reset() { @@ -175,6 +177,7 @@ void Head::render(bool lookingInMirror) { glEnable(GL_DEPTH_TEST); glEnable(GL_RESCALE_NORMAL); + renderMohawk(); renderHeadSphere(); renderEyeBalls(); renderEars(); @@ -186,6 +189,42 @@ void Head::render(bool lookingInMirror) { } } +void Head::createMohawk() { + 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; + _mohawkTriangleFan = new glm::vec3[MOHAWK_TRIANGLES]; + _mohawkColors = new glm::vec3[MOHAWK_TRIANGLES]; + _mohawkTriangleFan[0] = glm::vec3(0,0,0); + glm::vec3 basicColor(randFloat(), randFloat(), randFloat()); + _mohawkColors[0] = basicColor; + for (int i = 1; i < MOHAWK_TRIANGLES; i++) { + _mohawkTriangleFan[i] = glm::vec3((randFloat() - 0.5f) * variance, + height * cosf(i * RAD_PER_TRIANGLE - PI/2.f) + + (randFloat() - 0.5f) * variance, + height * sinf(i * RAD_PER_TRIANGLE - PI/2.f) + + (randFloat() - 0.5f) * variance); + _mohawkColors[i] = randFloat() * basicColor; + + } + +} + +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); + } + glEnd(); + glPopMatrix(); +} + + void Head::renderHeadSphere() { glPushMatrix(); glTranslatef(_position.x, _position.y, _position.z); //translate to head position diff --git a/interface/src/Head.h b/interface/src/Head.h index 6ea9218bbf..3b97361e3f 100644 --- a/interface/src/Head.h +++ b/interface/src/Head.h @@ -31,6 +31,7 @@ public: void reset(); void simulate(float deltaTime, bool isMine); void render(bool lookingInMirror); + void renderMohawk(); void setScale (float scale ) { _scale = scale; } void setPosition (glm::vec3 position ) { _position = position; } @@ -80,8 +81,11 @@ private: glm::vec3 _bodyRotation; glm::vec3 _headRotation; bool _renderLookatVectors; + glm::vec3* _mohawkTriangleFan; + glm::vec3* _mohawkColors; // private methods + void createMohawk(); void renderHeadSphere(); void renderEyeBalls(); void renderEyeBrows(); From 34a598dcd74a78209922d9835db035ec4cdf45f3 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Fri, 24 May 2013 09:35:27 -0700 Subject: [PATCH 02/15] make dragonfly move in circle instead of line --- animation-server/src/main.cpp | 89 ++++++++++++++++++++++++++++------- 1 file changed, 72 insertions(+), 17 deletions(-) diff --git a/animation-server/src/main.cpp b/animation-server/src/main.cpp index 78386934e4..e04502e77a 100644 --- a/animation-server/src/main.cpp +++ b/animation-server/src/main.cpp @@ -63,10 +63,32 @@ static void sendVoxelEditMessage(PACKET_HEADER header, VoxelDetail& detail) { } } -const float BUG_VOXEL_SIZE = 0.125f / TREE_SCALE; -glm::vec3 bugPosition = glm::vec3(BUG_VOXEL_SIZE * 10.0, BUG_VOXEL_SIZE * 30.0, BUG_VOXEL_SIZE * 10.0); +glm::vec3 rotatePoint(glm::vec3 point, float angle) +{ + // First, create the quaternion based on this angle of rotation + glm::quat q(glm::vec3(0, -angle, 0)); + + // Next, create a rotation matrix from that quaternion + glm::mat4 rotation = glm::mat4_cast(q); + + // Transform the original vectors by the rotation matrix to get the new vectors + glm::vec4 quatPoint(point.x, point.y, point.z, 0); + glm::vec4 newPoint = quatPoint * rotation; + + return glm::vec3(newPoint.x, newPoint.y, newPoint.z); +} + + +const float BUG_VOXEL_SIZE = 0.0625f / TREE_SCALE; +glm::vec3 bugPosition = glm::vec3(BUG_VOXEL_SIZE * 20.0, BUG_VOXEL_SIZE * 30.0, BUG_VOXEL_SIZE * 20.0); glm::vec3 bugDirection = glm::vec3(0, 0, 1); const int VOXELS_PER_BUG = 18; +glm::vec3 bugPathCenter = glm::vec3(BUG_VOXEL_SIZE * 150.0, BUG_VOXEL_SIZE * 30.0, BUG_VOXEL_SIZE * 150.0); +float bugPathRadius = BUG_VOXEL_SIZE * 140.0; +float bugPathTheta = 0.0 * PI_OVER_180; +float bugRotation = 0.0 * PI_OVER_180; +float bugAngleDelta = 0.2 * PI_OVER_180; +bool moveBugInLine = false; class BugPart { public: @@ -122,10 +144,15 @@ static void renderMovingBug() { // Generate voxels for where bug used to be for (int i = 0; i < VOXELS_PER_BUG; i++) { details[i].s = BUG_VOXEL_SIZE; - details[i].x = bugPosition.x + (bugParts[i].partLocation.x * BUG_VOXEL_SIZE * (bugDirection.x < 0 ? -1 : 1)); - details[i].y = bugPosition.y + (bugParts[i].partLocation.y * BUG_VOXEL_SIZE * (bugDirection.y < 0 ? -1 : 1)); - details[i].z = bugPosition.z + (bugParts[i].partLocation.z * BUG_VOXEL_SIZE * (bugDirection.z < 0 ? -1 : 1)); + + glm::vec3 partAt = bugParts[i].partLocation * BUG_VOXEL_SIZE * (bugDirection.x < 0 ? -1.0f : 1.0f); + glm::vec3 rotatedPartAt = rotatePoint(partAt, bugRotation); + glm::vec3 offsetPartAt = rotatedPartAt + bugPosition; + details[i].x = offsetPartAt.x; + details[i].y = offsetPartAt.y; + details[i].z = offsetPartAt.z; + details[i].red = bugParts[i].partColor[0]; details[i].green = bugParts[i].partColor[1]; details[i].blue = bugParts[i].partColor[2]; @@ -146,17 +173,40 @@ static void renderMovingBug() { } // Move the bug... - bugPosition.x += (bugDirection.x * BUG_VOXEL_SIZE); - bugPosition.y += (bugDirection.y * BUG_VOXEL_SIZE); - bugPosition.z += (bugDirection.z * BUG_VOXEL_SIZE); + if (moveBugInLine) { + bugPosition.x += (bugDirection.x * BUG_VOXEL_SIZE); + bugPosition.y += (bugDirection.y * BUG_VOXEL_SIZE); + bugPosition.z += (bugDirection.z * BUG_VOXEL_SIZE); - // Check boundaries - if (bugPosition.z > 1.0) { - bugDirection.z = -1; - } - if (bugPosition.z < BUG_VOXEL_SIZE) { - bugDirection.z = 1; + // Check boundaries + if (bugPosition.z > 1.0) { + bugDirection.z = -1; + } + if (bugPosition.z < BUG_VOXEL_SIZE) { + bugDirection.z = 1; + } + } else { + + //printf("bugPathCenter=(%f,%f,%f)\n", bugPathCenter.x, bugPathCenter.y, bugPathCenter.z); + + bugPathTheta += bugAngleDelta; // move slightly + bugRotation -= bugAngleDelta; // rotate slightly + + // If we loop past end of circle, just reset back into normal range + if (bugPathTheta > (360.0f * PI_OVER_180)) { + bugPathTheta = 0; + bugRotation = 0; + } + + float x = bugPathCenter.x + bugPathRadius * cos(bugPathTheta); + float z = bugPathCenter.z + bugPathRadius * sin(bugPathTheta); + float y = bugPathCenter.y; + + bugPosition = glm::vec3(x, y, z); + //printf("bugPathTheta=%f\n", bugPathTheta); + //printf("bugRotation=%f\n", bugRotation); } + //printf("bugPosition=(%f,%f,%f)\n", bugPosition.x, bugPosition.y, bugPosition.z); //printf("bugDirection=(%f,%f,%f)\n", bugDirection.x, bugDirection.y, bugDirection.z); // would be nice to add some randomness here... @@ -164,10 +214,15 @@ static void renderMovingBug() { // Generate voxels for where bug is going to for (int i = 0; i < VOXELS_PER_BUG; i++) { details[i].s = BUG_VOXEL_SIZE; - details[i].x = bugPosition.x + (bugParts[i].partLocation.x * BUG_VOXEL_SIZE * (bugDirection.x < 0 ? -1 : 1)); - details[i].y = bugPosition.y + (bugParts[i].partLocation.y * BUG_VOXEL_SIZE * (bugDirection.y < 0 ? -1 : 1)); - details[i].z = bugPosition.z + (bugParts[i].partLocation.z * BUG_VOXEL_SIZE * (bugDirection.z < 0 ? -1 : 1)); + + glm::vec3 partAt = bugParts[i].partLocation * BUG_VOXEL_SIZE * (bugDirection.x < 0 ? -1.0f : 1.0f); + glm::vec3 rotatedPartAt = rotatePoint(partAt, bugRotation); + glm::vec3 offsetPartAt = rotatedPartAt + bugPosition; + details[i].x = offsetPartAt.x; + details[i].y = offsetPartAt.y; + details[i].z = offsetPartAt.z; + details[i].red = bugParts[i].partColor[0]; details[i].green = bugParts[i].partColor[1]; details[i].blue = bugParts[i].partColor[2]; From bf94c88bcc127e41506430797a41902e328dad31 Mon Sep 17 00:00:00 2001 From: Philip Rosedale Date: Fri, 24 May 2013 10:12:50 -0700 Subject: [PATCH 03/15] Fixes per review --- 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 5d8ea1af57..cc628a448f 100644 --- a/interface/src/Head.cpp +++ b/interface/src/Head.cpp @@ -192,17 +192,17 @@ void Head::render(bool lookingInMirror) { void Head::createMohawk() { 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; + const float RAD_PER_TRIANGLE = (2.3f + randFloat() * 0.2f) / (float)MOHAWK_TRIANGLES; _mohawkTriangleFan = new glm::vec3[MOHAWK_TRIANGLES]; _mohawkColors = new glm::vec3[MOHAWK_TRIANGLES]; - _mohawkTriangleFan[0] = glm::vec3(0,0,0); + _mohawkTriangleFan[0] = glm::vec3(0, 0, 0); glm::vec3 basicColor(randFloat(), randFloat(), randFloat()); _mohawkColors[0] = basicColor; for (int i = 1; i < MOHAWK_TRIANGLES; i++) { _mohawkTriangleFan[i] = glm::vec3((randFloat() - 0.5f) * variance, - height * cosf(i * RAD_PER_TRIANGLE - PI/2.f) + height * cosf(i * RAD_PER_TRIANGLE - PI / 2.f) + (randFloat() - 0.5f) * variance, - height * sinf(i * RAD_PER_TRIANGLE - PI/2.f) + height * sinf(i * RAD_PER_TRIANGLE - PI / 2.f) + (randFloat() - 0.5f) * variance); _mohawkColors[i] = randFloat() * basicColor; From c767babba5e8cfdb788d299f7cb60713042ee21c Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Fri, 24 May 2013 10:47:57 -0700 Subject: [PATCH 04/15] lower voxel send rate --- voxel-server/src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/voxel-server/src/main.cpp b/voxel-server/src/main.cpp index 1cfcaa4282..4e5f931477 100644 --- a/voxel-server/src/main.cpp +++ b/voxel-server/src/main.cpp @@ -45,7 +45,7 @@ const float DEATH_STAR_RADIUS = 4.0; const float MAX_CUBE = 0.05f; const int VOXEL_SEND_INTERVAL_USECS = 100 * 1000; -int PACKETS_PER_CLIENT_PER_INTERVAL = 50; +int PACKETS_PER_CLIENT_PER_INTERVAL = 30; const int MAX_VOXEL_TREE_DEPTH_LEVELS = 4; From f961a40d1c100b6e1e60be2a79503e6169c5e8dc Mon Sep 17 00:00:00 2001 From: Philip Rosedale Date: Fri, 24 May 2013 10:55:26 -0700 Subject: [PATCH 05/15] 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 06/15] 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 b1232d0a87cf5a7577d04b47aa3abe5b4d39cb9a Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Fri, 24 May 2013 11:18:14 -0700 Subject: [PATCH 07/15] coding standard cleanup --- animation-server/src/main.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/animation-server/src/main.cpp b/animation-server/src/main.cpp index e04502e77a..a26b1a4674 100644 --- a/animation-server/src/main.cpp +++ b/animation-server/src/main.cpp @@ -63,8 +63,7 @@ static void sendVoxelEditMessage(PACKET_HEADER header, VoxelDetail& detail) { } } -glm::vec3 rotatePoint(glm::vec3 point, float angle) -{ +glm::vec3 rotatePoint(glm::vec3 point, float angle) { // First, create the quaternion based on this angle of rotation glm::quat q(glm::vec3(0, -angle, 0)); From 17c898c151ec1e21b8c47ad3712f964b98c64396 Mon Sep 17 00:00:00 2001 From: Philip Rosedale Date: Fri, 24 May 2013 11:33:00 -0700 Subject: [PATCH 08/15] 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 09/15] 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(); From 8560e42357ae3330d99be58751382ec61f463e80 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Fri, 24 May 2013 12:08:25 -0700 Subject: [PATCH 10/15] fix issue with duplicate VBO slots --- interface/src/VoxelSystem.cpp | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/interface/src/VoxelSystem.cpp b/interface/src/VoxelSystem.cpp index b776ac9d03..026f1dd4ee 100644 --- a/interface/src/VoxelSystem.cpp +++ b/interface/src/VoxelSystem.cpp @@ -372,7 +372,10 @@ int VoxelSystem::updateNodeInArraysAsFullVBO(VoxelNode* node) { _writeVoxelDirtyArray[nodeIndex] = true; // just in case we switch to Partial mode _voxelsInWriteArrays++; // our know vertices in the arrays return 1; // rendered - } + } else { + node->setBufferIndex(GLBUFFER_INDEX_UNKNOWN); + } + return 0; // not-rendered } @@ -978,6 +981,7 @@ public: shouldRenderNodes(0), coloredNodes(0), nodesInVBO(0), + nodesInVBONotShouldRender(0), nodesInVBOOverExpectedMax(0), duplicateVBOIndex(0), leafNodes(0) @@ -990,6 +994,7 @@ public: unsigned long shouldRenderNodes; unsigned long coloredNodes; unsigned long nodesInVBO; + unsigned long nodesInVBONotShouldRender; unsigned long nodesInVBOOverExpectedMax; unsigned long duplicateVBOIndex; unsigned long leafNodes; @@ -1032,6 +1037,11 @@ bool VoxelSystem::collectStatsForTreesAndVBOsOperation(VoxelNode* node, void* ex if (nodeIndex > args->expectedMax) { args->nodesInVBOOverExpectedMax++; } + + // if it's in VBO but not-shouldRender, track that also... + if (!node->getShouldRender()) { + args->nodesInVBONotShouldRender++; + } } return true; // keep going! @@ -1060,8 +1070,8 @@ void VoxelSystem::collectStatsForTreesAndVBOs() { printLog("stats: total %ld, leaves %ld, dirty %ld, colored %ld, shouldRender %ld, inVBO %ld\n", args.totalNodes, args.leafNodes, args.dirtyNodes, args.coloredNodes, args.shouldRenderNodes); - printLog("inVBO %ld, nodesInVBOOverExpectedMax %ld, duplicateVBOIndex %ld\n", - args.nodesInVBO, args.nodesInVBOOverExpectedMax, args.duplicateVBOIndex); + printLog("inVBO %ld, nodesInVBOOverExpectedMax %ld, duplicateVBOIndex %ld, nodesInVBONotShouldRender %ld\n", + args.nodesInVBO, args.nodesInVBOOverExpectedMax, args.duplicateVBOIndex, args.nodesInVBONotShouldRender); glBufferIndex minInVBO = GLBUFFER_INDEX_UNKNOWN; glBufferIndex maxInVBO = 0; From 36892da4886e6af73be827a256564928e79a5f03 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Fri, 24 May 2013 11:24:21 -0700 Subject: [PATCH 11/15] keep a pointer to owning agent in AgentData --- avatar-mixer/src/main.cpp | 2 +- eve/src/main.cpp | 4 ++-- interface/src/Application.cpp | 6 +++--- interface/src/Avatar.cpp | 3 ++- interface/src/Avatar.h | 2 +- interface/src/VoxelSystem.cpp | 2 +- libraries/audio/src/AudioRingBuffer.cpp | 3 ++- libraries/avatars/src/AvatarData.cpp | 3 ++- libraries/avatars/src/AvatarData.h | 2 +- libraries/shared/src/AgentData.cpp | 6 ++++++ libraries/shared/src/AgentData.h | 7 ++++++- voxel-server/src/VoxelAgentData.cpp | 1 + 12 files changed, 28 insertions(+), 13 deletions(-) diff --git a/avatar-mixer/src/main.cpp b/avatar-mixer/src/main.cpp index da2b41b1bd..0e838833f4 100644 --- a/avatar-mixer/src/main.cpp +++ b/avatar-mixer/src/main.cpp @@ -47,7 +47,7 @@ unsigned char *addAgentToBroadcastPacket(unsigned char *currentPosition, Agent * void attachAvatarDataToAgent(Agent *newAgent) { if (newAgent->getLinkedData() == NULL) { - newAgent->setLinkedData(new AvatarData()); + newAgent->setLinkedData(new AvatarData(newAgent)); } } diff --git a/eve/src/main.cpp b/eve/src/main.cpp index 62be6e36cd..92355970c6 100644 --- a/eve/src/main.cpp +++ b/eve/src/main.cpp @@ -71,7 +71,7 @@ void *receiveAgentData(void *args) { void createAvatarDataForAgent(Agent* agent) { if (!agent->getLinkedData()) { - agent->setLinkedData(new AvatarData()); + agent->setLinkedData(new AvatarData(agent)); } } @@ -95,7 +95,7 @@ int main(int argc, const char* argv[]) { pthread_create(&receiveAgentDataThread, NULL, receiveAgentData, NULL); // create an AvatarData object, "eve" - AvatarData eve; + AvatarData eve(NULL); // move eve away from the origin // pick a random point inside a 10x10 grid diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 37b8cf31b6..80690e162a 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -128,7 +128,7 @@ Application::Application(int& argc, char** argv, timeval &startup_time) : _viewFrustumOffsetDistance(25.0), _viewFrustumOffsetUp(0.0), _audioScope(256, 200, true), - _myAvatar(true), + _myAvatar(NULL, true), _manualFirstPerson(false), _mouseX(0), _mouseY(0), @@ -2098,9 +2098,9 @@ QAction* Application::checkedVoxelModeAction() const { return 0; } -void Application::attachNewHeadToAgent(Agent *newAgent) { +void Application::attachNewHeadToAgent(Agent* newAgent) { if (newAgent->getLinkedData() == NULL) { - newAgent->setLinkedData(new Avatar(false)); + newAgent->setLinkedData(new Avatar(newAgent, false)); } } diff --git a/interface/src/Avatar.cpp b/interface/src/Avatar.cpp index bdfd7c8691..de93fd859c 100644 --- a/interface/src/Avatar.cpp +++ b/interface/src/Avatar.cpp @@ -69,7 +69,8 @@ bool usingBigSphereCollisionTest = true; float chatMessageScale = 0.0015; float chatMessageHeight = 0.10; -Avatar::Avatar(bool isMine) : +Avatar::Avatar(Agent* owningAgent, bool isMine) : + AvatarData(owningAgent), _isMine(isMine), _TEST_bigSphereRadius(0.4f), _TEST_bigSpherePosition(5.0f, _TEST_bigSphereRadius, 5.0f), diff --git a/interface/src/Avatar.h b/interface/src/Avatar.h index 59f9018af3..a5f1531417 100644 --- a/interface/src/Avatar.h +++ b/interface/src/Avatar.h @@ -76,7 +76,7 @@ enum AvatarJointID class Avatar : public AvatarData { public: - Avatar(bool isMine); + Avatar(Agent* owningAgent, bool isMine); ~Avatar(); void reset(); diff --git a/interface/src/VoxelSystem.cpp b/interface/src/VoxelSystem.cpp index 026f1dd4ee..68707355bb 100644 --- a/interface/src/VoxelSystem.cpp +++ b/interface/src/VoxelSystem.cpp @@ -44,7 +44,7 @@ GLubyte identityIndices[] = { 0,2,1, 0,3,2, // Z- . 10,11,15, 10,15,14, // Y+ 4,5,6, 4,6,7 }; // Z+ . -VoxelSystem::VoxelSystem() { +VoxelSystem::VoxelSystem() : AgentData(NULL) { _voxelsInReadArrays = _voxelsInWriteArrays = _voxelsUpdated = 0; _writeRenderFullVBO = true; _readRenderFullVBO = true; diff --git a/libraries/audio/src/AudioRingBuffer.cpp b/libraries/audio/src/AudioRingBuffer.cpp index 59b35b18a3..ee693ebde3 100644 --- a/libraries/audio/src/AudioRingBuffer.cpp +++ b/libraries/audio/src/AudioRingBuffer.cpp @@ -13,6 +13,7 @@ #include "AudioRingBuffer.h" AudioRingBuffer::AudioRingBuffer(int ringSamples, int bufferSamples) : + AgentData(NULL), _ringBufferLengthSamples(ringSamples), _bufferLengthSamples(bufferSamples), _endOfLastWrite(NULL), @@ -20,7 +21,7 @@ AudioRingBuffer::AudioRingBuffer(int ringSamples, int bufferSamples) : _shouldBeAddedToMix(false), _shouldLoopbackForAgent(false), _streamIdentifier() -{ +{ _buffer = new int16_t[_ringBufferLengthSamples]; _nextOutput = _buffer; }; diff --git a/libraries/avatars/src/AvatarData.cpp b/libraries/avatars/src/AvatarData.cpp index ab69c28dd0..c660e55347 100644 --- a/libraries/avatars/src/AvatarData.cpp +++ b/libraries/avatars/src/AvatarData.cpp @@ -31,7 +31,8 @@ int unpackFloatAngleFromTwoByte(uint16_t* byteAnglePointer, float* destinationPo return sizeof(uint16_t); } -AvatarData::AvatarData() : +AvatarData::AvatarData(Agent* owningAgent) : + AgentData(owningAgent), _handPosition(0,0,0), _bodyYaw(-90.0), _bodyPitch(0.0), diff --git a/libraries/avatars/src/AvatarData.h b/libraries/avatars/src/AvatarData.h index 3e3536c3a9..b1582cf9f8 100644 --- a/libraries/avatars/src/AvatarData.h +++ b/libraries/avatars/src/AvatarData.h @@ -29,7 +29,7 @@ enum KeyState class AvatarData : public AgentData { public: - AvatarData(); + AvatarData(Agent* owningAgent); ~AvatarData(); const glm::vec3& getPosition() const { return _position; } diff --git a/libraries/shared/src/AgentData.cpp b/libraries/shared/src/AgentData.cpp index f4710246d7..c910a9c43f 100644 --- a/libraries/shared/src/AgentData.cpp +++ b/libraries/shared/src/AgentData.cpp @@ -8,4 +8,10 @@ #include "AgentData.h" +AgentData::AgentData(Agent* owningAgent) : + _owningAgent(owningAgent) +{ + +} + AgentData::~AgentData() {} \ No newline at end of file diff --git a/libraries/shared/src/AgentData.h b/libraries/shared/src/AgentData.h index 342f501a1e..99cdbaca95 100644 --- a/libraries/shared/src/AgentData.h +++ b/libraries/shared/src/AgentData.h @@ -3,16 +3,21 @@ // hifi // // Created by Stephen Birarda on 2/19/13. -// +// Copyright (c) 2013 High Fidelity, Inc. All rights reserved. // #ifndef hifi_AgentData_h #define hifi_AgentData_h +class Agent; + class AgentData { public: + AgentData(Agent* owningAgent); virtual ~AgentData() = 0; virtual int parseData(unsigned char* sourceBuffer, int numBytes) = 0; +private: + Agent* _owningAgent; }; #endif diff --git a/voxel-server/src/VoxelAgentData.cpp b/voxel-server/src/VoxelAgentData.cpp index e25defef7a..a017881301 100644 --- a/voxel-server/src/VoxelAgentData.cpp +++ b/voxel-server/src/VoxelAgentData.cpp @@ -12,6 +12,7 @@ #include VoxelAgentData::VoxelAgentData() : + AvatarData(NULL), _viewSent(false), _voxelPacketAvailableBytes(MAX_VOXEL_PACKET_SIZE), _maxSearchLevel(1), From 49b483ef53a38a3aa2b8427f7b441a428138ec28 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Fri, 24 May 2013 11:29:49 -0700 Subject: [PATCH 12/15] maintain a pointer to owning avatar from HeadData --- interface/src/Avatar.cpp | 1 + interface/src/Head.cpp | 4 ++-- interface/src/Head.h | 4 +++- libraries/avatars/src/AvatarData.cpp | 4 ++-- libraries/avatars/src/HeadData.cpp | 5 +++-- libraries/avatars/src/HeadData.h | 5 ++++- 6 files changed, 15 insertions(+), 8 deletions(-) diff --git a/interface/src/Avatar.cpp b/interface/src/Avatar.cpp index de93fd859c..125ef979bb 100644 --- a/interface/src/Avatar.cpp +++ b/interface/src/Avatar.cpp @@ -71,6 +71,7 @@ float chatMessageHeight = 0.10; Avatar::Avatar(Agent* owningAgent, bool isMine) : AvatarData(owningAgent), + _head(this), _isMine(isMine), _TEST_bigSphereRadius(0.4f), _TEST_bigSpherePosition(5.0f, _TEST_bigSphereRadius, 5.0f), diff --git a/interface/src/Head.cpp b/interface/src/Head.cpp index cc628a448f..0d891cf0e6 100644 --- a/interface/src/Head.cpp +++ b/interface/src/Head.cpp @@ -30,8 +30,8 @@ unsigned int IRIS_TEXTURE_WIDTH = 768; unsigned int IRIS_TEXTURE_HEIGHT = 498; vector irisTexture; -Head::Head() : - +Head::Head(Avatar* owningAvatar) : + HeadData((AvatarData*)owningAvatar), yawRate(0.0f), _returnHeadToCenter(false), _audioLoudness(0.0f), diff --git a/interface/src/Head.h b/interface/src/Head.h index 3b97361e3f..c20ce0e255 100644 --- a/interface/src/Head.h +++ b/interface/src/Head.h @@ -24,9 +24,11 @@ enum eyeContactTargets MOUTH }; +class Avatar; + class Head : public HeadData { public: - Head(); + Head(Avatar* owningAvatar); void reset(); void simulate(float deltaTime, bool isMine); diff --git a/libraries/avatars/src/AvatarData.cpp b/libraries/avatars/src/AvatarData.cpp index c660e55347..4b97a2a047 100644 --- a/libraries/avatars/src/AvatarData.cpp +++ b/libraries/avatars/src/AvatarData.cpp @@ -68,7 +68,7 @@ int AvatarData::getBroadcastData(unsigned char* destinationBuffer) { // lazily allocate memory for HeadData in case we're not an Avatar instance if (!_headData) { - _headData = new HeadData(); + _headData = new HeadData(this); } // Body world position @@ -149,7 +149,7 @@ int AvatarData::parseData(unsigned char* sourceBuffer, int numBytes) { // lazily allocate memory for HeadData in case we're not an Avatar instance if (!_headData) { - _headData = new HeadData(); + _headData = new HeadData(this); } // increment to push past the packet header diff --git a/libraries/avatars/src/HeadData.cpp b/libraries/avatars/src/HeadData.cpp index 9c01346152..906e10e48f 100644 --- a/libraries/avatars/src/HeadData.cpp +++ b/libraries/avatars/src/HeadData.cpp @@ -8,13 +8,14 @@ #include "HeadData.h" -HeadData::HeadData() : +HeadData::HeadData(AvatarData* owningAvatar) : _yaw(0.0f), _pitch(0.0f), _roll(0.0f), _lookAtPosition(0.0f, 0.0f, 0.0f), _leanSideways(0.0f), - _leanForward(0.0f) + _leanForward(0.0f), + _owningAvatar(owningAvatar) { } diff --git a/libraries/avatars/src/HeadData.h b/libraries/avatars/src/HeadData.h index fb16fea00e..1f0a8181b5 100644 --- a/libraries/avatars/src/HeadData.h +++ b/libraries/avatars/src/HeadData.h @@ -20,9 +20,11 @@ const float MAX_HEAD_PITCH = 60; const float MIN_HEAD_ROLL = -50; const float MAX_HEAD_ROLL = 50; +class AvatarData; + class HeadData { public: - HeadData(); + HeadData(AvatarData* owningAvatar); float getLeanSideways() const { return _leanSideways; } void setLeanSideways(float leanSideways) { _leanSideways = leanSideways; } @@ -55,6 +57,7 @@ protected: glm::vec3 _lookAtPosition; float _leanSideways; float _leanForward; + AvatarData* _owningAvatar; private: // privatize copy ctor and assignment operator so copies of this object cannot be made HeadData(const HeadData&); From eb25fd3b4648dad9ba197feb9ea87cd1889d7e04 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Fri, 24 May 2013 11:32:17 -0700 Subject: [PATCH 13/15] pass the owning agent for VoxelAgentData constructor --- voxel-server/src/VoxelAgentData.cpp | 4 ++-- voxel-server/src/VoxelAgentData.h | 2 +- voxel-server/src/main.cpp | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/voxel-server/src/VoxelAgentData.cpp b/voxel-server/src/VoxelAgentData.cpp index a017881301..07d19a7fb2 100644 --- a/voxel-server/src/VoxelAgentData.cpp +++ b/voxel-server/src/VoxelAgentData.cpp @@ -11,8 +11,8 @@ #include #include -VoxelAgentData::VoxelAgentData() : - AvatarData(NULL), +VoxelAgentData::VoxelAgentData(Agent* owningAgent) : + AvatarData(owningAgent), _viewSent(false), _voxelPacketAvailableBytes(MAX_VOXEL_PACKET_SIZE), _maxSearchLevel(1), diff --git a/voxel-server/src/VoxelAgentData.h b/voxel-server/src/VoxelAgentData.h index fbf5f12d3d..2afc64a6c8 100644 --- a/voxel-server/src/VoxelAgentData.h +++ b/voxel-server/src/VoxelAgentData.h @@ -17,7 +17,7 @@ class VoxelAgentData : public AvatarData { public: - VoxelAgentData(); + VoxelAgentData(Agent* owningAgent); ~VoxelAgentData(); void resetVoxelPacket(); // resets voxel packet to after "V" header diff --git a/voxel-server/src/main.cpp b/voxel-server/src/main.cpp index 4e5f931477..e2ffda0a0a 100644 --- a/voxel-server/src/main.cpp +++ b/voxel-server/src/main.cpp @@ -450,9 +450,9 @@ void *distributeVoxelsToListeners(void *args) { pthread_exit(0); } -void attachVoxelAgentDataToAgent(Agent *newAgent) { +void attachVoxelAgentDataToAgent(Agent* newAgent) { if (newAgent->getLinkedData() == NULL) { - newAgent->setLinkedData(new VoxelAgentData()); + newAgent->setLinkedData(new VoxelAgentData(newAgent)); } } From 59a6016f4b2529ace072e4ee0dd9cb9de9198874 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Fri, 24 May 2013 11:49:22 -0700 Subject: [PATCH 14/15] use a NULL default for owningAvatar to simplify constructors --- avatar-mixer/src/main.cpp | 2 +- eve/src/main.cpp | 2 +- interface/src/Application.cpp | 3 +-- interface/src/Avatar.cpp | 35 +++++++++++++++--------------- interface/src/Avatar.h | 3 +-- libraries/avatars/src/AvatarData.h | 4 ++-- libraries/shared/src/AgentData.h | 2 +- 7 files changed, 24 insertions(+), 27 deletions(-) diff --git a/avatar-mixer/src/main.cpp b/avatar-mixer/src/main.cpp index 0e838833f4..eca698e673 100644 --- a/avatar-mixer/src/main.cpp +++ b/avatar-mixer/src/main.cpp @@ -45,7 +45,7 @@ unsigned char *addAgentToBroadcastPacket(unsigned char *currentPosition, Agent * return currentPosition; } -void attachAvatarDataToAgent(Agent *newAgent) { +void attachAvatarDataToAgent(Agent* newAgent) { if (newAgent->getLinkedData() == NULL) { newAgent->setLinkedData(new AvatarData(newAgent)); } diff --git a/eve/src/main.cpp b/eve/src/main.cpp index 92355970c6..bf32474b33 100644 --- a/eve/src/main.cpp +++ b/eve/src/main.cpp @@ -95,7 +95,7 @@ int main(int argc, const char* argv[]) { pthread_create(&receiveAgentDataThread, NULL, receiveAgentData, NULL); // create an AvatarData object, "eve" - AvatarData eve(NULL); + AvatarData eve; // move eve away from the origin // pick a random point inside a 10x10 grid diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 80690e162a..990ca2aeff 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -128,7 +128,6 @@ Application::Application(int& argc, char** argv, timeval &startup_time) : _viewFrustumOffsetDistance(25.0), _viewFrustumOffsetUp(0.0), _audioScope(256, 200, true), - _myAvatar(NULL, true), _manualFirstPerson(false), _mouseX(0), _mouseY(0), @@ -2100,7 +2099,7 @@ QAction* Application::checkedVoxelModeAction() const { void Application::attachNewHeadToAgent(Agent* newAgent) { if (newAgent->getLinkedData() == NULL) { - newAgent->setLinkedData(new Avatar(newAgent, false)); + newAgent->setLinkedData(new Avatar(newAgent)); } } diff --git a/interface/src/Avatar.cpp b/interface/src/Avatar.cpp index 125ef979bb..83a3508b0d 100644 --- a/interface/src/Avatar.cpp +++ b/interface/src/Avatar.cpp @@ -69,10 +69,9 @@ bool usingBigSphereCollisionTest = true; float chatMessageScale = 0.0015; float chatMessageHeight = 0.10; -Avatar::Avatar(Agent* owningAgent, bool isMine) : +Avatar::Avatar(Agent* owningAgent) : AvatarData(owningAgent), _head(this), - _isMine(isMine), _TEST_bigSphereRadius(0.4f), _TEST_bigSpherePosition(5.0f, _TEST_bigSphereRadius, 5.0f), _mousePressed(false), @@ -231,7 +230,7 @@ void Avatar::simulate(float deltaTime, Transmitter* transmitter) { updateSkeleton(); //detect and respond to collisions with other avatars... - if (_isMine) { + if (!_owningAgent) { updateAvatarCollisions(deltaTime); } @@ -241,7 +240,7 @@ void Avatar::simulate(float deltaTime, Transmitter* transmitter) { _avatarTouch.simulate(deltaTime); // apply gravity and collision with the ground/floor - if (_isMine && USING_AVATAR_GRAVITY) { + if (!_owningAgent && USING_AVATAR_GRAVITY) { _velocity += _gravity * (GRAVITY_SCALE * deltaTime); updateCollisionWithEnvironment(); @@ -256,12 +255,12 @@ void Avatar::simulate(float deltaTime, Transmitter* transmitter) { } // collision response with voxels - if (_isMine) { + if (!_owningAgent) { updateCollisionWithVoxels(); } // driving the avatar around should only apply if this is my avatar (as opposed to an avatar being driven remotely) - if (_isMine) { + if (!_owningAgent) { _thrust = glm::vec3(0.0f, 0.0f, 0.0f); @@ -306,7 +305,7 @@ void Avatar::simulate(float deltaTime, Transmitter* transmitter) { } // update body yaw by body yaw delta - if (_isMine) { + if (!_owningAgent) { _bodyPitch += _bodyPitchDelta * deltaTime; _bodyYaw += _bodyYawDelta * deltaTime; _bodyRoll += _bodyRollDelta * deltaTime; @@ -367,7 +366,7 @@ void Avatar::simulate(float deltaTime, Transmitter* transmitter) { } // If another avatar is near, dampen velocity as a function of closeness - if (_isMine && (_distanceToNearestAvatar < PERIPERSONAL_RADIUS)) { + if (!_owningAgent && (_distanceToNearestAvatar < PERIPERSONAL_RADIUS)) { float closeness = 1.0f - (_distanceToNearestAvatar / PERIPERSONAL_RADIUS); float drag = 1.0f - closeness * AVATAR_BRAKING_STRENGTH * deltaTime; if ( drag > 0.0f ) { @@ -416,7 +415,7 @@ void Avatar::simulate(float deltaTime, Transmitter* transmitter) { } // set head lookat position - if (_isMine) { + if (!_owningAgent) { if (_interactingOther) { _head.setLookAtPosition(_interactingOther->caclulateAverageEyePosition()); } else { @@ -429,7 +428,7 @@ void Avatar::simulate(float deltaTime, Transmitter* transmitter) { _head.setScale (_joint[ AVATAR_JOINT_HEAD_BASE ].radius); _head.setAudioLoudness(_audioLoudness); _head.setSkinColor(glm::vec3(skinColor[0], skinColor[1], skinColor[2])); - _head.simulate(deltaTime, _isMine); + _head.simulate(deltaTime, !_owningAgent); // use speed and angular velocity to determine walking vs. standing if (_speed + fabs(_bodyYawDelta) > 0.2) { @@ -468,7 +467,7 @@ void Avatar::updateHandMovementAndTouching(float deltaTime) { _joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position += transformedHandMovement; - if (_isMine) { + if (!_owningAgent) { _avatarTouch.setMyBodyPosition(_position); float closestDistance = std::numeric_limits::max(); @@ -560,7 +559,7 @@ void Avatar::updateHandMovementAndTouching(float deltaTime) { updateArmIKAndConstraints(deltaTime); //Set right hand position and state to be transmitted, and also tell AvatarTouch about it - if (_isMine) { + if (!_owningAgent) { setHandPosition(_joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position); if (_mousePressed) { @@ -729,7 +728,7 @@ void Avatar::setGravity(glm::vec3 gravity) { void Avatar::render(bool lookingInMirror) { - if (_isMine && usingBigSphereCollisionTest) { + if (!_owningAgent && usingBigSphereCollisionTest) { // show TEST big sphere glColor4f(0.5f, 0.6f, 0.8f, 0.7); glPushMatrix(); @@ -746,7 +745,7 @@ void Avatar::render(bool lookingInMirror) { renderBody(lookingInMirror); // if this is my avatar, then render my interactions with the other avatar - if (_isMine) { + if (!_owningAgent) { _avatarTouch.render(getCameraPosition()); } @@ -1001,7 +1000,7 @@ void Avatar::updateSkeleton() { } // if this is not my avatar, then hand position comes from transmitted data - if (! _isMine) { + if (_owningAgent) { _joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position = _handPosition; } @@ -1137,12 +1136,12 @@ 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 || _owningAgent || distanceToCamera > RENDER_OPAQUE_BEYOND) { _head.render(lookingInMirror); } - } else if (!_isMine || distanceToCamera > RENDER_TRANSLUCENT_BEYOND) { + } else if (_owningAgent || distanceToCamera > RENDER_TRANSLUCENT_BEYOND) { // Render the sphere at the joint - if (!_isMine) { + if (_owningAgent) { glColor3f(skinColor[0] + _joint[b].touchForce * 0.3f, skinColor[1] - _joint[b].touchForce * 0.2f, skinColor[2] - _joint[b].touchForce * 0.1f); diff --git a/interface/src/Avatar.h b/interface/src/Avatar.h index a5f1531417..6d27eed22b 100644 --- a/interface/src/Avatar.h +++ b/interface/src/Avatar.h @@ -76,7 +76,7 @@ enum AvatarJointID class Avatar : public AvatarData { public: - Avatar(Agent* owningAgent, bool isMine); + Avatar(Agent* owningAgent = NULL); ~Avatar(); void reset(); @@ -151,7 +151,6 @@ private: }; Head _head; - bool _isMine; float _TEST_bigSphereRadius; glm::vec3 _TEST_bigSpherePosition; bool _mousePressed; diff --git a/libraries/avatars/src/AvatarData.h b/libraries/avatars/src/AvatarData.h index b1582cf9f8..5773dedffd 100644 --- a/libraries/avatars/src/AvatarData.h +++ b/libraries/avatars/src/AvatarData.h @@ -22,14 +22,14 @@ const int WANT_DELTA_AT_BIT = 2; enum KeyState { - NO_KEY_DOWN, + NO_KEY_DOWN, INSERT_KEY_DOWN, DELETE_KEY_DOWN }; class AvatarData : public AgentData { public: - AvatarData(Agent* owningAgent); + AvatarData(Agent* owningAgent = NULL); ~AvatarData(); const glm::vec3& getPosition() const { return _position; } diff --git a/libraries/shared/src/AgentData.h b/libraries/shared/src/AgentData.h index 99cdbaca95..7253d85e59 100644 --- a/libraries/shared/src/AgentData.h +++ b/libraries/shared/src/AgentData.h @@ -16,7 +16,7 @@ public: AgentData(Agent* owningAgent); virtual ~AgentData() = 0; virtual int parseData(unsigned char* sourceBuffer, int numBytes) = 0; -private: +protected: Agent* _owningAgent; }; From 6158410658e5dcef5336a95214884c55cec83acb Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Fri, 24 May 2013 12:32:00 -0700 Subject: [PATCH 15/15] provide a getter for the owning agent in AgentData --- libraries/shared/src/AgentData.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libraries/shared/src/AgentData.h b/libraries/shared/src/AgentData.h index 7253d85e59..9c931dd65a 100644 --- a/libraries/shared/src/AgentData.h +++ b/libraries/shared/src/AgentData.h @@ -14,8 +14,11 @@ class Agent; class AgentData { public: AgentData(Agent* owningAgent); + virtual ~AgentData() = 0; virtual int parseData(unsigned char* sourceBuffer, int numBytes) = 0; + + Agent* getOwningAgent() { return _owningAgent; } protected: Agent* _owningAgent; };