From 22a0e39d6c5f1d071e70e85c29ca7dfae0321ae1 Mon Sep 17 00:00:00 2001 From: Jeffrey Ventrella Date: Mon, 6 May 2013 18:29:20 -0700 Subject: [PATCH] more work on avatar touch, reachable radius, and hand states --- interface/src/Avatar.cpp | 25 ++++++------- interface/src/Avatar.h | 12 +----- interface/src/AvatarRenderer.cpp | 13 +++++++ interface/src/AvatarTouch.cpp | 63 ++++++++++++++++---------------- interface/src/AvatarTouch.h | 2 +- interface/src/Util.cpp | 57 ++++++++++++++++++++++++----- interface/src/Util.h | 3 ++ interface/src/main.cpp | 17 +++------ 8 files changed, 116 insertions(+), 76 deletions(-) diff --git a/interface/src/Avatar.cpp b/interface/src/Avatar.cpp index 41cc3ee04d..fc2177c1d3 100644 --- a/interface/src/Avatar.cpp +++ b/interface/src/Avatar.cpp @@ -34,10 +34,6 @@ const float BODY_ROLL_WHILE_TURNING = 0.1; const float LIN_VEL_DECAY = 5.0; const float MY_HAND_HOLDING_PULL = 0.2; const float YOUR_HAND_HOLDING_PULL = 1.0; - -//const float BODY_SPRING_DEFAULT_TIGHTNESS = 20.0f; -//const float BODY_SPRING_FORCE = 6.0f; - const float BODY_SPRING_DEFAULT_TIGHTNESS = 1500.0f; const float BODY_SPRING_FORCE = 300.0f; @@ -144,14 +140,13 @@ Avatar::Avatar(bool isMine) { _renderYaw = 0.0; _renderPitch = 0.0; _sphere = NULL; - //_interactingOther = NULL; _handHoldingPosition = glm::vec3(0.0f, 0.0f, 0.0f); _distanceToNearestAvatar = std::numeric_limits::max(); _gravity = glm::vec3(0.0f, -1.0f, 0.0f); // default initializeSkeleton(); - _avatarTouch.setReachableRadius(0.4); + _avatarTouch.setReachableRadius(0.6); if (iris_texture.size() == 0) { switchToResourcesParentIfRequired(); @@ -317,8 +312,8 @@ void Avatar::setLeanSideways(float dist){ _head.leanSideways = dist; } -void Avatar::setMousePressed(bool d) { - _mousePressed = d; +void Avatar::setMousePressed( bool mousePressed ) { + _mousePressed = mousePressed; } bool Avatar::getIsNearInteractingOther() { @@ -435,7 +430,6 @@ void Avatar::simulate(float deltaTime) { } - void Avatar::updateHandMovementAndTouching(float deltaTime) { // reset hand and arm positions according to hand movement @@ -472,6 +466,7 @@ void Avatar::updateHandMovementAndTouching(float deltaTime) { if (_interactingOther) { _avatarTouch.setYourBodyPosition(_interactingOther->_position); _avatarTouch.setYourHandPosition(_joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].springyPosition); + _avatarTouch.setYourHandState (_interactingOther->_handState); } }//if (_isMine) @@ -483,7 +478,12 @@ void Avatar::updateHandMovementAndTouching(float deltaTime) { if (_isMine) { //Set the vector we send for hand position to other people to be our right hand setHandPosition(_joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position); - _handState = _mousePressed; + + if ( _mousePressed ) { + _handState = 1; + } else { + _handState = 0; + } _avatarTouch.setMyHandState(_handState); @@ -493,7 +493,6 @@ void Avatar::updateHandMovementAndTouching(float deltaTime) { } } - void Avatar::updateHead(float deltaTime) { //apply the head lean values to the springy position... @@ -753,7 +752,7 @@ void Avatar::setGravity(glm::vec3 gravity) { } -void Avatar::render(bool lookingInMirror) { +void Avatar::render(bool lookingInMirror, glm::vec3 cameraPosition) { // render a simple round on the ground projected down from the avatar's position renderDiskShadow(_position, glm::vec3(0.0f, 1.0f, 0.0f ), 0.1f, 0.2f ); @@ -788,7 +787,7 @@ void Avatar::render(bool lookingInMirror) { // if this is my avatar, then render my interactions with the other avatar if (_isMine ) { - _avatarTouch.render(); + _avatarTouch.render(cameraPosition); } // Render the balls diff --git a/interface/src/Avatar.h b/interface/src/Avatar.h index 8bb98aadf3..29896556a5 100644 --- a/interface/src/Avatar.h +++ b/interface/src/Avatar.h @@ -101,13 +101,6 @@ public: void setLeanForward(float dist); void setLeanSideways(float dist); void addLean(float x, float z); - - /* - const glm::vec3& getHeadRightDirection() const { return _orientation.getRight(); }; - const glm::vec3& getHeadUpDirection () const { return _orientation.getUp (); }; - const glm::vec3& getHeadFrontDirection() const { return _orientation.getFront(); }; - */ - const glm::vec3& getHeadPosition() const ; const glm::vec3& getJointPosition(AvatarJointID j) const { return _joint[j].position; }; const glm::vec3& getBodyUpDirection() const { return _orientation.getUp(); }; @@ -117,8 +110,8 @@ public: AvatarMode getMode(); - void setMousePressed( bool pressed ); - void render(bool lookingInMirror); + void setMousePressed(bool pressed); + void render(bool lookingInMirrorm, glm::vec3 cameraPosition); void renderBody(); void renderHead(bool lookingInMirror); void simulate(float); @@ -241,7 +234,6 @@ private: float _transmitterHz; int _transmitterPackets; glm::vec3 _transmitterInitialReading; - //Avatar* _interactingOther; float _pelvisStandingHeight; float _height; Balls* _balls; diff --git a/interface/src/AvatarRenderer.cpp b/interface/src/AvatarRenderer.cpp index b1ed54d083..52d3fc0026 100644 --- a/interface/src/AvatarRenderer.cpp +++ b/interface/src/AvatarRenderer.cpp @@ -11,6 +11,19 @@ #include "AvatarRenderer.h" #include "InterfaceConfig.h" + +#include +#include +#include +#include +#include "Avatar.h" +#include "Log.h" +#include "ui/TextRenderer.h" +#include +#include +#include + + AvatarRenderer::AvatarRenderer() { } diff --git a/interface/src/AvatarTouch.cpp b/interface/src/AvatarTouch.cpp index 712a7af030..b56a8ac7e8 100644 --- a/interface/src/AvatarTouch.cpp +++ b/interface/src/AvatarTouch.cpp @@ -10,6 +10,7 @@ #include #include "AvatarTouch.h" #include "InterfaceConfig.h" +#include "Util.h" const float THREAD_RADIUS = 0.012; @@ -59,14 +60,16 @@ void AvatarTouch::setReachableRadius( float r ) { _reachableRadius = r; } -void AvatarTouch::render() { + +void AvatarTouch::render(glm::vec3 cameraPosition) { if (_canReachToOtherAvatar) { - glPushMatrix(); - glTranslatef(_yourBodyPosition.x, _yourBodyPosition.y, _yourBodyPosition.z); - glColor4f( 0.3, 0.4, 0.5, 0.3 ); glutSolidSphere( _reachableRadius, 30.0f, 30.0f ); - glPopMatrix(); - + + glColor4f( 0.3, 0.4, 0.5, 0.5 ); + glm::vec3 p(_yourBodyPosition); + p.y = 0.0005f; + renderCircle(p, _reachableRadius, glm::vec3(0.0f, 1.0f, 0.0f), 30); + // if your hand is grasping, show it... if ( _yourHandState == 1 ) { glPushMatrix(); @@ -76,6 +79,27 @@ void AvatarTouch::render() { glColor4f( 1.0, 1.0, 0.2, 0.1 ); glutSolidSphere( 0.030f, 10.0f, 10.0f ); glPopMatrix(); } + + //show beam + glm::vec3 v1( _myHandPosition ); + glm::vec3 v2( _yourHandPosition ); + + if (_handsCloseEnoughToGrasp) { + glLineWidth( 2.0 ); + glColor4f( 0.7f, 0.4f, 0.1f, 0.3 ); + glBegin( GL_LINE_STRIP ); + glVertex3f( v1.x, v1.y, v1.z ); + glVertex3f( v2.x, v2.y, v2.z ); + glEnd(); + + glColor4f( 1.0f, 1.0f, 0.0f, 0.8 ); + + for (int p=0; pbegin(); agent != agentList->end(); agent++) { if (agent->getLinkedData() != NULL && agent->getType() == AGENT_TYPE_AVATAR) { Avatar *avatar = (Avatar *)agent->getLinkedData(); - avatar->render(0); + avatar->render(0, ::myCamera.getPosition()); } } agentList->unlock(); @@ -723,7 +723,7 @@ void displaySide(Camera& whichCamera) { if (::frustumOn) renderViewFrustum(::viewFrustum); //Render my own avatar - myAvatar.render(::lookingInMirror); + myAvatar.render(::lookingInMirror, ::myCamera.getPosition()); glPopMatrix(); } @@ -1671,15 +1671,10 @@ void idle(void) { myAvatar.setHandMovementValues( handControl.getValues() ); // tell my avatar if the mouse is being pressed... - myAvatar.setMousePressed(mousePressed); - /* - if ( mousePressed == 1 ) { - myAvatar.setMousePressed( true ); - } else { - myAvatar.setMousePressed( false ); - } - */ - + if ( mousePressed) { + myAvatar.setMousePressed(mousePressed); + } + // walking triggers the handControl to stop if ( myAvatar.getMode() == AVATAR_MODE_WALKING ) { handControl.stop();