VR-Forces Developer's Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
DtWeatherLightning.h
Go to the documentation of this file.
1 /******************************************************************************
2 ** Copyright (c) 2025 MAK Technologies, Inc.
3 ** All rights reserved.
4 ******************************************************************************/
5 
9 
10 #pragma once
11 
12 #include <vrvCore/DtDe.h>
13 #include <vrvCore/DtJobSplitter.h>
14 
16 
17 #include <vrvOsg/DtGlVaoManager.h>
18 #include <vrvOsg/vrvOsg.h>
19 
22 
23 #include <matrix/vlVector.h>
24 
25 #include <osg/Vec3d>
26 #include <osg/Vec4d>
27 #include <osg/Matrixd>
28 #include <osg/Array>
29 
30 namespace osg
31 {
32  class RenderInfo;
33  class StateSet;
34  class State;
35 }
36 
37 namespace makVrv
38 {
39  // Forward declarations.
40  class DtJobSplitter;
41  class DtLight;
42  class DtWeatherArea;
43  class DtWeatherAreaGroup;
44  class DtGlBuffer;
45 
46 
49 
52 
54  template <>
55  inline const char* creatorTypeName<DtWeatherLightning>(void) { return "DtWeatherLightningCreator"; }
56 
64  {
65  friend class DtWeatherLightningFactory;
66 
67  public:
68 
70  struct DrawData
71  {
73  : myRenderInfo(0)
74  , myCamPos(0, 0, 0)
75  , myParametersUnfmLoc(0)
76  , myTransformUnfmLoc(0)
77  , myWeatherAreaGroup(0)
78  , myState(0)
79  {
80  // intentional nop
81  }
82 
83  osg::RenderInfo* myRenderInfo;
84  osg::Vec3d myCamPos;
85  osg::Matrixd myViewMatrix;
89  osg::StateSet* myState;
90  };
91 
93 
95  virtual ~DtWeatherLightning();
96 
98  DtWeatherLightning() = delete;
99 
101  DtWeatherLightning(const DtWeatherLightning &other) = delete;
102 
104  DtWeatherLightning &operator=(const DtWeatherLightning &other) = delete;
105 
106  protected:
107 
110 
111  public:
112 
114  virtual void init();
115 
117  virtual void releaseGLObjects(osg::State* state) const;
118 
123  virtual void simulationUpdate(float timeStep, double currentTime, DtJobSplitter* jobSplitter);
124 
131  virtual bool cullUpdate(const osg::Vec3d& camPos, const osg::Matrixd& viewMatrixI,
132  const Frustum_64& frustum, DtJobSplitter* jobSplitter);
133 
135  virtual void draw(DtWeatherLightning::DrawData& drawData);
136 
140  virtual void setBounds(const DtVector& bounds, float cornerRadius);
141 
145  virtual void setTransform(const osg::Vec3d& position, const osg::Matrixd& rotation);
146 
149  virtual void setIntensity(const float intensity);
150 
153  virtual void setBaseColor(const DtVector& color);
154 
157  virtual void runSort(const osg::Vec3& localCamPos);
158 
161  virtual void setEnabled(bool enabled);
162 
164  virtual bool enabled() const;
165 
168  virtual bool culled() const;
169 
174  virtual void computeBounds(osg::Vec4& bounds, osg::Vec3d& position, osg::Matrixd& rotation) const;
175 
176  protected:
177 
179  struct MeshGroup
180  {
182  : myVboPositionArray(0)
183  , myVboNormalArray(0)
184  , myVboTexCoordArray(0)
185  , myVboIndiceArray(0)
186  , myIndices(0)
187  , myIndicesCount(0)
188  , myActivePointCount(0)
189  {
190  myPoints = new osg::Vec4Array;
191  myNormals = new osg::Vec4Array;
192  myTexCoords = new osg::Vec2Array;
193  }
194 
198  unsigned short* myIndices;
199  unsigned int myIndicesCount;
200  unsigned int myActivePointCount;
201 
202  DtGlBuffer* myVboPositionArray = nullptr;
203  DtGlBuffer* myVboNormalArray = nullptr;
204  DtGlBuffer* myVboTexCoordArray = nullptr;
205  DtGlBuffer* myVboIndiceArray = nullptr;
206  };
207 
210  {
212  : myDirection(1, 0, 0)
213  , myWidthScale(1.0f)
214  , myChildDepth(0)
215  {
216  // intentional noop
217  }
218 
219  osg::Vec3 myDirection;
222  osg::Vec3 myPoints[16];
223  std::vector<LightningFinger*> myChildren;
224  };
225 
228  {
230  : mySortDepth(0)
231  , myUnique(0.0f)
232  , myAliveTime(0)
233  , myTime(0)
234  , myStart(0,0,0)
235  , myEnd(0,0,0)
236  , myLightPosition(0,0,0)
237  , myActiveFingers(0)
238  , myRootFinger(0)
239  , myMeshGroup(0)
240  , myVaoManager(0)
241  , myMeshDirty(false)
242  {
243  // intentional noop
244  }
245 
246  float mySortDepth;
247  float myUnique;
248  float myAliveTime; // amount of time to stay alive
249  float myTime; // amount of time that has passed
250  osg::Vec3 myStart;
251  osg::Vec3 myEnd;
252  osg::Vec3d myLightPosition;
253  LightningFinger myLightningFingerPool[24]; // memory pool
259  };
260 
263  friend struct SortDistanceComparator;
264 
266  {
267  public:
268  bool operator()(const DtWeatherLightning::LightningBolt* lhs, const DtWeatherLightning::LightningBolt* rhs);
269  };
270 
273  virtual void initBoltMeshGroup(LightningBolt* bolt);
274 
278  virtual void computeBoltAliveTimeRange(float& minTime, float& maxTime) const;
279 
283  virtual void createBolt(const osg::Vec3& start, const osg::Vec3& end);
284 
288  virtual void createFingerSegments(LightningBolt* bolt, LightningFinger* finger);
289 
295  virtual bool positionInBounds2D(const float x, const float y, const osg::Vec3& bounds);
296 
300  virtual float computeRandomMinMax(float fMin, float fMax);
301 
306  virtual bool updateRandomSeed( double currentTime );
307 
312  virtual void setRandomSeedSyncTimeInterval( unsigned long intervalInMs );
313 
316  virtual void computeSortDepth(const osg::Vec3& reference);
317 
321  void fillMeshGroupFlashPoint(LightningBolt* bolt);
322 
327  virtual void fillMeshGroup(LightningBolt* bolt, LightningFinger* finger);
328 
332  virtual bool bindMeshGroupData(MeshGroup* meshGroup, osg::RenderInfo& renderInfo) const;
333 
337  virtual bool bindDynamicMeshGroupData(MeshGroup* meshGroup, osg::RenderInfo& renderInfo) const;
338 
343  virtual bool bindVaoToMeshGroup(GLuint vao, MeshGroup* meshGroup, osg::RenderInfo& renderInfo) const;
344 
348  const osg::Vec3 crossProduct(const osg::Vec3& v0, const osg::Vec3& v1) const;
349 
350  protected:
351 
353  static void theSortJob(void* data);
354 
355  protected:
356 
358  struct SortJobData
359  {
361  : myWeatherLightning(0)
362  , myLocalCameraPos(0, 0, 0)
363  {
364  //intentional nop
365  }
366 
368  osg::Vec3 myLocalCameraPos;
369  };
370 
372 
373  bool myEnabled;
374  bool myCulled;
375 
376  osg::Vec3d myPosition;
377  osg::Matrixd myRotation;
378 
379  float myBoundsX;
380  float myBoundsY;
381  float myBoundsZ;
383 
384  float myBoltWidth;
385  float myIntensity;
386  osg::Vec3 myBaseColor;
387 
388  // These are mutable because they modified during releaseGLObjects.
389  mutable std::vector<LightningBolt*> myMutableLightningBoltsPool; // memory pool
390  mutable std::vector<LightningBolt*> myMutableLightningBoltsActive; // active list
391 
394 
396  unsigned int myRandomSeed;
397  unsigned long mySeedSyncInterval;
398  unsigned long myNextSyncTime;
402 
404  };
405 }
406 
407 
408 
409 
const DtWeatherAreaGroup * myWeatherAreaGroup
Definition: DtWeatherLightning.h:88
float myIntensity
Definition: DtWeatherLightning.h:385
DT_DLL_EXAMPLESCENEROOTPLUGIN void init(DtDe &anIG)
int myActiveFingers
Definition: DtWeatherLightning.h:254
A structure to hold data for a sorting job.
Definition: DtWeatherLightning.h:358
std::vector< LightningFinger * > myChildren
Definition: DtWeatherLightning.h:223
osg::Vec3 myBaseColor
Definition: DtWeatherLightning.h:386
float myBoundsCornerRadius
Definition: DtWeatherLightning.h:382
GLint myParametersUnfmLoc
Definition: DtWeatherLightning.h:86
Virtual base class. Allows for RTTI and proper virtual destruction. Used by Creators, Factories, Providers, Assemblers and User Interfaces.
Definition: DtVirtualBaseClass.h:19
Implementation independent random number generator.
Definition: DtRandomNumberGenerator.h:20
osg::Vec3 myDirection
Definition: DtWeatherLightning.h:219
unsigned long mySeedSyncInterval
Definition: DtWeatherLightning.h:397
osg::Vec3d myCamPos
Definition: DtWeatherLightning.h:84
float myBoltWidth
Definition: DtWeatherLightning.h:384
osg::Vec3d myLightPosition
Definition: DtWeatherLightning.h:252
float myWidthScale
Definition: DtWeatherLightning.h:220
osg::Vec3 myEnd
Definition: DtWeatherLightning.h:251
bool myMeshDirty
Definition: DtWeatherLightning.h:258
#define DT_DLL_VRVOSG
Definition: vrvOsg.h:23
osg::ref_ptr< osg::Vec2Array > myTexCoords
Definition: DtWeatherLightning.h:197
std::vector< LightningBolt * > myMutableLightningBoltsActive
Definition: DtWeatherLightning.h:390
MeshGroup()
Definition: DtWeatherLightning.h:181
LightningBolt()
Definition: DtWeatherLightning.h:229
unsigned int GLuint
Definition: DtGlTextureBufferObject.h:18
A structure used to hold data for drawing.
Definition: DtWeatherLightning.h:70
Contains makVrv::DtDe class.
this class is used to split work up between threads.
Definition: DtJobSplitter.h:64
DtWeatherLightning * myWeatherLightning
Definition: DtWeatherLightning.h:367
unsigned long myNextSyncTime
Definition: DtWeatherLightning.h:398
A structure used to define a lightning bolt.
Definition: DtWeatherLightning.h:227
A group node which serves as a root for weather areas, patchy ground fog areas and effects...
Definition: DtWeatherAreaGroup.h:76
DtDe & myDe
Definition: DtWeatherLightning.h:371
unsigned int myIndicesCount
Definition: DtWeatherLightning.h:199
DtVirtualBaseClassCreator< DtWeatherLightning > DtWeatherLightningCreator
creator
Definition: DtWeatherLightning.h:48
osg::Matrixd myViewMatrix
Definition: DtWeatherLightning.h:85
float myStrikeTimer
Definition: DtWeatherLightning.h:401
Camera forward declarations.
This class simulates and renders a lightning area. The area will randomly create lightning within a s...
Definition: DtWeatherLightning.h:63
float myBoundsZ
Definition: DtWeatherLightning.h:381
Variadic templated creator class for defining a DtVirtualBaseClass creator that is automatically regi...
Definition: DtVirtualBaseClassCreator.h:23
A structure used to define a lightning bolt finger.
Definition: DtWeatherLightning.h:209
osg::RenderInfo * myRenderInfo
Definition: DtWeatherLightning.h:83
float myBoundsX
Definition: DtWeatherLightning.h:379
Contains makVrv::DtRandomNumberGenerator class.
osg::ref_ptr< osg::Vec4Array > myPoints
Definition: DtWeatherLightning.h:195
unsigned int myActivePointCount
Definition: DtWeatherLightning.h:200
Contains makVrv::DtJobSplitter class.
osg::ref_ptr< osg::Vec4Array > myNormals
Definition: DtWeatherLightning.h:196
DtGlVaoManager * myVaoManager
Definition: DtWeatherLightning.h:257
osg::StateSet * myState
Definition: DtWeatherLightning.h:89
float myTime
Definition: DtWeatherLightning.h:249
const char * creatorTypeName< DtWeatherLightning >(void)
template specialization for the creator (pass the class being created to the creatorTypeName template...
Definition: DtWeatherLightning.h:55
osg::Vec3 myStart
Definition: DtWeatherLightning.h:250
DrawData()
Definition: DtWeatherLightning.h:72
DtLight * myLight
Definition: DtWeatherLightning.h:403
osg::Matrixd myRotation
Definition: DtWeatherLightning.h:377
A generic OpenGL buffer. This can be: -&gt; a vertex buffer -&gt; an index buffer -&gt; a shader storage buffe...
Definition: DtGlBuffer.h:29
A structure used to define a mesh group (voa, positions, coords).
Definition: DtWeatherLightning.h:179
DtJobSplitterJob mySortJob
Definition: DtWeatherLightning.h:393
Definition: DtWeatherLightning.h:265
DtRandomNumberGenerator myRandomNumberGen
Definition: DtWeatherLightning.h:395
A generic structure to hold data for a job for use with DtJobSplitter.
Definition: DtJobSplitter.h:26
SortJobData()
Definition: DtWeatherLightning.h:360
LightningFinger()
Definition: DtWeatherLightning.h:211
SortJobData mySortJobData
Definition: DtWeatherLightning.h:392
std::vector< LightningBolt * > myMutableLightningBoltsPool
Definition: DtWeatherLightning.h:389
bool myEnabled
Definition: DtWeatherLightning.h:373
Class for generic lights This holds per-light data such as range, attenuation factors, colors, etc.
Definition: DtLight.h:49
This class is used to manage an opengl vertex array object (VAO) dealing with multiple opengl context...
Definition: DtGlVaoManager.h:58
float myStrikeTimeMax
Definition: DtWeatherLightning.h:400
float myBoundsY
Definition: DtWeatherLightning.h:380
osg::Vec3d myPosition
Definition: DtWeatherLightning.h:376
float myUnique
Definition: DtWeatherLightning.h:247
int myChildDepth
Definition: DtWeatherLightning.h:221
Contains DLL export macros.
The DtDe is the core component of any VR-Vantage application. It owns a DtRenderer, DtDeCommunicator, as well as a DtDisplay and other things.
Definition: DtDe.h:76
float myStrikeTimeMin
Definition: DtWeatherLightning.h:399
Contains the DtGlVaoManager class declaration.
unsigned short * myIndices
Definition: DtWeatherLightning.h:198
GLint myTransformUnfmLoc
Definition: DtWeatherLightning.h:87
float mySortDepth
Definition: DtWeatherLightning.h:246
bool myCulled
Definition: DtWeatherLightning.h:374
float myAliveTime
Definition: DtWeatherLightning.h:248
MeshGroup * myMeshGroup
Definition: DtWeatherLightning.h:256
LightningFinger * myRootFinger
Definition: DtWeatherLightning.h:255
osg::Vec3 myLocalCameraPos
Definition: DtWeatherLightning.h:368
friend DtWeatherLightningCreator
Definition: DtWeatherLightning.h:92
unsigned int myRandomSeed
Definition: DtWeatherLightning.h:396

Document ID: Generated on Thu Oct 15 21:27:02 EDT 2026 from SVN revision 296421
Copyright © 2005-2026 MAK Technologies. All Rights Reserved (www.mak.com)