#ifndef OBJECT3D_H #define OBJECT3D_H #include "Algebra.h" #include "Material.h" #include #include #include //#include #include "glut.h" #include using namespace std; class Object3D { public: Object3D(Vector3DW& center, Vector3DW& xe, Vector3DW& ye, Vector3DW& ze); virtual bool rayIntersect( Vector3DW& rOrigin, Vector3DW& rDirection, Vector3DW& intersectionPoint, Vector3DW& intersectionNormal, real& intersectionDistance, Color& color, real& ka, real& kd, real& ks) = 0; virtual void drawOpenGL(){}; virtual void generateMatrices(); virtual void setPosition(Vector3DW& pos); virtual void translate(real dx, real dy, real dz); protected: Vector3DW center_; Vector3DW xe_; Vector3DW ye_; Vector3DW ze_; Matrix4x4 T; }; class ObjectComposite : public Object3D { public: ObjectComposite(Vector3DW& center, Vector3DW& xe, Vector3DW& ye, Vector3DW& ze); ~ObjectComposite(); virtual bool rayIntersect( Vector3DW& rOrigin, Vector3DW& rDirection, Vector3DW& intersectionPoint, Vector3DW& intersectionNormal, real& intersectionDistance, Color& color, real& ka, real& kd, real& ks); virtual void drawOpenGL(); virtual void translate(real dx, real dy, real dz); protected: vector components_; }; class Sphere : public Object3D { public: Sphere(Vector3DW& center, Vector3DW& xe, Vector3DW& ye, Vector3DW& ze, real r, Material* material); real getXC() { return center_.getX(); }; real getYC() { return center_.getY(); }; real getZC() { return center_.getZ(); }; real getRadius() { return r_; }; void setXC(real xc) { center_.setX(xc); }; void setYC(real yc) { center_.setY(yc); }; void setZC(real zc) { center_.setZ(zc); }; void setRadius(real r) { r_ = r; }; bool rayIntersect( Vector3DW& rOrigin, Vector3DW& rDirection, Vector3DW& intersectionPoint, Vector3DW& intersectionNormal, real& intersectionDistance, Color& color, real& ka, real& kd, real& ks); void drawOpenGL(); protected: Material* material_; real r_; }; class Circle : public Object3D { public: Circle(Vector3DW& center, Vector3DW& xe, Vector3DW& ye, Vector3DW& ze, real r, Material* material); bool rayIntersect( Vector3DW& rOrigin, Vector3DW& rDirection, Vector3DW& intersectionPoint, Vector3DW& intersectionNormal, real& intersectionDistance, Color& color, real& ka, real& kd, real& ks); protected: real r_; Material* material_; }; class Cylinder : public Object3D { public: Cylinder(Vector3DW& center, Vector3DW& xe, Vector3DW& ye, Vector3DW& ze, real r, real height, Material* material); bool rayIntersect( Vector3DW& rOrigin, Vector3DW& rDirection, Vector3DW& intersectionPoint, Vector3DW& intersectionNormal, real& intersectionDistance, Color& color, real& ka, real& kd, real& ks); protected: real r_; real height_; Material* material_; }; class Paralelepipedo : public Object3D { public: Paralelepipedo(Vector3DW& center, Vector3DW& xe, Vector3DW& ye, Vector3DW& ze, real dx, real dy, real dz, Material* material); Vector3DW getCenter() { return center_; } Vector3DW getXe() { return xe_; } Vector3DW getYe() { return ye_; } Vector3DW getZe() { return ze_; } real getDX() { return dx_; }; real getDY() { return dy_; }; real getDZ() { return dz_; }; void setCenter(Vector3DW center) { center_ = center; } void setXe(Vector3DW xe) { xe_ = xe; } void setYe(Vector3DW ye) { ye_ = ye; } void setZe(Vector3DW ze) { ze_ = ze; } void setDX(real dx) { dx_ = dx; }; void setDY(real dy) { dy_ = dy; }; void setDZ(real dz) { dz_ = dz; }; bool rayIntersect( Vector3DW& rOrigin, Vector3DW& rDirection, Vector3DW& intersectionPoint, Vector3DW& intersectionNormal, real& intersectionDistance, Color& color, real& ka, real& kd, real& ks); protected: Material* material_; real dx_; real dy_; real dz_; }; class FunctionRevolution : public Object3D { public: FunctionRevolution(Vector3DW& center, Vector3DW& xe, Vector3DW& ye, Vector3DW& ze, Material* material); virtual real f(real x) = 0; virtual real dfdt(real x) = 0; bool rayIntersect( Vector3DW& rOrigin, Vector3DW& rDirection, Vector3DW& intersectionPoint, Vector3DW& intersectionNormal, real& intersectionDistance, Color& color, real& ka, real& kd, real& ks); bool rayIntersectTransformed( Vector3DW& rOrigin, Vector3DW& rDirection, Vector3DW& intersectionPoint, Vector3DW& intersectionNormal, real& intersectionDistance, Color& color, real& ka, real& kd, real& ks); virtual void translate(real dx, real dy, real dz); protected: Material* material_; real ti_; real tf_; real maxRadius_; int num_intervals_; real tolerance_; void generateMatrices(); private: real a_; real b_; real c_; real Oz_; real drz_; Matrix4x4 T; Matrix4x4 T_1; Matrix4x4 R; Matrix4x4 R_1; bool find_t(real ti, real tf, real& t_intersection); }; #endif