Page 1 of 1
Confusion with screen coordinates
Posted: Tue May 21, 2024 4:11 pm
by Tomi
Hello everybody!
I'm a little confused about screen dimensions in ZGE.
When I moved a 2d bitmap (so, I changed the Position.X and Y of this model) in my first test program with the default settings, the left and right edge of the screen can be found at -5 and 5 values, while top and bottom are at -3 and 3.
But why? Why not 0 and 800, and 0 and 600? Is there a function to get the screen coordinates? And what if I set a smaller or greater screen resolution? The -5,5 and -3,3 values are constant even in this case?
Re: Confusion with screen coordinates
Posted: Tue May 21, 2024 5:22 pm
by Kjell
Hi Tomi,
Tomi wrote: ↑Tue May 21, 2024 4:11 pmWhen I moved a 2d bitmap (so, I changed the Position.X and Y of this model) in my first test program with the default settings, the left and right edge of the screen can be found at -5 and 5 values, while top and bottom are at -3 and 3.
By default ZGameEditor uses a camera with a perspective projection and a vertical field-of-view of 45 degrees positioned at coordinate 0,0,10.
When using a 3D / perspective camera the edge of the screen is dependent on how far your object is away from the camera.
Tomi wrote: ↑Tue May 21, 2024 4:11 pmWhy not 0 and 800, and 0 and 600? Is there a function to get the screen coordinates?
If you want to have a coordinate system that matches your viewport, i'd recommend using a camera with a orthographic projection instead. Attached is a basic example.
K
Re: Confusion with screen coordinates
Posted: Wed May 22, 2024 2:09 pm
by Tomi
A-ha! Thanks, Kjell; so is ZGE basically uses 3D projection, even in the case of a 2d program? But I will look your attached example program...
Re: Confusion with screen coordinates
Posted: Thu May 23, 2024 9:41 am
by Kjell
Hi Tomi,
Tomi wrote: ↑Wed May 22, 2024 2:09 pmso is ZGE basically uses 3D projection, even in the case of a 2d program?
No, you don't have to use a 3D projection if you don't want to. Simply add a Camera component to your project and configure it to your needs .. below is the exact same scene viewed using 3 different camera configurations.
K
Re: Confusion with screen coordinates
Posted: Thu May 23, 2024 1:40 pm
by Tomi
Thanks again, Kjell!
I started to understand it based on your attached images.
But returning to your previous words:
"When using a 3D / perspective camera the edge of the screen is dependent on how far your object is away from the camera."
Okay, but in this case how can I get the exact screen dimensions? Is there such a function that give those values in different distances from the camera? App.ViewportWidth and App.ViewportHeight?
Re: Confusion with screen coordinates
Posted: Thu May 23, 2024 2:36 pm
by Kjell
Hi Tomi,
It's simple Pythagoras theorem
So .. by default the camera is positioned at 0,0,10 and uses a perspective projection with a FOV of 45. When you create a diagram of that situation viewed from the side ( over the x-axis ) it looks something like this:
You can find the vertical "screen edge" for z-coordinate = 0 using the following calculation:
K
Re: Confusion with screen coordinates
Posted: Thu May 23, 2024 6:35 pm
by LsJack
hi Kjell,
could you upload the .zgeprojet of the isometric example?
Kjell wrote: ↑Thu May 23, 2024 9:41 am
Re: Confusion with screen coordinates
Posted: Fri May 24, 2024 7:58 am
by Kjell
Hi LsJack,
LsJack wrote: ↑Thu May 23, 2024 6:35 pmcould you upload the .zgeprojet of the isometric example?
Sure, i swapped out the model & textures with procedural alternatives for filesize & copyright reasons ( and added a bit of movement ) .. but aside from that it's the same thing.
K