merge branch assignee with upstream/master

This commit is contained in:
Stephen Birarda 2013-07-16 09:17:39 -07:00
commit 6844490dbe
27 changed files with 572 additions and 281 deletions

View file

@ -434,7 +434,7 @@ void sendDanceFloor() {
for (int i = 0; i < DANCE_FLOOR_WIDTH; i++) { for (int i = 0; i < DANCE_FLOOR_WIDTH; i++) {
for (int j = 0; j < DANCE_FLOOR_LENGTH; j++) { 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; ::danceFloorColors[i][j] = randomColorIndex;
::danceFloorLights[i][j] = ::danceFloorPosition + ::danceFloorLights[i][j] = ::danceFloorPosition +
glm::vec3(i * DANCE_FLOOR_LIGHT_SIZE, 0, j * DANCE_FLOOR_LIGHT_SIZE); glm::vec3(i * DANCE_FLOOR_LIGHT_SIZE, 0, j * DANCE_FLOOR_LIGHT_SIZE);
@ -697,8 +697,7 @@ int main(int argc, const char * argv[])
::wantLocalDomain = cmdOptionExists(argc, argv,local); ::wantLocalDomain = cmdOptionExists(argc, argv,local);
if (::wantLocalDomain) { if (::wantLocalDomain) {
printf("Local Domain MODE!\n"); printf("Local Domain MODE!\n");
int ip = getLocalAddress(); nodeList->setDomainIPToLocalhost();
sprintf(DOMAIN_IP,"%d.%d.%d.%d", (ip & 0xFF), ((ip >> 8) & 0xFF),((ip >> 16) & 0xFF), ((ip >> 24) & 0xFF));
} }
nodeList->linkedDataCreateCallback = NULL; // do we need a callback? nodeList->linkedDataCreateCallback = NULL; // do we need a callback?

View file

@ -70,16 +70,15 @@ bool wantLocalDomain = false;
int main(int argc, const char* argv[]) { int main(int argc, const char* argv[]) {
setvbuf(stdout, NULL, _IOLBF, 0); setvbuf(stdout, NULL, _IOLBF, 0);
NodeList* nodeList = NodeList::createInstance(NODE_TYPE_AUDIO_MIXER, MIXER_LISTEN_PORT);
// Handle Local Domain testing with the --local command line // Handle Local Domain testing with the --local command line
const char* local = "--local"; const char* local = "--local";
::wantLocalDomain = cmdOptionExists(argc, argv,local); ::wantLocalDomain = cmdOptionExists(argc, argv,local);
if (::wantLocalDomain) { if (::wantLocalDomain) {
printf("Local Domain MODE!\n"); printf("Local Domain MODE!\n");
int ip = getLocalAddress(); nodeList->setDomainIPToLocalhost();
sprintf(DOMAIN_IP,"%d.%d.%d.%d", (ip & 0xFF), ((ip >> 8) & 0xFF),((ip >> 16) & 0xFF), ((ip >> 24) & 0xFF)); }
}
NodeList* nodeList = NodeList::createInstance(NODE_TYPE_AUDIO_MIXER, MIXER_LISTEN_PORT);
ssize_t receivedBytes = 0; ssize_t receivedBytes = 0;

View file

@ -60,8 +60,7 @@ int main(int argc, const char* argv[]) {
const char* local = "--local"; const char* local = "--local";
if (cmdOptionExists(argc, argv, local)) { if (cmdOptionExists(argc, argv, local)) {
printf("Local Domain MODE!\n"); printf("Local Domain MODE!\n");
int ip = getLocalAddress(); nodeList->setDomainIPToLocalhost();
sprintf(DOMAIN_IP,"%d.%d.%d.%d", (ip & 0xFF), ((ip >> 8) & 0xFF),((ip >> 16) & 0xFF), ((ip >> 24) & 0xFF));
} }
nodeList->linkedDataCreateCallback = attachAvatarDataToNode; nodeList->linkedDataCreateCallback = attachAvatarDataToNode;
@ -97,7 +96,7 @@ int main(int argc, const char* argv[]) {
switch (packetData[0]) { switch (packetData[0]) {
case PACKET_TYPE_HEAD_DATA: case PACKET_TYPE_HEAD_DATA:
// grab the node ID from the packet // grab the node ID from the packet
unpackNodeId(packetData + 1, &nodeID); unpackNodeId(packetData + numBytesForPacketHeader(packetData), &nodeID);
// add or update the node in our list // add or update the node in our list
avatarNode = nodeList->addOrUpdateNode(nodeAddress, nodeAddress, NODE_TYPE_AGENT, nodeID); avatarNode = nodeList->addOrUpdateNode(nodeAddress, nodeAddress, NODE_TYPE_AGENT, nodeID);

View file

@ -82,6 +82,7 @@ const glm::vec3 START_LOCATION(4.f, 0.f, 5.f); // Where one's own node begins
const int IDLE_SIMULATE_MSECS = 16; // How often should call simulate and other stuff const int IDLE_SIMULATE_MSECS = 16; // How often should call simulate and other stuff
// in the idle loop? (60 FPS is default) // in the idle loop? (60 FPS is default)
static QTimer* idleTimer = NULL;
const int STARTUP_JITTER_SAMPLES = PACKET_LENGTH_SAMPLES_PER_CHANNEL / 2; const int STARTUP_JITTER_SAMPLES = PACKET_LENGTH_SAMPLES_PER_CHANNEL / 2;
// Startup optimistically with small jitter buffer that // Startup optimistically with small jitter buffer that
@ -227,14 +228,14 @@ Application::Application(int& argc, char** argv, timeval &startup_time) :
const char* domainIP = getCmdOption(argc, constArgv, "--domain"); const char* domainIP = getCmdOption(argc, constArgv, "--domain");
if (domainIP) { if (domainIP) {
strcpy(DOMAIN_IP, domainIP); NodeList::getInstance()->setDomainIP(domainIP);
} }
// Handle Local Domain testing with the --local command line // Handle Local Domain testing with the --local command line
if (cmdOptionExists(argc, constArgv, "--local")) { if (cmdOptionExists(argc, constArgv, "--local")) {
printLog("Local Domain MODE!\n"); printLog("Local Domain MODE!\n");
int ip = getLocalAddress();
sprintf(DOMAIN_IP,"%d.%d.%d.%d", (ip & 0xFF), ((ip >> 8) & 0xFF),((ip >> 16) & 0xFF), ((ip >> 24) & 0xFF)); NodeList::getInstance()->setDomainIPToLocalhost();
} }
// Check to see if the user passed in a command line option for loading a local // Check to see if the user passed in a command line option for loading a local
@ -341,7 +342,7 @@ void Application::initializeGL() {
timer->start(1000); timer->start(1000);
// call our idle function whenever we can // call our idle function whenever we can
QTimer* idleTimer = new QTimer(this); idleTimer = new QTimer(this);
connect(idleTimer, SIGNAL(timeout()), SLOT(idle())); connect(idleTimer, SIGNAL(timeout()), SLOT(idle()));
idleTimer->start(0); idleTimer->start(0);
_idleLoopStdev.reset(); _idleLoopStdev.reset();
@ -973,19 +974,9 @@ void Application::idle() {
gettimeofday(&check, NULL); gettimeofday(&check, NULL);
// Only run simulation code if more than IDLE_SIMULATE_MSECS have passed since last time we ran // Only run simulation code if more than IDLE_SIMULATE_MSECS have passed since last time we ran
sendPostedEvents(NULL, QEvent::TouchBegin);
sendPostedEvents(NULL, QEvent::TouchUpdate);
sendPostedEvents(NULL, QEvent::TouchEnd);
double timeSinceLastUpdate = diffclock(&_lastTimeUpdated, &check); double timeSinceLastUpdate = diffclock(&_lastTimeUpdated, &check);
if (timeSinceLastUpdate > IDLE_SIMULATE_MSECS) { if (timeSinceLastUpdate > IDLE_SIMULATE_MSECS) {
// If we're using multi-touch look, immediately process any
// touch events, and no other events.
// This is necessary because id the idle() call takes longer than the
// interval between idle() calls, the event loop never gets to run,
// and touch events get delayed.
const float BIGGEST_DELTA_TIME_SECS = 0.25f; const float BIGGEST_DELTA_TIME_SECS = 0.25f;
update(glm::clamp((float)timeSinceLastUpdate / 1000.f, 0.f, BIGGEST_DELTA_TIME_SECS)); update(glm::clamp((float)timeSinceLastUpdate / 1000.f, 0.f, BIGGEST_DELTA_TIME_SECS));
_glWidget->updateGL(); _glWidget->updateGL();
@ -998,6 +989,9 @@ void Application::idle() {
_idleLoopMeasuredJitter = _idleLoopStdev.getStDev(); _idleLoopMeasuredJitter = _idleLoopStdev.getStDev();
_idleLoopStdev.reset(); _idleLoopStdev.reset();
} }
// After finishing all of the above work, restart the idle timer, allowing 2ms to process events.
idleTimer->start(2);
} }
} }
void Application::terminate() { void Application::terminate() {
@ -1101,8 +1095,14 @@ void Application::editPreferences() {
QFormLayout* form = new QFormLayout(); QFormLayout* form = new QFormLayout();
layout->addLayout(form, 1); layout->addLayout(form, 1);
const int QLINE_MINIMUM_WIDTH = 400;
QLineEdit* domainServerHostname = new QLineEdit(QString(NodeList::getInstance()->getDomainHostname()));
domainServerHostname->setMinimumWidth(QLINE_MINIMUM_WIDTH);
form->addRow("Domain server:", domainServerHostname);
QLineEdit* avatarURL = new QLineEdit(_myAvatar.getVoxels()->getVoxelURL().toString()); QLineEdit* avatarURL = new QLineEdit(_myAvatar.getVoxels()->getVoxelURL().toString());
avatarURL->setMinimumWidth(400); avatarURL->setMinimumWidth(QLINE_MINIMUM_WIDTH);
form->addRow("Avatar URL:", avatarURL); form->addRow("Avatar URL:", avatarURL);
QSpinBox* horizontalFieldOfView = new QSpinBox(); QSpinBox* horizontalFieldOfView = new QSpinBox();
@ -1133,9 +1133,33 @@ void Application::editPreferences() {
if (dialog.exec() != QDialog::Accepted) { if (dialog.exec() != QDialog::Accepted) {
return; return;
} }
const char* newHostname = domainServerHostname->text().toLocal8Bit().data();
// check if the domain server hostname is new
if (memcmp(NodeList::getInstance()->getDomainHostname(), newHostname, sizeof(&newHostname)) != 0) {
// if so we need to clear the nodelist and delete the local voxels
Node *voxelServer = NodeList::getInstance()->soloNodeOfType(NODE_TYPE_VOXEL_SERVER);
if (voxelServer) {
voxelServer->lock();
}
_voxels.killLocalVoxels();
if (voxelServer) {
voxelServer->unlock();
}
NodeList::getInstance()->clear();
NodeList::getInstance()->setDomainHostname(newHostname);
}
QUrl url(avatarURL->text()); QUrl url(avatarURL->text());
_myAvatar.getVoxels()->setVoxelURL(url); _myAvatar.getVoxels()->setVoxelURL(url);
sendAvatarVoxelURLMessage(url); sendAvatarVoxelURLMessage(url);
_headCameraPitchYawScale = headCameraPitchYawScale->value(); _headCameraPitchYawScale = headCameraPitchYawScale->value();
_myAvatar.setLeanScale(leanScale->value()); _myAvatar.setLeanScale(leanScale->value());
_audioJitterBufferSamples = audioJitterBufferSamples->value(); _audioJitterBufferSamples = audioJitterBufferSamples->value();
@ -1182,6 +1206,24 @@ void Application::setRenderThirdPerson(bool thirdPerson) {
} }
} }
void Application::increaseAvatarSize() {
if (5.0f < _myAvatar.getScale() + 0.05f) {
return;
}
_myAvatar.setScale(_myAvatar.getScale() + 0.05f);
_myCamera.setScale(_myAvatar.getScale() + 0.05f);
}
void Application::decreaseAvatarSize() {
if (_myAvatar.getScale() - 0.05f < 0.15f) {
return;
}
_myAvatar.setScale(_myAvatar.getScale() - 0.05f);
_myCamera.setScale(_myAvatar.getScale() - 0.05f);
}
void Application::setFrustumOffset(bool frustumOffset) { void Application::setFrustumOffset(bool frustumOffset) {
// reshape so that OpenGL will get the right lens details for the camera of choice // reshape so that OpenGL will get the right lens details for the camera of choice
resizeGL(_glWidget->width(), _glWidget->height()); resizeGL(_glWidget->width(), _glWidget->height());
@ -1196,6 +1238,12 @@ void Application::setRenderWarnings(bool renderWarnings) {
_voxels.setRenderPipelineWarnings(renderWarnings); _voxels.setRenderPipelineWarnings(renderWarnings);
} }
void Application::setRenderVoxels(bool voxelRender) {
if (!voxelRender) {
doKillLocalVoxels();
}
}
void Application::doKillLocalVoxels() { void Application::doKillLocalVoxels() {
_wantToKillLocalVoxels = true; _wantToKillLocalVoxels = true;
} }
@ -1392,10 +1440,9 @@ void Application::importVoxels() {
_glWidget, tr("Import Voxels"), desktopLocation, _glWidget, tr("Import Voxels"), desktopLocation,
tr("Sparse Voxel Octree Files, Square PNG, Schematic Files (*.svo *.png *.schematic)")); tr("Sparse Voxel Octree Files, Square PNG, Schematic Files (*.svo *.png *.schematic)"));
QByteArray fileNameAscii = fileNameString.toAscii(); const char* fileName = fileNameString.toAscii().data();
const char* fileName = fileNameAscii.data();
_clipboardTree.eraseAllVoxels();
VoxelTree importVoxels;
if (fileNameString.endsWith(".png", Qt::CaseInsensitive)) { if (fileNameString.endsWith(".png", Qt::CaseInsensitive)) {
QImage pngImage = QImage(fileName); QImage pngImage = QImage(fileName);
if (pngImage.height() != pngImage.width()) { if (pngImage.height() != pngImage.width()) {
@ -1411,43 +1458,11 @@ void Application::importVoxels() {
pixels = reinterpret_cast<const uint32_t*>(tmp.constBits()); pixels = reinterpret_cast<const uint32_t*>(tmp.constBits());
} }
importVoxels.readFromSquareARGB32Pixels(pixels, pngImage.height()); _clipboardTree.readFromSquareARGB32Pixels(pixels, pngImage.height());
} else if (fileNameString.endsWith(".svo", Qt::CaseInsensitive)) { } else if (fileNameString.endsWith(".svo", Qt::CaseInsensitive)) {
importVoxels.readFromSVOFile(fileName); _clipboardTree.readFromSVOFile(fileName);
} else { } else if (fileNameString.endsWith(".schematic", Qt::CaseInsensitive)) {
importVoxels.readFromSchematicFile(fileName); _clipboardTree.readFromSchematicFile(fileName);
}
VoxelNode* selectedNode = _voxels.getVoxelAt(_mouseVoxel.x, _mouseVoxel.y, _mouseVoxel.z, _mouseVoxel.s);
// Recurse the Import Voxels tree, where everything is root relative, and send all the colored voxels to
// the server as an set voxel message, this will also rebase the voxels to the new location
unsigned char* calculatedOctCode = NULL;
SendVoxelsOperationArgs args;
int numBytesPacketHeader = populateTypeAndVersion(args.messageBuffer, PACKET_TYPE_SET_VOXEL_DESTRUCTIVE);
unsigned short int* sequenceAt = (unsigned short int*)&args.messageBuffer[numBytesPacketHeader];
*sequenceAt = 0;
args.bufferInUse = numBytesPacketHeader + sizeof(unsigned short int); // set to command + sequence
// we only need the selected voxel to get the newBaseOctCode, which we can actually calculate from the
// voxel size/position details.
if (selectedNode) {
args.newBaseOctCode = selectedNode->getOctalCode();
} else {
args.newBaseOctCode = calculatedOctCode = pointToVoxel(_mouseVoxel.x, _mouseVoxel.y, _mouseVoxel.z, _mouseVoxel.s);
}
importVoxels.recurseTreeWithOperation(sendVoxelsOperation, &args);
// 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);
}
if (calculatedOctCode) {
delete[] calculatedOctCode;
} }
// restore the main window's active state // restore the main window's active state
@ -1539,9 +1554,8 @@ void Application::initMenu() {
optionsMenu->addAction("Go Home", this, SLOT(goHome())); optionsMenu->addAction("Go Home", this, SLOT(goHome()));
QMenu* renderMenu = menuBar->addMenu("Render"); QMenu* renderMenu = menuBar->addMenu("Render");
(_renderVoxels = renderMenu->addAction("Voxels"))->setCheckable(true); (_renderVoxels = renderMenu->addAction("Voxels", this, SLOT(setRenderVoxels(bool)), Qt::SHIFT | Qt::Key_V))->setCheckable(true);
_renderVoxels->setChecked(true); _renderVoxels->setChecked(true);
_renderVoxels->setShortcut(Qt::SHIFT | Qt::Key_V);
(_renderVoxelTextures = renderMenu->addAction("Voxel Textures"))->setCheckable(true); (_renderVoxelTextures = renderMenu->addAction("Voxel Textures"))->setCheckable(true);
(_renderStarsOn = renderMenu->addAction("Stars"))->setCheckable(true); (_renderStarsOn = renderMenu->addAction("Stars"))->setCheckable(true);
_renderStarsOn->setChecked(true); _renderStarsOn->setChecked(true);
@ -1555,7 +1569,7 @@ void Application::initMenu() {
_renderAvatarsOn->setChecked(true); _renderAvatarsOn->setChecked(true);
(_renderAvatarBalls = renderMenu->addAction("Avatar as Balls"))->setCheckable(true); (_renderAvatarBalls = renderMenu->addAction("Avatar as Balls"))->setCheckable(true);
_renderAvatarBalls->setChecked(false); _renderAvatarBalls->setChecked(false);
renderMenu->addAction("Cycle Voxeltar Mode", _myAvatar.getVoxels(), SLOT(cycleMode())); renderMenu->addAction("Cycle Voxel Mode", _myAvatar.getVoxels(), SLOT(cycleMode()));
(_renderFrameTimerOn = renderMenu->addAction("Show Timer"))->setCheckable(true); (_renderFrameTimerOn = renderMenu->addAction("Show Timer"))->setCheckable(true);
_renderFrameTimerOn->setChecked(false); _renderFrameTimerOn->setChecked(false);
(_renderLookatOn = renderMenu->addAction("Lookat Vectors"))->setCheckable(true); (_renderLookatOn = renderMenu->addAction("Lookat Vectors"))->setCheckable(true);
@ -1564,6 +1578,9 @@ void Application::initMenu() {
"First Person", this, SLOT(setRenderFirstPerson(bool)), Qt::Key_P))->setCheckable(true); "First Person", this, SLOT(setRenderFirstPerson(bool)), Qt::Key_P))->setCheckable(true);
(_manualThirdPerson = renderMenu->addAction( (_manualThirdPerson = renderMenu->addAction(
"Third Person", this, SLOT(setRenderThirdPerson(bool))))->setCheckable(true); "Third Person", this, SLOT(setRenderThirdPerson(bool))))->setCheckable(true);
renderMenu->addAction("Increase Avatar Size", this, SLOT(increaseAvatarSize()), Qt::SHIFT | Qt::Key_Plus);
renderMenu->addAction("Decrease Avatar Size", this, SLOT(decreaseAvatarSize()), Qt::SHIFT | Qt::Key_Minus);
QMenu* toolsMenu = menuBar->addMenu("Tools"); QMenu* toolsMenu = menuBar->addMenu("Tools");
(_renderStatsOn = toolsMenu->addAction("Stats"))->setCheckable(true); (_renderStatsOn = toolsMenu->addAction("Stats"))->setCheckable(true);
@ -1656,6 +1673,8 @@ void Application::initMenu() {
(_renderCoverageMapV2 = debugMenu->addAction("Render Coverage Map V2"))->setCheckable(true); (_renderCoverageMapV2 = debugMenu->addAction("Render Coverage Map V2"))->setCheckable(true);
_renderCoverageMapV2->setShortcut(Qt::SHIFT | Qt::CTRL | Qt::Key_P); _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"); QMenu* settingsMenu = menuBar->addMenu("Settings");
(_settingsAutosave = settingsMenu->addAction("Autosave"))->setCheckable(true); (_settingsAutosave = settingsMenu->addAction("Autosave"))->setCheckable(true);
@ -1914,6 +1933,7 @@ void Application::update(float deltaTime) {
} }
// Leap finger-sensing device // Leap finger-sensing device
LeapManager::enableFakeFingers(_simulateLeapHand->isChecked() || _testRaveGlove->isChecked());
LeapManager::nextFrame(); LeapManager::nextFrame();
_myAvatar.getHand().setLeapFingers(LeapManager::getFingerTips(), LeapManager::getFingerRoots()); _myAvatar.getHand().setLeapFingers(LeapManager::getFingerTips(), LeapManager::getFingerRoots());
_myAvatar.getHand().setLeapHands(LeapManager::getHandPositions(), LeapManager::getHandNormals()); _myAvatar.getHand().setLeapHands(LeapManager::getHandPositions(), LeapManager::getHandNormals());
@ -1935,8 +1955,8 @@ void Application::update(float deltaTime) {
//loop through all the other avatars and simulate them... //loop through all the other avatars and simulate them...
NodeList* nodeList = NodeList::getInstance(); NodeList* nodeList = NodeList::getInstance();
nodeList->lock();
for(NodeList::iterator node = nodeList->begin(); node != nodeList->end(); node++) { for(NodeList::iterator node = nodeList->begin(); node != nodeList->end(); node++) {
node->lock();
if (node->getLinkedData() != NULL) { if (node->getLinkedData() != NULL) {
Avatar *avatar = (Avatar *)node->getLinkedData(); Avatar *avatar = (Avatar *)node->getLinkedData();
if (!avatar->isInitialized()) { if (!avatar->isInitialized()) {
@ -1945,8 +1965,8 @@ void Application::update(float deltaTime) {
avatar->simulate(deltaTime, NULL); avatar->simulate(deltaTime, NULL);
avatar->setMouseRay(mouseRayOrigin, mouseRayDirection); avatar->setMouseRay(mouseRayOrigin, mouseRayDirection);
} }
node->unlock();
} }
nodeList->unlock();
// Simulate myself // Simulate myself
if (_gravityUse->isChecked()) { if (_gravityUse->isChecked()) {
@ -2435,8 +2455,10 @@ void Application::displaySide(Camera& whichCamera) {
if (_renderAvatarsOn->isChecked()) { if (_renderAvatarsOn->isChecked()) {
// Render avatars of other nodes // Render avatars of other nodes
NodeList* nodeList = NodeList::getInstance(); NodeList* nodeList = NodeList::getInstance();
nodeList->lock();
for (NodeList::iterator node = nodeList->begin(); node != nodeList->end(); node++) { for (NodeList::iterator node = nodeList->begin(); node != nodeList->end(); node++) {
node->lock();
if (node->getLinkedData() != NULL && node->getType() == NODE_TYPE_AGENT) { if (node->getLinkedData() != NULL && node->getType() == NODE_TYPE_AGENT) {
Avatar *avatar = (Avatar *)node->getLinkedData(); Avatar *avatar = (Avatar *)node->getLinkedData();
if (!avatar->isInitialized()) { if (!avatar->isInitialized()) {
@ -2445,8 +2467,9 @@ void Application::displaySide(Camera& whichCamera) {
avatar->render(false, _renderAvatarBalls->isChecked()); avatar->render(false, _renderAvatarBalls->isChecked());
avatar->setDisplayingLookatVectors(_renderLookatOn->isChecked()); avatar->setDisplayingLookatVectors(_renderLookatOn->isChecked());
} }
node->unlock();
} }
nodeList->unlock();
// Render my own Avatar // Render my own Avatar
if (_myCamera.getMode() == CAMERA_MODE_MIRROR) { if (_myCamera.getMode() == CAMERA_MODE_MIRROR) {
@ -3195,7 +3218,7 @@ void* Application::networkReceive(void* args) {
if (app->_wantToKillLocalVoxels) { if (app->_wantToKillLocalVoxels) {
app->_voxels.killLocalVoxels(); app->_voxels.killLocalVoxels();
app->_wantToKillLocalVoxels = false; app->_wantToKillLocalVoxels = false;
} }
if (NodeList::getInstance()->getNodeSocket()->receive(&senderAddress, app->_incomingPacket, &bytesReceived)) { if (NodeList::getInstance()->getNodeSocket()->receive(&senderAddress, app->_incomingPacket, &bytesReceived)) {
app->_packetCount++; app->_packetCount++;
@ -3216,11 +3239,23 @@ void* Application::networkReceive(void* args) {
case PACKET_TYPE_VOXEL_DATA_MONOCHROME: case PACKET_TYPE_VOXEL_DATA_MONOCHROME:
case PACKET_TYPE_Z_COMMAND: case PACKET_TYPE_Z_COMMAND:
case PACKET_TYPE_ERASE_VOXEL: case PACKET_TYPE_ERASE_VOXEL:
app->_voxels.parseData(app->_incomingPacket, bytesReceived); case PACKET_TYPE_ENVIRONMENT_DATA: {
break; if (app->_renderVoxels->isChecked()) {
case PACKET_TYPE_ENVIRONMENT_DATA: Node* voxelServer = NodeList::getInstance()->soloNodeOfType(NODE_TYPE_VOXEL_SERVER);
app->_environment.parseData(&senderAddress, app->_incomingPacket, bytesReceived); if (voxelServer) {
voxelServer->lock();
if (app->_incomingPacket[0] == PACKET_TYPE_ENVIRONMENT_DATA) {
app->_environment.parseData(&senderAddress, app->_incomingPacket, bytesReceived);
} else {
app->_voxels.parseData(app->_incomingPacket, bytesReceived);
}
voxelServer->unlock();
}
}
break; break;
}
case PACKET_TYPE_BULK_AVATAR_DATA: case PACKET_TYPE_BULK_AVATAR_DATA:
NodeList::getInstance()->processBulkNodeData(&senderAddress, NodeList::getInstance()->processBulkNodeData(&senderAddress,
app->_incomingPacket, app->_incomingPacket,

View file

@ -118,6 +118,8 @@ private slots:
void setRenderFirstPerson(bool firstPerson); void setRenderFirstPerson(bool firstPerson);
void setRenderThirdPerson(bool thirdPerson); void setRenderThirdPerson(bool thirdPerson);
void increaseAvatarSize();
void decreaseAvatarSize();
void renderThrustAtVoxel(const glm::vec3& thrust); void renderThrustAtVoxel(const glm::vec3& thrust);
void renderLineToTouchedVoxel(); void renderLineToTouchedVoxel();
@ -126,6 +128,7 @@ private slots:
void cycleFrustumRenderMode(); void cycleFrustumRenderMode();
void setRenderWarnings(bool renderWarnings); void setRenderWarnings(bool renderWarnings);
void setRenderVoxels(bool renderVoxels);
void doKillLocalVoxels(); void doKillLocalVoxels();
void doRandomizeVoxelColors(); void doRandomizeVoxelColors();
void doFalseRandomizeVoxelColors(); void doFalseRandomizeVoxelColors();
@ -260,6 +263,9 @@ private:
QAction* _renderCoverageMapV2; QAction* _renderCoverageMapV2;
QAction* _renderCoverageMap; 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; BandwidthMeter _bandwidthMeter;
BandwidthDialog* _bandwidthDialog; BandwidthDialog* _bandwidthDialog;

View file

@ -96,6 +96,10 @@ inline void Audio::performIO(int16_t* inputLeft, int16_t* outputLeft, int16_t* o
Node* audioMixer = nodeList->soloNodeOfType(NODE_TYPE_AUDIO_MIXER); Node* audioMixer = nodeList->soloNodeOfType(NODE_TYPE_AUDIO_MIXER);
if (audioMixer) { if (audioMixer) {
audioMixer->lock();
sockaddr_in audioSocket = *(sockaddr_in*) audioMixer->getActiveSocket();
audioMixer->unlock();
glm::vec3 headPosition = interfaceAvatar->getHeadJointPosition(); glm::vec3 headPosition = interfaceAvatar->getHeadJointPosition();
glm::quat headOrientation = interfaceAvatar->getHead().getOrientation(); glm::quat headOrientation = interfaceAvatar->getHead().getOrientation();
@ -122,12 +126,13 @@ inline void Audio::performIO(int16_t* inputLeft, int16_t* outputLeft, int16_t* o
// copy the audio data to the last BUFFER_LENGTH_BYTES bytes of the data packet // copy the audio data to the last BUFFER_LENGTH_BYTES bytes of the data packet
memcpy(currentPacketPtr, inputLeft, BUFFER_LENGTH_BYTES_PER_CHANNEL); memcpy(currentPacketPtr, inputLeft, BUFFER_LENGTH_BYTES_PER_CHANNEL);
nodeList->getNodeSocket()->send(audioMixer->getActiveSocket(), nodeList->getNodeSocket()->send((sockaddr*) &audioSocket,
dataPacket, dataPacket,
BUFFER_LENGTH_BYTES_PER_CHANNEL + leadingBytes); BUFFER_LENGTH_BYTES_PER_CHANNEL + leadingBytes);
interface->getBandwidthMeter()->outputStream(BandwidthMeter::AUDIO) interface->getBandwidthMeter()->outputStream(BandwidthMeter::AUDIO).updateValue(BUFFER_LENGTH_BYTES_PER_CHANNEL
.updateValue(BUFFER_LENGTH_BYTES_PER_CHANNEL + leadingBytes); + leadingBytes);
} }
} }

View file

@ -86,6 +86,7 @@ Avatar::Avatar(Node* owningNode) :
_leanScale(0.5f), _leanScale(0.5f),
_pelvisStandingHeight(0.0f), _pelvisStandingHeight(0.0f),
_pelvisFloatingHeight(0.0f), _pelvisFloatingHeight(0.0f),
_scale(1.0f),
_distanceToNearestAvatar(std::numeric_limits<float>::max()), _distanceToNearestAvatar(std::numeric_limits<float>::max()),
_gravity(0.0f, -1.0f, 0.0f), _gravity(0.0f, -1.0f, 0.0f),
_worldUpDirection(DEFAULT_UP_DIRECTION), _worldUpDirection(DEFAULT_UP_DIRECTION),
@ -111,9 +112,9 @@ Avatar::Avatar(Node* owningNode) :
_skeleton.initialize(); _skeleton.initialize();
initializeBodyBalls(); initializeBodyBalls();
_height = _skeleton.getHeight() + _bodyBall[ BODY_BALL_LEFT_HEEL ].radius + _bodyBall[ BODY_BALL_HEAD_BASE ].radius; _height = _skeleton.getHeight() + _bodyBall[ BODY_BALL_LEFT_HEEL ].radius + _bodyBall[ BODY_BALL_HEAD_BASE ].radius;
_maxArmLength = _skeleton.getArmLength(); _maxArmLength = _skeleton.getArmLength();
_pelvisStandingHeight = _skeleton.getPelvisStandingHeight() + _bodyBall[ BODY_BALL_LEFT_HEEL ].radius; _pelvisStandingHeight = _skeleton.getPelvisStandingHeight() + _bodyBall[ BODY_BALL_LEFT_HEEL ].radius;
_pelvisFloatingHeight = _skeleton.getPelvisFloatingHeight() + _bodyBall[ BODY_BALL_LEFT_HEEL ].radius; _pelvisFloatingHeight = _skeleton.getPelvisFloatingHeight() + _bodyBall[ BODY_BALL_LEFT_HEEL ].radius;
@ -145,32 +146,32 @@ void Avatar::initializeBodyBalls() {
} }
// specify the radius of each ball // specify the radius of each ball
_bodyBall[ BODY_BALL_PELVIS ].radius = 0.07; _bodyBall[ BODY_BALL_PELVIS ].radius = BODY_BALL_RADIUS_PELVIS;
_bodyBall[ BODY_BALL_TORSO ].radius = 0.065; _bodyBall[ BODY_BALL_TORSO ].radius = BODY_BALL_RADIUS_TORSO;
_bodyBall[ BODY_BALL_CHEST ].radius = 0.08; _bodyBall[ BODY_BALL_CHEST ].radius = BODY_BALL_RADIUS_CHEST;
_bodyBall[ BODY_BALL_NECK_BASE ].radius = 0.03; _bodyBall[ BODY_BALL_NECK_BASE ].radius = BODY_BALL_RADIUS_NECK_BASE;
_bodyBall[ BODY_BALL_HEAD_BASE ].radius = 0.07; _bodyBall[ BODY_BALL_HEAD_BASE ].radius = BODY_BALL_RADIUS_HEAD_BASE;
_bodyBall[ BODY_BALL_LEFT_COLLAR ].radius = 0.04; _bodyBall[ BODY_BALL_LEFT_COLLAR ].radius = BODY_BALL_RADIUS_LEFT_COLLAR;
_bodyBall[ BODY_BALL_LEFT_SHOULDER ].radius = 0.03; _bodyBall[ BODY_BALL_LEFT_SHOULDER ].radius = BODY_BALL_RADIUS_LEFT_SHOULDER;
_bodyBall[ BODY_BALL_LEFT_ELBOW ].radius = 0.02; _bodyBall[ BODY_BALL_LEFT_ELBOW ].radius = BODY_BALL_RADIUS_LEFT_ELBOW;
_bodyBall[ BODY_BALL_LEFT_WRIST ].radius = 0.02; _bodyBall[ BODY_BALL_LEFT_WRIST ].radius = BODY_BALL_RADIUS_LEFT_WRIST;
_bodyBall[ BODY_BALL_LEFT_FINGERTIPS ].radius = 0.01; _bodyBall[ BODY_BALL_LEFT_FINGERTIPS ].radius = BODY_BALL_RADIUS_LEFT_FINGERTIPS;
_bodyBall[ BODY_BALL_RIGHT_COLLAR ].radius = 0.04; _bodyBall[ BODY_BALL_RIGHT_COLLAR ].radius = BODY_BALL_RADIUS_RIGHT_COLLAR;
_bodyBall[ BODY_BALL_RIGHT_SHOULDER ].radius = 0.03; _bodyBall[ BODY_BALL_RIGHT_SHOULDER ].radius = BODY_BALL_RADIUS_RIGHT_SHOULDER;
_bodyBall[ BODY_BALL_RIGHT_ELBOW ].radius = 0.02; _bodyBall[ BODY_BALL_RIGHT_ELBOW ].radius = BODY_BALL_RADIUS_RIGHT_ELBOW;
_bodyBall[ BODY_BALL_RIGHT_WRIST ].radius = 0.02; _bodyBall[ BODY_BALL_RIGHT_WRIST ].radius = BODY_BALL_RADIUS_RIGHT_WRIST;
_bodyBall[ BODY_BALL_RIGHT_FINGERTIPS ].radius = 0.01; _bodyBall[ BODY_BALL_RIGHT_FINGERTIPS ].radius = BODY_BALL_RADIUS_RIGHT_FINGERTIPS;
_bodyBall[ BODY_BALL_LEFT_HIP ].radius = 0.04; _bodyBall[ BODY_BALL_LEFT_HIP ].radius = BODY_BALL_RADIUS_LEFT_HIP;
//_bodyBall[ BODY_BALL_LEFT_MID_THIGH ].radius = 0.03; //_bodyBall[ BODY_BALL_LEFT_MID_THIGH ].radius = BODY_BALL_RADIUS_LEFT_MID_THIGH;
_bodyBall[ BODY_BALL_LEFT_KNEE ].radius = 0.025; _bodyBall[ BODY_BALL_LEFT_KNEE ].radius = BODY_BALL_RADIUS_LEFT_KNEE;
_bodyBall[ BODY_BALL_LEFT_HEEL ].radius = 0.025; _bodyBall[ BODY_BALL_LEFT_HEEL ].radius = BODY_BALL_RADIUS_LEFT_HEEL;
_bodyBall[ BODY_BALL_LEFT_TOES ].radius = 0.025; _bodyBall[ BODY_BALL_LEFT_TOES ].radius = BODY_BALL_RADIUS_LEFT_TOES;
_bodyBall[ BODY_BALL_RIGHT_HIP ].radius = 0.04; _bodyBall[ BODY_BALL_RIGHT_HIP ].radius = BODY_BALL_RADIUS_RIGHT_HIP;
_bodyBall[ BODY_BALL_RIGHT_KNEE ].radius = 0.025; _bodyBall[ BODY_BALL_RIGHT_KNEE ].radius = BODY_BALL_RADIUS_RIGHT_KNEE;
_bodyBall[ BODY_BALL_RIGHT_HEEL ].radius = 0.025; _bodyBall[ BODY_BALL_RIGHT_HEEL ].radius = BODY_BALL_RADIUS_RIGHT_HEEL;
_bodyBall[ BODY_BALL_RIGHT_TOES ].radius = 0.025; _bodyBall[ BODY_BALL_RIGHT_TOES ].radius = BODY_BALL_RADIUS_RIGHT_TOES;
// specify the parent joint for each ball // specify the parent joint for each ball
@ -331,7 +332,7 @@ void Avatar::updateFromGyrosAndOrWebcam(bool gyroLook,
_head.setCameraFollowsHead(gyroLook); _head.setCameraFollowsHead(gyroLook);
// Update torso lean distance based on accelerometer data // Update torso lean distance based on accelerometer data
const float TORSO_LENGTH = 0.5f; const float TORSO_LENGTH = _scale * 0.5f;
const float MAX_LEAN = 45.0f; const float MAX_LEAN = 45.0f;
_head.setLeanSideways(glm::clamp(glm::degrees(atanf(estimatedPosition.x * _leanScale / TORSO_LENGTH)), _head.setLeanSideways(glm::clamp(glm::degrees(atanf(estimatedPosition.x * _leanScale / TORSO_LENGTH)),
-MAX_LEAN, MAX_LEAN)); -MAX_LEAN, MAX_LEAN));
@ -378,18 +379,18 @@ void Avatar::updateThrust(float deltaTime, Transmitter * transmitter) {
const float THRUST_JUMP = 120.f; const float THRUST_JUMP = 120.f;
// Add Thrusts from keyboard // Add Thrusts from keyboard
if (_driveKeys[FWD ]) {_thrust += THRUST_MAG_FWD * deltaTime * front;} if (_driveKeys[FWD ]) {_thrust += _scale * THRUST_MAG_FWD * deltaTime * front;}
if (_driveKeys[BACK ]) {_thrust -= THRUST_MAG_BACK * deltaTime * front;} if (_driveKeys[BACK ]) {_thrust -= _scale * THRUST_MAG_BACK * deltaTime * front;}
if (_driveKeys[RIGHT ]) {_thrust += THRUST_MAG_LATERAL * deltaTime * right;} if (_driveKeys[RIGHT ]) {_thrust += _scale * THRUST_MAG_LATERAL * deltaTime * right;}
if (_driveKeys[LEFT ]) {_thrust -= THRUST_MAG_LATERAL * deltaTime * right;} if (_driveKeys[LEFT ]) {_thrust -= _scale * THRUST_MAG_LATERAL * deltaTime * right;}
if (_driveKeys[UP ]) {_thrust += THRUST_MAG_UP * deltaTime * up;} if (_driveKeys[UP ]) {_thrust += _scale * THRUST_MAG_UP * deltaTime * up;}
if (_driveKeys[DOWN ]) {_thrust -= THRUST_MAG_DOWN * deltaTime * up;} if (_driveKeys[DOWN ]) {_thrust -= _scale * THRUST_MAG_DOWN * deltaTime * up;}
if (_driveKeys[ROT_RIGHT]) {_bodyYawDelta -= YAW_MAG * deltaTime;} if (_driveKeys[ROT_RIGHT]) {_bodyYawDelta -= YAW_MAG * deltaTime;}
if (_driveKeys[ROT_LEFT ]) {_bodyYawDelta += YAW_MAG * deltaTime;} if (_driveKeys[ROT_LEFT ]) {_bodyYawDelta += YAW_MAG * deltaTime;}
// Add one time jumping force if requested // Add one time jumping force if requested
if (_shouldJump) { if (_shouldJump) {
_thrust += THRUST_JUMP * up; _thrust += _scale * THRUST_JUMP * up;
_shouldJump = false; _shouldJump = false;
} }
@ -424,8 +425,7 @@ void Avatar::updateThrust(float deltaTime, Transmitter * transmitter) {
} }
// Update speed brake status // Update speed brake status
const float MIN_SPEED_BRAKE_VELOCITY = _scale * 0.4f;
const float MIN_SPEED_BRAKE_VELOCITY = 0.4f;
if ((glm::length(_thrust) == 0.0f) && _isThrustOn && (glm::length(_velocity) > MIN_SPEED_BRAKE_VELOCITY)) { if ((glm::length(_thrust) == 0.0f) && _isThrustOn && (glm::length(_velocity) > MIN_SPEED_BRAKE_VELOCITY)) {
_speedBrakes = true; _speedBrakes = true;
} }
@ -434,7 +434,6 @@ void Avatar::updateThrust(float deltaTime, Transmitter * transmitter) {
_speedBrakes = false; _speedBrakes = false;
} }
_isThrustOn = (glm::length(_thrust) > EPSILON); _isThrustOn = (glm::length(_thrust) > EPSILON);
} }
void Avatar::simulate(float deltaTime, Transmitter* transmitter) { void Avatar::simulate(float deltaTime, Transmitter* transmitter) {
@ -443,6 +442,11 @@ void Avatar::simulate(float deltaTime, Transmitter* transmitter) {
glm::vec3 front = orientation * IDENTITY_FRONT; glm::vec3 front = orientation * IDENTITY_FRONT;
glm::vec3 right = orientation * IDENTITY_RIGHT; glm::vec3 right = orientation * IDENTITY_RIGHT;
//
if (!isMyAvatar() && _scale != _newScale) {
setScale(_newScale);
}
// Update movement timers // Update movement timers
if (isMyAvatar()) { if (isMyAvatar()) {
_elapsedTimeSinceCollision += deltaTime; _elapsedTimeSinceCollision += deltaTime;
@ -528,16 +532,17 @@ void Avatar::simulate(float deltaTime, Transmitter* transmitter) {
//update the movement of the hand and process handshaking with other avatars... //update the movement of the hand and process handshaking with other avatars...
updateHandMovementAndTouching(deltaTime, enableHandMovement); updateHandMovementAndTouching(deltaTime, enableHandMovement);
_avatarTouch.simulate(deltaTime); _avatarTouch.simulate(deltaTime);
if (isMyAvatar()) { if (isMyAvatar()) {
// apply gravity // apply gravity
if (USING_AVATAR_GRAVITY) { if (USING_AVATAR_GRAVITY) {
// For gravity, always move the avatar by the amount driven by gravity, so that the collision // For gravity, always move the avatar by the amount driven by gravity, so that the collision
// routines will detect it and collide every frame when pulled by gravity to a surface // routines will detect it and collide every frame when pulled by gravity to a surface
// //
_velocity += _gravity * (GRAVITY_EARTH * deltaTime);
_position += _gravity * (GRAVITY_EARTH * deltaTime) * deltaTime; _velocity += _scale * _gravity * (GRAVITY_EARTH * deltaTime);
_position += _scale * _gravity * (GRAVITY_EARTH * deltaTime) * deltaTime;
} }
updateCollisionWithEnvironment(); updateCollisionWithEnvironment();
@ -571,11 +576,11 @@ void Avatar::simulate(float deltaTime, Transmitter* transmitter) {
_bodyRollDelta *= bodySpinMomentum; _bodyRollDelta *= bodySpinMomentum;
const float MAX_STATIC_FRICTION_VELOCITY = 0.5f; const float MAX_STATIC_FRICTION_VELOCITY = 0.5f;
const float STATIC_FRICTION_STRENGTH = 20.f; const float STATIC_FRICTION_STRENGTH = _scale * 20.f;
applyStaticFriction(deltaTime, _velocity, MAX_STATIC_FRICTION_VELOCITY, STATIC_FRICTION_STRENGTH); applyStaticFriction(deltaTime, _velocity, MAX_STATIC_FRICTION_VELOCITY, STATIC_FRICTION_STRENGTH);
const float LINEAR_DAMPING_STRENGTH = 1.0f; const float LINEAR_DAMPING_STRENGTH = 1.0f;
const float SPEED_BRAKE_POWER = 10.0f; const float SPEED_BRAKE_POWER = _scale * 10.0f;
const float SQUARED_DAMPING_STRENGTH = 0.2f; const float SQUARED_DAMPING_STRENGTH = 0.2f;
if (_speedBrakes) { if (_speedBrakes) {
applyDamping(deltaTime, _velocity, LINEAR_DAMPING_STRENGTH * SPEED_BRAKE_POWER, SQUARED_DAMPING_STRENGTH * SPEED_BRAKE_POWER); applyDamping(deltaTime, _velocity, LINEAR_DAMPING_STRENGTH * SPEED_BRAKE_POWER, SQUARED_DAMPING_STRENGTH * SPEED_BRAKE_POWER);
@ -592,7 +597,7 @@ void Avatar::simulate(float deltaTime, Transmitter* transmitter) {
BODY_ROLL_WHILE_TURNING * deltaTime * _speed * _bodyYawDelta))); BODY_ROLL_WHILE_TURNING * deltaTime * _speed * _bodyYawDelta)));
// these forces keep the body upright... // these forces keep the body upright...
const float BODY_UPRIGHT_FORCE = 10.0; const float BODY_UPRIGHT_FORCE = _scale * 10.0;
float tiltDecay = BODY_UPRIGHT_FORCE * deltaTime; float tiltDecay = BODY_UPRIGHT_FORCE * deltaTime;
if (tiltDecay > 1.0f) {tiltDecay = 1.0f;} if (tiltDecay > 1.0f) {tiltDecay = 1.0f;}
@ -662,7 +667,7 @@ void Avatar::simulate(float deltaTime, Transmitter* transmitter) {
_head.setBodyRotation (glm::vec3(_bodyPitch, _bodyYaw, _bodyRoll)); _head.setBodyRotation (glm::vec3(_bodyPitch, _bodyYaw, _bodyRoll));
_head.setPosition(_bodyBall[ BODY_BALL_HEAD_BASE ].position); _head.setPosition(_bodyBall[ BODY_BALL_HEAD_BASE ].position);
_head.setScale (_bodyBall[ BODY_BALL_HEAD_BASE ].radius); _head.setScale(_scale);
_head.setSkinColor(glm::vec3(SKIN_COLOR[0], SKIN_COLOR[1], SKIN_COLOR[2])); _head.setSkinColor(glm::vec3(SKIN_COLOR[0], SKIN_COLOR[1], SKIN_COLOR[2]));
_head.simulate(deltaTime, isMyAvatar()); _head.simulate(deltaTime, isMyAvatar());
@ -748,7 +753,7 @@ void Avatar::updateHandMovementAndTouching(float deltaTime, bool enableHandMovem
if (distance < closestDistance) { if (distance < closestDistance) {
closestDistance = distance; closestDistance = distance;
if (distance < PERIPERSONAL_RADIUS) { if (distance < _scale * PERIPERSONAL_RADIUS) {
_interactingOther = otherAvatar; _interactingOther = otherAvatar;
} }
} }
@ -1017,7 +1022,7 @@ void Avatar::render(bool lookingInMirror, bool renderAvatarBalls) {
} }
// render a simple round on the ground projected down from the avatar's position // render a simple round on the ground projected down from the avatar's position
renderDiskShadow(_position, glm::vec3(0.0f, 1.0f, 0.0f), 0.1f, 0.2f); renderDiskShadow(_position, glm::vec3(0.0f, 1.0f, 0.0f), _scale * 0.1f, 0.2f);
// render body // render body
renderBody(lookingInMirror, renderAvatarBalls); renderBody(lookingInMirror, renderAvatarBalls);
@ -1091,7 +1096,7 @@ void Avatar::resetBodyBalls() {
void Avatar::updateBodyBalls(float deltaTime) { void Avatar::updateBodyBalls(float deltaTime) {
// Check for a large repositioning, and re-initialize balls if this has happened // Check for a large repositioning, and re-initialize balls if this has happened
const float BEYOND_BODY_SPRING_RANGE = 2.f; const float BEYOND_BODY_SPRING_RANGE = _scale * 2.f;
if (glm::length(_position - _bodyBall[BODY_BALL_PELVIS].position) > BEYOND_BODY_SPRING_RANGE) { if (glm::length(_position - _bodyBall[BODY_BALL_PELVIS].position) > BEYOND_BODY_SPRING_RANGE) {
resetBodyBalls(); resetBodyBalls();
} }
@ -1222,8 +1227,8 @@ glm::quat Avatar::computeRotationFromBodyToWorldUp(float proportion) const {
} }
float Avatar::getBallRenderAlpha(int ball, bool lookingInMirror) const { float Avatar::getBallRenderAlpha(int ball, bool lookingInMirror) const {
const float RENDER_OPAQUE_OUTSIDE = 0.25f; // render opaque if greater than this distance const float RENDER_OPAQUE_OUTSIDE = _scale * 0.25f; // render opaque if greater than this distance
const float DO_NOT_RENDER_INSIDE = 0.25f; // do not render if less than this distance const float DO_NOT_RENDER_INSIDE = _scale * 0.25f; // do not render if less than this distance
float distanceToCamera = glm::length(Application::getInstance()->getCamera()->getPosition() - _bodyBall[ball].position); float distanceToCamera = glm::length(Application::getInstance()->getCamera()->getPosition() - _bodyBall[ball].position);
return (lookingInMirror || !isMyAvatar()) ? 1.0f : glm::clamp( return (lookingInMirror || !isMyAvatar()) ? 1.0f : glm::clamp(
(distanceToCamera - DO_NOT_RENDER_INSIDE) / (RENDER_OPAQUE_OUTSIDE - DO_NOT_RENDER_INSIDE), 0.f, 1.f); (distanceToCamera - DO_NOT_RENDER_INSIDE) / (RENDER_OPAQUE_OUTSIDE - DO_NOT_RENDER_INSIDE), 0.f, 1.f);
@ -1390,3 +1395,47 @@ void Avatar::renderJointConnectingCone(glm::vec3 position1, glm::vec3 position2,
glEnd(); glEnd();
} }
void Avatar::setScale(const float scale) {
_scale = scale;
_newScale = _scale;
_skeleton.setScale(_scale);
// specify the new radius of each ball
_bodyBall[ BODY_BALL_PELVIS ].radius = _scale * BODY_BALL_RADIUS_PELVIS;
_bodyBall[ BODY_BALL_TORSO ].radius = _scale * BODY_BALL_RADIUS_TORSO;
_bodyBall[ BODY_BALL_CHEST ].radius = _scale * BODY_BALL_RADIUS_CHEST;
_bodyBall[ BODY_BALL_NECK_BASE ].radius = _scale * BODY_BALL_RADIUS_NECK_BASE;
_bodyBall[ BODY_BALL_HEAD_BASE ].radius = _scale * BODY_BALL_RADIUS_HEAD_BASE;
_bodyBall[ BODY_BALL_LEFT_COLLAR ].radius = _scale * BODY_BALL_RADIUS_LEFT_COLLAR;
_bodyBall[ BODY_BALL_LEFT_SHOULDER ].radius = _scale * BODY_BALL_RADIUS_LEFT_SHOULDER;
_bodyBall[ BODY_BALL_LEFT_ELBOW ].radius = _scale * BODY_BALL_RADIUS_LEFT_ELBOW;
_bodyBall[ BODY_BALL_LEFT_WRIST ].radius = _scale * BODY_BALL_RADIUS_LEFT_WRIST;
_bodyBall[ BODY_BALL_LEFT_FINGERTIPS ].radius = _scale * BODY_BALL_RADIUS_LEFT_FINGERTIPS;
_bodyBall[ BODY_BALL_RIGHT_COLLAR ].radius = _scale * BODY_BALL_RADIUS_RIGHT_COLLAR;
_bodyBall[ BODY_BALL_RIGHT_SHOULDER ].radius = _scale * BODY_BALL_RADIUS_RIGHT_SHOULDER;
_bodyBall[ BODY_BALL_RIGHT_ELBOW ].radius = _scale * BODY_BALL_RADIUS_RIGHT_ELBOW;
_bodyBall[ BODY_BALL_RIGHT_WRIST ].radius = _scale * BODY_BALL_RADIUS_RIGHT_WRIST;
_bodyBall[ BODY_BALL_RIGHT_FINGERTIPS ].radius = _scale * BODY_BALL_RADIUS_RIGHT_FINGERTIPS;
_bodyBall[ BODY_BALL_LEFT_HIP ].radius = _scale * BODY_BALL_RADIUS_LEFT_HIP;
//_bodyBall[ BODY_BALL_LEFT_MID_THIGH ].radius = _scale * BODY_BALL_RADIUS_LEFT_MID_THIGH;
_bodyBall[ BODY_BALL_LEFT_KNEE ].radius = _scale * BODY_BALL_RADIUS_LEFT_KNEE;
_bodyBall[ BODY_BALL_LEFT_HEEL ].radius = _scale * BODY_BALL_RADIUS_LEFT_HEEL;
_bodyBall[ BODY_BALL_LEFT_TOES ].radius = _scale * BODY_BALL_RADIUS_LEFT_TOES;
_bodyBall[ BODY_BALL_RIGHT_HIP ].radius = _scale * BODY_BALL_RADIUS_RIGHT_HIP;
_bodyBall[ BODY_BALL_RIGHT_KNEE ].radius = _scale * BODY_BALL_RADIUS_RIGHT_KNEE;
_bodyBall[ BODY_BALL_RIGHT_HEEL ].radius = _scale * BODY_BALL_RADIUS_RIGHT_HEEL;
_bodyBall[ BODY_BALL_RIGHT_TOES ].radius = _scale * BODY_BALL_RADIUS_RIGHT_TOES;
_height = _skeleton.getHeight() + _bodyBall[ BODY_BALL_LEFT_HEEL ].radius + _bodyBall[ BODY_BALL_HEAD_BASE ].radius;
_maxArmLength = _skeleton.getArmLength();
_pelvisStandingHeight = _skeleton.getPelvisStandingHeight() + _bodyBall[ BODY_BALL_LEFT_HEEL ].radius;
_pelvisFloatingHeight = _skeleton.getPelvisFloatingHeight() + _bodyBall[ BODY_BALL_LEFT_HEEL ].radius;
_pelvisToHeadLength = _skeleton.getPelvisToHeadLength();
_avatarTouch.setReachableRadius(_scale * PERIPERSONAL_RADIUS);
}

View file

@ -23,6 +23,30 @@
#include "Skeleton.h" #include "Skeleton.h"
#include "Transmitter.h" #include "Transmitter.h"
const float BODY_BALL_RADIUS_PELVIS = 0.07;
const float BODY_BALL_RADIUS_TORSO = 0.065;
const float BODY_BALL_RADIUS_CHEST = 0.08;
const float BODY_BALL_RADIUS_NECK_BASE = 0.03;
const float BODY_BALL_RADIUS_HEAD_BASE = 0.07;
const float BODY_BALL_RADIUS_LEFT_COLLAR = 0.04;
const float BODY_BALL_RADIUS_LEFT_SHOULDER = 0.03;
const float BODY_BALL_RADIUS_LEFT_ELBOW = 0.02;
const float BODY_BALL_RADIUS_LEFT_WRIST = 0.02;
const float BODY_BALL_RADIUS_LEFT_FINGERTIPS = 0.01;
const float BODY_BALL_RADIUS_RIGHT_COLLAR = 0.04;
const float BODY_BALL_RADIUS_RIGHT_SHOULDER = 0.03;
const float BODY_BALL_RADIUS_RIGHT_ELBOW = 0.02;
const float BODY_BALL_RADIUS_RIGHT_WRIST = 0.02;
const float BODY_BALL_RADIUS_RIGHT_FINGERTIPS = 0.01;
const float BODY_BALL_RADIUS_LEFT_HIP = 0.04;
const float BODY_BALL_RADIUS_LEFT_MID_THIGH = 0.03;
const float BODY_BALL_RADIUS_LEFT_KNEE = 0.025;
const float BODY_BALL_RADIUS_LEFT_HEEL = 0.025;
const float BODY_BALL_RADIUS_LEFT_TOES = 0.025;
const float BODY_BALL_RADIUS_RIGHT_HIP = 0.04;
const float BODY_BALL_RADIUS_RIGHT_KNEE = 0.025;
const float BODY_BALL_RADIUS_RIGHT_HEEL = 0.025;
const float BODY_BALL_RADIUS_RIGHT_TOES = 0.025;
enum AvatarBodyBallID enum AvatarBodyBallID
{ {
@ -105,6 +129,7 @@ public:
void setGravity (glm::vec3 gravity); void setGravity (glm::vec3 gravity);
void setMouseRay (const glm::vec3 &origin, const glm::vec3 &direction); void setMouseRay (const glm::vec3 &origin, const glm::vec3 &direction);
void setOrientation (const glm::quat& orientation); void setOrientation (const glm::quat& orientation);
void setScale (const float scale);
//getters //getters
bool isInitialized () const { return _initialized;} bool isInitialized () const { return _initialized;}
@ -118,6 +143,7 @@ public:
glm::vec3 getBodyRightDirection () const { return getOrientation() * IDENTITY_RIGHT; } glm::vec3 getBodyRightDirection () const { return getOrientation() * IDENTITY_RIGHT; }
glm::vec3 getBodyUpDirection () const { return getOrientation() * IDENTITY_UP; } glm::vec3 getBodyUpDirection () const { return getOrientation() * IDENTITY_UP; }
glm::vec3 getBodyFrontDirection () const { return getOrientation() * IDENTITY_FRONT; } glm::vec3 getBodyFrontDirection () const { return getOrientation() * IDENTITY_FRONT; }
float getScale () const { return _scale;}
const glm::vec3& getVelocity () const { return _velocity;} const glm::vec3& getVelocity () const { return _velocity;}
float getSpeed () const { return _speed;} float getSpeed () const { return _speed;}
float getHeight () const { return _height;} float getHeight () const { return _height;}
@ -200,6 +226,7 @@ private:
float _pelvisStandingHeight; float _pelvisStandingHeight;
float _pelvisFloatingHeight; float _pelvisFloatingHeight;
float _pelvisToHeadLength; float _pelvisToHeadLength;
float _scale;
float _height; float _height;
Balls* _balls; Balls* _balls;
AvatarTouch _avatarTouch; AvatarTouch _avatarTouch;

View file

@ -50,6 +50,7 @@ Camera::Camera() {
_targetPosition = glm::vec3(0.0f, 0.0f, 0.0f); _targetPosition = glm::vec3(0.0f, 0.0f, 0.0f);
_position = glm::vec3(0.0f, 0.0f, 0.0f); _position = glm::vec3(0.0f, 0.0f, 0.0f);
_idealPosition = glm::vec3(0.0f, 0.0f, 0.0f); _idealPosition = glm::vec3(0.0f, 0.0f, 0.0f);
_scale = 1.0f;
} }
void Camera::update(float deltaTime) { void Camera::update(float deltaTime) {
@ -91,14 +92,14 @@ void Camera::updateFollowMode(float deltaTime) {
if (_needsToInitialize || (_tightness == 0.0f)) { if (_needsToInitialize || (_tightness == 0.0f)) {
_rotation = _targetRotation; _rotation = _targetRotation;
_idealPosition = _targetPosition + _rotation * glm::vec3(0.0f, _upShift, _distance); _idealPosition = _targetPosition + _scale * (_rotation * glm::vec3(0.0f, _upShift, _distance));
_position = _idealPosition; _position = _idealPosition;
_needsToInitialize = false; _needsToInitialize = false;
} else { } else {
// pull rotation towards ideal // pull rotation towards ideal
_rotation = safeMix(_rotation, _targetRotation, t); _rotation = safeMix(_rotation, _targetRotation, t);
_idealPosition = _targetPosition + _rotation * glm::vec3(0.0f, _upShift, _distance); _idealPosition = _targetPosition + _scale * (_rotation * glm::vec3(0.0f, _upShift, _distance));
_position += (_idealPosition - _position) * t; _position += (_idealPosition - _position) * t;
} }
} }
@ -174,6 +175,12 @@ void Camera::setEyeOffsetOrientation (const glm::quat& o) {
_frustumNeedsReshape = true; _frustumNeedsReshape = true;
} }
void Camera::setScale(float s) {
_scale = s;
_needsToInitialize = true;
_frustumNeedsReshape = true;
}
void Camera::initialize() { void Camera::initialize() {
_needsToInitialize = true; _needsToInitialize = true;
_modeShift = 0.0; _modeShift = 0.0;

View file

@ -46,6 +46,7 @@ public:
void setFarClip ( float f ); void setFarClip ( float f );
void setEyeOffsetPosition ( const glm::vec3& p ); void setEyeOffsetPosition ( const glm::vec3& p );
void setEyeOffsetOrientation( const glm::quat& o ); void setEyeOffsetOrientation( const glm::quat& o );
void setScale ( const float s );
const glm::vec3& getTargetPosition () { return _targetPosition; } const glm::vec3& getTargetPosition () { return _targetPosition; }
const glm::vec3& getPosition () { return _position; } const glm::vec3& getPosition () { return _position; }
@ -54,10 +55,11 @@ public:
CameraMode getMode () { return _mode; } CameraMode getMode () { return _mode; }
float getFieldOfView () { return _fieldOfView; } float getFieldOfView () { return _fieldOfView; }
float getAspectRatio () { return _aspectRatio; } float getAspectRatio () { return _aspectRatio; }
float getNearClip () { return _nearClip; } float getNearClip () { return _scale * _nearClip; }
float getFarClip () { return _farClip; } float getFarClip () { return _scale * _farClip; }
const glm::vec3& getEyeOffsetPosition () { return _eyeOffsetPosition; } const glm::vec3& getEyeOffsetPosition () { return _eyeOffsetPosition; }
const glm::quat& getEyeOffsetOrientation () { return _eyeOffsetOrientation; } const glm::quat& getEyeOffsetOrientation () { return _eyeOffsetOrientation; }
float getScale () { return _scale; }
bool getFrustumNeedsReshape(); // call to find out if the view frustum needs to be reshaped bool getFrustumNeedsReshape(); // call to find out if the view frustum needs to be reshaped
void setFrustumWasReshaped(); // call this after reshaping the view frustum. void setFrustumWasReshaped(); // call this after reshaping the view frustum.
@ -90,6 +92,7 @@ private:
float _modeShift; float _modeShift;
float _linearModeShift; float _linearModeShift;
float _modeShiftRate; float _modeShiftRate;
float _scale;
void updateFollowMode( float deltaTime ); void updateFollowMode( float deltaTime );
}; };

View file

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

View file

@ -128,9 +128,9 @@ void Head::resetHairPhysics() {
glm::vec3 up = getUpDirection(); glm::vec3 up = getUpDirection();
for (int t = 0; t < NUM_HAIR_TUFTS; t ++) { for (int t = 0; t < NUM_HAIR_TUFTS; t ++) {
_hairTuft[t].length = HAIR_LENGTH; _hairTuft[t].length = _scale * HAIR_LENGTH;
_hairTuft[t].thickness = HAIR_THICKNESS; _hairTuft[t].thickness = _scale * HAIR_THICKNESS;
_hairTuft[t].basePosition = _position + up * _scale * 0.9f; _hairTuft[t].basePosition = _position + up * _scale * BODY_BALL_RADIUS_HEAD_BASE * 0.9f;
_hairTuft[t].midPosition = _hairTuft[t].basePosition + up * _hairTuft[t].length * ONE_HALF; _hairTuft[t].midPosition = _hairTuft[t].basePosition + up * _hairTuft[t].length * ONE_HALF;
_hairTuft[t].endPosition = _hairTuft[t].midPosition + up * _hairTuft[t].length * ONE_HALF; _hairTuft[t].endPosition = _hairTuft[t].midPosition + up * _hairTuft[t].length * ONE_HALF;
_hairTuft[t].midVelocity = glm::vec3(0.0f, 0.0f, 0.0f); _hairTuft[t].midVelocity = glm::vec3(0.0f, 0.0f, 0.0f);
@ -261,13 +261,13 @@ void Head::calculateGeometry() {
//calculate the eye positions //calculate the eye positions
_leftEyePosition = _position _leftEyePosition = _position
- right * _scale * EYE_RIGHT_OFFSET - right * _scale * BODY_BALL_RADIUS_HEAD_BASE * EYE_RIGHT_OFFSET
+ up * _scale * EYE_UP_OFFSET + up * _scale * BODY_BALL_RADIUS_HEAD_BASE * EYE_UP_OFFSET
+ front * _scale * EYE_FRONT_OFFSET; + front * _scale * BODY_BALL_RADIUS_HEAD_BASE * EYE_FRONT_OFFSET;
_rightEyePosition = _position _rightEyePosition = _position
+ right * _scale * EYE_RIGHT_OFFSET + right * _scale * BODY_BALL_RADIUS_HEAD_BASE * EYE_RIGHT_OFFSET
+ up * _scale * EYE_UP_OFFSET + up * _scale * BODY_BALL_RADIUS_HEAD_BASE * EYE_UP_OFFSET
+ front * _scale * EYE_FRONT_OFFSET; + front * _scale * BODY_BALL_RADIUS_HEAD_BASE * EYE_FRONT_OFFSET;
_eyeLevelPosition = _position + up * _scale * EYE_UP_OFFSET; _eyeLevelPosition = _position + up * _scale * EYE_UP_OFFSET;
@ -276,12 +276,12 @@ void Head::calculateGeometry() {
_rightEyeBrowPosition = _rightEyePosition; _rightEyeBrowPosition = _rightEyePosition;
//calculate the ear positions //calculate the ear positions
_leftEarPosition = _position - right * _scale * EAR_RIGHT_OFFSET; _leftEarPosition = _position - right * _scale * BODY_BALL_RADIUS_HEAD_BASE * EAR_RIGHT_OFFSET;
_rightEarPosition = _position + right * _scale * EAR_RIGHT_OFFSET; _rightEarPosition = _position + right * _scale * BODY_BALL_RADIUS_HEAD_BASE * EAR_RIGHT_OFFSET;
//calculate the mouth position //calculate the mouth position
_mouthPosition = _position + up * _scale * MOUTH_UP_OFFSET _mouthPosition = _position + up * _scale * BODY_BALL_RADIUS_HEAD_BASE * MOUTH_UP_OFFSET
+ front * _scale; + front * _scale * BODY_BALL_RADIUS_HEAD_BASE;
} }
@ -296,16 +296,25 @@ void Head::render(float alpha) {
renderMohawk(); renderMohawk();
renderHeadSphere(); renderHeadSphere();
renderEyeBalls(); renderEyeBalls();
renderEars(); renderEars();
renderMouth(); renderMouth();
renderEyeBrows(); renderEyeBrows();
if (_renderLookatVectors) { if (_renderLookatVectors) {
renderLookatVectors(_leftEyePosition, _rightEyePosition, _lookAtPosition); renderLookatVectors(_leftEyePosition, _rightEyePosition, _lookAtPosition);
} }
} }
void Head::setScale (float scale) {
_scale = scale;
delete[] _mohawkTriangleFan;
delete[] _mohawkColors;
createMohawk();
resetHairPhysics();
}
void Head::createMohawk() { void Head::createMohawk() {
uint16_t nodeId = 0; uint16_t nodeId = 0;
@ -318,7 +327,7 @@ void Head::createMohawk() {
} }
} }
srand(nodeId); srand(nodeId);
float height = 0.08f + randFloat() * 0.05f; float height = _scale * (0.08f + randFloat() * 0.05f);
float variance = 0.03 + randFloat() * 0.03f; float variance = 0.03 + randFloat() * 0.03f;
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]; _mohawkTriangleFan = new glm::vec3[MOHAWK_TRIANGLES];
@ -326,7 +335,7 @@ void Head::createMohawk() {
_mohawkTriangleFan[0] = glm::vec3(0, 0, 0); _mohawkTriangleFan[0] = glm::vec3(0, 0, 0);
glm::vec3 basicColor(randFloat(), randFloat(), randFloat()); glm::vec3 basicColor(randFloat(), randFloat(), randFloat());
_mohawkColors[0] = basicColor; _mohawkColors[0] = basicColor;
for (int i = 1; i < MOHAWK_TRIANGLES; i++) { for (int i = 1; i < MOHAWK_TRIANGLES; i++) {
_mohawkTriangleFan[i] = glm::vec3((randFloat() - 0.5f) * variance, _mohawkTriangleFan[i] = glm::vec3((randFloat() - 0.5f) * variance,
height * cosf(i * RAD_PER_TRIANGLE - PIf / 2.f) height * cosf(i * RAD_PER_TRIANGLE - PIf / 2.f)
@ -404,7 +413,9 @@ glm::quat Head::getCameraOrientation () const {
void Head::renderHeadSphere() { void Head::renderHeadSphere() {
glPushMatrix(); glPushMatrix();
glTranslatef(_position.x, _position.y, _position.z); //translate to head position glTranslatef(_position.x, _position.y, _position.z); //translate to head position
glScalef(_scale, _scale, _scale); //scale to head size glScalef(_scale * BODY_BALL_RADIUS_HEAD_BASE,
_scale * BODY_BALL_RADIUS_HEAD_BASE,
_scale * BODY_BALL_RADIUS_HEAD_BASE); //scale to head size
glColor4f(_skinColor.x, _skinColor.y, _skinColor.z, _renderAlpha); glColor4f(_skinColor.x, _skinColor.y, _skinColor.z, _renderAlpha);
glutSolidSphere(1, 30, 30); glutSolidSphere(1, 30, 30);
glPopMatrix(); glPopMatrix();
@ -415,13 +426,13 @@ void Head::renderEars() {
glPushMatrix(); glPushMatrix();
glColor4f(_skinColor.x, _skinColor.y, _skinColor.z, _renderAlpha); glColor4f(_skinColor.x, _skinColor.y, _skinColor.z, _renderAlpha);
glTranslatef(_leftEarPosition.x, _leftEarPosition.y, _leftEarPosition.z); glTranslatef(_leftEarPosition.x, _leftEarPosition.y, _leftEarPosition.z);
glutSolidSphere(0.02, 30, 30); glutSolidSphere(_scale * 0.02, 30, 30);
glPopMatrix(); glPopMatrix();
glPushMatrix(); glPushMatrix();
glColor4f(_skinColor.x, _skinColor.y, _skinColor.z, _renderAlpha); glColor4f(_skinColor.x, _skinColor.y, _skinColor.z, _renderAlpha);
glTranslatef(_rightEarPosition.x, _rightEarPosition.y, _rightEarPosition.z); glTranslatef(_rightEarPosition.x, _rightEarPosition.y, _rightEarPosition.z);
glutSolidSphere(0.02, 30, 30); glutSolidSphere(_scale * 0.02, 30, 30);
glPopMatrix(); glPopMatrix();
} }
@ -434,9 +445,9 @@ void Head::renderMouth() {
glm::vec3 up = orientation * IDENTITY_UP; glm::vec3 up = orientation * IDENTITY_UP;
glm::vec3 front = orientation * IDENTITY_FRONT; glm::vec3 front = orientation * IDENTITY_FRONT;
glm::vec3 r = right * _scale * (0.30f + s * 0.0014f ); glm::vec3 r = right * _scale * BODY_BALL_RADIUS_HEAD_BASE * (0.30f + s * 0.0014f );
glm::vec3 u = up * _scale * (0.05f + s * 0.0040f ); glm::vec3 u = up * _scale * BODY_BALL_RADIUS_HEAD_BASE * (0.05f + s * 0.0040f );
glm::vec3 f = front * _scale * 0.09f; glm::vec3 f = front * _scale * BODY_BALL_RADIUS_HEAD_BASE * 0.09f;
glm::vec3 middle = _mouthPosition; glm::vec3 middle = _mouthPosition;
glm::vec3 leftCorner = _mouthPosition - r * 1.0f; glm::vec3 leftCorner = _mouthPosition - r * 1.0f;
@ -449,7 +460,7 @@ void Head::renderMouth() {
// constrain all mouth vertices to a sphere slightly larger than the head... // constrain all mouth vertices to a sphere slightly larger than the head...
const float MOUTH_OFFSET_OFF_FACE = 0.003f; const float MOUTH_OFFSET_OFF_FACE = 0.003f;
float constrainedRadius = _scale + MOUTH_OFFSET_OFF_FACE; float constrainedRadius = _scale * BODY_BALL_RADIUS_HEAD_BASE + MOUTH_OFFSET_OFF_FACE;
middle = _position + glm::normalize(middle - _position) * constrainedRadius; middle = _position + glm::normalize(middle - _position) * constrainedRadius;
leftCorner = _position + glm::normalize(leftCorner - _position) * constrainedRadius; leftCorner = _position + glm::normalize(leftCorner - _position) * constrainedRadius;
rightCorner = _position + glm::normalize(rightCorner - _position) * constrainedRadius; rightCorner = _position + glm::normalize(rightCorner - _position) * constrainedRadius;
@ -484,9 +495,9 @@ void Head::renderMouth() {
void Head::renderEyeBrows() { void Head::renderEyeBrows() {
float height = _scale * 0.3f + _browAudioLift; float height = _scale * BODY_BALL_RADIUS_HEAD_BASE * 0.3f + _browAudioLift;
float length = _scale * 0.2f; float length = _scale * BODY_BALL_RADIUS_HEAD_BASE * 0.2f;
float width = _scale * 0.07f; float width = _scale * BODY_BALL_RADIUS_HEAD_BASE * 0.07f;
glColor3f(0.3f, 0.25f, 0.2f); glColor3f(0.3f, 0.25f, 0.2f);
@ -505,7 +516,7 @@ void Head::renderEyeBrows() {
glm::vec3 r = right * length; glm::vec3 r = right * length;
glm::vec3 u = up * height; glm::vec3 u = up * height;
glm::vec3 t = up * (height + width); glm::vec3 t = up * (height + width);
glm::vec3 f = front * _scale * -0.1f; glm::vec3 f = front * _scale * BODY_BALL_RADIUS_HEAD_BASE * -0.1f;
for (int i = 0; i < 2; i++) { for (int i = 0; i < 2; i++) {
@ -553,14 +564,14 @@ void Head::renderEyeBalls() {
glPushMatrix(); glPushMatrix();
glColor3fv(EYEBALL_COLOR); glColor3fv(EYEBALL_COLOR);
glTranslatef(_leftEyePosition.x, _leftEyePosition.y, _leftEyePosition.z); glTranslatef(_leftEyePosition.x, _leftEyePosition.y, _leftEyePosition.z);
glutSolidSphere(EYEBALL_RADIUS, 30, 30); glutSolidSphere(_scale * EYEBALL_RADIUS, 30, 30);
glPopMatrix(); glPopMatrix();
//render white ball of right eyeball //render white ball of right eyeball
glPushMatrix(); glPushMatrix();
glColor3fv(EYEBALL_COLOR); glColor3fv(EYEBALL_COLOR);
glTranslatef(_rightEyePosition.x, _rightEyePosition.y, _rightEyePosition.z); glTranslatef(_rightEyePosition.x, _rightEyePosition.y, _rightEyePosition.z);
glutSolidSphere(EYEBALL_RADIUS, 30, 30); glutSolidSphere(_scale * EYEBALL_RADIUS, 30, 30);
glPopMatrix(); glPopMatrix();
_irisProgram->bind(); _irisProgram->bind();
@ -580,13 +591,15 @@ void Head::renderEyeBalls() {
glm::vec3 rotationAxis = glm::axis(rotation); glm::vec3 rotationAxis = glm::axis(rotation);
glRotatef(glm::angle(rotation), rotationAxis.x, rotationAxis.y, rotationAxis.z); glRotatef(glm::angle(rotation), rotationAxis.x, rotationAxis.y, rotationAxis.z);
glTranslatef(0.0f, 0.0f, -IRIS_PROTRUSION); glTranslatef(0.0f, 0.0f, -IRIS_PROTRUSION);
glScalef(IRIS_RADIUS * 2.0f, IRIS_RADIUS * 2.0f, IRIS_RADIUS); // flatten the iris glScalef(_scale * IRIS_RADIUS * 2.0f,
_scale * IRIS_RADIUS * 2.0f,
_scale * IRIS_RADIUS); // flatten the iris
// this ugliness is simply to invert the model transform and get the eye position in model space // this ugliness is simply to invert the model transform and get the eye position in model space
_irisProgram->setUniform(_eyePositionLocation, (glm::inverse(rotation) * _irisProgram->setUniform(_eyePositionLocation, (glm::inverse(rotation) *
(Application::getInstance()->getCamera()->getPosition() - _leftEyePosition) + (Application::getInstance()->getCamera()->getPosition() - _leftEyePosition) +
glm::vec3(0.0f, 0.0f, IRIS_PROTRUSION)) * glm::vec3(1.0f / (IRIS_RADIUS * 2.0f), glm::vec3(0.0f, 0.0f, _scale * IRIS_PROTRUSION)) * glm::vec3(1.0f / (_scale * IRIS_RADIUS * 2.0f),
1.0f / (IRIS_RADIUS * 2.0f), 1.0f / IRIS_RADIUS)); 1.0f / (_scale * IRIS_RADIUS * 2.0f), 1.0f / (_scale * IRIS_RADIUS)));
glutSolidSphere(0.5f, 15, 15); glutSolidSphere(0.5f, 15, 15);
} }
@ -602,13 +615,15 @@ void Head::renderEyeBalls() {
glm::vec3 rotationAxis = glm::axis(rotation); glm::vec3 rotationAxis = glm::axis(rotation);
glRotatef(glm::angle(rotation), rotationAxis.x, rotationAxis.y, rotationAxis.z); glRotatef(glm::angle(rotation), rotationAxis.x, rotationAxis.y, rotationAxis.z);
glTranslatef(0.0f, 0.0f, -IRIS_PROTRUSION); glTranslatef(0.0f, 0.0f, -IRIS_PROTRUSION);
glScalef(IRIS_RADIUS * 2.0f, IRIS_RADIUS * 2.0f, IRIS_RADIUS); // flatten the iris glScalef(_scale * IRIS_RADIUS * 2.0f,
_scale * IRIS_RADIUS * 2.0f,
_scale * IRIS_RADIUS); // flatten the iris
// this ugliness is simply to invert the model transform and get the eye position in model space // this ugliness is simply to invert the model transform and get the eye position in model space
_irisProgram->setUniform(_eyePositionLocation, (glm::inverse(rotation) * _irisProgram->setUniform(_eyePositionLocation, (glm::inverse(rotation) *
(Application::getInstance()->getCamera()->getPosition() - _rightEyePosition) + (Application::getInstance()->getCamera()->getPosition() - _rightEyePosition) +
glm::vec3(0.0f, 0.0f, IRIS_PROTRUSION)) * glm::vec3(1.0f / (IRIS_RADIUS * 2.0f), glm::vec3(0.0f, 0.0f, _scale * IRIS_PROTRUSION)) * glm::vec3(1.0f / (_scale * IRIS_RADIUS * 2.0f),
1.0f / (IRIS_RADIUS * 2.0f), 1.0f / IRIS_RADIUS)); 1.0f / (_scale * IRIS_RADIUS * 2.0f), 1.0f / (_scale * IRIS_RADIUS)));
glutSolidSphere(0.5f, 15, 15); glutSolidSphere(0.5f, 15, 15);
} }
@ -626,7 +641,7 @@ void Head::renderEyeBalls() {
glTranslatef(_leftEyePosition.x, _leftEyePosition.y, _leftEyePosition.z); //translate to eyeball position glTranslatef(_leftEyePosition.x, _leftEyePosition.y, _leftEyePosition.z); //translate to eyeball position
glm::vec3 rotationAxis = glm::axis(orientation); glm::vec3 rotationAxis = glm::axis(orientation);
glRotatef(glm::angle(orientation), rotationAxis.x, rotationAxis.y, rotationAxis.z); glRotatef(glm::angle(orientation), rotationAxis.x, rotationAxis.y, rotationAxis.z);
glScalef(EYELID_RADIUS, EYELID_RADIUS, EYELID_RADIUS); glScalef(_scale * EYELID_RADIUS, _scale * EYELID_RADIUS, _scale * EYELID_RADIUS);
glRotatef(-40 - 50 * _leftEyeBlink, 1, 0, 0); glRotatef(-40 - 50 * _leftEyeBlink, 1, 0, 0);
Application::getInstance()->getGeometryCache()->renderHemisphere(15, 10); Application::getInstance()->getGeometryCache()->renderHemisphere(15, 10);
glRotatef(180 * _leftEyeBlink, 1, 0, 0); glRotatef(180 * _leftEyeBlink, 1, 0, 0);
@ -639,7 +654,7 @@ void Head::renderEyeBalls() {
glTranslatef(_rightEyePosition.x, _rightEyePosition.y, _rightEyePosition.z); //translate to eyeball position glTranslatef(_rightEyePosition.x, _rightEyePosition.y, _rightEyePosition.z); //translate to eyeball position
glm::vec3 rotationAxis = glm::axis(orientation); glm::vec3 rotationAxis = glm::axis(orientation);
glRotatef(glm::angle(orientation), rotationAxis.x, rotationAxis.y, rotationAxis.z); glRotatef(glm::angle(orientation), rotationAxis.x, rotationAxis.y, rotationAxis.z);
glScalef(EYELID_RADIUS, EYELID_RADIUS, EYELID_RADIUS); glScalef(_scale * EYELID_RADIUS, _scale * EYELID_RADIUS, _scale * EYELID_RADIUS);
glRotatef(-40 - 50 * _rightEyeBlink, 1, 0, 0); glRotatef(-40 - 50 * _rightEyeBlink, 1, 0, 0);
Application::getInstance()->getGeometryCache()->renderHemisphere(15, 10); Application::getInstance()->getGeometryCache()->renderHemisphere(15, 10);
glRotatef(180 * _rightEyeBlink, 1, 0, 0); glRotatef(180 * _rightEyeBlink, 1, 0, 0);
@ -682,7 +697,7 @@ void Head::updateHairPhysics(float deltaTime) {
= front * sinf(radian) = front * sinf(radian)
+ up * cosf(radian); + up * cosf(radian);
_hairTuft[t].basePosition = _position + _scale * 0.9f * baseDirection; _hairTuft[t].basePosition = _position + _scale * BODY_BALL_RADIUS_HEAD_BASE * 0.9f * baseDirection;
glm::vec3 midAxis = _hairTuft[t].midPosition - _hairTuft[t].basePosition; glm::vec3 midAxis = _hairTuft[t].midPosition - _hairTuft[t].basePosition;
glm::vec3 endAxis = _hairTuft[t].endPosition - _hairTuft[t].midPosition; glm::vec3 endAxis = _hairTuft[t].endPosition - _hairTuft[t].midPosition;

View file

@ -38,7 +38,7 @@ public:
void render(float alpha); void render(float alpha);
void renderMohawk(); void renderMohawk();
void setScale (float scale ) { _scale = scale; } void setScale (float scale );
void setPosition (glm::vec3 position ) { _position = position; } void setPosition (glm::vec3 position ) { _position = position; }
void setBodyRotation (glm::vec3 bodyRotation ) { _bodyRotation = bodyRotation; } void setBodyRotation (glm::vec3 bodyRotation ) { _bodyRotation = bodyRotation; }
void setGravity (glm::vec3 gravity ) { _gravity = gravity; } void setGravity (glm::vec3 gravity ) { _gravity = gravity; }

View file

@ -12,9 +12,14 @@
#include <sstream> #include <sstream>
bool LeapManager::_libraryExists = false; bool LeapManager::_libraryExists = false;
bool LeapManager::_doFakeFingers = false;
Leap::Controller* LeapManager::_controller = NULL; Leap::Controller* LeapManager::_controller = NULL;
HifiLeapListener* LeapManager::_listener = NULL; HifiLeapListener* LeapManager::_listener = NULL;
namespace {
glm::vec3 fakeHandOffset(0.0f, 50.0f, 50.0f);
} // end anonymous namespace
class HifiLeapListener : public Leap::Listener { class HifiLeapListener : public Leap::Listener {
public: public:
HifiLeapListener() {} HifiLeapListener() {}
@ -76,47 +81,91 @@ void LeapManager::terminate() {
} }
void LeapManager::nextFrame() { void LeapManager::nextFrame() {
if (_listener && _controller) if (controllersExist()) {
_listener->onFrame(*_controller); _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() { const std::vector<glm::vec3>& LeapManager::getFingerTips() {
if (_listener) { if (controllersExist()) {
return _listener->fingerTips; return _listener->fingerTips;
} }
else { else {
static std::vector<glm::vec3> empty; static std::vector<glm::vec3> stubData;
return empty; 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() { const std::vector<glm::vec3>& LeapManager::getFingerRoots() {
if (_listener) { if (controllersExist()) {
return _listener->fingerRoots; return _listener->fingerRoots;
} }
else { else {
static std::vector<glm::vec3> empty; static std::vector<glm::vec3> stubData;
return empty; 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() { const std::vector<glm::vec3>& LeapManager::getHandPositions() {
if (_listener) { if (controllersExist()) {
return _listener->handPositions; return _listener->handPositions;
} }
else { else {
static std::vector<glm::vec3> empty; static std::vector<glm::vec3> stubData;
return empty; 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() { const std::vector<glm::vec3>& LeapManager::getHandNormals() {
if (_listener) { if (controllersExist()) {
return _listener->handNormals; return _listener->handNormals;
} }
else { else {
static std::vector<glm::vec3> empty; static std::vector<glm::vec3> stubData;
return empty; 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 { class LeapManager {
public: 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>& getFingerTips();
static const std::vector<glm::vec3>& getFingerRoots(); static const std::vector<glm::vec3>& getFingerRoots();
static const std::vector<glm::vec3>& getHandPositions(); static const std::vector<glm::vec3>& getHandPositions();
@ -31,6 +33,7 @@ public:
private: private:
static bool _libraryExists; // The library is present, so we won't crash if we call it. static bool _libraryExists; // The library is present, so we won't crash if we call it.
static bool _doFakeFingers;
static Leap::Controller* _controller; static Leap::Controller* _controller;
static HifiLeapListener* _listener; static HifiLeapListener* _listener;
}; };

View file

@ -11,10 +11,39 @@
const float BODY_SPRING_DEFAULT_TIGHTNESS = 1000.0f; const float BODY_SPRING_DEFAULT_TIGHTNESS = 1000.0f;
const float FLOATING_HEIGHT = 0.13f; const float FLOATING_HEIGHT = 0.13f;
Skeleton::Skeleton() { const glm::vec3 AVATAR_JOINT_POSITION_PELVIS = glm::vec3(0.0, 0.0, 0.0 );
const glm::vec3 AVATAR_JOINT_POSITION_TORSO = glm::vec3( 0.0, 0.09, -0.01);
const glm::vec3 AVATAR_JOINT_POSITION_CHEST = glm::vec3( 0.0, 0.09, -0.01);
const glm::vec3 AVATAR_JOINT_POSITION_NECK_BASE = glm::vec3( 0.0, 0.14, 0.01);
const glm::vec3 AVATAR_JOINT_POSITION_HEAD_BASE = glm::vec3( 0.0, 0.04, 0.00);
const glm::vec3 AVATAR_JOINT_POSITION_HEAD_TOP = glm::vec3( 0.0, 0.04, 0.00);
const glm::vec3 AVATAR_JOINT_POSITION_LEFT_COLLAR = glm::vec3(-0.06, 0.04, 0.01);
const glm::vec3 AVATAR_JOINT_POSITION_LEFT_SHOULDER = glm::vec3(-0.05, 0.0 , 0.01);
const glm::vec3 AVATAR_JOINT_POSITION_LEFT_ELBOW = glm::vec3(-0.16, 0.0 , 0.0 );
const glm::vec3 AVATAR_JOINT_POSITION_LEFT_WRIST = glm::vec3(-0.12, 0.0 , 0.0 );
const glm::vec3 AVATAR_JOINT_POSITION_LEFT_FINGERTIPS = glm::vec3(-0.1, 0.0 , 0.0 );
const glm::vec3 AVATAR_JOINT_POSITION_RIGHT_COLLAR = glm::vec3( 0.06, 0.04, 0.01);
const glm::vec3 AVATAR_JOINT_POSITION_RIGHT_SHOULDER = glm::vec3( 0.05, 0.0 , 0.01);
const glm::vec3 AVATAR_JOINT_POSITION_RIGHT_ELBOW = glm::vec3( 0.16, 0.0 , 0.0 );
const glm::vec3 AVATAR_JOINT_POSITION_RIGHT_WRIST = glm::vec3( 0.12, 0.0 , 0.0 );
const glm::vec3 AVATAR_JOINT_POSITION_RIGHT_FINGERTIPS = glm::vec3( 0.1, 0.0 , 0.0 );
const glm::vec3 AVATAR_JOINT_POSITION_LEFT_HIP = glm::vec3(-0.05, 0.0 , 0.02);
const glm::vec3 AVATAR_JOINT_POSITION_LEFT_KNEE = glm::vec3( 0.00, -0.25, 0.00);
const glm::vec3 AVATAR_JOINT_POSITION_LEFT_HEEL = glm::vec3( 0.00, -0.23, 0.00);
const glm::vec3 AVATAR_JOINT_POSITION_LEFT_TOES = glm::vec3( 0.00, 0.00, -0.06);
const glm::vec3 AVATAR_JOINT_POSITION_RIGHT_HIP = glm::vec3( 0.05, 0.0 , 0.02);
const glm::vec3 AVATAR_JOINT_POSITION_RIGHT_KNEE = glm::vec3( 0.00, -0.25, 0.00);
const glm::vec3 AVATAR_JOINT_POSITION_RIGHT_HEEL = glm::vec3( 0.00, -0.23, 0.00);
const glm::vec3 AVATAR_JOINT_POSITION_RIGHT_TOES = glm::vec3( 0.00, 0.00, -0.06);
Skeleton::Skeleton() : _floatingHeight(FLOATING_HEIGHT){
} }
void Skeleton::initialize() { void Skeleton::initialize() {
for (int b = 0; b < NUM_AVATAR_JOINTS; b++) { for (int b = 0; b < NUM_AVATAR_JOINTS; b++) {
joint[b].parent = AVATAR_JOINT_NULL; joint[b].parent = AVATAR_JOINT_NULL;
@ -60,35 +89,39 @@ void Skeleton::initialize() {
joint[ AVATAR_JOINT_RIGHT_HEEL ].parent = AVATAR_JOINT_RIGHT_KNEE; joint[ AVATAR_JOINT_RIGHT_HEEL ].parent = AVATAR_JOINT_RIGHT_KNEE;
joint[ AVATAR_JOINT_RIGHT_TOES ].parent = AVATAR_JOINT_RIGHT_HEEL; joint[ AVATAR_JOINT_RIGHT_TOES ].parent = AVATAR_JOINT_RIGHT_HEEL;
setScale(1.0f);
}
void Skeleton::setScale(float scale) {
// specify the bind pose position // specify the bind pose position
joint[ AVATAR_JOINT_PELVIS ].bindPosePosition = glm::vec3( 0.0, 0.0, 0.0 ); joint[ AVATAR_JOINT_PELVIS ].bindPosePosition = scale * AVATAR_JOINT_POSITION_PELVIS;
joint[ AVATAR_JOINT_TORSO ].bindPosePosition = glm::vec3( 0.0, 0.09, -0.01 ); joint[ AVATAR_JOINT_TORSO ].bindPosePosition = scale * AVATAR_JOINT_POSITION_TORSO;
joint[ AVATAR_JOINT_CHEST ].bindPosePosition = glm::vec3( 0.0, 0.09, -0.01 ); joint[ AVATAR_JOINT_CHEST ].bindPosePosition = scale * AVATAR_JOINT_POSITION_CHEST;
joint[ AVATAR_JOINT_NECK_BASE ].bindPosePosition = glm::vec3( 0.0, 0.14, 0.01 ); joint[ AVATAR_JOINT_NECK_BASE ].bindPosePosition = scale * AVATAR_JOINT_POSITION_NECK_BASE;
joint[ AVATAR_JOINT_HEAD_BASE ].bindPosePosition = glm::vec3( 0.0, 0.04, 0.00 ); joint[ AVATAR_JOINT_HEAD_BASE ].bindPosePosition = scale * AVATAR_JOINT_POSITION_HEAD_BASE;
joint[ AVATAR_JOINT_HEAD_TOP ].bindPosePosition = glm::vec3( 0.0, 0.04, 0.00 ); joint[ AVATAR_JOINT_HEAD_TOP ].bindPosePosition = scale * AVATAR_JOINT_POSITION_HEAD_TOP;
joint[ AVATAR_JOINT_LEFT_COLLAR ].bindPosePosition = glm::vec3( -0.06, 0.04, 0.01 ); joint[ AVATAR_JOINT_LEFT_COLLAR ].bindPosePosition = scale * AVATAR_JOINT_POSITION_LEFT_COLLAR;
joint[ AVATAR_JOINT_LEFT_SHOULDER ].bindPosePosition = glm::vec3( -0.05, 0.0, 0.01 ); joint[ AVATAR_JOINT_LEFT_SHOULDER ].bindPosePosition = scale * AVATAR_JOINT_POSITION_LEFT_SHOULDER;
joint[ AVATAR_JOINT_LEFT_ELBOW ].bindPosePosition = glm::vec3( -0.16, 0.0, 0.0 ); joint[ AVATAR_JOINT_LEFT_ELBOW ].bindPosePosition = scale * AVATAR_JOINT_POSITION_LEFT_ELBOW;
joint[ AVATAR_JOINT_LEFT_WRIST ].bindPosePosition = glm::vec3( -0.12, 0.0, 0.0 ); joint[ AVATAR_JOINT_LEFT_WRIST ].bindPosePosition = scale * AVATAR_JOINT_POSITION_LEFT_WRIST;
joint[ AVATAR_JOINT_LEFT_FINGERTIPS ].bindPosePosition = glm::vec3( -0.1, 0.0, 0.0 ); joint[ AVATAR_JOINT_LEFT_FINGERTIPS ].bindPosePosition = scale * AVATAR_JOINT_POSITION_LEFT_FINGERTIPS;
joint[ AVATAR_JOINT_RIGHT_COLLAR ].bindPosePosition = glm::vec3( 0.06, 0.04, 0.01 ); joint[ AVATAR_JOINT_RIGHT_COLLAR ].bindPosePosition = scale * AVATAR_JOINT_POSITION_RIGHT_COLLAR;
joint[ AVATAR_JOINT_RIGHT_SHOULDER ].bindPosePosition = glm::vec3( 0.05, 0.0, 0.01 ); joint[ AVATAR_JOINT_RIGHT_SHOULDER ].bindPosePosition = scale * AVATAR_JOINT_POSITION_RIGHT_SHOULDER;
joint[ AVATAR_JOINT_RIGHT_ELBOW ].bindPosePosition = glm::vec3( 0.16, 0.0, 0.0 ); joint[ AVATAR_JOINT_RIGHT_ELBOW ].bindPosePosition = scale * AVATAR_JOINT_POSITION_RIGHT_ELBOW;
joint[ AVATAR_JOINT_RIGHT_WRIST ].bindPosePosition = glm::vec3( 0.12, 0.0, 0.0 ); joint[ AVATAR_JOINT_RIGHT_WRIST ].bindPosePosition = scale * AVATAR_JOINT_POSITION_RIGHT_WRIST;
joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].bindPosePosition = glm::vec3( 0.1, 0.0, 0.0 ); joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].bindPosePosition = scale * AVATAR_JOINT_POSITION_RIGHT_FINGERTIPS;
joint[ AVATAR_JOINT_LEFT_HIP ].bindPosePosition = glm::vec3( -0.05, 0.0, 0.02 ); joint[ AVATAR_JOINT_LEFT_HIP ].bindPosePosition = scale * AVATAR_JOINT_POSITION_LEFT_HIP;
joint[ AVATAR_JOINT_LEFT_KNEE ].bindPosePosition = glm::vec3( 0.00, -0.25, 0.00 ); joint[ AVATAR_JOINT_LEFT_KNEE ].bindPosePosition = scale * AVATAR_JOINT_POSITION_LEFT_KNEE;
joint[ AVATAR_JOINT_LEFT_HEEL ].bindPosePosition = glm::vec3( 0.00, -0.23, 0.00 ); joint[ AVATAR_JOINT_LEFT_HEEL ].bindPosePosition = scale * AVATAR_JOINT_POSITION_LEFT_HEEL;
joint[ AVATAR_JOINT_LEFT_TOES ].bindPosePosition = glm::vec3( 0.00, 0.00, -0.06 ); joint[ AVATAR_JOINT_LEFT_TOES ].bindPosePosition = scale * AVATAR_JOINT_POSITION_LEFT_TOES;
joint[ AVATAR_JOINT_RIGHT_HIP ].bindPosePosition = glm::vec3( 0.05, 0.0, 0.02 ); joint[ AVATAR_JOINT_RIGHT_HIP ].bindPosePosition = scale * AVATAR_JOINT_POSITION_RIGHT_HIP;
joint[ AVATAR_JOINT_RIGHT_KNEE ].bindPosePosition = glm::vec3( 0.00, -0.25, 0.00 ); joint[ AVATAR_JOINT_RIGHT_KNEE ].bindPosePosition = scale * AVATAR_JOINT_POSITION_RIGHT_KNEE;
joint[ AVATAR_JOINT_RIGHT_HEEL ].bindPosePosition = glm::vec3( 0.00, -0.23, 0.00 ); joint[ AVATAR_JOINT_RIGHT_HEEL ].bindPosePosition = scale * AVATAR_JOINT_POSITION_RIGHT_HEEL;
joint[ AVATAR_JOINT_RIGHT_TOES ].bindPosePosition = glm::vec3( 0.00, 0.00, -0.06 ); joint[ AVATAR_JOINT_RIGHT_TOES ].bindPosePosition = scale * AVATAR_JOINT_POSITION_RIGHT_TOES;
// calculate bone length, absolute bind positions/rotations // calculate bone length, absolute bind positions/rotations
for (int b = 0; b < NUM_AVATAR_JOINTS; b++) { for (int b = 0; b < NUM_AVATAR_JOINTS; b++) {
@ -99,12 +132,14 @@ void Skeleton::initialize() {
joint[b].absoluteBindPoseRotation = glm::quat(); joint[b].absoluteBindPoseRotation = glm::quat();
} else { } else {
joint[b].absoluteBindPosePosition = joint[ joint[b].parent ].absoluteBindPosePosition + joint[b].absoluteBindPosePosition = joint[ joint[b].parent ].absoluteBindPosePosition +
joint[b].bindPosePosition; joint[b].bindPosePosition;
glm::vec3 parentDirection = joint[ joint[b].parent ].absoluteBindPoseRotation * JOINT_DIRECTION; glm::vec3 parentDirection = joint[ joint[b].parent ].absoluteBindPoseRotation * JOINT_DIRECTION;
joint[b].absoluteBindPoseRotation = rotationBetween(parentDirection, joint[b].bindPosePosition) * joint[b].absoluteBindPoseRotation = rotationBetween(parentDirection, joint[b].bindPosePosition) *
joint[ joint[b].parent ].absoluteBindPoseRotation; joint[ joint[b].parent ].absoluteBindPoseRotation;
} }
} }
_floatingHeight = scale * FLOATING_HEIGHT;
} }
// calculate positions and rotations of all bones by traversing the skeleton tree: // calculate positions and rotations of all bones by traversing the skeleton tree:
@ -151,7 +186,7 @@ float Skeleton::getPelvisStandingHeight() {
float Skeleton::getPelvisFloatingHeight() { float Skeleton::getPelvisFloatingHeight() {
return joint[ AVATAR_JOINT_LEFT_HEEL ].length + return joint[ AVATAR_JOINT_LEFT_HEEL ].length +
joint[ AVATAR_JOINT_LEFT_KNEE ].length + joint[ AVATAR_JOINT_LEFT_KNEE ].length +
FLOATING_HEIGHT; _floatingHeight;
} }
float Skeleton::getPelvisToHeadLength() { float Skeleton::getPelvisToHeadLength() {

View file

@ -49,6 +49,7 @@ public:
Skeleton(); Skeleton();
void initialize(); void initialize();
void setScale(float scale);
void update(float deltaTime, const glm::quat&, glm::vec3 position); void update(float deltaTime, const glm::quat&, glm::vec3 position);
void render(); void render();
@ -72,7 +73,8 @@ public:
float length; // the length of vector connecting the joint and its parent float length; // the length of vector connecting the joint and its parent
}; };
AvatarJoint joint[ NUM_AVATAR_JOINTS ]; AvatarJoint joint[ NUM_AVATAR_JOINTS ];
}; float _floatingHeight;
};
#endif #endif

View file

@ -24,6 +24,7 @@ AvatarData::AvatarData(Node* owningNode) :
_bodyYaw(-90.0), _bodyYaw(-90.0),
_bodyPitch(0.0), _bodyPitch(0.0),
_bodyRoll(0.0), _bodyRoll(0.0),
_newScale(1.0f),
_handState(0), _handState(0),
_cameraPosition(0,0,0), _cameraPosition(0,0,0),
_cameraOrientation(), _cameraOrientation(),
@ -71,6 +72,7 @@ int AvatarData::getBroadcastData(unsigned char* destinationBuffer) {
destinationBuffer += packFloatAngleToTwoByte(destinationBuffer, _bodyYaw); destinationBuffer += packFloatAngleToTwoByte(destinationBuffer, _bodyYaw);
destinationBuffer += packFloatAngleToTwoByte(destinationBuffer, _bodyPitch); destinationBuffer += packFloatAngleToTwoByte(destinationBuffer, _bodyPitch);
destinationBuffer += packFloatAngleToTwoByte(destinationBuffer, _bodyRoll); destinationBuffer += packFloatAngleToTwoByte(destinationBuffer, _bodyRoll);
destinationBuffer += packFloatRatioToTwoByte(destinationBuffer, _newScale);
// Head rotation (NOTE: This needs to become a quaternion to save two bytes) // Head rotation (NOTE: This needs to become a quaternion to save two bytes)
destinationBuffer += packFloatAngleToTwoByte(destinationBuffer, _headData->_yaw); destinationBuffer += packFloatAngleToTwoByte(destinationBuffer, _headData->_yaw);
@ -197,7 +199,8 @@ int AvatarData::parseData(unsigned char* sourceBuffer, int numBytes) {
sourceBuffer += unpackFloatAngleFromTwoByte((uint16_t*) sourceBuffer, &_bodyYaw); sourceBuffer += unpackFloatAngleFromTwoByte((uint16_t*) sourceBuffer, &_bodyYaw);
sourceBuffer += unpackFloatAngleFromTwoByte((uint16_t*) sourceBuffer, &_bodyPitch); sourceBuffer += unpackFloatAngleFromTwoByte((uint16_t*) sourceBuffer, &_bodyPitch);
sourceBuffer += unpackFloatAngleFromTwoByte((uint16_t*) sourceBuffer, &_bodyRoll); sourceBuffer += unpackFloatAngleFromTwoByte((uint16_t*) sourceBuffer, &_bodyRoll);
sourceBuffer += unpackFloatRatioFromTwoByte( sourceBuffer, _newScale);
// Head rotation (NOTE: This needs to become a quaternion to save two bytes) // Head rotation (NOTE: This needs to become a quaternion to save two bytes)
float headYaw, headPitch, headRoll; float headYaw, headPitch, headRoll;
sourceBuffer += unpackFloatAngleFromTwoByte((uint16_t*) sourceBuffer, &headYaw); sourceBuffer += unpackFloatAngleFromTwoByte((uint16_t*) sourceBuffer, &headYaw);

View file

@ -112,6 +112,7 @@ protected:
float _bodyYaw; float _bodyYaw;
float _bodyPitch; float _bodyPitch;
float _bodyRoll; float _bodyRoll;
float _newScale;
// Hand state (are we grabbing something or not) // Hand state (are we grabbing something or not)
char _handState; char _handState;

View file

@ -20,6 +20,8 @@ class HandData {
public: public:
HandData(AvatarData* owningAvatar); 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>& getFingerTips() const { return _fingerTips; }
const std::vector<glm::vec3>& getFingerRoots() const { return _fingerRoots; } const std::vector<glm::vec3>& getFingerRoots() const { return _fingerRoots; }
const std::vector<glm::vec3>& getHandPositions() const { return _handPositions; } const std::vector<glm::vec3>& getHandPositions() const { return _handPositions; }

View file

@ -53,6 +53,8 @@ Node::Node(sockaddr* publicSocket, sockaddr* localSocket, char type, uint16_t no
} else { } else {
_localSocket = NULL; _localSocket = NULL;
} }
pthread_mutex_init(&_mutex, 0);
} }
Node::~Node() { Node::~Node() {
@ -60,6 +62,8 @@ Node::~Node() {
delete _localSocket; delete _localSocket;
delete _linkedData; delete _linkedData;
delete _bytesReceivedMovingAverage; delete _bytesReceivedMovingAverage;
pthread_mutex_destroy(&_mutex);
} }
// Names of Node Types // Names of Node Types

View file

@ -65,6 +65,9 @@ public:
int getPingMs() const { return _pingMs; }; int getPingMs() const { return _pingMs; };
void setPingMs(int pingMs) { _pingMs = pingMs; }; void setPingMs(int pingMs) { _pingMs = pingMs; };
void lock() { pthread_mutex_lock(&_mutex); }
void unlock() { pthread_mutex_unlock(&_mutex); }
static void printLog(Node const&); static void printLog(Node const&);
private: private:
@ -83,6 +86,7 @@ private:
NodeData* _linkedData; NodeData* _linkedData;
bool _isAlive; bool _isAlive;
int _pingMs; int _pingMs;
pthread_mutex_t _mutex;
}; };

View file

@ -29,9 +29,9 @@ const char SOLO_NODE_TYPES[3] = {
NODE_TYPE_VOXEL_SERVER NODE_TYPE_VOXEL_SERVER
}; };
char DOMAIN_HOSTNAME[] = "highfidelity.below92.com"; const char DEFAULT_DOMAIN_HOSTNAME[MAX_HOSTNAME_BYTES] = "root.highfidelity.io";
char DOMAIN_IP[100] = "192.168.1.47"; // IP Address will be re-set by lookup on startup const char DEFAULT_DOMAIN_IP[INET_ADDRSTRLEN] = ""; // IP Address will be re-set by lookup on startup
const int DOMAINSERVER_PORT = 40102; const int DEFAULT_DOMAINSERVER_PORT = 40102;
bool silentNodeThreadStopFlag = false; bool silentNodeThreadStopFlag = false;
bool pingUnknownNodeThreadStopFlag = false; bool pingUnknownNodeThreadStopFlag = false;
@ -63,20 +63,37 @@ NodeList::NodeList(char newOwnerType, unsigned int newSocketListenPort) :
_ownerType(newOwnerType), _ownerType(newOwnerType),
_nodeTypesOfInterest(NULL), _nodeTypesOfInterest(NULL),
_ownerID(UNKNOWN_NODE_ID), _ownerID(UNKNOWN_NODE_ID),
_lastNodeID(0) { _lastNodeID(0)
pthread_mutex_init(&mutex, 0); {
memcpy(_domainHostname, DEFAULT_DOMAIN_HOSTNAME, sizeof(DEFAULT_DOMAIN_HOSTNAME));
memcpy(_domainIP, DEFAULT_DOMAIN_IP, sizeof(DEFAULT_DOMAIN_IP));
} }
NodeList::~NodeList() { NodeList::~NodeList() {
delete _nodeTypesOfInterest; delete _nodeTypesOfInterest;
// delete the nodes in our list
clear(); clear();
// stop the spawned threads, if they were started // stop the spawned threads, if they were started
stopSilentNodeRemovalThread(); stopSilentNodeRemovalThread();
}
void NodeList::setDomainHostname(const char* domainHostname) {
memset(_domainHostname, 0, sizeof(_domainHostname));
memcpy(_domainHostname, domainHostname, strlen(domainHostname));
pthread_mutex_destroy(&mutex); // reset the domain IP so the hostname is checked again
setDomainIP("");
}
void NodeList::setDomainIP(const char* domainIP) {
memset(_domainIP, 0, sizeof(_domainIP));
memcpy(_domainIP, domainIP, strlen(domainIP));
}
void NodeList::setDomainIPToLocalhost() {
int ip = getLocalAddress();
sprintf(_domainIP, "%d.%d.%d.%d", (ip & 0xFF), ((ip >> 8) & 0xFF),((ip >> 16) & 0xFF), ((ip >> 24) & 0xFF));
} }
void NodeList::timePingReply(sockaddr *nodeAddress, unsigned char *packetData) { void NodeList::timePingReply(sockaddr *nodeAddress, unsigned char *packetData) {
@ -95,7 +112,14 @@ void NodeList::timePingReply(sockaddr *nodeAddress, unsigned char *packetData) {
void NodeList::processNodeData(sockaddr* senderAddress, unsigned char* packetData, size_t dataBytes) { void NodeList::processNodeData(sockaddr* senderAddress, unsigned char* packetData, size_t dataBytes) {
switch (packetData[0]) { switch (packetData[0]) {
case PACKET_TYPE_DOMAIN: { case PACKET_TYPE_DOMAIN: {
processDomainServerList(packetData, dataBytes); // only process the DS if this is our current domain server
sockaddr_in domainServerSocket = *(sockaddr_in*) senderAddress;
const char* domainSenderIP = inet_ntoa(domainServerSocket.sin_addr);
if (memcmp(domainSenderIP, _domainIP, strlen(domainSenderIP)) == 0) {
processDomainServerList(packetData, dataBytes);
}
break; break;
} }
case PACKET_TYPE_PING: { case PACKET_TYPE_PING: {
@ -113,7 +137,6 @@ void NodeList::processNodeData(sockaddr* senderAddress, unsigned char* packetDat
} }
void NodeList::processBulkNodeData(sockaddr *senderAddress, unsigned char *packetData, int numTotalBytes) { void NodeList::processBulkNodeData(sockaddr *senderAddress, unsigned char *packetData, int numTotalBytes) {
lock();
// find the avatar mixer in our node list and update the lastRecvTime from it // find the avatar mixer in our node list and update the lastRecvTime from it
Node* bulkSendNode = nodeWithAddress(senderAddress); Node* bulkSendNode = nodeWithAddress(senderAddress);
@ -121,38 +144,37 @@ void NodeList::processBulkNodeData(sockaddr *senderAddress, unsigned char *packe
if (bulkSendNode) { if (bulkSendNode) {
bulkSendNode->setLastHeardMicrostamp(usecTimestampNow()); bulkSendNode->setLastHeardMicrostamp(usecTimestampNow());
bulkSendNode->recordBytesReceived(numTotalBytes); bulkSendNode->recordBytesReceived(numTotalBytes);
}
int numBytesPacketHeader = numBytesForPacketHeader(packetData);
unsigned char *startPosition = packetData;
unsigned char *currentPosition = startPosition + numBytesPacketHeader;
unsigned char packetHolder[numTotalBytes];
// we've already verified packet version for the bulk packet, so all head data in the packet is also up to date
populateTypeAndVersion(packetHolder, PACKET_TYPE_HEAD_DATA);
uint16_t nodeID = -1;
while ((currentPosition - startPosition) < numTotalBytes) {
unpackNodeId(currentPosition, &nodeID);
memcpy(packetHolder + numBytesPacketHeader,
currentPosition,
numTotalBytes - (currentPosition - startPosition));
Node* matchingNode = nodeWithID(nodeID); int numBytesPacketHeader = numBytesForPacketHeader(packetData);
if (!matchingNode) { unsigned char* startPosition = packetData;
// we're missing this node, we need to add it to the list unsigned char* currentPosition = startPosition + numBytesPacketHeader;
matchingNode = addOrUpdateNode(NULL, NULL, NODE_TYPE_AGENT, nodeID); unsigned char packetHolder[numTotalBytes];
// we've already verified packet version for the bulk packet, so all head data in the packet is also up to date
populateTypeAndVersion(packetHolder, PACKET_TYPE_HEAD_DATA);
uint16_t nodeID = -1;
while ((currentPosition - startPosition) < numTotalBytes) {
unpackNodeId(currentPosition, &nodeID);
memcpy(packetHolder + numBytesPacketHeader,
currentPosition,
numTotalBytes - (currentPosition - startPosition));
Node* matchingNode = nodeWithID(nodeID);
if (!matchingNode) {
// we're missing this node, we need to add it to the list
matchingNode = addOrUpdateNode(NULL, NULL, NODE_TYPE_AGENT, nodeID);
}
currentPosition += updateNodeWithData(matchingNode,
packetHolder,
numTotalBytes - (currentPosition - startPosition));
} }
}
currentPosition += updateNodeWithData(matchingNode,
packetHolder,
numTotalBytes - (currentPosition - startPosition));
}
unlock();
} }
int NodeList::updateNodeWithData(sockaddr *senderAddress, unsigned char *packetData, size_t dataBytes) { int NodeList::updateNodeWithData(sockaddr *senderAddress, unsigned char *packetData, size_t dataBytes) {
@ -167,6 +189,8 @@ int NodeList::updateNodeWithData(sockaddr *senderAddress, unsigned char *packetD
} }
int NodeList::updateNodeWithData(Node *node, unsigned char *packetData, int dataBytes) { int NodeList::updateNodeWithData(Node *node, unsigned char *packetData, int dataBytes) {
node->lock();
node->setLastHeardMicrostamp(usecTimestampNow()); node->setLastHeardMicrostamp(usecTimestampNow());
if (node->getActiveSocket()) { if (node->getActiveSocket()) {
@ -177,7 +201,11 @@ int NodeList::updateNodeWithData(Node *node, unsigned char *packetData, int data
linkedDataCreateCallback(node); linkedDataCreateCallback(node);
} }
return node->getLinkedData()->parseData(packetData, dataBytes); int numParsedBytes = node->getLinkedData()->parseData(packetData, dataBytes);
node->unlock();
return numParsedBytes;
} }
Node* NodeList::nodeWithAddress(sockaddr *senderAddress) { Node* NodeList::nodeWithAddress(sockaddr *senderAddress) {
@ -218,7 +246,9 @@ void NodeList::clear() {
Node** nodeBucket = _nodeBuckets[i / NODES_PER_BUCKET]; Node** nodeBucket = _nodeBuckets[i / NODES_PER_BUCKET];
Node* node = nodeBucket[i % NODES_PER_BUCKET]; Node* node = nodeBucket[i % NODES_PER_BUCKET];
node->lock();
delete node; delete node;
node = NULL; node = NULL;
} }
@ -237,18 +267,19 @@ void NodeList::sendDomainServerCheckIn() {
static bool printedDomainServerIP = false; static bool printedDomainServerIP = false;
// Lookup the IP address of the domain server if we need to // Lookup the IP address of the domain server if we need to
if (atoi(DOMAIN_IP) == 0) { if (atoi(_domainIP) == 0) {
printf("Looking up %s\n", _domainHostname);
struct hostent* pHostInfo; struct hostent* pHostInfo;
if ((pHostInfo = gethostbyname(DOMAIN_HOSTNAME)) != NULL) { if ((pHostInfo = gethostbyname(_domainHostname)) != NULL) {
sockaddr_in tempAddress; sockaddr_in tempAddress;
memcpy(&tempAddress.sin_addr, pHostInfo->h_addr_list[0], pHostInfo->h_length); memcpy(&tempAddress.sin_addr, pHostInfo->h_addr_list[0], pHostInfo->h_length);
strcpy(DOMAIN_IP, inet_ntoa(tempAddress.sin_addr)); strcpy(_domainIP, inet_ntoa(tempAddress.sin_addr));
printLog("Domain Server: %s \n", DOMAIN_HOSTNAME); printLog("Domain Server: %s \n", _domainHostname);
} else { } else {
printLog("Failed domain server lookup\n"); printLog("Failed domain server lookup\n");
} }
} else if (!printedDomainServerIP) { } else if (!printedDomainServerIP) {
printLog("Domain Server IP: %s\n", DOMAIN_IP); printLog("Domain Server IP: %s\n", _domainIP);
printedDomainServerIP = true; printedDomainServerIP = true;
} }
@ -295,7 +326,7 @@ void NodeList::sendDomainServerCheckIn() {
checkInPacketSize = packetPosition - checkInPacket; checkInPacketSize = packetPosition - checkInPacket;
} }
_nodeSocket.send(DOMAIN_IP, DOMAINSERVER_PORT, checkInPacket, checkInPacketSize); _nodeSocket.send(_domainIP, DEFAULT_DOMAINSERVER_PORT, checkInPacket, checkInPacketSize);
} }
int NodeList::processDomainServerList(unsigned char* packetData, size_t dataBytes) { int NodeList::processDomainServerList(unsigned char* packetData, size_t dataBytes) {

View file

@ -9,8 +9,10 @@
#ifndef __hifi__NodeList__ #ifndef __hifi__NodeList__
#define __hifi__NodeList__ #define __hifi__NodeList__
#include <netinet/in.h>
#include <stdint.h> #include <stdint.h>
#include <iterator> #include <iterator>
#include <unistd.h>
#include "Node.h" #include "Node.h"
#include "NodeTypes.h" #include "NodeTypes.h"
@ -31,9 +33,11 @@ const int DOMAIN_SERVER_CHECK_IN_USECS = 1 * 1000000;
extern const char SOLO_NODE_TYPES[3]; extern const char SOLO_NODE_TYPES[3];
extern char DOMAIN_HOSTNAME[]; const int MAX_HOSTNAME_BYTES = 255;
extern char DOMAIN_IP[100]; // IP Address will be re-set by lookup on startup
extern const int DOMAINSERVER_PORT; extern const char DEFAULT_DOMAIN_HOSTNAME[MAX_HOSTNAME_BYTES];
extern const char DEFAULT_DOMAIN_IP[INET_ADDRSTRLEN]; // IP Address will be re-set by lookup on startup
extern const int DEFAULT_DOMAINSERVER_PORT;
const int UNKNOWN_NODE_ID = -1; const int UNKNOWN_NODE_ID = -1;
@ -49,9 +53,16 @@ public:
NodeListIterator begin() const; NodeListIterator begin() const;
NodeListIterator end() const; NodeListIterator end() const;
NODE_TYPE getOwnerType() const { return _ownerType; } NODE_TYPE getOwnerType() const { return _ownerType; }
void setOwnerType(NODE_TYPE ownerType) { _ownerType = ownerType; } void setOwnerType(NODE_TYPE ownerType) { _ownerType = ownerType; }
const char* getDomainHostname() const { return _domainHostname; };
void setDomainHostname(const char* domainHostname);
void setDomainIP(const char* domainIP);
void setDomainIPToLocalhost();
uint16_t getLastNodeID() const { return _lastNodeID; } uint16_t getLastNodeID() const { return _lastNodeID; }
void increaseNodeID() { ++_lastNodeID; } void increaseNodeID() { ++_lastNodeID; }
@ -69,9 +80,6 @@ public:
void clear(); void clear();
void lock() { pthread_mutex_lock(&mutex); }
void unlock() { pthread_mutex_unlock(&mutex); }
void setNodeTypesOfInterest(const char* nodeTypesOfInterest, int numNodeTypesOfInterest); void setNodeTypesOfInterest(const char* nodeTypesOfInterest, int numNodeTypesOfInterest);
void sendDomainServerCheckIn(); void sendDomainServerCheckIn();
@ -108,6 +116,8 @@ private:
void addNodeToList(Node* newNode); void addNodeToList(Node* newNode);
char _domainHostname[MAX_HOSTNAME_BYTES];
char _domainIP[INET_ADDRSTRLEN];
Node** _nodeBuckets[MAX_NUM_NODES / NODES_PER_BUCKET]; Node** _nodeBuckets[MAX_NUM_NODES / NODES_PER_BUCKET];
int _numNodes; int _numNodes;
UDPSocket _nodeSocket; UDPSocket _nodeSocket;
@ -118,7 +128,6 @@ private:
uint16_t _lastNodeID; uint16_t _lastNodeID;
pthread_t removeSilentNodesThread; pthread_t removeSilentNodesThread;
pthread_t checkInWithDomainServerThread; pthread_t checkInWithDomainServerThread;
pthread_mutex_t mutex;
void handlePingReply(sockaddr *nodeAddress); void handlePingReply(sockaddr *nodeAddress);
void timePingReply(sockaddr *nodeAddress, unsigned char *packetData); void timePingReply(sockaddr *nodeAddress, unsigned char *packetData);

View file

@ -13,6 +13,9 @@
PACKET_VERSION versionForPacketType(PACKET_TYPE type) { PACKET_VERSION versionForPacketType(PACKET_TYPE type) {
switch (type) { switch (type) {
case PACKET_TYPE_HEAD_DATA:
return 1;
break;
default: default:
return 0; return 0;
break; break;
@ -60,4 +63,4 @@ int numBytesForPacketHeader(unsigned char* packetHeader) {
// currently this need not be dynamic - there are 2 bytes for each packet header // currently this need not be dynamic - there are 2 bytes for each packet header
return 2; return 2;
} }

View file

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

View file

@ -383,8 +383,7 @@ int main(int argc, const char * argv[]) {
::wantLocalDomain = cmdOptionExists(argc, argv,local); ::wantLocalDomain = cmdOptionExists(argc, argv,local);
if (::wantLocalDomain) { if (::wantLocalDomain) {
printf("Local Domain MODE!\n"); printf("Local Domain MODE!\n");
int ip = getLocalAddress(); nodeList->setDomainIPToLocalhost();
sprintf(DOMAIN_IP,"%d.%d.%d.%d", (ip & 0xFF), ((ip >> 8) & 0xFF),((ip >> 16) & 0xFF), ((ip >> 24) & 0xFF));
} }
nodeList->linkedDataCreateCallback = &attachVoxelNodeDataToNode; nodeList->linkedDataCreateCallback = &attachVoxelNodeDataToNode;