-
-
Save mattsonic/df194e780d011706dc8b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var createSound = new Sound("http://highfidelity-public.s3-us-west-1.amazonaws.com/sounds/Space%20Invaders/hit.raw"); | |
var audioOptions = new AudioInjectionOptions(); | |
audioOptions.volume = 0.9; | |
var particleIds = []; | |
var startTime = new Date(); | |
var interval = 50.0; | |
var lastUpdate = new Date(); | |
var spawnTime = 0; | |
var spawnDelay = 1000.0; | |
function update() { | |
// update loop | |
var current = new Date(); | |
if (current.valueOf() < lastUpdate.valueOf() + interval) { | |
// only update at a given interval | |
return; | |
} | |
if (spawnTime.valueOf() == 0 || current.valueOf() < spawnTime.valueOf() + spawnDelay) { | |
// don't update until particles are ready | |
return; | |
} | |
lastUpdate = current; | |
var t = (current.valueOf() - spawnTime.valueOf()) * 0.005; | |
for (var i = 0; i < particleIds.length; i++) { | |
var pId = particleIds[i]; | |
if (Particles.identifyParticle(pId)) { | |
var prop = Particles.getParticleProperties(pId); | |
prop.color = { red: (Math.sin(t * i * 0.011) + 1) * 100.0, | |
green: (Math.sin(t * i * 0.01) + 1) * 100.0, | |
blue: (Math.sin(t * i * 0.0009) + 1) * 100.0 | |
}; | |
var d = 0.02; | |
var delta = { x: Math.sin(t * i * 0.1) * d, | |
y: Math.sin(t * i * 0.2) * d, | |
z: Math.sin(t * i * 0.3) * d | |
}; | |
prop.position = Vec3.sum(prop.position, delta); | |
Particles.editParticle(pId, prop); | |
} | |
} | |
print("updated: " + lastUpdate.valueOf()); | |
} | |
function keyPressEvent(event) { | |
if (event.text != "o") { | |
return; | |
} | |
// create particles | |
print("create particles now"); | |
particles = []; | |
var cameraPos = Camera.getPosition(); | |
audioOptions.position = cameraPos; | |
Audio.playSound(createSound, audioOptions); | |
var targetDir = Quat.angleAxis(0, { x: 0, y: 1, z: 0 }); | |
targetDir = Quat.multiply(Camera.getOrientation(), targetDir); | |
var forwardVector = Quat.getFront(targetDir); | |
var distanceFromYou = 10.0; | |
var startPos = Vec3.sum(cameraPos, Vec3.multiply(forwardVector, distanceFromYou)); | |
var r = 0.4; | |
var s = 3; | |
var dist = 2.0; | |
for (var x = 0; x < s; x++) { | |
for (var y = 0; y < s; y++) { | |
for (var z = 0; z < s; z++) { | |
var pos = { x: x*dist, y: y*dist, z: z*dist }; | |
var worldPos = Vec3.sum(startPos, pos); | |
var pId = Particles.addParticle({ | |
position: worldPos, | |
radius: r, | |
color: { red: 0, green: 100, blue: 100 }, | |
velocity: 0, | |
gravity: { x: 0, y: 0, z: 0 }, | |
lifetime: 10.0, | |
damping: 0 | |
}); | |
particleIds.push(pId); | |
} | |
} | |
} | |
spawnTime = new Date(); | |
} | |
Controller.keyPressEvent.connect(keyPressEvent); | |
Script.update.connect(update); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment