Simulate Z Axis in 2D

This topic is 2591 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

[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 http://en.wikipedia.org/wiki/Transformation_matrix 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 . [/font]

Share on other sites
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 on other sites
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 on other sites
It's basically:

x' = c * x / z
y' = c * y / z

where c is a constant scaling factor (depending on the field of view).

Share on other sites
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 on other sites
Hi darkchris !!!

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

Share on other sites
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 on other sites

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.

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 on other sites

Hi darkchris !!!

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

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.

1. 1
2. 2
Rutin
19
3. 3
4. 4
5. 5

• 14
• 12
• 9
• 12
• 37
• Forum Statistics

• Total Topics
631435
• Total Posts
3000056
×