#include #include #include #include #ifdef WIN32 #include #else #include #include #endif class Point { public: double x,y,z; }; class Ray { public: Point p,v; }; class Cylinder { public: Point centre; double radius,height; }; class Camera { public: double nearZ; double leftX,rightX; double bottomY,topY; int width,height; }; class Pixel { public: int x,y; }; Ray *make_ray(Camera& cam, Pixel& pix); Point *ray_cylinder_intersect(Ray *ray, Cylinder &cyl); Ray *ray; Cylinder cyl; Camera cam; Pixel *pixels; int nPixels; void readData(char *camFile, char *cylFile, char *pixFile) { ifstream inCam; ifstream inCyl; ifstream inPix; inCam.open(camFile); inCam >> cam.nearZ >> cam.leftX >> cam.rightX >> cam.bottomY >> cam.topY >> cam.width >> cam.height; inCam.close(); inCyl.open(cylFile); inCyl >> cyl.centre.x >> cyl.centre.y >> cyl.centre.z >> cyl.radius >> cyl.height; inCyl.close(); inPix.open(pixFile); inPix >> nPixels; pixels = new Pixel[nPixels]; for (int i=0; i> pixels[i].x >> pixels[i].y; } inPix.close(); } int main (int argc, char *argv[]) { Point *hitpoint; if (argc != 4) { cerr << "Usage:" << endl << "intersect [camera-file] [cylinder-file] [pixel-file]" << endl; exit(1); } readData(argv[1], argv[2], argv[3]); for (int i=0; ix,hitpoint->y,hitpoint->z); } return 0; } /************************************************************** * The code that you must change starts HERE. */ Ray *make_ray(Camera& cam, Pixel& pix) { Ray *ray = new Ray; /* * These are arbitrary values. * You'll have to set all of them correctly yourself. */ ray->p.x = 0.0; ray->p.y = 0.0; ray->p.z = 0.0; ray->v.x = 0.0; ray->v.y = 0.0; ray->v.z = 1.0; return ray; } /* * This is also incorrect. You have to change it to return * NULL if there is no intersection, and to return a new hit point if * there IS an intersection. */ Point *ray_cylinder_intersect(Ray *ray, Cylinder& cyl) { return NULL; }