VR-Vantage 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 
13 namespace makVrv
14 {
16  static void makeRotate( osg::Quat& q, const double& angle, const double& x, const double& y, const double& z )
17  {
18  double coshalfangle = cos( 0.5*angle );
19  double sinhalfangle = sin( 0.5*angle );
20 
21  q.set(
22  x * sinhalfangle,
23  y * sinhalfangle,
24  z * sinhalfangle,
25  coshalfangle);
26  }
27 
31  static void quatMult( osg::Quat& lhs, const osg::Quat& rhs )
32  {
33  // Algorithm from:
34  // http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/code/
35  double x = lhs[0] * rhs[3] + lhs[1] * rhs[2] - lhs[2] * rhs[1] + lhs[3] * rhs[0];
36  double y = -lhs[0] * rhs[2] + lhs[1] * rhs[3] + lhs[2] * rhs[0] + lhs[3] * rhs[1];
37  double z = lhs[0] * rhs[1] - lhs[1] * rhs[0] + lhs[2] * rhs[3] + lhs[3] * rhs[2];
38  double w = -lhs[0] * rhs[0] - lhs[1] * rhs[1] - lhs[2] * rhs[2] + lhs[3] * rhs[3];
39 
40  lhs[0] = x;
41  lhs[1] = y;
42  lhs[2] = z;
43  lhs[3] = w;
44  }
45 }


Copyright © 2005-2013 VT MÄK. All Rights Reserved (www.mak.com)