Stage click coords to Plane coords

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

Stage click coords to Plane coords

Thomas Robertz
Does anybody know a built-in or other function to convert the clicked
(stage) coordinate to a plane coordinate?
(2D only needed)

For instance if plane.width == stage.width, and I click on stage
coordinate 100,100, it should return 100,100.
But then if camera.zoom is increased, and I click on the same
projected stage coordinate (say 50,50), it should return 100,100 also.

To elaborate a little I load a jpeg (backgroundLayer) onto a plane
(backgroundPlane) and make it fit the stage window:

        camera.z = -1000;
        camera.focus = 100;
        camera.x = 0;
        camera.y = 0;
        widthProportion = backgroundLayer.bitmap.width / stage.width;  // global
        var distance:Number = Math.abs(backgroundPlane.z - camera.z);
        camera.zoom = 1 / (widthProportion) * (distance / camera.focus);

On the jpeg there is a 100x100 green square at 0,0 (top left).
I get the stage to plane coords with my own function like this:

        convertedCoords.x = (x / camera.zoom) * (camera.zoom * widthProportion);

This works for initial zoom and also for different size images, so
when I click on the lower right corner of the square (100,100),  it
yields 100,100.
But when I zoom in:


The green square grows and moves to the left and up, consequently I
have to click something like 50,50 to click on the same lower right
I'm sure you get the picture :) The coordinates are then wrong,
because my function obviously is missing something.
I'm working on another function but I thought surely someone must have
already solved this?

Papervision3D mailing list
[hidden email]