1
/***************************************************************************
2
* Copyright (c) J�rgen Riegel (juergen.riegel@web.de) 2005 *
4
* This file is part of the FreeCAD CAx development system. *
6
* This library is free software; you can redistribute it and/or *
7
* modify it under the terms of the GNU Library General Public *
8
* License as published by the Free Software Foundation; either *
9
* version 2 of the License, or (at your option) any later version. *
11
* This library is distributed in the hope that it will be useful, *
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14
* GNU Library General Public License for more details. *
16
* You should have received a copy of the GNU Library General Public *
17
* License along with this library; see the file COPYING.LIB. If not, *
18
* write to the Free Software Foundation, Inc., 59 Temple Place, *
19
* Suite 330, Boston, MA 02111-1307, USA *
21
***************************************************************************/
26
#ifndef APP_MATERIAL_H
27
#define APP_MATERIAL_H
48
* Defines the color as (R,G,B,A) whereas all values are in the range [0,1].
49
* \a A defines the transparency.
51
explicit Color(float R=0.0,float G=0.0, float B=0.0, float A=0.0)
52
:r(R),g(G),b(B),a(A){}
54
* Does basically the same as the constructor above unless that (R,G,B,A) is
55
* encoded as an unsigned int.
58
{ setPackedValue( rgba ); }
59
/** Copy constructor. */
61
:r(c.r),g(c.g),b(c.b),a(c.a){}
62
/** Returns true if both colors are equal. Therefore all components must be equal. */
63
bool operator==(const Color& c) const
65
return getPackedValue() == c.getPackedValue();
66
//return (c.r==r && c.g==g && c.b==b && c.a==a);
68
bool operator!=(const Color& c) const
70
return !operator==(c);
73
* Defines the color as (R,G,B,A) whereas all values are in the range [0,1].
74
* \a A defines the transparency, 0 means complete opaque and 1 invisible.
76
void set(float R,float G, float B, float A=0.0)
80
Color& operator=(const Color& c)
82
r=c.r;g=c.g;b=c.b;a=c.a;
86
* Sets the color value as a 32 bit combined red/green/blue/alpha value.
87
* Each component is 8 bit wide (i.e. from 0x00 to 0xff), and the red
88
* value should be stored leftmost, like this: 0xRRGGBBAA.
90
* \sa getPackedValue().
92
Color& setPackedValue(uint32_t rgba)
94
this->set( (rgba >> 24)/255.0f, ((rgba >> 16)&0xff)/255.0f, ((rgba >> 8)&0xff)/255.0f, (rgba&0xff)/255.0f );
98
* Returns color as a 32 bit packed unsigned int in the form 0xRRGGBBAA.
100
* \sa setPackedValue().
102
uint32_t getPackedValue() const
104
return ((uint32_t)(r*255.0f + 0.5f) << 24 |
105
(uint32_t)(g*255.0f + 0.5f) << 16 |
106
(uint32_t)(b*255.0f + 0.5f) << 8 |
107
(uint32_t)(a*255.0f + 0.5f));
110
/// color values, public accesible
117
class AppExport Material
147
/** @name Constructors
150
/** Sets the USER_DEFINED material type. The user must set the colors afterwards. */
152
/** Defines the colors and shininess for the material \a MatName. If \a MatName isn't defined then USER_DEFINED is
153
* set and the user must define the colors itself.
155
Material(const char* MatName);
156
/** Does basically the same as the constructor above unless that it accepts a MaterialType as argument. */
157
Material(const MaterialType MatType);
161
/** Set a material by name
162
* There are some standard materials defined which are:
184
* Furthermore there two additional modes \a Default which defines a kind of grey metalic and user defined that
186
* The Color and the other properties of the material are defined in the range [0-1].
187
* If \a MatName is an unknown material name then the type USER_DEFINED is set and the material doesn't get changed.
189
void set(const char* MatName);
191
* This method is provided for convenience which does basically the same as the method above unless that it accepts a MaterialType
194
void setType(const MaterialType MatType);
196
* Returns the currently set material type.
198
MaterialType getType() const
201
//Base::PyObjectBase* GetPyObject(void);
203
/** @name Properties */
205
Color ambientColor; /**< Defines the ambient color. */
206
Color diffuseColor; /**< Defines the diffuse color. */
207
Color specularColor; /**< Defines the specular color. */
208
Color emissiveColor; /**< Defines the emissive color. */
214
MaterialPy* _materialPy;
215
MaterialType _matType;
220
#endif // APP_MATERIAL_H