afxXM_Shockwave.cpp 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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 "math/mathIO.h"
  26. #include "math/mathUtils.h"
  27. #include "afx/afxEffectWrapper.h"
  28. #include "afx/afxChoreographer.h"
  29. #include "afx/xm/afxXfmMod.h"
  30. #include "afx/util/afxPath3D.h"
  31. #include "afx/util/afxPath.h"
  32. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  33. class afxXM_ShockwaveData : public afxXM_BaseData
  34. {
  35. typedef afxXM_BaseData Parent;
  36. public:
  37. F32 rate;
  38. bool aim_z_only;
  39. public:
  40. /*C*/ afxXM_ShockwaveData();
  41. /*C*/ afxXM_ShockwaveData(const afxXM_ShockwaveData&, bool = false);
  42. void packData(BitStream* stream);
  43. void unpackData(BitStream* stream);
  44. virtual bool allowSubstitutions() const { return true; }
  45. static void initPersistFields();
  46. afxXM_Base* create(afxEffectWrapper* fx, bool on_server);
  47. DECLARE_CONOBJECT(afxXM_ShockwaveData);
  48. DECLARE_CATEGORY("AFX");
  49. };
  50. class afxConstraint;
  51. class afxXM_Shockwave : public afxXM_Base
  52. {
  53. typedef afxXM_Base Parent;
  54. afxXM_ShockwaveData* db;
  55. bool first;
  56. Point3F fixed_pos;
  57. public:
  58. /*C*/ afxXM_Shockwave(afxXM_ShockwaveData*, afxEffectWrapper*);
  59. virtual void updateParams(F32 dt, F32 elapsed, afxXM_Params& params);
  60. };
  61. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  62. IMPLEMENT_CO_DATABLOCK_V1(afxXM_ShockwaveData);
  63. ConsoleDocClass( afxXM_ShockwaveData,
  64. "@brief An xmod datablock.\n\n"
  65. "@ingroup afxXMods\n"
  66. "@ingroup AFX\n"
  67. "@ingroup Datablocks\n"
  68. );
  69. afxXM_ShockwaveData::afxXM_ShockwaveData()
  70. {
  71. rate = 1.0f;
  72. aim_z_only = false;
  73. }
  74. afxXM_ShockwaveData::afxXM_ShockwaveData(const afxXM_ShockwaveData& other, bool temp_clone) : afxXM_BaseData(other, temp_clone)
  75. {
  76. rate = other.rate;
  77. aim_z_only = other.aim_z_only;
  78. }
  79. void afxXM_ShockwaveData::initPersistFields()
  80. {
  81. addField("rate", TypeF32, Offset(rate, afxXM_ShockwaveData),
  82. "...");
  83. addField("aimZOnly", TypeBool, Offset(aim_z_only, afxXM_ShockwaveData),
  84. "...");
  85. Parent::initPersistFields();
  86. }
  87. void afxXM_ShockwaveData::packData(BitStream* stream)
  88. {
  89. Parent::packData(stream);
  90. stream->write(rate);
  91. stream->write(aim_z_only);
  92. }
  93. void afxXM_ShockwaveData::unpackData(BitStream* stream)
  94. {
  95. Parent::unpackData(stream);
  96. stream->read(&rate);
  97. stream->read(&aim_z_only);
  98. }
  99. afxXM_Base* afxXM_ShockwaveData::create(afxEffectWrapper* fx, bool on_server)
  100. {
  101. afxXM_ShockwaveData* datablock = this;
  102. if (getSubstitutionCount() > 0)
  103. {
  104. datablock = new afxXM_ShockwaveData(*this, true);
  105. this->performSubstitutions(datablock, fx->getChoreographer(), fx->getGroupIndex());
  106. }
  107. return new afxXM_Shockwave(datablock, fx);
  108. }
  109. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//
  110. afxXM_Shockwave::afxXM_Shockwave(afxXM_ShockwaveData* db, afxEffectWrapper* fxw)
  111. : afxXM_Base(db, fxw)
  112. {
  113. this->db = db;
  114. first = true;
  115. fixed_pos.zero();
  116. }
  117. void afxXM_Shockwave::updateParams(F32 dt, F32 elapsed, afxXM_Params& params)
  118. {
  119. if (first)
  120. {
  121. fixed_pos = params.pos;
  122. first = false;
  123. }
  124. Point3F aim_at_pos = params.pos2;
  125. if (db->aim_z_only)
  126. aim_at_pos.z = fixed_pos.z;
  127. VectorF line_of_sight = aim_at_pos - fixed_pos;
  128. line_of_sight.normalize();
  129. params.pos = fixed_pos + line_of_sight*(elapsed*db->rate);
  130. }
  131. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//