|
@@ -90,30 +90,21 @@ class Camera implements Object3D {
|
|
|
return ret;
|
|
|
}
|
|
|
|
|
|
- getFocus(target: Vec3, radius: number, dir?: Vec3): Partial<Camera.Snapshot> {
|
|
|
+ getFocus(target: Vec3, radius: number): Partial<Camera.Snapshot> {
|
|
|
const fov = this.state.fov
|
|
|
const { width, height } = this.viewport
|
|
|
const aspect = width / height
|
|
|
const aspectFactor = (height < width ? 1 : aspect)
|
|
|
- const currentDistance = Vec3.distance(this.state.position, target)
|
|
|
const targetDistance = Math.abs((radius / aspectFactor) / Math.sin(fov / 2))
|
|
|
|
|
|
- const deltaDistance = Math.abs(currentDistance - targetDistance)
|
|
|
+ Vec3.setMagnitude(this.deltaDirection, this.state.direction, targetDistance)
|
|
|
+ Vec3.sub(this.newPosition, target, this.deltaDirection)
|
|
|
|
|
|
- if (dir) {
|
|
|
- Vec3.setMagnitude(this.deltaDirection, dir, targetDistance)
|
|
|
- Vec3.add(this.newPosition, target, this.deltaDirection)
|
|
|
- } else {
|
|
|
- Vec3.setMagnitude(this.deltaDirection, this.state.direction, deltaDistance)
|
|
|
- if (currentDistance < targetDistance) Vec3.negate(this.deltaDirection, this.deltaDirection)
|
|
|
- Vec3.add(this.newPosition, this.state.position, this.deltaDirection)
|
|
|
- }
|
|
|
-
|
|
|
- return { target, position: Vec3.clone(this.newPosition) };
|
|
|
+ return { target: Vec3.clone(target), position: Vec3.clone(this.newPosition) };
|
|
|
}
|
|
|
|
|
|
- focus(target: Vec3, radius: number, dir?: Vec3) {
|
|
|
- if (radius > 0) this.setState(this.getFocus(target, radius, dir));
|
|
|
+ focus(target: Vec3, radius: number) {
|
|
|
+ if (radius > 0) this.setState(this.getFocus(target, radius));
|
|
|
}
|
|
|
|
|
|
// lookAt(target: Vec3) {
|
|
@@ -202,7 +193,7 @@ namespace Camera {
|
|
|
mode: Mode,
|
|
|
|
|
|
position: Vec3,
|
|
|
- // Normalized camera direction
|
|
|
+ // Normalized camera direction, from Target to Position, for some reason?
|
|
|
direction: Vec3,
|
|
|
up: Vec3,
|
|
|
target: Vec3,
|