diff options
-rw-r--r-- | libdimension/cameras.c | 11 | ||||
-rw-r--r-- | libdimension/dimension/camera.h | 3 | ||||
-rw-r--r-- | libdimension/raytrace.c | 4 | ||||
-rw-r--r-- | libdimensionxx/camera.cpp | 14 | ||||
-rw-r--r-- | libdimensionxx/dimensionxx/camera.hpp | 4 |
5 files changed, 13 insertions, 23 deletions
diff --git a/libdimension/cameras.c b/libdimension/cameras.c index dfe4708..9e0642f 100644 --- a/libdimension/cameras.c +++ b/libdimension/cameras.c @@ -26,9 +26,7 @@ /* Perspective camera ray callback */ static dmnsn_line dmnsn_perspective_camera_ray_fn(const dmnsn_camera *camera, - const dmnsn_canvas *canvas, - unsigned int x, - unsigned int y); + double x, double y); /* Create a new perspective camera. Rays are aimed from the origin to a screen located on the z = 1 frame, from (-0.5, -0.5) to (0.5, 0.5). Rays are then @@ -73,8 +71,7 @@ dmnsn_set_perspective_camera_trans(dmnsn_camera *camera, dmnsn_matrix T) /* Perspective camera ray callback */ static dmnsn_line dmnsn_perspective_camera_ray_fn(const dmnsn_camera *camera, - const dmnsn_canvas *canvas, - unsigned int x, unsigned int y) + double x, double y) { dmnsn_matrix *trans = camera->ptr; dmnsn_line l; @@ -83,9 +80,7 @@ dmnsn_perspective_camera_ray_fn(const dmnsn_camera *camera, l.x0 = dmnsn_vector_construct(0.0, 0.0, 0.0); /* Aim at the z = 1 plane */ - l.n.x = ((double)x)/(canvas->x - 1) - 0.5; - l.n.y = ((double)y)/(canvas->y - 1) - 0.5; - l.n.z = 1.0; + l.n = dmnsn_vector_construct(x - 0.5, y - 0.5, 1.0); return dmnsn_matrix_line_mul(*trans, l); } diff --git a/libdimension/dimension/camera.h b/libdimension/dimension/camera.h index 3e6da4f..5e7b253 100644 --- a/libdimension/dimension/camera.h +++ b/libdimension/dimension/camera.h @@ -30,8 +30,7 @@ typedef struct dmnsn_camera dmnsn_camera; /* Camera callback types */ typedef dmnsn_line dmnsn_camera_ray_fn(const dmnsn_camera *camera, - const dmnsn_canvas *canvas, - unsigned int x, unsigned int y); + double x, double y); struct dmnsn_camera { /* Callback functions */ diff --git a/libdimension/raytrace.c b/libdimension/raytrace.c index 470af4f..df61d6b 100644 --- a/libdimension/raytrace.c +++ b/libdimension/raytrace.c @@ -213,7 +213,9 @@ dmnsn_raytrace_scene_impl(dmnsn_progress *progress, dmnsn_scene *scene, if (scene->quality >= DMNSN_RENDER_OBJECTS) { /* Get the ray corresponding to the (x,y)'th pixel */ - ray = (*scene->camera->ray_fn)(scene->camera, scene->canvas, x, y); + ray = (*scene->camera->ray_fn)(scene->camera, + ((double)x)/(scene->canvas->x - 1), + ((double)y)/(scene->canvas->y - 1)); /* Shoot a ray */ color = dmnsn_raytrace_shoot(scene, color, ray); } diff --git a/libdimensionxx/camera.cpp b/libdimensionxx/camera.cpp index 3536e54..d483ba3 100644 --- a/libdimensionxx/camera.cpp +++ b/libdimensionxx/camera.cpp @@ -32,9 +32,9 @@ namespace Dimension // Return the result of the dmnsn_camera*'s ray callback Line - Camera::ray(const Canvas& canvas, unsigned int x, unsigned int y) + Camera::ray(double x, double y) { - return Line((*dmnsn()->ray_fn)(dmnsn(), canvas.dmnsn(), x, y)); + return Line((*dmnsn()->ray_fn)(dmnsn(), x, y)); } // Return the wrapped camera @@ -91,16 +91,10 @@ namespace Dimension // Custom camera callbacks namespace { dmnsn_line - ray_fn(const dmnsn_camera *camera, const dmnsn_canvas *canvas, - unsigned int x, unsigned int y) + ray_fn(const dmnsn_camera *camera, double x, double y) { Custom_Camera* ccamera = reinterpret_cast<Custom_Camera*>(camera->ptr); - // Yes the const_cast is ugly, but there's no other way because C++ - // doesn't have `const' constructors. Luckily const Camera's treat their - // dmnsn_camera* as a const dmnsn_camera*. - return ccamera->ray( - Canvas(const_cast<dmnsn_canvas*>(canvas)), x, y - ).dmnsn(); + return ccamera->ray(x, y).dmnsn(); } } diff --git a/libdimensionxx/dimensionxx/camera.hpp b/libdimensionxx/dimensionxx/camera.hpp index 0f61435..81952d1 100644 --- a/libdimensionxx/dimensionxx/camera.hpp +++ b/libdimensionxx/dimensionxx/camera.hpp @@ -33,7 +33,7 @@ namespace Dimension virtual ~Camera(); // Camera callback - virtual Line ray(const Canvas& canvas, unsigned int x, unsigned int y); + virtual Line ray(double x, double y); // Shallow-copy a derived camera virtual Camera* copy() const = 0; @@ -70,7 +70,7 @@ namespace Dimension Custom_Camera(); virtual ~Custom_Camera(); - virtual Line ray(const Canvas& canvas, unsigned int x, unsigned int y) = 0; + virtual Line ray(double x, double y) = 0; }; // Array_Element specialization |