
export class Mathf {
    static GetData(value) {
        var theTime = Math.floor(value);// 需要转换的时间秒 
        var theTime1 = 0;// 分 
        var theTime2 = 0;// 小时 
        var theTime3 = 0;// 天
        if (theTime > 60) {
            theTime1 = Math.floor(theTime / 60);
            theTime = theTime % 60;
            if (theTime1 > 60) {
                theTime2 = Math.floor(theTime1 / 60);
                theTime1 = theTime1 % 60;
                if (theTime2 > 24) {
                    //大于24小时
                    theTime3 = Math.floor(theTime2 / 24);
                    theTime2 = theTime2 % 24;
                }
            }
        }
        var result = '';
        result = "" + theTime1 + "分" + result;
        result = "" + theTime2 + "时" + result;
        result = "" + theTime3 + "天" + result;
        return result;
    }

    /**
     * 确认精度
     */
    static GetNumAccuracy(num: number) {
        var b = Math.ceil(num * 10) / 10;
        if (Math.abs(b - num) < 0.0001) {
            return b;
        }
        var a = Math.floor(num * 10) / 10;
        if (Math.abs(a - num) < 0.0001) {
            return a;
        }
        return num;
    }
    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;
    }

    public static get Gravity() {
        return new Laya.Vector3(0, -10, 0);
    }

    //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 = Mathf.MixNumber(from.x, to.x, t);
        res.y = Mathf.MixNumber(from.y, to.y, t);
        res.z = Mathf.MixNumber(from.z, to.z, t);
        return res;
    }

    public static MixVector4(from: Laya.Quaternion, to: Laya.Quaternion, t: number, res: Laya.Quaternion): Laya.Quaternion {

        res.x = Mathf.MixNumber(from.x, to.x, t);
        res.y = Mathf.MixNumber(from.y, to.y, t);
        res.z = Mathf.MixNumber(from.z, to.z, t);
        res.w = Mathf.MixNumber(from.w, to.w, t);
        return res;
    }
    public static MixNumber(from: number, to: number, t: number): number {
        t = Mathf.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;
    }
}
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 = Mathf.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;
            }
        }
    }

    // this.m_goldFollow.target = this.m_mgrApp.userData.gold;
    // this.m_goldFollow.update();
    // this.m_goldText.text = Math.ceil(this.m_goldFollow.follow).toString();
}