physicalZone.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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);
  61. public:
  62. PhysicalZone();
  63. ~PhysicalZone();
  64. // SimObject
  65. DECLARE_CONOBJECT(PhysicalZone);
  66. static void consoleInit();
  67. static void initPersistFields();
  68. bool onAdd();
  69. void onRemove();
  70. void inspectPostApply();
  71. // NetObject
  72. U32 packUpdate (NetConnection *conn, U32 mask, BitStream *stream);
  73. void unpackUpdate(NetConnection *conn, BitStream *stream);
  74. // SceneObject
  75. void setTransform(const MatrixF &mat);
  76. void prepRenderImage( SceneRenderState* state );
  77. inline F32 getVelocityMod() const { return mVelocityMod; }
  78. inline F32 getGravityMod() const { return mGravityMod; }
  79. // the scene object is now passed in to getForce() where
  80. // it is needed to calculate the applied force when the
  81. // force is radial.
  82. const Point3F& getForce(const Point3F* center=0) const;
  83. void setPolyhedron(const Polyhedron&);
  84. bool testObject(SceneObject*);
  85. bool testBox( const Box3F &box ) const;
  86. void renderObject( ObjectRenderInst *ri, SceneRenderState *state, BaseMatInstance *overrideMat );
  87. void activate();
  88. void deactivate();
  89. inline bool isActive() const { return mActive; }
  90. protected:
  91. friend class afxPhysicalZoneData;
  92. friend class afxEA_PhysicalZone;
  93. Vector<SceneObject*> excluded_objects;
  94. S32 force_type;
  95. F32 force_mag;
  96. bool orient_force;
  97. F32 fade_amt;
  98. void setFadeAmount(F32 amt) { fade_amt = amt; if (fade_amt < 1.0f) setMaskBits(FadeMask); }
  99. public:
  100. enum ForceType { VECTOR, SPHERICAL, CYLINDRICAL };
  101. enum { FORCE_TYPE_BITS = 2 };
  102. virtual void onStaticModified(const char* slotName, const char*newValue = NULL);
  103. bool isExcludedObject(SceneObject*) const;
  104. void registerExcludedObject(SceneObject*);
  105. void unregisterExcludedObject(SceneObject*);
  106. };
  107. typedef PhysicalZone::ForceType PhysicalZone_ForceType;
  108. DefineEnumType( PhysicalZone_ForceType );
  109. #endif // _H_PHYSICALZONE