physicalZone.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. #ifndef _H_PHYSICALZONE
  23. #define _H_PHYSICALZONE
  24. #ifndef _SCENEOBJECT_H_
  25. #include "scene/sceneObject.h"
  26. #endif
  27. #ifndef _EARLYOUTPOLYLIST_H_
  28. #include "collision/earlyOutPolyList.h"
  29. #endif
  30. #ifndef _MPOLYHEDRON_H_
  31. #include "math/mPolyhedron.h"
  32. #endif
  33. class Convex;
  34. class PhysicalZone : public SceneObject
  35. {
  36. typedef SceneObject Parent;
  37. enum UpdateMasks {
  38. ActiveMask = Parent::NextFreeMask << 0,
  39. NextFreeMask = Parent::NextFreeMask << 1
  40. };
  41. protected:
  42. static bool smRenderPZones;
  43. F32 mVelocityMod;
  44. F32 mGravityMod;
  45. Point3F mAppliedForce;
  46. // Basically ripped from trigger
  47. Polyhedron mPolyhedron;
  48. EarlyOutPolyList mClippedList;
  49. bool mActive;
  50. Convex* mConvexList;
  51. void buildConvex(const Box3F& box, Convex* convex);
  52. public:
  53. PhysicalZone();
  54. ~PhysicalZone();
  55. // SimObject
  56. DECLARE_CONOBJECT(PhysicalZone);
  57. static void consoleInit();
  58. static void initPersistFields();
  59. bool onAdd();
  60. void onRemove();
  61. void inspectPostApply();
  62. // NetObject
  63. U32 packUpdate (NetConnection *conn, U32 mask, BitStream *stream);
  64. void unpackUpdate(NetConnection *conn, BitStream *stream);
  65. // SceneObject
  66. void setTransform(const MatrixF &mat);
  67. void prepRenderImage( SceneRenderState* state );
  68. inline F32 getVelocityMod() const { return mVelocityMod; }
  69. inline F32 getGravityMod() const { return mGravityMod; }
  70. inline const Point3F& getForce() const { return mAppliedForce; }
  71. void setPolyhedron(const Polyhedron&);
  72. bool testObject(SceneObject*);
  73. bool testBox( const Box3F &box ) const;
  74. void renderObject( ObjectRenderInst *ri, SceneRenderState *state, BaseMatInstance *overrideMat );
  75. void activate();
  76. void deactivate();
  77. inline bool isActive() const { return mActive; }
  78. };
  79. #endif // _H_PHYSICALZONE