--- a/ccdemos/textures.cc Wed Apr 23 10:38:33 2008 +0200
+++ b/ccdemos/textures.cc Wed Apr 23 14:39:33 2008 +0200
@@ -9,137 +9,6 @@
Float lx, ly, lz, cf;
-
-/*class CloudTexture: public Texture
-{
- Vector3 centre;
-public:
- Colour evaluate(Vector3 point)
- {
- Float sum = 0.0;
- for (int i = 1; i < 5; i++)
- sum += fabsf(perlin(point.x*i, point.y*i, point.z*i))/i;
- Float value = sinf(point.x + sum)/2 + 0.5;
- return Colour(value, value*0.5, value*0.5);
- };
-};*/
-
-void texture2D(Float u, Float v, Float &r, Float &g, Float &b)
-{
- // checkers
- r = fabs((int)(u*4.2)%2 + (int)(v*4.2)%2 - 1);
- g=r; b=r;
-}
-
-class PlanarMapTexture: public Texture
-{
- Vector3 centre;
-public:
- PlanarMapTexture(Vector3 acentre): centre(acentre) {};
- Colour evaluate(Vector3 point)
- {
- point = point - centre;
- Float u = 1000+point.x;
- Float v = 1000+point.y;
- Float r,g,b;
- texture2D(u,v, r,g,b);
- return Colour(r, g, b);
- };
-};
-
-class CubicMapTexture: public Texture
-{
- Vector3 centre;
-public:
- CubicMapTexture(Vector3 acentre): centre(acentre) {};
- Colour evaluate(Vector3 point)
- {
- point = point - centre;
- Float u,v;
- if (fabs(point.x) > fabs(point.y))
- {
- if (fabs(point.x) > fabs(point.z))
- {
- if (point.x < 0)
- u = -point.y;
- else
- u = point.y;
- v = point.z;
- }
- else
- {
- if (point.z < 0)
- u = -point.x;
- else
- u = point.x;
- v = point.y;
- }
- }
- else
- {
- if (fabs(point.y) > fabs(point.z))
- {
- if (point.y < 0)
- u = -point.x;
- else
- u = point.x;
- v = point.z;
- }
- else
- {
- if (point.z < 0)
- u = -point.x;
- else
- u = point.x;
- v = point.y;
- }
- }
- u += 1000;
- v += 1000;
- Float r,g,b;
- texture2D(u,v, r,g,b);
- return Colour(r, g, b);
- };
-};
-
-class CylinderMapTexture: public Texture
-{
- Vector3 centre;
-public:
- CylinderMapTexture(Vector3 acentre): centre(acentre) {};
- Colour evaluate(Vector3 point)
- {
- point = point - centre;
-
- Float u,v;
- v = 1000+point.y;
- u = M_PI + atan2(point.z, point.x);
-
- Float r,g,b;
- texture2D(u,v, r,g,b);
- return Colour(r, g, b);
- };
-};
-
-class SphereMapTexture: public Texture
-{
- Vector3 centre;
-public:
- SphereMapTexture(Vector3 acentre): centre(acentre) {};
- Colour evaluate(Vector3 point)
- {
- point = point - centre;
-
- Float u,v;
- v = acos(point.y / point.mag());
- u = M_PI + atan2(point.z, point.x);
-
- Float r,g,b;
- texture2D(u,v, r,g,b);
- return Colour(r, g, b);
- };
-};
-
void update_callback()
{
if (lx != 0.0)
@@ -196,7 +65,7 @@
light.castShadows(false);
Material mat0a(Colour(0.7, 0.7, 0.7));
- mat0a. setReflectivity(0.0);
+ mat0a.setReflectivity(0.0);
Box box(Vector3(-12.0, -1.2, -20.0), Vector3(12.0, -1.0, 0.0), &mat0a);
rt.addShape(&box);
@@ -205,45 +74,49 @@
Box box2(Vector3(-12.0, -1.2, -10.0), Vector3(12.0, 10.0, -10.2), &mat0b);
rt.addShape(&box2);
+ Float bounds[] = {0.3, 0.6, 1.1};
+ Colour colours[] = {Colour(0,0,0), Colour(1,1,1), Colour(0,0,0)};
+ BoundColourMap cmap(bounds, colours);
+
// spheres
Material mat1(Colour(1.0, 1.0, 1.0));
- mat1.texture = new PlanarMapTexture(Vector3(-4.5, 2.0, -7.0));
+ mat1.texture = new CheckersTexture(new PlanarMap(Vector3(-4.5, 2.0, -7.0), 0.48), &cmap);
Sphere sphere1(Vector3(-4.5, 2.0, -7.0), 1.0, &mat1);
rt.addShape(&sphere1);
Material mat2(Colour(1.0, 1.0, 1.0));
- mat2.texture = new CubicMapTexture(Vector3(-1.5, 2.0, -7.0));
+ mat2.texture = new CheckersTexture(new CubicMap(Vector3(-1.5, 2.0, -7.0), 0.48), &cmap);
Sphere sphere2(Vector3(-1.5, 2.0, -7.0), 1.0, &mat2);
rt.addShape(&sphere2);
Material mat3(Colour(1.0, 1.0, 1.0));
- mat3.texture = new CylinderMapTexture(Vector3(1.5, 2.0, -7.0));
+ mat3.texture = new CheckersTexture(new CylinderMap(Vector3(1.5, 2.0, -7.0), 0.48), &cmap);
Sphere sphere3(Vector3(1.5, 2.0, -7.0), 1.0, &mat3);
rt.addShape(&sphere3);
Material mat4(Colour(1.0, 1.0, 1.0));
- mat4.texture = new SphereMapTexture(Vector3(4.5, 2.0, -7.0));
+ mat4.texture = new CheckersTexture(new SphereMap(Vector3(4.5, 2.0, -7.0), 0.48), &cmap);
Sphere sphere4(Vector3(4.5, 2.0, -7.0), 1.0, &mat4);
rt.addShape(&sphere4);
// cubes
Material mat5(Colour(1.0, 1.0, 1.0));
- mat5.texture = new PlanarMapTexture(Vector3(-4.5, 0.0, -7.0));
+ mat5.texture = new CheckersTexture(new PlanarMap(Vector3(-4.5, 0.0, -7.0), 0.48), &cmap);
Box cube1(Vector3(-4.5, 0.0, -7.0)-1.0, Vector3(-4.5, 0.0, -7.0)+1.0, &mat5);
rt.addShape(&cube1);
Material mat6(Colour(1.0, 1.0, 1.0));
- mat6.texture = new CubicMapTexture(Vector3(-1.5, 0.0, -7.0));
+ mat6.texture = new CheckersTexture(new CubicMap(Vector3(-1.5, 0.0, -7.0), 0.48), &cmap);
Box cube2(Vector3(-1.5, 0.0, -7.0)-1.0, Vector3(-1.5, 0.0, -7.0)+1.0, &mat6);
rt.addShape(&cube2);
Material mat7(Colour(1.0, 1.0, 1.0));
- mat7.texture = new CylinderMapTexture(Vector3(1.5, 0.0, -7.0));
+ mat7.texture = new CheckersTexture(new CylinderMap(Vector3(1.5, 0.0, -7.0), 0.48), &cmap);
Box cube3(Vector3(1.5, 0.0, -7.0)-1.0, Vector3(1.5, 0.0, -7.0)+1.0, &mat7);
rt.addShape(&cube3);
Material mat8(Colour(1.0, 1.0, 1.0));
- mat8.texture = new SphereMapTexture(Vector3(4.5, 0.0, -7.0));
+ mat8.texture = new CheckersTexture(new SphereMap(Vector3(4.5, 0.0, -7.0), 0.48), &cmap);
Box cube4(Vector3(4.5, 0.0, -7.0)-1.0, Vector3(4.5, 0.0, -7.0)+1.0, &mat8);
rt.addShape(&cube4);