should rending matrix functions get along with shape functions?

64 views
Skip to first unread message

Bob Lyon

unread,
Feb 4, 2013, 11:32:55 PM2/4/13
to khan-academy-javas...@googlegroups.com
I was disappointed that translate() and rotate() do not affect vertex().  A simple example is at http://www.khanacademy.org/cs/no-rotating-while-shaping/1351182209 .... Basically the following function "doesn't work":

var myVertex = function(x, y) {
            pushMatrix();
            translate(x, y);
            vertex(0, 0);
            popMatrix();
};

Am I being unreasonable or naive, or both?

Element118

unread,
Sep 25, 2015, 6:52:32 PM9/25/15
to Khan Academy Javascript Technical Q&A
I think what vertex does is to push a coordinate (in that case (0, 0)) to memory such that endShape can draw it later. That is why transformations should not affect it.
You can try the following which shows only the endShape call affected by a transformation.
var myVertex = function(x, y) {
    pushMatrix();
    translate(x, y);
    vertex(0, 0);
    popMatrix();
};
beginShape();
myVertex(200, 200);
vertex(100, 100);
vertex(100, 200);
pushMatrix();
translate(20, 20);
endShape(CLOSE);
popMatrix();
Reply all
Reply to author
Forward
0 new messages