afxXM_RandomRot.cpp 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  31. class afxXM_RandomRotData : public afxXM_BaseData
  32. {
  33. typedef afxXM_BaseData Parent;
  34. public:
  35. Point3F axis;
  36. F32 theta_min;
  37. F32 theta_max;
  38. F32 phi_min;
  39. F32 phi_max;
  40. public:
  41. /*C*/ afxXM_RandomRotData();
  42. /*C*/ afxXM_RandomRotData(const afxXM_RandomRotData&, bool = false);
  43. void packData(BitStream* stream);
  44. void unpackData(BitStream* stream);
  45. bool onAdd();
  46. virtual bool allowSubstitutions() const { return true; }
  47. static void initPersistFields();
  48. afxXM_Base* create(afxEffectWrapper* fx, bool on_server);
  49. DECLARE_CONOBJECT(afxXM_RandomRotData);
  50. DECLARE_CATEGORY("AFX");
  51. };
  52. class afxXM_RandomRot : public afxXM_Base
  53. {
  54. typedef afxXM_Base Parent;
  55. MatrixF rand_ori;
  56. public:
  57. /*C*/ afxXM_RandomRot(afxXM_RandomRotData*, afxEffectWrapper*);
  58. virtual void updateParams(F32 dt, F32 elapsed, afxXM_Params& params);
  59. };
  60. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  61. IMPLEMENT_CO_DATABLOCK_V1(afxXM_RandomRotData);
  62. ConsoleDocClass( afxXM_RandomRotData,
  63. "@brief An xmod datablock.\n\n"
  64. "@ingroup afxXMods\n"
  65. "@ingroup AFX\n"
  66. "@ingroup Datablocks\n"
  67. );
  68. afxXM_RandomRotData::afxXM_RandomRotData()
  69. {
  70. axis.set(0,0,1);
  71. theta_min = 0.0f;
  72. theta_max = 360.0f;
  73. phi_min = 0.0f;
  74. phi_max = 360.0f;
  75. }
  76. afxXM_RandomRotData::afxXM_RandomRotData(const afxXM_RandomRotData& other, bool temp_clone) : afxXM_BaseData(other, temp_clone)
  77. {
  78. axis = other.axis;
  79. theta_min = other.theta_min;
  80. theta_max = other.theta_max;
  81. phi_min = other.phi_min;
  82. phi_max = other.phi_max;
  83. }
  84. void afxXM_RandomRotData::initPersistFields()
  85. {
  86. addField("axis", TypePoint3F, Offset(axis, afxXM_RandomRotData),
  87. "...");
  88. addField("thetaMin", TypeF32, Offset(theta_min, afxXM_RandomRotData),
  89. "...");
  90. addField("thetaMax", TypeF32, Offset(theta_max, afxXM_RandomRotData),
  91. "...");
  92. addField("phiMin", TypeF32, Offset(phi_min, afxXM_RandomRotData),
  93. "...");
  94. addField("phiMax", TypeF32, Offset(phi_max, afxXM_RandomRotData),
  95. "...");
  96. Parent::initPersistFields();
  97. }
  98. void afxXM_RandomRotData::packData(BitStream* stream)
  99. {
  100. Parent::packData(stream);
  101. mathWrite(*stream, axis);
  102. stream->write(theta_min);
  103. stream->write(theta_max);
  104. stream->write(phi_min);
  105. stream->write(phi_max);
  106. }
  107. void afxXM_RandomRotData::unpackData(BitStream* stream)
  108. {
  109. Parent::unpackData(stream);
  110. mathRead(*stream, &axis);
  111. stream->read(&theta_min);
  112. stream->read(&theta_max);
  113. stream->read(&phi_min);
  114. stream->read(&phi_max);
  115. }
  116. bool afxXM_RandomRotData::onAdd()
  117. {
  118. if (Parent::onAdd() == false)
  119. return false;
  120. axis.normalizeSafe();
  121. return true;
  122. }
  123. afxXM_Base* afxXM_RandomRotData::create(afxEffectWrapper* fx, bool on_server)
  124. {
  125. afxXM_RandomRotData* datablock = this;
  126. if (getSubstitutionCount() > 0)
  127. {
  128. datablock = new afxXM_RandomRotData(*this, true);
  129. this->performSubstitutions(datablock, fx->getChoreographer(), fx->getGroupIndex());
  130. }
  131. return new afxXM_RandomRot(datablock, fx);
  132. }
  133. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//
  134. afxXM_RandomRot::afxXM_RandomRot(afxXM_RandomRotData* db, afxEffectWrapper* fxw)
  135. : afxXM_Base(db, fxw)
  136. {
  137. Point3F rand_dir = MathUtils::randomDir(db->axis, db->theta_min, db->theta_max, db->phi_min, db->phi_max);
  138. rand_ori = MathUtils::createOrientFromDir(rand_dir);
  139. }
  140. void afxXM_RandomRot::updateParams(F32 dt, F32 elapsed, afxXM_Params& params)
  141. {
  142. params.ori = rand_ori;
  143. }
  144. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//