Jump to content
  • Advertisement
Sign in to follow this  
george7378

Creating a camera for my ray tracer

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

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 :)

Share this post


Link to post
Share on other sites
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 :)

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
Share on other sites

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

Edited by Gerretke

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!