AGX Dynamics 2.38.0.2
Loading...
Searching...
No Matches
ParticleState.h
Go to the documentation of this file.
1/*
2Copyright 2007-2024. Algoryx Simulation AB.
3
4All AGX source code, intellectual property, documentation, sample code,
5tutorials, scene files and technical white papers, are copyrighted, proprietary
6and confidential material of Algoryx Simulation AB. You may not download, read,
7store, distribute, publish, copy or otherwise disseminate, use or expose this
8material unless having a written signed agreement with Algoryx Simulation AB, or having been
9advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10valid commercial license from Algoryx Simulation AB.
11
12Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13from using this software, unless otherwise stated in written agreements with
14Algoryx Simulation AB.
15*/
16
17#ifndef AGX_PARTICLESTATE_H
18#define AGX_PARTICLESTATE_H
19
20#include <agx/Math.h>
21#include <agx/BitSet_small.h>
22#include <agxData/Type.h>
23
25
26namespace agx
27{
28 typedef agx::UInt32 ParticleStateDataType;
29
30 class ParticleState : public BitSet_small<ParticleStateDataType>
31 {
32 public:
33 ParticleState();
34 agx::UInt32 motionControl() const;
35 bool enabled() const;
36 bool removed() const;
37 bool enableMerge() const;
38 bool enableRotation() const;
39 bool particleClipped() const;
40 bool particleFiltered() const;
41 bool isTerrainSoilParticle() const;
42 bool enableRendering() const;
43 bool shouldRenderParticle() const;
44
45 void setMotionControl(agx::UInt32 motionControl);
46 void setEnabled(bool flag);
47 void setRemoved(bool flag);
48 void setEnableMerge(bool flag);
49 void setEnableRotation(bool flag);
50 void setParticleClipped(bool flag);
51 void setParticleFiltered(bool flag);
52 void setIsTerrainSoilParticle(bool flag);
53 void setEnableRendering(bool flag);
54
55 private:
56 friend class RigidBody;
57 friend class DynamicsSystem;
58 friend class MergedBody;
59 friend class MassPropertiesUpdate;
60
61 static const UInt16 ENABLE_RENDERING = 12;
62 static const UInt16 TERRAIN_SOIL_PARTICLE = 11;
63 static const UInt16 RENDERING_PARTICLE_FILTERED = 10;
64 static const UInt16 RENDERING_PARTICLE_CLIPPED = 9;
65 static const UInt16 ENABLE_NO_ROTATIONS = 8;
66 static const UInt16 ENABLE_MERGE_BIT = 7;
67 static const UInt16 REMOVED_BIT = 6;
68 static const UInt16 ENABLE_BIT = 5;
69 };
70
71 /* Implementation */
72 AGX_FORCE_INLINE ParticleState::ParticleState() : BitSet_small<ParticleStateDataType>()
73 {
74 this->set(ENABLE_BIT, true);
75 this->set(REMOVED_BIT, false);
76 this->set(ENABLE_MERGE_BIT, true);
77 this->set(RENDERING_PARTICLE_CLIPPED, false);
78 this->set(RENDERING_PARTICLE_FILTERED, false );
79 this->set(TERRAIN_SOIL_PARTICLE, false);
80 this->set(ENABLE_RENDERING, true);
81 this->setMotionControl(3); // This should be the DYNAMIC enum number in GranularBodySystem
82 }
83
84 AGX_FORCE_INLINE agx::UInt32 ParticleState::motionControl() const
85 {
86 return (agx::UInt32)(m_state & 0x3);
87 }
88
89 AGX_FORCE_INLINE bool ParticleState::enabled() const
90 {
91 return this->test(ENABLE_BIT);
92 }
93
94 AGX_FORCE_INLINE bool ParticleState::particleClipped() const
95 {
96 return this->test(RENDERING_PARTICLE_CLIPPED);
97 }
98
99 AGX_FORCE_INLINE bool ParticleState::removed() const
100 {
101 return this->test(REMOVED_BIT);
102 }
103
104 AGX_FORCE_INLINE bool ParticleState::enableMerge() const
105 {
106 return this->test(ENABLE_MERGE_BIT);
107 }
108
109 AGX_FORCE_INLINE bool ParticleState::enableRotation() const
110 {
111 return !this->test(ENABLE_NO_ROTATIONS);
112 }
113
114 AGX_FORCE_INLINE bool agx::ParticleState::particleFiltered() const
115 {
116 return this->test(RENDERING_PARTICLE_FILTERED);
117 }
118
119 AGX_FORCE_INLINE bool agx::ParticleState::isTerrainSoilParticle() const
120 {
121 return this->test( TERRAIN_SOIL_PARTICLE );
122 }
123
124 AGX_FORCE_INLINE bool ParticleState::enableRendering() const
125 {
126 return this->test( ENABLE_RENDERING );
127 }
128
129 AGX_FORCE_INLINE void ParticleState::setMotionControl(agx::UInt32 motionControl)
130 {
131 const ParticleStateDataType mask = (ParticleStateDataType) 0x3;
132 m_state = (m_state & ~mask) | ((ParticleStateDataType)motionControl);
133 }
134
135 AGX_FORCE_INLINE void ParticleState::setEnabled(bool flag)
136 {
137 this->set(ENABLE_BIT, flag);
138 }
139
140 AGX_FORCE_INLINE void ParticleState::setParticleClipped(bool flag)
141 {
142 this->set(RENDERING_PARTICLE_CLIPPED, flag);
143 }
144
145 AGX_FORCE_INLINE void agx::ParticleState::setParticleFiltered(bool flag)
146 {
147 this->set(RENDERING_PARTICLE_FILTERED, flag);
148 }
149
150 AGX_FORCE_INLINE void ParticleState::setEnableRotation(bool flag)
151 {
152 this->set(ENABLE_NO_ROTATIONS, !flag);
153 }
154
155 AGX_FORCE_INLINE void ParticleState::setRemoved(bool flag)
156 {
157 this->set(REMOVED_BIT, flag);
158 }
159
160 AGX_FORCE_INLINE void ParticleState::setEnableMerge(bool flag)
161 {
162 this->set(ENABLE_MERGE_BIT, flag);
163 }
164
165 AGX_FORCE_INLINE void agx::ParticleState::setIsTerrainSoilParticle( bool flag )
166 {
167 this->set( TERRAIN_SOIL_PARTICLE, flag );
168 }
169
170 AGX_FORCE_INLINE void ParticleState::setEnableRendering(bool flag)
171 {
172 this->set(ENABLE_RENDERING, flag);
173 }
174
175 AGX_FORCE_INLINE bool ParticleState::shouldRenderParticle() const
176 {
177 return enableRendering() && !( particleClipped() || particleFiltered() );
178 }
179
180#ifndef SWIG
181 std::ostream& operator << (std::ostream& output, const ParticleState& state);
182#endif // !SWIG
183}
184
185AGX_TYPE_BINDING(agx::ParticleState, "ParticleState")
186
188
189#endif /* AGX_RIGIDBODYSTATE_H */
#define AGX_TYPE_BINDING(_Type, _Name)
Definition Type.h:179
std::ostream & operator<<(std::ostream &o, const agx::Vec6 &v)
Definition Vec6.h:230
#define DOXYGEN_END_INTERNAL_BLOCK()
Definition macros.h:97
#define DOXYGEN_START_INTERNAL_BLOCK()
Definition macros.h:96
#define AGX_FORCE_INLINE
Definition macros.h:58
AGXPHYSICS_EXPORT void setMotionControl(agx::RigidBodyPtrVector &bodies, agx::RigidBody::MotionControl motionControl)
Utility function to set motion control for a vector of rigid bodies.
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
uint16_t UInt16
Definition Integer.h:31
uint32_t UInt32
Definition Integer.h:32