From adccd62f87feb0f81d805edf733cf544ca909167 Mon Sep 17 00:00:00 2001 From: Jeffrey Ventrella Date: Fri, 26 Apr 2013 17:43:47 -0700 Subject: [PATCH] made a different prototype for camera shifting into first-person --- interface/src/Avatar.cpp | 92 +++++++++++++++++++--------------------- interface/src/Avatar.h | 15 +++---- interface/src/main.cpp | 48 ++++++++++++++++++--- 3 files changed, 91 insertions(+), 64 deletions(-) diff --git a/interface/src/Avatar.cpp b/interface/src/Avatar.cpp index 3de87186f2..4fa556c66d 100644 --- a/interface/src/Avatar.cpp +++ b/interface/src/Avatar.cpp @@ -50,23 +50,22 @@ Avatar::Avatar(bool isMine) { _orientation.setToIdentity(); - _velocity = glm::vec3( 0.0, 0.0, 0.0 ); - _thrust = glm::vec3( 0.0, 0.0, 0.0 ); - _rotation = glm::quat( 0.0f, 0.0f, 0.0f, 0.0f ); - _bodyYaw = -90.0; - _bodyPitch = 0.0; - _bodyRoll = 0.0; - _bodyYawDelta = 0.0; - _mousePressed = false; - _mode = AVATAR_MODE_STANDING; - _isMine = isMine; - _maxArmLength = 0.0; - //_transmitterTimer = 0; - _transmitterHz = 0.0; - _transmitterPackets = 0; - _speed = 0.0; + _velocity = glm::vec3( 0.0, 0.0, 0.0 ); + _thrust = glm::vec3( 0.0, 0.0, 0.0 ); + _rotation = glm::quat( 0.0f, 0.0f, 0.0f, 0.0f ); + _bodyYaw = -90.0; + _bodyPitch = 0.0; + _bodyRoll = 0.0; + _bodyYawDelta = 0.0; + _mousePressed = false; + _mode = AVATAR_MODE_STANDING; + _isMine = isMine; + _maxArmLength = 0.0; + _transmitterHz = 0.0; + _transmitterPackets = 0; + _speed = 0.0; _pelvisStandingHeight = 0.0f; - + _displayingHead = true; _TEST_bigSphereRadius = 0.3f; _TEST_bigSpherePosition = glm::vec3( 0.0f, _TEST_bigSphereRadius, 2.0f ); @@ -591,6 +590,11 @@ void Avatar::updateAvatarCollisionDetectionAndResponse(glm::vec3 collisionPositi } } +void Avatar::setDisplayingHead( bool displayingHead ) { + _displayingHead = displayingHead; +} + + void Avatar::render(bool lookingInMirror) { /* @@ -618,8 +622,10 @@ void Avatar::render(bool lookingInMirror) { renderBody(); // render head - renderHead(lookingInMirror); - + if (_displayingHead) { + renderHead(lookingInMirror); + } + // if this is my avatar, then render my interactions with the other avatar if ( _isMine ) { @@ -1131,25 +1137,27 @@ void Avatar::renderBody() { // Render bone positions as spheres for (int b = 0; b < NUM_AVATAR_BONES; b++) { - //renderBoneAsBlock( (AvatarBoneID)b); - //render bone orientation - //renderOrientationDirections( _bone[b].springyPosition, _bone[b].orientation, _bone[b].radius * 2.0 ); - - if ( _usingBodySprings ) { - glColor3fv( skinColor ); - glPushMatrix(); - glTranslatef( _bone[b].springyPosition.x, _bone[b].springyPosition.y, _bone[b].springyPosition.z ); - glutSolidSphere( _bone[b].radius, 20.0f, 20.0f ); - glPopMatrix(); - } - else { - glColor3fv( skinColor ); - glPushMatrix(); - glTranslatef( _bone[b].position.x, _bone[b].position.y, _bone[b].position.z ); - glutSolidSphere( _bone[b].radius, 20.0f, 20.0f ); - glPopMatrix(); - } + if ( b != AVATAR_BONE_HEAD ) { // the head is rendered as a special case in "renderHead" + + //render bone orientation + //renderOrientationDirections( _bone[b].springyPosition, _bone[b].orientation, _bone[b].radius * 2.0 ); + + if ( _usingBodySprings ) { + glColor3fv( skinColor ); + glPushMatrix(); + glTranslatef( _bone[b].springyPosition.x, _bone[b].springyPosition.y, _bone[b].springyPosition.z ); + glutSolidSphere( _bone[b].radius, 20.0f, 20.0f ); + glPopMatrix(); + } + else { + glColor3fv( skinColor ); + glPushMatrix(); + glTranslatef( _bone[b].position.x, _bone[b].position.y, _bone[b].position.z ); + glutSolidSphere( _bone[b].radius, 20.0f, 20.0f ); + glPopMatrix(); + } + } } // Render lines connecting the bone positions @@ -1194,18 +1202,6 @@ void Avatar::renderBody() { } } -void Avatar::renderBoneAsBlock( AvatarBoneID b ) { - glColor3fv( skinColor ); - glPushMatrix(); - glTranslatef( _bone[b].springyPosition.x, _bone[b].springyPosition.y, _bone[b].springyPosition.z ); - glScalef( _bone[b].radius, _bone[b].length, _bone[b].radius ); - glRotatef(_bone[b].yaw, 0, 1, 0 ); - glRotatef(_bone[b].pitch, 1, 0, 0 ); - glRotatef(_bone[b].roll, 0, 0, 1 ); - glutSolidCube(1.0); - glPopMatrix(); -} - void Avatar::SetNewHeadTarget(float pitch, float yaw) { _head.pitchTarget = pitch; _head.yawTarget = yaw; diff --git a/interface/src/Avatar.h b/interface/src/Avatar.h index 6afb65c904..0e6d600a32 100644 --- a/interface/src/Avatar.h +++ b/interface/src/Avatar.h @@ -89,16 +89,8 @@ enum AvatarBoneID NUM_AVATAR_BONES }; -struct AvatarCollisionElipsoid -{ - bool colliding; - glm::vec3 position; - float girth; - float height; - glm::vec3 upVector; -}; -struct AvatarHandHolding +struct AvatarHandHolding //think of this as one half of a distributed spring :) { glm::vec3 position; glm::vec3 velocity; @@ -181,6 +173,8 @@ public: float getBodyYaw() {return _bodyYaw;}; void addBodyYaw(float y) {_bodyYaw += y;}; + bool getIsNearInteractingOther() { return _interactingOtherIsNearby; } + float getAbsoluteHeadYaw() const; void setLeanForward(float dist); void setLeanSideways(float dist); @@ -208,6 +202,7 @@ public: void setHandMovementValues( glm::vec3 movement ); void updateHandMovement( float deltaTime ); void updateArmIKAndConstraints( float deltaTime ); + void setDisplayingHead( bool displayingHead ); float getAverageLoudness() {return _head.averageLoudness;}; void setAverageLoudness(float al) {_head.averageLoudness = al;}; @@ -262,6 +257,7 @@ private: float _pelvisStandingHeight; Balls* _balls; AvatarTouch _avatarTouch; + bool _displayingHead; // should be false if in first-person view // private methods... void initializeSkeleton(); @@ -270,7 +266,6 @@ private: void updateBodySprings( float deltaTime ); void calculateBoneLengths(); void readSensors(); - void renderBoneAsBlock( AvatarBoneID b ); void updateAvatarCollisionDetectionAndResponse ( glm::vec3 collisionPosition, diff --git a/interface/src/main.cpp b/interface/src/main.cpp index 404f3bbfa9..05402d51bb 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -102,7 +102,7 @@ int HEIGHT = 800; int fullscreen = 0; float aspectRatio = 1.0f; -bool USING_FIRST_PERSON_EFFECT = false; +bool USING_FIRST_PERSON_EFFECT = true; bool wantColorRandomizer = true; // for addSphere and load file @@ -738,9 +738,14 @@ void display(void) myCamera.setTightness ( 100.0f ); } else { + //float firstPersonPitch = 20.0f; + //float firstPersonUpShift = 0.0f; + //float firstPersonDistance = 0.0f; + //float firstPersonTightness = 100.0f; + float firstPersonPitch = 20.0f; float firstPersonUpShift = 0.1f; - float firstPersonDistance = 0.0f; + float firstPersonDistance = 0.4f; float firstPersonTightness = 100.0f; float thirdPersonPitch = 0.0f; @@ -749,14 +754,44 @@ void display(void) float thirdPersonTightness = 8.0f; if ( USING_FIRST_PERSON_EFFECT ) { + float ff = 0.0; + float min = 0.1; + float max = 0.5; + + if ( myAvatar.getIsNearInteractingOther()){ + if ( myAvatar.getSpeed() < max ) { + + float s = (myAvatar.getSpeed()- min)/max ; + ff = 1.0 - s; + } + } + + /* + if ( ff < 0.8 ) { + myAvatar.setDisplayingHead( true ); + } else { + myAvatar.setDisplayingHead( false ); + } + */ + + //printf( "ff = %f\n", ff ); + + myCamera.setPitch ( thirdPersonPitch + ff * ( firstPersonPitch - thirdPersonPitch )); + myCamera.setUpShift ( thirdPersonUpShift + ff * ( firstPersonUpShift - thirdPersonUpShift )); + myCamera.setDistance ( thirdPersonDistance + ff * ( firstPersonDistance - thirdPersonDistance )); + myCamera.setTightness ( thirdPersonTightness + ff * ( firstPersonTightness - thirdPersonTightness )); + + + + // this version uses a ramp-up/ramp-down timer in the camera to determine shift between first and thirs-person view + /* 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()); - + //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 )); @@ -766,13 +801,14 @@ void display(void) myCamera.setMode(CAMERA_MODE_THIRD_PERSON); } - printf( "myCamera.getModeShift() = %f\n", myCamera.getModeShift()); - + //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 )); } + */ + } else { myCamera.setPitch (thirdPersonPitch ); myCamera.setUpShift (thirdPersonUpShift );