mirror of
https://github.com/overte-org/overte.git
synced 2025-04-24 03:33:35 +02:00
Fixes per code review.
This commit is contained in:
parent
0d231b5550
commit
53dc81e309
3 changed files with 27 additions and 21 deletions
|
@ -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();
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -15,6 +15,11 @@
|
|||
#include <cstring>
|
||||
#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__) */
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue