- Home /
Transforming plane to fit into 2d bounds
Hey guys!
So what I am trying to achieve is to draw 2d quadrangular bounds on a screen and then rotate plane game object to fit those bounds. Here's the screenshot of the bounds to give you a better idea:
I believe that there might be no easy way, but if any of you have any ideas I would really appreciate it!
I don't really get your question. Either your rectangle is a 3d rectangle or if it's 2d it's not a rectangle since it's angles are not 90°. Also what exactly do you mean by "bounds"? Unity's AABB Bounds? If this is actually a 2d-3d or 3d-2d conversion question, what kind of camera do you use? perspective?
In the end it's still not clear what input parameters you have and what's the desired output.
Do you mean to draw on say a touch device or with a mouse pointer and if you draw a square then a cube fits in that square. Or in your example if you draw a rectangle the a stretched cube rotates into place?
@$$anonymous$$mmpies: I guess, after reading that one sentence a couple of times, that he wants to draw a d2 trapezoid and calculate a possible position / rotation / scale for a 3d plane to fit that trapezoid. Only trapezoid would work as a perspective projection of a rectangle is always a trapezoid any "quadrilateral" won't work.
@mister-mortal:
If that's what you ment, keep in $$anonymous$$d that the size and position of a 2d-to-3d projection is always a matter of perspective(powered by Berenger)
@$$anonymous$$mmpies @Bunny83 What I mean is that I have a plane in a scene which should be rotated and scaled to fit in my drawn space. I draw space in UI using four draggable handles(as seen in a photo). Plane should be transformed (rotated, scaled) so its corners would appear to be at positions of UI draggable handles. Hope this makes thing more understandable.
What great example. True if you have no fixed points but I suppose it might be possible if one side was fixed, set a Z yourself and then match the location of X and Y creating a 3D object the right height to fix then do some calculations to swing the object until the side that's not fixed matches the x and y of the two remaining points and give it completely free range on the z. Still not easy going to be easy though!
Answer by Mmmpies · Dec 17, 2014 at 08:01 PM
OK as @Bunny83 points out no one can do that because we can't set the scale of the object.
But how about this...
We can get the X and Y as it's just how far left/right and up/down the screen it is what we can't work out is the depth.
However we could do some calculations on the distance between the points compared to screen height and then decide if say 3/4 of the screen that equates to 2 deep and half = 4 deep.
This can be done with a calculation to divide 1 by whatever the fraction of the screen height is. The smaller the height of the screen % used the bigger the number for how far away the object is.
So if we can pinpoint X and Y and calculate Z based on our rule you should be able to get the distance between these points. You should be able to create your plane and set it's corners that way.