#ifndef rdo_camera_H #define rdo_camera_H /* Representation of a virtual camera, and persective projetion functions. */ #define rdo_camera_H_COPYRIGHT "Copyright © 2008 Danillo Pereira and J. Stolfi, UNICAMP" /* Last edited on 2008-08-15 17:51:03 by stolfi */ #define _GNU_SOURCE #include #include #include #include #include #include typedef struct camera_t { /* Primary parameters: */ point3_t eye; /* Scene coordinates of the camera's ``pinhole''. */ point3_t scene; /* Scene coordinates of an aim point in the scene. */ vector3_t sky; /* A vector perpendicular to the camera's horizontal axis. */ double dist; /* Focal distance, between pinhole and image plane (scene units). */ double radius; /* Radius of image sensor in image plane (scene units). */ /* Derived parameters (computed from the primary ones): */ point3_t ctr; /* Center of sensor array on imaging plane. */ vector3_t r; /* Unit vector of camera's horiz axis. */ vector3_t s; /* Unit vector of camera's vertical axis. */ vector3_t t; /* Unit vector of camera's optical axis. */ } camera_t; /* Description of a virtual pinhole camera. Nominally, the pinhole is located at the point {eye}, and the camera is aimed at an arbitrary point of interest {scene} in the scene. The optical axis is the line from the {scene} to the {eye}, whose direction {t} points towards the {eye}. The camera's horizontal axis is perpendicular to the optical axis and to the {sky} vector; its direction {r} and points to the virtual photographer's right. The camera's vertical axis is perpendicular to the other two axes, and its direction {s} points up as sen by the photographer. The imaging plane is located at distance {dist} AHEAD of the pinhole, and the virtual image sensor array is located on that plane, upright, inscribed in a circle with radius {radius} centered on the point {ctr} where the on the optical axis. */ void rdo_camera_write(FILE *wr, camera_t *cam); /* Writes the description of the camera {cam} to file {wr}. Writes only the primary parameters. */ camera_t *rdo_camera_read(FILE *rd); /* Reads a camera description from {rd}. Reads only the primary parameters, and recomputes the derived parameters. */ void rdo_camera_free(camera_t *cam); /* Reclaims the storage used by the camera (INCLUING the record {*cam} itself). */ void rdo_camera_find_image_axes(camera_t *cam); /* Recomputes the scene coordinates {cam->ctr} of the center of the sensor array, and the unit direction vectors {cam->r,cam->s,cam->t} of the camera {cam}, from the user-given data {eye,scene,sky,dist}. */ void rdo_camera_compute_ray_direction(double x, double y, camera_t *cam, vector3_t *dir); /* Computes the direction {*dir} of the ray that goes from the camera's pinhole point through the point on the projection plane with projection plane coordinates {x,y}. The projection plane coordinate system has the origin on the optical axis, with X pointing left and Y pointing UP, scaled so that the camera's sensor array has radius 1.0. */ void rdo_camera_project_point(point3_t *p, camera_t *cam, double *xP, double *yP); /* Computes the projection plane coordinates {*xP,*yP} of the projection of point {p} on the imaging plane of camera {cam}. The projection plane coordinate system has the origin on the optical axis, with X pointing left and Y pointing UP, scaled so that the camera's sensor array has radius 1.0. */ #endif