mirror of
https://github.com/ssloy/tinyraytracer.git
synced 2025-09-03 02:53:17 +02:00
nicer expression for the ray direction
This commit is contained in:
@@ -81,3 +81,4 @@ template <size_t DIM, typename T> std::ostream& operator<<(std::ostream& out, co
|
||||
return out ;
|
||||
}
|
||||
#endif //__GEOMETRY_H__
|
||||
|
||||
|
@@ -127,9 +127,9 @@ void render(const std::vector<Sphere> &spheres, const std::vector<Light> &lights
|
||||
#pragma omp parallel for
|
||||
for (size_t j = 0; j<height; j++) {
|
||||
for (size_t i = 0; i<width; i++) {
|
||||
float x = (2*(i + 0.5)/(float)width - 1)*tan(fov/2.)*width/(float)height;
|
||||
float y = -(2*(j + 0.5)/(float)height - 1)*tan(fov/2.);
|
||||
Vec3f dir = Vec3f(x, y, -1).normalize();
|
||||
float x = (i + 0.5) - width/2.;
|
||||
float y = -(j + 0.5) + height/2.; // flips the image at the same time
|
||||
Vec3f dir = Vec3f(x, y, -height/(2.*tan(fov/2.))).normalize();
|
||||
framebuffer[i+j*width] = cast_ray(Vec3f(0,0,0), dir, spheres, lights);
|
||||
}
|
||||
}
|
||||
@@ -169,3 +169,4 @@ int main() {
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user