Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


We're also offering banner ads on our site from just $5! 1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


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.

  • You cannot reply to this topic
4 replies to this topic

#1 george7378   Members   -  Reputation: 1244

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



Sponsor:

#2 Krypt0n   Crossbones+   -  Reputation: 2600

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   -  Reputation: -460

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.


#4 george7378   Members   -  Reputation: 1244

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?



#5 Gerretke   Members   -  Reputation: 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 smile.png


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.



PARTNERS