-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
This reverts commit 89bd8bb
- Loading branch information
Showing
8 changed files
with
13 additions
and
129 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 0 additions & 32 deletions
32
visualization/app/codeCharta/ui/codeMap/threeViewer/threeCamera.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,21 @@ | ||
import { Injectable } from "@angular/core" | ||
import { PerspectiveCamera, Vector3 } from "three" | ||
import { EventEmitter } from "../../../util/EventEmitter" | ||
|
||
type CameraChangeEvents = { | ||
onCameraZoomChanged: (data: { camera: PerspectiveCamera }) => void | ||
} | ||
|
||
@Injectable({ providedIn: "root" }) | ||
export class ThreeCameraService { | ||
static VIEW_ANGLE = 45 | ||
static NEAR = 50 | ||
static FAR = 200_000 //TODO optimize renderer for far objects | ||
static readonly MAX_ZOOM_Factor = 50 | ||
static readonly MIN_ZOOM_Factor = 0.1 | ||
static readonly ZOOM_STEP = 0.25 | ||
private eventEmitter = new EventEmitter<CameraChangeEvents>() | ||
camera: PerspectiveCamera | ||
zoomFactor: number | ||
|
||
init(containerWidth: number, containerHeight: number) { | ||
const aspect = containerWidth / containerHeight | ||
this.camera = new PerspectiveCamera(ThreeCameraService.VIEW_ANGLE, aspect, ThreeCameraService.NEAR, ThreeCameraService.FAR) | ||
this.setPosition(new Vector3(0, 300, 1000)) | ||
this.zoomFactor = this.camera.zoom | ||
} | ||
|
||
setPosition(position: Vector3) { | ||
this.camera.position.set(position.x, position.y, position.z) | ||
this.camera.lookAt(0, 0, 0) | ||
} | ||
|
||
setZoomFactor(zoomFactor: number) { | ||
this.camera.zoom = zoomFactor | ||
this.zoomFactor = zoomFactor | ||
this.eventEmitter.emit("onCameraZoomChanged", { camera: this.camera }) | ||
this.camera.updateProjectionMatrix() | ||
} | ||
|
||
zoomIn() { | ||
this.setZoomFactor(Math.min(this.zoomFactor + ThreeCameraService.ZOOM_STEP, ThreeCameraService.MAX_ZOOM_Factor)) | ||
} | ||
|
||
zoomOut() { | ||
this.setZoomFactor(Math.max(this.zoomFactor - ThreeCameraService.ZOOM_STEP, ThreeCameraService.MIN_ZOOM_Factor)) | ||
} | ||
|
||
subscribe<Key extends keyof CameraChangeEvents>(key: Key, callback: CameraChangeEvents[Key]) { | ||
this.eventEmitter.on(key, data => { | ||
callback(data) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters