equal
deleted
inserted
replaced
41 */ |
41 */ |
42 class Texture |
42 class Texture |
43 { |
43 { |
44 public: |
44 public: |
45 virtual ~Texture() {}; |
45 virtual ~Texture() {}; |
46 virtual Colour evaluate(const Vector3 &point) = 0; |
46 virtual Colour evaluate(const Vector &point) = 0; |
47 }; |
47 }; |
48 |
48 |
49 /** |
49 /** |
50 * general colour map |
50 * general colour map |
51 */ |
51 */ |
101 * general texture mapping |
101 * general texture mapping |
102 */ |
102 */ |
103 class TextureMap |
103 class TextureMap |
104 { |
104 { |
105 protected: |
105 protected: |
106 Vector3 center; |
106 Vector center; |
107 Float invsize; |
107 Float invsize; |
108 public: |
108 public: |
109 TextureMap(const Vector3 &acenter, const Float &size): |
109 TextureMap(const Vector &acenter, const Float &size): |
110 center(acenter), invsize(1./size) {}; |
110 center(acenter), invsize(1./size) {}; |
111 virtual ~TextureMap() {}; |
111 virtual ~TextureMap() {}; |
112 virtual void map(const Vector3 &point, Float &u, Float &v) = 0; |
112 virtual void map(const Vector &point, Float &u, Float &v) = 0; |
113 }; |
113 }; |
114 |
114 |
115 /** |
115 /** |
116 * planar mapping |
116 * planar mapping |
117 */ |
117 */ |
118 class PlanarMap: public TextureMap |
118 class PlanarMap: public TextureMap |
119 { |
119 { |
120 public: |
120 public: |
121 PlanarMap(const Vector3 &acenter, const Float &size): |
121 PlanarMap(const Vector &acenter, const Float &size): |
122 TextureMap(acenter, size) {}; |
122 TextureMap(acenter, size) {}; |
123 void map(const Vector3 &point, Float &u, Float &v) |
123 void map(const Vector &point, Float &u, Float &v) |
124 { |
124 { |
125 const Vector3 p = point - center; |
125 const Vector p = point - center; |
126 u = p.x*invsize; |
126 u = p.x*invsize; |
127 v = p.y*invsize; |
127 v = p.y*invsize; |
128 }; |
128 }; |
129 }; |
129 }; |
130 |
130 |
132 * cubic mapping |
132 * cubic mapping |
133 */ |
133 */ |
134 class CubicMap: public TextureMap |
134 class CubicMap: public TextureMap |
135 { |
135 { |
136 public: |
136 public: |
137 CubicMap(const Vector3 &acenter, const Float &size): |
137 CubicMap(const Vector &acenter, const Float &size): |
138 TextureMap(acenter, size) {}; |
138 TextureMap(acenter, size) {}; |
139 void map(const Vector3 &point, Float &u, Float &v) |
139 void map(const Vector &point, Float &u, Float &v) |
140 { |
140 { |
141 const Vector3 p = point - center; |
141 const Vector p = point - center; |
142 if (fabs(p.x) > fabs(p.y)) |
142 if (fabs(p.x) > fabs(p.y)) |
143 { |
143 { |
144 if (fabs(p.x) > fabs(p.z)) |
144 if (fabs(p.x) > fabs(p.z)) |
145 { |
145 { |
146 if (p.x < 0) |
146 if (p.x < 0) |
186 * cylindrical mapping |
186 * cylindrical mapping |
187 */ |
187 */ |
188 class CylinderMap: public TextureMap |
188 class CylinderMap: public TextureMap |
189 { |
189 { |
190 public: |
190 public: |
191 CylinderMap(const Vector3 &acenter, const Float &size): |
191 CylinderMap(const Vector &acenter, const Float &size): |
192 TextureMap(acenter, size) {}; |
192 TextureMap(acenter, size) {}; |
193 void map(const Vector3 &point, Float &u, Float &v) |
193 void map(const Vector &point, Float &u, Float &v) |
194 { |
194 { |
195 const Vector3 p = point - center; |
195 const Vector p = point - center; |
196 u = ( M_PI + atan2(p.z, p.x) ) * invsize; |
196 u = ( M_PI + atan2(p.z, p.x) ) * invsize; |
197 v = p.y * invsize; |
197 v = p.y * invsize; |
198 }; |
198 }; |
199 }; |
199 }; |
200 |
200 |
202 * spherical mapping |
202 * spherical mapping |
203 */ |
203 */ |
204 class SphereMap: public TextureMap |
204 class SphereMap: public TextureMap |
205 { |
205 { |
206 public: |
206 public: |
207 SphereMap(const Vector3 &acenter, const Float &size): |
207 SphereMap(const Vector &acenter, const Float &size): |
208 TextureMap(acenter, size) {}; |
208 TextureMap(acenter, size) {}; |
209 void map(const Vector3 &point, Float &u, Float &v) |
209 void map(const Vector &point, Float &u, Float &v) |
210 { |
210 { |
211 const Vector3 p = point - center; |
211 const Vector p = point - center; |
212 u = ( M_PI + atan2(p.z, p.x) ) * invsize; |
212 u = ( M_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 |
232 { |
232 { |
233 Pixmap *pixmap; |
233 Pixmap *pixmap; |
234 public: |
234 public: |
235 ImageTexture(TextureMap *tmap, Pixmap *image): |
235 ImageTexture(TextureMap *tmap, Pixmap *image): |
236 Texture2D(tmap), pixmap(image) {}; |
236 Texture2D(tmap), pixmap(image) {}; |
237 Colour evaluate(const Vector3 &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.5; |
242 u -= floor(u); |
242 u -= floor(u); |
253 { |
253 { |
254 ColourMap *colourmap; |
254 ColourMap *colourmap; |
255 public: |
255 public: |
256 CheckersTexture(TextureMap *tmap, ColourMap *cmap): |
256 CheckersTexture(TextureMap *tmap, ColourMap *cmap): |
257 Texture2D(tmap), colourmap(cmap) {}; |
257 Texture2D(tmap), colourmap(cmap) {}; |
258 Colour evaluate(const Vector3 &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.5*(round(u - floor(u)) + round(v - floor(v))); |
263 return colourmap->map(val); |
263 return colourmap->map(val); |
272 Float detail; |
272 Float detail; |
273 ColourMap *colourmap; |
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 detail(adetail), colourmap(cmap) {}; |
277 Colour evaluate(const Vector3 &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; |
282 //Float value = sinf(point.x + sum)/2 + 0.5; |
282 //Float value = sinf(point.x + sum)/2 + 0.5; |