equal
deleted
inserted
replaced
105 protected: |
105 protected: |
106 Vector center; |
106 Vector center; |
107 Float invsize; |
107 Float invsize; |
108 public: |
108 public: |
109 TextureMap(const Vector &acenter, const Float &size): |
109 TextureMap(const Vector &acenter, const Float &size): |
110 center(acenter), invsize(1./size) {}; |
110 center(acenter), invsize(1.0f/size) {}; |
111 virtual ~TextureMap() {}; |
111 virtual ~TextureMap() {}; |
112 virtual void map(const Vector &point, Float &u, Float &v) = 0; |
112 virtual void map(const Vector &point, Float &u, Float &v) = 0; |
113 }; |
113 }; |
114 |
114 |
115 /** |
115 /** |
236 Texture2D(tmap), pixmap(image) {}; |
236 Texture2D(tmap), pixmap(image) {}; |
237 Colour evaluate(const Vector &point) |
237 Colour evaluate(const Vector &point) |
238 { |
238 { |
239 Float u,v; |
239 Float u,v; |
240 map->map(point, u,v); |
240 map->map(point, u,v); |
241 u = u - 0.5; |
241 u = u - 0.5f; |
242 u -= floor(u); |
242 u -= floor(u); |
243 v = -(v - 0.5); |
243 v = -(v - 0.5f); |
244 v -= floor(v); |
244 v -= floor(v); |
245 return pixmap->get((int)(u*pixmap->getWidth()), (int)(v*pixmap->getHeight())); |
245 return pixmap->get((int)(u*pixmap->getWidth()), (int)(v*pixmap->getHeight())); |
246 }; |
246 }; |
247 }; |
247 }; |
248 |
248 |
257 Texture2D(tmap), colourmap(cmap) {}; |
257 Texture2D(tmap), colourmap(cmap) {}; |
258 Colour evaluate(const Vector &point) |
258 Colour evaluate(const Vector &point) |
259 { |
259 { |
260 Float u,v, val; |
260 Float u,v, val; |
261 map->map(point, u,v); |
261 map->map(point, u,v); |
262 val = 0.5*(round(u - floor(u)) + round(v - floor(v))); |
262 val = 0.5f*(floor(0.5f + u - floor(u)) + floor(0.5f + v - floor(v))); |
263 return colourmap->map(val); |
263 return colourmap->map(val); |
264 }; |
264 }; |
265 }; |
265 }; |
266 |
266 |
267 /** |
267 /** |
297 Float transmissivity, refract_index; // part of light which can be refracted; index of refraction |
297 Float transmissivity, refract_index; // part of light which can be refracted; index of refraction |
298 bool smooth; // triangle smoothing |
298 bool smooth; // triangle smoothing |
299 |
299 |
300 Material(const Colour &acolour): colour(acolour), texture(NULL), smooth(false) |
300 Material(const Colour &acolour): colour(acolour), texture(NULL), smooth(false) |
301 { |
301 { |
302 ambient = 0.2; |
302 ambient = 0.2f; |
303 diffuse = 0.8; |
303 diffuse = 0.8f; |
304 specular = 0.2; |
304 specular = 0.2f; |
305 shininess = 0.5; |
305 shininess = 0.5f; |
306 reflectivity = 0.2; |
306 reflectivity = 0.2f; |
307 transmissivity = 0.0; |
307 transmissivity = 0.0f; |
308 refract_index = 1.3; |
308 refract_index = 1.3f; |
309 } |
309 } |
310 |
310 |
311 void setPhong(const Float amb, const Float dif, const Float spec, const Float shin) |
311 void setPhong(const Float amb, const Float dif, const Float spec, const Float shin) |
312 { ambient = amb; diffuse = dif; specular = spec; shininess = shin; }; |
312 { ambient = amb; diffuse = dif; specular = spec; shininess = shin; }; |
313 void setReflectivity(const Float refl) { reflectivity = refl; }; |
313 void setReflectivity(const Float refl) { reflectivity = refl; }; |