Skip to content

Commit

Permalink
Adds touch pan
Browse files Browse the repository at this point in the history
  • Loading branch information
guillaumeblanc committed Sep 23, 2023
1 parent e43c1aa commit ace4710
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/impl/orbit_camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,15 @@ bool OrbitCamera::Event(const sapp_event& _event) {
const auto v0 = HMM_Vec2{touch0.pos_x, touch0.pos_y};
const auto v1 = HMM_Vec2{touch1.pos_x, touch1.pos_y};

const auto& prev_v0 = last_touches_[touch0.identifier];
const auto& prev_v1 = last_touches_[touch1.identifier];
const auto& pv0 = last_touches_[touch0.identifier];
const auto& pv1 = last_touches_[touch1.identifier];

const float length0 = HMM_LenV2(v1 - v0);
const float length1 = HMM_LenV2(prev_v1 - prev_v0);
Zoom((HMM_LenV2(pv1 - pv0) - HMM_LenV2(v1 - v0)) * kZoomTouchFactor);

Zoom((length1 - length0) * kZoomTouchFactor);
const auto m = (v1 + v0) / 2;
const auto pm = (pv1 + pv0) / 2;
const auto dm = (m - pm) * kPanTouchFactor;
Pan(dm.X, dm.Y);
}

// Updates all touch coords
Expand Down
1 change: 1 addition & 0 deletions src/impl/orbit_camera.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class OrbitCamera : public Camera {
const float kOrbitFactor = .01f;
const float kOrbitTouchFactor = .3f;
const float kPanFactor = .002f;
const float kPanTouchFactor = .002f;
const float kMoveFactor = .002f;
const float kZoomFactor = .5f;
const float kZoomTouchFactor = .02f;
Expand Down

0 comments on commit ace4710

Please sign in to comment.