From fe759859e7f4426b586eba84a0f1dab13b394641 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Mon, 13 Oct 2014 14:11:20 -0700 Subject: [PATCH] removing particles --- examples/audioBall.js | 51 +++++++++++++++++++++++-------------------- 1 file changed, 27 insertions(+), 24 deletions(-) diff --git a/examples/audioBall.js b/examples/audioBall.js index 76f9aabec8..7e7126be06 100644 --- a/examples/audioBall.js +++ b/examples/audioBall.js @@ -5,8 +5,8 @@ // Created by Athanasios Gaitatzes on 2/10/14. // Copyright 2014 High Fidelity, Inc. // -// This script creates a particle in front of the user that stays in front of -// the user's avatar as they move, and animates it's radius and color +// This script creates a entity in front of the user that stays in front of +// the user's avatar as they move, and animates it's size and color // in response to the audio intensity. // // Distributed under the Apache License, Version 2.0. @@ -18,56 +18,59 @@ Script.include("libraries/globals.js"); var sound = new Sound(HIFI_PUBLIC_BUCKET + "sounds/Animals/mexicanWhipoorwill.raw"); var CHANCE_OF_PLAYING_SOUND = 0.01; -var FACTOR = 0.75; +var FACTOR = 0.05; -var countParticles = 0; // the first time around we want to create the particle and thereafter to modify it. -var particleID; +var countEntities = 0; // the first time around we want to create the entity and thereafter to modify it. +var entityID; -function updateParticle(deltaTime) { - // the particle should be placed in front of the user's avatar +function updateEntity(deltaTime) { + // the entity should be placed in front of the user's avatar var avatarFront = Quat.getFront(MyAvatar.orientation); - // move particle three units in front of the avatar - var particlePosition = Vec3.sum(MyAvatar.position, Vec3.multiply(avatarFront, 3)); + // move entity three units in front of the avatar + var entityPosition = Vec3.sum(MyAvatar.position, Vec3.multiply(avatarFront, 3)); if (Math.random() < CHANCE_OF_PLAYING_SOUND) { - // play a sound at the location of the particle + // play a sound at the location of the entity var options = new AudioInjectionOptions(); - options.position = particlePosition; + options.position = entityPosition; options.volume = 0.75; Audio.playSound(sound, options); } var audioAverageLoudness = MyAvatar.audioAverageLoudness * FACTOR; - //print ("Audio Loudness = " + MyAvatar.audioLoudness + " -- Audio Average Loudness = " + MyAvatar.audioAverageLoudness); + print ("Audio Loudness = " + MyAvatar.audioLoudness + " -- Audio Average Loudness = " + MyAvatar.audioAverageLoudness); - if (countParticles < 1) { - var particleProperies = { - position: particlePosition // the particle should stay in front of the user's avatar as he moves + if (countEntities < 1) { + var entityProperties = { + type: "Sphere", + position: entityPosition // the entity should stay in front of the user's avatar as he moves , color: { red: 0, green: 255, blue: 0 } - , radius: audioAverageLoudness + , dimensions: {x: audioAverageLoudness, y: audioAverageLoudness, z: audioAverageLoudness } , velocity: { x: 0.0, y: 0.0, z: 0.0 } , gravity: { x: 0.0, y: 0.0, z: 0.0 } , damping: 0.0 } - particleID = Particles.addParticle (particleProperies); - countParticles++; + entityID = Entities.addEntity(entityProperties); + countEntities++; } else { - // animates the particles radius and color in response to the changing audio intensity + // animates the particles size and color in response to the changing audio intensity var newProperties = { - position: particlePosition // the particle should stay in front of the user's avatar as he moves + position: entityPosition // the entity should stay in front of the user's avatar as he moves , color: { red: 0, green: 255 * audioAverageLoudness, blue: 0 } - , radius: audioAverageLoudness + , dimensions: {x: audioAverageLoudness, y: audioAverageLoudness, z: audioAverageLoudness } }; - Particles.editParticle (particleID, newProperties); + Entities.editEntity(entityID, newProperties); } } // register the call back so it fires before each data send -Script.update.connect(updateParticle); +Script.update.connect(updateEntity); // register our scriptEnding callback -Script.scriptEnding.connect(function scriptEnding() {}); +Script.scriptEnding.connect(function scriptEnding() { + Entities.deleteEntity(entityID); +});