import OimoBodyData from "./OimoBodyData";
export default class OimoHelper {

    private static instance: OimoHelper;
    public static get Inst(): OimoHelper {
        if (this.instance == null) {
            this.instance = new OimoHelper();
        }
        return this.instance;
    }
    public constructor() {
    }

    public world: OIMO.World;
    public createWolrd() {
        this.world = new OIMO.World({
            timestep: 1 / 60,
            iterations: 8,
            broadphase: 2, // 1 brute force, 2 sweep and prune, 3 volume tree
            worldscale: 1, // scale full world 
            random: true,  // randomize sample
            info: false,   // calculate statistic or not
            gravity: [0, -9.8, 0]
        });
        this.world.play();
    }

    public createBody(data: OimoBodyData) {
        return this.world.add(data);
    }

    public clearWorld() {
        if (this.world) {
            this.world.clear();
        }
    }

    public playWorld() {
        if (this.world) {
            this.world.play();
        }
    }
}