For clarity, break the projection matrix update out of resizeGL.

This commit is contained in:
Andrzej Kapolka 2013-09-05 12:34:25 -07:00
parent 4961913fc4
commit 32af1de3ac
2 changed files with 14 additions and 10 deletions

View file

@ -428,10 +428,14 @@ void Application::resizeGL(int width, int height) {
glViewport(0, 0, width, height); // shouldn't this account for the menu??? glViewport(0, 0, width, height); // shouldn't this account for the menu???
updateProjectionMatrix();
glLoadIdentity();
}
void Application::updateProjectionMatrix() {
glMatrixMode(GL_PROJECTION); glMatrixMode(GL_PROJECTION);
glLoadIdentity(); glLoadIdentity();
// On window reshape, we need to tell OpenGL about our new setting
float left, right, bottom, top, nearVal, farVal; float left, right, bottom, top, nearVal, farVal;
glm::vec4 nearClipPlane, farClipPlane; glm::vec4 nearClipPlane, farClipPlane;
_viewFrustum.computeOffAxisFrustum(left, right, bottom, top, nearVal, farVal, nearClipPlane, farClipPlane); _viewFrustum.computeOffAxisFrustum(left, right, bottom, top, nearVal, farVal, nearClipPlane, farClipPlane);
@ -445,7 +449,6 @@ void Application::resizeGL(int width, int height) {
glFrustum(left, right, bottom, top, nearVal, farVal); glFrustum(left, right, bottom, top, nearVal, farVal);
glMatrixMode(GL_MODELVIEW); glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
} }
void Application::controlledBroadcastToNodes(unsigned char* broadcastData, size_t dataBytes, void Application::controlledBroadcastToNodes(unsigned char* broadcastData, size_t dataBytes,
@ -613,7 +616,7 @@ void Application::keyPressEvent(QKeyEvent* event) {
} else { } else {
_myCamera.setEyeOffsetPosition(_myCamera.getEyeOffsetPosition() + glm::vec3(0, 0.001, 0)); _myCamera.setEyeOffsetPosition(_myCamera.getEyeOffsetPosition() + glm::vec3(0, 0.001, 0));
} }
resizeGL(_glWidget->width(), _glWidget->height()); updateProjectionMatrix();
break; break;
case Qt::Key_K: case Qt::Key_K:
@ -623,7 +626,7 @@ void Application::keyPressEvent(QKeyEvent* event) {
} else { } else {
_myCamera.setEyeOffsetPosition(_myCamera.getEyeOffsetPosition() + glm::vec3(0, -0.001, 0)); _myCamera.setEyeOffsetPosition(_myCamera.getEyeOffsetPosition() + glm::vec3(0, -0.001, 0));
} }
resizeGL(_glWidget->width(), _glWidget->height()); updateProjectionMatrix();
break; break;
case Qt::Key_J: case Qt::Key_J:
@ -633,7 +636,7 @@ void Application::keyPressEvent(QKeyEvent* event) {
} else { } else {
_myCamera.setEyeOffsetPosition(_myCamera.getEyeOffsetPosition() + glm::vec3(-0.001, 0, 0)); _myCamera.setEyeOffsetPosition(_myCamera.getEyeOffsetPosition() + glm::vec3(-0.001, 0, 0));
} }
resizeGL(_glWidget->width(), _glWidget->height()); updateProjectionMatrix();
break; break;
case Qt::Key_M: case Qt::Key_M:
@ -643,7 +646,7 @@ void Application::keyPressEvent(QKeyEvent* event) {
} else { } else {
_myCamera.setEyeOffsetPosition(_myCamera.getEyeOffsetPosition() + glm::vec3(0.001, 0, 0)); _myCamera.setEyeOffsetPosition(_myCamera.getEyeOffsetPosition() + glm::vec3(0.001, 0, 0));
} }
resizeGL(_glWidget->width(), _glWidget->height()); updateProjectionMatrix();
break; break;
case Qt::Key_U: case Qt::Key_U:
@ -653,7 +656,7 @@ void Application::keyPressEvent(QKeyEvent* event) {
} else { } else {
_myCamera.setEyeOffsetPosition(_myCamera.getEyeOffsetPosition() + glm::vec3(0, 0, -0.001)); _myCamera.setEyeOffsetPosition(_myCamera.getEyeOffsetPosition() + glm::vec3(0, 0, -0.001));
} }
resizeGL(_glWidget->width(), _glWidget->height()); updateProjectionMatrix();
break; break;
case Qt::Key_Y: case Qt::Key_Y:
@ -663,7 +666,7 @@ void Application::keyPressEvent(QKeyEvent* event) {
} else { } else {
_myCamera.setEyeOffsetPosition(_myCamera.getEyeOffsetPosition() + glm::vec3(0, 0, 0.001)); _myCamera.setEyeOffsetPosition(_myCamera.getEyeOffsetPosition() + glm::vec3(0, 0, 0.001));
} }
resizeGL(_glWidget->width(), _glWidget->height()); updateProjectionMatrix();
break; break;
case Qt::Key_H: case Qt::Key_H:
Menu::getInstance()->triggerOption(MenuOption::Mirror); Menu::getInstance()->triggerOption(MenuOption::Mirror);
@ -1806,12 +1809,12 @@ void Application::update(float deltaTime) {
const float EYE_OFFSET_SCALE = 0.005f; const float EYE_OFFSET_SCALE = 0.005f;
glm::vec3 position = _faceshift.getHeadTranslation() * EYE_OFFSET_SCALE; glm::vec3 position = _faceshift.getHeadTranslation() * EYE_OFFSET_SCALE;
_myCamera.setEyeOffsetPosition(glm::vec3(-position.x, position.y, position.z)); _myCamera.setEyeOffsetPosition(glm::vec3(-position.x, position.y, position.z));
resizeGL(_glWidget->width(), _glWidget->height()); updateProjectionMatrix();
} else if (_webcam.isActive()) { } else if (_webcam.isActive()) {
const float EYE_OFFSET_SCALE = 5.0f; const float EYE_OFFSET_SCALE = 5.0f;
_myCamera.setEyeOffsetPosition(_webcam.getEstimatedPosition() * EYE_OFFSET_SCALE); _myCamera.setEyeOffsetPosition(_webcam.getEstimatedPosition() * EYE_OFFSET_SCALE);
resizeGL(_glWidget->width(), _glWidget->height()); updateProjectionMatrix();
} }
} }
} }

View file

@ -178,6 +178,7 @@ private slots:
private: private:
void resetCamerasOnResizeGL(Camera& camera, int width, int height); void resetCamerasOnResizeGL(Camera& camera, int width, int height);
void updateProjectionMatrix();
static bool sendVoxelsOperation(VoxelNode* node, void* extraData); static bool sendVoxelsOperation(VoxelNode* node, void* extraData);
static void processAvatarVoxelURLMessage(unsigned char* packetData, size_t dataBytes); static void processAvatarVoxelURLMessage(unsigned char* packetData, size_t dataBytes);