diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index c65e314cc2..923f7821d2 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -2805,6 +2805,8 @@ void Application::updateShadowMap() { // store view matrix without translation, which we'll use for precision-sensitive objects updateUntranslatedViewMatrix(); + // TODO: assign an equivalent viewTransform object to the application to match the current path which uses glMatrixStack + // setViewTransform(viewTransform); glEnable(GL_POLYGON_OFFSET_FILL); glPolygonOffset(1.1f, 4.0f); // magic numbers courtesy http://www.eecs.berkeley.edu/~ravir/6160/papers/shadowmaps.ppt @@ -2883,6 +2885,7 @@ void Application::displaySide(Camera& whichCamera, bool selfAvatarOnly) { PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings), "Application::displaySide()"); // transform by eye offset + gpu::Transform viewTransform; // load the view frustum @@ -2902,9 +2905,9 @@ void Application::displaySide(Camera& whichCamera, bool selfAvatarOnly) { glm::quat eyeOffsetOrient = whichCamera.getEyeOffsetOrientation(); glm::vec3 eyeOffsetAxis = glm::axis(eyeOffsetOrient); glRotatef(-glm::degrees(glm::angle(eyeOffsetOrient)), eyeOffsetAxis.x, eyeOffsetAxis.y, eyeOffsetAxis.z); - viewTransform.preRotate(glm::quat(-glm::angle(eyeOffsetOrient), glm::vec3(eyeOffsetAxis.x, eyeOffsetAxis.y, eyeOffsetAxis.z))); - glTranslatef(-eyeOffsetPos.x, -eyeOffsetPos.y, -eyeOffsetPos.z); - viewTransform.preTranslate(glm::vec3(-eyeOffsetPos.x, -eyeOffsetPos.y, -eyeOffsetPos.z)); + viewTransform.postRotate(glm::conjugate(eyeOffsetOrient)); + glTranslatef(-eyeOffsetPos.x, -eyeOffsetPos.y, -eyeOffsetPos.z); + viewTransform.postTranslate(-eyeOffsetPos); // transform view according to whichCamera // could be myCamera (if in normal mode) @@ -2913,11 +2916,15 @@ void Application::displaySide(Camera& whichCamera, bool selfAvatarOnly) { glm::quat rotation = whichCamera.getRotation(); glm::vec3 axis = glm::axis(rotation); glRotatef(-glm::degrees(glm::angle(rotation)), axis.x, axis.y, axis.z); - viewTransform.preRotate(glm::quat(-glm::angle(rotation), axis)); + viewTransform.postRotate(glm::conjugate(rotation)); // store view matrix without translation, which we'll use for precision-sensitive objects updateUntranslatedViewMatrix(-whichCamera.getPosition()); - viewTransform.preTranslate(-whichCamera.getPosition()); + + // Equivalent to what is happening with _untranslatedViewMatrix and the _viewMatrixTranslation + // the viewTransofmr object is updated with the correct value and saved, + // this is what is used for rendering the ENtities and avatars + setViewTransform(viewTransform); glTranslatef(_viewMatrixTranslation.x, _viewMatrixTranslation.y, _viewMatrixTranslation.z); @@ -3120,8 +3127,10 @@ void Application::displaySide(Camera& whichCamera, bool selfAvatarOnly) { void Application::updateUntranslatedViewMatrix(const glm::vec3& viewMatrixTranslation) { glGetFloatv(GL_MODELVIEW_MATRIX, (GLfloat*)&_untranslatedViewMatrix); _viewMatrixTranslation = viewMatrixTranslation; - _viewTransform->evalFromRawMatrix(_untranslatedViewMatrix); - _viewTransform->postTranslate(viewMatrixTranslation); +} + +void Application::setViewTransform(const gpu::Transform& view) { + (*_viewTransform) = view; } void Application::loadTranslatedViewMatrix(const glm::vec3& translation) { diff --git a/interface/src/Application.h b/interface/src/Application.h index ca8651867f..b59b9c90a0 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -234,6 +234,7 @@ public: void setViewMatrixTranslation(const glm::vec3& translation) { _viewMatrixTranslation = translation; } const gpu::TransformPointer& getViewTransform() const { return _viewTransform; } + void setViewTransform(const gpu::Transform& view); /// if you need to access the application settings, use lockSettings()/unlockSettings() QSettings* lockSettings() { _settingsMutex.lock(); return _settings; } diff --git a/interface/src/gpu/Batch.cpp b/interface/src/gpu/Batch.cpp index a29e0f87a3..2bf92f43cf 100644 --- a/interface/src/gpu/Batch.cpp +++ b/interface/src/gpu/Batch.cpp @@ -21,7 +21,11 @@ Batch::Batch() : _commandOffsets(), _params(), _resources(), - _data(){ + _data(), + _buffers(), + _streamFormats(), + _transforms() +{ } Batch::~Batch() { @@ -32,8 +36,10 @@ void Batch::clear() { _commandOffsets.clear(); _params.clear(); _resources.clear(); - _buffers.clear(); _data.clear(); + _buffers.clear(); + _streamFormats.clear(); + _transforms.clear(); } uint32 Batch::cacheResource(Resource* res) { diff --git a/interface/src/gpu/Batch.h b/interface/src/gpu/Batch.h index cbda6627d3..cc838a8839 100644 --- a/interface/src/gpu/Batch.h +++ b/interface/src/gpu/Batch.h @@ -316,13 +316,12 @@ public: CommandOffsets _commandOffsets; Params _params; Resources _resources; + Bytes _data; BufferCaches _buffers; StreamFormatCaches _streamFormats; - TransformCaches _transforms; - Bytes _data; protected: }; diff --git a/interface/src/gpu/GLBackend.cpp b/interface/src/gpu/GLBackend.cpp index df62b3813c..24141cccdc 100644 --- a/interface/src/gpu/GLBackend.cpp +++ b/interface/src/gpu/GLBackend.cpp @@ -458,6 +458,7 @@ void GLBackend::do_setProjectionTransform(Batch& batch, uint32 paramOffset) { void GLBackend::updateTransform() { if (_transform._invalidProj) { + // TODO: implement the projection matrix assignment to gl state /* if (_transform._lastMode != GL_PROJECTION) { glMatrixMode(GL_PROJECTION); _transform._lastMode = GL_PROJECTION; diff --git a/interface/src/renderer/Model.cpp b/interface/src/renderer/Model.cpp index dcf70e418d..0919850f97 100644 --- a/interface/src/renderer/Model.cpp +++ b/interface/src/renderer/Model.cpp @@ -560,7 +560,8 @@ bool Model::render(float alpha, RenderMode mode, RenderArgs* args) { _transforms.push_back(gpu::TransformPointer(new gpu::Transform())); } (*_transforms[0]) = gpu::Transform((*Application::getInstance()->getViewTransform())); - _transforms[0]->postTranslate(_translation); + // apply entity translation + camera position offset to the viewTransform in one go + _transforms[0]->postTranslate(Application::getInstance()->getViewMatrixTranslation() + _translation); batch.setViewTransform(_transforms[0]); diff --git a/interface/src/ui/MetavoxelEditor.cpp b/interface/src/ui/MetavoxelEditor.cpp index e5a1f7f7a4..c0d8261427 100644 --- a/interface/src/ui/MetavoxelEditor.cpp +++ b/interface/src/ui/MetavoxelEditor.cpp @@ -919,7 +919,9 @@ void SetSpannerTool::applyEdit(const AttributePointer& attribute, const SharedOb Application::getInstance()->setupWorldLight(); Application::getInstance()->updateUntranslatedViewMatrix(); - + // TODO: assign an equivalent viewTransform object to the application to match the current path which uses glMatrixStack + // setViewTransform(viewTransform); + const glm::vec4 OPAQUE_WHITE(1.0f, 1.0f, 1.0f, 1.0f); spannerData->getRenderer()->render(OPAQUE_WHITE, SpannerRenderer::DIFFUSE_MODE, glm::vec3(), 0.0f); diff --git a/libraries/shared/src/Transform.cpp b/libraries/shared/src/Transform.cpp index c7438a058c..7e4a3724c9 100644 --- a/libraries/shared/src/Transform.cpp +++ b/libraries/shared/src/Transform.cpp @@ -25,14 +25,12 @@ void Transform::evalRotationScale(Quat& rotation, Vec3& scale, const Mat3& rotat Mat3 rotationMat = rotationScaleMatrix; do { Mat3 nextRotation; - Mat3 currInvTranspose = - glm::inverse(glm::transpose(rotationMat)); + Mat3 currInvTranspose = glm::inverse(glm::transpose(rotationMat)); // Go through every component in the matrices and find the next matrix for (int i = 0; i < 3; i++) { for (int j = 0; j <3; j++) { - nextRotation[j][i] = 0.5f * - (rotationMat[j][i] + currInvTranspose[j][i]); + nextRotation[j][i] = 0.5f * (rotationMat[j][i] + currInvTranspose[j][i]); } } @@ -73,7 +71,8 @@ void Transform::evalRotationScale(Quat& rotation, Vec3& scale, const Mat3& rotat // Beware: even though the matRot is supposed to be normalized at that point, // glm::quat_cast doesn't always return a normalized quaternion... - rotation = glm::normalize(glm::quat_cast(matRot)); + // rotation = glm::normalize(glm::quat_cast(matRot)); + rotation = (glm::quat_cast(matRot)); } diff --git a/libraries/shared/src/Transform.h b/libraries/shared/src/Transform.h index 37f8eddef8..635b4924c7 100644 --- a/libraries/shared/src/Transform.h +++ b/libraries/shared/src/Transform.h @@ -296,7 +296,7 @@ inline Transform& Transform::evalInverse(Transform& inverse) const { } } if (isRotating()) { - inverse.postRotate(-_rotation); + inverse.postRotate(glm::conjugate(_rotation)); } if (isTranslating()) { inverse.postTranslate(-_translation);