razerHydraUtil.cpp
Engine/source/platform/input/razerHydra/razerHydraUtil.cpp
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/razerHydra/razerHydraUtil.h" 25 26namespace RazerHydraUtil 27{ 28 29enum Components 30{ 31 X = 0, 32 Y = 1, 33 Z = 2, 34}; 35 36void convertPosition(const F32 inPosition[3], F32& x, F32& y, F32& z) 37{ 38 // Convert to Torque coordinates. The conversion is: 39 // 40 // Motion Torque 41 // x y z --> x -z y 42 x = inPosition[X]; // x = x 43 y = -inPosition[Z]; // y = -z 44 z = inPosition[Y]; // z = y; 45} 46 47void convertPosition(const F32 inPosition[3], Point3F& outPosition) 48{ 49 // Convert to Torque coordinates. The conversion is: 50 // 51 // Motion Torque 52 // x y z --> x -z y 53 outPosition.x = inPosition[X]; // x = x 54 outPosition.y = -inPosition[Z]; // y = -z 55 outPosition.z = inPosition[Y]; // z = y; 56} 57 58void convertRotation(const F32 inRotMat[3][3], MatrixF& outRotation) 59{ 60 // Set rotation. We need to convert from sixense coordinates to 61 // Torque coordinates. The conversion is: 62 // 63 // Sixense Torque 64 // a b c a b c a -c b 65 // d e f --> -g -h -i --> -g i -h 66 // g h i d e f d -f e 67 outRotation.setColumn(0, Point4F( inRotMat[0][0], -inRotMat[0][2], inRotMat[0][1], 0.0f)); 68 outRotation.setColumn(1, Point4F(-inRotMat[2][0], inRotMat[2][2], -inRotMat[2][1], 0.0f)); 69 outRotation.setColumn(2, Point4F( inRotMat[1][0], -inRotMat[1][2], inRotMat[1][1], 0.0f)); 70 outRotation.setPosition(Point3F::Zero); 71} 72 73void calculateAxisRotation(const MatrixF& inRotation, const F32& maxAxisRadius, Point2F& outRotation) 74{ 75 const VectorF& controllerUp = inRotation.getUpVector(); 76 Point2F axis(0,0); 77 axis.x = controllerUp.x; 78 axis.y = controllerUp.y; 79 80 // Limit the axis angle to that given to us 81 if(axis.len() > maxAxisRadius) 82 { 83 axis.normalize(maxAxisRadius); 84 } 85 86 // Renormalize to the range of 0..1 87 if(maxAxisRadius != 0.0f) 88 { 89 axis /= maxAxisRadius; 90 } 91 92 outRotation.x = axis.x; 93 outRotation.y = axis.y; 94} 95 96} 97