Ray Tracing problems

Started by
-1 comments, last by Forkbomb 15 years, 5 months ago
Hi All! This is my first time posting on GameDev, quite exciting! I very recently got into computer graphics and am using OpenGL to do my learning. At this point I'm working on a ray tracer and am getting some strange behavior, I think. So here's the code I'm working with (it's the display function hooked to glutDisplayFunc):

void display(void)
{
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(30,128/128,1.0,150);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    gluLookAt(50,50,50,0,10,0,0,1,0);

    GLdouble projection[16];
    GLdouble modelview[16];
    GLint viewport[4];
    GLdouble objx,objy,objz;

    glGetDoublev(GL_MODELVIEW_MATRIX,modelview);
    glGetDoublev(GL_PROJECTION_MATRIX,projection);
    glGetIntegerv(GL_VIEWPORT,viewport);

    for (int x = 0; x < 128; x++)
    {
        for (int y = 0; y < 128; y++)
        {
            gluUnProject(x,y,0,modelview,projection,viewport,&objx,&objy,&objz);
            cout << "pixel (x,y=" << x << "," << y << ") => " << objx << " " << objy << " " << objz << endl;
        }
    }

    glFlush();
}
I'm using gluUnProject to get my pixel coordinates in object space so I can compute my ray vector. The picture will be 128x128 pixels. My question is - does this look right as far as correctly using gluUnProject to get the pixel coordinates? All of my objx, objy, and objz values come out to 49.xxxx. The numbers seemed strange to me because if I combined these numbers with that of my camera coordinates then it would produce very similar vectors for all of my rays. I guess I'm just really unsure of myself since I'm so new at this, but I'm hoping to get some positive feedback from all you pros out there :) Thanks for taking the time to read. Regards, Forkbomb [Edited by - Forkbomb on December 6, 2008 1:30:54 PM]

This topic is closed to new replies.

Advertisement