Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by vexe · Jan 13, 2015 at 12:06 PM · camerablenderfovfieldofview

Negative results when converting HFOV to VFOV?

So I'm trying to match the FOV between blender's horizontal FOV and Unity's vertical.

I found a lot of similar equations in the web on how to do it: 1, 2, 3

My script:

 public class H2V_FOV : MonoBehaviour
 {
     public float vFov, hFov = 60.0f;
            
     void Update()
     {
         var c = Camera.main;
         vFov = 2 * Mathf.Atan(c.aspect * Mathf.Tan(hFov / 2));
         c.fieldOfView = vFov;
     }
 }

However; the result is always negative for some reason :(

The last link (3) gives me the right VFOV if I plug the values in the equation, for ex: width = 491, height = 368, hfov = 60 => vfov = 47 which seems to look correct when testing it.

What am I doing wrong? I tried (float)Screen.width / Screen.height but same result.

Thanks for any help.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
3
Best Answer

Answer by HarshadK · Jan 13, 2015 at 12:54 PM

The formula in link #3 is actually correct but it is for getting the value of HFOV based on VFOV. What you need is the value of VFOV and not HFOV so I solved that formula to get the value of VFOV from HFOV and that formula becomes:

vFov = Mathf.Atan(Mathf.Tan(hFov/2)/c.aspect)*2;

Plus the angles used in the formula are required in radian as per the same article from link #3. So using some conversions between degrees and radians the code becomes:

 public class H2V_FOV : MonoBehaviour
 {
     public float vFov, hFov = 60.0f;
          
     void Update()
     {
         var c = Camera.main;
         vFov = Mathf.Atan(Mathf.Tan(Mathf.Deg2Rad * hFov/2)/c.aspect)*2;
         c.fieldOfView = vFov * Mathf.Rad2Deg;
     }
 }

  

I verified the values using the same calculator from that same link and output is actually correct.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image vexe · Jan 13, 2015 at 01:13 PM 0
Share

Thanks. That's pretty clever. I got confused, cause the other links seemed to have the same equation I had, so I came to the conclusion that the third link had a typo, since it's calculating the vfov, but in the equation they're calculating hfov, why would they do that? psh

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

25 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Camera movement in a 2D? (like angry birds) 1 Answer

Find out if GameObject is in Field of View 2 Answers

Automatically adjust cameras FOV to maintain a perfect 360 coverage with multiple cameras 0 Answers

Is there a way to set the horizontal field of view of a camera? 3 Answers

Blender and Unity Camera Setup 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges