From 68b3f54f5c823c53e7d052e0189ca4b91a7ded4e Mon Sep 17 00:00:00 2001 From: Jeffrey Ventrella Date: Thu, 25 Apr 2013 10:44:01 -0700 Subject: [PATCH 1/5] tiny change --- interface/src/Avatar.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interface/src/Avatar.cpp b/interface/src/Avatar.cpp index 9f9d1febba..0ed3baf4fe 100644 --- a/interface/src/Avatar.cpp +++ b/interface/src/Avatar.cpp @@ -297,7 +297,7 @@ void Avatar::simulate(float deltaTime) { } _interactingOtherIsNearby = false; - + // if the avatar being simulated is mine, then loop through // all the other avatars for potential interactions... if ( _isMine ) From 9a4d27c0b5d139a8aeb549e5437e5bfff39ffe93 Mon Sep 17 00:00:00 2001 From: Jeffrey Ventrella Date: Thu, 25 Apr 2013 12:19:23 -0700 Subject: [PATCH 2/5] cleaned up some camera code and added some functionality for first-person view --- interface/src/Avatar.cpp | 4 +-- interface/src/Camera.cpp | 53 ++++++++++++++++---------------------- interface/src/Camera.h | 55 ++++++++++++++++++++-------------------- interface/src/main.cpp | 45 +++++++++++++++++--------------- 4 files changed, 76 insertions(+), 81 deletions(-) diff --git a/interface/src/Avatar.cpp b/interface/src/Avatar.cpp index 0ed3baf4fe..c77efd28b9 100644 --- a/interface/src/Avatar.cpp +++ b/interface/src/Avatar.cpp @@ -316,8 +316,8 @@ void Avatar::simulate(float deltaTime) { updateAvatarCollisionDetectionAndResponse ( otherAvatar->getBonePosition( AVATAR_BONE_PELVIS_SPINE ), - 0.2, - 0.2, + 0.1, + 0.1, otherAvatar->getBodyUpDirection(), deltaTime ); diff --git a/interface/src/Camera.cpp b/interface/src/Camera.cpp index 1333196b02..b251e1f5a5 100644 --- a/interface/src/Camera.cpp +++ b/interface/src/Camera.cpp @@ -12,14 +12,15 @@ Camera::Camera() { _mode = CAMERA_MODE_THIRD_PERSON; - _tightness = DEFAULT_CAMERA_TIGHTNESS; - _fieldOfView = 60.0; // default - _nearClip = 0.08; // default - _farClip = 50.0; // default + _tightness = 10.0; // default + _fieldOfView = 60.0; // default + _nearClip = 0.08; // default + _farClip = 50.0; // default _yaw = 0.0; _pitch = 0.0; _roll = 0.0; - _up = 0.0; + _upShift = 0.0; + _rightShift = 0.0; _distance = 0.0; _idealYaw = 0.0; _targetPosition = glm::vec3( 0.0, 0.0, 0.0 ); @@ -28,46 +29,36 @@ Camera::Camera() { _orientation.setToIdentity(); } +void Camera::update( float deltaTime ) { - -void Camera::update( float deltaTime ) -{ - //---------------------------------------- // derive t from tightness - //---------------------------------------- - float t = _tightness * deltaTime; - - if ( t > 1.0 ){ + float t = _tightness * deltaTime; + if ( t > 1.0 ) { t = 1.0; } - //---------------------------------------- // update _yaw (before position!) - //---------------------------------------- _yaw += ( _idealYaw - _yaw ) * t; + + // generate the ortho-normals for the orientation based on the Euler angles + _orientation.setToIdentity(); + _orientation.yaw ( _yaw ); + _orientation.pitch( _pitch ); + _orientation.roll ( _roll ); + float radian = ( _yaw / 180.0 ) * PIE; - //---------------------------------------- // update _position - //---------------------------------------- - //these need to be checked to make sure they correspond to the coordinate system. + //these need to be checked to make sure they correspond to the correct coordinate system. double x = _distance * -sin( radian ); double z = _distance * cos( radian ); - double y = _up; + double y = _upShift; - _idealPosition = _targetPosition + glm::vec3( x, y, z ); + _idealPosition = _targetPosition + glm::vec3( x, y, z ); + //_idealPosition += _orientation.getRight() * _rightShift; + //_idealPosition += _orientation.getUp () * _upShift; + // pull position towards ideal position _position += ( _idealPosition - _position ) * t; - - //------------------------------------------------------------------------------ - // generate the ortho-normals for the orientation based on the Euler angles - //------------------------------------------------------------------------------ - _orientation.setToIdentity(); - - _orientation.yaw ( _yaw ); - _orientation.pitch ( _pitch ); - _orientation.roll ( _roll ); - - //printLog( "orientation.front = %f, %f, %f\n", _orientation.front.x, _orientation.front.y, _orientation.front.z ); } diff --git a/interface/src/Camera.h b/interface/src/Camera.h index 354a5d8d16..befb5d0826 100644 --- a/interface/src/Camera.h +++ b/interface/src/Camera.h @@ -20,8 +20,6 @@ enum CameraMode NUM_CAMERA_MODES }; -static const float DEFAULT_CAMERA_TIGHTNESS = 10.0f; - class Camera { public: @@ -29,31 +27,33 @@ public: void update( float deltaTime ); - void setMode ( CameraMode m ) { _mode = m; } - void setYaw ( float y ) { _idealYaw = y; } - void setPitch ( float p ) { _pitch = p; } - void setRoll ( float r ) { _roll = r; } - void setUp ( float u ) { _up = u; } - void setDistance ( float d ) { _distance = d; } - void setTargetPosition ( glm::vec3 t ) { _targetPosition = t; }; - void setPosition ( glm::vec3 p ) { _position = p; }; - void setOrientation ( Orientation o ) { _orientation.set(o); } - void setTightness ( float t ) { _tightness = t; } - void setFieldOfView ( float f ) { _fieldOfView = f; } - void setAspectRatio ( float a ) { _aspectRatio = a; } - void setNearClip ( float n ) { _nearClip = n; } - void setFarClip ( float f ) { _farClip = f; } + void setMode ( CameraMode m ) { _mode = m; } + void setYaw ( float y ) { _yaw = y; } + void setPitch ( float p ) { _pitch = p; } + void setRoll ( float r ) { _roll = r; } + void setUpShift ( float u ) { _upShift = u; } + void setRightShift ( float r ) { _rightShift = r; } + void setDistance ( float d ) { _distance = d; } + void setTargetPosition( glm::vec3 t ) { _targetPosition = t; } + void setTargetYaw ( float y ) { _idealYaw = y; } + void setPosition ( glm::vec3 p ) { _position = p; } + void setOrientation ( Orientation o ) { _orientation.set(o); } + void setTightness ( float t ) { _tightness = t; } + void setFieldOfView ( float f ) { _fieldOfView = f; } + void setAspectRatio ( float a ) { _aspectRatio = a; } + void setNearClip ( float n ) { _nearClip = n; } + void setFarClip ( float f ) { _farClip = f; } - float getYaw () { return _yaw; } - float getPitch () { return _pitch; } - float getRoll () { return _roll; } - glm::vec3 getPosition () { return _position; } - Orientation getOrientation () { return _orientation; } - CameraMode getMode () { return _mode; } - float getFieldOfView () { return _fieldOfView; } - float getAspectRatio () { return _aspectRatio; } - float getNearClip () { return _nearClip; } - float getFarClip () { return _farClip; } + float getYaw () { return _yaw; } + float getPitch () { return _pitch; } + float getRoll () { return _roll; } + glm::vec3 getPosition () { return _position; } + Orientation getOrientation() { return _orientation; } + CameraMode getMode () { return _mode; } + float getFieldOfView() { return _fieldOfView; } + float getAspectRatio() { return _aspectRatio; } + float getNearClip () { return _nearClip; } + float getFarClip () { return _farClip; } private: @@ -68,7 +68,8 @@ private: float _yaw; float _pitch; float _roll; - float _up; + float _upShift; + float _rightShift; float _idealYaw; float _distance; float _tightness; diff --git a/interface/src/main.cpp b/interface/src/main.cpp index 497bbfd946..255b541c30 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -800,33 +800,38 @@ void display(void) glMaterialfv(GL_FRONT, GL_SPECULAR, specular_color); glMateriali(GL_FRONT, GL_SHININESS, 96); - //-------------------------------------------------------- // camera settings - //-------------------------------------------------------- if ( ::lookingInMirror ) { - //----------------------------------------------- // set the camera to looking at my own face - //----------------------------------------------- myCamera.setTargetPosition ( myAvatar.getHeadPosition() ); - myCamera.setYaw ( - myAvatar.getBodyYaw() ); + myCamera.setTargetYaw ( - myAvatar.getBodyYaw() ); myCamera.setPitch ( 0.0 ); myCamera.setRoll ( 0.0 ); - myCamera.setUp ( 0.0 ); + myCamera.setUpShift ( 0.0 ); myCamera.setDistance ( 0.2 ); myCamera.setTightness ( 100.0f ); myCamera.update ( 1.f/FPS ); } else { - //---------------------------------------------------- - // set the camera to third-person view behind my av - //---------------------------------------------------- - myCamera.setTargetPosition ( myAvatar.getPosition() ); - myCamera.setYaw ( 180.0 - myAvatar.getBodyYaw() ); - myCamera.setPitch ( 0.0 ); // temporarily, this must be 0.0 or else bad juju - myCamera.setRoll ( 0.0 ); - myCamera.setUp ( 0.45 ); - myCamera.setDistance ( 1.0 ); - myCamera.setTightness ( 8.0f ); - myCamera.update ( 1.f/FPS); + + //this is in the prototyping stages..keep firstPerson false for now. + bool firstPerson = false; + + if ( firstPerson ) { + myCamera.setPitch (15.0f ); // temporarily, this must be 0.0 or else bad juju + myCamera.setUpShift (0.0f ); + myCamera.setDistance (0.0f ); + myCamera.setTightness (100.0f); + } else { + myCamera.setPitch (0.0f ); // temporarily, this must be 0.0 or else bad juju + myCamera.setUpShift (-0.1f); + myCamera.setDistance (1.0f ); + myCamera.setTightness (8.0f ); + } + + myCamera.setTargetPosition( myAvatar.getHeadPosition() ); + myCamera.setTargetYaw ( 180.0 - myAvatar.getBodyYaw() ); + myCamera.setRoll ( 0.0 ); + myCamera.update ( 1.f/FPS); } // Note: whichCamera is used to pick between the normal camera myCamera for our @@ -843,10 +848,10 @@ void display(void) if (::viewFrustumFromOffset && ::frustumOn) { // set the camera to third-person view but offset so we can see the frustum - viewFrustumOffsetCamera.setYaw ( 180.0 - myAvatar.getBodyYaw() + ::viewFrustumOffsetYaw ); + viewFrustumOffsetCamera.setTargetYaw( 180.0 - myAvatar.getBodyYaw() + ::viewFrustumOffsetYaw ); viewFrustumOffsetCamera.setPitch ( ::viewFrustumOffsetPitch ); viewFrustumOffsetCamera.setRoll ( ::viewFrustumOffsetRoll ); - viewFrustumOffsetCamera.setUp ( ::viewFrustumOffsetUp ); + viewFrustumOffsetCamera.setUpShift ( ::viewFrustumOffsetUp ); viewFrustumOffsetCamera.setDistance ( ::viewFrustumOffsetDistance ); viewFrustumOffsetCamera.update(1.f/FPS); whichCamera = viewFrustumOffsetCamera; @@ -864,10 +869,8 @@ void display(void) if (::starsOn) { // should be the first rendering pass - w/o depth buffer / lighting - // finally render the starfield stars.render(whichCamera.getFieldOfView(), aspectRatio, whichCamera.getNearClip()); - } glEnable(GL_LIGHTING); From 5a0a1c1cecad19a471a94c1af7193d598f663b50 Mon Sep 17 00:00:00 2001 From: Jeffrey Ventrella Date: Thu, 25 Apr 2013 13:51:20 -0700 Subject: [PATCH 3/5] increased YAW_MAG (faster turning), redesigned the concept of avatar position, and reset Eve's position accordingly. Also added _frustumNeedsReshape in camera in anticipation of fixing problem where setting fov doesn't reshape the frustum. --- eve/src/main.cpp | 5 ++--- interface/src/Avatar.cpp | 44 +++++++++++++++++++++++++++++++--------- interface/src/Avatar.h | 3 ++- interface/src/Camera.cpp | 31 ++++++++++++++-------------- interface/src/Camera.h | 9 ++++---- interface/src/main.cpp | 19 +++++++++-------- 6 files changed, 70 insertions(+), 41 deletions(-) diff --git a/eve/src/main.cpp b/eve/src/main.cpp index 2da001b368..b4e6675ca0 100644 --- a/eve/src/main.cpp +++ b/eve/src/main.cpp @@ -113,9 +113,8 @@ int main(int argc, const char* argv[]) { // move eve away from the origin // pick a random point inside a 10x10 grid - eve.setPosition(glm::vec3(randFloatInRange(-RANDOM_POSITION_MAX_DIMENSION, RANDOM_POSITION_MAX_DIMENSION), - 0, - randFloatInRange(-RANDOM_POSITION_MAX_DIMENSION, RANDOM_POSITION_MAX_DIMENSION))); + eve.setPosition(glm::vec3(randFloatInRange(-RANDOM_POSITION_MAX_DIMENSION, RANDOM_POSITION_MAX_DIMENSION), 0.4, + randFloatInRange(-RANDOM_POSITION_MAX_DIMENSION, RANDOM_POSITION_MAX_DIMENSION))); // face any instance of eve down the z-axis eve.setBodyYaw(0); diff --git a/interface/src/Avatar.cpp b/interface/src/Avatar.cpp index c77efd28b9..fce2af682e 100644 --- a/interface/src/Avatar.cpp +++ b/interface/src/Avatar.cpp @@ -59,8 +59,7 @@ Avatar::Avatar(bool isMine) { //_transmitterTimer = 0; _transmitterHz = 0.0; _transmitterPackets = 0; - - initializeSkeleton(); + _pelvisStandingHeight = 0.0f; _TEST_bigSphereRadius = 0.3f; _TEST_bigSpherePosition = glm::vec3( 0.0f, _TEST_bigSphereRadius, 2.0f ); @@ -117,6 +116,8 @@ Avatar::Avatar(bool isMine) { _handHolding.velocity = glm::vec3( 0.0, 0.0, 0.0 ); _handHolding.force = 10.0f; + initializeSkeleton(); + if (iris_texture.size() == 0) { switchToResourcesParentIfRequired(); unsigned error = lodepng::decode(iris_texture, iris_texture_width, iris_texture_height, iris_texture_file); @@ -127,7 +128,6 @@ Avatar::Avatar(bool isMine) { } - Avatar::Avatar(const Avatar &otherAvatar) { _velocity = otherAvatar._velocity; @@ -156,8 +156,6 @@ Avatar::Avatar(const Avatar &otherAvatar) { _orientation.set( otherAvatar._orientation ); _sphere = NULL; - - initializeSkeleton(); for (int i = 0; i < MAX_DRIVE_KEYS; i++) _driveKeys[i] = otherAvatar._driveKeys[i]; @@ -198,6 +196,9 @@ Avatar::Avatar(const Avatar &otherAvatar) { _head.browAudioLift = otherAvatar._head.browAudioLift; _head.noise = otherAvatar._head.noise; + + initializeSkeleton(); + if (iris_texture.size() == 0) { switchToResourcesParentIfRequired(); unsigned error = lodepng::decode(iris_texture, iris_texture_width, iris_texture_height, iris_texture_file); @@ -315,7 +316,7 @@ void Avatar::simulate(float deltaTime) { // check for collisions with other avatars and respond updateAvatarCollisionDetectionAndResponse ( - otherAvatar->getBonePosition( AVATAR_BONE_PELVIS_SPINE ), + otherAvatar->getPosition(), 0.1, 0.1, otherAvatar->getBodyUpDirection(), @@ -327,7 +328,7 @@ void Avatar::simulate(float deltaTime) { v -= otherAvatar->getBonePosition( AVATAR_BONE_RIGHT_HAND ); float distance = glm::length( v ); - if ( distance < _maxArmLength ) { + if ( distance < _maxArmLength + _maxArmLength ) { //if ( distance < closestDistance ) { // perhaps I don't need this if we want to allow multi-avatar interactions { @@ -376,6 +377,19 @@ void Avatar::simulate(float deltaTime) { ); } + if ( AVATAR_GRAVITY ) { + if ( _position.y > _pelvisStandingHeight + 0.01 ) { + _velocity += glm::dvec3( 0.0, -1.0, 0.0 ) * ( 6.0 * deltaTime ); + } + else { + if ( _position.y < _pelvisStandingHeight ) { + _position.y = _pelvisStandingHeight; + _velocity.y = 0.0; + } + } + } + + /* if ( AVATAR_GRAVITY ) { if ( _position.y > _bone[ AVATAR_BONE_RIGHT_FOOT ].radius * 2.0 ) { _velocity += glm::dvec3( 0.0, -1.0, 0.0 ) * ( 6.0 * deltaTime ); @@ -387,6 +401,8 @@ void Avatar::simulate(float deltaTime) { } } } + */ + // update body springs updateBodySprings( deltaTime ); @@ -612,6 +628,7 @@ void Avatar::updateAvatarCollisionDetectionAndResponse void Avatar::render(bool lookingInMirror) { + /* // show avatar position glColor4f( 0.5f, 0.5f, 0.5f, 0.6 ); glPushMatrix(); @@ -619,6 +636,7 @@ void Avatar::render(bool lookingInMirror) { glScalef( 0.03, 0.03, 0.03 ); glutSolidSphere( 1, 10, 10 ); glPopMatrix(); + */ if ( usingBigSphereCollisionTest ) { @@ -884,7 +902,7 @@ void Avatar::initializeSkeleton() { _bone[ AVATAR_BONE_RIGHT_FOOT ].parent = AVATAR_BONE_RIGHT_SHIN; // specify the default pose position - _bone[ AVATAR_BONE_PELVIS_SPINE ].defaultPosePosition = glm::vec3( 0.0, 0.3, 0.0 ); + _bone[ AVATAR_BONE_PELVIS_SPINE ].defaultPosePosition = glm::vec3( 0.0, 0.0, 0.0 ); _bone[ AVATAR_BONE_MID_SPINE ].defaultPosePosition = glm::vec3( 0.0, 0.1, 0.0 ); _bone[ AVATAR_BONE_CHEST_SPINE ].defaultPosePosition = glm::vec3( 0.0, 0.06, 0.0 ); _bone[ AVATAR_BONE_NECK ].defaultPosePosition = glm::vec3( 0.0, 0.06, 0.0 ); @@ -907,8 +925,7 @@ void Avatar::initializeSkeleton() { _bone[ AVATAR_BONE_RIGHT_THIGH ].defaultPosePosition = glm::vec3( 0.0, -0.15, 0.0 ); _bone[ AVATAR_BONE_RIGHT_SHIN ].defaultPosePosition = glm::vec3( 0.0, -0.15, 0.0 ); _bone[ AVATAR_BONE_RIGHT_FOOT ].defaultPosePosition = glm::vec3( 0.0, 0.0, 0.04 ); - - + _bone[ AVATAR_BONE_PELVIS_SPINE ].radius = 0.05; _bone[ AVATAR_BONE_MID_SPINE ].radius = 0.06; _bone[ AVATAR_BONE_CHEST_SPINE ].radius = 0.03; @@ -935,6 +952,13 @@ void Avatar::initializeSkeleton() { // calculate bone length calculateBoneLengths(); + + _pelvisStandingHeight = + _bone[ AVATAR_BONE_PELVIS_SPINE ].length + + _bone[ AVATAR_BONE_LEFT_THIGH ].length + + _bone[ AVATAR_BONE_LEFT_SHIN ].length + + _bone[ AVATAR_BONE_LEFT_FOOT ].length + + _bone[ AVATAR_BONE_RIGHT_FOOT ].radius; // generate world positions updateSkeleton(); diff --git a/interface/src/Avatar.h b/interface/src/Avatar.h index 32d31184a8..be20b10389 100644 --- a/interface/src/Avatar.h +++ b/interface/src/Avatar.h @@ -25,7 +25,7 @@ const bool AVATAR_GRAVITY = true; const float DECAY = 0.1; const float THRUST_MAG = 10.0; -const float YAW_MAG = 300.0; +const float YAW_MAG = 500.0; //JJV - changed from 300.0; const float TEST_YAW_DECAY = 5.0; const float LIN_VEL_DECAY = 5.0; @@ -246,6 +246,7 @@ class Avatar : public AvatarData { int _transmitterPackets; Avatar* _interactingOther; bool _interactingOtherIsNearby; + float _pelvisStandingHeight; // private methods... void initializeSkeleton(); diff --git a/interface/src/Camera.cpp b/interface/src/Camera.cpp index b251e1f5a5..ce3542b217 100644 --- a/interface/src/Camera.cpp +++ b/interface/src/Camera.cpp @@ -11,21 +11,22 @@ #include "Camera.h" Camera::Camera() { - _mode = CAMERA_MODE_THIRD_PERSON; - _tightness = 10.0; // default - _fieldOfView = 60.0; // default - _nearClip = 0.08; // default - _farClip = 50.0; // default - _yaw = 0.0; - _pitch = 0.0; - _roll = 0.0; - _upShift = 0.0; - _rightShift = 0.0; - _distance = 0.0; - _idealYaw = 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 ); + _frustumNeedsReshape = false; + _mode = CAMERA_MODE_THIRD_PERSON; + _tightness = 10.0; // default + _fieldOfView = 60.0; // default + _nearClip = 0.08; // default + _farClip = 50.0; // default + _yaw = 0.0; + _pitch = 0.0; + _roll = 0.0; + _upShift = 0.0; + _rightShift = 0.0; + _distance = 0.0; + _idealYaw = 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 ); _orientation.setToIdentity(); } diff --git a/interface/src/Camera.h b/interface/src/Camera.h index befb5d0826..41ee21c7f0 100644 --- a/interface/src/Camera.h +++ b/interface/src/Camera.h @@ -39,10 +39,10 @@ public: void setPosition ( glm::vec3 p ) { _position = p; } void setOrientation ( Orientation o ) { _orientation.set(o); } void setTightness ( float t ) { _tightness = t; } - void setFieldOfView ( float f ) { _fieldOfView = f; } - void setAspectRatio ( float a ) { _aspectRatio = a; } - void setNearClip ( float n ) { _nearClip = n; } - void setFarClip ( float f ) { _farClip = f; } + void setFieldOfView ( float f ) { _fieldOfView = f; _frustumNeedsReshape = true; } + void setAspectRatio ( float a ) { _aspectRatio = a; _frustumNeedsReshape = true; } + void setNearClip ( float n ) { _nearClip = n; _frustumNeedsReshape = true; } + void setFarClip ( float f ) { _farClip = f; _frustumNeedsReshape = true; } float getYaw () { return _yaw; } float getPitch () { return _pitch; } @@ -57,6 +57,7 @@ public: private: + bool _frustumNeedsReshape; CameraMode _mode; glm::vec3 _position; glm::vec3 _idealPosition; diff --git a/interface/src/main.cpp b/interface/src/main.cpp index 255b541c30..e0d014d840 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -810,6 +810,7 @@ void display(void) myCamera.setUpShift ( 0.0 ); myCamera.setDistance ( 0.2 ); myCamera.setTightness ( 100.0f ); + myCamera.setFieldOfView ( 60.0f ); //this doesn't seem to be doing anything? myCamera.update ( 1.f/FPS ); } else { @@ -817,15 +818,17 @@ void display(void) bool firstPerson = false; if ( firstPerson ) { - myCamera.setPitch (15.0f ); // temporarily, this must be 0.0 or else bad juju - myCamera.setUpShift (0.0f ); - myCamera.setDistance (0.0f ); - myCamera.setTightness (100.0f); + myCamera.setPitch (15.0f ); // temporarily, this must be 0.0 or else bad juju + myCamera.setUpShift (0.0f ); + myCamera.setDistance (0.0f ); + myCamera.setTightness (100.0f); + myCamera.setFieldOfView(60.0f ); //this doesn't seem to be doing anything? } else { - myCamera.setPitch (0.0f ); // temporarily, this must be 0.0 or else bad juju - myCamera.setUpShift (-0.1f); - myCamera.setDistance (1.0f ); - myCamera.setTightness (8.0f ); + myCamera.setPitch (0.0f ); // temporarily, this must be 0.0 or else bad juju + myCamera.setUpShift (-0.1f); + myCamera.setDistance (1.0f ); + myCamera.setTightness (8.0f ); + myCamera.setFieldOfView(60.0f); //this doesn't seem to be doing anything? } myCamera.setTargetPosition( myAvatar.getHeadPosition() ); From 7a0ed469b8415b1551acef80835610fc9918d161 Mon Sep 17 00:00:00 2001 From: Jeffrey Ventrella Date: Thu, 25 Apr 2013 14:25:28 -0700 Subject: [PATCH 4/5] added methods to camera class to check for when the view frustum needs to be reshaped (but the calls are not yet being made - need to make sure the right place to use it) --- interface/src/Camera.cpp | 12 ++++++++++++ interface/src/Camera.h | 2 ++ interface/src/main.cpp | 2 -- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/interface/src/Camera.cpp b/interface/src/Camera.cpp index ce3542b217..1a4700216a 100644 --- a/interface/src/Camera.cpp +++ b/interface/src/Camera.cpp @@ -63,3 +63,15 @@ void Camera::update( float deltaTime ) { _position += ( _idealPosition - _position ) * t; } +// call to find out if the view frustum needs to be reshaped +bool Camera::getFrustumNeedsReshape() { + return _frustumNeedsReshape; +} + +// call this after reshaping the view frustum +void Camera::setFrustumWasReshaped() { + _frustumNeedsReshape = false; +} + + + diff --git a/interface/src/Camera.h b/interface/src/Camera.h index 41ee21c7f0..1826bb2c1f 100644 --- a/interface/src/Camera.h +++ b/interface/src/Camera.h @@ -54,6 +54,8 @@ public: float getAspectRatio() { return _aspectRatio; } float getNearClip () { return _nearClip; } float getFarClip () { return _farClip; } + bool getFrustumNeedsReshape(); // call to find out if the view frustum needs to be reshaped + void setFrustumWasReshaped(); // call this after reshaping the view frustum. private: diff --git a/interface/src/main.cpp b/interface/src/main.cpp index e0d014d840..080db4fe92 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -240,8 +240,6 @@ void updateHandController( int x, int y ) { handController.startX = WIDTH / 2; handController.startY = HEIGHT / 2; handController.envelope = 0.0; -//prototype -//myAvatar.stopHandMovement(); } } } From 86e72a90d48302e09d61d2bd4a1169409098d651 Mon Sep 17 00:00:00 2001 From: Jeffrey Ventrella Date: Thu, 25 Apr 2013 16:31:42 -0700 Subject: [PATCH 5/5] working on camera view shifting from first person to third person --- interface/src/Avatar.cpp | 38 +++++++++------ interface/src/Avatar.h | 2 + interface/src/Camera.cpp | 102 ++++++++++++++++++++++++--------------- interface/src/Camera.h | 12 +++-- interface/src/main.cpp | 60 ++++++++++++++++------- 5 files changed, 137 insertions(+), 77 deletions(-) diff --git a/interface/src/Avatar.cpp b/interface/src/Avatar.cpp index fce2af682e..ac3fffd853 100644 --- a/interface/src/Avatar.cpp +++ b/interface/src/Avatar.cpp @@ -59,6 +59,7 @@ Avatar::Avatar(bool isMine) { //_transmitterTimer = 0; _transmitterHz = 0.0; _transmitterPackets = 0; + _speed = 0.0; _pelvisStandingHeight = 0.0f; _TEST_bigSphereRadius = 0.3f; @@ -444,18 +445,7 @@ void Avatar::simulate(float deltaTime) { } } - float translationalSpeed = glm::length( _velocity ); - float rotationalSpeed = fabs( _bodyYawDelta ); - if ( translationalSpeed + rotationalSpeed > 0.2 ) - { - _mode = AVATAR_MODE_WALKING; - } - else - { - _mode = AVATAR_MODE_INTERACTING; - } - - // update body yaw by body yaw delta + // update body yaw by body yaw delta if (_isMine) { _bodyYaw += _bodyYawDelta * deltaTime; } @@ -568,6 +558,22 @@ void Avatar::simulate(float deltaTime) { const float AUDIO_AVERAGING_SECS = 0.05; _head.averageLoudness = (1.f - deltaTime / AUDIO_AVERAGING_SECS) * _head.averageLoudness + (deltaTime / AUDIO_AVERAGING_SECS) * _audioLoudness; + + _speed = glm::length( _velocity ); + float rotationalSpeed = fabs( _bodyYawDelta ); + if ( _speed + rotationalSpeed > 0.2 ) + { + _mode = AVATAR_MODE_WALKING; + } + else + { + _mode = AVATAR_MODE_INTERACTING; + } +} + + +float Avatar::getSpeed() { + return _speed; } @@ -1103,11 +1109,11 @@ glm::vec3 Avatar::getBonePosition( AvatarBoneID b ) { void Avatar::updateHandMovement( float deltaTime ) { glm::vec3 transformedHandMovement; - + transformedHandMovement - = _orientation.getRight() * _movedHandOffset.x - + _orientation.getUp() * -_movedHandOffset.y * 0.5f - + _orientation.getFront() * -_movedHandOffset.y; + = _orientation.getRight() * _movedHandOffset.x * 1.6f + + _orientation.getUp() * _movedHandOffset.y * -0.9f + + _orientation.getFront() * _movedHandOffset.y * -1.5f; _bone[ AVATAR_BONE_RIGHT_HAND ].position += transformedHandMovement; diff --git a/interface/src/Avatar.h b/interface/src/Avatar.h index be20b10389..94d2563e39 100644 --- a/interface/src/Avatar.h +++ b/interface/src/Avatar.h @@ -184,6 +184,7 @@ class Avatar : public AvatarData { glm::vec3 getHeadPosition(); glm::vec3 getBonePosition( AvatarBoneID b ); glm::vec3 getBodyUpDirection(); + float getSpeed(); float getGirth(); float getHeight(); @@ -235,6 +236,7 @@ class Avatar : public AvatarData { AvatarHandHolding _handHolding; glm::dvec3 _velocity; glm::vec3 _thrust; + float _speed; float _maxArmLength; Orientation _orientation; int _driveKeys[MAX_DRIVE_KEYS]; diff --git a/interface/src/Camera.cpp b/interface/src/Camera.cpp index 1a4700216a..6118a9ead5 100644 --- a/interface/src/Camera.cpp +++ b/interface/src/Camera.cpp @@ -11,58 +11,80 @@ #include "Camera.h" Camera::Camera() { - _frustumNeedsReshape = false; - _mode = CAMERA_MODE_THIRD_PERSON; - _tightness = 10.0; // default - _fieldOfView = 60.0; // default - _nearClip = 0.08; // default - _farClip = 50.0; // default - _yaw = 0.0; - _pitch = 0.0; - _roll = 0.0; - _upShift = 0.0; - _rightShift = 0.0; - _distance = 0.0; - _idealYaw = 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 ); + _frustumNeedsReshape = false; + _mode = CAMERA_MODE_THIRD_PERSON; + _tightness = 10.0; // default + _fieldOfView = 60.0; // default + _nearClip = 0.08; // default + _farClip = 50.0; // default + _modeShift = 0.0; + _yaw = 0.0; + _pitch = 0.0; + _roll = 0.0; + _upShift = 0.0; + _rightShift = 0.0; + _distance = 0.0; + _idealYaw = 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 ); _orientation.setToIdentity(); } + void Camera::update( float deltaTime ) { - // derive t from tightness - float t = _tightness * deltaTime; - if ( t > 1.0 ) { - t = 1.0; - } - - // update _yaw (before position!) - _yaw += ( _idealYaw - _yaw ) * t; + // generate the ortho-normals for the orientation based on the Euler angles + _orientation.setToIdentity(); + _orientation.yaw ( _yaw ); + _orientation.pitch( _pitch ); + _orientation.roll ( _roll ); - // generate the ortho-normals for the orientation based on the Euler angles - _orientation.setToIdentity(); - _orientation.yaw ( _yaw ); - _orientation.pitch( _pitch ); - _orientation.roll ( _roll ); - - float radian = ( _yaw / 180.0 ) * PIE; + if ( _mode == CAMERA_MODE_NULL ) { + _modeShift = 0.0; + } else { + // use iterative forces to keep the camera at the desired position and angle + updateFollowMode( deltaTime ); + + if ( _modeShift < 1.0f ) { + _modeShift += MODE_SHIFT_RATE * deltaTime; + if ( _modeShift > 1.0f ) { + _modeShift = 1.0f; + } + } + } +} - // update _position - //these need to be checked to make sure they correspond to the correct coordinate system. - double x = _distance * -sin( radian ); - double z = _distance * cos( radian ); - double y = _upShift; - - _idealPosition = _targetPosition + glm::vec3( x, y, z ); + +// use iterative forces to keep the camera at the desired position and angle +void Camera::updateFollowMode( float deltaTime ) { + // derive t from tightness + float t = _tightness * deltaTime; + if ( t > 1.0 ) { + t = 1.0; + } + + // update _yaw (before position!) + _yaw += ( _idealYaw - _yaw ) * t; + _orientation.yaw ( _yaw ); + + float radian = ( _yaw / 180.0 ) * PIE; + + // update _position + //these need to be checked to make sure they correspond to the correct coordinate system. + double x = _distance * -sin( radian ); + double z = _distance * cos( radian ); + double y = _upShift; + + _idealPosition = _targetPosition + glm::vec3( x, y, z ); //_idealPosition += _orientation.getRight() * _rightShift; //_idealPosition += _orientation.getUp () * _upShift; - + // pull position towards ideal position - _position += ( _idealPosition - _position ) * t; + _position += ( _idealPosition - _position ) * t; } + // call to find out if the view frustum needs to be reshaped bool Camera::getFrustumNeedsReshape() { return _frustumNeedsReshape; diff --git a/interface/src/Camera.h b/interface/src/Camera.h index 1826bb2c1f..51760867c0 100644 --- a/interface/src/Camera.h +++ b/interface/src/Camera.h @@ -14,12 +14,14 @@ enum CameraMode { CAMERA_MODE_NULL = -1, - CAMERA_MODE_FIRST_PERSON, CAMERA_MODE_THIRD_PERSON, + CAMERA_MODE_FIRST_PERSON, CAMERA_MODE_MY_OWN_FACE, NUM_CAMERA_MODES }; +const float MODE_SHIFT_RATE = 2.0f; + class Camera { public: @@ -27,7 +29,7 @@ public: void update( float deltaTime ); - void setMode ( CameraMode m ) { _mode = m; } + void setMode ( CameraMode m ) { _mode = m; _modeShift = 0.0f; } void setYaw ( float y ) { _yaw = y; } void setPitch ( float p ) { _pitch = p; } void setRoll ( float r ) { _roll = r; } @@ -50,6 +52,7 @@ public: glm::vec3 getPosition () { return _position; } Orientation getOrientation() { return _orientation; } CameraMode getMode () { return _mode; } + float getModeShift () { return _modeShift; } float getFieldOfView() { return _fieldOfView; } float getAspectRatio() { return _aspectRatio; } float getNearClip () { return _nearClip; } @@ -59,8 +62,9 @@ public: private: + CameraMode _mode; + float _modeShift; // 0.0 to 1.0 bool _frustumNeedsReshape; - CameraMode _mode; glm::vec3 _position; glm::vec3 _idealPosition; glm::vec3 _targetPosition; @@ -77,6 +81,8 @@ private: float _distance; float _tightness; Orientation _orientation; + + void updateFollowMode( float deltaTime ); }; #endif diff --git a/interface/src/main.cpp b/interface/src/main.cpp index 080db4fe92..fcaff494c1 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -808,32 +808,56 @@ void display(void) myCamera.setUpShift ( 0.0 ); myCamera.setDistance ( 0.2 ); myCamera.setTightness ( 100.0f ); - myCamera.setFieldOfView ( 60.0f ); //this doesn't seem to be doing anything? - myCamera.update ( 1.f/FPS ); } else { - - //this is in the prototyping stages..keep firstPerson false for now. - bool firstPerson = false; - - if ( firstPerson ) { - myCamera.setPitch (15.0f ); // temporarily, this must be 0.0 or else bad juju - myCamera.setUpShift (0.0f ); - myCamera.setDistance (0.0f ); - myCamera.setTightness (100.0f); - myCamera.setFieldOfView(60.0f ); //this doesn't seem to be doing anything? + + float firstPersonPitch = 20.0f; + float firstPersonUpShift = 0.1f; + float firstPersonDistance = 0.0f; + float firstPersonTightness = 100.0f; + + float thirdPersonPitch = 0.0f; + float thirdPersonUpShift = -0.1f; + float thirdPersonDistance = 1.f; + float thirdPersonTightness = 8.0f; + + myCamera.setPitch (thirdPersonPitch ); + myCamera.setUpShift (thirdPersonUpShift ); + myCamera.setDistance (thirdPersonDistance ); + myCamera.setTightness(thirdPersonTightness); + + /* + if ( myAvatar.getSpeed() < 0.02 ) { + if (myCamera.getMode() != CAMERA_MODE_FIRST_PERSON ) { + myCamera.setMode(CAMERA_MODE_FIRST_PERSON); + } + + printf( "myCamera.getModeShift() = %f\n", myCamera.getModeShift()); + + myCamera.setPitch ( thirdPersonPitch + myCamera.getModeShift() * ( firstPersonPitch - thirdPersonPitch )); + myCamera.setUpShift ( thirdPersonUpShift + myCamera.getModeShift() * ( firstPersonUpShift - thirdPersonUpShift )); + myCamera.setDistance ( thirdPersonDistance + myCamera.getModeShift() * ( firstPersonDistance - thirdPersonDistance )); + myCamera.setTightness ( thirdPersonTightness + myCamera.getModeShift() * ( firstPersonTightness - thirdPersonTightness )); } else { - myCamera.setPitch (0.0f ); // temporarily, this must be 0.0 or else bad juju - myCamera.setUpShift (-0.1f); - myCamera.setDistance (1.0f ); - myCamera.setTightness (8.0f ); - myCamera.setFieldOfView(60.0f); //this doesn't seem to be doing anything? + if (myCamera.getMode() != CAMERA_MODE_THIRD_PERSON ) { + myCamera.setMode(CAMERA_MODE_THIRD_PERSON); + } + + printf( "myCamera.getModeShift() = %f\n", myCamera.getModeShift()); + + myCamera.setPitch ( firstPersonPitch + myCamera.getModeShift() * ( thirdPersonPitch - firstPersonPitch )); + myCamera.setUpShift ( firstPersonUpShift + myCamera.getModeShift() * ( thirdPersonUpShift - firstPersonUpShift )); + myCamera.setDistance ( firstPersonDistance + myCamera.getModeShift() * ( thirdPersonDistance - firstPersonDistance )); + myCamera.setTightness ( firstPersonTightness + myCamera.getModeShift() * ( thirdPersonTightness - firstPersonTightness )); } + */ myCamera.setTargetPosition( myAvatar.getHeadPosition() ); myCamera.setTargetYaw ( 180.0 - myAvatar.getBodyYaw() ); myCamera.setRoll ( 0.0 ); - myCamera.update ( 1.f/FPS); } + + // important... + myCamera.update( 1.f/FPS ); // Note: whichCamera is used to pick between the normal camera myCamera for our // main camera, vs, an alternate camera. The alternate camera we support right now