Merge pull request #3664 from PhilipRosedale/master

Tour Guide script to let you follow people, better hair
This commit is contained in:
Stephen Birarda 2014-10-24 17:10:57 -07:00
commit 57e7fa233f
5 changed files with 52 additions and 7 deletions

47
examples/guidedTour.js Normal file
View file

@ -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);

View file

@ -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

View file

@ -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:

View file

@ -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);
}

View file

@ -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);
}