Showing the changes to interface/src/Application.cpp (1 of 21 files). Show all
Unified · Split
| @@ -196,8 +196,9 @@ Application::Application(int& argc, char** argv, timeval &startup_time) : · 195 unmodified lines | |||
| 196 | _isTouchPressed(false), | 196 | _isTouchPressed(false), |
| 197 | _yawFromTouch(0.0f), | 197 | _yawFromTouch(0.0f), |
| 198 | _pitchFromTouch(0.0f), | 198 | _pitchFromTouch(0.0f), |
| 199 | _groundPlaneImpact(0.0f), | ||
| 200 | _mousePressed(false), | 199 | _mousePressed(false), |
| 200 | _isHoverVoxel(false), | ||
| 201 | _isHoverVoxelSounding(false), | ||
| 201 | _mouseVoxelScale(1.0f / 1024.0f), | 202 | _mouseVoxelScale(1.0f / 1024.0f), |
| 202 | _justEditedVoxel(false), | 203 | _justEditedVoxel(false), |
| 203 | _isLookingAtOtherAvatar(false), | 204 | _isLookingAtOtherAvatar(false), |
| @@ -856,6 +857,11 @@ void Application::mouseMoveEvent(QMouseEvent* event) { · 652 unmodified lines | |||
| 856 | } | 857 | } |
| 857 | } | 858 | } |
| 858 | 859 | ||
| 860 | const bool MAKE_SOUND_ON_VOXEL_HOVER = false; | ||
| 861 | const bool MAKE_SOUND_ON_VOXEL_CLICK = true; | ||
| 862 | const float HOVER_VOXEL_FREQUENCY = 14080.f; | ||
| 863 | const float HOVER_VOXEL_DECAY = 0.999f; | ||
| 864 | |||
| 859 | void Application::mousePressEvent(QMouseEvent* event) { | 865 | void Application::mousePressEvent(QMouseEvent* event) { |
| 860 | if (activeWindow() == _window) { | 866 | if (activeWindow() == _window) { |
| 861 | if (event->button() == Qt::LeftButton) { | 867 | if (event->button() == Qt::LeftButton) { |
| @@ -866,9 +872,19 @@ void Application::mousePressEvent(QMouseEvent* event) { · 4 unmodified lines | |||
| 866 | _mouseVoxelDragging = _mouseVoxel; | 872 | _mouseVoxelDragging = _mouseVoxel; |
| 867 | _mousePressed = true; | 873 | _mousePressed = true; |
| 868 | 874 | ||
| 875 | |||
| 869 | if (!maybeEditVoxelUnderCursor()) { | 876 | if (!maybeEditVoxelUnderCursor()) { |
| 870 | _pieMenu.mousePressEvent(_mouseX, _mouseY); | 877 | _pieMenu.mousePressEvent(_mouseX, _mouseY); |
| 871 | } | 878 | } |
| 879 | |||
| 880 | if (MAKE_SOUND_ON_VOXEL_CLICK && _isHoverVoxel && !_isHoverVoxelSounding) { | ||
| 881 | _hoverVoxelOriginalColor[0] = _hoverVoxel.red; | ||
| 882 | _hoverVoxelOriginalColor[1] = _hoverVoxel.green; | ||
| 883 | _hoverVoxelOriginalColor[2] = _hoverVoxel.blue; | ||
| 884 | _hoverVoxelOriginalColor[3] = 1; | ||
| 885 | _audio.startCollisionSound(1.0, HOVER_VOXEL_FREQUENCY * _hoverVoxel.s * TREE_SCALE, 0.0, HOVER_VOXEL_DECAY); | ||
| 886 | _isHoverVoxelSounding = true; | ||
| 887 | } | ||
| 872 | 888 | ||
| 873 | } else if (event->button() == Qt::RightButton && checkedVoxelModeAction() != 0) { | 889 | } else if (event->button() == Qt::RightButton && checkedVoxelModeAction() != 0) { |
| 874 | deleteVoxelUnderCursor(); | 890 | deleteVoxelUnderCursor(); |
| @@ -925,8 +941,10 @@ void Application::touchEndEvent(QTouchEvent* event) { · 50 unmodified lines | |||
| 925 | _isTouchPressed = false; | 941 | _isTouchPressed = false; |
| 926 | } | 942 | } |
| 927 | 943 | ||
| 944 | const bool USE_MOUSEWHEEL = false; | ||
| 928 | void Application::wheelEvent(QWheelEvent* event) { | 945 | void Application::wheelEvent(QWheelEvent* event) { |
| 929 | if (activeWindow() == _window) { | 946 | // Wheel Events disabled for now because they are also activated by touch look pitch up/down. |
| 947 | if (USE_MOUSEWHEEL && (activeWindow() == _window)) { | ||
| 930 | if (checkedVoxelModeAction() == 0) { | 948 | if (checkedVoxelModeAction() == 0) { |
| 931 | event->ignore(); | 949 | event->ignore(); |
| 932 | return; | 950 | return; |
| @@ -972,14 +990,15 @@ void Application::sendAvatarFaceVideoMessage(int frameCount, const QByteArray& d · 39 unmodified lines | |||
| 972 | 990 | ||
| 973 | int headerSize = packetPosition - packet; | 991 | int headerSize = packetPosition - packet; |
| 974 | 992 | ||
| 975 | // break the data up into submessages of the maximum size | 993 | // break the data up into submessages of the maximum size (at least one, for zero-length packets) |
| 976 | *offsetPosition = 0; | 994 | *offsetPosition = 0; |
| 977 | while (*offsetPosition < data.size()) { | 995 | do { |
| 978 | int payloadSize = min(data.size() - (int)*offsetPosition, MAX_PACKET_SIZE - headerSize); | 996 | int payloadSize = min(data.size() - (int)*offsetPosition, MAX_PACKET_SIZE - headerSize); |
| 979 | memcpy(packetPosition, data.constData() + *offsetPosition, payloadSize); | 997 | memcpy(packetPosition, data.constData() + *offsetPosition, payloadSize); |
| 980 | getInstance()->controlledBroadcastToNodes(packet, headerSize + payloadSize, &NODE_TYPE_AVATAR_MIXER, 1); | 998 | getInstance()->controlledBroadcastToNodes(packet, headerSize + payloadSize, &NODE_TYPE_AVATAR_MIXER, 1); |
| 981 | *offsetPosition += payloadSize; | 999 | *offsetPosition += payloadSize; |
| 982 | } | 1000 | |
| 1001 | } while (*offsetPosition < data.size()); | ||
| 983 | } | 1002 | } |
| 984 | 1003 | ||
| 985 | // Every second, check the frame rates and other stuff | 1004 | // Every second, check the frame rates and other stuff |
| @@ -1502,16 +1521,18 @@ bool Application::sendVoxelsOperation(VoxelNode* node, void* extraData) { · 516 unmodified lines | |||
| 1502 | 1521 | ||
| 1503 | uint64_t now = usecTimestampNow(); | 1522 | uint64_t now = usecTimestampNow(); |
| 1504 | // dynamically sleep until we need to fire off the next set of voxels | 1523 | // dynamically sleep until we need to fire off the next set of voxels |
| 1505 | const uint64_t CLIENT_TO_SERVER_VOXEL_SEND_INTERVAL_USECS = 1000 * 5; // 1 packet every 10 milliseconds | ||
| 1506 | uint64_t elapsed = now - args->lastSendTime; | 1524 | uint64_t elapsed = now - args->lastSendTime; |
| 1507 | int usecToSleep = CLIENT_TO_SERVER_VOXEL_SEND_INTERVAL_USECS - elapsed; | 1525 | int usecToSleep = CLIENT_TO_SERVER_VOXEL_SEND_INTERVAL_USECS - elapsed; |
| 1508 | if (usecToSleep > 0) { | 1526 | if (usecToSleep > 0) { |
| 1509 | qDebug("sendVoxelsOperation: packet: %d bytes:%lld elapsed %lld usecs, sleeping for %d usecs!\n", | 1527 | //qDebug("sendVoxelsOperation: packet: %d bytes:%lld elapsed %lld usecs, sleeping for %d usecs!\n", |
| 1510 | args->packetsSent, (long long int)args->bytesSent, (long long int)elapsed, usecToSleep); | 1528 | // args->packetsSent, (long long int)args->bytesSent, (long long int)elapsed, usecToSleep); |
| 1529 | |||
| 1530 | Application::getInstance()->timer(); | ||
| 1531 | |||
| 1511 | usleep(usecToSleep); | 1532 | usleep(usecToSleep); |
| 1512 | } else { | 1533 | } else { |
| 1513 | qDebug("sendVoxelsOperation: packet: %d bytes:%lld elapsed %lld usecs, no need to sleep!\n", | 1534 | //qDebug("sendVoxelsOperation: packet: %d bytes:%lld elapsed %lld usecs, no need to sleep!\n", |
| 1514 | args->packetsSent, (long long int)args->bytesSent, (long long int)elapsed); | 1535 | // args->packetsSent, (long long int)args->bytesSent, (long long int)elapsed); |
| 1515 | } | 1536 | } |
| 1516 | args->lastSendTime = now; | 1537 | args->lastSendTime = now; |
| 1517 | } | 1538 | } |
| @@ -1579,70 +1600,127 @@ void Application::importVoxelsToClipboard() { · 61 unmodified lines | |||
| 1579 | 1600 | ||
| 1580 | void Application::importVoxels() { | 1601 | void Application::importVoxels() { |
| 1581 | QString desktopLocation = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation); | 1602 | QString desktopLocation = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation); |
| 1582 | QString fileNameString = QFileDialog::getOpenFileName(_glWidget, tr("Import Voxels"), desktopLocation, | 1603 | |
| 1604 | QStringList fileNameStringList = QFileDialog::getOpenFileNames(_glWidget, tr("Import Voxels"), desktopLocation, | ||
| 1583 | tr(IMPORT_FILE_TYPES)); | 1605 | tr(IMPORT_FILE_TYPES)); |
| 1584 | 1606 | ||
| 1585 | QByteArray fileNameAscii = fileNameString.toLocal8Bit(); | 1607 | |
| 1586 | const char* fileName = fileNameAscii.data(); | 1608 | // remember the "selected" voxel point before we do any importing... |
| 1609 | float originalX = _mouseVoxel.x; | ||
| 1610 | float originalZ = _mouseVoxel.z; | ||
| 1611 | |||
| 1612 | const int PNG_TYPE_NAME_LENGTH = 4; | ||
| 1613 | const int SVO_TYPE_NAME_LENGTH = 4; | ||
| 1614 | const int SCH_TYPE_NAME_LENGTH = 10; | ||
| 1615 | |||
| 1616 | for (int i = 0; i < fileNameStringList.size(); i++) { | ||
| 1617 | QString fileNameString = fileNameStringList.at(i); | ||
| 1618 | QByteArray fileNameAscii = fileNameString.toLocal8Bit(); | ||
| 1619 | const char* fileName = fileNameAscii.data(); | ||
| 1587 | 1620 | ||
| 1588 | VoxelTree importVoxels; | 1621 | int fileTypeNameLength = 0; |
| 1589 | if (fileNameString.endsWith(".png", Qt::CaseInsensitive)) { | 1622 | VoxelTree importVoxels; |
| 1590 | QImage pngImage = QImage(fileName); | 1623 | if (fileNameString.endsWith(".png", Qt::CaseInsensitive)) { |
| 1591 | if (pngImage.height() != pngImage.width()) { | 1624 | QImage pngImage = QImage(fileName); |
| 1592 | qDebug("ERROR: Bad PNG size: height != width.\n"); | 1625 | fileTypeNameLength = PNG_TYPE_NAME_LENGTH; |
| 1593 | return; | 1626 | if (pngImage.height() != pngImage.width()) { |
| 1627 | qDebug("ERROR: Bad PNG size: height != width.\n"); | ||
| 1628 | return; | ||
| 1629 | } | ||
| 1630 | |||
| 1631 | const uint32_t* pixels; | ||
| 1632 | if (pngImage.format() == QImage::Format_ARGB32) { | ||
| 1633 | pixels = reinterpret_cast<const uint32_t*>(pngImage.constBits()); | ||
| 1634 | } else { | ||
| 1635 | QImage tmp = pngImage.convertToFormat(QImage::Format_ARGB32); | ||
| 1636 | pixels = reinterpret_cast<const uint32_t*>(tmp.constBits()); | ||
| 1637 | } | ||
| 1638 | |||
| 1639 | importVoxels.readFromSquareARGB32Pixels(pixels, pngImage.height()); | ||
| 1640 | } else if (fileNameString.endsWith(".svo", Qt::CaseInsensitive)) { | ||
| 1641 | importVoxels.readFromSVOFile(fileName); | ||
| 1642 | fileTypeNameLength = SVO_TYPE_NAME_LENGTH; | ||
| 1643 | } else if (fileNameString.endsWith(".schematic", Qt::CaseInsensitive)) { | ||
| 1644 | importVoxels.readFromSchematicFile(fileName); | ||
| 1645 | fileTypeNameLength = SCH_TYPE_NAME_LENGTH; | ||
| 1594 | } | 1646 | } |
| 1595 | 1647 | ||
| 1596 | const uint32_t* pixels; | 1648 | int indexOfFirstPeriod = fileNameString.indexOf('.'); |
| 1597 | if (pngImage.format() == QImage::Format_ARGB32) { | 1649 | |
| 1598 | pixels = reinterpret_cast<const uint32_t*>(pngImage.constBits()); | 1650 | QString fileCoord = fileNameString.mid(indexOfFirstPeriod + 1, |
| 1651 | fileNameString.length() - indexOfFirstPeriod - fileTypeNameLength - 1); | ||
| 1652 | |||
| 1653 | indexOfFirstPeriod = fileCoord.indexOf('.'); | ||
| 1654 | QString columnNumString = fileCoord.right(fileCoord.length() - indexOfFirstPeriod - 1); | ||
| 1655 | QString rowNumString = fileCoord.left(indexOfFirstPeriod); | ||
| 1656 | |||
| 1657 | int columnNum = columnNumString.toFloat(); | ||
| 1658 | int rowNum = rowNumString.toFloat(); | ||
| 1659 | |||
| 1660 | qDebug("columnNum: %d\t rowNum: %d\n", columnNum, rowNum); | ||
| 1661 | |||
| 1662 | _mouseVoxel.x = originalX + (columnNum - 1) * _mouseVoxel.s; | ||
| 1663 | _mouseVoxel.z = originalZ + (rowNum - 1) * _mouseVoxel.s; | ||
| 1664 | |||
| 1665 | VoxelNode* selectedNode = _voxels.getVoxelAt(_mouseVoxel.x, _mouseVoxel.y, _mouseVoxel.z, _mouseVoxel.s); | ||
| 1666 | |||
| 1667 | // Recurse the Import Voxels tree, where everything is root relative, and send all the colored voxels to | ||
| 1668 | // the server as an set voxel message, this will also rebase the voxels to the new location | ||
| 1669 | unsigned char* calculatedOctCode = NULL; | ||
| 1670 | SendVoxelsOperationArgs args; | ||
| 1671 | args.lastSendTime = usecTimestampNow(); | ||
| 1672 | args.packetsSent = 0; | ||
| 1673 | args.bytesSent = 0; | ||
| 1674 | |||
| 1675 | int numBytesPacketHeader = populateTypeAndVersion(args.messageBuffer, PACKET_TYPE_SET_VOXEL_DESTRUCTIVE); | ||
| 1676 | |||
| 1677 | unsigned short int* sequenceAt = (unsigned short int*)&args.messageBuffer[numBytesPacketHeader]; | ||
| 1678 | *sequenceAt = 0; | ||
| 1679 | args.bufferInUse = numBytesPacketHeader + sizeof(unsigned short int); // set to command + sequence | ||
| 1680 | |||
| 1681 | // we only need the selected voxel to get the newBaseOctCode, which we can actually calculate from the | ||
| 1682 | // voxel size/position details. | ||
| 1683 | if (selectedNode) { | ||
| 1684 | args.newBaseOctCode = selectedNode->getOctalCode(); | ||
| 1599 | } else { | 1685 | } else { |
| 1600 | QImage tmp = pngImage.convertToFormat(QImage::Format_ARGB32); | 1686 | args.newBaseOctCode = calculatedOctCode = pointToVoxel(_mouseVoxel.x, _mouseVoxel.y, _mouseVoxel.z, _mouseVoxel.s); |
| 1601 | pixels = reinterpret_cast<const uint32_t*>(tmp.constBits()); | ||
| 1602 | } | 1687 | } |
| 1603 | |||
| 1604 | importVoxels.readFromSquareARGB32Pixels(pixels, pngImage.height()); | ||
| 1605 | } else if (fileNameString.endsWith(".svo", Qt::CaseInsensitive)) { | ||
| 1606 | importVoxels.readFromSVOFile(fileName); | ||
| 1607 | } else if (fileNameString.endsWith(".schematic", Qt::CaseInsensitive)) { | ||
| 1608 | importVoxels.readFromSchematicFile(fileName); | ||
| 1609 | } | ||
| 1610 | |||
| 1611 | VoxelNode* selectedNode = _voxels.getVoxelAt(_mouseVoxel.x, _mouseVoxel.y, _mouseVoxel.z, _mouseVoxel.s); | ||
| 1612 | |||
| 1613 | // Recurse the Import Voxels tree, where everything is root relative, and send all the colored voxels to | ||
| 1614 | // the server as an set voxel message, this will also rebase the voxels to the new location | ||
| 1615 | unsigned char* calculatedOctCode = NULL; | ||
| 1616 | SendVoxelsOperationArgs args; | ||
| 1617 | args.lastSendTime = usecTimestampNow(); | ||
| 1618 | args.packetsSent = 0; | ||
| 1619 | args.bytesSent = 0; | ||
| 1620 | 1688 | ||
| 1621 | int numBytesPacketHeader = populateTypeAndVersion(args.messageBuffer, PACKET_TYPE_SET_VOXEL_DESTRUCTIVE); | 1689 | qDebug("column:%d, row:%d, voxel:%f,%f,%f,%f\n", columnNum, rowNum, _mouseVoxel.x, _mouseVoxel.y, _mouseVoxel.z, _mouseVoxel.s ); |
| 1690 | |||
| 1691 | // send the insert/paste of these voxels | ||
| 1692 | importVoxels.recurseTreeWithOperation(sendVoxelsOperation, &args); | ||
| 1622 | 1693 | ||
| 1623 | unsigned short int* sequenceAt = (unsigned short int*)&args.messageBuffer[numBytesPacketHeader]; | 1694 | // If we have voxels left in the packet, then send the packet |
| 1624 | *sequenceAt = 0; | 1695 | if (args.bufferInUse > (numBytesPacketHeader + sizeof(unsigned short int))) { |
| 1625 | args.bufferInUse = numBytesPacketHeader + sizeof(unsigned short int); // set to command + sequence | 1696 | controlledBroadcastToNodes(args.messageBuffer, args.bufferInUse, & NODE_TYPE_VOXEL_SERVER, 1); |
| 1626 | 1697 | ||
| 1627 | // we only need the selected voxel to get the newBaseOctCode, which we can actually calculate from the | ||
| 1628 | // voxel size/position details. | ||
| 1629 | if (selectedNode) { | ||
| 1630 | args.newBaseOctCode = selectedNode->getOctalCode(); | ||
| 1631 | } else { | ||
| 1632 | args.newBaseOctCode = calculatedOctCode = pointToVoxel(_mouseVoxel.x, _mouseVoxel.y, _mouseVoxel.z, _mouseVoxel.s); | ||
| 1633 | } | ||
| 1634 | 1698 | ||
| 1635 | importVoxels.recurseTreeWithOperation(sendVoxelsOperation, &args); | 1699 | args.packetsSent++; |
| 1700 | args.bytesSent += args.bufferInUse; | ||
| 1701 | |||
| 1702 | uint64_t now = usecTimestampNow(); | ||
| 1703 | // dynamically sleep until we need to fire off the next set of voxels | ||
| 1704 | uint64_t elapsed = now - args.lastSendTime; | ||
| 1705 | int usecToSleep = CLIENT_TO_SERVER_VOXEL_SEND_INTERVAL_USECS - elapsed; | ||
| 1706 | |||
| 1707 | if (usecToSleep > 0) { | ||
| 1708 | //qDebug("after sendVoxelsOperation: packet: %d bytes:%lld elapsed %lld usecs, sleeping for %d usecs!\n", | ||
| 1709 | // args.packetsSent, (long long int)args.bytesSent, (long long int)elapsed, usecToSleep); | ||
| 1710 | usleep(usecToSleep); | ||
| 1711 | } else { | ||
| 1712 | //qDebug("after sendVoxelsOperation: packet: %d bytes:%lld elapsed %lld usecs, no need to sleep!\n", | ||
| 1713 | // args.packetsSent, (long long int)args.bytesSent, (long long int)elapsed); | ||
| 1714 | } | ||
| 1715 | args.lastSendTime = now; | ||
| 1716 | } | ||
| 1717 | |||
| 1718 | if (calculatedOctCode) { | ||
| 1719 | delete[] calculatedOctCode; | ||
| 1720 | } | ||
| 1636 | 1721 | ||
| 1637 | // If we have voxels left in the packet, then send the packet | ||
| 1638 | if (args.bufferInUse > (numBytesPacketHeader + sizeof(unsigned short int))) { | ||
| 1639 | controlledBroadcastToNodes(args.messageBuffer, args.bufferInUse, & NODE_TYPE_VOXEL_SERVER, 1); | ||
| 1640 | } | 1722 | } |
| 1641 | 1723 | ||
| 1642 | if (calculatedOctCode) { | ||
| 1643 | delete[] calculatedOctCode; | ||
| 1644 | } | ||
| 1645 | |||
| 1646 | // restore the main window's active state | 1724 | // restore the main window's active state |
| 1647 | _window->activateWindow(); | 1725 | _window->activateWindow(); |
| 1648 | } | 1726 | } |
| @@ -1735,6 +1813,8 @@ void Application::initMenu() { · 86 unmodified lines | |||
| 1735 | _testPing->setChecked(true); | 1813 | _testPing->setChecked(true); |
| 1736 | (_fullScreenMode = optionsMenu->addAction("Fullscreen", this, SLOT(setFullscreen(bool)), Qt::Key_F))->setCheckable(true); | 1814 | (_fullScreenMode = optionsMenu->addAction("Fullscreen", this, SLOT(setFullscreen(bool)), Qt::Key_F))->setCheckable(true); |
| 1737 | optionsMenu->addAction("Webcam", &_webcam, SLOT(setEnabled(bool)))->setCheckable(true); | 1815 | optionsMenu->addAction("Webcam", &_webcam, SLOT(setEnabled(bool)))->setCheckable(true); |
| 1816 | optionsMenu->addAction("Toggle Skeleton Tracking", &_webcam, SLOT(setSkeletonTrackingOn(bool)))->setCheckable(true); | ||
| 1817 | optionsMenu->addAction("Cycle Webcam Send Mode", _webcam.getGrabber(), SLOT(cycleVideoSendMode())); | ||
| 1738 | optionsMenu->addAction("Go Home", this, SLOT(goHome())); | 1818 | optionsMenu->addAction("Go Home", this, SLOT(goHome())); |
| 1739 | 1819 | ||
| 1740 | QMenu* renderMenu = menuBar->addMenu("Render"); | 1820 | QMenu* renderMenu = menuBar->addMenu("Render"); |
| @@ -1762,7 +1842,6 @@ void Application::initMenu() { · 21 unmodified lines | |||
| 1762 | (_renderLookatIndicatorOn = renderMenu->addAction("Lookat Indicator"))->setCheckable(true); | 1842 | (_renderLookatIndicatorOn = renderMenu->addAction("Lookat Indicator"))->setCheckable(true); |
| 1763 | _renderLookatIndicatorOn->setChecked(true); | 1843 | _renderLookatIndicatorOn->setChecked(true); |
| 1764 | (_renderParticleSystemOn = renderMenu->addAction("Particle System"))->setCheckable(true); | 1844 | (_renderParticleSystemOn = renderMenu->addAction("Particle System"))->setCheckable(true); |
| 1765 | _renderParticleSystemOn->setChecked(true); | ||
| 1766 | (_manualFirstPerson = renderMenu->addAction( | 1845 | (_manualFirstPerson = renderMenu->addAction( |
| 1767 | "First Person", this, SLOT(setRenderFirstPerson(bool)), Qt::Key_P))->setCheckable(true); | 1846 | "First Person", this, SLOT(setRenderFirstPerson(bool)), Qt::Key_P))->setCheckable(true); |
| 1768 | (_manualThirdPerson = renderMenu->addAction( | 1847 | (_manualThirdPerson = renderMenu->addAction( |
| @@ -2039,6 +2118,7 @@ void Application::renderLookatIndicator(glm::vec3 pointOfInterest, Camera& which · 270 unmodified lines | |||
| 2039 | } | 2118 | } |
| 2040 | 2119 | ||
| 2041 | void Application::update(float deltaTime) { | 2120 | void Application::update(float deltaTime) { |
| 2121 | |||
| 2042 | // Use Transmitter Hand to move hand if connected, else use mouse | 2122 | // Use Transmitter Hand to move hand if connected, else use mouse |
| 2043 | if (_myTransmitter.isConnected()) { | 2123 | if (_myTransmitter.isConnected()) { |
| 2044 | const float HAND_FORCE_SCALING = 0.01f; | 2124 | const float HAND_FORCE_SCALING = 0.01f; |
| @@ -2071,11 +2151,46 @@ void Application::update(float deltaTime) { · 26 unmodified lines | |||
| 2071 | // If the mouse is over another avatar's head... | 2151 | // If the mouse is over another avatar's head... |
| 2072 | glm::vec3 myLookAtFromMouse(eyePosition); | 2152 | glm::vec3 myLookAtFromMouse(eyePosition); |
| 2073 | _myAvatar.getHead().setLookAtPosition(myLookAtFromMouse); | 2153 | _myAvatar.getHead().setLookAtPosition(myLookAtFromMouse); |
| 2154 | } else if (_isHoverVoxel) { | ||
| 2155 | // Look at the hovered voxel | ||
| 2156 | glm::vec3 lookAtSpot = getMouseVoxelWorldCoordinates(_hoverVoxel); | ||
| 2157 | _myAvatar.getHead().setLookAtPosition(lookAtSpot); | ||
| 2074 | } else { | 2158 | } else { |
| 2159 | // Just look in direction of the mouse ray | ||
| 2075 | glm::vec3 myLookAtFromMouse(mouseRayOrigin + mouseRayDirection); | 2160 | glm::vec3 myLookAtFromMouse(mouseRayOrigin + mouseRayDirection); |
| 2076 | _myAvatar.getHead().setLookAtPosition(myLookAtFromMouse); | 2161 | _myAvatar.getHead().setLookAtPosition(myLookAtFromMouse); |
| 2077 | } | 2162 | } |
| 2078 | 2163 | ||
| 2164 | // Find the voxel we are hovering over, and respond if clicked | ||
| 2165 | float distance; | ||
| 2166 | BoxFace face; | ||
| 2167 | |||
| 2168 | // If we have clicked on a voxel, update it's color | ||
| 2169 | if (_isHoverVoxelSounding) { | ||
| 2170 | VoxelNode* hoveredNode = _voxels.getVoxelAt(_hoverVoxel.x, _hoverVoxel.y, _hoverVoxel.z, _hoverVoxel.s); | ||
| 2171 | float bright = _audio.getCollisionSoundMagnitude(); | ||
| 2172 | nodeColor clickColor = { 255 * bright + _hoverVoxelOriginalColor[0] * (1.f - bright), | ||
| 2173 | _hoverVoxelOriginalColor[1] * (1.f - bright), | ||
| 2174 | _hoverVoxelOriginalColor[2] * (1.f - bright), 1 }; | ||
| 2175 | hoveredNode->setColor(clickColor); | ||
| 2176 | if (bright < 0.01f) { | ||
| 2177 | hoveredNode->setColor(_hoverVoxelOriginalColor); | ||
| 2178 | _isHoverVoxelSounding = false; | ||
| 2179 | } | ||
| 2180 | } else { | ||
| 2181 | // Check for a new hover voxel | ||
| 2182 | glm::vec4 oldVoxel(_hoverVoxel.x, _hoverVoxel.y, _hoverVoxel.z, _hoverVoxel.s); | ||
| 2183 | _isHoverVoxel = _voxels.findRayIntersection(mouseRayOrigin, mouseRayDirection, _hoverVoxel, distance, face); | ||
| 2184 | if (MAKE_SOUND_ON_VOXEL_HOVER && _isHoverVoxel && glm::vec4(_hoverVoxel.x, _hoverVoxel.y, _hoverVoxel.z, _hoverVoxel.s) != oldVoxel) { | ||
| 2185 | _hoverVoxelOriginalColor[0] = _hoverVoxel.red; | ||
| 2186 | _hoverVoxelOriginalColor[1] = _hoverVoxel.green; | ||
| 2187 | _hoverVoxelOriginalColor[2] = _hoverVoxel.blue; | ||
| 2188 | _hoverVoxelOriginalColor[3] = 1; | ||
| 2189 | _audio.startCollisionSound(1.0, HOVER_VOXEL_FREQUENCY * _hoverVoxel.s * TREE_SCALE, 0.0, HOVER_VOXEL_DECAY); | ||
| 2190 | _isHoverVoxelSounding = true; | ||
| 2191 | } | ||
| 2192 | } | ||
| 2193 | |||
| 2079 | // If we are dragging on a voxel, add thrust according to the amount the mouse is dragging | 2194 | // If we are dragging on a voxel, add thrust according to the amount the mouse is dragging |
| 2080 | const float VOXEL_GRAB_THRUST = 0.0f; | 2195 | const float VOXEL_GRAB_THRUST = 0.0f; |
| 2081 | if (_mousePressed && (_mouseVoxel.s != 0)) { | 2196 | if (_mousePressed && (_mouseVoxel.s != 0)) { |
| @@ -2101,8 +2216,6 @@ void Application::update(float deltaTime) { · 19 unmodified lines | |||
| 2101 | (fabs(_myAvatar.getVelocity().x) + | 2216 | (fabs(_myAvatar.getVelocity().x) + |
| 2102 | fabs(_myAvatar.getVelocity().y) + | 2217 | fabs(_myAvatar.getVelocity().y) + |
| 2103 | fabs(_myAvatar.getVelocity().z)) / 3 < MAX_AVATAR_EDIT_VELOCITY) { | 2218 | fabs(_myAvatar.getVelocity().z)) / 3 < MAX_AVATAR_EDIT_VELOCITY) { |
| 2104 | float distance; | ||
| 2105 | BoxFace face; | ||
| 2106 | if (_voxels.findRayIntersection(mouseRayOrigin, mouseRayDirection, _mouseVoxel, distance, face)) { | 2219 | if (_voxels.findRayIntersection(mouseRayOrigin, mouseRayDirection, _mouseVoxel, distance, face)) { |
| 2107 | if (distance < MAX_VOXEL_EDIT_DISTANCE) { | 2220 | if (distance < MAX_VOXEL_EDIT_DISTANCE) { |
| 2108 | // find the nearest voxel with the desired scale | 2221 | // find the nearest voxel with the desired scale |
| @@ -2289,20 +2402,18 @@ void Application::update(float deltaTime) { · 180 unmodified lines | |||
| 2289 | } | 2402 | } |
| 2290 | 2403 | ||
| 2291 | void Application::updateAvatar(float deltaTime) { | 2404 | void Application::updateAvatar(float deltaTime) { |
| 2292 | 2405 | ||
| 2293 | // When head is rotated via touch/mouse look, slowly turn body to follow | 2406 | // rotate body yaw for yaw received from multitouch |
| 2294 | const float BODY_FOLLOW_HEAD_RATE = 0.5f; | ||
| 2295 | // update body yaw by body yaw delta | ||
| 2296 | _myAvatar.setOrientation(_myAvatar.getOrientation() | 2407 | _myAvatar.setOrientation(_myAvatar.getOrientation() |
| 2297 | * glm::quat(glm::vec3(0, _yawFromTouch * deltaTime * BODY_FOLLOW_HEAD_RATE, 0) * deltaTime)); | 2408 | * glm::quat(glm::vec3(0, _yawFromTouch * deltaTime, 0))); |
| 2298 | _yawFromTouch -= _yawFromTouch * deltaTime * BODY_FOLLOW_HEAD_RATE; | 2409 | _yawFromTouch = 0.f; |
| 2299 | 2410 | ||
| 2300 | // Update my avatar's state from gyros and/or webcam | 2411 | // Update my avatar's state from gyros and/or webcam |
| 2301 | _myAvatar.updateFromGyrosAndOrWebcam(_gyroLook->isChecked(), | 2412 | _myAvatar.updateFromGyrosAndOrWebcam(_gyroLook->isChecked(), |
| 2302 | glm::vec3(_headCameraPitchYawScale, | 2413 | glm::vec3(_headCameraPitchYawScale, |
| 2303 | _headCameraPitchYawScale, | 2414 | _headCameraPitchYawScale, |
| 2304 | _headCameraPitchYawScale), | 2415 | _headCameraPitchYawScale), |
| 2305 | _yawFromTouch, | 2416 | 0.f, |
| 2306 | _pitchFromTouch); | 2417 | _pitchFromTouch); |
| 2307 | 2418 | ||
| 2308 | if (_serialHeadSensor.isActive()) { | 2419 | if (_serialHeadSensor.isActive()) { |
| @@ -2761,8 +2872,12 @@ void Application::displayOverlay() { · 452 unmodified lines | |||
| 2761 | glDisable(GL_DEPTH_TEST); | 2872 | glDisable(GL_DEPTH_TEST); |
| 2762 | glDisable(GL_LIGHTING); | 2873 | glDisable(GL_LIGHTING); |
| 2763 | 2874 | ||
| 2764 | // Display a single screen-size quad to | 2875 | // Display a single screen-size quad to create an alpha blended 'collision' flash |
| 2765 | renderCollisionOverlay(_glWidget->width(), _glWidget->height(), _audio.getCollisionSoundMagnitude()); | 2876 | float collisionSoundMagnitude = _audio.getCollisionSoundMagnitude(); |
| 2877 | const float VISIBLE_COLLISION_SOUND_MAGNITUDE = 0.5f; | ||
| 2878 | if (collisionSoundMagnitude > VISIBLE_COLLISION_SOUND_MAGNITUDE) { | ||
| 2879 | renderCollisionOverlay(_glWidget->width(), _glWidget->height(), _audio.getCollisionSoundMagnitude()); | ||
| 2880 | } | ||
| 2766 | 2881 | ||
| 2767 | #ifndef _WIN32 | 2882 | #ifndef _WIN32 |
| 2768 | _audio.render(_glWidget->width(), _glWidget->height()); | 2883 | _audio.render(_glWidget->width(), _glWidget->height()); |
| @@ -3501,6 +3616,7 @@ void* Application::networkReceive(void* args) { · 732 unmodified lines | |||
| 3501 | } | 3616 | } |
| 3502 | 3617 | ||
| 3503 | if (NodeList::getInstance()->getNodeSocket()->receive(&senderAddress, app->_incomingPacket, &bytesReceived)) { | 3618 | if (NodeList::getInstance()->getNodeSocket()->receive(&senderAddress, app->_incomingPacket, &bytesReceived)) { |
| 3619 | |||
| 3504 | app->_packetCount++; | 3620 | app->_packetCount++; |
| 3505 | app->_bytesCount += bytesReceived; | 3621 | app->_bytesCount += bytesReceived; |
| 3506 | 3622 | ||
| @@ -3545,13 +3661,11 @@ void* Application::networkReceive(void* args) { · 38 unmodified lines | |||
| 3545 | Node* voxelServer = NodeList::getInstance()->soloNodeOfType(NODE_TYPE_VOXEL_SERVER); | 3661 | Node* voxelServer = NodeList::getInstance()->soloNodeOfType(NODE_TYPE_VOXEL_SERVER); |
| 3546 | if (voxelServer && socketMatch(voxelServer->getActiveSocket(), &senderAddress)) { | 3662 | if (voxelServer && socketMatch(voxelServer->getActiveSocket(), &senderAddress)) { |
| 3547 | voxelServer->lock(); | 3663 | voxelServer->lock(); |
| 3548 | |||
| 3549 | if (messageData[0] == PACKET_TYPE_ENVIRONMENT_DATA) { | 3664 | if (messageData[0] == PACKET_TYPE_ENVIRONMENT_DATA) { |
| 3550 | app->_environment.parseData(&senderAddress, messageData, messageLength); | 3665 | app->_environment.parseData(&senderAddress, messageData, messageLength); |
| 3551 | } else { | 3666 | } else { |
| 3552 | app->_voxels.parseData(messageData, messageLength); | 3667 | app->_voxels.parseData(messageData, messageLength); |
| 3553 | } | 3668 | } |
| 3554 | |||
| 3555 | voxelServer->unlock(); | 3669 | voxelServer->unlock(); |
| 3556 | } | 3670 | } |
| 3557 | } | 3671 | } |