Merge remote-tracking branch 'upstream/master'

This commit is contained in:
Jeffrey Ventrella 2013-05-23 10:15:18 -07:00
commit 649fb72556
10 changed files with 53 additions and 37 deletions

View file

@ -303,8 +303,8 @@ void Application::paintGL() {
_myCamera.setTightness (100.0f);
_myCamera.setTargetPosition(_myAvatar.getHeadPosition());
_myCamera.setTargetRotation(_myAvatar.getAbsoluteHeadYaw(),
-_myAvatar.getHead().getPitch(),
_myAvatar.getHead().getRoll());
_myAvatar.getHead().getPitch(),
-_myAvatar.getHead().getRoll());
} else if (_myCamera.getMode() == CAMERA_MODE_FIRST_PERSON) {
_myCamera.setTargetPosition(_myAvatar.getSpringyHeadPosition());
_myCamera.setTargetRotation(_myAvatar.getAbsoluteHeadYaw(),
@ -1365,7 +1365,7 @@ void Application::updateAvatar(float deltaTime) {
const float VERTICAL_PIXELS_PER_DEGREE = 1800.f / 30.f;
if (powf(measuredYawRate * measuredYawRate +
measuredPitchRate * measuredPitchRate, 0.5) > MIN_MOUSE_RATE) {
_headMouseX += measuredYawRate * HORIZONTAL_PIXELS_PER_DEGREE * deltaTime;
_headMouseX -= measuredYawRate * HORIZONTAL_PIXELS_PER_DEGREE * deltaTime;
_headMouseY -= measuredPitchRate * VERTICAL_PIXELS_PER_DEGREE * deltaTime;
}
_headMouseX = max(_headMouseX, 0);
@ -1377,7 +1377,7 @@ void Application::updateAvatar(float deltaTime) {
float yaw, pitch, roll;
OculusManager::getEulerAngles(yaw, pitch, roll);
_myAvatar.getHead().setYaw(-yaw);
_myAvatar.getHead().setYaw(yaw);
_myAvatar.getHead().setPitch(pitch);
_myAvatar.getHead().setRoll(roll);
}

View file

@ -145,8 +145,7 @@ void Avatar::updateHeadFromGyros(float deltaTime, SerialInterface* serialInterfa
// Update head lean distance based on accelerometer data
glm::vec3 headRotationRates(_head.getPitch(), _head.getYaw(), _head.getRoll());
glm::vec3 leaning = (serialInterface->getLastAcceleration() - serialInterface->getGravity())
glm::vec3 leaning = (serialInterface->getLastAcceleration() - serialInterface->getGravity())
* LEAN_SENSITIVITY
* (1.f - fminf(glm::length(headRotationRates), HEAD_RATE_MAX) / HEAD_RATE_MAX);
leaning.y = 0.f;

View file

@ -114,19 +114,29 @@ bool Environment::findCapsulePenetration(const glm::vec3& start, const glm::vec3
}
int Environment::parseData(sockaddr *senderAddress, unsigned char* sourceBuffer, int numBytes) {
EnvironmentData newData;
int bytesRead = newData.parseData(sourceBuffer, numBytes);
// push past the packet header
unsigned char* start = sourceBuffer;
sourceBuffer++;
numBytes--;
// get the lock for the duration of the call
QMutexLocker locker(&_mutex);
// update the mapping by address/ID
_data[*senderAddress][newData.getID()] = newData;
EnvironmentData newData;
while (numBytes > 0) {
int dataLength = newData.parseData(sourceBuffer, numBytes);
// update the mapping by address/ID
_data[*senderAddress][newData.getID()] = newData;
sourceBuffer += dataLength;
numBytes -= dataLength;
}
// remove the default mapping, if any
_data.remove(getZeroAddress());
return bytesRead;
return sourceBuffer - start;
}
ProgramObject* Environment::createSkyProgram(const char* from, int* locations) {

View file

@ -131,12 +131,12 @@ void Head::calculateGeometry(bool lookingInMirror) {
//generate orientation directions based on Euler angles...
float pitch = _pitch;
float yaw = -_yaw;
float roll = -_roll;
float yaw = _yaw;
float roll = _roll;
if (lookingInMirror) {
yaw = _yaw;
roll = _roll;
yaw = -_yaw;
roll = -_roll;
}
_orientation.setToIdentity();
@ -210,8 +210,6 @@ void Head::renderEars() {
glPopMatrix();
}
void Head::renderMouth() {
float s = sqrt(_averageLoudness);

View file

@ -38,7 +38,7 @@ void OculusManager::connect() {
void OculusManager::getEulerAngles(float& yaw, float& pitch, float& roll) {
#ifdef __APPLE__
_sensorFusion.GetOrientation().GetEulerAngles<Axis_Y, Axis_X, Axis_Z, Rotate_CW, Handed_R>(&yaw, &pitch, &roll);
_sensorFusion.GetOrientation().GetEulerAngles<Axis_Y, Axis_X, Axis_Z, Rotate_CCW, Handed_R>(&yaw, &pitch, &roll);
// convert each angle to degrees
yaw = glm::degrees(yaw);

View file

@ -203,8 +203,8 @@ void SerialInterface::readData() {
// Convert the integer rates to floats
const float LSB_TO_DEGREES_PER_SECOND = 1.f / 16.4f; // From MPU-9150 register map, 2000 deg/sec.
_lastRollRate = ((float) rollRate) * LSB_TO_DEGREES_PER_SECOND;
_lastYawRate = ((float) yawRate) * LSB_TO_DEGREES_PER_SECOND;
_lastRollRate = ((float) -rollRate) * LSB_TO_DEGREES_PER_SECOND;
_lastYawRate = ((float) -yawRate) * LSB_TO_DEGREES_PER_SECOND;
_lastPitchRate = ((float) -pitchRate) * LSB_TO_DEGREES_PER_SECOND;
// Accumulate a set of initial baseline readings for setting gravity

View file

@ -52,6 +52,10 @@ bool randomBoolean() {
return rand() % 2;
}
bool shouldDo(float desiredInterval, float deltaTime) {
return randFloat() < deltaTime / desiredInterval;
}
void outputBufferBits(unsigned char* buffer, int length, bool withNewLine) {
for (int i = 0; i < length; i++) {
outputBits(buffer[i], false);
@ -417,4 +421,3 @@ int insertIntoSortedArrays(void* value, float key, int originalIndex,
}
return -1; // error case
}

View file

@ -44,6 +44,8 @@ float randFloatInRange (float min,float max);
unsigned char randomColorValue(int minimum);
bool randomBoolean();
bool shouldDo(float desiredInterval, float deltaTime);
void outputBufferBits(unsigned char* buffer, int length, bool withNewLine = true);
void outputBits(unsigned char byte, bool withNewLine = true);
void printVoxelCode(unsigned char* voxelCode);

View file

@ -28,8 +28,6 @@ EnvironmentData::EnvironmentData(int id) :
int EnvironmentData::getBroadcastData(unsigned char* destinationBuffer) const {
unsigned char* bufferStart = destinationBuffer;
*destinationBuffer++ = PACKET_HEADER_ENVIRONMENT_DATA;
memcpy(destinationBuffer, &_id, sizeof(_id));
destinationBuffer += sizeof(_id);
@ -64,9 +62,6 @@ int EnvironmentData::getBroadcastData(unsigned char* destinationBuffer) const {
}
int EnvironmentData::parseData(unsigned char* sourceBuffer, int numBytes) {
// increment to push past the packet header
sourceBuffer++;
unsigned char* startPosition = sourceBuffer;
memcpy(&_id, sourceBuffer, sizeof(_id));

View file

@ -49,6 +49,8 @@ int PACKETS_PER_CLIENT_PER_INTERVAL = 50;
const int MAX_VOXEL_TREE_DEPTH_LEVELS = 4;
const int ENVIRONMENT_SEND_INTERVAL_USECS = 1000000;
VoxelTree randomTree(true); // this is a reaveraging tree
bool wantVoxelPersist = true;
bool wantLocalDomain = false;
@ -161,8 +163,8 @@ void resInVoxelDistributor(AgentList* agentList,
int trueBytesSent = 0;
double start = usecTimestampNow();
int environmentPacketCount = sizeof(environmentData) / sizeof(environmentData[0]);
while (packetsSentThisInterval < PACKETS_PER_CLIENT_PER_INTERVAL - environmentPacketCount) {
bool shouldSendEnvironments = shouldDo(ENVIRONMENT_SEND_INTERVAL_USECS, VOXEL_SEND_INTERVAL_USECS);
while (packetsSentThisInterval < PACKETS_PER_CLIENT_PER_INTERVAL - (shouldSendEnvironments ? 1 : 0)) {
if (!agentData->nodeBag.isEmpty()) {
VoxelNode* subTree = agentData->nodeBag.extract();
bytesWritten = randomTree.encodeTreeBitstream(agentData->getMaxSearchLevel(), subTree,
@ -194,13 +196,16 @@ void resInVoxelDistributor(AgentList* agentList,
}
}
// send the environment packets
for (int i = 0; i < environmentPacketCount; i++) {
int envPacketLength = environmentData[i].getBroadcastData(tempOutputBuffer);
if (shouldSendEnvironments) {
int envPacketLength = 1;
*tempOutputBuffer = PACKET_HEADER_ENVIRONMENT_DATA;
for (int i = 0; i < sizeof(environmentData) / sizeof(environmentData[0]); i++) {
envPacketLength += environmentData[i].getBroadcastData(tempOutputBuffer + envPacketLength);
}
agentList->getAgentSocket()->send(agent->getActiveSocket(), tempOutputBuffer, envPacketLength);
trueBytesSent += envPacketLength;
truePacketsSent++;
truePacketsSent++;
}
double end = usecTimestampNow();
double elapsedmsec = (end - start)/1000.0;
if (elapsedmsec > 100) {
@ -301,8 +306,8 @@ void deepestLevelVoxelDistributor(AgentList* agentList,
int trueBytesSent = 0;
double start = usecTimestampNow();
int environmentPacketCount = sizeof(environmentData) / sizeof(environmentData[0]);
while (packetsSentThisInterval < PACKETS_PER_CLIENT_PER_INTERVAL - environmentPacketCount) {
bool shouldSendEnvironments = shouldDo(ENVIRONMENT_SEND_INTERVAL_USECS, VOXEL_SEND_INTERVAL_USECS);
while (packetsSentThisInterval < PACKETS_PER_CLIENT_PER_INTERVAL - (shouldSendEnvironments ? 1 : 0)) {
if (!agentData->nodeBag.isEmpty()) {
VoxelNode* subTree = agentData->nodeBag.extract();
bytesWritten = randomTree.encodeTreeBitstream(INT_MAX, subTree,
@ -334,9 +339,13 @@ void deepestLevelVoxelDistributor(AgentList* agentList,
packetsSentThisInterval = PACKETS_PER_CLIENT_PER_INTERVAL; // done for now, no nodes left
}
}
// send the environment packets
for (int i = 0; i < environmentPacketCount; i++) {
int envPacketLength = environmentData[i].getBroadcastData(tempOutputBuffer);
// send the environment packet
if (shouldSendEnvironments) {
int envPacketLength = 1;
*tempOutputBuffer = PACKET_HEADER_ENVIRONMENT_DATA;
for (int i = 0; i < sizeof(environmentData) / sizeof(environmentData[0]); i++) {
envPacketLength += environmentData[i].getBroadcastData(tempOutputBuffer + envPacketLength);
}
agentList->getAgentSocket()->send(agent->getActiveSocket(), tempOutputBuffer, envPacketLength);
trueBytesSent += envPacketLength;
truePacketsSent++;