Commit 0eee285c authored by Marc R.'s avatar Marc R.

scene view: added method that returns precomputed inverted MVP matrix;...

scene view: added method that returns precomputed inverted MVP matrix; adjusted corresponding code in hsec/vsec/poles
parent 98522b64
......@@ -569,9 +569,10 @@ int MMovablePoleActor::checkIntersectionWithHandle(MSceneViewGLWidget *sceneView
// Scale the radius (in world space) with respect to the viewer distance
float radius = static_cast<float>(clipRadius * viewDir.length() / 100.0);
QMatrix4x4 *mvpMatrix = sceneView->getModelViewProjectionMatrix();
QMatrix4x4 *mvpMatrixInverted =
sceneView->getModelViewProjectionMatrixInverted();
// Compute the world position of the current mouse position
QVector3D mouseWorldPos = mvpMatrix->inverted() * QVector3D(clipX, clipY, 1);
QVector3D mouseWorldPos = *mvpMatrixInverted * QVector3D(clipX, clipY, 1);
// Get the ray direction from the camera to the mouse position
QVector3D l = mouseWorldPos - cameraPos;
......@@ -594,7 +595,7 @@ int MMovablePoleActor::checkIntersectionWithHandle(MSceneViewGLWidget *sceneView
if (root >= 0)
{
highlightPole = i;
mvpMatrix = sceneView->getModelViewProjectionMatrix();
QMatrix4x4 *mvpMatrix = sceneView->getModelViewProjectionMatrix();
QVector3D posPoleClip = *mvpMatrix * posPole;
offsetPickPositionToHandleCentre = QVector2D(posPoleClip.x() - clipX,
posPoleClip.y() - clipY);
......@@ -645,8 +646,9 @@ void MMovablePoleActor::addPositionLabel(MSceneViewGLWidget *sceneView,
// http://en.wikipedia.org/wiki/Line-plane_intersection
// To compute l0, the MVP matrix has to be inverted.
QMatrix4x4 *mvpMatrix = sceneView->getModelViewProjectionMatrix();
QVector3D l0 = mvpMatrix->inverted() * mousePosClipSpace;
QMatrix4x4 *mvpMatrixInverted =
sceneView->getModelViewProjectionMatrixInverted();
QVector3D l0 = *mvpMatrixInverted * mousePosClipSpace;
// Compute l as the vector from l0 to the camera origin.
QVector3D cameraPosWorldSpace = sceneView->getCamera()->getOrigin();
......@@ -699,8 +701,9 @@ void MMovablePoleActor::dragEvent(MSceneViewGLWidget *sceneView,
// http://en.wikipedia.org/wiki/Line-plane_intersection
// To compute l0, the MVP matrix has to be inverted.
QMatrix4x4 *mvpMatrix = sceneView->getModelViewProjectionMatrix();
QVector3D l0 = mvpMatrix->inverted() * mousePosClipSpace;
QMatrix4x4 *mvpMatrixInverted =
sceneView->getModelViewProjectionMatrixInverted();
QVector3D l0 = *mvpMatrixInverted * mousePosClipSpace;
// Compute l as the vector from l0 to the camera origin.
QVector3D cameraPosWorldSpace = sceneView->getCamera()->getOrigin();
......
......@@ -659,9 +659,10 @@ int MNWPHorizontalSectionActor::checkIntersectionWithHandle(
// Scale the radius (in world space) with respect to the viewer distance
float radius = static_cast<float>(clipRadius * viewDir.length() / 100.0);
QMatrix4x4 *mvpMatrix = sceneView->getModelViewProjectionMatrix();
QMatrix4x4 *mvpMatrixInverted =
sceneView->getModelViewProjectionMatrixInverted();
// Compute the world position of the current mouse position
QVector3D mouseWorldPos = mvpMatrix->inverted() * QVector3D(clipX, clipY, 1);
QVector3D mouseWorldPos = *mvpMatrixInverted * QVector3D(clipX, clipY, 1);
// Get the ray direction from the camera to the mouse position
QVector3D l = mouseWorldPos - cameraPos;
......@@ -684,7 +685,7 @@ int MNWPHorizontalSectionActor::checkIntersectionWithHandle(
if (root >= 0)
{
selectedMouseHandle = i;
mvpMatrix = sceneView->getModelViewProjectionMatrix();
QMatrix4x4 *mvpMatrix = sceneView->getModelViewProjectionMatrix();
QVector3D posCentreClip = *mvpMatrix * posPole;
offsetPickPositionToHandleCentre = QVector2D(posCentreClip.x() - clipX,
posCentreClip.y() - clipY);
......@@ -718,8 +719,9 @@ void MNWPHorizontalSectionActor::addPositionLabel(MSceneViewGLWidget *sceneView,
// http://en.wikipedia.org/wiki/Line-plane_intersection
// To compute l0, the MVP matrix has to be inverted.
QMatrix4x4 *mvpMatrix = sceneView->getModelViewProjectionMatrix();
QVector3D l0 = mvpMatrix->inverted() * mousePosClipSpace;
QMatrix4x4 *mvpMatrixInverted =
sceneView->getModelViewProjectionMatrixInverted();
QVector3D l0 = *mvpMatrixInverted * mousePosClipSpace;
// Compute l as the vector from l0 to the camera origin.
QVector3D cameraPosWorldSpace = sceneView->getCamera()->getOrigin();
......@@ -788,8 +790,9 @@ void MNWPHorizontalSectionActor::dragEvent(
// http://en.wikipedia.org/wiki/Line-plane_intersection
// To compute l0, the MVP matrix has to be inverted.
QMatrix4x4 *mvpMatrix = sceneView->getModelViewProjectionMatrix();
QVector3D l0 = mvpMatrix->inverted() * mousePosClipSpace;
QMatrix4x4 *mvpMatrixInverted =
sceneView->getModelViewProjectionMatrixInverted();
QVector3D l0 = *mvpMatrixInverted * mousePosClipSpace;
// Compute l as the vector from l0 to the camera origin.
QVector3D cameraPosWorldSpace = sceneView->getCamera()->getOrigin();
......
......@@ -285,9 +285,10 @@ int MNWPVerticalSectionActor::checkIntersectionWithHandle(
float radiusBot = static_cast<float>(clipRadius * viewDirBot.length() / 100.0);
float radiusTop = static_cast<float>(clipRadius * viewDirTop.length() / 100.0);
QMatrix4x4 *mvpMatrix = sceneView->getModelViewProjectionMatrix();
QMatrix4x4 *mvpMatrixInverted =
sceneView->getModelViewProjectionMatrixInverted();
// Compute the world position of the current mouse position
QVector3D mouseWorldPos = mvpMatrix->inverted() * QVector3D(clipX, clipY, 1);
QVector3D mouseWorldPos = *mvpMatrixInverted * QVector3D(clipX, clipY, 1);
// Get the ray direction from the camera to the mouse position
QVector3D l = mouseWorldPos - cameraPos;
......@@ -316,7 +317,7 @@ int MNWPVerticalSectionActor::checkIntersectionWithHandle(
{
modifyWaypoint = i;
modifyWaypoint_worldZ = wpPositionBottom.z();
mvpMatrix = sceneView->getModelViewProjectionMatrix();
QMatrix4x4 *mvpMatrix = sceneView->getModelViewProjectionMatrix();
QVector3D posPoleClip = *mvpMatrix * wpPositionBottom;
offsetPickPositionToHandleCentre = QVector2D(posPoleClip.x() - clipX,
posPoleClip.y() - clipY);
......@@ -326,7 +327,7 @@ int MNWPVerticalSectionActor::checkIntersectionWithHandle(
{
modifyWaypoint = i;
modifyWaypoint_worldZ = wpPositionTop.z();
mvpMatrix = sceneView->getModelViewProjectionMatrix();
QMatrix4x4 *mvpMatrix = sceneView->getModelViewProjectionMatrix();
QVector3D posCentreClip = *mvpMatrix * wpPositionTop;
offsetPickPositionToHandleCentre = QVector2D(posCentreClip.x() - clipX,
posCentreClip.y() - clipY);
......@@ -362,8 +363,9 @@ void MNWPVerticalSectionActor::addPositionLabel(MSceneViewGLWidget *sceneView,
// http://en.wikipedia.org/wiki/Line-plane_intersection
// To compute l0, the MVP matrix has to be inverted.
QMatrix4x4 *mvpMatrix = sceneView->getModelViewProjectionMatrix();
QVector3D l0 = mvpMatrix->inverted() * mousePosClipSpace;
QMatrix4x4 *mvpMatrixInverted =
sceneView->getModelViewProjectionMatrixInverted();
QVector3D l0 = *mvpMatrixInverted * mousePosClipSpace;
// Compute l as the vector from l0 to the camera origin.
QVector3D cameraPosWorldSpace = sceneView->getCamera()->getOrigin();
......@@ -432,8 +434,9 @@ void MNWPVerticalSectionActor::dragEvent(MSceneViewGLWidget *sceneView,
// http://en.wikipedia.org/wiki/Line-plane_intersection
// To compute l0, the MVP matrix has to be inverted.
QMatrix4x4 *mvpMatrix = sceneView->getModelViewProjectionMatrix();
QVector3D l0 = mvpMatrix->inverted() * mousePosClipSpace;
QMatrix4x4 *mvpMatrixInverted =
sceneView->getModelViewProjectionMatrixInverted();
QVector3D l0 = *mvpMatrixInverted * mousePosClipSpace;
// Compute l as the vector from l0 to the camera origin.
QVector3D cameraPosWorldSpace = sceneView->getCamera()->getOrigin();
......
......@@ -698,7 +698,7 @@ QVector3D MSceneViewGLWidget::lonLatPToClipSpace(const QVector3D& lonlatp)
QVector3D MSceneViewGLWidget::clipSpaceToLonLatWorldZ(const QVector3D &clipPos)
{
QVector3D worldSpacePos = modelViewProjectionMatrix.inverted() * clipPos;
QVector3D worldSpacePos = modelViewProjectionMatrixInverted * clipPos;
return worldSpacePos;
}
......@@ -1677,6 +1677,7 @@ void MSceneViewGLWidget::paintGL()
}
modelViewProjectionMatrix *= camera.getViewMatrix();
modelViewProjectionMatrixInverted = modelViewProjectionMatrix.inverted();
QList<MLabel*> labelList;
labelList.append(staticLabels);
......@@ -1853,6 +1854,7 @@ void MSceneViewGLWidget::resizeGL(int width, int height)
}
modelViewProjectionMatrix *= camera.getViewMatrix();
modelViewProjectionMatrixInverted = modelViewProjectionMatrix.inverted();
}
......
......@@ -118,6 +118,12 @@ public:
QMatrix4x4* getModelViewProjectionMatrix()
{ return &modelViewProjectionMatrix; }
/**
Returns the current inverted model-view-projection matrix.
*/
QMatrix4x4* getModelViewProjectionMatrixInverted()
{ return &modelViewProjectionMatrixInverted; }
/**
Compute a world z-coordinate from a pressure value @p p_hPa (in hPa).
*/
......@@ -395,6 +401,7 @@ private:
MCamera camera;
QMatrix4x4 modelViewProjectionMatrix;
QMatrix4x4 modelViewProjectionMatrixInverted;
QMatrix4x4 sceneRotationMatrix;
SceneNavigationMode sceneNavigationMode;
QVector3D sceneRotationCentre;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment