From 9e046b74e67b457fdae56b7fb7bf238574145d47 Mon Sep 17 00:00:00 2001 From: Jeffrey Ventrella Date: Mon, 3 Jun 2013 08:09:27 -0700 Subject: [PATCH 01/10] working on avatar touch --- interface/src/Application.cpp | 39 +++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index fe84ec4748..e0e5ea8046 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -50,6 +50,8 @@ using namespace std; +const bool TESTING_AVATAR_TOUCH = false; + // Starfield information static char STAR_FILE[] = "https://s3-us-west-1.amazonaws.com/highfidelity/stars.txt"; static char STAR_CACHE_FILE[] = "cachedStars.txt"; @@ -1078,24 +1080,31 @@ void Application::idle() { _myAvatar.simulate(deltaTime, NULL); } - if (_myCamera.getMode() != CAMERA_MODE_MIRROR && !OculusManager::isConnected()) { - if (_manualFirstPerson) { - if (_myCamera.getMode() != CAMERA_MODE_FIRST_PERSON ) { - _myCamera.setMode(CAMERA_MODE_FIRST_PERSON); - _myCamera.setModeShiftRate(1.0f); - } - } else { - - if (_myAvatar.getIsNearInteractingOther()) { - if (_myCamera.getMode() != CAMERA_MODE_FIRST_PERSON) { + if (TESTING_AVATAR_TOUCH) { + if (_myCamera.getMode() != CAMERA_MODE_THIRD_PERSON) { + _myCamera.setMode(CAMERA_MODE_THIRD_PERSON); + _myCamera.setModeShiftRate(1.0f); + } + } else { + if (_myCamera.getMode() != CAMERA_MODE_MIRROR && !OculusManager::isConnected()) { + if (_manualFirstPerson) { + if (_myCamera.getMode() != CAMERA_MODE_FIRST_PERSON ) { _myCamera.setMode(CAMERA_MODE_FIRST_PERSON); _myCamera.setModeShiftRate(1.0f); } - } - else { - if (_myCamera.getMode() != CAMERA_MODE_THIRD_PERSON) { - _myCamera.setMode(CAMERA_MODE_THIRD_PERSON); - _myCamera.setModeShiftRate(1.0f); + } else { + + if (_myAvatar.getIsNearInteractingOther()) { + if (_myCamera.getMode() != CAMERA_MODE_FIRST_PERSON) { + _myCamera.setMode(CAMERA_MODE_FIRST_PERSON); + _myCamera.setModeShiftRate(1.0f); + } + } + else { + if (_myCamera.getMode() != CAMERA_MODE_THIRD_PERSON) { + _myCamera.setMode(CAMERA_MODE_THIRD_PERSON); + _myCamera.setModeShiftRate(1.0f); + } } } } From cf67f28b57eb4c7eda9f3f4c9a6c8c45ac637337 Mon Sep 17 00:00:00 2001 From: Jeffrey Ventrella Date: Mon, 3 Jun 2013 08:10:41 -0700 Subject: [PATCH 02/10] merge --- .../resources/shaders/SkyFromAtmosphere.frag | 212 +++++++++--------- 1 file changed, 106 insertions(+), 106 deletions(-) diff --git a/interface/resources/shaders/SkyFromAtmosphere.frag b/interface/resources/shaders/SkyFromAtmosphere.frag index b640f5f952..dbefc8270e 100644 --- a/interface/resources/shaders/SkyFromAtmosphere.frag +++ b/interface/resources/shaders/SkyFromAtmosphere.frag @@ -1,106 +1,106 @@ -#version 120 - -// -// For licensing information, see http://http.developer.nvidia.com/GPUGems/gpugems_app01.html: -// -// NVIDIA Statement on the Software -// -// The source code provided is freely distributable, so long as the NVIDIA header remains unaltered and user modifications are -// detailed. -// -// No Warranty -// -// THE SOFTWARE AND ANY OTHER MATERIALS PROVIDED BY NVIDIA ON THE ENCLOSED CD-ROM ARE PROVIDED "AS IS." NVIDIA DISCLAIMS ALL -// WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF TITLE, MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -// -// Limitation of Liability -// -// NVIDIA SHALL NOT BE LIABLE TO ANY USER, DEVELOPER, DEVELOPER'S CUSTOMERS, OR ANY OTHER PERSON OR ENTITY CLAIMING THROUGH OR -// UNDER DEVELOPER FOR ANY LOSS OF PROFITS, INCOME, SAVINGS, OR ANY OTHER CONSEQUENTIAL, INCIDENTAL, SPECIAL, PUNITIVE, DIRECT -// OR INDIRECT DAMAGES (WHETHER IN AN ACTION IN CONTRACT, TORT OR BASED ON A WARRANTY), EVEN IF NVIDIA HAS BEEN ADVISED OF THE -// POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS SHALL APPLY NOTWITHSTANDING ANY FAILURE OF THE ESSENTIAL PURPOSE OF ANY -// LIMITED REMEDY. IN NO EVENT SHALL NVIDIA'S AGGREGATE LIABILITY TO DEVELOPER OR ANY OTHER PERSON OR ENTITY CLAIMING THROUGH -// OR UNDER DEVELOPER EXCEED THE AMOUNT OF MONEY ACTUALLY PAID BY DEVELOPER TO NVIDIA FOR THE SOFTWARE OR ANY OTHER MATERIALS. -// - -// -// Atmospheric scattering fragment shader -// -// Author: Sean O'Neil -// -// Copyright (c) 2004 Sean O'Neil -// - -uniform vec3 v3CameraPos; // The camera's current position -uniform vec3 v3InvWavelength; // 1 / pow(wavelength, 4) for the red, green, and blue channels -uniform float fInnerRadius; // The inner (planetary) radius -uniform float fKrESun; // Kr * ESun -uniform float fKmESun; // Km * ESun -uniform float fKr4PI; // Kr * 4 * PI -uniform float fKm4PI; // Km * 4 * PI -uniform float fScale; // 1 / (fOuterRadius - fInnerRadius) -uniform float fScaleDepth; // The scale depth (i.e. the altitude at which the atmosphere's average density is found) -uniform float fScaleOverScaleDepth; // fScale / fScaleDepth - -const int nSamples = 2; -const float fSamples = 2.0; - -uniform vec3 v3LightPos; -uniform float g; -uniform float g2; - -varying vec3 position; - -float scale(float fCos) -{ - float x = 1.0 - fCos; - return fScaleDepth * exp(-0.00287 + x*(0.459 + x*(3.83 + x*(-6.80 + x*5.25)))); -} - -void main (void) -{ - // Get the ray from the camera to the vertex, and its length (which is the far point of the ray passing through the atmosphere) - vec3 v3Pos = position; - vec3 v3Ray = v3Pos - v3CameraPos; - float fFar = length(v3Ray); - v3Ray /= fFar; - - // Calculate the ray's starting position, then calculate its scattering offset - vec3 v3Start = v3CameraPos; - float fHeight = length(v3Start); - float fDepth = exp(fScaleOverScaleDepth * (fInnerRadius - fHeight)); - float fStartAngle = dot(v3Ray, v3Start) / fHeight; - float fStartOffset = fDepth * scale(fStartAngle); - - // Initialize the scattering loop variables - //gl_FrontColor = vec4(0.0, 0.0, 0.0, 0.0); - float fSampleLength = fFar / fSamples; - float fScaledLength = fSampleLength * fScale; - vec3 v3SampleRay = v3Ray * fSampleLength; - vec3 v3SamplePoint = v3Start + v3SampleRay * 0.5; - - // Now loop through the sample rays - vec3 v3FrontColor = vec3(0.0, 0.0, 0.0); - for(int i=0; i Date: Mon, 3 Jun 2013 11:53:00 -0700 Subject: [PATCH 03/10] preparation for extending the avatar ball array to accommodate more touch capabilities --- interface/src/Application.cpp | 10 +++--- interface/src/Audio.cpp | 2 +- interface/src/Avatar.cpp | 43 +++++++++++----------- interface/src/Avatar.h | 68 ++++++++++++++++++++++++----------- interface/src/Skeleton.h | 4 +-- 5 files changed, 77 insertions(+), 50 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index e0e5ea8046..130bd5e7fe 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -289,22 +289,22 @@ void Application::paintGL() { if (_myCamera.getMode() == CAMERA_MODE_MIRROR) { _myCamera.setTightness (100.0f); - _myCamera.setTargetPosition(_myAvatar.getSpringyHeadPosition()); + _myCamera.setTargetPosition(_myAvatar.getBallPosition(AVATAR_JOINT_HEAD_BASE)); _myCamera.setTargetRotation(_myAvatar.getWorldAlignedOrientation() * glm::quat(glm::vec3(0.0f, PI, 0.0f))); } else if (OculusManager::isConnected()) { _myCamera.setUpShift (0.0f); _myCamera.setDistance (0.0f); _myCamera.setTightness (100.0f); - _myCamera.setTargetPosition(_myAvatar.getHeadPosition()); + _myCamera.setTargetPosition(_myAvatar.getHeadJointPosition()); _myCamera.setTargetRotation(_myAvatar.getHead().getOrientation()); } else if (_myCamera.getMode() == CAMERA_MODE_FIRST_PERSON) { - _myCamera.setTargetPosition(_myAvatar.getSpringyHeadPosition()); + _myCamera.setTargetPosition(_myAvatar.getBallPosition(AVATAR_JOINT_HEAD_BASE)); _myCamera.setTargetRotation(_myAvatar.getHead().getWorldAlignedOrientation()); } else if (_myCamera.getMode() == CAMERA_MODE_THIRD_PERSON) { - _myCamera.setTargetPosition(_myAvatar.getHeadPosition()); + _myCamera.setTargetPosition(_myAvatar.getHeadJointPosition()); _myCamera.setTargetRotation(_myAvatar.getHead().getWorldAlignedOrientation()); } @@ -1556,7 +1556,7 @@ void Application::loadViewFrustum(Camera& camera, ViewFrustum& viewFrustum) { if (_cameraFrustum->isChecked()) { position = camera.getPosition(); } else { - position = _myAvatar.getHeadPosition(); + position = _myAvatar.getHeadJointPosition(); } float fov = camera.getFieldOfView(); diff --git a/interface/src/Audio.cpp b/interface/src/Audio.cpp index 97929a99ca..3f5068a577 100644 --- a/interface/src/Audio.cpp +++ b/interface/src/Audio.cpp @@ -143,7 +143,7 @@ int audioCallback (const void* inputBuffer, unsigned char *currentPacketPtr = dataPacket + 1; // memcpy the three float positions - memcpy(currentPacketPtr, &interfaceAvatar->getHeadPosition(), sizeof(float) * 3); + memcpy(currentPacketPtr, &interfaceAvatar->getHeadJointPosition(), sizeof(float) * 3); currentPacketPtr += (sizeof(float) * 3); // tell the mixer not to add additional attenuation to our source diff --git a/interface/src/Avatar.cpp b/interface/src/Avatar.cpp index 46a4d302ca..c02a6ccaa7 100644 --- a/interface/src/Avatar.cpp +++ b/interface/src/Avatar.cpp @@ -118,16 +118,18 @@ Avatar::Avatar(Agent* owningAgent) : void Avatar::initializeBodyBalls() { - for (int b=0; b 0.0) { glm::vec3 directionVector = vectorFromJointToBigSphereCenter / distanceToBigSphereCenter; float penetration = 1.0 - (distanceToBigSphereCenter / combinedRadius); glm::vec3 collisionForce = vectorFromJointToBigSphereCenter * penetration; - - _bodyBall[b].velocity += collisionForce * 0.0f * deltaTime; - _velocity += collisionForce * 40.0f * deltaTime; + + _velocity += collisionForce * 40.0f * deltaTime; _bodyBall[b].position = position + directionVector * combinedRadius; } } @@ -760,11 +759,11 @@ void Avatar::applyCollisionWithOtherAvatar(Avatar * otherAvatar, float deltaTime glm::vec3 bodyPushForce = glm::vec3(0.0f, 0.0f, 0.0f); - // loop through the joints of each avatar to check for every possible collision - for (int b=1; b_bodyBall[o].isCollidable) { glm::vec3 vectorBetweenJoints(_bodyBall[b].position - otherAvatar->_bodyBall[o].position); @@ -893,8 +892,8 @@ void Avatar::render(bool lookingInMirror) { } void Avatar::resetBodyBalls() { - for (int b = 0; b < NUM_AVATAR_JOINTS; b++) { - _bodyBall[b].position = _skeleton.joint[b].position; + for (int b = 0; b < NUM_AVATAR_BODY_BALLS; b++) { + _bodyBall[b].position = _skeleton.joint[b].position; // put balls on joints _bodyBall[b].velocity = glm::vec3(0.0f, 0.0f, 0.0f); } } @@ -905,7 +904,7 @@ void Avatar::updateBodyBalls(float deltaTime) { if (glm::length(_position - _bodyBall[AVATAR_JOINT_PELVIS].position) > BEYOND_BODY_SPRING_RANGE) { resetBodyBalls(); } - for (int b = 0; b < NUM_AVATAR_JOINTS; b++) { + for (int b = 0; b < NUM_AVATAR_BODY_BALLS; b++) { glm::vec3 springVector(_bodyBall[b].position); if (_skeleton.joint[b].parent == AVATAR_JOINT_NULL) { @@ -942,8 +941,8 @@ void Avatar::updateBodyBalls(float deltaTime) { /* //apply forces from touch... - if (_skeleton.joint[b].touchForce > 0.0) { - _skeleton.joint[b].springyVelocity += _mouseRayDirection * _skeleton.joint[b].touchForce * 0.7f; + if (_bodyBall[b].touchForce > 0.0) { + _bodyBall[b].velocity += _mouseRayDirection * _bodyBall[b].touchForce * 0.7f; } */ @@ -1010,8 +1009,8 @@ void Avatar::renderBody(bool lookingInMirror) { const float RENDER_TRANSLUCENT_BEYOND = 0.5f; // Render the body as balls and cones - for (int b = 0; b < NUM_AVATAR_JOINTS; b++) { - float distanceToCamera = glm::length(_cameraPosition - _skeleton.joint[b].position); + for (int b = 0; b < NUM_AVATAR_BODY_BALLS; b++) { + float distanceToCamera = glm::length(_cameraPosition - _bodyBall[b].position); float alpha = lookingInMirror ? 1.0f : glm::clamp((distanceToCamera - RENDER_TRANSLUCENT_BEYOND) / (RENDER_OPAQUE_BEYOND - RENDER_TRANSLUCENT_BEYOND), 0.f, 1.f); @@ -1029,7 +1028,7 @@ void Avatar::renderBody(bool lookingInMirror) { || b == AVATAR_JOINT_RIGHT_ELBOW || b == AVATAR_JOINT_RIGHT_WRIST || b == AVATAR_JOINT_RIGHT_FINGERTIPS ) { - // Render the sphere at the joint + // Render the body ball sphere if (_owningAgent || b == AVATAR_JOINT_RIGHT_ELBOW || b == AVATAR_JOINT_RIGHT_WRIST || b == AVATAR_JOINT_RIGHT_FINGERTIPS ) { @@ -1051,7 +1050,7 @@ void Avatar::renderBody(bool lookingInMirror) { glPopMatrix(); } - // Render the cone connecting this joint to its parent + // Render the cone connecting this ball to its parent if (_skeleton.joint[b].parent != AVATAR_JOINT_NULL) { if ((b != AVATAR_JOINT_HEAD_TOP ) && (b != AVATAR_JOINT_HEAD_BASE ) diff --git a/interface/src/Avatar.h b/interface/src/Avatar.h index 6746ba51cd..c1303287be 100644 --- a/interface/src/Avatar.h +++ b/interface/src/Avatar.h @@ -20,6 +20,37 @@ #include "Skeleton.h" #include "Transmitter.h" + +enum AvatarBodyBallID +{ + BODY_BALL_NULL = -1, + BODY_BALL_PELVIS, + BODY_BALL_TORSO, + BODY_BALL_CHEST, + BODY_BALL_NECK_BASE, + BODY_BALL_HEAD_BASE, + BODY_BALL_HEAD_TOP, + BODY_BALL_LEFT_COLLAR, + BODY_BALL_LEFT_SHOULDER, + BODY_BALL_LEFT_ELBOW, + BODY_BALL_LEFT_WRIST, + BODY_BALL_LEFT_FINGERTIPS, + BODY_BALL_RIGHT_COLLAR, + BODY_BALL_RIGHT_SHOULDER, + BODY_BALL_RIGHT_ELBOW, + BODY_BALL_RIGHT_WRIST, + BODY_BALL_RIGHT_FINGERTIPS, + BODY_BALL_LEFT_HIP, + BODY_BALL_LEFT_KNEE, + BODY_BALL_LEFT_HEEL, + BODY_BALL_LEFT_TOES, + BODY_BALL_RIGHT_HIP, + BODY_BALL_RIGHT_KNEE, + BODY_BALL_RIGHT_HEEL, + BODY_BALL_RIGHT_TOES, + NUM_AVATAR_BODY_BALLS +}; + enum DriveKeys { FWD = 0, @@ -64,19 +95,14 @@ public: void setOrientation (const glm::quat& orientation); //getters - - float getHeadYawRate () const { return _head.yawRate;} - float getBodyYaw () const { return _bodyYaw;} - bool getIsNearInteractingOther() const { return _avatarTouch.getAbleToReachOtherAvatar();} - const glm::vec3& getHeadPosition () const { return _skeleton.joint[ AVATAR_JOINT_HEAD_BASE ].position;} - const glm::vec3& getSpringyHeadPosition () const { return _bodyBall[ AVATAR_JOINT_HEAD_BASE ].position;} - const glm::vec3& getJointPosition (AvatarJointID j) const { return _bodyBall[j].position;} - - glm::vec3 getBodyRightDirection () const { return getOrientation() * AVATAR_RIGHT; } - glm::vec3 getBodyUpDirection () const { return getOrientation() * AVATAR_UP; } - glm::vec3 getBodyFrontDirection () const { return getOrientation() * AVATAR_FRONT; } - - + float getHeadYawRate () const { return _head.yawRate;} + float getBodyYaw () const { return _bodyYaw;} + bool getIsNearInteractingOther () const { return _avatarTouch.getAbleToReachOtherAvatar();} + const glm::vec3& getHeadJointPosition () const { return _skeleton.joint[ AVATAR_JOINT_HEAD_BASE ].position;} + const glm::vec3& getBallPosition (AvatarJointID j) const { return _bodyBall[j].position;} + glm::vec3 getBodyRightDirection () const { return getOrientation() * AVATAR_RIGHT; } + glm::vec3 getBodyUpDirection () const { return getOrientation() * AVATAR_UP; } + glm::vec3 getBodyFrontDirection () const { return getOrientation() * AVATAR_FRONT; } const glm::vec3& getVelocity () const { return _velocity;} float getSpeed () const { return _speed;} float getHeight () const { return _height;} @@ -106,12 +132,14 @@ private: struct AvatarBall { - glm::vec3 position; - glm::vec3 velocity; - float jointTightness; - float radius; - bool isCollidable; - float touchForce; + AvatarJointID parent; + glm::vec3 parentOffset; + glm::vec3 position; + glm::vec3 velocity; + float jointTightness; + float radius; + bool isCollidable; + float touchForce; }; Head _head; @@ -124,7 +152,7 @@ private: float _bodyRollDelta; glm::vec3 _movedHandOffset; glm::quat _rotation; // the rotation of the avatar body as a whole expressed as a quaternion - AvatarBall _bodyBall[ NUM_AVATAR_JOINTS ]; + AvatarBall _bodyBall[ NUM_AVATAR_BODY_BALLS ]; AvatarMode _mode; glm::vec3 _cameraPosition; glm::vec3 _handHoldingPosition; diff --git a/interface/src/Skeleton.h b/interface/src/Skeleton.h index 4c1152728d..28d3a6e81e 100644 --- a/interface/src/Skeleton.h +++ b/interface/src/Skeleton.h @@ -60,9 +60,9 @@ public: { 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 defaultPosePosition; // the parent relative position when the avatar is in the default pose glm::quat rotation; // the parent-relative rotation (orientation) of the joint as a quaternion - float length; // the length of vector connecting the joint and its parent + float length; // the length of vector between the joint and its parent }; AvatarJoint joint[ NUM_AVATAR_JOINTS ]; From 00dce6b59e0ae18125e75d346b6f922d87370d36 Mon Sep 17 00:00:00 2001 From: Jeffrey Ventrella Date: Mon, 3 Jun 2013 12:01:01 -0700 Subject: [PATCH 04/10] fix --- interface/src/Avatar.cpp | 2 +- interface/src/Avatar.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/interface/src/Avatar.cpp b/interface/src/Avatar.cpp index c02a6ccaa7..6d2f0eefad 100644 --- a/interface/src/Avatar.cpp +++ b/interface/src/Avatar.cpp @@ -119,7 +119,7 @@ Avatar::Avatar(Agent* owningAgent) : void Avatar::initializeBodyBalls() { for (int b=0; b Date: Mon, 3 Jun 2013 12:26:20 -0700 Subject: [PATCH 05/10] more ball prep --- interface/src/Avatar.cpp | 168 ++++++++++++++++++++++----------------- 1 file changed, 97 insertions(+), 71 deletions(-) diff --git a/interface/src/Avatar.cpp b/interface/src/Avatar.cpp index 6d2f0eefad..4fb2846a0f 100644 --- a/interface/src/Avatar.cpp +++ b/interface/src/Avatar.cpp @@ -101,10 +101,10 @@ Avatar::Avatar(Agent* owningAgent) : initializeBodyBalls(); - _height = _skeleton.getHeight() + _bodyBall[ AVATAR_JOINT_LEFT_HEEL ].radius + _bodyBall[ AVATAR_JOINT_HEAD_BASE ].radius; + _height = _skeleton.getHeight() + _bodyBall[ BODY_BALL_LEFT_HEEL ].radius + _bodyBall[ BODY_BALL_HEAD_BASE ].radius; _maxArmLength = _skeleton.getArmLength(); - _pelvisStandingHeight = _skeleton.getPelvisStandingHeight() + _bodyBall[ AVATAR_JOINT_LEFT_HEEL ].radius; - _pelvisFloatingHeight = _skeleton.getPelvisFloatingHeight() + _bodyBall[ AVATAR_JOINT_LEFT_HEEL ].radius; + _pelvisStandingHeight = _skeleton.getPelvisStandingHeight() + _bodyBall[ BODY_BALL_LEFT_HEEL ].radius; + _pelvisFloatingHeight = _skeleton.getPelvisFloatingHeight() + _bodyBall[ BODY_BALL_LEFT_HEEL ].radius; _avatarTouch.setReachableRadius(PERIPERSONAL_RADIUS); @@ -128,41 +128,67 @@ void Avatar::initializeBodyBalls() { _bodyBall[b].isCollidable = true; _bodyBall[b].jointTightness = BODY_SPRING_DEFAULT_TIGHTNESS; } + + // specify the parent joint of each ball + _bodyBall[ BODY_BALL_PELVIS ].radius = 0.07; + _bodyBall[ BODY_BALL_TORSO ].radius = 0.065; + _bodyBall[ BODY_BALL_CHEST ].radius = 0.08; + _bodyBall[ BODY_BALL_NECK_BASE ].radius = 0.03; + _bodyBall[ BODY_BALL_HEAD_BASE ].radius = 0.07; - // specify the radii of the balls - _bodyBall[ AVATAR_JOINT_PELVIS ].radius = 0.07; - _bodyBall[ AVATAR_JOINT_TORSO ].radius = 0.065; - _bodyBall[ AVATAR_JOINT_CHEST ].radius = 0.08; - _bodyBall[ AVATAR_JOINT_NECK_BASE ].radius = 0.03; - _bodyBall[ AVATAR_JOINT_HEAD_BASE ].radius = 0.07; + _bodyBall[ BODY_BALL_LEFT_COLLAR ].radius = 0.04; + _bodyBall[ BODY_BALL_LEFT_SHOULDER ].radius = 0.03; + _bodyBall[ BODY_BALL_LEFT_ELBOW ].radius = 0.02; + _bodyBall[ BODY_BALL_LEFT_WRIST ].radius = 0.02; + _bodyBall[ BODY_BALL_LEFT_FINGERTIPS ].radius = 0.01; - _bodyBall[ AVATAR_JOINT_LEFT_COLLAR ].radius = 0.04; - _bodyBall[ AVATAR_JOINT_LEFT_SHOULDER ].radius = 0.03; - _bodyBall[ AVATAR_JOINT_LEFT_ELBOW ].radius = 0.02; - _bodyBall[ AVATAR_JOINT_LEFT_WRIST ].radius = 0.02; - _bodyBall[ AVATAR_JOINT_LEFT_FINGERTIPS ].radius = 0.01; + _bodyBall[ BODY_BALL_RIGHT_COLLAR ].radius = 0.04; + _bodyBall[ BODY_BALL_RIGHT_SHOULDER ].radius = 0.03; + _bodyBall[ BODY_BALL_RIGHT_ELBOW ].radius = 0.02; + _bodyBall[ BODY_BALL_RIGHT_WRIST ].radius = 0.02; + _bodyBall[ BODY_BALL_RIGHT_FINGERTIPS ].radius = 0.01; - _bodyBall[ AVATAR_JOINT_RIGHT_COLLAR ].radius = 0.04; - _bodyBall[ AVATAR_JOINT_RIGHT_SHOULDER ].radius = 0.03; - _bodyBall[ AVATAR_JOINT_RIGHT_ELBOW ].radius = 0.02; - _bodyBall[ AVATAR_JOINT_RIGHT_WRIST ].radius = 0.02; - _bodyBall[ AVATAR_JOINT_RIGHT_FINGERTIPS ].radius = 0.01; + _bodyBall[ BODY_BALL_LEFT_HIP ].radius = 0.04; + _bodyBall[ BODY_BALL_LEFT_KNEE ].radius = 0.025; + _bodyBall[ BODY_BALL_LEFT_HEEL ].radius = 0.025; + _bodyBall[ BODY_BALL_LEFT_TOES ].radius = 0.025; - _bodyBall[ AVATAR_JOINT_LEFT_HIP ].radius = 0.04; - _bodyBall[ AVATAR_JOINT_LEFT_KNEE ].radius = 0.025; - _bodyBall[ AVATAR_JOINT_LEFT_HEEL ].radius = 0.025; - _bodyBall[ AVATAR_JOINT_LEFT_TOES ].radius = 0.025; - - _bodyBall[ AVATAR_JOINT_RIGHT_HIP ].radius = 0.04; - _bodyBall[ AVATAR_JOINT_RIGHT_KNEE ].radius = 0.025; - _bodyBall[ AVATAR_JOINT_RIGHT_HEEL ].radius = 0.025; - _bodyBall[ AVATAR_JOINT_RIGHT_TOES ].radius = 0.025; + _bodyBall[ BODY_BALL_RIGHT_HIP ].radius = 0.04; + _bodyBall[ BODY_BALL_RIGHT_KNEE ].radius = 0.025; + _bodyBall[ BODY_BALL_RIGHT_HEEL ].radius = 0.025; + _bodyBall[ BODY_BALL_RIGHT_TOES ].radius = 0.025; + // specify the parent joint for each ball + _bodyBall[ BODY_BALL_PELVIS ].parentJoint = AVATAR_JOINT_NULL; + _bodyBall[ BODY_BALL_TORSO ].parentJoint = AVATAR_JOINT_PELVIS; + _bodyBall[ BODY_BALL_CHEST ].parentJoint = AVATAR_JOINT_TORSO; + _bodyBall[ BODY_BALL_NECK_BASE ].parentJoint = AVATAR_JOINT_CHEST; + _bodyBall[ BODY_BALL_HEAD_BASE ].parentJoint = AVATAR_JOINT_NECK_BASE; + _bodyBall[ BODY_BALL_HEAD_TOP ].parentJoint = AVATAR_JOINT_HEAD_BASE; + _bodyBall[ BODY_BALL_LEFT_COLLAR ].parentJoint = AVATAR_JOINT_CHEST; + _bodyBall[ BODY_BALL_LEFT_SHOULDER ].parentJoint = AVATAR_JOINT_LEFT_COLLAR; + _bodyBall[ BODY_BALL_LEFT_ELBOW ].parentJoint = AVATAR_JOINT_LEFT_SHOULDER; + _bodyBall[ BODY_BALL_LEFT_WRIST ].parentJoint = AVATAR_JOINT_LEFT_ELBOW; + _bodyBall[ BODY_BALL_LEFT_FINGERTIPS ].parentJoint = AVATAR_JOINT_LEFT_WRIST; + _bodyBall[ BODY_BALL_RIGHT_COLLAR ].parentJoint = AVATAR_JOINT_CHEST; + _bodyBall[ BODY_BALL_RIGHT_SHOULDER ].parentJoint = AVATAR_JOINT_RIGHT_COLLAR; + _bodyBall[ BODY_BALL_RIGHT_ELBOW ].parentJoint = AVATAR_JOINT_RIGHT_SHOULDER; + _bodyBall[ BODY_BALL_RIGHT_WRIST ].parentJoint = AVATAR_JOINT_RIGHT_ELBOW; + _bodyBall[ BODY_BALL_RIGHT_FINGERTIPS ].parentJoint = AVATAR_JOINT_RIGHT_WRIST; + _bodyBall[ BODY_BALL_LEFT_HIP ].parentJoint = AVATAR_JOINT_PELVIS; + _bodyBall[ BODY_BALL_LEFT_KNEE ].parentJoint = AVATAR_JOINT_LEFT_HIP; + _bodyBall[ BODY_BALL_LEFT_HEEL ].parentJoint = AVATAR_JOINT_LEFT_KNEE; + _bodyBall[ BODY_BALL_LEFT_TOES ].parentJoint = AVATAR_JOINT_LEFT_HEEL; + _bodyBall[ BODY_BALL_RIGHT_HIP ].parentJoint = AVATAR_JOINT_PELVIS; + _bodyBall[ BODY_BALL_RIGHT_KNEE ].parentJoint = AVATAR_JOINT_RIGHT_HIP; + _bodyBall[ BODY_BALL_RIGHT_HEEL ].parentJoint = AVATAR_JOINT_RIGHT_KNEE; + _bodyBall[ BODY_BALL_RIGHT_TOES ].parentJoint = AVATAR_JOINT_RIGHT_HEEL; + /* // to aid in hand-shaking and hand-holding, the right hand is not collidable - _bodyBall[ AVATAR_JOINT_RIGHT_ELBOW ].isCollidable = false; - _bodyBall[ AVATAR_JOINT_RIGHT_WRIST ].isCollidable = false; - _bodyBall[ AVATAR_JOINT_RIGHT_FINGERTIPS].isCollidable = false; + _bodyBall[ BODY_BALL_RIGHT_ELBOW ].isCollidable = false; + _bodyBall[ BODY_BALL_RIGHT_WRIST ].isCollidable = false; + _bodyBall[ BODY_BALL_RIGHT_FINGERTIPS].isCollidable = false; */ } @@ -458,22 +484,22 @@ void Avatar::simulate(float deltaTime, Transmitter* transmitter) { right * _head.getLeanSideways() + front * _head.getLeanForward(); - _bodyBall[ AVATAR_JOINT_TORSO ].position += headLean * 0.1f; - _bodyBall[ AVATAR_JOINT_CHEST ].position += headLean * 0.4f; - _bodyBall[ AVATAR_JOINT_NECK_BASE ].position += headLean * 0.7f; - _bodyBall[ AVATAR_JOINT_HEAD_BASE ].position += headLean * 1.0f; + _bodyBall[ BODY_BALL_TORSO ].position += headLean * 0.1f; + _bodyBall[ BODY_BALL_CHEST ].position += headLean * 0.4f; + _bodyBall[ BODY_BALL_NECK_BASE ].position += headLean * 0.7f; + _bodyBall[ BODY_BALL_HEAD_BASE ].position += headLean * 1.0f; - _bodyBall[ AVATAR_JOINT_LEFT_COLLAR ].position += headLean * 0.6f; - _bodyBall[ AVATAR_JOINT_LEFT_SHOULDER ].position += headLean * 0.6f; - _bodyBall[ AVATAR_JOINT_LEFT_ELBOW ].position += headLean * 0.2f; - _bodyBall[ AVATAR_JOINT_LEFT_WRIST ].position += headLean * 0.1f; - _bodyBall[ AVATAR_JOINT_LEFT_FINGERTIPS ].position += headLean * 0.0f; + _bodyBall[ BODY_BALL_LEFT_COLLAR ].position += headLean * 0.6f; + _bodyBall[ BODY_BALL_LEFT_SHOULDER ].position += headLean * 0.6f; + _bodyBall[ BODY_BALL_LEFT_ELBOW ].position += headLean * 0.2f; + _bodyBall[ BODY_BALL_LEFT_WRIST ].position += headLean * 0.1f; + _bodyBall[ BODY_BALL_LEFT_FINGERTIPS ].position += headLean * 0.0f; - _bodyBall[ AVATAR_JOINT_RIGHT_COLLAR ].position += headLean * 0.6f; - _bodyBall[ AVATAR_JOINT_RIGHT_SHOULDER ].position += headLean * 0.6f; - _bodyBall[ AVATAR_JOINT_RIGHT_ELBOW ].position += headLean * 0.2f; - _bodyBall[ AVATAR_JOINT_RIGHT_WRIST ].position += headLean * 0.1f; - _bodyBall[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position += headLean * 0.0f; + _bodyBall[ BODY_BALL_RIGHT_COLLAR ].position += headLean * 0.6f; + _bodyBall[ BODY_BALL_RIGHT_SHOULDER ].position += headLean * 0.6f; + _bodyBall[ BODY_BALL_RIGHT_ELBOW ].position += headLean * 0.2f; + _bodyBall[ BODY_BALL_RIGHT_WRIST ].position += headLean * 0.1f; + _bodyBall[ BODY_BALL_RIGHT_FINGERTIPS ].position += headLean * 0.0f; } } @@ -487,8 +513,8 @@ void Avatar::simulate(float deltaTime, Transmitter* transmitter) { } _head.setBodyRotation (glm::vec3(_bodyPitch, _bodyYaw, _bodyRoll)); - _head.setPosition(_bodyBall[ AVATAR_JOINT_HEAD_BASE ].position); - _head.setScale (_bodyBall[ AVATAR_JOINT_HEAD_BASE ].radius); + _head.setPosition(_bodyBall[ BODY_BALL_HEAD_BASE ].position); + _head.setScale (_bodyBall[ BODY_BALL_HEAD_BASE ].radius); _head.setSkinColor(glm::vec3(SKIN_COLOR[0], SKIN_COLOR[1], SKIN_COLOR[2])); _head.simulate(deltaTime, !_owningAgent); @@ -581,7 +607,7 @@ void Avatar::updateHandMovementAndTouching(float deltaTime) { _avatarTouch.setHasInteractingOther(true); _avatarTouch.setYourBodyPosition(_interactingOther->_position); - _avatarTouch.setYourHandPosition(_interactingOther->_bodyBall[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position); + _avatarTouch.setYourHandPosition(_interactingOther->_bodyBall[ BODY_BALL_RIGHT_FINGERTIPS ].position); _avatarTouch.setYourOrientation (_interactingOther->getOrientation()); _avatarTouch.setYourHandState (_interactingOther->_handState); @@ -652,7 +678,7 @@ void Avatar::updateHandMovementAndTouching(float deltaTime) { } _avatarTouch.setMyHandState(_handState); - _avatarTouch.setMyHandPosition(_bodyBall[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position); + _avatarTouch.setMyHandPosition(_bodyBall[ BODY_BALL_RIGHT_FINGERTIPS ].position); } } @@ -856,7 +882,7 @@ void Avatar::render(bool lookingInMirror) { } glPushMatrix(); - glm::vec3 chatPosition = _bodyBall[AVATAR_JOINT_HEAD_BASE].position + getBodyUpDirection() * chatMessageHeight; + glm::vec3 chatPosition = _bodyBall[BODY_BALL_HEAD_BASE].position + getBodyUpDirection() * chatMessageHeight; glTranslatef(chatPosition.x, chatPosition.y, chatPosition.z); glm::quat chatRotation = Application::getInstance()->getCamera()->getRotation(); glm::vec3 chatAxis = glm::axis(chatRotation); @@ -901,13 +927,13 @@ void Avatar::resetBodyBalls() { void Avatar::updateBodyBalls(float deltaTime) { // Check for a large repositioning, and re-initialize balls if this has happened const float BEYOND_BODY_SPRING_RANGE = 2.f; - if (glm::length(_position - _bodyBall[AVATAR_JOINT_PELVIS].position) > BEYOND_BODY_SPRING_RANGE) { + if (glm::length(_position - _bodyBall[BODY_BALL_PELVIS].position) > BEYOND_BODY_SPRING_RANGE) { resetBodyBalls(); } for (int b = 0; b < NUM_AVATAR_BODY_BALLS; b++) { glm::vec3 springVector(_bodyBall[b].position); - if (_skeleton.joint[b].parent == AVATAR_JOINT_NULL) { + if (b == BODY_BALL_PELVIS) { springVector -= _position; } else { @@ -1020,18 +1046,18 @@ void Avatar::renderBody(bool lookingInMirror) { } // Always render other people, and render myself when beyond threshold distance - if (b == AVATAR_JOINT_HEAD_BASE) { // the head is rendered as a special + if (b == BODY_BALL_HEAD_BASE) { // the head is rendered as a special if (lookingInMirror || _owningAgent || distanceToCamera > RENDER_OPAQUE_BEYOND * 0.5) { _head.render(lookingInMirror, _cameraPosition, alpha); } } else if (_owningAgent || distanceToCamera > RENDER_TRANSLUCENT_BEYOND - || b == AVATAR_JOINT_RIGHT_ELBOW - || b == AVATAR_JOINT_RIGHT_WRIST - || b == AVATAR_JOINT_RIGHT_FINGERTIPS ) { + || b == BODY_BALL_RIGHT_ELBOW + || b == BODY_BALL_RIGHT_WRIST + || b == BODY_BALL_RIGHT_FINGERTIPS ) { // Render the body ball sphere - if (_owningAgent || b == AVATAR_JOINT_RIGHT_ELBOW - || b == AVATAR_JOINT_RIGHT_WRIST - || b == AVATAR_JOINT_RIGHT_FINGERTIPS ) { + if (_owningAgent || b == BODY_BALL_RIGHT_ELBOW + || b == BODY_BALL_RIGHT_WRIST + || b == BODY_BALL_RIGHT_FINGERTIPS ) { glColor3f(SKIN_COLOR[0] + _bodyBall[b].touchForce * 0.3f, SKIN_COLOR[1] - _bodyBall[b].touchForce * 0.2f, SKIN_COLOR[2] - _bodyBall[b].touchForce * 0.1f); @@ -1042,8 +1068,8 @@ void Avatar::renderBody(bool lookingInMirror) { alpha); } - if ((b != AVATAR_JOINT_HEAD_TOP ) - && (b != AVATAR_JOINT_HEAD_BASE )) { + if ((b != BODY_BALL_HEAD_TOP ) + && (b != BODY_BALL_HEAD_BASE )) { glPushMatrix(); glTranslatef(_bodyBall[b].position.x, _bodyBall[b].position.y, _bodyBall[b].position.z); glutSolidSphere(_bodyBall[b].radius, 20.0f, 20.0f); @@ -1052,20 +1078,20 @@ void Avatar::renderBody(bool lookingInMirror) { // Render the cone connecting this ball to its parent if (_skeleton.joint[b].parent != AVATAR_JOINT_NULL) { - if ((b != AVATAR_JOINT_HEAD_TOP ) - && (b != AVATAR_JOINT_HEAD_BASE ) - && (b != AVATAR_JOINT_PELVIS ) - && (b != AVATAR_JOINT_TORSO ) - && (b != AVATAR_JOINT_CHEST ) - && (b != AVATAR_JOINT_LEFT_COLLAR ) - && (b != AVATAR_JOINT_LEFT_SHOULDER ) - && (b != AVATAR_JOINT_RIGHT_COLLAR ) - && (b != AVATAR_JOINT_RIGHT_SHOULDER)) { + if ((b != BODY_BALL_HEAD_TOP ) + && (b != BODY_BALL_HEAD_BASE ) + && (b != BODY_BALL_PELVIS ) + && (b != BODY_BALL_TORSO ) + && (b != BODY_BALL_CHEST ) + && (b != BODY_BALL_LEFT_COLLAR ) + && (b != BODY_BALL_LEFT_SHOULDER ) + && (b != BODY_BALL_RIGHT_COLLAR ) + && (b != BODY_BALL_RIGHT_SHOULDER)) { glColor3fv(DARK_SKIN_COLOR); float r1 = _bodyBall[_skeleton.joint[b].parent ].radius * 0.8; float r2 = _bodyBall[b ].radius * 0.8; - if (b == AVATAR_JOINT_HEAD_BASE) { + if (b == BODY_BALL_HEAD_BASE) { r1 *= 0.5f; } renderJointConnectingCone From 26bbb9917b7b9ab096e3238048a4a800f510b6e2 Mon Sep 17 00:00:00 2001 From: Jeffrey Ventrella Date: Mon, 3 Jun 2013 16:23:55 -0700 Subject: [PATCH 06/10] more work on avatar touch --- interface/src/Application.cpp | 2 +- interface/src/Avatar.cpp | 242 +++++++++++++++++++++++----------- interface/src/Avatar.h | 23 ++-- interface/src/Skeleton.cpp | 1 + interface/src/Skeleton.h | 1 + 5 files changed, 185 insertions(+), 84 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 130bd5e7fe..1480b81050 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -50,7 +50,7 @@ using namespace std; -const bool TESTING_AVATAR_TOUCH = false; +const bool TESTING_AVATAR_TOUCH = true; // Starfield information static char STAR_FILE[] = "https://s3-us-west-1.amazonaws.com/highfidelity/stars.txt"; diff --git a/interface/src/Avatar.cpp b/interface/src/Avatar.cpp index 4fb2846a0f..99ddd65853 100644 --- a/interface/src/Avatar.cpp +++ b/interface/src/Avatar.cpp @@ -44,7 +44,7 @@ const float HEAD_MAX_YAW = 85; const float HEAD_MIN_YAW = -85; const float PERIPERSONAL_RADIUS = 1.0f; const float AVATAR_BRAKING_STRENGTH = 40.0f; -const float JOINT_TOUCH_RANGE = 0.01f; +const float MOUSE_RAY_TOUCH_RANGE = 0.01f; const float FLOATING_HEIGHT = 0.13f; const bool USING_HEAD_LEAN = false; const float LEAN_SENSITIVITY = 0.15; @@ -64,7 +64,8 @@ float chatMessageHeight = 0.20; Avatar::Avatar(Agent* owningAgent) : AvatarData(owningAgent), _head(this), - _TEST_bigSphereRadius(0.4f), + _ballSpringsInitialized(false), + _TEST_bigSphereRadius(0.5f), _TEST_bigSpherePosition(5.0f, _TEST_bigSphereRadius, 5.0f), _mousePressed(false), _bodyPitchDelta(0.0f), @@ -118,6 +119,8 @@ Avatar::Avatar(Agent* owningAgent) : void Avatar::initializeBodyBalls() { + _ballSpringsInitialized = false; //this gets set to true on the first update pass... + for (int b=0; b (1.0f - range)) { _bodyBall[b].touchForce = (dot - (1.0f - range)) / range; @@ -585,11 +670,6 @@ void Avatar::updateHandMovementAndTouching(float deltaTime) { if (agent->getLinkedData() != NULL && agent->getType() == AGENT_TYPE_AVATAR) { Avatar *otherAvatar = (Avatar *)agent->getLinkedData(); - //Test: Show angle between your fwd vector and nearest avatar - //glm::vec3 vectorBetweenUs = otherAvatar->getJointPosition(AVATAR_JOINT_PELVIS) - - // getJointPosition(AVATAR_JOINT_PELVIS); - //printLog("Angle between: %f\n", angleBetween(vectorBetweenUs, getBodyFrontDirection())); - // test whether shoulders are close enough to allow for reaching to touch hands glm::vec3 v(_position - otherAvatar->_position); float distance = glm::length(v); @@ -689,16 +769,16 @@ void Avatar::updateCollisionWithSphere(glm::vec3 position, float radius, float d float distanceToBigSphere = glm::length(vectorFromMyBodyToBigSphere); if (distanceToBigSphere < myBodyApproximateBoundingRadius + radius) { for (int b = 0; b < NUM_AVATAR_BODY_BALLS; b++) { - glm::vec3 vectorFromJointToBigSphereCenter(_bodyBall[b].position - position); - float distanceToBigSphereCenter = glm::length(vectorFromJointToBigSphereCenter); + glm::vec3 vectorFromBallToBigSphereCenter(_bodyBall[b].position - position); + float distanceToBigSphereCenter = glm::length(vectorFromBallToBigSphereCenter); float combinedRadius = _bodyBall[b].radius + radius; if (distanceToBigSphereCenter < combinedRadius) { if (distanceToBigSphereCenter > 0.0) { - glm::vec3 directionVector = vectorFromJointToBigSphereCenter / distanceToBigSphereCenter; + glm::vec3 directionVector = vectorFromBallToBigSphereCenter / distanceToBigSphereCenter; float penetration = 1.0 - (distanceToBigSphereCenter / combinedRadius); - glm::vec3 collisionForce = vectorFromJointToBigSphereCenter * penetration; + glm::vec3 collisionForce = vectorFromBallToBigSphereCenter * penetration; _velocity += collisionForce * 40.0f * deltaTime; _bodyBall[b].position = position + directionVector * combinedRadius; @@ -792,18 +872,18 @@ void Avatar::applyCollisionWithOtherAvatar(Avatar * otherAvatar, float deltaTime for (int o=b+1; o_bodyBall[o].isCollidable) { - glm::vec3 vectorBetweenJoints(_bodyBall[b].position - otherAvatar->_bodyBall[o].position); - float distanceBetweenJoints = glm::length(vectorBetweenJoints); + glm::vec3 vectorBetweenBalls(_bodyBall[b].position - otherAvatar->_bodyBall[o].position); + float distanceBetweenBalls = glm::length(vectorBetweenBalls); - if (distanceBetweenJoints > 0.0) { // to avoid divide by zero + if (distanceBetweenBalls > 0.0) { // to avoid divide by zero float combinedRadius = _bodyBall[b].radius + otherAvatar->_bodyBall[o].radius; // check for collision - if (distanceBetweenJoints < combinedRadius * COLLISION_RADIUS_SCALAR) { - glm::vec3 directionVector = vectorBetweenJoints / distanceBetweenJoints; + if (distanceBetweenBalls < combinedRadius * COLLISION_RADIUS_SCALAR) { + glm::vec3 directionVector = vectorBetweenBalls / distanceBetweenBalls; // push balls away from each other and apply friction - float penetration = 1.0f - (distanceBetweenJoints / (combinedRadius * COLLISION_RADIUS_SCALAR)); + float penetration = 1.0f - (distanceBetweenBalls / (combinedRadius * COLLISION_RADIUS_SCALAR)); glm::vec3 ballPushForce = directionVector * COLLISION_BALL_FORCE * penetration * deltaTime; bodyPushForce += directionVector * COLLISION_BODY_FORCE * penetration * deltaTime; @@ -919,7 +999,12 @@ void Avatar::render(bool lookingInMirror) { void Avatar::resetBodyBalls() { for (int b = 0; b < NUM_AVATAR_BODY_BALLS; b++) { - _bodyBall[b].position = _skeleton.joint[b].position; // put balls on joints + + glm::vec3 targetPosition + = _skeleton.joint[_bodyBall[b].parentJoint].position + + _skeleton.joint[_bodyBall[b].parentJoint].rotation * _bodyBall[b].parentOffset; + + _bodyBall[b].position = targetPosition; // put ball on target position _bodyBall[b].velocity = glm::vec3(0.0f, 0.0f, 0.0f); } } @@ -931,30 +1016,39 @@ void Avatar::updateBodyBalls(float deltaTime) { resetBodyBalls(); } for (int b = 0; b < NUM_AVATAR_BODY_BALLS; b++) { - glm::vec3 springVector(_bodyBall[b].position); - - if (b == BODY_BALL_PELVIS) { - springVector -= _position; - } - else { - springVector -= _bodyBall[ _skeleton.joint[b].parent ].position; - } - - float length = glm::length(springVector); - - if (length > 0.0f) { // to avoid divide by zero - glm::vec3 springDirection = springVector / length; - - float force = (length - _skeleton.joint[b].length) * BODY_SPRING_FORCE * deltaTime; - _bodyBall[b].velocity -= springDirection * force; + + if (_ballSpringsInitialized) { + + //apply spring forces + glm::vec3 springVector(_bodyBall[b].position); - if (_skeleton.joint[b].parent != AVATAR_JOINT_NULL) { - _bodyBall[_skeleton.joint[b].parent].velocity += springDirection * force; + if (b == BODY_BALL_PELVIS) { + springVector -= _position; } + else { + springVector -= _bodyBall[_bodyBall[b].parentBall].position; + } + + float length = glm::length(springVector); + + if (length > 0.0f) { // to avoid divide by zero + glm::vec3 springDirection = springVector / length; + + float force = (length - _skeleton.joint[b].length) * BODY_SPRING_FORCE * deltaTime; + _bodyBall[b].velocity -= springDirection * force; + + if (_bodyBall[b].parentBall != BODY_BALL_NULL) { + _bodyBall[_bodyBall[b].parentBall].velocity += springDirection * force; + } + } } // apply tightness force - (causing ball position to be close to skeleton joint position) - _bodyBall[b].velocity += (_skeleton.joint[b].position - _bodyBall[b].position) * _bodyBall[b].jointTightness * deltaTime; + glm::vec3 targetPosition + = _skeleton.joint[_bodyBall[b].parentJoint].position + + _skeleton.joint[_bodyBall[b].parentJoint].rotation * _bodyBall[b].parentOffset; + + _bodyBall[b].velocity += (targetPosition - _bodyBall[b].position) * _bodyBall[b].jointTightness * deltaTime; // apply decay float decay = 1.0 - BODY_SPRING_DECAY * deltaTime; @@ -1077,7 +1171,7 @@ void Avatar::renderBody(bool lookingInMirror) { } // Render the cone connecting this ball to its parent - if (_skeleton.joint[b].parent != AVATAR_JOINT_NULL) { + if (_bodyBall[b].parentBall != BODY_BALL_NULL) { if ((b != BODY_BALL_HEAD_TOP ) && (b != BODY_BALL_HEAD_BASE ) && (b != BODY_BALL_PELVIS ) @@ -1089,15 +1183,15 @@ void Avatar::renderBody(bool lookingInMirror) { && (b != BODY_BALL_RIGHT_SHOULDER)) { glColor3fv(DARK_SKIN_COLOR); - float r1 = _bodyBall[_skeleton.joint[b].parent ].radius * 0.8; - float r2 = _bodyBall[b ].radius * 0.8; + float r1 = _bodyBall[_bodyBall[b].parentBall ].radius * 0.8; + float r2 = _bodyBall[b].radius * 0.8; if (b == BODY_BALL_HEAD_BASE) { r1 *= 0.5f; } renderJointConnectingCone ( - _bodyBall[_skeleton.joint[b].parent ].position, - _bodyBall[b ].position, r2, r2 + _bodyBall[_bodyBall[b].parentBall].position, + _bodyBall[b].position, r2, r2 ); } } diff --git a/interface/src/Avatar.h b/interface/src/Avatar.h index 8b5a67c7fb..3809678cd5 100644 --- a/interface/src/Avatar.h +++ b/interface/src/Avatar.h @@ -48,6 +48,9 @@ enum AvatarBodyBallID BODY_BALL_RIGHT_KNEE, BODY_BALL_RIGHT_HEEL, BODY_BALL_RIGHT_TOES, + +//TEST! +//BODY_BALL_LEFT_MID_THIGH, NUM_AVATAR_BODY_BALLS }; @@ -132,18 +135,21 @@ private: struct AvatarBall { - AvatarJointID parentJoint; - glm::vec3 parentOffset; - glm::vec3 position; - glm::vec3 velocity; - float jointTightness; - float radius; - bool isCollidable; - float touchForce; + AvatarJointID parentJoint; // the skeletal joint that serves as a reference for determining the position + glm::vec3 parentOffset; // a 3D vector in the frame of reference of the parent skeletal joint + AvatarBodyBallID parentBall; // the ball to which this ball is constrained for spring forces + glm::vec3 position; // the actual dynamic position of the ball at any given time + glm::vec3 velocity; // the velocity of the ball + float springLength; // the ideal length of the spring between this ball and its parentBall + float jointTightness; // how tightly the ball position attempts to stay at its ideal position (determined by parentOffset) + float radius; // the radius of the ball + bool isCollidable; // whether or not the ball responds to collisions + float touchForce; // a scalar determining the amount that the cursor (or hand) is penetrating the ball }; Head _head; Skeleton _skeleton; + bool _ballSpringsInitialized; float _TEST_bigSphereRadius; glm::vec3 _TEST_bigSpherePosition; bool _mousePressed; @@ -151,7 +157,6 @@ private: float _bodyYawDelta; float _bodyRollDelta; glm::vec3 _movedHandOffset; - glm::quat _rotation; // the rotation of the avatar body as a whole expressed as a quaternion AvatarBall _bodyBall[ NUM_AVATAR_BODY_BALLS ]; AvatarMode _mode; glm::vec3 _cameraPosition; diff --git a/interface/src/Skeleton.cpp b/interface/src/Skeleton.cpp index 64a8645247..e360b0f97f 100644 --- a/interface/src/Skeleton.cpp +++ b/interface/src/Skeleton.cpp @@ -101,6 +101,7 @@ void Skeleton::update(float deltaTime, const glm::quat& orientation, glm::vec3 p } } + float Skeleton::getArmLength() { return joint[ AVATAR_JOINT_RIGHT_ELBOW ].length + joint[ AVATAR_JOINT_RIGHT_WRIST ].length diff --git a/interface/src/Skeleton.h b/interface/src/Skeleton.h index 28d3a6e81e..5b979b47f3 100644 --- a/interface/src/Skeleton.h +++ b/interface/src/Skeleton.h @@ -55,6 +55,7 @@ public: float getHeight(); float getPelvisStandingHeight(); float getPelvisFloatingHeight(); + //glm::vec3 getJointVectorFromParent(AvatarJointID jointID) {return joint[jointID].position - joint[joint[jointID].parent].position; } struct AvatarJoint { From b73eb66492a6654347efde52e598d83b47d46244 Mon Sep 17 00:00:00 2001 From: Jeffrey Ventrella Date: Mon, 3 Jun 2013 16:31:39 -0700 Subject: [PATCH 07/10] temp test --- interface/src/Avatar.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/interface/src/Avatar.cpp b/interface/src/Avatar.cpp index 99ddd65853..91feb88681 100644 --- a/interface/src/Avatar.cpp +++ b/interface/src/Avatar.cpp @@ -43,7 +43,10 @@ const float HEAD_MIN_PITCH = -45; const float HEAD_MAX_YAW = 85; const float HEAD_MIN_YAW = -85; const float PERIPERSONAL_RADIUS = 1.0f; -const float AVATAR_BRAKING_STRENGTH = 40.0f; + +//const float AVATAR_BRAKING_STRENGTH = 40.0f; +const float AVATAR_BRAKING_STRENGTH = 0.0f; + const float MOUSE_RAY_TOUCH_RANGE = 0.01f; const float FLOATING_HEIGHT = 0.13f; const bool USING_HEAD_LEAN = false; From 3ff11d0eb88b586812c5816b5cf741261d182985 Mon Sep 17 00:00:00 2001 From: Jeffrey Ventrella Date: Mon, 3 Jun 2013 16:42:27 -0700 Subject: [PATCH 08/10] test --- interface/src/Avatar.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/interface/src/Avatar.cpp b/interface/src/Avatar.cpp index 91feb88681..f4a2627e41 100644 --- a/interface/src/Avatar.cpp +++ b/interface/src/Avatar.cpp @@ -35,7 +35,10 @@ const float BODY_SPRING_FORCE = 300.0f; const float BODY_SPRING_DECAY = 16.0f; const float COLLISION_RADIUS_SCALAR = 1.2; //pertains to avatar-to-avatar collisions const float COLLISION_BALL_FORCE = 200.0; //pertains to avatar-to-avatar collisions -const float COLLISION_BODY_FORCE = 30.0; //pertains to avatar-to-avatar collisions + +//const float COLLISION_BODY_FORCE = 30.0; //pertains to avatar-to-avatar collisions +const float COLLISION_BODY_FORCE = 0.0; //pertains to avatar-to-avatar collisions + const float HEAD_ROTATION_SCALE = 0.70; const float HEAD_ROLL_SCALE = 0.40; const float HEAD_MAX_PITCH = 45; From da09dd3259ca59f53bbb9aaa6f2cb2fe44950180 Mon Sep 17 00:00:00 2001 From: Jeffrey Ventrella Date: Mon, 3 Jun 2013 17:16:52 -0700 Subject: [PATCH 09/10] test --- interface/src/Avatar.cpp | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/interface/src/Avatar.cpp b/interface/src/Avatar.cpp index f4a2627e41..99ddd65853 100644 --- a/interface/src/Avatar.cpp +++ b/interface/src/Avatar.cpp @@ -35,10 +35,7 @@ const float BODY_SPRING_FORCE = 300.0f; const float BODY_SPRING_DECAY = 16.0f; const float COLLISION_RADIUS_SCALAR = 1.2; //pertains to avatar-to-avatar collisions const float COLLISION_BALL_FORCE = 200.0; //pertains to avatar-to-avatar collisions - -//const float COLLISION_BODY_FORCE = 30.0; //pertains to avatar-to-avatar collisions -const float COLLISION_BODY_FORCE = 0.0; //pertains to avatar-to-avatar collisions - +const float COLLISION_BODY_FORCE = 30.0; //pertains to avatar-to-avatar collisions const float HEAD_ROTATION_SCALE = 0.70; const float HEAD_ROLL_SCALE = 0.40; const float HEAD_MAX_PITCH = 45; @@ -46,10 +43,7 @@ const float HEAD_MIN_PITCH = -45; const float HEAD_MAX_YAW = 85; const float HEAD_MIN_YAW = -85; const float PERIPERSONAL_RADIUS = 1.0f; - -//const float AVATAR_BRAKING_STRENGTH = 40.0f; -const float AVATAR_BRAKING_STRENGTH = 0.0f; - +const float AVATAR_BRAKING_STRENGTH = 40.0f; const float MOUSE_RAY_TOUCH_RANGE = 0.01f; const float FLOATING_HEIGHT = 0.13f; const bool USING_HEAD_LEAN = false; From cee22443643174d2493a12435f730e975553abb0 Mon Sep 17 00:00:00 2001 From: Jeffrey Ventrella Date: Mon, 3 Jun 2013 17:55:48 -0700 Subject: [PATCH 10/10] fixed formatting things --- interface/src/Application.cpp | 6 ++---- interface/src/Avatar.cpp | 32 +++++++++++++++----------------- interface/src/Skeleton.cpp | 2 +- 3 files changed, 18 insertions(+), 22 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 1480b81050..36ff4075d5 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -50,7 +50,7 @@ using namespace std; -const bool TESTING_AVATAR_TOUCH = true; +const bool TESTING_AVATAR_TOUCH = false; // Starfield information static char STAR_FILE[] = "https://s3-us-west-1.amazonaws.com/highfidelity/stars.txt"; @@ -1093,14 +1093,12 @@ void Application::idle() { _myCamera.setModeShiftRate(1.0f); } } else { - if (_myAvatar.getIsNearInteractingOther()) { if (_myCamera.getMode() != CAMERA_MODE_FIRST_PERSON) { _myCamera.setMode(CAMERA_MODE_FIRST_PERSON); _myCamera.setModeShiftRate(1.0f); } - } - else { + } else { if (_myCamera.getMode() != CAMERA_MODE_THIRD_PERSON) { _myCamera.setMode(CAMERA_MODE_THIRD_PERSON); _myCamera.setModeShiftRate(1.0f); diff --git a/interface/src/Avatar.cpp b/interface/src/Avatar.cpp index 99ddd65853..3949120737 100644 --- a/interface/src/Avatar.cpp +++ b/interface/src/Avatar.cpp @@ -121,7 +121,7 @@ void Avatar::initializeBodyBalls() { _ballSpringsInitialized = false; //this gets set to true on the first update pass... - for (int b=0; b::max(); - //loop through all the other avatars for potential interactions... + // loop through all the other avatars for potential interactions... AgentList* agentList = AgentList::getInstance(); for (AgentList::iterator agent = agentList->begin(); agent != agentList->end(); agent++) { if (agent->getLinkedData() != NULL && agent->getType() == AGENT_TYPE_AVATAR) { @@ -844,7 +844,7 @@ void Avatar::updateAvatarCollisions(float deltaTime) { glm::vec3 vectorBetweenBoundingSpheres(_position - otherAvatar->_position); if (glm::length(vectorBetweenBoundingSpheres) < _height * ONE_HALF + otherAvatar->_height * ONE_HALF) { - //apply forces from collision + // apply forces from collision applyCollisionWithOtherAvatar(otherAvatar, deltaTime); } @@ -860,16 +860,16 @@ void Avatar::updateAvatarCollisions(float deltaTime) { } } -//detect collisions with other avatars and respond +// detect collisions with other avatars and respond void Avatar::applyCollisionWithOtherAvatar(Avatar * otherAvatar, float deltaTime) { glm::vec3 bodyPushForce = glm::vec3(0.0f, 0.0f, 0.0f); // loop through the body balls of each avatar to check for every possible collision - for (int b=1; b_bodyBall[o].isCollidable) { glm::vec3 vectorBetweenBalls(_bodyBall[b].position - otherAvatar->_bodyBall[o].position); @@ -898,7 +898,7 @@ void Avatar::applyCollisionWithOtherAvatar(Avatar * otherAvatar, float deltaTime } // b loop } // collidable - //apply force on the whole body + // apply force on the whole body _velocity += bodyPushForce; } @@ -938,7 +938,7 @@ void Avatar::render(bool lookingInMirror) { // render a simple round on the ground projected down from the avatar's position renderDiskShadow(_position, glm::vec3(0.0f, 1.0f, 0.0f), 0.1f, 0.2f); - //render body + // render body renderBody(lookingInMirror); // if this is my avatar, then render my interactions with the other avatar @@ -1010,7 +1010,7 @@ void Avatar::resetBodyBalls() { } void Avatar::updateBodyBalls(float deltaTime) { - // Check for a large repositioning, and re-initialize balls if this has happened + // Check for a large repositioning, and re-initialize balls if this has happened const float BEYOND_BODY_SPRING_RANGE = 2.f; if (glm::length(_position - _bodyBall[BODY_BALL_PELVIS].position) > BEYOND_BODY_SPRING_RANGE) { resetBodyBalls(); @@ -1019,13 +1019,12 @@ void Avatar::updateBodyBalls(float deltaTime) { if (_ballSpringsInitialized) { - //apply spring forces + // apply spring forces glm::vec3 springVector(_bodyBall[b].position); if (b == BODY_BALL_PELVIS) { springVector -= _position; - } - else { + } else { springVector -= _bodyBall[_bodyBall[b].parentBall].position; } @@ -1054,19 +1053,18 @@ void Avatar::updateBodyBalls(float deltaTime) { float decay = 1.0 - BODY_SPRING_DECAY * deltaTime; if (decay > 0.0) { _bodyBall[b].velocity *= decay; - } - else { + } else { _bodyBall[b].velocity = glm::vec3(0.0f, 0.0f, 0.0f); } /* - //apply forces from touch... + // apply forces from touch... if (_bodyBall[b].touchForce > 0.0) { _bodyBall[b].velocity += _mouseRayDirection * _bodyBall[b].touchForce * 0.7f; } */ - //update position by velocity... + // update position by velocity... _bodyBall[b].position += _bodyBall[b].velocity * deltaTime; } } @@ -1229,7 +1227,7 @@ void Avatar::setHeadFromGyros(glm::vec3* eulerAngles, glm::vec3* angularVelocity _head.setYaw (angles.x); _head.setPitch(angles.y); _head.setRoll (angles.z); - //printLog("Y/P/R: %3.1f, %3.1f, %3.1f\n", angles.x, angles.y, angles.z); + // printLog("Y/P/R: %3.1f, %3.1f, %3.1f\n", angles.x, angles.y, angles.z); } } diff --git a/interface/src/Skeleton.cpp b/interface/src/Skeleton.cpp index e360b0f97f..55c6210068 100644 --- a/interface/src/Skeleton.cpp +++ b/interface/src/Skeleton.cpp @@ -14,7 +14,7 @@ Skeleton::Skeleton() { void Skeleton::initialize() { - for (int b=0; b