formatting fixes

This commit is contained in:
ZappoMan 2014-09-03 19:46:33 -07:00
parent be7a03b97e
commit 68d2be97f7
2 changed files with 8 additions and 25 deletions

View file

@ -3,9 +3,10 @@
// //
// //
// Created by Adrian McCarlie on August 2, 2014 // Created by Adrian McCarlie on August 2, 2014
// Modified by Brad Hefta-Gaub to use Entities on Sept. 3, 2014
// Copyright 2014 High Fidelity, Inc. // Copyright 2014 High Fidelity, Inc.
// //
// This sample script creates a swarm of butterfly Entities that fly around the avatar. // This sample script creates a swarm of butterfly entities that fly around the avatar.
// //
// Distributed under the Apache License, Version 2.0. // Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
@ -17,7 +18,6 @@ function getRandomFloat(min, max) {
} }
// Multiply vector by scalar // Multiply vector by scalar
function vScalarMult(v, s) { function vScalarMult(v, s) {
var rval = { x: v.x * s, y: v.y * s, z: v.z * s }; var rval = { x: v.x * s, y: v.y * s, z: v.z * s };
return rval; return rval;
@ -56,7 +56,7 @@ var roll = 0.0; //experimental
var rotation = Quat.fromPitchYawRollDegrees(pitch, yaw, roll);//experimental var rotation = Quat.fromPitchYawRollDegrees(pitch, yaw, roll);//experimental
// This is our butterfly object // This is our butterfly object
function defineButterfly (entityID, targetPosition ) { function defineButterfly(entityID, targetPosition) {
this.entityID = entityID; this.entityID = entityID;
this.previousFlapOffset = 0; this.previousFlapOffset = 0;
this.targetPosition = targetPosition; this.targetPosition = targetPosition;
@ -66,7 +66,7 @@ function defineButterfly (entityID, targetPosition ) {
// Array of butterflies // Array of butterflies
var butterflies = []; var butterflies = [];
var numButterflies = 20; var numButterflies = 20;
function addButterfly( ){ function addButterfly() {
// Decide the size of butterfly // Decide the size of butterfly
var color = { red: 100, green: 100, blue: 100 }; var color = { red: 100, green: 100, blue: 100 };
var size = 0; var size = 0;
@ -102,29 +102,22 @@ function addButterfly( ){
//animationURL: "http://business.ozblog.me/objects/butterfly/newButterfly6.fbx", //animationURL: "http://business.ozblog.me/objects/butterfly/newButterfly6.fbx",
//animationIsPlaying: true, //animationIsPlaying: true,
modelURL: "http://business.ozblog.me/objects/butterfly/newButterfly6.fbx" modelURL: "http://business.ozblog.me/objects/butterfly/newButterfly6.fbx"
}; };
properties.position.z = properties.position.z+1; properties.position.z = properties.position.z+1;
butterflies.push(new defineButterfly(Entities.addEntity(properties), properties.position)); butterflies.push(new defineButterfly(Entities.addEntity(properties), properties.position));
} }
// Generate the butterflies // Generate the butterflies
for (var i = 0; i < numButterflies; i++) { for (var i = 0; i < numButterflies; i++) {
addButterfly(); addButterfly();
} }
// Main update function // Main update function
function updateButterflies(deltaTime) { function updateButterflies(deltaTime) {
// Check to see if we've been running long enough that our butterflies are dead // Check to see if we've been running long enough that our butterflies are dead
var nowTimeInSeconds = new Date().getTime() / 1000; var nowTimeInSeconds = new Date().getTime() / 1000;
if ((nowTimeInSeconds - startTimeInSeconds) >= lifeTime) { if ((nowTimeInSeconds - startTimeInSeconds) >= lifeTime) {
// print("our butterflies are dying, stop our script");
// print("our butterflies are dying, stop our script");
Script.stop(); Script.stop();
return; return;
} }
@ -177,7 +170,6 @@ function updateButterflies(deltaTime) {
if (butterflies[i].moving == false) { if (butterflies[i].moving == false) {
if (Math.random() < CHANCE_OF_MOVING) { if (Math.random() < CHANCE_OF_MOVING) {
var targetPosition = Vec3.sum(randVector(-range, range), myPosition); var targetPosition = Vec3.sum(randVector(-range, range), myPosition);
if (targetPosition.x < 0) { if (targetPosition.x < 0) {
targetPosition.x = 0; targetPosition.x = 0;
} }
@ -196,13 +188,10 @@ function updateButterflies(deltaTime) {
if (targetPosition.z > TREE_SCALE) { if (targetPosition.z > TREE_SCALE) {
targetPosition.z = TREE_SCALE; targetPosition.z = TREE_SCALE;
} }
butterflies[i].targetPosition = targetPosition; butterflies[i].targetPosition = targetPosition;
butterflies[i].moving = true; butterflies[i].moving = true;
} }
} }
// If we are moving, move towards the target // If we are moving, move towards the target
if (butterflies[i].moving) { if (butterflies[i].moving) {
@ -216,28 +205,22 @@ function updateButterflies(deltaTime) {
properties.velocity.y = holding ; properties.velocity.y = holding ;
// If we are near the target, we should get a new target // If we are near the target, we should get a new target
if (Vec3.length(Vec3.subtract(properties.position, butterflies[i].targetPosition)) < (properties.radius / 1.0)) { if (Vec3.length(Vec3.subtract(properties.position, butterflies[i].targetPosition)) < (properties.radius / 1.0)) {
butterflies[i].moving = false; butterflies[i].moving = false;
} }
var yawRads = Math.atan2(properties.velocity.z, properties.velocity.x); var yawRads = Math.atan2(properties.velocity.z, properties.velocity.x);
yawRads = yawRads + Math.PI / 2.0; yawRads = yawRads + Math.PI / 2.0;
var newOrientation = Quat.fromPitchYawRollRadians(0.0, yawRads, 0.0); var newOrientation = Quat.fromPitchYawRollRadians(0.0, yawRads, 0.0);
properties.rotation = newOrientation; properties.rotation = newOrientation;
} }
// Use a cosine wave offset to make it look like its flapping. // Use a cosine wave offset to make it look like its flapping.
var offset = Math.cos(nowTimeInSeconds * BUTTERFLY_FLAP_SPEED) * (properties.radius); var offset = Math.cos(nowTimeInSeconds * BUTTERFLY_FLAP_SPEED) * (properties.radius);
properties.position.y = properties.position.y + (offset - butterflies[i].previousFlapOffset); properties.position.y = properties.position.y + (offset - butterflies[i].previousFlapOffset);
// Change position relative to previous offset. // Change position relative to previous offset.
butterflies[i].previousFlapOffset = offset; butterflies[i].previousFlapOffset = offset;
Entities.editEntity(entityID, properties); Entities.editEntity(entityID, properties);
} }
} }

View file

@ -1,5 +1,5 @@
// //
// Testing.js // twoFallingEntities.js
// //
// Creates a red 0.2 meter diameter ball right in front of your avatar that lives for 60 seconds // Creates a red 0.2 meter diameter ball right in front of your avatar that lives for 60 seconds
// //