afxXM_HeightSampler.cpp 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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_HeightSamplerData : public afxXM_WeightedBaseData
  32. {
  33. typedef afxXM_WeightedBaseData Parent;
  34. public:
  35. /*C*/ afxXM_HeightSamplerData();
  36. /*C*/ afxXM_HeightSamplerData(const afxXM_HeightSamplerData&, bool = false);
  37. void packData(BitStream* stream);
  38. void unpackData(BitStream* stream);
  39. virtual bool allowSubstitutions() const { return true; }
  40. static void initPersistFields();
  41. afxXM_Base* create(afxEffectWrapper* fx, bool on_server);
  42. DECLARE_CONOBJECT(afxXM_HeightSamplerData);
  43. DECLARE_CATEGORY("AFX");
  44. };
  45. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//
  46. class afxConstraint;
  47. class afxXM_HeightSampler : public afxXM_WeightedBase
  48. {
  49. typedef afxXM_WeightedBase Parent;
  50. public:
  51. /*C*/ afxXM_HeightSampler(afxXM_HeightSamplerData*, afxEffectWrapper*);
  52. virtual void updateParams(F32 dt, F32 elapsed, afxXM_Params& params);
  53. };
  54. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  55. IMPLEMENT_CO_DATABLOCK_V1(afxXM_HeightSamplerData);
  56. ConsoleDocClass( afxXM_HeightSamplerData,
  57. "@brief An xmod datablock.\n\n"
  58. "@ingroup afxXMods\n"
  59. "@ingroup AFX\n"
  60. "@ingroup Datablocks\n"
  61. );
  62. afxXM_HeightSamplerData::afxXM_HeightSamplerData()
  63. {
  64. }
  65. afxXM_HeightSamplerData::afxXM_HeightSamplerData(const afxXM_HeightSamplerData& other, bool temp_clone) : afxXM_WeightedBaseData(other, temp_clone)
  66. {
  67. }
  68. void afxXM_HeightSamplerData::initPersistFields()
  69. {
  70. Parent::initPersistFields();
  71. }
  72. void afxXM_HeightSamplerData::packData(BitStream* stream)
  73. {
  74. Parent::packData(stream);
  75. }
  76. void afxXM_HeightSamplerData::unpackData(BitStream* stream)
  77. {
  78. Parent::unpackData(stream);
  79. }
  80. afxXM_Base* afxXM_HeightSamplerData::create(afxEffectWrapper* fx, bool on_server)
  81. {
  82. afxXM_HeightSamplerData* datablock = this;
  83. if (getSubstitutionCount() > 0)
  84. {
  85. datablock = new afxXM_HeightSamplerData(*this, true);
  86. this->performSubstitutions(datablock, fx->getChoreographer(), fx->getGroupIndex());
  87. }
  88. return new afxXM_HeightSampler(datablock, fx);
  89. }
  90. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//
  91. afxXM_HeightSampler::afxXM_HeightSampler(afxXM_HeightSamplerData* db, afxEffectWrapper* fxw)
  92. : afxXM_WeightedBase(db, fxw)
  93. {
  94. }
  95. void afxXM_HeightSampler::updateParams(F32 dt, F32 elapsed, afxXM_Params& params)
  96. {
  97. afxConstraint* pos_cons = fx_wrapper->getPosConstraint();
  98. if (!pos_cons)
  99. return;
  100. Point3F base_pos;
  101. pos_cons->getPosition(base_pos);
  102. F32 range = 0.5f;
  103. F32 height = (base_pos.z > params.pos.z) ? (base_pos.z - params.pos.z) : 0.0f;
  104. F32 factor = mClampF(1.0f - (height/range), 0.0f, 1.0f);
  105. //Con::printf("SET height=%g liveScaleFactor=%g", height, factor);
  106. fx_wrapper->setField("liveScaleFactor", avar("%g", factor));
  107. fx_wrapper->setField("liveFadeFactor", avar("%g", factor));
  108. }
  109. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//