Showing the changes to interface/src/Application.cpp (1 of 34 files). Show all
Unified · Split
| @@ -164,9 +164,9 @@ void GLCanvas::wheelEvent(QWheelEvent* event) { · 163 unmodified lines | |||
| 164 | Application::getInstance()->wheelEvent(event); | 164 | Application::getInstance()->wheelEvent(event); |
| 165 | } | 165 | } |
| 166 | 166 | ||
| 167 | void messageHandler(QtMsgType type, const char* message) { | 167 | void messageHandler(QtMsgType type, const QMessageLogContext& context, const QString &message) { |
| 168 | fprintf(stdout, "%s", message); | 168 | fprintf(stdout, "%s", message.toLocal8Bit().constData()); |
| 169 | LogDisplay::instance.addMessage(message); | 169 | LogDisplay::instance.addMessage(message.toLocal8Bit().constData()); |
| 170 | } | 170 | } |
| 171 | 171 | ||
| 172 | Application::Application(int& argc, char** argv, timeval &startup_time) : | 172 | 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 | |||
| 222 | _applicationStartupTime = startup_time; | 222 | _applicationStartupTime = startup_time; |
| 223 | _window->setWindowTitle("Interface"); | 223 | _window->setWindowTitle("Interface"); |
| 224 | 224 | ||
| 225 | qInstallMsgHandler(messageHandler); | 225 | qInstallMessageHandler(messageHandler); |
| 226 | 226 | ||
| 227 | unsigned int listenPort = 0; // bind to an ephemeral port by default | 227 | unsigned int listenPort = 0; // bind to an ephemeral port by default |
| 228 | const char** constArgv = const_cast<const char**>(argv); | 228 | const char** constArgv = const_cast<const char**>(argv); |
| @@ -564,6 +564,11 @@ void Application::keyPressEvent(QKeyEvent* event) { · 335 unmodified lines | |||
| 564 | } | 564 | } |
| 565 | return; | 565 | return; |
| 566 | } | 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 | } | ||
| 567 | 572 | ||
| 568 | bool shifted = event->modifiers().testFlag(Qt::ShiftModifier); | 573 | bool shifted = event->modifiers().testFlag(Qt::ShiftModifier); |
| 569 | switch (event->key()) { | 574 | switch (event->key()) { |
| @@ -1216,7 +1221,7 @@ void Application::editPreferences() { · 646 unmodified lines | |||
| 1216 | 1221 | ||
| 1217 | if (domainServerHostname->text().size() > 0) { | 1222 | if (domainServerHostname->text().size() > 0) { |
| 1218 | // the user input a new hostname, use that | 1223 | // the user input a new hostname, use that |
| 1219 | newHostname = domainServerHostname->text().toAscii(); | 1224 | newHostname = domainServerHostname->text().toLocal8Bit(); |
| 1220 | } else { | 1225 | } else { |
| 1221 | // the user left the field blank, use the default hostname | 1226 | // the user left the field blank, use the default hostname |
| 1222 | newHostname = QByteArray(DEFAULT_DOMAIN_HOSTNAME); | 1227 | newHostname = QByteArray(DEFAULT_DOMAIN_HOSTNAME); |
| @@ -1494,16 +1499,18 @@ bool Application::sendVoxelsOperation(VoxelNode* node, void* extraData) { · 271 unmodified lines | |||
| 1494 | 1499 | ||
| 1495 | uint64_t now = usecTimestampNow(); | 1500 | uint64_t now = usecTimestampNow(); |
| 1496 | // dynamically sleep until we need to fire off the next set of voxels | 1501 | // 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 | ||
| 1498 | uint64_t elapsed = now - args->lastSendTime; | 1502 | uint64_t elapsed = now - args->lastSendTime; |
| 1499 | int usecToSleep = CLIENT_TO_SERVER_VOXEL_SEND_INTERVAL_USECS - elapsed; | 1503 | int usecToSleep = CLIENT_TO_SERVER_VOXEL_SEND_INTERVAL_USECS - elapsed; |
| 1500 | if (usecToSleep > 0) { | 1504 | if (usecToSleep > 0) { |
| 1501 | qDebug("sendVoxelsOperation: packet: %d bytes:%lld elapsed %lld usecs, sleeping for %d usecs!\n", | 1505 | //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); | 1506 | // args->packetsSent, (long long int)args->bytesSent, (long long int)elapsed, usecToSleep); |
| 1507 | |||
| 1508 | Application::getInstance()->timer(); | ||
| 1509 | |||
| 1503 | usleep(usecToSleep); | 1510 | usleep(usecToSleep); |
| 1504 | } else { | 1511 | } else { |
| 1505 | qDebug("sendVoxelsOperation: packet: %d bytes:%lld elapsed %lld usecs, no need to sleep!\n", | 1512 | //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); | 1513 | // args->packetsSent, (long long int)args->bytesSent, (long long int)elapsed); |
| 1507 | } | 1514 | } |
| 1508 | args->lastSendTime = now; | 1515 | args->lastSendTime = now; |
| 1509 | } | 1516 | } |
| @@ -1516,12 +1523,12 @@ bool Application::sendVoxelsOperation(VoxelNode* node, void* extraData) { · 6 unmodified lines | |||
| 1516 | } | 1523 | } |
| 1517 | 1524 | ||
| 1518 | void Application::exportVoxels() { | 1525 | void Application::exportVoxels() { |
| 1519 | QString desktopLocation = QDesktopServices::storageLocation(QDesktopServices::DesktopLocation); | 1526 | QString desktopLocation = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation); |
| 1520 | QString suggestedName = desktopLocation.append("/voxels.svo"); | 1527 | QString suggestedName = desktopLocation.append("/voxels.svo"); |
| 1521 | 1528 | ||
| 1522 | QString fileNameString = QFileDialog::getSaveFileName(_glWidget, tr("Export Voxels"), suggestedName, | 1529 | QString fileNameString = QFileDialog::getSaveFileName(_glWidget, tr("Export Voxels"), suggestedName, |
| 1523 | tr("Sparse Voxel Octree Files (*.svo)")); | 1530 | tr("Sparse Voxel Octree Files (*.svo)")); |
| 1524 | QByteArray fileNameAscii = fileNameString.toAscii(); | 1531 | QByteArray fileNameAscii = fileNameString.toLocal8Bit(); |
| 1525 | const char* fileName = fileNameAscii.data(); | 1532 | const char* fileName = fileNameAscii.data(); |
| 1526 | VoxelNode* selectedNode = _voxels.getVoxelAt(_mouseVoxel.x, _mouseVoxel.y, _mouseVoxel.z, _mouseVoxel.s); | 1533 | VoxelNode* selectedNode = _voxels.getVoxelAt(_mouseVoxel.x, _mouseVoxel.y, _mouseVoxel.z, _mouseVoxel.s); |
| 1527 | if (selectedNode) { | 1534 | if (selectedNode) { |
| @@ -1536,11 +1543,11 @@ void Application::exportVoxels() { · 8 unmodified lines | |||
| 1536 | 1543 | ||
| 1537 | const char* IMPORT_FILE_TYPES = "Sparse Voxel Octree Files, Square PNG, Schematic Files (*.svo *.png *.schematic)"; | 1544 | const char* IMPORT_FILE_TYPES = "Sparse Voxel Octree Files, Square PNG, Schematic Files (*.svo *.png *.schematic)"; |
| 1538 | void Application::importVoxelsToClipboard() { | 1545 | void Application::importVoxelsToClipboard() { |
| 1539 | QString desktopLocation = QDesktopServices::storageLocation(QDesktopServices::DesktopLocation); | 1546 | QString desktopLocation = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation); |
| 1540 | QString fileNameString = QFileDialog::getOpenFileName(_glWidget, tr("Import Voxels to Clipboard"), desktopLocation, | 1547 | QString fileNameString = QFileDialog::getOpenFileName(_glWidget, tr("Import Voxels to Clipboard"), desktopLocation, |
| 1541 | tr(IMPORT_FILE_TYPES)); | 1548 | tr(IMPORT_FILE_TYPES)); |
| 1542 | 1549 | ||
| 1543 | QByteArray fileNameAscii = fileNameString.toAscii(); | 1550 | QByteArray fileNameAscii = fileNameString.toLocal8Bit(); |
| 1544 | const char* fileName = fileNameAscii.data(); | 1551 | const char* fileName = fileNameAscii.data(); |
| 1545 | 1552 | ||
| 1546 | _clipboardTree.eraseAllVoxels(); | 1553 | _clipboardTree.eraseAllVoxels(); |
| @@ -1570,71 +1577,128 @@ void Application::importVoxelsToClipboard() { · 23 unmodified lines | |||
| 1570 | } | 1577 | } |
| 1571 | 1578 | ||
| 1572 | void Application::importVoxels() { | 1579 | void Application::importVoxels() { |
| 1573 | QString desktopLocation = QDesktopServices::storageLocation(QDesktopServices::DesktopLocation); | 1580 | QString desktopLocation = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation); |
| 1574 | QString fileNameString = QFileDialog::getOpenFileName(_glWidget, tr("Import Voxels"), desktopLocation, | 1581 | |
| 1582 | QStringList fileNameStringList = QFileDialog::getOpenFileNames(_glWidget, tr("Import Voxels"), desktopLocation, | ||
| 1575 | tr(IMPORT_FILE_TYPES)); | 1583 | tr(IMPORT_FILE_TYPES)); |
| 1576 | 1584 | ||
| 1577 | QByteArray fileNameAscii = fileNameString.toAscii(); | 1585 | |
| 1578 | const char* fileName = fileNameAscii.data(); | 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(); | ||
| 1579 | 1598 | ||
| 1580 | VoxelTree importVoxels; | 1599 | int fileTypeNameLength = 0; |
| 1581 | if (fileNameString.endsWith(".png", Qt::CaseInsensitive)) { | 1600 | VoxelTree importVoxels; |
| 1582 | QImage pngImage = QImage(fileName); | 1601 | if (fileNameString.endsWith(".png", Qt::CaseInsensitive)) { |
| 1583 | if (pngImage.height() != pngImage.width()) { | 1602 | QImage pngImage = QImage(fileName); |
| 1584 | qDebug("ERROR: Bad PNG size: height != width.\n"); | 1603 | fileTypeNameLength = PNG_TYPE_NAME_LENGTH; |
| 1585 | return; | 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; | ||
| 1586 | } | 1624 | } |
| 1587 | 1625 | ||
| 1588 | const uint32_t* pixels; | 1626 | int indexOfFirstPeriod = fileNameString.indexOf('.'); |
| 1589 | if (pngImage.format() == QImage::Format_ARGB32) { | 1627 | |
| 1590 | pixels = reinterpret_cast<const uint32_t*>(pngImage.constBits()); | 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(); | ||
| 1591 | } else { | 1663 | } else { |
| 1592 | QImage tmp = pngImage.convertToFormat(QImage::Format_ARGB32); | 1664 | args.newBaseOctCode = calculatedOctCode = pointToVoxel(_mouseVoxel.x, _mouseVoxel.y, _mouseVoxel.z, _mouseVoxel.s); |
| 1593 | pixels = reinterpret_cast<const uint32_t*>(tmp.constBits()); | ||
| 1594 | } | 1665 | } |
| 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; | ||
| 1612 | 1666 | ||
| 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); | ||
| 1614 | 1671 | ||
| 1615 | unsigned short int* sequenceAt = (unsigned short int*)&args.messageBuffer[numBytesPacketHeader]; | 1672 | // If we have voxels left in the packet, then send the packet |
| 1616 | *sequenceAt = 0; | 1673 | if (args.bufferInUse > (numBytesPacketHeader + sizeof(unsigned short int))) { |
| 1617 | args.bufferInUse = numBytesPacketHeader + sizeof(unsigned short int); // set to command + sequence | 1674 | controlledBroadcastToNodes(args.messageBuffer, args.bufferInUse, & NODE_TYPE_VOXEL_SERVER, 1); |
| 1618 | 1675 | ||
| 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 | } | ||
| 1626 | 1676 | ||
| 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 | } | ||
| 1628 | 1699 | ||
| 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); | ||
| 1632 | } | 1700 | } |
| 1633 | 1701 | ||
| 1634 | if (calculatedOctCode) { | ||
| 1635 | delete[] calculatedOctCode; | ||
| 1636 | } | ||
| 1637 | |||
| 1638 | // restore the main window's active state | 1702 | // restore the main window's active state |
| 1639 | _window->activateWindow(); | 1703 | _window->activateWindow(); |
| 1640 | } | 1704 | } |
| @@ -1989,8 +2053,11 @@ const float MAX_VOXEL_EDIT_DISTANCE = 20.0f; · 348 unmodified lines | |||
| 1989 | const float HEAD_SPHERE_RADIUS = 0.07; | 2053 | const float HEAD_SPHERE_RADIUS = 0.07; |
| 1990 | 2054 | ||
| 1991 | 2055 | ||
| 2056 | static uint16_t DEFAULT_NODE_ID_REF = 1; | ||
| 2057 | |||
| 2058 | |||
| 1992 | bool Application::isLookingAtOtherAvatar(glm::vec3& mouseRayOrigin, glm::vec3& mouseRayDirection, | 2059 | 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) { |
| 1994 | 2061 | ||
| 1995 | NodeList* nodeList = NodeList::getInstance(); | 2062 | NodeList* nodeList = NodeList::getInstance(); |
| 1996 | for (NodeList::iterator node = nodeList->begin(); node != nodeList->end(); node++) { | 2063 | for (NodeList::iterator node = nodeList->begin(); node != nodeList->end(); node++) { |
| @@ -2047,8 +2114,8 @@ void Application::update(float deltaTime) { · 50 unmodified lines | |||
| 2047 | 2114 | ||
| 2048 | // Set where I am looking based on my mouse ray (so that other people can see) | 2115 | // Set where I am looking based on my mouse ray (so that other people can see) |
| 2049 | glm::vec3 eyePosition; | 2116 | glm::vec3 eyePosition; |
| 2050 | uint16_t ignored; | 2117 | |
| 2051 | _isLookingAtOtherAvatar = isLookingAtOtherAvatar(mouseRayOrigin, mouseRayDirection, eyePosition, ignored); | 2118 | _isLookingAtOtherAvatar = isLookingAtOtherAvatar(mouseRayOrigin, mouseRayDirection, eyePosition); |
| 2052 | if (_isLookingAtOtherAvatar) { | 2119 | if (_isLookingAtOtherAvatar) { |
| 2053 | // If the mouse is over another avatar's head... | 2120 | // If the mouse is over another avatar's head... |
| 2054 | glm::vec3 myLookAtFromMouse(eyePosition); | 2121 | glm::vec3 myLookAtFromMouse(eyePosition); |
| @@ -2314,8 +2381,8 @@ void Application::updateAvatar(float deltaTime) { · 259 unmodified lines | |||
| 2314 | _viewFrustum.computePickRay(MIDPOINT_OF_SCREEN, MIDPOINT_OF_SCREEN, screenCenterRayOrigin, screenCenterRayDirection); | 2381 | _viewFrustum.computePickRay(MIDPOINT_OF_SCREEN, MIDPOINT_OF_SCREEN, screenCenterRayOrigin, screenCenterRayDirection); |
| 2315 | 2382 | ||
| 2316 | glm::vec3 eyePosition; | 2383 | glm::vec3 eyePosition; |
| 2317 | uint16_t ignored; | 2384 | |
| 2318 | _isLookingAtOtherAvatar = isLookingAtOtherAvatar(screenCenterRayOrigin, screenCenterRayDirection, eyePosition, ignored); | 2385 | _isLookingAtOtherAvatar = isLookingAtOtherAvatar(screenCenterRayOrigin, screenCenterRayDirection, eyePosition); |
| 2319 | if (_isLookingAtOtherAvatar) { | 2386 | if (_isLookingAtOtherAvatar) { |
| 2320 | glm::vec3 myLookAtFromMouse(eyePosition); | 2387 | glm::vec3 myLookAtFromMouse(eyePosition); |
| 2321 | _myAvatar.getHead().setLookAtPosition(myLookAtFromMouse); | 2388 | _myAvatar.getHead().setLookAtPosition(myLookAtFromMouse); |
| @@ -2354,7 +2421,7 @@ void Application::updateAvatar(float deltaTime) { · 32 unmodified lines | |||
| 2354 | NodeList* nodeList = NodeList::getInstance(); | 2421 | NodeList* nodeList = NodeList::getInstance(); |
| 2355 | if (nodeList->getOwnerID() != UNKNOWN_NODE_ID) { | 2422 | if (nodeList->getOwnerID() != UNKNOWN_NODE_ID) { |
| 2356 | // if I know my ID, send head/hand data to the avatar mixer and voxel server | 2423 | // 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]; |
| 2358 | unsigned char* endOfBroadcastStringWrite = broadcastString; | 2425 | unsigned char* endOfBroadcastStringWrite = broadcastString; |
| 2359 | 2426 | ||
| 2360 | endOfBroadcastStringWrite += populateTypeAndVersion(endOfBroadcastStringWrite, PACKET_TYPE_HEAD_DATA); | 2427 | endOfBroadcastStringWrite += populateTypeAndVersion(endOfBroadcastStringWrite, PACKET_TYPE_HEAD_DATA); |
| @@ -2673,13 +2740,14 @@ void Application::displaySide(Camera& whichCamera) { · 312 unmodified lines | |||
| 2673 | if (_mouseVoxel.s != 0) { | 2740 | if (_mouseVoxel.s != 0) { |
| 2674 | glDisable(GL_LIGHTING); | 2741 | glDisable(GL_LIGHTING); |
| 2675 | glPushMatrix(); | 2742 | glPushMatrix(); |
| 2743 | glScalef(TREE_SCALE, TREE_SCALE, TREE_SCALE); | ||
| 2744 | renderMouseVoxelGrid(_mouseVoxel.x, _mouseVoxel.y, _mouseVoxel.z, _mouseVoxel.s); | ||
| 2676 | if (_addVoxelMode->isChecked()) { | 2745 | if (_addVoxelMode->isChecked()) { |
| 2677 | // use a contrasting color so that we can see what we're doing | 2746 | // use a contrasting color so that we can see what we're doing |
| 2678 | glColor3ub(_mouseVoxel.red + 128, _mouseVoxel.green + 128, _mouseVoxel.blue + 128); | 2747 | glColor3ub(_mouseVoxel.red + 128, _mouseVoxel.green + 128, _mouseVoxel.blue + 128); |
| 2679 | } else { | 2748 | } else { |
| 2680 | glColor3ub(_mouseVoxel.red, _mouseVoxel.green, _mouseVoxel.blue); | 2749 | glColor3ub(_mouseVoxel.red, _mouseVoxel.green, _mouseVoxel.blue); |
| 2681 | } | 2750 | } |
| 2682 | glScalef(TREE_SCALE, TREE_SCALE, TREE_SCALE); | ||
| 2683 | glTranslatef(_mouseVoxel.x + _mouseVoxel.s*0.5f, | 2751 | glTranslatef(_mouseVoxel.x + _mouseVoxel.s*0.5f, |
| 2684 | _mouseVoxel.y + _mouseVoxel.s*0.5f, | 2752 | _mouseVoxel.y + _mouseVoxel.s*0.5f, |
| 2685 | _mouseVoxel.z + _mouseVoxel.s*0.5f); | 2753 | _mouseVoxel.z + _mouseVoxel.s*0.5f); |
| @@ -2725,13 +2793,12 @@ void Application::displaySide(Camera& whichCamera) { · 39 unmodified lines | |||
| 2725 | _particleSystem.render(); | 2793 | _particleSystem.render(); |
| 2726 | } | 2794 | } |
| 2727 | } | 2795 | } |
| 2728 | 2796 | ||
| 2729 | // Render the world box | 2797 | // Render the world box |
| 2730 | if (!_lookingInMirror->isChecked() && _renderStatsOn->isChecked()) { render_world_box(); } | 2798 | if (!_lookingInMirror->isChecked() && _renderStatsOn->isChecked()) { render_world_box(); } |
| 2731 | 2799 | ||
| 2732 | // brad's frustum for debugging | 2800 | // brad's frustum for debugging |
| 2733 | if (_frustumOn->isChecked()) renderViewFrustum(_viewFrustum); | 2801 | if (_frustumOn->isChecked()) renderViewFrustum(_viewFrustum); |
| 2734 | |||
| 2735 | } | 2802 | } |
| 2736 | 2803 | ||
| 2737 | void Application::displayOverlay() { | 2804 | void Application::displayOverlay() { |
| @@ -3475,6 +3542,7 @@ void* Application::networkReceive(void* args) { · 737 unmodified lines | |||
| 3475 | } | 3542 | } |
| 3476 | 3543 | ||
| 3477 | if (NodeList::getInstance()->getNodeSocket()->receive(&senderAddress, app->_incomingPacket, &bytesReceived)) { | 3544 | if (NodeList::getInstance()->getNodeSocket()->receive(&senderAddress, app->_incomingPacket, &bytesReceived)) { |
| 3545 | |||
| 3478 | app->_packetCount++; | 3546 | app->_packetCount++; |
| 3479 | app->_bytesCount += bytesReceived; | 3547 | app->_bytesCount += bytesReceived; |
| 3480 | 3548 | ||
| @@ -3519,7 +3587,6 @@ void* Application::networkReceive(void* args) { · 38 unmodified lines | |||
| 3519 | Node* voxelServer = NodeList::getInstance()->nodeWithAddress(&senderAddress); | 3587 | Node* voxelServer = NodeList::getInstance()->nodeWithAddress(&senderAddress); |
| 3520 | if (voxelServer && socketMatch(voxelServer->getActiveSocket(), &senderAddress)) { | 3588 | if (voxelServer && socketMatch(voxelServer->getActiveSocket(), &senderAddress)) { |
| 3521 | voxelServer->lock(); | 3589 | voxelServer->lock(); |
| 3522 | |||
| 3523 | if (messageData[0] == PACKET_TYPE_ENVIRONMENT_DATA) { | 3590 | if (messageData[0] == PACKET_TYPE_ENVIRONMENT_DATA) { |
| 3524 | app->_environment.parseData(&senderAddress, messageData, messageLength); | 3591 | app->_environment.parseData(&senderAddress, messageData, messageLength); |
| 3525 | } else { | 3592 | } else { |
| @@ -3527,7 +3594,6 @@ void* Application::networkReceive(void* args) { · 1 unmodified line | |||
| 3527 | app->_voxels.parseData(messageData, messageLength); | 3594 | app->_voxels.parseData(messageData, messageLength); |
| 3528 | app->_voxels.setDataSourceID(UNKNOWN_NODE_ID); | 3595 | app->_voxels.setDataSourceID(UNKNOWN_NODE_ID); |
| 3529 | } | 3596 | } |
| 3530 | |||
| 3531 | voxelServer->unlock(); | 3597 | voxelServer->unlock(); |
| 3532 | } | 3598 | } |
| 3533 | } | 3599 | } |
| @@ -3647,7 +3713,7 @@ void Application::saveSettings(QSettings* settings) { · 113 unmodified lines | |||
| 3647 | } | 3713 | } |
| 3648 | 3714 | ||
| 3649 | void Application::importSettings() { | 3715 | void Application::importSettings() { |
| 3650 | QString locationDir(QDesktopServices::displayName(QDesktopServices::DesktopLocation)); | 3716 | QString locationDir(QStandardPaths::displayName(QStandardPaths::DesktopLocation)); |
| 3651 | QString fileName = QFileDialog::getOpenFileName(_window, | 3717 | QString fileName = QFileDialog::getOpenFileName(_window, |
| 3652 | tr("Open .ini config file"), | 3718 | tr("Open .ini config file"), |
| 3653 | locationDir, | 3719 | locationDir, |
| @@ -3659,7 +3725,7 @@ void Application::importSettings() { · 5 unmodified lines | |||
| 3659 | } | 3725 | } |
| 3660 | 3726 | ||
| 3661 | void Application::exportSettings() { | 3727 | void Application::exportSettings() { |
| 3662 | QString locationDir(QDesktopServices::displayName(QDesktopServices::DesktopLocation)); | 3728 | QString locationDir(QStandardPaths::displayName(QStandardPaths::DesktopLocation)); |
| 3663 | QString fileName = QFileDialog::getSaveFileName(_window, | 3729 | QString fileName = QFileDialog::getSaveFileName(_window, |
| 3664 | tr("Save .ini config file"), | 3730 | tr("Save .ini config file"), |
| 3665 | locationDir, | 3731 | locationDir, |
| @@ -3672,56 +3738,57 @@ void Application::exportSettings() { · 6 unmodified lines | |||
| 3672 | } | 3738 | } |
| 3673 | 3739 | ||
| 3674 | 3740 | ||
| 3675 | |||
| 3676 | void Application::updateParticleSystem(float deltaTime) { | 3741 | void Application::updateParticleSystem(float deltaTime) { |
| 3677 | 3742 | ||
| 3678 | if (!_particleSystemInitialized) { | 3743 | if (!_particleSystemInitialized) { |
| 3744 | |||
| 3745 | const int LIFESPAN_IN_SECONDS = 100000.0f; | ||
| 3746 | const float EMIT_RATE_IN_SECONDS = 10000.0; | ||
| 3679 | // create a stable test emitter and spit out a bunch of particles | 3747 | // create a stable test emitter and spit out a bunch of particles |
| 3680 | _coolDemoParticleEmitter = _particleSystem.addEmitter(); | 3748 | _coolDemoParticleEmitter = _particleSystem.addEmitter(); |
| 3681 | 3749 | ||
| 3682 | if (_coolDemoParticleEmitter != -1) { | 3750 | if (_coolDemoParticleEmitter != -1) { |
| 3751 | |||
| 3683 | _particleSystem.setShowingEmitter(_coolDemoParticleEmitter, true); | 3752 | _particleSystem.setShowingEmitter(_coolDemoParticleEmitter, true); |
| 3684 | glm::vec3 particleEmitterPosition = glm::vec3(5.0f, 1.0f, 5.0f); | 3753 | glm::vec3 particleEmitterPosition = glm::vec3(5.0f, 1.0f, 5.0f); |
| 3685 | _particleSystem.setEmitterPosition(_coolDemoParticleEmitter, particleEmitterPosition); | 3754 | |
| 3686 | glm::vec3 velocity(0.0f, 0.1f, 0.0f); | 3755 | _particleSystem.setEmitterPosition (_coolDemoParticleEmitter, particleEmitterPosition); |
| 3687 | float lifespan = 100000.0f; | 3756 | _particleSystem.setEmitterParticleLifespan(_coolDemoParticleEmitter, LIFESPAN_IN_SECONDS); |
| 3688 | _particleSystem.emitParticlesNow(_coolDemoParticleEmitter, 1500, velocity, lifespan); | 3757 | _particleSystem.setEmitterThrust (_coolDemoParticleEmitter, 0.0f); |
| 3758 | _particleSystem.setEmitterRate (_coolDemoParticleEmitter, EMIT_RATE_IN_SECONDS); // to emit a pile o particles now | ||
| 3689 | } | 3759 | } |
| 3690 | 3760 | ||
| 3691 | // signal that the particle system has been initialized | 3761 | // signal that the particle system has been initialized |
| 3692 | _particleSystemInitialized = true; | 3762 | _particleSystemInitialized = true; |
| 3693 | } else { | 3763 | } else { |
| 3694 | // update the particle system | 3764 | // update the particle system |
| 3695 | 3765 | ||
| 3696 | static float t = 0.0f; | 3766 | static bool emitting = true; |
| 3697 | t += deltaTime; | 3767 | static float effectsTimer = 0.0f; |
| 3768 | effectsTimer += deltaTime; | ||
| 3698 | 3769 | ||
| 3699 | if (_coolDemoParticleEmitter != -1) { | 3770 | if (_coolDemoParticleEmitter != -1) { |
| 3700 | 3771 | ||
| 3701 | glm::vec3 tilt = glm::vec3 | 3772 | _particleSystem.setEmitterDirection(_coolDemoParticleEmitter, glm::vec3(0.0f, 1.0f, 0.0f)); |
| 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))); | ||
| 3709 | 3773 | ||
| 3710 | ParticleSystem::ParticleAttributes attributes; | 3774 | ParticleSystem::ParticleAttributes attributes; |
| 3711 | 3775 | ||
| 3712 | attributes.radius = 0.01f; | 3776 | attributes.radius = 0.01f; |
| 3713 | attributes.color = glm::vec4( 1.0f, 1.0f, 1.0f, 1.0f); | 3777 | attributes.color = glm::vec4( 1.0f, 1.0f, 1.0f, 1.0f); |
| 3714 | attributes.gravity = 0.0f + 0.05f * sinf( t * 0.52f ); | 3778 | attributes.gravity = 0.0f + 0.05f * sinf( effectsTimer * 0.52f ); |
| 3715 | attributes.airFriction = 2.5 + 2.0f * sinf( t * 0.32f ); | 3779 | attributes.airFriction = 2.5 + 2.0f * sinf( effectsTimer * 0.32f ); |
| 3716 | attributes.jitter = 0.05f + 0.05f * sinf( t * 0.42f ); | 3780 | attributes.jitter = 0.05f + 0.05f * sinf( effectsTimer * 0.42f ); |
| 3717 | attributes.emitterAttraction = 0.015f + 0.015f * cosf( t * 0.6f ); | 3781 | attributes.emitterAttraction = 0.015f + 0.015f * cosf( effectsTimer * 0.6f ); |
| 3718 | attributes.tornadoForce = 0.0f + 0.03f * sinf( t * 0.7f ); | 3782 | attributes.tornadoForce = 0.0f + 0.03f * sinf( effectsTimer * 0.7f ); |
| 3719 | attributes.neighborAttraction = 0.1f + 0.1f * cosf( t * 0.8f ); | 3783 | attributes.neighborAttraction = 0.1f + 0.1f * cosf( effectsTimer * 0.8f ); |
| 3720 | attributes.neighborRepulsion = 0.2f + 0.2f * sinf( t * 0.4f ); | 3784 | attributes.neighborRepulsion = 0.2f + 0.2f * sinf( effectsTimer * 0.4f ); |
| 3721 | attributes.bounce = 1.0f; | 3785 | attributes.bounce = 1.0f; |
| 3722 | attributes.usingCollisionSphere = true; | 3786 | attributes.usingCollisionSphere = true; |
| 3723 | attributes.collisionSpherePosition = glm::vec3( 5.0f, 0.5f, 5.0f ); | 3787 | attributes.collisionSpherePosition = glm::vec3( 5.0f, 0.5f, 5.0f ); |
| 3724 | attributes.collisionSphereRadius = 0.5f; | 3788 | 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 ); | ||
| 3725 | 3792 | ||
| 3726 | if (attributes.gravity < 0.0f) { | 3793 | if (attributes.gravity < 0.0f) { |
| 3727 | attributes.gravity = 0.0f; | 3794 | attributes.gravity = 0.0f; |
| @@ -3732,6 +3799,15 @@ void Application::updateParticleSystem(float deltaTime) { · 4 unmodified lines | |||
| 3732 | 3799 | ||
| 3733 | _particleSystem.setUpDirection(glm::vec3(0.0f, 1.0f, 0.0f)); | 3800 | _particleSystem.setUpDirection(glm::vec3(0.0f, 1.0f, 0.0f)); |
| 3734 | _particleSystem.simulate(deltaTime); | 3801 | _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 | } | ||
| 3735 | } | 3811 | } |
| 3736 | } | 3812 | } |
| 3737 | 3813 | ||