Plugin Cafe Homepage
Forum Home Forum Home > Plugin Cafe > PYTHON Development
  New Posts New Posts
  FAQ FAQ  Forum Search

How to get horizontal field of view angle?

Author
Message
  Topic Search Topic Search
Vertexwahn View Drop Down
Member
Member


Joined: 2017 Jul 05
Online Status: Offline
Posts: 4
Direct Link To This Post Topic: How to get horizontal field of view angle?
    Posted: 2017 Jul 05 at 3:57am
How do I get the horizontal field of view angle of the current view?

My first attempt looks like this:

import c4d

def main():
    doc = c4d.documents.GetActiveDocument()
    rbd = doc.GetRenderBaseDraw()
    cameraObject = rbd.GetSceneCamera(doc)

    print("cameraObject[c4d.CAMERAOBJECT_FOV] = " + str(cameraObject[c4d.CAMERAOBJECT_FOV]))
    print("cameraObject[c4d.CAMERAOBJECT_FOV_VERTICAL] = " + str(cameraObject[c4d.CAMERAOBJECT_FOV_VERTICAL]))
    fov2 = (360.0 / (2 * 3.1415926535897932384626433832795)) * cameraObject[c4d.CAMERAOBJECT_FOV]
    print("Horizontal fov in deg: " + str(fov2))
    

if __name__=='__main__':
    main()


Back to Top
Vertexwahn View Drop Down
Member
Member


Joined: 2017 Jul 05
Online Status: Offline
Posts: 4
Direct Link To This Post Posted: 2017 Jul 05 at 7:20am
First attempt to compute the "big" fov:

import c4d
import math

def main():
    doc = c4d.documents.GetActiveDocument()
    rbd = doc.GetRenderBaseDraw()
    cameraObject = rbd.GetSceneCamera(doc)
    
    bd = doc.GetRenderBaseDraw()
    frame = bd.GetFrame()
    xresolution = frame["cr"] - frame["cl"] + 1
    yresolution = frame["cb"] - frame["ct"] +1
        
    renderData = doc.GetActiveRenderData()
    renderDataBc = renderData.GetDataInstance()
    
    smallFov = cameraObject[c4d.CAMERAOBJECT_FOV]
    print("SmallFov = " + str(c4d.utils.Deg(smallFov)))

    bigFov = (smallFov / renderDataBc[c4d.RDATA_XRES]) * xresolution
    print("BigFov = " + str(c4d.utils.Deg(bigFov)))

if __name__=='__main__':
    main()

Situation is better now, but it does not fit perfectly
Back to Top
Vertexwahn View Drop Down
Member
Member


Joined: 2017 Jul 05
Online Status: Offline
Posts: 4
Direct Link To This Post Posted: 2017 Jul 05 at 7:26am
Back to Top
Vertexwahn View Drop Down
Member
Member


Joined: 2017 Jul 05
Online Status: Offline
Posts: 4
Direct Link To This Post Posted: 2017 Jul 05 at 8:08am
Changed my computation - see bigFov2

import c4d
import math

def main():
    doc = c4d.documents.GetActiveDocument()
    rbd = doc.GetRenderBaseDraw()
    cameraObject = rbd.GetSceneCamera(doc)
    
    bd = doc.GetRenderBaseDraw()
    frame = bd.GetFrame()
    xresolution = frame["cr"] - frame["cl"] + 1
    yresolution = frame["cb"] - frame["ct"] +1
        
    renderData = doc.GetActiveRenderData()
    renderDataBc = renderData.GetDataInstance()
    
    smallFov = cameraObject[c4d.CAMERAOBJECT_FOV]
    print("SmallFov = " + str(c4d.utils.Deg(smallFov)))

    bigFov = (smallFov / renderDataBc[c4d.RDATA_XRES]) * xresolution
    print("BigFov = " + str(c4d.utils.Deg(bigFov)))
    
    imagePlaneDistance = (renderDataBc[c4d.RDATA_XRES]*0.5) / math.tan(smallFov * 0.5)
    print(imagePlaneDistance)
    
    bigFov2 = math.atan( (xresolution*0.5) / (imagePlaneDistance) ) * 2
    print("BigFov2 = " + str(c4d.utils.Deg(bigFov2)))
    
if __name__=='__main__':
    main()

no everything looks better:


Is there maybe a better/more clean way to find out the "Big" fov. I am a bit confused by the different image plane sizes ( renderDataBc[c4d.RDATA_XRES] vs. xresolution = frame["cr"] - frame["cl"] + 1
Back to Top
Andreas Block View Drop Down
Forum Moderator
Forum Moderator
Avatar

Joined: 2014 Oct 01
Location: Hannover
Online Status: Offline
Posts: 1878
Direct Link To This Post Posted: 2017 Jul 06 at 9:19am
Hi,

welcome to the Plugin Café forums Smile

Your very last question first:
The sizes are different, because in render settings (RenderData) it is the actual size of the final render. The view port on the other hand may have completely different aspect ratio, that's why there are the grey areas on the left and right (or top and bottom). And of course the resolution of the view port is also completely different (in most cases) from the final render resolution. The part of the view port which matches the final render (the non grey part) is returned by GetSafeFrame() instead of GetFrame().

In order to get the FOV for the of the entire view port (yellow line in your first screenshot), I'd actually cheat by cloning the current render settings, setting its resolution to the size returned by GetFrame() and making it active. Then you could use your first code snippet. Afterwards throw away the extra render settings and make the previous one active again.

Cheers,
Andreas
SDK Support Engineer
Back to Top

Forum Jump Forum Permissions View Drop Down

Bulletin Board Software by Web Wiz Forums® version 9.61 [Free Express Edition]
Copyright ©2001-2009 Web Wiz

This page was generated in 0.094 seconds.