equal
deleted
inserted
replaced
108 Float invsize; |
108 Float invsize; |
109 public: |
109 public: |
110 TextureMap(const Vector &acenter, const Float &size): |
110 TextureMap(const Vector &acenter, const Float &size): |
111 center(acenter), invsize(1.0f/size) {}; |
111 center(acenter), invsize(1.0f/size) {}; |
112 virtual ~TextureMap() {}; |
112 virtual ~TextureMap() {}; |
113 virtual void map(const Vector &point, Float &u, Float &v) = 0; |
113 virtual void map(const Vector &point, Float &u, Float &v) const = 0; |
114 }; |
114 }; |
115 |
115 |
116 /** |
116 /** |
117 * planar mapping |
117 * planar mapping |
118 */ |
118 */ |
119 class PlanarMap: public TextureMap |
119 class PlanarMap: public TextureMap |
120 { |
120 { |
121 public: |
121 public: |
122 PlanarMap(const Vector &acenter, const Float &size): |
122 PlanarMap(const Vector &acenter, const Float &size): |
123 TextureMap(acenter, size) {}; |
123 TextureMap(acenter, size) {}; |
124 void map(const Vector &point, Float &u, Float &v) |
124 void map(const Vector &point, Float &u, Float &v) const |
125 { |
125 { |
126 const Vector p = point - center; |
126 const Vector p = point - center; |
127 u = p.x*invsize; |
127 u = p.x*invsize; |
128 v = p.y*invsize; |
128 v = p.y*invsize; |
129 }; |
129 }; |
135 class CubicMap: public TextureMap |
135 class CubicMap: public TextureMap |
136 { |
136 { |
137 public: |
137 public: |
138 CubicMap(const Vector &acenter, const Float &size): |
138 CubicMap(const Vector &acenter, const Float &size): |
139 TextureMap(acenter, size) {}; |
139 TextureMap(acenter, size) {}; |
140 void map(const Vector &point, Float &u, Float &v) |
140 void map(const Vector &point, Float &u, Float &v) const |
141 { |
141 { |
142 const Vector p = point - center; |
142 const Vector p = point - center; |
143 if (fabs(p.x) > fabs(p.y)) |
143 if (fabs(p.x) > fabs(p.y)) |
144 { |
144 { |
145 if (fabs(p.x) > fabs(p.z)) |
145 if (fabs(p.x) > fabs(p.z)) |
189 class CylinderMap: public TextureMap |
189 class CylinderMap: public TextureMap |
190 { |
190 { |
191 public: |
191 public: |
192 CylinderMap(const Vector &acenter, const Float &size): |
192 CylinderMap(const Vector &acenter, const Float &size): |
193 TextureMap(acenter, size) {}; |
193 TextureMap(acenter, size) {}; |
194 void map(const Vector &point, Float &u, Float &v) |
194 void map(const Vector &point, Float &u, Float &v) const |
195 { |
195 { |
196 const Vector p = point - center; |
196 const Vector p = point - center; |
197 u = ( PI + atan2(p.z, p.x) ) * invsize; |
197 u = ( PI + atan2(p.z, p.x) ) * invsize; |
198 v = p.y * invsize; |
198 v = p.y * invsize; |
199 }; |
199 }; |
205 class SphereMap: public TextureMap |
205 class SphereMap: public TextureMap |
206 { |
206 { |
207 public: |
207 public: |
208 SphereMap(const Vector &acenter, const Float &size): |
208 SphereMap(const Vector &acenter, const Float &size): |
209 TextureMap(acenter, size) {}; |
209 TextureMap(acenter, size) {}; |
210 void map(const Vector &point, Float &u, Float &v) |
210 void map(const Vector &point, Float &u, Float &v) const |
211 { |
211 { |
212 const Vector p = point - center; |
212 const Vector p = point - center; |
213 u = ( PI + atan2(p.z, p.x) ) * invsize; |
213 u = ( PI + atan2(p.z, p.x) ) * invsize; |
214 v = acos(p.y / p.mag()) * invsize; |
214 v = acos(p.y / p.mag()) * invsize; |
215 }; |
215 }; |
219 * general 2D texture |
219 * general 2D texture |
220 */ |
220 */ |
221 class Texture2D: public Texture |
221 class Texture2D: public Texture |
222 { |
222 { |
223 protected: |
223 protected: |
224 TextureMap *map; |
224 const TextureMap *map; |
225 public: |
225 public: |
226 Texture2D(TextureMap *amap): map(amap) {}; |
226 Texture2D(const TextureMap *amap): map(amap) {}; |
227 }; |
227 }; |
228 |
228 |
229 /** |
229 /** |
230 * 2D image texture |
230 * 2D image texture |
231 */ |
231 */ |
232 class ImageTexture: public Texture2D |
232 class ImageTexture: public Texture2D |
233 { |
233 { |
234 Pixmap *pixmap; |
234 const Pixmap *pixmap; |
235 public: |
235 public: |
236 ImageTexture(TextureMap *tmap, Pixmap *image): |
236 ImageTexture(const TextureMap *tmap, const Pixmap *image): |
237 Texture2D(tmap), pixmap(image) {}; |
237 Texture2D(tmap), pixmap(image) {}; |
238 Colour evaluate(const Vector &point) |
238 Colour evaluate(const Vector &point) |
239 { |
239 { |
240 Float u,v; |
240 Float u,v; |
241 map->map(point, u,v); |
241 map->map(point, u,v); |