Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 4 of 4

Thread: distortion of sphere while rotating...help

  1. #1
    Junior Member Newbie
    Join Date
    Jun 2004
    Posts
    2

    distortion of sphere while rotating...help

    /*
    Hi,

    I am trying to model a small solar system - sun,
    a planet. Sun at the centre, planet goes arnd it.
    The problem is that when the planet is closing
    towards or moving away from eyes, it appears
    distored. sphere appears bulged at poles. Though
    when it's exactly infront of the eyes it's fine. view is perspective. Here is some code :
    */

    void display(void)
    {
    glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glPushMatrix();
    glCallList(theSun); //makes a sphere
    glTranslatef(0.0,0.0,0.0);
    glRotatef(rev_planet,0.0,1.0,0.0);
    glTranslatef(-sun_radius*AR,0.0,0.0);
    glColor3f(1.0,1.0,1.0);
    glCallList(thePlanet);
    glPopMatrix();
    glutSwapBuffers();
    }

    void update()
    { //update here
    }

    void reshape (int w, int h)
    {
    glViewport (0, 0, (GLsizei) w, (GLsizei) h);
    glMatrixMode (GL_PROJECTION);
    glLoadIdentity();

    gluPerspective(120.0, (GLfloat)w/(GLfloat)h , 2.0, 3*(sun_radius*4 + planet_radius + 1));

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    gluLookAt(0.0,0.0,1.1*(sun_radius*4 + planet_radius),0.0,0.0,0.0,0.0,1.0,0.0);
    }

    /* completely newbie to graphics as well as
    opengl , so (if any then) pls also make comments
    on how this code can b optimized
    Thanks ,
    Amit
    */

  2. #2
    Super Moderator OpenGL Lord
    Join Date
    Dec 2003
    Location
    Grenoble - France
    Posts
    5,655

    Re: distortion of sphere while rotating...help

    >> gluPerspective(120.0, ...

    As it specifies th fovy, the fovx is likely to be larger (standard monitor is 4:3 aspect ratio).
    As the perpective projection is done, the objets appear distorted when approaching the edges of the screen. This effect is stronger with higher fovs, so you will want to stay below 80 degres for fovx.

    The only way to completely remove this squashing effect is to use a spherical projection, but it is pretty hard.

    To illustrate this see http://wouter.fov120.com/gfxengine/f...e/compare.html especially the part about 150 and 170 degrees fov : look at the green armor. The spherical projection (here called 'fish eye') does keep the aspect of objects, whereas the standard planar projection distord them a lot.

  3. #3
    Super Moderator OpenGL Guru dorbie's Avatar
    Join Date
    Jul 2000
    Location
    Bay Area, CA, USA
    Posts
    4,388

    Re: distortion of sphere while rotating...help

    Spherical is interesting but also wrong for all views. Displays are flat rectangles and a frustum matching the viewing eyepoint w.r.t. the display will be correct as you originally observed. The distortion of the sphere is perfectly normal, but with a fisheye view it will also be distorted in a different way. The only way to make things look correct is to match the projection geometry with the viewing geometry of the display and for a flat rectangular display that requires a simple frustum, and in your case it's probably just a matter of reducing the field of view.

  4. #4
    Junior Member Newbie
    Join Date
    Jun 2004
    Posts
    2

    Re: distortion of sphere while rotating...help

    Hi,

    thanks to both of you for suggestions. i tried
    reducing the field and distortion reduced (though
    it's still there). will check about spherical
    projection .

    regards,
    Amit

Posting Permissions

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