limit camera zoom
This commit is contained in:
@@ -138,7 +138,9 @@ public:
|
||||
Sampler m_sampler_mix;
|
||||
glm::mat4 m_cam_rot = glm::mat4(1);
|
||||
glm::vec3 m_cam_pos{ 0 };
|
||||
float m_cam_fov = 85;
|
||||
float m_cam_fov = 85.f;
|
||||
const float m_cam_fov_min = 5.f;
|
||||
const float m_cam_fov_max = 150.f;
|
||||
glm::vec2 m_cur_pos;
|
||||
|
||||
std::shared_ptr<Brush> m_current_brush;
|
||||
|
||||
@@ -49,7 +49,8 @@ void CanvasModeBasicCamera::on_MouseEvent(MouseEvent* me, glm::vec2& loc)
|
||||
{
|
||||
if (m_zooming)
|
||||
{
|
||||
Canvas::I->m_cam_fov = m_fov_start - (me->m_pos.x - m_dragR_start.x) * 0.05f;
|
||||
Canvas::I->m_cam_fov = glm::clamp(m_fov_start - (me->m_pos.x - m_dragR_start.x) * 0.05f,
|
||||
Canvas::I->m_cam_fov_min, Canvas::I->m_cam_fov_max);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -62,7 +63,8 @@ void CanvasModeBasicCamera::on_MouseEvent(MouseEvent* me, glm::vec2& loc)
|
||||
break;
|
||||
case kEventType::MouseScroll:
|
||||
m_zoom_canvas += me->m_scroll_delta * 0.1f;
|
||||
Canvas::I->m_cam_fov -= me->m_scroll_delta * 2.0f;
|
||||
Canvas::I->m_cam_fov = glm::clamp(Canvas::I->m_cam_fov - me->m_scroll_delta * 2.0f,
|
||||
Canvas::I->m_cam_fov_min, Canvas::I->m_cam_fov_max);
|
||||
App::I->brush_update();
|
||||
break;
|
||||
case kEventType::MouseCancel:
|
||||
@@ -86,7 +88,8 @@ void CanvasModeBasicCamera::on_GestureEvent(GestureEvent* ge)
|
||||
case kEventType::GestureMove:
|
||||
{
|
||||
Canvas::I->m_pan = m_pan_start + ge->m_pos_delta * glm::vec2(-1, -1) * 0.3f * (Canvas::I->m_cam_fov / 85.f);
|
||||
Canvas::I->m_cam_fov = m_camera_fov - ge->m_distance_delta * .05f;
|
||||
Canvas::I->m_cam_fov = glm::clamp(m_camera_fov - ge->m_distance_delta * .05f,
|
||||
Canvas::I->m_cam_fov_min, Canvas::I->m_cam_fov_max);
|
||||
auto angle = Canvas::I->m_pan * 0.003f;
|
||||
Canvas::I->m_cam_rot = glm::eulerAngleXY(angle.y, angle.x);
|
||||
App::I->brush_update();
|
||||
|
||||
Reference in New Issue
Block a user