Fixed zoom-dependent rotation

This commit is contained in:
leca 2023-12-01 14:42:42 +03:00
parent 07ef091ae1
commit f2f5a26729
1 changed files with 2 additions and 3 deletions

5
view/controls.js vendored
View File

@ -1,16 +1,15 @@
import { Euler, MathUtils, Quaternion, Vector3 } from "three"; import { Euler, MathUtils, Quaternion, Vector3 } from "three";
import { getDistance, setDistance, getCameraPosition, setCameraPostion, rotateCamera, getCanvasSize, getCameraRotation, getCameraQuaternion } from "./graphics.js"; import { getDistance, setDistance, getCameraPosition, setCameraPostion, rotateCamera, getCanvasSize, getCameraRotation, getCameraQuaternion } from "./graphics.js";
let r = 5
let isMousePressed = false let isMousePressed = false
let angle = 0; let angle = 0;
const updateCameraPosition = (horizontal, vertical) => { const updateCameraPosition = (horizontal, vertical) => {
let ratio = 2 * Math.PI * r / getCanvasSize().width; let ratio = 4 * Math.PI / getCanvasSize().width;
let distance = getDistance(); let distance = getDistance();
let alpha = (360 * (horizontal * ratio / (2 * Math.PI * distance))) ; let alpha = (360 * (horizontal * ratio / (2 * Math.PI))) ;
let betta = MathUtils.degToRad(angle); let betta = MathUtils.degToRad(angle);
let x = Math.cos(betta) * distance; let x = Math.cos(betta) * distance;
let z = Math.sin(betta) * distance; let z = Math.sin(betta) * distance;