Creating a camera for my ray tracer

Started by
3 comments, last by Gerretke 10 years, 1 month ago

Hi everyone,

I'm trying to create a class to manage my camera for my ray tracer. I've got field of view, aspect ratio, a look direction, an up direction and a right direction, but I don't know how to translate this into ray directions which I can shoot from my camera position - can anyone help? I think some example code would help me best!

Thanks :)

Advertisement

dir=right*x+up*y+lookdir;

x and y are -1 to 1, mapped from the screen pixel coordinate. if you want to apply the fov, simply multiply x and y by the horizontal respectably vertical fov.

yes, it's that easy to start :)

i was using

       float x_ = ((float)(-pixels_x/2 + x))/pixels_x;
       float y_ = ((float)(-pixels_y/2 + y))/pixels_y;
 
        float dx =  x_*physical_window_width;
        float dy =  y_*physical_window_height;
        float dz =  z_physical_distance_to_screen;
 
        ray.origin.x = cameraPos.x + cameraLeft.x*dx + cameraUp.x*dy;
        ray.origin.y = cameraPos.y + cameraLeft.y*dx + cameraUp.y*dy;
        ray.origin.z = cameraPos.z + cameraLeft.z*dx + cameraUp.z*dy;
 
        ray.direction.x = cameraLeft.x*dx + cameraUp.x*dy + cameraDir.x*dz;
        ray.direction.y = cameraLeft.y*dx + cameraUp.y*dy + cameraDir.y*dz;
        ray.direction.z = cameraLeft.z*dx + cameraUp.z*dy + cameraDir.z*dz;
 
        normalize(&ray.direction);
ps could your maybe say a bit about your intersection routines or lightning (I mean pixel color) calculation routine .. i wonder how people do that (though im f**n tired today)

OK, it's working :) I'm also interested in the proper way to shade pixels - do people use the phong model? What's the proper way to combine refraction, reflection and surface colours?

Hey this is a great topic, I was searching for the something thans for your help smile.png

This topic is closed to new replies.

Advertisement