[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Public WebGL] Re: Get Viewport for converting coordinates

hi, thanks for your answer!

2010/8/18 Gregg Tavares (wrk) <gman@google.com>:
> The size the canvas is rendered to is independent of the size it is
> displayed at.
> <cavnas width="100" height="100" style="width: 300px; height:
> 400px"></canvas>
> Will create a canvas that renders to a 100x100 pixel backbuffer but is
> stretched and displayed at 300x400 pixels so you should use the size it's
> displayed at to do your projection and click computations.
I have this one:
 <canvas id="lesson03-canvas" width="700" height="530" style="border:
none;" width="700" height="530" oncontextmenu="return false"></canvas>

> Assuming you are doing standard world * view * projection math for your
> models
yes, i do that standard.

> here's how you should calculate the correct projection for your
> projection matrix based on the size the backbuffer is displayed

is it necessary to use the perspective matrix you posted? I'm using
the matrices-functions which Vladimir Y. has written:

 perspective(45, gl.viewportWidth / gl.viewportHeight, 0.1, 20000000.0);

  var pMatrix;
  function perspective(fovy, aspect, znear, zfar) {
    pMatrix = makePerspective(fovy, aspect, znear, zfar);

function makePerspective(fovy, aspect, znear, zfar)
    var ymax = znear * Math.tan(fovy * Math.PI / 360.0);
    var ymin = -ymax;
    var xmin = ymin * aspect;
    var xmax = ymax * aspect;

    return makeFrustum(xmin, xmax, ymin, ymax, znear, zfar);


function makeFrustum(left, right,
                     bottom, top,
                     znear, zfar)
    var X = 2*znear/(right-left);
    var Y = 2*znear/(top-bottom);
    var A = (right+left)/(right-left);
    var B = (top+bottom)/(top-bottom);
    var C = -(zfar+znear)/(zfar-znear);
    var D = -2*zfar*znear/(zfar-znear);

    return $M([[X, 0, A, 0],
               [0, Y, B, 0],
               [0, 0, C, D],
               [0, 0, -1, 0]]);

> If you need code for viewProjectionInverse I can post that as well.

you mean inverse(projectionMatrix*mvMatrix) ? Got that..but sure I
would be glad if you post that,too :)
You are currently subscribed to public_webgl@khronos.org.
To unsubscribe, send an email to majordomo@khronos.org with
the following command in the body of your email: