export class FollowNumber {
    private m_t: number = 0;
    public target: number = 0;
    public follow: number = 0;
    private m_tiny: number = 0;
    constructor(t: number, from: number = 0, to: number = 0, tiny: number = 0) {
        this.m_t = t;
        this.target = to;
        this.follow = from;
        this.m_tiny = tiny;
    }
    //this.m_goldFollow = new FollowNumber(0.1, 0, 0, 0.1);
    public ChangeT(value: number): void {
        this.m_t = value;
    }
    public get t(): number { return this.m_t; }
    public update(): void {
        this.follow = MathTool.MixNumber(this.follow, this.target, this.m_t);
        if (this.m_tiny != 0 && this.target != this.follow) {
            if (Math.abs(this.target - this.follow) <= this.m_tiny) {
                this.follow = this.target;
            }
        }
    }
}

export class MathTool {
    static get VecZero(): Laya.Vector3 {
        return new Laya.Vector3();
    }

    //随机一个浮点数
    public static RandomNumber(from: number, to: number): number {
        if (from >= to) {
            return 0;
        }
        var size = to - from;
        var curNumber = Math.random() * size + from;
        return curNumber;
    }

    //3d物体旋转转相机坐标
    //相机   4.7  -68  -1.88
    //-4.7   111,  1.88
    public static SpToCam(v3: Laya.Vector3) {
        v3.x = -v3.x;
        v3.y = v3.y - 180;
        v3.z = -v3.z;
        return v3;
    }

    //v3 插值
    private static m_mixVector: Laya.Vector3 = new Laya.Vector3();
    public static MixVector3(from: Laya.Vector3, to: Laya.Vector3, t: number, res: Laya.Vector3 = null): Laya.Vector3 {
        if (res == null) {
            res = this.m_mixVector;
        }
        res.x = MathTool.MixNumber(from.x, to.x, t);
        res.y = MathTool.MixNumber(from.y, to.y, t);
        res.z = MathTool.MixNumber(from.z, to.z, t);
        return res;
    }

    public static MixNumber(from: number, to: number, t: number): number {
        t = MathTool.Clamp(t, 0, 1);
        from = (to - from) * t + from;
        return from;
    }

    public static Clamp(value: number, from: number, to: number): number {
        if (value < from) {
            value = from;
        }
        if (value > to) {
            value = to;
        }
        return value;
    }
}
