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) 2023 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  , myWindDirectionRad(0)
97  , myWindSpeedMps(0)
98  , myWeatherAreaGroup(0)
99  , myState(0)
100  {
101  // intentional nop
102  }
103 
104  osg::RenderInfo* myRenderInfo;
105  osg::Vec3d myCamPos;
116  osg::StateSet* myState;
117  };
118 
120  DtGroundFogPatchArea(makVrv::DtDe& de, const float& worldSize, const float& thickness);
121 
123  virtual ~DtGroundFogPatchArea();
124 
125  private:
126 
129 
132 
134  DtGroundFogPatchArea &operator=(const DtGroundFogPatchArea &other);
135 
136  public:
137 
141  virtual void init(float worldSize, float thickness);
142 
145  virtual void addEffect(DtGroundFogEffect* effect);
146 
148  virtual void releaseFogPatchGLObjects(osg::State* state) const;
149 
151  virtual void releaseFogEffectGLObjects(osg::State* state) const;
152 
158  virtual bool cullUpdate(const osg::Vec3d& camPos, const osg::Matrixd& viewMatrixI,
159  const Frustum_64& frustum, DtJobSplitter* jobSplitter);
160 
162  virtual bool shouldDrawFogPatches();
163 
165  virtual void drawFogPatches(DtGroundFogPatchArea::DrawData& drawData);
166 
168  virtual void drawFogEffects(DtGroundFogEffect::DrawData& drawData);
169 
172  virtual void setDensity(float density);
173 
175  virtual float density() const;
176 
181  virtual void setTransform(const DtVector& position, float orientation, bool relativeToCamera = false);
182 
185  virtual void computeWorldTransform(osg::Vec3d& position, osg::Matrixf& rotation) const;
186 
189  virtual void setEnabled(bool enabled);
190 
192  virtual bool enabled() const;
193 
196  virtual void setClampingEnabled(bool enabled);
197 
199  virtual bool clampingEnabled() const;
200 
202  virtual float worldSize() const;
203 
205  virtual float computeParticleSize() const;
206 
210  virtual void setBounds(const DtVector& bounds, float cornerRadius);
211 
214  virtual bool isPositionAboveArea(const osg::Vec3d& position);
215 
220  virtual void setBaseColor(float red, float green, float blue);
221 
224  virtual void setParticleSizeVariation(float variation);
225 
230  virtual void setPatternedLook(bool patternedEnable);
231 
235  virtual void setAreaType(DtGroundFogPatchArea::AreaType areaType);
236 
239  virtual DtGroundFogPatchArea::AreaType areaType() const;
240 
245  virtual void computeBounds(osg::Vec4& bounds, osg::Vec3d& position, osg::Matrixd& rotation) const;
246 
247  protected:
248 
250  struct MeshGroup
251  {
253  : myVboPositionArray(0)
254  , myVboTexCoords0Array(0)
255  , myVboBonesArray(0)
256  , myVboWeightsArray(0)
257  {
258  myPoints = new osg::Vec3Array;
259  myTexCoords0 = new osg::Vec2Array;
260  myBones = new osg::Vec4Array;
261  myWeights = new osg::Vec4Array;
262  }
263 
268 
269  DtGlBuffer* myVboPositionArray = nullptr;
270  DtGlBuffer* myVboTexCoords0Array = nullptr;
271  DtGlBuffer* myVboBonesArray = nullptr;
272  DtGlBuffer* myVboWeightsArray = nullptr;
273  };
274 
276  struct BoneWeight
277  {
279  : myIndex(0)
280  , myWeight(0)
281  {
282  // intentional nop
283  }
284 
285  int myIndex;
286  double myWeight;
287  };
288 
290  virtual void freeData(void);
291 
298  virtual void computeWeights(float x, float y, float patchSize, float* bones, float* weights);
299 
303  virtual void initLod(int gridSize, float patchSize);
304 
308  virtual bool bindMeshGroupData(MeshGroup* meshGroup, osg::RenderInfo& renderInfo) const;
309 
314  virtual bool bindVaoToMeshGroup(GLuint vao, MeshGroup* meshGroup, osg::RenderInfo& renderInfo) const;
315 
319  virtual void computeBasis(const osg::Vec3d& inGeocentricPos, osg::Matrixd& rotOut);
320 
323  virtual void computeSortDepth(const osg::Vec3& camPos);
324 
329  virtual void inverseTransformPlane(osg::Vec4d& plane, const osg::Vec3d& position, const osg::Matrixd& rotation);
330 
335  virtual bool isSphereVisible(const std::vector<osg::Vec4d>& planes, const osg::Vec3d& center, double radius);
336 
338  virtual void computeBoundsCulling();
339 
341  virtual float computeEffectFade(const osg::Vec3& localCam);
342 
344  virtual double clampDistance() const;
345 
348  virtual bool clampPosition(osg::Vec3d& position);
349 
351  virtual float computePatchCellSize() const;
352 
354  static int theSortWeights(const void* arg0, const void* arg1);
355 
357  static int theSortBackToFront(const void* arg0, const void* arg1);
358 
359  protected:
360 
362 
363  float myDensity;
364  bool myEnabled;
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:285
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:364
#define DT_DLL_VRVOSG
Definition: vrvOsg.h:23
DtDe & myDe
Definition: DtGroundFogPatchArea.h:361
osg::RenderInfo * myRenderInfo
Definition: DtGroundFogPatchArea.h:104
double myLastWindTime
Definition: DtGroundFogPatchArea.h:368
osg::ref_ptr< osg::Vec4Array > myBones
Definition: DtGroundFogPatchArea.h:266
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:286
GLint myPatternedUnfmLoc
Definition: DtGroundFogPatchArea.h:109
Definition: DtGroundFogPatchArea.h:79
DrawData()
Definition: DtGroundFogPatchArea.h:86
BoneWeight()
Definition: DtGroundFogPatchArea.h:278
A group node which serves as a root for weather areas, patchy ground fog areas and effects...
Definition: DtWeatherAreaGroup.h:75
DtVirtualBaseClassCreator< DtGroundFogPatchArea, const float &, const float & > DtGroundFogPatchAreaCreator
creator
Definition: DtGroundFogPatchArea.h:46
GLint myGroundFogUnfmLoc
Definition: DtGroundFogPatchArea.h:106
MeshGroup()
Definition: DtGroundFogPatchArea.h:252
Camera forward declarations.
std::vector< DtGroundFogEffect * > myEffects
Definition: DtGroundFogPatchArea.h:409
int myClampBoneIndex
Definition: DtGroundFogPatchArea.h:374
osg::Vec3d myCamPos
Definition: DtGroundFogPatchArea.h:105
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
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:111
bool myCameraBasisDirty
Definition: DtGroundFogPatchArea.h:370
int myRenderPatchCount
Definition: DtGroundFogPatchArea.h:407
float myPatternSize
Definition: DtGroundFogPatchArea.h:112
float myPatternedLook
Definition: DtGroundFogPatchArea.h:384
float myParticleSizeVariation
Definition: DtGroundFogPatchArea.h:381
float myWindU
Definition: DtGroundFogPatchArea.h:366
bool myInitialized
Definition: DtGroundFogPatchArea.h:371
float myWindDirectionRad
Definition: DtGroundFogPatchArea.h:113
A structure used to define a mesh group (voa, positions, coords).
Definition: DtGroundFogPatchArea.h:250
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:107
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 myWindSpeedMps
Definition: DtGroundFogPatchArea.h:114
float myOrientation
Definition: DtGroundFogPatchArea.h:391
osg::ref_ptr< osg::Vec4Array > myWeights
Definition: DtGroundFogPatchArea.h:267
int myGridSize
Definition: DtGroundFogPatchArea.h:402
GLint myInstanceMatrixUnfmLoc
Definition: DtGroundFogPatchArea.h:108
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:363
osg::ref_ptr< osg::Vec3Array > myPoints
Definition: DtGroundFogPatchArea.h:264
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:110
osg::StateSet * myState
Definition: DtGroundFogPatchArea.h:116
Contains the DtGlVaoManager class declaration.
int myPatchCount
Definition: DtGroundFogPatchArea.h:405
float myBoundsY
Definition: DtGroundFogPatchArea.h:396
const DtWeatherAreaGroup * myWeatherAreaGroup
Definition: DtGroundFogPatchArea.h:115
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:265
static const int DT_GFP_CELL_SIZE
Definition: DtGroundFogPatchArea.h:400
A structure used to define a skeleton bone weight.
Definition: DtGroundFogPatchArea.h:276

Document ID: Generated on Thu Oct 23 22:29:17 EDT 2025 from SVN revision 280951
Copyright © 2005-2024 MAK Technologies. All Rights Reserved (www.mak.com)