Torque3D Documentation / _generateds / oculusVRUtil.cpp

oculusVRUtil.cpp

Engine/source/platform/input/oculusVR/oculusVRUtil.cpp

More...

Namespaces:

namespace

Detailed Description

 1
 2//-----------------------------------------------------------------------------
 3// Copyright (c) 2012 GarageGames, LLC
 4//
 5// Permission is hereby granted, free of charge, to any person obtaining a copy
 6// of this software and associated documentation files (the "Software"), to
 7// deal in the Software without restriction, including without limitation the
 8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 9// sell copies of the Software, and to permit persons to whom the Software is
10// furnished to do so, subject to the following conditions:
11//
12// The above copyright notice and this permission notice shall be included in
13// all copies or substantial portions of the Software.
14//
15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21// IN THE SOFTWARE.
22//-----------------------------------------------------------------------------
23
24#include "platform/input/oculusVR/oculusVRUtil.h"
25
26namespace OculusVRUtil
27{
28
29void convertRotation(const F32 inRotMat[4][4], MatrixF& outRotation)
30{
31   // Set rotation.  We need to convert from sensor coordinates to
32   // Torque coordinates.  The sensor matrix is stored row-major.
33   // The conversion is:
34   //
35   // Sensor                       Torque
36   // a b c         a  b  c        a -c  b
37   // d e f   -->  -g -h -i  -->  -g  i -h
38   // g h i         d  e  f        d -f  e
39   outRotation.setColumn(0, Point4F( inRotMat[0][0], -inRotMat[2][0],  inRotMat[1][0], 0.0f));
40   outRotation.setColumn(1, Point4F(-inRotMat[0][2],  inRotMat[2][2], -inRotMat[1][2], 0.0f));
41   outRotation.setColumn(2, Point4F( inRotMat[0][1], -inRotMat[2][1],  inRotMat[1][1], 0.0f));
42   outRotation.setPosition(Point3F::Zero);
43}
44
45void convertRotation(OVR::Quatf& inRotation, EulerF& outRotation)
46{
47   F32 yaw, pitch, roll;
48   inRotation.GetEulerAngles<OVR::Axis_X, OVR::Axis_Z, OVR::Axis_Y, OVR::Rotate_CW, OVR::Handed_R>(&outRotation.x, &outRotation.y, &outRotation.z);
49}
50
51void calculateAxisRotation(const MatrixF& inRotation, const F32& maxAxisRadius, Point2F& outRotation)
52{
53   const VectorF& controllerUp = inRotation.getUpVector();
54   Point2F axis(0,0);
55   axis.x = controllerUp.x;
56   axis.y = controllerUp.y;
57
58   // Limit the axis angle to that given to us
59   if(axis.len() > maxAxisRadius)
60   {
61      axis.normalize(maxAxisRadius);
62   }
63
64   // Renormalize to the range of 0..1
65   if(maxAxisRadius != 0.0f)
66   {
67      axis /= maxAxisRadius;
68   }
69
70   outRotation.x = axis.x;
71   outRotation.y = axis.y;
72}
73
74void convertAcceleration(OVR::Vector3f& inAcceleration, VectorF& outAcceleration)
75{
76   outAcceleration.set(inAcceleration.x, -inAcceleration.z, inAcceleration.y);
77}
78
79void convertAngularVelocity(OVR::Vector3f& inAngVel, EulerF& outAngVel)
80{
81   outAngVel.set(-inAngVel.x, inAngVel.z, -inAngVel.y);
82}
83
84void convertMagnetometer(OVR::Vector3f& inMagnetometer, VectorF& outMagnetometer)
85{
86   outMagnetometer.set(inMagnetometer.x, -inMagnetometer.z, inMagnetometer.y);
87}
88
89}
90