razerHydraData.cpp
Engine/source/platform/input/razerHydra/razerHydraData.cpp
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/razerHydraData.h" 25#include "platform/input/razerHydra/razerHydraUtil.h" 26 27RazerHyrdaControllerData::RazerHyrdaControllerData() 28{ 29 reset(); 30} 31 32void RazerHyrdaControllerData::reset() 33{ 34 mDataSet = false; 35 36 mShoulder = false; 37 mThumb = false; 38 mStart = false; 39 mButton1 = false; 40 mButton2 = false; 41 mButton3 = false; 42 mButton4 = false; 43 44 mIsDocked = false; 45} 46 47void RazerHyrdaControllerData::setData(const sixenseControllerData& data, const F32& maxAxisRadius) 48{ 49 // Controller position 50 RazerHydraUtil::convertPosition(data.pos, mRawPos[0], mRawPos[1], mRawPos[2]); 51 mPos[0] = (S32)mFloor(mRawPos[0]); 52 mPos[1] = (S32)mFloor(mRawPos[1]); 53 mPos[2] = (S32)mFloor(mRawPos[2]); 54 55 mPosPoint.set(mPos[0], mPos[1], mPos[2]); 56 57 // Controller rotation 58 RazerHydraUtil::convertRotation(data.rot_mat, mRot); 59 mRotQuat.set(mRot); 60 61 // Controller rotation as axis, but only if not docked 62 if(!data.is_docked) 63 { 64 RazerHydraUtil::calculateAxisRotation(mRot, maxAxisRadius, mRotAxis); 65 } 66 else 67 { 68 mRotAxis.x = 0.0f; 69 mRotAxis.y = 0.0f; 70 } 71 72 // Thumb stick 73 mThumbStick[0] = data.joystick_x; 74 mThumbStick[1] = data.joystick_y; 75 76 // Trigger 77 mTrigger = data.trigger; 78 79 //Buttons 80 mShoulder = data.buttons & SIXENSE_BUTTON_BUMPER; 81 mThumb = data.buttons & SIXENSE_BUTTON_JOYSTICK; 82 mStart = data.buttons & SIXENSE_BUTTON_START; 83 mButton1 = data.buttons & SIXENSE_BUTTON_1; 84 mButton2 = data.buttons & SIXENSE_BUTTON_2; 85 mButton3 = data.buttons & SIXENSE_BUTTON_3; 86 mButton4 = data.buttons & SIXENSE_BUTTON_4; 87 88 // Other data 89 mIsDocked = data.is_docked; 90 91 // Store the current sequence number 92 mSequenceNum = data.sequence_number; 93 94 mDataSet = true; 95} 96 97U32 RazerHyrdaControllerData::compare(RazerHyrdaControllerData* other) 98{ 99 S32 result = DIFF_NONE; 100 101 // Check position 102 if(mDataSet) 103 { 104 if(mPos[0] != other->mPos[0]) 105 result |= DIFF_POSX; 106 107 if(mPos[1] != other->mPos[1]) 108 result |= DIFF_POSY; 109 110 if(mPos[2] != other->mPos[2]) 111 result |= DIFF_POSZ; 112 } 113 else 114 { 115 result |= DIFF_POS; 116 } 117 118 // Check rotation 119 if(mRotQuat != other->mRotQuat || !mDataSet) 120 { 121 result |= DIFF_ROT; 122 } 123 124 // Check rotation as axis 125 if(mRotAxis.x != other->mRotAxis.x || !mDataSet) 126 { 127 result |= DIFF_ROTAXISX; 128 } 129 if(mRotAxis.y != other->mRotAxis.y || !mDataSet) 130 { 131 result |= DIFF_ROTAXISY; 132 } 133 134 // Check thumb stick 135 if(mThumbStick[0] != other->mThumbStick[0] || !mDataSet) 136 { 137 result |= DIFF_AXISX; 138 } 139 if(mThumbStick[1] != other->mThumbStick[1] || !mDataSet) 140 { 141 result |= DIFF_AXISY; 142 } 143 144 // Check trigger 145 if(mTrigger != other->mTrigger || !mDataSet) 146 { 147 result |= DIFF_TRIGGER; 148 } 149 150 // Check buttons 151 if(mShoulder != other->mShoulder) 152 { 153 result |= DIFF_BUTTON_SHOULDER; 154 } 155 if(mThumb != other->mThumb) 156 { 157 result |= DIFF_BUTTON_THUMB; 158 } 159 if(mStart != other->mStart) 160 { 161 result |= DIFF_BUTTON_START; 162 } 163 if(mButton1 != other->mButton1) 164 { 165 result |= DIFF_BUTTON1; 166 } 167 if(mButton2 != other->mButton2) 168 { 169 result |= DIFF_BUTTON2; 170 } 171 if(mButton3 != other->mButton3) 172 { 173 result |= DIFF_BUTTON3; 174 } 175 if(mButton4 != other->mButton4) 176 { 177 result |= DIFF_BUTTON4; 178 } 179 180 return result; 181} 182 183U32 RazerHyrdaControllerData::compareMeta(RazerHyrdaControllerData* other) 184{ 185 S32 result = DIFF_NONE; 186 187 if(mIsDocked != other->mIsDocked || !mDataSet) 188 { 189 result |= METADIFF_DOCKED; 190 } 191 192 return result; 193} 194