From e5b665cc30334d086991ae86265f004806c9d8cb Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Fri, 17 Oct 2014 09:50:15 -0700 Subject: [PATCH] more Particles to Entities migration --- examples/gun.js | 43 ++++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/examples/gun.js b/examples/gun.js index 6f1371e5d9..385664226c 100644 --- a/examples/gun.js +++ b/examples/gun.js @@ -6,9 +6,9 @@ // Modified by Philip on 3/3/14 // Copyright 2013 High Fidelity, Inc. // -// This is an example script that turns the hydra controllers and mouse into a particle gun. -// It reads the controller, watches for trigger pulls, and launches particles. -// When particles collide with voxels they blow little holes out of the voxels. +// This is an example script that turns the hydra controllers and mouse into a entity gun. +// It reads the controller, watches for trigger pulls, and launches entities. +// When entities collide with voxels they blow little holes out of the voxels. // // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html @@ -96,9 +96,10 @@ function printVector(string, vector) { function shootBullet(position, velocity) { var BULLET_SIZE = 0.01; var BULLET_GRAVITY = -0.02; - Particles.addParticle( - { position: position, - radius: BULLET_SIZE, + Entities.addEntity( + { type: "Sphere", + position: position, + dimensions: { x: BULLET_SIZE, y: BULLET_SIZE, z: BULLET_SIZE }, color: { red: 10, green: 10, blue: 10 }, velocity: velocity, gravity: { x: 0, y: BULLET_GRAVITY, z: 0 }, @@ -131,9 +132,10 @@ function shootTarget() { velocity.y += TARGET_UP_VELOCITY; //printVector("velocity", velocity); - Particles.addParticle( - { position: newPosition, - radius: TARGET_SIZE, + Entities.addEntity( + { type: "Sphere", + position: newPosition, + dimensions: { x: TARGET_SIZE, y: TARGET_SIZE, z: TARGET_SIZE }, color: { red: 0, green: 200, blue: 200 }, velocity: velocity, gravity: { x: 0, y: TARGET_GRAVITY, z: 0 }, @@ -150,11 +152,11 @@ function shootTarget() { -function particleCollisionWithVoxel(particle, voxel, collision) { +function entityCollisionWithVoxel(entity, voxel, collision) { var HOLE_SIZE = 0.125; - var particleProperties = Particles.getParticleProperties(particle); - var position = particleProperties.position; - Particles.deleteParticle(particle); + var entityProperties = Entities.getEntityProperties(entity); + var position = entityProperties.position; + Entities.deleteEntity(entity); // Make a hole in this voxel //Vec3.print("voxel penetration", collision.penetration); //Vec3.print("voxel contactPoint", collision.contactPoint); @@ -163,13 +165,13 @@ function particleCollisionWithVoxel(particle, voxel, collision) { Audio.playSound(impactSound, audioOptions); } -function particleCollisionWithParticle(particle1, particle2, collision) { +function entityCollisionWithEntity(entity1, entity2, collision) { score++; if (showScore) { Overlays.editOverlay(text, { text: "Score: " + score } ); } - // Sort out which particle is which + // Sort out which entity is which // Record shot time var endTime = new Date(); @@ -177,8 +179,8 @@ function particleCollisionWithParticle(particle1, particle2, collision) { //print("hit, msecs = " + msecs); //Vec3.print("penetration = ", collision.penetration); //Vec3.print("contactPoint = ", collision.contactPoint); - Particles.deleteParticle(particle1); - Particles.deleteParticle(particle2); + Entities.deleteEntity(entity1); + Entities.deleteEntity(entity2); // play the sound near the camera so the shooter can hear it audioOptions.position = Vec3.sum(Camera.getPosition(), Quat.getFront(Camera.getOrientation())); Audio.playSound(targetHitSound, audioOptions); @@ -240,7 +242,6 @@ function update(deltaTime) { for (var t = 0; t < numberOfTriggers; t++) { var shootABullet = false; var triggerValue = Controller.getTriggerValue(t); - if (triggerPulled[t]) { // must release to at least 0.1 if (triggerValue < 0.1) { @@ -254,8 +255,8 @@ function update(deltaTime) { } } + if (shootABullet) { - var palmController = t * controllersPerTrigger; var palmPosition = Controller.getSpatialControlPosition(palmController); @@ -324,8 +325,8 @@ function scriptEnding() { MyAvatar.detachOne(gunModel); } -Particles.particleCollisionWithVoxel.connect(particleCollisionWithVoxel); -Particles.particleCollisionWithParticle.connect(particleCollisionWithParticle); +Entities.entityCollisionWithVoxel.connect(entityCollisionWithVoxel); +Entities.entityCollisionWithEntity.connect(entityCollisionWithEntity); Script.scriptEnding.connect(scriptEnding); Script.update.connect(update); Controller.mousePressEvent.connect(mousePressEvent);