Skip to content

Instantly share code, notes, and snippets.

@williame
Created August 7, 2012 20:34
Show Gist options
  • Select an option

  • Save williame/3289055 to your computer and use it in GitHub Desktop.

Select an option

Save williame/3289055 to your computer and use it in GitHub Desktop.
function createOrtho2D(left,right,top,bottom) {
var near = -1, far = 1, rl = right-left, tb = top-bottom, fn = far-near;
return [2/rl,0,0,0,
0,2/tb,0,0,
0,0,-2/fn,0,
-(right+left)/rl, -(top+bottom)/tb, -(far+near)/fn,1];
}
createOrtho2D(0,canvas.offsetWidth,0,canvas.offsetHeight) * [10,10,0] = [-0.9804878048598766,0.9450549436733127,0]
I was expecting [10/canvas.offsetWidth,1-(10/canvas.offsetHeight),0] ??
If I do createOrtho2D(0,canvas.offsetWidth,canvas.offsetHeight,0) then the point 10,10 is 10 pixels in from the bottom left, and everything draws upside down
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment