I am trying to "fake 3D" in a computer game. Think of a road on a flat landscape, and that the objects start to appear somewhere in the distant. As they get closer, they look bigger, and eventually they grow in size very fast. (The same effect, another example: Think of a comet moving close to planet Earth. At first, it seems if it just becomes a tad bigger, but eventually it grows insanely fast until it collides with Earth.)
In this case, the objects move slightly downwards as they seem to get nearer (as in the road example). I'm thinking that when the object first appears, it's close to 0 pixels in width and height. As it moves towards the player (i.e., it goes downwards some pixels), it becomes closer to hundred percent of its true size. (Again, at first it grows slowly, and when it is rather close to the player, it grows very quickly.)
I think I will need to solve this using logarithmic/exponential calculations, and there are several threads on that. What I would really want to do however, is to send in three values to a LogaritmicGrowth method:
- the starting Y point
- the Y point at which the object should appear at 100%
- the Y point where the object is at this very moment.
Thus, what I would like to get in return is the scaling factor for the object in question. So if it's halfway between the starting point and the ending point, then perhaps 0.3 (or so) should be returned, meaning that if the true size of the object is 100 pixels with and 50 pixels height, it should be drawn at 30 pixels with and 16.7 pixels width.
I can write the method inputs and outputs myself, but need help with the formula. (I tried asking this question on Stackoverflow, but was told to ask on this forum instead.)
Also, on Stackoverflow, I got this reply, but I don't think it's really what I am after (and if it is, then I can't understand it):
Think about a point P which is D distance in front of you, which has a height Y (from your line of observation). Your screen is d distance in front of you. The intersection point of the light from P on the screen is p, which makes a height y on screen.
Then, by considering the similar triangles, one can show that:
y = (Y/D) d
Thanks for any input!