OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * ***** BEGIN GPL LICENSE BLOCK ***** |
| 3 * |
| 4 * This program is free software; you can redistribute it and/or |
| 5 * modify it under the terms of the GNU General Public License |
| 6 * as published by the Free Software Foundation; either version 2 |
| 7 * of the License, or (at your option) any later version. |
| 8 * |
| 9 * This program is distributed in the hope that it will be useful, |
| 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 * GNU General Public License for more details. |
| 13 * |
| 14 * You should have received a copy of the GNU General Public License |
| 15 * along with this program; if not, write to the Free Software Foundation, |
| 16 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 17 * |
| 18 * The Original Code is Copyright (C) 2010 Blender Foundation. |
| 19 * All rights reserved. |
| 20 * |
| 21 * The Original Code is: all of this file. |
| 22 * |
| 23 * Contributor(s): none yet. |
| 24 * |
| 25 * ***** END GPL LICENSE BLOCK ***** |
| 26 */ |
| 27 |
| 28 #ifndef __FREESTYLE_MATERIAL_H__ |
| 29 #define __FREESTYLE_MATERIAL_H__ |
| 30 |
| 31 /** \file blender/freestyle/intern/scene_graph/FrsMaterial.h |
| 32 * \ingroup freestyle |
| 33 * \brief Class used to handle materials. |
| 34 * \author Stephane Grabli |
| 35 * \date 10/10/2002 |
| 36 */ |
| 37 |
| 38 #include "../system/FreestyleConfig.h" |
| 39 |
| 40 /*! Class defining a material */ |
| 41 class FrsMaterial |
| 42 { |
| 43 public: |
| 44 /*! Default constructor */ |
| 45 inline FrsMaterial(); |
| 46 |
| 47 /*! Builds a Material from its diffuse, ambiant, specular, emissive colo
rs and a shininess coefficient. |
| 48 * \param iDiffuse |
| 49 * A 4 element float-array containing the diffuse color. |
| 50 * \param iAmbiant |
| 51 * A 4 element float-array containing the ambiant color. |
| 52 * \param iSpecular |
| 53 * A 4 element float-array containing the specular color. |
| 54 * \param iEmission |
| 55 * A 4 element float-array containing the emissive color. |
| 56 * \param iShininess |
| 57 * The shininess coefficient. |
| 58 */ |
| 59 inline FrsMaterial(const float *iDiffuse, const float *iAmbiant, const f
loat *iSpecular, const float *iEmission, |
| 60 const float iShininess); |
| 61 |
| 62 /*! Copy constructor */ |
| 63 inline FrsMaterial(const FrsMaterial& m); |
| 64 |
| 65 /*! Destructor */ |
| 66 virtual ~FrsMaterial() {} |
| 67 |
| 68 |
| 69 /*! Returns the diffuse color as a 4 float array */ |
| 70 inline const float *diffuse() const |
| 71 { |
| 72 return Diffuse; |
| 73 } |
| 74 |
| 75 /*! Returns the red component of the diffuse color */ |
| 76 inline const float diffuseR() const |
| 77 { |
| 78 return Diffuse[0]; |
| 79 } |
| 80 |
| 81 /*! Returns the green component of the diffuse color */ |
| 82 inline const float diffuseG() const |
| 83 { |
| 84 return Diffuse[1]; |
| 85 } |
| 86 |
| 87 /*! Returns the blue component of the diffuse color */ |
| 88 inline const float diffuseB() const |
| 89 { |
| 90 return Diffuse[2]; |
| 91 } |
| 92 |
| 93 /*! Returns the alpha component of the diffuse color */ |
| 94 inline const float diffuseA() const |
| 95 { |
| 96 return Diffuse[3]; |
| 97 } |
| 98 |
| 99 /*! Returns the specular color as a 4 float array */ |
| 100 inline const float *specular() const |
| 101 { |
| 102 return Specular; |
| 103 } |
| 104 |
| 105 /*! Returns the red component of the specular color */ |
| 106 inline const float specularR() const |
| 107 { |
| 108 return Specular[0]; |
| 109 } |
| 110 |
| 111 /*! Returns the green component of the specular color */ |
| 112 inline const float specularG() const |
| 113 { |
| 114 return Specular[1]; |
| 115 } |
| 116 |
| 117 /*! Returns the blue component of the specular color */ |
| 118 inline const float specularB() const |
| 119 { |
| 120 return Specular[2]; |
| 121 } |
| 122 |
| 123 /*! Returns the alpha component of the specular color */ |
| 124 inline const float specularA() const |
| 125 { |
| 126 return Specular[3]; |
| 127 } |
| 128 |
| 129 /*! Returns the ambiant color as a 4 float array */ |
| 130 inline const float *ambient() const |
| 131 { |
| 132 return Ambient; |
| 133 } |
| 134 |
| 135 /*! Returns the red component of the ambiant color */ |
| 136 inline const float ambientR() const |
| 137 { |
| 138 return Ambient[0]; |
| 139 } |
| 140 |
| 141 /*! Returns the green component of the ambiant color */ |
| 142 inline const float ambientG() const |
| 143 { |
| 144 return Ambient[1]; |
| 145 } |
| 146 |
| 147 /*! Returns the blue component of the ambiant color */ |
| 148 inline const float ambientB() const |
| 149 { |
| 150 return Ambient[2]; |
| 151 } |
| 152 |
| 153 /*! Returns the alpha component of the ambiant color */ |
| 154 inline const float ambientA() const |
| 155 { |
| 156 return Ambient[3]; |
| 157 } |
| 158 |
| 159 /*! Returns the emissive color as a 4 float array */ |
| 160 inline const float *emission() const |
| 161 { |
| 162 return Emission; |
| 163 } |
| 164 |
| 165 /*! Returns the red component of the emissive color */ |
| 166 inline const float emissionR() const |
| 167 { |
| 168 return Emission[0]; |
| 169 } |
| 170 |
| 171 /*! Returns the green component of the emissive color */ |
| 172 inline const float emissionG() const |
| 173 { |
| 174 return Emission[1]; |
| 175 } |
| 176 |
| 177 /*! Returns the blue component of the emissive color */ |
| 178 inline const float emissionB() const |
| 179 { |
| 180 return Emission[2]; |
| 181 } |
| 182 |
| 183 /*! Returns the alpha component of the emissive color */ |
| 184 inline const float emissionA() const |
| 185 { |
| 186 return Emission[3]; |
| 187 } |
| 188 |
| 189 /*! Returns the shininess coefficient */ |
| 190 inline const float shininess() const |
| 191 { |
| 192 return Shininess; |
| 193 } |
| 194 |
| 195 /*! Sets the diffuse color. |
| 196 * \param r |
| 197 * Red component |
| 198 * \param g |
| 199 * Green component |
| 200 * \param b |
| 201 * Blue component |
| 202 * \param a |
| 203 * Alpha component |
| 204 */ |
| 205 inline void setDiffuse(const float r, const float g, const float b, cons
t float a); |
| 206 |
| 207 /*! Sets the specular color. |
| 208 * \param r |
| 209 * Red component |
| 210 * \param g |
| 211 * Green component |
| 212 * \param b |
| 213 * Blue component |
| 214 * \param a |
| 215 * Alpha component |
| 216 */ |
| 217 inline void setSpecular(const float r, const float g, const float b, con
st float a); |
| 218 |
| 219 /*! Sets the ambiant color. |
| 220 * \param r |
| 221 * Red component |
| 222 * \param g |
| 223 * Green component |
| 224 * \param b |
| 225 * Blue component |
| 226 * \param a |
| 227 * Alpha component |
| 228 */ |
| 229 inline void setAmbient(const float r, const float g, const float b, cons
t float a); |
| 230 |
| 231 /*! Sets the emissive color. |
| 232 * \param r |
| 233 * Red component |
| 234 * \param g |
| 235 * Green component |
| 236 * \param b |
| 237 * Blue component |
| 238 * \param a |
| 239 * Alpha component |
| 240 */ |
| 241 inline void setEmission(const float r, const float g, const float b, con
st float a); |
| 242 |
| 243 /*! Sets the shininess. |
| 244 * \param s |
| 245 * Shininess |
| 246 */ |
| 247 inline void setShininess(const float s); |
| 248 |
| 249 /* operators */ |
| 250 inline FrsMaterial& operator=(const FrsMaterial& m); |
| 251 inline bool operator!=(const FrsMaterial& m) const; |
| 252 inline bool operator==(const FrsMaterial& m) const; |
| 253 |
| 254 private: |
| 255 /*! Material properties */ |
| 256 float Diffuse[4]; |
| 257 float Specular[4]; |
| 258 float Ambient[4]; |
| 259 float Emission[4]; |
| 260 float Shininess; |
| 261 }; |
| 262 |
| 263 FrsMaterial::FrsMaterial() |
| 264 { |
| 265 Ambient[0] = Ambient[1] = Ambient[2] = 0.2f; |
| 266 Ambient[3] = 1.0f; |
| 267 |
| 268 Diffuse[0] = Diffuse[1] = Diffuse[2] = 0.8f; |
| 269 Diffuse[3] = 1.0f; |
| 270 |
| 271 Emission[0] = Emission[1] = Emission[2] = 0.0f; |
| 272 Emission[3] = 1.0f; |
| 273 |
| 274 Specular[0] = Specular[1] = Specular[2] = 0.0f; |
| 275 Specular[3] = 1.0f; |
| 276 |
| 277 Shininess = 0.0f; |
| 278 } |
| 279 |
| 280 FrsMaterial::FrsMaterial(const float *iDiffuse, const float *iAmbiant, const flo
at *iSpecular, const float *iEmission, |
| 281 const float iShininess) |
| 282 { |
| 283 for (int i = 0; i < 4; i++) { |
| 284 Diffuse[i] = iDiffuse[i]; |
| 285 Specular[i] = iSpecular[i]; |
| 286 Ambient[i] = iAmbiant[i]; |
| 287 Emission[i] = iEmission[i]; |
| 288 } |
| 289 |
| 290 Shininess = iShininess; |
| 291 } |
| 292 |
| 293 FrsMaterial::FrsMaterial(const FrsMaterial& m) |
| 294 { |
| 295 for (int i = 0; i < 4; i++) { |
| 296 Diffuse[i] = m.diffuse()[i]; |
| 297 Specular[i] = m.specular()[i]; |
| 298 Ambient[i] = m.ambient()[i]; |
| 299 Emission[i] = m.emission()[i]; |
| 300 } |
| 301 |
| 302 Shininess = m.shininess(); |
| 303 } |
| 304 |
| 305 void FrsMaterial::setDiffuse(const float r, const float g, const float b, const
float a) |
| 306 { |
| 307 Diffuse[0] = r; |
| 308 Diffuse[1] = g; |
| 309 Diffuse[2] = b; |
| 310 Diffuse[3] = a; |
| 311 } |
| 312 |
| 313 void FrsMaterial::setSpecular(const float r, const float g, const float b, const
float a) |
| 314 { |
| 315 Specular[0] = r; |
| 316 Specular[1] = g; |
| 317 Specular[2] = b; |
| 318 Specular[3] = a; |
| 319 } |
| 320 |
| 321 void FrsMaterial::setAmbient(const float r, const float g, const float b, const
float a) |
| 322 { |
| 323 Ambient[0] = r; |
| 324 Ambient[1] = g; |
| 325 Ambient[2] = b; |
| 326 Ambient[3] = a; |
| 327 } |
| 328 |
| 329 void FrsMaterial::setEmission(const float r, const float g, const float b, const
float a) |
| 330 { |
| 331 Emission[0] = r; |
| 332 Emission[1] = g; |
| 333 Emission[2] = b; |
| 334 Emission[3] = a; |
| 335 } |
| 336 |
| 337 void FrsMaterial::setShininess(const float s) |
| 338 { |
| 339 Shininess = s; |
| 340 } |
| 341 |
| 342 FrsMaterial& FrsMaterial::operator=(const FrsMaterial& m) |
| 343 { |
| 344 for (int i = 0; i < 4; i++) { |
| 345 Diffuse[i] = m.diffuse()[i]; |
| 346 Specular[i] = m.specular()[i]; |
| 347 Ambient[i] = m.ambient()[i]; |
| 348 Emission[i] = m.emission()[i]; |
| 349 } |
| 350 |
| 351 Shininess = m.shininess(); |
| 352 return *this; |
| 353 } |
| 354 |
| 355 bool FrsMaterial::operator!=(const FrsMaterial& m) const |
| 356 { |
| 357 if (Shininess != m.shininess()) |
| 358 return true; |
| 359 |
| 360 for (int i = 0; i < 4; i++) { |
| 361 if (Diffuse[i] != m.diffuse()[i]) |
| 362 return true; |
| 363 if (Specular[i] != m.specular()[i]) |
| 364 return true; |
| 365 if (Ambient[i] != m.ambient()[i]) |
| 366 return true; |
| 367 if (Emission[i] != m.emission()[i]) |
| 368 return true; |
| 369 } |
| 370 |
| 371 return false; |
| 372 } |
| 373 |
| 374 bool FrsMaterial::operator==(const FrsMaterial& m) const |
| 375 { |
| 376 return (!((*this) != m)); |
| 377 } |
| 378 |
| 379 #endif // __FREESTYLE_MATERIAL_H__ |
OLD | NEW |