pangwa
unread,Nov 10, 2011, 4:00:45 AM11/10/11Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to PhiloGL
Hi there,
I'm implementing the ray picking algorithm and writes a function to
convert the NDC coord to world coord. Apprent I got a wrong result.
Below is the unproject function I wrote:
PhiloGL.unproject = function (pt, camera)
{
return camera.view.invert().mulMat4 (camera.projection.invert
()).mulVec3 (pt);
};
//
// I set the canvas width = height = 840,
//
camera = new PhiloGL.Camera (60, 1, 0.5, 100000);
camera.position = [0, 0, 30];
camera.target = [0, 0, 0];
And I drew a standard cube at the origin with the scale to 10.
var ndcx = e.x * 2 / this.canvas.width;
var ndcy = e.y * 2 / this.canvas.height;
var origin = PhiloGL.unproject ([ndcx, ndcy, -1.0], this.camera);
The result of origin was apprantly wrong here, for e( -302, 247), I
got the
ndcx, y, z as -0.41514232754707336, 0.3395369350910187, 59
It's apprantly wrong because the ray (to camera.position (0, 0, 30)
intersect with a cube at (0.32707035541534424, -0.25786416283969227,
10) which is apprantly wrong as it should at somewhere (-7, -8, 10).
I believe the ray code is correct as I can get the correct result if I
hard code the ray's origin/direction.
I think the camera things in PhiloGL is in a mess..... Anybody can
help?
Thanks in advance!