physicalZone.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  23. // Arcane-FX for MIT Licensed Open Source version of Torque 3D from GarageGames
  24. // Copyright (C) 2015 Faust Logic, Inc.
  25. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  26. #ifndef _H_PHYSICALZONE
  27. #define _H_PHYSICALZONE
  28. #ifndef _SCENEOBJECT_H_
  29. #include "scene/sceneObject.h"
  30. #endif
  31. #ifndef _EARLYOUTPOLYLIST_H_
  32. #include "collision/earlyOutPolyList.h"
  33. #endif
  34. #ifndef _MPOLYHEDRON_H_
  35. #include "math/mPolyhedron.h"
  36. #endif
  37. class Convex;
  38. class PhysicalZone : public SceneObject
  39. {
  40. typedef SceneObject Parent;
  41. enum UpdateMasks {
  42. ActiveMask = Parent::NextFreeMask << 0,
  43. SettingsMask = Parent::NextFreeMask << 1,
  44. FadeMask = Parent::NextFreeMask << 2,
  45. PolyhedronMask = Parent::NextFreeMask << 3,
  46. MoveMask = Parent::NextFreeMask << 4,
  47. ExclusionMask = Parent::NextFreeMask << 5,
  48. NextFreeMask = Parent::NextFreeMask << 6
  49. };
  50. protected:
  51. static bool smRenderPZones;
  52. F32 mVelocityMod;
  53. F32 mGravityMod;
  54. Point3F mAppliedForce;
  55. // Basically ripped from trigger
  56. Polyhedron mPolyhedron;
  57. EarlyOutPolyList mClippedList;
  58. bool mActive;
  59. Convex* mConvexList;
  60. void buildConvex(const Box3F& box, Convex* convex) override;
  61. public:
  62. PhysicalZone();
  63. ~PhysicalZone();
  64. // SimObject
  65. DECLARE_CONOBJECT(PhysicalZone);
  66. DECLARE_CATEGORY("Volume");
  67. static void consoleInit();
  68. static void initPersistFields();
  69. bool onAdd() override;
  70. void onRemove() override;
  71. void inspectPostApply() override;
  72. // NetObject
  73. U32 packUpdate (NetConnection *conn, U32 mask, BitStream *stream) override;
  74. void unpackUpdate(NetConnection *conn, BitStream *stream) override;
  75. // SceneObject
  76. void setTransform(const MatrixF &mat) override;
  77. void prepRenderImage( SceneRenderState* state ) override;
  78. inline F32 getVelocityMod() const { return mVelocityMod; }
  79. inline F32 getGravityMod() const { return mGravityMod; }
  80. // the scene object is now passed in to getForce() where
  81. // it is needed to calculate the applied force when the
  82. // force is radial.
  83. const Point3F& getForce(const Point3F* center=0) const;
  84. void setPolyhedron(const Polyhedron&);
  85. bool testObject(SceneObject*);
  86. bool testBox( const Box3F &box ) const;
  87. void renderObject( ObjectRenderInst *ri, SceneRenderState *state, BaseMatInstance *overrideMat );
  88. void activate();
  89. void deactivate();
  90. inline bool isActive() const { return mActive; }
  91. protected:
  92. friend class afxPhysicalZoneData;
  93. friend class afxEA_PhysicalZone;
  94. Vector<SceneObject*> excluded_objects;
  95. S32 force_type;
  96. F32 force_mag;
  97. bool orient_force;
  98. F32 fade_amt;
  99. void setFadeAmount(F32 amt) { fade_amt = amt; if (fade_amt < 1.0f) setMaskBits(FadeMask); }
  100. public:
  101. enum ForceType { VECTOR, SPHERICAL, CYLINDRICAL };
  102. enum { FORCE_TYPE_BITS = 2 };
  103. void onStaticModified(const char* slotName, const char*newValue = NULL) override;
  104. bool isExcludedObject(SceneObject*) const;
  105. void registerExcludedObject(SceneObject*);
  106. void unregisterExcludedObject(SceneObject*);
  107. };
  108. typedef PhysicalZone::ForceType PhysicalZone_ForceType;
  109. DefineEnumType( PhysicalZone_ForceType );
  110. #endif // _H_PHYSICALZONE