added comments to example scripts

This commit is contained in:
ZappoMan 2013-12-31 12:24:37 -08:00
parent 8f9a99e1f4
commit 32ec15beb7
2 changed files with 30 additions and 32 deletions

View file

@ -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 = {

View file

@ -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)... '); " +