cam update should move target too (#1674)
This commit is contained in:
@ -731,6 +731,7 @@ export class CameraControls {
|
|||||||
|
|
||||||
async tweenCameraToQuaternion(
|
async tweenCameraToQuaternion(
|
||||||
targetQuaternion: Quaternion,
|
targetQuaternion: Quaternion,
|
||||||
|
targetPosition = new Vector3(),
|
||||||
duration = 500,
|
duration = 500,
|
||||||
toOrthographic = true
|
toOrthographic = true
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
@ -750,12 +751,14 @@ export class CameraControls {
|
|||||||
}
|
}
|
||||||
await this._tweenCameraToQuaternion(
|
await this._tweenCameraToQuaternion(
|
||||||
targetQuaternion,
|
targetQuaternion,
|
||||||
|
targetPosition,
|
||||||
remainingDuration,
|
remainingDuration,
|
||||||
toOrthographic
|
toOrthographic
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
_tweenCameraToQuaternion(
|
_tweenCameraToQuaternion(
|
||||||
targetQuaternion: Quaternion,
|
targetQuaternion: Quaternion,
|
||||||
|
targetPosition: Vector3,
|
||||||
duration = 500,
|
duration = 500,
|
||||||
toOrthographic = false
|
toOrthographic = false
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
@ -763,10 +766,11 @@ export class CameraControls {
|
|||||||
const camera = this.camera
|
const camera = this.camera
|
||||||
this._isCamMovingCallback(true, true)
|
this._isCamMovingCallback(true, true)
|
||||||
const initialQuaternion = camera.quaternion.clone()
|
const initialQuaternion = camera.quaternion.clone()
|
||||||
|
const initialTarget = this.target.clone()
|
||||||
const isVertical = isQuaternionVertical(targetQuaternion)
|
const isVertical = isQuaternionVertical(targetQuaternion)
|
||||||
let tweenEnd = isVertical ? 0.99 : 1
|
let tweenEnd = isVertical ? 0.99 : 1
|
||||||
const controlsTarget = this.target.clone()
|
const tempVec = new Vector3()
|
||||||
const initialDistance = controlsTarget.distanceTo(camera.position.clone())
|
const initialDistance = initialTarget.distanceTo(camera.position.clone())
|
||||||
|
|
||||||
const cameraAtTime = (animationProgress: number /* 0 - 1 */) => {
|
const cameraAtTime = (animationProgress: number /* 0 - 1 */) => {
|
||||||
const currentQ = tempQuaternion.slerpQuaternions(
|
const currentQ = tempQuaternion.slerpQuaternions(
|
||||||
@ -774,6 +778,11 @@ export class CameraControls {
|
|||||||
targetQuaternion,
|
targetQuaternion,
|
||||||
animationProgress
|
animationProgress
|
||||||
)
|
)
|
||||||
|
const currentTarget = tempVec.lerpVectors(
|
||||||
|
initialTarget,
|
||||||
|
targetPosition,
|
||||||
|
animationProgress
|
||||||
|
)
|
||||||
if (this.camera instanceof PerspectiveCamera)
|
if (this.camera instanceof PerspectiveCamera)
|
||||||
// changing the camera position back when it's orthographic doesn't do anything
|
// changing the camera position back when it's orthographic doesn't do anything
|
||||||
// and it messes up animating back to perspective later
|
// and it messes up animating back to perspective later
|
||||||
@ -781,12 +790,11 @@ export class CameraControls {
|
|||||||
.set(0, 0, 1)
|
.set(0, 0, 1)
|
||||||
.applyQuaternion(currentQ)
|
.applyQuaternion(currentQ)
|
||||||
.multiplyScalar(initialDistance)
|
.multiplyScalar(initialDistance)
|
||||||
.add(controlsTarget)
|
.add(currentTarget)
|
||||||
|
|
||||||
this.camera.up.set(0, 1, 0).applyQuaternion(currentQ).normalize()
|
this.camera.up.set(0, 1, 0).applyQuaternion(currentQ).normalize()
|
||||||
this.camera.quaternion.copy(currentQ)
|
this.camera.quaternion.copy(currentQ)
|
||||||
this.target.copy(controlsTarget)
|
this.target.copy(currentTarget)
|
||||||
// this.controls.update()
|
|
||||||
this.camera.updateProjectionMatrix()
|
this.camera.updateProjectionMatrix()
|
||||||
this.update()
|
this.update()
|
||||||
this.onCameraChange()
|
this.onCameraChange()
|
||||||
|
Reference in New Issue
Block a user