History

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

atlante45 committed 13 years ago

Commit c095b6b2 parents f2305fd 015ff4a70 files · +2330 −813Browse files

Showing the changes to interface/src/Application.cpp (1 of 70 files). Show all

Unified · Split

interface/src/Application.cpp+447−193
@@ -77,8 +77,10 @@ static char STAR_CACHE_FILE[] = "cachedStars.txt"; · 76 unmodified lines
7777
7878 static const int BANDWIDTH_METER_CLICK_MAX_DRAG_LENGTH = 6; // farther dragged clicks are ignored
7979
80−const glm::vec3 START_LOCATION(4.f, 0.f, 5.f); // Where one's own node begins in the world
81− // (will be overwritten if avatar data file is found)
80+// Where one's own Avatar begins in the world (will be overwritten if avatar data file is found)
81+// this is basically in the center of the ground plane. Slightly adjusted. This was asked for by
82+// Grayson as he's building a street around here for demo dinner 2
83+const glm::vec3 START_LOCATION(0.485f * TREE_SCALE, 0.f, 0.5f * TREE_SCALE);
8284
8385 const int IDLE_SIMULATE_MSECS = 16; // How often should call simulate and other stuff
8486 // in the idle loop? (60 FPS is default)
@@ -215,6 +217,7 @@ Application::Application(int& argc, char** argv, timeval &startup_time) : · 130 unmodified lines
215217 _audio(&_audioScope, STARTUP_JITTER_SAMPLES),
216218 #endif
217219 _stopNetworkReceiveThread(false),
220+ _stopProcessVoxelsThread(false),
218221 _packetCount(0),
219222 _packetsPerSecond(0),
220223 _bytesPerSecond(0),
@@ -235,7 +238,12 @@ Application::Application(int& argc, char** argv, timeval &startup_time) : · 14 unmodified lines
235238
236239 NodeList::createInstance(NODE_TYPE_AGENT, listenPort);
237240
238− _enableNetworkThread = !cmdOptionExists(argc, constArgv, "--nonblocking");
241+ NodeList::getInstance()->addHook(&_voxels);
242+ NodeList::getInstance()->addHook(this);
243+
244+
245+ // network receive thread and voxel parsing thread are both controlled by the --nonblocking command line
246+ _enableProcessVoxelsThread = _enableNetworkThread = !cmdOptionExists(argc, constArgv, "--nonblocking");
239247 if (!_enableNetworkThread) {
240248 NodeList::getInstance()->getNodeSocket()->setBlocking(false);
241249 }
@@ -318,6 +326,11 @@ Application::Application(int& argc, char** argv, timeval &startup_time) : · 76 unmodified lines
318326 // initialization continues in initializeGL when OpenGL context is ready
319327 }
320328
329+Application::~Application() {
330+ NodeList::getInstance()->removeHook(&_voxels);
331+ NodeList::getInstance()->removeHook(this);
332+}
333+
321334 void Application::initializeGL() {
322335 qDebug( "Created Display Window.\n" );
323336
@@ -354,6 +367,12 @@ void Application::initializeGL() { · 30 unmodified lines
354367 pthread_create(&_networkReceiveThread, NULL, networkReceive, NULL);
355368 qDebug("Network receive thread created.\n");
356369 }
370+
371+ // create thread for parsing of voxel data independent of the main network and rendering threads
372+ if (_enableProcessVoxelsThread) {
373+ pthread_create(&_processVoxelsThread, NULL, processVoxels, NULL);
374+ qDebug("Voxel parsing thread created.\n");
375+ }
357376
358377 // call terminate before exiting
359378 connect(this, SIGNAL(aboutToQuit()), SLOT(terminate()));
@@ -429,7 +448,7 @@ void Application::paintGL() { · 69 unmodified lines
429448 // myCamera is. But we also want to do meaningful camera transforms on OpenGL for the offset camera
430449 Camera whichCamera = _myCamera;
431450
432− if (_viewFrustumFromOffset->isChecked() && _frustumOn->isChecked()) {
451+ if (_frustumOn->isChecked()) {
433452
434453 // set the camera to third-person view but offset so we can see the frustum
435454 _viewFrustumOffsetCamera.setTargetPosition(_myCamera.getTargetPosition());
@@ -457,56 +476,49 @@ void Application::paintGL() { · 21 unmodified lines
457476 _frameCount++;
458477 }
459478
460−void Application::resizeGL(int width, int height) {
479+void Application::resetCamerasOnResizeGL(Camera& camera, int width, int height) {
461480 float aspectRatio = ((float)width/(float)height); // based on screen resize
462−
463− // reset the camera FOV to our preference...
464− _myCamera.setFieldOfView(_horizontalFieldOfView);
465−
466− // get the lens details from the current camera
467− Camera& camera = _viewFrustumFromOffset->isChecked() ? _viewFrustumOffsetCamera : _myCamera;
468− float nearClip = camera.getNearClip();
469− float farClip = camera.getFarClip();
470− float fov;
471−
481+
472482 if (OculusManager::isConnected()) {
473483 // more magic numbers; see Oculus SDK docs, p. 32
474484 camera.setAspectRatio(aspectRatio *= 0.5);
475− camera.setFieldOfView(fov = 2 * atan((0.0468 * _oculusDistortionScale) / 0.041) * (180 / PIf));
476−
477− // resize the render texture
478− if (_oculusTextureID != 0) {
479− glBindTexture(GL_TEXTURE_2D, _oculusTextureID);
480− glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
481− glBindTexture(GL_TEXTURE_2D, 0);
482− }
485+ camera.setFieldOfView(2 * atan((0.0468 * _oculusDistortionScale) / 0.041) * (180 / PIf));
483486 } else {
484487 camera.setAspectRatio(aspectRatio);
485− camera.setFieldOfView(fov = _horizontalFieldOfView);
488+ camera.setFieldOfView(_fieldOfView);
486489 }
490+}
491+
492+void Application::resizeGL(int width, int height) {
493+ resetCamerasOnResizeGL(_viewFrustumOffsetCamera, width, height);
494+ resetCamerasOnResizeGL(_myCamera, width, height);
487495
488− // Tell our viewFrustum about this change
489− _viewFrustum.setAspectRatio(aspectRatio);
496+ // resize the render texture
497+ if (OculusManager::isConnected() && _oculusTextureID != 0) {
498+ glBindTexture(GL_TEXTURE_2D, _oculusTextureID);
499+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
500+ glBindTexture(GL_TEXTURE_2D, 0);
501+ }
502+
503+ // Tell our viewFrustum about this change, using the application camera
504+ loadViewFrustum(_myCamera, _viewFrustum);
490505
491506 glViewport(0, 0, width, height); // shouldn't this account for the menu???
492507
493508 glMatrixMode(GL_PROJECTION);
494509 glLoadIdentity();
495510
496− // XXXBHG - If we're in view frustum mode, then we need to do this little bit of hackery so that
497− // OpenGL won't clip our frustum rendering lines. This is a debug hack for sure! Basically, this makes
498− // the near clip a little bit closer (therefor you see more) and the far clip a little bit farther (also,
499− // to see more.)
500− if (_frustumOn->isChecked()) {
501− nearClip -= 0.01f;
502− farClip += 0.01f;
503− }
504−
505511 // On window reshape, we need to tell OpenGL about our new setting
506512 float left, right, bottom, top, nearVal, farVal;
507513 glm::vec4 nearClipPlane, farClipPlane;
508− loadViewFrustum(camera, _viewFrustum);
509514 _viewFrustum.computeOffAxisFrustum(left, right, bottom, top, nearVal, farVal, nearClipPlane, farClipPlane);
515+
516+ // If we're in Display Frustum mode, then we want to use the slightly adjust near/far clip values of the
517+ // _viewFrustumOffsetCamera, so that we can see more of the application content in the application's frustum
518+ if (_frustumOn->isChecked()) {
519+ nearVal = _viewFrustumOffsetCamera.getNearClip();
520+ farVal = _viewFrustumOffsetCamera.getFarClip();
521+ }
510522 glFrustum(left, right, bottom, top, nearVal, farVal);
511523
512524 glMatrixMode(GL_MODELVIEW);
@@ -809,11 +821,7 @@ void Application::keyPressEvent(QKeyEvent* event) { · 296 unmodified lines
809821 _colorVoxelMode->trigger();
810822 break;
811823 case Qt::Key_O:
812− if (isShifted) {
813− _viewFrustumFromOffset->trigger();
814− } else {
815− _selectVoxelMode->trigger();
816− }
824+ _selectVoxelMode->trigger();
817825 break;
818826 case Qt::Key_Slash:
819827 _renderStatsOn->trigger();
@@ -944,7 +952,7 @@ void Application::mousePressEvent(QMouseEvent* event) { · 124 unmodified lines
944952
945953 maybeEditVoxelUnderCursor();
946954
947− if (!_palette.isActive()) {
955+ if (!_palette.isActive() && (!_isHoverVoxel || _isLookingAtOtherAvatar)) {
948956 _pieMenu.mousePressEvent(_mouseX, _mouseY);
949957 }
950958
@@ -953,7 +961,16 @@ void Application::mousePressEvent(QMouseEvent* event) { · 2 unmodified lines
953961 _hoverVoxelOriginalColor[1] = _hoverVoxel.green;
954962 _hoverVoxelOriginalColor[2] = _hoverVoxel.blue;
955963 _hoverVoxelOriginalColor[3] = 1;
956− _audio.startCollisionSound(1.0, HOVER_VOXEL_FREQUENCY * _hoverVoxel.s * TREE_SCALE, 0.0, HOVER_VOXEL_DECAY);
964+ const float RED_CLICK_FREQUENCY = 1000.f;
965+ const float GREEN_CLICK_FREQUENCY = 1250.f;
966+ const float BLUE_CLICK_FREQUENCY = 1330.f;
967+ const float MIDDLE_A_FREQUENCY = 440.f;
968+ float frequency = MIDDLE_A_FREQUENCY +
969+ (_hoverVoxel.red / 255.f * RED_CLICK_FREQUENCY +
970+ _hoverVoxel.green / 255.f * GREEN_CLICK_FREQUENCY +
971+ _hoverVoxel.blue / 255.f * BLUE_CLICK_FREQUENCY) / 3.f;
972+
973+ _audio.startCollisionSound(1.0, frequency, 0.0, HOVER_VOXEL_DECAY);
957974 _isHoverVoxelSounding = true;
958975 }
959976
@@ -1161,6 +1178,11 @@ void Application::terminate() { · 201 unmodified lines
11611178 _stopNetworkReceiveThread = true;
11621179 pthread_join(_networkReceiveThread, NULL);
11631180 }
1181+
1182+ if (_enableProcessVoxelsThread) {
1183+ _stopProcessVoxelsThread = true;
1184+ pthread_join(_processVoxelsThread, NULL);
1185+ }
11641186 }
11651187
11661188 void Application::sendAvatarVoxelURLMessage(const QUrl& url) {
@@ -1182,6 +1204,13 @@ void Application::sendAvatarVoxelURLMessage(const QUrl& url) { · 15 unmodified lines
11821204 }
11831205
11841206 static Avatar* processAvatarMessageHeader(unsigned char*& packetData, size_t& dataBytes) {
1207+ // record the packet for stats-tracking
1208+ Application::getInstance()->getBandwidthMeter()->inputStream(BandwidthMeter::AVATARS).updateValue(dataBytes);
1209+ Node* avatarMixerNode = NodeList::getInstance()->soloNodeOfType(NODE_TYPE_AVATAR_MIXER);
1210+ if (avatarMixerNode) {
1211+ avatarMixerNode->recordBytesReceived(dataBytes);
1212+ }
1213+
11851214 // skip the header
11861215 int numBytesPacketHeader = numBytesForPacketHeader(packetData);
11871216 packetData += numBytesPacketHeader;
@@ -1285,15 +1314,15 @@ void Application::editPreferences() { · 97 unmodified lines
12851314 avatarURL->setMinimumWidth(QLINE_MINIMUM_WIDTH);
12861315 form->addRow("Avatar URL:", avatarURL);
12871316
1288− QSpinBox* horizontalFieldOfView = new QSpinBox();
1289− horizontalFieldOfView->setMaximum(180);
1290− horizontalFieldOfView->setMinimum(1);
1291− horizontalFieldOfView->setValue(_horizontalFieldOfView);
1292− form->addRow("Horizontal field of view (degrees):", horizontalFieldOfView);
1317+ QSpinBox* fieldOfView = new QSpinBox();
1318+ fieldOfView->setMaximum(180);
1319+ fieldOfView->setMinimum(1);
1320+ fieldOfView->setValue(_fieldOfView);
1321+ form->addRow("Vertical Field of View (Degrees):", fieldOfView);
12931322
1294− QDoubleSpinBox* headCameraPitchYawScale = new QDoubleSpinBox();
1295− headCameraPitchYawScale->setValue(_headCameraPitchYawScale);
1296− form->addRow("Head Camera Pitch/Yaw Scale:", headCameraPitchYawScale);
1323+ QDoubleSpinBox* gyroCameraSensitivity = new QDoubleSpinBox();
1324+ gyroCameraSensitivity->setValue(_gyroCameraSensitivity);
1325+ form->addRow("Gyro Camera Sensitivity (0 - 1):", gyroCameraSensitivity);
12971326
12981327 QDoubleSpinBox* leanScale = new QDoubleSpinBox();
12991328 leanScale->setValue(_myAvatar.getLeanScale());
@@ -1343,13 +1372,13 @@ void Application::editPreferences() { · 43 unmodified lines
13431372 _myAvatar.getVoxels()->setVoxelURL(url);
13441373 sendAvatarVoxelURLMessage(url);
13451374
1346− _headCameraPitchYawScale = headCameraPitchYawScale->value();
1375+ _gyroCameraSensitivity = gyroCameraSensitivity->value();
13471376 _myAvatar.setLeanScale(leanScale->value());
13481377 _audioJitterBufferSamples = audioJitterBufferSamples->value();
13491378 if (!shouldDynamicallySetJitterBuffer()) {
13501379 _audio.setJitterBufferSamples(_audioJitterBufferSamples);
13511380 }
1352− _horizontalFieldOfView = horizontalFieldOfView->value();
1381+ _fieldOfView = fieldOfView->value();
13531382 resizeGL(_glWidget->width(), _glWidget->height());
13541383
13551384 }
@@ -1379,6 +1408,8 @@ void Application::setRenderFirstPerson(bool firstPerson) { · 23 unmodified lines
13791408 if (firstPerson) {
13801409 _lookingInMirror->setChecked(false);
13811410 _manualThirdPerson->setChecked(false);
1411+ } else {
1412+ _manualThirdPerson->trigger();
13821413 }
13831414 }
13841415
@@ -1476,8 +1507,8 @@ void Application::doTreeStats() { · 91 unmodified lines
14761507 _voxels.collectStatsForTreesAndVBOs();
14771508 }
14781509
1479−void Application::setWantsLowResMoving(bool wantsLowResMoving) {
1480− _myAvatar.setWantLowResMoving(wantsLowResMoving);
1510+void Application::disableLowResMoving(bool disableLowResMoving) {
1511+ _myAvatar.setWantLowResMoving(!disableLowResMoving);
14811512 }
14821513
14831514 void Application::setWantsMonochrome(bool wantsMonochrome) {
@@ -1944,8 +1975,11 @@ void Application::initMenu() { · 460 unmodified lines
19441975 _testPing->setChecked(true);
19451976 (_fullScreenMode = optionsMenu->addAction("Fullscreen", this, SLOT(setFullscreen(bool)), Qt::Key_F))->setCheckable(true);
19461977 optionsMenu->addAction("Webcam", &_webcam, SLOT(setEnabled(bool)))->setCheckable(true);
1947− optionsMenu->addAction("Toggle Skeleton Tracking", &_webcam, SLOT(setSkeletonTrackingOn(bool)))->setCheckable(true);
1978+ optionsMenu->addAction("Skeleton Tracking", &_webcam, SLOT(setSkeletonTrackingOn(bool)))->setCheckable(true);
1979+ (_wantCollisionsOn = optionsMenu->addAction("Turn collisions On", this, SLOT(toggleWantCollisionsOn())))->setCheckable(true);
1980+ _wantCollisionsOn->setChecked(true);
19481981 optionsMenu->addAction("Cycle Webcam Send Mode", _webcam.getGrabber(), SLOT(cycleVideoSendMode()));
1982+ optionsMenu->addAction("Webcam Texture", _webcam.getGrabber(), SLOT(setDepthOnly(bool)))->setCheckable(true);
19491983 optionsMenu->addAction("Go Home", this, SLOT(goHome()), Qt::CTRL | Qt::Key_G);
19501984
19511985 QMenu* audioMenu = menuBar->addMenu("Audio");
@@ -2045,8 +2079,6 @@ void Application::initMenu() { · 93 unmodified lines
20452079 QMenu* frustumMenu = debugMenu->addMenu("View Frustum Debugging Tools");
20462080 (_frustumOn = frustumMenu->addAction("Display Frustum"))->setCheckable(true);
20472081 _frustumOn->setShortcut(Qt::SHIFT | Qt::Key_F);
2048− (_viewFrustumFromOffset = frustumMenu->addAction(
2049− "Use Offset Camera", this, SLOT(setFrustumOffset(bool)), Qt::SHIFT | Qt::Key_O))->setCheckable(true);
20502082 _frustumRenderModeAction = frustumMenu->addAction(
20512083 "Render Mode", this, SLOT(cycleFrustumRenderMode()), Qt::SHIFT | Qt::Key_R);
20522084 updateFrustumRenderModeAction();
@@ -2055,7 +2087,8 @@ void Application::initMenu() { · 2 unmodified lines
20552087 debugMenu->addAction("Calculate Tree Stats", this, SLOT(doTreeStats()), Qt::SHIFT | Qt::Key_S);
20562088
20572089 QMenu* renderDebugMenu = debugMenu->addMenu("Render Debugging Tools");
2058− renderDebugMenu->addAction("Show Render Pipeline Warnings", this, SLOT(setRenderWarnings(bool)))->setCheckable(true);
2090+ (_renderPipelineWarnings = renderDebugMenu->addAction("Show Render Pipeline Warnings",
2091+ this, SLOT(setRenderWarnings(bool))))->setCheckable(true);
20592092 renderDebugMenu->addAction("Kill Local Voxels", this, SLOT(doKillLocalVoxels()), Qt::CTRL | Qt::Key_K);
20602093 renderDebugMenu->addAction("Randomize Voxel TRUE Colors", this, SLOT(doRandomizeVoxelColors()), Qt::CTRL | Qt::Key_R);
20612094 renderDebugMenu->addAction("FALSE Color Voxels Randomly", this, SLOT(doFalseRandomizeVoxelColors()));
@@ -2070,7 +2103,7 @@ void Application::initMenu() { · 8 unmodified lines
20702103 (_shouldLowPassFilter = debugMenu->addAction("Test: LowPass filter"))->setCheckable(true);
20712104
20722105 debugMenu->addAction("Wants Monochrome", this, SLOT(setWantsMonochrome(bool)))->setCheckable(true);
2073− debugMenu->addAction("Use Lower Resolution While Moving", this, SLOT(setWantsLowResMoving(bool)))->setCheckable(true);
2106+ debugMenu->addAction("Disable Lower Resolution While Moving", this, SLOT(disableLowResMoving(bool)))->setCheckable(true);
20742107 debugMenu->addAction("Disable Delta Sending", this, SLOT(disableDeltaSending(bool)))->setCheckable(true);
20752108 (_occlusionCulling = debugMenu->addAction("Disable Occlusion Culling", this, SLOT(disableOcclusionCulling(bool)),
20762109 Qt::SHIFT | Qt::Key_C))->setCheckable(true);
@@ -2138,6 +2171,10 @@ void Application::toggleMixedSong() { · 61 unmodified lines
21382171 }
21392172 }
21402173
2174+void Application::toggleWantCollisionsOn() {
2175+ _myAvatar.setWantCollisionsOn(_wantCollisionsOn->isChecked());
2176+}
2177+
21412178 void Application::resetSongMixMenuItem() {
21422179 if (_audio.getSongFileBytes() == 0) {
21432180 _rawAudioMicrophoneMix->setText("Mix RAW Song");
@@ -2288,6 +2325,56 @@ void Application::renderLookatIndicator(glm::vec3 pointOfInterest, Camera& which · 144 unmodified lines
22882325 renderCircle(haloOrigin, INDICATOR_RADIUS, IDENTITY_UP, NUM_SEGMENTS);
22892326 }
22902327
2328+void Application::renderFollowIndicator() {
2329+ NodeList* nodeList = NodeList::getInstance();
2330+
2331+ glLineWidth(5);
2332+ glBegin(GL_LINES);
2333+ for (NodeList::iterator node = nodeList->begin(); node != nodeList->end(); ++node) {
2334+ if (node->getLinkedData() != NULL && node->getType() == NODE_TYPE_AGENT) {
2335+ Avatar* avatar = (Avatar *) node->getLinkedData();
2336+ Avatar* leader = NULL;
2337+
2338+ if (avatar->getLeaderID() != UNKNOWN_NODE_ID) {
2339+ if (avatar->getLeaderID() == NodeList::getInstance()->getOwnerID()) {
2340+ leader = &_myAvatar;
2341+ } else {
2342+ for (NodeList::iterator it = nodeList->begin(); it != nodeList->end(); ++it) {
2343+ if(it->getNodeID() == avatar->getLeaderID()
2344+ && it->getType() == NODE_TYPE_AGENT) {
2345+ leader = (Avatar*) it->getLinkedData();
2346+ }
2347+ }
2348+ }
2349+
2350+ if (leader != NULL) {
2351+ glColor3f(1.f, 0.f, 0.f);
2352+ glVertex3f((avatar->getHead().getPosition().x + avatar->getPosition().x) / 2.f,
2353+ (avatar->getHead().getPosition().y + avatar->getPosition().y) / 2.f,
2354+ (avatar->getHead().getPosition().z + avatar->getPosition().z) / 2.f);
2355+ glColor3f(0.f, 1.f, 0.f);
2356+ glVertex3f((leader->getHead().getPosition().x + leader->getPosition().x) / 2.f,
2357+ (leader->getHead().getPosition().y + leader->getPosition().y) / 2.f,
2358+ (leader->getHead().getPosition().z + leader->getPosition().z) / 2.f);
2359+ }
2360+ }
2361+ }
2362+ }
2363+
2364+ if (_myAvatar.getLeadingAvatar() != NULL) {
2365+ glColor3f(1.f, 0.f, 0.f);
2366+ glVertex3f((_myAvatar.getHead().getPosition().x + _myAvatar.getPosition().x) / 2.f,
2367+ (_myAvatar.getHead().getPosition().y + _myAvatar.getPosition().y) / 2.f,
2368+ (_myAvatar.getHead().getPosition().z + _myAvatar.getPosition().z) / 2.f);
2369+ glColor3f(0.f, 1.f, 0.f);
2370+ glVertex3f((_myAvatar.getLeadingAvatar()->getHead().getPosition().x + _myAvatar.getLeadingAvatar()->getPosition().x) / 2.f,
2371+ (_myAvatar.getLeadingAvatar()->getHead().getPosition().y + _myAvatar.getLeadingAvatar()->getPosition().y) / 2.f,
2372+ (_myAvatar.getLeadingAvatar()->getHead().getPosition().z + _myAvatar.getLeadingAvatar()->getPosition().z) / 2.f);
2373+ }
2374+
2375+ glEnd();
2376+}
2377+
22912378 void Application::update(float deltaTime) {
22922379
22932380 // Use Transmitter Hand to move hand if connected, else use mouse
@@ -2473,7 +2560,7 @@ void Application::update(float deltaTime) { · 179 unmodified lines
24732560 }
24742561
24752562 // Leap finger-sensing device
2476− LeapManager::enableFakeFingers(_simulateLeapHand->isChecked() || _testRaveGlove->isChecked());
2563+ LeapManager::enableFakeFingers(_simulateLeapHand->isChecked());
24772564 _myAvatar.getHand().setRaveGloveActive(_testRaveGlove->isChecked());
24782565 LeapManager::nextFrame(_myAvatar);
24792566
@@ -2491,6 +2578,11 @@ void Application::update(float deltaTime) { · 11 unmodified lines
24912578 if (!_enableNetworkThread) {
24922579 networkReceive(0);
24932580 }
2581+
2582+ // parse voxel packets
2583+ if (!_enableProcessVoxelsThread) {
2584+ processVoxels(0);
2585+ }
24942586
24952587 //loop through all the other avatars and simulate them...
24962588 NodeList* nodeList = NodeList::getInstance();
@@ -2501,7 +2593,7 @@ void Application::update(float deltaTime) { · 4 unmodified lines
25012593 if (!avatar->isInitialized()) {
25022594 avatar->init();
25032595 }
2504− avatar->simulate(deltaTime, NULL);
2596+ avatar->simulate(deltaTime, NULL, 0.f);
25052597 avatar->setMouseRay(mouseRayOrigin, mouseRayDirection);
25062598 }
25072599 node->unlock();
@@ -2516,13 +2608,11 @@ void Application::update(float deltaTime) { · 8 unmodified lines
25162608 }
25172609
25182610 if (_transmitterDrives->isChecked() && _myTransmitter.isConnected()) {
2519− _myAvatar.simulate(deltaTime, &_myTransmitter);
2611+ _myAvatar.simulate(deltaTime, &_myTransmitter, _gyroCameraSensitivity);
25202612 } else {
2521− _myAvatar.simulate(deltaTime, NULL);
2613+ _myAvatar.simulate(deltaTime, NULL, _gyroCameraSensitivity);
25222614 }
25232615
2524− _myAvatar.getHand().simulate(deltaTime, true);
2525−
25262616 if (!OculusManager::isConnected()) {
25272617 if (_lookingInMirror->isChecked()) {
25282618 if (_myCamera.getMode() != CAMERA_MODE_MIRROR) {
@@ -2575,7 +2665,7 @@ void Application::update(float deltaTime) { · 46 unmodified lines
25752665
25762666 if (_renderParticleSystemOn->isChecked()) {
25772667 updateParticleSystem(deltaTime);
2578− }
2668+ }
25792669 }
25802670
25812671 void Application::updateAvatar(float deltaTime) {
@@ -2587,10 +2677,6 @@ void Application::updateAvatar(float deltaTime) { · 5 unmodified lines
25872677
25882678 // Update my avatar's state from gyros and/or webcam
25892679 _myAvatar.updateFromGyrosAndOrWebcam(_gyroLook->isChecked(),
2590− glm::vec3(_headCameraPitchYawScale,
2591− _headCameraPitchYawScale,
2592− _headCameraPitchYawScale),
2593− 0.f,
25942680 _pitchFromTouch);
25952681
25962682 if (_serialHeadSensor.isActive()) {
@@ -2682,7 +2768,7 @@ void Application::updateAvatar(float deltaTime) { · 85 unmodified lines
26822768
26832769 // If I'm in paint mode, send a voxel out to VOXEL server nodes.
26842770 if (_paintOn) {
2685−
2771+
26862772 glm::vec3 avatarPos = _myAvatar.getPosition();
26872773
26882774 // For some reason, we don't want to flip X and Z here.
@@ -2693,7 +2779,7 @@ void Application::updateAvatar(float deltaTime) { · 4 unmodified lines
26932779 if (_paintingVoxel.x >= 0.0 && _paintingVoxel.x <= 1.0 &&
26942780 _paintingVoxel.y >= 0.0 && _paintingVoxel.y <= 1.0 &&
26952781 _paintingVoxel.z >= 0.0 && _paintingVoxel.z <= 1.0) {
2696−
2782+
26972783 PACKET_TYPE message = (_destructiveAddVoxel->isChecked() ?
26982784 PACKET_TYPE_SET_VOXEL_DESTRUCTIVE : PACKET_TYPE_SET_VOXEL);
26992785 sendVoxelEditMessage(message, _paintingVoxel);
@@ -2713,6 +2799,7 @@ void Application::loadViewFrustum(Camera& camera, ViewFrustum& viewFrustum) { · 13 unmodified lines
27132799 float fov = camera.getFieldOfView();
27142800 float nearClip = camera.getNearClip();
27152801 float farClip = camera.getFarClip();
2802+ float aspectRatio = camera.getAspectRatio();
27162803
27172804 glm::quat rotation = camera.getRotation();
27182805
@@ -2721,6 +2808,7 @@ void Application::loadViewFrustum(Camera& camera, ViewFrustum& viewFrustum) { · 2 unmodified lines
27212808 viewFrustum.setOrientation(rotation);
27222809
27232810 // Also make sure it's got the correct lens details from the camera
2811+ viewFrustum.setAspectRatio(aspectRatio);
27242812 viewFrustum.setFieldOfView(fov);
27252813 viewFrustum.setNearClip(nearClip);
27262814 viewFrustum.setFarClip(farClip);
@@ -2877,6 +2965,29 @@ void Application::displayOculus(Camera& whichCamera) { · 150 unmodified lines
28772965 glPopMatrix();
28782966 }
28792967
2968+const GLfloat WHITE_SPECULAR_COLOR[] = { 1.0f, 1.0f, 1.0f, 1.0f };
2969+const GLfloat NO_SPECULAR_COLOR[] = { 0.0f, 0.0f, 0.0f, 1.0f };
2970+
2971+void Application::setupWorldLight(Camera& whichCamera) {
2972+
2973+ // Setup 3D lights (after the camera transform, so that they are positioned in world space)
2974+ glEnable(GL_COLOR_MATERIAL);
2975+ glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
2976+
2977+ glm::vec3 relativeSunLoc = glm::normalize(_environment.getClosestData(whichCamera.getPosition()).getSunLocation() -
2978+ whichCamera.getPosition());
2979+ GLfloat light_position0[] = { relativeSunLoc.x, relativeSunLoc.y, relativeSunLoc.z, 0.0 };
2980+ glLightfv(GL_LIGHT0, GL_POSITION, light_position0);
2981+ GLfloat ambient_color[] = { 0.7, 0.7, 0.8 };
2982+ glLightfv(GL_LIGHT0, GL_AMBIENT, ambient_color);
2983+ GLfloat diffuse_color[] = { 0.8, 0.7, 0.7 };
2984+ glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse_color);
2985+
2986+ glLightfv(GL_LIGHT0, GL_SPECULAR, WHITE_SPECULAR_COLOR);
2987+ glMaterialfv(GL_FRONT, GL_SPECULAR, WHITE_SPECULAR_COLOR);
2988+ glMateriali(GL_FRONT, GL_SHININESS, 96);
2989+}
2990+
28802991 void Application::displaySide(Camera& whichCamera) {
28812992 // transform by eye offset
28822993
@@ -2906,22 +3017,7 @@ void Application::displaySide(Camera& whichCamera) { · 23 unmodified lines
29063017 glTranslatef(-whichCamera.getPosition().x, -whichCamera.getPosition().y, -whichCamera.getPosition().z);
29073018
29083019 // Setup 3D lights (after the camera transform, so that they are positioned in world space)
2909− glEnable(GL_COLOR_MATERIAL);
2910− glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
2911−
2912− glm::vec3 relativeSunLoc = glm::normalize(_environment.getClosestData(whichCamera.getPosition()).getSunLocation() -
2913− whichCamera.getPosition());
2914− GLfloat light_position0[] = { relativeSunLoc.x, relativeSunLoc.y, relativeSunLoc.z, 0.0 };
2915− glLightfv(GL_LIGHT0, GL_POSITION, light_position0);
2916− GLfloat ambient_color[] = { 0.7, 0.7, 0.8 };
2917− glLightfv(GL_LIGHT0, GL_AMBIENT, ambient_color);
2918− GLfloat diffuse_color[] = { 0.8, 0.7, 0.7 };
2919− glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse_color);
2920− GLfloat specular_color[] = { 1.0, 1.0, 1.0, 1.0};
2921− glLightfv(GL_LIGHT0, GL_SPECULAR, specular_color);
2922−
2923− glMaterialfv(GL_FRONT, GL_SPECULAR, specular_color);
2924− glMateriali(GL_FRONT, GL_SHININESS, 96);
3020+ setupWorldLight(whichCamera);
29253021
29263022 if (_renderStarsOn->isChecked()) {
29273023 if (!_stars.getFileLoaded()) {
@@ -2966,6 +3062,9 @@ void Application::displaySide(Camera& whichCamera) { · 38 unmodified lines
29663062 glutSolidSphere(sphereRadius, 15, 15);
29673063 glPopMatrix();
29683064
3065+ // disable specular lighting for ground and voxels
3066+ glMaterialfv(GL_FRONT, GL_SPECULAR, NO_SPECULAR_COLOR);
3067+
29693068 //draw a grid ground plane....
29703069 if (_renderGroundPlaneOn->isChecked()) {
29713070 // draw grass plane with fog
@@ -2987,13 +3086,16 @@ void Application::displaySide(Camera& whichCamera) { · 15 unmodified lines
29873086 glDisable(GL_FOG);
29883087 glDisable(GL_NORMALIZE);
29893088
2990− renderGroundPlaneGrid(EDGE_SIZE_GROUND_PLANE, _audio.getCollisionSoundMagnitude());
3089+ //renderGroundPlaneGrid(EDGE_SIZE_GROUND_PLANE, _audio.getCollisionSoundMagnitude());
29913090 }
29923091 // Draw voxels
29933092 if (_renderVoxels->isChecked()) {
29943093 _voxels.render(_renderVoxelTextures->isChecked());
29953094 }
29963095
3096+ // restore default, white specular
3097+ glMaterialfv(GL_FRONT, GL_SPECULAR, WHITE_SPECULAR_COLOR);
3098+
29973099 // indicate what we'll be adding/removing in mouse mode, if anything
29983100 if (_mouseVoxel.s != 0) {
29993101 glDisable(GL_LIGHTING);
@@ -3016,6 +3118,8 @@ void Application::displaySide(Camera& whichCamera) { · 16 unmodified lines
30163118 glEnable(GL_LIGHTING);
30173119 }
30183120
3121+ _myAvatar.renderScreenTint(SCREEN_TINT_BEFORE_AVATARS, whichCamera);
3122+
30193123 if (_renderAvatarsOn->isChecked()) {
30203124 // Render avatars of other nodes
30213125 NodeList* nodeList = NodeList::getInstance();
@@ -3041,7 +3145,7 @@ void Application::displaySide(Camera& whichCamera) { · 19 unmodified lines
30413145 // Render my own Avatar
30423146 if (_myCamera.getMode() == CAMERA_MODE_MIRROR) {
30433147 _myAvatar.getHead().setLookAtPosition(_myCamera.getPosition());
3044− }
3148+ }
30453149 _myAvatar.render(_lookingInMirror->isChecked(), _renderAvatarBalls->isChecked());
30463150 _myAvatar.setDisplayingLookatVectors(_renderLookatOn->isChecked());
30473151
@@ -3050,6 +3154,8 @@ void Application::displaySide(Camera& whichCamera) { · 2 unmodified lines
30503154 }
30513155 }
30523156
3157+ _myAvatar.renderScreenTint(SCREEN_TINT_AFTER_AVATARS, whichCamera);
3158+
30533159 if (_renderParticleSystemOn->isChecked()) {
30543160 if (_particleSystemInitialized) {
30553161 _particleSystem.render();
@@ -3061,6 +3167,20 @@ void Application::displaySide(Camera& whichCamera) { · 5 unmodified lines
30613167
30623168 // brad's frustum for debugging
30633169 if (_frustumOn->isChecked()) renderViewFrustum(_viewFrustum);
3170+
3171+ // render voxel fades if they exist
3172+ if (_voxelFades.size() > 0) {
3173+ for(std::vector<VoxelFade>::iterator fade = _voxelFades.begin(); fade != _voxelFades.end();) {
3174+ fade->render();
3175+ if(fade->isDone()) {
3176+ fade = _voxelFades.erase(fade);
3177+ } else {
3178+ ++fade;
3179+ }
3180+ }
3181+ }
3182+
3183+ renderFollowIndicator();
30643184 }
30653185
30663186 void Application::displayOverlay() {
@@ -3220,7 +3340,7 @@ void Application::displayStats() { · 153 unmodified lines
32203340 int statsVerticalOffset = 8;
32213341
32223342 char stats[200];
3223− sprintf(stats, "%3.0f FPS, %d Pkts/sec, %3.2f Mbps",
3343+ sprintf(stats, "%3.0f FPS, %d Pkts/sec, %3.2f Mbps ",
32243344 _fps, _packetsPerSecond, (float)_bytesPerSecond * 8.f / 1000000.f);
32253345 drawtext(10, statsVerticalOffset + 15, 0.10f, 0, 1.0, 0, stats);
32263346
@@ -3251,11 +3371,16 @@ void Application::displayStats() { · 24 unmodified lines
32513371 pingVoxel = totalPingVoxel/voxelServerCount;
32523372 }
32533373
3254−
32553374 char pingStats[200];
32563375 sprintf(pingStats, "Ping audio/avatar/voxel: %d / %d / %d avg %d max ", pingAudio, pingAvatar, pingVoxel, pingVoxelMax);
32573376 drawtext(10, statsVerticalOffset + 35, 0.10f, 0, 1.0, 0, pingStats);
32583377 }
3378+
3379+ char avatarStats[200];
3380+ glm::vec3 avatarPos = _myAvatar.getPosition();
3381+ sprintf(avatarStats, "Avatar position: %.3f, %.3f, %.3f, yaw = %.2f", avatarPos.x, avatarPos.y, avatarPos.z, _myAvatar.getBodyYaw());
3382+ drawtext(10, statsVerticalOffset + 55, 0.10f, 0, 1.0, 0, avatarStats);
3383+
32593384
32603385 std::stringstream voxelStats;
32613386 voxelStats.precision(4);
@@ -3276,6 +3401,11 @@ void Application::displayStats() { · 14 unmodified lines
32763401 voxelDetails = _voxelSceneStats.getItemValue(VoxelSceneStats::ITEM_ENCODE);
32773402 voxelStats << "Encode Time on Server: " << voxelDetails;
32783403 drawtext(10, statsVerticalOffset + 290, 0.10f, 0, 1.0, 0, (char *)voxelStats.str().c_str());
3404+
3405+ voxelStats.str("");
3406+ voxelDetails = _voxelSceneStats.getItemValue(VoxelSceneStats::ITEM_MODE);
3407+ voxelStats << "Sending Mode: " << voxelDetails;
3408+ drawtext(10, statsVerticalOffset + 310, 0.10f, 0, 1.0, 0, (char *)voxelStats.str().c_str());
32793409
32803410 Node *avatarMixer = NodeList::getInstance()->soloNodeOfType(NODE_TYPE_AVATAR_MIXER);
32813411 char avatarMixerStats[200];
@@ -3628,6 +3758,62 @@ void Application::shiftPaintingColor() { · 346 unmodified lines
36283758 }
36293759
36303760
3761+void Application::injectVoxelAddedSoundEffect() {
3762+ AudioInjector* voxelInjector = AudioInjectionManager::injectorWithCapacity(11025);
3763+
3764+ if (voxelInjector) {
3765+ voxelInjector->setPosition(glm::vec3(_mouseVoxel.x, _mouseVoxel.y, _mouseVoxel.z));
3766+ //voxelInjector->setBearing(-1 * _myAvatar.getAbsoluteHeadYaw());
3767+ voxelInjector->setVolume (16 * pow (_mouseVoxel.s, 2) / .0000001); //255 is max, and also default value
3768+
3769+ /* for (int i = 0; i
3770+ < 22050; i++) {
3771+ if (i % 4 == 0) {
3772+ voxelInjector->addSample(4000);
3773+ } else if (i % 4 == 1) {
3774+ voxelInjector->addSample(0);
3775+ } else if (i % 4 == 2) {
3776+ voxelInjector->addSample(-4000);
3777+ } else {
3778+ voxelInjector->addSample(0);
3779+ }
3780+ */
3781+
3782+ const float BIG_VOXEL_MIN_SIZE = .01f;
3783+
3784+ for (int i = 0; i < 11025; i++) {
3785+
3786+ /*
3787+ A440 square wave
3788+ if (sin(i * 2 * PIE / 50)>=0) {
3789+ voxelInjector->addSample(4000);
3790+ } else {
3791+ voxelInjector->addSample(-4000);
3792+ }
3793+ */
3794+
3795+ if (_mouseVoxel.s > BIG_VOXEL_MIN_SIZE) {
3796+ voxelInjector->addSample(20000 * sin((i * 2 * PIE) / (500 * sin((i + 1) / 200))));
3797+ } else {
3798+ voxelInjector->addSample(16000 * sin(i / (1.5 * log (_mouseVoxel.s / .0001) * ((i + 11025) / 5512.5)))); //808
3799+ }
3800+ }
3801+
3802+ //voxelInjector->addSample(32500 * sin(i/(2 * 1 * ((i+5000)/5512.5)))); //80
3803+ //voxelInjector->addSample(20000 * sin(i/(6 * (_mouseVoxel.s/.001) *((i+5512.5)/5512.5)))); //808
3804+ //voxelInjector->addSample(20000 * sin(i/(6 * ((i+5512.5)/5512.5)))); //808
3805+ //voxelInjector->addSample(4000 * sin(i * 2 * PIE /50)); //A440 sine wave
3806+ //voxelInjector->addSample(4000 * sin(i * 2 * PIE /50) * sin (i/500)); //A440 sine wave with amplitude modulation
3807+
3808+ //FM library
3809+ //voxelInjector->addSample(20000 * sin((i * 2 * PIE) /(500*sin((i+1)/200)))); //FM 1 dubstep
3810+ //voxelInjector->addSample(20000 * sin((i * 2 * PIE) /(300*sin((i+1)/5.0)))); //FM 2 flange sweep
3811+ //voxelInjector->addSample(10000 * sin((i * 2 * PIE) /(500*sin((i+1)/500.0)))); //FM 3 resonant pulse
3812+
3813+ AudioInjectionManager::threadInjector(voxelInjector);
3814+ }
3815+}
3816+
36313817 bool Application::maybeEditVoxelUnderCursor() {
36323818 if (_addVoxelMode->isChecked() || _colorVoxelMode->isChecked()) {
36333819 if (_mouseVoxel.s != 0) {
@@ -3638,65 +3824,35 @@ bool Application::maybeEditVoxelUnderCursor() { · 4 unmodified lines
36383824 // create the voxel locally so it appears immediately
36393825 _voxels.createVoxel(_mouseVoxel.x, _mouseVoxel.y, _mouseVoxel.z, _mouseVoxel.s,
36403826 _mouseVoxel.red, _mouseVoxel.green, _mouseVoxel.blue, _destructiveAddVoxel->isChecked());
3827+
3828+ // Implement voxel fade effect
3829+ VoxelFade fade(VoxelFade::FADE_OUT, 1.0f, 1.0f, 1.0f);
3830+ const float VOXEL_BOUNDS_ADJUST = 0.01f;
3831+ float slightlyBigger = _mouseVoxel.s * VOXEL_BOUNDS_ADJUST;
3832+ fade.voxelDetails.x = _mouseVoxel.x - slightlyBigger;
3833+ fade.voxelDetails.y = _mouseVoxel.y - slightlyBigger;
3834+ fade.voxelDetails.z = _mouseVoxel.z - slightlyBigger;
3835+ fade.voxelDetails.s = _mouseVoxel.s + slightlyBigger + slightlyBigger;
3836+ _voxelFades.push_back(fade);
3837+
3838+ // inject a sound effect
3839+ injectVoxelAddedSoundEffect();
36413840
36423841 // remember the position for drag detection
36433842 _justEditedVoxel = true;
36443843
3645− AudioInjector* voxelInjector = AudioInjectionManager::injectorWithCapacity(11025);
3646− voxelInjector->setPosition(glm::vec3(_mouseVoxel.x, _mouseVoxel.y, _mouseVoxel.z));
3647− //_myAvatar.getPosition()
3648−// voxelInjector->setBearing(-1 * _myAvatar.getAbsoluteHeadYaw());
3649− voxelInjector->setVolume (16 * pow (_mouseVoxel.s, 2) / .0000001); //255 is max, and also default value
3650−
3651− /* for (int i = 0; i
3652− < 22050; i++) {
3653− if (i % 4 == 0) {
3654− voxelInjector->addSample(4000);
3655− } else if (i % 4 == 1) {
3656− voxelInjector->addSample(0);
3657− } else if (i % 4 == 2) {
3658− voxelInjector->addSample(-4000);
3659− } else {
3660− voxelInjector->addSample(0);
3661− }
3662− */
3663−
3664−
3665− const float BIG_VOXEL_MIN_SIZE = .01f;
3666−
3667− for (int i = 0; i < 11025; i++) {
3668−
3669− /*
3670− A440 square wave
3671− if (sin(i * 2 * PIE / 50)>=0) {
3672− voxelInjector->addSample(4000);
3673− } else {
3674− voxelInjector->addSample(-4000);
3675− }
3676− */
3677−
3678− if (_mouseVoxel.s > BIG_VOXEL_MIN_SIZE) {
3679− voxelInjector->addSample(20000 * sin((i * 2 * PIE) / (500 * sin((i + 1) / 200))));
3680− } else {
3681− voxelInjector->addSample(16000 * sin(i / (1.5 * log (_mouseVoxel.s / .0001) * ((i + 11025) / 5512.5)))); //808
3682− }
3683− }
3684−
3685− //voxelInjector->addSample(32500 * sin(i/(2 * 1 * ((i+5000)/5512.5)))); //80
3686− //voxelInjector->addSample(20000 * sin(i/(6 * (_mouseVoxel.s/.001) *((i+5512.5)/5512.5)))); //808
3687− //voxelInjector->addSample(20000 * sin(i/(6 * ((i+5512.5)/5512.5)))); //808
3688− //voxelInjector->addSample(4000 * sin(i * 2 * PIE /50)); //A440 sine wave
3689− //voxelInjector->addSample(4000 * sin(i * 2 * PIE /50) * sin (i/500)); //A440 sine wave with amplitude modulation
3690−
3691− //FM library
3692− //voxelInjector->addSample(20000 * sin((i * 2 * PIE) /(500*sin((i+1)/200)))); //FM 1 dubstep
3693− //voxelInjector->addSample(20000 * sin((i * 2 * PIE) /(300*sin((i+1)/5.0)))); //FM 2 flange sweep
3694− //voxelInjector->addSample(10000 * sin((i * 2 * PIE) /(500*sin((i+1)/500.0)))); //FM 3 resonant pulse
3695−
3696− AudioInjectionManager::threadInjector(voxelInjector);
36973844 }
36983845 } else if (_deleteVoxelMode->isChecked()) {
36993846 deleteVoxelUnderCursor();
3847+ VoxelFade fade(VoxelFade::FADE_OUT, 1.0f, 1.0f, 1.0f);
3848+ const float VOXEL_BOUNDS_ADJUST = 0.01f;
3849+ float slightlyBigger = _mouseVoxel.s * VOXEL_BOUNDS_ADJUST;
3850+ fade.voxelDetails.x = _mouseVoxel.x - slightlyBigger;
3851+ fade.voxelDetails.y = _mouseVoxel.y - slightlyBigger;
3852+ fade.voxelDetails.z = _mouseVoxel.z - slightlyBigger;
3853+ fade.voxelDetails.s = _mouseVoxel.s + slightlyBigger + slightlyBigger;
3854+ _voxelFades.push_back(fade);
3855+
37003856 } else if (_eyedropperMode->isChecked()) {
37013857 eyedropperVoxelUnderCursor();
37023858 } else {
@@ -3711,17 +3867,20 @@ void Application::deleteVoxelUnderCursor() { · 8 unmodified lines
37113867 // sending delete to the server is sufficient, server will send new version so we see updates soon enough
37123868 sendVoxelEditMessage(PACKET_TYPE_ERASE_VOXEL, _mouseVoxel);
37133869 AudioInjector* voxelInjector = AudioInjectionManager::injectorWithCapacity(5000);
3714− voxelInjector->setPosition(glm::vec3(_mouseVoxel.x, _mouseVoxel.y, _mouseVoxel.z));
3715−// voxelInjector->setBearing(0); //straight down the z axis
3716− voxelInjector->setVolume (255); //255 is max, and also default value
37173870
3718−
3719− for (int i = 0; i < 5000; i++) {
3720− voxelInjector->addSample(10000 * sin((i * 2 * PIE) / (500 * sin((i + 1) / 500.0)))); //FM 3 resonant pulse
3721− //voxelInjector->addSample(20000 * sin((i) /((4 / _mouseVoxel.s) * sin((i)/(20 * _mouseVoxel.s / .001))))); //FM 2 comb filter
3871+ if (voxelInjector) {
3872+ voxelInjector->setPosition(glm::vec3(_mouseVoxel.x, _mouseVoxel.y, _mouseVoxel.z));
3873+ //voxelInjector->setBearing(0); //straight down the z axis
3874+ voxelInjector->setVolume (255); //255 is max, and also default value
3875+
3876+
3877+ for (int i = 0; i < 5000; i++) {
3878+ voxelInjector->addSample(10000 * sin((i * 2 * PIE) / (500 * sin((i + 1) / 500.0)))); //FM 3 resonant pulse
3879+ //voxelInjector->addSample(20000 * sin((i) /((4 / _mouseVoxel.s) * sin((i)/(20 * _mouseVoxel.s / .001))))); //FM 2 comb filter
3880+ }
3881+
3882+ AudioInjectionManager::threadInjector(voxelInjector);
37223883 }
3723−
3724− AudioInjectionManager::threadInjector(voxelInjector);
37253884 }
37263885 // remember the position for drag detection
37273886 _justEditedVoxel = true;
@@ -3818,6 +3977,133 @@ void Application::attachNewHeadToNode(Node* newNode) { · 90 unmodified lines
38183977 }
38193978 }
38203979
3980+void Application::nodeAdded(Node* node) {
3981+}
3982+
3983+void Application::nodeKilled(Node* node) {
3984+ if (node->getType() == NODE_TYPE_VOXEL_SERVER) {
3985+ uint16_t nodeID = node->getNodeID();
3986+ // see if this is the first we've heard of this node...
3987+ if (_voxelServerJurisdictions.find(nodeID) != _voxelServerJurisdictions.end()) {
3988+ VoxelPositionSize jurisditionDetails;
3989+ jurisditionDetails = _voxelServerJurisdictions[nodeID];
3990+
3991+ printf("voxel server going away...... v[%f, %f, %f, %f]\n",
3992+ jurisditionDetails.x, jurisditionDetails.y, jurisditionDetails.z, jurisditionDetails.s);
3993+
3994+ // Add the jurisditionDetails object to the list of "fade outs"
3995+ VoxelFade fade(VoxelFade::FADE_OUT, NODE_KILLED_RED, NODE_KILLED_GREEN, NODE_KILLED_BLUE);
3996+ fade.voxelDetails = jurisditionDetails;
3997+ const float slightly_smaller = 0.99;
3998+ fade.voxelDetails.s = fade.voxelDetails.s * slightly_smaller;
3999+ _voxelFades.push_back(fade);
4000+ }
4001+ }
4002+}
4003+
4004+int Application::parseVoxelStats(unsigned char* messageData, ssize_t messageLength, sockaddr senderAddress) {
4005+
4006+ // parse the incoming stats data, and stick it into our averaging stats object for now... even though this
4007+ // means mixing in stats from potentially multiple servers.
4008+ int statsMessageLength = _voxelSceneStats.unpackFromMessage(messageData, messageLength);
4009+
4010+ // But, also identify the sender, and keep track of the contained jurisdiction root for this server
4011+ Node* voxelServer = NodeList::getInstance()->nodeWithAddress(&senderAddress);
4012+
4013+ // quick fix for crash... why would voxelServer be NULL?
4014+ if (voxelServer) {
4015+ uint16_t nodeID = voxelServer->getNodeID();
4016+
4017+ VoxelPositionSize jurisditionDetails;
4018+ voxelDetailsForCode(_voxelSceneStats.getJurisdictionRoot(), jurisditionDetails);
4019+
4020+ // see if this is the first we've heard of this node...
4021+ if (_voxelServerJurisdictions.find(nodeID) == _voxelServerJurisdictions.end()) {
4022+ printf("stats from new voxel server... v[%f, %f, %f, %f]\n",
4023+ jurisditionDetails.x, jurisditionDetails.y, jurisditionDetails.z, jurisditionDetails.s);
4024+
4025+ // Add the jurisditionDetails object to the list of "fade outs"
4026+ VoxelFade fade(VoxelFade::FADE_OUT, NODE_ADDED_RED, NODE_ADDED_GREEN, NODE_ADDED_BLUE);
4027+ fade.voxelDetails = jurisditionDetails;
4028+ const float slightly_smaller = 0.99;
4029+ fade.voxelDetails.s = fade.voxelDetails.s * slightly_smaller;
4030+ _voxelFades.push_back(fade);
4031+ }
4032+ // store jurisdiction details for later use
4033+ _voxelServerJurisdictions[nodeID] = jurisditionDetails;
4034+ }
4035+ return statsMessageLength;
4036+}
4037+
4038+// Receive packets from other nodes/servers and decide what to do with them!
4039+void* Application::processVoxels(void* args) {
4040+ Application* app = Application::getInstance();
4041+ while (!app->_stopProcessVoxelsThread) {
4042+
4043+ // check to see if the UI thread asked us to kill the voxel tree. since we're the only thread allowed to do that
4044+ if (app->_wantToKillLocalVoxels) {
4045+ app->_voxels.killLocalVoxels();
4046+ app->_wantToKillLocalVoxels = false;
4047+ }
4048+
4049+ while (app->_voxelPackets.size() > 0) {
4050+ NetworkPacket& packet = app->_voxelPackets.front();
4051+ app->processVoxelPacket(packet.getSenderAddress(), packet.getData(), packet.getLength());
4052+ app->_voxelPackets.erase(app->_voxelPackets.begin());
4053+ }
4054+
4055+ if (!app->_enableProcessVoxelsThread) {
4056+ break;
4057+ }
4058+ }
4059+
4060+ if (app->_enableProcessVoxelsThread) {
4061+ pthread_exit(0);
4062+ }
4063+ return NULL;
4064+}
4065+
4066+void Application::queueVoxelPacket(sockaddr& senderAddress, unsigned char* packetData, ssize_t packetLength) {
4067+ _voxelPackets.push_back(NetworkPacket(senderAddress, packetData, packetLength));
4068+}
4069+
4070+void Application::processVoxelPacket(sockaddr& senderAddress, unsigned char* packetData, ssize_t packetLength) {
4071+ PerformanceWarning warn(_renderPipelineWarnings->isChecked(),"processVoxelPacket()");
4072+ ssize_t messageLength = packetLength;
4073+
4074+ // note: PACKET_TYPE_VOXEL_STATS can have PACKET_TYPE_VOXEL_DATA or PACKET_TYPE_VOXEL_DATA_MONOCHROME
4075+ // immediately following them inside the same packet. So, we process the PACKET_TYPE_VOXEL_STATS first
4076+ // then process any remaining bytes as if it was another packet
4077+ if (packetData[0] == PACKET_TYPE_VOXEL_STATS) {
4078+
4079+ int statsMessageLength = parseVoxelStats(packetData, messageLength, senderAddress);
4080+ if (messageLength > statsMessageLength) {
4081+ packetData += statsMessageLength;
4082+ messageLength -= statsMessageLength;
4083+ if (!packetVersionMatch(packetData)) {
4084+ return; // bail since piggyback data doesn't match our versioning
4085+ }
4086+ } else {
4087+ return; // bail since no piggyback data
4088+ }
4089+ } // fall through to piggyback message
4090+
4091+ if (_renderVoxels->isChecked()) {
4092+ Node* voxelServer = NodeList::getInstance()->nodeWithAddress(&senderAddress);
4093+ if (voxelServer && socketMatch(voxelServer->getActiveSocket(), &senderAddress)) {
4094+ voxelServer->lock();
4095+ if (packetData[0] == PACKET_TYPE_ENVIRONMENT_DATA) {
4096+ _environment.parseData(&senderAddress, packetData, messageLength);
4097+ } else {
4098+ _voxels.setDataSourceID(voxelServer->getNodeID());
4099+ _voxels.parseData(packetData, messageLength);
4100+ _voxels.setDataSourceID(UNKNOWN_NODE_ID);
4101+ }
4102+ voxelServer->unlock();
4103+ }
4104+ }
4105+}
4106+
38214107 // Receive packets from other nodes/servers and decide what to do with them!
38224108 void* Application::networkReceive(void* args) {
38234109 sockaddr senderAddress;
@@ -3853,40 +4139,8 @@ void* Application::networkReceive(void* args) { · 29 unmodified lines
38534139 case PACKET_TYPE_ERASE_VOXEL:
38544140 case PACKET_TYPE_VOXEL_STATS:
38554141 case PACKET_TYPE_ENVIRONMENT_DATA: {
3856−
3857− unsigned char* messageData = app->_incomingPacket;
3858− ssize_t messageLength = bytesReceived;
3859−
3860− // note: PACKET_TYPE_VOXEL_STATS can have PACKET_TYPE_VOXEL_DATA or PACKET_TYPE_VOXEL_DATA_MONOCHROME
3861− // immediately following them inside the same packet. So, we process the PACKET_TYPE_VOXEL_STATS first
3862− // then process any remaining bytes as if it was another packet
3863− if (messageData[0] == PACKET_TYPE_VOXEL_STATS) {
3864− int statsMessageLength = app->_voxelSceneStats.unpackFromMessage(messageData, messageLength);
3865− if (messageLength > statsMessageLength) {
3866− messageData += statsMessageLength;
3867− messageLength -= statsMessageLength;
3868− if (!packetVersionMatch(messageData)) {
3869− break; // bail since piggyback data doesn't match our versioning
3870− }
3871− } else {
3872− break; // bail since no piggyback data
3873− }
3874− } // fall through to piggyback message
3875−
3876− if (app->_renderVoxels->isChecked()) {
3877− Node* voxelServer = NodeList::getInstance()->nodeWithAddress(&senderAddress);
3878− if (voxelServer && socketMatch(voxelServer->getActiveSocket(), &senderAddress)) {
3879− voxelServer->lock();
3880− if (messageData[0] == PACKET_TYPE_ENVIRONMENT_DATA) {
3881− app->_environment.parseData(&senderAddress, messageData, messageLength);
3882− } else {
3883− app->_voxels.setDataSourceID(voxelServer->getNodeID());
3884− app->_voxels.parseData(messageData, messageLength);
3885− app->_voxels.setDataSourceID(UNKNOWN_NODE_ID);
3886− }
3887− voxelServer->unlock();
3888− }
3889− }
4142+ // add this packet to our list of voxel packets and process them on the voxel processing
4143+ app->queueVoxelPacket(senderAddress, app->_incomingPacket, bytesReceived);
38904144 break;
38914145 }
38924146 case PACKET_TYPE_BULK_AVATAR_DATA:
@@ -3955,13 +4209,13 @@ void Application::saveAction(QSettings* set, QAction* action) { · 62 unmodified lines
39554209 }
39564210
39574211 void Application::loadSettings(QSettings* settings) {
3958− if (!settings) {
4212+ if (!settings) {
39594213 settings = getSettings();
39604214 }
39614215
3962− _headCameraPitchYawScale = loadSetting(settings, "headCameraPitchYawScale", 0.0f);
4216+ _gyroCameraSensitivity = loadSetting(settings, "gyroCameraSensitivity", 0.5f);
39634217 _audioJitterBufferSamples = loadSetting(settings, "audioJitterBufferSamples", 0);
3964− _horizontalFieldOfView = loadSetting(settings, "horizontalFieldOfView", HORIZONTAL_FIELD_OF_VIEW_DEGREES);
4218+ _fieldOfView = loadSetting(settings, "fieldOfView", DEFAULT_FIELD_OF_VIEW_DEGREES);
39654219
39664220 settings->beginGroup("View Frustum Offset Camera");
39674221 // in case settings is corrupt or missing loadSetting() will check for NaN
@@ -3983,9 +4237,9 @@ void Application::saveSettings(QSettings* settings) { · 15 unmodified lines
39834237 settings = getSettings();
39844238 }
39854239
3986− settings->setValue("headCameraPitchYawScale", _headCameraPitchYawScale);
4240+ settings->setValue("gyroCameraSensitivity", _gyroCameraSensitivity);
39874241 settings->setValue("audioJitterBufferSamples", _audioJitterBufferSamples);
3988− settings->setValue("horizontalFieldOfView", _horizontalFieldOfView);
4242+ settings->setValue("fieldOfView", _fieldOfView);
39894243 settings->beginGroup("View Frustum Offset Camera");
39904244 settings->setValue("viewFrustumOffsetYaw", _viewFrustumOffsetYaw);
39914245 settings->setValue("viewFrustumOffsetPitch", _viewFrustumOffsetPitch);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t