jit.gl.sketch inconsistent translate rendering


    Feb 24 2013 | 10:19 pm
    Hello,
    I am sending opengl commands to jit.gl.sketch object from javascript. I would like to draw the same pattern at different positions, so I refactored my code in a method. The problem is that I call the same function "twice" with the same parameters, and I get one pattern translated by 0.5 on the x-axis.
    When I remove the code for the yellow line, it seems to be working. However, I could not think of a reason why it should yield a incorrect result with it.
    function bang() {
    outlet(0, "reset");
    // outlet(0, "glmatrixmode", "modelview");
    draw_unit([0, 0, 0], [0,0]);
    draw_unit([0, 0, 0], [0,0]);
    }
    function draw_unit(globCell, localCell) {
    outlet(0, "glpushmatrix");
    outlet(0, "glcolor", 1, 1, 1);
    outlet(0, "gltranslate", globCell[0], globCell[1], globCell[2]); // global transform
    outlet(0, "glpushmatrix");
    outlet(0, "gltranslate", -0.5, localCell[0], 0);
    outlet(0, "framecircle", 0.1, angle, angle+arc);
    outlet(0, "glpopmatrix");
    outlet(0, "glpushmatrix");
    outlet(0, "gltranslate", 0.5, localCell[1], 0);
    outlet(0, "framecircle", 0.1, angle, angle+arc);
    outlet(0, "glpopmatrix");
    outlet(0, "glpushmatrix");
    outlet(0, "glcolor", 1, 0, 0);
    outlet(0, "framecircle", 0.4);
    outlet(0, "glpopmatrix");
    outlet(0, "glcolor", 1, 1, 0);
    outlet(0, "glpushmatrix");
    outlet(0, "glbegin", "lines");
    outlet(0, "glvertex", -0.5, localCell[0], 0);
    outlet(0, "glvertex", 0.5, localCell[1], 0);
    outlet(0, "glend");
    outlet(0, "glpopmatrix");
    outlet(0, "glpopmatrix");
    }
    [attachment=215757,5065] [attachment=215757,5066]
    All the best,

    • Feb 25 2013 | 7:20 pm
      won't be able to help without seeing the full javascript.
    • Feb 25 2013 | 9:18 pm
      here is the full JS. thanks in advance...
      var arc = 300, angle = 0;
      function bang() {
      outlet(0, "reset");
      draw_unit([0, 0, 0], [0,0]);
      draw_unit([0, 0, 0], [0,0]);
      }
      function draw_unit(globCell, localCell) {
      outlet(0, "glpushmatrix");
      outlet(0, "glcolor", 1, 1, 1);
      outlet(0, "gltranslate", globCell[0], globCell[1], globCell[2]); // global transform
      outlet(0, "glpushmatrix");
      outlet(0, "gltranslate", -0.5, localCell[0], 0);
      outlet(0, "framecircle", 0.1, angle, angle+arc);
      outlet(0, "glpopmatrix");
      outlet(0, "glpushmatrix");
      outlet(0, "gltranslate", 0.5, localCell[1], 0);
      outlet(0, "framecircle", 0.1, angle, angle+arc);
      outlet(0, "glpopmatrix");
      outlet(0, "glpushmatrix");
      outlet(0, "glcolor", 1, 0, 0);
      outlet(0, "framecircle", 0.4);
      outlet(0, "glpopmatrix");
      outlet(0, "glcolor", 1, 1, 0);
      outlet(0, "glpushmatrix");
      outlet(0, "glbegin", "lines");
      outlet(0, "glvertex", -0.5, localCell[0], 0);
      outlet(0, "glvertex", 0.5, localCell[1], 0);
      outlet(0, "glend");
      outlet(0, "glpopmatrix");
      outlet(0, "glpopmatrix");
      }
    • Feb 26 2013 | 9:54 pm
      anyone would like to comment on this, please?
    • Feb 26 2013 | 9:57 pm
      ok, it looks like you need to use the "moveto" message at the start of your draw_unit function.
      not entirely sure why that is.
      the following works for me
      var arc = 300, angle = 0;
      
      function bang() {
      	outlet(0, "reset");
      	draw_unit([0, 0, 0], [0,0]);
      	draw_unit([0.25, 0.25, 0], [0,0]);
      }
      
      function draw_unit(globCell, localCell) {
      	outlet(0, "glcolor", 1, 1, 1);
      	outlet(0, "moveto", globCell[0], globCell[1], globCell[2]); // global transform
      
      	outlet(0, "glpushmatrix");
      	outlet(0, "gltranslate", -0.5, localCell[0], 0);
      	outlet(0, "framecircle", 0.1, angle, angle+arc);
      	outlet(0, "glpopmatrix");
      
      	outlet(0, "glpushmatrix");
      	outlet(0, "gltranslate", 0.5, localCell[1], 0);
      	outlet(0, "framecircle", 0.1, angle, angle+arc);
      	outlet(0, "glpopmatrix");
      
      	outlet(0, "glcolor", 1, 0, 0);
      	outlet(0, "framecircle", 0.4);
      
      	outlet(0, "glcolor", 1, 1, 0);
      	outlet(0, "gltranslate", globCell[0], globCell[1], globCell[2]);
      	outlet(0, "glbegin", "lines");
      	outlet(0, "glvertex", -0.5, localCell[0], 0);
      	outlet(0, "glvertex", 0.5, localCell[1], 0);
      	outlet(0, "glend");
      }