Obj Light Cone.cpp 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /******************************************************************************/
  2. #include "stdafx.h"
  3. namespace EE{
  4. namespace Game{
  5. /******************************************************************************/
  6. ObjLightCone::~ObjLightCone()
  7. {
  8. }
  9. ObjLightCone::ObjLightCone()
  10. {
  11. cast_shadows=true;
  12. range =0;
  13. volumetric=0;
  14. angle =1;
  15. falloff =0.5f;
  16. position .zero();
  17. direction.set(0, 0, 1);
  18. color .set(1, 1, 1);
  19. }
  20. /******************************************************************************/
  21. // MANAGE
  22. /******************************************************************************/
  23. void ObjLightCone::create(Object &obj)
  24. {
  25. range = obj.scale();
  26. position = obj.matrixFinal().pos;
  27. direction=!obj.matrix.z;
  28. if(Param *param=obj.findParam("cast shadows"))cast_shadows= param->asBool();
  29. if(Param *param=obj.findParam("volumetric" ))volumetric =Max(param->asFlt (), 0.0f);
  30. if(Param *param=obj.findParam("angle" ))angle =Max(param->asFlt (), 0.0f);
  31. if(Param *param=obj.findParam("falloff" ))falloff =Sat(param->asFlt ());
  32. if(Param *param=obj.findParam("color" ))color = param->asVec ();
  33. }
  34. /******************************************************************************/
  35. // GET / SET
  36. /******************************************************************************/
  37. Vec ObjLightCone::pos ( ) {return position ;}
  38. Matrix ObjLightCone::matrix( ) {return position ;}
  39. void ObjLightCone::pos (C Vec &pos ) { position=pos ;}
  40. void ObjLightCone::matrix(C Matrix &matrix) { position=matrix.pos; direction=matrix.z;}
  41. /******************************************************************************/
  42. // UPDATE
  43. /******************************************************************************/
  44. Bool ObjLightCone::update()
  45. {
  46. return true;
  47. }
  48. /******************************************************************************/
  49. // DRAW
  50. /******************************************************************************/
  51. void ObjLightCone::drawPrepare(C Matrix &matrix)
  52. {
  53. LightCone lc(range, position*matrix, !(direction*matrix.orn()), color, volumetric);
  54. lc.pyramid.scale=angle;
  55. lc.falloff =falloff;
  56. lc.add(cast_shadows, this);
  57. }
  58. UInt ObjLightCone::drawPrepare()
  59. {
  60. LightCone lc(range, position, direction, color, volumetric);
  61. lc.pyramid.scale=angle;
  62. lc.falloff =falloff;
  63. lc.add(cast_shadows, this);
  64. return 0; // no additional render modes required
  65. }
  66. /******************************************************************************/
  67. // IO
  68. /******************************************************************************/
  69. Bool ObjLightCone::save(File &f)
  70. {
  71. if(super::save(f))
  72. {
  73. f.cmpUIntV(0); // version
  74. f<<cast_shadows<<range<<volumetric<<angle<<falloff<<position<<direction<<color;
  75. return f.ok();
  76. }
  77. return false;
  78. }
  79. Bool ObjLightCone::load(File &f)
  80. {
  81. if(super::load(f))switch(f.decUIntV()) // version
  82. {
  83. case 0:
  84. {
  85. f>>cast_shadows>>range>>volumetric>>angle>>falloff>>position>>direction>>color;
  86. if(f.ok())return true;
  87. }break;
  88. }
  89. return false;
  90. }
  91. /******************************************************************************/
  92. }}
  93. /******************************************************************************/