History

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

atlante45 committed 13 years ago

Commit b6049c92 parents d165891 f560f6346 files · +1507 −698Browse files

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

Unified · Split

interface/src/Application.cpp+72−55
@@ -75,8 +75,6 @@ using namespace std; · 74 unmodified lines
75static char STAR_FILE[] = "http://s3-us-west-1.amazonaws.com/highfidelity/stars.txt";75static char STAR_FILE[] = "http://s3-us-west-1.amazonaws.com/highfidelity/stars.txt";
76static char STAR_CACHE_FILE[] = "cachedStars.txt";76static char STAR_CACHE_FILE[] = "cachedStars.txt";
77 77
78static const bool TESTING_PARTICLE_SYSTEM = true;
79
80static 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
81 79
82const glm::vec3 START_LOCATION(4.f, 0.f, 5.f); // Where one's own node begins in the world80const glm::vec3 START_LOCATION(4.f, 0.f, 5.f); // Where one's own node begins in the world
@@ -166,9 +164,9 @@ void GLCanvas::wheelEvent(QWheelEvent* event) { · 83 unmodified lines
166 Application::getInstance()->wheelEvent(event);164 Application::getInstance()->wheelEvent(event);
167}165}
168 166
169void messageHandler(QtMsgType type, const char* message) {167void messageHandler(QtMsgType type, const QMessageLogContext& context, const QString &message) {
170 fprintf(stdout, "%s", message); 168 fprintf(stdout, "%s", message.toLocal8Bit().constData());
171 LogDisplay::instance.addMessage(message);169 LogDisplay::instance.addMessage(message.toLocal8Bit().constData());
172}170}
173 171
174Application::Application(int& argc, char** argv, timeval &startup_time) :172Application::Application(int& argc, char** argv, timeval &startup_time) :
@@ -224,7 +222,7 @@ Application::Application(int& argc, char** argv, timeval &startup_time) : · 49 unmodified lines
224 _applicationStartupTime = startup_time;222 _applicationStartupTime = startup_time;
225 _window->setWindowTitle("Interface");223 _window->setWindowTitle("Interface");
226 224
227 qInstallMsgHandler(messageHandler);225 qInstallMessageHandler(messageHandler);
228 226
229 unsigned int listenPort = 0; // bind to an ephemeral port by default227 unsigned int listenPort = 0; // bind to an ephemeral port by default
230 const char** constArgv = const_cast<const char**>(argv);228 const char** constArgv = const_cast<const char**>(argv);
@@ -407,7 +405,7 @@ void Application::paintGL() { · 176 unmodified lines
407 405
408 } else if (_myCamera.getMode() == CAMERA_MODE_FIRST_PERSON) {406 } else if (_myCamera.getMode() == CAMERA_MODE_FIRST_PERSON) {
409 _myCamera.setTightness(0.0f); // In first person, camera follows head exactly without delay407 _myCamera.setTightness(0.0f); // In first person, camera follows head exactly without delay
410 _myCamera.setTargetPosition(_myAvatar.getUprightHeadPosition());408 _myCamera.setTargetPosition(_myAvatar.getUprightEyeLevelPosition());
411 _myCamera.setTargetRotation(_myAvatar.getHead().getCameraOrientation());409 _myCamera.setTargetRotation(_myAvatar.getHead().getCameraOrientation());
412 410
413 } else if (_myCamera.getMode() == CAMERA_MODE_THIRD_PERSON) {411 } else if (_myCamera.getMode() == CAMERA_MODE_THIRD_PERSON) {
@@ -566,6 +564,11 @@ void Application::keyPressEvent(QKeyEvent* event) { · 152 unmodified lines
566 }564 }
567 return;565 return;
568 }566 }
567
568 //this is for switching between modes for the leap rave glove test
569 if (_simulateLeapHand->isChecked() || _testRaveGlove->isChecked()) {
570 _myAvatar.getHand().setRaveGloveEffectsMode((QKeyEvent*)event);
571 }
569 572
570 bool shifted = event->modifiers().testFlag(Qt::ShiftModifier);573 bool shifted = event->modifiers().testFlag(Qt::ShiftModifier);
571 switch (event->key()) {574 switch (event->key()) {
@@ -1225,7 +1228,7 @@ void Application::editPreferences() { · 653 unmodified lines
1225 1228
1226 if (domainServerHostname->text().size() > 0) {1229 if (domainServerHostname->text().size() > 0) {
1227 // the user input a new hostname, use that1230 // the user input a new hostname, use that
1228 newHostname = domainServerHostname->text().toAscii();1231 newHostname = domainServerHostname->text().toLocal8Bit();
1229 } else {1232 } else {
1230 // the user left the field blank, use the default hostname1233 // the user left the field blank, use the default hostname
1231 newHostname = QByteArray(DEFAULT_DOMAIN_HOSTNAME);1234 newHostname = QByteArray(DEFAULT_DOMAIN_HOSTNAME);
@@ -1504,11 +1507,11 @@ bool Application::sendVoxelsOperation(VoxelNode* node, void* extraData) { · 272 unmodified lines
1504 int usecToSleep = CLIENT_TO_SERVER_VOXEL_SEND_INTERVAL_USECS - elapsed;1507 int usecToSleep = CLIENT_TO_SERVER_VOXEL_SEND_INTERVAL_USECS - elapsed;
1505 if (usecToSleep > 0) {1508 if (usecToSleep > 0) {
1506 qDebug("sendVoxelsOperation: packet: %d bytes:%lld elapsed %lld usecs, sleeping for %d usecs!\n",1509 qDebug("sendVoxelsOperation: packet: %d bytes:%lld elapsed %lld usecs, sleeping for %d usecs!\n",
1507 args->packetsSent, args->bytesSent, elapsed, usecToSleep);1510 args->packetsSent, (long long int)args->bytesSent, (long long int)elapsed, usecToSleep);
1508 usleep(usecToSleep);1511 usleep(usecToSleep);
1509 } else {1512 } else {
1510 qDebug("sendVoxelsOperation: packet: %d bytes:%lld elapsed %lld usecs, no need to sleep!\n",1513 qDebug("sendVoxelsOperation: packet: %d bytes:%lld elapsed %lld usecs, no need to sleep!\n",
1511 args->packetsSent, args->bytesSent, elapsed);1514 args->packetsSent, (long long int)args->bytesSent, (long long int)elapsed);
1512 }1515 }
1513 args->lastSendTime = now;1516 args->lastSendTime = now;
1514 }1517 }
@@ -1521,12 +1524,12 @@ bool Application::sendVoxelsOperation(VoxelNode* node, void* extraData) { · 6 unmodified lines
1521}1524}
1522 1525
1523void Application::exportVoxels() {1526void Application::exportVoxels() {
1524 QString desktopLocation = QDesktopServices::storageLocation(QDesktopServices::DesktopLocation);1527 QString desktopLocation = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation);
1525 QString suggestedName = desktopLocation.append("/voxels.svo");1528 QString suggestedName = desktopLocation.append("/voxels.svo");
1526 1529
1527 QString fileNameString = QFileDialog::getSaveFileName(_glWidget, tr("Export Voxels"), suggestedName, 1530 QString fileNameString = QFileDialog::getSaveFileName(_glWidget, tr("Export Voxels"), suggestedName,
1528 tr("Sparse Voxel Octree Files (*.svo)"));1531 tr("Sparse Voxel Octree Files (*.svo)"));
1529 QByteArray fileNameAscii = fileNameString.toAscii();1532 QByteArray fileNameAscii = fileNameString.toLocal8Bit();
1530 const char* fileName = fileNameAscii.data();1533 const char* fileName = fileNameAscii.data();
1531 VoxelNode* selectedNode = _voxels.getVoxelAt(_mouseVoxel.x, _mouseVoxel.y, _mouseVoxel.z, _mouseVoxel.s);1534 VoxelNode* selectedNode = _voxels.getVoxelAt(_mouseVoxel.x, _mouseVoxel.y, _mouseVoxel.z, _mouseVoxel.s);
1532 if (selectedNode) {1535 if (selectedNode) {
@@ -1541,11 +1544,11 @@ void Application::exportVoxels() { · 8 unmodified lines
1541 1544
1542const char* IMPORT_FILE_TYPES = "Sparse Voxel Octree Files, Square PNG, Schematic Files (*.svo *.png *.schematic)";1545const char* IMPORT_FILE_TYPES = "Sparse Voxel Octree Files, Square PNG, Schematic Files (*.svo *.png *.schematic)";
1543void Application::importVoxelsToClipboard() {1546void Application::importVoxelsToClipboard() {
1544 QString desktopLocation = QDesktopServices::storageLocation(QDesktopServices::DesktopLocation);1547 QString desktopLocation = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation);
1545 QString fileNameString = QFileDialog::getOpenFileName(_glWidget, tr("Import Voxels to Clipboard"), desktopLocation,1548 QString fileNameString = QFileDialog::getOpenFileName(_glWidget, tr("Import Voxels to Clipboard"), desktopLocation,
1546 tr(IMPORT_FILE_TYPES));1549 tr(IMPORT_FILE_TYPES));
1547 1550
1548 QByteArray fileNameAscii = fileNameString.toAscii();1551 QByteArray fileNameAscii = fileNameString.toLocal8Bit();
1549 const char* fileName = fileNameAscii.data();1552 const char* fileName = fileNameAscii.data();
1550 1553
1551 _clipboardTree.eraseAllVoxels();1554 _clipboardTree.eraseAllVoxels();
@@ -1575,11 +1578,11 @@ void Application::importVoxelsToClipboard() { · 23 unmodified lines
1575}1578}
1576 1579
1577void Application::importVoxels() {1580void Application::importVoxels() {
1578 QString desktopLocation = QDesktopServices::storageLocation(QDesktopServices::DesktopLocation);1581 QString desktopLocation = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation);
1579 QString fileNameString = QFileDialog::getOpenFileName(_glWidget, tr("Import Voxels"), desktopLocation,1582 QString fileNameString = QFileDialog::getOpenFileName(_glWidget, tr("Import Voxels"), desktopLocation,
1580 tr(IMPORT_FILE_TYPES));1583 tr(IMPORT_FILE_TYPES));
1581 1584
1582 QByteArray fileNameAscii = fileNameString.toAscii();1585 QByteArray fileNameAscii = fileNameString.toLocal8Bit();
1583 const char* fileName = fileNameAscii.data();1586 const char* fileName = fileNameAscii.data();
1584 1587
1585 VoxelTree importVoxels;1588 VoxelTree importVoxels;
@@ -1693,7 +1696,7 @@ void Application::pasteVoxels() { · 107 unmodified lines
1693 controlledBroadcastToNodes(args.messageBuffer, args.bufferInUse, & NODE_TYPE_VOXEL_SERVER, 1);1696 controlledBroadcastToNodes(args.messageBuffer, args.bufferInUse, & NODE_TYPE_VOXEL_SERVER, 1);
1694 qDebug("sending packet: %d\n", ++args.packetsSent);1697 qDebug("sending packet: %d\n", ++args.packetsSent);
1695 args.bytesSent += args.bufferInUse;1698 args.bytesSent += args.bufferInUse;
1696 qDebug("total bytes sent: %lld\n", args.bytesSent);1699 qDebug("total bytes sent: %lld\n", (long long int)args.bytesSent);
1697 }1700 }
1698 1701
1699 if (calculatedOctCode) {1702 if (calculatedOctCode) {
@@ -1758,6 +1761,8 @@ void Application::initMenu() { · 58 unmodified lines
1758 _renderLookatOn->setChecked(false);1761 _renderLookatOn->setChecked(false);
1759 (_renderLookatIndicatorOn = renderMenu->addAction("Lookat Indicator"))->setCheckable(true);1762 (_renderLookatIndicatorOn = renderMenu->addAction("Lookat Indicator"))->setCheckable(true);
1760 _renderLookatIndicatorOn->setChecked(true);1763 _renderLookatIndicatorOn->setChecked(true);
1764 (_renderParticleSystemOn = renderMenu->addAction("Particle System"))->setCheckable(true);
1765 _renderParticleSystemOn->setChecked(true);
1761 (_manualFirstPerson = renderMenu->addAction(1766 (_manualFirstPerson = renderMenu->addAction(
1762 "First Person", this, SLOT(setRenderFirstPerson(bool)), Qt::Key_P))->setCheckable(true);1767 "First Person", this, SLOT(setRenderFirstPerson(bool)), Qt::Key_P))->setCheckable(true);
1763 (_manualThirdPerson = renderMenu->addAction(1768 (_manualThirdPerson = renderMenu->addAction(
@@ -1995,8 +2000,11 @@ const float MAX_VOXEL_EDIT_DISTANCE = 20.0f; · 231 unmodified lines
1995const float HEAD_SPHERE_RADIUS = 0.07;2000const float HEAD_SPHERE_RADIUS = 0.07;
1996 2001
1997 2002
2003static uint16_t DEFAULT_NODE_ID_REF = 1;
2004
2005
1998bool Application::isLookingAtOtherAvatar(glm::vec3& mouseRayOrigin, glm::vec3& mouseRayDirection, 2006bool Application::isLookingAtOtherAvatar(glm::vec3& mouseRayOrigin, glm::vec3& mouseRayDirection,
1999 glm::vec3& eyePosition, uint16_t& nodeID) {2007 glm::vec3& eyePosition, uint16_t& nodeID = DEFAULT_NODE_ID_REF) {
2000 2008
2001 NodeList* nodeList = NodeList::getInstance();2009 NodeList* nodeList = NodeList::getInstance();
2002 for (NodeList::iterator node = nodeList->begin(); node != nodeList->end(); node++) {2010 for (NodeList::iterator node = nodeList->begin(); node != nodeList->end(); node++) {
@@ -2053,8 +2061,8 @@ void Application::update(float deltaTime) { · 50 unmodified lines
2053 2061
2054 // Set where I am looking based on my mouse ray (so that other people can see)2062 // Set where I am looking based on my mouse ray (so that other people can see)
2055 glm::vec3 eyePosition;2063 glm::vec3 eyePosition;
2056 uint16_t ignored;2064
2057 _isLookingAtOtherAvatar = isLookingAtOtherAvatar(mouseRayOrigin, mouseRayDirection, eyePosition, ignored);2065 _isLookingAtOtherAvatar = isLookingAtOtherAvatar(mouseRayOrigin, mouseRayDirection, eyePosition);
2058 if (_isLookingAtOtherAvatar) {2066 if (_isLookingAtOtherAvatar) {
2059 // If the mouse is over another avatar's head...2067 // If the mouse is over another avatar's head...
2060 glm::vec3 myLookAtFromMouse(eyePosition);2068 glm::vec3 myLookAtFromMouse(eyePosition);
@@ -2271,7 +2279,7 @@ void Application::update(float deltaTime) { · 210 unmodified lines
2271 _audio.eventuallyAnalyzePing();2279 _audio.eventuallyAnalyzePing();
2272 #endif2280 #endif
2273 2281
2274 if (TESTING_PARTICLE_SYSTEM) {2282 if (_renderParticleSystemOn->isChecked()) {
2275 updateParticleSystem(deltaTime);2283 updateParticleSystem(deltaTime);
2276 } 2284 }
2277}2285}
@@ -2320,8 +2328,8 @@ void Application::updateAvatar(float deltaTime) { · 42 unmodified lines
2320 _viewFrustum.computePickRay(MIDPOINT_OF_SCREEN, MIDPOINT_OF_SCREEN, screenCenterRayOrigin, screenCenterRayDirection);2328 _viewFrustum.computePickRay(MIDPOINT_OF_SCREEN, MIDPOINT_OF_SCREEN, screenCenterRayOrigin, screenCenterRayDirection);
2321 2329
2322 glm::vec3 eyePosition;2330 glm::vec3 eyePosition;
2323 uint16_t ignored;2331
2324 _isLookingAtOtherAvatar = isLookingAtOtherAvatar(screenCenterRayOrigin, screenCenterRayDirection, eyePosition, ignored);2332 _isLookingAtOtherAvatar = isLookingAtOtherAvatar(screenCenterRayOrigin, screenCenterRayDirection, eyePosition);
2325 if (_isLookingAtOtherAvatar) {2333 if (_isLookingAtOtherAvatar) {
2326 glm::vec3 myLookAtFromMouse(eyePosition);2334 glm::vec3 myLookAtFromMouse(eyePosition);
2327 _myAvatar.getHead().setLookAtPosition(myLookAtFromMouse);2335 _myAvatar.getHead().setLookAtPosition(myLookAtFromMouse);
@@ -2360,7 +2368,7 @@ void Application::updateAvatar(float deltaTime) { · 32 unmodified lines
2360 NodeList* nodeList = NodeList::getInstance();2368 NodeList* nodeList = NodeList::getInstance();
2361 if (nodeList->getOwnerID() != UNKNOWN_NODE_ID) {2369 if (nodeList->getOwnerID() != UNKNOWN_NODE_ID) {
2362 // if I know my ID, send head/hand data to the avatar mixer and voxel server2370 // if I know my ID, send head/hand data to the avatar mixer and voxel server
2363 unsigned char broadcastString[200];2371 unsigned char broadcastString[MAX_PACKET_SIZE];
2364 unsigned char* endOfBroadcastStringWrite = broadcastString;2372 unsigned char* endOfBroadcastStringWrite = broadcastString;
2365 2373
2366 endOfBroadcastStringWrite += populateTypeAndVersion(endOfBroadcastStringWrite, PACKET_TYPE_HEAD_DATA);2374 endOfBroadcastStringWrite += populateTypeAndVersion(endOfBroadcastStringWrite, PACKET_TYPE_HEAD_DATA);
@@ -2679,13 +2687,14 @@ void Application::displaySide(Camera& whichCamera) { · 312 unmodified lines
2679 if (_mouseVoxel.s != 0) {2687 if (_mouseVoxel.s != 0) {
2680 glDisable(GL_LIGHTING);2688 glDisable(GL_LIGHTING);
2681 glPushMatrix();2689 glPushMatrix();
2690 glScalef(TREE_SCALE, TREE_SCALE, TREE_SCALE);
2691 renderMouseVoxelGrid(_mouseVoxel.x, _mouseVoxel.y, _mouseVoxel.z, _mouseVoxel.s);
2682 if (_addVoxelMode->isChecked()) {2692 if (_addVoxelMode->isChecked()) {
2683 // use a contrasting color so that we can see what we're doing2693 // use a contrasting color so that we can see what we're doing
2684 glColor3ub(_mouseVoxel.red + 128, _mouseVoxel.green + 128, _mouseVoxel.blue + 128);2694 glColor3ub(_mouseVoxel.red + 128, _mouseVoxel.green + 128, _mouseVoxel.blue + 128);
2685 } else {2695 } else {
2686 glColor3ub(_mouseVoxel.red, _mouseVoxel.green, _mouseVoxel.blue);2696 glColor3ub(_mouseVoxel.red, _mouseVoxel.green, _mouseVoxel.blue);
2687 }2697 }
2688 glScalef(TREE_SCALE, TREE_SCALE, TREE_SCALE);
2689 glTranslatef(_mouseVoxel.x + _mouseVoxel.s*0.5f,2698 glTranslatef(_mouseVoxel.x + _mouseVoxel.s*0.5f,
2690 _mouseVoxel.y + _mouseVoxel.s*0.5f,2699 _mouseVoxel.y + _mouseVoxel.s*0.5f,
2691 _mouseVoxel.z + _mouseVoxel.s*0.5f);2700 _mouseVoxel.z + _mouseVoxel.s*0.5f);
@@ -2720,25 +2729,23 @@ void Application::displaySide(Camera& whichCamera) { · 28 unmodified lines
2720 _myAvatar.getHead().setLookAtPosition(_myCamera.getPosition());2729 _myAvatar.getHead().setLookAtPosition(_myCamera.getPosition());
2721 } 2730 }
2722 _myAvatar.render(_lookingInMirror->isChecked(), _renderAvatarBalls->isChecked());2731 _myAvatar.render(_lookingInMirror->isChecked(), _renderAvatarBalls->isChecked());
2723 _myAvatar.setDisplayingLookatVectors(_renderLookatOn->isChecked());
2724 2732
2725 if (_renderLookatIndicatorOn->isChecked() && _isLookingAtOtherAvatar) {2733 if (_renderLookatIndicatorOn->isChecked() && _isLookingAtOtherAvatar) {
2726 renderLookatIndicator(_lookatOtherPosition, whichCamera);2734 renderLookatIndicator(_lookatOtherPosition, whichCamera);
2727 }2735 }
2728 }2736 }
2729 2737
2730 if (TESTING_PARTICLE_SYSTEM) {2738 if (_renderParticleSystemOn->isChecked()) {
2731 if (_particleSystemInitialized) {2739 if (_particleSystemInitialized) {
2732 _particleSystem.render(); 2740 _particleSystem.render();
2733 }2741 }
2734 }2742 }
2735 2743
2736 // Render the world box2744 // Render the world box
2737 if (!_lookingInMirror->isChecked() && _renderStatsOn->isChecked()) { render_world_box(); }2745 if (!_lookingInMirror->isChecked() && _renderStatsOn->isChecked()) { render_world_box(); }
2738 2746
2739 // brad's frustum for debugging2747 // brad's frustum for debugging
2740 if (_frustumOn->isChecked()) renderViewFrustum(_viewFrustum);2748 if (_frustumOn->isChecked()) renderViewFrustum(_viewFrustum);
2741
2742}2749}
2743 2750
2744void Application::displayOverlay() {2751void Application::displayOverlay() {
@@ -3644,7 +3651,7 @@ void Application::saveSettings(QSettings* settings) { · 899 unmodified lines
3644}3651}
3645 3652
3646void Application::importSettings() {3653void Application::importSettings() {
3647 QString locationDir(QDesktopServices::displayName(QDesktopServices::DesktopLocation));3654 QString locationDir(QStandardPaths::displayName(QStandardPaths::DesktopLocation));
3648 QString fileName = QFileDialog::getOpenFileName(_window,3655 QString fileName = QFileDialog::getOpenFileName(_window,
3649 tr("Open .ini config file"),3656 tr("Open .ini config file"),
3650 locationDir,3657 locationDir,
@@ -3656,7 +3663,7 @@ void Application::importSettings() { · 5 unmodified lines
3656}3663}
3657 3664
3658void Application::exportSettings() {3665void Application::exportSettings() {
3659 QString locationDir(QDesktopServices::displayName(QDesktopServices::DesktopLocation));3666 QString locationDir(QStandardPaths::displayName(QStandardPaths::DesktopLocation));
3660 QString fileName = QFileDialog::getSaveFileName(_window,3667 QString fileName = QFileDialog::getSaveFileName(_window,
3661 tr("Save .ini config file"),3668 tr("Save .ini config file"),
3662 locationDir,3669 locationDir,
@@ -3669,56 +3676,57 @@ void Application::exportSettings() { · 6 unmodified lines
3669}3676}
3670 3677
3671 3678
3672
3673void Application::updateParticleSystem(float deltaTime) {3679void Application::updateParticleSystem(float deltaTime) {
3674 3680
3675 if (!_particleSystemInitialized) {3681 if (!_particleSystemInitialized) {
3682
3683 const int LIFESPAN_IN_SECONDS = 100000.0f;
3684 const float EMIT_RATE_IN_SECONDS = 10000.0;
3676 // create a stable test emitter and spit out a bunch of particles3685 // create a stable test emitter and spit out a bunch of particles
3677 _coolDemoParticleEmitter = _particleSystem.addEmitter();3686 _coolDemoParticleEmitter = _particleSystem.addEmitter();
3678 3687
3679 if (_coolDemoParticleEmitter != -1) {3688 if (_coolDemoParticleEmitter != -1) {
3689
3680 _particleSystem.setShowingEmitter(_coolDemoParticleEmitter, true);3690 _particleSystem.setShowingEmitter(_coolDemoParticleEmitter, true);
3681 glm::vec3 particleEmitterPosition = glm::vec3(5.0f, 1.0f, 5.0f); 3691 glm::vec3 particleEmitterPosition = glm::vec3(5.0f, 1.0f, 5.0f);
3682 _particleSystem.setEmitterPosition(_coolDemoParticleEmitter, particleEmitterPosition);3692
3683 glm::vec3 velocity(0.0f, 0.1f, 0.0f);3693 _particleSystem.setEmitterPosition (_coolDemoParticleEmitter, particleEmitterPosition);
3684 float lifespan = 100000.0f;3694 _particleSystem.setEmitterParticleLifespan(_coolDemoParticleEmitter, LIFESPAN_IN_SECONDS);
3685 _particleSystem.emitParticlesNow(_coolDemoParticleEmitter, 1500, velocity, lifespan); 3695 _particleSystem.setEmitterThrust (_coolDemoParticleEmitter, 0.0f);
3696 _particleSystem.setEmitterRate (_coolDemoParticleEmitter, EMIT_RATE_IN_SECONDS); // to emit a pile o particles now
3686 }3697 }
3687 3698
3688 // signal that the particle system has been initialized 3699 // signal that the particle system has been initialized
3689 _particleSystemInitialized = true; 3700 _particleSystemInitialized = true;
3690 } else {3701 } else {
3691 // update the particle system3702 // update the particle system
3692 3703
3693 static float t = 0.0f;3704 static bool emitting = true;
3694 t += deltaTime;3705 static float effectsTimer = 0.0f;
3706 effectsTimer += deltaTime;
3695 3707
3696 if (_coolDemoParticleEmitter != -1) {3708 if (_coolDemoParticleEmitter != -1) {
3697 3709
3698 glm::vec3 tilt = glm::vec33710 _particleSystem.setEmitterDirection(_coolDemoParticleEmitter, glm::vec3(0.0f, 1.0f, 0.0f));
3699 (
3700 30.0f * sinf( t * 0.55f ),
3701 0.0f,
3702 30.0f * cosf( t * 0.75f )
3703 );
3704
3705 _particleSystem.setEmitterRotation(_coolDemoParticleEmitter, glm::quat(glm::radians(tilt)));
3706 3711
3707 ParticleSystem::ParticleAttributes attributes;3712 ParticleSystem::ParticleAttributes attributes;
3708 3713
3709 attributes.radius = 0.01f;3714 attributes.radius = 0.01f;
3710 attributes.color = glm::vec4( 1.0f, 1.0f, 1.0f, 1.0f);3715 attributes.color = glm::vec4( 1.0f, 1.0f, 1.0f, 1.0f);
3711 attributes.gravity = 0.0f + 0.05f * sinf( t * 0.52f );3716 attributes.gravity = 0.0f + 0.05f * sinf( effectsTimer * 0.52f );
3712 attributes.airFriction = 2.5 + 2.0f * sinf( t * 0.32f );3717 attributes.airFriction = 2.5 + 2.0f * sinf( effectsTimer * 0.32f );
3713 attributes.jitter = 0.05f + 0.05f * sinf( t * 0.42f );3718 attributes.jitter = 0.05f + 0.05f * sinf( effectsTimer * 0.42f );
3714 attributes.emitterAttraction = 0.015f + 0.015f * cosf( t * 0.6f );3719 attributes.emitterAttraction = 0.015f + 0.015f * cosf( effectsTimer * 0.6f );
3715 attributes.tornadoForce = 0.0f + 0.03f * sinf( t * 0.7f );3720 attributes.tornadoForce = 0.0f + 0.03f * sinf( effectsTimer * 0.7f );
3716 attributes.neighborAttraction = 0.1f + 0.1f * cosf( t * 0.8f );3721 attributes.neighborAttraction = 0.1f + 0.1f * cosf( effectsTimer * 0.8f );
3717 attributes.neighborRepulsion = 0.2f + 0.2f * sinf( t * 0.4f );3722 attributes.neighborRepulsion = 0.2f + 0.2f * sinf( effectsTimer * 0.4f );
3718 attributes.bounce = 1.0f;3723 attributes.bounce = 1.0f;
3719 attributes.usingCollisionSphere = true;3724 attributes.usingCollisionSphere = true;
3720 attributes.collisionSpherePosition = glm::vec3( 5.0f, 0.5f, 5.0f );3725 attributes.collisionSpherePosition = glm::vec3( 5.0f, 0.5f, 5.0f );
3721 attributes.collisionSphereRadius = 0.5f;3726 attributes.collisionSphereRadius = 0.5f;
3727 attributes.usingCollisionPlane = true;
3728 attributes.collisionPlanePosition = glm::vec3( 5.0f, 0.0f, 5.0f );
3729 attributes.collisionPlaneNormal = glm::vec3( 0.0f, 1.0f, 0.0f );
3722 3730
3723 if (attributes.gravity < 0.0f) {3731 if (attributes.gravity < 0.0f) {
3724 attributes.gravity = 0.0f;3732 attributes.gravity = 0.0f;
@@ -3729,6 +3737,15 @@ void Application::updateParticleSystem(float deltaTime) { · 4 unmodified lines
3729 3737
3730 _particleSystem.setUpDirection(glm::vec3(0.0f, 1.0f, 0.0f)); 3738 _particleSystem.setUpDirection(glm::vec3(0.0f, 1.0f, 0.0f));
3731 _particleSystem.simulate(deltaTime); 3739 _particleSystem.simulate(deltaTime);
3740
3741 const float EMIT_RATE_IN_SECONDS = 0.0;
3742
3743 if (_coolDemoParticleEmitter != -1) {
3744 if (emitting) {
3745 _particleSystem.setEmitterRate(_coolDemoParticleEmitter, EMIT_RATE_IN_SECONDS); // stop emitter
3746 emitting = false;
3747 }
3748 }
3732 }3749 }
3733}3750}
3734 3751

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