VR-Forces Developer's Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
DtGroundFogPatchArea.h
Go to the documentation of this file.
1 /******************************************************************************
2 ** Copyright (c) 2026 MAK Technologies, Inc.
3 ** All rights reserved.
4 ******************************************************************************/
5 
9 
10 #pragma once
11 
12 #include <osg/Camera>
13 #include <osg/Drawable>
14 
15 #include <vrvCore/DtDe.h>
16 
18 
20 #include <vrvOsg/DtGlVaoManager.h>
22 #include <vrvOsg/vrvOsg.h>
23 
25 
26 #include <matrix/vlVector.h>
27 
28 #include <osg/Matrixd>
29 #include <osg/ref_ptr>
30 #include <osg/RenderInfo>
31 #include <osg/State>
32 #include <osg/Vec3d>
33 #include <osg/Vec4d>
34 #include <osg/Array>
35 
36 
37 namespace makVrv
38 {
39  // Forward declarations.
40  class DtGroundFogPatch;
41  class DtJobSplitter;
42  class DtWeatherAreaGroup;
43  class DtGlBuffer;
44 
47 
50 
52  template <>
53  inline const char* creatorTypeName<DtGroundFogPatchArea>(void) { return "DtGroundFogPatchAreaCreator"; }
54 
55 
72  {
73  public:
74 
77  enum AreaType
78  {
80  AreaTypeSandstorm
81  };
82 
84  struct DrawData
85  {
87  : myRenderInfo(0)
88  , myCamPos(0, 0, 0)
89  , myGroundFogUnfmLoc(0)
90  , myInstanceParamsUnfmLoc(0)
91  , myInstanceMatrixUnfmLoc(0)
92  , myPatternedUnfmLoc(0)
93  , mySkeletonUnfmLoc(0)
94  , mySoftnessUnfmLoc(0)
95  , myPatternSize(512.0f)
96  , myWeatherAreaGroup(0)
97  , myState(0)
98  {
99  // intentional nop
100  }
101 
102  osg::RenderInfo* myRenderInfo;
103  osg::Vec3d myCamPos;
112  osg::StateSet* myState;
113  };
114 
116  DtGroundFogPatchArea(makVrv::DtDe& de, const float& worldSize, const float& thickness);
117 
119  virtual ~DtGroundFogPatchArea();
120 
121  private:
122 
125 
128 
130  DtGroundFogPatchArea &operator=(const DtGroundFogPatchArea &other);
131 
132  public:
133 
137  virtual void init(float worldSize, float thickness);
138 
141  virtual void addEffect(DtGroundFogEffect* effect);
142 
144  virtual void releaseFogPatchGLObjects(osg::State* state) const;
145 
147  virtual void releaseFogEffectGLObjects(osg::State* state) const;
148 
155  virtual bool cullUpdate(const osg::Vec3d& camPos, const osg::Matrixd& viewMatrixI,
156  const Frustum_64& frustum, DtJobSplitter* jobSplitter);
157 
159  virtual bool shouldDrawFogPatches();
160 
162  virtual void drawFogPatches(DtGroundFogPatchArea::DrawData& drawData);
163 
165  virtual void drawFogEffects(DtGroundFogEffect::DrawData& drawData);
166 
169  virtual void setDensity(float density);
170 
172  virtual float density() const;
173 
177  virtual void setWind(const float windDirectionRad, const float windSpeedMps);
178 
183  virtual void setTransform(const DtVector& position, float orientation, bool relativeToCamera = false);
184 
187  virtual void computeWorldTransform(osg::Vec3d& position, osg::Matrixf& rotation) const;
188 
191  virtual void setEnabled(bool enabled);
192 
194  virtual bool enabled() const;
195 
198  virtual void setClampingEnabled(bool enabled);
199 
201  virtual bool clampingEnabled() const;
202 
204  virtual float worldSize() const;
205 
207  virtual float computeParticleSize() const;
208 
212  virtual void setBounds(const DtVector& bounds, float cornerRadius);
213 
216  virtual bool isPositionAboveArea(const osg::Vec3d& position);
217 
222  virtual void setBaseColor(float red, float green, float blue);
223 
226  virtual void setParticleSizeVariation(float variation);
227 
232  virtual void setPatternedLook(bool patternedEnable);
233 
237  virtual void setAreaType(DtGroundFogPatchArea::AreaType areaType);
238 
241  virtual DtGroundFogPatchArea::AreaType areaType() const;
242 
247  virtual void computeBounds(osg::Vec4& bounds, osg::Vec3d& position, osg::Matrixd& rotation) const;
248 
249  protected:
250 
252  struct MeshGroup
253  {
255  : myVboPositionArray(0)
256  , myVboTexCoords0Array(0)
257  , myVboBonesArray(0)
258  , myVboWeightsArray(0)
259  {
260  myPoints = new osg::Vec3Array;
261  myTexCoords0 = new osg::Vec2Array;
262  myBones = new osg::Vec4Array;
263  myWeights = new osg::Vec4Array;
264  }
265 
270 
271  DtGlBuffer* myVboPositionArray = nullptr;
272  DtGlBuffer* myVboTexCoords0Array = nullptr;
273  DtGlBuffer* myVboBonesArray = nullptr;
274  DtGlBuffer* myVboWeightsArray = nullptr;
275  };
276 
278  struct BoneWeight
279  {
281  : myIndex(0)
282  , myWeight(0)
283  {
284  // intentional nop
285  }
286 
287  int myIndex;
288  double myWeight;
289  };
290 
292  virtual void freeData(void);
293 
300  virtual void computeWeights(float x, float y, float patchSize, float* bones, float* weights);
301 
305  virtual void initLod(int gridSize, float patchSize);
306 
310  virtual bool bindMeshGroupData(MeshGroup* meshGroup, osg::RenderInfo& renderInfo) const;
311 
316  virtual bool bindVaoToMeshGroup(GLuint vao, MeshGroup* meshGroup, osg::RenderInfo& renderInfo) const;
317 
320  virtual void computeSortDepth(const osg::Vec3& camPos);
321 
326  virtual void inverseTransformPlane(osg::Vec4d& plane, const osg::Vec3d& position, const osg::Matrixd& rotation);
327 
332  virtual bool isSphereVisible(const std::vector<osg::Vec4d>& planes, const osg::Vec3d& center, double radius);
333 
335  virtual void computeBoundsCulling();
336 
338  virtual float computeEffectFade(const osg::Vec3& localCam);
339 
341  virtual double clampDistance() const;
342 
345  virtual bool clampPosition(osg::Vec3d& position);
346 
348  virtual float computePatchCellSize() const;
349 
351  static int theSortWeights(const void* arg0, const void* arg1);
352 
354  static int theSortBackToFront(const void* arg0, const void* arg1);
355 
356  protected:
357 
359 
360  float myDensity;
361  bool myEnabled;
362 
365 
366  float myWindU; // current pattern texture U offset for wind
367  float myWindV; // current pattern texture V offset for wind
368  double myLastWindTime; // last time wind was computed
369 
370  bool myCameraBasisDirty; // true if the basis needs computed from the camera
375  float myMaxClampOffset; // the maximum computed abs(clamp offset)
376 
377  float myBaseColorR; // the red component of the base color
378  float myBaseColorG; // the green component of the base color
379  float myBaseColorB; // the blue component of the base color
380 
381  float myParticleSizeVariation; // particle size variation
382  // base size + random(-myParticleSizeVariation, myParticleSizeVariation) * base size
383 
384  float myPatternedLook; // (-1 or 1) passed to shader to indicate patterned look or not
386 
389 
390  osg::Vec3d myPosition;
392  osg::Vec3d myBasisPos;
393  osg::Matrixd myBasisRot;
394 
395  float myBoundsX;
396  float myBoundsY;
398 
399  static const double DT_GFP_CLAMP_DISTANCE; // the skeletal terrain clamping distance (affects culling too)
400  static const int DT_GFP_CELL_SIZE; // the number of cells in 1 row of a patch
401 
402  int myGridSize; // the number of patches in 1 row of a ground fog system
403  float myPatchWorldSize; // the world size of a patch: dimensions are (myPatchWorldSize x myPatchWorldSize x patchWorldHeight)
404  std::vector<DtGroundFogPatch*> myPatches;
405  int myPatchCount; // the total number of patches (myGridSize x myGridSize)
406  DtGroundFogPatch** myRenderPatches; // pointer to dynamically allocated array of pointers used for draw queue
408 
409  std::vector<DtGroundFogEffect*> myEffects;
410  };
411 }
DT_DLL_EXAMPLESCENEROOTPLUGIN void init(DtDe &anIG)
int myIndex
Definition: DtGroundFogPatchArea.h:287
const char * creatorTypeName< DtGroundFogPatchArea >(void)
template specialization for the creator (pass the class being created to the creatorTypeName template...
Definition: DtGroundFogPatchArea.h:53
A structure used to hold data for drawing.
Definition: DtGroundFogEffect.h:53
DtGroundFogPatch ** myRenderPatches
Definition: DtGroundFogPatchArea.h:406
float myPatchWorldSize
Definition: DtGroundFogPatchArea.h:403
bool myEnabled
Definition: DtGroundFogPatchArea.h:361
#define DT_DLL_VRVOSG
Definition: vrvOsg.h:23
DtDe & myDe
Definition: DtGroundFogPatchArea.h:358
osg::RenderInfo * myRenderInfo
Definition: DtGroundFogPatchArea.h:102
double myLastWindTime
Definition: DtGroundFogPatchArea.h:368
osg::ref_ptr< osg::Vec4Array > myBones
Definition: DtGroundFogPatchArea.h:268
unsigned int GLuint
Definition: DtGlTextureBufferObject.h:18
float myBoundsX
Definition: DtGroundFogPatchArea.h:395
Contains makVrv::DtDe class.
this class is used to split work up between threads.
Definition: DtJobSplitter.h:64
float myBaseColorR
Definition: DtGroundFogPatchArea.h:377
double myWeight
Definition: DtGroundFogPatchArea.h:288
GLint myPatternedUnfmLoc
Definition: DtGroundFogPatchArea.h:107
Definition: DtGroundFogPatchArea.h:79
DrawData()
Definition: DtGroundFogPatchArea.h:86
BoneWeight()
Definition: DtGroundFogPatchArea.h:280
A group node which serves as a root for weather areas, patchy ground fog areas and effects...
Definition: DtWeatherAreaGroup.h:76
DtVirtualBaseClassCreator< DtGroundFogPatchArea, const float &, const float & > DtGroundFogPatchAreaCreator
creator
Definition: DtGroundFogPatchArea.h:46
GLint myGroundFogUnfmLoc
Definition: DtGroundFogPatchArea.h:104
MeshGroup()
Definition: DtGroundFogPatchArea.h:254
Camera forward declarations.
std::vector< DtGroundFogEffect * > myEffects
Definition: DtGroundFogPatchArea.h:409
int myClampBoneIndex
Definition: DtGroundFogPatchArea.h:374
osg::Vec3d myCamPos
Definition: DtGroundFogPatchArea.h:103
this class is used to create an effect around the eye to represent blowing particle effects such as s...
Definition: DtGroundFogEffect.h:48
std::vector< DtGroundFogPatch * > myPatches
Definition: DtGroundFogPatchArea.h:404
DtGlVaoManager * myVaoManager
Definition: DtGroundFogPatchArea.h:388
float myWindSpeedMps
Definition: DtGroundFogPatchArea.h:364
static const double DT_GFP_CLAMP_DISTANCE
Definition: DtGroundFogPatchArea.h:399
osg::Vec3d myBasisPos
Definition: DtGroundFogPatchArea.h:392
Variadic templated creator class for defining a DtVirtualBaseClass creator that is automatically regi...
Definition: DtVirtualBaseClassCreator.h:23
float myMaxClampOffset
Definition: DtGroundFogPatchArea.h:375
an object used to represent 1 patch of a patchy ground fog system. The patch is made up of cells in a...
Definition: DtGroundFogPatch.h:33
Contains makVrv::DtOsgCullVisitor class.
float myWindV
Definition: DtGroundFogPatchArea.h:367
GLint mySoftnessUnfmLoc
Definition: DtGroundFogPatchArea.h:109
bool myCameraBasisDirty
Definition: DtGroundFogPatchArea.h:370
int myRenderPatchCount
Definition: DtGroundFogPatchArea.h:407
float myPatternSize
Definition: DtGroundFogPatchArea.h:110
float myPatternedLook
Definition: DtGroundFogPatchArea.h:384
float myParticleSizeVariation
Definition: DtGroundFogPatchArea.h:381
float myWindU
Definition: DtGroundFogPatchArea.h:366
bool myInitialized
Definition: DtGroundFogPatchArea.h:371
A structure used to define a mesh group (voa, positions, coords).
Definition: DtGroundFogPatchArea.h:252
float myBaseColorB
Definition: DtGroundFogPatchArea.h:379
AreaType
brief Area type enumerations. Area types help with descibing the area for items like sensors...
Definition: DtGroundFogPatchArea.h:77
GLint myInstanceParamsUnfmLoc
Definition: DtGroundFogPatchArea.h:105
float myBaseColorG
Definition: DtGroundFogPatchArea.h:378
An area of ground fog patch items and effects. One ground fog patch area is associated with a non-inf...
Definition: DtGroundFogPatchArea.h:71
bool myClampingEnabled
Definition: DtGroundFogPatchArea.h:372
A generic OpenGL buffer. This can be: -&gt; a vertex buffer -&gt; an index buffer -&gt; a shader storage buffe...
Definition: DtGlBuffer.h:29
float myWindDirectionRad
Definition: DtGroundFogPatchArea.h:363
float myOrientation
Definition: DtGroundFogPatchArea.h:391
osg::ref_ptr< osg::Vec4Array > myWeights
Definition: DtGroundFogPatchArea.h:269
int myGridSize
Definition: DtGroundFogPatchArea.h:402
GLint myInstanceMatrixUnfmLoc
Definition: DtGroundFogPatchArea.h:106
This class is used to manage an opengl vertex array object (VAO) dealing with multiple opengl context...
Definition: DtGlVaoManager.h:58
float myBoundsCornerRadius
Definition: DtGroundFogPatchArea.h:397
int myClampIndex
Definition: DtGroundFogPatchArea.h:373
Contains makVrv::DtGroundFogEffect class.
Contains DLL export macros.
float myDensity
Definition: DtGroundFogPatchArea.h:360
osg::ref_ptr< osg::Vec3Array > myPoints
Definition: DtGroundFogPatchArea.h:266
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
MeshGroup * myMeshGroup
Definition: DtGroundFogPatchArea.h:387
GLint mySkeletonUnfmLoc
Definition: DtGroundFogPatchArea.h:108
osg::StateSet * myState
Definition: DtGroundFogPatchArea.h:112
Contains the DtGlVaoManager class declaration.
int myPatchCount
Definition: DtGroundFogPatchArea.h:405
float myBoundsY
Definition: DtGroundFogPatchArea.h:396
const DtWeatherAreaGroup * myWeatherAreaGroup
Definition: DtGroundFogPatchArea.h:111
osg::Matrixd myBasisRot
Definition: DtGroundFogPatchArea.h:393
A structure used to hold data for drawing.
Definition: DtGroundFogPatchArea.h:84
osg::Vec3d myPosition
Definition: DtGroundFogPatchArea.h:390
AreaType myAreaType
Definition: DtGroundFogPatchArea.h:385
osg::ref_ptr< osg::Vec2Array > myTexCoords0
Definition: DtGroundFogPatchArea.h:267
static const int DT_GFP_CELL_SIZE
Definition: DtGroundFogPatchArea.h:400
A structure used to define a skeleton bone weight.
Definition: DtGroundFogPatchArea.h:278

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)