Screen cooridinates of 3d point code is avaliable

Software: Away3D 4.x

Avatar
SasMaster, Sr. Member
Posted: 17 July 2011 09:36 AM   Total Posts: 127

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 smile
It would be nice if such a feature could be incorporated into the Away trunk.

 Signature 

This looks like a job for superman
http://blog.alladvanced.net

   

John Brookes, Moderator
Posted: 17 July 2011 11:02 AM   Total Posts: 732   [ # 1 ]

Been doing it this way

private function getStagePosition(cam:Camera3Dobj:ObjectContainer3D):Vector3D 
{
 
var camT:Matrix3D cam.viewProjection.clone();
 var 
planT:Matrix3D obj.sceneTransform.clone();
 
camT.prepend(planT);

 var 
pv:Vector3D Utils3D.projectVector(camT, new Vector3D());
 
pv.= (pv.view.width 2) + view.width 2
 pv
.y  = (pv.y*-view.height 2) + view.height 2
 
return pv;
   

Avatar
SasMaster, Sr. Member
Posted: 17 July 2011 11:30 AM   Total Posts: 127   [ # 2 ]

Yes ,that is an elegant ” John Brooks way ” solution wink .

 Signature 

This looks like a job for superman
http://blog.alladvanced.net

   

John Brookes, Moderator
Posted: 17 July 2011 11:39 AM   Total Posts: 732   [ # 3 ]

edit
totally wrong guess was here
now gone smile

I did the getstageposition thang before project was added.

   

_kihu, Jr. Member
Posted: 16 March 2012 04:02 PM   Total Posts: 43   [ # 4 ]

It works! Altough I needed to change 2 things:

var v:Vector3D=matrix.transformVector(point3d);

and

return lens.projectToScreenSpace(inverseSceneTransform.transformVector(point3d),screenW,screenH);

   

John Brookes, Moderator
Posted: 16 March 2012 04:28 PM   Total Posts: 732   [ # 5 ]

You dont need to do this..old post.

Just use
view.project(yourVertexPosition)

   

_kihu, Jr. Member
Posted: 16 March 2012 04:32 PM   Total Posts: 43   [ # 6 ]

silly me. Thanks!:)

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X