I understand that OrbitControls.js
has a damping feature, which adds a smooth dragging of panorama, also known as easing. I am looking to achieve the same functionality without relying on this library. This is because I want to streamline my code and have more precise control over mouse or tap events.
I have created a Plunker to demonstrate the initial project I use for my panorama view.
https://plnkr.co/edit/eX2dwgbrfNoX9RwWaPaH?p=preview
In this demo, mouse coordinates are converted to latitude/longitude to adjust the camera position. It's a basic example showcasing a minimal panorama from the three.js site.
While experimenting with damping in OrbitControls.js
(view this line), I couldn't quite replicate the same smooth behavior - the interaction caused the panorama to jump:
if ( scope.enableDamping === true ) {
sphericalDelta.theta *= ( 1 - scope.dampingFactor );
sphericalDelta.phi *= ( 1 - scope.dampingFactor );
panOffset.multiplyScalar( 1 - scope.dampingFactor );
}
I'm struggling to apply this damping effect to my Plunker example.
Can someone provide guidance on how to implement damping
in my Plunker project?
Update:
I made some progress by introducing new delta values for longitude and latitude: refer to latDelta
and lonDelta
in the updated Plunker. I now have a better grasp of how it works in OrbitControls.js
. You can notice a smooth scroll on page load due to lonDelta = 0.35
. However, I'm unsure about adjusting this during user mouse scrolling. Nonetheless, I feel like I'm heading in the right direction.