Project point coordinates (without drawing on Canvas)

45 views
Skip to first unread message

gabrielpillet

unread,
Nov 3, 2010, 5:36:59 AM11/3/10
to pre3d
Hello and thanks for this handy lib. I found it really easy to use
with Canvas.

I got a specific need, my application need to draw a 3D plane (rotated
on X for perspective), this is working as expected, I just create my
plane and set a transformation to it, positioning my camera
accordingly.

Then I need do create some HTML div on top of the canvas, and one
corner of each div should match the position on my 3D plane, so I need
to apply my world transformation (rotation), along with my camera, and
get the projected coordinates.

Here is my code :

this.getProjectedPoint = function()
{
var p = this.p; //the point to transform (is in the same
coordinate system as my plane before transformation)

var transformPoint = new Pre3d.Transform();
transformPoint.rotateX(anglePlane);
transformPoint.m = transformPoint.m;

var transformCam = new Pre3d.Transform();
transformCam.m = renderer.camera.transform.m;

transformCam.multTransform(transformPoint);
p = transformCam.transformPoint(p);

return renderer.projectPointToCanvas(p);
}

The result is not exactly what I expect, but not far from it (hard to
explain without screenshot), therefor I think it's just a little
mistake. Any ideas ?

Gabriel

gabrielpillet

unread,
Nov 4, 2010, 5:52:08 AM11/4/10
to pre3d
Self answer : it was actually working as expected. The problem was
related to the translation to CSS coordinates.
Reply all
Reply to author
Forward
0 new messages