Obj Light Point.cpp 2.8 KB

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