From 570dfba934fccdbe349d5371cdcda6a4efd24114 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Mon, 20 May 2013 16:12:38 -0700 Subject: [PATCH] code review comments, cleanup Avatar constructor --- interface/src/Application.cpp | 16 ------ interface/src/Avatar.cpp | 85 +++++++++++++++--------------- interface/src/Avatar.h | 4 +- libraries/avatars/src/HeadData.cpp | 22 -------- libraries/avatars/src/HeadData.h | 13 +++-- 5 files changed, 54 insertions(+), 86 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 7c577589f9..88c41665ee 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -1356,22 +1356,6 @@ void Application::updateAvatar(float deltaTime) { _headMouseY = max(_headMouseY, 0); _headMouseY = min(_headMouseY, _glWidget->height()); - // Update head and body pitch and yaw based on measured gyro rates - if (_gyroLook->isChecked()) { - // Render Yaw - /* NOTE: PER - Leave here until I get back and can modify to couple gyros to head pitch, yaw - float renderYawSpring = fabs(_headMouseX - _glWidget->width() / 2.f) / (_glWidget->width() / 2.f); - const float RENDER_YAW_MULTIPLY = 4.f; - _myAvatar.setRenderYaw((1.f - renderYawSpring * deltaTime) * _myAvatar.getRenderYaw() + - renderYawSpring * deltaTime * -_myAvatar.getHeadYaw() * RENDER_YAW_MULTIPLY); - // Render Pitch - float renderPitchSpring = fabs(_headMouseY - _glWidget->height() / 2.f) / (_glWidget->height() / 2.f); - const float RENDER_PITCH_MULTIPLY = 4.f; - _myAvatar.setRenderPitch((1.f - renderPitchSpring * deltaTime) * _myAvatar.getRenderPitch() + - renderPitchSpring * deltaTime * -_myAvatar.getHeadPitch() * RENDER_PITCH_MULTIPLY); - */ - } - if (OculusManager::isConnected()) { float yaw, pitch, roll; OculusManager::getEulerAngles(yaw, pitch, roll); diff --git a/interface/src/Avatar.cpp b/interface/src/Avatar.cpp index cc41e0d585..d4e6ae0a8b 100644 --- a/interface/src/Avatar.cpp +++ b/interface/src/Avatar.cpp @@ -59,61 +59,62 @@ bool usingBigSphereCollisionTest = true; float chatMessageScale = 0.0015; float chatMessageHeight = 0.45; -Avatar::Avatar(bool isMine) : _head() { +Avatar::Avatar(bool isMine) : + _isMine(isMine), + _TEST_bigSphereRadius(0.4f), + _TEST_bigSpherePosition(5.0f, _TEST_bigSphereRadius, 5.0f), + _mousePressed(false), + _bodyPitchDelta(0.0f), + _bodyYawDelta(0.0f), + _bodyRollDelta(0.0f), + _movedHandOffset(0.0f, 0.0f, 0.0f), + _rotation(0.0f, 0.0f, 0.0f, 0.0f), + _mode(AVATAR_MODE_STANDING), + _handHoldingPosition(0.0f, 0.0f, 0.0f), + _velocity(0.0f, 0.0f, 0.0f), + _thrust(0.0f, 0.0f, 0.0f), + _speed(0.0f), + _maxArmLength(0.0f), + _orientation(), + _transmitterIsFirstData(true), + _transmitterHz(0.0f), + _transmitterPackets(0), + _transmitterInitialReading(0.0f, 0.0f, 0.0f), + _isTransmitterV2Connected(false), + _pelvisStandingHeight(0.0f), + _displayingHead(true), + _distanceToNearestAvatar(std::numeric_limits::max()), + _gravity(0.0f, -1.0f, 0.0f), + _mouseRayOrigin(0.0f, 0.0f, 0.0f), + _mouseRayDirection(0.0f, 0.0f, 0.0f), + _cameraPosition(0.0f, 0.0f, 0.0f), + _interactingOther(NULL), + _cumulativeMouseYaw(0.0f), + _isMouseTurningRight(false) +{ // give the pointer to our head to inherited _headData variable from AvatarData _headData = &_head; - - _orientation.setToIdentity(); - - _velocity = glm::vec3(0.0f, 0.0f, 0.0f); - _thrust = glm::vec3(0.0f, 0.0f, 0.0f); - _rotation = glm::quat(0.0f, 0.0f, 0.0f, 0.0f); - _bodyYaw = -90.0; - _bodyPitch = 0.0; - _bodyRoll = 0.0; - _bodyPitchDelta = 0.0; - _bodyYawDelta = 0.0; - _bodyRollDelta = 0.0; - _mousePressed = false; - _mode = AVATAR_MODE_STANDING; - _isMine = isMine; - _maxArmLength = 0.0; - _transmitterHz = 0.0; - _transmitterPackets = 0; - _transmitterIsFirstData = true; - _transmitterInitialReading = glm::vec3(0.f, 0.f, 0.f); - _isTransmitterV2Connected = false; - _speed = 0.0; - _pelvisStandingHeight = 0.0f; - _displayingHead = true; - _TEST_bigSphereRadius = 0.4f; - _TEST_bigSpherePosition = glm::vec3(5.0f, _TEST_bigSphereRadius, 5.0f); - _mouseRayOrigin = glm::vec3(0.0f, 0.0f, 0.0f); - _mouseRayDirection = glm::vec3(0.0f, 0.0f, 0.0f); - _cameraPosition = glm::vec3(0.0f, 0.0f, 0.0f); - _interactingOther = NULL; - for (int i = 0; i < MAX_DRIVE_KEYS; i++) _driveKeys[i] = false; - - _movedHandOffset = glm::vec3(0.0f, 0.0f, 0.0f); - _handHoldingPosition = glm::vec3(0.0f, 0.0f, 0.0f); - _distanceToNearestAvatar = std::numeric_limits::max(); - _gravity = glm::vec3(0.0f, -1.0f, 0.0f); - _cumulativeMouseYaw = 0.f; - _isMouseTurningRight = false; + + for (int i = 0; i < MAX_DRIVE_KEYS; i++) { + _driveKeys[i] = false; + } initializeSkeleton(); _avatarTouch.setReachableRadius(PERIPERSONAL_RADIUS); - if (BALLS_ON) { _balls = new Balls(100); } - else { _balls = NULL; } + if (BALLS_ON) { + _balls = new Balls(100); + } else { + _balls = NULL; + } } Avatar::~Avatar() { - // if _balls is something that's sticking around other than Philip playing around it needs to be delete here too _headData = NULL; + delete _balls; } void Avatar::reset() { diff --git a/interface/src/Avatar.h b/interface/src/Avatar.h index 90735c5876..5e2ce0fd47 100644 --- a/interface/src/Avatar.h +++ b/interface/src/Avatar.h @@ -165,8 +165,8 @@ private: Head _head; bool _isMine; - glm::vec3 _TEST_bigSpherePosition; float _TEST_bigSphereRadius; + glm::vec3 _TEST_bigSpherePosition; bool _mousePressed; float _bodyPitchDelta; float _bodyYawDelta; @@ -182,8 +182,6 @@ private: float _maxArmLength; Orientation _orientation; int _driveKeys[MAX_DRIVE_KEYS]; - float _renderYaw; - float _renderPitch; // Pitch from view frustum when this is own head bool _transmitterIsFirstData; timeval _transmitterTimeLastReceived; timeval _transmitterTimer; diff --git a/libraries/avatars/src/HeadData.cpp b/libraries/avatars/src/HeadData.cpp index c95f1b68e9..bc400b96bb 100644 --- a/libraries/avatars/src/HeadData.cpp +++ b/libraries/avatars/src/HeadData.cpp @@ -17,28 +17,6 @@ HeadData::HeadData() : } -void HeadData::setYaw(float yaw) { - const float MAX_YAW = 85; - const float MIN_YAW = -85; - - _yaw = glm::clamp(yaw, MIN_YAW, MAX_YAW); -} - -void HeadData::setPitch(float pitch) { - // set head pitch and apply limits - const float MAX_PITCH = 60; - const float MIN_PITCH = -60; - - _pitch = glm::clamp(pitch, MIN_PITCH, MAX_PITCH); -} - -void HeadData::setRoll(float roll) { - const float MAX_ROLL = 50; - const float MIN_ROLL = -50; - - _roll = glm::clamp(roll, MIN_ROLL, MAX_ROLL); -} - void HeadData::addYaw(float yaw) { setYaw(_yaw + yaw); } diff --git a/libraries/avatars/src/HeadData.h b/libraries/avatars/src/HeadData.h index eca16ef6b0..7da3085fe7 100644 --- a/libraries/avatars/src/HeadData.h +++ b/libraries/avatars/src/HeadData.h @@ -13,18 +13,25 @@ #include +const float MIN_HEAD_YAW = -85; +const float MAX_HEAD_YAW = 85; +const float MIN_HEAD_PITCH = -60; +const float MAX_HEAD_PITCH = 60; +const float MIN_HEAD_ROLL = -50; +const float MAX_HEAD_ROLL = 50; + class HeadData { public: HeadData(); float getYaw() const { return _yaw; } - void setYaw(float yaw); + void setYaw(float yaw) { _yaw = glm::clamp(yaw, MIN_HEAD_YAW, MAX_HEAD_YAW); } float getPitch() const { return _pitch; } - void setPitch(float pitch); + void setPitch(float pitch) { _pitch = glm::clamp(pitch, MIN_HEAD_PITCH, MAX_HEAD_PITCH); } float getRoll() const { return _roll; } - void setRoll(float roll); + void setRoll(float roll) { _roll = glm::clamp(roll, MIN_HEAD_ROLL, MAX_HEAD_ROLL); } void addYaw(float yaw); void addPitch(float pitch);