I will precise my question, I have a 2D object moving in a 2D world (X,Y), and I want to fake a movement on the Z axis. So I believe the best is to play with its extent (width,height) and position a bit. But what would be the equation to determine the new extent for an object of size(w,h) and moving from 1 meter forward the camera (Z axis)? What would be the parameters of such a function?
Thanks in advance for your help.
Use a projection by storing the object's true (X,Y,Z)
coordinates and display from a camera K
units above the plane by a 2D projection (K*X/(Z+K),K*Y/(Z+K))
where +Z
moves away from the camera.
To change the height, width follow a similar pattern with (DX,DY)
the true size of the sprite and (K*DX/(Z+K),K*DY/(Z+K))
the apparent (drawn) size.
To do this right you can follow the advice from this FlipCode article.
The main parameters would be the distance to the camera and the aperture angle.
It is simple to determine the new size by new_size = size / distance
.
Notice that objects that have no distance would be of infinite size.
To get the effect of the aperture angle you would want to include another factor f
:
new_size = f * size / distance
Where f
is the distance of unit size.
Distance of unit size is the distance where the image would be drawn at its original size.
Of course, this must not be zero too. By this distance you define impicitly the aperture angle.
When I talk about size I mean width and height so the formula applies on both.
I hope you can follow my explanations.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With