Javascript physics engine Oimojs

Oimojs is a javascript port of a physics engine. What’s a physics engine, you may ask. Well it’s simple.
You describe a world of objects in some simple code, run the code and the world is rendered and animated. To create the world, you use the ADD function. Each ADD function takes a object, which defines its behavior. Types include “ground”, which is what you’d think, “box” a rectangular area, “sphere” and “cylinder.” If an object has the “move” property set to true it’s subject to gravity and collision. If false, it’s static.
Here’s a sample of its use:
//Some setup, all magic.
CLEAR({timer:false, timestep:1/60, iteration:8, broadphase:'sweep', G:-10});
function initDemo()
{

//
ADD({type:"ground", size:[550,300,550], pos:[0,-150,0]});
// wall
ADD({ type:"box", size:[450,1000,50], pos:[0,500,-250] });
ADD({ type:"box", size:[450,1000,50], pos:[0,500, 250] });
ADD({ type:"box", size:[50,1000,550], pos:[-250,500,0] });
ADD({ type:"box", size:[50,1000,550], pos:[ 250,500,0] });

// dynamique object
var max = 200;
var px, pz, t, n;
var sx, sy, sz;

for (var i=0; i!==max; ++i ){
    if(version=="DEV") n=2;
    else n=3;
    t = Math.floor(Math.random()*n)+1;
    px = -100+Math.random()*200;
    pz = -100+Math.random()*200;

    sx = 20+Math.random()*100;
    sy = 20+Math.random()*100;
    sz = 20+Math.random()*100;
    if(t==1) ADD({ type:"sphere", size:[sx*0.5], pos:[px,100*i,pz], move:true });
    else if(t==2) ADD({ type:"box", size:[sx,sy,sz], pos:[px,100*i,pz], move:true });
    else if(t==3) ADD({ type:"cylinder", size:[sx*0.5,sy,sx*0.5], pos:[px,100*i,pz], move:true });
}
Just grab it, and run with it.

Comments

Popular Posts