About Store Forum Documentation Contact



Post Reply 
Auto Fov
Author Message
cmontiel Offline
Member

Post: #1
Auto Fov
Let say that you like 65ยบ of FOVY for 1,33 aspect ratio (for example 1024x768).

When you change aspect ratio, you will see a different viewport because fov must be changed too.

I want to share this function for those ppl working with different resolutions or for mobiles.

Code:
// deg param is relative to 1.3333 aspect ratio.
Flt AutoFov(Flt deg, FOV_MODE fov)
{
    if(fov == FOV_X)
    {
        Flt vertical = 2 * Atan( Tan(DegToRad(deg)/2.f) * (1.f / 1.3333f) );
        Flt finalHorizontal = 2 * Atan( Tan(vertical/2.f) * D.w() );
        return finalHorizontal;
    }
    else
    {
        Flt horizontal = 2 * Atan( Tan(DegToRad(deg)/2.f) * 1.3333f );
        Flt finalVertical = 2 * Atan( Tan(horizontal/2.f) * (1.f / D.w()) );
        return finalVertical;
    }
}

How it works:

1) Set aspect ratio of 1.333 => D.mode(1024,768);
2) Choice a fov value playing with D.viewFov(); For this example D.viewFov(65,FOV_Y);
3) Change the resolution => D.mode(1280,720);
4) Change D.viewFov(65,FOV_Y) by D.viewFov(AutoFov(65,FOV_Y),FOV_Y);

You will get the same viewport for any resolution. It also works with FOV_X.

wink

IRC: irc.freenode.net
Channel: #Esenthel
(This post was last modified: 05-16-2013 07:51 PM by cmontiel.)
05-16-2013 06:29 PM
Find all posts by this user Quote this message in a reply
Ozmodian Offline
Member

Post: #2
RE: Auto Fov
Awesome! Thanks for sharing
05-16-2013 06:45 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #3
RE: Auto Fov
Hi,

I'm kinda missing the point why you're doing this like that? wink

FOV_Y by design works that way so for each resolution/aspect ratio it sets the same FOV in Y dimension:
When you do D.viewFov(DegToRad(65), FOV_Y) you should always have the same _Vertical_ fov for all resolutions.

But if you like to have constant _Horizontal_ fov for all resolutions, then just do: D.viewFov(DegToRad(65), FOV_X);

For mobiles where you can rotate the device and with one rotation get let's say 4/3 aspect ratio, and then with other rotation you get 3/4 aspect, then I just do:
D.viewFov(DegToRad(65), D.w()>D.h() ? FOV_Y : FOV_X);
05-16-2013 07:08 PM
Find all posts by this user Quote this message in a reply
cmontiel Offline
Member

Post: #4
RE: Auto Fov
The thing is that i dont want constant fov of 65 because you will see different things on different resolutions.

What makes the function is calculate the fov to see exactly the same. This is not related with mobile rotations.

IRC: irc.freenode.net
Channel: #Esenthel
(This post was last modified: 05-16-2013 07:57 PM by cmontiel.)
05-16-2013 07:54 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #5
RE: Auto Fov
I don't understand.

FOV_Y keeps the same vertical fov (for all resolutions), but calculates horizontal fov to match the vertical one.

FOV_X keeps the same horizontal fov (for all resolutions), but calculates vertical fov to match the horizontal one.

Use FOV_Y if you want to have the same vertical fov for all resolutions.
Use FOV_X if you want to have the same horizontal fov for all resolutions.

You cannot make both horizontal and vertical fovs to be identical for all resolutions.. only one can be constant, while the second one will always be calculated proportionally.
05-16-2013 08:54 PM
Find all posts by this user Quote this message in a reply
cmontiel Offline
Member

Post: #6
RE: Auto Fov
As you say, keeps the same fov, I don't want that. I want to see the same screen. I am terrible explaining with english. Wait I am going to make images pfft.

D.mode(1024,768) [1.333f]
D.viewFov(DegToRad(63.8f),FOV_Y);
[Image: Untitled_1.jpg]

D.mode(1280,720) [1.7777f]
D.viewFov(DegToRad(63.8f),FOV_Y);
[Image: Untitled_2.jpg]

I dont want to see parts inside red rectangles, then my function gives the correct FOV_Y:

D.mode(1024,768) [1.333f]
D.viewFov(AutoFov(63.8f,FOV_Y),FOV_Y);
[Image: Untitled_1.jpg]

D.mode(1280,720) [1.7777f]
D.viewFov(AutoFov(63.8f,FOV_Y),FOV_Y);
[Image: Untitled_3.jpg]

I know you can do the same with D.viewFov(DegToRad(someValue),FOV_X). My function is the inverse of that. Ie :

FOV_Y keeps the same horizontal fov (for all resolutions), but calculates vertical fov to match the horizontal one.

FOV_X keeps the same vertical fov (for all resolutions), but calculates horizontal fov to match the vertical one.

Which is the reason of this? Because in Esenthel editor you can change only the FOV_Y in advanced video options, but what if you want to see the same horizontal and you only have that value? When I add a new scene to my project this is useful for me, I just wanted to share it. pfft

IRC: irc.freenode.net
Channel: #Esenthel
(This post was last modified: 05-16-2013 10:12 PM by cmontiel.)
05-16-2013 08:59 PM
Find all posts by this user Quote this message in a reply
Rubeus Offline
Member

Post: #7
RE: Auto Fov
This is really cool. I had this on my to-do list, so I will be borrowing your code. smile
Sometimes-especially in games that rely on a certain perspective-something like this is needed.
05-16-2013 09:53 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #8
RE: Auto Fov
If you want to set constant horizontal fov for your game for all resolutions, and then get the vertical fov, you could have just done:
D.viewFov(DegToRad(65), FOV_X); // first set fov from horizontal value
Flt fov_y=D.viewFovY(); // now get resulting vertical fov after setting fov above
05-16-2013 10:18 PM
Find all posts by this user Quote this message in a reply
cmontiel Offline
Member

Post: #9
RE: Auto Fov
And how you know that is 65 and not 200? Doing a lot of build&run?
The thing is that you don't know desired FOV_X but yes FOV_Y (from Esenthel Editor).

IRC: irc.freenode.net
Channel: #Esenthel
05-16-2013 10:24 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #10
RE: Auto Fov
You can do this other way around:
for resolution of your choice
set vertical fov D.viewFov with FOV_Y
now you can get D.viewFovX which later you can reuse for your game.
05-16-2013 10:29 PM
Find all posts by this user Quote this message in a reply
cmontiel Offline
Member

Post: #11
RE: Auto Fov
Yes that's another way.

IRC: irc.freenode.net
Channel: #Esenthel
(This post was last modified: 05-16-2013 10:39 PM by cmontiel.)
05-16-2013 10:38 PM
Find all posts by this user Quote this message in a reply
Post Reply