History

Merge remote-tracking branch 'upstream/master' into particles

Jeffrey Ventrella committed 13 years ago

Commit b007ab12 parents 253154c cdfabd736 files · +1394 −482Browse files

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

Unified · Split

interface/src/Application.cpp+265−98
@@ -77,8 +77,10 @@ static char STAR_CACHE_FILE[] = "cachedStars.txt"; · 76 unmodified lines
77 77
78static const int BANDWIDTH_METER_CLICK_MAX_DRAG_LENGTH = 6; // farther dragged clicks are ignored 78static const int BANDWIDTH_METER_CLICK_MAX_DRAG_LENGTH = 6; // farther dragged clicks are ignored
79 79
80const glm::vec3 START_LOCATION(4.f, 0.f, 5.f); // Where one's own node begins in the world80// Where one's own Avatar begins in the world (will be overwritten if avatar data file is found)
81 // (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
83const glm::vec3 START_LOCATION(0.485f * TREE_SCALE, 0.f, 0.5f * TREE_SCALE);
82 84
83const int IDLE_SIMULATE_MSECS = 16; // How often should call simulate and other stuff85const int IDLE_SIMULATE_MSECS = 16; // How often should call simulate and other stuff
84 // in the idle loop? (60 FPS is default)86 // in the idle loop? (60 FPS is default)
@@ -234,6 +236,10 @@ Application::Application(int& argc, char** argv, timeval &startup_time) : · 149 unmodified lines
234 236
235 NodeList::createInstance(NODE_TYPE_AGENT, listenPort);237 NodeList::createInstance(NODE_TYPE_AGENT, listenPort);
236 238
239 NodeList::getInstance()->addHook(&_voxels);
240 NodeList::getInstance()->addHook(this);
241
242
237 _enableNetworkThread = !cmdOptionExists(argc, constArgv, "--nonblocking");243 _enableNetworkThread = !cmdOptionExists(argc, constArgv, "--nonblocking");
238 if (!_enableNetworkThread) {244 if (!_enableNetworkThread) {
239 NodeList::getInstance()->getNodeSocket()->setBlocking(false);245 NodeList::getInstance()->getNodeSocket()->setBlocking(false);
@@ -317,6 +323,11 @@ Application::Application(int& argc, char** argv, timeval &startup_time) : · 77 unmodified lines
317 // initialization continues in initializeGL when OpenGL context is ready323 // initialization continues in initializeGL when OpenGL context is ready
318}324}
319 325
326Application::~Application() {
327 NodeList::getInstance()->removeHook(&_voxels);
328 NodeList::getInstance()->removeHook(this);
329}
330
320void Application::initializeGL() {331void Application::initializeGL() {
321 qDebug( "Created Display Window.\n" );332 qDebug( "Created Display Window.\n" );
322 333
@@ -1290,9 +1301,9 @@ void Application::editPreferences() { · 967 unmodified lines
1290 horizontalFieldOfView->setValue(_horizontalFieldOfView);1301 horizontalFieldOfView->setValue(_horizontalFieldOfView);
1291 form->addRow("Horizontal field of view (degrees):", horizontalFieldOfView);1302 form->addRow("Horizontal field of view (degrees):", horizontalFieldOfView);
1292 1303
1293 QDoubleSpinBox* headCameraPitchYawScale = new QDoubleSpinBox();1304 QDoubleSpinBox* gyroCameraSensitivity = new QDoubleSpinBox();
1294 headCameraPitchYawScale->setValue(_headCameraPitchYawScale);1305 gyroCameraSensitivity->setValue(_gyroCameraSensitivity);
1295 form->addRow("Head Camera Pitch/Yaw Scale:", headCameraPitchYawScale);1306 form->addRow("Gyro Camera Sensitivity (0 - 1):", gyroCameraSensitivity);
1296 1307
1297 QDoubleSpinBox* leanScale = new QDoubleSpinBox();1308 QDoubleSpinBox* leanScale = new QDoubleSpinBox();
1298 leanScale->setValue(_myAvatar.getLeanScale());1309 leanScale->setValue(_myAvatar.getLeanScale());
@@ -1342,7 +1353,7 @@ void Application::editPreferences() { · 43 unmodified lines
1342 _myAvatar.getVoxels()->setVoxelURL(url);1353 _myAvatar.getVoxels()->setVoxelURL(url);
1343 sendAvatarVoxelURLMessage(url);1354 sendAvatarVoxelURLMessage(url);
1344 1355
1345 _headCameraPitchYawScale = headCameraPitchYawScale->value();1356 _gyroCameraSensitivity = gyroCameraSensitivity->value();
1346 _myAvatar.setLeanScale(leanScale->value());1357 _myAvatar.setLeanScale(leanScale->value());
1347 _audioJitterBufferSamples = audioJitterBufferSamples->value();1358 _audioJitterBufferSamples = audioJitterBufferSamples->value();
1348 if (!shouldDynamicallySetJitterBuffer()) {1359 if (!shouldDynamicallySetJitterBuffer()) {
@@ -1943,8 +1954,11 @@ void Application::initMenu() { · 594 unmodified lines
1943 _testPing->setChecked(true);1954 _testPing->setChecked(true);
1944 (_fullScreenMode = optionsMenu->addAction("Fullscreen", this, SLOT(setFullscreen(bool)), Qt::Key_F))->setCheckable(true);1955 (_fullScreenMode = optionsMenu->addAction("Fullscreen", this, SLOT(setFullscreen(bool)), Qt::Key_F))->setCheckable(true);
1945 optionsMenu->addAction("Webcam", &_webcam, SLOT(setEnabled(bool)))->setCheckable(true);1956 optionsMenu->addAction("Webcam", &_webcam, SLOT(setEnabled(bool)))->setCheckable(true);
1946 optionsMenu->addAction("Toggle Skeleton Tracking", &_webcam, SLOT(setSkeletonTrackingOn(bool)))->setCheckable(true);1957 optionsMenu->addAction("Skeleton Tracking", &_webcam, SLOT(setSkeletonTrackingOn(bool)))->setCheckable(true);
1958 (_wantCollisionsOn = optionsMenu->addAction("Turn collisions On", this, SLOT(toggleWantCollisionsOn())))->setCheckable(true);
1959 _wantCollisionsOn->setChecked(true);
1947 optionsMenu->addAction("Cycle Webcam Send Mode", _webcam.getGrabber(), SLOT(cycleVideoSendMode()));1960 optionsMenu->addAction("Cycle Webcam Send Mode", _webcam.getGrabber(), SLOT(cycleVideoSendMode()));
1961 optionsMenu->addAction("Webcam Texture", _webcam.getGrabber(), SLOT(setDepthOnly(bool)))->setCheckable(true);
1948 optionsMenu->addAction("Go Home", this, SLOT(goHome()), Qt::CTRL | Qt::Key_G);1962 optionsMenu->addAction("Go Home", this, SLOT(goHome()), Qt::CTRL | Qt::Key_G);
1949 1963
1950 QMenu* audioMenu = menuBar->addMenu("Audio");1964 QMenu* audioMenu = menuBar->addMenu("Audio");
@@ -2137,6 +2151,10 @@ void Application::toggleMixedSong() { · 186 unmodified lines
2137 }2151 }
2138}2152}
2139 2153
2154void Application::toggleWantCollisionsOn() {
2155 _myAvatar.setWantCollisionsOn(_wantCollisionsOn->isChecked());
2156}
2157
2140void Application::resetSongMixMenuItem() {2158void Application::resetSongMixMenuItem() {
2141 if (_audio.getSongFileBytes() == 0) {2159 if (_audio.getSongFileBytes() == 0) {
2142 _rawAudioMicrophoneMix->setText("Mix RAW Song");2160 _rawAudioMicrophoneMix->setText("Mix RAW Song");
@@ -2287,6 +2305,56 @@ void Application::renderLookatIndicator(glm::vec3 pointOfInterest, Camera& which · 144 unmodified lines
2287 renderCircle(haloOrigin, INDICATOR_RADIUS, IDENTITY_UP, NUM_SEGMENTS);2305 renderCircle(haloOrigin, INDICATOR_RADIUS, IDENTITY_UP, NUM_SEGMENTS);
2288}2306}
2289 2307
2308void Application::renderFollowIndicator() {
2309 NodeList* nodeList = NodeList::getInstance();
2310
2311 glLineWidth(5);
2312 glBegin(GL_LINES);
2313 for (NodeList::iterator node = nodeList->begin(); node != nodeList->end(); ++node) {
2314 if (node->getLinkedData() != NULL && node->getType() == NODE_TYPE_AGENT) {
2315 Avatar* avatar = (Avatar *) node->getLinkedData();
2316 Avatar* leader = NULL;
2317
2318 if (avatar->getLeaderID() != UNKNOWN_NODE_ID) {
2319 if (avatar->getLeaderID() == NodeList::getInstance()->getOwnerID()) {
2320 leader = &_myAvatar;
2321 } else {
2322 for (NodeList::iterator it = nodeList->begin(); it != nodeList->end(); ++it) {
2323 if(it->getNodeID() == avatar->getLeaderID()
2324 && it->getType() == NODE_TYPE_AGENT) {
2325 leader = (Avatar*) it->getLinkedData();
2326 }
2327 }
2328 }
2329
2330 if (leader != NULL) {
2331 glColor3f(1.f, 0.f, 0.f);
2332 glVertex3f(avatar->getPosition().x,
2333 avatar->getPosition().y,
2334 avatar->getPosition().z);
2335 glColor3f(0.f, 1.f, 0.f);
2336 glVertex3f(leader->getPosition().x,
2337 leader->getPosition().y,
2338 leader->getPosition().z);
2339 }
2340 }
2341 }
2342 }
2343
2344 if (_myAvatar.getLeadingAvatar() != NULL) {
2345 glColor3f(1.f, 0.f, 0.f);
2346 glVertex3f(_myAvatar.getPosition().x,
2347 _myAvatar.getPosition().y,
2348 _myAvatar.getPosition().z);
2349 glColor3f(0.f, 1.f, 0.f);
2350 glVertex3f(_myAvatar.getLeadingAvatar()->getPosition().x,
2351 _myAvatar.getLeadingAvatar()->getPosition().y,
2352 _myAvatar.getLeadingAvatar()->getPosition().z);
2353 }
2354
2355 glEnd();
2356}
2357
2290void Application::update(float deltaTime) {2358void Application::update(float deltaTime) {
2291 2359
2292 // Use Transmitter Hand to move hand if connected, else use mouse2360 // Use Transmitter Hand to move hand if connected, else use mouse
@@ -2500,7 +2568,7 @@ void Application::update(float deltaTime) { · 207 unmodified lines
2500 if (!avatar->isInitialized()) {2568 if (!avatar->isInitialized()) {
2501 avatar->init();2569 avatar->init();
2502 }2570 }
2503 avatar->simulate(deltaTime, NULL);2571 avatar->simulate(deltaTime, NULL, 0.f);
2504 avatar->setMouseRay(mouseRayOrigin, mouseRayDirection);2572 avatar->setMouseRay(mouseRayOrigin, mouseRayDirection);
2505 }2573 }
2506 node->unlock();2574 node->unlock();
@@ -2515,13 +2583,11 @@ void Application::update(float deltaTime) { · 8 unmodified lines
2515 }2583 }
2516 2584
2517 if (_transmitterDrives->isChecked() && _myTransmitter.isConnected()) {2585 if (_transmitterDrives->isChecked() && _myTransmitter.isConnected()) {
2518 _myAvatar.simulate(deltaTime, &_myTransmitter);2586 _myAvatar.simulate(deltaTime, &_myTransmitter, _gyroCameraSensitivity);
2519 } else {2587 } else {
2520 _myAvatar.simulate(deltaTime, NULL);2588 _myAvatar.simulate(deltaTime, NULL, _gyroCameraSensitivity);
2521 }2589 }
2522 2590
2523 _myAvatar.getHand().simulate(deltaTime, true);
2524
2525 if (!OculusManager::isConnected()) { 2591 if (!OculusManager::isConnected()) {
2526 if (_lookingInMirror->isChecked()) {2592 if (_lookingInMirror->isChecked()) {
2527 if (_myCamera.getMode() != CAMERA_MODE_MIRROR) {2593 if (_myCamera.getMode() != CAMERA_MODE_MIRROR) {
@@ -2586,10 +2652,6 @@ void Application::updateAvatar(float deltaTime) { · 58 unmodified lines
2586 2652
2587 // Update my avatar's state from gyros and/or webcam2653 // Update my avatar's state from gyros and/or webcam
2588 _myAvatar.updateFromGyrosAndOrWebcam(_gyroLook->isChecked(),2654 _myAvatar.updateFromGyrosAndOrWebcam(_gyroLook->isChecked(),
2589 glm::vec3(_headCameraPitchYawScale,
2590 _headCameraPitchYawScale,
2591 _headCameraPitchYawScale),
2592 0.f,
2593 _pitchFromTouch);2655 _pitchFromTouch);
2594 2656
2595 if (_serialHeadSensor.isActive()) {2657 if (_serialHeadSensor.isActive()) {
@@ -2876,6 +2938,27 @@ void Application::displayOculus(Camera& whichCamera) { · 280 unmodified lines
2876 glPopMatrix();2938 glPopMatrix();
2877}2939}
2878 2940
2941void Application::setupWorldLight(Camera& whichCamera) {
2942
2943 // Setup 3D lights (after the camera transform, so that they are positioned in world space)
2944 glEnable(GL_COLOR_MATERIAL);
2945 glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
2946
2947 glm::vec3 relativeSunLoc = glm::normalize(_environment.getClosestData(whichCamera.getPosition()).getSunLocation() -
2948 whichCamera.getPosition());
2949 GLfloat light_position0[] = { relativeSunLoc.x, relativeSunLoc.y, relativeSunLoc.z, 0.0 };
2950 glLightfv(GL_LIGHT0, GL_POSITION, light_position0);
2951 GLfloat ambient_color[] = { 0.7, 0.7, 0.8 };
2952 glLightfv(GL_LIGHT0, GL_AMBIENT, ambient_color);
2953 GLfloat diffuse_color[] = { 0.8, 0.7, 0.7 };
2954 glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse_color);
2955 GLfloat specular_color[] = { 1.0, 1.0, 1.0, 1.0};
2956 glLightfv(GL_LIGHT0, GL_SPECULAR, specular_color);
2957
2958 glMaterialfv(GL_FRONT, GL_SPECULAR, specular_color);
2959 glMateriali(GL_FRONT, GL_SHININESS, 96);
2960}
2961
2879void Application::displaySide(Camera& whichCamera) {2962void Application::displaySide(Camera& whichCamera) {
2880 // transform by eye offset2963 // transform by eye offset
2881 2964
@@ -2905,22 +2988,7 @@ void Application::displaySide(Camera& whichCamera) { · 23 unmodified lines
2905 glTranslatef(-whichCamera.getPosition().x, -whichCamera.getPosition().y, -whichCamera.getPosition().z);2988 glTranslatef(-whichCamera.getPosition().x, -whichCamera.getPosition().y, -whichCamera.getPosition().z);
2906 2989
2907 // Setup 3D lights (after the camera transform, so that they are positioned in world space)2990 // Setup 3D lights (after the camera transform, so that they are positioned in world space)
2908 glEnable(GL_COLOR_MATERIAL);2991 setupWorldLight(whichCamera);
2909 glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
2910
2911 glm::vec3 relativeSunLoc = glm::normalize(_environment.getClosestData(whichCamera.getPosition()).getSunLocation() -
2912 whichCamera.getPosition());
2913 GLfloat light_position0[] = { relativeSunLoc.x, relativeSunLoc.y, relativeSunLoc.z, 0.0 };
2914 glLightfv(GL_LIGHT0, GL_POSITION, light_position0);
2915 GLfloat ambient_color[] = { 0.7, 0.7, 0.8 };
2916 glLightfv(GL_LIGHT0, GL_AMBIENT, ambient_color);
2917 GLfloat diffuse_color[] = { 0.8, 0.7, 0.7 };
2918 glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse_color);
2919 GLfloat specular_color[] = { 1.0, 1.0, 1.0, 1.0};
2920 glLightfv(GL_LIGHT0, GL_SPECULAR, specular_color);
2921
2922 glMaterialfv(GL_FRONT, GL_SPECULAR, specular_color);
2923 glMateriali(GL_FRONT, GL_SHININESS, 96);
2924 2992
2925 if (_renderStarsOn->isChecked()) {2993 if (_renderStarsOn->isChecked()) {
2926 if (!_stars.getFileLoaded()) {2994 if (!_stars.getFileLoaded()) {
@@ -2986,7 +3054,7 @@ void Application::displaySide(Camera& whichCamera) { · 59 unmodified lines
2986 glDisable(GL_FOG);3054 glDisable(GL_FOG);
2987 glDisable(GL_NORMALIZE);3055 glDisable(GL_NORMALIZE);
2988 3056
2989 renderGroundPlaneGrid(EDGE_SIZE_GROUND_PLANE, _audio.getCollisionSoundMagnitude());3057 //renderGroundPlaneGrid(EDGE_SIZE_GROUND_PLANE, _audio.getCollisionSoundMagnitude());
2990 } 3058 }
2991 // Draw voxels3059 // Draw voxels
2992 if (_renderVoxels->isChecked()) {3060 if (_renderVoxels->isChecked()) {
@@ -3015,6 +3083,8 @@ void Application::displaySide(Camera& whichCamera) { · 22 unmodified lines
3015 glEnable(GL_LIGHTING);3083 glEnable(GL_LIGHTING);
3016 }3084 }
3017 3085
3086 _myAvatar.renderScreenTint(SCREEN_TINT_BEFORE_AVATARS, whichCamera);
3087
3018 if (_renderAvatarsOn->isChecked()) {3088 if (_renderAvatarsOn->isChecked()) {
3019 // Render avatars of other nodes3089 // Render avatars of other nodes
3020 NodeList* nodeList = NodeList::getInstance();3090 NodeList* nodeList = NodeList::getInstance();
@@ -3049,6 +3119,8 @@ void Application::displaySide(Camera& whichCamera) { · 28 unmodified lines
3049 }3119 }
3050 }3120 }
3051 3121
3122 _myAvatar.renderScreenTint(SCREEN_TINT_AFTER_AVATARS, whichCamera);
3123
3052 if (_renderParticleSystemOn->isChecked()) {3124 if (_renderParticleSystemOn->isChecked()) {
3053 if (_particleSystemInitialized) {3125 if (_particleSystemInitialized) {
3054 _particleSystem.render(); 3126 _particleSystem.render();
@@ -3060,6 +3132,20 @@ void Application::displaySide(Camera& whichCamera) { · 5 unmodified lines
3060 3132
3061 // brad's frustum for debugging3133 // brad's frustum for debugging
3062 if (_frustumOn->isChecked()) renderViewFrustum(_viewFrustum);3134 if (_frustumOn->isChecked()) renderViewFrustum(_viewFrustum);
3135
3136 // render voxel fades if they exist
3137 if (_voxelFades.size() > 0) {
3138 for(std::vector<VoxelFade>::iterator fade = _voxelFades.begin(); fade != _voxelFades.end();) {
3139 fade->render();
3140 if(fade->isDone()) {
3141 fade = _voxelFades.erase(fade);
3142 } else {
3143 ++fade;
3144 }
3145 }
3146 }
3147
3148 renderFollowIndicator();
3063}3149}
3064 3150
3065void Application::displayOverlay() {3151void Application::displayOverlay() {
@@ -3627,6 +3713,62 @@ void Application::shiftPaintingColor() { · 561 unmodified lines
3627}3713}
3628 3714
3629 3715
3716void Application::injectVoxelAddedSoundEffect() {
3717 AudioInjector* voxelInjector = AudioInjectionManager::injectorWithCapacity(11025);
3718
3719 if (voxelInjector) {
3720 voxelInjector->setPosition(glm::vec3(_mouseVoxel.x, _mouseVoxel.y, _mouseVoxel.z));
3721 //voxelInjector->setBearing(-1 * _myAvatar.getAbsoluteHeadYaw());
3722 voxelInjector->setVolume (16 * pow (_mouseVoxel.s, 2) / .0000001); //255 is max, and also default value
3723
3724 /* for (int i = 0; i
3725 < 22050; i++) {
3726 if (i % 4 == 0) {
3727 voxelInjector->addSample(4000);
3728 } else if (i % 4 == 1) {
3729 voxelInjector->addSample(0);
3730 } else if (i % 4 == 2) {
3731 voxelInjector->addSample(-4000);
3732 } else {
3733 voxelInjector->addSample(0);
3734 }
3735 */
3736
3737 const float BIG_VOXEL_MIN_SIZE = .01f;
3738
3739 for (int i = 0; i < 11025; i++) {
3740
3741 /*
3742 A440 square wave
3743 if (sin(i * 2 * PIE / 50)>=0) {
3744 voxelInjector->addSample(4000);
3745 } else {
3746 voxelInjector->addSample(-4000);
3747 }
3748 */
3749
3750 if (_mouseVoxel.s > BIG_VOXEL_MIN_SIZE) {
3751 voxelInjector->addSample(20000 * sin((i * 2 * PIE) / (500 * sin((i + 1) / 200))));
3752 } else {
3753 voxelInjector->addSample(16000 * sin(i / (1.5 * log (_mouseVoxel.s / .0001) * ((i + 11025) / 5512.5)))); //808
3754 }
3755 }
3756
3757 //voxelInjector->addSample(32500 * sin(i/(2 * 1 * ((i+5000)/5512.5)))); //80
3758 //voxelInjector->addSample(20000 * sin(i/(6 * (_mouseVoxel.s/.001) *((i+5512.5)/5512.5)))); //808
3759 //voxelInjector->addSample(20000 * sin(i/(6 * ((i+5512.5)/5512.5)))); //808
3760 //voxelInjector->addSample(4000 * sin(i * 2 * PIE /50)); //A440 sine wave
3761 //voxelInjector->addSample(4000 * sin(i * 2 * PIE /50) * sin (i/500)); //A440 sine wave with amplitude modulation
3762
3763 //FM library
3764 //voxelInjector->addSample(20000 * sin((i * 2 * PIE) /(500*sin((i+1)/200)))); //FM 1 dubstep
3765 //voxelInjector->addSample(20000 * sin((i * 2 * PIE) /(300*sin((i+1)/5.0)))); //FM 2 flange sweep
3766 //voxelInjector->addSample(10000 * sin((i * 2 * PIE) /(500*sin((i+1)/500.0)))); //FM 3 resonant pulse
3767
3768 AudioInjectionManager::threadInjector(voxelInjector);
3769 }
3770}
3771
3630bool Application::maybeEditVoxelUnderCursor() {3772bool Application::maybeEditVoxelUnderCursor() {
3631 if (_addVoxelMode->isChecked() || _colorVoxelMode->isChecked()) {3773 if (_addVoxelMode->isChecked() || _colorVoxelMode->isChecked()) {
3632 if (_mouseVoxel.s != 0) {3774 if (_mouseVoxel.s != 0) {
@@ -3637,65 +3779,35 @@ bool Application::maybeEditVoxelUnderCursor() { · 4 unmodified lines
3637 // create the voxel locally so it appears immediately3779 // create the voxel locally so it appears immediately
3638 _voxels.createVoxel(_mouseVoxel.x, _mouseVoxel.y, _mouseVoxel.z, _mouseVoxel.s,3780 _voxels.createVoxel(_mouseVoxel.x, _mouseVoxel.y, _mouseVoxel.z, _mouseVoxel.s,
3639 _mouseVoxel.red, _mouseVoxel.green, _mouseVoxel.blue, _destructiveAddVoxel->isChecked());3781 _mouseVoxel.red, _mouseVoxel.green, _mouseVoxel.blue, _destructiveAddVoxel->isChecked());
3782
3783 // Implement voxel fade effect
3784 VoxelFade fade(VoxelFade::FADE_OUT, 1.0f, 1.0f, 1.0f);
3785 const float VOXEL_BOUNDS_ADJUST = 0.01f;
3786 float slightlyBigger = _mouseVoxel.s * VOXEL_BOUNDS_ADJUST;
3787 fade.voxelDetails.x = _mouseVoxel.x - slightlyBigger;
3788 fade.voxelDetails.y = _mouseVoxel.y - slightlyBigger;
3789 fade.voxelDetails.z = _mouseVoxel.z - slightlyBigger;
3790 fade.voxelDetails.s = _mouseVoxel.s + slightlyBigger + slightlyBigger;
3791 _voxelFades.push_back(fade);
3792
3793 // inject a sound effect
3794 injectVoxelAddedSoundEffect();
3640 3795
3641 // remember the position for drag detection3796 // remember the position for drag detection
3642 _justEditedVoxel = true;3797 _justEditedVoxel = true;
3643 3798
3644 AudioInjector* voxelInjector = AudioInjectionManager::injectorWithCapacity(11025);
3645 voxelInjector->setPosition(glm::vec3(_mouseVoxel.x, _mouseVoxel.y, _mouseVoxel.z));
3646 //_myAvatar.getPosition()
3647// voxelInjector->setBearing(-1 * _myAvatar.getAbsoluteHeadYaw());
3648 voxelInjector->setVolume (16 * pow (_mouseVoxel.s, 2) / .0000001); //255 is max, and also default value
3649
3650 /* for (int i = 0; i
3651 < 22050; i++) {
3652 if (i % 4 == 0) {
3653 voxelInjector->addSample(4000);
3654 } else if (i % 4 == 1) {
3655 voxelInjector->addSample(0);
3656 } else if (i % 4 == 2) {
3657 voxelInjector->addSample(-4000);
3658 } else {
3659 voxelInjector->addSample(0);
3660 }
3661 */
3662
3663
3664 const float BIG_VOXEL_MIN_SIZE = .01f;
3665
3666 for (int i = 0; i < 11025; i++) {
3667
3668 /*
3669 A440 square wave
3670 if (sin(i * 2 * PIE / 50)>=0) {
3671 voxelInjector->addSample(4000);
3672 } else {
3673 voxelInjector->addSample(-4000);
3674 }
3675 */
3676
3677 if (_mouseVoxel.s > BIG_VOXEL_MIN_SIZE) {
3678 voxelInjector->addSample(20000 * sin((i * 2 * PIE) / (500 * sin((i + 1) / 200))));
3679 } else {
3680 voxelInjector->addSample(16000 * sin(i / (1.5 * log (_mouseVoxel.s / .0001) * ((i + 11025) / 5512.5)))); //808
3681 }
3682 }
3683
3684 //voxelInjector->addSample(32500 * sin(i/(2 * 1 * ((i+5000)/5512.5)))); //80
3685 //voxelInjector->addSample(20000 * sin(i/(6 * (_mouseVoxel.s/.001) *((i+5512.5)/5512.5)))); //808
3686 //voxelInjector->addSample(20000 * sin(i/(6 * ((i+5512.5)/5512.5)))); //808
3687 //voxelInjector->addSample(4000 * sin(i * 2 * PIE /50)); //A440 sine wave
3688 //voxelInjector->addSample(4000 * sin(i * 2 * PIE /50) * sin (i/500)); //A440 sine wave with amplitude modulation
3689
3690 //FM library
3691 //voxelInjector->addSample(20000 * sin((i * 2 * PIE) /(500*sin((i+1)/200)))); //FM 1 dubstep
3692 //voxelInjector->addSample(20000 * sin((i * 2 * PIE) /(300*sin((i+1)/5.0)))); //FM 2 flange sweep
3693 //voxelInjector->addSample(10000 * sin((i * 2 * PIE) /(500*sin((i+1)/500.0)))); //FM 3 resonant pulse
3694
3695 AudioInjectionManager::threadInjector(voxelInjector);
3696 }3799 }
3697 } else if (_deleteVoxelMode->isChecked()) {3800 } else if (_deleteVoxelMode->isChecked()) {
3698 deleteVoxelUnderCursor();3801 deleteVoxelUnderCursor();
3802 VoxelFade fade(VoxelFade::FADE_OUT, NODE_KILLED_RED, NODE_KILLED_GREEN, NODE_KILLED_BLUE);
3803 const float VOXEL_BOUNDS_ADJUST = 0.01f;
3804 float slightlyBigger = _mouseVoxel.s * VOXEL_BOUNDS_ADJUST;
3805 fade.voxelDetails.x = _mouseVoxel.x - slightlyBigger;
3806 fade.voxelDetails.y = _mouseVoxel.y - slightlyBigger;
3807 fade.voxelDetails.z = _mouseVoxel.z - slightlyBigger;
3808 fade.voxelDetails.s = _mouseVoxel.s + slightlyBigger + slightlyBigger;
3809 _voxelFades.push_back(fade);
3810
3699 } else if (_eyedropperMode->isChecked()) {3811 } else if (_eyedropperMode->isChecked()) {
3700 eyedropperVoxelUnderCursor();3812 eyedropperVoxelUnderCursor();
3701 } else {3813 } else {
@@ -3710,17 +3822,20 @@ void Application::deleteVoxelUnderCursor() { · 8 unmodified lines
3710 // sending delete to the server is sufficient, server will send new version so we see updates soon enough3822 // sending delete to the server is sufficient, server will send new version so we see updates soon enough
3711 sendVoxelEditMessage(PACKET_TYPE_ERASE_VOXEL, _mouseVoxel);3823 sendVoxelEditMessage(PACKET_TYPE_ERASE_VOXEL, _mouseVoxel);
3712 AudioInjector* voxelInjector = AudioInjectionManager::injectorWithCapacity(5000);3824 AudioInjector* voxelInjector = AudioInjectionManager::injectorWithCapacity(5000);
3713 voxelInjector->setPosition(glm::vec3(_mouseVoxel.x, _mouseVoxel.y, _mouseVoxel.z));
3714// voxelInjector->setBearing(0); //straight down the z axis
3715 voxelInjector->setVolume (255); //255 is max, and also default value
3716
3717 3825
3718 for (int i = 0; i < 5000; i++) {3826 if (voxelInjector) {
3719 voxelInjector->addSample(10000 * sin((i * 2 * PIE) / (500 * sin((i + 1) / 500.0)))); //FM 3 resonant pulse3827 voxelInjector->setPosition(glm::vec3(_mouseVoxel.x, _mouseVoxel.y, _mouseVoxel.z));
3720 //voxelInjector->addSample(20000 * sin((i) /((4 / _mouseVoxel.s) * sin((i)/(20 * _mouseVoxel.s / .001))))); //FM 2 comb filter3828 //voxelInjector->setBearing(0); //straight down the z axis
3829 voxelInjector->setVolume (255); //255 is max, and also default value
3830
3831
3832 for (int i = 0; i < 5000; i++) {
3833 voxelInjector->addSample(10000 * sin((i * 2 * PIE) / (500 * sin((i + 1) / 500.0)))); //FM 3 resonant pulse
3834 //voxelInjector->addSample(20000 * sin((i) /((4 / _mouseVoxel.s) * sin((i)/(20 * _mouseVoxel.s / .001))))); //FM 2 comb filter
3835 }
3836
3837 AudioInjectionManager::threadInjector(voxelInjector);
3721 }3838 }
3722
3723 AudioInjectionManager::threadInjector(voxelInjector);
3724 }3839 }
3725 // remember the position for drag detection3840 // remember the position for drag detection
3726 _justEditedVoxel = true;3841 _justEditedVoxel = true;
@@ -3817,6 +3932,57 @@ void Application::attachNewHeadToNode(Node* newNode) { · 90 unmodified lines
3817 }3932 }
3818}3933}
3819 3934
3935void Application::nodeAdded(Node* node) {
3936}
3937
3938void Application::nodeKilled(Node* node) {
3939 if (node->getType() == NODE_TYPE_VOXEL_SERVER) {
3940 uint16_t nodeID = node->getNodeID();
3941 // see if this is the first we've heard of this node...
3942 if (_voxelServerJurisdictions.find(nodeID) != _voxelServerJurisdictions.end()) {
3943 VoxelPositionSize jurisditionDetails;
3944 jurisditionDetails = _voxelServerJurisdictions[nodeID];
3945
3946 printf("voxel server going away...... v[%f, %f, %f, %f]\n",
3947 jurisditionDetails.x, jurisditionDetails.y, jurisditionDetails.z, jurisditionDetails.s);
3948
3949 // Add the jurisditionDetails object to the list of "fade outs"
3950 VoxelFade fade(VoxelFade::FADE_OUT, NODE_KILLED_RED, NODE_KILLED_GREEN, NODE_KILLED_BLUE);
3951 fade.voxelDetails = jurisditionDetails;
3952 _voxelFades.push_back(fade);
3953 }
3954 }
3955}
3956
3957int Application::parseVoxelStats(unsigned char* messageData, ssize_t messageLength, sockaddr senderAddress) {
3958
3959 // parse the incoming stats data, and stick it into our averaging stats object for now... even though this
3960 // means mixing in stats from potentially multiple servers.
3961 int statsMessageLength = _voxelSceneStats.unpackFromMessage(messageData, messageLength);
3962
3963 // But, also identify the sender, and keep track of the contained jurisdiction root for this server
3964 Node* voxelServer = NodeList::getInstance()->nodeWithAddress(&senderAddress);
3965 uint16_t nodeID = voxelServer->getNodeID();
3966
3967 VoxelPositionSize jurisditionDetails;
3968 voxelDetailsForCode(_voxelSceneStats.getJurisdictionRoot(), jurisditionDetails);
3969
3970 // see if this is the first we've heard of this node...
3971 if (_voxelServerJurisdictions.find(nodeID) == _voxelServerJurisdictions.end()) {
3972 printf("stats from new voxel server... v[%f, %f, %f, %f]\n",
3973 jurisditionDetails.x, jurisditionDetails.y, jurisditionDetails.z, jurisditionDetails.s);
3974
3975 // Add the jurisditionDetails object to the list of "fade outs"
3976 VoxelFade fade(VoxelFade::FADE_OUT, NODE_ADDED_RED, NODE_ADDED_GREEN, NODE_ADDED_BLUE);
3977 fade.voxelDetails = jurisditionDetails;
3978 _voxelFades.push_back(fade);
3979 }
3980 // store jurisdiction details for later use
3981 _voxelServerJurisdictions[nodeID] = jurisditionDetails;
3982
3983 return statsMessageLength;
3984}
3985
3820// Receive packets from other nodes/servers and decide what to do with them!3986// Receive packets from other nodes/servers and decide what to do with them!
3821void* Application::networkReceive(void* args) {3987void* Application::networkReceive(void* args) {
3822 sockaddr senderAddress;3988 sockaddr senderAddress;
@@ -3860,7 +4026,8 @@ void* Application::networkReceive(void* args) { · 37 unmodified lines
3860 // immediately following them inside the same packet. So, we process the PACKET_TYPE_VOXEL_STATS first4026 // immediately following them inside the same packet. So, we process the PACKET_TYPE_VOXEL_STATS first
3861 // then process any remaining bytes as if it was another packet4027 // then process any remaining bytes as if it was another packet
3862 if (messageData[0] == PACKET_TYPE_VOXEL_STATS) {4028 if (messageData[0] == PACKET_TYPE_VOXEL_STATS) {
3863 int statsMessageLength = app->_voxelSceneStats.unpackFromMessage(messageData, messageLength);4029
4030 int statsMessageLength = app->parseVoxelStats(messageData, messageLength, senderAddress);
3864 if (messageLength > statsMessageLength) {4031 if (messageLength > statsMessageLength) {
3865 messageData += statsMessageLength;4032 messageData += statsMessageLength;
3866 messageLength -= statsMessageLength;4033 messageLength -= statsMessageLength;
@@ -3954,11 +4121,11 @@ void Application::saveAction(QSettings* set, QAction* action) { · 87 unmodified lines
3954}4121}
3955 4122
3956void Application::loadSettings(QSettings* settings) {4123void Application::loadSettings(QSettings* settings) {
3957 if (!settings) { 4124 if (!settings) {
3958 settings = getSettings();4125 settings = getSettings();
3959 }4126 }
3960 4127
3961 _headCameraPitchYawScale = loadSetting(settings, "headCameraPitchYawScale", 0.0f);4128 _gyroCameraSensitivity = loadSetting(settings, "gyroCameraSensitivity", 0.5f);
3962 _audioJitterBufferSamples = loadSetting(settings, "audioJitterBufferSamples", 0);4129 _audioJitterBufferSamples = loadSetting(settings, "audioJitterBufferSamples", 0);
3963 _horizontalFieldOfView = loadSetting(settings, "horizontalFieldOfView", HORIZONTAL_FIELD_OF_VIEW_DEGREES);4130 _horizontalFieldOfView = loadSetting(settings, "horizontalFieldOfView", HORIZONTAL_FIELD_OF_VIEW_DEGREES);
3964 4131
@@ -3982,7 +4149,7 @@ void Application::saveSettings(QSettings* settings) { · 17 unmodified lines
3982 settings = getSettings();4149 settings = getSettings();
3983 }4150 }
3984 4151
3985 settings->setValue("headCameraPitchYawScale", _headCameraPitchYawScale);4152 settings->setValue("gyroCameraSensitivity", _gyroCameraSensitivity);
3986 settings->setValue("audioJitterBufferSamples", _audioJitterBufferSamples);4153 settings->setValue("audioJitterBufferSamples", _audioJitterBufferSamples);
3987 settings->setValue("horizontalFieldOfView", _horizontalFieldOfView);4154 settings->setValue("horizontalFieldOfView", _horizontalFieldOfView);
3988 settings->beginGroup("View Frustum Offset Camera");4155 settings->beginGroup("View Frustum Offset Camera");

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