Static.cpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /******************************************************************************/
  2. #include "stdafx.h"
  3. namespace EE{
  4. namespace Game{
  5. /******************************************************************************/
  6. Static::~Static()
  7. {
  8. }
  9. Static::Static()
  10. {
  11. scale=0;
  12. mesh_variation=0;
  13. _matrix.zero();
  14. _matrix_scaled.zero();
  15. }
  16. /******************************************************************************/
  17. // MANAGE
  18. /******************************************************************************/
  19. void Static::setUnsavedParams()
  20. {
  21. mesh=(base ? base->mesh() : MeshPtr());
  22. if(base && base->phys())actor.create(*base->phys(), 0, scale)
  23. .matrix(_matrix)
  24. .obj (this)
  25. .group (AG_TERRAIN);
  26. }
  27. void Static::create(Object &obj)
  28. {
  29. base =obj.firstStored();
  30. scale =obj.scale3 ();
  31. _matrix=obj.matrixFinal().normalize(); _matrix_scaled=_matrix; _matrix_scaled.scaleOrnL(scale);
  32. mesh_variation=obj.meshVariationIndex();
  33. setUnsavedParams();
  34. }
  35. /******************************************************************************/
  36. // GET / SET
  37. /******************************************************************************/
  38. Vec Static::pos ( ) {return _matrix.pos ;}
  39. Matrix Static::matrix ( ) {return _matrix ;}
  40. Matrix Static::matrixScaled( ) {return _matrix_scaled;}
  41. void Static::pos (C Vec &pos ) {actor.pos (pos ); T._matrix_scaled.pos=T._matrix.pos=pos ;}
  42. void Static::matrix (C Matrix &matrix) {actor.matrix(matrix); T._matrix_scaled =T._matrix =matrix; T._matrix_scaled.scaleOrnL(scale);}
  43. /******************************************************************************/
  44. // CALLBACKS
  45. /******************************************************************************/
  46. void Static::memoryAddressChanged()
  47. {
  48. actor.obj(this);
  49. }
  50. /******************************************************************************/
  51. // UPDATE
  52. /******************************************************************************/
  53. Bool Static::update()
  54. {
  55. return true;
  56. }
  57. /******************************************************************************/
  58. // DRAW
  59. /******************************************************************************/
  60. UInt Static::drawPrepare()
  61. {
  62. if(mesh)if(Frustum(*mesh, _matrix_scaled))
  63. {
  64. SetVariation(mesh_variation); mesh->draw(_matrix_scaled);
  65. SetVariation();
  66. }
  67. return 0; // no additional render modes required
  68. }
  69. /******************************************************************************/
  70. void Static::drawShadow()
  71. {
  72. if(mesh)if(Frustum(*mesh, _matrix_scaled))
  73. {
  74. SetVariation(mesh_variation); mesh->drawShadow(_matrix_scaled);
  75. SetVariation();
  76. }
  77. }
  78. /******************************************************************************/
  79. // IO
  80. /******************************************************************************/
  81. Bool Static::save(File &f)
  82. {
  83. if(super::save(f))
  84. {
  85. f.cmpUIntV(0); // version
  86. f.putAsset(base.id())<<scale<<_matrix;
  87. f.putUInt (mesh ? mesh->variationID(mesh_variation) : 0);
  88. if(!actor.saveState(f))return false;
  89. return f.ok();
  90. }
  91. return false;
  92. }
  93. /******************************************************************************/
  94. Bool Static::load(File &f)
  95. {
  96. if(super::load(f))switch(f.decUIntV()) // version
  97. {
  98. case 0:
  99. {
  100. base=f.getAssetID();
  101. f>>scale>>_matrix; _matrix_scaled=_matrix; _matrix_scaled.scaleOrnL(scale);
  102. setUnsavedParams();
  103. UInt mesh_variation_id=f.getUInt(); mesh_variation=(mesh ? mesh->variationFind(mesh_variation_id) : 0);
  104. if(!actor.loadState(f))return false;
  105. if(f.ok())return true;
  106. }break;
  107. }
  108. return false;
  109. }
  110. /******************************************************************************/
  111. }}
  112. /******************************************************************************/