Hello,

just want to share something (took me hours to figure it out) & ask if
there is maybe a better method.

You have: a Vector3D (coordinates of a point in 3D, f.e. Pivot-Point
or Vertex-Point)
You want: to project this coordiantes to a 2D-Space and place a 2D-
Sprite (2D-Display overlaying the 3D-Display) at resulting XY values.

Dummy-Code (tracking the Pivot-Point of a 3D-Object):

var VIEW_WIDTH:Number = the width of your view;
var VIEW_HEIGHT:Number = the height of your view;

var view:View3D;
var camera:Camera3D;
var cameraDummy:Camera3D;
var your3DObject:Cube; (Cube or something else)
var point2D:Sprite;
var projectionM:Matrix3D; // the projection-matrix of your camera and
cameraDummy

function setProjectionMatrix():void {

// Using cameraDummy because of the 'camera.viewProjection.clone()'-
Distortion-Problem!
// (camera.viewProjection.clone()' used on a camera which has been
added to view will distort it!
// cameraDummy.settings == camera.settings;

projectionM = cameraDummy.viewProjection.clone();

}


function placeSpriteOnPivotPoint():void {

        // 2D-Projection Formula
        //------ found out by TRYING & ERRORING for hours! ---> toDo: try to
explain/understand. ---------

                var __v:Vector3D = your3DObject.position;
                var __pv:Vector3D = 
flash.geom.Utils3D.projectVector(projectionM,
__v);

                point2D.x = VIEW_WIDTH*0.5   +   __pv.x*VIEW_HEIGHT*0.5;
                point2D.y = VIEW_HEIGHT*0.5  -  __pv.y*VIEW_HEIGHT*0.5;

        
//-----------------------------------------------------------------------------------------------------
}

it works, demos here:
http://www.vatrobot.de/molehill_broomstick/HelloCube_PivotPoint2D.html
http://www.vatrobot.de/molehill_broomstick/HelloCube_VertexPoint2D.html

QUESTIONS:
1. Is there a better method to do this? If not, will it be
implemented?
2. Does anyone can explain why cloning the Matrix3D of a camera
distorts the view? Any ideas how to avoid this?

Thanks,
Vatrobot


Reply via email to