summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZolnai Tamás <tamas.zolnai@collabora.com>2014-07-03 16:26:44 +0200
committerZolnai Tamás <tamas.zolnai@collabora.com>2014-07-03 16:28:20 +0200
commit9a670eb493f3760eb398c3f9d2296d979b608f95 (patch)
treef61c645d4913a24493f988afd53f8407e46560d0
parent0b3a918860944878b5fc4cf87883889bc467a052 (diff)
glTF: constraine camera move in orbit mode
Not to get too close to / too far from the model. Too close means move into the model. Change-Id: Ie25d87c88093d4baaf98f13ab8239263b5e1bf66
-rw-r--r--avmedia/source/opengl/oglwindow.cxx17
-rw-r--r--avmedia/source/opengl/oglwindow.hxx2
2 files changed, 19 insertions, 0 deletions
diff --git a/avmedia/source/opengl/oglwindow.cxx b/avmedia/source/opengl/oglwindow.cxx
index f45468e3981c..b3b177782950 100644
--- a/avmedia/source/opengl/oglwindow.cxx
+++ b/avmedia/source/opengl/oglwindow.cxx
@@ -21,6 +21,7 @@ OGLWindow::OGLWindow( glTFHandle& rHandle, OpenGLContext& rContext, Window& rEve
, m_bVisible ( false )
, m_aLastMousePos(Point())
, m_bIsOrbitMode( false )
+ , m_fCameraDistance(0.0)
{
}
@@ -261,6 +262,16 @@ IMPL_LINK(OGLWindow, CameraHandler, VclWindowEvent*, pEvent)
if(nCode == KEY_A)vMoveBy -= vStrafe*(0.0005f*fModelSize);
if(nCode == KEY_D)vMoveBy += vStrafe*(0.0005f*fModelSize);
}
+ else
+ {
+ // Limit zooming in orbit mode
+ m_fCameraDistance += vMoveBy.z;
+ if (m_fCameraDistance < 0.75 * fModelSize || m_fCameraDistance > 2 * fModelSize)
+ {
+ m_fCameraDistance -= vMoveBy.z;
+ vMoveBy = glm::vec3(0.0);
+ }
+ }
}
gltf_renderer_move_camera(&m_rHandle, vMoveBy.x, vMoveBy.y, vMoveBy.z, 0.0);
}
@@ -275,6 +286,12 @@ IMPL_LINK(OGLWindow, CameraHandler, VclWindowEvent*, pEvent)
{
gltf_orbit_mode_start(&m_rHandle);
m_bIsOrbitMode = true;
+ // Set default camera distance
+ glm::vec3 vEye;
+ glm::vec3 vView;
+ glm::vec3 vUp;
+ gltf_get_camera_pos(&m_rHandle, &vEye,&vView,&vUp);
+ m_fCameraDistance = vEye.z - gltf_get_model_center_pos(&m_rHandle)->z;
}
}
else if(nCode == KEY_F)
diff --git a/avmedia/source/opengl/oglwindow.hxx b/avmedia/source/opengl/oglwindow.hxx
index b4b1390b67ae..68b1ed8b84ad 100644
--- a/avmedia/source/opengl/oglwindow.hxx
+++ b/avmedia/source/opengl/oglwindow.hxx
@@ -68,9 +68,11 @@ private:
glTFHandle& m_rHandle;
OpenGLContext& m_rContext;
Window& m_rEventHandler;
+
bool m_bVisible;
Point m_aLastMousePos;
bool m_bIsOrbitMode;
+ double m_fCameraDistance;
};
} // namespace ogl