From cd334c2ade297ca68374b2be1741dde590769b6a Mon Sep 17 00:00:00 2001 From: Jeffrey Ventrella Date: Thu, 2 May 2013 13:13:56 -0700 Subject: [PATCH 1/5] renamed avatar skeleton from "bones" to "joints" to be more consistent with standard language. Also improved skeleton some --- interface/src/Avatar.cpp | 680 ++++++++++++++++++--------------------- interface/src/Avatar.h | 109 ++++--- 2 files changed, 390 insertions(+), 399 deletions(-) diff --git a/interface/src/Avatar.cpp b/interface/src/Avatar.cpp index cfb6fb9f6a..5ffae0115e 100644 --- a/interface/src/Avatar.cpp +++ b/interface/src/Avatar.cpp @@ -20,29 +20,6 @@ using namespace std; -/* -const bool BALLS_ON = false; - -const bool AVATAR_GRAVITY = true; -const float DECAY = 0.1; - -//const float THRUST_MAG = 1200.0; -const float THRUST_MAG = 0.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; -const float MY_HAND_HOLDING_PULL = 0.2; -const float YOUR_HAND_HOLDING_PULL = 1.0; -const float BODY_SPRING_FORCE = 6.0f; -const float BODY_SPRING_DECAY = 16.0f; -const float COLLISION_RADIUS_SCALAR = 1.8; -const float COLLISION_BALL_FORCE = 0.6; -const float COLLISION_BODY_FORCE = 6.0; -const float COLLISION_BALL_FRICTION = 200.0; -const float COLLISION_BODY_FRICTION = 0.5; -*/ - float skinColor[] = {1.0, 0.84, 0.66}; float lightBlue[] = { 0.7, 0.8, 1.0 }; float browColor[] = {210.0/255.0, 105.0/255.0, 30.0/255.0}; @@ -140,7 +117,6 @@ Avatar::Avatar(bool isMine) { _renderPitch = 0.0; _sphere = NULL; _interactingOther = NULL; - //_canReachToOtherAvatar = false; _handHoldingPosition = glm::vec3( 0.0, 0.0, 0.0 ); initializeSkeleton(); @@ -162,7 +138,6 @@ Avatar::Avatar(const Avatar &otherAvatar) { _velocity = otherAvatar._velocity; _thrust = otherAvatar._thrust; _rotation = otherAvatar._rotation; - //_canReachToOtherAvatar = otherAvatar._canReachToOtherAvatar; _bodyYaw = otherAvatar._bodyYaw; _bodyPitch = otherAvatar._bodyPitch; _bodyRoll = otherAvatar._bodyRoll; @@ -328,115 +303,21 @@ bool Avatar::getIsNearInteractingOther() { void Avatar::simulate(float deltaTime) { -//keep this - I'm still using it to test things.... -/* -//TEST -static float tt = 0.0f; -tt += deltaTime * 2.0f; -//_head.leanSideways = 0.01 * sin( tt ); -_head.leanForward = 0.02 * sin( tt * 0.8 ); -*/ - // update balls if (_balls) { _balls->simulate(deltaTime); } // update avatar skeleton updateSkeleton(); - // reset hand and arm positions according to hand movement - updateHandMovement( deltaTime ); - - if ( !_avatarTouch.getAbleToReachOtherAvatar() ) { - //initialize _handHolding - _handHoldingPosition = _bone[ AVATAR_BONE_RIGHT_HAND ].position; - } - - //reset these for the next go-round - _avatarTouch.setAbleToReachOtherAvatar (false); - _avatarTouch.setHandsCloseEnoughToGrasp(false); - - // if the avatar being simulated is mine, then loop through - // all the other avatars for potential interactions... - if ( _isMine ) - { - AgentList* agentList = AgentList::getInstance(); - for (AgentList::iterator agent = agentList->begin(); agent != agentList->end(); agent++) { - if (agent->getLinkedData() != NULL && agent->getType() == AGENT_TYPE_AVATAR) { - Avatar *otherAvatar = (Avatar *)agent->getLinkedData(); - - // check for collisions with other avatars and respond - updateCollisionWithOtherAvatar(otherAvatar, deltaTime ); - - // test other avatar hand position for proximity - glm::vec3 v( _bone[ AVATAR_BONE_RIGHT_SHOULDER ].position ); - v -= otherAvatar->getBonePosition( AVATAR_BONE_RIGHT_SHOULDER ); - - float distance = glm::length( v ); - if ( distance < _maxArmLength + _maxArmLength ) { - - _interactingOther = otherAvatar; - _avatarTouch.setAbleToReachOtherAvatar(true); - - glm::vec3 vectorBetweenHands( _bone[ AVATAR_BONE_RIGHT_HAND ].position ); - vectorBetweenHands -= otherAvatar->getBonePosition( AVATAR_BONE_RIGHT_HAND ); - float distanceBetweenHands = glm::length(vectorBetweenHands); - - if (distanceBetweenHands < _avatarTouch.HANDS_CLOSE_ENOUGH_TO_GRASP) { - _avatarTouch.setHandsCloseEnoughToGrasp(true); - } - - // if I am holding hands with another avatar, a force is applied - if (( _handState == 1 ) || ( _interactingOther->_handState == 1 )) { - - // if the hands are close enough to grasp... - if (distanceBetweenHands < _avatarTouch.HANDS_CLOSE_ENOUGH_TO_GRASP) - { - // apply the forces... - glm::vec3 vectorToOtherHand = _interactingOther->_handPosition - _handHoldingPosition; - glm::vec3 vectorToMyHand = _bone[ AVATAR_BONE_RIGHT_HAND ].position - _handHoldingPosition; - - _handHoldingPosition += vectorToOtherHand * YOUR_HAND_HOLDING_PULL; - _handHoldingPosition += vectorToMyHand * MY_HAND_HOLDING_PULL; - _bone[ AVATAR_BONE_RIGHT_HAND ].position = _handHoldingPosition; - - // apply a force to the avatar body - if ( glm::length(vectorToOtherHand) > _maxArmLength * 0.9 ) { - _velocity += vectorToOtherHand; - } - } - } - } - } - } + //update the movement of the hand and process handshaking with other avatars... + updateHandMovementAndTouching(deltaTime); - // Set the vector we send for hand position to other people to be our right hand - setHandPosition(_bone[ AVATAR_BONE_RIGHT_HAND ].position); - - }//if ( _isMine ) - - //constrain right arm length and re-adjust elbow position as it bends - updateArmIKAndConstraints( deltaTime ); - - // set hand positions for _avatarTouch.setMyHandPosition AFTER calling updateArmIKAndConstraints - if ( _interactingOther ) { - if (_isMine) { - _avatarTouch.setMyHandPosition ( _bone[ AVATAR_BONE_RIGHT_HAND ].position ); - _avatarTouch.setYourHandPosition( _interactingOther->_bone[ AVATAR_BONE_RIGHT_HAND ].position ); - _avatarTouch.setMyHandState ( _handState ); - _avatarTouch.setYourHandState ( _interactingOther->_handState ); - _avatarTouch.simulate(deltaTime); - } - } - - if (!_avatarTouch.getAbleToReachOtherAvatar() ) { - _interactingOther = NULL; - } - + // test for avatar collision response with the big sphere if (usingBigSphereCollisionTest) { - // test for avatar collision response with the big sphere updateCollisionWithSphere( _TEST_bigSpherePosition, _TEST_bigSphereRadius, deltaTime ); } + // apply gravity and collision wiht the ground/floor if ( AVATAR_GRAVITY ) { if ( _position.y > _pelvisStandingHeight + 0.01 ) { _velocity += glm::dvec3(getGravity(getPosition())) * ( 6.0 * deltaTime ); @@ -497,6 +378,112 @@ _head.leanForward = 0.02 * sin( tt * 0.8 ); } } + + +//update the movement of the hand and process handshaking with other avatars... +void Avatar::updateHandMovementAndTouching(float deltaTime) { + + // reset hand and arm positions according to hand movement + glm::vec3 transformedHandMovement + = _orientation.getRight() * _movedHandOffset.x * 2.0f + + _orientation.getUp() * -_movedHandOffset.y * 1.0f + + _orientation.getFront() * -_movedHandOffset.y * 1.0f; + + _joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position += transformedHandMovement; + + if (_isMine) { + _handState = _mousePressed; + } + + //reset these for the next go-round + _avatarTouch.setAbleToReachOtherAvatar (false); + _avatarTouch.setHandsCloseEnoughToGrasp(false); + + // if the avatar being simulated is mine, then loop through + // all the other avatars for potential interactions... + if ( _isMine ) + { + AgentList* agentList = AgentList::getInstance(); + for (AgentList::iterator agent = agentList->begin(); agent != agentList->end(); agent++) { + if (agent->getLinkedData() != NULL && agent->getType() == AGENT_TYPE_AVATAR) { + Avatar *otherAvatar = (Avatar *)agent->getLinkedData(); + + // check for collisions with other avatars and respond + updateCollisionWithOtherAvatar(otherAvatar, deltaTime ); + + // test other avatar hand position for proximity + glm::vec3 v( _joint[ AVATAR_JOINT_RIGHT_SHOULDER ].position ); + v -= otherAvatar->getJointPosition( AVATAR_JOINT_RIGHT_SHOULDER ); + + float distance = glm::length( v ); + if ( distance < _maxArmLength + _maxArmLength ) { + + _interactingOther = otherAvatar; + + if ( ! _avatarTouch.getAbleToReachOtherAvatar() ) { + //initialize _handHolding + _handHoldingPosition = _joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position; + _avatarTouch.setAbleToReachOtherAvatar(true); + } + + glm::vec3 vectorBetweenHands( _joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position ); + vectorBetweenHands -= otherAvatar->getJointPosition( AVATAR_JOINT_RIGHT_FINGERTIPS ); + float distanceBetweenHands = glm::length(vectorBetweenHands); + + if (distanceBetweenHands < _avatarTouch.HANDS_CLOSE_ENOUGH_TO_GRASP) { + _avatarTouch.setHandsCloseEnoughToGrasp(true); + } + + // if I am holding hands with another avatar, a force is applied + if (( _handState == 1 ) || ( _interactingOther->_handState == 1 )) { + + // if the hands are close enough to grasp... + if (distanceBetweenHands < _avatarTouch.HANDS_CLOSE_ENOUGH_TO_GRASP) + { + // apply the forces... + glm::vec3 vectorToOtherHand = _interactingOther->_handPosition - _handHoldingPosition; + glm::vec3 vectorToMyHand = _joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position - _handHoldingPosition; + + _handHoldingPosition += vectorToOtherHand * YOUR_HAND_HOLDING_PULL; + _handHoldingPosition += vectorToMyHand * MY_HAND_HOLDING_PULL; + _joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position = _handHoldingPosition; + + // apply a force to the avatar body + if ( glm::length(vectorToOtherHand) > _maxArmLength * 0.9 ) { + _velocity += vectorToOtherHand; + } + } + } + } + } + } + + // Set the vector we send for hand position to other people to be our right hand + setHandPosition(_joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position); + + }//if ( _isMine ) + + //constrain right arm length and re-adjust elbow position as it bends + updateArmIKAndConstraints( deltaTime ); + + // set hand positions for _avatarTouch.setMyHandPosition AFTER calling updateArmIKAndConstraints + if ( _interactingOther ) { + if (_isMine) { + _avatarTouch.setMyHandPosition ( _joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position ); + _avatarTouch.setYourHandPosition( _interactingOther->_joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position ); + _avatarTouch.setMyHandState ( _handState ); + _avatarTouch.setYourHandState ( _interactingOther->_handState ); + _avatarTouch.simulate(deltaTime); + } + } + + if (!_avatarTouch.getAbleToReachOtherAvatar() ) { + _interactingOther = NULL; + } +} + + + void Avatar::updateHead(float deltaTime) { //apply the head lean values to the springy position... @@ -504,7 +491,7 @@ void Avatar::updateHead(float deltaTime) { glm::vec3 headLean = _orientation.getRight() * _head.leanSideways + _orientation.getFront() * _head.leanForward; - _bone[ AVATAR_BONE_HEAD ].springyPosition += headLean; + _joint[ AVATAR_JOINT_HEAD_BASE ].springyPosition += headLean; } // Decay head back to center if turned on @@ -618,10 +605,10 @@ void Avatar::updateCollisionWithSphere( glm::vec3 position, float radius, float float distanceToBigSphere = glm::length(vectorFromMyBodyToBigSphere); if ( distanceToBigSphere < myBodyApproximateBoundingRadius + radius ) { - for (int b = 0; b < NUM_AVATAR_BONES; b++) { - glm::vec3 vectorFromJointToBigSphereCenter(_bone[b].springyPosition - position); + for (int b = 0; b < NUM_AVATAR_JOINTS; b++) { + glm::vec3 vectorFromJointToBigSphereCenter(_joint[b].springyPosition - position); float distanceToBigSphereCenter = glm::length(vectorFromJointToBigSphereCenter); - float combinedRadius = _bone[b].radius + radius; + float combinedRadius = _joint[b].radius + radius; if ( distanceToBigSphereCenter < combinedRadius ) { jointCollision = true; @@ -631,9 +618,9 @@ void Avatar::updateCollisionWithSphere( glm::vec3 position, float radius, float float penetration = 1.0 - (distanceToBigSphereCenter / combinedRadius); glm::vec3 collisionForce = vectorFromJointToBigSphereCenter * penetration; - _bone[b].springyVelocity += collisionForce * 30.0f * deltaTime; + _joint[b].springyVelocity += collisionForce * 30.0f * deltaTime; _velocity += collisionForce * 100.0f * deltaTime; - _bone[b].springyPosition = position + directionVector * combinedRadius; + _joint[b].springyPosition = position + directionVector * combinedRadius; } } } @@ -658,18 +645,18 @@ void Avatar::updateCollisionWithOtherAvatar( Avatar * otherAvatar, float deltaTi float bodyMomentum = 1.0f; glm::vec3 bodyPushForce = glm::vec3( 0.0, 0.0, 0.0 ); - // loop through the bones of each avatar to check for every possible collision - for (int b=1; b_bone[o].isCollidable ) { + for (int o=b+1; o_joint[o].isCollidable ) { - glm::vec3 vectorBetweenJoints(_bone[b].springyPosition - otherAvatar->_bone[o].springyPosition); + glm::vec3 vectorBetweenJoints(_joint[b].springyPosition - otherAvatar->_joint[o].springyPosition); float distanceBetweenJoints = glm::length(vectorBetweenJoints); if ( distanceBetweenJoints > 0.0 ) { // to avoid divide by zero - float combinedRadius = _bone[b].radius + otherAvatar->_bone[o].radius; + float combinedRadius = _joint[b].radius + otherAvatar->_joint[o].radius; // check for collision if ( distanceBetweenJoints < combinedRadius * COLLISION_RADIUS_SCALAR) { @@ -681,11 +668,11 @@ void Avatar::updateCollisionWithOtherAvatar( Avatar * otherAvatar, float deltaTi float ballMomentum = 1.0 - COLLISION_BALL_FRICTION * deltaTime; if ( ballMomentum < 0.0 ) { ballMomentum = 0.0;} - _bone[b].springyVelocity += ballPushForce; - otherAvatar->_bone[o].springyVelocity -= ballPushForce; + _joint[b].springyVelocity += ballPushForce; + otherAvatar->_joint[o].springyVelocity -= ballPushForce; - _bone[b].springyVelocity *= ballMomentum; - otherAvatar->_bone[o].springyVelocity *= ballMomentum; + _joint[b].springyVelocity *= ballMomentum; + otherAvatar->_joint[o].springyVelocity *= ballMomentum; // accumulate forces and frictions to apply to the velocities of avatar bodies bodyPushForce += directionVector * COLLISION_BODY_FORCE * deltaTime; @@ -812,19 +799,19 @@ void Avatar::renderHead(bool lookingInMirror) { glEnable(GL_RESCALE_NORMAL); // show head orientation - //renderOrientationDirections( _bone[ AVATAR_BONE_HEAD ].springyPosition, _bone[ AVATAR_BONE_HEAD ].orientation, 0.2f ); + //renderOrientationDirections( _joint[ AVATAR_JOINT_HEAD_BASE ].springyPosition, _joint[ AVATAR_JOINT_HEAD_BASE ].orientation, 0.2f ); glPushMatrix(); if (_usingBodySprings) { - glTranslatef(_bone[ AVATAR_BONE_HEAD ].springyPosition.x, - _bone[ AVATAR_BONE_HEAD ].springyPosition.y, - _bone[ AVATAR_BONE_HEAD ].springyPosition.z); + glTranslatef(_joint[ AVATAR_JOINT_HEAD_BASE ].springyPosition.x, + _joint[ AVATAR_JOINT_HEAD_BASE ].springyPosition.y, + _joint[ AVATAR_JOINT_HEAD_BASE ].springyPosition.z); } else { - glTranslatef(_bone[ AVATAR_BONE_HEAD ].position.x, - _bone[ AVATAR_BONE_HEAD ].position.y, - _bone[ AVATAR_BONE_HEAD ].position.z); + glTranslatef(_joint[ AVATAR_JOINT_HEAD_BASE ].position.x, + _joint[ AVATAR_JOINT_HEAD_BASE ].position.y, + _joint[ AVATAR_JOINT_HEAD_BASE ].position.z); } glScalef( 0.03, 0.03, 0.03 ); @@ -975,149 +962,149 @@ AvatarMode Avatar::getMode() { void Avatar::initializeSkeleton() { - for (int b=0; b 0.0f ) { glm::vec3 springDirection = springVector / length; - float force = (length - _bone[b].length) * BODY_SPRING_FORCE * deltaTime; + float force = (length - _joint[b].length) * BODY_SPRING_FORCE * deltaTime; - _bone[b].springyVelocity -= springDirection * force; + _joint[b].springyVelocity -= springDirection * force; - if ( _bone[b].parent != AVATAR_BONE_NULL ) { - _bone[_bone[b].parent].springyVelocity += springDirection * force; + if ( _joint[b].parent != AVATAR_JOINT_NULL ) { + _joint[_joint[b].parent].springyVelocity += springDirection * force; } } - _bone[b].springyVelocity += (_bone[b].position - _bone[b].springyPosition) * _bone[b].springBodyTightness * deltaTime; + _joint[b].springyVelocity += (_joint[b].position - _joint[b].springyPosition) * _joint[b].springBodyTightness * deltaTime; float decay = 1.0 - BODY_SPRING_DECAY * deltaTime; if (decay > 0.0) { - _bone[b].springyVelocity *= decay; + _joint[b].springyVelocity *= decay; } else { - _bone[b].springyVelocity = glm::vec3( 0.0f, 0.0f, 0.0f ); + _joint[b].springyVelocity = glm::vec3( 0.0f, 0.0f, 0.0f ); } - _bone[b].springyPosition += _bone[b].springyVelocity; + _joint[b].springyPosition += _joint[b].springyVelocity; } } @@ -1222,34 +1209,19 @@ const glm::vec3& Avatar::getHeadPosition() const { //if (_usingBodySprings) { - // return _bone[ AVATAR_BONE_HEAD ].springyPosition; + // return _joint[ AVATAR_JOINT_HEAD_BASE ].springyPosition; //} - return _bone[ AVATAR_BONE_HEAD ].position; + return _joint[ AVATAR_JOINT_HEAD_BASE ].position; } -void Avatar::updateHandMovement( float deltaTime ) { - glm::vec3 transformedHandMovement; - - transformedHandMovement - = _orientation.getRight() * _movedHandOffset.x * 2.0f - + _orientation.getUp() * -_movedHandOffset.y * 1.0f - + _orientation.getFront() * -_movedHandOffset.y * 1.0f; - - _bone[ AVATAR_BONE_RIGHT_HAND ].position += transformedHandMovement; - - if (_isMine) { - _handState = _mousePressed; - } -} - void Avatar::updateArmIKAndConstraints( float deltaTime ) { // determine the arm vector - glm::vec3 armVector = _bone[ AVATAR_BONE_RIGHT_HAND ].position; - armVector -= _bone[ AVATAR_BONE_RIGHT_SHOULDER ].position; + glm::vec3 armVector = _joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position; + armVector -= _joint[ AVATAR_JOINT_RIGHT_SHOULDER ].position; // test to see if right hand is being dragged beyond maximum arm length float distance = glm::length( armVector ); @@ -1257,30 +1229,29 @@ void Avatar::updateArmIKAndConstraints( float deltaTime ) { // don't let right hand get dragged beyond maximum arm length... if ( distance > _maxArmLength ) { // reset right hand to be constrained to maximum arm length - _bone[ AVATAR_BONE_RIGHT_HAND ].position = _bone[ AVATAR_BONE_RIGHT_SHOULDER ].position; + _joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position = _joint[ AVATAR_JOINT_RIGHT_SHOULDER ].position; glm::vec3 armNormal = armVector / distance; armVector = armNormal * _maxArmLength; distance = _maxArmLength; - glm::vec3 constrainedPosition = _bone[ AVATAR_BONE_RIGHT_SHOULDER ].position; + glm::vec3 constrainedPosition = _joint[ AVATAR_JOINT_RIGHT_SHOULDER ].position; constrainedPosition += armVector; - _bone[ AVATAR_BONE_RIGHT_HAND ].position = constrainedPosition; + _joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position = constrainedPosition; } // set elbow position - glm::vec3 newElbowPosition = _bone[ AVATAR_BONE_RIGHT_SHOULDER ].position; + glm::vec3 newElbowPosition = _joint[ AVATAR_JOINT_RIGHT_SHOULDER ].position; newElbowPosition += armVector * ONE_HALF; - glm::vec3 perpendicular = glm::cross( _orientation.getFront(), armVector ); - + glm::vec3 perpendicular = glm::cross( _orientation.getFront(), armVector ); + newElbowPosition += perpendicular * ( 1.0f - ( _maxArmLength / distance ) ) * ONE_HALF; - _bone[ AVATAR_BONE_RIGHT_UPPER_ARM ].position = newElbowPosition; + _joint[ AVATAR_JOINT_RIGHT_ELBOW ].position = newElbowPosition; // set wrist position - glm::vec3 vv( _bone[ AVATAR_BONE_RIGHT_HAND ].position ); - vv -= _bone[ AVATAR_BONE_RIGHT_UPPER_ARM ].position; - glm::vec3 newWristPosition = _bone[ AVATAR_BONE_RIGHT_UPPER_ARM ].position; - newWristPosition += vv * 0.7f; - _bone[ AVATAR_BONE_RIGHT_FOREARM ].position = newWristPosition; + glm::vec3 vv( _joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position ); + vv -= _joint[ AVATAR_JOINT_RIGHT_ELBOW ].position; + glm::vec3 newWristPosition = _joint[ AVATAR_JOINT_RIGHT_ELBOW ].position + vv * 0.7f; + _joint[ AVATAR_JOINT_RIGHT_WRIST ].position = newWristPosition; } @@ -1288,41 +1259,41 @@ void Avatar::updateArmIKAndConstraints( float deltaTime ) { void Avatar::renderBody() { - // Render bone positions as spheres - for (int b = 0; b < NUM_AVATAR_BONES; b++) { + // Render joint positions as spheres + for (int b = 0; b < NUM_AVATAR_JOINTS; b++) { - if ( b != AVATAR_BONE_HEAD ) { // the head is rendered as a special case in "renderHead" + if ( b != AVATAR_JOINT_HEAD_BASE ) { // 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 ); + //renderOrientationDirections( _joint[b].springyPosition, _joint[b].orientation, _joint[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 ); + glTranslatef( _joint[b].springyPosition.x, _joint[b].springyPosition.y, _joint[b].springyPosition.z ); + glutSolidSphere( _joint[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 ); + glTranslatef( _joint[b].position.x, _joint[b].position.y, _joint[b].position.z ); + glutSolidSphere( _joint[b].radius, 20.0f, 20.0f ); glPopMatrix(); } } } - // Render lines connecting the bone positions + // Render lines connecting the joint positions if ( _usingBodySprings ) { glColor3f( 0.4f, 0.5f, 0.6f ); glLineWidth(3.0); - for (int b = 1; b < NUM_AVATAR_BONES; b++) { - if ( _bone[b].parent != AVATAR_BONE_NULL ) { + for (int b = 1; b < NUM_AVATAR_JOINTS; b++) { + if ( _joint[b].parent != AVATAR_JOINT_NULL ) { glBegin( GL_LINE_STRIP ); - glVertex3fv( &_bone[ _bone[ b ].parent ].springyPosition.x ); - glVertex3fv( &_bone[ b ].springyPosition.x ); + glVertex3fv( &_joint[ _joint[ b ].parent ].springyPosition.x ); + glVertex3fv( &_joint[ b ].springyPosition.x ); glEnd(); } } @@ -1331,30 +1302,15 @@ void Avatar::renderBody() { glColor3fv( skinColor ); glLineWidth(3.0); - for (int b = 1; b < NUM_AVATAR_BONES; b++) { - if ( _bone[b].parent != AVATAR_BONE_NULL ) { + for (int b = 1; b < NUM_AVATAR_JOINTS; b++) { + if ( _joint[b].parent != AVATAR_JOINT_NULL ) { glBegin( GL_LINE_STRIP ); - glVertex3fv( &_bone[ _bone[ b ].parent ].position.x ); - glVertex3fv( &_bone[ b ].position.x); + glVertex3fv( &_joint[ _joint[ b ].parent ].position.x ); + glVertex3fv( &_joint[ b ].position.x); glEnd(); } } } - - /* - // if the hand is grasping, show it... - if (( _usingBodySprings ) && ( _handState == 1 )) { - glPushMatrix(); - glTranslatef(_bone[ AVATAR_BONE_RIGHT_HAND ].springyPosition.x, - _bone[ AVATAR_BONE_RIGHT_HAND ].springyPosition.y, - _bone[ AVATAR_BONE_RIGHT_HAND ].springyPosition.z); - glColor4f( 1.0, 1.0, 0.8, 0.3 ); glutSolidSphere( 0.020f, 10.0f, 10.0f ); - glColor4f( 1.0, 1.0, 0.4, 0.2 ); glutSolidSphere( 0.025f, 10.0f, 10.0f ); - glColor4f( 1.0, 1.0, 0.2, 0.1 ); glutSolidSphere( 0.030f, 10.0f, 10.0f ); - - glPopMatrix(); - } - */ } void Avatar::SetNewHeadTarget(float pitch, float yaw) { diff --git a/interface/src/Avatar.h b/interface/src/Avatar.h index fec8b6e4d0..c14680df4f 100644 --- a/interface/src/Avatar.h +++ b/interface/src/Avatar.h @@ -42,36 +42,71 @@ enum AvatarMode NUM_AVATAR_MODES }; -enum AvatarBoneID + +enum AvatarJointID { - AVATAR_BONE_NULL = -1, - AVATAR_BONE_PELVIS_SPINE, // connects pelvis joint with torso joint (not supposed to be rotated) - AVATAR_BONE_MID_SPINE, // connects torso joint with chest joint - AVATAR_BONE_CHEST_SPINE, // connects chest joint with neckBase joint (not supposed to be rotated) - AVATAR_BONE_NECK, // connects neckBase joint with headBase joint - AVATAR_BONE_HEAD, // connects headBase joint with headTop joint - AVATAR_BONE_LEFT_CHEST, // connects chest joint with left clavicle joint (not supposed to be rotated) - AVATAR_BONE_LEFT_SHOULDER, // connects left clavicle joint with left shoulder joint - AVATAR_BONE_LEFT_UPPER_ARM, // connects left shoulder joint with left elbow joint - AVATAR_BONE_LEFT_FOREARM, // connects left elbow joint with left wrist joint - AVATAR_BONE_LEFT_HAND, // connects left wrist joint with left fingertips joint - AVATAR_BONE_RIGHT_CHEST, // connects chest joint with right clavicle joint (not supposed to be rotated) - AVATAR_BONE_RIGHT_SHOULDER, // connects right clavicle joint with right shoulder joint - AVATAR_BONE_RIGHT_UPPER_ARM, // connects right shoulder joint with right elbow joint - AVATAR_BONE_RIGHT_FOREARM, // connects right elbow joint with right wrist joint - AVATAR_BONE_RIGHT_HAND, // connects right wrist joint with right fingertips joint - AVATAR_BONE_LEFT_PELVIS, // connects pelvis joint with left hip joint (not supposed to be rotated) - AVATAR_BONE_LEFT_THIGH, // connects left hip joint with left knee joint - AVATAR_BONE_LEFT_SHIN, // connects left knee joint with left heel joint - AVATAR_BONE_LEFT_FOOT, // connects left heel joint with left toes joint - AVATAR_BONE_RIGHT_PELVIS, // connects pelvis joint with right hip joint (not supposed to be rotated) - AVATAR_BONE_RIGHT_THIGH, // connects right hip joint with right knee joint - AVATAR_BONE_RIGHT_SHIN, // connects right knee joint with right heel joint - AVATAR_BONE_RIGHT_FOOT, // connects right heel joint with right toes joint + AVATAR_JOINT_NULL = -1, + AVATAR_JOINT_PELVIS, + AVATAR_JOINT_TORSO, + AVATAR_JOINT_CHEST, + AVATAR_JOINT_NECK_BASE, + AVATAR_JOINT_HEAD_BASE, + AVATAR_JOINT_HEAD_TOP, + + AVATAR_JOINT_LEFT_COLLAR, + AVATAR_JOINT_LEFT_SHOULDER, + AVATAR_JOINT_LEFT_ELBOW, + AVATAR_JOINT_LEFT_WRIST, + AVATAR_JOINT_LEFT_FINGERTIPS, + + AVATAR_JOINT_RIGHT_COLLAR, + AVATAR_JOINT_RIGHT_SHOULDER, + AVATAR_JOINT_RIGHT_ELBOW, + AVATAR_JOINT_RIGHT_WRIST, + AVATAR_JOINT_RIGHT_FINGERTIPS, + + AVATAR_JOINT_LEFT_HIP, + AVATAR_JOINT_LEFT_KNEE, + AVATAR_JOINT_LEFT_HEEL, + AVATAR_JOINT_LEFT_TOES, + AVATAR_JOINT_RIGHT_HIP, + AVATAR_JOINT_RIGHT_KNEE, + AVATAR_JOINT_RIGHT_HEEL, + AVATAR_JOINT_RIGHT_TOES, + + /* + AVATAR_JOINT_NULL = -1, + AVATAR_JOINT_PELVIS, + AVATAR_JOINT_TORSO, + AVATAR_JOINT_CHEST, + AVATAR_JOINT_NECK_BASE, + AVATAR_JOINT_HEAD_BASE, + AVATAR_JOINT_HEAD_TOP, + AVATAR_JOINT_LEFT_COLLAR, + AVATAR_JOINT_LEFT_SHOULDER, + AVATAR_JOINT_LEFT_ELBOW, + AVATAR_JOINT_LEFT_WRIST, + AVATAR_JOINT_LEFT_FINGERTIPS, + AVATAR_JOINT_RIGHT_COLLAR, + AVATAR_JOINT_RIGHT_SHOULDER, + AVATAR_JOINT_RIGHT_ELBOW, + AVATAR_JOINT_RIGHT_WRIST, + AVATAR_JOINT_RIGHT_FINGERTIPS, + AVATAR_JOINT_LEFT_HIP, + AVATAR_JOINT_LEFT_KNEE, + AVATAR_JOINT_LEFT_HEEL, + AVATAR_JOINT_LEFT_TOES, + AVATAR_JOINT_RIGHT_HIP, + AVATAR_JOINT_RIGHT_KNEE, + AVATAR_JOINT_RIGHT_HEEL, + AVATAR_JOINT_RIGHT_TOES, + */ + + NUM_AVATAR_JOINTS - NUM_AVATAR_BONES }; + class Avatar : public AvatarData { public: Avatar(bool isMine); @@ -103,7 +138,7 @@ public: const glm::vec3& getHeadLookatDirectionUp() const { return _orientation.getUp(); }; const glm::vec3& getHeadLookatDirectionRight() const { return _orientation.getRight(); }; const glm::vec3& getHeadPosition() const ; - const glm::vec3& getBonePosition(AvatarBoneID b) const { return _bone[b].position; }; + const glm::vec3& getJointPosition(AvatarJointID j) const { return _joint[j].position; }; const glm::vec3& getBodyUpDirection() const { return _orientation.getUp(); }; float getSpeed() const { return _speed; }; float getGirth(); @@ -117,7 +152,6 @@ public: void renderHead(bool lookingInMirror); void simulate(float); void setHandMovementValues( glm::vec3 movement ); - void updateHandMovement( float deltaTime ); void updateArmIKAndConstraints( float deltaTime ); void setDisplayingHead( bool displayingHead ); @@ -168,22 +202,22 @@ private: void setHeadReturnToCenter(bool r) { _returnHeadToCenter = r; }; const bool getHeadReturnToCenter() const { return _returnHeadToCenter; }; - struct AvatarBone + struct AvatarJoint { - AvatarBoneID parent; // which bone is this bone connected to? - glm::vec3 position; // the position at the "end" of the bone - in global space + AvatarJointID parent; // which joint is this joint connected to? + glm::vec3 position; // the position at the "end" of the joint - in global space glm::vec3 defaultPosePosition; // the parent relative position when the avatar is in the "T-pose" glm::vec3 springyPosition; // used for special effects (a 'flexible' variant of position) glm::vec3 springyVelocity; // used for special effects ( the velocity of the springy position) float springBodyTightness; // how tightly the springy position tries to stay on the position glm::quat rotation; // this will eventually replace yaw, pitch and roll (and maybe orientation) - float yaw; // the yaw Euler angle of the bone rotation off the parent - float pitch; // the pitch Euler angle of the bone rotation off the parent - float roll; // the roll Euler angle of the bone rotation off the parent + float yaw; // the yaw Euler angle of the joint rotation off the parent + float pitch; // the pitch Euler angle of the joint rotation off the parent + float roll; // the roll Euler angle of the joint rotation off the parent Orientation orientation; // three orthogonal normals determined by yaw, pitch, roll - float length; // the length of the bone + float length; // the length of the joint float radius; // used for detecting collisions for certain physical effects - bool isCollidable; // when false, the bone position will not register a collision + bool isCollidable; // when false, the joint position will not register a collision }; struct AvatarHead @@ -238,7 +272,7 @@ private: bool _usingBodySprings; glm::vec3 _movedHandOffset; glm::quat _rotation; // the rotation of the avatar body as a whole expressed as a quaternion - AvatarBone _bone[ NUM_AVATAR_BONES ]; + AvatarJoint _joint[ NUM_AVATAR_JOINTS ]; AvatarMode _mode; glm::vec3 _handHoldingPosition; glm::vec3 _velocity; @@ -272,6 +306,7 @@ private: void calculateBoneLengths(); void readSensors(); void updateHead( float deltaTime ); + void updateHandMovementAndTouching(float deltaTime); void updateCollisionWithSphere( glm::vec3 position, float radius, float deltaTime ); void updateCollisionWithOtherAvatar( Avatar * other, float deltaTime ); void setHeadFromGyros(glm::vec3 * eulerAngles, glm::vec3 * angularVelocity, float deltaTime, float smoothingTime); From 673936e14179a7a08229e7b9de17e2b9ff9c1562 Mon Sep 17 00:00:00 2001 From: Jeffrey Ventrella Date: Thu, 2 May 2013 14:05:51 -0700 Subject: [PATCH 2/5] adjusted proportions of avatar skeleton to make it closer to average human --- eve/src/main.cpp | 4 +- interface/src/Avatar.cpp | 100 ++++++++++++++++++++++++--------------- interface/src/main.cpp | 2 +- 3 files changed, 64 insertions(+), 42 deletions(-) diff --git a/eve/src/main.cpp b/eve/src/main.cpp index 9ebffec7e9..30de50c284 100644 --- a/eve/src/main.cpp +++ b/eve/src/main.cpp @@ -114,7 +114,7 @@ int main(int argc, const char* argv[]) { // pick a random point inside a 10x10 grid eve.setPosition(glm::vec3(randFloatInRange(-RANDOM_POSITION_MAX_DIMENSION, RANDOM_POSITION_MAX_DIMENSION), - 0.32, // this is the same as the pelvis standing height (as of 4/26/13) + 1.33, // this should be the same as the avatar's pelvis standing height randFloatInRange(-RANDOM_POSITION_MAX_DIMENSION, RANDOM_POSITION_MAX_DIMENSION))); // face any instance of eve down the z-axis @@ -122,7 +122,7 @@ int main(int argc, const char* argv[]) { // put her hand out so somebody can shake it eve.setHandPosition(glm::vec3(eve.getPosition()[0] - 0.2, - 0.25, + 0.5, eve.getPosition()[2] + 0.1)); // read eve's audio data AudioInjector eveAudioInjector("/etc/highfidelity/eve/resources/eve.raw"); diff --git a/interface/src/Avatar.cpp b/interface/src/Avatar.cpp index 5ffae0115e..8cca1a7a9a 100644 --- a/interface/src/Avatar.cpp +++ b/interface/src/Avatar.cpp @@ -69,7 +69,7 @@ Avatar::Avatar(bool isMine) { _speed = 0.0; _pelvisStandingHeight = 0.0f; _displayingHead = true; - _TEST_bigSphereRadius = 0.3f; + _TEST_bigSphereRadius = 0.4f; _TEST_bigSpherePosition = glm::vec3( 0.0f, _TEST_bigSphereRadius, 2.0f ); for (int i = 0; i < MAX_DRIVE_KEYS; i++) _driveKeys[i] = false; @@ -814,7 +814,13 @@ void Avatar::renderHead(bool lookingInMirror) { _joint[ AVATAR_JOINT_HEAD_BASE ].position.z); } - glScalef( 0.03, 0.03, 0.03 ); + glScalef + ( + _joint[ AVATAR_JOINT_HEAD_BASE ].radius, + _joint[ AVATAR_JOINT_HEAD_BASE ].radius, + _joint[ AVATAR_JOINT_HEAD_BASE ].radius + ); + if (lookingInMirror) { glRotatef(_bodyYaw - _headYaw, 0, 1, 0); @@ -826,7 +832,7 @@ void Avatar::renderHead(bool lookingInMirror) { glRotatef(_bodyRoll + _headRoll, 0, 0, 1); } - glScalef(2.0, 2.0, 2.0); + //glScalef(2.0, 2.0, 2.0); glColor3fv(skinColor); glutSolidSphere(1, 30, 30); @@ -1006,50 +1012,58 @@ void Avatar::initializeSkeleton() { // specify the default pose position _joint[ AVATAR_JOINT_PELVIS ].defaultPosePosition = glm::vec3( 0.0, 0.0, 0.0 ); - _joint[ AVATAR_JOINT_TORSO ].defaultPosePosition = glm::vec3( 0.0, 0.05, 0.0 ); - _joint[ AVATAR_JOINT_CHEST ].defaultPosePosition = glm::vec3( 0.0, 0.06, 0.0 ); - _joint[ AVATAR_JOINT_NECK_BASE ].defaultPosePosition = glm::vec3( 0.0, 0.06, 0.0 ); - _joint[ AVATAR_JOINT_HEAD_BASE ].defaultPosePosition = glm::vec3( 0.0, 0.1, 0.0 ); - _joint[ AVATAR_JOINT_LEFT_COLLAR ].defaultPosePosition = glm::vec3( -0.05, 0.02, 0.0 ); - _joint[ AVATAR_JOINT_LEFT_SHOULDER ].defaultPosePosition = glm::vec3( -0.03, 0.0, 0.0 ); - _joint[ AVATAR_JOINT_LEFT_ELBOW ].defaultPosePosition = glm::vec3( 0.0, -0.1, 0.0 ); - _joint[ AVATAR_JOINT_LEFT_WRIST ].defaultPosePosition = glm::vec3( 0.0, -0.1, 0.0 ); - _joint[ AVATAR_JOINT_LEFT_FINGERTIPS ].defaultPosePosition = glm::vec3( 0.0, -0.05, 0.0 ); - _joint[ AVATAR_JOINT_RIGHT_COLLAR ].defaultPosePosition = glm::vec3( 0.05, 0.02, 0.0 ); - _joint[ AVATAR_JOINT_RIGHT_SHOULDER ].defaultPosePosition = glm::vec3( 0.03, 0.0, 0.0 ); - _joint[ AVATAR_JOINT_RIGHT_ELBOW ].defaultPosePosition = glm::vec3( 0.0, -0.1, 0.0 ); - _joint[ AVATAR_JOINT_RIGHT_WRIST ].defaultPosePosition = glm::vec3( 0.0, -0.1, 0.0 ); - _joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].defaultPosePosition = glm::vec3( 0.0, -0.05, 0.0 ); - _joint[ AVATAR_JOINT_LEFT_HIP ].defaultPosePosition = glm::vec3( -0.03, 0.0, 0.0 ); - _joint[ AVATAR_JOINT_LEFT_KNEE ].defaultPosePosition = glm::vec3( 0.0, -0.15, 0.0 ); - _joint[ AVATAR_JOINT_LEFT_HEEL ].defaultPosePosition = glm::vec3( 0.0, -0.15, 0.0 ); + _joint[ AVATAR_JOINT_TORSO ].defaultPosePosition = glm::vec3( 0.0, 0.08, 0.0 ); + _joint[ AVATAR_JOINT_CHEST ].defaultPosePosition = glm::vec3( 0.0, 0.09, 0.0 ); + _joint[ AVATAR_JOINT_NECK_BASE ].defaultPosePosition = glm::vec3( 0.0, 0.1, 0.0 ); + _joint[ AVATAR_JOINT_HEAD_BASE ].defaultPosePosition = glm::vec3( 0.0, 0.08, 0.0 ); + + _joint[ AVATAR_JOINT_LEFT_COLLAR ].defaultPosePosition = glm::vec3( -0.06, 0.04, 0.0 ); + _joint[ AVATAR_JOINT_LEFT_SHOULDER ].defaultPosePosition = glm::vec3( -0.04, 0.0, 0.0 ); + _joint[ AVATAR_JOINT_LEFT_ELBOW ].defaultPosePosition = glm::vec3( 0.0, -0.13, 0.0 ); + _joint[ AVATAR_JOINT_LEFT_WRIST ].defaultPosePosition = glm::vec3( 0.0, -0.11, 0.0 ); + _joint[ AVATAR_JOINT_LEFT_FINGERTIPS ].defaultPosePosition = glm::vec3( 0.0, -0.07, 0.0 ); + + _joint[ AVATAR_JOINT_RIGHT_COLLAR ].defaultPosePosition = glm::vec3( 0.06, 0.04, 0.0 ); + _joint[ AVATAR_JOINT_RIGHT_SHOULDER ].defaultPosePosition = glm::vec3( 0.04, 0.0, 0.0 ); + _joint[ AVATAR_JOINT_RIGHT_ELBOW ].defaultPosePosition = glm::vec3( 0.0, -0.13, 0.0 ); + _joint[ AVATAR_JOINT_RIGHT_WRIST ].defaultPosePosition = glm::vec3( 0.0, -0.11, 0.0 ); + _joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].defaultPosePosition = glm::vec3( 0.0, -0.07, 0.0 ); + + _joint[ AVATAR_JOINT_LEFT_HIP ].defaultPosePosition = glm::vec3( -0.05, 0.0, 0.0 ); + _joint[ AVATAR_JOINT_LEFT_KNEE ].defaultPosePosition = glm::vec3( 0.0, -0.22, 0.0 ); + _joint[ AVATAR_JOINT_LEFT_HEEL ].defaultPosePosition = glm::vec3( 0.0, -0.22, 0.0 ); _joint[ AVATAR_JOINT_LEFT_TOES ].defaultPosePosition = glm::vec3( 0.0, 0.0, 0.04 ); - _joint[ AVATAR_JOINT_RIGHT_HIP ].defaultPosePosition = glm::vec3( 0.03, 0.0, 0.0 ); - _joint[ AVATAR_JOINT_RIGHT_KNEE ].defaultPosePosition = glm::vec3( 0.0, -0.15, 0.0 ); - _joint[ AVATAR_JOINT_RIGHT_HEEL ].defaultPosePosition = glm::vec3( 0.0, -0.15, 0.0 ); + + _joint[ AVATAR_JOINT_RIGHT_HIP ].defaultPosePosition = glm::vec3( 0.05, 0.0, 0.0 ); + _joint[ AVATAR_JOINT_RIGHT_KNEE ].defaultPosePosition = glm::vec3( 0.0, -0.22, 0.0 ); + _joint[ AVATAR_JOINT_RIGHT_HEEL ].defaultPosePosition = glm::vec3( 0.0, -0.22, 0.0 ); _joint[ AVATAR_JOINT_RIGHT_TOES ].defaultPosePosition = glm::vec3( 0.0, 0.0, 0.04 ); // specify the radii of the bone positions - _joint[ AVATAR_JOINT_PELVIS ].radius = 0.05; - _joint[ AVATAR_JOINT_TORSO ].radius = 0.04; - _joint[ AVATAR_JOINT_CHEST ].radius = 0.06; - _joint[ AVATAR_JOINT_NECK_BASE ].radius = 0.02; - _joint[ AVATAR_JOINT_HEAD_BASE ].radius = 0.02; - _joint[ AVATAR_JOINT_LEFT_COLLAR ].radius = 0.025; - _joint[ AVATAR_JOINT_LEFT_SHOULDER ].radius = 0.02; - _joint[ AVATAR_JOINT_LEFT_ELBOW ].radius = 0.015; - _joint[ AVATAR_JOINT_LEFT_WRIST ].radius = 0.015; + _joint[ AVATAR_JOINT_PELVIS ].radius = 0.06; + _joint[ AVATAR_JOINT_TORSO ].radius = 0.055; + _joint[ AVATAR_JOINT_CHEST ].radius = 0.075; + _joint[ AVATAR_JOINT_NECK_BASE ].radius = 0.03; + _joint[ AVATAR_JOINT_HEAD_BASE ].radius = 0.07; + + _joint[ AVATAR_JOINT_LEFT_COLLAR ].radius = 0.027; + _joint[ AVATAR_JOINT_LEFT_SHOULDER ].radius = 0.023; + _joint[ AVATAR_JOINT_LEFT_ELBOW ].radius = 0.017; + _joint[ AVATAR_JOINT_LEFT_WRIST ].radius = 0.017; _joint[ AVATAR_JOINT_LEFT_FINGERTIPS ].radius = 0.01; - _joint[ AVATAR_JOINT_RIGHT_COLLAR ].radius = 0.025; - _joint[ AVATAR_JOINT_RIGHT_SHOULDER ].radius = 0.02; + + _joint[ AVATAR_JOINT_RIGHT_COLLAR ].radius = 0.027; + _joint[ AVATAR_JOINT_RIGHT_SHOULDER ].radius = 0.023; _joint[ AVATAR_JOINT_RIGHT_ELBOW ].radius = 0.015; _joint[ AVATAR_JOINT_RIGHT_WRIST ].radius = 0.015; _joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].radius = 0.01; - _joint[ AVATAR_JOINT_LEFT_HIP ].radius = 0.02; + + _joint[ AVATAR_JOINT_LEFT_HIP ].radius = 0.03; _joint[ AVATAR_JOINT_LEFT_KNEE ].radius = 0.02; _joint[ AVATAR_JOINT_LEFT_HEEL ].radius = 0.015; _joint[ AVATAR_JOINT_LEFT_TOES ].radius = 0.02; - _joint[ AVATAR_JOINT_RIGHT_HIP ].radius = 0.02; + + _joint[ AVATAR_JOINT_RIGHT_HIP ].radius = 0.03; _joint[ AVATAR_JOINT_RIGHT_KNEE ].radius = 0.02; _joint[ AVATAR_JOINT_RIGHT_HEEL ].radius = 0.015; _joint[ AVATAR_JOINT_RIGHT_TOES ].radius = 0.02; @@ -1091,14 +1105,16 @@ void Avatar::initializeSkeleton() { calculateBoneLengths(); _pelvisStandingHeight = - _joint[ AVATAR_JOINT_LEFT_TOES ].radius + + _joint[ AVATAR_JOINT_LEFT_HEEL ].radius + _joint[ AVATAR_JOINT_LEFT_HEEL ].length + - _joint[ AVATAR_JOINT_LEFT_KNEE ].length + - _joint[ AVATAR_JOINT_PELVIS ].length; + _joint[ AVATAR_JOINT_LEFT_KNEE ].length; _height = ( _pelvisStandingHeight + + _joint[ AVATAR_JOINT_LEFT_HEEL ].radius + + _joint[ AVATAR_JOINT_LEFT_HEEL ].length + + _joint[ AVATAR_JOINT_LEFT_KNEE ].length + _joint[ AVATAR_JOINT_PELVIS ].length + _joint[ AVATAR_JOINT_TORSO ].length + _joint[ AVATAR_JOINT_CHEST ].length + @@ -1107,6 +1123,12 @@ void Avatar::initializeSkeleton() { _joint[ AVATAR_JOINT_HEAD_BASE ].radius ); + printf( "_height = %f\n", _height ); + + + + + // generate world positions updateSkeleton(); } diff --git a/interface/src/main.cpp b/interface/src/main.cpp index 08b1666d05..e3788ec236 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -728,7 +728,7 @@ void display(void) float thirdPersonPitch = 0.0f; float thirdPersonUpShift = -0.1f; - float thirdPersonDistance = 1.f; + float thirdPersonDistance = 1.2f; float thirdPersonTightness = 8.0f; if ( USING_FIRST_PERSON_EFFECT ) { From c46fc5a861f0df65db652db387a70a44c35afab1 Mon Sep 17 00:00:00 2001 From: Jeffrey Ventrella Date: Thu, 2 May 2013 17:46:10 -0700 Subject: [PATCH 3/5] (1) added avatar tilting while walking; (2) added avatar renderer; (3) tweaked body proportions; (4) --- interface/src/Avatar.cpp | 141 +++++++++++++++++++++------------------ interface/src/Avatar.h | 77 +++++++-------------- interface/src/main.cpp | 6 ++ 3 files changed, 106 insertions(+), 118 deletions(-) diff --git a/interface/src/Avatar.cpp b/interface/src/Avatar.cpp index 8cca1a7a9a..4655c0e9ec 100644 --- a/interface/src/Avatar.cpp +++ b/interface/src/Avatar.cpp @@ -135,31 +135,31 @@ Avatar::Avatar(bool isMine) { Avatar::Avatar(const Avatar &otherAvatar) { - _velocity = otherAvatar._velocity; - _thrust = otherAvatar._thrust; - _rotation = otherAvatar._rotation; - _bodyYaw = otherAvatar._bodyYaw; - _bodyPitch = otherAvatar._bodyPitch; - _bodyRoll = otherAvatar._bodyRoll; - _bodyPitchDelta = otherAvatar._bodyPitchDelta; - _bodyYawDelta = otherAvatar._bodyYawDelta; - _bodyRollDelta = otherAvatar._bodyRollDelta; - _mousePressed = otherAvatar._mousePressed; - _mode = otherAvatar._mode; - _isMine = otherAvatar._isMine; - _renderYaw = otherAvatar._renderYaw; - _renderPitch = otherAvatar._renderPitch; - _maxArmLength = otherAvatar._maxArmLength; - _transmitterTimer = otherAvatar._transmitterTimer; - _transmitterIsFirstData = otherAvatar._transmitterIsFirstData; - _transmitterTimeLastReceived = otherAvatar._transmitterTimeLastReceived; - _transmitterHz = otherAvatar._transmitterHz; - _transmitterInitialReading = otherAvatar._transmitterInitialReading; - _transmitterPackets = otherAvatar._transmitterPackets; - _TEST_bigSphereRadius = otherAvatar._TEST_bigSphereRadius; - _TEST_bigSpherePosition = otherAvatar._TEST_bigSpherePosition; - _movedHandOffset = otherAvatar._movedHandOffset; - _usingBodySprings = otherAvatar._usingBodySprings; + _velocity = otherAvatar._velocity; + _thrust = otherAvatar._thrust; + _rotation = otherAvatar._rotation; + _bodyYaw = otherAvatar._bodyYaw; + _bodyPitch = otherAvatar._bodyPitch; + _bodyRoll = otherAvatar._bodyRoll; + _bodyPitchDelta = otherAvatar._bodyPitchDelta; + _bodyYawDelta = otherAvatar._bodyYawDelta; + _bodyRollDelta = otherAvatar._bodyRollDelta; + _mousePressed = otherAvatar._mousePressed; + _mode = otherAvatar._mode; + _isMine = otherAvatar._isMine; + _renderYaw = otherAvatar._renderYaw; + _renderPitch = otherAvatar._renderPitch; + _maxArmLength = otherAvatar._maxArmLength; + _transmitterTimer = otherAvatar._transmitterTimer; + _transmitterIsFirstData = otherAvatar._transmitterIsFirstData; + _transmitterTimeLastReceived = otherAvatar._transmitterTimeLastReceived; + _transmitterHz = otherAvatar._transmitterHz; + _transmitterInitialReading = otherAvatar._transmitterInitialReading; + _transmitterPackets = otherAvatar._transmitterPackets; + _TEST_bigSphereRadius = otherAvatar._TEST_bigSphereRadius; + _TEST_bigSpherePosition = otherAvatar._TEST_bigSpherePosition; + _movedHandOffset = otherAvatar._movedHandOffset; + _usingBodySprings = otherAvatar._usingBodySprings; _orientation.set( otherAvatar._orientation ); @@ -347,16 +347,34 @@ void Avatar::simulate(float deltaTime) { // update body yaw by body yaw delta if (_isMine) { - _bodyYaw += _bodyYawDelta * deltaTime; + _bodyPitch += _bodyPitchDelta * deltaTime; + _bodyYaw += _bodyYawDelta * deltaTime; + _bodyRoll += _bodyRollDelta * deltaTime; } - // decay body rotation deltas - _bodyPitchDelta *= (1.0 - BODY_PITCH_DECAY * deltaTime); - _bodyYawDelta *= (1.0 - BODY_YAW_DECAY * deltaTime); - _bodyRollDelta *= (1.0 - BODY_ROLL_DECAY * deltaTime); - + // decay body rotation momentum + float bodySpinMomentum = 1.0 - BODY_SPIN_FRICTION * deltaTime; + if ( bodySpinMomentum < 0.0f ) { bodySpinMomentum = 0.0f; } + _bodyPitchDelta *= bodySpinMomentum; + _bodyYawDelta *= bodySpinMomentum; + _bodyRollDelta *= bodySpinMomentum; + // add thrust to velocity _velocity += _thrust * deltaTime; + + // calculate speed + _speed = glm::length( _velocity ); + + //pitch and roll the body as a function of forward speed and turning delta + float forwardComponentOfVelocity = glm::dot( _orientation.getFront(), _velocity ); + _bodyPitch += BODY_PITCH_WHILE_WALKING * deltaTime * forwardComponentOfVelocity; + _bodyRoll += BODY_ROLL_WHILE_TURNING * deltaTime * _speed * _bodyYawDelta; + + // these forces keep the body upright... + float tiltDecay = 1.0 - BODY_UPRIGHT_FORCE * deltaTime; + if ( tiltDecay < 0.0f ) { tiltDecay = 0.0f; } + _bodyPitch *= tiltDecay; + _bodyRoll *= tiltDecay; // update position by velocity _position += _velocity * deltaTime; @@ -367,11 +385,8 @@ void Avatar::simulate(float deltaTime) { // update head information updateHead(deltaTime); - // calculate speed, and use that to determine walking vs. standing - _speed = glm::length( _velocity ); - float rotationalSpeed = fabs( _bodyYawDelta ); - - if ( _speed + rotationalSpeed > 0.2 ) { + // use speed and angular velocity to determine walking vs. standing + if ( _speed + fabs( _bodyYawDelta ) > 0.2 ) { _mode = AVATAR_MODE_WALKING; } else { _mode = AVATAR_MODE_INTERACTING; @@ -708,6 +723,7 @@ static TextRenderer* textRenderer() { } void Avatar::render(bool lookingInMirror) { + /* // show avatar position @@ -991,6 +1007,7 @@ void Avatar::initializeSkeleton() { _joint[ AVATAR_JOINT_CHEST ].parent = AVATAR_JOINT_TORSO; _joint[ AVATAR_JOINT_NECK_BASE ].parent = AVATAR_JOINT_CHEST; _joint[ AVATAR_JOINT_HEAD_BASE ].parent = AVATAR_JOINT_NECK_BASE; + _joint[ AVATAR_JOINT_HEAD_TOP ].parent = AVATAR_JOINT_HEAD_BASE; _joint[ AVATAR_JOINT_LEFT_COLLAR ].parent = AVATAR_JOINT_CHEST; _joint[ AVATAR_JOINT_LEFT_SHOULDER ].parent = AVATAR_JOINT_LEFT_COLLAR; _joint[ AVATAR_JOINT_LEFT_ELBOW ].parent = AVATAR_JOINT_LEFT_SHOULDER; @@ -1012,32 +1029,28 @@ void Avatar::initializeSkeleton() { // specify the default pose position _joint[ AVATAR_JOINT_PELVIS ].defaultPosePosition = glm::vec3( 0.0, 0.0, 0.0 ); - _joint[ AVATAR_JOINT_TORSO ].defaultPosePosition = glm::vec3( 0.0, 0.08, 0.0 ); + _joint[ AVATAR_JOINT_TORSO ].defaultPosePosition = glm::vec3( 0.0, 0.08, 0.01 ); _joint[ AVATAR_JOINT_CHEST ].defaultPosePosition = glm::vec3( 0.0, 0.09, 0.0 ); - _joint[ AVATAR_JOINT_NECK_BASE ].defaultPosePosition = glm::vec3( 0.0, 0.1, 0.0 ); - _joint[ AVATAR_JOINT_HEAD_BASE ].defaultPosePosition = glm::vec3( 0.0, 0.08, 0.0 ); - - _joint[ AVATAR_JOINT_LEFT_COLLAR ].defaultPosePosition = glm::vec3( -0.06, 0.04, 0.0 ); - _joint[ AVATAR_JOINT_LEFT_SHOULDER ].defaultPosePosition = glm::vec3( -0.04, 0.0, 0.0 ); + _joint[ AVATAR_JOINT_NECK_BASE ].defaultPosePosition = glm::vec3( 0.0, 0.1, -0.01 ); + _joint[ AVATAR_JOINT_HEAD_BASE ].defaultPosePosition = glm::vec3( 0.0, 0.08, 0.01 ); + _joint[ AVATAR_JOINT_LEFT_COLLAR ].defaultPosePosition = glm::vec3( -0.06, 0.04, -0.01 ); + _joint[ AVATAR_JOINT_LEFT_SHOULDER ].defaultPosePosition = glm::vec3( -0.03, 0.0, -0.01 ); _joint[ AVATAR_JOINT_LEFT_ELBOW ].defaultPosePosition = glm::vec3( 0.0, -0.13, 0.0 ); _joint[ AVATAR_JOINT_LEFT_WRIST ].defaultPosePosition = glm::vec3( 0.0, -0.11, 0.0 ); _joint[ AVATAR_JOINT_LEFT_FINGERTIPS ].defaultPosePosition = glm::vec3( 0.0, -0.07, 0.0 ); - - _joint[ AVATAR_JOINT_RIGHT_COLLAR ].defaultPosePosition = glm::vec3( 0.06, 0.04, 0.0 ); - _joint[ AVATAR_JOINT_RIGHT_SHOULDER ].defaultPosePosition = glm::vec3( 0.04, 0.0, 0.0 ); + _joint[ AVATAR_JOINT_RIGHT_COLLAR ].defaultPosePosition = glm::vec3( 0.06, 0.04, -0.01 ); + _joint[ AVATAR_JOINT_RIGHT_SHOULDER ].defaultPosePosition = glm::vec3( 0.03, 0.0, -0.01 ); _joint[ AVATAR_JOINT_RIGHT_ELBOW ].defaultPosePosition = glm::vec3( 0.0, -0.13, 0.0 ); _joint[ AVATAR_JOINT_RIGHT_WRIST ].defaultPosePosition = glm::vec3( 0.0, -0.11, 0.0 ); _joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].defaultPosePosition = glm::vec3( 0.0, -0.07, 0.0 ); - - _joint[ AVATAR_JOINT_LEFT_HIP ].defaultPosePosition = glm::vec3( -0.05, 0.0, 0.0 ); - _joint[ AVATAR_JOINT_LEFT_KNEE ].defaultPosePosition = glm::vec3( 0.0, -0.22, 0.0 ); - _joint[ AVATAR_JOINT_LEFT_HEEL ].defaultPosePosition = glm::vec3( 0.0, -0.22, 0.0 ); - _joint[ AVATAR_JOINT_LEFT_TOES ].defaultPosePosition = glm::vec3( 0.0, 0.0, 0.04 ); - - _joint[ AVATAR_JOINT_RIGHT_HIP ].defaultPosePosition = glm::vec3( 0.05, 0.0, 0.0 ); - _joint[ AVATAR_JOINT_RIGHT_KNEE ].defaultPosePosition = glm::vec3( 0.0, -0.22, 0.0 ); - _joint[ AVATAR_JOINT_RIGHT_HEEL ].defaultPosePosition = glm::vec3( 0.0, -0.22, 0.0 ); - _joint[ AVATAR_JOINT_RIGHT_TOES ].defaultPosePosition = glm::vec3( 0.0, 0.0, 0.04 ); + _joint[ AVATAR_JOINT_LEFT_HIP ].defaultPosePosition = glm::vec3( -0.04, 0.0, -0.02 ); + _joint[ AVATAR_JOINT_LEFT_KNEE ].defaultPosePosition = glm::vec3( 0.0, -0.22, 0.02 ); + _joint[ AVATAR_JOINT_LEFT_HEEL ].defaultPosePosition = glm::vec3( 0.0, -0.22, -0.01 ); + _joint[ AVATAR_JOINT_LEFT_TOES ].defaultPosePosition = glm::vec3( 0.0, 0.0, 0.05 ); + _joint[ AVATAR_JOINT_RIGHT_HIP ].defaultPosePosition = glm::vec3( 0.04, 0.0, -0.02 ); + _joint[ AVATAR_JOINT_RIGHT_KNEE ].defaultPosePosition = glm::vec3( 0.0, -0.22, 0.02 ); + _joint[ AVATAR_JOINT_RIGHT_HEEL ].defaultPosePosition = glm::vec3( 0.0, -0.22, -0.01 ); + _joint[ AVATAR_JOINT_RIGHT_TOES ].defaultPosePosition = glm::vec3( 0.0, 0.0, 0.05 ); // specify the radii of the bone positions _joint[ AVATAR_JOINT_PELVIS ].radius = 0.06; @@ -1046,13 +1059,13 @@ void Avatar::initializeSkeleton() { _joint[ AVATAR_JOINT_NECK_BASE ].radius = 0.03; _joint[ AVATAR_JOINT_HEAD_BASE ].radius = 0.07; - _joint[ AVATAR_JOINT_LEFT_COLLAR ].radius = 0.027; + _joint[ AVATAR_JOINT_LEFT_COLLAR ].radius = 0.029; _joint[ AVATAR_JOINT_LEFT_SHOULDER ].radius = 0.023; _joint[ AVATAR_JOINT_LEFT_ELBOW ].radius = 0.017; _joint[ AVATAR_JOINT_LEFT_WRIST ].radius = 0.017; _joint[ AVATAR_JOINT_LEFT_FINGERTIPS ].radius = 0.01; - _joint[ AVATAR_JOINT_RIGHT_COLLAR ].radius = 0.027; + _joint[ AVATAR_JOINT_RIGHT_COLLAR ].radius = 0.029; _joint[ AVATAR_JOINT_RIGHT_SHOULDER ].radius = 0.023; _joint[ AVATAR_JOINT_RIGHT_ELBOW ].radius = 0.015; _joint[ AVATAR_JOINT_RIGHT_WRIST ].radius = 0.015; @@ -1122,12 +1135,7 @@ void Avatar::initializeSkeleton() { _joint[ AVATAR_JOINT_HEAD_BASE ].length + _joint[ AVATAR_JOINT_HEAD_BASE ].radius ); - - printf( "_height = %f\n", _height ); - - - - + //printf( "_height = %f\n", _height ); // generate world positions updateSkeleton(); @@ -1145,9 +1153,12 @@ void Avatar::calculateBoneLengths() { } void Avatar::updateSkeleton() { - // rotate body... + + // rotate body... _orientation.setToIdentity(); - _orientation.yaw( _bodyYaw ); + _orientation.yaw ( _bodyYaw ); + _orientation.pitch( _bodyPitch ); + _orientation.roll ( _bodyRoll ); // calculate positions of all bones by traversing the skeleton tree: for (int b = 0; b < NUM_AVATAR_JOINTS; b++) { diff --git a/interface/src/Avatar.h b/interface/src/Avatar.h index c14680df4f..45b43e50bb 100644 --- a/interface/src/Avatar.h +++ b/interface/src/Avatar.h @@ -42,7 +42,6 @@ enum AvatarMode NUM_AVATAR_MODES }; - enum AvatarJointID { AVATAR_JOINT_NULL = -1, @@ -52,19 +51,16 @@ enum AvatarJointID AVATAR_JOINT_NECK_BASE, AVATAR_JOINT_HEAD_BASE, AVATAR_JOINT_HEAD_TOP, - AVATAR_JOINT_LEFT_COLLAR, AVATAR_JOINT_LEFT_SHOULDER, AVATAR_JOINT_LEFT_ELBOW, AVATAR_JOINT_LEFT_WRIST, AVATAR_JOINT_LEFT_FINGERTIPS, - AVATAR_JOINT_RIGHT_COLLAR, AVATAR_JOINT_RIGHT_SHOULDER, AVATAR_JOINT_RIGHT_ELBOW, AVATAR_JOINT_RIGHT_WRIST, AVATAR_JOINT_RIGHT_FINGERTIPS, - AVATAR_JOINT_LEFT_HIP, AVATAR_JOINT_LEFT_KNEE, AVATAR_JOINT_LEFT_HEEL, @@ -73,37 +69,8 @@ enum AvatarJointID AVATAR_JOINT_RIGHT_KNEE, AVATAR_JOINT_RIGHT_HEEL, AVATAR_JOINT_RIGHT_TOES, - - /* - AVATAR_JOINT_NULL = -1, - AVATAR_JOINT_PELVIS, - AVATAR_JOINT_TORSO, - AVATAR_JOINT_CHEST, - AVATAR_JOINT_NECK_BASE, - AVATAR_JOINT_HEAD_BASE, - AVATAR_JOINT_HEAD_TOP, - AVATAR_JOINT_LEFT_COLLAR, - AVATAR_JOINT_LEFT_SHOULDER, - AVATAR_JOINT_LEFT_ELBOW, - AVATAR_JOINT_LEFT_WRIST, - AVATAR_JOINT_LEFT_FINGERTIPS, - AVATAR_JOINT_RIGHT_COLLAR, - AVATAR_JOINT_RIGHT_SHOULDER, - AVATAR_JOINT_RIGHT_ELBOW, - AVATAR_JOINT_RIGHT_WRIST, - AVATAR_JOINT_RIGHT_FINGERTIPS, - AVATAR_JOINT_LEFT_HIP, - AVATAR_JOINT_LEFT_KNEE, - AVATAR_JOINT_LEFT_HEEL, - AVATAR_JOINT_LEFT_TOES, - AVATAR_JOINT_RIGHT_HIP, - AVATAR_JOINT_RIGHT_KNEE, - AVATAR_JOINT_RIGHT_HEEL, - AVATAR_JOINT_RIGHT_TOES, - */ NUM_AVATAR_JOINTS - }; @@ -134,9 +101,12 @@ public: void setLeanSideways(float dist); void addLean(float x, float z); - const glm::vec3& getHeadLookatDirection() const { return _orientation.getFront(); }; - const glm::vec3& getHeadLookatDirectionUp() const { return _orientation.getUp(); }; - const glm::vec3& getHeadLookatDirectionRight() const { return _orientation.getRight(); }; + /* + 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(); }; @@ -183,9 +153,10 @@ private: const float DECAY = 0.1; const float THRUST_MAG = 1200.0; const float YAW_MAG = 500.0; - const float BODY_PITCH_DECAY = 5.0; - const float BODY_YAW_DECAY = 5.0; - const float BODY_ROLL_DECAY = 5.0; + const float BODY_SPIN_FRICTION = 5.0; + const float BODY_UPRIGHT_FORCE = 10.0; + const float BODY_PITCH_WHILE_WALKING = 30.0; + 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; @@ -204,20 +175,20 @@ private: struct AvatarJoint { - AvatarJointID parent; // which joint is this joint connected to? - glm::vec3 position; // the position at the "end" of the joint - in global space - glm::vec3 defaultPosePosition; // the parent relative position when the avatar is in the "T-pose" - glm::vec3 springyPosition; // used for special effects (a 'flexible' variant of position) - glm::vec3 springyVelocity; // used for special effects ( the velocity of the springy position) - float springBodyTightness; // how tightly the springy position tries to stay on the position - glm::quat rotation; // this will eventually replace yaw, pitch and roll (and maybe orientation) - float yaw; // the yaw Euler angle of the joint rotation off the parent - float pitch; // the pitch Euler angle of the joint rotation off the parent - float roll; // the roll Euler angle of the joint rotation off the parent - Orientation orientation; // three orthogonal normals determined by yaw, pitch, roll - float length; // the length of the joint - float radius; // used for detecting collisions for certain physical effects - bool isCollidable; // when false, the joint position will not register a collision + AvatarJointID parent; // which joint is this joint connected to? + glm::vec3 position; // the position at the "end" of the joint - in global space + glm::vec3 defaultPosePosition; // the parent relative position when the avatar is in the "T-pose" + glm::vec3 springyPosition; // used for special effects (a 'flexible' variant of position) + glm::vec3 springyVelocity; // used for special effects ( the velocity of the springy position) + float springBodyTightness; // how tightly the springy position tries to stay on the position + glm::quat rotation; // this will eventually replace yaw, pitch and roll (and maybe orientation) + float yaw; // the yaw Euler angle of the joint rotation off the parent + float pitch; // the pitch Euler angle of the joint rotation off the parent + float roll; // the roll Euler angle of the joint rotation off the parent + Orientation orientation; // three orthogonal normals determined by yaw, pitch, roll + float length; // the length of vector connecting the joint and its parent + float radius; // used for detecting collisions for certain physical effects + bool isCollidable; // when false, the joint position will not register a collision }; struct AvatarHead diff --git a/interface/src/main.cpp b/interface/src/main.cpp index e3788ec236..a8f6a6fec4 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -69,6 +69,7 @@ #include "Camera.h" #include "Avatar.h" +#include "AvatarRenderer.h" #include "Texture.h" #include #include @@ -119,6 +120,9 @@ Avatar myAvatar(true); // The rendered avatar of oneself Camera myCamera; // My view onto the world (sometimes on myself :) Camera viewFrustumOffsetCamera; // The camera we use to sometimes show the view frustum from an offset mode + +AvatarRenderer avatarRenderer; + // Starfield information char starFile[] = "https://s3-us-west-1.amazonaws.com/highfidelity/stars.txt"; char starCacheFile[] = "cachedStars.txt"; @@ -869,6 +873,7 @@ void display(void) if (agent->getLinkedData() != NULL && agent->getType() == AGENT_TYPE_AVATAR) { Avatar *avatar = (Avatar *)agent->getLinkedData(); avatar->render(0); + //avatarRenderer.render(avatar, 0); // this will replace the above call } } agentList->unlock(); @@ -881,6 +886,7 @@ void display(void) //Render my own avatar myAvatar.render(::lookingInMirror); + //avatarRenderer.render(&myAvatar, lookingInMirror); // this will replace the above call } glPopMatrix(); From 7a52d51251e1b5e2cd8a10551e5cf9a49a9062c8 Mon Sep 17 00:00:00 2001 From: Jeffrey Ventrella Date: Thu, 2 May 2013 17:47:28 -0700 Subject: [PATCH 4/5] adding avatar renderer --- interface/src/AvatarRenderer.cpp | 32 ++++++++++++++++++++++++++++++++ interface/src/AvatarRenderer.h | 25 +++++++++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 interface/src/AvatarRenderer.cpp create mode 100644 interface/src/AvatarRenderer.h diff --git a/interface/src/AvatarRenderer.cpp b/interface/src/AvatarRenderer.cpp new file mode 100644 index 0000000000..b533b69e22 --- /dev/null +++ b/interface/src/AvatarRenderer.cpp @@ -0,0 +1,32 @@ +// +// AvatarRenderer.cpp +// interface +// +// Created by Jeffrey Ventrella +// Copyright (c) 2013 High Fidelity, Inc. All rights reserved. +// +#include +#include +#include +#include "AvatarRenderer.h" +#include "InterfaceConfig.h" + + +AvatarRenderer::AvatarRenderer() { +} + +// this method renders the avatar +void AvatarRenderer::render(Avatar *avatar, bool lookingInMirror) { + +/* + // show avatar position + glColor4f( 0.5f, 0.5f, 0.5f, 0.6 ); + glPushMatrix(); + glTranslatef(avatar->_position.x, avatar->_position.y, avatar->_position.z); + glScalef( 0.03, 0.03, 0.03 ); + glutSolidSphere( 1, 10, 10 ); + glPopMatrix(); + */ +} + + \ No newline at end of file diff --git a/interface/src/AvatarRenderer.h b/interface/src/AvatarRenderer.h new file mode 100644 index 0000000000..80728ba560 --- /dev/null +++ b/interface/src/AvatarRenderer.h @@ -0,0 +1,25 @@ +// +// AvatarRenderer.h +// interface +// +// Created by Jeffrey Ventrella +// Copyright (c) 2013 High Fidelity, Inc. All rights reserved. +// + +#ifndef __interface__AvatarRenderer__ +#define __interface__AvatarRenderer__ + +#include "Avatar.h" +#include + +class AvatarRenderer { +public: + + AvatarRenderer(); + void render(Avatar *avatar, bool lookingInMirror); + +private: + +}; + +#endif From a4f2dc283dac65b857d708f7d2df984029fc8581 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Fri, 3 May 2013 09:58:52 -0700 Subject: [PATCH 5/5] various changes to help debug render pipeline - fixing some cases where TREE_SCALE was not using constant in prep for making TREE_SCALE larger - added createLine() to VoxelTree - added axis lines made of voxels to scene - added corner points made of voxels to scene --- interface/src/VoxelSystem.cpp | 2 +- interface/src/main.cpp | 2 +- libraries/voxels/src/VoxelNode.h | 1 + libraries/voxels/src/VoxelTree.cpp | 17 +++++++++++- libraries/voxels/src/VoxelTree.h | 2 ++ voxel-server/src/main.cpp | 44 ++++++++++++++++++++---------- 6 files changed, 50 insertions(+), 18 deletions(-) diff --git a/interface/src/VoxelSystem.cpp b/interface/src/VoxelSystem.cpp index b8f8485a67..989ab8ff3d 100644 --- a/interface/src/VoxelSystem.cpp +++ b/interface/src/VoxelSystem.cpp @@ -433,7 +433,7 @@ void VoxelSystem::render() { // draw the number of voxels we have glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _vboIndicesID); - glScalef(10, 10, 10); + glScalef(TREE_SCALE, TREE_SCALE, TREE_SCALE); glDrawElements(GL_TRIANGLES, 36 * _voxelsInArrays, GL_UNSIGNED_INT, 0); // deactivate vertex and color arrays after drawing diff --git a/interface/src/main.cpp b/interface/src/main.cpp index 6d3adcdbba..f3b82cc663 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -1696,7 +1696,7 @@ int main(int argc, const char * argv[]) // field of view and near and far clip to make it interesting. //viewFrustumOffsetCamera.setFieldOfView(90.0); viewFrustumOffsetCamera.setNearClip(0.1); - viewFrustumOffsetCamera.setFarClip(500.0); + viewFrustumOffsetCamera.setFarClip(500.0*TREE_SCALE); printLog( "Created Display Window.\n" ); diff --git a/libraries/voxels/src/VoxelNode.h b/libraries/voxels/src/VoxelNode.h index 26edb87e79..90ee3bf730 100644 --- a/libraries/voxels/src/VoxelNode.h +++ b/libraries/voxels/src/VoxelNode.h @@ -15,6 +15,7 @@ typedef unsigned char colorPart; typedef unsigned char nodeColor[4]; +typedef unsigned char rgbColor[3]; class VoxelNode { private: diff --git a/libraries/voxels/src/VoxelTree.cpp b/libraries/voxels/src/VoxelTree.cpp index 72327c2346..21118c929e 100644 --- a/libraries/voxels/src/VoxelTree.cpp +++ b/libraries/voxels/src/VoxelTree.cpp @@ -25,7 +25,7 @@ using voxels_lib::printLog; int boundaryDistanceForRenderLevel(unsigned int renderLevel) { - float voxelSizeScale = 5000.0; + float voxelSizeScale = 500.0*TREE_SCALE; return voxelSizeScale / powf(2, renderLevel); } @@ -444,6 +444,21 @@ void VoxelTree::createVoxel(float x, float y, float z, float s, unsigned char re delete voxelData; } + +void VoxelTree::createLine(glm::vec3 point1, glm::vec3 point2, float unitSize, rgbColor color) { + glm::vec3 distance = point2 - point1; + glm::vec3 items = distance / unitSize; + int maxItems = std::max(items.x, std::max(items.y, items.z)); + glm::vec3 increment = distance * (1.0f/ maxItems); + glm::vec3 pointAt = point1; + for (int i = 0; i <= maxItems; i++ ) { + pointAt += increment; + unsigned char* voxelData = pointToVoxel(pointAt.x,pointAt.y,pointAt.z,unitSize,color[0],color[1],color[2]); + readCodeColorBufferToTree(voxelData); + delete voxelData; + } +} + void VoxelTree::createSphere(float r,float xc, float yc, float zc, float s, bool solid, bool wantColorRandomizer) { // About the color of the sphere... we're going to make this sphere be a gradient // between two RGB colors. We will do the gradient along the phi spectrum diff --git a/libraries/voxels/src/VoxelTree.h b/libraries/voxels/src/VoxelTree.h index 2ccb704964..309766bcd2 100644 --- a/libraries/voxels/src/VoxelTree.h +++ b/libraries/voxels/src/VoxelTree.h @@ -47,6 +47,8 @@ public: void loadVoxelsFile(const char* fileName, bool wantColorRandomizer); void createSphere(float r,float xc, float yc, float zc, float s, bool solid, bool wantColorRandomizer); void createVoxel(float x, float y, float z, float s, unsigned char red, unsigned char green, unsigned char blue); + + void createLine(glm::vec3 point1, glm::vec3 point2, float unitSize, rgbColor color); void recurseTreeWithOperation(RecurseVoxelTreeOperation operation, void* extraData=NULL); diff --git a/voxel-server/src/main.cpp b/voxel-server/src/main.cpp index 9f5fc75ccb..17c4915988 100644 --- a/voxel-server/src/main.cpp +++ b/voxel-server/src/main.cpp @@ -75,10 +75,36 @@ bool countVoxelsOperation(VoxelNode* node, void* extraData) { } void addSphereScene(VoxelTree * tree, bool wantColorRandomizer) { - printf("adding scene of spheres...\n"); + printf("adding scene...\n"); + + float voxelSize = 1.f/32; + printf("creating corner points...\n"); + tree->createVoxel(0 , 0 , 0 , voxelSize, 255, 255 ,255); + tree->createVoxel(1.0 - voxelSize, 0 , 0 , voxelSize, 255, 0 ,0 ); + tree->createVoxel(0 , 1.0 - voxelSize, 0 , voxelSize, 0 , 255 ,0 ); + tree->createVoxel(0 , 0 , 1.0 - voxelSize, voxelSize, 0 , 0 ,255); + + + tree->createVoxel(1.0 - voxelSize, 0 , 1.0 - voxelSize, voxelSize, 255, 0 ,255); + tree->createVoxel(0 , 1.0 - voxelSize, 1.0 - voxelSize, voxelSize, 0 , 255 ,255); + tree->createVoxel(1.0 - voxelSize, 1.0 - voxelSize, 0 , voxelSize, 255, 255 ,0 ); + tree->createVoxel(1.0 - voxelSize, 1.0 - voxelSize, 1.0 - voxelSize, voxelSize, 255, 255 ,255); + printf("DONE creating corner points...\n"); + + printf("creating voxel lines...\n"); + float lineVoxelSize = 0.99f/256; + rgbColor red = {255,0,0}; + rgbColor green = {0,255,0}; + rgbColor blue = {0,0,255}; + + tree->createLine(glm::vec3(0, 0, 0), glm::vec3(0, 0, 1), lineVoxelSize, blue); + tree->createLine(glm::vec3(0, 0, 0), glm::vec3(1, 0, 0), lineVoxelSize, red); + tree->createLine(glm::vec3(0, 0, 0), glm::vec3(0, 1, 0), lineVoxelSize, green); + + printf("DONE creating lines...\n"); int sphereBaseSize = 512; - + printf("creating spheres...\n"); tree->createSphere(0.25, 0.5, 0.5, 0.5, (1.0 / sphereBaseSize), true, wantColorRandomizer); printf("one sphere added...\n"); tree->createSphere(0.030625, 0.5, 0.5, (0.25-0.06125), (1.0 / (sphereBaseSize * 2)), true, true); @@ -106,19 +132,7 @@ void addSphereScene(VoxelTree * tree, bool wantColorRandomizer) { tree->createSphere(radius, 0.025, radius * 5.0f, 0.25, (1.0 / 4096), true, true); printf("11 spheres added...\n"); - float voxelSize = 0.99f/8; - printf("creating corner points...\n"); - tree->createVoxel(0 , 0 , 0 , voxelSize, 255, 255 ,255); - tree->createVoxel(1.0 - voxelSize, 0 , 0 , voxelSize, 255, 0 ,0 ); - tree->createVoxel(0 , 1.0 - voxelSize, 0 , voxelSize, 0 , 255 ,0 ); - tree->createVoxel(0 , 0 , 1.0 - voxelSize, voxelSize, 0 , 0 ,255); - - - tree->createVoxel(1.0 - voxelSize, 0 , 1.0 - voxelSize, voxelSize, 255, 0 ,255); - tree->createVoxel(0 , 1.0 - voxelSize, 1.0 - voxelSize, voxelSize, 0 , 255 ,255); - tree->createVoxel(1.0 - voxelSize, 1.0 - voxelSize, 1.0 - voxelSize, voxelSize, 255, 255 ,255); - tree->createVoxel(1.0 - voxelSize, 1.0 - voxelSize, 0 , voxelSize, 255, 255 ,0 ); - printf("DONE creating corner points...\n"); + printf("DONE creating spheres...\n"); _nodeCount=0; tree->recurseTreeWithOperation(countVoxelsOperation);