VR-Forces Developer's Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
DtOsgUtils.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/Quat>
13 #include <osg/Texture2DArray>
14 #include <osg/Depth>
15 #include <osg/Camera>
16 #include <osg/MatrixTransform>
17 #include <osg/Geometry>
18 #include <osg/BoundingBox>
19 
20 #include <osgEarth/MapNode>
21 #include <osgEarth/DecalLayer>
22 #include <osgEarth/FeatureSource>
23 
27 
29 
30 #include <set>
31 #include <map>
32 
33 class DtTaitBryan;
34 
35 namespace osgEarth
36 {
37  class MetadataNode;
38 }
39 
40 namespace osg
41 {
42  class TextureBuffer;
43 }
44 
45 namespace makVrv
46 {
47 
48  // see the <mappings> for the decal coverage raster layer
49 #define COVERAGE_MAPPING_VALUE_CRATER 11
50 #define COVERAGE_MAPPING_VALUE_SCRAPE 11
51 #define COVERAGE_MAPPING_VALUE_DITCH 11
52 
53  class DtGlSimpleTexture;
54  class DtDynamicTerrainGeometry;
55  class DtDynamicTerrainChange;
56  class DtDynamicTerrainSphere;
57  class DtIntersector;
58 
61  class DtOsgDebugFrustum : public osg::Referenced
62  {
63  public:
64  DtOsgDebugFrustum(const osg::Vec4 & color);
65  void updateDebugFrustum(osg::Vec3d * frustumVertices);
66 
69  };
70 
72  {
73  public:
75  static osg::Camera* CreateTextureQuadOverlay(DtGlSimpleTexture* texture,
76  float x, float y, float w, float h);
77 
79  static osg::Camera* CreateTextureQuadOverlay(osg::Texture* texture,
80  float x, float y, float w, float h);
81 
83  static osg::Camera* CreateTextureQuadOverlay(const std::string& shader_root, osg::Texture2DArray* textureArray,
84  float x, float y, float w, float h);
85  };
86 
90  {
91  public:
92 
93  // Get values for crater
94  static const std::string CRATER_MAJOR_AXIS;
95  static const std::string CRATER_MINOR_AXIS;
96  static const std::string CRATER_HEADING;
97  static const std::string CRATER_EFFECT_ENUM;
98  static const std::string CRATER_SOIL_TYPE;
99  static const std::string CRATER_DEPTH;
100  static const std::string CRATER_TYPE;
101  static const std::string MODELDEFINITION_PROPS;
102 
103  // static const std::string CRATER_LAND_COVER = "crater-land-cover";
104  static const std::string COMMAND_UID;
105  // Deprecated, but still set (to the same value as CRATER_MAJOR_AXIS)
106  static const std::string CRATER_RADIUS;
107 
108  static const std::string TerrainDamageName;
109  static const std::string TerrainDamageSlight;
110  static const std::string TerrainDamageModerate;
111  static const std::string TerrainDamageDestroyed;
112 
113  // Get values for the tracks (others are in keyValuePairDefinitions.h)
114  static const std::string TRACKS_LINE_WIDTH;
115  static const std::string TRACKS_TERRAIN_TIME;
116 
117  static const std::string EffectMapTextureUniformName;
118  static const std::string EffectMapTextureMatrixUniformName;
119  static const std::string TrackModelDefinitionSchema;
120  static const std::string TrackTypeParameterName;
121  static const std::string TrackSoilTypeParameterName;
122  static const std::string TrackDepthParameterName;
123  static const std::string TrackPointAParameterName;
124  static const std::string TrackPointBParameterName;
125  static const std::string TrackTexureParameterName;
126  static const std::string TrackSegmentSpacingParameterName;
127 
128  // Get values for other terrain deformation (ditch/berm/tank scrape,..)
129  static const std::string TERRAIN_DEFORMATION_ENUM;
130  static const std::string TERRAIN_DEFORMATION_LANDCOVER_OVERRIDE;
131  static const std::string TERRAIN_DEFORMATION_WIDTH;
132  static const std::string TERRAIN_DEFORMATION_HEIGHT;
133  static const std::string TERRAIN_DEFORMATION_RESOLUTION;
134 
136  {
137  DtTerrainDeformationNone = 0,
138  DtTerrainDeformationBerm = 1,
139  DtTerrainDeformationDitch = 2,
140  DtTerrainDeformationTankScrape = 3,
141  DtTerrainDeformationHill = 4
142  };
143 
144  // Used to map from vrfVrlinkExt enum DtTerrainCraterEffectEnum32 which is what's provided
145  // in string form in CRATER_EFFECT_ENUM
147  {
153  };
154 
156  static void makeRotate(osg::Quat& q, const double& angle, const double& x, const double& y, const double& z);
157 
159  static osg::Matrixf toOsgRotation(const DtTaitBryan& orientation);
160 
164  static void quatMult(osg::Quat& lhs, const osg::Quat& rhs);
165 
167  static osg::MatrixTransform * create_axis_primitive();
168 
171 
174  static osg::Matrix getOrthoMatrix(bool useReverseZ, double left, double right,
175  double bottom, double top, double zNear, double zFar);
176 
179  static osg::Matrix getProjMatrix(bool useReverseZ, double left, double right,
180  double bottom, double top, double zNear, double zFar);
181 
183  static osg::Matrixd getRevZOrthoMatrix(double left, double right, double bottom,
184  double top, double zNear, double zFar);
185 
188  static bool getRevZPerspectiveMatrixAsFrustum(const osg::Matrix& mat, double& left,
189  double& right, double& bottom, double& top, double& zNear, double& zFar);
190 
193  static bool getRevZOrthoMatrixAsFrustum(const osg::Matrix& orthoMat, double& left,
194  double& right, double& bottom, double& top, double& zNear, double& zFar);
195 
198  static bool getRevZPerspective(const osg::Matrix& mat, double& fovy,
199  double& aspectRatio, double& zNear, double& zFar);
200 
203  static osg::Matrix makeRevZPerspective(double fovy, double aspectRatio,
204  double zNear, double zFar);
205 
207  static void getYPR(const osg::Matrix& m, double& yaw, double& pitch, double& roll);
208 
210  static void osgPolytopeToFrustum(Frustum_64& frustum, const osg::Polytope& polytope, bool hasNearFar);
211 
215  static void computeTopoBasis(const osg::Vec3d& inGeocentricPos, osg::Matrixd& rotOut);
216 
218  static void debugDumpShaderState(osg::State* state);
219 
221  static void debugDumpUniformState(const osg::Node* node);
222 
224 
225  static osg::Vec2 rotateVec2( const osg::Vec2& v, double rad );
227 
229  static osg::Vec2 translateVec2( const osg::Vec2& v, const osg::Vec2& translation );
230 
232  static osg::Vec2 scaleVec2( const osg::Vec2& v, double s );
233 
235  static osg::Vec2 scaleVec2( const osg::Vec2& v, double xScale, double yScale );
237 
239  static bool clipLine( double xMin, double xMax, double yMin, double yMax,
240  double x0src, double y0src, double x1src, double y1src,
241  double &x0clip, double &y0clip, double &x1clip, double &y1clip );
242 
244  static void clipPolygon( double xMin, double xMax, double yMin, double yMax,
245  std::vector<osg::Vec2>& vertices );
246 
247  // Adapted from VR-Link DtModPerLo [matrix/modper.cxx]
248  template <class VecType> static VecType DtModPerLoVec3( const VecType& in, double min, double max )
249  {
250  VecType result;
251  double per = max - min;
252 
253  for( int i = 0; i < 3; ++i )
254  {
255  if( min <= in[i] && in[i] < max )
256  {
257  result[i] = in[i];
258  }
259  else
260  {
261  result[i] = fmod( in[i] - min, per );
262 
263  if( result[i] < 0.0 )
264  {
265  result[i] += per;
266  }
267 
268  result[i] += min;
269  }
270  }
271  return result;
272  }
273 
280  static bool insideTriangulate( const std::vector<osg::Vec2>& contour, std::vector<int>& results );
281 
282  static osg::Matrixd calculateRevZProjectionMatrix(double left, double right
283  , double bottom, double top
284  , double zNear, double zFar);
285 
286  static osg::Matrixd calculateOrthoMatrix(double left, double right
287  , double bottom, double top
288  , double zNear, double zFar);
289 
290  static osg::Matrixd calculateRevZProjectionMatrixWithRevZAsNegativeOneForRttCamera(double left, double right
291  , double bottom, double top
292  , double zNear, double zFar);
293 
295  static void dynamicTerrainLineToFeature(const DtDynamicTerrainLine* line, osgEarth::Feature* feature,
297 
298  static void dumpCommandValues(const DtDynamicTerrainChange& command);
299 
304  {
305  public:
306  OSMBuildingInfo(osgEarth::MetadataNode* metadataNode, const std::set<int>& objectIndexList) :
307  myMetadataNode(metadataNode),
308  myObjectIndexList(objectIndexList)
309  {
310  }
311 
312  osgEarth::MetadataNode* myMetadataNode;
314  std::set<int> myObjectIndexList;
315  };
316 
318  typedef std::map<osgEarth::MetadataNode*, DtOsgUtils::OSMBuildingInfo> MetadaNodeMap;
319 
321  typedef std::map<std::string, DtOsgUtils::MetadaNodeMap> ChangeIdMetadaNodeMap;
322 
325  {
326  public:
327  FidMetadataNode(long long FID, osgEarth::MetadataNode* metadataNode, int objectIndex):
328  myFID(FID),
329  myMetadataNode(metadataNode),
330  myObjectIndex(objectIndex)
331  {
332  }
333  long long myFID;
334  osgEarth::MetadataNode* myMetadataNode;
336  };
337 
339  typedef std::map<long long, osg::BoundingBoxd> Fid2DebrisMapType;
340 
342  {
343  DebrisPositionStruct(const DtVector& position, const std::string& modelDefinition):
344  myPosition(position),
345  myModelDefinition(modelDefinition)
346  {
347  }
348 
349  DtVector myPosition;
350  std::string myModelDefinition;
351  };
352 
354  typedef std::vector<DebrisPositionStruct> DebrisPositionListType;
355 
357  static void getGeometriesFID(osg::ref_ptr<osgEarth::MapNode> mapNode, const makVrv::DtDynamicTerrainSphere* sphere, std::set<long long>& OsmFidList, DtOsgUtils::Fid2DebrisMapType* fid2DebrisMap);
358 
361  static void hideGeometries(osg::ref_ptr<osgEarth::MapNode> mapNode, osg::BoundingSphere bs, const std::set<long long>& FidList, std::vector<DtOsgUtils::FidMetadataNode>& dataList);
362 
365  static void showGeometries(osg::ref_ptr<osgEarth::MapNode> mapNode, osg::BoundingSphere bs, const std::set<long long>& FidList);
366 
368  static void getDebrisModels(DtDe* de, const DtOsgUtils::Fid2DebrisMapType& fid2DebrisMap, DtOsgUtils::DebrisPositionListType& debrisPositionList, DtIntersector* intersector = nullptr);
369 
373  static bool isCraterStateSphereValid(const DtDynamicTerrainChange& command);
374 
378  static bool addCraterState(
379  const DtDynamicTerrainChange& command,
381  DtDynamicTerrainRasterLibrary* rasterLibrary,
382  osg::ref_ptr<osgEarth::LandCoverDictionary> landCoverDictionary_Splat,
387  osg::ref_ptr<osgEarth::Contrib::DecalImageLayer> decalCoverageRasterLayer,
388  unsigned coverageMappingValue,
389  std::string& info,
390  std::string& warn,
391  osgEarth::GeoExtent& out_feature_extent,
392  std::string& craterModelDefinition,
393  int minInvalidateLod = -1);
394 
398  static bool addLinearStateDeformation(
399  const DtDynamicTerrainChange& command,
401  DtDynamicTerrainRasterLibrary* rasterLibrary,
402  osg::ref_ptr<osgEarth::LandCoverDictionary> landCoverDictionary_Splat,
407  osg::ref_ptr<osgEarth::Contrib::DecalImageLayer> decalCoverageRasterLayer,
408  unsigned coverageMappingValue,
409  std::string& info,
410  std::string& warn,
411  osgEarth::GeoExtent& out_feature_extent);
412 
416  static bool addTankScrapeState(
417  const DtDynamicTerrainChange& command,
419  DtDynamicTerrainRasterLibrary* rasterLibrary,
420  osg::ref_ptr<osgEarth::LandCoverDictionary> landCoverDictionary_Splat,
425  osg::ref_ptr<osgEarth::Contrib::DecalImageLayer> decalCoverageRasterLayer,
426  unsigned coverageMappingValue,
427  std::string& info,
428  std::string& warn,
429  osgEarth::GeoExtent& out_feature_extent,
430  double start_angle = 0.0,
431  int minInvalidateLod = -1);
432 
434  static std::string osmFidStringFromList(std::set<long long>& osmFidList);
435 
437  static void osmFidStringToList(const std::string& osmFidString, std::set<long long>& osmFidList);
438 
440  static int getObjectID(unsigned int instance, osg::TextureBuffer* tbo);
441 
443  static bool isReflectionCamera(const osg::Camera* camera);
444 
445  protected:
447  static bool snipTriangle( const std::vector<osg::Vec2>& contour, int u, int v, int w, int n, int *V );
449  static bool insideTriangle( float Ax, float Ay, float Bx, float By, float Cx, float Cy, float Px, float Py );
451  static float triangulateAreaSize( const std::vector<osg::Vec2> &contour );
452 
453 
454  };
455 }
456 
static VecType DtModPerLoVec3(const VecType &in, double min, double max)
Definition: DtOsgUtils.h:248
void updateDebugFrustum(osg::Vec3d *frustumVertices)
static const std::string CRATER_HEADING
Definition: DtOsgUtils.h:96
static const std::string EffectMapTextureUniformName
Definition: DtOsgUtils.h:117
static const std::string CRATER_MAJOR_AXIS
Definition: DtOsgUtils.h:94
Contains makVrv::DtDynamicTerrainLine class.
static const std::string EffectMapTextureMatrixUniformName
Definition: DtOsgUtils.h:118
Contains makVrv::DtOsgShaderUtils class.
DtDynamicTerrainRasterLibrary This class is used to managed rasters and out-the-window images appl...
Definition: DtDynamicTerrainRasterLibrary.h:95
#define DT_DLL_VRVOSG
Definition: vrvOsg.h:23
FidMetadataNode(long long FID, osgEarth::MetadataNode *metadataNode, int objectIndex)
Definition: DtOsgUtils.h:327
Definition: DtOsgUtils.h:341
DtIntersector is an abstract class that provides the interface for requesting intersections with the ...
Definition: DtIntersector.h:26
static const std::string TerrainDamageDestroyed
Definition: DtOsgUtils.h:111
Definition: terrainCraterGeometry.h:26
Wrapper for OpenGL Texture.
Definition: DtGlSimpleTexture.h:36
static const std::string CRATER_MINOR_AXIS
Definition: DtOsgUtils.h:95
Definition: terrainCraterGeometry.h:23
static const std::string TerrainDamageSlight
Definition: DtOsgUtils.h:109
Definition: terrainCraterGeometry.h:24
static const std::string TrackModelDefinitionSchema
Definition: DtOsgUtils.h:119
std::map< long long, osg::BoundingBoxd > Fid2DebrisMapType
map of FID and bounding sphere debris
Definition: DtOsgUtils.h:339
static const std::string TERRAIN_DEFORMATION_LANDCOVER_OVERRIDE
Definition: DtOsgUtils.h:130
static const std::string TRACKS_TERRAIN_TIME
Definition: DtOsgUtils.h:115
osg::ref_ptr< osg::MatrixTransform > myTransform
Definition: DtOsgUtils.h:67
std::map< osgEarth::MetadataNode *, DtOsgUtils::OSMBuildingInfo > MetadaNodeMap
map between a metadataNode and OSM object indexes (used to display/hide buildings) ...
Definition: DtOsgUtils.h:318
static const std::string TrackPointAParameterName
Definition: DtOsgUtils.h:123
static const std::string TrackDepthParameterName
Definition: DtOsgUtils.h:122
Camera forward declarations.
static const std::string TERRAIN_DEFORMATION_ENUM
Definition: DtOsgUtils.h:129
DtCraterEffect
Definition: DtOsgUtils.h:146
static const std::string TrackSoilTypeParameterName
Definition: DtOsgUtils.h:121
osgEarth::MetadataNode * myMetadataNode
Definition: DtOsgUtils.h:312
Definition: DtOsgUtils.h:71
static const std::string CRATER_RADIUS
Definition: DtOsgUtils.h:106
long long myFID
Definition: DtOsgUtils.h:333
OSMBuildingInfo(osgEarth::MetadataNode *metadataNode, const std::set< int > &objectIndexList)
Definition: DtOsgUtils.h:306
Structure to map a pair between a MetadataNode and list of OSM object index This class is used to tra...
Definition: DtOsgUtils.h:303
static const std::string TrackPointBParameterName
Definition: DtOsgUtils.h:124
DtDynamicTerrainLine is used to represent a collection of vertices for a linear dynamic terrain objec...
Definition: DtDynamicTerrainLine.h:24
static const std::string TrackSegmentSpacingParameterName
Definition: DtOsgUtils.h:126
static const std::string TERRAIN_DEFORMATION_WIDTH
Definition: DtOsgUtils.h:131
DT_DLL_vrfutil double angle(double vec1[3], double vec2[3])
osgEarth::MetadataNode * myMetadataNode
Definition: DtOsgUtils.h:334
helper class, random osg debug helpers and math
Definition: DtOsgUtils.h:89
static const std::string TerrainDamageModerate
Definition: DtOsgUtils.h:110
std::string myModelDefinition
Definition: DtOsgUtils.h:350
static const std::string CRATER_EFFECT_ENUM
Definition: DtOsgUtils.h:97
static const std::string CRATER_TYPE
Definition: DtOsgUtils.h:100
Definition: terrainCraterGeometry.h:25
osg::ref_ptr< osg::Geometry > myGeometry
Definition: DtOsgUtils.h:68
int myObjectIndex
Definition: DtOsgUtils.h:335
Definition: terrainCraterGeometry.h:27
static const std::string CRATER_SOIL_TYPE
Definition: DtOsgUtils.h:98
DtTerrainDeformation
Definition: DtOsgUtils.h:135
std::vector< DebrisPositionStruct > DebrisPositionListType
list of position / debris model definition
Definition: DtOsgUtils.h:354
static const std::string CRATER_DEPTH
Definition: DtOsgUtils.h:99
static const std::string TRACKS_LINE_WIDTH
Definition: DtOsgUtils.h:114
DtOsgDebugFrustum(const osg::Vec4 &color)
DtDynamicTerrainSphere is used to represent a sphere of impact for a dynamic terrain event...
Definition: DtDynamicTerrainSphere.h:21
std::set< int > myObjectIndexList
List of OSM object index under the associated MetadataNode.
Definition: DtOsgUtils.h:314
Command which can be given to the dynamic terrain system to perform some change. This class is a simp...
Definition: DtDynamicTerrainChange.h:44
static const std::string COMMAND_UID
Definition: DtOsgUtils.h:104
static const std::string MODELDEFINITION_PROPS
Definition: DtOsgUtils.h:101
std::map< std::string, DtOsgUtils::MetadaNodeMap > ChangeIdMetadaNodeMap
map between a crater change ID and MetadaNodeMap changes (hidden OSM buildings)
Definition: DtOsgUtils.h:321
DebrisPositionStruct(const DtVector &position, const std::string &modelDefinition)
Definition: DtOsgUtils.h:343
static const std::string TrackTypeParameterName
Definition: DtOsgUtils.h:120
helper for visualizing debug frustra
Definition: DtOsgUtils.h:61
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
DtVector myPosition
Definition: DtOsgUtils.h:349
static const std::string TERRAIN_DEFORMATION_RESOLUTION
Definition: DtOsgUtils.h:133
static const std::string TERRAIN_DEFORMATION_HEIGHT
Definition: DtOsgUtils.h:132
map between FID and MetadataNode
Definition: DtOsgUtils.h:324
static const std::string TrackTexureParameterName
Definition: DtOsgUtils.h:125
static const std::string TerrainDamageName
Definition: DtOsgUtils.h:108
Definition: dfadData.h:59

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)