Desperately need help - OpenGl - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Desperately need help - OpenGl

Hello!
i'm a very-very beginning OpenGl programmer.
And for making up first serious ( even somehow) programmes, i'd like to understand the basics.

I competely do NOT understand how function [b]GluPerspective[/b] works. I mean, i know its usage in theory but i still can't use it the way it works as i need to.

For instance, i have a cobe centered in (0,0,0), its heigth is 0.6. (so it crosses all the axes in points 0.3,-0.3).

How should I call [b]GluPerspective[/b] to see the edges of the cube ( some of them in fron of the viewer)???

And i do NOT understand the location of the viewer, i mean, the place i stand to see the scene ???

Can anybody explane me , please?

it's really urgent

HUGE thanks

Comments

  • gautamgautam Posts: 642Member
    Hi,

    Its very simple. There are two types of projecttion - Perspective Projection and othograpics projection.

    Perspective Projection gives you a view like in the real world - further you go smaller it will look while Orthographics projection keeps the size in tact. However far in the world it goes - the size is the same.

    Now to do perspective projection you need to use gluPerspective in Opengl.

    Consider this diagram of the two types of viewing frustum. The cuboid/rectangular type is the Orthographics projection frustum while the other one is the perspective viewing frsutum.

    http://www.microsoft.com/msj/archive/opengl8.gif

    Now lets get to the specific of gluPerspective -
    gluPerspective( GLdouble fovy,
    GLdouble aspect,
    GLdouble zNear,
    GLdouble zFar )

    fovy is field of view for the y direction. This is the amount that you would want to see. So it goes like this in terms of a diagram


    .
    . |
    . |
    . |y direction
    eye. ) angle |
    . |
    . |
    . |

    The aspect ratio determines the angle or how much is visible to eye on the x direction. However in an application it needs to use something to determine thus so it uses the width/height as the factor to calculate this. Thus your aspect ratio becomes the application width divided by the application height.

    | |
    | |
    near clipping | | far clipping plane
    plane | |
    zNear | | zFar
    | |

    zFar - Think of this as the horizon after which you cannot see anything. Anything outside of this value will be clipped meaning not rendered.

    zNear - This is the nearest point to the view/eye before which nothing will be visible.

    So what you would do is do the following in opengl for gluPerspective for what you want

    gluPerspective(45.0f, width/height, 0.1f, 100.0f);

    And also set yourself at (should be done after you call glClear(..) and before rendering anything.)
    gluLookAt(0, 0, 5, 0, 0, 0, 0, 1, 0);

    Basically saying set the eye point at 0, 0, 5 pixels behind origin with center being 0, 0, 0 and Up vector being 0, 1, 0.

    Hope this helps

    : Hello!
    : i'm a very-very beginning OpenGl programmer.
    : And for making up first serious ( even somehow) programmes, i'd like
    : to understand the basics.
    :
    : I competely do NOT understand how function [b]GluPerspective[/b]
    : works. I mean, i know its usage in theory but i still can't use it
    : the way it works as i need to.
    :
    : For instance, i have a cobe centered in (0,0,0), its heigth is 0.6.
    : (so it crosses all the axes in points 0.3,-0.3).
    :
    : How should I call [b]GluPerspective[/b] to see the edges of the cube
    : ( some of them in fron of the viewer)???
    :
    : And i do NOT understand the location of the viewer, i mean, the
    : place i stand to see the scene ???
    :
    : Can anybody explane me , please?
    :
    : it's really urgent
    :
    : HUGE thanks
    :
Sign In or Register to comment.