Author Topic: Map Plane to 2d Coords  (Read 692 times)

John Byrne   «   on: June 28, 2012, 04:52:45 AM »
Hi, 

I have a plane on the stage, and am tweening the coords. I would like however to bring a 2d dialog up in its exact position.

Is there any way to map a 3d x, y and z (and the width and height) to a 2d Rect?

I have seen the sample here: 
http://wiki.flare3d.com/index.php/3D_units_to_2D_pixels_conversion

But I think this only applies when the z value is set to be the reciprocal of the camera zoom.

Cheers

Ivan Vodopiviz   «   Reply #1 on: June 28, 2012, 10:37:34 AM »
Hi John,

You can get the screen coords of a pivot like this:

var point:Vector3D = pivot.getScreenCoords();

The x and y components of the returned Vector3D will hold the values you need.

John Byrne   «   Reply #2 on: July 02, 2012, 04:58:42 AM »
Hi Ivan, 

Yes, I can get the x and y of the center of the plane, but the length and radius don't correspond to the 2d width. Is there a way to get the width translated as well?

Cheers

Ivan Vodopiviz   «   Reply #3 on: July 02, 2012, 02:48:04 PM »
Hi,

I'm not sure I'm understanding what you want to do. Are you trying to draw 2D displaylist content over 3D content?

Regards,

John Byrne   «   Reply #4 on: July 03, 2012, 06:54:43 AM »
Well, yes, I want to find the 2d on-screen dimensions of a face of a mesh and place a 2D display object within those dimensions.

Is this crazy :D

Ivan Vodopiviz   «   Reply #5 on: July 03, 2012, 01:26:22 PM »
I don't know if it's crazy or not, but let's try some sample code you can find here. Just for reference, you can find "elsa.f3d" in the standard Flare3D distribution. I'm not a 100% sure this is what you need, but it might give you some clues.

Cheers,

John Byrne   «   Reply #6 on: July 05, 2012, 11:44:07 AM »
I ran that and played around with it, but am a little confused as to what the radius of 50 is referring to. It seems a little arbitrary.

I suppose if I was to say what I wanted in a sample, it would be to have a scene and then add a plane to it. Then, in the update event for that scene update rotateX, rotateY, rotateZ, scaleX, scaleY, scaleZ, x,  y and z for that plane. Then, after applying some or all of those operations, draw a 2d rect on the screen corresponding to the bounding box of that plane

John Byrne   «   Reply #7 on: July 05, 2012, 01:37:00 PM »
just to follow up, I had to do something, so I did this: 
http://pastebin.com/97ktBe60

I'm sure there's an infinitely better way, but my maths skills are getting there ass kicked :D

Ivan Vodopiviz   «   Reply #8 on: July 05, 2012, 03:41:37 PM »
Hi,

Please check this demo: http://flare3d.com/demos/screenRect/
Does this suit your needs? This will be included as a built-in feature in Flare3D 2.5, but we can send you the source if you need it urgently.

Cheers,

John Byrne   «   Reply #9 on: July 06, 2012, 03:30:57 AM »
Lol, I think that that's exactly what I was looking for :-)

If you could send it on that would be great, my email is troot1 (at) gmail.com

Just out of curiosity, is there an expected release date for 2.5?

John Byrne   «   Reply #10 on: July 09, 2012, 11:51:43 AM »
bump

Ariel Nehmad   «   Reply #11 on: July 10, 2012, 03:14:00 PM »
Hi John, here is the code we're using for the getScreenRect method.
Keep in mind that this is copied from the Mesh3D class, so variables like _bounds should be referencing to the mesh bounds you want to get the screen rect.
The code simply projects each corner into the screen and get the min and max values.