mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-09 08:36:26 +02:00
Merge branch 'baseball' of github.com:huffman/hifi into baseball
This commit is contained in:
commit
35b13b11eb
2 changed files with 28 additions and 74 deletions
|
@ -2,19 +2,15 @@ Script.include("http://rawgit.com/huffman/hifi/baseball/examples/baseball/utils.
|
||||||
|
|
||||||
var emitters = [];
|
var emitters = [];
|
||||||
|
|
||||||
var currentIdx = 0;
|
|
||||||
var smokeTrailEmitters = [];
|
|
||||||
var burstEmitters = [];
|
|
||||||
|
|
||||||
var smokeTrailSettings = {
|
var smokeTrailSettings = {
|
||||||
"name":"ParticlesTest Emitter",
|
"name":"ParticlesTest Emitter",
|
||||||
"type": "ParticleEffect",
|
"type": "ParticleEffect",
|
||||||
"color":{"red":205,"green":84.41176470588235,"blue":84.41176470588235},
|
"color":{"red":205,"green":84.41176470588235,"blue":84.41176470588235},
|
||||||
"maxParticles":1000,
|
"maxParticles":1000,
|
||||||
"velocity": { x: 0, y: 18.0, z: 0 },
|
"velocity": { x: 0, y: 18.0, z: 0 },
|
||||||
//"lifetime": 20,
|
"lifetime": 20,
|
||||||
"lifespan":3,
|
"lifespan":3,
|
||||||
"emitRate":1000,
|
"emitRate":100,
|
||||||
"emitSpeed":0.5,
|
"emitSpeed":0.5,
|
||||||
"speedSpread":0,
|
"speedSpread":0,
|
||||||
"emitOrientation":{"x":0,"y":0,"z":0,"w":1},
|
"emitOrientation":{"x":0,"y":0,"z":0,"w":1},
|
||||||
|
@ -45,7 +41,7 @@ var fireworkSettings = {
|
||||||
"type": "ParticleEffect",
|
"type": "ParticleEffect",
|
||||||
"color":{"red":205,"green":84.41176470588235,"blue":84.41176470588235},
|
"color":{"red":205,"green":84.41176470588235,"blue":84.41176470588235},
|
||||||
"maxParticles":1000,
|
"maxParticles":1000,
|
||||||
//"lifetime": 20,
|
"lifetime": 20,
|
||||||
"lifespan":4,
|
"lifespan":4,
|
||||||
"emitRate":1000,
|
"emitRate":1000,
|
||||||
"emitSpeed":1.5,
|
"emitSpeed":1.5,
|
||||||
|
@ -79,55 +75,33 @@ var popSounds = getSounds([
|
||||||
"atp:830312930577cb1ea36ba2d743e957debbacceb441b20addead5a6faa05a3771.wav",
|
"atp:830312930577cb1ea36ba2d743e957debbacceb441b20addead5a6faa05a3771.wav",
|
||||||
"atp:62e80d0a9f084cf731bcc66ca6e9020ee88587417071a281eee3167307b53560.wav"
|
"atp:62e80d0a9f084cf731bcc66ca6e9020ee88587417071a281eee3167307b53560.wav"
|
||||||
]);
|
]);
|
||||||
var fireSounds = getSounds([
|
|
||||||
|
var launchSounds = getSounds([
|
||||||
"atp:ee6afe565576c4546c6d6cd89c1af532484c9b60ab30574d6b40c2df022f7260.wav",
|
"atp:ee6afe565576c4546c6d6cd89c1af532484c9b60ab30574d6b40c2df022f7260.wav",
|
||||||
"atp:91ef19ba1c78be82d3fd06530cd05ceb90d1e75f4204c66819c208c55da049ef.wav",
|
"atp:91ef19ba1c78be82d3fd06530cd05ceb90d1e75f4204c66819c208c55da049ef.wav",
|
||||||
"atp:ee56993daf775012cf49293bfd5971eec7e5c396642f8bfbea902ba8f47b56cd.wav",
|
"atp:ee56993daf775012cf49293bfd5971eec7e5c396642f8bfbea902ba8f47b56cd.wav",
|
||||||
"atp:37775d267f00f82242a7e7f61f3f3d7bf64a54c5a3799e7f2540fa5f6b79bd02.wav"
|
"atp:37775d267f00f82242a7e7f61f3f3d7bf64a54c5a3799e7f2540fa5f6b79bd02.wav"
|
||||||
])
|
]);
|
||||||
|
|
||||||
function playRandomSound(sounds, options) {
|
function playRandomSound(sounds, options) {
|
||||||
Audio.playSound(sounds[randomInt(sounds.length)], options);
|
Audio.playSound(sounds[randomInt(sounds.length)], options);
|
||||||
}
|
}
|
||||||
|
|
||||||
function shootFirework(position, color, options) {
|
function shootFirework(position, color, options) {
|
||||||
var updatedSmokeProperties = {
|
|
||||||
position: position,
|
|
||||||
velocity: randomVec3(-5, 5, 10, 20, 10, 15),
|
|
||||||
gravity: randomVec3(-5, 5, -9.8, -9.8, 20, 40),
|
|
||||||
emitRate: 100
|
|
||||||
};
|
|
||||||
|
|
||||||
smokeTrailSettings.position = position;
|
smokeTrailSettings.position = position;
|
||||||
smokeTrailSettings.velocity = randomVec3(-5, 5, 10, 20, 10, 15);
|
smokeTrailSettings.velocity = randomVec3(-5, 5, 10, 20, 10, 15);
|
||||||
smokeTrailSettings.gravity = randomVec3(-5, 5, -9.8, -9.8, 20, 40);
|
smokeTrailSettings.gravity = randomVec3(-5, 5, -9.8, -9.8, 20, 40);
|
||||||
smokeTrailSettings.emitRate = 100;
|
|
||||||
|
|
||||||
|
|
||||||
var idx = currentIdx;
|
playRandomSound(launchSounds, { position: {x: 0, y: 0 , z: 0}, volume: 3.0 });
|
||||||
currentIdx = (currentIdx + 1) % MAX_SIMULTANEOUS_FIREWORKS;
|
|
||||||
|
|
||||||
playRandomSound(fireSounds, { position: {x: 0, y: 0 , z: 0}, volume: 3.0 });
|
|
||||||
//var smokeID = smokeTrailEmitters[idx];
|
|
||||||
//var burstID = burstEmitters[idx];
|
|
||||||
//Entities.editEntity(smokeID, updatedSmokeProperties);
|
|
||||||
var smokeID = Entities.addEntity(smokeTrailSettings);
|
var smokeID = Entities.addEntity(smokeTrailSettings);
|
||||||
|
|
||||||
Script.setTimeout(function() {
|
Script.setTimeout(function() {
|
||||||
Entities.editEntity(smokeID, { emitRate: 0 });
|
Entities.editEntity(smokeID, { emitRate: 0 });
|
||||||
var position = Entities.getEntityProperties(smokeID, ['position']).position;
|
var position = Entities.getEntityProperties(smokeID, ['position']).position;
|
||||||
var updatedBurstProperties = {
|
|
||||||
position: position,
|
|
||||||
colorStart: color,
|
|
||||||
colorFinish: color,
|
|
||||||
emitRate: 1000
|
|
||||||
};
|
|
||||||
fireworkSettings.position = position;
|
fireworkSettings.position = position;
|
||||||
fireworkSettings.colorStart = color;
|
fireworkSettings.colorStart = color;
|
||||||
fireworkSettings.colorFinish = color;
|
fireworkSettings.colorFinish = color;
|
||||||
fireworkSettings.emitRate = 1000;
|
|
||||||
var burstID = Entities.addEntity(fireworkSettings);
|
var burstID = Entities.addEntity(fireworkSettings);
|
||||||
//Entities.editEntity(burstID, updatedBurstProperties);
|
|
||||||
playRandomSound(popSounds, { position: {x: 0, y: 0 , z: 0}, volume: 3.0 });
|
playRandomSound(popSounds, { position: {x: 0, y: 0 , z: 0}, volume: 3.0 });
|
||||||
Script.setTimeout(function() {
|
Script.setTimeout(function() {
|
||||||
Entities.editEntity(burstID, { emitRate: 0 });
|
Entities.editEntity(burstID, { emitRate: 0 });
|
||||||
|
@ -139,9 +113,7 @@ function shootFirework(position, color, options) {
|
||||||
}, 2000);
|
}, 2000);
|
||||||
}
|
}
|
||||||
|
|
||||||
playFireworkShow = function(numberOfFireworks, duration) {
|
playFireworkShow = function(position, numberOfFireworks, duration) {
|
||||||
var position = { x: 0, y: 0, z: -78.0 };
|
|
||||||
|
|
||||||
for (var i = 0; i < numberOfFireworks; i++) {
|
for (var i = 0; i < numberOfFireworks; i++) {
|
||||||
var randomOffset = randomVec3(-15, 15, -3, 3, -1, 1);
|
var randomOffset = randomVec3(-15, 15, -3, 3, -1, 1);
|
||||||
var randomPosition = Vec3.sum(position, randomOffset);
|
var randomPosition = Vec3.sum(position, randomOffset);
|
||||||
|
@ -154,19 +126,4 @@ playFireworkShow = function(numberOfFireworks, duration) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var MAX_SIMULTANEOUS_FIREWORKS = 0;
|
//playFireworkShow(10, 2000);
|
||||||
|
|
||||||
smokeTrailSettings.emitRate = 0;
|
|
||||||
fireworkSettings.emitRate = 0;
|
|
||||||
for (var i = 0; i < MAX_SIMULTANEOUS_FIREWORKS; ++i) {
|
|
||||||
smokeTrailEmitters.push(Entities.addEntity(smokeTrailSettings));
|
|
||||||
burstEmitters.push(Entities.addEntity(fireworkSettings));
|
|
||||||
}
|
|
||||||
Script.scriptEnding.connect(function() {
|
|
||||||
for (var i = 0; i < MAX_SIMULTANEOUS_FIREWORKS; ++i) {
|
|
||||||
Entities.deleteEntity(smokeTrailEmitters[i]);
|
|
||||||
Entities.deleteEntity(burstEmitters[i]);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
//playFireworkShow(30, 2000);
|
|
||||||
|
|
|
@ -3,6 +3,11 @@ print("Loading pitching");
|
||||||
Script.include("https://raw.githubusercontent.com/huffman/hifi/line-js/examples/libraries/line.js");
|
Script.include("https://raw.githubusercontent.com/huffman/hifi/line-js/examples/libraries/line.js");
|
||||||
Script.include("http://rawgit.com/huffman/hifi/baseball/examples/baseball/firework.js");
|
Script.include("http://rawgit.com/huffman/hifi/baseball/examples/baseball/firework.js");
|
||||||
|
|
||||||
|
function findEntity(properties, searchRadius) {
|
||||||
|
var entities = findEntities(properties, searchRadius);
|
||||||
|
return entities.length > 0 ? entities[0] : null;
|
||||||
|
}
|
||||||
|
|
||||||
// Return all entities with properties `properties` within radius `searchRadius`
|
// Return all entities with properties `properties` within radius `searchRadius`
|
||||||
function findEntities(properties, searchRadius) {
|
function findEntities(properties, searchRadius) {
|
||||||
var entities = Entities.findEntities(MyAvatar.position, searchRadius);
|
var entities = Entities.findEntities(MyAvatar.position, searchRadius);
|
||||||
|
@ -26,11 +31,11 @@ function findEntities(properties, searchRadius) {
|
||||||
return matchedEntities;
|
return matchedEntities;
|
||||||
}
|
}
|
||||||
|
|
||||||
// These are hard-coded to the relevant entity IDs on the sport server
|
|
||||||
var DISTANCE_BILLBOARD_NAME = "CurrentScore";
|
var DISTANCE_BILLBOARD_NAME = "CurrentScore";
|
||||||
var HIGH_SCORE_BILLBOARD_NAME = "HighScore";
|
var HIGH_SCORE_BILLBOARD_NAME = "HighScore";
|
||||||
var DISTANCE_BILLBOARD_ENTITY_ID = findEntities({name: DISTANCE_BILLBOARD_NAME }, 1000)[0];
|
var DISTANCE_BILLBOARD_ENTITY_ID = findEntity({name: DISTANCE_BILLBOARD_NAME }, 1000);
|
||||||
var HIGH_SCORE_BILLBOARD_ENTITY_ID = findEntities({name: HIGH_SCORE_BILLBOARD_NAME }, 1000)[0];
|
var HIGH_SCORE_BILLBOARD_ENTITY_ID = findEntity({name: HIGH_SCORE_BILLBOARD_NAME }, 1000);
|
||||||
|
|
||||||
print("Distance: ", DISTANCE_BILLBOARD_ENTITY_ID)
|
print("Distance: ", DISTANCE_BILLBOARD_ENTITY_ID)
|
||||||
|
|
||||||
var METERS_TO_FEET = 3.28084;
|
var METERS_TO_FEET = 3.28084;
|
||||||
|
@ -63,6 +68,7 @@ var AUDIO = {
|
||||||
|
|
||||||
var PITCH_THUNK_SOUND_URL = "http://hifi-public.s3.amazonaws.com/sounds/ping_pong_gun/pong_sound.wav";
|
var PITCH_THUNK_SOUND_URL = "http://hifi-public.s3.amazonaws.com/sounds/ping_pong_gun/pong_sound.wav";
|
||||||
var pitchSound = SoundCache.getSound(PITCH_THUNK_SOUND_URL, false);
|
var pitchSound = SoundCache.getSound(PITCH_THUNK_SOUND_URL, false);
|
||||||
|
updateBillboard("");
|
||||||
|
|
||||||
var PITCHING_MACHINE_URL = "atp:87d4879530b698741ecc45f6f31789aac11f7865a2c3bec5fe9b061a182c80d4.fbx";
|
var PITCHING_MACHINE_URL = "atp:87d4879530b698741ecc45f6f31789aac11f7865a2c3bec5fe9b061a182c80d4.fbx";
|
||||||
var PITCHING_MACHINE_OUTPUT_OFFSET_PCT = {
|
var PITCHING_MACHINE_OUTPUT_OFFSET_PCT = {
|
||||||
|
@ -142,22 +148,17 @@ PitchingMachine.prototype = {
|
||||||
print("Pitching ball");
|
print("Pitching ball");
|
||||||
var pitchDirection = { x: 0, y: 0, z: 1 };
|
var pitchDirection = { x: 0, y: 0, z: 1 };
|
||||||
var machineProperties = Entities.getEntityProperties(this.pitchingMachineID, ["dimensions", "position", "rotation"]);
|
var machineProperties = Entities.getEntityProperties(this.pitchingMachineID, ["dimensions", "position", "rotation"]);
|
||||||
//print("PROPS");
|
|
||||||
//print("props ", JSON.stringify(machineProperties));
|
|
||||||
var pitchFromPositionBase = machineProperties.position;
|
var pitchFromPositionBase = machineProperties.position;
|
||||||
var pitchFromOffset = vec3Mult(machineProperties.dimensions, PITCHING_MACHINE_OUTPUT_OFFSET_PCT);
|
var pitchFromOffset = vec3Mult(machineProperties.dimensions, PITCHING_MACHINE_OUTPUT_OFFSET_PCT);
|
||||||
pitchFromOffset = Vec3.multiplyQbyV(machineProperties.rotation, pitchFromOffset);
|
pitchFromOffset = Vec3.multiplyQbyV(machineProperties.rotation, pitchFromOffset);
|
||||||
var pitchFromPosition = Vec3.sum(pitchFromPositionBase, pitchFromOffset);
|
var pitchFromPosition = Vec3.sum(pitchFromPositionBase, pitchFromOffset);
|
||||||
var pitchDirection = Quat.getFront(machineProperties.rotation);
|
var pitchDirection = Quat.getFront(machineProperties.rotation);
|
||||||
var ballScale = machineProperties.dimensions.x / PITCHING_MACHINE_PROPERTIES.dimensions.x;
|
var ballScale = machineProperties.dimensions.x / PITCHING_MACHINE_PROPERTIES.dimensions.x;
|
||||||
print("Creating baseball");
|
|
||||||
|
|
||||||
var speed = randomFloat(BASEBALL_MIN_SPEED, BASEBALL_MAX_SPEED);
|
var speed = randomFloat(BASEBALL_MIN_SPEED, BASEBALL_MAX_SPEED);
|
||||||
var velocity = Vec3.multiply(speed, pitchDirection);
|
var velocity = Vec3.multiply(speed, pitchDirection);
|
||||||
|
|
||||||
this.baseball = new Baseball(pitchFromPosition, velocity, ballScale);
|
this.baseball = new Baseball(pitchFromPosition, velocity, ballScale);
|
||||||
Vec3.print("vel", velocity);
|
|
||||||
Vec3.print("pos", pitchFromPosition);
|
|
||||||
|
|
||||||
if (!this.injector) {
|
if (!this.injector) {
|
||||||
this.injector = Audio.playSound(pitchSound, {
|
this.injector = Audio.playSound(pitchSound, {
|
||||||
|
@ -188,7 +189,6 @@ PitchingMachine.prototype = {
|
||||||
if (this.baseball) {
|
if (this.baseball) {
|
||||||
this.baseball.update(dt);
|
this.baseball.update(dt);
|
||||||
if (this.baseball.finished()) {
|
if (this.baseball.finished()) {
|
||||||
print("BALL IS FINISHED");
|
|
||||||
this.baseball = null;
|
this.baseball = null;
|
||||||
var self = this;
|
var self = this;
|
||||||
Script.setTimeout(function() { self.pitchBall() }, 3000);
|
Script.setTimeout(function() { self.pitchBall() }, 3000);
|
||||||
|
@ -311,7 +311,6 @@ function ObjectTrail(entityID, startPosition) {
|
||||||
this.line = null;
|
this.line = null;
|
||||||
var lineInterval = null;
|
var lineInterval = null;
|
||||||
|
|
||||||
print("Creating Trail!");
|
|
||||||
var lastPosition = startPosition;
|
var lastPosition = startPosition;
|
||||||
trail = new InfiniteLine(startPosition, trailColor, trailLifetime);
|
trail = new InfiniteLine(startPosition, trailColor, trailLifetime);
|
||||||
trailInterval = Script.setInterval(function() {
|
trailInterval = Script.setInterval(function() {
|
||||||
|
@ -351,7 +350,6 @@ function cleanupTrail() {
|
||||||
function setupTrail(entityID, position) {
|
function setupTrail(entityID, position) {
|
||||||
cleanupTrail();
|
cleanupTrail();
|
||||||
|
|
||||||
print("Creating Trail!");
|
|
||||||
var lastPosition = position;
|
var lastPosition = position;
|
||||||
trail = new InfiniteLine(position, { red: 128, green: 255, blue: 89 }, 20);
|
trail = new InfiniteLine(position, { red: 128, green: 255, blue: 89 }, 20);
|
||||||
trailInterval = Script.setInterval(function() {
|
trailInterval = Script.setInterval(function() {
|
||||||
|
@ -433,7 +431,9 @@ function updateBillboard(distance) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
var FIREWORK_SHOW_DISTANCE_FEET = 2;
|
var FIREWORKS_SHOW_POSITION = { x: 0, y: 0, z: -78.0 };
|
||||||
|
var FIREWORK_PER_X_FEET = 100;
|
||||||
|
var MAX_FIREWORKS = 10;
|
||||||
|
|
||||||
Baseball.prototype = {
|
Baseball.prototype = {
|
||||||
finished: function() {
|
finished: function() {
|
||||||
|
@ -462,11 +462,10 @@ Baseball.prototype = {
|
||||||
},
|
},
|
||||||
ballLanded: function() {
|
ballLanded: function() {
|
||||||
this.state = BASEBALL_STATE.HIT_LANDED;
|
this.state = BASEBALL_STATE.HIT_LANDED;
|
||||||
if (this.distanceTravelled > FIREWORK_SHOW_DISTANCE_FEET) {
|
var numberOfFireworks = Math.floor(this.distanceTravelled / FIREWORK_PER_X_FEET);
|
||||||
print("PLAYING SHOW")
|
if (numberOfFireworks > 0) {
|
||||||
var numberOfFireworks = Math.floor(this.distanceTravelled / 200);
|
numberOfFireworks = Math.min(MAX_FIREWORKS, numberOfFireworks);
|
||||||
numberOfFireworks = Math.min(10, numberOfFireworks);
|
playFireworkShow(FIREWORKS_SHOW_POSITION, numberOfFireworks, 2000);
|
||||||
playFireworkShow(numberOfFireworks, 2000);
|
|
||||||
}
|
}
|
||||||
print("Ball took " + this.timeSinceHit.toFixed(3) + " seconds to land");
|
print("Ball took " + this.timeSinceHit.toFixed(3) + " seconds to land");
|
||||||
print("Ball travelled " + this.distanceTravelled + " feet")
|
print("Ball travelled " + this.distanceTravelled + " feet")
|
||||||
|
@ -483,7 +482,6 @@ Baseball.prototype = {
|
||||||
});
|
});
|
||||||
|
|
||||||
var name = Entities.getEntityProperties(entityB, ["name"]).name;
|
var name = Entities.getEntityProperties(entityB, ["name"]).name;
|
||||||
print("Hit: " + name);
|
|
||||||
if (name == "Bat") {
|
if (name == "Bat") {
|
||||||
if (this.state == BASEBALL_STATE.PITCHING) {
|
if (this.state == BASEBALL_STATE.PITCHING) {
|
||||||
print("HIT");
|
print("HIT");
|
||||||
|
@ -528,9 +526,10 @@ Baseball.prototype = {
|
||||||
volume: 1.0
|
volume: 1.0
|
||||||
});
|
});
|
||||||
}, 500);
|
}, 500);
|
||||||
|
|
||||||
if (foul) {
|
if (foul) {
|
||||||
|
print("FOUL, yaw: ", yaw);
|
||||||
updateBillboard("FOUL");
|
updateBillboard("FOUL");
|
||||||
print("FOUL ", yaw)
|
|
||||||
this.state = BASEBALL_STATE.FOUL;
|
this.state = BASEBALL_STATE.FOUL;
|
||||||
playRandomSound(AUDIO.foul, {
|
playRandomSound(AUDIO.foul, {
|
||||||
position: myPosition,
|
position: myPosition,
|
||||||
|
@ -542,14 +541,13 @@ Baseball.prototype = {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (name == "stadium") {
|
} else if (name == "stadium") {
|
||||||
//iprint("PARTICLES");
|
|
||||||
//entityCollisionWithGround(entityB, this.entityID, collision);
|
//entityCollisionWithGround(entityB, this.entityID, collision);
|
||||||
this.landed = true;
|
this.landed = true;
|
||||||
} else if (name == "backstop") {
|
} else if (name == "backstop") {
|
||||||
if (this.state == BASEBALL_STATE.PITCHING) {
|
if (this.state == BASEBALL_STATE.PITCHING) {
|
||||||
|
print("STRIKE");
|
||||||
this.state = BASEBALL_STATE.STRIKE;
|
this.state = BASEBALL_STATE.STRIKE;
|
||||||
updateBillboard("STRIKE");
|
updateBillboard("STRIKE");
|
||||||
print("STRIKE");
|
|
||||||
playRandomSound(AUDIO.strike, {
|
playRandomSound(AUDIO.strike, {
|
||||||
position: myPosition,
|
position: myPosition,
|
||||||
volume: 2.0
|
volume: 2.0
|
||||||
|
@ -565,7 +563,6 @@ function update(dt) {
|
||||||
if (baseball) {
|
if (baseball) {
|
||||||
baseball.update(dt);
|
baseball.update(dt);
|
||||||
if (baseball.finished()) {
|
if (baseball.finished()) {
|
||||||
print("BALL IS FINSIEHD");
|
|
||||||
baseball = null;
|
baseball = null;
|
||||||
Script.setTimeout(pitchBall, 3000);
|
Script.setTimeout(pitchBall, 3000);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue