Merge remote-tracking branch 'upstream/master'

This commit is contained in:
Jeffrey Ventrella 2013-05-09 11:22:55 -07:00
commit 7cfc9844a3
14 changed files with 474 additions and 388 deletions

View file

@ -22,7 +22,6 @@
#include <AgentTypes.h> #include <AgentTypes.h>
#include <SharedUtil.h> #include <SharedUtil.h>
#include <StdDev.h> #include <StdDev.h>
#include <Stacktrace.h>
#include "AudioRingBuffer.h" #include "AudioRingBuffer.h"
#include "PacketHeaders.h" #include "PacketHeaders.h"
@ -259,7 +258,6 @@ void attachNewBufferToAgent(Agent *newAgent) {
} }
int main(int argc, const char* argv[]) { int main(int argc, const char* argv[]) {
signal(SIGSEGV, printStacktrace);
setvbuf(stdout, NULL, _IOLBF, 0); setvbuf(stdout, NULL, _IOLBF, 0);
AgentList* agentList = AgentList::createInstance(AGENT_TYPE_AUDIO_MIXER, MIXER_LISTEN_PORT); AgentList* agentList = AgentList::createInstance(AGENT_TYPE_AUDIO_MIXER, MIXER_LISTEN_PORT);

View file

@ -1,3 +1,5 @@
#!/usr/bin/env python
# #
# gen_stars.py # gen_stars.py
# interface # interface
@ -12,7 +14,7 @@ from random import random,randint
from math import sqrt, hypot, atan2, pi, fmod, degrees from math import sqrt, hypot, atan2, pi, fmod, degrees
from sys import argv,stderr from sys import argv,stderr
hemisphere_only, equator, meridians= False, 1000, 1000 hemisphere_only, equator, meridians= False, 0, 1000
n_random = 100000 n_random = 100000
if len(argv) > 1: if len(argv) > 1:
@ -50,10 +52,13 @@ for i in range(n_random):
g = max(0,min(255,w + randint(-20,60))) g = max(0,min(255,w + randint(-20,60)))
b = max(0,min(255,w + randint(-10,100))) b = max(0,min(255,w + randint(-10,100)))
# position # position
while True:
x,y,z = random()*2-1,random(),random()*2-1 x,y,z = random()*2-1,random(),random()*2-1
if not hemisphere_only: if not hemisphere_only:
y = y*2-1 y = y*2-1
l = sqrt(x*x + y*y + z*z) l = sqrt(x*x + y*y + z*z)
if l <= 1.0:
break
x /= l; y /= l; z /= l x /= l; y /= l; z /= l
xz = hypot(x,z) xz = hypot(x,z)

View file

@ -1257,6 +1257,11 @@ void Avatar::initializeBodySprings() {
} }
void Avatar::updateBodySprings(float deltaTime) { void Avatar::updateBodySprings(float deltaTime) {
// Check for a large repositioning, and re-initialize body springs if this has happened
const float BEYOND_BODY_SPRING_RANGE = 2.f;
if (glm::length(_position - _joint[AVATAR_JOINT_PELVIS].springyPosition) > BEYOND_BODY_SPRING_RANGE) {
initializeBodySprings();
}
for (int b = 0; b < NUM_AVATAR_JOINTS; b++) { for (int b = 0; b < NUM_AVATAR_JOINTS; b++) {
glm::vec3 springVector(_joint[b].springyPosition); glm::vec3 springVector(_joint[b].springyPosition);

View file

@ -42,9 +42,6 @@ void SerialInterface::pair() {
int matchStatus; int matchStatus;
regex_t regex; regex_t regex;
if (_failedOpenAttempts < 2) {
// if we've already failed to open the detected interface twice then don't try again
// for now this only works on OS X, where the usb serial shows up as /dev/tty.usb* // for now this only works on OS X, where the usb serial shows up as /dev/tty.usb*
if((devDir = opendir("/dev"))) { if((devDir = opendir("/dev"))) {
while((entry = readdir(devDir))) { while((entry = readdir(devDir))) {
@ -62,8 +59,6 @@ void SerialInterface::pair() {
} }
closedir(devDir); closedir(devDir);
} }
}
#endif #endif
} }
@ -76,7 +71,6 @@ void SerialInterface::initializePort(char* portname, int baud) {
if (_serialDescriptor == -1) { if (_serialDescriptor == -1) {
printLog("Failed.\n"); printLog("Failed.\n");
_failedOpenAttempts++;
return; return;
} }
struct termios options; struct termios options;
@ -123,6 +117,9 @@ void SerialInterface::initializePort(char* portname, int baud) {
// this disables streaming so there's no garbage data on reads // this disables streaming so there's no garbage data on reads
write(_serialDescriptor, "SD\n", 3); write(_serialDescriptor, "SD\n", 3);
// delay after disabling streaming
usleep(10000);
// flush whatever was produced by the last two commands // flush whatever was produced by the last two commands
tcflush(_serialDescriptor, TCIOFLUSH); tcflush(_serialDescriptor, TCIOFLUSH);
} }
@ -232,26 +229,38 @@ void SerialInterface::readData() {
int initialSamples = totalSamples; int initialSamples = totalSamples;
if (USING_INVENSENSE_MPU9150) { if (USING_INVENSENSE_MPU9150) {
unsigned char gyroBuffer[20]; unsigned char sensorBuffer[36];
// ask the invensense for raw gyro data // ask the invensense for raw gyro data
write(_serialDescriptor, "RD684306\n", 9); write(_serialDescriptor, "RD683B0E\n", 9);
read(_serialDescriptor, gyroBuffer, 20); read(_serialDescriptor, sensorBuffer, 36);
int accelXRate, accelYRate, accelZRate;
convertHexToInt(sensorBuffer + 6, accelXRate);
convertHexToInt(sensorBuffer + 10, accelYRate);
convertHexToInt(sensorBuffer + 14, accelZRate);
const float LSB_TO_METERS_PER_SECOND = 1.f / 16384.f;
_lastAccelX = ((float) accelXRate) * LSB_TO_METERS_PER_SECOND;
_lastAccelY = ((float) accelYRate) * LSB_TO_METERS_PER_SECOND;
_lastAccelZ = ((float) accelZRate) * LSB_TO_METERS_PER_SECOND;
int rollRate, yawRate, pitchRate; int rollRate, yawRate, pitchRate;
convertHexToInt(gyroBuffer + 6, rollRate); convertHexToInt(sensorBuffer + 22, rollRate);
convertHexToInt(gyroBuffer + 10, yawRate); convertHexToInt(sensorBuffer + 26, yawRate);
convertHexToInt(gyroBuffer + 14, pitchRate); convertHexToInt(sensorBuffer + 30, pitchRate);
// Convert the integer rates to floats // 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. const float LSB_TO_DEGREES_PER_SECOND = 1.f / 16.4f; // From MPU-9150 register map, 2000 deg/sec.
const float PITCH_BIAS = 2.0; // Strangely, there is a small DC bias in the const float PITCH_BIAS = 2.0; // Strangely, there is a small DC bias in the
// invensense pitch reading. Gravity? // invensense pitch reading. Gravity?
_lastRollRate = (float) rollRate * LSB_TO_DEGREES_PER_SECOND; _lastRollRate = ((float) rollRate) * LSB_TO_DEGREES_PER_SECOND;
_lastYawRate = (float) yawRate * LSB_TO_DEGREES_PER_SECOND; _lastYawRate = ((float) yawRate) * LSB_TO_DEGREES_PER_SECOND;
_lastPitchRate = (float) -pitchRate * LSB_TO_DEGREES_PER_SECOND + PITCH_BIAS; _lastPitchRate = ((float) -pitchRate) * LSB_TO_DEGREES_PER_SECOND + PITCH_BIAS;
totalSamples++; totalSamples++;
} else { } else {

View file

@ -37,7 +37,12 @@ extern const bool USING_INVENSENSE_MPU9150;
class SerialInterface { class SerialInterface {
public: public:
SerialInterface() : active(false), SerialInterface() : active(false),
_failedOpenAttempts(0) {} _lastAccelX(0),
_lastAccelY(0),
_lastAccelZ(0),
_lastYawRate(0),
_lastPitchRate(0),
_lastRollRate(0) {}
void pair(); void pair();
void readData(); void readData();
@ -69,10 +74,12 @@ private:
int totalSamples; int totalSamples;
timeval lastGoodRead; timeval lastGoodRead;
glm::vec3 gravity; glm::vec3 gravity;
float _lastAccelX;
float _lastAccelY;
float _lastAccelZ;
float _lastYawRate; // Rates are in degrees per second. float _lastYawRate; // Rates are in degrees per second.
float _lastPitchRate; float _lastPitchRate;
float _lastRollRate; float _lastRollRate;
int _failedOpenAttempts;
}; };
#endif #endif

View file

@ -679,3 +679,19 @@ void VoxelSystem::removeOutOfView() {
); );
} }
} }
bool VoxelSystem::findRayIntersection(const glm::vec3& origin, const glm::vec3& direction,
VoxelDetail& detail, float& distance, BoxFace& face) {
VoxelNode* node;
if (!_tree->findRayIntersection(origin, direction, node, distance, face)) {
return false;
}
detail.x = node->getCorner().x;
detail.y = node->getCorner().y;
detail.z = node->getCorner().z;
detail.s = node->getScale();
detail.red = node->getColor()[0];
detail.green = node->getColor()[1];
detail.blue = node->getColor()[2];
return true;
}

View file

@ -11,6 +11,7 @@
#include "InterfaceConfig.h" #include "InterfaceConfig.h"
#include <glm/glm.hpp> #include <glm/glm.hpp>
#include <SharedUtil.h>
#include <UDPSocket.h> #include <UDPSocket.h>
#include <AgentData.h> #include <AgentData.h>
#include <VoxelTree.h> #include <VoxelTree.h>
@ -64,6 +65,9 @@ public:
void removeOutOfView(); void removeOutOfView();
bool hasViewChanged(); bool hasViewChanged();
bool findRayIntersection(const glm::vec3& origin, const glm::vec3& direction,
VoxelDetail& detail, float& distance, BoxFace& face);
private: private:
int _callsToTreesToArrays; int _callsToTreesToArrays;
VoxelNodeBag _removedVoxels; VoxelNodeBag _removedVoxels;

View file

@ -70,7 +70,6 @@
#include "Oscilloscope.h" #include "Oscilloscope.h"
#include "UDPSocket.h" #include "UDPSocket.h"
#include "SerialInterface.h" #include "SerialInterface.h"
#include <SharedUtil.h>
#include <PacketHeaders.h> #include <PacketHeaders.h>
#include <AvatarData.h> #include <AvatarData.h>
#include <PerfStat.h> #include <PerfStat.h>
@ -1007,22 +1006,6 @@ void display(void)
glPushMatrix(); { glPushMatrix(); {
glLoadIdentity(); glLoadIdentity();
// Setup 3D lights
glEnable(GL_COLOR_MATERIAL);
glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
GLfloat light_position0[] = { 1.0, 1.0, 0.0, 0.0 };
glLightfv(GL_LIGHT0, GL_POSITION, light_position0);
GLfloat ambient_color[] = { 0.7, 0.7, 0.8 };
glLightfv(GL_LIGHT0, GL_AMBIENT, ambient_color);
GLfloat diffuse_color[] = { 0.8, 0.7, 0.7 };
glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse_color);
GLfloat specular_color[] = { 1.0, 1.0, 1.0, 1.0};
glLightfv(GL_LIGHT0, GL_SPECULAR, specular_color);
glMaterialfv(GL_FRONT, GL_SPECULAR, specular_color);
glMateriali(GL_FRONT, GL_SHININESS, 96);
// camera settings // camera settings
if (::lookingInMirror) { if (::lookingInMirror) {
// set the camera to looking at my own face // set the camera to looking at my own face
@ -1155,6 +1138,22 @@ void display(void)
glTranslatef(-whichCamera.getPosition().x, -whichCamera.getPosition().y, -whichCamera.getPosition().z); glTranslatef(-whichCamera.getPosition().x, -whichCamera.getPosition().y, -whichCamera.getPosition().z);
// Setup 3D lights (after the camera transform, so that they are positioned in world space)
glEnable(GL_COLOR_MATERIAL);
glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
GLfloat light_position0[] = { 1.0, 1.0, 0.0, 0.0 };
glLightfv(GL_LIGHT0, GL_POSITION, light_position0);
GLfloat ambient_color[] = { 0.7, 0.7, 0.8 };
glLightfv(GL_LIGHT0, GL_AMBIENT, ambient_color);
GLfloat diffuse_color[] = { 0.8, 0.7, 0.7 };
glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse_color);
GLfloat specular_color[] = { 1.0, 1.0, 1.0, 1.0};
glLightfv(GL_LIGHT0, GL_SPECULAR, specular_color);
glMaterialfv(GL_FRONT, GL_SPECULAR, specular_color);
glMateriali(GL_FRONT, GL_SHININESS, 96);
if (::oculusOn) { if (::oculusOn) {
displayOculus(whichCamera); displayOculus(whichCamera);
@ -1484,6 +1483,68 @@ void setupPaintingVoxel() {
shiftPaintingColor(); shiftPaintingColor();
} }
void addVoxelUnderCursor() {
glm::vec3 origin, direction;
viewFrustum.computePickRay(mouseX / (float)WIDTH, mouseY / (float)HEIGHT, origin, direction);
VoxelDetail detail;
float distance;
BoxFace face;
if (voxels.findRayIntersection(origin, direction, detail, distance, face)) {
// use the face to determine the side on which to create a neighbor
switch (face) {
case MIN_X_FACE:
detail.x -= detail.s;
break;
case MAX_X_FACE:
detail.x += detail.s;
break;
case MIN_Y_FACE:
detail.y -= detail.s;
break;
case MAX_Y_FACE:
detail.y += detail.s;
break;
case MIN_Z_FACE:
detail.z -= detail.s;
break;
case MAX_Z_FACE:
detail.z += detail.s;
break;
}
unsigned char* bufferOut;
int sizeOut;
if (createVoxelEditMessage(PACKET_HEADER_SET_VOXEL, 0, 1, &detail, bufferOut, sizeOut)){
AgentList::getInstance()->broadcastToAgents(bufferOut, sizeOut, &AGENT_TYPE_VOXEL, 1);
delete bufferOut;
}
}
}
void deleteVoxelUnderCursor() {
glm::vec3 origin, direction;
viewFrustum.computePickRay(mouseX / (float)WIDTH, mouseY / (float)HEIGHT, origin, direction);
VoxelDetail detail;
float distance;
BoxFace face;
if (voxels.findRayIntersection(origin, direction, detail, distance, face)) {
unsigned char* bufferOut;
int sizeOut;
if (createVoxelEditMessage(PACKET_HEADER_ERASE_VOXEL, 0, 1, &detail, bufferOut, sizeOut)){
AgentList::getInstance()->broadcastToAgents(bufferOut, sizeOut, &AGENT_TYPE_VOXEL, 1);
delete bufferOut;
}
}
}
const float KEYBOARD_YAW_RATE = 0.8; const float KEYBOARD_YAW_RATE = 0.8;
const float KEYBOARD_PITCH_RATE = 0.6; const float KEYBOARD_PITCH_RATE = 0.6;
const float KEYBOARD_STRAFE_RATE = 0.03; const float KEYBOARD_STRAFE_RATE = 0.03;
@ -1601,6 +1662,8 @@ void key(unsigned char k, int x, int y) {
if (k == '^') ::shiftPaintingColor(); // shifts randomize color between R,G,B dominant if (k == '^') ::shiftPaintingColor(); // shifts randomize color between R,G,B dominant
if (k == '-') ::sendVoxelServerEraseAll(); // sends erase all command to voxel server if (k == '-') ::sendVoxelServerEraseAll(); // sends erase all command to voxel server
if (k == '%') ::sendVoxelServerAddScene(); // sends add scene command to voxel server if (k == '%') ::sendVoxelServerAddScene(); // sends add scene command to voxel server
if (k == '1') ::addVoxelUnderCursor();
if (k == '2') ::deleteVoxelUnderCursor();
if (k == 'n' || k == 'N') if (k == 'n' || k == 'N')
{ {
noiseOn = !noiseOn; // Toggle noise noiseOn = !noiseOn; // Toggle noise

View file

@ -1,28 +0,0 @@
//
// Stacktrace.cpp
// hifi
//
// Created by Stephen Birarda on 5/6/13.
//
//
#include <signal.h>
#include <stdio.h>
#include <execinfo.h>
#include <cstdlib>
#include "Stacktrace.h"
const int NUMBER_OF_STACK_ENTRIES = 20;
void printStacktrace(int signal) {
void* array[NUMBER_OF_STACK_ENTRIES];
// get void*'s for all entries on the stack
size_t size = backtrace(array, NUMBER_OF_STACK_ENTRIES);
// print out all the frames to stderr
fprintf(stderr, "Error: signal %d:\n", signal);
backtrace_symbols_fd(array, size, 2);
exit(1);
}

View file

@ -1,16 +0,0 @@
//
// Stacktrace.h
// hifi
//
// Created by Stephen Birarda on 5/6/13.
//
//
#ifndef __hifi__Stacktrace__
#define __hifi__Stacktrace__
#include <iostream>
void printStacktrace(int signal);
#endif /* defined(__hifi__Stacktrace__) */

View file

@ -95,7 +95,7 @@ static bool findIntersection(float origin, float direction, float corner, float
return false; return false;
} }
bool AABox::findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, float& distance) const { bool AABox::findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, float& distance, BoxFace& face) const {
// handle the trivial case where the box contains the origin // handle the trivial case where the box contains the origin
if (contains(origin)) { if (contains(origin)) {
distance = 0; distance = 0;
@ -105,14 +105,23 @@ bool AABox::findRayIntersection(const glm::vec3& origin, const glm::vec3& direct
float axisDistance; float axisDistance;
if ((findIntersection(origin.x, direction.x, _corner.x, _size.x, axisDistance) && axisDistance >= 0 && if ((findIntersection(origin.x, direction.x, _corner.x, _size.x, axisDistance) && axisDistance >= 0 &&
isWithin(origin.y + axisDistance*direction.y, _corner.y, _size.y) && isWithin(origin.y + axisDistance*direction.y, _corner.y, _size.y) &&
isWithin(origin.z + axisDistance*direction.z, _corner.z, _size.z)) || isWithin(origin.z + axisDistance*direction.z, _corner.z, _size.z))) {
(findIntersection(origin.y, direction.y, _corner.y, _size.y, axisDistance) && axisDistance >= 0 && distance = axisDistance;
face = direction.x > 0 ? MIN_X_FACE : MAX_X_FACE;
return true;
}
if ((findIntersection(origin.y, direction.y, _corner.y, _size.y, axisDistance) && axisDistance >= 0 &&
isWithin(origin.x + axisDistance*direction.x, _corner.x, _size.x) && isWithin(origin.x + axisDistance*direction.x, _corner.x, _size.x) &&
isWithin(origin.z + axisDistance*direction.z, _corner.z, _size.z)) || isWithin(origin.z + axisDistance*direction.z, _corner.z, _size.z))) {
(findIntersection(origin.z, direction.z, _corner.z, _size.z, axisDistance) && axisDistance >= 0 && distance = axisDistance;
face = direction.y > 0 ? MIN_Y_FACE : MAX_Y_FACE;
return true;
}
if ((findIntersection(origin.z, direction.z, _corner.z, _size.z, axisDistance) && axisDistance >= 0 &&
isWithin(origin.y + axisDistance*direction.y, _corner.y, _size.y) && isWithin(origin.y + axisDistance*direction.y, _corner.y, _size.y) &&
isWithin(origin.x + axisDistance*direction.x, _corner.x, _size.x))) { isWithin(origin.x + axisDistance*direction.x, _corner.x, _size.x))) {
distance = axisDistance; distance = axisDistance;
face = direction.z > 0 ? MIN_Z_FACE : MAX_Z_FACE;
return true; return true;
} }
return false; return false;

View file

@ -13,6 +13,15 @@
#include <glm/glm.hpp> #include <glm/glm.hpp>
enum BoxFace {
MIN_X_FACE,
MAX_X_FACE,
MIN_Y_FACE,
MAX_Y_FACE,
MIN_Z_FACE,
MAX_Z_FACE
};
class AABox class AABox
{ {
@ -37,7 +46,7 @@ public:
const glm::vec3& getCenter() const { return _center; }; const glm::vec3& getCenter() const { return _center; };
bool contains(const glm::vec3& point) const; bool contains(const glm::vec3& point) const;
bool findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, float& distance) const; bool findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, float& distance, BoxFace& face) const;
private: private:
glm::vec3 _corner; glm::vec3 _corner;

View file

@ -605,6 +605,7 @@ public:
glm::vec3 direction; glm::vec3 direction;
VoxelNode*& node; VoxelNode*& node;
float& distance; float& distance;
BoxFace& face;
bool found; bool found;
}; };
@ -612,7 +613,8 @@ bool findRayOperation(VoxelNode* node, void* extraData) {
RayArgs* args = static_cast<RayArgs*>(extraData); RayArgs* args = static_cast<RayArgs*>(extraData);
AABox box = node->getAABox(); AABox box = node->getAABox();
float distance; float distance;
if (!box.findRayIntersection(args->origin, args->direction, distance)) { BoxFace face;
if (!box.findRayIntersection(args->origin, args->direction, distance, face)) {
return false; return false;
} }
if (!node->isLeaf()) { if (!node->isLeaf()) {
@ -621,14 +623,16 @@ bool findRayOperation(VoxelNode* node, void* extraData) {
if (!args->found || distance < args->distance) { if (!args->found || distance < args->distance) {
args->node = node; args->node = node;
args->distance = distance; args->distance = distance;
args->face = face;
args->found = true; args->found = true;
} }
return false; return false;
} }
bool VoxelTree::findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, VoxelNode*& node, float& distance) bool VoxelTree::findRayIntersection(const glm::vec3& origin, const glm::vec3& direction,
VoxelNode*& node, float& distance, BoxFace& face)
{ {
RayArgs args = { origin / (float)TREE_SCALE, direction, node, distance }; RayArgs args = { origin / (float)TREE_SCALE, direction, node, distance, face };
recurseTreeWithOperation(findRayOperation, &args); recurseTreeWithOperation(findRayOperation, &args);
return args.found; return args.found;
} }

View file

@ -63,7 +63,8 @@ public:
void clearDirtyBit() { _isDirty = false; }; void clearDirtyBit() { _isDirty = false; };
unsigned long int getNodesChangedFromBitstream() const { return _nodesChangedFromBitstream; }; unsigned long int getNodesChangedFromBitstream() const { return _nodesChangedFromBitstream; };
bool findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, VoxelNode*& node, float& distance); bool findRayIntersection(const glm::vec3& origin, const glm::vec3& direction,
VoxelNode*& node, float& distance, BoxFace& face);
// Note: this assumes the fileFormat is the HIO individual voxels code files // Note: this assumes the fileFormat is the HIO individual voxels code files
void loadVoxelsFile(const char* fileName, bool wantColorRandomizer); void loadVoxelsFile(const char* fileName, bool wantColorRandomizer);