VR-Forces 5.0.1 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) 2021 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 #include <vrvOsg/DtGlVaoManager.h>
20 #include <vrvOsg/vrvOsg.h>
21 
22 #include <matrix/vlVector.h>
23 
24 #include <osg/Matrixd>
25 #include <osg/ref_ptr>
26 #include <osg/RenderInfo>
27 #include <osg/State>
28 #include <osg/Vec3d>
29 #include <osg/Vec4d>
30 #include <osg/Array>
31 
32 
33 namespace makVrv
34 {
35  // Forward declarations.
36  class DtGroundFogPatch;
37  class DtJobSplitter;
38  class DtWeatherAreaGroup;
39 
40 
57  {
58  public:
59 
62  enum AreaType
63  {
65  AreaTypeSandstorm
66  };
67 
69  struct DrawData
70  {
72  : myRenderInfo(0)
73  , myCamPos(0, 0, 0)
74  , myGroundFogUnfmLoc(0)
75  , myInstanceParamsUnfmLoc(0)
76  , myInstanceMatrixUnfmLoc(0)
77  , myPatternedUnfmLoc(0)
78  , mySkeletonUnfmLoc(0)
79  , mySoftnessUnfmLoc(0)
80  , myPatternSize(512.0f)
81  , myWindDirectionRad(0)
82  , myWindSpeedMps(0)
83  , myWeatherAreaGroup(0)
84  , myState(0)
85  {
86  // intentional nop
87  }
88 
89  osg::RenderInfo* myRenderInfo;
90  osg::Vec3d myCamPos;
101  osg::StateSet* myState;
102  };
103 
106 
108  virtual ~DtGroundFogPatchArea();
109 
110  private:
111 
114 
117 
119  DtGroundFogPatchArea &operator=(const DtGroundFogPatchArea &other);
120 
121  public:
122 
126  virtual void init(float worldSize, float thickness);
127 
130  virtual void addEffect(DtGroundFogEffect* effect);
131 
133  virtual void releaseFogPatchGLObjects(osg::State* state) const;
134 
136  virtual void releaseFogEffectGLObjects(osg::State* state) const;
137 
142  virtual bool cullUpdate(const osg::Vec3d& camPos, const osg::Matrixd& viewMatrixI, const std::vector<osg::Vec4d>& cullingPlanes, DtJobSplitter* jobSplitter);
143 
145  virtual bool shouldDrawFogPatches();
146 
148  virtual void drawFogPatches(DtGroundFogPatchArea::DrawData& drawData);
149 
151  virtual void drawFogEffects(DtGroundFogEffect::DrawData& drawData);
152 
155  virtual void setDensity(float density);
156 
158  virtual float density() const;
159 
164  virtual void setTransform(const DtVector& position, float orientation, bool relativeToCamera = false);
165 
168  virtual void computeWorldTransform(osg::Vec3d& position, osg::Matrixf& rotation) const;
169 
172  virtual void setEnabled(bool enabled);
173 
175  virtual bool enabled() const;
176 
179  virtual void setClampingEnabled(bool enabled);
180 
182  virtual bool clampingEnabled() const;
183 
185  virtual float worldSize() const;
186 
188  virtual float computeParticleSize() const;
189 
193  virtual void setBounds(const DtVector& bounds, float cornerRadius);
194 
197  virtual bool isPositionAboveArea(const osg::Vec3d& position);
198 
203  virtual void setBaseColor(float red, float green, float blue);
204 
207  virtual void setParticleSizeVariation(float variation);
208 
213  virtual void setPatternedLook(bool patternedEnable);
214 
218  virtual void setAreaType(DtGroundFogPatchArea::AreaType areaType);
219 
222  virtual DtGroundFogPatchArea::AreaType areaType() const;
223 
228  virtual void computeBounds(osg::Vec4& bounds, osg::Vec3d& position, osg::Matrixd& rotation) const;
229 
230  protected:
231 
233  struct MeshGroup
234  {
236  : myVboPositionArray(0)
237  , myVboTexCoords0Array(0)
238  , myVboBonesArray(0)
239  , myVboWeightsArray(0)
240  {
241  myPoints = new osg::Vec3Array;
242  myTexCoords0 = new osg::Vec2Array;
243  myBones = new osg::Vec4Array;
244  myWeights = new osg::Vec4Array;
245  }
246 
251 
252  unsigned int myVboPositionArray;
253  unsigned int myVboTexCoords0Array;
254  unsigned int myVboBonesArray;
255  unsigned int myVboWeightsArray;
256  };
257 
259  struct BoneWeight
260  {
262  : myIndex(0)
263  , myWeight(0)
264  {
265  // intentional nop
266  }
267 
268  int myIndex;
269  double myWeight;
270  };
271 
273  virtual void freeData(void);
274 
281  virtual void computeWeights(float x, float y, float patchSize, float* bones, float* weights);
282 
286  virtual void initLod(int gridSize, float patchSize);
287 
291  virtual bool bindMeshGroupData(MeshGroup* meshGroup, osg::RenderInfo& renderInfo) const;
292 
297  virtual bool bindVaoToMeshGroup(GLuint vao, MeshGroup* meshGroup, osg::RenderInfo& renderInfo) const;
298 
302  virtual void computeBasis(const osg::Vec3d& inGeocentricPos, osg::Matrixd& rotOut);
303 
306  virtual void computeSortDepth(const osg::Vec3& camPos);
307 
312  virtual void inverseTransformPlane(osg::Vec4d& plane, const osg::Vec3d& position, const osg::Matrixd& rotation);
313 
318  virtual bool isSphereVisible(const std::vector<osg::Vec4d>& planes, const osg::Vec3d& center, double radius);
319 
321  virtual void computeBoundsCulling();
322 
324  virtual float computeEffectFade(const osg::Vec3& localCam);
325 
327  virtual double clampDistance() const;
328 
331  virtual bool clampPosition(osg::Vec3d& position);
332 
334  virtual float computePatchCellSize() const;
335 
337  static int theSortWeights(const void* arg0, const void* arg1);
338 
340  static int theSortBackToFront(const void* arg0, const void* arg1);
341 
342  protected:
343 
345 
346  float myDensity;
347  bool myEnabled;
348 
349  float myWindU; // current pattern texture U offset for wind
350  float myWindV; // current pattern texture V offset for wind
351  double myLastWindTime; // last time wind was computed
352 
353  bool myCameraBasisDirty; // true if the basis needs computed from the camera
358  float myMaxClampOffset; // the maximum computed abs(clamp offset)
359 
360  float myBaseColorR; // the red component of the base color
361  float myBaseColorG; // the green component of the base color
362  float myBaseColorB; // the blue component of the base color
363 
364  float myParticleSizeVariation; // particle size variation
365  // base size + random(-myParticleSizeVariation, myParticleSizeVariation) * base size
366 
367  float myPatternedLook; // (-1 or 1) passed to shader to indicate patterned look or not
369 
372 
373  osg::Vec3d myPosition;
375  osg::Vec3d myBasisPos;
376  osg::Matrixd myBasisRot;
377 
378  float myBoundsX;
379  float myBoundsY;
381 
382  static const double DT_GFP_CLAMP_DISTANCE; // the skeletal terrain clamping distance (affects culling too)
383  static const int DT_GFP_CELL_SIZE; // the number of cells in 1 row of a patch
384 
385  int myGridSize; // the number of patches in 1 row of a ground fog system
386  float myPatchWorldSize; // the world size of a patch: dimensions are (myPatchWorldSize x myPatchWorldSize x patchWorldHeight)
387  std::vector<DtGroundFogPatch*> myPatches;
388  int myPatchCount; // the total number of patches (myGridSize x myGridSize)
389  DtGroundFogPatch** myRenderPatches; // pointer to dynamically allocated array of pointers used for draw queue
391 
392  std::vector<DtGroundFogEffect*> myEffects;
393  };
394 
395 
398  {
399  public:
402 
404  virtual ~DtGroundFogPatchAreaCreator();
405 
406  private:
411 
412  public:
416  virtual DtGroundFogPatchArea* create(float worldSize, float thickness) const;
417 
420  static DtGroundFogPatchAreaCreator& instance(DtDe& de);
421 
423  static const std::string& theClassName();
424 
425  protected:
427  };
428 }
429 
430 
431 
DT_DLL_EXAMPLESCENEROOTPLUGIN void init(DtDe &anIG)
int myIndex
Definition: DtGroundFogPatchArea.h:268
Virtual base class. Allows for RTTI and proper virtual destruction. Used by Creators, Factories, Providers, Assemblers and User Interfaces.
Definition: DtVirtualBaseClass.h:19
A structure used to hold data for drawing.
Definition: DtGroundFogEffect.h:41
DtGroundFogPatch ** myRenderPatches
Definition: DtGroundFogPatchArea.h:389
float myPatchWorldSize
Definition: DtGroundFogPatchArea.h:386
bool myEnabled
Definition: DtGroundFogPatchArea.h:347
#define DT_DLL_VRVOSG
Definition: vrvOsg.h:23
DtDe & myDe
Definition: DtGroundFogPatchArea.h:344
osg::RenderInfo * myRenderInfo
Definition: DtGroundFogPatchArea.h:89
double myLastWindTime
Definition: DtGroundFogPatchArea.h:351
osg::ref_ptr< osg::Vec4Array > myBones
Definition: DtGroundFogPatchArea.h:249
creator for DtGroundFogPatchArea
Definition: DtGroundFogPatchArea.h:397
unsigned int GLuint
Definition: DtGlTextureBufferObject.h:17
float myBoundsX
Definition: DtGroundFogPatchArea.h:378
Contains makVrv::DtDe class.
this class is used to split work up between threads.
Definition: DtJobSplitter.h:64
float myBaseColorR
Definition: DtGroundFogPatchArea.h:360
double myWeight
Definition: DtGroundFogPatchArea.h:269
GLint myPatternedUnfmLoc
Definition: DtGroundFogPatchArea.h:94
Definition: DtGroundFogPatchArea.h:64
DrawData()
Definition: DtGroundFogPatchArea.h:71
BoneWeight()
Definition: DtGroundFogPatchArea.h:261
A group node which serves as a root for weather areas, patchy ground fog areas and effects...
Definition: DtWeatherAreaGroup.h:72
GLint myGroundFogUnfmLoc
Definition: DtGroundFogPatchArea.h:91
MeshGroup()
Definition: DtGroundFogPatchArea.h:235
DtDe & myDe
Definition: DtGroundFogPatchArea.h:426
std::vector< DtGroundFogEffect * > myEffects
Definition: DtGroundFogPatchArea.h:392
int myClampBoneIndex
Definition: DtGroundFogPatchArea.h:357
osg::Vec3d myCamPos
Definition: DtGroundFogPatchArea.h:90
this class is used to create an effect around the eye to represent blowing particle effects such as s...
Definition: DtGroundFogEffect.h:36
std::vector< DtGroundFogPatch * > myPatches
Definition: DtGroundFogPatchArea.h:387
DtGlVaoManager * myVaoManager
Definition: DtGroundFogPatchArea.h:371
static const double DT_GFP_CLAMP_DISTANCE
Definition: DtGroundFogPatchArea.h:382
osg::Vec3d myBasisPos
Definition: DtGroundFogPatchArea.h:375
float myMaxClampOffset
Definition: DtGroundFogPatchArea.h:358
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
unsigned int myVboTexCoords0Array
Definition: DtGroundFogPatchArea.h:253
Contains makVrv::DtOsgCullVisitor class.
float myWindV
Definition: DtGroundFogPatchArea.h:350
unsigned int myVboWeightsArray
Definition: DtGroundFogPatchArea.h:255
GLint mySoftnessUnfmLoc
Definition: DtGroundFogPatchArea.h:96
bool myCameraBasisDirty
Definition: DtGroundFogPatchArea.h:353
int myRenderPatchCount
Definition: DtGroundFogPatchArea.h:390
float myPatternSize
Definition: DtGroundFogPatchArea.h:97
unsigned int myVboBonesArray
Definition: DtGroundFogPatchArea.h:254
float myPatternedLook
Definition: DtGroundFogPatchArea.h:367
float myParticleSizeVariation
Definition: DtGroundFogPatchArea.h:364
float myWindU
Definition: DtGroundFogPatchArea.h:349
bool myInitialized
Definition: DtGroundFogPatchArea.h:354
float myWindDirectionRad
Definition: DtGroundFogPatchArea.h:98
A structure used to define a mesh group (voa, positions, coords).
Definition: DtGroundFogPatchArea.h:233
float myBaseColorB
Definition: DtGroundFogPatchArea.h:362
AreaType
brief Area type enumerations. Area types help with descibing the area for items like sensors...
Definition: DtGroundFogPatchArea.h:62
GLint myInstanceParamsUnfmLoc
Definition: DtGroundFogPatchArea.h:92
float myBaseColorG
Definition: DtGroundFogPatchArea.h:361
An area of ground fog patch items and effects. One ground fog patch area is associated with a non-inf...
Definition: DtGroundFogPatchArea.h:56
bool myClampingEnabled
Definition: DtGroundFogPatchArea.h:355
float myWindSpeedMps
Definition: DtGroundFogPatchArea.h:99
float myOrientation
Definition: DtGroundFogPatchArea.h:374
osg::ref_ptr< osg::Vec4Array > myWeights
Definition: DtGroundFogPatchArea.h:250
int myGridSize
Definition: DtGroundFogPatchArea.h:385
GLint myInstanceMatrixUnfmLoc
Definition: DtGroundFogPatchArea.h:93
This class is used to manage an opengl vertex array object (VAO) dealing with multiple opengl context...
Definition: DtGlVaoManager.h:65
float myBoundsCornerRadius
Definition: DtGroundFogPatchArea.h:380
int myClampIndex
Definition: DtGroundFogPatchArea.h:356
Contains makVrv::DtGroundFogEffect class.
Contains DLL export macros.
float myDensity
Definition: DtGroundFogPatchArea.h:346
osg::ref_ptr< osg::Vec3Array > myPoints
Definition: DtGroundFogPatchArea.h:247
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:70
MeshGroup * myMeshGroup
Definition: DtGroundFogPatchArea.h:370
GLint mySkeletonUnfmLoc
Definition: DtGroundFogPatchArea.h:95
unsigned int myVboPositionArray
Definition: DtGroundFogPatchArea.h:252
osg::StateSet * myState
Definition: DtGroundFogPatchArea.h:101
Contains the DtGlVaoManager class declaration.
int myPatchCount
Definition: DtGroundFogPatchArea.h:388
float myBoundsY
Definition: DtGroundFogPatchArea.h:379
const DtWeatherAreaGroup * myWeatherAreaGroup
Definition: DtGroundFogPatchArea.h:100
osg::Matrixd myBasisRot
Definition: DtGroundFogPatchArea.h:376
A structure used to hold data for drawing.
Definition: DtGroundFogPatchArea.h:69
osg::Vec3d myPosition
Definition: DtGroundFogPatchArea.h:373
AreaType myAreaType
Definition: DtGroundFogPatchArea.h:368
osg::ref_ptr< osg::Vec2Array > myTexCoords0
Definition: DtGroundFogPatchArea.h:248
static const int DT_GFP_CELL_SIZE
Definition: DtGroundFogPatchArea.h:383
A structure used to define a skeleton bone weight.
Definition: DtGroundFogPatchArea.h:259

Document ID: Generated on Mon Jun 20 00:38:30 EDT 2022 from SVN revision 244029
Copyright © 2005-2021 MAK Technologies. All Rights Reserved (www.mak.com)