VR-Forces 4.8 Class Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
DtWeatherEffect.h
Go to the documentation of this file.
1 /******************************************************************************
2 ** Copyright (c) 2020 MAK Technologies, Inc.
3 ** All rights reserved.
4 ******************************************************************************/
5 
9 
10 #pragma once
11 
12 #include <vrvOsg/DtGlVaoManager.h>
13 #include <vrvOsg/vrvOsg.h>
14 
15 #include <vrvUtil/DtJobSplitter.h>
18 
19 #include <osg/BlendFunc>
20 #include <osg/RenderInfo>
21 #include <osg/Vec3d>
22 
23 
24 namespace makVrv
25 {
26  // Forward declarations.
27  class DtWeatherEffectDrawable;
28 
29 
41  {
42  public:
43 
45  struct DrawData
46  {
48  : myRenderInfo(0)
49  , myCamPos(0, 0, 0)
50  , myCamMove(0, 0, 0)
51  , myNearClip(1.0f)
52  , myParametersUnfmLoc(0)
53  , mySoftnessUnfmLoc(0)
54  , myAdditiveBlend(false)
55  , myStateDirty(true)
56  , myDrawable(0)
57  {
58  // intentional nop
59  }
60 
61  osg::RenderInfo* myRenderInfo;
62  osg::Vec3d myCamPos;
63  osg::Vec3d myCamMove;
64  float myNearClip;
70  };
71 
78  {
79  EffectTypePrecipitation = 0,
80  EffectTypeParticle
81  };
82 
90  {
91  SurfaceHitTypeNone = 0,
92  SurfaceHitTypeHail
93  };
94 
95 
98 
100  virtual ~DtWeatherEffect();
101 
102  private:
103 
105  DtWeatherEffect();
106 
108  DtWeatherEffect(const DtWeatherEffect &other);
109 
111  DtWeatherEffect &operator=(const DtWeatherEffect &other);
112 
113  public:
114 
116  // \param particleCount The maximum number of particles to simulate.
117  // \param particleSize The base particle size.
118  // \param radius The effect radius.
119  // \param type the type of effect.
120  virtual void init(int particleCount, float particleSize, float radius, EffectType type);
121 
123  virtual void releaseGLObjects(osg::State* state) const;
124 
129  virtual void simulationUpdate(float timeStep, double currentTime, DtJobSplitter* jobSplitter);
130 
134  virtual void postSimulationUpdate(float timeStep, double currentTime);
135 
137  virtual void draw(DtWeatherEffect::DrawData& drawData, const osg::Vec3& baseColor) const;
138 
143  virtual void cullUpdate(const osg::Vec3d& camPos, const osg::Matrixd& basis, DtJobSplitter* jobSplitter);
144 
150  virtual void setSurfaceHitType(SurfaceHitType type);
151 
155  virtual void setWind(float windDirectionRad, float windSpeedMps);
156 
159  virtual void setWindSpeedMultiplier(float multiplier);
160 
163  virtual void setWindLiftMultiplier(float multiplier);
164 
167  virtual void setWindTurbulence(float multiplier);
168 
173  virtual void setStreak(float multiplier);
174 
179  virtual void setCameraStreakEnable(bool enable);
180 
183  virtual void setEffectFade(float fade);
184 
187  virtual void setIntensity(float intensity);
188 
196  virtual void setFadePerIntensity(float fadeMin, float fadeMax, float intensityMin, float intensityMax);
197 
205  virtual void setFadePerWind(float fadeMin, float fadeMax, float windMin, float windMax);
206 
214  virtual void setParticlesPerIntensity(float percentMin, float percentMax, float intensityMin, float intensityMax);
215 
218  virtual void setColorMult(float r, float g, float b);
219 
222  virtual void setAdditiveBlend(bool enable);
223 
225  virtual bool additiveBlend() const;
226 
229  virtual void setVelocity(float x, float y, float z);
230 
233  virtual void setInitRotationVariation(float rotationDeg);
234 
236  virtual float radius() const;
237 
243  virtual void setTextureAtlasCell(unsigned char numColumns, unsigned char numRows, unsigned char col, unsigned char row);
244 
247  virtual void setDepthSoftness(float softness);
248 
250  virtual float depthSoftness() const;
251 
254  virtual void setDragCoefficient(float coefficient);
255 
257  virtual float dragCoefficient() const;
258 
261  virtual void setSortEnable(bool enable);
262 
264  virtual bool sortEnable() const;
265 
268  virtual void runSort(const osg::Vec3& localCamPos);
269 
270  protected:
271 
273  struct MeshGroup
274  {
276  : myVboPositionArray(0)
277  , myVboMoveArray(0)
278  , myVboTexCoords0Array(0)
279  {
280  myPoints = new osg::Vec4Array;
281  myMove = new osg::Vec4Array;
282  myTexCoords0 = new osg::Vec2Array;
283  }
284 
288 
289  unsigned int myVboPositionArray;
290  unsigned int myVboMoveArray;
291  unsigned int myVboTexCoords0Array;
292  };
293 
295  struct Particle
296  {
298  : myParent(0)
299  , myChild(0)
300  , mySortDepth(0)
301  , myPosition(0, 0, 0, 0)
302  , myMove(0, 0, 0, 1)
303  , myVelocity(0, 0, 0)
304  , myUsePhysics(true)
305  , myLifeTime(0.0f)
306  , myLifeTimeInit(1.0f)
307  {
308  //intentional nop
309  }
310 
311  Particle* myParent; // next particle in linked list
312  Particle* myChild; // previous particle in link list
313  float mySortDepth;
314  osg::Vec4 myPosition;
315  osg::Vec4 myMove;
316  osg::Vec3 myVelocity;
318  float myLifeTime; // current life time left
319  float myLifeTimeInit; // initial life time
320  };
321 
326  struct BlendData
327  {
329  : myValueMin(0)
330  , myValueMax(1)
331  , myBlendMin(0)
332  , myBlendMax(1)
333  {
334  //intentional nop
335  }
336 
337  float myValueMin; // the output value at the min blend
338  float myValueMax; // the output value at the max blend
339  float myBlendMin; // < this value output is 0
340  float myBlendMax; // >= this value, output is myValueMax
341  };
342 
346  virtual void runSimulationUpdateJob(float timeStep, double currentTime);
347 
349  virtual void updateHailSurfaceHit(float timeStep);
350 
353  virtual void computeSortDepth(const osg::Vec3& reference);
354 
356  virtual void fillSortedParticles();
357 
361  virtual bool bindMeshGroupData(MeshGroup* meshGroup, osg::RenderInfo& renderInfo) const;
362 
366  virtual bool bindDynamicMeshGroupData(MeshGroup* meshGroup, osg::RenderInfo& renderInfo) const;
367 
372  virtual bool bindVaoToMeshGroup(GLuint vao, MeshGroup* meshGroup, osg::RenderInfo& renderInfo) const;
373 
377  virtual void simulatePrecipitationParticles(float timeStep, double currentTime);
378 
383  virtual void simulateParticles(float timeStep, double currentTime, osg::Vec3d& basisPosChange);
384 
385  // non-virtual for maximum inner loop performance.
386 
391  void wrapPosition(float& posX, float& posY, float& posZ);
392 
396  Particle* getFreeParticle(void);
397 
400  void freeParticle(Particle* particle);
401 
406  void spawnHailParticle(const osg::Vec3d& position, const osg::Vec3& normal, bool usePhysics);
407 
411  const osg::Vec3 crossProduct(const osg::Vec3& v0, const osg::Vec3& v1);
412 
416  float computeRandomMinMax(float fMin, float fMax);
417 
421  void computeRandomPointInRadius(osg::Vec2& point, float radius);
422 
428  bool clampPosition(osg::Vec3d& position, osg::Vec3& normal, const osg::Vec3& up);
429 
433  virtual float computeBlendControl(const BlendData& data, float blendPos) const;
434 
435  private:
436 
438  static void theSimulationUpdateJob(void* data);
439 
441  static int theSortBackToFront(const void* arg0, const void* arg1);
442 
444  static void theSortJob(void* data);
445 
446  protected:
447 
450  {
452  : myEffect(0)
453  , myTimeStep(0)
454  , myCurrentTime(0)
455  {
456  //intentional nop
457  }
458 
460  float myTimeStep;
462  };
463 
465  struct SortJobData
466  {
468  : myEffect(0)
469  , myCameraPos(0, 0, 0)
470  {
471  //intentional nop
472  }
473 
475  osg::Vec3 myCameraPos;
476  };
477 
479 
480  osg::Matrixd myBasisRot;
481  osg::Vec3d myBasisPos;
482  osg::Vec3d myLastBasisPos;
484 
488  osg::Vec3 myScroll;
489  float myRadius;
496  osg::Vec3 myVelocity;
499  float myIntensity;
504  osg::Vec3 myColorMult;
507  float myStreak;
516 
519 
520  Particle* myParticlesMemoryPool; // the array of all particles
521  int myParticleMemoryPoolCount; // the maximum number of particles
522 
523  Particle* myParticlesFree; // the head of the free particle list
524  Particle* myParticlesActive; // the head of the active particle list
525  int myParticleActiveCount; // current active amount of particles
526 
527  Particle** myRenderList; // particle render list array
528  int myRenderParticleCount; // number of particles active in the render list array
529 
532 
535 
537  };
538 
539 
542  {
543  public:
546 
548  virtual ~DtWeatherEffectCreator();
549 
550  private:
554  DtWeatherEffectCreator &operator=(const DtWeatherEffectCreator& other);
555 
556  public:
558  // \param particleCount The maximum number of particles to simulate.
559  // \param particleSize The base particle size.
560  // \param radius The effect radius.
561  // \param type The type of effect to create.
562  virtual DtWeatherEffect* create(int particleCount, float particleSize, float radius, DtWeatherEffect::EffectType type) const;
563 
566  static DtWeatherEffectCreator& instance(DtDe& de);
567 
569  static const std::string& theClassName();
570 
571  protected:
573  };
574 }
575 
576 
577 
578 
float myLifeTimeInit
Definition: DtWeatherEffect.h:319
osg::ref_ptr< osg::BlendFunc > myBlendFunc
Definition: DtWeatherEffect.h:506
float myWindLiftMultiplier
Definition: DtWeatherEffect.h:493
osg::Vec3d myBasisPos
Definition: DtWeatherEffect.h:481
A structure used to define a mesh group (voa, positions, coords).
Definition: DtWeatherEffect.h:273
BlendData myFadeByIntensity
Definition: DtWeatherEffect.h:500
float myBlendMax
Definition: DtWeatherEffect.h:340
float myBlendMin
Definition: DtWeatherEffect.h:339
Virtual base class.
Definition: DtVirtualBaseClass.h:22
bool myAdditiveBlend
Definition: DtWeatherEffect.h:67
Particle ** myRenderList
Definition: DtWeatherEffect.h:527
Implementation independent random number generator.
Definition: DtRandomNumberGenerator.h:23
osg::Vec3 myCameraPos
Definition: DtWeatherEffect.h:475
osg::Vec3d myCamMove
Definition: DtWeatherEffect.h:63
#define DT_DLL_VRVOSG
Definition: vrvOsg.h:23
bool myBasisDirty
Definition: DtWeatherEffect.h:483
SimulationUpdateJobData()
Definition: DtWeatherEffect.h:451
unsigned int myVboTexCoords0Array
Definition: DtWeatherEffect.h:291
bool mySortEnable
Definition: DtWeatherEffect.h:515
SortJobData()
Definition: DtWeatherEffect.h:467
A structure to hold data for a sorting job.
Definition: DtWeatherEffect.h:465
osg::ref_ptr< osg::Vec4Array > myMove
Definition: DtWeatherEffect.h:286
unsigned int GLuint
Definition: DtGlTextureBufferObject.h:17
DrawData()
Definition: DtWeatherEffect.h:47
float myTimeStep
Definition: DtWeatherEffect.h:460
this class is used to split work up between threads.
Definition: DtJobSplitter.h:64
Particle()
Definition: DtWeatherEffect.h:297
osg::Vec3d myCamPos
Definition: DtWeatherEffect.h:62
bool myCameraStreak
Definition: DtWeatherEffect.h:509
SurfaceHitType mySurfaceHitType
Definition: DtWeatherEffect.h:486
GLint myParametersUnfmLoc
Definition: DtWeatherEffect.h:65
DtWeatherEffect * myEffect
Definition: DtWeatherEffect.h:474
unsigned int myVboMoveArray
Definition: DtWeatherEffect.h:290
float myTextureAtlasRow
Definition: DtWeatherEffect.h:513
BlendData myParticlesByIntensity
Definition: DtWeatherEffect.h:502
osg::Vec3 myVelocity
Definition: DtWeatherEffect.h:316
float myTextureAtlasRows
Definition: DtWeatherEffect.h:511
bool myAdditiveBlend
Definition: DtWeatherEffect.h:505
float myTextureAtlasCols
Definition: DtWeatherEffect.h:510
DtRandomNumberGenerator myRandomNumberGen
Definition: DtWeatherEffect.h:536
creator for DtWeatherEffect
Definition: DtWeatherEffect.h:541
A structure used to hold data for drawing.
Definition: DtWeatherEffect.h:45
osg::Vec3d myLastBasisPos
Definition: DtWeatherEffect.h:482
float myInitRotationRad
Definition: DtWeatherEffect.h:497
Contains makVrv::DtVirtualBaseClass class.
A drawable for drawing weather effects such as hail.
Definition: DtWeatherEffectDrawable.h:36
Contains makVrv::DtRandomNumberGenerator class.
BlendData()
Definition: DtWeatherEffect.h:328
bool myStateDirty
Definition: DtWeatherEffect.h:68
osg::ref_ptr< osg::Vec4Array > myPoints
Definition: DtWeatherEffect.h:285
float myIntensity
Definition: DtWeatherEffect.h:499
osg::Vec3 myScroll
Definition: DtWeatherEffect.h:488
int myRenderParticleCount
Definition: DtWeatherEffect.h:528
SortJobData mySortJobData
Definition: DtWeatherEffect.h:533
Contains makVrv::DtJobSplitter class.
float myWindSpeedMultiplier
Definition: DtWeatherEffect.h:492
float myValueMax
Definition: DtWeatherEffect.h:338
DtJobSplitterJob mySimulationUpdateJob
Definition: DtWeatherEffect.h:531
float myNearClip
Definition: DtWeatherEffect.h:64
this class is used to create weather effects around the eye to represent effects such as mist...
Definition: DtWeatherEffect.h:40
float myWindTurbulence
Definition: DtWeatherEffect.h:494
float mySurfaceHitTimer
Definition: DtWeatherEffect.h:487
int myParticleActiveCount
Definition: DtWeatherEffect.h:525
EffectType
An enumeration to define the effect type.
Definition: DtWeatherEffect.h:77
float mySortDepth
Definition: DtWeatherEffect.h:313
A structure to hold blending control data for things like particle amount per intensity.
Definition: DtWeatherEffect.h:326
float myDepthSoftness
Definition: DtWeatherEffect.h:514
float myDragCoefficient
Definition: DtWeatherEffect.h:495
osg::Vec3 myVelocity
Definition: DtWeatherEffect.h:496
float myWindDirectionRad
Definition: DtWeatherEffect.h:490
A structure used to define a simulation particle.
Definition: DtWeatherEffect.h:295
osg::ref_ptr< osg::Vec2Array > myTexCoords0
Definition: DtWeatherEffect.h:287
float myTextureAtlasCol
Definition: DtWeatherEffect.h:512
float myEffectFade
Definition: DtWeatherEffect.h:498
Particle * myParent
Definition: DtWeatherEffect.h:311
double myCurrentTime
Definition: DtWeatherEffect.h:461
DtGlVaoManager * myVaoManager
Definition: DtWeatherEffect.h:518
GLint mySoftnessUnfmLoc
Definition: DtWeatherEffect.h:66
Particle * myParticlesActive
Definition: DtWeatherEffect.h:524
osg::Vec4 myMove
Definition: DtWeatherEffect.h:315
osg::Vec3 myColorMult
Definition: DtWeatherEffect.h:504
DtDe & myDe
Definition: DtWeatherEffect.h:572
bool myUsePhysics
Definition: DtWeatherEffect.h:317
osg::RenderInfo * myRenderInfo
Definition: DtWeatherEffect.h:61
float myWindSpeedMps
Definition: DtWeatherEffect.h:491
A structure to hold data for a simluation update job.
Definition: DtWeatherEffect.h:449
SimulationUpdateJobData mySimulationUpdateJobData
Definition: DtWeatherEffect.h:530
A generic structure to hold data for a job for use with DtJobSplitter.
Definition: DtJobSplitter.h:26
MeshGroup * myMeshGroup
Definition: DtWeatherEffect.h:517
float myStreakAdjustment
Definition: DtWeatherEffect.h:508
DtDe & myDe
Definition: DtWeatherEffect.h:478
This class is used to manage an opengl vertex array object (VAO) dealing with multiple opengl context...
Definition: DtGlVaoManager.h:49
DT_DLL_DEBUGDRAWRENDERER void init(makVrv::DtDe &de)
Work function for the plugin initialization.
float myLifeTime
Definition: DtWeatherEffect.h:318
float myRadius
Definition: DtWeatherEffect.h:489
Contains DLL export macros.
unsigned int myVboPositionArray
Definition: DtWeatherEffect.h:289
EffectType myEffectType
Definition: DtWeatherEffect.h:485
Particle * myParticlesMemoryPool
Definition: DtWeatherEffect.h:520
The DtDe is the core component of any VR-Vantage application.
Definition: DtDe.h:69
osg::Vec4 myPosition
Definition: DtWeatherEffect.h:314
float myParticleSize
Definition: DtWeatherEffect.h:503
SurfaceHitType
An enumeration to define a surface hit effect.
Definition: DtWeatherEffect.h:89
float myValueMin
Definition: DtWeatherEffect.h:337
BlendData myFadeByWind
Definition: DtWeatherEffect.h:501
Contains the DtGlVaoManager class declaration.
DtJobSplitterJob mySortJob
Definition: DtWeatherEffect.h:534
DtWeatherEffect * myEffect
Definition: DtWeatherEffect.h:459
int myParticleMemoryPoolCount
Definition: DtWeatherEffect.h:521
MeshGroup()
Definition: DtWeatherEffect.h:275
const DtWeatherEffectDrawable * myDrawable
Definition: DtWeatherEffect.h:69
Particle * myParticlesFree
Definition: DtWeatherEffect.h:523
float myStreak
Definition: DtWeatherEffect.h:507
osg::Matrixd myBasisRot
Definition: DtWeatherEffect.h:480
Particle * myChild
Definition: DtWeatherEffect.h:312

Document ID: Generated on Thu Aug 27 10:56:05 EDT 2020 from SVN revision 217100
Copyright © 2005-2020 MAK Technologies. All Rights Reserved (www.mak.com)