Results 1 to 4 of 4

Thread: How to calculate optimal distance for camera?

  1. #1
    Senior Member Regular Contributor
    Join Date
    Jul 2001
    Posts
    442

    How to calculate optimal distance for camera?

    Hi,


    How can I calculate the optimal distance from a object for the camera eye-point such that all of the object is visible on screen (assume that the camera is axis aligned and that I only care about the x width of the object to look at).

    As a follow up, given a cylinder of radius R, how can I calculate the optimal camera distance such that the end section (circular) of the cylinder is completely visible on screen?

    Thanks for any help you may be able to give.

  2. #2
    Senior Member Regular Contributor
    Join Date
    Mar 2002
    Location
    Melbourne, Australia
    Posts
    224

    Re: How to calculate optimal distance for camera?

    hi!

    if i understand you well you're trying to do following:
    your camera has certain position and certain viewing angles...and there're some objects somewhere - you want to move camera forward or back so that all objects are visible and moving "a little bit" forward would cause that some of the objects are invisible

    if that's what you mean, then for each vertex of your object you need to compute how much your present frustum requires to be moved (forward or backward) so that this vertex is in front of every frustum plane

    say at the beginning you set move_length to -INFINITY, and then for each vertex you do:
    move_length = max(move_length, length_required_for_this_vertex)

    the only problem is now computation of length_required_for_this_point, but that's easy - just dot product + Pitagoras (more or less

    sorry for not being user_not_familiar_with_frustum friendly in this post, if you're not take a look at some frustum culling tuts

    [This message has been edited by MickeyMouse (edited 05-14-2002).]

  3. #3
    Junior Member Newbie
    Join Date
    Dec 2001
    Posts
    6

    Re: How to calculate optimal distance for camera?

    First, find the ratio between the width of the object and the pixel width of the screen.

    Then use this ratio to scale the view distance. This new distance is where you want to position the object in front of the eye point.

    By the way,
    View distance = (SCR_W/2) / tan(VIEWANGLE/2)

  4. #4
    Senior Member Regular Contributor
    Join Date
    Dec 2001
    Location
    Belmont, CA, USA
    Posts
    216

    Re: How to calculate optimal distance for camera?

    Originally posted by Robbo:

    How can I calculate the optimal distance from a object for the camera eye-point such that all of the object is visible on screen (assume that the camera is axis aligned and that I only care about the x width of the object to look at).
    Assuming that you know the aspect ratio and the field-of-view (you must supply these to gluPerspective), and assuming that Y is up and you are looking down the -Z axis and the object centered:

    d = w / 2. * aspect / tan( fov )

    d is the distance to the widest part.


    Originally posted by Robbo:

    As a follow up, given a cylinder of radius R, how can I calculate the optimal camera distance such that the end section (circular) of the cylinder is completely visible on screen?

    Thanks for any help you may be able to give.

    Assuming you know the aspect ratio and field-of-view and the cylinder is centered on the camera's -Z axis:

    if (aspect > 1)
    d = r / tan( fov )
    else
    d = r * aspect / tan(fov)

    Bounding sphere (in case you are wondering):

    If the object is within a bounding sphere with a radius of r and the camera is pointing at the center of the sphere,

    if (aspect > 1)
    d = r / sin( fov )
    else
    d = r * aspect / sin(fov)

    Note the bounding sphere uses sin rather than tan

Similar Threads

  1. Increasing camera far distance
    By lummxx in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 02-18-2016, 12:01 PM
  2. calculate optimal pitch value
    By sajis997 in forum OpenCL
    Replies: 1
    Last Post: 01-31-2014, 01:59 AM
  3. How to calculate points distance to point?
    By in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 03-15-2003, 04:27 PM
  4. Calculate the distance between two Matrixes
    By laserwiz in forum OpenGL: Basic Coding
    Replies: 8
    Last Post: 05-31-2002, 06:18 PM
  5. How to calculate optimal distance for camera?
    By Robbo in forum OpenGL: Advanced Coding
    Replies: 6
    Last Post: 05-14-2002, 08:32 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean