# OpenGL Ray Tracing problems

This topic is 3655 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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);
gluPerspective(30,128/128,1.0,150);
glMatrixMode(GL_MODELVIEW);
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]

1. 1
2. 2
3. 3
Rutin
25
4. 4
5. 5
khawk
14

• 11
• 11
• 23
• 10
• 9
• ### Forum Statistics

• Total Topics
633648
• Total Posts
3013116
×