1
0
mirror of https://github.com/misskey-dev/misskey.git synced 2026-05-23 05:14:13 +02:00
This commit is contained in:
syuilo
2026-04-26 17:08:51 +09:00
parent a77987ab28
commit 17697ba6ec
5 changed files with 276 additions and 36 deletions

View File

@@ -607,3 +607,52 @@ export function getRgb(hex: string | number): [number, number, number] | null {
if (m == null) return [0, 0, 0];
return m.map(x => parseInt(x, 16) / 255) as [number, number, number];
}
export class FreeCameraTouchVirtualJoystickInput implements BABYLON.ICameraInput<BABYLON.FreeCamera> {
public camera: BABYLON.FreeCamera;
private joystickMoveSensitivity: number;
private joystickRotationSensitivity: number;
private joystickMoveVector = BABYLON.Vector3.Zero();
private joystickRotationVecX = 0;
private joystickRotationVecY = 0;
constructor(options: {
moveSensitivity?: number;
rotationSensitivity?: number;
}) {
this.joystickMoveSensitivity = options.moveSensitivity ?? 0.01;
this.joystickRotationSensitivity = options.rotationSensitivity ?? 0.01;
}
getClassName = () => this.constructor.name;
getSimpleName = () => 'joystick';
attachControl(noPreventDefault) {
}
detachControl() {
}
public setJoystickMoveVector(vec: { x: number; y: number }) {
this.joystickMoveVector = new BABYLON.Vector3(vec.x, 0, -vec.y).scale(this.joystickMoveSensitivity);
}
public setJoystickRotationVector(vec: { x: number; y: number }) {
let directionAdjust = 1;
if (this.camera.getScene().useRightHandedSystem) directionAdjust *= -1;
if (this.camera.parent && this.camera.parent._getWorldMatrixDeterminant() < 0) directionAdjust *= -1;
this.joystickRotationVecX = vec.y * this.joystickRotationSensitivity * this.joystickRotationSensitivity;
this.joystickRotationVecY = vec.x * this.joystickRotationSensitivity * directionAdjust * this.joystickRotationSensitivity;
}
checkInputs() {
this.camera.cameraRotation.y += this.joystickRotationVecY;
this.camera.cameraRotation.x += this.joystickRotationVecX;
this.camera.cameraDirection.addInPlace(
BABYLON.Vector3.TransformCoordinates(this.joystickMoveVector, BABYLON.Matrix.RotationY(this.camera.rotation.y)),
);
}
}