connecting jit.phys.body to jit.gl.gridshape in javascript


    Jan 30 2014 | 7:09 am
    i want to generate many jit.gl.gridshape objects which are connected to jit.phys.body objects in javascript.
    my code works fine, but since i set the gridshapes position and rotatexyz to the phys.bodies' position and rotatexyz in the bang-function (which is triggered by a qmetro 40), it uses a lot of cpu performance.
    i also tried to do a similar patch using jit.phys.multiple and jit.gl.multiple (without javascript). but that's not an alternative for me, cause i want to change the x-, y- and x- scales of the objects on the fly.
    can anyone explain how to connect jit.gl.gridshape- to jit.phys.body-objects using javascript only?
    thanks for any help!
    PS: below is my code which uses a lot of cpu-performance.
    var maxo = 250;
    var cside = 0.04;
    var cube = new Array();
    var cubx = new Array();
    for(var i=0;i {
    var r = (Math.random()*0.1)-0.05;
    cube[i] = new JitterObject("jit.phys.body","orjo-world");
    cube[i].shape = "cube";
    cube[i].scale = [cside, 0.1, cside];
    cube[i].position = [r, r, r];
    cube[i].friction = 0;
    cube[i].mass = 1;
    cube[i].restitution = 0;
    cube[i].damping = [0.99,1];
    cubx[i] = new JitterObject("jit.gl.gridshape","orjo");
    cubx[i].shape = "cube";
    cubx[i].shader = "orshade";
    cubx[i].lighting_enable = 1;
    cubx[i].antialias = 1;
    cubx[i].scale = [cside, 0.1, cside];
    cubx[i].position = cube[i].position;
    }
    function bang()
    {
    for(var i=0;i {
    cubx[i].position = cube[i].position;
    cubx[i].rotatexyz = cube[i].rotatexyz;
    }
    }
    function resetit()
    {
    for(var i=0;i {
    var r = Math.random()*0.1-0.05;
    cube[i].position = [r, r, r];
    }
    }

    • Feb 03 2014 | 8:52 pm
      you can connect a phys.body to a gl.gridshape in javascript by setting the phys.body @targetname to the gl.gridshape @name attribute:
      pbody.targetname=gshape.name;