fish swim to where youre looking

This commit is contained in:
James B. Pollack 2016-03-01 10:53:50 -08:00
parent 42ec6de512
commit ba2e977968
2 changed files with 71 additions and 68 deletions

View file

@ -27,6 +27,12 @@ var BUBBLE_SYSTEM_FORWARD_OFFSET = 0.2;
var BUBBLE_SYSTEM_LATERAL_OFFSET = 0.2;
var BUBBLE_SYSTEM_VERTICAL_OFFSET = -0.2;
var BUBBLE_SYSTEM_DIMENSIONS = {
x: TANK_DIMENSIONS.x / 8,
y: TANK_DIMENSIONS.y,
z: TANK_DIMENSIONS.z / 8
}
var BUBBLE_SOUND_URL = "http://hifi-content.s3.amazonaws.com/DomainContent/Home/Sounds/aquarium_small.L.wav";
var bubbleSound = SoundCache.getSound(BUBBLE_SOUND_URL);
@ -109,7 +115,7 @@ function createBubbleSystem() {
};
bubbleProperties.type = "ParticleEffect";
bubbleProperties.collisionless = true;
bubbleProperties.dimensions = BUBBLE_SYSTEM_DIMENSIONS;
var upVector = Quat.getRight(tankProperties.rotation);
var frontVector = Quat.getRight(tankProperties.rotation);
@ -126,13 +132,14 @@ function createBubbleSystem() {
bubbleProperties.position = finalOffset;
bubbleSystem = Entities.addEntity(bubbleProperties);
createBubbleSound(finalOffset);
}
function createBubbleSound() {
var bubbleSystemProperties = Entities.getEntityProperties(bubbleSystem);
function createBubbleSound(position) {
var audioProperties = {
volume: 0.2,
position: position
position: position,
loop: true
};
Audio.playSound(bubbleSound, audioProperties);
@ -145,24 +152,8 @@ function cleanup() {
createFishTank();
// createBubbleSystem();
// createBubbleSound();
// createAttractors();
var attractors = []
//@position,radius,strength
function createAttractor(position, radius, strength) {
return {
position: position,
radius: radius,
strength: strength
};
}
createBubbleSystem();
createBubbleSound();
Script.scriptEnding.connect(cleanup);

View file

@ -18,12 +18,6 @@
blue: 255
}
var NO_INTERSECT_COLOR = {
red: 0,
green: 255,
blue: 0
}
function FishTank() {
_this = this;
}
@ -42,6 +36,7 @@
if (connected === true) {
connected = false;
Script.update.disconnect(_this.update);
_this.clearLookAttractor();
}
//hook up callbacks to the baton
baton.claim(startUpdate, stopUpdateAndReclaim);
@ -51,35 +46,10 @@
FishTank.prototype = {
fish: null,
tankLocked: false,
combinedEntitySearch: function() {
var results = Entities.findEntities(_this.currentProperties.position, TANK_SEARCH_RADIUS);
var attractorList = [];
var fishList = [];
results.forEach(function(entity) {
var properties = Entities.getEntityProperties(entity, 'name');
if (properties.name.indexOf('hifi-fishtank-attractor' + _this.entityID) > -1) {
attractorList.push(entity);
}
if (properties.name.indexOf('hifi-fishtank-fish' + _this.entityID) > -1) {
fishList.push(entity);
}
});
},
findAttractors: function() {
var results = Entities.findEntities(_this.currentProperties.position, TANK_SEARCH_RADIUS);
var attractorList = [];
results.forEach(function(attractor) {
var properties = Entities.getEntityProperties(attractor, 'name');
if (properties.name.indexOf('hifi-fishtank-attractor' + _this.entityID) > -1) {
fishList.push(attractor);
}
})
},
hasLookAttractor: false,
lookAttractor: null,
overlayLine: null,
overlayLineDistance: 3,
findFishInTank: function() {
// print('looking for a fish in the tank')
var results = Entities.findEntities(_this.currentProperties.position, TANK_SEARCH_RADIUS);
@ -146,10 +116,9 @@
}
},
update: function() {
//print('AM I THE OWNER??' + iOwn);
if (iOwn === false) {
//exit if we're not supposed to be simulating the fish
return
}
// print('i am the owner!')
@ -158,11 +127,8 @@
_this.seeIfOwnerIsLookingAtTheTank();
},
overlayLine: null,
overlayLineOn: function(closePoint, farPoint, color) {
print('closePoint: ' + JSON.stringify(closePoint));
print('farPoint: ' + JSON.stringify(farPoint));
if (_this.overlayLine === null) {
var lineProperties = {
lineWidth: 5,
@ -195,7 +161,7 @@
_this.overlayLine = null;
},
overlayLineDistance: 3,
seeIfOwnerIsLookingAtTheTank: function() {
var cameraPosition = Camera.getPosition();
@ -211,10 +177,51 @@
var intersection = Entities.findRayIntersection(pickRay, true, [_this.entityID]);
// print('INTERSCTION::: ' + JSON.stringify(intersection));
if (intersection.intersects && intersection.entityID === _this.entityID) {
print('intersecting a tank')
print('intersection:: ' + JSON.stringify(intersection));
if (_this.hasLookAttractor === false) {
_this.createLookAttractor();
} else if (_this.hasLookAttractor === true) {
_this.updateLookAttractor();
}
} else {
if (_this.hasLookAttractor === true) {
clearLookAttractor();
}
}
},
//look attractors could be private to the tank...
createLookAttractor: function(position) {
_this.lookAttractor = position;
},
updateLookAttractor: function(position) {
_this.lookAttractor = position;
},
clearLookAttractor: function() {
_this.hasLookAttractor = false;
_this.lookAttractor = null;
},
createLookAttractorEntity: function() {
},
findLookAttractorEntities: function() {
},
seeIfAnyoneIsLookingAtTheTank: function() {
// get avatars
// get their positions
// get their gazes
// check for intersection
// add attractor for closest person (?)
var intersection = Entities.findRayIntersection(pickRay, true, [_this.entityID]);
if (intersection.intersects && intersection.entityID === _this.entityID) {
print('intersecting a tank')
print('intersection:: ' + JSON.stringify(intersection));
}
}
@ -250,8 +257,10 @@
var AVOIDANCE_FORCE = 0.3;
var COHESION_FORCE = 0.025;
var ALIGNMENT_FORCE = 0.025;
var LOOK_ATTRACTOR_FORCE = 0.030;
var SWIMMING_FORCE = 0.05;
var SWIMMING_SPEED = 0.5;
var FISH_DAMPING = 0.25;
var THROTTLE = false;
var THROTTLE_RATE = 100;
@ -293,7 +302,6 @@
// print('has userdata fish??' + _this.userData['hifi-home-fishtank'].fishLoaded)
if (_this.userData['hifi-home-fishtank'].fishLoaded === false) {
//no fish in the user data
_this.tankLocked = true;
@ -334,8 +342,6 @@
z: 0
};
var birdPositionsCounted = 0;
var birdVelocitiesCounted = 0;
var center = _this.currentProperties.position;
lowerCorner = {
@ -419,6 +425,12 @@
//attractors
//[position, radius, force]
if (_this.hasLookAttractor === true) {
var attractorPosition = _this.lookAttractor;
var towardAttractor = Vec3.subtract(attractorPosition, position);
velocity = Vec3.mix(velocity, Vec3.multiply(Vec3.normalize(towardAttractor), Vec3.length(velocity)), LOOK_ATTRACTOR_FORCE);
}
}
// Try to swim at a constant speed
@ -519,7 +531,7 @@
// y: SWIMMING_SPEED,
// z: SWIMMING_SPEED
// },
damping: 0.1,
damping: FISH_DAMPING,
dynamic: false,
lifetime: LIFETIME,
color: {