Thank you guys, I faced the following problem,
When I rotate the object the camera view(or the object) will rebound If set the Intertia Factor. The larger Intertia Factor,the stronger the rebound.
Thank you guys, I faced the following problem,
When I rotate the object the camera view(or the object) will rebound If set the Intertia Factor. The larger Intertia Factor,the stronger the rebound.
It is because of the way yaw
is calculated when you rotate the camera:
// Property to get and set the yaw of the camera around the pivot point (degrees)
Object.defineProperty(OrbitCamera.prototype, "yaw", {
...
set: function (value) {
...
var diff = this._targetYaw - this._yaw;
var reminder = diff % 360;
if (reminder > 180) {
this._targetYaw = this._yaw - (360 - reminder);
} else if (reminder < -180) {
this._targetYaw = this._yaw + (360 + reminder);
} else {
this._targetYaw = this._yaw + reminder;
}
}
});
If you rotate fast enough, with inertia factor, your target yaw will be much larger than current yaw. For example, if current yaw angle is at zero and you swipe really fast, so that the target yaw goes over 180 degrees, say 185, then it will substract 180 from current yaw and the target yaw on the next frame will become -175 instead. That flip is causing the camera to “bounce” in opposite direction.
Well, as a workaround, you could clamp the remainder, so it never leaves [-180, 180] range. The downside is that it will limit the maximum speed you can turn the camera. Something like this:
// change
var reminder = diff % 360;
// to
var reminder = pc.math.clamp(diff % 360, -180, 180);
If you don’t want to limit the max speed, you would need to figure out the math, so that it doesn’t jump from +180 to -180 when it is over 180 degrees.
Thank you very much!