You have to do the same calculation as WebGL. It takes a three-dimensional point [X,Y,Z] to a homogeneous point [x,y,z,w] through
[x,y,z,w] = pMatrix * mvMatrix * [X,Y,Z,1]
To get the clip space coordinates, divide it by w :
[x/w,y/w,z/w]
x/w and y/w are in the range [-1,1]. To convert them to viewing coordinates, scale them according to the size of the canvas.
[x/w,y/w] -> [(1 + x/w)*canvas.width/2, (1 - y/w)*canvas.height/2]
Notice how the "direction" of the y coordinate changes in the last transformation.
For more information, you can use the Google graphics pipeline. For instance. http://en.wikipedia.org/wiki/Graphics_pipeline
source share