VR-Forces 5.0.2 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) 2021 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 
21 
22 class DtTaitBryan;
23 
24 namespace makVrv
25 {
26  class DtGlSimpleTexture;
27 
30  class DtOsgDebugFrustum : public osg::Referenced
31  {
32  public:
33  DtOsgDebugFrustum(const osg::Vec4 & color);
34  void updateDebugFrustum(osg::Vec3d * frustumVertices);
35 
38  };
39 
41  {
42  public:
44  static osg::Camera* CreateTextureQuadOverlay(DtGlSimpleTexture* texture,
45  float x, float y, float w, float h);
46 
48  static osg::Camera* CreateTextureQuadOverlay(osg::Texture* texture,
49  float x, float y, float w, float h);
50 
52  static osg::Camera* CreateTextureQuadOverlay(const std::string& shader_root, osg::Texture2DArray* textureArray,
53  float x, float y, float w, float h);
54  };
55 
59  {
60  public:
62  static void makeRotate(osg::Quat& q, const double& angle, const double& x, const double& y, const double& z);
63 
65  static osg::Matrixf toOsgRotation(const DtTaitBryan& orientation);
66 
70  static void quatMult(osg::Quat& lhs, const osg::Quat& rhs);
71 
73  static osg::MatrixTransform * create_axis_primitive();
74 
77 
80  static osg::Matrix getOrthoMatrix(bool useReverseZ, double left, double right,
81  double bottom, double top, double zNear, double zFar);
82 
85  static osg::Matrix getProjMatrix(bool useReverseZ, double left, double right,
86  double bottom, double top, double zNear, double zFar);
87 
89  static osg::Matrixd getRevZOrthoMatrix(double left, double right, double bottom,
90  double top, double zNear, double zFar);
91 
94  static bool getRevZPerspectiveMatrixAsFrustum(const osg::Matrix& mat, double& left,
95  double& right, double& bottom, double& top, double& zNear, double& zFar);
96 
99  static bool getRevZOrthoMatrixAsFrustum(const osg::Matrix& orthoMat, double& left,
100  double& right, double& bottom, double& top, double& zNear, double& zFar);
101 
104  static bool getRevZPerspective(const osg::Matrix& mat, double& fovy,
105  double& aspectRatio, double& zNear, double& zFar);
106 
109  static osg::Matrix makeRevZPerspective(double fovy, double aspectRatio,
110  double zNear, double zFar);
111 
113  static void getYPR(const osg::Matrix& m, double& yaw, double& pitch, double& roll);
114 
116  static void osgPolytopeToFrustum(Frustum_64& frustum, const osg::Polytope& polytope, bool hasNearFar);
117 
121  static void computeOsgCameraFrustumPlanes(std::vector<osg::Vec4d>& planes, const osg::Camera* camera);
122 
124  static void debugDumpShaderState(osg::State* state);
125 
127  static void debugDumpUniformState(const osg::Node* node);
128 
130 
131  static osg::Vec2 rotateVec2( const osg::Vec2& v, double rad );
133 
135  static osg::Vec2 translateVec2( const osg::Vec2& v, const osg::Vec2& translation );
136 
138  static osg::Vec2 scaleVec2( const osg::Vec2& v, double s );
139 
141  static osg::Vec2 scaleVec2( const osg::Vec2& v, double xScale, double yScale );
143 
145  static bool clipLine( double xMin, double xMax, double yMin, double yMax,
146  double x0src, double y0src, double x1src, double y1src,
147  double &x0clip, double &y0clip, double &x1clip, double &y1clip );
148 
150  static void clipPolygon( double xMin, double xMax, double yMin, double yMax,
151  std::vector<osg::Vec2>& vertices );
152 
153  // Adapted from VR-Link DtModPerLo [matrix/modper.cxx]
154  template <class VecType> static VecType DtModPerLoVec3( const VecType& in, double min, double max )
155  {
156  VecType result;
157  double per = max - min;
158 
159  for( int i = 0; i < 3; ++i )
160  {
161  if( min <= in[i] && in[i] < max )
162  {
163  result[i] = in[i];
164  }
165  else
166  {
167  result[i] = fmod( in[i] - min, per );
168 
169  if( result[i] < 0.0 )
170  {
171  result[i] += per;
172  }
173 
174  result[i] += min;
175  }
176  }
177  return result;
178  }
179 
186  static bool insideTriangulate( const std::vector<osg::Vec2>& contour, std::vector<int>& results );
187 
188  static osg::Matrixd calculateRevZProjectionMatrix(double left, double right
189  , double bottom, double top
190  , double zNear, double zFar);
191 
192  static osg::Matrixd calculateOrthoMatrix(double left, double right
193  , double bottom, double top
194  , double zNear, double zFar);
195 
196  static osg::Matrixd calculateRevZProjectionMatrixWithRevZAsNegativeOneForRttCamera(double left, double right
197  , double bottom, double top
198  , double zNear, double zFar);
199 
200  protected:
202  static bool snipTriangle( const std::vector<osg::Vec2>& contour, int u, int v, int w, int n, int *V );
204  static bool insideTriangle( float Ax, float Ay, float Bx, float By, float Cx, float Cy, float Px, float Py );
206  static float triangulateAreaSize( const std::vector<osg::Vec2> &contour );
207 
208 
209  };
210 }
211 
Diagonal crossing liens.
Definition: DtTacticalGraphicUtilities.h:93
static VecType DtModPerLoVec3(const VecType &in, double min, double max)
Definition: DtOsgUtils.h:154
void updateDebugFrustum(osg::Vec3d *frustumVertices)
Contains makVrv::DtOsgShaderUtils class.
#define DT_DLL_VRVOSG
Definition: vrvOsg.h:23
Wrapper for OpenGL Texture.
Definition: DtGlSimpleTexture.h:35
osg::ref_ptr< osg::MatrixTransform > myTransform
Definition: DtOsgUtils.h:36
Camera forward declarations.
Definition: DtOsgUtils.h:40
DT_DLL_vrfutil double angle(double vec1[3], double vec2[3])
helper class, random osg debug helpers and math
Definition: DtOsgUtils.h:58
osg::ref_ptr< osg::Geometry > myGeometry
Definition: DtOsgUtils.h:37
DtOsgDebugFrustum(const osg::Vec4 &color)
helper for visualizing debug frustra
Definition: DtOsgUtils.h:30

Document ID: Generated on Sun Dec 4 20:22:03 EST 2022 from SVN revision 249613
Copyright © 2005-2021 MAK Technologies. All Rights Reserved (www.mak.com)