From 883d21a5e46469a59bee17b071fb43eab99d6f1f Mon Sep 17 00:00:00 2001 From: Jeffrey Ventrella Date: Sun, 26 May 2013 15:17:58 -0700 Subject: [PATCH] added facing other av requirement for camera shift to 1p; improved ease-in/out for camera mode shift; did some clean up on the camera code --- interface/src/Application.cpp | 43 +++------- interface/src/Avatar.cpp | 2 + interface/src/AvatarTouch.cpp | 47 ++++------- interface/src/AvatarTouch.h | 50 ++++++------ interface/src/Camera.cpp | 145 +++++++++++++++++++--------------- interface/src/Camera.h | 35 +++----- 6 files changed, 148 insertions(+), 174 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index a0979eb4b9..9671e66f54 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -918,31 +918,21 @@ void Application::idle() { if (_myCamera.getMode() != CAMERA_MODE_MIRROR) { if (_manualFirstPerson) { if (_myCamera.getMode() != CAMERA_MODE_FIRST_PERSON ) { - Camera::CameraFollowingAttributes a; - a.upShift = 0.0f; - a.distance = 0.0f; - a.tightness = 100.0f; - _myCamera.setMode(CAMERA_MODE_FIRST_PERSON, a); + _myCamera.setMode(CAMERA_MODE_FIRST_PERSON); + _myCamera.setModeShiftRate(1.0f); } } else { if (_myAvatar.getIsNearInteractingOther()) { if (_myCamera.getMode() != CAMERA_MODE_FIRST_PERSON) { - - Camera::CameraFollowingAttributes a; - a.upShift = 0.0f; - a.distance = 0.0f; - a.tightness = 100.0f; - _myCamera.setMode(CAMERA_MODE_FIRST_PERSON, a); + _myCamera.setMode(CAMERA_MODE_FIRST_PERSON); + _myCamera.setModeShiftRate(1.0f); } } else { if (_myCamera.getMode() != CAMERA_MODE_THIRD_PERSON) { - Camera::CameraFollowingAttributes a; - a.upShift = -0.2f; - a.distance = 1.5f; - a.tightness = 8.0f; - _myCamera.setMode(CAMERA_MODE_THIRD_PERSON, a); + _myCamera.setMode(CAMERA_MODE_THIRD_PERSON); + _myCamera.setModeShiftRate(1.0f); } } } @@ -981,17 +971,11 @@ void Application::setHead(bool head) { #endif if (head) { - Camera::CameraFollowingAttributes a; - a.upShift = 0.0f; - a.distance = 0.2f; - a.tightness = 100.0f; - _myCamera.setMode(CAMERA_MODE_MIRROR, a); + _myCamera.setMode(CAMERA_MODE_MIRROR); + _myCamera.setModeShiftRate(100.0f); } else { - Camera::CameraFollowingAttributes a; - a.upShift = -0.2f; - a.distance = 1.5f; - a.tightness = 8.0f; - _myCamera.setMode(CAMERA_MODE_THIRD_PERSON, a); + _myCamera.setMode(CAMERA_MODE_THIRD_PERSON); + _myCamera.setModeShiftRate(1.0f); } } @@ -1285,11 +1269,8 @@ void Application::init() { _stars.readInput(STAR_FILE, STAR_CACHE_FILE, 0); _myAvatar.setPosition(START_LOCATION); - Camera::CameraFollowingAttributes a; - a.upShift = -0.2f; - a.distance = 1.5f; - a.tightness = 8.0f; - _myCamera.setMode(CAMERA_MODE_THIRD_PERSON, a); + _myCamera.setMode(CAMERA_MODE_THIRD_PERSON ); + _myCamera.setModeShiftRate(1.0f); _myAvatar.setDisplayingLookatVectors(false); QCursor::setPos(_headMouseX, _headMouseY); diff --git a/interface/src/Avatar.cpp b/interface/src/Avatar.cpp index 8ce1abb05b..b3dd505f40 100644 --- a/interface/src/Avatar.cpp +++ b/interface/src/Avatar.cpp @@ -486,6 +486,7 @@ void Avatar::updateHandMovementAndTouching(float deltaTime) { if (!_owningAgent) { _avatarTouch.setMyBodyPosition(_position); + _avatarTouch.setMyOrientation(_orientation); float closestDistance = std::numeric_limits::max(); @@ -518,6 +519,7 @@ void Avatar::updateHandMovementAndTouching(float deltaTime) { if (_interactingOther) { _avatarTouch.setYourBodyPosition(_interactingOther->_position); + _avatarTouch.setYourOrientation (_interactingOther->_orientation); _avatarTouch.setYourHandPosition(_interactingOther->_joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].springyPosition); _avatarTouch.setYourHandState (_interactingOther->_handState); diff --git a/interface/src/AvatarTouch.cpp b/interface/src/AvatarTouch.cpp index 7651a0a9a8..2072848902 100644 --- a/interface/src/AvatarTouch.cpp +++ b/interface/src/AvatarTouch.cpp @@ -27,55 +27,38 @@ AvatarTouch::AvatarTouch() { _weAreHoldingHands = false; _canReachToOtherAvatar = false; _handsCloseEnoughToGrasp = false; + _myOrientation.setToIdentity(); + _yourOrientation.setToIdentity(); for (int p=0; p 0.1f)) { + facingEachOther = true; + } - if (distanceBetweenBodies < _reachableRadius) { + if ((distanceBetweenBodies < _reachableRadius) + && (facingEachOther)) { _vectorBetweenHands = _yourHandPosition - _myHandPosition; - float distanceBetweenHands = glm::length(_vectorBetweenHands); + float distanceBetweenHands = glm::length(_vectorBetweenHands); if (distanceBetweenHands < HANDS_CLOSE_ENOUGH_TO_GRASP) { _handsCloseEnoughToGrasp = true; } else { _handsCloseEnoughToGrasp = false; } - + _canReachToOtherAvatar = true; } else { _canReachToOtherAvatar = false; @@ -92,7 +75,7 @@ void AvatarTouch::render(glm::vec3 cameraPosition) { p.y = 0.0005f; renderCircle(p, _reachableRadius, glm::vec3(0.0f, 1.0f, 0.0f), 30); - // show is we are golding hands... + // show if we are golding hands... if (_weAreHoldingHands) { renderBeamBetweenHands(); diff --git a/interface/src/AvatarTouch.h b/interface/src/AvatarTouch.h index 2111c0ecf1..fb90efa5fd 100644 --- a/interface/src/AvatarTouch.h +++ b/interface/src/AvatarTouch.h @@ -9,6 +9,7 @@ #define __interface__AvatarTouch__ #include +#include "Orientation.h" enum AvatarHandState { @@ -26,18 +27,17 @@ public: void simulate(float deltaTime); void render(glm::vec3 cameraPosition); - - void setMyHandPosition (glm::vec3 position); - void setYourHandPosition(glm::vec3 position); - void setMyBodyPosition (glm::vec3 position); - void setYourBodyPosition(glm::vec3 position); - void setMyHandState (int state); - void setYourHandState (int state); - void setReachableRadius (float r); - - void setAbleToReachOtherAvatar (bool a) {_canReachToOtherAvatar = a;} - void setHandsCloseEnoughToGrasp(bool h) {_handsCloseEnoughToGrasp = h;} - void setHoldingHands (bool h) {_weAreHoldingHands = h;} + + void setMyHandPosition (glm::vec3 position ) { _myHandPosition = position; } + void setYourHandPosition(glm::vec3 position ) { _yourHandPosition = position; } + void setMyOrientation (Orientation orientation) { _myOrientation = orientation; } + void setYourOrientation (Orientation orientation) { _yourOrientation = orientation; } + void setMyBodyPosition (glm::vec3 position ) { _myBodyPosition = position; } + void setYourBodyPosition(glm::vec3 position ) { _yourBodyPosition = position; } + void setMyHandState (int state ) { _myHandState = state; } + void setYourHandState (int state ) { _yourHandState = state; } + void setReachableRadius (float radius ) { _reachableRadius = radius; } + void setHoldingHands (bool holding ) { _weAreHoldingHands = holding; } bool getAbleToReachOtherAvatar () const {return _canReachToOtherAvatar; } bool getHandsCloseEnoughToGrasp() const {return _handsCloseEnoughToGrasp;} @@ -47,18 +47,20 @@ private: static const int NUM_POINTS = 100; - bool _weAreHoldingHands; - glm::vec3 _point [NUM_POINTS]; - glm::vec3 _myBodyPosition; - glm::vec3 _yourBodyPosition; - glm::vec3 _myHandPosition; - glm::vec3 _yourHandPosition; - glm::vec3 _vectorBetweenHands; - int _myHandState; - int _yourHandState; - bool _canReachToOtherAvatar; - bool _handsCloseEnoughToGrasp; - float _reachableRadius; + bool _weAreHoldingHands; + glm::vec3 _point [NUM_POINTS]; + glm::vec3 _myBodyPosition; + glm::vec3 _yourBodyPosition; + glm::vec3 _myHandPosition; + glm::vec3 _yourHandPosition; + Orientation _myOrientation; + Orientation _yourOrientation; + glm::vec3 _vectorBetweenHands; + int _myHandState; + int _yourHandState; + bool _canReachToOtherAvatar; + bool _handsCloseEnoughToGrasp; + float _reachableRadius; void renderBeamBetweenHands(); }; diff --git a/interface/src/Camera.cpp b/interface/src/Camera.cpp index b408135c40..1b1dc56ae2 100644 --- a/interface/src/Camera.cpp +++ b/interface/src/Camera.cpp @@ -11,49 +11,51 @@ #include "Camera.h" -const float MODE_SHIFT_RATE = 6.0f; +const float CAMERA_MINIMUM_MODE_SHIFT_RATE = 0.5f; + +const float CAMERA_FIRST_PERSON_MODE_UP_SHIFT = 0.0f; +const float CAMERA_FIRST_PERSON_MODE_DISTANCE = 0.0f; +const float CAMERA_FIRST_PERSON_MODE_TIGHTNESS = 100.0f; + +const float CAMERA_THIRD_PERSON_MODE_UP_SHIFT = -0.2f; +const float CAMERA_THIRD_PERSON_MODE_DISTANCE = 1.5f; +const float CAMERA_THIRD_PERSON_MODE_TIGHTNESS = 8.0f; + +const float CAMERA_MIRROR_MODE_UP_SHIFT = 0.0f; +const float CAMERA_MIRROR_MODE_DISTANCE = 0.2f; +const float CAMERA_MIRROR_MODE_TIGHTNESS = 100.0f; Camera::Camera() { _needsToInitialize = true; _frustumNeedsReshape = true; - _modeShift = 0.0; - _mode = CAMERA_MODE_THIRD_PERSON; - _tightness = 10.0; // default - _fieldOfView = 60.0; // default - _nearClip = 0.08; // default - _farClip = 50.0 * TREE_SCALE; // default - _yaw = 0.0; - _pitch = 0.0; - _roll = 0.0; - _upShift = 0.0; - _distance = 0.0; - _idealYaw = 0.0; - _idealPitch = 0.0; - _idealRoll = 0.0; - _targetPosition = glm::vec3(0.0, 0.0, 0.0); - _position = glm::vec3(0.0, 0.0, 0.0); - _idealPosition = glm::vec3(0.0, 0.0, 0.0); + _modeShift = 0.0f; + _modeShiftRate = 1.0f; + _linearModeShift = 0.0f; + _mode = CAMERA_MODE_THIRD_PERSON; + _tightness = 10.0f; // default + _fieldOfView = 60.0f; // default + _nearClip = 0.08f; // default + _farClip = 50.0f * TREE_SCALE; // default + _yaw = 0.0f; + _pitch = 0.0f; + _roll = 0.0f; + _upShift = 0.0f; + _distance = 0.0f; + _previousUpShift = 0.0f; + _previousDistance = 0.0f; + _previousTightness = 0.0f; + _newUpShift = 0.0f; + _newDistance = 0.0f; + _newTightness = 0.0f; + _idealYaw = 0.0f; + _idealPitch = 0.0f; + _idealRoll = 0.0f; + _targetPosition = glm::vec3(0.0f, 0.0f, 0.0f); + _position = glm::vec3(0.0f, 0.0f, 0.0f); + _idealPosition = glm::vec3(0.0f, 0.0f, 0.0f); _orientation.setToIdentity(); - - _attributes[CAMERA_MODE_FIRST_PERSON].upShift = CAMERA_DEFAULT_FIRST_PERSON_MODE_UP_SHIFT; - _attributes[CAMERA_MODE_FIRST_PERSON].distance = CAMERA_DEFAULT_FIRST_PERSON_MODE_DISTANCE; - _attributes[CAMERA_MODE_FIRST_PERSON].tightness = CAMERA_DEFAULT_FIRST_PERSON_MODE_TIGHTNESS; - - _attributes[CAMERA_MODE_THIRD_PERSON].upShift = CAMERA_DEFAULT_THIRD_PERSON_MODE_UP_SHIFT; - _attributes[CAMERA_MODE_THIRD_PERSON].distance = CAMERA_DEFAULT_THIRD_PERSON_MODE_DISTANCE; - _attributes[CAMERA_MODE_THIRD_PERSON].tightness = CAMERA_DEFAULT_THIRD_PERSON_MODE_TIGHTNESS; - - _attributes[CAMERA_MODE_MIRROR ].upShift = CAMERA_DEFAULT_MIRROR_MODE_UP_SHIFT; - _attributes[CAMERA_MODE_MIRROR ].distance = CAMERA_DEFAULT_MIRROR_MODE_DISTANCE; - _attributes[CAMERA_MODE_MIRROR ].tightness = CAMERA_DEFAULT_MIRROR_MODE_TIGHTNESS; - - for (int m = 0; m < NUM_CAMERA_MODES; m ++) { - _previousAttributes[m].upShift = 0.0f; - _previousAttributes[m].distance = 0.0f; - _previousAttributes[m].tightness = 0.0f; - } } void Camera::update(float deltaTime) { @@ -67,7 +69,6 @@ void Camera::update(float deltaTime) { generateOrientation(); } - // generate the ortho-normals for the orientation based on the three Euler angles void Camera::generateOrientation() { _orientation.setToIdentity(); @@ -79,15 +80,26 @@ void Camera::generateOrientation() { // use iterative forces to keep the camera at the desired position and angle void Camera::updateFollowMode(float deltaTime) { - if (_modeShift < 1.0f) { - _modeShift += 5.0f * deltaTime; - if (_modeShift > 1.0f ) { + if (_linearModeShift < 1.0f) { + _linearModeShift += _modeShiftRate * deltaTime; + + _modeShift = ONE_HALF - ONE_HALF * cosf(_linearModeShift * PIE * 1.0); + + _upShift = _previousUpShift * (1.0f - _modeShift) + _newUpShift * _modeShift; + _distance = _previousDistance * (1.0f - _modeShift) + _newDistance * _modeShift; + _tightness = _previousTightness * (1.0f - _modeShift) + _newTightness * _modeShift; + + if (_linearModeShift > 1.0f ) { + _linearModeShift = 1.0f; _modeShift = 1.0f; + _upShift = _newUpShift; + _distance = _newDistance; + _tightness = _newTightness; } } // derive t from tightness - float t = _tightness * deltaTime; + float t = _tightness * _modeShift * deltaTime; if (t > 1.0) { t = 1.0; } @@ -103,10 +115,6 @@ void Camera::updateFollowMode(float deltaTime) { _pitch += (_idealPitch - _pitch) * t; _roll += (_idealRoll - _roll ) * t; } - - _orientation.yaw (_yaw ); - _orientation.pitch(_pitch); - _orientation.roll (_roll ); float radian = (_yaw / 180.0) * PIE; @@ -124,32 +132,45 @@ void Camera::updateFollowMode(float deltaTime) { // force position towards ideal position _position += (_idealPosition - _position) * t; } - - float inverseModeShift = 1.0f - _modeShift; - _upShift = _attributes[_mode].upShift * _modeShift + _previousAttributes[_mode].upShift * inverseModeShift; - _distance = _attributes[_mode].distance * _modeShift + _previousAttributes[_mode].distance * inverseModeShift; - _upShift = _attributes[_mode].upShift * _modeShift + _previousAttributes[_mode].upShift * inverseModeShift; } - -void Camera::setMode(CameraMode m, CameraFollowingAttributes a) { - - _previousAttributes[m].upShift = _attributes[m].upShift; - _previousAttributes[m].distance = _attributes[m].distance; - _previousAttributes[m].tightness = _attributes[m].tightness; - - _attributes[m].upShift = a.upShift; - _attributes[m].distance = a.distance; - _attributes[m].tightness = a.tightness; +void Camera::setModeShiftRate ( float rate ) { - setMode(m); + _modeShiftRate = rate; + + if (_modeShiftRate < CAMERA_MINIMUM_MODE_SHIFT_RATE ) { + _modeShiftRate = CAMERA_MINIMUM_MODE_SHIFT_RATE; + } } -void Camera::setMode(CameraMode m) { +void Camera::setMode(CameraMode m) { + _mode = m; _modeShift = 0.0; + _linearModeShift = 0.0; + + _previousUpShift = _upShift; + _previousDistance = _distance; + _previousTightness = _tightness; + + if (_mode == CAMERA_MODE_THIRD_PERSON) { + _newUpShift = CAMERA_THIRD_PERSON_MODE_UP_SHIFT; + _newDistance = CAMERA_THIRD_PERSON_MODE_DISTANCE; + _newTightness = CAMERA_THIRD_PERSON_MODE_TIGHTNESS; + + } else if (_mode == CAMERA_MODE_FIRST_PERSON) { + _newUpShift = CAMERA_FIRST_PERSON_MODE_UP_SHIFT; + _newDistance = CAMERA_FIRST_PERSON_MODE_DISTANCE; + _newTightness = CAMERA_FIRST_PERSON_MODE_TIGHTNESS; + + } else if (_mode == CAMERA_MODE_MIRROR) { + _newUpShift = CAMERA_MIRROR_MODE_UP_SHIFT; + _newDistance = CAMERA_MIRROR_MODE_DISTANCE; + _newTightness = CAMERA_MIRROR_MODE_TIGHTNESS; + } } + void Camera::setTargetRotation( float yaw, float pitch, float roll ) { _idealYaw = yaw; _idealPitch = pitch; diff --git a/interface/src/Camera.h b/interface/src/Camera.h index b01839d97a..ae3e3ef7b2 100644 --- a/interface/src/Camera.h +++ b/interface/src/Camera.h @@ -21,31 +21,11 @@ enum CameraMode NUM_CAMERA_MODES }; - -const float CAMERA_DEFAULT_FIRST_PERSON_MODE_UP_SHIFT = 0.0f; -const float CAMERA_DEFAULT_FIRST_PERSON_MODE_DISTANCE = 0.0f; -const float CAMERA_DEFAULT_FIRST_PERSON_MODE_TIGHTNESS = 100.0f; - -const float CAMERA_DEFAULT_THIRD_PERSON_MODE_UP_SHIFT = -0.2f; -const float CAMERA_DEFAULT_THIRD_PERSON_MODE_DISTANCE = 1.5f; -const float CAMERA_DEFAULT_THIRD_PERSON_MODE_TIGHTNESS = 8.0f; - -const float CAMERA_DEFAULT_MIRROR_MODE_UP_SHIFT = 0.0f; -const float CAMERA_DEFAULT_MIRROR_MODE_DISTANCE = 0.2f; -const float CAMERA_DEFAULT_MIRROR_MODE_TIGHTNESS = 100.0f; - class Camera { public: Camera(); - struct CameraFollowingAttributes - { - float upShift; - float distance; - float tightness; - }; - void initialize(); // instantly put the camera at the ideal position and rotation. void update( float deltaTime ); @@ -62,7 +42,7 @@ public: void setTargetRotation( float yaw, float pitch, float roll ); void setMode ( CameraMode m ); - void setMode ( CameraMode m, CameraFollowingAttributes attributes ); + void setModeShiftRate ( float r ); void setFieldOfView ( float f ); void setAspectRatio ( float a ); void setNearClip ( float n ); @@ -102,18 +82,23 @@ private: float _yaw; float _pitch; float _roll; - float _upShift; float _idealYaw; float _idealPitch; float _idealRoll; + float _upShift; float _distance; float _tightness; + float _previousUpShift; + float _previousDistance; + float _previousTightness; + float _newUpShift; + float _newDistance; + float _newTightness; Orientation _orientation; float _modeShift; + float _linearModeShift; + float _modeShiftRate; - CameraFollowingAttributes _attributes[NUM_CAMERA_MODES]; - CameraFollowingAttributes _previousAttributes[NUM_CAMERA_MODES]; - void generateOrientation(); void updateFollowMode( float deltaTime ); };