pxFluid.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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 _PXFLUID_H_
  23. #define _PXFLUID_H_
  24. #ifndef _SCENEOBJECT_H_
  25. #include "scene/sceneObject.h"
  26. #endif
  27. #ifndef _PHYSX_H_
  28. #include "T3D/physics/physx/px.h"
  29. #endif
  30. class BaseMatInstance;
  31. class PxWorld;
  32. class NxScene;
  33. class PxFluid : public SceneObject
  34. {
  35. typedef SceneObject Parent;
  36. protected:
  37. enum NetMasks
  38. {
  39. UpdateMask = Parent::NextFreeMask,
  40. ResetMask = Parent::NextFreeMask << 1,
  41. NextFreeMask = Parent::NextFreeMask << 2
  42. };
  43. struct FluidParticle
  44. {
  45. NxVec3 position;
  46. NxVec3 velocity;
  47. NxReal density;
  48. NxReal lifetime;
  49. NxU32 id;
  50. NxVec3 collisionNormal;
  51. };
  52. #define MAX_PARTICLES 100
  53. public:
  54. PxFluid();
  55. virtual ~PxFluid();
  56. DECLARE_CONOBJECT( PxFluid );
  57. // SimObject
  58. virtual bool onAdd();
  59. virtual void onRemove();
  60. static void initPersistFields();
  61. virtual void inspectPostApply();
  62. // NetObject
  63. virtual U32 packUpdate( NetConnection *conn, U32 mask, BitStream *stream );
  64. virtual void unpackUpdate( NetConnection *conn, BitStream *stream );
  65. // SceneObject
  66. virtual void setTransform( const MatrixF &mat );
  67. virtual void setScale( const VectorF &scale );
  68. virtual void prepRenderImage( SceneRenderState *state );
  69. void resetParticles();
  70. void setRate( F32 rate );
  71. protected:
  72. void renderObject( ObjectRenderInst *ri, SceneRenderState *state, BaseMatInstance *overrideMat );
  73. void _createFluid();
  74. void _destroyFluid();
  75. protected:
  76. PxWorld *mWorld;
  77. NxScene *mScene;
  78. FluidParticle *mParticles;
  79. //NxParticleData *mParticleData;
  80. NxFluid *mFluid;
  81. U32 mParticleCount;
  82. NxFluidEmitter *mEmitter;
  83. };
  84. #endif // _PXFLUID_H_