Showing the changes to interface/src/Application.cpp (1 of 25 files). Show all
Unified · Split
| @@ -439,7 +439,7 @@ void Application::paintGL() { · 438 unmodified lines | ||
| 439 | 439 | // myCamera is. But we also want to do meaningful camera transforms on OpenGL for the offset camera |
| 440 | 440 | Camera whichCamera = _myCamera; |
| 441 | 441 | |
| 442 | − if (_viewFrustumFromOffset->isChecked() && _frustumOn->isChecked()) { | |
| 442 | + if (_frustumOn->isChecked()) { | |
| 443 | 443 | |
| 444 | 444 | // set the camera to third-person view but offset so we can see the frustum |
| 445 | 445 | _viewFrustumOffsetCamera.setTargetPosition(_myCamera.getTargetPosition()); |
| @@ -467,56 +467,49 @@ void Application::paintGL() { · 21 unmodified lines | ||
| 467 | 467 | _frameCount++; |
| 468 | 468 | } |
| 469 | 469 | |
| 470 | −void Application::resizeGL(int width, int height) { | |
| 470 | +void Application::resetCamerasOnResizeGL(Camera& camera, int width, int height) { | |
| 471 | 471 | float aspectRatio = ((float)width/(float)height); // based on screen resize |
| 472 | − | |
| 473 | − // reset the camera FOV to our preference... | |
| 474 | − _myCamera.setFieldOfView(_horizontalFieldOfView); | |
| 475 | − | |
| 476 | − // get the lens details from the current camera | |
| 477 | − Camera& camera = _viewFrustumFromOffset->isChecked() ? _viewFrustumOffsetCamera : _myCamera; | |
| 478 | − float nearClip = camera.getNearClip(); | |
| 479 | − float farClip = camera.getFarClip(); | |
| 480 | − float fov; | |
| 481 | − | |
| 472 | + | |
| 482 | 473 | if (OculusManager::isConnected()) { |
| 483 | 474 | // more magic numbers; see Oculus SDK docs, p. 32 |
| 484 | 475 | camera.setAspectRatio(aspectRatio *= 0.5); |
| 485 | − camera.setFieldOfView(fov = 2 * atan((0.0468 * _oculusDistortionScale) / 0.041) * (180 / PIf)); | |
| 486 | − | |
| 487 | − // resize the render texture | |
| 488 | − if (_oculusTextureID != 0) { | |
| 489 | − glBindTexture(GL_TEXTURE_2D, _oculusTextureID); | |
| 490 | − glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0); | |
| 491 | − glBindTexture(GL_TEXTURE_2D, 0); | |
| 492 | − } | |
| 476 | + camera.setFieldOfView(2 * atan((0.0468 * _oculusDistortionScale) / 0.041) * (180 / PIf)); | |
| 493 | 477 | } else { |
| 494 | 478 | camera.setAspectRatio(aspectRatio); |
| 495 | − camera.setFieldOfView(fov = _horizontalFieldOfView); | |
| 479 | + camera.setFieldOfView(_fieldOfView); | |
| 496 | 480 | } |
| 481 | +} | |
| 497 | 482 | |
| 498 | − // Tell our viewFrustum about this change | |
| 499 | − _viewFrustum.setAspectRatio(aspectRatio); | |
| 483 | +void Application::resizeGL(int width, int height) { | |
| 484 | + resetCamerasOnResizeGL(_viewFrustumOffsetCamera, width, height); | |
| 485 | + resetCamerasOnResizeGL(_myCamera, width, height); | |
| 486 | + | |
| 487 | + // resize the render texture | |
| 488 | + if (OculusManager::isConnected() && _oculusTextureID != 0) { | |
| 489 | + glBindTexture(GL_TEXTURE_2D, _oculusTextureID); | |
| 490 | + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0); | |
| 491 | + glBindTexture(GL_TEXTURE_2D, 0); | |
| 492 | + } | |
| 493 | + | |
| 494 | + // Tell our viewFrustum about this change, using the application camera | |
| 495 | + loadViewFrustum(_myCamera, _viewFrustum); | |
| 500 | 496 | |
| 501 | 497 | glViewport(0, 0, width, height); // shouldn't this account for the menu??? |
| 502 | 498 | |
| 503 | 499 | glMatrixMode(GL_PROJECTION); |
| 504 | 500 | glLoadIdentity(); |
| 505 | 501 | |
| 506 | − // XXXBHG - If we're in view frustum mode, then we need to do this little bit of hackery so that | |
| 507 | − // OpenGL won't clip our frustum rendering lines. This is a debug hack for sure! Basically, this makes | |
| 508 | − // the near clip a little bit closer (therefor you see more) and the far clip a little bit farther (also, | |
| 509 | − // to see more.) | |
| 510 | − if (_frustumOn->isChecked()) { | |
| 511 | − nearClip -= 0.01f; | |
| 512 | − farClip += 0.01f; | |
| 513 | − } | |
| 514 | − | |
| 515 | 502 | // On window reshape, we need to tell OpenGL about our new setting |
| 516 | 503 | float left, right, bottom, top, nearVal, farVal; |
| 517 | 504 | glm::vec4 nearClipPlane, farClipPlane; |
| 518 | − loadViewFrustum(camera, _viewFrustum); | |
| 519 | 505 | _viewFrustum.computeOffAxisFrustum(left, right, bottom, top, nearVal, farVal, nearClipPlane, farClipPlane); |
| 506 | + | |
| 507 | + // If we're in Display Frustum mode, then we want to use the slightly adjust near/far clip values of the | |
| 508 | + // _viewFrustumOffsetCamera, so that we can see more of the application content in the application's frustum | |
| 509 | + if (_frustumOn->isChecked()) { | |
| 510 | + nearVal = _viewFrustumOffsetCamera.getNearClip(); | |
| 511 | + farVal = _viewFrustumOffsetCamera.getFarClip(); | |
| 512 | + } | |
| 520 | 513 | glFrustum(left, right, bottom, top, nearVal, farVal); |
| 521 | 514 | |
| 522 | 515 | glMatrixMode(GL_MODELVIEW); |
| @@ -819,11 +812,7 @@ void Application::keyPressEvent(QKeyEvent* event) { · 296 unmodified lines | ||
| 819 | 812 | _colorVoxelMode->trigger(); |
| 820 | 813 | break; |
| 821 | 814 | case Qt::Key_O: |
| 822 | − if (isShifted) { | |
| 823 | − _viewFrustumFromOffset->trigger(); | |
| 824 | − } else { | |
| 825 | − _selectVoxelMode->trigger(); | |
| 826 | − } | |
| 815 | + _selectVoxelMode->trigger(); | |
| 827 | 816 | break; |
| 828 | 817 | case Qt::Key_Slash: |
| 829 | 818 | _renderStatsOn->trigger(); |
| @@ -1295,11 +1284,11 @@ void Application::editPreferences() { · 465 unmodified lines | ||
| 1295 | 1284 | avatarURL->setMinimumWidth(QLINE_MINIMUM_WIDTH); |
| 1296 | 1285 | form->addRow("Avatar URL:", avatarURL); |
| 1297 | 1286 | |
| 1298 | − QSpinBox* horizontalFieldOfView = new QSpinBox(); | |
| 1299 | − horizontalFieldOfView->setMaximum(180); | |
| 1300 | − horizontalFieldOfView->setMinimum(1); | |
| 1301 | − horizontalFieldOfView->setValue(_horizontalFieldOfView); | |
| 1302 | − form->addRow("Horizontal field of view (degrees):", horizontalFieldOfView); | |
| 1287 | + QSpinBox* fieldOfView = new QSpinBox(); | |
| 1288 | + fieldOfView->setMaximum(180); | |
| 1289 | + fieldOfView->setMinimum(1); | |
| 1290 | + fieldOfView->setValue(_fieldOfView); | |
| 1291 | + form->addRow("Vertical Field of View (Degrees):", fieldOfView); | |
| 1303 | 1292 | |
| 1304 | 1293 | QDoubleSpinBox* gyroCameraSensitivity = new QDoubleSpinBox(); |
| 1305 | 1294 | gyroCameraSensitivity->setValue(_gyroCameraSensitivity); |
| @@ -1359,7 +1348,7 @@ void Application::editPreferences() { · 53 unmodified lines | ||
| 1359 | 1348 | if (!shouldDynamicallySetJitterBuffer()) { |
| 1360 | 1349 | _audio.setJitterBufferSamples(_audioJitterBufferSamples); |
| 1361 | 1350 | } |
| 1362 | − _horizontalFieldOfView = horizontalFieldOfView->value(); | |
| 1351 | + _fieldOfView = fieldOfView->value(); | |
| 1363 | 1352 | resizeGL(_glWidget->width(), _glWidget->height()); |
| 1364 | 1353 | |
| 1365 | 1354 | } |
| @@ -2060,8 +2049,6 @@ void Application::initMenu() { · 694 unmodified lines | ||
| 2060 | 2049 | QMenu* frustumMenu = debugMenu->addMenu("View Frustum Debugging Tools"); |
| 2061 | 2050 | (_frustumOn = frustumMenu->addAction("Display Frustum"))->setCheckable(true); |
| 2062 | 2051 | _frustumOn->setShortcut(Qt::SHIFT | Qt::Key_F); |
| 2063 | − (_viewFrustumFromOffset = frustumMenu->addAction( | |
| 2064 | − "Use Offset Camera", this, SLOT(setFrustumOffset(bool)), Qt::SHIFT | Qt::Key_O))->setCheckable(true); | |
| 2065 | 2052 | _frustumRenderModeAction = frustumMenu->addAction( |
| 2066 | 2053 | "Render Mode", this, SLOT(cycleFrustumRenderMode()), Qt::SHIFT | Qt::Key_R); |
| 2067 | 2054 | updateFrustumRenderModeAction(); |
| @@ -2776,6 +2763,7 @@ void Application::loadViewFrustum(Camera& camera, ViewFrustum& viewFrustum) { · 708 unmodified lines | ||
| 2776 | 2763 | float fov = camera.getFieldOfView(); |
| 2777 | 2764 | float nearClip = camera.getNearClip(); |
| 2778 | 2765 | float farClip = camera.getFarClip(); |
| 2766 | + float aspectRatio = camera.getAspectRatio(); | |
| 2779 | 2767 | |
| 2780 | 2768 | glm::quat rotation = camera.getRotation(); |
| 2781 | 2769 | |
| @@ -2784,6 +2772,7 @@ void Application::loadViewFrustum(Camera& camera, ViewFrustum& viewFrustum) { · 2 unmodified lines | ||
| 2784 | 2772 | viewFrustum.setOrientation(rotation); |
| 2785 | 2773 | |
| 2786 | 2774 | // Also make sure it's got the correct lens details from the camera |
| 2775 | + viewFrustum.setAspectRatio(aspectRatio); | |
| 2787 | 2776 | viewFrustum.setFieldOfView(fov); |
| 2788 | 2777 | viewFrustum.setNearClip(nearClip); |
| 2789 | 2778 | viewFrustum.setFarClip(farClip); |
| @@ -2940,6 +2929,9 @@ void Application::displayOculus(Camera& whichCamera) { · 150 unmodified lines | ||
| 2940 | 2929 | glPopMatrix(); |
| 2941 | 2930 | } |
| 2942 | 2931 | |
| 2932 | +const GLfloat WHITE_SPECULAR_COLOR[] = { 1.0f, 1.0f, 1.0f, 1.0f }; | |
| 2933 | +const GLfloat NO_SPECULAR_COLOR[] = { 0.0f, 0.0f, 0.0f, 1.0f }; | |
| 2934 | + | |
| 2943 | 2935 | void Application::setupWorldLight(Camera& whichCamera) { |
| 2944 | 2936 | |
| 2945 | 2937 | // Setup 3D lights (after the camera transform, so that they are positioned in world space) |
| @@ -2954,10 +2946,9 @@ void Application::setupWorldLight(Camera& whichCamera) { · 8 unmodified lines | ||
| 2954 | 2946 | glLightfv(GL_LIGHT0, GL_AMBIENT, ambient_color); |
| 2955 | 2947 | GLfloat diffuse_color[] = { 0.8, 0.7, 0.7 }; |
| 2956 | 2948 | glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse_color); |
| 2957 | − GLfloat specular_color[] = { 1.0, 1.0, 1.0, 1.0}; | |
| 2958 | − glLightfv(GL_LIGHT0, GL_SPECULAR, specular_color); | |
| 2959 | 2949 | |
| 2960 | − glMaterialfv(GL_FRONT, GL_SPECULAR, specular_color); | |
| 2950 | + glLightfv(GL_LIGHT0, GL_SPECULAR, WHITE_SPECULAR_COLOR); | |
| 2951 | + glMaterialfv(GL_FRONT, GL_SPECULAR, WHITE_SPECULAR_COLOR); | |
| 2961 | 2952 | glMateriali(GL_FRONT, GL_SHININESS, 96); |
| 2962 | 2953 | } |
| 2963 | 2954 | |
| @@ -3035,6 +3026,9 @@ void Application::displaySide(Camera& whichCamera) { · 71 unmodified lines | ||
| 3035 | 3026 | glutSolidSphere(sphereRadius, 15, 15); |
| 3036 | 3027 | glPopMatrix(); |
| 3037 | 3028 | |
| 3029 | + // disable specular lighting for ground and voxels | |
| 3030 | + glMaterialfv(GL_FRONT, GL_SPECULAR, NO_SPECULAR_COLOR); | |
| 3031 | + | |
| 3038 | 3032 | //draw a grid ground plane.... |
| 3039 | 3033 | if (_renderGroundPlaneOn->isChecked()) { |
| 3040 | 3034 | // draw grass plane with fog |
| @@ -3063,6 +3057,9 @@ void Application::displaySide(Camera& whichCamera) { · 22 unmodified lines | ||
| 3063 | 3057 | _voxels.render(_renderVoxelTextures->isChecked()); |
| 3064 | 3058 | } |
| 3065 | 3059 | |
| 3060 | + // restore default, white specular | |
| 3061 | + glMaterialfv(GL_FRONT, GL_SPECULAR, WHITE_SPECULAR_COLOR); | |
| 3062 | + | |
| 3066 | 3063 | // indicate what we'll be adding/removing in mouse mode, if anything |
| 3067 | 3064 | if (_mouseVoxel.s != 0) { |
| 3068 | 3065 | glDisable(GL_LIGHTING); |
| @@ -3110,16 +3107,14 @@ void Application::displaySide(Camera& whichCamera) { · 41 unmodified lines | ||
| 3110 | 3107 | } |
| 3111 | 3108 | |
| 3112 | 3109 | // Render my own Avatar |
| 3113 | − if (_myCamera.getMode() != CAMERA_MODE_FIRST_PERSON) { | |
| 3114 | − if (_myCamera.getMode() == CAMERA_MODE_MIRROR) { | |
| 3115 | − _myAvatar.getHead().setLookAtPosition(_myCamera.getPosition()); | |
| 3116 | − } | |
| 3117 | − _myAvatar.render(_lookingInMirror->isChecked(), _renderAvatarBalls->isChecked()); | |
| 3118 | − _myAvatar.setDisplayingLookatVectors(_renderLookatOn->isChecked()); | |
| 3110 | + if (_myCamera.getMode() == CAMERA_MODE_MIRROR) { | |
| 3111 | + _myAvatar.getHead().setLookAtPosition(_myCamera.getPosition()); | |
| 3112 | + } | |
| 3113 | + _myAvatar.render(_lookingInMirror->isChecked(), _renderAvatarBalls->isChecked()); | |
| 3114 | + _myAvatar.setDisplayingLookatVectors(_renderLookatOn->isChecked()); | |
| 3119 | 3115 | |
| 3120 | − if (_renderLookatIndicatorOn->isChecked() && _isLookingAtOtherAvatar) { | |
| 3121 | − renderLookatIndicator(_lookatOtherPosition, whichCamera); | |
| 3122 | − } | |
| 3116 | + if (_renderLookatIndicatorOn->isChecked() && _isLookingAtOtherAvatar) { | |
| 3117 | + renderLookatIndicator(_lookatOtherPosition, whichCamera); | |
| 3123 | 3118 | } |
| 3124 | 3119 | } |
| 3125 | 3120 | |
| @@ -3312,7 +3307,7 @@ void Application::displayStats() { · 186 unmodified lines | ||
| 3312 | 3307 | int statsVerticalOffset = 8; |
| 3313 | 3308 | |
| 3314 | 3309 | char stats[200]; |
| 3315 | − sprintf(stats, "%3.0f FPS, %d Pkts/sec, %3.2f Mbps", | |
| 3310 | + sprintf(stats, "%3.0f FPS, %d Pkts/sec, %3.2f Mbps ", | |
| 3316 | 3311 | _fps, _packetsPerSecond, (float)_bytesPerSecond * 8.f / 1000000.f); |
| 3317 | 3312 | drawtext(10, statsVerticalOffset + 15, 0.10f, 0, 1.0, 0, stats); |
| 3318 | 3313 | |
| @@ -3343,11 +3338,16 @@ void Application::displayStats() { · 24 unmodified lines | ||
| 3343 | 3338 | pingVoxel = totalPingVoxel/voxelServerCount; |
| 3344 | 3339 | } |
| 3345 | 3340 | |
| 3346 | − | |
| 3347 | 3341 | char pingStats[200]; |
| 3348 | 3342 | sprintf(pingStats, "Ping audio/avatar/voxel: %d / %d / %d avg %d max ", pingAudio, pingAvatar, pingVoxel, pingVoxelMax); |
| 3349 | 3343 | drawtext(10, statsVerticalOffset + 35, 0.10f, 0, 1.0, 0, pingStats); |
| 3350 | 3344 | } |
| 3345 | + | |
| 3346 | + char avatarStats[200]; | |
| 3347 | + glm::vec3 avatarPos = _myAvatar.getPosition(); | |
| 3348 | + sprintf(avatarStats, "Avatar position: %.3f, %.3f, %.3f, yaw = %.2f", avatarPos.x, avatarPos.y, avatarPos.z, _myAvatar.getBodyYaw()); | |
| 3349 | + drawtext(10, statsVerticalOffset + 55, 0.10f, 0, 1.0, 0, avatarStats); | |
| 3350 | + | |
| 3351 | 3351 | |
| 3352 | 3352 | std::stringstream voxelStats; |
| 3353 | 3353 | voxelStats.precision(4); |
| @@ -3961,6 +3961,8 @@ void Application::nodeKilled(Node* node) { · 607 unmodified lines | ||
| 3961 | 3961 | // Add the jurisditionDetails object to the list of "fade outs" |
| 3962 | 3962 | VoxelFade fade(VoxelFade::FADE_OUT, NODE_KILLED_RED, NODE_KILLED_GREEN, NODE_KILLED_BLUE); |
| 3963 | 3963 | fade.voxelDetails = jurisditionDetails; |
| 3964 | + const float slightly_smaller = 0.99; | |
| 3965 | + fade.voxelDetails.s = fade.voxelDetails.s * slightly_smaller; | |
| 3964 | 3966 | _voxelFades.push_back(fade); |
| 3965 | 3967 | } |
| 3966 | 3968 | } |
| @@ -3990,6 +3992,8 @@ int Application::parseVoxelStats(unsigned char* messageData, ssize_t messageLeng · 23 unmodified lines | ||
| 3990 | 3992 | // Add the jurisditionDetails object to the list of "fade outs" |
| 3991 | 3993 | VoxelFade fade(VoxelFade::FADE_OUT, NODE_ADDED_RED, NODE_ADDED_GREEN, NODE_ADDED_BLUE); |
| 3992 | 3994 | fade.voxelDetails = jurisditionDetails; |
| 3995 | + const float slightly_smaller = 0.99; | |
| 3996 | + fade.voxelDetails.s = fade.voxelDetails.s * slightly_smaller; | |
| 3993 | 3997 | _voxelFades.push_back(fade); |
| 3994 | 3998 | } |
| 3995 | 3999 | // store jurisdiction details for later use |
| @@ -4144,7 +4148,7 @@ void Application::loadSettings(QSettings* settings) { · 148 unmodified lines | ||
| 4144 | 4148 | |
| 4145 | 4149 | _gyroCameraSensitivity = loadSetting(settings, "gyroCameraSensitivity", 0.5f); |
| 4146 | 4150 | _audioJitterBufferSamples = loadSetting(settings, "audioJitterBufferSamples", 0); |
| 4147 | − _horizontalFieldOfView = loadSetting(settings, "horizontalFieldOfView", HORIZONTAL_FIELD_OF_VIEW_DEGREES); | |
| 4151 | + _fieldOfView = loadSetting(settings, "fieldOfView", DEFAULT_FIELD_OF_VIEW_DEGREES); | |
| 4148 | 4152 | |
| 4149 | 4153 | settings->beginGroup("View Frustum Offset Camera"); |
| 4150 | 4154 | // in case settings is corrupt or missing loadSetting() will check for NaN |
| @@ -4168,7 +4172,7 @@ void Application::saveSettings(QSettings* settings) { · 17 unmodified lines | ||
| 4168 | 4172 | |
| 4169 | 4173 | settings->setValue("gyroCameraSensitivity", _gyroCameraSensitivity); |
| 4170 | 4174 | settings->setValue("audioJitterBufferSamples", _audioJitterBufferSamples); |
| 4171 | − settings->setValue("horizontalFieldOfView", _horizontalFieldOfView); | |
| 4175 | + settings->setValue("fieldOfView", _fieldOfView); | |
| 4172 | 4176 | settings->beginGroup("View Frustum Offset Camera"); |
| 4173 | 4177 | settings->setValue("viewFrustumOffsetYaw", _viewFrustumOffsetYaw); |
| 4174 | 4178 | settings->setValue("viewFrustumOffsetPitch", _viewFrustumOffsetPitch); |