Perfect Orthagonal Camera?

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
trollger
Posts: 84
Joined: Tue Jun 01, 2010 2:17 am
Location: At my computer

Perfect Orthagonal Camera?

Post by trollger »

Hi guys,

I want to make a top down isometric game (its an RTS) and I have come across a somewhat large problem. I don't want differnt screen resolutions to scale the video, I only want people with largers screens to be able to see more stuff not larger stuff.

When I change the size of the resolution, the mesh that I am drawing on the screen scales just slightly. This is unnoticable to the human eye but it throws off all my bounding boxes, and other 2d images that get drawn over the game (such as energy and health bars).

I am only using 16:9 aspect ratios.

I made an orthagonal camera like so

Code: Select all

 
// The Resolution of the window/screen
float ResWidth = 1024;
float ResHeight = 576;
 
// Nothing special about 160, its just the size I want
float Zoom = ResWidth/160;
int AspectX = 16;
int AspectY = 9;
 
// Create an orthagonal camera
irr::core::CMatrix4<float> CamCMatrix;
CamCMatrix.buildProjectionMatrixOrthoLH(AspectX*Zoom, AspectY*Zoom, 0, 100);
 
cam->setProjectionMatrix(CamCMatrix,true);
 
Is there anything in there that would make the image change slightly depending on the sceen resolution?
dmb
Posts: 9
Joined: Thu Jun 13, 2013 2:07 pm

Re: Perfect Orthagonal Camera?

Post by dmb »

In this situation you can actually kill two birds with one stone.

Orthogonal Projection means that everything looks the same no matter how far away you look. The way you have it set up currently, you're scaling the view to fit the screen, but slightly, and can mesh with the meshes since you're doing it via float (int / float = float unless typecast) because you're using decimal values. Its sort of like why do we need to see .35 percent more of the screen?

Instead scale your view based on the screen-size. This keeps everything aligned to your aspect ratio (16:9) and lets you see more if you're farther away.

Simple solution in code below:

Code: Select all

// The Resolution of the window/screen
float ResWidth = 1024;
float ResHeight = 576;
 
//Define our aspect here. We use  16 as our constant for scaling purposes. 
float aspectx= ResWidth/16.f;
float aspecty = ResHeight/16.f; 
 
// Create an orthagonal camera
irr::core::CMatrix4<float> CamCMatrix;
CamCMatrix.buildProjectionMatrixOrthoLH(aspectx , aspecty, 0, 100);
 
cam->setProjectionMatrix(CamCMatrix,true);
Doing this should scale what the client see's based on the screen size. I.E. smaller screen = less shown. This also prevents your images from being screwed up where they render, because its constant in 3D space.

Also look out for your near/far value. If you're not careful you won't see enough of the rendered image. I had to spend a lot of time toying around with the proper positioning in order to make sure nothing disappeared while it was still on-screen.
trollger
Posts: 84
Joined: Tue Jun 01, 2010 2:17 am
Location: At my computer

Re: Perfect Orthagonal Camera?

Post by trollger »

OK thanks, thats fixes it for all resolutions except 1920*1080, which is my main monitors native resolution. When I run it in windowed mode at that resolution I lose about 20ish px from the screen border and the title bar on top. In fullscreen it works great, but I would like a windowed-fullscreen option in my game, it thats possible.
dmb
Posts: 9
Joined: Thu Jun 13, 2013 2:07 pm

Re: Perfect Orthagonal Camera?

Post by dmb »

trollger wrote:OK thanks, thats fixes it for all resolutions except 1920*1080, which is my main monitors native resolution. When I run it in windowed mode at that resolution I lose about 20ish px from the screen border and the title bar on top. In full screen it works great, but I would like a windowed-fullscreen option in my game, it that's possible.
Its possible you can change the value from 16 to 4, but this changes your aspect ratio to 4:3 instead of 16:9 (yes I know they're divisible) and may mess with the rest of your aspect. but this is the only way to achieve 1920x1080 comfortably. If you're ok with it it keeps every thing in line but shows a whole lot more if I'm correct.
Post Reply