« Return to Thread: screen space to 3D space...

screen space to 3D space...

by timbon :: Rate this Message:

Reply to Author | View in Thread

Please help...
I  would like to create a 3D representation of the mouse pointer at different z depths.
For example matching a cube to the screen space pointer at 400 units away from the camera.
For a camera with a zoom value of 5 I have found the following code works. HOWEVER I would like to automate the cube.z depth value from the camera and to do that I need to find the formula that describes the scale value that converts the screen space mouse coordinates to correct perspective distorted space. I think it might have something to do with this:
H/h=(fl+z)/fl
realScale/screenScale = (focalLength + Zdepth) / focalLength
http://www.kirupa.com/developer/mx/perspective.htm
http://www.experiencefestival.com/a/3D_projection/id/387095
//Code example:
camera.zoom = 5;
camera.addChild( cube );
camera.addChild( cube1 );
//3Dobject.x = (stage.mouseX - (stage.stageWidth/2) )/MAGIC_SCALE_VALUE;3Dobject.depth =auto;
cube.x = (stage.mouseX - (stage.stageWidth/2) )/4.1;cube.z =25;
cube.y = ((stage.mouseY - (stage.stageHeight/2))*-1)/4.1;cube.z = 25;
//cube.x = (stage.mouseX - (stage.stageWidth/2) )/3.35;cube.z  =50;
//cube.y = ((stage.mouseY - (stage.stageHeight/2))*-1)/3.35;cube.z  = 50;
//cube.x = (stage.mouseX - (stage.stageWidth/2) )/2.5;cube.z  =100;
//cube.y = ((stage.mouseY - (stage.stageHeight/2))*-1)/2.5;cube.z = 100;
//cube.x = (stage.mouseX - (stage.stageWidth/2) )/1.65;cube.z  = 200;
//cube.y = ((stage.mouseY - (stage.stageHeight/2))*-1)/1.65;cube.z  = 200;
//cube.x = (stage.mouseX - (stage.stageWidth/2) )/1.25;cube.z  = 300;
//cube.y = ((stage.mouseY - (stage.stageHeight/2))*-1)/1.25;cube.z  = 300;
cube1.x = (stage.mouseX - (stage.stageWidth/2) )/1;cube.z = 400;
cube1.y = ((stage.mouseY - (stage.stageHeight/2))*-1)/1;cube.z = 400;
//cube.x = (stage.mouseX - (stage.stageWidth/2) )/.73;cube.z = 600;
//cube.y = ((stage.mouseY - (stage.stageHeight/2))*-1)/.73;cube.z = 600;
//cube.x = (stage.mouseX - (stage.stageWidth/2) )/.56;cube.z = 800;
//cube.y = ((stage.mouseY - (stage.stageHeight/2))*-1)/.56;cube.z = 800;

 « Return to Thread: screen space to 3D space...