Material.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (c) Jürgen Riegel          (juergen.riegel@web.de) 2005     *
00003  *                                                                         *
00004  *   This file is part of the FreeCAD CAx development system.              *
00005  *                                                                         *
00006  *   This library is free software; you can redistribute it and/or         *
00007  *   modify it under the terms of the GNU Library General Public           *
00008  *   License as published by the Free Software Foundation; either          *
00009  *   version 2 of the License, or (at your option) any later version.      *
00010  *                                                                         *
00011  *   This library  is distributed in the hope that it will be useful,      *
00012  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00013  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00014  *   GNU Library General Public License for more details.                  *
00015  *                                                                         *
00016  *   You should have received a copy of the GNU Library General Public     *
00017  *   License along with this library; see the file COPYING.LIB. If not,    *
00018  *   write to the Free Software Foundation, Inc., 59 Temple Place,         *
00019  *   Suite 330, Boston, MA  02111-1307, USA                                *
00020  *                                                                         *
00021  ***************************************************************************/
00022 
00023 
00024 #ifndef APP_MATERIAL_H
00025 #define APP_MATERIAL_H
00026 
00027 #ifdef __GNUC__
00028 # include <stdint.h>
00029 #endif
00030 
00031 namespace App
00032 {
00033 
00036 class AppExport Color
00037 {
00038 public:
00043     explicit Color(float R=0.0,float G=0.0, float B=0.0, float A=0.0)
00044       :r(R),g(G),b(B),a(A){}
00049     Color(uint32_t rgba)
00050     { setPackedValue( rgba ); }
00052     Color(const Color& c)
00053       :r(c.r),g(c.g),b(c.b),a(c.a){}
00055     bool operator==(const Color& c) const
00056     {
00057         return getPackedValue() == c.getPackedValue();
00058         //return (c.r==r && c.g==g && c.b==b && c.a==a); 
00059     }
00060     bool operator!=(const Color& c) const 
00061     {
00062         return !operator==(c);
00063     }
00068     void set(float R,float G, float B, float A=0.0)
00069     {
00070         r=R;g=G;b=B;a=A;
00071     }
00072     Color& operator=(const Color& c)
00073     {
00074         r=c.r;g=c.g;b=c.b;a=c.a;
00075         return *this;
00076     }
00084     Color& setPackedValue(uint32_t rgba)
00085     {
00086         this->set((rgba >> 24)/255.0f,
00087                  ((rgba >> 16)&0xff)/255.0f,
00088                  ((rgba >> 8)&0xff)/255.0f,
00089                  (rgba&0xff)/255.0f);
00090         return *this;
00091     }
00097     uint32_t getPackedValue() const
00098     {
00099         return ((uint32_t)(r*255.0f + 0.5f) << 24 |
00100                 (uint32_t)(g*255.0f + 0.5f) << 16 |
00101                 (uint32_t)(b*255.0f + 0.5f) << 8  |
00102                 (uint32_t)(a*255.0f + 0.5f));
00103     }
00104 
00106     float r,g,b,a;
00107 };
00108 
00111 class AppExport Material
00112 {
00113 public:
00114     enum MaterialType { 
00115         BRASS,
00116         BRONZE,
00117         COPPER,
00118         GOLD,
00119         PEWTER,
00120         PLASTER,
00121         PLASTIC,
00122         SILVER,
00123         STEEL,
00124         STONE,
00125         SHINY_PLASTIC,
00126         SATIN,
00127         METALIZED,
00128         NEON_GNC,
00129         CHROME,
00130         ALUMINIUM,
00131         OBSIDIAN,
00132         NEON_PHC,
00133         JADE,
00134         RUBY,
00135         EMERALD,
00136         DEFAULT,
00137         USER_DEFINED
00138     };
00139 
00140 public:
00145     Material(void);
00149     Material(const char* MatName);
00151     Material(const MaterialType MatType);
00153     ~Material();
00154 
00183     void set(const char* MatName);
00188     void setType(const MaterialType MatType);
00192     MaterialType getType() const
00193     { return _matType; }
00194 
00197     Color ambientColor;  
00198     Color diffuseColor;  
00199     Color specularColor; 
00200     Color emissiveColor; 
00201     float shininess;
00202     float transparency;
00204 
00205 private:
00206     MaterialType _matType;
00207 };
00208 
00209 } //namespace App
00210 
00211 #endif // APP_MATERIAL_H

Generated on Wed Nov 23 19:00:21 2011 for FreeCAD by  doxygen 1.6.1