mirror of
https://github.com/guezoloic/website.git
synced 2026-03-31 03:01:37 +00:00
feat: rework entire project structure
This commit is contained in:
34
app/three/camera.ts
Normal file
34
app/three/camera.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
import * as THREE from "three";
|
||||
|
||||
export default class Camera {
|
||||
private camera: THREE.PerspectiveCamera;
|
||||
|
||||
private box = new THREE.Box3();
|
||||
private size = new THREE.Vector3();
|
||||
private center = new THREE.Vector3();
|
||||
|
||||
constructor(camera: THREE.PerspectiveCamera, model: THREE.Object3D) {
|
||||
this.camera = camera;
|
||||
this.box = this.box.setFromObject(model);
|
||||
}
|
||||
|
||||
public centerCamera(
|
||||
mouvement: (box: THREE.Box3, size: THREE.Vector3, center: THREE.Vector3) => void
|
||||
) {
|
||||
this.box.getSize(this.size);
|
||||
this.box.getCenter(this.center);
|
||||
|
||||
mouvement(this.box, this.size, this.center);
|
||||
}
|
||||
|
||||
public positionCamera() {
|
||||
const fov = this.camera.fov * (Math.PI / 180);
|
||||
const distance = this.size.y / (2 * Math.tan(fov / 2));
|
||||
this.camera.position.set(0, 0, distance * 1.2);
|
||||
this.camera.lookAt(0, 0, 0);
|
||||
}
|
||||
|
||||
public getCamera(): THREE.PerspectiveCamera {
|
||||
return this.camera;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user