Merge remote-tracking branch 'upstream/master' into owner-pointers

This commit is contained in:
Stephen Birarda 2013-05-24 12:23:12 -07:00
commit 81307939d4
5 changed files with 57 additions and 29 deletions

View file

@ -883,7 +883,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

View file

@ -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(Agent* owningAgent) :
AvatarData(owningAgent),

View file

@ -8,6 +8,7 @@
#include "Util.h"
#include <vector>
#include <lodepng.h>
#include <AgentList.h>
using namespace std;
@ -55,8 +56,10 @@ Head::Head(Avatar* owningAvatar) :
_returnSpringScale(1.0f),
_bodyRotation(0.0f, 0.0f, 0.0f),
_headRotation(0.0f, 0.0f, 0.0f),
_renderLookatVectors(false) {
createMohawk();
_renderLookatVectors(false),
_mohawkTriangleFan(NULL),
_mohawkColors(NULL)
{
}
void Head::reset() {
@ -190,6 +193,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 +211,24 @@ void Head::createMohawk() {
_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);
if (!_mohawkTriangleFan) {
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();
}

View file

@ -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++;

View file

@ -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;