mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-10 02:42:52 +02:00
fish swim to where youre looking
This commit is contained in:
parent
42ec6de512
commit
ba2e977968
2 changed files with 71 additions and 68 deletions
|
@ -27,6 +27,12 @@ var BUBBLE_SYSTEM_FORWARD_OFFSET = 0.2;
|
||||||
var BUBBLE_SYSTEM_LATERAL_OFFSET = 0.2;
|
var BUBBLE_SYSTEM_LATERAL_OFFSET = 0.2;
|
||||||
var BUBBLE_SYSTEM_VERTICAL_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 BUBBLE_SOUND_URL = "http://hifi-content.s3.amazonaws.com/DomainContent/Home/Sounds/aquarium_small.L.wav";
|
||||||
var bubbleSound = SoundCache.getSound(BUBBLE_SOUND_URL);
|
var bubbleSound = SoundCache.getSound(BUBBLE_SOUND_URL);
|
||||||
|
|
||||||
|
@ -109,7 +115,7 @@ function createBubbleSystem() {
|
||||||
};
|
};
|
||||||
|
|
||||||
bubbleProperties.type = "ParticleEffect";
|
bubbleProperties.type = "ParticleEffect";
|
||||||
bubbleProperties.collisionless = true;
|
bubbleProperties.dimensions = BUBBLE_SYSTEM_DIMENSIONS;
|
||||||
|
|
||||||
var upVector = Quat.getRight(tankProperties.rotation);
|
var upVector = Quat.getRight(tankProperties.rotation);
|
||||||
var frontVector = Quat.getRight(tankProperties.rotation);
|
var frontVector = Quat.getRight(tankProperties.rotation);
|
||||||
|
@ -126,13 +132,14 @@ function createBubbleSystem() {
|
||||||
bubbleProperties.position = finalOffset;
|
bubbleProperties.position = finalOffset;
|
||||||
|
|
||||||
bubbleSystem = Entities.addEntity(bubbleProperties);
|
bubbleSystem = Entities.addEntity(bubbleProperties);
|
||||||
|
createBubbleSound(finalOffset);
|
||||||
}
|
}
|
||||||
|
|
||||||
function createBubbleSound() {
|
function createBubbleSound(position) {
|
||||||
var bubbleSystemProperties = Entities.getEntityProperties(bubbleSystem);
|
|
||||||
var audioProperties = {
|
var audioProperties = {
|
||||||
volume: 0.2,
|
volume: 0.2,
|
||||||
position: position
|
position: position,
|
||||||
|
loop: true
|
||||||
};
|
};
|
||||||
|
|
||||||
Audio.playSound(bubbleSound, audioProperties);
|
Audio.playSound(bubbleSound, audioProperties);
|
||||||
|
@ -145,24 +152,8 @@ function cleanup() {
|
||||||
|
|
||||||
createFishTank();
|
createFishTank();
|
||||||
|
|
||||||
// createBubbleSystem();
|
createBubbleSystem();
|
||||||
|
|
||||||
// createBubbleSound();
|
|
||||||
|
|
||||||
// createAttractors();
|
|
||||||
|
|
||||||
var attractors = []
|
|
||||||
//@position,radius,strength
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function createAttractor(position, radius, strength) {
|
|
||||||
return {
|
|
||||||
position: position,
|
|
||||||
radius: radius,
|
|
||||||
strength: strength
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
|
createBubbleSound();
|
||||||
|
|
||||||
Script.scriptEnding.connect(cleanup);
|
Script.scriptEnding.connect(cleanup);
|
|
@ -18,12 +18,6 @@
|
||||||
blue: 255
|
blue: 255
|
||||||
}
|
}
|
||||||
|
|
||||||
var NO_INTERSECT_COLOR = {
|
|
||||||
red: 0,
|
|
||||||
green: 255,
|
|
||||||
blue: 0
|
|
||||||
}
|
|
||||||
|
|
||||||
function FishTank() {
|
function FishTank() {
|
||||||
_this = this;
|
_this = this;
|
||||||
}
|
}
|
||||||
|
@ -42,6 +36,7 @@
|
||||||
if (connected === true) {
|
if (connected === true) {
|
||||||
connected = false;
|
connected = false;
|
||||||
Script.update.disconnect(_this.update);
|
Script.update.disconnect(_this.update);
|
||||||
|
_this.clearLookAttractor();
|
||||||
}
|
}
|
||||||
//hook up callbacks to the baton
|
//hook up callbacks to the baton
|
||||||
baton.claim(startUpdate, stopUpdateAndReclaim);
|
baton.claim(startUpdate, stopUpdateAndReclaim);
|
||||||
|
@ -51,35 +46,10 @@
|
||||||
FishTank.prototype = {
|
FishTank.prototype = {
|
||||||
fish: null,
|
fish: null,
|
||||||
tankLocked: false,
|
tankLocked: false,
|
||||||
|
hasLookAttractor: false,
|
||||||
combinedEntitySearch: function() {
|
lookAttractor: null,
|
||||||
var results = Entities.findEntities(_this.currentProperties.position, TANK_SEARCH_RADIUS);
|
overlayLine: null,
|
||||||
var attractorList = [];
|
overlayLineDistance: 3,
|
||||||
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);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
},
|
|
||||||
|
|
||||||
findFishInTank: function() {
|
findFishInTank: function() {
|
||||||
// print('looking for a fish in the tank')
|
// print('looking for a fish in the tank')
|
||||||
var results = Entities.findEntities(_this.currentProperties.position, TANK_SEARCH_RADIUS);
|
var results = Entities.findEntities(_this.currentProperties.position, TANK_SEARCH_RADIUS);
|
||||||
|
@ -146,10 +116,9 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
update: function() {
|
update: function() {
|
||||||
//print('AM I THE OWNER??' + iOwn);
|
|
||||||
if (iOwn === false) {
|
if (iOwn === false) {
|
||||||
|
//exit if we're not supposed to be simulating the fish
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// print('i am the owner!')
|
// print('i am the owner!')
|
||||||
|
@ -158,11 +127,8 @@
|
||||||
_this.seeIfOwnerIsLookingAtTheTank();
|
_this.seeIfOwnerIsLookingAtTheTank();
|
||||||
},
|
},
|
||||||
|
|
||||||
overlayLine: null,
|
|
||||||
|
|
||||||
overlayLineOn: function(closePoint, farPoint, color) {
|
overlayLineOn: function(closePoint, farPoint, color) {
|
||||||
print('closePoint: ' + JSON.stringify(closePoint));
|
|
||||||
print('farPoint: ' + JSON.stringify(farPoint));
|
|
||||||
if (_this.overlayLine === null) {
|
if (_this.overlayLine === null) {
|
||||||
var lineProperties = {
|
var lineProperties = {
|
||||||
lineWidth: 5,
|
lineWidth: 5,
|
||||||
|
@ -195,7 +161,7 @@
|
||||||
_this.overlayLine = null;
|
_this.overlayLine = null;
|
||||||
},
|
},
|
||||||
|
|
||||||
overlayLineDistance: 3,
|
|
||||||
|
|
||||||
seeIfOwnerIsLookingAtTheTank: function() {
|
seeIfOwnerIsLookingAtTheTank: function() {
|
||||||
var cameraPosition = Camera.getPosition();
|
var cameraPosition = Camera.getPosition();
|
||||||
|
@ -211,10 +177,51 @@
|
||||||
|
|
||||||
var intersection = Entities.findRayIntersection(pickRay, true, [_this.entityID]);
|
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) {
|
if (intersection.intersects && intersection.entityID === _this.entityID) {
|
||||||
print('intersecting a tank')
|
print('intersecting a tank')
|
||||||
|
|
||||||
|
print('intersection:: ' + JSON.stringify(intersection));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -250,8 +257,10 @@
|
||||||
var AVOIDANCE_FORCE = 0.3;
|
var AVOIDANCE_FORCE = 0.3;
|
||||||
var COHESION_FORCE = 0.025;
|
var COHESION_FORCE = 0.025;
|
||||||
var ALIGNMENT_FORCE = 0.025;
|
var ALIGNMENT_FORCE = 0.025;
|
||||||
|
var LOOK_ATTRACTOR_FORCE = 0.030;
|
||||||
var SWIMMING_FORCE = 0.05;
|
var SWIMMING_FORCE = 0.05;
|
||||||
var SWIMMING_SPEED = 0.5;
|
var SWIMMING_SPEED = 0.5;
|
||||||
|
var FISH_DAMPING = 0.25;
|
||||||
|
|
||||||
var THROTTLE = false;
|
var THROTTLE = false;
|
||||||
var THROTTLE_RATE = 100;
|
var THROTTLE_RATE = 100;
|
||||||
|
@ -293,7 +302,6 @@
|
||||||
|
|
||||||
// print('has userdata fish??' + _this.userData['hifi-home-fishtank'].fishLoaded)
|
// print('has userdata fish??' + _this.userData['hifi-home-fishtank'].fishLoaded)
|
||||||
|
|
||||||
|
|
||||||
if (_this.userData['hifi-home-fishtank'].fishLoaded === false) {
|
if (_this.userData['hifi-home-fishtank'].fishLoaded === false) {
|
||||||
//no fish in the user data
|
//no fish in the user data
|
||||||
_this.tankLocked = true;
|
_this.tankLocked = true;
|
||||||
|
@ -334,8 +342,6 @@
|
||||||
z: 0
|
z: 0
|
||||||
};
|
};
|
||||||
|
|
||||||
var birdPositionsCounted = 0;
|
|
||||||
var birdVelocitiesCounted = 0;
|
|
||||||
var center = _this.currentProperties.position;
|
var center = _this.currentProperties.position;
|
||||||
|
|
||||||
lowerCorner = {
|
lowerCorner = {
|
||||||
|
@ -419,6 +425,12 @@
|
||||||
//attractors
|
//attractors
|
||||||
//[position, radius, force]
|
//[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
|
// Try to swim at a constant speed
|
||||||
|
@ -519,7 +531,7 @@
|
||||||
// y: SWIMMING_SPEED,
|
// y: SWIMMING_SPEED,
|
||||||
// z: SWIMMING_SPEED
|
// z: SWIMMING_SPEED
|
||||||
// },
|
// },
|
||||||
damping: 0.1,
|
damping: FISH_DAMPING,
|
||||||
dynamic: false,
|
dynamic: false,
|
||||||
lifetime: LIFETIME,
|
lifetime: LIFETIME,
|
||||||
color: {
|
color: {
|
||||||
|
|
Loading…
Reference in a new issue