Welcome to mirror list, hosted at ThFree Co, Russian Federation.

Material.h « scene_graph « intern « freestyle « blender « source - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 64ae526ccb0b432ea0973ead95350c0cfac4d0db (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
//
//  Filename         : Material.h
//  Author(s)        : Stephane Grabli
//  Purpose          : Class used to handle materials.
//  Date of creation : 10/10/2002
//
///////////////////////////////////////////////////////////////////////////////


//
//  Copyright (C) : Please refer to the COPYRIGHT file distributed 
//   with this source distribution. 
//
//  This program is free software; you can redistribute it and/or
//  modify it under the terms of the GNU General Public License
//  as published by the Free Software Foundation; either version 2
//  of the License, or (at your option) any later version.
//
//  This program is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.
//
//  You should have received a copy of the GNU General Public License
//  along with this program; if not, write to the Free Software
//  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
//
///////////////////////////////////////////////////////////////////////////////

#ifndef  MATERIAL_H
# define MATERIAL_H

# include "../system/FreestyleConfig.h"

/*! Class defining a material */
class Material
{
public:
  /*! Default constructor */
  inline Material();
  /*! Builds a Material from its diffuse, ambiant, specular, emissive
   *  colors and a shininess coefficient.
   *    \param iDiffuse
   *      A 4 element float-array containing the diffuse color.
   *    \param iAmbiant
   *      A 4 element float-array containing the ambiant color.
   *    \param iSpecular
   *      A 4 element float-array containing the specular color.
   *    \param iEmission
   *      A 4 element float-array containing the emissive color.
   *    \param iShininess
   *      The shininess coefficient.
   */
  inline Material(const float *iDiffuse,
                  const float *iAmbiant,
                  const float *iSpecular, 
                  const float *iEmission, 
                  const float iShininess);

  /*! Copy constructor */
  inline Material(const Material& m);
  /*! Destructor */
  virtual ~Material() {}


  /*! Returns the diffuse color as a 4 float array */
  inline const float * diffuse() const { return Diffuse; }
  /*! Returns the red component of the diffuse color */
  inline const float   diffuseR() const { return Diffuse[0]; }
  /*! Returns the green component of the diffuse color */
  inline const float   diffuseG() const { return Diffuse[1]; }
  /*! Returns the blue component of the diffuse color */
  inline const float   diffuseB() const { return Diffuse[2]; }
  /*! Returns the alpha component of the diffuse color */
  inline const float   diffuseA() const { return Diffuse[3]; }

  /*! Returns the specular color as a 4 float array */
  inline const float * specular() const { return Specular; }
  /*! Returns the red component of the specular color */
  inline const float   specularR() const { return Specular[0]; }
  /*! Returns the green component of the specular color */
  inline const float   specularG() const { return Specular[1]; }
  /*! Returns the blue component of the specular color */
  inline const float   specularB() const { return Specular[2]; }
  /*! Returns the alpha component of the specular color */
  inline const float   specularA() const { return Specular[3]; }

  /*! Returns the ambiant color as a 4 float array */
  inline const float * ambient() const { return Ambient; }
  /*! Returns the red component of the ambiant color */
  inline const float   ambientR() const { return Ambient[0]; }
  /*! Returns the green component of the ambiant color */
  inline const float   ambientG() const { return Ambient[1]; }
  /*! Returns the blue component of the ambiant color */
  inline const float   ambientB() const { return Ambient[2]; }
  /*! Returns the alpha component of the ambiant color */
  inline const float   ambientA() const { return Ambient[3]; }

  /*! Returns the emissive color as a 4 float array */
  inline const float * emission() const { return Emission; }
  /*! Returns the red component of the emissive color */
  inline const float   emissionR() const { return Emission[0]; }
  /*! Returns the green component of the emissive color */
  inline const float   emissionG() const { return Emission[1]; }
  /*! Returns the blue component of the emissive color */
  inline const float   emissionB() const { return Emission[2]; }
  /*! Returns the alpha component of the emissive color */
  inline const float   emissionA() const { return Emission[3]; }

  /*! Returns the shininess coefficient */
  inline const float shininess() const { return Shininess; }

  /*! Sets the diffuse color.
   *    \param r
   *      Red component
   *    \param g
   *      Green component
   *    \param b
   *     Blue component
   *    \param a
   *      Alpha component
   */
  inline void setDiffuse(const float r, const float g, const float b, const float a);
  /*! Sets the specular color.
   *    \param r
   *      Red component
   *    \param g
   *      Green component
   *    \param b
   *     Blue component
   *    \param a
   *      Alpha component
   */
  inline void setSpecular(const float r, const float g, const float b, const float a);
  /*! Sets the ambiant color.
   *    \param r
   *      Red component
   *    \param g
   *      Green component
   *    \param b
   *     Blue component
   *    \param a
   *      Alpha component
   */
  inline void setAmbient(const float r, const float g, const float b, const float a);

  /*! Sets the emissive color.
   *    \param r
   *      Red component
   *    \param g
   *      Green component
   *    \param b
   *     Blue component
   *    \param a
   *      Alpha component
   */
  inline void setEmission(const float r, const float g, const float b, const float a);

  /*! Sets the shininess.
   *    \param s
   *      Shininess
   */
  inline void setShininess(const float s);

  /* operators */
  inline Material& operator=(const Material& m);
  inline bool operator!=(const Material& m) const;
  inline bool operator==(const Material& m) const;

private:

  /*! Material properties */
  float Diffuse[4];
  float Specular[4];
  float Ambient[4];
  float Emission[4];
  float Shininess;

};

Material::Material()
{
  Ambient[0] = Ambient[1] = Ambient[2] = 0.2f;
  Ambient[3] = 1.f;

  Diffuse[0] = Diffuse[1] = Diffuse[2] = 0.8f;
  Diffuse[3] = 1.f;

  Emission[0] = Emission[1] = Emission[2] = 0.f;
  Emission[3] = 1.f;

  Specular[0] = Specular[1] = Specular[2] = 0.f;
  Specular[3] = 1.f;

  Shininess = 0.f;
}

Material::Material(const float *iDiffuse,
                   const float *iAmbiant,
                   const float *iSpecular, 
                   const float *iEmission, 
                   const float iShininess)
{
  for(int i=0; i<4; i++)
  {
    Diffuse[i]  = iDiffuse[i];
    Specular[i] = iSpecular[i];
    Ambient[i]  = iAmbiant[i];
    Emission[i] = iEmission[i];
  }

  Shininess = iShininess;
}

Material::Material(const Material& m)
{
  for(int i=0; i<4; i++)
  {
    Diffuse[i]  = m.diffuse()[i];
    Specular[i] = m.specular()[i];
    Ambient[i]  = m.ambient()[i];
    Emission[i] = m.emission()[i];
  }

  Shininess = m.shininess();
}

void Material::setDiffuse(const float r, const float g, const float b, const float a)
{
  Diffuse[0] = r;
  Diffuse[1] = g;
  Diffuse[2] = b;
  Diffuse[3] = a;
}

void Material::setSpecular(const float r, const float g, const float b, const float a)
{
  Specular[0] = r;
  Specular[1] = g;
  Specular[2] = b;
  Specular[3] = a;
}
  
void Material::setAmbient(const float r, const float g, const float b, const float a)
{
  Ambient[0] = r;
  Ambient[1] = g;
  Ambient[2] = b;
  Ambient[3] = a;
}

void Material::setEmission(const float r, const float g, const float b, const float a)
{
  Emission[0] = r;
  Emission[1] = g;
  Emission[2] = b;
  Emission[3] = a;
}

void Material::setShininess(const float s)
{
  Shininess = s;
}

Material& Material::operator=(const Material& m)
{
  for(int i=0; i<4; i++)
  {
    Diffuse[i]  = m.diffuse()[i];
    Specular[i] = m.specular()[i];
    Ambient[i]  = m.ambient()[i];
    Emission[i] = m.emission()[i];
  }

  Shininess = m.shininess();

  return *this;
}

bool Material::operator!=(const Material& m) const
{
  if(Shininess != m.shininess())
    return true;
  for(int i=0; i<4; i++)
  {
    if(Diffuse[i]  != m.diffuse()[i])
      return true;
    if(Specular[i] != m.specular()[i])
      return true;
    if(Ambient[i]  != m.ambient()[i])
      return true;
    if(Emission[i] != m.emission()[i])
      return true;
  }

  return false;
}

bool Material::operator==(const Material& m) const
{
  return (!((*this)!=m));
}

#endif // MATERIAL_H