afxXM_Scale.cpp 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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_ScaleData : public afxXM_WeightedBaseData
  34. {
  35. typedef afxXM_WeightedBaseData Parent;
  36. public:
  37. Point3F scale;
  38. public:
  39. /*C*/ afxXM_ScaleData();
  40. /*C*/ afxXM_ScaleData(const afxXM_ScaleData&, bool = false);
  41. void packData(BitStream* stream);
  42. void unpackData(BitStream* stream);
  43. virtual bool allowSubstitutions() const { return true; }
  44. static void initPersistFields();
  45. afxXM_Base* create(afxEffectWrapper* fx, bool on_server);
  46. DECLARE_CONOBJECT(afxXM_ScaleData);
  47. DECLARE_CATEGORY("AFX");
  48. };
  49. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//
  50. class afxXM_Scale_weighted : public afxXM_WeightedBase
  51. {
  52. typedef afxXM_WeightedBase Parent;
  53. Point3F xm_scale;
  54. public:
  55. /*C*/ afxXM_Scale_weighted(afxXM_ScaleData*, afxEffectWrapper*);
  56. virtual void updateParams(F32 dt, F32 elapsed, afxXM_Params& params);
  57. };
  58. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  59. IMPLEMENT_CO_DATABLOCK_V1(afxXM_ScaleData);
  60. ConsoleDocClass( afxXM_ScaleData,
  61. "@brief An xmod datablock.\n\n"
  62. "@ingroup afxXMods\n"
  63. "@ingroup AFX\n"
  64. "@ingroup Datablocks\n"
  65. );
  66. afxXM_ScaleData::afxXM_ScaleData()
  67. {
  68. scale.set(0,0,0);
  69. }
  70. afxXM_ScaleData::afxXM_ScaleData(const afxXM_ScaleData& other, bool temp_clone) : afxXM_WeightedBaseData(other, temp_clone)
  71. {
  72. scale = other.scale;
  73. }
  74. void afxXM_ScaleData::initPersistFields()
  75. {
  76. addField("scale", TypePoint3F, Offset(scale, afxXM_ScaleData),
  77. "...");
  78. Parent::initPersistFields();
  79. }
  80. void afxXM_ScaleData::packData(BitStream* stream)
  81. {
  82. Parent::packData(stream);
  83. mathWrite(*stream, scale);
  84. }
  85. void afxXM_ScaleData::unpackData(BitStream* stream)
  86. {
  87. Parent::unpackData(stream);
  88. mathRead(*stream, &scale);
  89. }
  90. afxXM_Base* afxXM_ScaleData::create(afxEffectWrapper* fx, bool on_server)
  91. {
  92. afxXM_ScaleData* datablock = this;
  93. if (getSubstitutionCount() > 0)
  94. {
  95. datablock = new afxXM_ScaleData(*this, true);
  96. this->performSubstitutions(datablock, fx->getChoreographer(), fx->getGroupIndex());
  97. }
  98. if (datablock->hasFixedWeight())
  99. return new afxXM_Scale_weighted(datablock, fx);
  100. else
  101. return new afxXM_Scale_weighted(datablock, fx);
  102. }
  103. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//
  104. afxXM_Scale_weighted::afxXM_Scale_weighted(afxXM_ScaleData* db, afxEffectWrapper* fxw)
  105. : afxXM_WeightedBase(db, fxw)
  106. {
  107. xm_scale = db->scale;
  108. }
  109. void afxXM_Scale_weighted::updateParams(F32 dt, F32 elapsed, afxXM_Params& params)
  110. {
  111. F32 wt_factor = calc_weight_factor(elapsed);
  112. params.scale += xm_scale*wt_factor;
  113. if (params.scale.x < 0.00001f)
  114. params.scale.x = 0.00001f;
  115. if (params.scale.y < 0.00001f)
  116. params.scale.y = 0.00001f;
  117. if (params.scale.z < 0.00001f)
  118. params.scale.z = 0.00001f;
  119. }
  120. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//