From fee5f7cd0f9e69354074880527b771938a3bbd03 Mon Sep 17 00:00:00 2001
From: Brad Davis <bdavis@saintandreas.org>
Date: Mon, 13 Jul 2015 19:07:44 -0700
Subject: [PATCH] Merge fixes

---
 interface/src/Application.cpp                 | 43 ++++++-------------
 interface/src/avatar/MyAvatar.cpp             |  5 +--
 .../src/ui/overlays/LocalModelsOverlay.cpp    |  6 +--
 interface/ui/temp.qml                         | 33 ++++++++++++++
 4 files changed, 49 insertions(+), 38 deletions(-)
 create mode 100644 interface/ui/temp.qml

diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp
index 5ed8b3df42..250c5ce079 100644
--- a/interface/src/Application.cpp
+++ b/interface/src/Application.cpp
@@ -923,6 +923,10 @@ void Application::paintGL() {
 
     {
         PerformanceTimer perfTimer("renderOverlay");
+        gpu::Context context(new gpu::GLBackend());
+        RenderArgs renderArgs(&context, nullptr, getViewFrustum(), lodManager->getOctreeSizeScale(),
+            lodManager->getBoundaryLevelAdjust(), RenderArgs::DEFAULT_RENDER_MODE,
+            RenderArgs::MONO, RenderArgs::RENDER_DEBUG_NONE);
         _applicationOverlay.renderOverlay(&renderArgs);
     }
 
@@ -1066,7 +1070,6 @@ void Application::paintGL() {
         renderArgs._renderMode = RenderArgs::NORMAL_RENDER_MODE;
 #endif
 
-<<<<<<< HEAD
     // deliver final composited scene to the display plugin
     {
         GLuint finalTexture = gpu::GLBackend::getTextureID(finalFbo->getRenderBuffer(0));
@@ -3049,25 +3052,6 @@ QRect Application::getDesirableApplicationGeometry() {
     return applicationGeometry;
 }
 
-/////////////////////////////////////////////////////////////////////////////////////
-// loadViewFrustum()
-//
-// Description: this will load the view frustum bounds for EITHER the head
-//                 or the "myCamera".
-//
-void Application::loadViewFrustum(Camera& camera, ViewFrustum& viewFrustum) {
-    PROFILE_RANGE(__FUNCTION__);
-    // We will use these below, from either the camera or head vectors calculated above
-    viewFrustum.setProjection(camera.getProjection());
-
-    // Set the viewFrustum up with the correct position and orientation of the camera
-    viewFrustum.setPosition(camera.getPosition());
-    viewFrustum.setOrientation(camera.getRotation());
-
-    // Ask the ViewFrustum class to calculate our corners
-    viewFrustum.calculate();
-}
-
 glm::vec3 Application::getSunDirection() {
     // Sun direction is in fact just the location of the sun relative to the origin
     auto skyStage = DependencyManager::get<SceneScriptingInterface>()->getSkyStage();
@@ -3478,9 +3462,15 @@ void Application::displaySide(RenderArgs* renderArgs, Camera& theCamera, bool se
     // load the view frustum
     theCamera.loadViewFrustum(_displayViewFrustum);
 
-    // transform view according to theCamera
-    // could be myCamera (if in normal mode)
-    // or could be viewFrustumOffsetCamera if in offset mode
+    // Load the legacy GL stacks, used by entities (for now)
+    glMatrixMode(GL_PROJECTION);
+    glPushMatrix();
+    glLoadMatrixf(glm::value_ptr(theCamera.getProjection()));
+
+    glMatrixMode(GL_MODELVIEW);
+    glPushMatrix();
+    glLoadMatrixf(glm::value_ptr(glm::inverse(theCamera.getTransform())));
+
 
     glm::quat rotation = theCamera.getRotation();
     // Equivalent to what is happening with _untranslatedViewMatrix and the _viewMatrixTranslation
@@ -3489,13 +3479,6 @@ void Application::displaySide(RenderArgs* renderArgs, Camera& theCamera, bool se
     Transform viewTransform;
     viewTransform.setTranslation(theCamera.getPosition());
     viewTransform.setRotation(rotation);
-    if (renderArgs->_renderSide != RenderArgs::MONO) {
-        glm::mat4 invView = glm::inverse(_untranslatedViewMatrix);
-
-        viewTransform.evalFromRawMatrix(invView);
-        viewTransform.preTranslate(_viewMatrixTranslation);
-    }
-
     setViewTransform(viewTransform);
 
     //  Setup 3D lights (after the camera transform, so that they are positioned in world space)
diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp
index 79c600b7ec..60f99f8d6a 100644
--- a/interface/src/avatar/MyAvatar.cpp
+++ b/interface/src/avatar/MyAvatar.cpp
@@ -35,7 +35,6 @@
 #include <UserActivityLogger.h>
 
 #include "devices/Faceshift.h"
-#include "devices/OculusManager.h"
 
 #include "Application.h"
 #include "AvatarManager.h"
@@ -919,10 +918,8 @@ void MyAvatar::updateLookAtTargetAvatar() {
                 gazeOffset = gazeOffset * HUMAN_EYE_SEPARATION / myEyeSeparation;
 
                 if (Application::getInstance()->isHMDMode()) {
-                    //avatar->getHead()->setCorrectedLookAtPosition(Application::getInstance()->getCamera()->getPosition()
-                    //    + OculusManager::getMidEyePosition() + gazeOffset);
                     avatar->getHead()->setCorrectedLookAtPosition(Application::getInstance()->getViewFrustum()->getPosition()
-                        + OculusManager::getMidEyePosition() + gazeOffset);
+                        + glm::vec3(qApp->getHeadPose()[3]) + gazeOffset);
                 } else {
                     avatar->getHead()->setCorrectedLookAtPosition(Application::getInstance()->getViewFrustum()->getPosition()
                         + gazeOffset);
diff --git a/interface/src/ui/overlays/LocalModelsOverlay.cpp b/interface/src/ui/overlays/LocalModelsOverlay.cpp
index 6e0b53f0c2..a3ea8527f0 100644
--- a/interface/src/ui/overlays/LocalModelsOverlay.cpp
+++ b/interface/src/ui/overlays/LocalModelsOverlay.cpp
@@ -40,14 +40,12 @@ void LocalModelsOverlay::render(RenderArgs* args) {
         
         auto batch = args ->_batch;
         Application* app = Application::getInstance();
-        glm::vec3 oldTranslation = app->getViewMatrixTranslation();
+        glm::vec3 oldTranslation = app->getViewFrustum()->getPosition();
         Transform transform = Transform();
         transform.setTranslation(oldTranslation + getPosition());
         batch->setViewTransform(transform);
         _entityTreeRenderer->render(args);
-        transform.setTranslation(oldTranslation);
-        batch->setViewTransform(transform);
-    
+   
         if (glower) {
             delete glower;
         }
diff --git a/interface/ui/temp.qml b/interface/ui/temp.qml
new file mode 100644
index 0000000000..9617a0a8b7
--- /dev/null
+++ b/interface/ui/temp.qml
@@ -0,0 +1,33 @@
+import QtQuick 2.4
+import QtQuick.Controls 2.3
+import QtQuick.Controls.Styles 1.3
+
+
+Item {
+    implicitHeight: 200
+    implicitWidth: 800
+
+
+    TextArea {
+        id: gutter
+        anchors.left: parent.left
+        anchors.top: parent.top
+        anchors.bottom: parent.bottom
+        style: TextAreaStyle {
+            backgroundColor: "grey"
+        }
+        width: 16
+        text: ">"
+        font.family: "Lucida Console"
+    }
+    TextArea {
+        anchors.left: gutter.right
+        anchors.top: parent.top
+        anchors.bottom: parent.bottom
+        anchors.right: parent.right
+        text: "undefined"
+        font.family: "Lucida Console"
+
+    }
+}
+