Free Electron
Blade.h
Go to the documentation of this file.
1 /* Copyright (C) 2003-2021 Free Electron Organization
2  Any use of this software requires a license. If a valid license
3  was not distributed with this file, visit freeelectron.org. */
4 
5 /** @file */
6 
7 #ifndef __grass_Blade__
8 #define __grass_Blade__
9 
10 namespace fe
11 {
12 namespace ext
13 {
14 
15 /**************************************************************************//**
16  @brief minimal semi-implicit curve sim
17 
18  @ingroup grass
19 *//***************************************************************************/
20 class FE_DL_EXPORT Blade
21 {
22  public:
23  typedef enum
24  {
25  e_boundingSphere=0x00,
26  e_nearestPoint=0x01,
27  e_rayCastOneStep=0x02,
28  e_rayCastHalvsies=0x03
29  } CollisionMethod;
30 
31  Blade(void);
32 virtual ~Blade(void) {}
33 
34  void setTime(Real a_t) { m_t=a_t; }
35  Real time(void) const { return m_t; }
36 
37  void setTimeStep(Real a_h) { m_h=a_h; }
38  Real timeStep(void) const { return m_h; }
39 
40  void setTension(Real a_tension) { m_tension=a_tension; }
41  Real tension(void) const { return m_tension; }
42 
43  void setTensionRandom(Real a_tensionRandom)
44  { m_tensionRandom=a_tensionRandom; }
45  Real tensionRandom(void) const
46  { return m_tensionRandom; }
47 
48  void setRestoration(Real a_restoration)
49  { m_restoration=a_restoration; }
50  Real restoration(void) const
51  { return m_restoration; }
52 
53  void setRestorationRandom(Real a_restorationRandom)
54  { m_restorationRandom=a_restorationRandom; }
55  Real restorationRandom(void) const
56  { return m_restorationRandom; }
57 
58  void setDrag(Real a_drag) { m_drag=a_drag; }
59  Real drag(void) const { return m_drag; }
60 
61  void setDragRandom(Real a_dragRandom)
62  { m_dragRandom=a_dragRandom; }
63  Real dragRandom(void) const
64  { return m_dragRandom; }
65 
66  void setBend(Real a_bend) { m_bend=a_bend; }
67  Real bend(void) const { return m_bend; }
68 
69  void setGrabbing(BWORD a_grabbing)
70  { m_grabbing=a_grabbing; }
71  BWORD grabbing(void) const
72  { return m_grabbing; }
73 
74  void setGrabBias(Real a_grabBias){ m_grabBias=a_grabBias; }
75  Real grabBias(void) const { return m_grabBias; }
76 
77  void setGrabBiasRandom(Real a_grabBiasRandom)
78  { m_grabBiasRandom=a_grabBiasRandom; }
79  Real grabBiasRandom(void) const
80  { return m_grabBiasRandom; }
81 
82  void setCollisionGap(Real a_collisionGap)
83  { m_collisionGap=a_collisionGap; }
84  Real collisionGap(void) const
85  { return m_collisionGap; }
86 
87  void setMass(Real a_mass) { m_mass=a_mass; }
88  Real mass(void) const { return m_mass; }
89 
90  void setWind(Real a_wind)
91  { m_wind=a_wind; }
92  Real wind(void) const
93  { return m_wind; }
94 
95  void setTurbulence(Real a_turbulence)
96  { m_turbulence=a_turbulence; }
97  Real turbulence(void) const
98  { return m_turbulence; }
99 
100  void setBuckling(BWORD a_buckling)
101  { m_buckling=a_buckling; }
102  BWORD buckling(void) const
103  { return m_buckling; }
104 
105  void setBreakAngle(Real a_breakAngle)
106  { m_breakAngle=a_breakAngle; }
107  Real breakAngle(void) const
108  { return m_breakAngle; }
109 
110  void setBreakAngleRandom(Real a_breakAngleRandom)
111  { m_breakAngleRandom=a_breakAngleRandom; }
112  Real breakAngleRandom(void) const
113  { return m_breakAngleRandom; }
114 
115  void setElasticAngle(Real a_elasticAngle)
116  { m_elasticAngle=a_elasticAngle; }
117  Real elasticAngle(void) const
118  { return m_elasticAngle; }
119 
120  void setElasticAngleRandom(Real a_elasticAngleRandom)
121  { m_elasticAngleRandom=a_elasticAngleRandom; }
122  Real elasticAngleRandom(void) const
123  { return m_elasticAngleRandom; }
124 
125  void setPopAngle(Real a_popAngle)
126  { m_popAngle=a_popAngle; }
127  Real popAngle(void) const
128  { return m_popAngle; }
129 
130  void setPopAngleRandom(Real a_popAngleRandom)
131  { m_popAngleRandom=a_popAngleRandom; }
132  Real popAngleRandom(void) const
133  { return m_popAngleRandom; }
134 
135  void setRecoveryAngle(Real a_recoveryAngle)
136  { m_recoveryAngle=a_recoveryAngle; }
137  Real recoveryAngle(void) const
138  { return m_recoveryAngle; }
139 
140  void setRecoveryAngleRandom(Real a_recoveryAngleRandom)
141  { m_recoveryAngleRandom=a_recoveryAngleRandom; }
142  Real recoveryAngleRandom(void) const
143  { return m_recoveryAngleRandom; }
144 
145  void setHalfingSteps(I32 a_halfingSteps)
146  { m_halfingSteps=a_halfingSteps; }
147  I32 halfingSteps(void)
148  { return m_halfingSteps; }
149 
150  void setCollisionMethod(CollisionMethod a_method)
151  { m_method=a_method; }
152  CollisionMethod collisionMethod(void)
153  { return m_method; }
154 
155  void setCollider(sp<SurfaceI> a_spSurfaceI)
156  { m_spCollider=a_spSurfaceI; }
157  sp<SurfaceI> collider(void)
158  { return m_spCollider; }
159 
160  void setDriver(sp<SurfaceI> a_spSurfaceI)
161  { m_spDriver=a_spSurfaceI; }
162  sp<SurfaceI> driver(void)
163  { return m_spDriver; }
164 
165  void setDeformed(sp<SurfaceI> a_spSurfaceI)
166  { m_spDeformed=a_spSurfaceI; }
167  sp<SurfaceI> deformed(void)
168  { return m_spDeformed; }
169 
170  void setDrawDebug(sp<DrawI> a_spDrawDebug)
171  { m_spDrawDebug=a_spDrawDebug; }
172 
173  void storeAsRest(U32 a_index);
174 
175  void populate(void);
176  void step(U32 a_index);
177 
178  Array<SpatialVector>& tangent(void) { return m_tangent; }
179  Array<SpatialVector>& facing(void) { return m_facing; }
180  Array<SpatialVector>& forceIn(void) { return m_forceIn; }
181  Array<SpatialVector>& velocityIn(void){ return m_velocityIn; }
182  Array<Real>& velocity(void) { return m_velocity; }
183  Array<I32>& bindFace(void) { return m_bindFace; }
184  Array<SpatialBary>& bindBary(void) { return m_bindBary; }
185  Array<SpatialVector>& location(void) { return m_location; }
186  Array<SpatialVector>& locationRef(void)
187  { return m_locationRef; }
188  Array<SpatialVector>& locationDef(void)
189  { return m_locationDef; }
190 
191  private:
192  class Contact
193  {
194  public:
195  Contact(void) { clear(); }
196  ~Contact(void) {}
197 
198  void clear(void)
199  {
200  set(m_offset);
201  set(m_normal);
202  m_active=FALSE;
203  }
204  void setOffset(SpatialVector a_offset)
205  {
206  m_offset=a_offset;
207  m_active=TRUE;
208  }
209  void setNormal(SpatialVector a_normal)
210  {
211  m_normal=a_normal;
212  }
213 
214  BWORD active(void) { return m_active; }
215  SpatialVector offset(void) { return m_offset; }
216  SpatialVector normal(void) { return m_normal; }
217 
218  private:
219  SpatialVector m_offset;
220  SpatialVector m_normal;
221  BWORD m_active;
222  };
223 
224  void computeAngles(U32 a_index, Vector4& a_rAngle,
225  const SpatialVector* a_pDelta);
226 
227  Array<Contact> m_contact;
228  Array<SpatialVector> m_tangent; // root direction
229  Array<SpatialVector> m_facing; // unit facing
230  Array<SpatialVector> m_forceIn; // external force
231  Array<SpatialVector> m_velocityIn; // external velocity
232  Array<SpatialVector> m_restFacing; // original facing
233  Array<SpatialVector> m_location; // local points
234  Array<SpatialVector> m_locationRef; // in driver space
235  Array<SpatialVector> m_locationDef; // in deformed space
236  Array<Real> m_velocity; // angular velocities
237  Array<I32> m_bindFace; // attach face index
238  Array<SpatialBary> m_bindBary; // attach coordinate
239  Array<Real> m_restLength; // full base to tip
240  Array<Real> m_tangentBias; // tend to keep same dir
241  Array<I32> m_kink; // buckle index
242  Array<I32> m_kinkForward; // buckle dir (boolean)
243  Array< Vector4 > m_y; // last correction
244  Array< Vector4 > m_length; // segment length
245  Array< Vector4 > m_restAngle; // original rest angle
246  Array< Vector4 > m_plasticAngle; // dynamic rest angle
247 
248  Real m_t; // time
249  Real m_tension; // spring
250  Real m_tensionRandom;
251  Real m_restoration;
252  Real m_restorationRandom;
253  Real m_drag; // angular drag
254  Real m_dragRandom;
255  Real m_bend; // added bend to rest angle
256  BWORD m_grabbing;
257  Real m_grabBias;
258  Real m_grabBiasRandom;
259  Real m_collisionGap;
260  Real m_mass;
261  Real m_h; // time step
262  Real m_wind;
263  Real m_turbulence;
264  BWORD m_buckling;
265  Real m_breakAngle; // buckle above this
266  Real m_breakAngleRandom;
267  Real m_elasticAngle; // spring back a little
268  Real m_elasticAngleRandom;
269  Real m_popAngle; // unbuckle below this
270  Real m_popAngleRandom;
271  Real m_recoveryAngle; // inc towards original rest
272  Real m_recoveryAngleRandom;
273  CollisionMethod m_method;
274  I32 m_halfingSteps;
275 
276  sp<SurfaceI> m_spCollider;
277  sp<SurfaceI> m_spDriver;
278  sp<SurfaceI> m_spDeformed;
279  sp<DrawI> m_spDrawDebug;
280 
281  Matrix<4,4,Real> m_invA;
282  Matrix<4,4,Real> m_dfdx;
283  Matrix<4,4,Real> m_hdfdx;
284 };
285 
286 } /* namespace ext */
287 } /* namespace fe */
288 
289 #endif /* __grass_Blade__ */
kernel
Definition: namespace.dox:3
Wrapper for std::vector.
Definition: Array.h:21
Intrusive Smart Pointer.
Definition: src/core/ptr.h:53
minimal semi-implicit curve sim
Definition: Blade.h:20