include/material.h
branchpyrit
changeset 93 96d65f841791
parent 92 9af5c039b678
child 94 4c8abb8977dc
equal deleted inserted replaced
92:9af5c039b678 93:96d65f841791
    60  * linear colour map
    60  * linear colour map
    61  * maps value lineary between two colours
    61  * maps value lineary between two colours
    62  */
    62  */
    63 class LinearColourMap: public ColourMap
    63 class LinearColourMap: public ColourMap
    64 {
    64 {
    65 	Colour col,cdiff;
    65 	Colour col, cdiff;
    66 public:
    66 public:
    67 	LinearColourMap(const Colour &clow, const Colour &chigh):
    67 	LinearColourMap(const Colour &clow, const Colour &chigh):
    68 		col(clow), cdiff(chigh-clow) {};
    68 		col(clow), cdiff(chigh-clow) {};
    69 	Colour map(const Float &val) { return col + cdiff*val; };
    69 	Colour map(const Float &val) { return col + cdiff*val; };
    70 };
    70 };
   191 	CylinderMap(const Vector &acenter, const Float &size):
   191 	CylinderMap(const Vector &acenter, const Float &size):
   192 		TextureMap(acenter, size) {};
   192 		TextureMap(acenter, size) {};
   193 	void map(const Vector &point, Float &u, Float &v)
   193 	void map(const Vector &point, Float &u, Float &v)
   194 	{
   194 	{
   195 		const Vector p = point - center;
   195 		const Vector p = point - center;
   196 		u = ( M_PI + atan2(p.z, p.x) ) * invsize;
   196 		u = ( PI + atan2(p.z, p.x) ) * invsize;
   197 		v = p.y * invsize;
   197 		v = p.y * invsize;
   198 	};
   198 	};
   199 };
   199 };
   200 
   200 
   201 /**
   201 /**
   207 	SphereMap(const Vector &acenter, const Float &size):
   207 	SphereMap(const Vector &acenter, const Float &size):
   208 		TextureMap(acenter, size) {};
   208 		TextureMap(acenter, size) {};
   209 	void map(const Vector &point, Float &u, Float &v)
   209 	void map(const Vector &point, Float &u, Float &v)
   210 	{
   210 	{
   211 		const Vector p = point - center;
   211 		const Vector p = point - center;
   212 		u = ( M_PI + atan2(p.z, p.x) ) * invsize;
   212 		u = ( PI + atan2(p.z, p.x) ) * invsize;
   213 		v = acos(p.y / p.mag()) * invsize;
   213 		v = acos(p.y / p.mag()) * invsize;
   214 	};
   214 	};
   215 };
   215 };
   216 
   216 
   217 /**
   217 /**
   267 /**
   267 /**
   268  * 3D perlin cloud texture
   268  * 3D perlin cloud texture
   269  */
   269  */
   270 class CloudTexture: public Texture
   270 class CloudTexture: public Texture
   271 {
   271 {
       
   272 	ColourMap *colourmap;
   272 	Float detail;
   273 	Float detail;
   273 	ColourMap *colourmap;
       
   274 public:
   274 public:
   275 	CloudTexture(const Float &adetail, ColourMap *cmap):
   275 	CloudTexture(const Float &adetail, ColourMap *cmap):
   276 		detail(adetail), colourmap(cmap) {};
   276 		colourmap(cmap), detail(adetail) {};
   277 	Colour evaluate(const Vector &point)
   277 	Colour evaluate(const Vector &point)
   278 	{
   278 	{
   279 		Float sum = 0.0;
   279 		Float sum = 0.0;
   280 		for (int i = 1; i < detail; i++)
   280 		for (int i = 1; i < detail; i++)
   281 			sum += fabs(perlin(point.x*i, point.y*i, point.z*i))/i;
   281 			sum += fabs(perlin(point.x*i, point.y*i, point.z*i))/i;
   293 	Colour colour;
   293 	Colour colour;
   294 	Texture *texture;
   294 	Texture *texture;
   295 	Float ambient, diffuse, specular, shininess; // Phong constants
   295 	Float ambient, diffuse, specular, shininess; // Phong constants
   296 	Float reflectivity; // how much reflective is the surface
   296 	Float reflectivity; // how much reflective is the surface
   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 	int 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.2f;
   302 		ambient = 0.2f;
   303 		diffuse = 0.8f;
   303 		diffuse = 0.8f;
   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; };
   314 	void setTransmissivity(const Float trans, const Float rindex)
   314 	void setTransmissivity(const Float trans, const Float rindex)
   315 		{ transmissivity = trans; refract_index = rindex; };
   315 		{ transmissivity = trans; refract_index = rindex; };
   316 	void setSmooth(bool sm) { smooth = sm; };
   316 	void setSmooth(int sm) { smooth = sm; };
   317 	void setTexture(Texture *tex) { texture = tex; };
   317 	void setTexture(Texture *tex) { texture = tex; };
   318 };
   318 };
   319 
   319 
   320 #endif
   320 #endif