From d5d0fbd9d8ecb58101fe960f875fd9d24d4af544 Mon Sep 17 00:00:00 2001 From: Philip Rosedale Date: Fri, 24 Oct 2014 16:08:01 -0700 Subject: [PATCH 1/3] Hair gravity always the same --- interface/src/Hair.cpp | 6 +++--- interface/src/Hair.h | 4 ++-- interface/src/avatar/Avatar.cpp | 1 - interface/src/avatar/MyAvatar.cpp | 1 - 4 files changed, 5 insertions(+), 7 deletions(-) diff --git a/interface/src/Hair.cpp b/interface/src/Hair.cpp index 6ca0d4a899..acc00c14b0 100644 --- a/interface/src/Hair.cpp +++ b/interface/src/Hair.cpp @@ -38,7 +38,7 @@ Hair::Hair(int strands, _acceleration(0.0f), _angularVelocity(0.0f), _angularAcceleration(0.0f), - _gravity(0.0f), + _gravity(DEFAULT_GRAVITY), _loudness(0.0f) { _hairPosition = new glm::vec3[_strands * _links]; @@ -53,7 +53,7 @@ Hair::Hair(int strands, for (int strand = 0; strand < _strands; strand++) { float strandAngle = randFloat() * PI; float azimuth; - float elevation = PI_OVER_TWO - (randFloat() * 0.10f * PI); + float elevation = - (randFloat() * PI); azimuth = PI_OVER_TWO; if (randFloat() < 0.5f) { azimuth *= -1.0f; @@ -127,7 +127,7 @@ void Hair::simulate(float deltaTime) { _hairPosition[vertexIndex] += randVector() * (QUIESCENT_LOUDNESS + loudnessFactor) * ((float)link / (float)_links); // Add gravity - const float SCALE_GRAVITY = 0.13f; + const float SCALE_GRAVITY = 0.001f; _hairPosition[vertexIndex] += _gravity * deltaTime * SCALE_GRAVITY; // Add linear acceleration diff --git a/interface/src/Hair.h b/interface/src/Hair.h index f799140c53..94378dfd6a 100644 --- a/interface/src/Hair.h +++ b/interface/src/Hair.h @@ -25,9 +25,10 @@ const int HAIR_CONSTRAINTS = 2; const int DEFAULT_HAIR_STRANDS = 20; const int DEFAULT_HAIR_LINKS = 10; -const float DEFAULT_HAIR_RADIUS = 0.15f; +const float DEFAULT_HAIR_RADIUS = 0.075f; const float DEFAULT_HAIR_LINK_LENGTH = 0.06f; const float DEFAULT_HAIR_THICKNESS = 0.025f; +const glm::vec3 DEFAULT_GRAVITY(0.0f, -9.8f, 0.0f); class Hair { public: @@ -41,7 +42,6 @@ public: void setAcceleration(const glm::vec3& acceleration) { _acceleration = acceleration; } void setAngularVelocity(const glm::vec3& angularVelocity) { _angularVelocity = angularVelocity; } void setAngularAcceleration(const glm::vec3& angularAcceleration) { _angularAcceleration = angularAcceleration; } - void setGravity(const glm::vec3& gravity) { _gravity = gravity; } void setLoudness(const float loudness) { _loudness = loudness; } private: diff --git a/interface/src/avatar/Avatar.cpp b/interface/src/avatar/Avatar.cpp index 169583b14b..b1c4b44104 100644 --- a/interface/src/avatar/Avatar.cpp +++ b/interface/src/avatar/Avatar.cpp @@ -191,7 +191,6 @@ void Avatar::simulate(float deltaTime) { _hair.setAcceleration(getAcceleration() * getHead()->getFinalOrientationInWorldFrame()); _hair.setAngularVelocity((getAngularVelocity() + getHead()->getAngularVelocity()) * getHead()->getFinalOrientationInWorldFrame()); _hair.setAngularAcceleration(getAngularAcceleration() * getHead()->getFinalOrientationInWorldFrame()); - _hair.setGravity(Application::getInstance()->getEnvironment()->getGravity(getPosition()) * getHead()->getFinalOrientationInWorldFrame()); _hair.setLoudness((float) getHeadData()->getAudioLoudness()); _hair.simulate(deltaTime); } diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index 4751abfd84..7576d42325 100644 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -217,7 +217,6 @@ void MyAvatar::simulate(float deltaTime) { _hair.setAcceleration(getAcceleration() * getHead()->getFinalOrientationInWorldFrame()); _hair.setAngularVelocity((getAngularVelocity() + getHead()->getAngularVelocity()) * getHead()->getFinalOrientationInWorldFrame()); _hair.setAngularAcceleration(getAngularAcceleration() * getHead()->getFinalOrientationInWorldFrame()); - _hair.setGravity(Application::getInstance()->getEnvironment()->getGravity(getPosition()) * getHead()->getFinalOrientationInWorldFrame()); _hair.setLoudness((float)getHeadData()->getAudioLoudness()); _hair.simulate(deltaTime); } From 1e832e7bbbe34a755a7c86de2006c2682600b45a Mon Sep 17 00:00:00 2001 From: Philip Rosedale Date: Fri, 24 Oct 2014 16:38:24 -0700 Subject: [PATCH 2/3] Tour guide script --- examples/guidedTour.js | 47 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 examples/guidedTour.js diff --git a/examples/guidedTour.js b/examples/guidedTour.js new file mode 100644 index 0000000000..fe31e1db30 --- /dev/null +++ b/examples/guidedTour.js @@ -0,0 +1,47 @@ +// +// TourGuide.js +// +// This script will follow another person, if their display name is "Tour Guide" +// +var leaderName = "Tour Guide"; + +var guide; +var isGuide = false; +var lastGuidePosition = { x:0, y:0, z:0 }; +var MIN_CHANGE = 2.0; +var LANDING_DISTANCE = 2.0; +var LANDING_RANDOM = 0.2; + +function update(deltaTime) { + + if (Math.random() < deltaTime) { + guide = AvatarList.avatarWithDisplayName(leaderName); + if (guide && !isGuide) { + print("found a guide!"); + isGuide = true; + } else if (!isGuide) { + print("Lost My Guide"); + isguide = false; + } + } + + if (guide) { + // Check whether guide has moved, update if so + if (Vec3.length(lastGuidePosition) == 0.0) { + lastGuidePosition = guide.position; + } else { + if (Vec3.length(Vec3.subtract(lastGuidePosition, guide.position)) > MIN_CHANGE) { + var meToGuide = Vec3.multiply(Vec3.normalize(Vec3.subtract(guide.position, MyAvatar.position)), LANDING_DISTANCE); + var newPosition = Vec3.subtract(guide.position, meToGuide); + newPosition = Vec3.sum(newPosition, { x: Math.random() * LANDING_RANDOM - LANDING_RANDOM / 2.0, + y: 0, + z: Math.random() * LANDING_RANDOM - LANDING_RANDOM / 2.0 }); + MyAvatar.position = newPosition; + + lastGuidePosition = guide.position; + MyAvatar.orientation = guide.orientation; + } + } + } +} +Script.update.connect(update); \ No newline at end of file From 54197b2c2304948add3bc17c259473f34284432c Mon Sep 17 00:00:00 2001 From: Philip Rosedale Date: Fri, 24 Oct 2014 17:10:46 -0700 Subject: [PATCH 3/3] fix for spacing --- examples/guidedTour.js | 50 +++++++++++++++++++++--------------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/examples/guidedTour.js b/examples/guidedTour.js index fe31e1db30..3416e55d1c 100644 --- a/examples/guidedTour.js +++ b/examples/guidedTour.js @@ -14,34 +14,34 @@ var LANDING_RANDOM = 0.2; function update(deltaTime) { - if (Math.random() < deltaTime) { - guide = AvatarList.avatarWithDisplayName(leaderName); - if (guide && !isGuide) { - print("found a guide!"); - isGuide = true; - } else if (!isGuide) { - print("Lost My Guide"); - isguide = false; - } + if (Math.random() < deltaTime) { + guide = AvatarList.avatarWithDisplayName(leaderName); + if (guide && !isGuide) { + print("found a guide!"); + isGuide = true; + } else if (!isGuide) { + print("Lost My Guide"); + isguide = false; } + } - if (guide) { - // Check whether guide has moved, update if so - if (Vec3.length(lastGuidePosition) == 0.0) { - lastGuidePosition = guide.position; - } else { - if (Vec3.length(Vec3.subtract(lastGuidePosition, guide.position)) > MIN_CHANGE) { - var meToGuide = Vec3.multiply(Vec3.normalize(Vec3.subtract(guide.position, MyAvatar.position)), LANDING_DISTANCE); - var newPosition = Vec3.subtract(guide.position, meToGuide); - newPosition = Vec3.sum(newPosition, { x: Math.random() * LANDING_RANDOM - LANDING_RANDOM / 2.0, - y: 0, - z: Math.random() * LANDING_RANDOM - LANDING_RANDOM / 2.0 }); - MyAvatar.position = newPosition; + if (guide) { + // Check whether guide has moved, update if so + if (Vec3.length(lastGuidePosition) == 0.0) { + lastGuidePosition = guide.position; + } else { + if (Vec3.length(Vec3.subtract(lastGuidePosition, guide.position)) > MIN_CHANGE) { + var meToGuide = Vec3.multiply(Vec3.normalize(Vec3.subtract(guide.position, MyAvatar.position)), LANDING_DISTANCE); + var newPosition = Vec3.subtract(guide.position, meToGuide); + newPosition = Vec3.sum(newPosition, { x: Math.random() * LANDING_RANDOM - LANDING_RANDOM / 2.0, + y: 0, + z: Math.random() * LANDING_RANDOM - LANDING_RANDOM / 2.0 }); + MyAvatar.position = newPosition; - lastGuidePosition = guide.position; - MyAvatar.orientation = guide.orientation; - } - } + lastGuidePosition = guide.position; + MyAvatar.orientation = guide.orientation; + } } + } } Script.update.connect(update); \ No newline at end of file