## Confusion with screen coordinates

All topics about ZGameEditor goes here.

Moderator: Moderators

Tomi
Posts: 7
Joined: Mon May 20, 2024 12:40 pm

### Confusion with screen coordinates

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?
Kjell
Posts: 1900
Joined: Sat Feb 23, 2008 11:15 pm

### Re: Confusion with screen coordinates

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
Attachments
Ortho.zgeproj
(2.34 KiB) Downloaded 110 times
Tomi
Posts: 7
Joined: Mon May 20, 2024 12:40 pm

### Re: Confusion with screen coordinates

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...
Kjell
Posts: 1900
Joined: Sat Feb 23, 2008 11:15 pm

### Re: Confusion with screen coordinates

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
Tomi
Posts: 7
Joined: Mon May 20, 2024 12:40 pm

### Re: Confusion with screen coordinates

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?
Kjell
Posts: 1900
Joined: Sat Feb 23, 2008 11:15 pm

### Re: Confusion with screen coordinates

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
LsJack
Posts: 4
Joined: Tue May 14, 2024 4:15 pm

### Re: Confusion with screen coordinates

hi Kjell,

could you upload the .zgeprojet of the isometric example?
Kjell wrote: Thu May 23, 2024 9:41 am
Kjell
Posts: 1900
Joined: Sat Feb 23, 2008 11:15 pm

### Re: Confusion with screen coordinates

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
Attachments
Isometric.zgeproj
(5.46 KiB) Downloaded 115 times