Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Page 1 of 2 12 LastLast
Results 1 to 10 of 15

Thread: Near & far parameter in glfrustum-glperspective c++

  1. #1
    Junior Member Newbie
    Join Date
    Aug 2012
    Posts
    9

    Near & far parameter in glfrustum-glperspective c++

    Hello,
    I develop an application of computer graphics based on OpenGL and Glut. He then asked to develop the application in order to comply with the following request:

    "The student is required to make a general application that is able to accommodate the size of the dataset to be displayed appropriately parameterizing the volume of view."

    I tried using the commands glFrustum AND gluPerspective but without being able to parameterize the values ​​near and far to these commands. How do I set the zoom so that it filled the entire window?

    If anyone can 'give me some advice (even with some additional information on the project) would be very grateful to him.

  2. #2
    Senior Member OpenGL Pro Aleksandar's Avatar
    Join Date
    Jul 2009
    Posts
    1,214

  3. #3
    Junior Member Newbie
    Join Date
    Aug 2012
    Posts
    9
    Thank You for the answer.
    I read more documents but i don't understand what is the method for resolve my problem.can you help me?

  4. #4
    Junior Member Newbie
    Join Date
    Aug 2012
    Posts
    9
    Quote Originally Posted by Aleksandar View Post
    could help me the function:

    "
    The Transformed Depth Coordinate

    The depth (z) coordinate is encoded during the viewport transformation (and later stored in the depth buffer). You can scale z values to lie within a desired range with the glDepthRange() command. (Chapter 10 discusses the depth buffer and the corresponding uses for the depth coordinate.) Unlike x and y window coordinates, z window coordinates are treated by OpenGL as though they always range from 0.0 to 1.0.

    void glDepthRange(GLclampd near, GLclampd far);
    Defines an encoding for z coordinates that's performed during the viewport transformation. The near and far values represent adjustments to the minimum and maximum values that can be stored in the depth buffer. By default, they're 0.0 and 1.0, respectively, which work for most applications. These parameters are clamped to lie within [0,1].

    In perspective projection, the transformed depth coordinate (like the x and y coordinates) is subject to perspective division by the w coordinate. As the transformed depth coordinate moves farther away from the near clipping plane, its location becomes increasingly less precise. (See Figure 3-18.) "

    ?

    the problem that i have is how fix the values of near & far in GLFRUSTUM

  5. #5
    Senior Member OpenGL Guru Dark Photon's Avatar
    Join Date
    Oct 2004
    Location
    Druidia
    Posts
    4,568
    You haven't really told us what you're specific question is. You just said you have this homework problem and you don't know what to do. It sounds like the point of the exercise is for you to learn how the planes comprising the view frustum are calculated, and then use your math skills to figure out how to fit those planes to the objects in your scene.

    Beside Chapter 3, see this for a summary:

    * OpenGL Transformation (Song Ho Ahn)

  6. #6
    Junior Member Newbie
    Join Date
    Aug 2012
    Posts
    9
    Quote Originally Posted by Dark Photon View Post
    You haven't really told us what you're specific question is. You just said you have this homework problem and you don't know what to do. It sounds like the point of the exercise is for you to learn how the planes comprising the view frustum are calculated, and then use your math skills to figure out how to fit those planes to the objects in your scene.

    Beside Chapter 3, see this for a summary:

    * OpenGL Transformation (Song Ho Ahn)
    i don't know what is the method for automatically parametrize the parameter near e far.
    my project must be available with all the dataset that i pass to the project...
    the dataset could be 10x10x10, 100x100x100 etc..
    the project must automatically adapt the visualization to the dataset

  7. #7
    Junior Member Newbie
    Join Date
    Aug 2012
    Posts
    9
    Quote Originally Posted by Agata_ View Post
    i don't know what is the method for automatically parametrize the parameter near e far.
    my project must be available with all the dataset that i pass to the project...
    the dataset could be 10x10x10, 100x100x100 etc..
    the project must automatically adapt the visualization to the dataset
    Anyone help me please...i'm blocked

  8. #8
    Senior Member OpenGL Guru Dark Photon's Avatar
    Join Date
    Oct 2004
    Location
    Druidia
    Posts
    4,568
    Quote Originally Posted by Agata_ View Post
    Anyone help me please...i'm blocked
    Picture what you're trying to do, and then it becomes much simpler.

    Where can the object be in EYE-SPACE? How big is it in EYE-SPACE? That tells you the volume of space you need to make sure you have in your view frustum, right?

    Think about how you can use the makeFrustum() function on the Song Ho Ann page I mentioned (this is essentially gluPerspective). How can you compute those parameters? Write a formula in terms of the size of the object.

  9. #9
    Junior Member Newbie
    Join Date
    Aug 2012
    Posts
    9
    Quote Originally Posted by Dark Photon View Post
    Picture what you're trying to do, and then it becomes much simpler.

    Where can the object be in EYE-SPACE? How big is it in EYE-SPACE? That tells you the volume of space you need to make sure you have in your view frustum, right?

    Think about how you can use the makeFrustum() function on the Song Ho Ann page I mentioned (this is essentially gluPerspective). How can you compute those parameters? Write a formula in terms of the size of the object.
    I have a project that must set the cam automatically for adapting to only dataset that i fix.
    I think that the problem was how define the parameter of glPerspective or glFrustum, in particular the parameter "near" and "far". Is it right?
    I have searched on the web, on forum and on books but i haven't find a solution for my problem.
    I also read * OpenGL Transformation (Song Ho Ahn)...could you help me to resolve my problem?if i don't resolve that, i can't go to next request of the project.
    If you want, i could send you information and documentation by mail.

    the function MAKEFRUSTUM is

    void makeFrustum(double fovY, double aspectRatio, double front, double back)
    {
    const double DEG2RAD = 3.14159265 / 180;

    double tangent = tan(fovY/2 * DEG2RAD); // tangent of half fovY
    double height = front * tangent; // half height of near plane
    double width = height * aspectRatio; // half width of near plane

    // params: left, right, bottom, top, near, far
    glFrustum(-width, width, -height, height, front, back);
    }

    the parameter FRONT & BACK are the same of NEAR & FAR? I use glFrustum and i center my object with these parameters:

    glFrustum(heightMap->minX-heightMap->xcenter, heightMap->maxX-heightMap->xcenter, heightMap->minY-heightMap->ycenter, heightMap->maxY-heightMap->ycenter, heightMap->near, heightMap->far);

    minX=0.0;
    maxX=nrows*cellsize;
    minY=0.0;
    maxY=ncols*cellsize;
    far = 500;
    near = 100;
    xcenter = (minX + maxX)/2;
    ycenter = (minY + maxY)/2;
    zcenter = (far+near)/2;

    as you could watch, i fix the parameter near & far manually...but the project expressly ask that the camera'sparameters must set automatically.
    Help me please.
    Thanks

  10. #10
    Senior Member OpenGL Guru Dark Photon's Avatar
    Join Date
    Oct 2004
    Location
    Druidia
    Posts
    4,568
    Quote Originally Posted by Agata_ View Post
    ...
    Code :
    void makeFrustum(double fovY, double aspectRatio, double front, double back)
    {
    ...
    glFrustum(-width, width, -height, height, front, back);
    }

    the parameter FRONT & BACK are the same of NEAR & FAR?
    Yes, you can see that from the code. glFrustum's 5th and 6th parms are near and far (click for man page). The man page also describes clearly what region on the near clip plane the glFrustum parameters correspond to.

    as you could watch, i fix the parameter near & far manually...but the project expressly ask that the camera'sparameters must set automatically. Help me please.
    Since this is a homework problem, I shouldn't get into the details of helping you solve it. I'd talk to your instructor and get some guidance.

    BTW, does the assignment require you to use perspective? If not, consider orthographic. It's a little simpler to think about. In fact, since you're having trouble, I'd just use glOrtho first regardless. Then think about what (if anything) you need to change for perspective.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •