Sign in to follow this  
aghausman

Simulate Z Axis in 2D

Recommended Posts

aghausman    100
[font=arial, sans-serif][size=2]
Hi,


I am working on a 2D image where I have X and Y axis now I want to simulate Z axis by scaling the size of objects in image. but I am stuck with the calculation. I don't know how to scale the objects based on Z-Axis. I red this [url="http://en.wikipedia.org/wiki/Transformation_matrix"]http://en.wikipedia.org/wiki/Transformation_matrix[/url] link but didn't proof very helpful.

Can anyone of you forward me to the right direction. I think I have successfully put my question on this email but if there is some thing missing please let me know . [/size][/font]

Share this post


Link to post
Share on other sites
ryan20fun    2635
why dont you just scale it down on the X and Y axis ?
that way the image will be smaller.
if you want it to be behind another sprite, then draw the backmost first and then move to the fonrt most
in other words the last sprite to be draw will be on 'top' and the first to be drawn will be on the 'bottom'

Share this post


Link to post
Share on other sites
alvaro    21263
I think he wants to know how to compute the scaling factor. Let D be the distance between the eye and the screen. The scaling factor is then D/(D+z). This is not hard to figure out with pen and paper (draw a diagram of the x/z plane and project an arbitrary point; you can find the formula using triangle similarity).

Share this post


Link to post
Share on other sites
aghausman    100
Alvaro !! Sorry for the basic question but how do I calculate D. I understand that this the distance between eye and screen but how do I calculate that ? Is this constant ? One place I tried using 1000 as D and it always return me wrong result. I was using the same formula u mention.
Thanks for prompt response

Share this post


Link to post
Share on other sites
ryan20fun    2635
Field Of View or FOV (in 3D atleast) is the angle of the sides of a triangle or its like defineing how wide you can see.
try pictureing it as a 3D triangle and whith a greater FOV the greater the base of the triange is.
get it ?
i dont always explain things well.

Share this post


Link to post
Share on other sites
alvaro    21263
[quote name='aghausman' timestamp='1305996077' post='4813890']
Alvaro !! Sorry for the basic question but how do I calculate D. I understand that this the distance between eye and screen but how do I calculate that ? Is this constant ? One place I tried using 1000 as D and it always return me wrong result. I was using the same formula u mention.
[/quote]

You can only calculate D if you know something else, like perhaps the horizontal angle of view and the width of the screen. Or you can just start setting D equal to the width of the screen and play with it until you like the results.

Share this post


Link to post
Share on other sites
DarkChris    110
[quote name='aghausman' timestamp='1305996509' post='4813892']
Hi darkchris !!!

What should I put in c ? I understand this is a constant but u mention field view .... What is that ?
[/quote]

You can calculate the scaling factor c using the intercept theorem.

This is how the formula would look like with the field of view angle included:

x' = x / (z * tan(fov_angle / 2))
y' = x / (z * tan(fov_angle / 2))


Note that the resulting coordinates will be in the range -1..1, so you might have to scale them.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this