afxXM_BoxHeightOffset.cpp 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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 "afx/afxEffectWrapper.h"
  27. #include "afx/xm/afxXfmMod.h"
  28. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  29. // BOX HEIGHT OFFSET
  30. class afxXM_BoxHeightOffsetData : public afxXM_BaseData
  31. {
  32. typedef afxXM_BaseData Parent;
  33. public:
  34. Point3F offset;
  35. public:
  36. /*C*/ afxXM_BoxHeightOffsetData();
  37. /*C*/ afxXM_BoxHeightOffsetData(const afxXM_BoxHeightOffsetData&, bool = false);
  38. void packData(BitStream* stream) override;
  39. void unpackData(BitStream* stream) override;
  40. static void initPersistFields();
  41. #if defined(AFX_VERSION)
  42. afxXM_Base* create(afxEffectWrapper* fx, bool on_server) override;
  43. #else
  44. afxXM_Base* create(afxEffectWrapper* fx);
  45. #endif
  46. DECLARE_CONOBJECT(afxXM_BoxHeightOffsetData);
  47. };
  48. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//
  49. class afxXM_BoxHeightOffset : public afxXM_Base
  50. {
  51. typedef afxXM_Base Parent;
  52. Point3F offset;
  53. public:
  54. /*C*/ afxXM_BoxHeightOffset(afxXM_BoxHeightOffsetData*, afxEffectWrapper*);
  55. void updateParams(F32 dt, F32 elapsed, afxXM_Params& params) override;
  56. };
  57. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  58. // BOX HEIGHT OFFSET
  59. IMPLEMENT_CO_DATABLOCK_V1(afxXM_BoxHeightOffsetData);
  60. ConsoleDocClass( afxXM_BoxHeightOffsetData,
  61. "@brief An xmod datablock.\n\n"
  62. "@ingroup afxXMods\n"
  63. "@ingroup AFX\n"
  64. "@ingroup Datablocks\n"
  65. );
  66. afxXM_BoxHeightOffsetData::afxXM_BoxHeightOffsetData()
  67. {
  68. offset.zero();
  69. }
  70. afxXM_BoxHeightOffsetData::afxXM_BoxHeightOffsetData(const afxXM_BoxHeightOffsetData& other, bool temp_clone)
  71. : afxXM_BaseData(other, temp_clone)
  72. {
  73. offset = other.offset;
  74. }
  75. void afxXM_BoxHeightOffsetData::initPersistFields()
  76. {
  77. docsURL;
  78. addField("offset", TypePoint3F, Offset(offset, afxXM_BoxHeightOffsetData));
  79. Parent::initPersistFields();
  80. }
  81. void afxXM_BoxHeightOffsetData::packData(BitStream* stream)
  82. {
  83. Parent::packData(stream);
  84. mathWrite(*stream, offset);
  85. }
  86. void afxXM_BoxHeightOffsetData::unpackData(BitStream* stream)
  87. {
  88. Parent::unpackData(stream);
  89. mathRead(*stream, &offset);
  90. }
  91. #if defined(AFX_VERSION)
  92. afxXM_Base* afxXM_BoxHeightOffsetData::create(afxEffectWrapper* fx, bool on_server)
  93. #else
  94. afxXM_Base* afxXM_BoxHeightOffsetData::create(afxEffectWrapper* fx)
  95. #endif
  96. {
  97. return new afxXM_BoxHeightOffset(this, fx);
  98. }
  99. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//
  100. afxXM_BoxHeightOffset::afxXM_BoxHeightOffset(afxXM_BoxHeightOffsetData* db, afxEffectWrapper* fxw)
  101. : afxXM_Base(db, fxw)
  102. {
  103. offset = db->offset;
  104. }
  105. void afxXM_BoxHeightOffset::updateParams(F32 dt, F32 elapsed, afxXM_Params& params)
  106. {
  107. afxConstraint* pos_cons = fx_wrapper->getPosConstraint();
  108. SceneObject* scn_obj = (pos_cons) ? pos_cons->getSceneObject() : 0;
  109. if (scn_obj)
  110. params.pos.z += scn_obj->getWorldBox().maxExtents.z - scn_obj->getWorldBox().minExtents.z;
  111. params.pos += offset;
  112. }
  113. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//