Skip to content
Snippets Groups Projects
Commit 3e6066a1 authored by Alexander Rose's avatar Alexander Rose
Browse files

add .getCenter and .center to Camera

parent b61e5c76
Branches
No related tags found
No related merge requests found
...@@ -24,6 +24,7 @@ Note that since we don't clearly distinguish between a public and private interf ...@@ -24,6 +24,7 @@ Note that since we don't clearly distinguish between a public and private interf
- Add StructureElement.Loci.forEachLocation - Add StructureElement.Loci.forEachLocation
- Add RepresentationRegistry.clear and ThemeRegistry.clear - Add RepresentationRegistry.clear and ThemeRegistry.clear
- Add generic Loci support for overpaint, substance, clipping themes - Add generic Loci support for overpaint, substance, clipping themes
- Add `.getCenter` and `.center` to `Camera`
## [v3.28.0] - 2022-12-20 ## [v3.28.0] - 2022-12-20
......
/** /**
* Copyright (c) 2018-2022 mol* contributors, licensed under MIT, See LICENSE file for more info. * Copyright (c) 2018-2023 mol* contributors, licensed under MIT, See LICENSE file for more info.
* *
* @author David Sehnal <david.sehnal@gmail.com> * @author David Sehnal <david.sehnal@gmail.com>
* @author Alexander Rose <alexander.rose@weirdbyte.de> * @author Alexander Rose <alexander.rose@weirdbyte.de>
...@@ -137,6 +137,18 @@ class Camera implements ICamera { ...@@ -137,6 +137,18 @@ class Camera implements ICamera {
return state; return state;
} }
getCenter(target: Vec3, radius?: number): Partial<Camera.Snapshot> {
Vec3.sub(this.deltaDirection, this.target, this.position);
Vec3.sub(this.newPosition, target, this.deltaDirection);
const state = Camera.copySnapshot(Camera.createDefaultSnapshot(), this.state);
state.target = Vec3.clone(target);
state.position = Vec3.clone(this.newPosition);
if (radius) state.radius = Math.max(radius, 0.01);
return state;
}
getInvariantFocus(target: Vec3, radius: number, up: Vec3, dir: Vec3): Partial<Camera.Snapshot> { getInvariantFocus(target: Vec3, radius: number, up: Vec3, dir: Vec3): Partial<Camera.Snapshot> {
const r = Math.max(radius, 0.01); const r = Math.max(radius, 0.01);
const targetDistance = this.getTargetDistance(r); const targetDistance = this.getTargetDistance(r);
...@@ -160,6 +172,10 @@ class Camera implements ICamera { ...@@ -160,6 +172,10 @@ class Camera implements ICamera {
} }
} }
center(target: Vec3, durationMs?: number) {
this.setState(this.getCenter(target), durationMs);
}
/** Transform point into 2D window coordinates. */ /** Transform point into 2D window coordinates. */
project(out: Vec4, point: Vec3) { project(out: Vec4, point: Vec3) {
return cameraProject(out, point, this.viewport, this.projectionView); return cameraProject(out, point, this.viewport, this.projectionView);
......
/** /**
* Copyright (c) 2019-2020 mol* contributors, licensed under MIT, See LICENSE file for more info. * Copyright (c) 2019-2023 mol* contributors, licensed under MIT, See LICENSE file for more info.
* *
* @author David Sehnal <david.sehnal@gmail.com> * @author David Sehnal <david.sehnal@gmail.com>
* @author Alexander Rose <alexander.rose@weirdbyte.de> * @author Alexander Rose <alexander.rose@weirdbyte.de>
...@@ -18,7 +18,7 @@ import { StructureElement } from '../../mol-model/structure'; ...@@ -18,7 +18,7 @@ import { StructureElement } from '../../mol-model/structure';
const DefaultCameraFocusOptions = { const DefaultCameraFocusOptions = {
minRadius: 5, minRadius: 5,
extraRadius: 4, extraRadius: 4,
durationMs: 250 durationMs: 250,
}; };
export type CameraFocusOptions = typeof DefaultCameraFocusOptions export type CameraFocusOptions = typeof DefaultCameraFocusOptions
...@@ -107,19 +107,19 @@ export class CameraManager { ...@@ -107,19 +107,19 @@ export class CameraManager {
} }
focusSphere(sphere: Sphere3D, options?: Partial<CameraFocusOptions> & { principalAxes?: PrincipalAxes }) { focusSphere(sphere: Sphere3D, options?: Partial<CameraFocusOptions> & { principalAxes?: PrincipalAxes }) {
const { canvas3d } = this.plugin;
if (!canvas3d) return;
const { extraRadius, minRadius, durationMs } = { ...DefaultCameraFocusOptions, ...options }; const { extraRadius, minRadius, durationMs } = { ...DefaultCameraFocusOptions, ...options };
const radius = Math.max(sphere.radius + extraRadius, minRadius); const radius = Math.max(sphere.radius + extraRadius, minRadius);
if (options?.principalAxes) { if (options?.principalAxes) {
const { origin, dirA, dirC } = options?.principalAxes.boxAxes; const { origin, dirA, dirC } = options?.principalAxes.boxAxes;
const snapshot = this.plugin.canvas3d?.camera.getFocus(origin, radius, dirA, dirC); const snapshot = canvas3d.camera.getFocus(origin, radius, dirA, dirC);
this.plugin.canvas3d?.requestCameraReset({ durationMs, snapshot }); canvas3d.requestCameraReset({ durationMs, snapshot });
// this.plugin.canvas3d?.camera.focus(origin, radius, durationMs, dirA, dirC);
} else { } else {
const snapshot = this.plugin.canvas3d?.camera.getFocus(sphere.center, radius); const snapshot = canvas3d.camera.getFocus(sphere.center, radius);
this.plugin.canvas3d?.requestCameraReset({ durationMs, snapshot }); canvas3d.requestCameraReset({ durationMs, snapshot });
// this.plugin.canvas3d?.camera.focus(sphere.center, radius, durationMs);
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment