From 32ec15beb7fc88295722212dc40628c164b8b92c Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Tue, 31 Dec 2013 12:24:37 -0800 Subject: [PATCH] added comments to example scripts --- examples/collidingParticles.js | 42 +++++++++++----------------------- examples/gun.js | 20 +++++++++++++--- 2 files changed, 30 insertions(+), 32 deletions(-) diff --git a/examples/collidingParticles.js b/examples/collidingParticles.js index 641dd1a4ec..f53933871f 100644 --- a/examples/collidingParticles.js +++ b/examples/collidingParticles.js @@ -1,3 +1,16 @@ +// +// collidingParticles.js +// hifi +// +// Created by Brad Hefta-Gaub on 12/31/13. +// Copyright (c) 2013 HighFidelity, Inc. All rights reserved. +// +// This is an example script that creates a couple particles, and sends them on a collision course. +// One of the particles has a script that when it collides with another particle, it swaps colors with that particle. +// The other particle has a script that when it collides with another particle it set's it's script to a suicide script. +// +// + var currentIteration = 0; var NUM_ITERATIONS_BEFORE_SEND = 15; // every 1/4th seconds send another @@ -17,11 +30,6 @@ var gravity = { var damping = 0.1; var scriptA = " " + - //" function update() { " + - //" print('update()\\n'); " + - //" var color = { red: 255, green: 127 + (Math.random() * 128), blue: 0 };" + - //" Particle.setColor(color); " + - //" } " + " function collisionWithParticle(other) { " + " print('collisionWithParticle(other.getID()=' + other.getID() + ')...'); " + " print('myID=' + Particle.getID() + '\\n'); " + @@ -33,40 +41,16 @@ var scriptA = " " + " Particle.setColor(otherColor); " + " other.setColor(myColor); " + " } " + - " function collisionWithVoxel(voxel) { " + - " print('collisionWithVoxel(voxel)... '); " + - " print('myID=' + Particle.getID() + '\\n'); " + - " var voxelColor = voxel.getColor();" + - " print('voxelColor=' + voxelColor.red + ', ' + voxelColor.green + ', ' + voxelColor.blue + '\\n'); " + - " var myColor = Particle.getColor();" + - " print('myColor=' + myColor.red + ', ' + myColor.green + ', ' + myColor.blue + '\\n'); " + - " Particle.setColor(voxelColor); " + - " } " + " Particle.collisionWithParticle.connect(collisionWithParticle); " + - " Particle.collisionWithVoxel.connect(collisionWithVoxel); " + " "; var scriptB = " " + " function collisionWithParticle(other) { " + " print('collisionWithParticle(other.getID()=' + other.getID() + ')...'); " + " print('myID=' + Particle.getID() + '\\n'); " + - " var myPosition = Particle.getPosition();" + - " var myRadius = Particle.getRadius();" + - " var myColor = Particle.getColor();" + - " Voxels.queueDestructiveVoxelAdd(myPosition.x, myPosition.y, myPosition.z, myRadius, myColor.red, myColor.green, myColor.blue); " + " Particle.setScript('Particle.setShouldDie(true);'); " + " } " + - " function collisionWithVoxel(voxel) { " + - " print('collisionWithVoxel(voxel)... '); " + - " print('myID=' + Particle.getID() + '\\n'); " + - " var voxelColor = voxel.getColor();" + - " print('voxelColor=' + voxelColor.red + ', ' + voxelColor.green + ', ' + voxelColor.blue + '\\n'); " + - " var myColor = Particle.getColor();" + - " print('myColor=' + myColor.red + ', ' + myColor.green + ', ' + myColor.blue + '\\n'); " + - " Particle.setColor(voxelColor); " + - " } " + " Particle.collisionWithParticle.connect(collisionWithParticle); " + - " Particle.collisionWithVoxel.connect(collisionWithVoxel); " + " "; var color = { diff --git a/examples/gun.js b/examples/gun.js index f4e6e04ea9..e9b1472700 100644 --- a/examples/gun.js +++ b/examples/gun.js @@ -1,3 +1,18 @@ +// +// gun.js +// hifi +// +// Created by Brad Hefta-Gaub on 12/31/13. +// Copyright (c) 2013 HighFidelity, Inc. All rights reserved. +// +// This is an example script that turns the hydra controllers into a particle gun. +// It reads the controller, watches for trigger pulls, and launches particles. +// The particles it creates have a script that when they collide with Voxels, the +// particle will change it's color to match the voxel it hits, and then delete the +// voxel. +// +// + // initialize our triggers var triggerPulled = new Array(); var numberOfTriggers = Controller.getNumberOfTriggers(); @@ -9,9 +24,6 @@ function checkController() { var numberOfTriggers = Controller.getNumberOfTriggers(); var numberOfSpatialControls = Controller.getNumberOfSpatialControls(); var controllersPerTrigger = numberOfSpatialControls / numberOfTriggers; - //print("numberOfTriggers:" + numberOfTriggers + "\n"); - //print("numberOfSpatialControls:" + numberOfSpatialControls + "\n"); - //print("controllersPerTrigger:" + controllersPerTrigger + "\n"); // this is expected for hydras if (numberOfTriggers == 2 && controllersPerTrigger == 2) { @@ -71,6 +83,8 @@ function checkController() { var color = { red: 128, green: 128, blue: 128 }; var damping = 0; // no damping var inHand = false; + + // This is the script for the particles that this gun shoots. var script = " function collisionWithVoxel(voxel) { " + " print('collisionWithVoxel(voxel)... '); " +