afxXM_BoxConform.cpp 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  2. // Arcane-FX for MIT Licensed Open Source version of Torque 3D from GarageGames
  3. // Copyright (C) 2015 Faust Logic, Inc.
  4. //
  5. // Permission is hereby granted, free of charge, to any person obtaining a copy
  6. // of this software and associated documentation files (the "Software"), to
  7. // deal in the Software without restriction, including without limitation the
  8. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  9. // sell copies of the Software, and to permit persons to whom the Software is
  10. // furnished to do so, subject to the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be included in
  13. // all copies or substantial portions of the Software.
  14. //
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  20. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  21. // IN THE SOFTWARE.
  22. //
  23. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  24. #include "afx/arcaneFX.h"
  25. #include "afx/afxEffectWrapper.h"
  26. #include "afx/xm/afxXfmMod.h"
  27. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  28. enum afxXM_BoxConformType
  29. {
  30. X_POS, X_NEG, Y_POS, Y_NEG, Z_POS, Z_NEG
  31. };
  32. DefineEnumType( afxXM_BoxConformType );
  33. class afxXM_BoxConformData : public afxXM_BaseData
  34. {
  35. typedef afxXM_BaseData Parent;
  36. public:
  37. S32 aabb_alignment;
  38. public:
  39. /*C*/ afxXM_BoxConformData();
  40. /*C*/ afxXM_BoxConformData(const afxXM_BoxConformData&, bool = false);
  41. void packData(BitStream* stream);
  42. void unpackData(BitStream* stream);
  43. static void initPersistFields();
  44. afxXM_Base* create(afxEffectWrapper* fx, bool on_server);
  45. DECLARE_CONOBJECT(afxXM_BoxConformData);
  46. DECLARE_CATEGORY("AFX");
  47. };
  48. class afxXM_BoxConform : public afxXM_Base
  49. {
  50. typedef afxXM_Base Parent;
  51. afxXM_BoxConformData* db;
  52. public:
  53. /*C*/ afxXM_BoxConform(afxXM_BoxConformData*, afxEffectWrapper*, bool on_server);
  54. virtual void updateParams(F32 dt, F32 elapsed, afxXM_Params& params);
  55. };
  56. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  57. IMPLEMENT_CO_DATABLOCK_V1(afxXM_BoxConformData);
  58. ConsoleDocClass( afxXM_BoxConformData,
  59. "@brief An xmod datablock.\n\n"
  60. "@ingroup afxXMods\n"
  61. "@ingroup AFX\n"
  62. "@ingroup Datablocks\n"
  63. );
  64. afxXM_BoxConformData::afxXM_BoxConformData()
  65. {
  66. aabb_alignment = Z_NEG;
  67. }
  68. afxXM_BoxConformData::afxXM_BoxConformData(const afxXM_BoxConformData& other, bool temp_clone)
  69. : afxXM_BaseData(other, temp_clone)
  70. {
  71. aabb_alignment = other.aabb_alignment;
  72. }
  73. ImplementEnumType( afxXM_BoxConformType, "Possible box conform alignment types.\n" "@ingroup afxXM_BoxConform\n\n" )
  74. { X_POS, "+x", "..." },
  75. { X_NEG, "-x", "..." },
  76. { Y_POS, "+y", "..." },
  77. { Y_NEG, "-y", "..." },
  78. { Z_POS, "+z", "..." },
  79. { Z_NEG, "-z", "..." },
  80. { X_POS, "x", "..." },
  81. { Y_POS, "y", "..." },
  82. { Z_POS, "z", "..." },
  83. EndImplementEnumType;
  84. void afxXM_BoxConformData::initPersistFields()
  85. {
  86. addField("boxAlignment", TYPEID< afxXM_BoxConformType >(), Offset(aabb_alignment, afxXM_BoxConformData),
  87. "...");
  88. Parent::initPersistFields();
  89. }
  90. void afxXM_BoxConformData::packData(BitStream* stream)
  91. {
  92. Parent::packData(stream);
  93. stream->write(aabb_alignment);
  94. }
  95. void afxXM_BoxConformData::unpackData(BitStream* stream)
  96. {
  97. Parent::unpackData(stream);
  98. stream->read(&aabb_alignment);
  99. }
  100. afxXM_Base* afxXM_BoxConformData::create(afxEffectWrapper* fx, bool on_server)
  101. {
  102. return new afxXM_BoxConform(this, fx, on_server);
  103. }
  104. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//
  105. afxXM_BoxConform::afxXM_BoxConform(afxXM_BoxConformData* db, afxEffectWrapper* fxw, bool on_server)
  106. : afxXM_Base(db, fxw)
  107. {
  108. this->db = db;
  109. }
  110. void afxXM_BoxConform::updateParams(F32 dt, F32 elapsed, afxXM_Params& params)
  111. {
  112. afxConstraint* pos_cons = fx_wrapper->getPosConstraint();
  113. if (!pos_cons)
  114. return;
  115. SceneObject* obj = pos_cons->getSceneObject();
  116. if (!obj)
  117. return;
  118. const Box3F& box = obj->getWorldBox();
  119. switch (db->aabb_alignment)
  120. {
  121. case X_POS:
  122. params.pos.x = box.maxExtents.x;
  123. break;
  124. case X_NEG:
  125. params.pos.x = box.minExtents.x;
  126. break;
  127. case Y_POS:
  128. params.pos.y = box.maxExtents.y;
  129. break;
  130. case Y_NEG:
  131. params.pos.y = box.minExtents.y;
  132. break;
  133. case Z_POS:
  134. params.pos.z = box.maxExtents.z;
  135. break;
  136. case Z_NEG:
  137. params.pos.z = box.minExtents.z;
  138. break;
  139. }
  140. }
  141. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//