2d coords -> Ray intersection of plane

Software: Away3D 4.x

Dirkjan, Newbie
Posted: 29 December 2011 03:08 PM   Total Posts: 2

I’d like to know where some 2d stage coords are on a 3d plane. I know about the MouseEvent3D, but that does not really work for me I’m afraid.

So I figure: Let ‘s use Ray.getRayToTriangleIntersection twice.

var dest:Vector3D _view.camera.unproject(x,y);
  
   var 
cameraPosition:Vector3D _view.camera.position;
   
dest.add(cameraPosition);
   
   var 
r:Ray = new Ray();
   
   
//plane is 1000x1000 @ 0,0,0, yUp=true
   
var v0:Vector3D = new Vector3D(-500,0,-500);
   var 
v1:Vector3D = new Vector3D(+500,0,-500); 
   var 
v2:Vector3D = new Vector3D(+500,0, +500); 
   
   var 
intersection:Vector3D r.getRayToTriangleIntersection(cameraPositiondestv0,v1,v2);
   
   if(!
intersection){
    v1 
= new Vector3D(+500,0,-500);
    
intersection r.getRayToTriangleIntersection(cameraPositionrayv0,v1,v2);
   
}
   
   
if(!intersection{
    trace
'no intersection!');    
    return;
   

So this does not work.

I think the problem lies with the unproject function, which gives me values way up in the +/- 9.000.

Any better ways to do this?

   

Dirkjan, Newbie
Posted: 02 January 2012 07:26 AM   Total Posts: 2   [ # 1 ]

Ok, I admit: My description of the problem was pretty bad and not clear at all. Sorry about that. My Math just sucks and 3D is pretty overwhelming at times.

I would like to re-state the problem:
“How do I get the 3D cords of a 2D point on the screen”

In my case, I only need the coords on the “floor” at zero Y.

I used the Drag3D class to “borrow” some code. Here is my solution:

override public function getScreenTo3DPosition($x:Number$y:Number):Vector3D{
   
   
var _np:Vector3D = new Vector3D(0,1,0);
   
   var 
_d:Number 0;// _intersection height / Y coord I think?
   
   
var _intersect:Vector3D = new Vector3D();
   
   var 
pMouse:Vector3D _view.unproject($x$y);
   var 
cam:Vector3D _view.camera.position;
   var 
d0Number _np.cam._np.cam._np.cam._d;
   var 
d1Number _np.pMouse._np.pMouse._np.pMouse._d;
   var 
mNumber d1 / ( d1 d0 );
   
   
_intersect.pMouse.+ ( cam.pMouse.) * m;
   
_intersect.pMouse.+ ( cam.pMouse.) * m;
   
_intersect.pMouse.+ ( cam.pMouse.) * m;
   
   return 
_intersect;
  

Now, I do have a follow up question:

What is actually happening here? What formula’s or what Math is used here?

   

Rob Dodson, Newbie
Posted: 02 January 2012 04:30 PM   Total Posts: 15   [ # 2 ]

just wondering what’s the use case you’re trying to achieve?

when I need to determine the 2D coords of a MouseEvent3D on a plane I use the uv’s that are passed in the MouseEvent3D.

var pt:Point = new Point(event.uv.x * sourceMovieClip.width, event.uv.y * sourceMovieClip.height);

in this case sourceMovieClip is used by my version of MovieMaterial but you could use a bitmap or something else.

You mentioned “knowing about MouseEvent3D” but it doesn’t work for you so I guess I’m wondering about that statement when I ask what is your use case.

   

3dNewb, Sr. Member
Posted: 02 January 2012 06:06 PM   Total Posts: 105   [ # 3 ]

In my case, it is not necessarily the mouse that is performing the action. The application is structured to respond to x, y coordinates without knowing the kind of input.

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X