[Papervision3D] Getting Mouse Click Coordinates in Away3D
Alexander Zadorozhny
alexander.zadorozhny at gmail.com
Mon Jul 16 16:52:33 EDT 2007
Hi Mike
Actually in MouseEvent3D you already have the worldX, worldY and
worldZ coordinates
http://away3d.com/docs/away3d/core/scene/MouseEvent3D.html#worldX
And in Camera3D class there's a method
public function screen(object:Object3D, vertex:Vertex =
null):ScreenVertex
that converts object's 3d coordinates to the screen coordinates.
http://away3d.com/docs/away3d/core/scene/Camera3D.html#screen()
wbr,
Alexander
On 7/16/07, Mike Pearson <gmp26 at cam.ac.uk> wrote:
> John,
>
> This probably won't help you but it's useful for some apps anyway - e.g.
> http://nrich.maths.org/public/viewer.php?obj_id=5646
>
> It depends on Away3D's MouseEvent3D which gives you u,v
> coordinates of the mouse click. This code then calculates the x,y,z
> of the mouse pointer in object space as a linear combination of the
> vertices of the face you clicked on.
>
> public function onGlobeMouseDown(e:MouseEvent3D):void
> {
> var f:Face3D = (e.drawpri as DrawTriangle).face;
> if(f==null) return;
>
> var fv0:Number3D = f.v0;
> var fv1:Number3D = f.v1;
> var fv2:Number3D = f.v2;
> var m:Matrix3D = new Matrix3D();
> m.n11 = f.uv0.u;
> m.n12 = f.uv1.u;
> m.n13 = f.uv2.u;
> m.n21 = f.uv0.v;
> m.n22 = f.uv1.v;
> m.n23 = f.uv2.v;
> m.n31 = 1;
> m.n32 = 1;
> m.n33 = 1;
> var a:Number3D = new Number3D(e.uv.u, e.uv.v, 1).rotate
> (Matrix3D.inverse(m));
> var b:Number = a.x + a.y + a.z;
>
> // Calculate approximate object coordinates of mouse.
> var obj:Number3D = new Number3D();
> obj.x = (a.x*fv0.x + a.y*fv1.x + a.z*fv2.x)/b;
> obj.y = (a.x*fv0.y + a.y*fv1.y + a.z*fv2.y)/b;
> obj.z = (a.x*fv0.z + a.y*fv1.z + a.z*fv2.z)/b;
> ...
> }
>
> --
> Mike Pearson
>
> MMP, Centre for Mathematical Sciences,
> Cambridge CB3 0WA
>
>
>
>
> _______________________________________________
> Papervision3D mailing list
> Papervision3D at osflash.org
> http://osflash.org/mailman/listinfo/papervision3d_osflash.org
>
More information about the Papervision3D
mailing list