From f20808b47fe88921ff56318d6397f3b50b31cf70 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Mon, 24 Feb 2014 15:11:02 -0800 Subject: [PATCH] remove option to drive from transmitter --- interface/src/Application.cpp | 5 - interface/src/DatagramProcessor.cpp | 6 - interface/src/Menu.cpp | 3 - interface/src/avatar/MyAvatar.cpp | 85 ------------- interface/src/avatar/MyAvatar.h | 10 -- interface/src/devices/Transmitter.cpp | 167 -------------------------- interface/src/devices/Transmitter.h | 50 -------- libraries/shared/src/PacketHeaders.h | 4 +- 8 files changed, 3 insertions(+), 327 deletions(-) delete mode 100644 interface/src/devices/Transmitter.cpp delete mode 100644 interface/src/devices/Transmitter.h diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index d7c3746e57..0e0130793e 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -2926,9 +2926,6 @@ void Application::displaySide(Camera& whichCamera, bool selfAvatarOnly) { } } - // render transmitter pick ray, if non-empty - _myAvatar->renderTransmitterPickRay(); - // give external parties a change to hook in emit renderingInWorldInterface(); @@ -2994,8 +2991,6 @@ void Application::displayOverlay() { _myAvatar->renderHeadMouse(); } - _myAvatar->renderTransmitterLevels(_glWidget->width(), _glWidget->height()); - // Display stats and log text onscreen glLineWidth(1.0f); glPointSize(1.0f); diff --git a/interface/src/DatagramProcessor.cpp b/interface/src/DatagramProcessor.cpp index 2de9b40a95..50e84db7b5 100644 --- a/interface/src/DatagramProcessor.cpp +++ b/interface/src/DatagramProcessor.cpp @@ -43,12 +43,6 @@ void DatagramProcessor::processDatagrams() { if (nodeList->packetVersionAndHashMatch(incomingPacket)) { // only process this packet if we have a match on the packet version switch (packetTypeForPacket(incomingPacket)) { - case PacketTypeTransmitterData: - // V2 = IOS transmitter app - application->getAvatar()->getTransmitter().processIncomingData(reinterpret_cast(incomingPacket.data()), - incomingPacket.size()); - - break; case PacketTypeMixedAudio: QMetaObject::invokeMethod(&application->_audio, "addReceivedAudioToBuffer", Qt::QueuedConnection, Q_ARG(QByteArray, incomingPacket)); diff --git a/interface/src/Menu.cpp b/interface/src/Menu.cpp index b5567f7e90..c1ea761ba3 100644 --- a/interface/src/Menu.cpp +++ b/interface/src/Menu.cpp @@ -135,9 +135,6 @@ Menu::Menu() : addActionToQMenuAndActionHash(fileMenu, MenuOption::SettingsImport, 0, this, SLOT(importSettings())); addActionToQMenuAndActionHash(fileMenu, MenuOption::SettingsExport, 0, this, SLOT(exportSettings())); - addDisabledActionAndSeparator(fileMenu, "Devices"); - addCheckableActionToQMenuAndActionHash(fileMenu, MenuOption::TransmitterDrive, 0, true); - addActionToQMenuAndActionHash(fileMenu, MenuOption::Quit, Qt::CTRL | Qt::Key_Q, diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index 55f18e23e3..e9a510e0da 100644 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -89,7 +89,6 @@ void MyAvatar::reset() { setVelocity(glm::vec3(0,0,0)); setThrust(glm::vec3(0,0,0)); - _transmitter.resetLevels(); } void MyAvatar::setMoveTarget(const glm::vec3 moveTarget) { @@ -97,32 +96,7 @@ void MyAvatar::setMoveTarget(const glm::vec3 moveTarget) { _moveTargetStepCounter = 0; } -void MyAvatar::updateTransmitter(float deltaTime) { - // no transmitter drive implies transmitter pick - if (!Menu::getInstance()->isOptionChecked(MenuOption::TransmitterDrive) && _transmitter.isConnected()) { - _transmitterPickStart = getChestPosition(); - glm::vec3 direction = getOrientation() * glm::quat(glm::radians(_transmitter.getEstimatedRotation())) * IDENTITY_FRONT; - - // check against voxels, avatars - const float MAX_PICK_DISTANCE = 100.0f; - float minDistance = MAX_PICK_DISTANCE; - VoxelDetail detail; - float distance; - BoxFace face; - VoxelSystem* voxels = Application::getInstance()->getVoxels(); - if (voxels->findRayIntersection(_transmitterPickStart, direction, detail, distance, face)) { - minDistance = min(minDistance, distance); - } - _transmitterPickEnd = _transmitterPickStart + direction * minDistance; - - } else { - _transmitterPickStart = _transmitterPickEnd = glm::vec3(); - } -} - void MyAvatar::update(float deltaTime) { - updateTransmitter(deltaTime); - updateFromGyros(deltaTime); // Update head mouse from faceshift if active @@ -574,35 +548,6 @@ void MyAvatar::renderHeadMouse() const { */ } -void MyAvatar::renderTransmitterPickRay() const { - if (_transmitterPickStart != _transmitterPickEnd) { - Glower glower; - const float TRANSMITTER_PICK_COLOR[] = { 1.0f, 1.0f, 0.0f }; - glColor3fv(TRANSMITTER_PICK_COLOR); - glLineWidth(3.0f); - glBegin(GL_LINES); - glVertex3f(_transmitterPickStart.x, _transmitterPickStart.y, _transmitterPickStart.z); - glVertex3f(_transmitterPickEnd.x, _transmitterPickEnd.y, _transmitterPickEnd.z); - glEnd(); - glLineWidth(1.0f); - - glPushMatrix(); - glTranslatef(_transmitterPickEnd.x, _transmitterPickEnd.y, _transmitterPickEnd.z); - - const float PICK_END_RADIUS = 0.025f; - glutSolidSphere(PICK_END_RADIUS, 8, 8); - - glPopMatrix(); - } -} - -void MyAvatar::renderTransmitterLevels(int width, int height) const { - // Show hand transmitter data if detected - if (_transmitter.isConnected()) { - _transmitter.renderLevels(width, height); - } -} - void MyAvatar::saveData(QSettings* settings) { settings->beginGroup("Avatar"); @@ -784,36 +729,6 @@ void MyAvatar::updateThrust(float deltaTime) { _shouldJump = false; } - // Add thrusts from Transmitter - if (Menu::getInstance()->isOptionChecked(MenuOption::TransmitterDrive) && _transmitter.isConnected()) { - _transmitter.checkForLostTransmitter(); - glm::vec3 rotation = _transmitter.getEstimatedRotation(); - const float TRANSMITTER_MIN_RATE = 1.f; - const float TRANSMITTER_MIN_YAW_RATE = 4.f; - const float TRANSMITTER_LATERAL_FORCE_SCALE = 5.f; - const float TRANSMITTER_FWD_FORCE_SCALE = 25.f; - const float TRANSMITTER_UP_FORCE_SCALE = 100.f; - const float TRANSMITTER_YAW_SCALE = 10.0f; - const float TRANSMITTER_LIFT_SCALE = 3.f; - const float TOUCH_POSITION_RANGE_HALF = 32767.f; - if (fabs(rotation.z) > TRANSMITTER_MIN_RATE) { - _thrust += rotation.z * TRANSMITTER_LATERAL_FORCE_SCALE * deltaTime * right; - } - if (fabs(rotation.x) > TRANSMITTER_MIN_RATE) { - _thrust += -rotation.x * TRANSMITTER_FWD_FORCE_SCALE * deltaTime * front; - } - if (fabs(rotation.y) > TRANSMITTER_MIN_YAW_RATE) { - _bodyYawDelta += rotation.y * TRANSMITTER_YAW_SCALE * deltaTime; - } - if (_transmitter.getTouchState()->state == 'D') { - _thrust += TRANSMITTER_UP_FORCE_SCALE * - (float)(_transmitter.getTouchState()->y - TOUCH_POSITION_RANGE_HALF) / TOUCH_POSITION_RANGE_HALF * - TRANSMITTER_LIFT_SCALE * - deltaTime * - up; - } - } - // Update speed brake status const float MIN_SPEED_BRAKE_VELOCITY = _scale * 0.4f; if ((glm::length(_thrust) == 0.0f) && _isThrustOn && (glm::length(_velocity) > MIN_SPEED_BRAKE_VELOCITY)) { diff --git a/interface/src/avatar/MyAvatar.h b/interface/src/avatar/MyAvatar.h index 10156cf130..cc5c2662a6 100644 --- a/interface/src/avatar/MyAvatar.h +++ b/interface/src/avatar/MyAvatar.h @@ -11,8 +11,6 @@ #include -#include - #include "Avatar.h" enum AvatarHandState @@ -35,13 +33,10 @@ public: void update(float deltaTime); void simulate(float deltaTime); void updateFromGyros(float deltaTime); - void updateTransmitter(float deltaTime); void render(bool forceRenderHead); void renderDebugBodyPoints(); void renderHeadMouse() const; - void renderTransmitterPickRay() const; - void renderTransmitterLevels(int width, int height) const; // setters void setMousePressed(bool mousePressed) { _mousePressed = mousePressed; } @@ -60,7 +55,6 @@ public: float getAbsoluteHeadYaw() const; const glm::vec3& getMouseRayOrigin() const { return _mouseRayOrigin; } const glm::vec3& getMouseRayDirection() const { return _mouseRayDirection; } - Transmitter& getTransmitter() { return _transmitter; } glm::vec3 getGravity() const { return _gravity; } glm::vec3 getUprightHeadPosition() const; @@ -118,10 +112,6 @@ private: int _moveTargetStepCounter; QWeakPointer _lookAtTargetAvatar; - Transmitter _transmitter; // Gets UDP data from transmitter app used to animate the avatar - glm::vec3 _transmitterPickStart; - glm::vec3 _transmitterPickEnd; - bool _billboardValid; // private methods diff --git a/interface/src/devices/Transmitter.cpp b/interface/src/devices/Transmitter.cpp deleted file mode 100644 index 5fca045cfd..0000000000 --- a/interface/src/devices/Transmitter.cpp +++ /dev/null @@ -1,167 +0,0 @@ -// -// Transmitter.cpp -// hifi -// -// Created by Philip Rosedale on 5/20/13. -// Copyright (c) 2013 HighFidelity, Inc. All rights reserved. -// - -#ifdef WIN32 -#define WANT_TIMEVAL -#include -#endif - -#include - -#include - -#include - -#include "InterfaceConfig.h" -#include "Transmitter.h" -#include "Util.h" - -const float DELTA_TIME = 1.f / 60.f; -const float DECAY_RATE = 0.15f; - -Transmitter::Transmitter() : - _isConnected(false), - _lastRotationRate(0,0,0), - _lastAcceleration(0,0,0), - _estimatedRotation(0,0,0), - _lastReceivedPacket(NULL) -{ - -} - -Transmitter::~Transmitter() { - if (_lastReceivedPacket) { - delete _lastReceivedPacket; - } -} - -void Transmitter::checkForLostTransmitter() { - // If we are in motion, check for loss of transmitter packets - if (glm::length(_estimatedRotation) > 0.f) { - timeval now; - gettimeofday(&now, NULL); - const int TIME_TO_ASSUME_LOST_MSECS = 2000; - int msecsSinceLast = diffclock(_lastReceivedPacket, &now); - if (msecsSinceLast > TIME_TO_ASSUME_LOST_MSECS) { - resetLevels(); - qDebug("Transmitter signal lost."); - } - } -} -void Transmitter::resetLevels() { - _lastRotationRate *= 0.f; - _estimatedRotation *= 0.f; -} - -void Transmitter::processIncomingData(unsigned char* packetData, int numBytes) { - // Packet's first byte is 'T' - int numBytesPacketHeader = numBytesForPacketHeader(reinterpret_cast(packetData)); - - 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 (!_lastReceivedPacket) { - _lastReceivedPacket = new timeval; - } - gettimeofday(_lastReceivedPacket, NULL); - - if (numBytes == numBytesPacketHeader + ROTATION_MARKER_SIZE + ACCELERATION_MARKER_SIZE - + sizeof(_lastRotationRate) + sizeof(_lastAcceleration) - + sizeof(_touchState.x) + sizeof(_touchState.y) + sizeof(_touchState.state)) { - unsigned char* packetDataPosition = packetData + numBytesPacketHeader + 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; - - // Sensor Fusion! Slowly adjust estimated rotation to be relative to gravity (average acceleration) - const float GRAVITY_FOLLOW_RATE = 1.f; - float rollAngle = angleBetween(glm::vec3(_lastAcceleration.x, _lastAcceleration.y, 0.f), glm::vec3(0,-1,0)) * - ((_lastAcceleration.x < 0.f) ? -1.f : 1.f); - float pitchAngle = angleBetween(glm::vec3(0.f, _lastAcceleration.y, _lastAcceleration.z), glm::vec3(0,-1,0)) * - ((_lastAcceleration.z < 0.f) ? 1.f : -1.f); - - _estimatedRotation.x = (1.f - GRAVITY_FOLLOW_RATE * DELTA_TIME) * _estimatedRotation.x + - GRAVITY_FOLLOW_RATE * DELTA_TIME * pitchAngle; - _estimatedRotation.z = (1.f - GRAVITY_FOLLOW_RATE * DELTA_TIME) * _estimatedRotation.z + - GRAVITY_FOLLOW_RATE * DELTA_TIME * rollAngle; - - // Can't apply gravity fusion to Yaw, so decay estimated yaw to zero, - // presuming that the average yaw direction is toward screen - _estimatedRotation.y *= (1.f - DECAY_RATE * DELTA_TIME); - - if (!_isConnected) { - qDebug("Transmitter Connected."); - _isConnected = true; - _estimatedRotation *= 0.0; - } - } else { - qDebug("Transmitter packet read error, %d bytes.", numBytes); - } -} - -void Transmitter::renderLevels(int width, int height) const { - char val[50]; - const int LEVEL_CORNER_X = 10; - const int LEVEL_CORNER_Y = 400; - - // Draw the numeric degree/sec values from the gyros - sprintf(val, "Pitch Rate %4.1f", _lastRotationRate.x); - drawtext(LEVEL_CORNER_X, LEVEL_CORNER_Y, 0.10f, 0, 1.0f, 1, val, 0, 1, 0); - sprintf(val, "Yaw Rate %4.1f", _lastRotationRate.y); - drawtext(LEVEL_CORNER_X, LEVEL_CORNER_Y + 15, 0.10f, 0, 1.0f, 1, val, 0, 1, 0); - sprintf(val, "Roll Rate %4.1f", _lastRotationRate.z); - drawtext(LEVEL_CORNER_X, LEVEL_CORNER_Y + 30, 0.10f, 0, 1.0f, 1, val, 0, 1, 0); - sprintf(val, "Pitch %4.3f", _estimatedRotation.x); - drawtext(LEVEL_CORNER_X, LEVEL_CORNER_Y + 45, 0.10f, 0, 1.0f, 1, val, 0, 1, 0); - sprintf(val, "Yaw %4.3f", _estimatedRotation.y); - drawtext(LEVEL_CORNER_X, LEVEL_CORNER_Y + 60, 0.10f, 0, 1.0f, 1, val, 0, 1, 0); - sprintf(val, "Roll %4.3f", _estimatedRotation.z); - drawtext(LEVEL_CORNER_X, LEVEL_CORNER_Y + 75, 0.10f, 0, 1.0f, 1, val, 0, 1, 0); - - // Draw the levels as horizontal lines - const int LEVEL_CENTER = 150; - const float ACCEL_VIEW_SCALING = 1.f; - glLineWidth(2.0); - glColor4f(1, 1, 1, 1); - glBegin(GL_LINES); - // Gyro rates - glVertex2f(LEVEL_CORNER_X + LEVEL_CENTER, LEVEL_CORNER_Y - 3); - glVertex2f(LEVEL_CORNER_X + LEVEL_CENTER + _lastRotationRate.x, LEVEL_CORNER_Y - 3); - glVertex2f(LEVEL_CORNER_X + LEVEL_CENTER, LEVEL_CORNER_Y + 12); - glVertex2f(LEVEL_CORNER_X + LEVEL_CENTER + _lastRotationRate.y, LEVEL_CORNER_Y + 12); - glVertex2f(LEVEL_CORNER_X + LEVEL_CENTER, LEVEL_CORNER_Y + 27); - glVertex2f(LEVEL_CORNER_X + LEVEL_CENTER + _lastRotationRate.z, LEVEL_CORNER_Y + 27); - // Acceleration - glVertex2f(LEVEL_CORNER_X + LEVEL_CENTER, LEVEL_CORNER_Y + 42); - glVertex2f(LEVEL_CORNER_X + LEVEL_CENTER + (int)(_estimatedRotation.x * ACCEL_VIEW_SCALING), - LEVEL_CORNER_Y + 42); - glVertex2f(LEVEL_CORNER_X + LEVEL_CENTER, LEVEL_CORNER_Y + 57); - glVertex2f(LEVEL_CORNER_X + LEVEL_CENTER + (int)(_estimatedRotation.y * ACCEL_VIEW_SCALING), - LEVEL_CORNER_Y + 57); - glVertex2f(LEVEL_CORNER_X + LEVEL_CENTER, LEVEL_CORNER_Y + 72); - glVertex2f(LEVEL_CORNER_X + LEVEL_CENTER + (int)(_estimatedRotation.z * ACCEL_VIEW_SCALING), - LEVEL_CORNER_Y + 72); - - glEnd(); - // Draw green vertical centerline - glColor4f(0, 1, 0, 0.5); - glBegin(GL_LINES); - glVertex2f(LEVEL_CORNER_X + LEVEL_CENTER, LEVEL_CORNER_Y - 6); - glVertex2f(LEVEL_CORNER_X + LEVEL_CENTER, LEVEL_CORNER_Y + 30); - glEnd(); -} - diff --git a/interface/src/devices/Transmitter.h b/interface/src/devices/Transmitter.h deleted file mode 100644 index 12f2b302f7..0000000000 --- a/interface/src/devices/Transmitter.h +++ /dev/null @@ -1,50 +0,0 @@ -// -// Transmitter.h -// hifi -// -// Created by Philip Rosedale on 5/20/13. -// Copyright (c) 2013 HighFidelity, Inc. All rights reserved. -// - -#ifndef __hifi__Transmitter__ -#define __hifi__Transmitter__ - -#include -#include -#include -#include -#include "world.h" -#include - -struct TouchState { - uint16_t x, y; - char state; -}; - -class Transmitter -{ -public: - Transmitter(); - ~Transmitter(); - void render(); - void checkForLostTransmitter(); - void resetLevels(); - void renderLevels(int width, int height) const; - bool isConnected() const { return _isConnected; }; - const glm::vec3 getLastRotationRate() const { return _lastRotationRate; }; - const glm::vec3 getLastAcceleration() const { return _lastRotationRate; }; - const glm::vec3 getEstimatedRotation() const { return _estimatedRotation; }; - const TouchState* getTouchState() const { return &_touchState; }; - void processIncomingData(unsigned char* packetData, int numBytes); - -private: - bool _isConnected; - glm::vec3 _lastRotationRate; - glm::vec3 _lastAcceleration; - glm::vec3 _estimatedRotation; - TouchState _touchState; - timeval* _lastReceivedPacket; - -}; - -#endif /* defined(__hifi__Transmitter__) */ diff --git a/libraries/shared/src/PacketHeaders.h b/libraries/shared/src/PacketHeaders.h index 075598d2a9..0122e36a61 100644 --- a/libraries/shared/src/PacketHeaders.h +++ b/libraries/shared/src/PacketHeaders.h @@ -17,6 +17,8 @@ #include "UUID.h" +// NOTE: if adding a new packet type, you can replace one marked usable or add at the end + enum PacketType { PacketTypeUnknown, PacketTypeStunResponse, @@ -30,7 +32,7 @@ enum PacketType { PacketTypeMicrophoneAudioNoEcho, PacketTypeMicrophoneAudioWithEcho, PacketTypeBulkAvatarData, - PacketTypeTransmitterData, + PacketTypeTransmitterData, // usable PacketTypeEnvironmentData, PacketTypeDomainListRequest, PacketTypeRequestAssignment,