pex-gl / pex-cam

Cameras models and controllers for 3D rendering in PEX.
MIT License
2 stars 3 forks source link

Dragging orbiter fast rotates backwards #21

Open vorg opened 5 years ago

vorg commented 5 years ago

Dragging orbiter fast e.g. from right to left makes camera jump backwards before continuing rotation CW.

vorg commented 5 years ago

I think i nailed it! Blue click arrow is (target) longitude and dark blue arrow is current latitude. Yellow is slerp angle. See when yellow is > 180deg slerp chooses shortest (red) path instead which is incorrect and the green position arc starts to zig zag backwards… so the problem is slerp but triggered by easing drag.

screenshot 2019-02-14 at 10 37 06 copy

Possible solutions:

dmnsgn commented 5 years ago
  • get rid of quaternions and switch to only lat/lon (downsides = ?)

We'll still have the same problem of lerping to the closest target

  • replace easing with inertia (1:1 tracking while dragging + "slide" on mouse up)

Probably the best alternative to lerping

  • limit delta longitude to < 180deg

We'll need to track the dragging direction then

  • limit dx (acceleration)

Will need to be relative to the currentLon and lon properties somehow

vorg commented 5 years ago

I’ve just realised that current code doesn’t use quaternions. Wouldn’t the fix be then to extend interpolateAngle with direction?

interpolateAngle( (toRadians(this.currentLon) + 2 Math.PI) % (2 Math.PI), (toRadians(this.lon) + 2 Math.PI) % (2 Math.PI), this.easing, dx //positive for cw? )

dmnsgn commented 5 years ago

What if a sudden change in direction happen and the difference is > 180?