From 5f514642305d1d7b617cca4b93aa753a32630270 Mon Sep 17 00:00:00 2001 From: Philip Rosedale Date: Wed, 17 Jul 2013 17:15:19 -0700 Subject: [PATCH 01/20] Start clicking on voxels makes sound --- interface/src/Application.cpp | 37 +++++++++++++++++++++++++++++++---- interface/src/Application.h | 6 +++++- 2 files changed, 38 insertions(+), 5 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 582bc4fcb4..a87564cf2e 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -197,6 +197,8 @@ Application::Application(int& argc, char** argv, timeval &startup_time) : _pitchFromTouch(0.0f), _groundPlaneImpact(0.0f), _mousePressed(false), + _isHoverVoxel(false), + _isHoverVoxelSounding(false), _mouseVoxelScale(1.0f / 1024.0f), _justEditedVoxel(false), _paintOn(false), @@ -848,6 +850,15 @@ void Application::mousePressEvent(QMouseEvent* event) { _mouseVoxelDragging = _mouseVoxel; _mousePressed = true; maybeEditVoxelUnderCursor(); + if (_isHoverVoxel && !_isHoverVoxelSounding) { + _hoverVoxelOriginalColor[0] = _hoverVoxel.red; + _hoverVoxelOriginalColor[1] = _hoverVoxel.green; + _hoverVoxelOriginalColor[2] = _hoverVoxel.blue; + _hoverVoxelOriginalColor[3] = 1; + _audio.startCollisionSound(1.0, 220, 0.0, 0.999f); + qDebug("s = %f\n", _hoverVoxel.s); + _isHoverVoxelSounding = true; + } } else if (event->button() == Qt::RightButton && checkedVoxelModeAction() != 0) { deleteVoxelUnderCursor(); @@ -1927,7 +1938,27 @@ void Application::update(float deltaTime) { glm::vec3 myLookAtFromMouse(mouseRayOrigin + mouseRayDirection); _myAvatar.getHead().setLookAtPosition(myLookAtFromMouse); } - + + // Find the voxel we are hovering over, and respond if clicked + float distance; + BoxFace face; + + // If we have clicked on a voxel, update it's color + if (_isHoverVoxelSounding) { + qDebug("clicking on voxel\n"); + VoxelNode* hoveredNode = _voxels.getVoxelAt(_hoverVoxel.x, _hoverVoxel.y, _hoverVoxel.z, _hoverVoxel.s); + nodeColor clickColor = { 1, 0, 0, 1 }; + float bright = _audio.getCollisionSoundMagnitude(); + hoveredNode->setColor(clickColor); + if (bright < 0.01f) { + hoveredNode->setColor(_hoverVoxelOriginalColor); + _isHoverVoxelSounding = false; + } + } else { + // Check for a new hover voxel + _isHoverVoxel = _voxels.findRayIntersection(mouseRayOrigin, mouseRayDirection, _hoverVoxel, distance, face); + } + // If we are dragging on a voxel, add thrust according to the amount the mouse is dragging const float VOXEL_GRAB_THRUST = 0.0f; if (_mousePressed && (_mouseVoxel.s != 0)) { @@ -1953,8 +1984,6 @@ void Application::update(float deltaTime) { (fabs(_myAvatar.getVelocity().x) + fabs(_myAvatar.getVelocity().y) + fabs(_myAvatar.getVelocity().z)) / 3 < MAX_AVATAR_EDIT_VELOCITY) { - float distance; - BoxFace face; if (_voxels.findRayIntersection(mouseRayOrigin, mouseRayDirection, _mouseVoxel, distance, face)) { if (distance < MAX_VOXEL_EDIT_DISTANCE) { // find the nearest voxel with the desired scale @@ -2140,7 +2169,7 @@ void Application::update(float deltaTime) { } void Application::updateAvatar(float deltaTime) { - + // When head is rotated via touch/mouse look, slowly turn body to follow const float BODY_FOLLOW_HEAD_RATE = 0.5f; // update body yaw by body yaw delta diff --git a/interface/src/Application.h b/interface/src/Application.h index 9333808a27..1f65ea7586 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -358,8 +358,12 @@ private: glm::vec3 _voxelThrust; bool _mousePressed; // true if mouse has been pressed (clear when finished) + VoxelDetail _hoverVoxel; // Stuff about the voxel I am hovering or clicking + bool _isHoverVoxel; + bool _isHoverVoxelSounding; + nodeColor _hoverVoxelOriginalColor; - VoxelDetail _mouseVoxel; // details of the voxel under the mouse cursor + VoxelDetail _mouseVoxel; // details of the voxel to be edited float _mouseVoxelScale; // the scale for adding/removing voxels glm::vec3 _lastMouseVoxelPos; // the position of the last mouse voxel edit bool _justEditedVoxel; // set when we've just added/deleted/colored a voxel From 0b101699152dc48f4a63b2b644bb78fb2fd2e9df Mon Sep 17 00:00:00 2001 From: Philip Rosedale Date: Thu, 18 Jul 2013 11:13:16 -0700 Subject: [PATCH 02/20] More audio collision on hover experiments --- interface/src/Application.cpp | 18 ++++++++++++++---- interface/src/Head.cpp | 4 ++-- interface/src/Physics.cpp | 4 ++++ 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 2001ba5d71..0cff3f0966 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -855,8 +855,7 @@ void Application::mousePressEvent(QMouseEvent* event) { _hoverVoxelOriginalColor[1] = _hoverVoxel.green; _hoverVoxelOriginalColor[2] = _hoverVoxel.blue; _hoverVoxelOriginalColor[3] = 1; - _audio.startCollisionSound(1.0, 220, 0.0, 0.999f); - qDebug("s = %f\n", _hoverVoxel.s); + _audio.startCollisionSound(1.0, 14080 * _hoverVoxel.s * TREE_SCALE, 0.0, 0.999f); _isHoverVoxelSounding = true; } @@ -1945,10 +1944,11 @@ void Application::update(float deltaTime) { // If we have clicked on a voxel, update it's color if (_isHoverVoxelSounding) { - qDebug("clicking on voxel\n"); VoxelNode* hoveredNode = _voxels.getVoxelAt(_hoverVoxel.x, _hoverVoxel.y, _hoverVoxel.z, _hoverVoxel.s); - nodeColor clickColor = { 1, 0, 0, 1 }; float bright = _audio.getCollisionSoundMagnitude(); + nodeColor clickColor = { 255 * bright + _hoverVoxelOriginalColor[0] * (1.f - bright), + _hoverVoxelOriginalColor[1] * (1.f - bright), + _hoverVoxelOriginalColor[2] * (1.f - bright), 1 }; hoveredNode->setColor(clickColor); if (bright < 0.01f) { hoveredNode->setColor(_hoverVoxelOriginalColor); @@ -1956,7 +1956,17 @@ void Application::update(float deltaTime) { } } else { // Check for a new hover voxel + glm::vec4 oldVoxel(_hoverVoxel.x, _hoverVoxel.y, _hoverVoxel.z, _hoverVoxel.s); _isHoverVoxel = _voxels.findRayIntersection(mouseRayOrigin, mouseRayDirection, _hoverVoxel, distance, face); + if (_isHoverVoxel && glm::vec4(_hoverVoxel.x, _hoverVoxel.y, _hoverVoxel.z, _hoverVoxel.s) != oldVoxel) { + //qDebug("bing! x,y,z = %f,%f,%f\n", _hoverVoxel.x, _hoverVoxel.y, _hoverVoxel.z); + _hoverVoxelOriginalColor[0] = _hoverVoxel.red; + _hoverVoxelOriginalColor[1] = _hoverVoxel.green; + _hoverVoxelOriginalColor[2] = _hoverVoxel.blue; + _hoverVoxelOriginalColor[3] = 1; + _audio.startCollisionSound(1.0, 14080 * _hoverVoxel.s * TREE_SCALE, 0.0, 0.992f); + _isHoverVoxelSounding = true; + } } // If we are dragging on a voxel, add thrust according to the amount the mouse is dragging diff --git a/interface/src/Head.cpp b/interface/src/Head.cpp index 84ae9fffe9..bd73753b70 100644 --- a/interface/src/Head.cpp +++ b/interface/src/Head.cpp @@ -227,8 +227,8 @@ void Head::simulate(float deltaTime, bool isMine) { const float CAMERA_FOLLOW_HEAD_RATE_MAX = 0.5f; const float CAMERA_FOLLOW_HEAD_RATE_RAMP_RATE = 1.05f; const float CAMERA_STOP_TOLERANCE_DEGREES = 0.1f; - const float CAMERA_PITCH_START_TOLERANCE_DEGREES = 10.0f; - const float CAMERA_YAW_START_TOLERANCE_DEGREES = 3.0f; + const float CAMERA_PITCH_START_TOLERANCE_DEGREES = 20.0f; + const float CAMERA_YAW_START_TOLERANCE_DEGREES = 10.0f; float cameraHeadAngleDifference = glm::length(glm::vec2(_pitch - _cameraPitch, _yaw - _cameraYaw)); if (_isCameraMoving) { _cameraFollowHeadRate = glm::clamp(_cameraFollowHeadRate * CAMERA_FOLLOW_HEAD_RATE_RAMP_RATE, diff --git a/interface/src/Physics.cpp b/interface/src/Physics.cpp index 31e64ccad3..101087b1ef 100644 --- a/interface/src/Physics.cpp +++ b/interface/src/Physics.cpp @@ -38,3 +38,7 @@ void applyDamping(float deltaTime, glm::vec3& velocity, float linearStrength, fl } } +void applyDampedSpring(float deltaTime, glm::vec3& velocity, glm::vec3& position, glm::vec3& targetPosition, float k, float damping) { + +} + From 4af92d46f30040288452003e2b3b82e55d618320 Mon Sep 17 00:00:00 2001 From: Philip Rosedale Date: Thu, 18 Jul 2013 16:50:37 -0700 Subject: [PATCH 03/20] Set lookAt to hovered voxel --- interface/src/Application.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 0cff3f0966..0b4b36eda1 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -1933,7 +1933,12 @@ void Application::update(float deltaTime) { // If the mouse is over another avatar's head... glm::vec3 myLookAtFromMouse(eyePosition); _myAvatar.getHead().setLookAtPosition(myLookAtFromMouse); + } else if (_isHoverVoxel) { + // Look at the hovered voxel + glm::vec3 lookAtSpot = getMouseVoxelWorldCoordinates(_hoverVoxel); + _myAvatar.getHead().setLookAtPosition(lookAtSpot); } else { + // Just look in direction of the mouse ray glm::vec3 myLookAtFromMouse(mouseRayOrigin + mouseRayDirection); _myAvatar.getHead().setLookAtPosition(myLookAtFromMouse); } From 72774a5e20535eac600b114ee98686df80d65cd1 Mon Sep 17 00:00:00 2001 From: atlante45 Date: Fri, 19 Jul 2013 17:01:38 -0700 Subject: [PATCH 04/20] First step toward pie menus --- interface/src/Application.cpp | 19 ++++++- interface/src/Application.h | 5 +- interface/src/PieMenu.cpp | 97 +++++++++++++++++++++++++++++++++++ interface/src/PieMenu.h | 48 +++++++++++++++++ 4 files changed, 166 insertions(+), 3 deletions(-) create mode 100644 interface/src/PieMenu.cpp create mode 100644 interface/src/PieMenu.h diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index adb88147e9..632eb12404 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -835,6 +835,8 @@ void Application::mouseMoveEvent(QMouseEvent* event) { deleteVoxelUnderCursor(); } } + + _pieMenu.mouseMoveEvent(_mouseX, _mouseY); } } @@ -847,7 +849,10 @@ void Application::mousePressEvent(QMouseEvent* event) { _mouseDragStartedY = _mouseY; _mouseVoxelDragging = _mouseVoxel; _mousePressed = true; - maybeEditVoxelUnderCursor(); + + if (!maybeEditVoxelUnderCursor()) { + _pieMenu.mousePressEvent(_mouseX, _mouseY); + } } else if (event->button() == Qt::RightButton && checkedVoxelModeAction() != 0) { deleteVoxelUnderCursor(); @@ -862,6 +867,8 @@ void Application::mouseReleaseEvent(QMouseEvent* event) { _mouseY = event->y(); _mousePressed = false; checkBandwidthMeterClick(); + + _pieMenu.mouseReleaseEvent(_mouseX, _mouseY); } } } @@ -2740,6 +2747,10 @@ void Application::displayOverlay() { _swatch.checkColor(); } + if (_pieMenu.isDisplayed()) { + _pieMenu.render(); + } + glPopMatrix(); } @@ -3147,7 +3158,7 @@ void Application::shiftPaintingColor() { } -void Application::maybeEditVoxelUnderCursor() { +bool Application::maybeEditVoxelUnderCursor() { if (_addVoxelMode->isChecked() || _colorVoxelMode->isChecked()) { if (_mouseVoxel.s != 0) { PACKET_TYPE message = (_destructiveAddVoxel->isChecked() ? @@ -3218,7 +3229,11 @@ void Application::maybeEditVoxelUnderCursor() { deleteVoxelUnderCursor(); } else if (_eyedropperMode->isChecked()) { eyedropperVoxelUnderCursor(); + } else { + return false; } + + return true; } void Application::deleteVoxelUnderCursor() { diff --git a/interface/src/Application.h b/interface/src/Application.h index 9333808a27..f5f9c17883 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -42,6 +42,7 @@ #include "ViewFrustum.h" #include "VoxelSystem.h" #include "Webcam.h" +#include "PieMenu.h" class QAction; @@ -208,7 +209,7 @@ private: void setupPaintingVoxel(); void shiftPaintingColor(); - void maybeEditVoxelUnderCursor(); + bool maybeEditVoxelUnderCursor(); void deleteVoxelUnderCursor(); void eyedropperVoxelUnderCursor(); void resetSensors(); @@ -406,6 +407,8 @@ private: ToolsPalette _palette; Swatch _swatch; + + PieMenu _pieMenu; }; #endif /* defined(__interface__Application__) */ diff --git a/interface/src/PieMenu.cpp b/interface/src/PieMenu.cpp new file mode 100644 index 0000000000..73be3d12c3 --- /dev/null +++ b/interface/src/PieMenu.cpp @@ -0,0 +1,97 @@ +// +// PieMenu.cpp +// hifi +// +// Created by Clement Brisset on 7/18/13. +// Copyright (c) 2013 High Fidelity, Inc. All rights reserved. +// + +#include "PieMenu.h" + +#include + +#include +#include + +PieMenu::PieMenu() : + _radiusIntern(30), + _radiusExtern(70), + _isDisplayed(false) { + + addAction(NULL); + addAction(NULL); + addAction(NULL); + addAction(NULL); + addAction(NULL); +} + +void PieMenu::init(const char *fileName, int screenWidth, int screenHeight) { + +} + +void PieMenu::addAction(QAction* action){ + _actions.push_back(action); +} + +void PieMenu::render() { + if (_actions.size() == 0) { + return; + } + + float start = M_PI / 2.0f; + float end = start + 2.0f * M_PI; + float step = 2.0f * M_PI / 100.0f; + float distance = sqrt((_mouseX - _x) * (_mouseX - _x) + + (_mouseY - _y) * (_mouseY - _y)); + + glBegin(GL_QUAD_STRIP); + glColor3f(1.0f, 1.0f, 1.0f); + for (float i = start; i < end; i += step) { + glVertex2f(_x + _radiusIntern * cos(i), _y + _radiusIntern * sin(i)); + glVertex2f(_x + _radiusExtern * cos(i), _y + _radiusExtern * sin(i)); + } + glVertex2f(_x + _radiusIntern * cos(end), _y + _radiusIntern * sin(end)); + glVertex2f(_x + _radiusExtern * cos(end), _y + _radiusExtern * sin(end)); + glEnd(); + + if (_radiusIntern < distance) { + float angle = atan2((_mouseY - _y), (_mouseX - _x)) - start; + angle = (0.0f < angle) ? angle : angle + 2.0f * M_PI; + + _selectedAction = floor(angle / (2.0f * M_PI / _actions.size())); + + start = start + _selectedAction * 2.0f * M_PI / _actions.size(); + end = start + 2.0f * M_PI / _actions.size(); + glBegin(GL_QUAD_STRIP); + glColor3f(0.0f, 0.0f, 0.0f); + for (float i = start; i < end; i += step) { + glVertex2f(_x + _radiusIntern * cos(i), _y + _radiusIntern * sin(i)); + glVertex2f(_x + _radiusExtern * cos(i), _y + _radiusExtern * sin(i)); + } + glVertex2f(_x + _radiusIntern * cos(end), _y + _radiusIntern * sin(end)); + glVertex2f(_x + _radiusExtern * cos(end), _y + _radiusExtern * sin(end)); + glEnd(); + } else { + _selectedAction = -1; + } +} + +void PieMenu::resize(int screenWidth, int screenHeight) { +} + +void PieMenu::mouseMoveEvent(int x, int y) { + _mouseX = x; + _mouseY = y; +} + +void PieMenu::mousePressEvent(int x, int y) { + _x = _mouseX = x; + _y = _mouseY = y; + _isDisplayed = true; +} + +void PieMenu::mouseReleaseEvent(int x, int y) { + // TODO + + _isDisplayed = false; +} diff --git a/interface/src/PieMenu.h b/interface/src/PieMenu.h new file mode 100644 index 0000000000..0323af8f94 --- /dev/null +++ b/interface/src/PieMenu.h @@ -0,0 +1,48 @@ +// +// PieMenu.h +// hifi +// +// Created by Clement Brisset on 7/18/13. +// Copyright (c) 2013 High Fidelity, Inc. All rights reserved. +// + +#ifndef __hifi__PieMenu__ +#define __hifi__PieMenu__ + +#include + +class QAction; + +class PieMenu { +public: + PieMenu(); + + void init(const char* fileName, int screenWidth, int screenHeight); + void addAction(QAction* action); + void render(); + void resize(int screenWidth, int screenHeight); + + bool isDisplayed() const {return _isDisplayed;} + + void mouseMoveEvent (int x, int y); + void mousePressEvent (int x, int y); + void mouseReleaseEvent(int x, int y); + +private: + // position of the menu + int _x; + int _y; + int _radiusIntern; + int _radiusExtern; + + int _mouseX; + int _mouseY; + + int _selectedAction; + + bool _isDisplayed; + + std::vector _actions; +}; + +#endif /* defined(__hifi__PieMenu__) */ From fc3aa2da9b5aebad18f5cc66ed92a480300c3506 Mon Sep 17 00:00:00 2001 From: atlante45 Date: Fri, 19 Jul 2013 17:02:45 -0700 Subject: [PATCH 05/20] Fixed typo in Tags.cpp top comments --- libraries/voxels/src/Tags.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/voxels/src/Tags.cpp b/libraries/voxels/src/Tags.cpp index e6875f36a6..7df6f227ad 100644 --- a/libraries/voxels/src/Tags.cpp +++ b/libraries/voxels/src/Tags.cpp @@ -1,5 +1,5 @@ // -// Tags.h +// Tags.cpp // hifi // // Created by Clement Brisset on 7/3/13. From 177471e83ba0ac310c8b7d73b4a9a58576932e1d Mon Sep 17 00:00:00 2001 From: atlante45 Date: Wed, 24 Jul 2013 11:24:28 -0700 Subject: [PATCH 06/20] First step toward follow mode --- interface/src/Application.cpp | 14 +++++++++++++- interface/src/Application.h | 4 ++++ interface/src/avatar/Avatar.cpp | 6 ++++++ interface/src/avatar/Avatar.h | 24 ++++++++++++------------ 4 files changed, 35 insertions(+), 13 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index ed47262942..9edfeafcbf 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -1982,7 +1982,14 @@ void Application::init() { _palette.addTool(&_swatch); _palette.addAction(_colorVoxelMode, 0, 2); _palette.addAction(_eyedropperMode, 0, 3); - _palette.addAction(_selectVoxelMode, 0, 4); + _palette.addAction(_selectVoxelMode, 0, 4); + + _pieMenu.init("./resources/images/hifi-interface-tools-v2-pie.svg", + _glWidget->width(), + _glWidget->height()); + _followMode = new QAction(this); + connect(_followMode, SIGNAL(triggered()), this, SLOT(toggleFollowMode())); + _pieMenu.addAction(_followMode); } @@ -3400,6 +3407,11 @@ void Application::goHome() { _myAvatar.setPosition(START_LOCATION); } + +void Application::toggleFollowMode() { + +} + void Application::resetSensors() { _headMouseX = _mouseX = _glWidget->width() / 2; _headMouseY = _mouseY = _glWidget->height() / 2; diff --git a/interface/src/Application.h b/interface/src/Application.h index 66f17dd9cb..6bc9c2acc2 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -189,6 +189,8 @@ private slots: glm::vec2 getScaledScreenPoint(glm::vec2 projectedPoint); void goHome(); + void toggleFollowMode(); + private: static void controlledBroadcastToNodes(unsigned char* broadcastData, size_t dataBytes, @@ -292,6 +294,8 @@ private: QAction* _simulateLeapHand; // When there's no Leap, use this to pretend there is one and feed fake hand data QAction* _testRaveGlove; // Test fancy sparkle-rave-glove mode + + QAction* _followMode; BandwidthMeter _bandwidthMeter; BandwidthDialog* _bandwidthDialog; diff --git a/interface/src/avatar/Avatar.cpp b/interface/src/avatar/Avatar.cpp index c2a2d5aadd..a23c082cca 100755 --- a/interface/src/avatar/Avatar.cpp +++ b/interface/src/avatar/Avatar.cpp @@ -446,6 +446,12 @@ void Avatar::updateThrust(float deltaTime, Transmitter * transmitter) { _isThrustOn = (glm::length(_thrust) > EPSILON); } +void Avatar::follow(Avatar* leadingAvatar) { + _leadingAvatar = leadingAvatar; + + +} + void Avatar::simulate(float deltaTime, Transmitter* transmitter) { glm::quat orientation = getOrientation(); diff --git a/interface/src/avatar/Avatar.h b/interface/src/avatar/Avatar.h index ec0d5a2ce5..ddec983d97 100755 --- a/interface/src/avatar/Avatar.h +++ b/interface/src/avatar/Avatar.h @@ -114,6 +114,7 @@ public: void reset(); void simulate(float deltaTime, Transmitter* transmitter); void updateThrust(float deltaTime, Transmitter * transmitter); + void follow(Avatar* leadingAvatar); void updateFromGyrosAndOrWebcam(bool gyroLook, const glm::vec3& amplifyAngle, float yawFromTouch, @@ -157,18 +158,16 @@ public: float getElapsedTimeMoving () const { return _elapsedTimeMoving;} float getElapsedTimeSinceCollision() const { return _elapsedTimeSinceCollision;} const glm::vec3& getLastCollisionPosition () const { return _lastCollisionPosition;} - float getAbsoluteHeadYaw () const; - float getAbsoluteHeadPitch () const; - Head& getHead () {return _head; } - Hand& getHand () {return _hand; } - glm::quat getOrientation () const; - glm::quat getWorldAlignedOrientation() const; - - const glm::vec3& getMouseRayOrigin() const { return _mouseRayOrigin; } - const glm::vec3& getMouseRayDirection() const { return _mouseRayDirection; } - - - glm::vec3 getGravity () const { return _gravity; } + float getAbsoluteHeadYaw () const; + float getAbsoluteHeadPitch () const; + Head& getHead () {return _head; } + Hand& getHand () {return _hand; } + glm::quat getOrientation () const; + glm::quat getWorldAlignedOrientation() const; + const glm::vec3& getMouseRayOrigin () const { return _mouseRayOrigin; } + const glm::vec3& getMouseRayDirection () const { return _mouseRayDirection; } + Avatar* getLeadingAvatar () const {return _leadingAvatar; } + glm::vec3 getGravity () const { return _gravity; } glm::vec3 getUprightHeadPosition() const; @@ -254,6 +253,7 @@ private: glm::vec3 _lastCollisionPosition; bool _speedBrakes; bool _isThrustOn; + Avatar* _leadingAvatar; AvatarVoxelSystem _voxels; From d165891fe6c770bec9d39b8d189b15635a823f6e Mon Sep 17 00:00:00 2001 From: atlante45 Date: Wed, 24 Jul 2013 12:38:35 -0700 Subject: [PATCH 07/20] New design for pie menus --- interface/src/Application.cpp | 6 ++- interface/src/PieMenu.cpp | 83 ++++++++++++++++++++++++++--------- interface/src/PieMenu.h | 17 +++++-- 3 files changed, 80 insertions(+), 26 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index ed47262942..0245585e42 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -1982,7 +1982,11 @@ void Application::init() { _palette.addTool(&_swatch); _palette.addAction(_colorVoxelMode, 0, 2); _palette.addAction(_eyedropperMode, 0, 3); - _palette.addAction(_selectVoxelMode, 0, 4); + _palette.addAction(_selectVoxelMode, 0, 4); + + _pieMenu.init("./resources/images/hifi-interface-tools-v2-pie.svg", + _glWidget->width(), + _glWidget->height()); } diff --git a/interface/src/PieMenu.cpp b/interface/src/PieMenu.cpp index 73be3d12c3..1f79d46814 100644 --- a/interface/src/PieMenu.cpp +++ b/interface/src/PieMenu.cpp @@ -11,22 +11,47 @@ #include #include +#include +#include #include +#include PieMenu::PieMenu() : _radiusIntern(30), _radiusExtern(70), + _magnification(1.2f), _isDisplayed(false) { - - addAction(NULL); - addAction(NULL); - addAction(NULL); - addAction(NULL); - addAction(NULL); } void PieMenu::init(const char *fileName, int screenWidth, int screenHeight) { + // Load SVG + switchToResourcesParentIfRequired(); + QSvgRenderer renderer((QString) QString(fileName)); + // Prepare a QImage with desired characteritisc + QImage image(2 * _radiusExtern, 2 * _radiusExtern, QImage::Format_ARGB32); + image.fill(0x0); + + // Get QPainter that paints to the image + QPainter painter(&image); + renderer.render(&painter); + + //get the OpenGL-friendly image + _textureImage = QGLWidget::convertToGLFormat(image); + + glGenTextures(1, &_textureID); + glBindTexture(GL_TEXTURE_2D, _textureID); + + //generate the texture + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, + _textureImage.width(), + _textureImage.height(), + 0, GL_RGBA, GL_UNSIGNED_BYTE, + _textureImage.bits()); + + //texture parameters + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); } void PieMenu::addAction(QAction* action){ @@ -44,15 +69,10 @@ void PieMenu::render() { float distance = sqrt((_mouseX - _x) * (_mouseX - _x) + (_mouseY - _y) * (_mouseY - _y)); - glBegin(GL_QUAD_STRIP); + glEnable(GL_TEXTURE_2D); + glBindTexture(GL_TEXTURE_2D, _textureID); + glColor3f(1.0f, 1.0f, 1.0f); - for (float i = start; i < end; i += step) { - glVertex2f(_x + _radiusIntern * cos(i), _y + _radiusIntern * sin(i)); - glVertex2f(_x + _radiusExtern * cos(i), _y + _radiusExtern * sin(i)); - } - glVertex2f(_x + _radiusIntern * cos(end), _y + _radiusIntern * sin(end)); - glVertex2f(_x + _radiusExtern * cos(end), _y + _radiusExtern * sin(end)); - glEnd(); if (_radiusIntern < distance) { float angle = atan2((_mouseY - _y), (_mouseX - _x)) - start; @@ -62,18 +82,36 @@ void PieMenu::render() { start = start + _selectedAction * 2.0f * M_PI / _actions.size(); end = start + 2.0f * M_PI / _actions.size(); - glBegin(GL_QUAD_STRIP); - glColor3f(0.0f, 0.0f, 0.0f); + glBegin(GL_TRIANGLE_FAN); + glTexCoord2f(0.5f, 0.5f); + glVertex2f(_x, _y); for (float i = start; i < end; i += step) { - glVertex2f(_x + _radiusIntern * cos(i), _y + _radiusIntern * sin(i)); - glVertex2f(_x + _radiusExtern * cos(i), _y + _radiusExtern * sin(i)); + glTexCoord2f(0.5f + 0.5f * cos(i), 0.5f - 0.5f * sin(i)); + glVertex2f(_x + _magnification * _radiusExtern * cos(i), + _y + _magnification * _radiusExtern * sin(i)); } - glVertex2f(_x + _radiusIntern * cos(end), _y + _radiusIntern * sin(end)); - glVertex2f(_x + _radiusExtern * cos(end), _y + _radiusExtern * sin(end)); + glTexCoord2f(0.5f + 0.5f * cos(end), 0.5f + - 0.5f * sin(end)); + glVertex2f(_x + _magnification * _radiusExtern * cos(end), + _y + _magnification * _radiusExtern * sin(end)); glEnd(); } else { _selectedAction = -1; + + glBegin(GL_QUADS); + glTexCoord2f(1, 1); + glVertex2f(_x + _radiusExtern, _y - _radiusExtern); + + glTexCoord2f(1, 0); + glVertex2f(_x + _radiusExtern, _y + _radiusExtern); + + glTexCoord2f(0, 0); + glVertex2f(_x - _radiusExtern, _y + _radiusExtern); + + glTexCoord2f(0, 1); + glVertex2f(_x - _radiusExtern, _y - _radiusExtern); + glEnd(); } + glDisable(GL_TEXTURE_2D); } void PieMenu::resize(int screenWidth, int screenHeight) { @@ -87,11 +125,14 @@ void PieMenu::mouseMoveEvent(int x, int y) { void PieMenu::mousePressEvent(int x, int y) { _x = _mouseX = x; _y = _mouseY = y; + _selectedAction = -1; _isDisplayed = true; } void PieMenu::mouseReleaseEvent(int x, int y) { - // TODO + if (0 <= _selectedAction && _selectedAction < _actions.size() && _actions[_selectedAction]) { + _actions[_selectedAction]->trigger(); + } _isDisplayed = false; } diff --git a/interface/src/PieMenu.h b/interface/src/PieMenu.h index 0323af8f94..863a91cb45 100644 --- a/interface/src/PieMenu.h +++ b/interface/src/PieMenu.h @@ -11,6 +11,11 @@ #include +#include "InterfaceConfig.h" +#include "Util.h" + +#include + class QAction; class PieMenu { @@ -29,11 +34,15 @@ public: void mouseReleaseEvent(int x, int y); private: + QImage _textureImage; + GLuint _textureID; + // position of the menu - int _x; - int _y; - int _radiusIntern; - int _radiusExtern; + int _x; + int _y; + int _radiusIntern; + int _radiusExtern; + float _magnification; int _mouseX; int _mouseY; From f3c87b81ec0363a42b977df1d3fa5956cfbd32bb Mon Sep 17 00:00:00 2001 From: atlante45 Date: Thu, 25 Jul 2013 16:14:47 -0700 Subject: [PATCH 08/20] Avatar can follow but don't look at the same point for the moment --- interface/src/Application.cpp | 1 - interface/src/avatar/Avatar.cpp | 47 ++++++++++++++++++++++++++++++--- interface/src/avatar/Avatar.h | 4 ++- 3 files changed, 47 insertions(+), 5 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index f3b1f4a304..c7be8c014a 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -3421,7 +3421,6 @@ void Application::toggleFollowMode() { eyePositionIgnored, nodeIDIgnored); - qDebug("[DEBUG] toggleFollowMode() %d\n", leadingAvatar); _myAvatar.follow(leadingAvatar); } diff --git a/interface/src/avatar/Avatar.cpp b/interface/src/avatar/Avatar.cpp index a613822fbf..bf9b4bb732 100755 --- a/interface/src/avatar/Avatar.cpp +++ b/interface/src/avatar/Avatar.cpp @@ -404,6 +404,32 @@ void Avatar::updateThrust(float deltaTime, Transmitter * transmitter) { _thrust += _scale * THRUST_JUMP * up; _shouldJump = false; } + + // Add thrusts from leading avatar + if (_leadingAvatar != NULL) { + glm::vec3 toTarget = _leadingAvatar->getPosition() - _position; + + if (.5f < up.x * toTarget.x + up.y * toTarget.y + up.z * toTarget.z) { + _thrust += _scale * THRUST_MAG_UP * deltaTime * up; + } else if (up.x * toTarget.x + up.y * toTarget.y + up.z * toTarget.z < -.5f) { + _thrust -= _scale * THRUST_MAG_UP * deltaTime * up; + } + + if (glm::length(_position - _leadingAvatar->getPosition()) > _scale * _stringLength) { + _thrust += _scale * THRUST_MAG_FWD * deltaTime * front; + } else { + toTarget = _leadingAvatar->getHead().getLookAtPosition(); + } + + float yawAngle = angleBetween(front, glm::vec3(toTarget.x, 0.f, toTarget.z)); + if (yawAngle < -10.f || 10.f < yawAngle){ + if (right.x * toTarget.x + right.y * toTarget.y + right.z * toTarget.z > 0) { + _bodyYawDelta -= YAW_MAG * deltaTime; + } else { + _bodyYawDelta += YAW_MAG * deltaTime; + } + } + } // Add thrusts from Transmitter if (transmitter) { @@ -448,9 +474,15 @@ void Avatar::updateThrust(float deltaTime, Transmitter * transmitter) { } void Avatar::follow(Avatar* leadingAvatar) { - _leadingAvatar = leadingAvatar; + const float MAX_STRING_LENGTH = 2; - qDebug("[DEBUG] %d\n", _leadingAvatar); + _leadingAvatar = leadingAvatar; + if (_leadingAvatar != NULL) { + _stringLength = glm::length(_position - _leadingAvatar->getPosition()) / _scale; + if (_stringLength > MAX_STRING_LENGTH) { + _stringLength = MAX_STRING_LENGTH; + } + } } void Avatar::simulate(float deltaTime, Transmitter* transmitter) { @@ -481,6 +513,13 @@ void Avatar::simulate(float deltaTime, Transmitter* transmitter) { if (isMyAvatar()) { updateThrust(deltaTime, transmitter); } + + // Ajust, scale, thrust and lookAt position when following an other avatar + if (isMyAvatar() && _leadingAvatar && _scale != _leadingAvatar->getScale()) { + float scale = 0.95f * _scale + 0.05f * _leadingAvatar->getScale(); + setScale(scale); + Application::getInstance()->getCamera()->setScale(scale); + } // copy velocity so we can use it later for acceleration glm::vec3 oldVelocity = getVelocity(); @@ -687,7 +726,9 @@ void Avatar::simulate(float deltaTime, Transmitter* transmitter) { _head.setScale(_scale); _head.setSkinColor(glm::vec3(SKIN_COLOR[0], SKIN_COLOR[1], SKIN_COLOR[2])); _head.simulate(deltaTime, isMyAvatar()); - + + + // use speed and angular velocity to determine walking vs. standing if (_speed + fabs(_bodyYawDelta) > 0.2) { _mode = AVATAR_MODE_WALKING; diff --git a/interface/src/avatar/Avatar.h b/interface/src/avatar/Avatar.h index 02f360f83f..c69cbbadbf 100755 --- a/interface/src/avatar/Avatar.h +++ b/interface/src/avatar/Avatar.h @@ -253,8 +253,10 @@ private: glm::vec3 _lastCollisionPosition; bool _speedBrakes; bool _isThrustOn; + Avatar* _leadingAvatar; - + float _stringLength; + AvatarVoxelSystem _voxels; // private methods... From 1b2f236d42d009e9b71eb2500fdcf9f557785c6d Mon Sep 17 00:00:00 2001 From: atlante45 Date: Tue, 30 Jul 2013 12:30:15 -0700 Subject: [PATCH 09/20] Follow mode operationnal --- interface/src/avatar/Avatar.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/interface/src/avatar/Avatar.cpp b/interface/src/avatar/Avatar.cpp index bf9b4bb732..f832b9276f 100755 --- a/interface/src/avatar/Avatar.cpp +++ b/interface/src/avatar/Avatar.cpp @@ -418,7 +418,8 @@ void Avatar::updateThrust(float deltaTime, Transmitter * transmitter) { if (glm::length(_position - _leadingAvatar->getPosition()) > _scale * _stringLength) { _thrust += _scale * THRUST_MAG_FWD * deltaTime * front; } else { - toTarget = _leadingAvatar->getHead().getLookAtPosition(); + toTarget = _leadingAvatar->getHead().getLookAtPosition() - _position; + getHead().setLookAtPosition(_leadingAvatar->getHead().getLookAtPosition()); } float yawAngle = angleBetween(front, glm::vec3(toTarget.x, 0.f, toTarget.z)); From 5b2693f99c9373f0be2e1a581cf16370e32418c9 Mon Sep 17 00:00:00 2001 From: Jeffrey Ventrella Date: Wed, 31 Jul 2013 17:59:15 -0700 Subject: [PATCH 10/20] added emitter active bool for switching emitters on/off when Leap loses fingers --- interface/src/ParticleSystem.cpp | 53 ++++++++++++++------------ interface/src/ParticleSystem.h | 5 ++- interface/src/avatar/Hand.cpp | 64 +++++++++++++++++++++----------- 3 files changed, 77 insertions(+), 45 deletions(-) diff --git a/interface/src/ParticleSystem.cpp b/interface/src/ParticleSystem.cpp index 5e2b92bb64..fcea8ca270 100644 --- a/interface/src/ParticleSystem.cpp +++ b/interface/src/ParticleSystem.cpp @@ -27,6 +27,7 @@ ParticleSystem::ParticleSystem() { for (unsigned int emitterIndex = 0; emitterIndex < MAX_EMITTERS; emitterIndex++) { Emitter * e = &_emitter[emitterIndex]; + e->active = false; e->position = glm::vec3(0.0f, 0.0f, 0.0f); e->previousPosition = glm::vec3(0.0f, 0.0f, 0.0f); e->direction = glm::vec3(0.0f, 1.0f, 0.0f); @@ -72,25 +73,16 @@ void ParticleSystem::simulate(float deltaTime) { _timer += deltaTime; - // emit particles - for (int e = 0; e < _numEmitters; e++) { + // update emitters + for (int emitterIndex = 0; emitterIndex < _numEmitters; emitterIndex++) { + assert(emitterIndex <= MAX_EMITTERS); - assert(e >= 0); - assert(e <= MAX_EMITTERS); - assert(_emitter[e].rate >= 0); - - _emitter[e].emitReserve += _emitter[e].rate * deltaTime; - _emitter[e].numParticlesEmittedThisTime = (int)_emitter[e].emitReserve; - _emitter[e].emitReserve -= _emitter[e].numParticlesEmittedThisTime; - - for (int p = 0; p < _emitter[e].numParticlesEmittedThisTime; p++) { - float timeFraction = (float)p / (float)_emitter[e].numParticlesEmittedThisTime; - createParticle(e, timeFraction); + if (_emitter[emitterIndex].active) { + updateEmitter(emitterIndex, deltaTime); } } - - // update particles + // update particles for (int p = 0; p < MAX_PARTICLES; p++) { if (_particle[p].alive) { if (_particle[p].age > _emitter[_particle[p].emitterIndex].particleLifespan) { @@ -102,6 +94,20 @@ void ParticleSystem::simulate(float deltaTime) { } } + +void ParticleSystem::updateEmitter(int emitterIndex, float deltaTime) { + + _emitter[emitterIndex].emitReserve += _emitter[emitterIndex].rate * deltaTime; + _emitter[emitterIndex].numParticlesEmittedThisTime = (int)_emitter[emitterIndex].emitReserve; + _emitter[emitterIndex].emitReserve -= _emitter[emitterIndex].numParticlesEmittedThisTime; + + for (int p = 0; p < _emitter[emitterIndex].numParticlesEmittedThisTime; p++) { + float timeFraction = (float)p / (float)_emitter[emitterIndex].numParticlesEmittedThisTime; + createParticle(emitterIndex, timeFraction); + } +} + + void ParticleSystem::createParticle(int e, float timeFraction) { for (unsigned int p = 0; p < MAX_PARTICLES; p++) { @@ -212,7 +218,6 @@ void ParticleSystem::setParticleAttributes(int emitterIndex, ParticleLifeStage l } - void ParticleSystem::updateParticle(int p, float deltaTime) { Emitter myEmitter = _emitter[_particle[p].emitterIndex]; @@ -363,14 +368,16 @@ void ParticleSystem::killAllParticles() { void ParticleSystem::render() { // render the emitters - for (int e = 0; e < _numEmitters; e++) { + for (int e = 0; e < MAX_EMITTERS; e++) { - if (_emitter[e].showingBaseParticle) { - glColor4f(_particle[0].color.r, _particle[0].color.g, _particle[0].color.b, _particle[0].color.a); - glPushMatrix(); - glTranslatef(_emitter[e].position.x, _emitter[e].position.y, _emitter[e].position.z); - glutSolidSphere(_particle[0].radius, _emitter[e].particleResolution, _emitter[e].particleResolution); - glPopMatrix(); + if (_emitter[e].active) { + if (_emitter[e].showingBaseParticle) { + glColor4f(_particle[0].color.r, _particle[0].color.g, _particle[0].color.b, _particle[0].color.a); + glPushMatrix(); + glTranslatef(_emitter[e].position.x, _emitter[e].position.y, _emitter[e].position.z); + glutSolidSphere(_particle[0].radius, _emitter[e].particleResolution, _emitter[e].particleResolution); + glPopMatrix(); + } } if (_emitter[e].visible) { diff --git a/interface/src/ParticleSystem.h b/interface/src/ParticleSystem.h index d79f621f69..a0131883a1 100644 --- a/interface/src/ParticleSystem.h +++ b/interface/src/ParticleSystem.h @@ -10,10 +10,10 @@ #include -const int MAX_PARTICLES = 5000; const int NULL_EMITTER = -1; const int NULL_PARTICLE = -1; const int MAX_EMITTERS = 100; +const int MAX_PARTICLES = 5000; enum ParticleRenderStyle { @@ -78,6 +78,7 @@ public: void setParticleAttributes (int emitterIndex, ParticleAttributes attributes); // set attributes for whole life of particles void setParticleAttributes (int emitterIndex, ParticleLifeStage lifeStage, ParticleAttributes attributes); // set attributes for this life stage void setEmitterPosition (int emitterIndex, glm::vec3 position ); + void setEmitterActive (int emitterIndex, bool active ) {_emitter[emitterIndex].active = active; } void setEmitterParticleResolution (int emitterIndex, int resolution ) {_emitter[emitterIndex].particleResolution = resolution; } void setEmitterDirection (int emitterIndex, glm::vec3 direction ) {_emitter[emitterIndex].direction = direction; } void setShowingEmitter (int emitterIndex, bool showing ) {_emitter[emitterIndex].visible = showing; } @@ -101,6 +102,7 @@ private: }; struct Emitter { + bool active; // if false, the emitter is disabled - allows for easy switching on and off glm::vec3 position; // the position of the emitter in world coordinates glm::vec3 previousPosition; // the position of the emitter in the previous time step glm::vec3 direction; // a normalized vector used as an axis for particle emission and other effects @@ -124,6 +126,7 @@ private: float _timer; // private methods + void updateEmitter(int emitterIndex, float deltaTime); void updateParticle(int index, float deltaTime); void createParticle(int e, float timeFraction); void killParticle(int p); diff --git a/interface/src/avatar/Hand.cpp b/interface/src/avatar/Hand.cpp index 28b1af0603..3eec1925c0 100755 --- a/interface/src/avatar/Hand.cpp +++ b/interface/src/avatar/Hand.cpp @@ -244,6 +244,7 @@ void Hand::setLeapHands(const std::vector& handPositions, } } + // call this right after the geometry of the leap hands are set void Hand::updateRaveGloveEmitters() { @@ -253,7 +254,7 @@ void Hand::updateRaveGloveEmitters() { if(debug) printf( "\n" ); if(debug) printf( "------------------------------------\n" ); - if(debug) printf( "updating rave glove emitters:\n" ); + if(debug) printf( "updating rave glove emitters: \n" ); if(debug) printf( "------------------------------------\n" ); int emitterIndex = 0; @@ -271,16 +272,16 @@ void Hand::updateRaveGloveEmitters() { for (size_t f = 0; f < palm.getNumFingers(); ++f) { FingerData& finger = palm.getFingers()[f]; - if(debug) printf( "emitterIndex %d: ", emitterIndex ); + if(debug) printf( "emitterIndex %d: ", emitterIndex ); - if (finger.isActive()) { - - if ((emitterIndex >=0) - && (emitterIndex < NUM_FINGERS)) { - - assert(emitterIndex >=0 ); - assert(emitterIndex < NUM_FINGERS ); + if ((emitterIndex >=0) + && (emitterIndex < NUM_FINGERS)) { + _raveGloveParticleSystem.setEmitterActive(_raveGloveEmitter[emitterIndex], false); // set to false by default... + + if (finger.isActive()) { + _raveGloveParticleSystem.setEmitterActive(_raveGloveEmitter[emitterIndex], true); + if(debug) printf( "_raveGloveEmitter[%d] = %d\n", emitterIndex, _raveGloveEmitter[emitterIndex] ); glm::vec3 fingerDirection = finger.getTipPosition() - finger.getRootPosition(); @@ -317,16 +318,11 @@ void Hand::updateRaveGloveParticles(float deltaTime) { if (!_raveGloveInitialized) { - //printf( "Initializing rave glove emitters:\n" ); - //printf( "The indices of the emitters are:\n" ); - // start up the rave glove finger particles... for ( int f = 0; f< NUM_FINGERS; f ++ ) { - _raveGloveEmitter[f] = _raveGloveParticleSystem.addEmitter(); + _raveGloveEmitter[f] = _raveGloveParticleSystem.addEmitter(); assert( _raveGloveEmitter[f] >= 0 ); assert( _raveGloveEmitter[f] != NULL_EMITTER ); - - //printf( "%d\n", _raveGloveEmitter[f] ); } setRaveGloveMode(RAVE_GLOVE_EFFECTS_MODE_FIRE); @@ -339,13 +335,13 @@ void Hand::updateRaveGloveParticles(float deltaTime) { // this rave glove effect oscillates though various colors and radii that are meant to show off some effects if (_raveGloveMode == RAVE_GLOVE_EFFECTS_MODE_THROBBING_COLOR) { ParticleSystem::ParticleAttributes attributes; - float red = 0.5f + 0.5f * sinf(_raveGloveClock * 1.4f); - float green = 0.5f + 0.5f * cosf(_raveGloveClock * 1.7f); - float blue = 0.5f + 0.5f * sinf(_raveGloveClock * 2.0f); + float red = 0.5f + 0.5f * sinf(_raveGloveClock * 2.4f); + float green = 0.5f + 0.5f * cosf(_raveGloveClock * 2.7f); + float blue = 0.5f + 0.5f * sinf(_raveGloveClock * 3.0f); float alpha = 1.0f; attributes.color = glm::vec4(red, green, blue, alpha); - attributes.radius = 0.01f + 0.005f * sinf(_raveGloveClock * 2.2f); + attributes.radius = 0.01f + 0.003f * sinf(_raveGloveClock * 50.0f); attributes.modulationAmplitude = 0.0f; for ( int f = 0; f< NUM_FINGERS; f ++ ) { @@ -360,6 +356,8 @@ void Hand::updateRaveGloveParticles(float deltaTime) { } } + + void Hand::setRaveGloveMode(int mode) { _raveGloveMode = mode; @@ -376,7 +374,7 @@ void Hand::setRaveGloveMode(int mode) { if (mode == RAVE_GLOVE_EFFECTS_MODE_THROBBING_COLOR) { _raveGloveParticleSystem.setParticleRenderStyle (_raveGloveEmitter[f], PARTICLE_RENDER_STYLE_SPHERE ); _raveGloveParticleSystem.setShowingEmitterBaseParticle(_raveGloveEmitter[f], true ); - _raveGloveParticleSystem.setEmitterParticleLifespan (_raveGloveEmitter[f], 0.0f ); + _raveGloveParticleSystem.setEmitterParticleLifespan (_raveGloveEmitter[f], 0.03f ); _raveGloveParticleSystem.setEmitterThrust (_raveGloveEmitter[f], 0.0f ); _raveGloveParticleSystem.setEmitterRate (_raveGloveEmitter[f], 30.0f ); _raveGloveParticleSystem.setEmitterParticleResolution (_raveGloveEmitter[f], 20 ); @@ -650,7 +648,7 @@ void Hand::setRaveGloveMode(int mode) { _raveGloveParticleSystem.setParticleAttributes(_raveGloveEmitter[f], PARTICLE_LIFESTAGE_3, attributes); //----------------------------------------- - // throb + // long sparkler //----------------------------------------- } else if (mode == RAVE_GLOVE_EFFECTS_MODE_LONG_SPARKLER) { @@ -672,6 +670,30 @@ void Hand::setRaveGloveMode(int mode) { _raveGloveParticleSystem.setParticleAttributes(_raveGloveEmitter[f], PARTICLE_LIFESTAGE_1, attributes); _raveGloveParticleSystem.setParticleAttributes(_raveGloveEmitter[f], PARTICLE_LIFESTAGE_2, attributes); _raveGloveParticleSystem.setParticleAttributes(_raveGloveEmitter[f], PARTICLE_LIFESTAGE_3, attributes); + + //----------------------------------------- + // throb + //----------------------------------------- + } else if (mode == RAVE_GLOVE_EFFECTS_MODE_THROB) { + + _raveGloveParticleSystem.setParticleRenderStyle (_raveGloveEmitter[f], PARTICLE_RENDER_STYLE_SPHERE ); + _raveGloveParticleSystem.setShowingEmitterBaseParticle(_raveGloveEmitter[f], true ); + _raveGloveParticleSystem.setEmitterParticleLifespan (_raveGloveEmitter[f], 0.03 ); + _raveGloveParticleSystem.setEmitterThrust (_raveGloveEmitter[f], 0.0f ); + _raveGloveParticleSystem.setEmitterRate (_raveGloveEmitter[f], 30.0 ); + _raveGloveParticleSystem.setEmitterParticleResolution (_raveGloveEmitter[f], 20 ); + + _raveGloveParticleSystem.setParticleAttributesToDefault(&attributes); + + attributes.radius = 0.01f; + attributes.color = glm::vec4( 0.1f, 0.2f, 0.4f, 0.5f); + attributes.modulationAmplitude = 0.5; + attributes.modulationRate = 3.0; + attributes.modulationStyle = COLOR_MODULATION_STYLE_LIGHTNESS_WAVE; + _raveGloveParticleSystem.setParticleAttributes(_raveGloveEmitter[f], PARTICLE_LIFESTAGE_0, attributes); + _raveGloveParticleSystem.setParticleAttributes(_raveGloveEmitter[f], PARTICLE_LIFESTAGE_1, attributes); + _raveGloveParticleSystem.setParticleAttributes(_raveGloveEmitter[f], PARTICLE_LIFESTAGE_2, attributes); + _raveGloveParticleSystem.setParticleAttributes(_raveGloveEmitter[f], PARTICLE_LIFESTAGE_3, attributes); } } } From 0cd1018e7624aaacc4dd80ecc8f85f354ecd718a Mon Sep 17 00:00:00 2001 From: Jeffrey Ventrella Date: Thu, 1 Aug 2013 10:53:20 -0700 Subject: [PATCH 11/20] some experimental work on hand rendering --- interface/src/avatar/Hand.cpp | 46 +++++++++++++++++++++++++++++++---- interface/src/avatar/Hand.h | 6 +++-- 2 files changed, 45 insertions(+), 7 deletions(-) diff --git a/interface/src/avatar/Hand.cpp b/interface/src/avatar/Hand.cpp index 3eec1925c0..2e409a10bf 100755 --- a/interface/src/avatar/Hand.cpp +++ b/interface/src/avatar/Hand.cpp @@ -14,7 +14,7 @@ #include "Util.h" #include "renderer/ProgramObject.h" -const bool SHOW_LEAP_HAND = false; +const bool SHOW_LEAP_HAND = true; using namespace std; @@ -120,8 +120,9 @@ void Hand::render(bool lookingInMirror) { glEnable(GL_RESCALE_NORMAL); if ( SHOW_LEAP_HAND ) { - renderFingerTrails(); - renderHandSpheres(); + renderLeapHands(); + //renderFingerTrails(); + //renderHandSpheres(); } } @@ -153,7 +154,42 @@ void Hand::renderRaveGloveStage() { } } -void Hand::renderHandSpheres() { + + +void Hand::renderLeapHands() { + for (size_t i = 0; i < getNumPalms(); ++i) { + PalmData& hand = getPalms()[i]; + if (hand.isActive()) { + renderLeapHand(hand); + } + } +} + + +void Hand::renderLeapHand(PalmData& hand) { + + glPushMatrix(); + const float palmThickness = 0.002f; + glColor4f(0.5f, 0.5f, 0.5f, 1.0); + glm::vec3 tip = hand.getPosition(); + glm::vec3 root = hand.getPosition() + hand.getNormal() * palmThickness; + Avatar::renderJointConnectingCone(root, tip, 0.05, 0.03); + + for (size_t f = 0; f < hand.getNumFingers(); ++f) { + FingerData& finger = hand.getFingers()[f]; + if (finger.isActive()) { + glColor4f(_ballColor.r, _ballColor.g, _ballColor.b, 0.5); + glm::vec3 tip = finger.getTipPosition(); + glm::vec3 root = finger.getRootPosition(); + Avatar::renderJointConnectingCone(root, tip, 0.001, 0.003); + } + } + + glPopMatrix(); +} + + +void Hand::renderLeapHandSpheres() { glPushMatrix(); // Draw the leap balls for (size_t i = 0; i < _leapBalls.size(); i++) { @@ -200,7 +236,7 @@ void Hand::renderHandSpheres() { glPopMatrix(); } -void Hand::renderFingerTrails() { +void Hand::renderLeapFingerTrails() { // Draw the finger root cones for (size_t i = 0; i < getNumPalms(); ++i) { PalmData& palm = getPalms()[i]; diff --git a/interface/src/avatar/Hand.h b/interface/src/avatar/Hand.h index a3a00beb96..2ee066d7b6 100755 --- a/interface/src/avatar/Hand.h +++ b/interface/src/avatar/Hand.h @@ -92,8 +92,10 @@ private: void renderRaveGloveStage(); void setRaveGloveMode(int mode); - void renderHandSpheres(); - void renderFingerTrails(); + void renderLeapHandSpheres(); + void renderLeapHands(); + void renderLeapHand(PalmData& hand); + void renderLeapFingerTrails(); void calculateGeometry(); }; From 1df7026b26b79216ea1b9b32f2af06ecb7335e81 Mon Sep 17 00:00:00 2001 From: Jeffrey Ventrella Date: Thu, 1 Aug 2013 10:54:09 -0700 Subject: [PATCH 12/20] merge? --- libraries/avatars/src/AvatarData.cpp | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 libraries/avatars/src/AvatarData.cpp diff --git a/libraries/avatars/src/AvatarData.cpp b/libraries/avatars/src/AvatarData.cpp old mode 100755 new mode 100644 From bc1ac6b455fb131c4a1e8afbe7553c1ca083acce Mon Sep 17 00:00:00 2001 From: Philip Rosedale Date: Thu, 1 Aug 2013 12:49:10 -0700 Subject: [PATCH 13/20] turn down collision sounds --- interface/src/Application.cpp | 9 ++++++--- interface/src/Application.h | 4 ---- interface/src/Util.cpp | 8 +++++++- interface/src/avatar/Avatar.cpp | 6 ------ 4 files changed, 13 insertions(+), 14 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index b6c2187256..8add2325d9 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -196,7 +196,6 @@ Application::Application(int& argc, char** argv, timeval &startup_time) : _isTouchPressed(false), _yawFromTouch(0.0f), _pitchFromTouch(0.0f), - _groundPlaneImpact(0.0f), _mousePressed(false), _isHoverVoxel(false), _isHoverVoxelSounding(false), @@ -2789,8 +2788,12 @@ void Application::displayOverlay() { glDisable(GL_DEPTH_TEST); glDisable(GL_LIGHTING); - // Display a single screen-size quad to - renderCollisionOverlay(_glWidget->width(), _glWidget->height(), _audio.getCollisionSoundMagnitude()); + // Display a single screen-size quad to create an alpha blended 'collision' flash + float collisionSoundMagnitude = _audio.getCollisionSoundMagnitude(); + const float VISIBLE_COLLISION_SOUND_MAGNITUDE = 0.5f; + if (collisionSoundMagnitude > VISIBLE_COLLISION_SOUND_MAGNITUDE) { + renderCollisionOverlay(_glWidget->width(), _glWidget->height(), _audio.getCollisionSoundMagnitude()); + } #ifndef _WIN32 _audio.render(_glWidget->width(), _glWidget->height()); diff --git a/interface/src/Application.h b/interface/src/Application.h index 9d3d508b72..8a4a3bf18d 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -109,8 +109,6 @@ public slots: void sendAvatarFaceVideoMessage(int frameCount, const QByteArray& data); - void setGroundPlaneImpact(float groundPlaneImpact) { _groundPlaneImpact = groundPlaneImpact; } - private slots: @@ -371,8 +369,6 @@ private: float _yawFromTouch; float _pitchFromTouch; - float _groundPlaneImpact; - VoxelDetail _mouseVoxelDragging; glm::vec3 _voxelThrust; bool _mousePressed; // true if mouse has been pressed (clear when finished) diff --git a/interface/src/Util.cpp b/interface/src/Util.cpp index 0f2c3a8955..1830a30014 100644 --- a/interface/src/Util.cpp +++ b/interface/src/Util.cpp @@ -339,6 +339,7 @@ void renderCollisionOverlay(int width, int height, float magnitude) { } void renderGroundPlaneGrid(float size, float impact) { + float IMPACT_SOUND_MAGNITUDE_FOR_RECOLOR = 0.3f; glLineWidth(2.0); glm::vec4 impactColor(1, 0, 0, 1); glm::vec3 lineColor(0.4, 0.5, 0.3); @@ -355,7 +356,12 @@ void renderGroundPlaneGrid(float size, float impact) { } // Draw the floor, colored for recent impact - glm::vec4 floorColor = impact * impactColor + (1.f - impact) * surfaceColor; + glm::vec4 floorColor; + if (impact > IMPACT_SOUND_MAGNITUDE_FOR_RECOLOR) { + floorColor = impact * impactColor + (1.f - impact) * surfaceColor; + } else { + floorColor = surfaceColor; + } glColor4fv(&floorColor.x); glBegin(GL_QUADS); glVertex3f(0, 0, 0); diff --git a/interface/src/avatar/Avatar.cpp b/interface/src/avatar/Avatar.cpp index 1af82083ae..626be35d1b 100755 --- a/interface/src/avatar/Avatar.cpp +++ b/interface/src/avatar/Avatar.cpp @@ -892,21 +892,15 @@ void Avatar::updateCollisionWithSphere(glm::vec3 position, float radius, float d } void Avatar::updateCollisionWithEnvironment(float deltaTime) { - glm::vec3 up = getBodyUpDirection(); float radius = _height * 0.125f; const float ENVIRONMENT_SURFACE_ELASTICITY = 1.0f; const float ENVIRONMENT_SURFACE_DAMPING = 0.01; const float ENVIRONMENT_COLLISION_FREQUENCY = 0.05f; - const float VISIBLE_GROUND_COLLISION_VELOCITY = 0.2f; glm::vec3 penetration; if (Application::getInstance()->getEnvironment()->findCapsulePenetration( _position - up * (_pelvisFloatingHeight - radius), _position + up * (_height - _pelvisFloatingHeight - radius), radius, penetration)) { - float velocityTowardCollision = glm::dot(_velocity, glm::normalize(penetration)); - if (velocityTowardCollision > VISIBLE_GROUND_COLLISION_VELOCITY) { - Application::getInstance()->setGroundPlaneImpact(1.0f); - } _lastCollisionPosition = _position; updateCollisionSound(penetration, deltaTime, ENVIRONMENT_COLLISION_FREQUENCY); applyHardCollision(penetration, ENVIRONMENT_SURFACE_ELASTICITY, ENVIRONMENT_SURFACE_DAMPING); From fcf20a7ebc9a10e2f320310f34ba067af6114a3d Mon Sep 17 00:00:00 2001 From: Philip Rosedale Date: Thu, 1 Aug 2013 15:00:08 -0700 Subject: [PATCH 14/20] Sound on click, but not on hover --- interface/src/Application.cpp | 16 ++++++++++------ interface/src/Util.cpp | 2 +- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 8add2325d9..70a1169d90 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -855,6 +855,11 @@ void Application::mouseMoveEvent(QMouseEvent* event) { } } +const bool MAKE_SOUND_ON_VOXEL_HOVER = false; +const bool MAKE_SOUND_ON_VOXEL_CLICK = true; +const float HOVER_VOXEL_FREQUENCY = 14080.f; +const float HOVER_VOXEL_DECAY = 0.999f; + void Application::mousePressEvent(QMouseEvent* event) { if (activeWindow() == _window) { if (event->button() == Qt::LeftButton) { @@ -865,12 +870,12 @@ void Application::mousePressEvent(QMouseEvent* event) { _mouseVoxelDragging = _mouseVoxel; _mousePressed = true; maybeEditVoxelUnderCursor(); - if (_isHoverVoxel && !_isHoverVoxelSounding) { + if (MAKE_SOUND_ON_VOXEL_CLICK && _isHoverVoxel && !_isHoverVoxelSounding) { _hoverVoxelOriginalColor[0] = _hoverVoxel.red; _hoverVoxelOriginalColor[1] = _hoverVoxel.green; _hoverVoxelOriginalColor[2] = _hoverVoxel.blue; _hoverVoxelOriginalColor[3] = 1; - _audio.startCollisionSound(1.0, 14080 * _hoverVoxel.s * TREE_SCALE, 0.0, 0.999f); + _audio.startCollisionSound(1.0, HOVER_VOXEL_FREQUENCY * _hoverVoxel.s * TREE_SCALE, 0.0, HOVER_VOXEL_DECAY); _isHoverVoxelSounding = true; } @@ -2090,18 +2095,17 @@ void Application::update(float deltaTime) { if (bright < 0.01f) { hoveredNode->setColor(_hoverVoxelOriginalColor); _isHoverVoxelSounding = false; - } + } } else { // Check for a new hover voxel glm::vec4 oldVoxel(_hoverVoxel.x, _hoverVoxel.y, _hoverVoxel.z, _hoverVoxel.s); _isHoverVoxel = _voxels.findRayIntersection(mouseRayOrigin, mouseRayDirection, _hoverVoxel, distance, face); - if (_isHoverVoxel && glm::vec4(_hoverVoxel.x, _hoverVoxel.y, _hoverVoxel.z, _hoverVoxel.s) != oldVoxel) { - //qDebug("bing! x,y,z = %f,%f,%f\n", _hoverVoxel.x, _hoverVoxel.y, _hoverVoxel.z); + if (MAKE_SOUND_ON_VOXEL_HOVER && _isHoverVoxel && glm::vec4(_hoverVoxel.x, _hoverVoxel.y, _hoverVoxel.z, _hoverVoxel.s) != oldVoxel) { _hoverVoxelOriginalColor[0] = _hoverVoxel.red; _hoverVoxelOriginalColor[1] = _hoverVoxel.green; _hoverVoxelOriginalColor[2] = _hoverVoxel.blue; _hoverVoxelOriginalColor[3] = 1; - _audio.startCollisionSound(1.0, 14080 * _hoverVoxel.s * TREE_SCALE, 0.0, 0.992f); + _audio.startCollisionSound(1.0, HOVER_VOXEL_FREQUENCY * _hoverVoxel.s * TREE_SCALE, 0.0, HOVER_VOXEL_DECAY); _isHoverVoxelSounding = true; } } diff --git a/interface/src/Util.cpp b/interface/src/Util.cpp index 1830a30014..ffb9ea25e0 100644 --- a/interface/src/Util.cpp +++ b/interface/src/Util.cpp @@ -339,7 +339,7 @@ void renderCollisionOverlay(int width, int height, float magnitude) { } void renderGroundPlaneGrid(float size, float impact) { - float IMPACT_SOUND_MAGNITUDE_FOR_RECOLOR = 0.3f; + float IMPACT_SOUND_MAGNITUDE_FOR_RECOLOR = 1.f; glLineWidth(2.0); glm::vec4 impactColor(1, 0, 0, 1); glm::vec3 lineColor(0.4, 0.5, 0.3); From 9defa6255aa8b39c7cccab1d538577217a490650 Mon Sep 17 00:00:00 2001 From: Philip Rosedale Date: Thu, 1 Aug 2013 15:31:09 -0700 Subject: [PATCH 15/20] disable mouse wheel voxel scale change --- interface/src/Application.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 551e666338..a82b9bc8f3 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -932,8 +932,10 @@ void Application::touchEndEvent(QTouchEvent* event) { _isTouchPressed = false; } +const bool USE_MOUSEWHEEL = false; void Application::wheelEvent(QWheelEvent* event) { - if (activeWindow() == _window) { + // Wheel Events disabled for now because they are also activated by touch look pitch up/down. + if (USE_MOUSEWHEEL && (activeWindow() == _window)) { if (checkedVoxelModeAction() == 0) { event->ignore(); return; From 8f955346448d64a3d70122fda112d6968e00de7f Mon Sep 17 00:00:00 2001 From: Philip Rosedale Date: Thu, 1 Aug 2013 16:04:38 -0700 Subject: [PATCH 16/20] Fix jittering in view from body slowly following head --- interface/src/Application.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index a82b9bc8f3..c297e578ca 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -2324,19 +2324,17 @@ void Application::update(float deltaTime) { void Application::updateAvatar(float deltaTime) { - // When head is rotated via touch/mouse look, slowly turn body to follow - const float BODY_FOLLOW_HEAD_RATE = 0.5f; - // update body yaw by body yaw delta + // rotate body yaw for yaw received from multitouch _myAvatar.setOrientation(_myAvatar.getOrientation() - * glm::quat(glm::vec3(0, _yawFromTouch * deltaTime * BODY_FOLLOW_HEAD_RATE, 0) * deltaTime)); - _yawFromTouch -= _yawFromTouch * deltaTime * BODY_FOLLOW_HEAD_RATE; + * glm::quat(glm::vec3(0, _yawFromTouch * deltaTime, 0))); + _yawFromTouch = 0.f; // Update my avatar's state from gyros and/or webcam _myAvatar.updateFromGyrosAndOrWebcam(_gyroLook->isChecked(), glm::vec3(_headCameraPitchYawScale, _headCameraPitchYawScale, _headCameraPitchYawScale), - _yawFromTouch, + 0.f, _pitchFromTouch); if (_serialHeadSensor.isActive()) { From 8fc800acffbc4689a852ff13c5326cea35216999 Mon Sep 17 00:00:00 2001 From: Jeffrey Ventrella Date: Fri, 2 Aug 2013 10:59:04 -0700 Subject: [PATCH 17/20] some work on hands --- interface/src/Application.cpp | 1 + interface/src/avatar/Hand.cpp | 10 +++++----- libraries/avatars/src/AvatarData.cpp | 17 +++++++++++++++++ libraries/avatars/src/HandData.cpp | 5 ++++- 4 files changed, 27 insertions(+), 6 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 9b292b3d50..8048d437b7 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -2024,6 +2024,7 @@ void Application::renderLookatIndicator(glm::vec3 pointOfInterest, Camera& which } void Application::update(float deltaTime) { + // Use Transmitter Hand to move hand if connected, else use mouse if (_myTransmitter.isConnected()) { const float HAND_FORCE_SCALING = 0.01f; diff --git a/interface/src/avatar/Hand.cpp b/interface/src/avatar/Hand.cpp index 2e409a10bf..7e5652c5d5 100755 --- a/interface/src/avatar/Hand.cpp +++ b/interface/src/avatar/Hand.cpp @@ -51,6 +51,7 @@ void Hand::reset() { void Hand::simulate(float deltaTime, bool isMine) { + if (_isRaveGloveActive) { updateRaveGloveParticles(deltaTime); } @@ -120,9 +121,9 @@ void Hand::render(bool lookingInMirror) { glEnable(GL_RESCALE_NORMAL); if ( SHOW_LEAP_HAND ) { - renderLeapHands(); - //renderFingerTrails(); - //renderHandSpheres(); + //renderLeapHands(); + renderLeapFingerTrails(); + renderLeapHandSpheres(); } } @@ -155,7 +156,6 @@ void Hand::renderRaveGloveStage() { } - void Hand::renderLeapHands() { for (size_t i = 0; i < getNumPalms(); ++i) { PalmData& hand = getPalms()[i]; @@ -165,7 +165,6 @@ void Hand::renderLeapHands() { } } - void Hand::renderLeapHand(PalmData& hand) { glPushMatrix(); @@ -265,6 +264,7 @@ void Hand::renderLeapFingerTrails() { } } + void Hand::setLeapHands(const std::vector& handPositions, const std::vector& handNormals) { for (size_t i = 0; i < getNumPalms(); ++i) { diff --git a/libraries/avatars/src/AvatarData.cpp b/libraries/avatars/src/AvatarData.cpp index 65ae0c6952..9c254453e1 100644 --- a/libraries/avatars/src/AvatarData.cpp +++ b/libraries/avatars/src/AvatarData.cpp @@ -130,6 +130,8 @@ int AvatarData::getBroadcastData(unsigned char* destinationBuffer) { // leap hand data std::vector fingerVectors; + +//printf("about to call _handData->encodeRemoteData(fingerVectors);\n"); _handData->encodeRemoteData(fingerVectors); if (fingerVectors.size() > 255) @@ -244,17 +246,32 @@ int AvatarData::parseData(unsigned char* sourceBuffer, int numBytes) { // hand state, stored as a semi-nibble in the bitItems _handState = getSemiNibbleAt(bitItems,HAND_STATE_START_BIT); +//printf("about to call leap hand data code in AvatarData::parseData...\n"); + // leap hand data if (sourceBuffer - startPosition < numBytes) { + +//printf("got inside of 'if (sourceBuffer - startPosition < numBytes)'\n"); + + // check passed, bytes match unsigned int numFingerVectors = *sourceBuffer++; + +//printf("numFingerVectors = %d\n", numFingerVectors); + + if (numFingerVectors > 0) { + +//printf("ok, we got fingers in AvatarData::parseData\n"); + std::vector fingerVectors(numFingerVectors); for (size_t i = 0; i < numFingerVectors; ++i) { sourceBuffer += unpackFloatScalarFromSignedTwoByteFixed((int16_t*) sourceBuffer, &(fingerVectors[i].x), fingerVectorRadix); sourceBuffer += unpackFloatScalarFromSignedTwoByteFixed((int16_t*) sourceBuffer, &(fingerVectors[i].y), fingerVectorRadix); sourceBuffer += unpackFloatScalarFromSignedTwoByteFixed((int16_t*) sourceBuffer, &(fingerVectors[i].z), fingerVectorRadix); } + +//printf("about to call _handData->decodeRemoteData(fingerVectors);\n"); _handData->decodeRemoteData(fingerVectors); } } diff --git a/libraries/avatars/src/HandData.cpp b/libraries/avatars/src/HandData.cpp index 7bb6eebdc0..605442c926 100755 --- a/libraries/avatars/src/HandData.cpp +++ b/libraries/avatars/src/HandData.cpp @@ -51,12 +51,15 @@ _owningHandData(owningHandData) void HandData::encodeRemoteData(std::vector& fingerVectors) { fingerVectors.clear(); + for (size_t i = 0; i < getNumPalms(); ++i) { + PalmData& palm = getPalms()[i]; fingerVectors.push_back(palm.getRawPosition()); fingerVectors.push_back(palm.getRawNormal()); for (size_t f = 0; f < palm.getNumFingers(); ++f) { FingerData& finger = palm.getFingers()[f]; + if (finger.isActive()) { fingerVectors.push_back(finger.getTipRawPosition()); fingerVectors.push_back(finger.getRootRawPosition()); @@ -82,7 +85,7 @@ void HandData::decodeRemoteData(const std::vector& fingerVectors) { if (palmActive) { palm.setRawPosition(fingerVectors[vectorIndex++]); palm.setRawNormal(fingerVectors[vectorIndex++]); - for (size_t f = 0; f < NUM_FINGERS_PER_HAND; ++f) { + for (size_t f = 0; f < NUM_FINGERS_PER_HAND; ++f) { FingerData& finger = palm.getFingers()[i]; finger.setRawTipPosition(fingerVectors[vectorIndex++]); finger.setRawRootPosition(fingerVectors[vectorIndex++]); From c60acfad28f2b8db157fc21e8e852786dfc63580 Mon Sep 17 00:00:00 2001 From: Jeffrey Ventrella Date: Fri, 2 Aug 2013 11:00:53 -0700 Subject: [PATCH 18/20] merge --- libraries/avatars/src/HandData.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) mode change 100755 => 100644 libraries/avatars/src/HandData.cpp diff --git a/libraries/avatars/src/HandData.cpp b/libraries/avatars/src/HandData.cpp old mode 100755 new mode 100644 index 541c223e4e..0b91191d92 --- a/libraries/avatars/src/HandData.cpp +++ b/libraries/avatars/src/HandData.cpp @@ -88,8 +88,9 @@ void HandData::decodeRemoteData(const std::vector& fingerVectors) { if (palmActive) { palm.setRawPosition(fingerVectors[vectorIndex++]); palm.setRawNormal(fingerVectors[vectorIndex++]); - for (size_t f = 0; f < NUM_FINGERS_PER_HAND; ++f) { - FingerData& finger = palm.getFingers()[i]; + for (size_t f = 0; f < NUM_FINGERS_PER_HAND; ++f) { + FingerData& finger = palm.getFingers()[f]; + finger.setActive(true); finger.setRawTipPosition(fingerVectors[vectorIndex++]); finger.setRawRootPosition(fingerVectors[vectorIndex++]); } From a9ec94de492380c11209c2049107eb23c62a9c96 Mon Sep 17 00:00:00 2001 From: Jeffrey Ventrella Date: Fri, 2 Aug 2013 13:35:35 -0700 Subject: [PATCH 19/20] fixed a problem with emitters not being coordinated with Leap fingers --- interface/src/avatar/Hand.cpp | 119 ++++++++++++++++------------------ interface/src/avatar/Hand.h | 8 ++- 2 files changed, 61 insertions(+), 66 deletions(-) diff --git a/interface/src/avatar/Hand.cpp b/interface/src/avatar/Hand.cpp index 7e5652c5d5..e5afe7e654 100755 --- a/interface/src/avatar/Hand.cpp +++ b/interface/src/avatar/Hand.cpp @@ -64,7 +64,8 @@ void Hand::calculateGeometry() { _basePosition = head.getPosition() + head.getOrientation() * offset; _baseOrientation = head.getOrientation(); - _leapBalls.clear(); + // generate finger tip balls.... + _leapFingerTipBalls.clear(); for (size_t i = 0; i < getNumPalms(); ++i) { PalmData& palm = getPalms()[i]; if (palm.isActive()) { @@ -72,8 +73,8 @@ void Hand::calculateGeometry() { FingerData& finger = palm.getFingers()[f]; if (finger.isActive()) { const float standardBallRadius = 0.01f; - _leapBalls.resize(_leapBalls.size() + 1); - HandBall& ball = _leapBalls.back(); + _leapFingerTipBalls.resize(_leapFingerTipBalls.size() + 1); + HandBall& ball = _leapFingerTipBalls.back(); ball.rotation = _baseOrientation; ball.position = finger.getTipPosition(); ball.radius = standardBallRadius; @@ -83,6 +84,27 @@ void Hand::calculateGeometry() { } } } + + // generate finger rot balls.... + _leapFingerRootBalls.clear(); + for (size_t i = 0; i < getNumPalms(); ++i) { + PalmData& palm = getPalms()[i]; + if (palm.isActive()) { + for (size_t f = 0; f < palm.getNumFingers(); ++f) { + FingerData& finger = palm.getFingers()[f]; + if (finger.isActive()) { + const float standardBallRadius = 0.01f; + _leapFingerRootBalls.resize(_leapFingerRootBalls.size() + 1); + HandBall& ball = _leapFingerRootBalls.back(); + ball.rotation = _baseOrientation; + ball.position = finger.getRootPosition(); + ball.radius = standardBallRadius; + ball.touchForce = 0.0; + ball.isCollidable = true; + } + } + } + } } void Hand::setRaveGloveEffectsMode(QKeyEvent* event) { @@ -191,15 +213,28 @@ void Hand::renderLeapHand(PalmData& hand) { void Hand::renderLeapHandSpheres() { glPushMatrix(); // Draw the leap balls - for (size_t i = 0; i < _leapBalls.size(); i++) { + for (size_t i = 0; i < _leapFingerTipBalls.size(); i++) { float alpha = 1.0f; if (alpha > 0.0f) { glColor4f(_ballColor.r, _ballColor.g, _ballColor.b, alpha); glPushMatrix(); - glTranslatef(_leapBalls[i].position.x, _leapBalls[i].position.y, _leapBalls[i].position.z); - glutSolidSphere(_leapBalls[i].radius, 20.0f, 20.0f); + glTranslatef(_leapFingerTipBalls[i].position.x, _leapFingerTipBalls[i].position.y, _leapFingerTipBalls[i].position.z); + glutSolidSphere(_leapFingerTipBalls[i].radius, 20.0f, 20.0f); + glPopMatrix(); + } + } + + for (size_t i = 0; i < _leapFingerRootBalls.size(); i++) { + float alpha = 1.0f; + + if (alpha > 0.0f) { + glColor4f(0.3f, 0.4f, 0.6f, alpha); + + glPushMatrix(); + glTranslatef(_leapFingerRootBalls[i].position.x, _leapFingerRootBalls[i].position.y, _leapFingerRootBalls[i].position.z); + glutSolidSphere(_leapFingerRootBalls[i].radius, 20.0f, 20.0f); glPopMatrix(); } } @@ -281,69 +316,27 @@ void Hand::setLeapHands(const std::vector& handPositions, } -// call this right after the geometry of the leap hands are set +// call this soon after the geometry of the leap hands are set void Hand::updateRaveGloveEmitters() { - bool debug = false; + for (size_t i = 0; i < NUM_FINGERS; i++) { + _raveGloveParticleSystem.setEmitterActive(_raveGloveEmitter[i], false); + } - if (_raveGloveInitialized) { - - if(debug) printf( "\n" ); - if(debug) printf( "------------------------------------\n" ); - if(debug) printf( "updating rave glove emitters: \n" ); - if(debug) printf( "------------------------------------\n" ); - - int emitterIndex = 0; - - for (size_t i = 0; i < getNumPalms(); ++i) { - PalmData& palm = getPalms()[i]; + for (size_t i = 0; i < _leapFingerTipBalls.size(); i++) { + if (i < NUM_FINGERS) { + glm::vec3 fingerDirection = _leapFingerTipBalls[i].position - _leapFingerRootBalls[i].position; + float fingerLength = glm::length(fingerDirection); - if(debug) printf( "\n" ); - if(debug) printf( "palm %d ", (int)i ); - - if (palm.isActive()) { - - if(debug) printf( "is active\n" ); - - for (size_t f = 0; f < palm.getNumFingers(); ++f) { - FingerData& finger = palm.getFingers()[f]; - - if(debug) printf( "emitterIndex %d: ", emitterIndex ); - - if ((emitterIndex >=0) - && (emitterIndex < NUM_FINGERS)) { - - _raveGloveParticleSystem.setEmitterActive(_raveGloveEmitter[emitterIndex], false); // set to false by default... - - if (finger.isActive()) { - _raveGloveParticleSystem.setEmitterActive(_raveGloveEmitter[emitterIndex], true); - - if(debug) printf( "_raveGloveEmitter[%d] = %d\n", emitterIndex, _raveGloveEmitter[emitterIndex] ); - - glm::vec3 fingerDirection = finger.getTipPosition() - finger.getRootPosition(); - float fingerLength = glm::length(fingerDirection); - - if (fingerLength > 0.0f) { - fingerDirection /= fingerLength; - } else { - fingerDirection = IDENTITY_UP; - } - - assert(_raveGloveEmitter[emitterIndex] >=0 ); - assert(_raveGloveEmitter[emitterIndex] < NUM_FINGERS ); - - _raveGloveParticleSystem.setEmitterPosition (_raveGloveEmitter[emitterIndex], finger.getTipPosition()); - _raveGloveParticleSystem.setEmitterDirection(_raveGloveEmitter[emitterIndex], fingerDirection); - } - } else { - if(debug) printf( "BOGUS finger\n" ); - } - - emitterIndex ++; - } + if (fingerLength > 0.0f) { + fingerDirection /= fingerLength; } else { - if(debug) printf( "is NOT active\n" ); + fingerDirection = IDENTITY_UP; } + + _raveGloveParticleSystem.setEmitterActive (_raveGloveEmitter[i], true); + _raveGloveParticleSystem.setEmitterPosition (_raveGloveEmitter[i], _leapFingerTipBalls[i].position); + _raveGloveParticleSystem.setEmitterDirection(_raveGloveEmitter[i], fingerDirection); } } } diff --git a/interface/src/avatar/Hand.h b/interface/src/avatar/Hand.h index 2ee066d7b6..beb7b8d516 100755 --- a/interface/src/avatar/Hand.h +++ b/interface/src/avatar/Hand.h @@ -65,8 +65,9 @@ public: void setRaveGloveEffectsMode(QKeyEvent* event); // getters - const glm::vec3& getLeapBallPosition (int ball) const { return _leapBalls[ball].position;} - bool isRaveGloveActive () const { return _isRaveGloveActive; } + const glm::vec3& getLeapFingerTipBallPosition (int ball) const { return _leapFingerTipBalls [ball].position;} + const glm::vec3& getLeapFingerRootBallPosition(int ball) const { return _leapFingerRootBalls[ball].position;} + bool isRaveGloveActive() const { return _isRaveGloveActive; } private: // disallow copies of the Hand, copy of owning Avatar is disallowed too @@ -84,7 +85,8 @@ private: float _renderAlpha; bool _lookingInMirror; glm::vec3 _ballColor; - std::vector _leapBalls; + std::vector _leapFingerTipBalls; + std::vector _leapFingerRootBalls; // private methods void setLeapHands(const std::vector& handPositions, From 29c5511a543401ee1e0bbf2441cb68f947667d70 Mon Sep 17 00:00:00 2001 From: Jeffrey Ventrella Date: Fri, 2 Aug 2013 13:49:50 -0700 Subject: [PATCH 20/20] test --- interface/src/avatar/Hand.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interface/src/avatar/Hand.cpp b/interface/src/avatar/Hand.cpp index e5afe7e654..45a2117285 100755 --- a/interface/src/avatar/Hand.cpp +++ b/interface/src/avatar/Hand.cpp @@ -14,7 +14,7 @@ #include "Util.h" #include "renderer/ProgramObject.h" -const bool SHOW_LEAP_HAND = true; +const bool SHOW_LEAP_HAND = false; using namespace std;