watmough / glmatrix

Automatically exported from code.google.com/p/glmatrix
0 stars 1 forks source link

Unproject #21

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
I'm trying to unproject but am having difficulty!

mat4.unproject = function (width, height, maxDepth, minDepth, x, y, 
screenSpace, ProjectionMatrix, ViewMatrix, uv) {
  var scale = mat4.create();
  var invScale = mat4.create();

  scale[0] = width / 2f;
  scale[5] = -height / 2f;
  scale[10] = maxDepth - minDepth;
  scale[12] = x + width / 2f;
  scale[13] = y + height / 2f;
  scale[14] = minDepth;
  scale[15] = 1f;
  mat4.inverse(scale, invScale);

  var us = vec3.create();
  var up = vec3.create();

  mat4.multiplyVec3(invScale, screenSpace, us);
  mat4.multiplyVec3(projectionMatrix, us, up);
  mat4.multiplyVec3(viewMatrix, up, uv);
}

Original issue reported on code.google.com by denis.ra...@gmail.com on 21 Jun 2010 at 5:02

GoogleCodeExporter commented 8 years ago

Original comment by Tojiro@gmail.com on 1 Jul 2010 at 9:35