VR-Vantage 2.3 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 
18 
19 namespace makVrv
20 {
22  static void makeRotate( osg::Quat& q, const double& angle, const double& x, const double& y, const double& z )
23  {
24  double coshalfangle = cos( 0.5*angle );
25  double sinhalfangle = sin( 0.5*angle );
26 
27  q.set(
28  x * sinhalfangle,
29  y * sinhalfangle,
30  z * sinhalfangle,
31  coshalfangle);
32  }
33 
37  static void quatMult( osg::Quat& lhs, const osg::Quat& rhs )
38  {
39  // Algorithm from:
40  // http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/code/
41  double x = lhs[0] * rhs[3] + lhs[1] * rhs[2] - lhs[2] * rhs[1] + lhs[3] * rhs[0];
42  double y = -lhs[0] * rhs[2] + lhs[1] * rhs[3] + lhs[2] * rhs[0] + lhs[3] * rhs[1];
43  double z = lhs[0] * rhs[1] - lhs[1] * rhs[0] + lhs[2] * rhs[3] + lhs[3] * rhs[2];
44  double w = -lhs[0] * rhs[0] - lhs[1] * rhs[1] - lhs[2] * rhs[2] + lhs[3] * rhs[3];
45 
46  lhs[0] = x;
47  lhs[1] = y;
48  lhs[2] = z;
49  lhs[3] = w;
50  }
51 
52 
54  float x, float y, float w, float h);
55 
56  DT_DLL_VRVOSG osg::Camera * CreateTextureQuadOverlay(const std::string & shader_root, osg::Texture2DArray * textureArray,
57  float x, float y, float w, float h);
58 
60  struct DT_DLL_VRVOSG DtOsgDebugFrustum : public osg::Referenced
61  {
62  osg::ref_ptr<osg::MatrixTransform> myTransform;
63  osg::ref_ptr<osg::Geometry> myGeometry;
64  DtOsgDebugFrustum(const osg::Vec4 & color);
65  void updateDebugFrustum(osg::Vec3d * frustumVertices);
66  };
67 
69  osg::MatrixTransform * create_axis_primitive();
70 
71 
74  DT_DLL_VRVOSG osg::Matrixd oglRevDepthOrtho(double left, double right, double bottom,
75  double top, double zNear, double zFar);
76 
80  DT_DLL_VRVOSG bool getRevZProjectionMatrixAsFrustum(const osg::Matrix& mat, double& left,
81  double& right, double& bottom, double& top, double& zNear, double& zFar);
82 
86  DT_DLL_VRVOSG bool getRevPerspective(const osg::Matrix& mat, double& fovy,
87  double& aspectRatio, double& zNear, double& zFar);
88 
92  DT_DLL_VRVOSG osg::Matrix makeRevFrustum(double left, double right,
93  double bottom, double top, double zNear, double zFar);
94 
98  DT_DLL_VRVOSG osg::Matrix makeRevPerspective(double fovy, double aspectRatio,
99  double zNear, double zFar);
100 
102  // helpers for matrix and reverse z matrixes
103  DT_DLL_VRVOSG osg::Matrixd oglRevDepthOrtho(double left, double right, double bottom, double top, double zNear, double zFar);
104  DT_DLL_VRVOSG osg::Matrix getOrthoMatrix(bool useReverseZ, double left, double right, double bottom, double top, double zNear, double zFar);
105 
106  void DT_DLL_VRVOSG getYPR(const osg::Matrix& m, double& yaw, double& pitch, double& roll);
107 
108 }
109 


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