• Create Account

## Creating a camera for my ray tracer

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

4 replies to this topic

### #1george7378  Members

1419
Like
0Likes
Like

Posted 21 February 2014 - 10:56 AM

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

### #2Krypt0n  Members

4529
Like
3Likes
Like

Posted 21 February 2014 - 11:07 AM

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

### #3 fir   Members

-464
Like
3Likes
Like

Posted 21 February 2014 - 11:31 AM

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)

Edited by fir, 21 February 2014 - 11:35 AM.

### #4george7378  Members

1419
Like
0Likes
Like

Posted 21 February 2014 - 06:05 PM

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?

### #5Gerretke  Members

114
Like
1Likes
Like

Posted 28 February 2014 - 10:55 AM

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

Edited by Gerretke, 28 February 2014 - 10:55 AM.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.