material.I 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. // Filename: material.I
  2. // Created by: mike (05Feb99)
  3. //
  4. ////////////////////////////////////////////////////////////////////
  5. //
  6. // PANDA 3D SOFTWARE
  7. // Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved
  8. //
  9. // All use of this software is subject to the terms of the Panda 3d
  10. // Software license. You should have received a copy of this license
  11. // along with this source code; you will also find a current copy of
  12. // the license at http://etc.cmu.edu/panda3d/docs/license/ .
  13. //
  14. // To contact the maintainers of this program write to
  15. // [email protected] .
  16. //
  17. ////////////////////////////////////////////////////////////////////
  18. ////////////////////////////////////////////////////////////////////
  19. // Function: Material::Constructor
  20. // Access: Public
  21. // Description:
  22. ////////////////////////////////////////////////////////////////////
  23. INLINE Material::
  24. Material() {
  25. _flags = 0;
  26. _shininess = 0.0;
  27. }
  28. ////////////////////////////////////////////////////////////////////
  29. // Function: Material::Copy Constructor
  30. // Access: Public
  31. // Description:
  32. ////////////////////////////////////////////////////////////////////
  33. INLINE Material::
  34. Material(const Material &copy) {
  35. operator = (copy);
  36. }
  37. ////////////////////////////////////////////////////////////////////
  38. // Function: Material::Destructor
  39. // Access: Public
  40. // Description:
  41. ////////////////////////////////////////////////////////////////////
  42. INLINE Material::
  43. ~Material() {
  44. }
  45. ////////////////////////////////////////////////////////////////////
  46. // Function: Material::has_ambient
  47. // Access: Public
  48. // Description: Returns true if the ambient color has been explicitly
  49. // set for this material, false otherwise.
  50. ////////////////////////////////////////////////////////////////////
  51. INLINE bool Material::
  52. has_ambient() const {
  53. return (_flags & F_ambient) != 0;
  54. }
  55. ////////////////////////////////////////////////////////////////////
  56. // Function: Material::get_ambient
  57. // Access: Public
  58. // Description: Returns the ambient color setting, if it has been
  59. // set. Returns (0,0,0,0) if the ambient color has not
  60. // been set.
  61. ////////////////////////////////////////////////////////////////////
  62. INLINE const Colorf &Material::
  63. get_ambient() const {
  64. return (_flags & F_ambient) != 0 ? _ambient : Colorf::zero();
  65. }
  66. ////////////////////////////////////////////////////////////////////
  67. // Function: Material::clear_ambient
  68. // Access: Public
  69. // Description: Removes the explicit ambient color from the material.
  70. ////////////////////////////////////////////////////////////////////
  71. INLINE void Material::
  72. clear_ambient() {
  73. _flags &= ~F_ambient;
  74. }
  75. ////////////////////////////////////////////////////////////////////
  76. // Function: Material::has_diffuse
  77. // Access: Public
  78. // Description: Returns true if the diffuse color has been explicitly
  79. // set for this material, false otherwise.
  80. ////////////////////////////////////////////////////////////////////
  81. INLINE bool Material::
  82. has_diffuse() const {
  83. return (_flags & F_diffuse) != 0;
  84. }
  85. ////////////////////////////////////////////////////////////////////
  86. // Function: Material::get_diffuse
  87. // Access: Public
  88. // Description: Returns the diffuse color setting, if it has been
  89. // set. Returns (0,0,0,0) if the diffuse color has not
  90. // been set.
  91. ////////////////////////////////////////////////////////////////////
  92. INLINE const Colorf &Material::
  93. get_diffuse() const {
  94. return (_flags & F_diffuse) != 0 ? _diffuse : Colorf::zero();
  95. }
  96. ////////////////////////////////////////////////////////////////////
  97. // Function: Material::clear_diffuse
  98. // Access: Public
  99. // Description: Removes the explicit diffuse color from the material.
  100. ////////////////////////////////////////////////////////////////////
  101. INLINE void Material::
  102. clear_diffuse() {
  103. _flags &= ~F_diffuse;
  104. }
  105. ////////////////////////////////////////////////////////////////////
  106. // Function: Material::has_specular
  107. // Access: Public
  108. // Description: Returns true if the specular color has been explicitly
  109. // set for this material, false otherwise.
  110. ////////////////////////////////////////////////////////////////////
  111. INLINE bool Material::
  112. has_specular() const {
  113. return (_flags & F_specular) != 0;
  114. }
  115. ////////////////////////////////////////////////////////////////////
  116. // Function: Material::get_specular
  117. // Access: Public
  118. // Description: Returns the specular color setting, if it has been
  119. // set. Returns (0,0,0,0) if the specular color has not
  120. // been set.
  121. ////////////////////////////////////////////////////////////////////
  122. INLINE const Colorf &Material::
  123. get_specular() const {
  124. return (_flags & F_specular) != 0 ? _specular : Colorf::zero();
  125. }
  126. ////////////////////////////////////////////////////////////////////
  127. // Function: Material::clear_specular
  128. // Access: Public
  129. // Description: Removes the explicit specular color from the material.
  130. ////////////////////////////////////////////////////////////////////
  131. INLINE void Material::
  132. clear_specular() {
  133. _flags &= ~F_specular;
  134. }
  135. ////////////////////////////////////////////////////////////////////
  136. // Function: Material::has_emission
  137. // Access: Public
  138. // Description: Returns true if the emission color has been explicitly
  139. // set for this material, false otherwise.
  140. ////////////////////////////////////////////////////////////////////
  141. INLINE bool Material::
  142. has_emission() const {
  143. return (_flags & F_emission) != 0;
  144. }
  145. ////////////////////////////////////////////////////////////////////
  146. // Function: Material::get_emission
  147. // Access: Public
  148. // Description: Returns the emmission color setting, if it has been
  149. // set. Returns (0,0,0,0) if the emmission color has not
  150. // been set.
  151. ////////////////////////////////////////////////////////////////////
  152. INLINE const Colorf &Material::
  153. get_emission() const {
  154. return (_flags & F_emission) != 0 ? _emission : Colorf::zero();
  155. }
  156. ////////////////////////////////////////////////////////////////////
  157. // Function: Material::clear_emission
  158. // Access: Public
  159. // Description: Removes the explicit emission color from the material.
  160. ////////////////////////////////////////////////////////////////////
  161. INLINE void Material::
  162. clear_emission() {
  163. _flags &= ~F_emission;
  164. }
  165. ////////////////////////////////////////////////////////////////////
  166. // Function: Material::get_shininess
  167. // Access: Public
  168. // Description: Returns the shininess exponent of the material.
  169. ////////////////////////////////////////////////////////////////////
  170. INLINE float Material::
  171. get_shininess() const {
  172. return _shininess;
  173. }
  174. ////////////////////////////////////////////////////////////////////
  175. // Function: Material::set_shininess
  176. // Access: Public
  177. // Description: Sets the shininess exponent of the material. This
  178. // controls the size of the specular highlight spot. In
  179. // general, larger number produce a smaller specular
  180. // highlight, which makes the object appear shinier.
  181. // Smaller numbers produce a larger highlight, which
  182. // makes the object appear less shiny.
  183. ////////////////////////////////////////////////////////////////////
  184. INLINE void Material::
  185. set_shininess(float shininess) {
  186. _shininess = shininess;
  187. }
  188. ////////////////////////////////////////////////////////////////////
  189. // Function: Material::get_local
  190. // Access: Public
  191. // Description:
  192. ////////////////////////////////////////////////////////////////////
  193. INLINE bool Material::
  194. get_local() const {
  195. return (_flags & F_local) != 0;
  196. }
  197. ////////////////////////////////////////////////////////////////////
  198. // Function: Material::set_local
  199. // Access: Public
  200. // Description:
  201. ////////////////////////////////////////////////////////////////////
  202. INLINE void Material::
  203. set_local(bool local) {
  204. if (local) {
  205. _flags |= F_local;
  206. } else {
  207. _flags &= ~F_local;
  208. }
  209. }
  210. ////////////////////////////////////////////////////////////////////
  211. // Function: Material::get_twoside
  212. // Access: Public
  213. // Description:
  214. ////////////////////////////////////////////////////////////////////
  215. INLINE bool Material::
  216. get_twoside() const {
  217. return (_flags & F_twoside) != 0;
  218. }
  219. ////////////////////////////////////////////////////////////////////
  220. // Function: Material::set_twoside
  221. // Access: Public
  222. // Description:
  223. ////////////////////////////////////////////////////////////////////
  224. INLINE void Material::
  225. set_twoside(bool twoside) {
  226. if (twoside) {
  227. _flags |= F_twoside;
  228. } else {
  229. _flags &= ~F_twoside;
  230. }
  231. }
  232. ////////////////////////////////////////////////////////////////////
  233. // Function: Material::operator ==
  234. // Access: Public
  235. // Description:
  236. ////////////////////////////////////////////////////////////////////
  237. INLINE bool Material::
  238. operator == (const Material &other) const {
  239. return compare_to(other) == 0;
  240. }
  241. ////////////////////////////////////////////////////////////////////
  242. // Function: Material::operator !=
  243. // Access: Public
  244. // Description:
  245. ////////////////////////////////////////////////////////////////////
  246. INLINE bool Material::
  247. operator != (const Material &other) const {
  248. return compare_to(other) != 0;
  249. }
  250. ////////////////////////////////////////////////////////////////////
  251. // Function: Material::operator <
  252. // Access: Public
  253. // Description:
  254. ////////////////////////////////////////////////////////////////////
  255. INLINE bool Material::
  256. operator < (const Material &other) const {
  257. return compare_to(other) < 0;
  258. }