include/scene.h
branchpyrit
changeset 79 062b1c4143f7
parent 78 9569e9f35374
child 80 907929fa9b59
equal deleted inserted replaced
78:9569e9f35374 79:062b1c4143f7
    79 		return Ray(eye, dir);
    79 		return Ray(eye, dir);
    80 	};
    80 	};
    81 };
    81 };
    82 
    82 
    83 /**
    83 /**
    84  * axis-aligned bounding box
       
    85  */
       
    86 class BBox
       
    87 {
       
    88 public:
       
    89 	Vector3 L;
       
    90 	Vector3 H;
       
    91 	BBox(): L(), H() {};
       
    92 	BBox(const Vector3 aL, const Vector3 aH): L(aL), H(aH) {};
       
    93 	Float w() { return H.x-L.x; };
       
    94 	Float h() { return H.y-L.y; };
       
    95 	Float d() { return H.z-L.z; };
       
    96 	bool intersect(const Ray &ray, Float &a, Float &b);
       
    97 };
       
    98 
       
    99 /**
       
   100  * light object
    84  * light object
   101  */
    85  */
   102 class Light
    86 class Light
   103 {
    87 {
   104 public:
    88 public:
   112 		pos(position), colour(acolour), cast_shadows(true) {};
    96 		pos(position), colour(acolour), cast_shadows(true) {};
   113 	void castShadows(bool cast) { cast_shadows = cast; };
    97 	void castShadows(bool cast) { cast_shadows = cast; };
   114 };
    98 };
   115 
    99 
   116 /**
   100 /**
   117  * texture
   101  * axis-aligned bounding box
   118  */
   102  */
   119 class Texture
   103 class BBox
   120 {
   104 {
   121 public:
   105 public:
   122 	virtual ~Texture() {};
   106 	Vector3 L;
   123 	virtual Colour evaluate(Vector3 point) = 0;
   107 	Vector3 H;
   124 };
   108 	BBox(): L(), H() {};
   125 
   109 	BBox(const Vector3 aL, const Vector3 aH): L(aL), H(aH) {};
   126 /**
   110 	Float w() { return H.x-L.x; };
   127  * material
   111 	Float h() { return H.y-L.y; };
   128  */
   112 	Float d() { return H.z-L.z; };
   129 class Material
   113 	bool intersect(const Ray &ray, Float &a, Float &b);
   130 {
       
   131 public:
       
   132 	Colour colour;
       
   133 	Texture *texture;
       
   134 	Float ambient, diffuse, specular, shininess; // Phong constants
       
   135 	Float reflectivity; // how much reflective is the surface
       
   136 	Float transmissivity, refract_index; // part of light which can be refracted; index of refraction
       
   137 	bool smooth; // triangle smoothing
       
   138 
       
   139 	Material(const Colour &acolour): colour(acolour), texture(NULL), smooth(false)
       
   140 	{
       
   141 		ambient = 0.2;
       
   142 		diffuse = 0.8;
       
   143 		specular = 0.2;
       
   144 		shininess = 0.5;
       
   145 		reflectivity = 0.2;
       
   146 		transmissivity = 0.0;
       
   147 		refract_index = 1.3;
       
   148 	}
       
   149 
       
   150 	void setPhong(const Float amb, const Float dif, const Float spec, const Float shin)
       
   151 		{ ambient = amb; diffuse = dif; specular = spec; shininess = shin; };
       
   152 	void setReflectivity(const Float refl) { reflectivity = refl; };
       
   153 	void setTransmissivity(const Float trans, const Float rindex)
       
   154 		{ transmissivity = trans; refract_index = rindex; };
       
   155 	void setSmooth(bool sm) { smooth = sm; };
       
   156 };
   114 };
   157 
   115 
   158 #endif
   116 #endif