Merge branch 'master' of https://github.com/worklist/hifi into bug_fixes

This commit is contained in:
ZappoMan 2013-07-15 17:05:10 -07:00
commit 31875abcab
10 changed files with 84 additions and 25 deletions

View file

@ -434,7 +434,7 @@ void sendDanceFloor() {
for (int i = 0; i < DANCE_FLOOR_WIDTH; i++) {
for (int j = 0; j < DANCE_FLOOR_LENGTH; j++) {
int randomColorIndex = randIntInRange( -(DANCE_FLOOR_COLORS), (DANCE_FLOOR_COLORS + 1));
int randomColorIndex = randIntInRange(-DANCE_FLOOR_COLORS, DANCE_FLOOR_COLORS);
::danceFloorColors[i][j] = randomColorIndex;
::danceFloorLights[i][j] = ::danceFloorPosition +
glm::vec3(i * DANCE_FLOOR_LIGHT_SIZE, 0, j * DANCE_FLOOR_LIGHT_SIZE);

View file

@ -97,7 +97,7 @@ int main(int argc, const char* argv[]) {
switch (packetData[0]) {
case PACKET_TYPE_HEAD_DATA:
// grab the node ID from the packet
unpackNodeId(packetData + 1, &nodeID);
unpackNodeId(packetData + numBytesForPacketHeader(packetData), &nodeID);
// add or update the node in our list
avatarNode = nodeList->addOrUpdateNode(nodeAddress, nodeAddress, NODE_TYPE_AGENT, nodeID);

View file

@ -1447,7 +1447,7 @@ void Application::importVoxels() {
importVoxels.readFromSquareARGB32Pixels(pixels, pngImage.height());
} else if (fileNameString.endsWith(".svo", Qt::CaseInsensitive)) {
importVoxels.readFromSVOFile(fileName);
} else {
} else if (fileNameString.endsWith(".schematic", Qt::CaseInsensitive)) {
importVoxels.readFromSchematicFile(fileName);
}
@ -1480,9 +1480,6 @@ void Application::importVoxels() {
// If we have voxels left in the packet, then send the packet
if (args.bufferInUse > (numBytesPacketHeader + sizeof(unsigned short int))) {
controlledBroadcastToNodes(args.messageBuffer, args.bufferInUse, & NODE_TYPE_VOXEL_SERVER, 1);
printLog("sending packet: %d\n", ++args.packetsSent);
args.bytesSent += args.bufferInUse;
printLog("total bytes sent: %ld\n", args.bytesSent);
}
if (calculatedOctCode) {
@ -1704,6 +1701,8 @@ void Application::initMenu() {
(_renderCoverageMapV2 = debugMenu->addAction("Render Coverage Map V2"))->setCheckable(true);
_renderCoverageMapV2->setShortcut(Qt::SHIFT | Qt::CTRL | Qt::Key_P);
(_simulateLeapHand = debugMenu->addAction("Simulate Leap Hand"))->setCheckable(true);
(_testRaveGlove = debugMenu->addAction("Test RaveGlove"))->setCheckable(true);
QMenu* settingsMenu = menuBar->addMenu("Settings");
(_settingsAutosave = settingsMenu->addAction("Autosave"))->setCheckable(true);
@ -1962,6 +1961,7 @@ void Application::update(float deltaTime) {
}
// Leap finger-sensing device
LeapManager::enableFakeFingers(_simulateLeapHand->isChecked() || _testRaveGlove->isChecked());
LeapManager::nextFrame();
_myAvatar.getHand().setLeapFingers(LeapManager::getFingerTips(), LeapManager::getFingerRoots());
_myAvatar.getHand().setLeapHands(LeapManager::getHandPositions(), LeapManager::getHandNormals());

View file

@ -262,6 +262,9 @@ private:
QAction* _renderCoverageMapV2;
QAction* _renderCoverageMap;
QAction* _simulateLeapHand; // When there's no Leap, use this to pretend there is one and feed fake hand data
QAction* _testRaveGlove; // Test fancy sparkle-rave-glove mode
BandwidthMeter _bandwidthMeter;
BandwidthDialog* _bandwidthDialog;

View file

@ -50,6 +50,9 @@ public:
// getters
const glm::vec3& getLeapBallPosition (int ball) const { return _leapBalls[ball].position;}
// position conversion
glm::vec3 leapPositionToWorldPosition(const glm::vec3& leapPosition);
private:
// disallow copies of the Hand, copy of owning Avatar is disallowed too
Hand(const Hand&);
@ -66,7 +69,6 @@ private:
// private methods
void renderHandSpheres();
void calculateGeometry();
glm::vec3 leapPositionToWorldPosition(const glm::vec3& leapPosition);
};
#endif

View file

@ -599,7 +599,7 @@ void Head::renderEyeBalls() {
_irisProgram->setUniform(_eyePositionLocation, (glm::inverse(rotation) *
(Application::getInstance()->getCamera()->getPosition() - _leftEyePosition) +
glm::vec3(0.0f, 0.0f, _scale * IRIS_PROTRUSION)) * glm::vec3(1.0f / (_scale * IRIS_RADIUS * 2.0f),
1.0f / (_scale * IRIS_RADIUS * 2.0f), 1.0f / _scale * IRIS_RADIUS));
1.0f / (_scale * IRIS_RADIUS * 2.0f), 1.0f / (_scale * IRIS_RADIUS)));
glutSolidSphere(0.5f, 15, 15);
}
@ -623,7 +623,7 @@ void Head::renderEyeBalls() {
_irisProgram->setUniform(_eyePositionLocation, (glm::inverse(rotation) *
(Application::getInstance()->getCamera()->getPosition() - _rightEyePosition) +
glm::vec3(0.0f, 0.0f, _scale * IRIS_PROTRUSION)) * glm::vec3(1.0f / (_scale * IRIS_RADIUS * 2.0f),
1.0f / (_scale * IRIS_RADIUS * 2.0f), 1.0f / _scale * IRIS_RADIUS));
1.0f / (_scale * IRIS_RADIUS * 2.0f), 1.0f / (_scale * IRIS_RADIUS)));
glutSolidSphere(0.5f, 15, 15);
}

View file

@ -12,9 +12,14 @@
#include <sstream>
bool LeapManager::_libraryExists = false;
bool LeapManager::_doFakeFingers = false;
Leap::Controller* LeapManager::_controller = NULL;
HifiLeapListener* LeapManager::_listener = NULL;
namespace {
glm::vec3 fakeHandOffset(0.0f, 50.0f, 50.0f);
} // end anonymous namespace
class HifiLeapListener : public Leap::Listener {
public:
HifiLeapListener() {}
@ -76,47 +81,91 @@ void LeapManager::terminate() {
}
void LeapManager::nextFrame() {
if (_listener && _controller)
if (controllersExist()) {
_listener->onFrame(*_controller);
}
}
void LeapManager::enableFakeFingers(bool enable) {
_doFakeFingers = enable;
}
bool LeapManager::controllersExist() {
#ifdef LEAP_STUBS
return false;
#else
return _listener && _controller && _controller->devices().count() > 0;
#endif
}
const std::vector<glm::vec3>& LeapManager::getFingerTips() {
if (_listener) {
if (controllersExist()) {
return _listener->fingerTips;
}
else {
static std::vector<glm::vec3> empty;
return empty;
static std::vector<glm::vec3> stubData;
stubData.clear();
if (_doFakeFingers) {
// Simulated data
float scale = 1.5f;
stubData.push_back(glm::vec3( -60.0f, 0.0f, -40.0f) * scale + fakeHandOffset);
stubData.push_back(glm::vec3( -20.0f, 0.0f, -60.0f) * scale + fakeHandOffset);
stubData.push_back(glm::vec3( 20.0f, 0.0f, -60.0f) * scale + fakeHandOffset);
stubData.push_back(glm::vec3( 60.0f, 0.0f, -40.0f) * scale + fakeHandOffset);
stubData.push_back(glm::vec3( -50.0f, 0.0f, 30.0f) * scale + fakeHandOffset);
}
return stubData;
}
}
const std::vector<glm::vec3>& LeapManager::getFingerRoots() {
if (_listener) {
if (controllersExist()) {
return _listener->fingerRoots;
}
else {
static std::vector<glm::vec3> empty;
return empty;
static std::vector<glm::vec3> stubData;
stubData.clear();
if (_doFakeFingers) {
// Simulated data
float scale = 0.75f;
stubData.push_back(glm::vec3( -60.0f, 0.0f, -40.0f) * scale + fakeHandOffset);
stubData.push_back(glm::vec3( -20.0f, 0.0f, -60.0f) * scale + fakeHandOffset);
stubData.push_back(glm::vec3( 20.0f, 0.0f, -60.0f) * scale + fakeHandOffset);
stubData.push_back(glm::vec3( 60.0f, 0.0f, -40.0f) * scale + fakeHandOffset);
stubData.push_back(glm::vec3( -50.0f, 0.0f, 30.0f) * scale + fakeHandOffset);
}
return stubData;
}
}
const std::vector<glm::vec3>& LeapManager::getHandPositions() {
if (_listener) {
if (controllersExist()) {
return _listener->handPositions;
}
else {
static std::vector<glm::vec3> empty;
return empty;
static std::vector<glm::vec3> stubData;
stubData.clear();
if (_doFakeFingers) {
// Simulated data
glm::vec3 handOffset(0.0f, 50.0f, 50.0f);
stubData.push_back(glm::vec3( 0.0f, 0.0f, 0.0f) + fakeHandOffset);
}
return stubData;
}
}
const std::vector<glm::vec3>& LeapManager::getHandNormals() {
if (_listener) {
if (controllersExist()) {
return _listener->handNormals;
}
else {
static std::vector<glm::vec3> empty;
return empty;
static std::vector<glm::vec3> stubData;
stubData.clear();
if (_doFakeFingers) {
// Simulated data
stubData.push_back(glm::vec3(0.0f, 1.0f, 0.0f));
}
return stubData;
}
}

View file

@ -20,7 +20,9 @@ namespace Leap {
class LeapManager {
public:
static void nextFrame(); // called once per frame to get new Leap data
static void nextFrame(); // called once per frame to get new Leap data
static bool controllersExist(); // Returns true if there's at least one active Leap plugged in
static void enableFakeFingers(bool enable); // put fake data in if there's no Leap plugged in
static const std::vector<glm::vec3>& getFingerTips();
static const std::vector<glm::vec3>& getFingerRoots();
static const std::vector<glm::vec3>& getHandPositions();
@ -31,6 +33,7 @@ public:
private:
static bool _libraryExists; // The library is present, so we won't crash if we call it.
static bool _doFakeFingers;
static Leap::Controller* _controller;
static HifiLeapListener* _listener;
};

View file

@ -20,6 +20,8 @@ class HandData {
public:
HandData(AvatarData* owningAvatar);
// These methods return the positions in Leap-relative space.
// To convert to world coordinates, use Hand::leapPositionToWorldPosition.
const std::vector<glm::vec3>& getFingerTips() const { return _fingerTips; }
const std::vector<glm::vec3>& getFingerRoots() const { return _fingerRoots; }
const std::vector<glm::vec3>& getHandPositions() const { return _handPositions; }

View file

@ -40,7 +40,7 @@ float randFloat () {
}
int randIntInRange (int min, int max) {
return min + (rand() % (max - min));
return min + (rand() % ((max + 1) - min));
}
float randFloatInRange (float min,float max) {
@ -48,7 +48,7 @@ float randFloatInRange (float min,float max) {
}
unsigned char randomColorValue(int miniumum) {
return miniumum + (rand() % (255 - miniumum));
return miniumum + (rand() % (256 - miniumum));
}
bool randomBoolean() {