polylightNode.I 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436
  1. // Filename: PolylightNodeEffect.I
  2. // Created by: sshodhan (02Jun04)
  3. //
  4. ////////////////////////////////////////////////////////////////////
  5. //
  6. // PANDA 3D SOFTWARE
  7. // Copyright (c) Carnegie Mellon University. All rights reserved.
  8. //
  9. // All use of this software is subject to the terms of the revised BSD
  10. // license. You should have received a copy of this license along
  11. // with this source code in a file named "LICENSE."
  12. //
  13. ////////////////////////////////////////////////////////////////////
  14. ////////////////////////////////////////////////////////////////////
  15. // Function: PolylightNode::operator ==
  16. // Access: Published
  17. // Description: Returns true if the two lights are equivalent
  18. // that is, all their properties are same
  19. ////////////////////////////////////////////////////////////////////
  20. INLINE bool PolylightNode::
  21. operator == (const PolylightNode &other) const {
  22. return (compare_to(other) == 0);
  23. }
  24. ////////////////////////////////////////////////////////////////////
  25. // Function: PolylightNode::operator !=
  26. // Access: Published
  27. // Description: Returns true if the two lights are not equivalent.
  28. ////////////////////////////////////////////////////////////////////
  29. INLINE bool PolylightNode::
  30. operator != (const PolylightNode &other) const {
  31. return (compare_to(other) != 0);
  32. }
  33. ////////////////////////////////////////////////////////////////////
  34. // Function: PolylightNode::operator <
  35. // Access: Published
  36. // Description: Returns true if this PolylightNode sorts before the other
  37. // one, false otherwise. The sorting order of two
  38. // nonequivalent PolylightNodes is consistent but undefined,
  39. // and is useful only for storing PolylightNodes in a sorted
  40. // container like an STL set.
  41. ////////////////////////////////////////////////////////////////////
  42. INLINE bool PolylightNode::
  43. operator < (const PolylightNode &other) const {
  44. return (compare_to(other) < 0);
  45. }
  46. ////////////////////////////////////////////////////////////////////
  47. // Function: PolylightNode::is_enabled
  48. // Access: Published
  49. // Description: Is this light is enabled/disabled?
  50. ////////////////////////////////////////////////////////////////////
  51. INLINE bool PolylightNode::
  52. is_enabled() const {
  53. return _enabled;
  54. }
  55. ////////////////////////////////////////////////////////////////////
  56. // Function: PolylightNode::enable
  57. // Access: Published
  58. // Description: Enable this light
  59. ////////////////////////////////////////////////////////////////////
  60. INLINE void PolylightNode::
  61. enable(){
  62. _enabled=true;
  63. }
  64. ////////////////////////////////////////////////////////////////////
  65. // Function: PolylightNode::disable
  66. // Access: Published
  67. // Description: Disable this light
  68. ////////////////////////////////////////////////////////////////////
  69. INLINE void PolylightNode::
  70. disable(){
  71. _enabled=false;
  72. }
  73. ////////////////////////////////////////////////////////////////////
  74. // Function: PolylightNode::set_pos
  75. // Access: Published
  76. // Description: Set this light's position
  77. ////////////////////////////////////////////////////////////////////
  78. INLINE void PolylightNode::
  79. set_pos(LVecBase3f position){
  80. _position = position;
  81. }
  82. ////////////////////////////////////////////////////////////////////
  83. // Function: PolylightNode::set_pos
  84. // Access: Published
  85. // Description: Set this light's position
  86. ////////////////////////////////////////////////////////////////////
  87. INLINE void PolylightNode::
  88. set_pos(float x, float y, float z){
  89. _position[0]=x;
  90. _position[1]=y;
  91. _position[2]=z;
  92. }
  93. ////////////////////////////////////////////////////////////////////
  94. // Function: PolylightNode::get_pos
  95. // Access: Published
  96. // Description: Returns position as a LPoint3f
  97. ////////////////////////////////////////////////////////////////////
  98. INLINE LVecBase3f PolylightNode::
  99. get_pos() const {
  100. return _position;
  101. }
  102. ////////////////////////////////////////////////////////////////////
  103. // Function: PolylightNode::set_radius
  104. // Access: Published
  105. // Description: Set radius of the spherical light volume
  106. ////////////////////////////////////////////////////////////////////
  107. INLINE void PolylightNode::
  108. set_radius(float r){
  109. _radius=r;
  110. }
  111. ////////////////////////////////////////////////////////////////////
  112. // Function: PolylightNode::get_radius
  113. // Access: Published
  114. // Description: Get radius of the spherical light volume
  115. ////////////////////////////////////////////////////////////////////
  116. INLINE float PolylightNode::
  117. get_radius() const {
  118. return _radius;
  119. }
  120. ////////////////////////////////////////////////////////////////////
  121. // Function: PolylightNode::set_attenuation
  122. // Access: Published
  123. // Description: Set ALINEAR or AQUADRATIC attenuation
  124. ////////////////////////////////////////////////////////////////////
  125. INLINE bool PolylightNode::
  126. set_attenuation(PolylightNode::Attenuation_Type type){
  127. nassertr(type == ALINEAR || type == AQUADRATIC,false);
  128. _attenuation_type=type;
  129. return true;
  130. }
  131. ////////////////////////////////////////////////////////////////////
  132. // Function: PolylightNode::get_attenuation
  133. // Access: Published
  134. // Description: Get "linear" or "quadratic" attenuation type
  135. ////////////////////////////////////////////////////////////////////
  136. INLINE PolylightNode::Attenuation_Type PolylightNode::
  137. get_attenuation() const {
  138. return _attenuation_type;
  139. }
  140. ////////////////////////////////////////////////////////////////////
  141. // Function: PolylightNode::set_a0
  142. // Access: Published
  143. // Description: Set the quadratic attenuation factor a0
  144. // fd = 1 / ( a0 + a1*distance + a2*distance*distance)
  145. ////////////////////////////////////////////////////////////////////
  146. INLINE void PolylightNode::
  147. set_a0(float a0){
  148. _a0=a0;
  149. }
  150. ////////////////////////////////////////////////////////////////////
  151. // Function: PolylightNode::set_a1
  152. // Access: Published
  153. // Description: Set the quadratic attenuation factor a1
  154. // fd = 1 / ( a0 + a1*distance + a2*distance*distance)
  155. ////////////////////////////////////////////////////////////////////
  156. INLINE void PolylightNode::
  157. set_a1(float a1){
  158. _a1=a1;
  159. }
  160. ////////////////////////////////////////////////////////////////////
  161. // Function: PolylightNode::set_a2
  162. // Access: Published
  163. // Description: Set the quadratic attenuation factor a2
  164. // fd = 1 / ( a0 + a1*distance + a2*distance*distance)
  165. ////////////////////////////////////////////////////////////////////
  166. INLINE void PolylightNode::
  167. set_a2(float a2){
  168. _a2=a2;
  169. }
  170. ////////////////////////////////////////////////////////////////////
  171. // Function: PolylightNode::get_a0
  172. // Access: Published
  173. // Description: Get the quadratic attenuation factor a0
  174. // fd = 1 / ( a0 + a1*distance + a2*distance*distance)
  175. ////////////////////////////////////////////////////////////////////
  176. INLINE float PolylightNode::
  177. get_a0() const {
  178. return _a0;
  179. }
  180. ////////////////////////////////////////////////////////////////////
  181. // Function: PolylightNode::get_a1
  182. // Access: Published
  183. // Description: Get the quadratic attenuation factor a1
  184. // fd = 1 / ( a0 + a1*distance + a2*distance*distance)
  185. ////////////////////////////////////////////////////////////////////
  186. INLINE float PolylightNode::
  187. get_a1() const {
  188. return _a1;
  189. }
  190. ////////////////////////////////////////////////////////////////////
  191. // Function: PolylightNode::get_a2
  192. // Access: Published
  193. // Description: Get the quadratic attenuation factor a2
  194. // fd = 1 / ( a0 + a1*distance + a2*distance*distance)
  195. ////////////////////////////////////////////////////////////////////
  196. INLINE float PolylightNode::
  197. get_a2() const {
  198. return _a2;
  199. }
  200. ////////////////////////////////////////////////////////////////////
  201. // Function: PolylightNode::flicker_on
  202. // Access: Published
  203. // Description: Set flickering to true so at every loop this light's
  204. // color is varied based on flicker_type
  205. ////////////////////////////////////////////////////////////////////
  206. INLINE void PolylightNode::
  207. flicker_on(){
  208. _flickering=true;
  209. }
  210. ////////////////////////////////////////////////////////////////////
  211. // Function: PolylightNode::flicker_off
  212. // Access: Published
  213. // Description: Turn flickering off
  214. ////////////////////////////////////////////////////////////////////
  215. INLINE void PolylightNode::
  216. flicker_off(){
  217. _flickering=false;
  218. }
  219. ////////////////////////////////////////////////////////////////////
  220. // Function: PolylightNode::is_flickering
  221. // Access: Published
  222. // Description: Check is this light is flickering
  223. ////////////////////////////////////////////////////////////////////
  224. INLINE bool PolylightNode::
  225. is_flickering() const {
  226. return _flickering;
  227. }
  228. ////////////////////////////////////////////////////////////////////
  229. // Function: PolylightNode::set_flicker_type
  230. // Access: Published
  231. // Description: Flicker type can be FRANDOM or FSIN
  232. // At a later point there might be a FCUSTOM
  233. // Custom flicker will be a set of fix points recorded
  234. // by animating the light's intensity
  235. ////////////////////////////////////////////////////////////////////
  236. INLINE bool PolylightNode::
  237. set_flicker_type(PolylightNode::Flicker_Type type){
  238. nassertr(type == FRANDOM || type == FSIN,false);
  239. _flicker_type=type;
  240. return true;
  241. }
  242. ////////////////////////////////////////////////////////////////////
  243. // Function: PolylightNode::get_flicker_type
  244. // Access: Published
  245. // Description: Returns FRANDOM or FSIN
  246. ////////////////////////////////////////////////////////////////////
  247. INLINE PolylightNode::Flicker_Type PolylightNode::
  248. get_flicker_type() const {
  249. return _flicker_type;
  250. }
  251. ////////////////////////////////////////////////////////////////////
  252. // Function: PolylightNode::set_offset
  253. // Access: Published
  254. // Description: Set the offset value for the random and sin
  255. // flicker variations... used to tweak the flicker
  256. // This value is added to the variation
  257. ////////////////////////////////////////////////////////////////////
  258. INLINE void PolylightNode::
  259. set_offset(float offset){
  260. _offset=offset;
  261. }
  262. ////////////////////////////////////////////////////////////////////
  263. // Function: PolylightNode::get_offset
  264. // Access: Published
  265. // Description: Get the offset value for the random and sin
  266. // flicker variations
  267. ////////////////////////////////////////////////////////////////////
  268. INLINE float PolylightNode::
  269. get_offset() const {
  270. return _offset;
  271. }
  272. ////////////////////////////////////////////////////////////////////
  273. // Function: PolylightNode::set_scale
  274. // Access: Published
  275. // Description: Set the scale value for the random and sin
  276. // flicker variations... used to tweak the flicker
  277. // This value is multiplied with the variation
  278. ////////////////////////////////////////////////////////////////////
  279. INLINE void PolylightNode::
  280. set_scale(float scale){
  281. _scale=scale;
  282. }
  283. ////////////////////////////////////////////////////////////////////
  284. // Function: PolylightNode::get_scale
  285. // Access: Published
  286. // Description: Get the scale value for the random and sin
  287. // flicker variations
  288. ////////////////////////////////////////////////////////////////////
  289. INLINE float PolylightNode::
  290. get_scale() const {
  291. return _scale;
  292. }
  293. ////////////////////////////////////////////////////////////////////
  294. // Function: PolylightNode::set_step_size
  295. // Access: Published
  296. // Description: Set the step size for the sin function in flicker
  297. // This is the increment size for the value supplied
  298. // to the sin function
  299. ////////////////////////////////////////////////////////////////////
  300. INLINE void PolylightNode::
  301. set_step_size(float step){
  302. _step_size=step;
  303. }
  304. ////////////////////////////////////////////////////////////////////
  305. // Function: PolylightNode::get_step_size
  306. // Access: Published
  307. // Description: Get the step size for the sin function in flicker
  308. // This is the increment size for the value supplied
  309. // to the sin function
  310. ////////////////////////////////////////////////////////////////////
  311. INLINE float PolylightNode::
  312. get_step_size() const {
  313. return _step_size;
  314. }
  315. ////////////////////////////////////////////////////////////////////
  316. // Function: PolylightNode::set_color
  317. // Access: Published
  318. // Description: Set the light's color...
  319. ////////////////////////////////////////////////////////////////////
  320. INLINE void PolylightNode::
  321. set_color(Colorf color) {
  322. //PandaNode::set_attrib(ColorAttrib::make_flat(color));
  323. _color = color;
  324. }
  325. ////////////////////////////////////////////////////////////////////
  326. // Function: PolylightNode::set_color
  327. // Access: Published
  328. // Description: Set the light's color... 3 floats between 0 and 1
  329. ////////////////////////////////////////////////////////////////////
  330. INLINE void PolylightNode::
  331. set_color(float r, float g, float b) {
  332. /*
  333. Colorf color;
  334. color[0] = r;
  335. color[1] = g;
  336. color[2] = b;
  337. color[3] = 1.0;
  338. PandaNode::set_attrib(ColorAttrib::make_flat(color));
  339. */
  340. _color[0] = r;
  341. _color[1] = g;
  342. _color[2] = b;
  343. _color[3] = 1.0;
  344. }
  345. ////////////////////////////////////////////////////////////////////
  346. // Function: PolylightNode::get_color
  347. // Access: Published
  348. // Description: Returns the light's color as Colorf
  349. ////////////////////////////////////////////////////////////////////
  350. INLINE Colorf PolylightNode::
  351. get_color() const {
  352. return _color;
  353. }
  354. ////////////////////////////////////////////////////////////////////
  355. // Function: PolylightNode::get_color_scenegraph
  356. // Access: Published
  357. // Description: This differs from get_color in that when applying
  358. // the light color we need to make sure that a color
  359. // flattening external to the PolylightNode is not
  360. // ignored.
  361. ////////////////////////////////////////////////////////////////////
  362. INLINE Colorf PolylightNode::
  363. get_color_scenegraph() const {
  364. const RenderAttrib *attrib =
  365. PandaNode::get_attrib(ColorAttrib::get_class_type());
  366. if (attrib != (const RenderAttrib *)NULL) {
  367. const ColorAttrib *ca = DCAST(ColorAttrib, attrib);
  368. if (ca->get_color_type() == ColorAttrib::T_flat) {
  369. return ca->get_color();
  370. }
  371. }
  372. return _color;
  373. }
  374. ////////////////////////////////////////////////////////////////////
  375. // Function: PolylightNode::set_freq
  376. // Access: Published
  377. // Description: Set frequency of sin flicker
  378. ////////////////////////////////////////////////////////////////////
  379. INLINE void PolylightNode::
  380. set_freq(float f) {
  381. _sin_freq=f;
  382. }
  383. ////////////////////////////////////////////////////////////////////
  384. // Function: PolylightNode::get_freq
  385. // Access: Published
  386. // Description: Get frequency of sin flicker
  387. ////////////////////////////////////////////////////////////////////
  388. INLINE float PolylightNode::
  389. get_freq() const {
  390. return _sin_freq;
  391. }