include/material.h
branchpyrit
changeset 81 9dbb9c8c115b
parent 80 907929fa9b59
child 82 930a2d3ecaed
equal deleted inserted replaced
80:907929fa9b59 81:9dbb9c8c115b
   221 public:
   221 public:
   222 	Texture2D(TextureMap *amap): map(amap) {};
   222 	Texture2D(TextureMap *amap): map(amap) {};
   223 };
   223 };
   224 
   224 
   225 /**
   225 /**
       
   226  * pixmap for image texture
       
   227  */
       
   228 class Pixmap
       
   229 {
       
   230 	Colour *data;
       
   231 	int w,h;
       
   232 public:
       
   233 	Pixmap(): data(NULL), w(0), h(0) {};
       
   234 	Pixmap(Float *adata, int aw, int ah):
       
   235 		data((Colour*)(adata)), w(aw), h(ah) {};
       
   236 	void setData(Float *adata, int aw, int ah)
       
   237 		{ data = (Colour*)adata; w = aw; h = ah; };
       
   238 	Colour get(int x, int y) { return data[y*w + x]; };
       
   239 	int getWidth() { return w; };
       
   240 	int getHeight() { return h; };
       
   241 };
       
   242 
       
   243 /**
       
   244  * 2D image texture
       
   245  */
       
   246 class ImageTexture: public Texture2D
       
   247 {
       
   248 	Pixmap *pixmap;
       
   249 public:
       
   250 	ImageTexture(TextureMap *tmap, Pixmap *image):
       
   251 		Texture2D(tmap), pixmap(image) {};
       
   252 	Colour evaluate(const Vector3 &point)
       
   253 	{
       
   254 		Float u,v;
       
   255 		map->map(point, u,v);
       
   256 		u = u - 0.5;
       
   257 		u -= floor(u);
       
   258 		v = -(v - 0.5);
       
   259 		v -= floor(v);
       
   260 		return pixmap->get(u*pixmap->getWidth(), v*pixmap->getHeight());
       
   261 	};
       
   262 };
       
   263 
       
   264 /**
   226  * 2D checkers texture
   265  * 2D checkers texture
   227  */
   266  */
   228 class CheckersTexture: public Texture2D
   267 class CheckersTexture: public Texture2D
   229 {
   268 {
   230 	ColourMap *colourmap;
   269 	ColourMap *colourmap;