fix rear view mirror mode to only render self

This commit is contained in:
ZappoMan 2013-10-23 11:58:01 -07:00
parent b1364f589a
commit 161367c899
2 changed files with 153 additions and 141 deletions

View file

@ -438,13 +438,15 @@ void Application::paintGL() {
// set the bounds of rear mirror view
glViewport(_mirrorViewRect.x(), _glWidget->height() - _mirrorViewRect.y() - _mirrorViewRect.height(), _mirrorViewRect.width(), _mirrorViewRect.height());
glScissor(_mirrorViewRect.x(), _glWidget->height() - _mirrorViewRect.y() - _mirrorViewRect.height(), _mirrorViewRect.width(), _mirrorViewRect.height());
updateProjectionMatrix(_mirrorCamera);
bool updateViewFrustum = false;
updateProjectionMatrix(_mirrorCamera, updateViewFrustum);
glEnable(GL_SCISSOR_TEST);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// render rear mirror view
glPushMatrix();
displaySide(_mirrorCamera);
bool selfAvatarOnly = true;
displaySide(_mirrorCamera, selfAvatarOnly);
glPopMatrix();
// render rear view tools if mouse is in the bounds
@ -456,7 +458,7 @@ void Application::paintGL() {
// reset Viewport and projection matrix
glViewport(0, 0, _glWidget->width(), _glWidget->height());
glDisable(GL_SCISSOR_TEST);
updateProjectionMatrix();
updateProjectionMatrix(_myCamera, updateViewFrustum);
}
displayOverlay();
@ -494,15 +496,16 @@ void Application::updateProjectionMatrix() {
updateProjectionMatrix(_myCamera);
}
void Application::updateProjectionMatrix(Camera& camera) {
void Application::updateProjectionMatrix(Camera& camera, bool updateViewFrustum) {
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
// Tell our viewFrustum about this change, using the application camera
loadViewFrustum(camera, _viewFrustum);
float left, right, bottom, top, nearVal, farVal;
glm::vec4 nearClipPlane, farClipPlane;
// Tell our viewFrustum about this change, using the application camera
if (updateViewFrustum) {
loadViewFrustum(camera, _viewFrustum);
computeOffAxisFrustum(left, right, bottom, top, nearVal, farVal, nearClipPlane, farClipPlane);
// If we're in Display Frustum mode, then we want to use the slightly adjust near/far clip values of the
@ -511,6 +514,11 @@ void Application::updateProjectionMatrix(Camera& camera) {
nearVal = _viewFrustumOffsetCamera.getNearClip();
farVal = _viewFrustumOffsetCamera.getFarClip();
}
} else {
ViewFrustum tempViewFrustum;
loadViewFrustum(camera, tempViewFrustum);
tempViewFrustum.computeOffAxisFrustum(left, right, bottom, top, nearVal, farVal, nearClipPlane, farClipPlane);
}
glFrustum(left, right, bottom, top, nearVal, farVal);
glMatrixMode(GL_MODELVIEW);
@ -2508,7 +2516,7 @@ void Application::computeOffAxisFrustum(float& left, float& right, float& bottom
_viewFrustum.computeOffAxisFrustum(left, right, bottom, top, near, far, nearClipPlane, farClipPlane);
}
void Application::displaySide(Camera& whichCamera) {
void Application::displaySide(Camera& whichCamera, bool selfAvatarOnly) {
PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings), "Application::displaySide()");
// transform by eye offset
@ -2540,7 +2548,7 @@ void Application::displaySide(Camera& whichCamera) {
// Setup 3D lights (after the camera transform, so that they are positioned in world space)
setupWorldLight(whichCamera);
if (Menu::getInstance()->isOptionChecked(MenuOption::Stars)) {
if (!selfAvatarOnly && Menu::getInstance()->isOptionChecked(MenuOption::Stars)) {
PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings),
"Application::displaySide() ... stars...");
if (!_stars.isStarsLoaded()) {
@ -2567,7 +2575,7 @@ void Application::displaySide(Camera& whichCamera) {
}
// draw the sky dome
if (Menu::getInstance()->isOptionChecked(MenuOption::Atmosphere)) {
if (!selfAvatarOnly && Menu::getInstance()->isOptionChecked(MenuOption::Atmosphere)) {
PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings),
"Application::displaySide() ... atmosphere...");
_environment.renderAtmospheres(whichCamera);
@ -2580,6 +2588,7 @@ void Application::displaySide(Camera& whichCamera) {
//renderLineToTouchedVoxel();
//renderThrustAtVoxel(_voxelThrust);
if (!selfAvatarOnly) {
// draw a red sphere
float sphereRadius = 0.25f;
glColor3f(1,0,0);
@ -2697,6 +2706,7 @@ void Application::displaySide(Camera& whichCamera) {
_sharedVoxelSystem.render(true);
glPopMatrix();
}
}
_myAvatar.renderScreenTint(SCREEN_TINT_BEFORE_AVATARS, whichCamera);
@ -2705,6 +2715,7 @@ void Application::displaySide(Camera& whichCamera) {
"Application::displaySide() ... Avatars...");
if (!selfAvatarOnly) {
// Render avatars of other nodes
NodeList* nodeList = NodeList::getInstance();
@ -2726,6 +2737,7 @@ void Application::displaySide(Camera& whichCamera) {
node->unlock();
}
}
// Render my own Avatar
if (whichCamera.getMode() == CAMERA_MODE_MIRROR && !_faceshift.isActive()) {

View file

@ -196,7 +196,7 @@ private slots:
private:
void resetCamerasOnResizeGL(Camera& camera, int width, int height);
void updateProjectionMatrix();
void updateProjectionMatrix(Camera& camera);
void updateProjectionMatrix(Camera& camera, bool updateViewFrustum = true);
static bool sendVoxelsOperation(VoxelNode* node, void* extraData);
static void processAvatarURLsMessage(unsigned char* packetData, size_t dataBytes);
@ -221,7 +221,7 @@ private:
void loadViewFrustum(Camera& camera, ViewFrustum& viewFrustum);
void displayOculus(Camera& whichCamera);
void displaySide(Camera& whichCamera);
void displaySide(Camera& whichCamera, bool selfAvatarOnly = false);
void displayOverlay();
void displayStats();
void renderViewFrustum(ViewFrustum& viewFrustum);