Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CameraTransition: Improve transition capabilities #932

Closed
gkjohnson opened this issue Jan 18, 2025 · 2 comments · Fixed by #944
Closed

CameraTransition: Improve transition capabilities #932

gkjohnson opened this issue Jan 18, 2025 · 2 comments · Fixed by #944
Milestone

Comments

@gkjohnson
Copy link
Contributor

  • Transitioning to Ortho: provide easy way to tilt camera up to top down, retaining the orientation
  • Transitioning to Persp: tilt camera down from ortho view if it's not already tilted down too far
  • Afford transition while dragging the camera
    • ie rotating the camera from ortho auto-transitions to perspective
@gkjohnson gkjohnson modified the milestones: v0.4.3, v0.4.4 Jan 18, 2025
@gkjohnson
Copy link
Contributor Author

When calculating the top down orientation of the ortho camera, ensure the same screen space position of the pivot point. Though calculating the top-orientation of the offset position in that case is not necessarily trivial. Requiring a centered position is easiest.

@gkjohnson
Copy link
Contributor Author

gkjohnson commented Jan 23, 2025

if ( ! manager.animating ) {

	// Force the fixed point to be in the camera center
	raycaster.ray.direction.set( 0, 0, - 1 ).transformDirection( manager.camera.matrixWorld );
	raycaster.ray.origin.setFromMatrixPosition( manager.camera.matrixWorld );
	const hit = raycaster.intersectObject( scene )[ 0 ];
	if ( hit ) {

		manager.fixedPoint.copy( hit.point );
		manager.syncCameras();

	} else {

		controls.getPivotPoint( manager.fixedPoint );
		manager.syncCameras();

	}

	if ( targetCamera.isOrthographicCamera ) {

		targetCamera.updateMatrixWorld();
		downVector.set( 0, - 1, 0 );	

		// transition the camera view to the top down while retaining same general pointing direction
		const angle = downVector.angleTo( raycaster.ray.direction );
		axis.crossVectors( downVector, raycaster.ray.direction );
		quat.setFromAxisAngle( axis, - angle ).normalize()	;

		makeRotateAroundPoint( manager.fixedPoint, quat, matrix );
		targetCamera.matrixWorld.premultiply( matrix );
		targetCamera.matrixWorld.decompose(
			targetCamera.position,
			targetCamera.quaternion,
			targetCamera.scale,
		);

	} else {

		targetCamera.updateMatrixWorld();
		downVector.set( 0, - 1, 0 );	

		// tilt the perspective down slightly
		let angle = downVector.angleTo( raycaster.ray.direction );
		angle = Math.max( 65 * MathUtils.DEG2RAD - angle, 0 );

		axis.set( 1, 0, 0 ).transformDirection( targetCamera.matrixWorld );
		quat.setFromAxisAngle( axis, angle ).normalize()	;

		makeRotateAroundPoint( manager.fixedPoint, quat, matrix );
		targetCamera.matrixWorld.premultiply( matrix );
		targetCamera.matrixWorld.decompose(
			targetCamera.position,
			targetCamera.quaternion,
			targetCamera.scale,
		);

	}

}

controls.adjustCamera( manager.perspectiveCamera );
controls.adjustCamera( manager.orthographicCamera );

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant