I really like the way look-around.js in this project works to rotate the camera:
https://playcanvas.com/project/434444/overview/webxr-360-video
I’m currently working on implementing it as a first person camera controller in a click and drag/hotspot to move scene.
I’ve modified the script to only set the localEulerAngles of the camera when the scene is not in the process of tweening the camera and it’s parent around:
LbLookAround.prototype.update = function (dt) {
// Update the camera's orientation
this.ex = pc.math.lerp(this.ex, this.targetEx, dt / 0.2);
this.ey = pc.math.lerp(this.ey, this.targetEy, dt / 0.2);
if (! this.app.xr.active && !this.relocating) {
this.entity.setLocalEulerAngles(this.ex, this.ey, 0);
// console.log(this.entity.getLocalEulerAngles());
}
};
At the end of my tween, I fire an event that resets this.ex
and this.ey
along with their respective targets, which means the user can pickup where the tween left off and continue looking around:
LbLookAround.prototype.onMoveComplete = function() {
var quat = this.entity.getLocalRotation();
this.ex = this.getPitch(quat) * pc.math.RAD_TO_DEG;
this.ey = this.getYaw(quat) * pc.math.RAD_TO_DEG;
this.targetEx = this.ex;
this.targetEy = this.ey;
this.relocating = false;
};
This mostly works. As long as x and z are both either 0 or 180, the tween ends and and the user can look around as expected. The problem I run into is if I deviate from this, the camera snaps away from the intended position after the tween ends.
I know that look-around.js is setting z rotation to 0 in the update function, and console.logging ex and ey and using those values as tween targets to keep z at zero does not seem to be solving the problem either. It still snaps after the tween ends to a completely parallel to the ground position.
Any insights would be greatly appreciated.
Thank you!