VR-Vantage 2.5 API Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
vrvOsgUtils.h
Go to the documentation of this file.
1 /******************************************************************************
2 ** Copyright (c) 2014 MAK Technologies, Inc.
3 ** All rights reserved.
4 ******************************************************************************/
5 
8 
9 #pragma once
10 
11 #include <osg/Quat>
12 #include <osg/Texture2DArray>
13 #include <osg/Depth>
14 #include <osg/Camera>
15 #include <osg/MatrixTransform>
16 #include <osg/Geometry>
17 
19 
20 namespace makVrv
21 {
23  static void makeRotate( osg::Quat& q, const double& angle, const double& x, const double& y, const double& z )
24  {
25  double coshalfangle = cos( 0.5*angle );
26  double sinhalfangle = sin( 0.5*angle );
27 
28  q.set(
29  x * sinhalfangle,
30  y * sinhalfangle,
31  z * sinhalfangle,
32  coshalfangle);
33  }
34 
38  static void quatMult( osg::Quat& lhs, const osg::Quat& rhs )
39  {
40  // Algorithm from:
41  // http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/code/
42  double x = lhs[0] * rhs[3] + lhs[1] * rhs[2] - lhs[2] * rhs[1] + lhs[3] * rhs[0];
43  double y = -lhs[0] * rhs[2] + lhs[1] * rhs[3] + lhs[2] * rhs[0] + lhs[3] * rhs[1];
44  double z = lhs[0] * rhs[1] - lhs[1] * rhs[0] + lhs[2] * rhs[3] + lhs[3] * rhs[2];
45  double w = -lhs[0] * rhs[0] - lhs[1] * rhs[1] - lhs[2] * rhs[2] + lhs[3] * rhs[3];
46 
47  lhs[0] = x;
48  lhs[1] = y;
49  lhs[2] = z;
50  lhs[3] = w;
51  }
52 
53 
55  float x, float y, float w, float h);
56 
57  DT_DLL_VRVOSG osg::Camera * CreateTextureQuadOverlay(const std::string & shader_root, osg::Texture2DArray * textureArray,
58  float x, float y, float w, float h);
59 
61  struct DT_DLL_VRVOSG DtOsgDebugFrustum : public osg::Referenced
62  {
63  osg::ref_ptr<osg::MatrixTransform> myTransform;
64  osg::ref_ptr<osg::Geometry> myGeometry;
65  DtOsgDebugFrustum(const osg::Vec4 & color);
66  void updateDebugFrustum(osg::Vec3d * frustumVertices);
67  };
68 
70  osg::MatrixTransform * create_axis_primitive();
71 
72 
75  DT_DLL_VRVOSG osg::Matrixd oglRevDepthOrtho(double left, double right, double bottom,
76  double top, double zNear, double zFar);
77 
81  DT_DLL_VRVOSG bool getRevZProjectionMatrixAsFrustum(const osg::Matrix& mat, double& left,
82  double& right, double& bottom, double& top, double& zNear, double& zFar);
83 
87  DT_DLL_VRVOSG bool getRevPerspective(const osg::Matrix& mat, double& fovy,
88  double& aspectRatio, double& zNear, double& zFar);
89 
93  DT_DLL_VRVOSG osg::Matrix makeRevFrustum(double left, double right,
94  double bottom, double top, double zNear, double zFar);
95 
99  DT_DLL_VRVOSG osg::Matrix makeRevPerspective(double fovy, double aspectRatio,
100  double zNear, double zFar);
101 
103  // helpers for matrix and reverse z matrixes
104  DT_DLL_VRVOSG osg::Matrixd oglRevDepthOrtho(double left, double right, double bottom, double top, double zNear, double zFar);
105  DT_DLL_VRVOSG osg::Matrix getOrthoMatrix(bool useReverseZ, double left, double right, double bottom, double top, double zNear, double zFar);
106 
107  void DT_DLL_VRVOSG getYPR(const osg::Matrix& m, double& yaw, double& pitch, double& roll);
108 
109 }
110 


Copyright © 2005-2019 VT MAK. All Rights Reserved (www.mak.com)