afxXM_Shockwave.cpp 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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. docsURL;
  82. addField("rate", TypeF32, Offset(rate, afxXM_ShockwaveData),
  83. "...");
  84. addField("aimZOnly", TypeBool, Offset(aim_z_only, afxXM_ShockwaveData),
  85. "...");
  86. Parent::initPersistFields();
  87. }
  88. void afxXM_ShockwaveData::packData(BitStream* stream)
  89. {
  90. Parent::packData(stream);
  91. stream->write(rate);
  92. stream->write(aim_z_only);
  93. }
  94. void afxXM_ShockwaveData::unpackData(BitStream* stream)
  95. {
  96. Parent::unpackData(stream);
  97. stream->read(&rate);
  98. stream->read(&aim_z_only);
  99. }
  100. afxXM_Base* afxXM_ShockwaveData::create(afxEffectWrapper* fx, bool on_server)
  101. {
  102. afxXM_ShockwaveData* datablock = this;
  103. if (getSubstitutionCount() > 0)
  104. {
  105. datablock = new afxXM_ShockwaveData(*this, true);
  106. this->performSubstitutions(datablock, fx->getChoreographer(), fx->getGroupIndex());
  107. }
  108. return new afxXM_Shockwave(datablock, fx);
  109. }
  110. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//
  111. afxXM_Shockwave::afxXM_Shockwave(afxXM_ShockwaveData* db, afxEffectWrapper* fxw)
  112. : afxXM_Base(db, fxw)
  113. {
  114. this->db = db;
  115. first = true;
  116. fixed_pos.zero();
  117. }
  118. void afxXM_Shockwave::updateParams(F32 dt, F32 elapsed, afxXM_Params& params)
  119. {
  120. if (first)
  121. {
  122. fixed_pos = params.pos;
  123. first = false;
  124. }
  125. Point3F aim_at_pos = params.pos2;
  126. if (db->aim_z_only)
  127. aim_at_pos.z = fixed_pos.z;
  128. VectorF line_of_sight = aim_at_pos - fixed_pos;
  129. line_of_sight.normalize();
  130. params.pos = fixed_pos + line_of_sight*(elapsed*db->rate);
  131. }
  132. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//