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

panda/src/egg/eggMaterial.cxx

Go to the documentation of this file.
00001 // Filename: eggMaterial.cxx
00002 // Created by:  drose (29Jan99)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
00008 //
00009 // All use of this software is subject to the terms of the Panda 3d
00010 // Software license.  You should have received a copy of this license
00011 // along with this source code; you will also find a current copy of
00012 // the license at http://www.panda3d.org/license.txt .
00013 //
00014 // To contact the maintainers of this program write to
00015 // panda3d@yahoogroups.com .
00016 //
00017 ////////////////////////////////////////////////////////////////////
00018 
00019 #include "eggMaterial.h"
00020 
00021 #include <indent.h>
00022 
00023 TypeHandle EggMaterial::_type_handle;
00024 
00025 
00026 ////////////////////////////////////////////////////////////////////
00027 //     Function: EggMaterial::Constructor
00028 //       Access: Public
00029 //  Description:
00030 ////////////////////////////////////////////////////////////////////
00031 EggMaterial::
00032 EggMaterial(const string &mref_name)
00033   : EggNode(mref_name)
00034 {
00035   _flags = 0;
00036 }
00037 
00038 ////////////////////////////////////////////////////////////////////
00039 //     Function: EggMaterial::Copy Constructor
00040 //       Access: Public
00041 //  Description:
00042 ////////////////////////////////////////////////////////////////////
00043 EggMaterial::
00044 EggMaterial(const EggMaterial &copy)
00045   : EggNode(copy),
00046     _diff(copy._diff),
00047     _amb(copy._amb),
00048     _emit(copy._emit),
00049     _spec(copy._spec),
00050     _shininess(copy._shininess),
00051     _local(copy._local),
00052     _flags(copy._flags)
00053 {
00054 }
00055 
00056 
00057 ////////////////////////////////////////////////////////////////////
00058 //     Function: EggMaterial::write
00059 //       Access: Public, Virtual
00060 //  Description: Writes the material definition to the indicated output
00061 //               stream in Egg format.
00062 ////////////////////////////////////////////////////////////////////
00063 void EggMaterial::
00064 write(ostream &out, int indent_level) const {
00065   write_header(out, indent_level, "<Material>");
00066 
00067   if (has_diff()) {
00068     indent(out, indent_level + 2)
00069       << "<Scalar> diffr { " << get_diff()[0] << " }\n";
00070     indent(out, indent_level + 2)
00071       << "<Scalar> diffg { " << get_diff()[1] << " }\n";
00072     indent(out, indent_level + 2)
00073       << "<Scalar> diffb { " << get_diff()[2] << " }\n";
00074     if (get_diff()[3] != 1.0) {
00075       indent(out, indent_level + 2)
00076         << "<Scalar> diffa { " << get_diff()[3] << " }\n";
00077     }
00078   }
00079 
00080   if (has_amb()) {
00081     indent(out, indent_level + 2)
00082       << "<Scalar> ambr { " << get_amb()[0] << " }\n";
00083     indent(out, indent_level + 2)
00084       << "<Scalar> ambg { " << get_amb()[1] << " }\n";
00085     indent(out, indent_level + 2)
00086       << "<Scalar> ambb { " << get_amb()[2] << " }\n";
00087     if (get_amb()[3] != 1.0) {
00088       indent(out, indent_level + 2)
00089         << "<Scalar> amba { " << get_amb()[3] << " }\n";
00090     }
00091   }
00092 
00093   if (has_emit()) {
00094     indent(out, indent_level + 2)
00095       << "<Scalar> emitr { " << get_emit()[0] << " }\n";
00096     indent(out, indent_level + 2)
00097       << "<Scalar> emitg { " << get_emit()[1] << " }\n";
00098     indent(out, indent_level + 2)
00099       << "<Scalar> emitb { " << get_emit()[2] << " }\n";
00100     if (get_emit()[3] != 1.0) {
00101       indent(out, indent_level + 2)
00102         << "<Scalar> emita { " << get_emit()[3] << " }\n";
00103     }
00104   }
00105 
00106   if (has_spec()) {
00107     indent(out, indent_level + 2)
00108       << "<Scalar> specr { " << get_spec()[0] << " }\n";
00109     indent(out, indent_level + 2)
00110       << "<Scalar> specg { " << get_spec()[1] << " }\n";
00111     indent(out, indent_level + 2)
00112       << "<Scalar> specb { " << get_spec()[2] << " }\n";
00113     if (get_spec()[3] != 1.0) {
00114       indent(out, indent_level + 2)
00115         << "<Scalar> speca { " << get_spec()[3] << " }\n";
00116     }
00117   }
00118 
00119   if (has_shininess()) {
00120     indent(out, indent_level + 2)
00121       << "<Scalar> shininess { " << get_shininess() << " }\n";
00122   }
00123 
00124   if (has_local()) {
00125     indent(out, indent_level + 2)
00126       << "<Scalar> local { " << get_local() << " }\n";
00127   }
00128 
00129   indent(out, indent_level) << "}\n";
00130 }
00131 
00132 ////////////////////////////////////////////////////////////////////
00133 //     Function: EggMaterial::is_equivalent_to
00134 //       Access: Public
00135 //  Description: Returns true if the two materials are equivalent in
00136 //               all relevant properties (according to eq), false
00137 //               otherwise.
00138 //
00139 //               The Equivalence parameter, eq, should be set to the
00140 //               bitwise OR of the following properties, according to
00141 //               what you consider relevant:
00142 //
00143 //               EggMaterial::E_attributes:
00144 //                 All material attributes (diff, spec,
00145 //                 etc.) except MRef name.
00146 //
00147 //               EggMaterial::E_mref_name:
00148 //                 The MRef name.
00149 ////////////////////////////////////////////////////////////////////
00150 bool EggMaterial::
00151 is_equivalent_to(const EggMaterial &other, int eq) const {
00152   if (eq & E_attributes) {
00153     if (_flags != other._flags ||
00154         (has_diff() && get_diff() != other.get_diff()) ||
00155         (has_amb() && get_amb() != other.get_amb()) ||
00156         (has_emit() && get_emit() != other.get_emit()) ||
00157         (has_spec() && get_spec() != other.get_spec()) ||
00158         (has_shininess() && get_shininess() != other.get_shininess()) ||
00159         (has_local() && get_local() != other.get_local())) {
00160       return false;
00161     }
00162   }
00163 
00164   if (eq & E_mref_name) {
00165     if (get_name() != other.get_name()) {
00166       return false;
00167     }
00168   }
00169 
00170   return true;
00171 }
00172 
00173 ////////////////////////////////////////////////////////////////////
00174 //     Function: EggMaterial::sorts_less_than
00175 //       Access: Public
00176 //  Description: An ordering operator to compare two materials for
00177 //               sorting order.  This imposes an arbitrary ordering
00178 //               useful to identify unique materials, according to the
00179 //               indicated Equivalence factor.  See
00180 //               is_equivalent_to().
00181 ////////////////////////////////////////////////////////////////////
00182 bool EggMaterial::
00183 sorts_less_than(const EggMaterial &other, int eq) const {
00184   if (eq & E_attributes) {
00185     if (_flags != other._flags) {
00186       return _flags < (int)other._flags;
00187     }
00188     if (has_diff() && get_diff() != other.get_diff()) {
00189       return get_diff().compare_to(other.get_diff()) < 0;
00190     }
00191     if (has_amb() && get_amb() != other.get_amb()) {
00192       return get_amb().compare_to(other.get_amb()) < 0;
00193     }
00194     if (has_emit() && get_emit() != other.get_emit()) {
00195       return get_emit().compare_to(other.get_emit()) < 0;
00196     }
00197     if (has_spec() && get_spec() != other.get_spec()) {
00198       return get_spec().compare_to(other.get_spec()) < 0;
00199     }
00200     if (has_shininess() && get_shininess() != other.get_shininess()) {
00201       return get_shininess() < other.get_shininess();
00202     }
00203     if (has_local() && get_local() != other.get_local()) {
00204       return get_local() < other.get_local();
00205     }
00206   }
00207 
00208   if (eq & E_mref_name) {
00209     if (get_name() != other.get_name()) {
00210       return get_name() < other.get_name();
00211     }
00212   }
00213 
00214   return false;
00215 }

Generated on Fri May 2 00:37:40 2003 for Panda by doxygen1.3