No Clean Feed - Stop Internet Censorship in Australia
«
»

3d, AS3, Flash

getting 2d coords from displayobject3d

04.07.08 | 8 Comments

I have been banging my head against a wall with a simple Papervision3D problem: making a normal Flash 2D object (a DisplayObject, or Sprite) to appear at the same coordinates as a 3D object (a DisplayObject3D, or Plane, or whatever).

After spending the best part of a day scouring mailing lists, I found this method that solved the problem:

public function convertTo2DCoords(o:DisplayObject3D, camera:CameraObject3D, offsetX:Number = 0, offsetY:Number = 0):Point {
var view:Matrix3D = o.view;
var persp:Number = (camera.focus * camera.zoom) / (camera.focus + view.n34);
return new Point((view.n14 * persp) + offsetX, (view.n24 * persp) + offsetY);
}

You just need to add half the Stage.width to point.x, and half the Stage.height to point.y, and Bob’s your uncle …

(I was working with a 3D scene that filled the whole stage … might need some tweaking if this is not the case …)

I am posting this because, although it’s apparently a quite basic Papervision problem, it took ages to find it. We need better PV3D documentation!

related

8 Comments

have your say

Add your comment below, or trackback from your own site. Subscribe to these comments.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

:

:


«
»
Close
E-mail It