Away 4.
Hi all.I was looking for the good old Away3x screen() method to get a 2d screen space position of a 3d point but found only camera.project() .This method is strange (would like to get an explanation from the devs) .Because it looks like it return a 2d point in a device screen space but from the other side the values look like those of clip space.Or may be those are homogeneous coordinates (though they don’t range between -1 1) ?
Well for all who are interested here are two function that will give you an abiltiy to extract the screen space coordinates of your 3d objects:
This one put into LensBase:
public function projectToScreenSpace(point3d:Vector,screenW:Number,screenH:Number):Point{
var p:Point=new Point();
var v:Vector=matrix.transformVector(point3d);
p.x=((v.x*screenW)/(2*v.w))+screenW*0.5;
p.y=(-(v.y*screenH)/(2*v.w))+screenH*0.5;
return p;
}
This one goes into Camera3D
public function projectToScreen(point3d : Vector3D,screenW:Number,screenH:Number) : Point
{
return lens.projectToScreenSpace(inverseSceneTransform.transformVector(point3d,screenW,screenH));
}
Usage:
var screenPoint:Point=camera.projectToScreen(mySphere,view.width,view.height)
mySprite.x=screenPoint.x;
mySprite.y=screenPoint.y;
That is all folks
It would be nice if such a feature could be incorporated into the Away trunk.