History

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

ZappoMan committed 13 years ago

Commit 983db5f2 parents 75fe532 e0881ad34 files · +1416 −574Browse files

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

Unified · Split

interface/src/Application.cpp+178−102
@@ -164,9 +164,9 @@ void GLCanvas::wheelEvent(QWheelEvent* event) { · 163 unmodified lines
164164 Application::getInstance()->wheelEvent(event);
165165 }
166166
167−void messageHandler(QtMsgType type, const char* message) {
168− fprintf(stdout, "%s", message);
169− LogDisplay::instance.addMessage(message);
167+void messageHandler(QtMsgType type, const QMessageLogContext& context, const QString &message) {
168+ fprintf(stdout, "%s", message.toLocal8Bit().constData());
169+ LogDisplay::instance.addMessage(message.toLocal8Bit().constData());
170170 }
171171
172172 Application::Application(int& argc, char** argv, timeval &startup_time) :
@@ -222,7 +222,7 @@ Application::Application(int& argc, char** argv, timeval &startup_time) : · 49 unmodified lines
222222 _applicationStartupTime = startup_time;
223223 _window->setWindowTitle("Interface");
224224
225− qInstallMsgHandler(messageHandler);
225+ qInstallMessageHandler(messageHandler);
226226
227227 unsigned int listenPort = 0; // bind to an ephemeral port by default
228228 const char** constArgv = const_cast<const char**>(argv);
@@ -564,6 +564,11 @@ void Application::keyPressEvent(QKeyEvent* event) { · 335 unmodified lines
564564 }
565565 return;
566566 }
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+ }
567572
568573 bool shifted = event->modifiers().testFlag(Qt::ShiftModifier);
569574 switch (event->key()) {
@@ -1216,7 +1221,7 @@ void Application::editPreferences() { · 646 unmodified lines
12161221
12171222 if (domainServerHostname->text().size() > 0) {
12181223 // the user input a new hostname, use that
1219− newHostname = domainServerHostname->text().toAscii();
1224+ newHostname = domainServerHostname->text().toLocal8Bit();
12201225 } else {
12211226 // the user left the field blank, use the default hostname
12221227 newHostname = QByteArray(DEFAULT_DOMAIN_HOSTNAME);
@@ -1494,16 +1499,18 @@ bool Application::sendVoxelsOperation(VoxelNode* node, void* extraData) { · 271 unmodified lines
14941499
14951500 uint64_t now = usecTimestampNow();
14961501 // dynamically sleep until we need to fire off the next set of voxels
1497− const uint64_t CLIENT_TO_SERVER_VOXEL_SEND_INTERVAL_USECS = 1000 * 5; // 1 packet every 10 milliseconds
14981502 uint64_t elapsed = now - args->lastSendTime;
14991503 int usecToSleep = CLIENT_TO_SERVER_VOXEL_SEND_INTERVAL_USECS - elapsed;
15001504 if (usecToSleep > 0) {
1501− qDebug("sendVoxelsOperation: packet: %d bytes:%lld elapsed %lld usecs, sleeping for %d usecs!\n",
1502− args->packetsSent, (long long int)args->bytesSent, (long long int)elapsed, usecToSleep);
1505+ //qDebug("sendVoxelsOperation: packet: %d bytes:%lld elapsed %lld usecs, sleeping for %d usecs!\n",
1506+ // args->packetsSent, (long long int)args->bytesSent, (long long int)elapsed, usecToSleep);
1507+
1508+ Application::getInstance()->timer();
1509+
15031510 usleep(usecToSleep);
15041511 } else {
1505− qDebug("sendVoxelsOperation: packet: %d bytes:%lld elapsed %lld usecs, no need to sleep!\n",
1506− args->packetsSent, (long long int)args->bytesSent, (long long int)elapsed);
1512+ //qDebug("sendVoxelsOperation: packet: %d bytes:%lld elapsed %lld usecs, no need to sleep!\n",
1513+ // args->packetsSent, (long long int)args->bytesSent, (long long int)elapsed);
15071514 }
15081515 args->lastSendTime = now;
15091516 }
@@ -1516,12 +1523,12 @@ bool Application::sendVoxelsOperation(VoxelNode* node, void* extraData) { · 6 unmodified lines
15161523 }
15171524
15181525 void Application::exportVoxels() {
1519− QString desktopLocation = QDesktopServices::storageLocation(QDesktopServices::DesktopLocation);
1526+ QString desktopLocation = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation);
15201527 QString suggestedName = desktopLocation.append("/voxels.svo");
15211528
15221529 QString fileNameString = QFileDialog::getSaveFileName(_glWidget, tr("Export Voxels"), suggestedName,
15231530 tr("Sparse Voxel Octree Files (*.svo)"));
1524− QByteArray fileNameAscii = fileNameString.toAscii();
1531+ QByteArray fileNameAscii = fileNameString.toLocal8Bit();
15251532 const char* fileName = fileNameAscii.data();
15261533 VoxelNode* selectedNode = _voxels.getVoxelAt(_mouseVoxel.x, _mouseVoxel.y, _mouseVoxel.z, _mouseVoxel.s);
15271534 if (selectedNode) {
@@ -1536,11 +1543,11 @@ void Application::exportVoxels() { · 8 unmodified lines
15361543
15371544 const char* IMPORT_FILE_TYPES = "Sparse Voxel Octree Files, Square PNG, Schematic Files (*.svo *.png *.schematic)";
15381545 void Application::importVoxelsToClipboard() {
1539− QString desktopLocation = QDesktopServices::storageLocation(QDesktopServices::DesktopLocation);
1546+ QString desktopLocation = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation);
15401547 QString fileNameString = QFileDialog::getOpenFileName(_glWidget, tr("Import Voxels to Clipboard"), desktopLocation,
15411548 tr(IMPORT_FILE_TYPES));
15421549
1543− QByteArray fileNameAscii = fileNameString.toAscii();
1550+ QByteArray fileNameAscii = fileNameString.toLocal8Bit();
15441551 const char* fileName = fileNameAscii.data();
15451552
15461553 _clipboardTree.eraseAllVoxels();
@@ -1570,71 +1577,128 @@ void Application::importVoxelsToClipboard() { · 23 unmodified lines
15701577 }
15711578
15721579 void Application::importVoxels() {
1573− QString desktopLocation = QDesktopServices::storageLocation(QDesktopServices::DesktopLocation);
1574− QString fileNameString = QFileDialog::getOpenFileName(_glWidget, tr("Import Voxels"), desktopLocation,
1580+ QString desktopLocation = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation);
1581+
1582+ QStringList fileNameStringList = QFileDialog::getOpenFileNames(_glWidget, tr("Import Voxels"), desktopLocation,
15751583 tr(IMPORT_FILE_TYPES));
15761584
1577− QByteArray fileNameAscii = fileNameString.toAscii();
1578− const char* fileName = fileNameAscii.data();
1585+
1586+ // remember the "selected" voxel point before we do any importing...
1587+ float originalX = _mouseVoxel.x;
1588+ float originalZ = _mouseVoxel.z;
1589+
1590+ const int PNG_TYPE_NAME_LENGTH = 4;
1591+ const int SVO_TYPE_NAME_LENGTH = 4;
1592+ const int SCH_TYPE_NAME_LENGTH = 10;
1593+
1594+ for (int i = 0; i < fileNameStringList.size(); i++) {
1595+ QString fileNameString = fileNameStringList.at(i);
1596+ QByteArray fileNameAscii = fileNameString.toLocal8Bit();
1597+ const char* fileName = fileNameAscii.data();
15791598
1580− VoxelTree importVoxels;
1581− if (fileNameString.endsWith(".png", Qt::CaseInsensitive)) {
1582− QImage pngImage = QImage(fileName);
1583− if (pngImage.height() != pngImage.width()) {
1584− qDebug("ERROR: Bad PNG size: height != width.\n");
1585− return;
1599+ int fileTypeNameLength = 0;
1600+ VoxelTree importVoxels;
1601+ if (fileNameString.endsWith(".png", Qt::CaseInsensitive)) {
1602+ QImage pngImage = QImage(fileName);
1603+ fileTypeNameLength = PNG_TYPE_NAME_LENGTH;
1604+ if (pngImage.height() != pngImage.width()) {
1605+ qDebug("ERROR: Bad PNG size: height != width.\n");
1606+ return;
1607+ }
1608+
1609+ const uint32_t* pixels;
1610+ if (pngImage.format() == QImage::Format_ARGB32) {
1611+ pixels = reinterpret_cast<const uint32_t*>(pngImage.constBits());
1612+ } else {
1613+ QImage tmp = pngImage.convertToFormat(QImage::Format_ARGB32);
1614+ pixels = reinterpret_cast<const uint32_t*>(tmp.constBits());
1615+ }
1616+
1617+ importVoxels.readFromSquareARGB32Pixels(pixels, pngImage.height());
1618+ } else if (fileNameString.endsWith(".svo", Qt::CaseInsensitive)) {
1619+ importVoxels.readFromSVOFile(fileName);
1620+ fileTypeNameLength = SVO_TYPE_NAME_LENGTH;
1621+ } else if (fileNameString.endsWith(".schematic", Qt::CaseInsensitive)) {
1622+ importVoxels.readFromSchematicFile(fileName);
1623+ fileTypeNameLength = SCH_TYPE_NAME_LENGTH;
15861624 }
15871625
1588− const uint32_t* pixels;
1589− if (pngImage.format() == QImage::Format_ARGB32) {
1590− pixels = reinterpret_cast<const uint32_t*>(pngImage.constBits());
1626+ int indexOfFirstPeriod = fileNameString.indexOf('.');
1627+
1628+ QString fileCoord = fileNameString.mid(indexOfFirstPeriod + 1,
1629+ fileNameString.length() - indexOfFirstPeriod - fileTypeNameLength - 1);
1630+
1631+ indexOfFirstPeriod = fileCoord.indexOf('.');
1632+ QString columnNumString = fileCoord.right(fileCoord.length() - indexOfFirstPeriod - 1);
1633+ QString rowNumString = fileCoord.left(indexOfFirstPeriod);
1634+
1635+ int columnNum = columnNumString.toFloat();
1636+ int rowNum = rowNumString.toFloat();
1637+
1638+ qDebug("columnNum: %d\t rowNum: %d\n", columnNum, rowNum);
1639+
1640+ _mouseVoxel.x = originalX + (columnNum - 1) * _mouseVoxel.s;
1641+ _mouseVoxel.z = originalZ + (rowNum - 1) * _mouseVoxel.s;
1642+
1643+ VoxelNode* selectedNode = _voxels.getVoxelAt(_mouseVoxel.x, _mouseVoxel.y, _mouseVoxel.z, _mouseVoxel.s);
1644+
1645+ // Recurse the Import Voxels tree, where everything is root relative, and send all the colored voxels to
1646+ // the server as an set voxel message, this will also rebase the voxels to the new location
1647+ unsigned char* calculatedOctCode = NULL;
1648+ SendVoxelsOperationArgs args;
1649+ args.lastSendTime = usecTimestampNow();
1650+ args.packetsSent = 0;
1651+ args.bytesSent = 0;
1652+
1653+ int numBytesPacketHeader = populateTypeAndVersion(args.messageBuffer, PACKET_TYPE_SET_VOXEL_DESTRUCTIVE);
1654+
1655+ unsigned short int* sequenceAt = (unsigned short int*)&args.messageBuffer[numBytesPacketHeader];
1656+ *sequenceAt = 0;
1657+ args.bufferInUse = numBytesPacketHeader + sizeof(unsigned short int); // set to command + sequence
1658+
1659+ // we only need the selected voxel to get the newBaseOctCode, which we can actually calculate from the
1660+ // voxel size/position details.
1661+ if (selectedNode) {
1662+ args.newBaseOctCode = selectedNode->getOctalCode();
15911663 } else {
1592− QImage tmp = pngImage.convertToFormat(QImage::Format_ARGB32);
1593− pixels = reinterpret_cast<const uint32_t*>(tmp.constBits());
1664+ args.newBaseOctCode = calculatedOctCode = pointToVoxel(_mouseVoxel.x, _mouseVoxel.y, _mouseVoxel.z, _mouseVoxel.s);
15941665 }
1595−
1596− importVoxels.readFromSquareARGB32Pixels(pixels, pngImage.height());
1597− } else if (fileNameString.endsWith(".svo", Qt::CaseInsensitive)) {
1598− importVoxels.readFromSVOFile(fileName);
1599− } else if (fileNameString.endsWith(".schematic", Qt::CaseInsensitive)) {
1600− importVoxels.readFromSchematicFile(fileName);
1601− }
1602−
1603− VoxelNode* selectedNode = _voxels.getVoxelAt(_mouseVoxel.x, _mouseVoxel.y, _mouseVoxel.z, _mouseVoxel.s);
1604−
1605− // Recurse the Import Voxels tree, where everything is root relative, and send all the colored voxels to
1606− // the server as an set voxel message, this will also rebase the voxels to the new location
1607− unsigned char* calculatedOctCode = NULL;
1608− SendVoxelsOperationArgs args;
1609− args.lastSendTime = usecTimestampNow();
1610− args.packetsSent = 0;
1611− args.bytesSent = 0;
16121666
1613− int numBytesPacketHeader = populateTypeAndVersion(args.messageBuffer, PACKET_TYPE_SET_VOXEL_DESTRUCTIVE);
1667+ qDebug("column:%d, row:%d, voxel:%f,%f,%f,%f\n", columnNum, rowNum, _mouseVoxel.x, _mouseVoxel.y, _mouseVoxel.z, _mouseVoxel.s );
1668+
1669+ // send the insert/paste of these voxels
1670+ importVoxels.recurseTreeWithOperation(sendVoxelsOperation, &args);
16141671
1615− unsigned short int* sequenceAt = (unsigned short int*)&args.messageBuffer[numBytesPacketHeader];
1616− *sequenceAt = 0;
1617− args.bufferInUse = numBytesPacketHeader + sizeof(unsigned short int); // set to command + sequence
1672+ // If we have voxels left in the packet, then send the packet
1673+ if (args.bufferInUse > (numBytesPacketHeader + sizeof(unsigned short int))) {
1674+ controlledBroadcastToNodes(args.messageBuffer, args.bufferInUse, & NODE_TYPE_VOXEL_SERVER, 1);
16181675
1619− // we only need the selected voxel to get the newBaseOctCode, which we can actually calculate from the
1620− // voxel size/position details.
1621− if (selectedNode) {
1622− args.newBaseOctCode = selectedNode->getOctalCode();
1623− } else {
1624− args.newBaseOctCode = calculatedOctCode = pointToVoxel(_mouseVoxel.x, _mouseVoxel.y, _mouseVoxel.z, _mouseVoxel.s);
1625− }
16261676
1627− importVoxels.recurseTreeWithOperation(sendVoxelsOperation, &args);
1677+ args.packetsSent++;
1678+ args.bytesSent += args.bufferInUse;
1679+
1680+ uint64_t now = usecTimestampNow();
1681+ // dynamically sleep until we need to fire off the next set of voxels
1682+ uint64_t elapsed = now - args.lastSendTime;
1683+ int usecToSleep = CLIENT_TO_SERVER_VOXEL_SEND_INTERVAL_USECS - elapsed;
1684+
1685+ if (usecToSleep > 0) {
1686+ //qDebug("after sendVoxelsOperation: packet: %d bytes:%lld elapsed %lld usecs, sleeping for %d usecs!\n",
1687+ // args.packetsSent, (long long int)args.bytesSent, (long long int)elapsed, usecToSleep);
1688+ usleep(usecToSleep);
1689+ } else {
1690+ //qDebug("after sendVoxelsOperation: packet: %d bytes:%lld elapsed %lld usecs, no need to sleep!\n",
1691+ // args.packetsSent, (long long int)args.bytesSent, (long long int)elapsed);
1692+ }
1693+ args.lastSendTime = now;
1694+ }
1695+
1696+ if (calculatedOctCode) {
1697+ delete[] calculatedOctCode;
1698+ }
16281699
1629− // If we have voxels left in the packet, then send the packet
1630− if (args.bufferInUse > (numBytesPacketHeader + sizeof(unsigned short int))) {
1631− controlledBroadcastToNodes(args.messageBuffer, args.bufferInUse, & NODE_TYPE_VOXEL_SERVER, 1);
16321700 }
16331701
1634− if (calculatedOctCode) {
1635− delete[] calculatedOctCode;
1636− }
1637−
16381702 // restore the main window's active state
16391703 _window->activateWindow();
16401704 }
@@ -1989,8 +2053,11 @@ const float MAX_VOXEL_EDIT_DISTANCE = 20.0f; · 348 unmodified lines
19892053 const float HEAD_SPHERE_RADIUS = 0.07;
19902054
19912055
2056+static uint16_t DEFAULT_NODE_ID_REF = 1;
2057+
2058+
19922059 bool Application::isLookingAtOtherAvatar(glm::vec3& mouseRayOrigin, glm::vec3& mouseRayDirection,
1993− glm::vec3& eyePosition, uint16_t& nodeID) {
2060+ glm::vec3& eyePosition, uint16_t& nodeID = DEFAULT_NODE_ID_REF) {
19942061
19952062 NodeList* nodeList = NodeList::getInstance();
19962063 for (NodeList::iterator node = nodeList->begin(); node != nodeList->end(); node++) {
@@ -2047,8 +2114,8 @@ void Application::update(float deltaTime) { · 50 unmodified lines
20472114
20482115 // Set where I am looking based on my mouse ray (so that other people can see)
20492116 glm::vec3 eyePosition;
2050− uint16_t ignored;
2051− _isLookingAtOtherAvatar = isLookingAtOtherAvatar(mouseRayOrigin, mouseRayDirection, eyePosition, ignored);
2117+
2118+ _isLookingAtOtherAvatar = isLookingAtOtherAvatar(mouseRayOrigin, mouseRayDirection, eyePosition);
20522119 if (_isLookingAtOtherAvatar) {
20532120 // If the mouse is over another avatar's head...
20542121 glm::vec3 myLookAtFromMouse(eyePosition);
@@ -2314,8 +2381,8 @@ void Application::updateAvatar(float deltaTime) { · 259 unmodified lines
23142381 _viewFrustum.computePickRay(MIDPOINT_OF_SCREEN, MIDPOINT_OF_SCREEN, screenCenterRayOrigin, screenCenterRayDirection);
23152382
23162383 glm::vec3 eyePosition;
2317− uint16_t ignored;
2318− _isLookingAtOtherAvatar = isLookingAtOtherAvatar(screenCenterRayOrigin, screenCenterRayDirection, eyePosition, ignored);
2384+
2385+ _isLookingAtOtherAvatar = isLookingAtOtherAvatar(screenCenterRayOrigin, screenCenterRayDirection, eyePosition);
23192386 if (_isLookingAtOtherAvatar) {
23202387 glm::vec3 myLookAtFromMouse(eyePosition);
23212388 _myAvatar.getHead().setLookAtPosition(myLookAtFromMouse);
@@ -2354,7 +2421,7 @@ void Application::updateAvatar(float deltaTime) { · 32 unmodified lines
23542421 NodeList* nodeList = NodeList::getInstance();
23552422 if (nodeList->getOwnerID() != UNKNOWN_NODE_ID) {
23562423 // if I know my ID, send head/hand data to the avatar mixer and voxel server
2357− unsigned char broadcastString[200];
2424+ unsigned char broadcastString[MAX_PACKET_SIZE];
23582425 unsigned char* endOfBroadcastStringWrite = broadcastString;
23592426
23602427 endOfBroadcastStringWrite += populateTypeAndVersion(endOfBroadcastStringWrite, PACKET_TYPE_HEAD_DATA);
@@ -2673,13 +2740,14 @@ void Application::displaySide(Camera& whichCamera) { · 312 unmodified lines
26732740 if (_mouseVoxel.s != 0) {
26742741 glDisable(GL_LIGHTING);
26752742 glPushMatrix();
2743+ glScalef(TREE_SCALE, TREE_SCALE, TREE_SCALE);
2744+ renderMouseVoxelGrid(_mouseVoxel.x, _mouseVoxel.y, _mouseVoxel.z, _mouseVoxel.s);
26762745 if (_addVoxelMode->isChecked()) {
26772746 // use a contrasting color so that we can see what we're doing
26782747 glColor3ub(_mouseVoxel.red + 128, _mouseVoxel.green + 128, _mouseVoxel.blue + 128);
26792748 } else {
26802749 glColor3ub(_mouseVoxel.red, _mouseVoxel.green, _mouseVoxel.blue);
26812750 }
2682− glScalef(TREE_SCALE, TREE_SCALE, TREE_SCALE);
26832751 glTranslatef(_mouseVoxel.x + _mouseVoxel.s*0.5f,
26842752 _mouseVoxel.y + _mouseVoxel.s*0.5f,
26852753 _mouseVoxel.z + _mouseVoxel.s*0.5f);
@@ -2725,13 +2793,12 @@ void Application::displaySide(Camera& whichCamera) { · 39 unmodified lines
27252793 _particleSystem.render();
27262794 }
27272795 }
2728−
2796+
27292797 // Render the world box
27302798 if (!_lookingInMirror->isChecked() && _renderStatsOn->isChecked()) { render_world_box(); }
27312799
27322800 // brad's frustum for debugging
27332801 if (_frustumOn->isChecked()) renderViewFrustum(_viewFrustum);
2734−
27352802 }
27362803
27372804 void Application::displayOverlay() {
@@ -3475,6 +3542,7 @@ void* Application::networkReceive(void* args) { · 737 unmodified lines
34753542 }
34763543
34773544 if (NodeList::getInstance()->getNodeSocket()->receive(&senderAddress, app->_incomingPacket, &bytesReceived)) {
3545+
34783546 app->_packetCount++;
34793547 app->_bytesCount += bytesReceived;
34803548
@@ -3519,7 +3587,6 @@ void* Application::networkReceive(void* args) { · 38 unmodified lines
35193587 Node* voxelServer = NodeList::getInstance()->nodeWithAddress(&senderAddress);
35203588 if (voxelServer && socketMatch(voxelServer->getActiveSocket(), &senderAddress)) {
35213589 voxelServer->lock();
3522−
35233590 if (messageData[0] == PACKET_TYPE_ENVIRONMENT_DATA) {
35243591 app->_environment.parseData(&senderAddress, messageData, messageLength);
35253592 } else {
@@ -3527,7 +3594,6 @@ void* Application::networkReceive(void* args) { · 1 unmodified line
35273594 app->_voxels.parseData(messageData, messageLength);
35283595 app->_voxels.setDataSourceID(UNKNOWN_NODE_ID);
35293596 }
3530−
35313597 voxelServer->unlock();
35323598 }
35333599 }
@@ -3647,7 +3713,7 @@ void Application::saveSettings(QSettings* settings) { · 113 unmodified lines
36473713 }
36483714
36493715 void Application::importSettings() {
3650− QString locationDir(QDesktopServices::displayName(QDesktopServices::DesktopLocation));
3716+ QString locationDir(QStandardPaths::displayName(QStandardPaths::DesktopLocation));
36513717 QString fileName = QFileDialog::getOpenFileName(_window,
36523718 tr("Open .ini config file"),
36533719 locationDir,
@@ -3659,7 +3725,7 @@ void Application::importSettings() { · 5 unmodified lines
36593725 }
36603726
36613727 void Application::exportSettings() {
3662− QString locationDir(QDesktopServices::displayName(QDesktopServices::DesktopLocation));
3728+ QString locationDir(QStandardPaths::displayName(QStandardPaths::DesktopLocation));
36633729 QString fileName = QFileDialog::getSaveFileName(_window,
36643730 tr("Save .ini config file"),
36653731 locationDir,
@@ -3672,56 +3738,57 @@ void Application::exportSettings() { · 6 unmodified lines
36723738 }
36733739
36743740
3675−
36763741 void Application::updateParticleSystem(float deltaTime) {
36773742
36783743 if (!_particleSystemInitialized) {
3744+
3745+ const int LIFESPAN_IN_SECONDS = 100000.0f;
3746+ const float EMIT_RATE_IN_SECONDS = 10000.0;
36793747 // create a stable test emitter and spit out a bunch of particles
36803748 _coolDemoParticleEmitter = _particleSystem.addEmitter();
3681−
3749+
36823750 if (_coolDemoParticleEmitter != -1) {
3751+
36833752 _particleSystem.setShowingEmitter(_coolDemoParticleEmitter, true);
36843753 glm::vec3 particleEmitterPosition = glm::vec3(5.0f, 1.0f, 5.0f);
3685− _particleSystem.setEmitterPosition(_coolDemoParticleEmitter, particleEmitterPosition);
3686− glm::vec3 velocity(0.0f, 0.1f, 0.0f);
3687− float lifespan = 100000.0f;
3688− _particleSystem.emitParticlesNow(_coolDemoParticleEmitter, 1500, velocity, lifespan);
3754+
3755+ _particleSystem.setEmitterPosition (_coolDemoParticleEmitter, particleEmitterPosition);
3756+ _particleSystem.setEmitterParticleLifespan(_coolDemoParticleEmitter, LIFESPAN_IN_SECONDS);
3757+ _particleSystem.setEmitterThrust (_coolDemoParticleEmitter, 0.0f);
3758+ _particleSystem.setEmitterRate (_coolDemoParticleEmitter, EMIT_RATE_IN_SECONDS); // to emit a pile o particles now
36893759 }
36903760
36913761 // signal that the particle system has been initialized
36923762 _particleSystemInitialized = true;
36933763 } else {
36943764 // update the particle system
3695−
3696− static float t = 0.0f;
3697− t += deltaTime;
3765+
3766+ static bool emitting = true;
3767+ static float effectsTimer = 0.0f;
3768+ effectsTimer += deltaTime;
36983769
36993770 if (_coolDemoParticleEmitter != -1) {
37003771
3701− glm::vec3 tilt = glm::vec3
3702− (
3703− 30.0f * sinf( t * 0.55f ),
3704− 0.0f,
3705− 30.0f * cosf( t * 0.75f )
3706− );
3707−
3708− _particleSystem.setEmitterRotation(_coolDemoParticleEmitter, glm::quat(glm::radians(tilt)));
3772+ _particleSystem.setEmitterDirection(_coolDemoParticleEmitter, glm::vec3(0.0f, 1.0f, 0.0f));
37093773
37103774 ParticleSystem::ParticleAttributes attributes;
37113775
37123776 attributes.radius = 0.01f;
37133777 attributes.color = glm::vec4( 1.0f, 1.0f, 1.0f, 1.0f);
3714− attributes.gravity = 0.0f + 0.05f * sinf( t * 0.52f );
3715− attributes.airFriction = 2.5 + 2.0f * sinf( t * 0.32f );
3716− attributes.jitter = 0.05f + 0.05f * sinf( t * 0.42f );
3717− attributes.emitterAttraction = 0.015f + 0.015f * cosf( t * 0.6f );
3718− attributes.tornadoForce = 0.0f + 0.03f * sinf( t * 0.7f );
3719− attributes.neighborAttraction = 0.1f + 0.1f * cosf( t * 0.8f );
3720− attributes.neighborRepulsion = 0.2f + 0.2f * sinf( t * 0.4f );
3778+ attributes.gravity = 0.0f + 0.05f * sinf( effectsTimer * 0.52f );
3779+ attributes.airFriction = 2.5 + 2.0f * sinf( effectsTimer * 0.32f );
3780+ attributes.jitter = 0.05f + 0.05f * sinf( effectsTimer * 0.42f );
3781+ attributes.emitterAttraction = 0.015f + 0.015f * cosf( effectsTimer * 0.6f );
3782+ attributes.tornadoForce = 0.0f + 0.03f * sinf( effectsTimer * 0.7f );
3783+ attributes.neighborAttraction = 0.1f + 0.1f * cosf( effectsTimer * 0.8f );
3784+ attributes.neighborRepulsion = 0.2f + 0.2f * sinf( effectsTimer * 0.4f );
37213785 attributes.bounce = 1.0f;
37223786 attributes.usingCollisionSphere = true;
37233787 attributes.collisionSpherePosition = glm::vec3( 5.0f, 0.5f, 5.0f );
37243788 attributes.collisionSphereRadius = 0.5f;
3789+ attributes.usingCollisionPlane = true;
3790+ attributes.collisionPlanePosition = glm::vec3( 5.0f, 0.0f, 5.0f );
3791+ attributes.collisionPlaneNormal = glm::vec3( 0.0f, 1.0f, 0.0f );
37253792
37263793 if (attributes.gravity < 0.0f) {
37273794 attributes.gravity = 0.0f;
@@ -3732,6 +3799,15 @@ void Application::updateParticleSystem(float deltaTime) { · 4 unmodified lines
37323799
37333800 _particleSystem.setUpDirection(glm::vec3(0.0f, 1.0f, 0.0f));
37343801 _particleSystem.simulate(deltaTime);
3802+
3803+ const float EMIT_RATE_IN_SECONDS = 0.0;
3804+
3805+ if (_coolDemoParticleEmitter != -1) {
3806+ if (emitting) {
3807+ _particleSystem.setEmitterRate(_coolDemoParticleEmitter, EMIT_RATE_IN_SECONDS); // stop emitter
3808+ emitting = false;
3809+ }
3810+ }
37353811 }
37363812 }
37373813

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