Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages

material.cpp

Go to the documentation of this file.
00001 /* ***********************************************************************************
00002         Writer:         Sebastien Bloc
00003         Copyright:      2003-2004
00004         eMail:          sebastien.bloc@free.fr
00005         URL:            http://mignonsoft.free.fr
00006 
00007         This program is free software; you can redistribute it and/or
00008         modify it under the terms of the GNU General Public License
00009         as published by the Free Software Foundation; either version 2
00010         of the License, or (at your option) any later version.
00011 
00012         This program is distributed in the hope that it will be useful,
00013         but WITHOUT ANY WARRANTY; without even the implied warranty of
00014         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015         GNU General Public License for more details.
00016         http://www.gnu.org/copyleft/gpl.html
00017 *********************************************************************************** */
00018 
00019 #include "material.h"
00020 
00021 Material::Material()
00022 {
00023         Zero();
00024 }
00025 
00026 void Material::Zero()
00027 {
00028         typeFace = GL_FRONT_AND_BACK;
00029         ambient.Zero();
00030         //ambient.opacity=&opacity;
00031         diffuse.Zero();
00032         //diffuse.opacity=&opacity;
00033         specular.Zero();
00034         //specular.opacity=&opacity;
00035         emission.Zero();
00036         //emission.opacity=&opacity;
00037         shiness.elem=0;
00038         //opacity=1; // gestion a faire
00039 }
00040 
00041 void Material::operator=(Material &source)
00042 {
00043         typeFace = source.typeFace;
00044         ambient = source.ambient;
00045         diffuse = source.diffuse;
00046         specular = source.specular;
00047         emission = source.emission;
00048         shiness = source.shiness;
00049         opacity = source.opacity;
00050 }
00051 
00052 void Material::SetDS (Color color)
00053 {
00054         ambient.SetNull();
00055         diffuse=color;
00056         specular=diffuse;
00057         emission.SetNull();
00058 }
00059 
00060 void Material::SetDS (float *source)
00061 {
00062         SetDS(source[0],source[1],source[2],source[3]);
00063 }
00064 
00065 void Material::SetAlpha(float alpha)
00066 {
00067         ambient.a = alpha;
00068         diffuse.a = alpha;
00069         specular.a = alpha;
00070         emission.a = alpha;
00071 }
00072 
00074 void Material::SetDS (float r,float g,float b,float a) 
00075 {
00076         ambient.SetNull();
00077         diffuse.Set(r,g,b,a);
00078         specular=diffuse;
00079         emission.SetNull();
00080 }
00081 
00082 void Material::SetDS (float r,float g,float b) 
00083 {
00084         ambient.SetNull();
00085         diffuse.Set(r,g,b);
00086         specular=diffuse;
00087         emission.SetNull();
00088 }
00089 
00090 void Material::SetNull ()
00091 {
00092         ambient.SetNull();
00093         diffuse.SetNull();
00094         specular.SetNull();
00095         emission.SetNull();
00096 }
00097 
00098 void Material::SetFull(BOOL includeEmission)
00099 {
00100         ambient.SetFull();
00101         diffuse.SetFull();
00102         specular.SetFull();
00103         if (includeEmission) emission.SetFull();
00104 }
00105 void Material::Use()
00106 {
00107         if (ambient.isEnable)   glMaterialfv(typeFace,GL_AMBIENT,ambient);
00108         if (diffuse.isEnable)   glMaterialfv(typeFace,GL_DIFFUSE,diffuse);
00109         if (specular.isEnable)  glMaterialfv(typeFace,GL_SPECULAR,specular);
00110         if (emission.isEnable)  glMaterialfv(typeFace,GL_EMISSION,emission);
00111         if (shiness.isEnable)   glMateriali (typeFace,GL_SHININESS,shiness.elem);
00112 }
00113 
00114 void Material::Record()
00115 {
00116         recorder.BeginRecord(FALSE);
00117         Use();
00118         recorder.EndRecord();
00119 }
00120 
00121 void Material::Play()
00122 {
00123         recorder.Play();
00124 }
00125 
00130 void Material::As(TypeMaterial mat) 
00131 {
00132         int num = mat%NB_MATERIAL;
00133         AsMaterial *material = &materials[num];
00134         ambient=material->ambient;
00135         diffuse=material->diffuse;
00136         specular=material->specular;
00137         //shiness=material->shininess; // sinon fait des trucs bizard
00138         shiness.Set(0);
00139 }

Generated on Fri Aug 20 19:19:47 2004 for 3d Controls by doxygen 1.3.6