import { ArcRotateCamera } from '@babylonjs/core/Cameras/arcRotateCamera';
import { Vector3 } from '@babylonjs/core/Maths/math.vector';
import { Tools } from '@babylonjs/core/Misc/tools';
import { Monobehiver } from '../base/Monobehiver';
import { AppConfig } from './AppConfig';

/**
 * 相机控制类- 负责创建和控制弧形旋转相机
 */
export class AppCamera extends Monobehiver {
    object: ArcRotateCamera | null;

    constructor(mainApp: any) {
        super(mainApp);
        this.object = null;
    }

    /** 初始化相机 */
    Awake(): void {
        const scene = this.mainApp.appScene.object;
        const canvas = AppConfig.container;
        if (!scene || !canvas) return;

        // 创建弧形旋转相机：水平角70度，垂直角80度，距离5，目标点(0,1,0)
        this.object = new ArcRotateCamera('Camera', Tools.ToRadians(70), Tools.ToRadians(80), 5, new Vector3(0, 0, 0), scene);
        this.object.attachControl(canvas, true);
        this.object.minZ = 0.01;           // 近裁剪面
        this.object.wheelPrecision =999999;    // 滚轮缩放精度
        this.object.panningSensibility = 0;
         this.object.position = new Vector3(-0, 0, 100);
        this.setTarget(0, 2, 0);
    }

    /** 设置相机目标点 */
    setTarget(x: number, y: number, z: number): void {
        if (this.object) {
            this.object.target = new Vector3(x, y, z);
        }
    }



    /** 重置相机到默认位置 */
    reset(): void {
        if (!this.object) return;
        this.object.radius = 2; this.setTarget(0, 0, 0);
        this.object.position = new Vector3(0, 1.5, 2);
    }

    update(): void { 
        
    }
}
