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) 2023 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 
130  virtual bool cullUpdate(const osg::Vec3d& camPos, const osg::Matrixd& viewMatrixI,
131  const Frustum_64& frustum, DtJobSplitter* jobSplitter);
132 
134  virtual void draw(DtWeatherLightning::DrawData& drawData);
135 
139  virtual void setBounds(const DtVector& bounds, float cornerRadius);
140 
144  virtual void setTransform(const osg::Vec3d& position, const osg::Matrixd& rotation);
145 
148  virtual void setIntensity(const float intensity);
149 
152  virtual void setBaseColor(const DtVector& color);
153 
156  virtual void runSort(const osg::Vec3& localCamPos);
157 
160  virtual void setEnabled(bool enabled);
161 
163  virtual bool enabled() const;
164 
167  virtual bool culled() const;
168 
173  virtual void computeBounds(osg::Vec4& bounds, osg::Vec3d& position, osg::Matrixd& rotation) const;
174 
175  protected:
176 
178  struct MeshGroup
179  {
181  : myVboPositionArray(0)
182  , myVboNormalArray(0)
183  , myVboTexCoordArray(0)
184  , myVboIndiceArray(0)
185  , myIndices(0)
186  , myIndicesCount(0)
187  , myActivePointCount(0)
188  {
189  myPoints = new osg::Vec4Array;
190  myNormals = new osg::Vec4Array;
191  myTexCoords = new osg::Vec2Array;
192  }
193 
197  unsigned short* myIndices;
198  unsigned int myIndicesCount;
199  unsigned int myActivePointCount;
200 
201  DtGlBuffer* myVboPositionArray = nullptr;
202  DtGlBuffer* myVboNormalArray = nullptr;
203  DtGlBuffer* myVboTexCoordArray = nullptr;
204  DtGlBuffer* myVboIndiceArray = nullptr;
205  };
206 
209  {
211  : myDirection(1, 0, 0)
212  , myWidthScale(1.0f)
213  , myChildDepth(0)
214  {
215  // intentional noop
216  }
217 
218  osg::Vec3 myDirection;
221  osg::Vec3 myPoints[16];
222  std::vector<LightningFinger*> myChildren;
223  };
224 
227  {
229  : mySortDepth(0)
230  , myUnique(0.0f)
231  , myAliveTime(0)
232  , myTime(0)
233  , myStart(0,0,0)
234  , myEnd(0,0,0)
235  , myLightPosition(0,0,0)
236  , myActiveFingers(0)
237  , myRootFinger(0)
238  , myMeshGroup(0)
239  , myVaoManager(0)
240  , myMeshDirty(false)
241  {
242  // intentional noop
243  }
244 
245  float mySortDepth;
246  float myUnique;
247  float myAliveTime; // amount of time to stay alive
248  float myTime; // amount of time that has passed
249  osg::Vec3 myStart;
250  osg::Vec3 myEnd;
251  osg::Vec3d myLightPosition;
252  LightningFinger myLightningFingerPool[24]; // memory pool
258  };
259 
262  friend struct SortDistanceComparator;
263 
265  {
266  public:
267  bool operator()(const DtWeatherLightning::LightningBolt* lhs, const DtWeatherLightning::LightningBolt* rhs);
268  };
269 
272  virtual void initBoltMeshGroup(LightningBolt* bolt);
273 
277  virtual void createBolt(const osg::Vec3& start, const osg::Vec3& end);
278 
282  virtual void createFingerSegments(LightningBolt* bolt, LightningFinger* finger);
283 
289  virtual bool positionInBounds2D(const float x, const float y, const osg::Vec3& bounds);
290 
294  virtual float computeRandomMinMax(float fMin, float fMax);
295 
298  virtual void computeSortDepth(const osg::Vec3& reference);
299 
303  void fillMeshGroupFlashPoint(LightningBolt* bolt);
304 
309  virtual void fillMeshGroup(LightningBolt* bolt, LightningFinger* finger);
310 
314  virtual bool bindMeshGroupData(MeshGroup* meshGroup, osg::RenderInfo& renderInfo) const;
315 
319  virtual bool bindDynamicMeshGroupData(MeshGroup* meshGroup, osg::RenderInfo& renderInfo) const;
320 
325  virtual bool bindVaoToMeshGroup(GLuint vao, MeshGroup* meshGroup, osg::RenderInfo& renderInfo) const;
326 
330  const osg::Vec3 crossProduct(const osg::Vec3& v0, const osg::Vec3& v1) const;
331 
332  protected:
333 
335  static void theSortJob(void* data);
336 
337  protected:
338 
340  struct SortJobData
341  {
343  : myWeatherLightning(0)
344  , myLocalCameraPos(0, 0, 0)
345  {
346  //intentional nop
347  }
348 
350  osg::Vec3 myLocalCameraPos;
351  };
352 
354 
355  bool myEnabled;
356  bool myCulled;
357 
358  osg::Vec3d myPosition;
359  osg::Matrixd myRotation;
360 
361  float myBoundsX;
362  float myBoundsY;
363  float myBoundsZ;
365 
366  float myBoltWidth;
367  float myIntensity;
368  osg::Vec3 myBaseColor;
369 
370  // These are mutable because they modified during releaseGLObjects.
371  mutable std::vector<LightningBolt*> myMutableLightningBoltsPool; // memory pool
372  mutable std::vector<LightningBolt*> myMutableLightningBoltsActive; // active list
373 
376 
378  unsigned int myRandomSeed;
379 
383 
385  };
386 }
387 
388 
389 
390 
const DtWeatherAreaGroup * myWeatherAreaGroup
Definition: DtWeatherLightning.h:88
float myIntensity
Definition: DtWeatherLightning.h:367
DT_DLL_EXAMPLESCENEROOTPLUGIN void init(DtDe &anIG)
int myActiveFingers
Definition: DtWeatherLightning.h:253
A structure to hold data for a sorting job.
Definition: DtWeatherLightning.h:340
std::vector< LightningFinger * > myChildren
Definition: DtWeatherLightning.h:222
osg::Vec3 myBaseColor
Definition: DtWeatherLightning.h:368
float myBoundsCornerRadius
Definition: DtWeatherLightning.h:364
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:218
osg::Vec3d myCamPos
Definition: DtWeatherLightning.h:84
float myBoltWidth
Definition: DtWeatherLightning.h:366
osg::Vec3d myLightPosition
Definition: DtWeatherLightning.h:251
float myWidthScale
Definition: DtWeatherLightning.h:219
osg::Vec3 myEnd
Definition: DtWeatherLightning.h:250
bool myMeshDirty
Definition: DtWeatherLightning.h:257
#define DT_DLL_VRVOSG
Definition: vrvOsg.h:23
osg::ref_ptr< osg::Vec2Array > myTexCoords
Definition: DtWeatherLightning.h:196
std::vector< LightningBolt * > myMutableLightningBoltsActive
Definition: DtWeatherLightning.h:372
MeshGroup()
Definition: DtWeatherLightning.h:180
LightningBolt()
Definition: DtWeatherLightning.h:228
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:349
A structure used to define a lightning bolt.
Definition: DtWeatherLightning.h:226
A group node which serves as a root for weather areas, patchy ground fog areas and effects...
Definition: DtWeatherAreaGroup.h:75
DtDe & myDe
Definition: DtWeatherLightning.h:353
unsigned int myIndicesCount
Definition: DtWeatherLightning.h:198
DtVirtualBaseClassCreator< DtWeatherLightning > DtWeatherLightningCreator
creator
Definition: DtWeatherLightning.h:48
osg::Matrixd myViewMatrix
Definition: DtWeatherLightning.h:85
float myStrikeTimer
Definition: DtWeatherLightning.h:382
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:363
Variadic templated creator class for defining a DtVirtualBaseClass creator that is automatically regi...
Definition: DtVirtualBaseClassCreator.h:22
A structure used to define a lightning bolt finger.
Definition: DtWeatherLightning.h:208
osg::RenderInfo * myRenderInfo
Definition: DtWeatherLightning.h:83
float myBoundsX
Definition: DtWeatherLightning.h:361
Contains makVrv::DtRandomNumberGenerator class.
osg::ref_ptr< osg::Vec4Array > myPoints
Definition: DtWeatherLightning.h:194
unsigned int myActivePointCount
Definition: DtWeatherLightning.h:199
Contains makVrv::DtJobSplitter class.
osg::ref_ptr< osg::Vec4Array > myNormals
Definition: DtWeatherLightning.h:195
DtGlVaoManager * myVaoManager
Definition: DtWeatherLightning.h:256
osg::StateSet * myState
Definition: DtWeatherLightning.h:89
float myTime
Definition: DtWeatherLightning.h:248
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:249
DrawData()
Definition: DtWeatherLightning.h:72
DtLight * myLight
Definition: DtWeatherLightning.h:384
osg::Matrixd myRotation
Definition: DtWeatherLightning.h:359
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:178
DtJobSplitterJob mySortJob
Definition: DtWeatherLightning.h:375
Definition: DtWeatherLightning.h:264
DtRandomNumberGenerator myRandomNumberGen
Definition: DtWeatherLightning.h:377
A generic structure to hold data for a job for use with DtJobSplitter.
Definition: DtJobSplitter.h:26
SortJobData()
Definition: DtWeatherLightning.h:342
LightningFinger()
Definition: DtWeatherLightning.h:210
SortJobData mySortJobData
Definition: DtWeatherLightning.h:374
std::vector< LightningBolt * > myMutableLightningBoltsPool
Definition: DtWeatherLightning.h:371
bool myEnabled
Definition: DtWeatherLightning.h:355
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:381
float myBoundsY
Definition: DtWeatherLightning.h:362
osg::Vec3d myPosition
Definition: DtWeatherLightning.h:358
float myUnique
Definition: DtWeatherLightning.h:246
int myChildDepth
Definition: DtWeatherLightning.h:220
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:72
float myStrikeTimeMin
Definition: DtWeatherLightning.h:380
Contains the DtGlVaoManager class declaration.
unsigned short * myIndices
Definition: DtWeatherLightning.h:197
GLint myTransformUnfmLoc
Definition: DtWeatherLightning.h:87
float mySortDepth
Definition: DtWeatherLightning.h:245
bool myCulled
Definition: DtWeatherLightning.h:356
float myAliveTime
Definition: DtWeatherLightning.h:247
MeshGroup * myMeshGroup
Definition: DtWeatherLightning.h:255
LightningFinger * myRootFinger
Definition: DtWeatherLightning.h:254
osg::Vec3 myLocalCameraPos
Definition: DtWeatherLightning.h:350
friend DtWeatherLightningCreator
Definition: DtWeatherLightning.h:92
unsigned int myRandomSeed
Definition: DtWeatherLightning.h:378

Document ID: Generated on Wed Mar 27 22:49:11 EDT 2024 from SVN revision 264633
Copyright © 2005-2024 MAK Technologies. All Rights Reserved (www.mak.com)