From 53dc81e309647785676ea9d1b9cb42a696afc9a9 Mon Sep 17 00:00:00 2001 From: Philip Rosedale Date: Wed, 22 May 2013 11:57:11 -0700 Subject: [PATCH] Fixes per code review. --- interface/src/Avatar.cpp | 4 ++-- interface/src/Transmitter.cpp | 33 ++++++++++++++++++--------------- interface/src/Transmitter.h | 11 +++++++---- 3 files changed, 27 insertions(+), 21 deletions(-) diff --git a/interface/src/Avatar.cpp b/interface/src/Avatar.cpp index d4c16a3bb3..12d14aafdf 100644 --- a/interface/src/Avatar.cpp +++ b/interface/src/Avatar.cpp @@ -293,9 +293,9 @@ void Avatar::simulate(float deltaTime, Transmitter* transmitter) { if (fabs(rotation.y) > TRANSMITTER_MIN_YAW_RATE) { _bodyYawDelta += rotation.y * TRANSMITTER_YAW_SCALE * deltaTime; } - if (transmitter->getTouchState() == 'D') { + if (transmitter->getTouchState()->state == 'D') { _thrust += THRUST_MAG * - (float)(transmitter->getTouchPoint()[1] - TOUCH_POSITION_RANGE_HALF) / TOUCH_POSITION_RANGE_HALF * + (float)(transmitter->getTouchState()->y - TOUCH_POSITION_RANGE_HALF) / TOUCH_POSITION_RANGE_HALF * TRANSMITTER_LIFT_SCALE * deltaTime * _orientation.getUp(); diff --git a/interface/src/Transmitter.cpp b/interface/src/Transmitter.cpp index 3a3a3f3ff8..5f6def92f7 100644 --- a/interface/src/Transmitter.cpp +++ b/interface/src/Transmitter.cpp @@ -31,21 +31,24 @@ void Transmitter::resetLevels() { } void Transmitter::processIncomingData(unsigned char* packetData, int numBytes) { - if (numBytes >= 3 + sizeof(_lastRotationRate) + - sizeof(_lastAcceleration) + sizeof(_touchState)) { - unsigned char* ptr = &packetData[2]; - memcpy(&_lastRotationRate, ptr, sizeof(_lastRotationRate)); - ptr += sizeof(_lastRotationRate) + 1; - memcpy(&_lastAcceleration, ptr, sizeof(_lastAcceleration)); - ptr += sizeof(_lastAcceleration); - memcpy(&_touchState, ptr, sizeof(_touchState)); - ptr += sizeof(_touchState); - if (_touchState == 'D') { - memcpy(&_touchPoint, ptr, sizeof(_touchPoint)); - ptr += sizeof(_touchPoint); - } else { - _touchPoint[0] = _touchPoint[1] = 0; - } + const int PACKET_HEADER_SIZE = 1; // Packet's first byte is 'T' + const int ROTATION_MARKER_SIZE = 1; // 'R' = Rotation (clockwise about x,y,z) + const int ACCELERATION_MARKER_SIZE = 1; // 'A' = Acceleration (x,y,z) + if (numBytes == PACKET_HEADER_SIZE + ROTATION_MARKER_SIZE + ACCELERATION_MARKER_SIZE + + sizeof(_lastRotationRate) + sizeof(_lastAcceleration) + + sizeof(_touchState.x) + sizeof(_touchState.y) + sizeof(_touchState.state)) { + unsigned char* packetDataPosition = &packetData[PACKET_HEADER_SIZE + ROTATION_MARKER_SIZE]; + memcpy(&_lastRotationRate, packetDataPosition, sizeof(_lastRotationRate)); + packetDataPosition += sizeof(_lastRotationRate) + ACCELERATION_MARKER_SIZE; + memcpy(&_lastAcceleration, packetDataPosition, sizeof(_lastAcceleration)); + packetDataPosition += sizeof(_lastAcceleration); + memcpy(&_touchState.state, packetDataPosition, sizeof(_touchState.state)); + packetDataPosition += sizeof(_touchState.state); + memcpy(&_touchState.x, packetDataPosition, sizeof(_touchState.x)); + packetDataPosition += sizeof(_touchState.x); + memcpy(&_touchState.y, packetDataPosition, sizeof(_touchState.y)); + packetDataPosition += sizeof(_touchState.y); + // Update estimated absolute position from rotation rates _estimatedRotation += _lastRotationRate * DELTA_TIME; diff --git a/interface/src/Transmitter.h b/interface/src/Transmitter.h index 8a8b19cb6a..326d0a1182 100644 --- a/interface/src/Transmitter.h +++ b/interface/src/Transmitter.h @@ -15,6 +15,11 @@ #include #include "world.h" +struct TouchState { + uint16_t x, y; + char state; +}; + class Transmitter { public: @@ -26,8 +31,7 @@ public: const glm::vec3 getLastRotationRate() const { return _lastRotationRate; }; const glm::vec3 getLastAcceleration() const { return _lastRotationRate; }; const glm::vec3 getEstimatedRotation() const { return _estimatedRotation; }; - const uint16_t* getTouchPoint() const { return _touchPoint; }; - const char getTouchState() const { return _touchState; }; + const TouchState* getTouchState() const { return &_touchState; }; void processIncomingData(unsigned char* packetData, int numBytes); private: @@ -35,8 +39,7 @@ private: glm::vec3 _lastRotationRate; glm::vec3 _lastAcceleration; glm::vec3 _estimatedRotation; - uint16_t _touchPoint[2]; - char _touchState; + TouchState _touchState; #endif /* defined(__hifi__Transmitter__) */ };