#ifndef _DEFS_H_ #define _DEFS_H_ //#define bDebug #include #include "functions.h" using namespace std; typedef struct { double r,g,b; } RGB; typedef struct Vector{ public: double x = NAN, y = NAN, z = NAN; struct Vector operator+(Vector &other); struct Vector operator-(Vector &other); struct Vector operator*(Vector &other); struct Vector operator/(Vector &other); struct Vector operator*(int &other); struct Vector operator*(double &other); } Vector; typedef Vector Point; typedef struct { Point center; double intensity; } Light; typedef struct MaterialAttributes{ double k_dr, k_dg, k_db; //diffuse properties, rgb double k_ar, k_ag, k_ab; //ambient properties, rgb double k_s; //specular properties, rgb same double n_spec; //specular exponent } MaterialAttributes; std::ostream &operator<< ( std::ostream &ofs, struct MaterialAttributes m ); class Ray { public: Point origin = Point(); Vector direction = Vector(); Ray() {} Ray (Point start, Point end); double length = NAN; Ray operator+(Ray &other); Ray operator-(Ray &other); }; class Primitive { public: MaterialAttributes attrib; virtual double intersectsWith(Ray)=0; virtual bool intersectsWithSelf(Point p, Light l, Point v)=0; virtual Vector normal(Point p, Light l)=0; virtual void printName() { printf("I am a primitive. Wheeee"); } }; class Sphere : public Primitive { public: Point center; double radius; double intersectsWith(Ray ray); bool intersectsWithSelf(Point p, Light l, Point v); void printName(); Vector normal(Point p); Vector normal(Point p, Light l); friend std::ostream &operator<< ( std::ostream &ofs, Sphere s ); }; class Triangle : public Primitive { public: Point a1, a2, a3; double intersectsWith(Ray ray); bool intersectsWithSelf(Point p, Light l, Point v); void printName(); Vector normal(Point p, Light l); Vector normal(Point p); friend std::ostream &operator<< ( std::ostream &ofs, Triangle t ); }; /* ------------ image class ------------ */ class image { int xsize,ysize; // resolution RGB *rgb; // pixel intensities public: image ( int m, int n ); // allocates image of specified size RGB &pixel ( int i, int j ); // access to a specific pixel friend std::ostream &operator<< ( std::ostream &ofs, image i ); // dumps image as a ppm file }; /* ------------- RayTracer ------------ */ class RayTracer { public: int m, n; // specify the output image size, assuming m x n Point e, l; // viewpoint e, lower left corner l Vector h, v; // vectors vertical and horizontal edges Light light; // Light source double ambience; // Ambient light intensity int numPrimitives; // Number of Primitives std::vector primitives; void getPixelAt(int x, int y, RGB& pixel); private: //double length(Point a, Point b); }; /*void printObject(Point p);*/ void printObject(Vector v); void printObject(int i); void printObject(double f); void printObject(Light l); void printObject(MaterialAttributes attrib); void scanInput(Point &point, char* input); void scanInput(MaterialAttributes &attrib, char* input); void scanInput(vector &primitives, int numPrimitives, char* input); void scanInput(Vector &v, char* input); void scanInput(Light &light, char* input); double length(Point p, Point p2); double length(Vector p); double dot(Vector,Vector); #endif