Panda3D
|
00001 // Filename: material.I 00002 // Created by: mike (05Feb99) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) Carnegie Mellon University. All rights reserved. 00008 // 00009 // All use of this software is subject to the terms of the revised BSD 00010 // license. You should have received a copy of this license along 00011 // with this source code in a file named "LICENSE." 00012 // 00013 //////////////////////////////////////////////////////////////////// 00014 00015 00016 //////////////////////////////////////////////////////////////////// 00017 // Function: Material::Constructor 00018 // Access: Published 00019 // Description: 00020 //////////////////////////////////////////////////////////////////// 00021 INLINE Material:: 00022 Material(const string &name) : Namable(name) { 00023 _ambient.set(1.0f, 1.0f, 1.0f, 1.0f); 00024 _diffuse.set(1.0f, 1.0f, 1.0f, 1.0f); 00025 _specular.set(0.0f, 0.0f, 0.0f, 1.0f); 00026 _emission.set(0.0f, 0.0f, 0.0f, 1.0f); 00027 _shininess = 0.0; 00028 _flags = 0; 00029 } 00030 00031 //////////////////////////////////////////////////////////////////// 00032 // Function: Material::Copy Constructor 00033 // Access: Published 00034 // Description: 00035 //////////////////////////////////////////////////////////////////// 00036 INLINE Material:: 00037 Material(const Material ©) : Namable(copy) { 00038 operator = (copy); 00039 } 00040 00041 //////////////////////////////////////////////////////////////////// 00042 // Function: Material::Destructor 00043 // Access: Published 00044 // Description: 00045 //////////////////////////////////////////////////////////////////// 00046 INLINE Material:: 00047 ~Material() { 00048 } 00049 00050 //////////////////////////////////////////////////////////////////// 00051 // Function: Material::get_default 00052 // Access: Published, Static 00053 // Description: Returns the default material. 00054 //////////////////////////////////////////////////////////////////// 00055 INLINE Material *Material:: 00056 get_default() { 00057 if (_default == 0) { 00058 _default = new Material("default"); 00059 } 00060 return _default; 00061 } 00062 00063 //////////////////////////////////////////////////////////////////// 00064 // Function: Material::has_ambient 00065 // Access: Published 00066 // Description: Returns true if the ambient color has been explicitly 00067 // set for this material, false otherwise. 00068 //////////////////////////////////////////////////////////////////// 00069 INLINE bool Material:: 00070 has_ambient() const { 00071 return (_flags & F_ambient) != 0; 00072 } 00073 00074 //////////////////////////////////////////////////////////////////// 00075 // Function: Material::get_ambient 00076 // Access: Published 00077 // Description: Returns the ambient color setting, if it has been 00078 // set. Returns (0,0,0,0) if the ambient color has not 00079 // been set. 00080 //////////////////////////////////////////////////////////////////// 00081 INLINE const LColor &Material:: 00082 get_ambient() const { 00083 return _ambient; 00084 } 00085 00086 //////////////////////////////////////////////////////////////////// 00087 // Function: Material::clear_ambient 00088 // Access: Published 00089 // Description: Removes the explicit ambient color from the material. 00090 //////////////////////////////////////////////////////////////////// 00091 INLINE void Material:: 00092 clear_ambient() { 00093 if (enforce_attrib_lock) { 00094 nassertv(!is_attrib_locked()); 00095 } 00096 _flags &= ~F_ambient; 00097 _ambient.set(0.0f, 0.0f, 0.0f, 0.0f); 00098 } 00099 00100 //////////////////////////////////////////////////////////////////// 00101 // Function: Material::has_diffuse 00102 // Access: Published 00103 // Description: Returns true if the diffuse color has been explicitly 00104 // set for this material, false otherwise. 00105 //////////////////////////////////////////////////////////////////// 00106 INLINE bool Material:: 00107 has_diffuse() const { 00108 return (_flags & F_diffuse) != 0; 00109 } 00110 00111 //////////////////////////////////////////////////////////////////// 00112 // Function: Material::get_diffuse 00113 // Access: Published 00114 // Description: Returns the diffuse color setting, if it has been 00115 // set. Returns (1,1,1,1) if the diffuse color has not 00116 // been set. 00117 //////////////////////////////////////////////////////////////////// 00118 INLINE const LColor &Material:: 00119 get_diffuse() const { 00120 return _diffuse; 00121 } 00122 00123 //////////////////////////////////////////////////////////////////// 00124 // Function: Material::clear_diffuse 00125 // Access: Published 00126 // Description: Removes the explicit diffuse color from the material. 00127 //////////////////////////////////////////////////////////////////// 00128 INLINE void Material:: 00129 clear_diffuse() { 00130 if (enforce_attrib_lock) { 00131 nassertv(!is_attrib_locked()); 00132 } 00133 _flags &= ~F_diffuse; 00134 _diffuse.set(1.0f, 1.0f, 1.0f, 1.0f); 00135 } 00136 00137 //////////////////////////////////////////////////////////////////// 00138 // Function: Material::has_specular 00139 // Access: Published 00140 // Description: Returns true if the specular color has been explicitly 00141 // set for this material, false otherwise. 00142 //////////////////////////////////////////////////////////////////// 00143 INLINE bool Material:: 00144 has_specular() const { 00145 return (_flags & F_specular) != 0; 00146 } 00147 00148 //////////////////////////////////////////////////////////////////// 00149 // Function: Material::get_specular 00150 // Access: Published 00151 // Description: Returns the specular color setting, if it has been 00152 // set. Returns (0,0,0,0) if the specular color has not 00153 // been set. 00154 //////////////////////////////////////////////////////////////////// 00155 INLINE const LColor &Material:: 00156 get_specular() const { 00157 return _specular; 00158 } 00159 00160 //////////////////////////////////////////////////////////////////// 00161 // Function: Material::clear_specular 00162 // Access: Published 00163 // Description: Removes the explicit specular color from the material. 00164 //////////////////////////////////////////////////////////////////// 00165 INLINE void Material:: 00166 clear_specular() { 00167 if (enforce_attrib_lock) { 00168 nassertv(!is_attrib_locked()); 00169 } 00170 _flags &= ~F_specular; 00171 _specular.set(0.0f, 0.0f, 0.0f, 0.0f); 00172 } 00173 00174 //////////////////////////////////////////////////////////////////// 00175 // Function: Material::has_emission 00176 // Access: Published 00177 // Description: Returns true if the emission color has been explicitly 00178 // set for this material, false otherwise. 00179 //////////////////////////////////////////////////////////////////// 00180 INLINE bool Material:: 00181 has_emission() const { 00182 return (_flags & F_emission) != 0; 00183 } 00184 00185 //////////////////////////////////////////////////////////////////// 00186 // Function: Material::get_emission 00187 // Access: Published 00188 // Description: Returns the emission color setting, if it has been 00189 // set. Returns (0,0,0,0) if the emission color has not 00190 // been set. 00191 //////////////////////////////////////////////////////////////////// 00192 INLINE const LColor &Material:: 00193 get_emission() const { 00194 return _emission; 00195 } 00196 00197 //////////////////////////////////////////////////////////////////// 00198 // Function: Material::clear_emission 00199 // Access: Published 00200 // Description: Removes the explicit emission color from the material. 00201 //////////////////////////////////////////////////////////////////// 00202 INLINE void Material:: 00203 clear_emission() { 00204 if (enforce_attrib_lock) { 00205 nassertv(!is_attrib_locked()); 00206 } 00207 _flags &= ~F_emission; 00208 _emission.set(0.0f, 0.0f, 0.0f, 0.0f); 00209 } 00210 00211 //////////////////////////////////////////////////////////////////// 00212 // Function: Material::get_shininess 00213 // Access: Published 00214 // Description: Returns the shininess exponent of the material. 00215 //////////////////////////////////////////////////////////////////// 00216 INLINE PN_stdfloat Material:: 00217 get_shininess() const { 00218 return _shininess; 00219 } 00220 00221 //////////////////////////////////////////////////////////////////// 00222 // Function: Material::set_shininess 00223 // Access: Published 00224 // Description: Sets the shininess exponent of the material. This 00225 // controls the size of the specular highlight spot. In 00226 // general, larger number produce a smaller specular 00227 // highlight, which makes the object appear shinier. 00228 // Smaller numbers produce a larger highlight, which 00229 // makes the object appear less shiny. 00230 //////////////////////////////////////////////////////////////////// 00231 INLINE void Material:: 00232 set_shininess(PN_stdfloat shininess) { 00233 _shininess = shininess; 00234 } 00235 00236 //////////////////////////////////////////////////////////////////// 00237 // Function: Material::get_local 00238 // Access: Published 00239 // Description: Returns the local viewer flag. Set set_local(). 00240 //////////////////////////////////////////////////////////////////// 00241 INLINE bool Material:: 00242 get_local() const { 00243 return (_flags & F_local) != 0; 00244 } 00245 00246 //////////////////////////////////////////////////////////////////// 00247 // Function: Material::set_local 00248 // Access: Published 00249 // Description: Sets the local viewer flag. Set this true to enable 00250 // camera-relative specular highlights, or false to use 00251 // orthogonal specular highlights. The default value is 00252 // true. Applications that use orthogonal projection 00253 // should specify false. 00254 //////////////////////////////////////////////////////////////////// 00255 INLINE void Material:: 00256 set_local(bool local) { 00257 if (enforce_attrib_lock) { 00258 nassertv(!is_attrib_locked()); 00259 } 00260 if (local) { 00261 _flags |= F_local; 00262 } else { 00263 _flags &= ~F_local; 00264 } 00265 } 00266 00267 //////////////////////////////////////////////////////////////////// 00268 // Function: Material::get_twoside 00269 // Access: Published 00270 // Description: Returns the state of the two-sided lighting flag. 00271 // See set_twoside(). 00272 //////////////////////////////////////////////////////////////////// 00273 INLINE bool Material:: 00274 get_twoside() const { 00275 return (_flags & F_twoside) != 0; 00276 } 00277 00278 //////////////////////////////////////////////////////////////////// 00279 // Function: Material::set_twoside 00280 // Access: Published 00281 // Description: Set this true to enable two-sided lighting. When 00282 // two-sided lighting is on, both sides of a polygon 00283 // will be lit by this material. The default is for 00284 // two-sided lighting to be off, in which case only the 00285 // front surface is lit. 00286 //////////////////////////////////////////////////////////////////// 00287 INLINE void Material:: 00288 set_twoside(bool twoside) { 00289 if (enforce_attrib_lock) { 00290 nassertv(!is_attrib_locked()); 00291 } 00292 if (twoside) { 00293 _flags |= F_twoside; 00294 } else { 00295 _flags &= ~F_twoside; 00296 } 00297 } 00298 00299 //////////////////////////////////////////////////////////////////// 00300 // Function: Material::operator == 00301 // Access: Published 00302 // Description: 00303 //////////////////////////////////////////////////////////////////// 00304 INLINE bool Material:: 00305 operator == (const Material &other) const { 00306 return compare_to(other) == 0; 00307 } 00308 00309 //////////////////////////////////////////////////////////////////// 00310 // Function: Material::operator != 00311 // Access: Published 00312 // Description: 00313 //////////////////////////////////////////////////////////////////// 00314 INLINE bool Material:: 00315 operator != (const Material &other) const { 00316 return compare_to(other) != 0; 00317 } 00318 00319 //////////////////////////////////////////////////////////////////// 00320 // Function: Material::operator < 00321 // Access: Published 00322 // Description: 00323 //////////////////////////////////////////////////////////////////// 00324 INLINE bool Material:: 00325 operator < (const Material &other) const { 00326 return compare_to(other) < 0; 00327 } 00328 00329 //////////////////////////////////////////////////////////////////// 00330 // Function: Material::is_attrib_locked 00331 // Access: Published 00332 // Description: 00333 //////////////////////////////////////////////////////////////////// 00334 INLINE bool Material:: 00335 is_attrib_locked() const { 00336 return (_flags & F_attrib_lock) != 0; 00337 } 00338 00339 //////////////////////////////////////////////////////////////////// 00340 // Function: Material::set_attrib_lock 00341 // Access: Published 00342 // Description: 00343 //////////////////////////////////////////////////////////////////// 00344 INLINE void Material:: 00345 set_attrib_lock() { 00346 _flags |= F_attrib_lock; 00347 }