Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

Material.cpp

Go to the documentation of this file.
00001 #include "Material.h"
00002 
00003 using namespace X3DTK;
00004 
00005 Material::Material()
00006 : X3DMaterialNode(), ambientIntensity_(0.2f), diffuseColor_(SFColor(0.8f, 0.8f, 0.8f)), emissiveColor_(SFColor(0.0f, 0.0f, 0.0f)), shininess_(0.2f), specularColor_(SFColor(0.0f, 0.0f, 0.0f)), transparency_(0.0f)
00007 { 
00008   defineTagName("Material", "Shape");
00009 }
00010 
00011 Material::Material(SFFloat ambientIntensity, SFColor diffuseColor, SFColor emissiveColor, SFFloat shininess, SFColor specularColor, SFFloat transparency)
00012 : X3DMaterialNode(), ambientIntensity_(ambientIntensity), diffuseColor_(diffuseColor), emissiveColor_(emissiveColor), shininess_(shininess), specularColor_(specularColor), transparency_(transparency)
00013 {
00014   defineTagName("Material", "Shape");
00015 }
00016 
00017 Material::Material(const Material &M)
00018 : X3DMaterialNode(M), ambientIntensity_(M.ambientIntensity_), diffuseColor_(M.diffuseColor_), emissiveColor_(M.emissiveColor_), shininess_(M.shininess_), specularColor_(M.specularColor_), transparency_(M.transparency_)
00019 {
00020   defineTagName("Material", "Shape");
00021 }
00022 
00023 SFNode Material::clone() const
00024 {
00025   return new Material(*this);
00026 }
00027 
00028 Material::~Material()
00029 {
00030 }
00031 
00032 void Material::setAmbientIntensity(SFFloat ambientIntensity)
00033 {
00034   ambientIntensity_ = ambientIntensity;
00035 }
00036 
00037 void Material::setDiffuseColor(SFColor diffuseColor)
00038 {
00039   diffuseColor_ = diffuseColor;
00040 }
00041 
00042 void Material::setEmissiveColor(SFColor emissiveColor)  
00043 {
00044   emissiveColor_ = emissiveColor;
00045 }
00046 
00047 void Material::setShininess(SFFloat shininess)  
00048 {
00049   shininess_ = shininess;
00050 }
00051 
00052 void Material::setSpecularColor(SFColor specularColor)  
00053 {
00054   specularColor_ = specularColor;  
00055 }
00056 
00057 void Material::setTransparency(SFFloat transparency)  
00058 {
00059   transparency_ = transparency;
00060 }
00061 
00062 void Material::loadAttributes(const X3DFileElement *element)
00063 {
00064   int index;
00065   index = element->getIndexAttribute("ambientIntensity");
00066   if (index != -1)
00067     ambientIntensity_ = element->getAttribute(index).toFloat();
00068 
00069   index = element->getIndexAttribute("diffuseColor");
00070   if (index != -1)
00071     diffuseColor_ = SFColor(element->getAttribute(index));
00072 
00073   index = element->getIndexAttribute("emissiveColor");
00074   if (index != -1)
00075     emissiveColor_ = SFColor(element->getAttribute(index));
00076 
00077   index = element->getIndexAttribute("shininess");
00078   if (index != -1)
00079     shininess_ = element->getAttribute(index).toFloat();
00080 
00081   index = element->getIndexAttribute("specularColor");
00082   if (index != -1)
00083     specularColor_ = SFColor(element->getAttribute(index));
00084 }
00085 
00086 SFString Material::writeAttributes() const
00087 {
00088   SFString attr;
00089   if (ambientIntensity_ != 0.2f)
00090     attr += " ambientIntensity=\"" + toSFString(ambientIntensity_) + "\"";
00091   if (diffuseColor_ != SFColor(0.8f, 0.8f, 0.8f))  
00092     attr += " diffuseColor=\"" + toSFString(diffuseColor_) + "\"";
00093   if (emissiveColor_ != SFColor(0.0f, 0.0f, 0.0f))  
00094     attr += " emissiveColor=\"" + toSFString(emissiveColor_) + "\"";
00095   if (shininess_ != 0.2f)
00096     attr += " shininess=\"" + toSFString(shininess_) + "\"";
00097   if (specularColor_ != SFColor(0.0f, 0.0f, 0.0f))
00098     attr += " specularColor=\"" + toSFString(specularColor_) + "\"";
00099   if (transparency_ != 0.0f)
00100     attr += " transparency=\"" + toSFString(transparency_) + "\"";
00101       
00102   return attr;
00103 }

Generated on Wed May 14 10:03:10 2003 for X3DToolKit by doxygen1.3