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
7575 static char STAR_FILE[] = "http://s3-us-west-1.amazonaws.com/highfidelity/stars.txt";
7676 static char STAR_CACHE_FILE[] = "cachedStars.txt";
7777
78−static const bool TESTING_PARTICLE_SYSTEM = true;
79−
8078 static const int BANDWIDTH_METER_CLICK_MAX_DRAG_LENGTH = 6; // farther dragged clicks are ignored
8179
8280 const 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
166164 Application::getInstance()->wheelEvent(event);
167165 }
168166
169−void messageHandler(QtMsgType type, const char* message) {
170− fprintf(stdout, "%s", message);
171− 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());
172170 }
173171
174172 Application::Application(int& argc, char** argv, timeval &startup_time) :
@@ -224,7 +222,7 @@ Application::Application(int& argc, char** argv, timeval &startup_time) : · 49 unmodified lines
224222 _applicationStartupTime = startup_time;
225223 _window->setWindowTitle("Interface");
226224
227− qInstallMsgHandler(messageHandler);
225+ qInstallMessageHandler(messageHandler);
228226
229227 unsigned int listenPort = 0; // bind to an ephemeral port by default
230228 const char** constArgv = const_cast<const char**>(argv);
@@ -407,7 +405,7 @@ void Application::paintGL() { · 176 unmodified lines
407405
408406 } else if (_myCamera.getMode() == CAMERA_MODE_FIRST_PERSON) {
409407 _myCamera.setTightness(0.0f); // In first person, camera follows head exactly without delay
410− _myCamera.setTargetPosition(_myAvatar.getUprightHeadPosition());
408+ _myCamera.setTargetPosition(_myAvatar.getUprightEyeLevelPosition());
411409 _myCamera.setTargetRotation(_myAvatar.getHead().getCameraOrientation());
412410
413411 } else if (_myCamera.getMode() == CAMERA_MODE_THIRD_PERSON) {
@@ -566,6 +564,11 @@ void Application::keyPressEvent(QKeyEvent* event) { · 152 unmodified lines
566564 }
567565 return;
568566 }
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+ }
569572
570573 bool shifted = event->modifiers().testFlag(Qt::ShiftModifier);
571574 switch (event->key()) {
@@ -1225,7 +1228,7 @@ void Application::editPreferences() { · 653 unmodified lines
12251228
12261229 if (domainServerHostname->text().size() > 0) {
12271230 // the user input a new hostname, use that
1228− newHostname = domainServerHostname->text().toAscii();
1231+ newHostname = domainServerHostname->text().toLocal8Bit();
12291232 } else {
12301233 // the user left the field blank, use the default hostname
12311234 newHostname = QByteArray(DEFAULT_DOMAIN_HOSTNAME);
@@ -1504,11 +1507,11 @@ bool Application::sendVoxelsOperation(VoxelNode* node, void* extraData) { · 272 unmodified lines
15041507 int usecToSleep = CLIENT_TO_SERVER_VOXEL_SEND_INTERVAL_USECS - elapsed;
15051508 if (usecToSleep > 0) {
15061509 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);
15081511 usleep(usecToSleep);
15091512 } else {
15101513 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);
15121515 }
15131516 args->lastSendTime = now;
15141517 }
@@ -1521,12 +1524,12 @@ bool Application::sendVoxelsOperation(VoxelNode* node, void* extraData) { · 6 unmodified lines
15211524 }
15221525
15231526 void Application::exportVoxels() {
1524− QString desktopLocation = QDesktopServices::storageLocation(QDesktopServices::DesktopLocation);
1527+ QString desktopLocation = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation);
15251528 QString suggestedName = desktopLocation.append("/voxels.svo");
15261529
15271530 QString fileNameString = QFileDialog::getSaveFileName(_glWidget, tr("Export Voxels"), suggestedName,
15281531 tr("Sparse Voxel Octree Files (*.svo)"));
1529− QByteArray fileNameAscii = fileNameString.toAscii();
1532+ QByteArray fileNameAscii = fileNameString.toLocal8Bit();
15301533 const char* fileName = fileNameAscii.data();
15311534 VoxelNode* selectedNode = _voxels.getVoxelAt(_mouseVoxel.x, _mouseVoxel.y, _mouseVoxel.z, _mouseVoxel.s);
15321535 if (selectedNode) {
@@ -1541,11 +1544,11 @@ void Application::exportVoxels() { · 8 unmodified lines
15411544
15421545 const char* IMPORT_FILE_TYPES = "Sparse Voxel Octree Files, Square PNG, Schematic Files (*.svo *.png *.schematic)";
15431546 void Application::importVoxelsToClipboard() {
1544− QString desktopLocation = QDesktopServices::storageLocation(QDesktopServices::DesktopLocation);
1547+ QString desktopLocation = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation);
15451548 QString fileNameString = QFileDialog::getOpenFileName(_glWidget, tr("Import Voxels to Clipboard"), desktopLocation,
15461549 tr(IMPORT_FILE_TYPES));
15471550
1548− QByteArray fileNameAscii = fileNameString.toAscii();
1551+ QByteArray fileNameAscii = fileNameString.toLocal8Bit();
15491552 const char* fileName = fileNameAscii.data();
15501553
15511554 _clipboardTree.eraseAllVoxels();
@@ -1575,11 +1578,11 @@ void Application::importVoxelsToClipboard() { · 23 unmodified lines
15751578 }
15761579
15771580 void Application::importVoxels() {
1578− QString desktopLocation = QDesktopServices::storageLocation(QDesktopServices::DesktopLocation);
1581+ QString desktopLocation = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation);
15791582 QString fileNameString = QFileDialog::getOpenFileName(_glWidget, tr("Import Voxels"), desktopLocation,
15801583 tr(IMPORT_FILE_TYPES));
15811584
1582− QByteArray fileNameAscii = fileNameString.toAscii();
1585+ QByteArray fileNameAscii = fileNameString.toLocal8Bit();
15831586 const char* fileName = fileNameAscii.data();
15841587
15851588 VoxelTree importVoxels;
@@ -1693,7 +1696,7 @@ void Application::pasteVoxels() { · 107 unmodified lines
16931696 controlledBroadcastToNodes(args.messageBuffer, args.bufferInUse, & NODE_TYPE_VOXEL_SERVER, 1);
16941697 qDebug("sending packet: %d\n", ++args.packetsSent);
16951698 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);
16971700 }
16981701
16991702 if (calculatedOctCode) {
@@ -1758,6 +1761,8 @@ void Application::initMenu() { · 58 unmodified lines
17581761 _renderLookatOn->setChecked(false);
17591762 (_renderLookatIndicatorOn = renderMenu->addAction("Lookat Indicator"))->setCheckable(true);
17601763 _renderLookatIndicatorOn->setChecked(true);
1764+ (_renderParticleSystemOn = renderMenu->addAction("Particle System"))->setCheckable(true);
1765+ _renderParticleSystemOn->setChecked(true);
17611766 (_manualFirstPerson = renderMenu->addAction(
17621767 "First Person", this, SLOT(setRenderFirstPerson(bool)), Qt::Key_P))->setCheckable(true);
17631768 (_manualThirdPerson = renderMenu->addAction(
@@ -1995,8 +2000,11 @@ const float MAX_VOXEL_EDIT_DISTANCE = 20.0f; · 231 unmodified lines
19952000 const float HEAD_SPHERE_RADIUS = 0.07;
19962001
19972002
2003+static uint16_t DEFAULT_NODE_ID_REF = 1;
2004+
2005+
19982006 bool 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) {
20002008
20012009 NodeList* nodeList = NodeList::getInstance();
20022010 for (NodeList::iterator node = nodeList->begin(); node != nodeList->end(); node++) {
@@ -2053,8 +2061,8 @@ void Application::update(float deltaTime) { · 50 unmodified lines
20532061
20542062 // Set where I am looking based on my mouse ray (so that other people can see)
20552063 glm::vec3 eyePosition;
2056− uint16_t ignored;
2057− _isLookingAtOtherAvatar = isLookingAtOtherAvatar(mouseRayOrigin, mouseRayDirection, eyePosition, ignored);
2064+
2065+ _isLookingAtOtherAvatar = isLookingAtOtherAvatar(mouseRayOrigin, mouseRayDirection, eyePosition);
20582066 if (_isLookingAtOtherAvatar) {
20592067 // If the mouse is over another avatar's head...
20602068 glm::vec3 myLookAtFromMouse(eyePosition);
@@ -2271,7 +2279,7 @@ void Application::update(float deltaTime) { · 210 unmodified lines
22712279 _audio.eventuallyAnalyzePing();
22722280 #endif
22732281
2274− if (TESTING_PARTICLE_SYSTEM) {
2282+ if (_renderParticleSystemOn->isChecked()) {
22752283 updateParticleSystem(deltaTime);
22762284 }
22772285 }
@@ -2320,8 +2328,8 @@ void Application::updateAvatar(float deltaTime) { · 42 unmodified lines
23202328 _viewFrustum.computePickRay(MIDPOINT_OF_SCREEN, MIDPOINT_OF_SCREEN, screenCenterRayOrigin, screenCenterRayDirection);
23212329
23222330 glm::vec3 eyePosition;
2323− uint16_t ignored;
2324− _isLookingAtOtherAvatar = isLookingAtOtherAvatar(screenCenterRayOrigin, screenCenterRayDirection, eyePosition, ignored);
2331+
2332+ _isLookingAtOtherAvatar = isLookingAtOtherAvatar(screenCenterRayOrigin, screenCenterRayDirection, eyePosition);
23252333 if (_isLookingAtOtherAvatar) {
23262334 glm::vec3 myLookAtFromMouse(eyePosition);
23272335 _myAvatar.getHead().setLookAtPosition(myLookAtFromMouse);
@@ -2360,7 +2368,7 @@ void Application::updateAvatar(float deltaTime) { · 32 unmodified lines
23602368 NodeList* nodeList = NodeList::getInstance();
23612369 if (nodeList->getOwnerID() != UNKNOWN_NODE_ID) {
23622370 // 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];
23642372 unsigned char* endOfBroadcastStringWrite = broadcastString;
23652373
23662374 endOfBroadcastStringWrite += populateTypeAndVersion(endOfBroadcastStringWrite, PACKET_TYPE_HEAD_DATA);
@@ -2679,13 +2687,14 @@ void Application::displaySide(Camera& whichCamera) { · 312 unmodified lines
26792687 if (_mouseVoxel.s != 0) {
26802688 glDisable(GL_LIGHTING);
26812689 glPushMatrix();
2690+ glScalef(TREE_SCALE, TREE_SCALE, TREE_SCALE);
2691+ renderMouseVoxelGrid(_mouseVoxel.x, _mouseVoxel.y, _mouseVoxel.z, _mouseVoxel.s);
26822692 if (_addVoxelMode->isChecked()) {
26832693 // use a contrasting color so that we can see what we're doing
26842694 glColor3ub(_mouseVoxel.red + 128, _mouseVoxel.green + 128, _mouseVoxel.blue + 128);
26852695 } else {
26862696 glColor3ub(_mouseVoxel.red, _mouseVoxel.green, _mouseVoxel.blue);
26872697 }
2688− glScalef(TREE_SCALE, TREE_SCALE, TREE_SCALE);
26892698 glTranslatef(_mouseVoxel.x + _mouseVoxel.s*0.5f,
26902699 _mouseVoxel.y + _mouseVoxel.s*0.5f,
26912700 _mouseVoxel.z + _mouseVoxel.s*0.5f);
@@ -2720,25 +2729,23 @@ void Application::displaySide(Camera& whichCamera) { · 28 unmodified lines
27202729 _myAvatar.getHead().setLookAtPosition(_myCamera.getPosition());
27212730 }
27222731 _myAvatar.render(_lookingInMirror->isChecked(), _renderAvatarBalls->isChecked());
2723− _myAvatar.setDisplayingLookatVectors(_renderLookatOn->isChecked());
27242732
27252733 if (_renderLookatIndicatorOn->isChecked() && _isLookingAtOtherAvatar) {
27262734 renderLookatIndicator(_lookatOtherPosition, whichCamera);
27272735 }
27282736 }
27292737
2730− if (TESTING_PARTICLE_SYSTEM) {
2738+ if (_renderParticleSystemOn->isChecked()) {
27312739 if (_particleSystemInitialized) {
27322740 _particleSystem.render();
27332741 }
27342742 }
2735−
2743+
27362744 // Render the world box
27372745 if (!_lookingInMirror->isChecked() && _renderStatsOn->isChecked()) { render_world_box(); }
27382746
27392747 // brad's frustum for debugging
27402748 if (_frustumOn->isChecked()) renderViewFrustum(_viewFrustum);
2741−
27422749 }
27432750
27442751 void Application::displayOverlay() {
@@ -3644,7 +3651,7 @@ void Application::saveSettings(QSettings* settings) { · 899 unmodified lines
36443651 }
36453652
36463653 void Application::importSettings() {
3647− QString locationDir(QDesktopServices::displayName(QDesktopServices::DesktopLocation));
3654+ QString locationDir(QStandardPaths::displayName(QStandardPaths::DesktopLocation));
36483655 QString fileName = QFileDialog::getOpenFileName(_window,
36493656 tr("Open .ini config file"),
36503657 locationDir,
@@ -3656,7 +3663,7 @@ void Application::importSettings() { · 5 unmodified lines
36563663 }
36573664
36583665 void Application::exportSettings() {
3659− QString locationDir(QDesktopServices::displayName(QDesktopServices::DesktopLocation));
3666+ QString locationDir(QStandardPaths::displayName(QStandardPaths::DesktopLocation));
36603667 QString fileName = QFileDialog::getSaveFileName(_window,
36613668 tr("Save .ini config file"),
36623669 locationDir,
@@ -3669,56 +3676,57 @@ void Application::exportSettings() { · 6 unmodified lines
36693676 }
36703677
36713678
3672−
36733679 void Application::updateParticleSystem(float deltaTime) {
36743680
36753681 if (!_particleSystemInitialized) {
3682+
3683+ const int LIFESPAN_IN_SECONDS = 100000.0f;
3684+ const float EMIT_RATE_IN_SECONDS = 10000.0;
36763685 // create a stable test emitter and spit out a bunch of particles
36773686 _coolDemoParticleEmitter = _particleSystem.addEmitter();
3678−
3687+
36793688 if (_coolDemoParticleEmitter != -1) {
3689+
36803690 _particleSystem.setShowingEmitter(_coolDemoParticleEmitter, true);
36813691 glm::vec3 particleEmitterPosition = glm::vec3(5.0f, 1.0f, 5.0f);
3682− _particleSystem.setEmitterPosition(_coolDemoParticleEmitter, particleEmitterPosition);
3683− glm::vec3 velocity(0.0f, 0.1f, 0.0f);
3684− float lifespan = 100000.0f;
3685− _particleSystem.emitParticlesNow(_coolDemoParticleEmitter, 1500, velocity, lifespan);
3692+
3693+ _particleSystem.setEmitterPosition (_coolDemoParticleEmitter, particleEmitterPosition);
3694+ _particleSystem.setEmitterParticleLifespan(_coolDemoParticleEmitter, LIFESPAN_IN_SECONDS);
3695+ _particleSystem.setEmitterThrust (_coolDemoParticleEmitter, 0.0f);
3696+ _particleSystem.setEmitterRate (_coolDemoParticleEmitter, EMIT_RATE_IN_SECONDS); // to emit a pile o particles now
36863697 }
36873698
36883699 // signal that the particle system has been initialized
36893700 _particleSystemInitialized = true;
36903701 } else {
36913702 // update the particle system
3692−
3693− static float t = 0.0f;
3694− t += deltaTime;
3703+
3704+ static bool emitting = true;
3705+ static float effectsTimer = 0.0f;
3706+ effectsTimer += deltaTime;
36953707
36963708 if (_coolDemoParticleEmitter != -1) {
36973709
3698− glm::vec3 tilt = glm::vec3
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)));
3710+ _particleSystem.setEmitterDirection(_coolDemoParticleEmitter, glm::vec3(0.0f, 1.0f, 0.0f));
37063711
37073712 ParticleSystem::ParticleAttributes attributes;
37083713
37093714 attributes.radius = 0.01f;
37103715 attributes.color = glm::vec4( 1.0f, 1.0f, 1.0f, 1.0f);
3711− attributes.gravity = 0.0f + 0.05f * sinf( t * 0.52f );
3712− attributes.airFriction = 2.5 + 2.0f * sinf( t * 0.32f );
3713− attributes.jitter = 0.05f + 0.05f * sinf( t * 0.42f );
3714− attributes.emitterAttraction = 0.015f + 0.015f * cosf( t * 0.6f );
3715− attributes.tornadoForce = 0.0f + 0.03f * sinf( t * 0.7f );
3716− attributes.neighborAttraction = 0.1f + 0.1f * cosf( t * 0.8f );
3717− attributes.neighborRepulsion = 0.2f + 0.2f * sinf( t * 0.4f );
3716+ attributes.gravity = 0.0f + 0.05f * sinf( effectsTimer * 0.52f );
3717+ attributes.airFriction = 2.5 + 2.0f * sinf( effectsTimer * 0.32f );
3718+ attributes.jitter = 0.05f + 0.05f * sinf( effectsTimer * 0.42f );
3719+ attributes.emitterAttraction = 0.015f + 0.015f * cosf( effectsTimer * 0.6f );
3720+ attributes.tornadoForce = 0.0f + 0.03f * sinf( effectsTimer * 0.7f );
3721+ attributes.neighborAttraction = 0.1f + 0.1f * cosf( effectsTimer * 0.8f );
3722+ attributes.neighborRepulsion = 0.2f + 0.2f * sinf( effectsTimer * 0.4f );
37183723 attributes.bounce = 1.0f;
37193724 attributes.usingCollisionSphere = true;
37203725 attributes.collisionSpherePosition = glm::vec3( 5.0f, 0.5f, 5.0f );
37213726 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 );
37223730
37233731 if (attributes.gravity < 0.0f) {
37243732 attributes.gravity = 0.0f;
@@ -3729,6 +3737,15 @@ void Application::updateParticleSystem(float deltaTime) { · 4 unmodified lines
37293737
37303738 _particleSystem.setUpDirection(glm::vec3(0.0f, 1.0f, 0.0f));
37313739 _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+ }
37323749 }
37333750 }
37343751

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