프로그래밍/Flex/AIR2008.09.23 09:41
source:
http://joshua.almirun.com/tech/ria/flash/getting-2d-coords-from-displayobject3d

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!





Posted by 시난

댓글을 달아 주세요