Merge branch 'master' of https://github.com/highfidelity/hifi into gpuStreamizing

This commit is contained in:
ZappoMan 2015-01-06 19:12:01 -08:00
commit 7e8194a3d7
39 changed files with 170 additions and 835 deletions

View file

@ -1,139 +0,0 @@
//
// avatarLocalLight.js
//
// Created by Tony Peng on July 2nd, 2014
// Copyright 2014 High Fidelity, Inc.
//
// Set the local light direction and color on the avatar
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
var localLightDirections = [ {x: 1.0, y:0.0, z: 0.0}, {x: 0.0, y:0.0, z: 1.0} ];
var localLightColors = [ {x: 0.4, y:0.335, z: 0.266}, {x: 0.4, y:0.335, z: 0.266} ];
var currentSelection = 0;
var currentNumLights = 2;
var maxNumLights = 2;
var currentNumAvatars = 0;
var changeDelta = 0.1;
var lightsDirty = true;
function keyPressEvent(event) {
var choice = parseInt(event.text);
if (event.text == "1") {
currentSelection = 0;
print("light election = " + currentSelection);
}
else if (event.text == "2" ) {
currentSelection = 1;
print("light selection = " + currentSelection);
}
else if (event.text == "3" ) {
currentSelection = 2;
print("light selection = " + currentSelection);
}
else if (event.text == "4" ) {
currentSelection = 3;
print("light selection = " + currentSelection);
}
else if (event.text == "5" ) {
localLightColors[currentSelection].x += changeDelta;
if ( localLightColors[currentSelection].x > 1.0) {
localLightColors[currentSelection].x = 0.0;
}
lightsDirty = true;
print("CHANGE RED light " + currentSelection + " color (" + localLightColors[currentSelection].x + ", " + localLightColors[currentSelection].y + ", " + localLightColors[currentSelection].z + " )" );
}
else if (event.text == "6" ) {
localLightColors[currentSelection].y += changeDelta;
if ( localLightColors[currentSelection].y > 1.0) {
localLightColors[currentSelection].y = 0.0;
}
lightsDirty = true;
print("CHANGE GREEN light " + currentSelection + " color (" + localLightColors[currentSelection].x + ", " + localLightColors[currentSelection].y + ", " + localLightColors[currentSelection].z + " )" );
}
else if (event.text == "7" ) {
localLightColors[currentSelection].z += changeDelta;
if ( localLightColors[currentSelection].z > 1.0) {
localLightColors[currentSelection].z = 0.0;
}
lightsDirty = true;
print("CHANGE BLUE light " + currentSelection + " color (" + localLightColors[currentSelection].x + ", " + localLightColors[currentSelection].y + ", " + localLightColors[currentSelection].z + " )" );
}
else if (event.text == "8" ) {
localLightDirections[currentSelection].x += changeDelta;
if (localLightDirections[currentSelection].x > 1.0) {
localLightDirections[currentSelection].x = -1.0;
}
lightsDirty = true;
print("PLUS X light " + currentSelection + " direction (" + localLightDirections[currentSelection].x + ", " + localLightDirections[currentSelection].y + ", " + localLightDirections[currentSelection].z + " )" );
}
else if (event.text == "9" ) {
localLightDirections[currentSelection].x -= changeDelta;
if (localLightDirections[currentSelection].x < -1.0) {
localLightDirections[currentSelection].x = 1.0;
}
lightsDirty = true;
print("MINUS X light " + currentSelection + " direction (" + localLightDirections[currentSelection].x + ", " + localLightDirections[currentSelection].y + ", " + localLightDirections[currentSelection].z + " )" );
}
else if (event.text == "0" ) {
localLightDirections[currentSelection].y += changeDelta;
if (localLightDirections[currentSelection].y > 1.0) {
localLightDirections[currentSelection].y = -1.0;
}
lightsDirty = true;
print("PLUS Y light " + currentSelection + " direction (" + localLightDirections[currentSelection].x + ", " + localLightDirections[currentSelection].y + ", " + localLightDirections[currentSelection].z + " )" );
}
else if (event.text == "-" ) {
localLightDirections[currentSelection].y -= changeDelta;
if (localLightDirections[currentSelection].y < -1.0) {
localLightDirections[currentSelection].y = 1.0;
}
lightsDirty = true;
print("MINUS Y light " + currentSelection + " direction (" + localLightDirections[currentSelection].x + ", " + localLightDirections[currentSelection].y + ", " + localLightDirections[currentSelection].z + " )" );
}
else if (event.text == "," ) {
if (currentNumLights + 1 <= maxNumLights) {
++currentNumLights;
lightsDirty = true;
}
print("ADD LIGHT, number of lights " + currentNumLights);
}
else if (event.text == "." ) {
if (currentNumLights - 1 >= 0 ) {
--currentNumLights;
lightsDirty = true;
}
print("REMOVE LIGHT, number of lights " + currentNumLights);
}
}
function updateLocalLights()
{
if (lightsDirty) {
var localLights = [];
for (var i = 0; i < currentNumLights; i++) {
localLights.push({ direction: localLightDirections[i], color: localLightColors[i] });
}
AvatarManager.setLocalLights(localLights);
lightsDirty = false;
}
}
// main
Script.update.connect(updateLocalLights);
Controller.keyPressEvent.connect(keyPressEvent);

View file

@ -10,7 +10,7 @@
// 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
// //
Script.include("libraries/globals.js"); Script.include("../../libraries/globals.js");
function length(v) { function length(v) {
return Math.sqrt(v.x * v.x + v.y * v.y + v.z * v.z); return Math.sqrt(v.x * v.x + v.y * v.y + v.z * v.z);

View file

@ -10,7 +10,7 @@
// 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
// //
Script.include("libraries/globals.js"); Script.include("../../libraries/globals.js");
function length(v) { function length(v) {
return Math.sqrt(v.x * v.x + v.y * v.y + v.z * v.z); return Math.sqrt(v.x * v.x + v.y * v.y + v.z * v.z);

View file

@ -15,8 +15,8 @@
// 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
// //
Script.include("libraries/globals.js"); Script.include("../../libraries/globals.js");
Script.include("libraries/toolBars.js"); Script.include("../../libraries/toolBars.js");
const LEFT_PALM = 0; const LEFT_PALM = 0;
const LEFT_TIP = 1; const LEFT_TIP = 1;
@ -192,15 +192,18 @@ function cleanupFrisbees() {
} }
function checkControllerSide(hand) { function checkControllerSide(hand) {
// print("cCS");
// If I don't currently have a frisbee in my hand, then try to catch closest one // If I don't currently have a frisbee in my hand, then try to catch closest one
if (!hand.holdingFrisbee && hand.grabButtonPressed()) { if (!hand.holdingFrisbee && hand.grabButtonPressed()) {
var closestEntity = Entities.findClosestEntity(hand.palmPosition(), CATCH_RADIUS); var closestEntity = Entities.findClosestEntity(hand.palmPosition(), CATCH_RADIUS);
var modelUrl = Entities.getEntityProperties(closestEntity).modelURL; var modelUrl = Entities.getEntityProperties(closestEntity).modelURL;
print("lol2"+closestEntity.isKnownID);
if (closestEntity.isKnownID && validFrisbeeURL(Entities.getEntityProperties(closestEntity).modelURL)) { if (closestEntity.isKnownID && validFrisbeeURL(Entities.getEntityProperties(closestEntity).modelURL)) {
print("lol");
Entities.editEntity(closestEntity, {modelScale: 1, inHand: true, position: hand.holdPosition(), shouldDie: true}); Entities.editEntity(closestEntity, {modelScale: 1, inHand: true, position: hand.holdPosition(), shouldDie: true});
Entities.deleteEntity(closestEntity); Entities.deleteEntity(closestEntity);
debugPrint(hand.message + " HAND- CAUGHT SOMETHING!!"); debugPrint(hand.message + " HAND- CAUGHT SOMETHING!!");
print("lol");
var properties = { var properties = {
type: "Model", type: "Model",
position: hand.holdPosition(), position: hand.holdPosition(),
@ -208,10 +211,10 @@ function checkControllerSide(hand) {
gravity: { x: 0, y: 0, z: 0}, gravity: { x: 0, y: 0, z: 0},
inHand: true, inHand: true,
dimensions: { x: FRISBEE_RADIUS, y: FRISBEE_RADIUS / 5, z: FRISBEE_RADIUS }, dimensions: { x: FRISBEE_RADIUS, y: FRISBEE_RADIUS / 5, z: FRISBEE_RADIUS },
damping: 0.00001, damping: 0.999,
modelURL: modelUrl, modelURL: modelUrl,
modelScale: FRISBEE_MODEL_SCALE, scale: FRISBEE_MODEL_SCALE,
modelRotation: hand.holdRotation(), rotation: hand.holdRotation(),
lifetime: FRISBEE_LIFETIME lifetime: FRISBEE_LIFETIME
}; };
@ -235,10 +238,10 @@ function checkControllerSide(hand) {
gravity: { x: 0, y: 0, z: 0}, gravity: { x: 0, y: 0, z: 0},
inHand: true, inHand: true,
dimensions: { x: FRISBEE_RADIUS, y: FRISBEE_RADIUS / 5, z: FRISBEE_RADIUS }, dimensions: { x: FRISBEE_RADIUS, y: FRISBEE_RADIUS / 5, z: FRISBEE_RADIUS },
damping: 0.00001, damping: 0,
modelURL: frisbeeURL(), modelURL: frisbeeURL(),
modelScale: FRISBEE_MODEL_SCALE, scale: FRISBEE_MODEL_SCALE,
modelRotation: hand.holdRotation(), rotation: hand.holdRotation(),
lifetime: FRISBEE_LIFETIME lifetime: FRISBEE_LIFETIME
}; };
@ -270,7 +273,7 @@ function checkControllerSide(hand) {
inHand: false, inHand: false,
lifetime: FRISBEE_LIFETIME, lifetime: FRISBEE_LIFETIME,
gravity: { x: 0, y: -GRAVITY_STRENGTH, z: 0}, gravity: { x: 0, y: -GRAVITY_STRENGTH, z: 0},
modelRotation: hand.holdRotation() rotation: hand.holdRotation()
}; };
Entities.editEntity(hand.entity, properties); Entities.editEntity(hand.entity, properties);
@ -304,7 +307,7 @@ function hydraCheck() {
var numberOfSpatialControls = Controller.getNumberOfSpatialControls(); var numberOfSpatialControls = Controller.getNumberOfSpatialControls();
var controllersPerTrigger = numberOfSpatialControls / numberOfTriggers; var controllersPerTrigger = numberOfSpatialControls / numberOfTriggers;
hydrasConnected = (numberOfButtons == 12 && numberOfTriggers == 2 && controllersPerTrigger == 2); hydrasConnected = (numberOfButtons == 12 && numberOfTriggers == 2 && controllersPerTrigger == 2);
return hydrasConnected; return true;//hydrasConnected;
} }
function checkController(deltaTime) { function checkController(deltaTime) {
@ -314,6 +317,7 @@ function checkController(deltaTime) {
} }
// this is expected for hydras // this is expected for hydras
if (hydraCheck()) { if (hydraCheck()) {
///print("testrr ");
checkControllerSide(leftHand); checkControllerSide(leftHand);
checkControllerSide(rightHand); checkControllerSide(rightHand);
} }
@ -333,7 +337,7 @@ function controlFrisbees(deltaTime) {
killSimulations.push(frisbee); killSimulations.push(frisbee);
continue; continue;
} }
Entities.editEntity(simulatedFrisbees[frisbee], {modelRotation: Quat.multiply(properties.modelRotation, Quat.fromPitchYawRollDegrees(0, speed * deltaTime * SPIN_MULTIPLIER, 0))}); Entities.editEntity(simulatedFrisbees[frisbee], {rotation: Quat.multiply(properties.modelRotation, Quat.fromPitchYawRollDegrees(0, speed * deltaTime * SPIN_MULTIPLIER, 0))});
} }
for (var i = killSimulations.length - 1; i >= 0; i--) { for (var i = killSimulations.length - 1; i >= 0; i--) {
@ -444,4 +448,4 @@ Controller.mouseReleaseEvent.connect(mouseReleaseEvent);
Menu.menuItemEvent.connect(menuItemEvent); Menu.menuItemEvent.connect(menuItemEvent);
Script.scriptEnding.connect(scriptEnding); Script.scriptEnding.connect(scriptEnding);
Script.update.connect(checkController); Script.update.connect(checkController);
Script.update.connect(controlFrisbees); Script.update.connect(controlFrisbees);

View file

@ -14,7 +14,7 @@
// 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
// //
Script.include("libraries/globals.js"); Script.include("../../libraries/globals.js");
function getRandomFloat(min, max) { function getRandomFloat(min, max) {
return Math.random() * (max - min) + min; return Math.random() * (max - min) + min;
@ -194,8 +194,8 @@ function playLoadSound() {
Audio.playSound(loadSound, audioOptions); Audio.playSound(loadSound, audioOptions);
} }
//MyAvatar.attach(gunModel, "RightHand", {x: -0.02, y: -.14, z: 0.07}, Quat.fromPitchYawRollDegrees(-70, -151, 72), 0.20); MyAvatar.attach(gunModel, "RightHand", {x:0.02, y: 0.11, z: 0.04}, Quat.fromPitchYawRollDegrees(-0, -160, -79), 0.20);
MyAvatar.attach(gunModel, "LeftHand", {x: -0.02, y: -.14, z: 0.07}, Quat.fromPitchYawRollDegrees(-70, -151, 72), 0.20); //MyAvatar.attach(gunModel, "LeftHand", {x: -0.02, y: -.14, z: 0.07}, Quat.fromPitchYawRollDegrees(-70, -151, 72), 0.20);
// Give a bit of time to load before playing sound // Give a bit of time to load before playing sound
Script.setTimeout(playLoadSound, 2000); Script.setTimeout(playLoadSound, 2000);

View file

@ -9,7 +9,7 @@
// 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
// //
Script.include("libraries/globals.js"); Script.include("../../libraries/globals.js");
var rightHandAnimation = HIFI_PUBLIC_BUCKET + "animations/RightHandAnimPhilip.fbx"; var rightHandAnimation = HIFI_PUBLIC_BUCKET + "animations/RightHandAnimPhilip.fbx";
var leftHandAnimation = HIFI_PUBLIC_BUCKET + "animations/LeftHandAnimPhilip.fbx"; var leftHandAnimation = HIFI_PUBLIC_BUCKET + "animations/LeftHandAnimPhilip.fbx";

View file

@ -15,7 +15,7 @@
// 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
// //
Script.include("libraries/globals.js"); Script.include("../../libraries/globals.js");
const KBD_UPPERCASE_DEFAULT = 0; const KBD_UPPERCASE_DEFAULT = 0;
const KBD_LOWERCASE_DEFAULT = 1; const KBD_LOWERCASE_DEFAULT = 1;

View file

@ -77,7 +77,6 @@ var modelURLs = [
HIFI_PUBLIC_BUCKET + "models/entities/2-Terrain:%20Alder.fbx", HIFI_PUBLIC_BUCKET + "models/entities/2-Terrain:%20Alder.fbx",
HIFI_PUBLIC_BUCKET + "models/entities/2-Terrain:%20Bush1.fbx", HIFI_PUBLIC_BUCKET + "models/entities/2-Terrain:%20Bush1.fbx",
HIFI_PUBLIC_BUCKET + "models/entities/2-Terrain:%20Bush6.fbx", HIFI_PUBLIC_BUCKET + "models/entities/2-Terrain:%20Bush6.fbx",
HIFI_PUBLIC_BUCKET + "meshes/newInvader16x16-large-purple.svo",
HIFI_PUBLIC_BUCKET + "models/entities/3-Buildings-1-Rustic-Shed.fbx", HIFI_PUBLIC_BUCKET + "models/entities/3-Buildings-1-Rustic-Shed.fbx",
HIFI_PUBLIC_BUCKET + "models/entities/3-Buildings-1-Rustic-Shed2.fbx", HIFI_PUBLIC_BUCKET + "models/entities/3-Buildings-1-Rustic-Shed2.fbx",
HIFI_PUBLIC_BUCKET + "models/entities/3-Buildings-1-Rustic-Shed4.fbx", HIFI_PUBLIC_BUCKET + "models/entities/3-Buildings-1-Rustic-Shed4.fbx",
@ -192,8 +191,7 @@ var toolBar = (function () {
}); });
newTextButton = toolBar.addTool({ newTextButton = toolBar.addTool({
//imageURL: toolIconUrl + "add-text.svg", imageURL: toolIconUrl + "add-text.svg",
imageURL: "https://s3-us-west-1.amazonaws.com/highfidelity-public/images/tools/add-text.svg", // temporarily
subImage: { x: 0, y: Tool.IMAGE_WIDTH, width: Tool.IMAGE_WIDTH, height: Tool.IMAGE_HEIGHT }, subImage: { x: 0, y: Tool.IMAGE_WIDTH, width: Tool.IMAGE_WIDTH, height: Tool.IMAGE_HEIGHT },
width: toolWidth, width: toolWidth,
height: toolHeight, height: toolHeight,

View file

@ -56,7 +56,6 @@ var modelURLs = [
HIFI_PUBLIC_BUCKET + "models/entities/2-Terrain:%20Alder.fbx", HIFI_PUBLIC_BUCKET + "models/entities/2-Terrain:%20Alder.fbx",
HIFI_PUBLIC_BUCKET + "models/entities/2-Terrain:%20Bush1.fbx", HIFI_PUBLIC_BUCKET + "models/entities/2-Terrain:%20Bush1.fbx",
HIFI_PUBLIC_BUCKET + "models/entities/2-Terrain:%20Bush6.fbx", HIFI_PUBLIC_BUCKET + "models/entities/2-Terrain:%20Bush6.fbx",
HIFI_PUBLIC_BUCKET + "meshes/newInvader16x16-large-purple.svo",
HIFI_PUBLIC_BUCKET + "models/entities/3-Buildings-1-Rustic-Shed.fbx", HIFI_PUBLIC_BUCKET + "models/entities/3-Buildings-1-Rustic-Shed.fbx",
HIFI_PUBLIC_BUCKET + "models/entities/3-Buildings-1-Rustic-Shed2.fbx", HIFI_PUBLIC_BUCKET + "models/entities/3-Buildings-1-Rustic-Shed2.fbx",
HIFI_PUBLIC_BUCKET + "models/entities/3-Buildings-1-Rustic-Shed4.fbx", HIFI_PUBLIC_BUCKET + "models/entities/3-Buildings-1-Rustic-Shed4.fbx",
@ -1215,8 +1214,7 @@ var toolBar = (function () {
}); });
newTextButton = toolBar.addTool({ newTextButton = toolBar.addTool({
//imageURL: toolIconUrl + "add-text.svg", imageURL: toolIconUrl + "add-text.svg",
imageURL: "https://s3-us-west-1.amazonaws.com/highfidelity-public/images/tools/add-text.svg", // temporarily
subImage: { x: 0, y: Tool.IMAGE_WIDTH, width: Tool.IMAGE_WIDTH, height: Tool.IMAGE_HEIGHT }, subImage: { x: 0, y: Tool.IMAGE_WIDTH, width: Tool.IMAGE_WIDTH, height: Tool.IMAGE_HEIGHT },
width: toolWidth, width: toolWidth,
height: toolHeight, height: toolHeight,

View file

@ -1,202 +0,0 @@
//
// particleBirds.js
// examples
//
// Created by Benjamin Arnold on May 29, 2014
// Copyright 2014 High Fidelity, Inc.
//
// This sample script creates a swarm of tweeting bird entities that fly around the avatar.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
Script.include("libraries/globals.js");
// Multiply vector by scalar
function vScalarMult(v, s) {
var rval = { x: v.x * s, y: v.y * s, z: v.z * s };
return rval;
}
function printVector(v) {
print(v.x + ", " + v.y + ", " + v.z + "\n");
}
// Create a random vector with individual lengths between a,b
function randVector(a, b) {
var rval = { x: a + Math.random() * (b - a), y: a + Math.random() * (b - a), z: a + Math.random() * (b - a) };
return rval;
}
// Returns a vector which is fraction of the way between a and b
function vInterpolate(a, b, fraction) {
var rval = { x: a.x + (b.x - a.x) * fraction, y: a.y + (b.y - a.y) * fraction, z: a.z + (b.z - a.z) * fraction };
return rval;
}
var startTimeInSeconds = new Date().getTime() / 1000;
var birdLifetime = 20; // lifetime of the birds in seconds!
var range = 1.0; // Over what distance in meters do you want the flock to fly around
var frame = 0;
var CHANCE_OF_MOVING = 0.1;
var CHANCE_OF_TWEETING = 0.05;
var BIRD_GRAVITY = -0.1;
var BIRD_FLAP_SPEED = 10.0;
var BIRD_VELOCITY = 0.5;
var myPosition = MyAvatar.position;
var range = 1.0; // Distance around avatar where I can move
// This is our Bird object
function Bird (particleID, tweetSound, targetPosition) {
this.particleID = particleID;
this.tweetSound = tweetSound;
this.previousFlapOffset = 0;
this.targetPosition = targetPosition;
this.moving = false;
this.tweeting = -1;
}
// Array of birds
var birds = [];
function addBird()
{
// Decide what kind of bird we are
var tweet;
var color;
var size;
var which = Math.random();
if (which < 0.2) {
tweet = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Animals/bushtit_1.raw");
color = { red: 100, green: 50, blue: 120 };
size = 0.08;
} else if (which < 0.4) {
tweet = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Animals/rosyfacedlovebird.raw");
color = { red: 100, green: 150, blue: 75 };
size = 0.09;
} else if (which < 0.6) {
tweet = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Animals/saysphoebe.raw");
color = { red: 84, green: 121, blue: 36 };
size = 0.05;
} else if (which < 0.8) {
tweet = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Animals/mexicanWhipoorwill.raw");
color = { red: 23, green: 197, blue: 230 };
size = 0.12;
} else {
tweet = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Animals/westernscreechowl.raw");
color = { red: 50, green: 67, blue: 144 };
size = 0.15;
}
var properties = {
type: "Sphere",
lifetime: birdLifetime,
position: Vec3.sum(randVector(-range, range), myPosition),
velocity: { x: 0, y: 0, z: 0 },
gravity: { x: 0, y: BIRD_GRAVITY, z: 0 },
dimensions: { x: size * 2, y: size * 2, z: size * 2 },
color: color
};
birds.push(new Bird(Entities.addEntity(properties), tweet, properties.position));
}
var numBirds = 30;
// Generate the birds
for (var i = 0; i < numBirds; i++) {
addBird();
}
// Main update function
function updateBirds(deltaTime) {
// Check to see if we've been running long enough that our birds are dead
var nowTimeInSeconds = new Date().getTime() / 1000;
if ((nowTimeInSeconds - startTimeInSeconds) >= birdLifetime) {
print("our birds are dying, stop our script");
Script.stop();
return;
}
frame++;
// Only update every third frame
if ((frame % 3) == 0) {
myPosition = MyAvatar.position;
// Update all the birds
for (var i = 0; i < numBirds; i++) {
particleID = birds[i].particleID;
var properties = Entities.getEntityProperties(particleID);
// Tweeting behavior
if (birds[i].tweeting == 0) {
if (Math.random() < CHANCE_OF_TWEETING) {
Audio.playSound(birds[i].tweetSound, {
position: properties.position,
volume: 0.75
});
birds[i].tweeting = 10;
}
} else {
birds[i].tweeting -= 1;
}
// Begin movement by getting a target
if (birds[i].moving == false) {
if (Math.random() < CHANCE_OF_MOVING) {
var targetPosition = Vec3.sum(randVector(-range, range), myPosition);
if (targetPosition.x < 0) {
targetPosition.x = 0;
}
if (targetPosition.y < 0) {
targetPosition.y = 0;
}
if (targetPosition.z < 0) {
targetPosition.z = 0;
}
if (targetPosition.x > TREE_SCALE) {
targetPosition.x = TREE_SCALE;
}
if (targetPosition.y > TREE_SCALE) {
targetPosition.y = TREE_SCALE;
}
if (targetPosition.z > TREE_SCALE) {
targetPosition.z = TREE_SCALE;
}
birds[i].targetPosition = targetPosition;
birds[i].moving = true;
}
}
// If we are moving, move towards the target
if (birds[i].moving) {
var desiredVelocity = Vec3.subtract(birds[i].targetPosition, properties.position);
desiredVelocity = vScalarMult(Vec3.normalize(desiredVelocity), BIRD_VELOCITY);
properties.velocity = vInterpolate(properties.velocity, desiredVelocity, 0.2);
// If we are near the target, we should get a new target
if (Vec3.length(Vec3.subtract(properties.position, birds[i].targetPosition)) < (properties.dimensions.x / 5.0)) {
birds[i].moving = false;
}
}
// Use a cosine wave offset to make it look like its flapping.
var offset = Math.cos(nowTimeInSeconds * BIRD_FLAP_SPEED) * properties.dimensions.x;
properties.position.y = properties.position.y + (offset - birds[i].previousFlapOffset);
// Change position relative to previous offset.
birds[i].previousFlapOffset = offset;
// Update the particle
Entities.editEntity(particleID, properties);
}
}
}
// register the call back so it fires before each data send
Script.update.connect(updateBirds);

View file

@ -13,7 +13,7 @@
// 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
// //
Script.include("libraries/globals.js"); Script.include("../libraries/globals.js");
var sound = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Animals/mexicanWhipoorwill.raw"); var sound = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Animals/mexicanWhipoorwill.raw");
var CHANCE_OF_PLAYING_SOUND = 0.01; var CHANCE_OF_PLAYING_SOUND = 0.01;

View file

@ -4,6 +4,10 @@
// //
// Copyright 2014 High Fidelity, Inc. // Copyright 2014 High Fidelity, Inc.
// //
//
// Gives the ability to be set various reverb settings.
//
//
// 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
@ -14,7 +18,7 @@ var audioOptions = new AudioEffectOptions({
roomSize: 50, roomSize: 50,
// Seconds // Seconds
reverbTime: 4, reverbTime: 10,
// Between 0 - 1 // Between 0 - 1
damping: 0.50, damping: 0.50,

View file

@ -12,7 +12,7 @@
// 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
// //
Script.include("libraries/globals.js"); Script.include("../libraries/globals.js");
function getRandomFloat(min, max) { function getRandomFloat(min, max) {
return Math.random() * (max - min) + min; return Math.random() * (max - min) + min;

View file

@ -20,7 +20,7 @@
// //
//For procedural walk animation //For procedural walk animation
Script.include("libraries/globals.js"); Script.include("../libraries/globals.js");
Script.include(HIFI_PUBLIC_BUCKET + "scripts/proceduralAnimationAPI.js"); Script.include(HIFI_PUBLIC_BUCKET + "scripts/proceduralAnimationAPI.js");
var procAnimAPI = new ProcAnimAPI(); var procAnimAPI = new ProcAnimAPI();

View file

@ -11,7 +11,7 @@
// //
//For procedural walk animation //For procedural walk animation
Script.include("libraries/globals.js"); Script.include("../libraries/globals.js");
Script.include(HIFI_PUBLIC_BUCKET + "scripts/proceduralAnimationAPI.js"); Script.include(HIFI_PUBLIC_BUCKET + "scripts/proceduralAnimationAPI.js");
var procAnimAPI = new ProcAnimAPI(); var procAnimAPI = new ProcAnimAPI();

View file

@ -12,7 +12,7 @@
// 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
// //
Script.include("libraries/globals.js"); Script.include("../libraries/globals.js");
function getRandomFloat(min, max) { function getRandomFloat(min, max) {
return Math.random() * (max - min) + min; return Math.random() * (max - min) + min;

View file

@ -82,9 +82,9 @@ function addButterfly() {
damping: 0.00001, damping: 0.00001,
dimensions: dimensions, dimensions: dimensions,
color: color, color: color,
animationURL: "https://s3-us-west-1.amazonaws.com/highfidelity-public/models/content/butterfly/butterfly.fbx", animationURL: "http://public.highfidelity.io/models/content/butterfly/butterfly.fbx",
animationSettings: "{\"firstFrame\":0,\"fps\":" + newFrameRate + ",\"frameIndex\":0,\"hold\":false,\"lastFrame\":10000,\"loop\":true,\"running\":true,\"startAutomatically\":false}", animationSettings: "{\"firstFrame\":0,\"fps\":" + newFrameRate + ",\"frameIndex\":0,\"hold\":false,\"lastFrame\":10000,\"loop\":true,\"running\":true,\"startAutomatically\":false}",
modelURL: "https://s3-us-west-1.amazonaws.com/highfidelity-public/models/content/butterfly/butterfly.fbx" modelURL: "http://public.highfidelity.io/models/content/butterfly/butterfly.fbx"
}; };
butterflies.push(Entities.addEntity(properties)); butterflies.push(Entities.addEntity(properties));
} }

View file

@ -11,7 +11,7 @@
// 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
// //
Script.include("libraries/globals.js"); Script.include("../libraries/globals.js");
var count = 0; var count = 0;
var moveUntil = 2000; var moveUntil = 2000;

View file

@ -11,7 +11,7 @@
// 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
// //
Script.include("libraries/globals.js"); Script.include("../libraries/globals.js");
// The "Swatches" example of this script will create 9 different image overlays, that use the color feature to // The "Swatches" example of this script will create 9 different image overlays, that use the color feature to
// display different colors as color swatches. The overlays can be clicked on, to change the "selectedSwatch" variable // display different colors as color swatches. The overlays can be clicked on, to change the "selectedSwatch" variable

View file

@ -9,7 +9,7 @@
// 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
// //
Script.include("libraries/globals.js"); Script.include("../libraries/globals.js");
var modelURL = HIFI_PUBLIC_BUCKET + "models/entities/radio/Speakers.fbx"; var modelURL = HIFI_PUBLIC_BUCKET + "models/entities/radio/Speakers.fbx";
var soundURL = HIFI_PUBLIC_BUCKET + "sounds/family.stereo.raw"; var soundURL = HIFI_PUBLIC_BUCKET + "sounds/family.stereo.raw";

View file

@ -11,7 +11,7 @@
// 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
// //
Script.include("libraries/globals.js"); Script.include("../libraries/globals.js");
var iteration = 0; var iteration = 0;
@ -59,7 +59,7 @@ var middleY = gameAt.y + (gameSize.y/2);
var invaderSize = 0.4; var invaderSize = 0.4;
var shipSize = 0.25; var shipSize = 0.25;
var missileSize = 0.1; var missileSize = 1.0;
var myShip; var myShip;
var myShipProperties; var myShipProperties;
@ -101,7 +101,7 @@ var soundInMyHead = true;
// models... // models...
var invaderModels = new Array(); var invaderModels = new Array();
invaderModels[0] = { invaderModels[0] = {
modelURL: HIFI_PUBLIC_BUCKET + "meshes/newInvader16x16-large-purple.svo", modelURL: HIFI_PUBLIC_BUCKET + "meshes/space_invader.fbx",
modelScale: 450, modelScale: 450,
modelTranslation: { x: -1.3, y: -1.3, z: -1.3 }, modelTranslation: { x: -1.3, y: -1.3, z: -1.3 },
}; };
@ -141,7 +141,7 @@ function initializeMyShip() {
damping: 0, damping: 0,
dimensions: { x: shipSize * 2, y: shipSize * 2, z: shipSize * 2 }, dimensions: { x: shipSize * 2, y: shipSize * 2, z: shipSize * 2 },
color: { red: 0, green: 255, blue: 0 }, color: { red: 0, green: 255, blue: 0 },
modelURL: HIFI_PUBLIC_BUCKET + "meshes/myCannon16x16.svo", modelURL: HIFI_PUBLIC_BUCKET + "meshes/space_invader.fbx",
lifetime: itemLifetimes lifetime: itemLifetimes
}; };
myShip = Entities.addEntity(myShipProperties); myShip = Entities.addEntity(myShipProperties);
@ -360,7 +360,7 @@ function keyPressEvent(key) {
myShipProperties.position.x = gameAt.x + gameSize.x; myShipProperties.position.x = gameAt.x + gameSize.x;
} }
moveShipTo(myShipProperties.position); moveShipTo(myShipProperties.position);
} else if (key.text == " ") { } else if (key.text == "f") {
fireMissile(); fireMissile();
} else if (key.text == "q") { } else if (key.text == "q") {
endGame(); endGame();

View file

@ -58,7 +58,7 @@ var button1 = Overlays.addOverlay("image", { // green button
width: 40, width: 40,
height: 35, height: 35,
subImage: { x: 0, y: 0, width: 39, height: 35 }, subImage: { x: 0, y: 0, width: 39, height: 35 },
imageURL: "https://s3-us-west-1.amazonaws.com/highfidelity-public/images/thumb.png", imageURL: "https://public.highfidelity.io/images/thumb.png",
color: readyColor, color: readyColor,
visible: true visible: true
}); });
@ -69,7 +69,7 @@ var button2 = Overlays.addOverlay("image", { // red button
width: 40, width: 40,
height: 35, height: 35,
subImage: { x: 0, y: 0, width: 39, height: 35 }, subImage: { x: 0, y: 0, width: 39, height: 35 },
imageURL: "https://s3-us-west-1.amazonaws.com/highfidelity-public/images/thumb.png", imageURL: "https://public.highfidelity.io/images/thumb.png",
color: { red: 250, green: 2, blue: 2}, color: { red: 250, green: 2, blue: 2},
visible: true, visible: true,
}); });

View file

@ -1,77 +0,0 @@
//
// fountain.js
// examples
//
// Copyright 2014 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
function vLength(v) {
return Math.sqrt(v.x * v.x + v.y * v.y + v.z * v.z);
}
function printVector(v) {
print(v.x + ", " + v.y + ", " + v.z + "\n");
}
// Create a random vector with individual lengths between a,b
function randVector(a, b) {
var rval = { x: a + Math.random() * (b - a), y: a + Math.random() * (b - a), z: a + Math.random() * (b - a) };
return rval;
}
function vMinus(a, b) {
var rval = { x: a.x - b.x, y: a.y - b.y, z: a.z - b.z };
return rval;
}
function vPlus(a, b) {
var rval = { x: a.x + b.x, y: a.y + b.y, z: a.z + b.z };
return rval;
}
function vCopy(a, b) {
a.x = b.x;
a.y = b.y;
a.z = b.z;
return;
}
// Returns a vector which is fraction of the way between a and b
function vInterpolate(a, b, fraction) {
var rval = { x: a.x + (b.x - a.x) * fraction, y: a.y + (b.y - a.y) * fraction, z: a.z + (b.z - a.z) * fraction };
return rval;
}
var position = { x: 5.0, y: 0.6, z: 5.0 };
//Voxels.setVoxel(position.x, 0, position.z, 0.5, 0, 0, 255);
var totalEntities = 0;
function makeFountain(deltaTime) {
if (Math.random() < 0.10) {
//print("Made entity!\n");
var radius = (0.02 + (Math.random() * 0.05));
var properties = {
type: "Sphere",
position: position,
dimensions: { x: radius, y: radius, z: radius},
color: { red: 0, green: 0, blue: 128 },
velocity: { x: (Math.random() * 1.0 - 0.5),
y: (1.0 + (Math.random() * 2.0)),
z: (Math.random() * 1.0 - 0.5) },
gravity: { x: 0, y: -0.1, z: 0 },
damping: 0.25,
lifetime: 1
}
Entities.addEntity(properties);
totalEntities++;
}
if (totalEntities > 100) {
Script.stop();
}
}
// register the call back so it fires before each data send
Script.update.connect(makeFountain);

View file

@ -1,328 +0,0 @@
//
// grenadeLauncher.js
// examples
// Created by Ben Arnold on 7/11/14.
// This is a modified version of gun.js by Brad Hefta-Gaub.
//
// Copyright 2013 High Fidelity, Inc.
//
// 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 big 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
//
Script.include("libraries/globals.js");
function getRandomFloat(min, max) {
return Math.random() * (max - min) + min;
}
var lastX = 0;
var lastY = 0;
var yawFromMouse = 0;
var pitchFromMouse = 0;
var isMouseDown = false;
var BULLET_VELOCITY = 3.0;
var MIN_THROWER_DELAY = 1000;
var MAX_THROWER_DELAY = 1000;
var LEFT_BUTTON_1 = 1;
var LEFT_BUTTON_3 = 3;
var RELOAD_INTERVAL = 5;
var showScore = false;
// Load some sound to use for loading and firing
var fireSound = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Guns/GUN-SHOT2.raw");
var loadSound = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Guns/Gun_Reload_Weapon22.raw");
var impactSound = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Guns/BulletImpact2.raw");
var targetHitSound = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Space%20Invaders/hit.raw");
var targetLaunchSound = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Space%20Invaders/shoot.raw");
var gunModel = "http://public.highfidelity.io/models/attachments/HaloGun.fst";
var audioOptions {
volume: 0.9
}
var shotsFired = 0;
var shotTime = new Date();
// initialize our triggers
var triggerPulled = new Array();
var numberOfTriggers = Controller.getNumberOfTriggers();
for (t = 0; t < numberOfTriggers; t++) {
triggerPulled[t] = false;
}
var isLaunchButtonPressed = false;
var score = 0;
// Create a reticle image in center of screen
var screenSize = Controller.getViewportDimensions();
var reticle = Overlays.addOverlay("image", {
x: screenSize.x / 2 - 16,
y: screenSize.y / 2 - 16,
width: 32,
height: 32,
imageURL: HIFI_PUBLIC_BUCKET + "images/reticle.png",
color: { red: 255, green: 255, blue: 255},
alpha: 1
});
if (showScore) {
var text = Overlays.addOverlay("text", {
x: screenSize.x / 2 - 100,
y: screenSize.y / 2 - 50,
width: 150,
height: 50,
color: { red: 0, green: 0, blue: 0},
textColor: { red: 255, green: 0, blue: 0},
topMargin: 4,
leftMargin: 4,
text: "Score: " + score
});
}
function printVector(string, vector) {
print(string + " " + vector.x + ", " + vector.y + ", " + vector.z);
}
function shootBullet(position, velocity) {
var BULLET_SIZE = 0.1;
var BULLET_GRAVITY = -3.0;
//Creates a grenade with a reasonable lifetime so that one is less likely to accidentally blow up
//far away voxels
Entities.addEntity(
{ type: "Sphere",
position: position,
collisionsWillMove: true,
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 },
lifetime: 10.0,
damping: 0 });
// Play firing sounds
audioOptions.position = position;
Audio.playSound(fireSound, audioOptions);
shotsFired++;
if ((shotsFired % RELOAD_INTERVAL) == 0) {
Audio.playSound(loadSound, audioOptions);
}
}
function shootTarget() {
var TARGET_SIZE = 0.25;
var TARGET_GRAVITY = -0.6;
var TARGET_UP_VELOCITY = 3.0;
var TARGET_FWD_VELOCITY = 5.0;
var DISTANCE_TO_LAUNCH_FROM = 3.0;
var camera = Camera.getPosition();
//printVector("camera", camera);
var targetDirection = Quat.angleAxis(getRandomFloat(-20.0, 20.0), { x:0, y:1, z:0 });
targetDirection = Quat.multiply(Camera.getOrientation(), targetDirection);
var forwardVector = Quat.getFront(targetDirection);
//printVector("forwardVector", forwardVector);
var newPosition = Vec3.sum(camera, Vec3.multiply(forwardVector, DISTANCE_TO_LAUNCH_FROM));
//printVector("newPosition", newPosition);
var velocity = Vec3.multiply(forwardVector, TARGET_FWD_VELOCITY);
velocity.y += TARGET_UP_VELOCITY;
//printVector("velocity", velocity);
Entities.addEntity(
{ type: "Sphere",
position: newPosition,
collisionsWillMove: true,
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 },
lifetime: 1000.0,
damping: 0.0001 });
// Record start time
shotTime = new Date();
// Play target shoot sound
audioOptions.position = newPosition;
Audio.playSound(targetLaunchSound, audioOptions);
}
function entityCollisionWithEntity(entity1, entity2, collision) {
score++;
if (showScore) {
Overlays.editOverlay(text, { text: "Score: " + score } );
}
// Record shot time
var endTime = new Date();
var msecs = endTime.valueOf() - shotTime.valueOf();
//print("hit, msecs = " + msecs);
//Vec3.print("penetration = ", collision.penetration);
//Vec3.print("contactPoint = ", collision.contactPoint);
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);
}
function keyPressEvent(event) {
// if our tools are off, then don't do anything
if (event.text == "t") {
var time = MIN_THROWER_DELAY + Math.random() * MAX_THROWER_DELAY;
Script.setTimeout(shootTarget, time);
} else if (event.text == ".") {
shootFromMouse();
} else if (event.text == "r") {
playLoadSound();
}
}
function playLoadSound() {
audioOptions.position = Vec3.sum(Camera.getPosition(), Quat.getFront(Camera.getOrientation()));
Audio.playSound(loadSound, audioOptions);
}
//MyAvatar.attach(gunModel, "RightHand", {x: -0.02, y: -.14, z: 0.07}, Quat.fromPitchYawRollDegrees(-70, -151, 72), 0.20);
MyAvatar.attach(gunModel, "LeftHand", {x: -0.02, y: -.14, z: 0.07}, Quat.fromPitchYawRollDegrees(-70, -151, 72), 0.20);
// Give a bit of time to load before playing sound
Script.setTimeout(playLoadSound, 2000);
function update(deltaTime) {
// Check for mouseLook movement, update rotation
// rotate body yaw for yaw received from controller or mouse
var newOrientation = Quat.multiply(MyAvatar.orientation, Quat.fromVec3Radians( { x: 0, y: yawFromMouse, z: 0 } ));
MyAvatar.orientation = newOrientation;
yawFromMouse = 0;
// apply pitch from controller or mouse
var newPitch = MyAvatar.headPitch + pitchFromMouse;
MyAvatar.headPitch = newPitch;
pitchFromMouse = 0;
// Check hydra controller for launch button press
if (!isLaunchButtonPressed && Controller.isButtonPressed(LEFT_BUTTON_3)) {
isLaunchButtonPressed = true;
var time = MIN_THROWER_DELAY + Math.random() * MAX_THROWER_DELAY;
Script.setTimeout(shootTarget, time);
} else if (isLaunchButtonPressed && !Controller.isButtonPressed(LEFT_BUTTON_3)) {
isLaunchButtonPressed = false;
}
// Check hydra controller for trigger press
var numberOfTriggers = Controller.getNumberOfTriggers();
var numberOfSpatialControls = Controller.getNumberOfSpatialControls();
var controllersPerTrigger = numberOfSpatialControls / numberOfTriggers;
// this is expected for hydras
if (numberOfTriggers == 2 && controllersPerTrigger == 2) {
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) {
triggerPulled[t] = false; // unpulled
}
} else {
// must pull to at least 0.9
if (triggerValue > 0.9) {
triggerPulled[t] = true; // pulled
shootABullet = true;
}
}
if (shootABullet) {
var palmController = t * controllersPerTrigger;
var palmPosition = Controller.getSpatialControlPosition(palmController);
var fingerTipController = palmController + 1;
var fingerTipPosition = Controller.getSpatialControlPosition(fingerTipController);
var palmToFingerTipVector =
{ x: (fingerTipPosition.x - palmPosition.x),
y: (fingerTipPosition.y - palmPosition.y),
z: (fingerTipPosition.z - palmPosition.z) };
// just off the front of the finger tip
var position = { x: fingerTipPosition.x + palmToFingerTipVector.x/2,
y: fingerTipPosition.y + palmToFingerTipVector.y/2,
z: fingerTipPosition.z + palmToFingerTipVector.z/2};
var linearVelocity = 25;
var velocity = { x: palmToFingerTipVector.x * linearVelocity,
y: palmToFingerTipVector.y * linearVelocity,
z: palmToFingerTipVector.z * linearVelocity };
shootBullet(position, velocity);
}
}
}
}
function mousePressEvent(event) {
isMouseDown = true;
lastX = event.x;
lastY = event.y;
//audioOptions.position = Vec3.sum(Camera.getPosition(), Quat.getFront(Camera.getOrientation()));
//Audio.playSound(loadSound, audioOptions);
}
function shootFromMouse() {
var DISTANCE_FROM_CAMERA = 2.0;
var camera = Camera.getPosition();
var forwardVector = Quat.getFront(Camera.getOrientation());
var newPosition = Vec3.sum(camera, Vec3.multiply(forwardVector, DISTANCE_FROM_CAMERA));
var velocity = Vec3.multiply(forwardVector, BULLET_VELOCITY);
shootBullet(newPosition, velocity);
}
function mouseReleaseEvent(event) {
// position
isMouseDown = false;
}
function mouseMoveEvent(event) {
//Move the camera if LEFT_BUTTON_1 is pressed
if (Controller.isButtonPressed(LEFT_BUTTON_1)) {
var MOUSE_YAW_SCALE = -0.25;
var MOUSE_PITCH_SCALE = -12.5;
var FIXED_MOUSE_TIMESTEP = 0.016;
yawFromMouse += ((event.x - lastX) * MOUSE_YAW_SCALE * FIXED_MOUSE_TIMESTEP);
pitchFromMouse += ((event.y - lastY) * MOUSE_PITCH_SCALE * FIXED_MOUSE_TIMESTEP);
lastX = event.x;
lastY = event.y;
}
}
function scriptEnding() {
Overlays.deleteOverlay(reticle);
Overlays.deleteOverlay(text);
MyAvatar.detachOne(gunModel);
}
Entities.entityCollisionWithEntity.connect(entityCollisionWithEntity);
Script.scriptEnding.connect(scriptEnding);
Script.update.connect(update);
Controller.mousePressEvent.connect(mousePressEvent);
Controller.mouseReleaseEvent.connect(mouseReleaseEvent);
Controller.mouseMoveEvent.connect(mouseMoveEvent);
Controller.keyPressEvent.connect(keyPressEvent);

View file

@ -590,7 +590,7 @@ SelectionDisplay = (function () {
}); });
var yawHandle = Overlays.addOverlay("billboard", { var yawHandle = Overlays.addOverlay("billboard", {
url: "https://s3-us-west-1.amazonaws.com/highfidelity-public/images/rotate-arrow-west-north.png", url: "https://public.highfidelity.io/images/rotate-arrow-west-north.png",
position: { x:0, y: 0, z: 0}, position: { x:0, y: 0, z: 0},
color: rotateHandleColor, color: rotateHandleColor,
alpha: rotateHandleAlpha, alpha: rotateHandleAlpha,
@ -603,7 +603,7 @@ SelectionDisplay = (function () {
var pitchHandle = Overlays.addOverlay("billboard", { var pitchHandle = Overlays.addOverlay("billboard", {
url: "https://s3-us-west-1.amazonaws.com/highfidelity-public/images/rotate-arrow-west-north.png", url: "https://public.highfidelity.io/images/rotate-arrow-west-north.png",
position: { x:0, y: 0, z: 0}, position: { x:0, y: 0, z: 0},
color: rotateHandleColor, color: rotateHandleColor,
alpha: rotateHandleAlpha, alpha: rotateHandleAlpha,
@ -616,7 +616,7 @@ SelectionDisplay = (function () {
var rollHandle = Overlays.addOverlay("billboard", { var rollHandle = Overlays.addOverlay("billboard", {
url: "https://s3-us-west-1.amazonaws.com/highfidelity-public/images/rotate-arrow-west-north.png", url: "https://public.highfidelity.io/images/rotate-arrow-west-north.png",
position: { x:0, y: 0, z: 0}, position: { x:0, y: 0, z: 0},
color: rotateHandleColor, color: rotateHandleColor,
alpha: rotateHandleAlpha, alpha: rotateHandleAlpha,
@ -835,8 +835,8 @@ SelectionDisplay = (function () {
rollCenter = { x: boundsCenter.x, y: boundsCenter.y, z: far }; rollCenter = { x: boundsCenter.x, y: boundsCenter.y, z: far };
Overlays.editOverlay(pitchHandle, { url: "https://s3-us-west-1.amazonaws.com/highfidelity-public/images/rotate-arrow-west-south.png" }); Overlays.editOverlay(pitchHandle, { url: "https://public.highfidelity.io/images/rotate-arrow-west-south.png" });
Overlays.editOverlay(rollHandle, { url: "https://s3-us-west-1.amazonaws.com/highfidelity-public/images/rotate-arrow-west-south.png" }); Overlays.editOverlay(rollHandle, { url: "https://public.highfidelity.io/images/rotate-arrow-west-south.png" });
} else { } else {
@ -867,8 +867,8 @@ SelectionDisplay = (function () {
pitchCenter = { x: right, y: boundsCenter.y, z: boundsCenter.z }; pitchCenter = { x: right, y: boundsCenter.y, z: boundsCenter.z };
rollCenter = { x: boundsCenter.x, y: boundsCenter.y, z: near}; rollCenter = { x: boundsCenter.x, y: boundsCenter.y, z: near};
Overlays.editOverlay(pitchHandle, { url: "https://s3-us-west-1.amazonaws.com/highfidelity-public/images/rotate-arrow-west-north.png" }); Overlays.editOverlay(pitchHandle, { url: "https://public.highfidelity.io/images/rotate-arrow-west-north.png" });
Overlays.editOverlay(rollHandle, { url: "https://s3-us-west-1.amazonaws.com/highfidelity-public/images/rotate-arrow-west-north.png" }); Overlays.editOverlay(rollHandle, { url: "https://public.highfidelity.io/images/rotate-arrow-west-north.png" });
} }
} else { } else {
@ -899,8 +899,8 @@ SelectionDisplay = (function () {
pitchCenter = { x: left, y: boundsCenter.y, z: boundsCenter.z }; pitchCenter = { x: left, y: boundsCenter.y, z: boundsCenter.z };
rollCenter = { x: boundsCenter.x, y: boundsCenter.y, z: far}; rollCenter = { x: boundsCenter.x, y: boundsCenter.y, z: far};
Overlays.editOverlay(pitchHandle, { url: "https://s3-us-west-1.amazonaws.com/highfidelity-public/images/rotate-arrow-west-north.png" }); Overlays.editOverlay(pitchHandle, { url: "https://public.highfidelity.io/images/rotate-arrow-west-north.png" });
Overlays.editOverlay(rollHandle, { url: "https://s3-us-west-1.amazonaws.com/highfidelity-public/images/rotate-arrow-west-north.png" }); Overlays.editOverlay(rollHandle, { url: "https://public.highfidelity.io/images/rotate-arrow-west-north.png" });
} else { } else {
@ -928,8 +928,8 @@ SelectionDisplay = (function () {
rollCenter = { x: boundsCenter.x, y: boundsCenter.y, z: near }; rollCenter = { x: boundsCenter.x, y: boundsCenter.y, z: near };
pitchCenter = { x: left, y: boundsCenter.y, z: boundsCenter.z}; pitchCenter = { x: left, y: boundsCenter.y, z: boundsCenter.z};
Overlays.editOverlay(pitchHandle, { url: "https://s3-us-west-1.amazonaws.com/highfidelity-public/images/rotate-arrow-west-north.png" }); Overlays.editOverlay(pitchHandle, { url: "https://public.highfidelity.io/images/rotate-arrow-west-north.png" });
Overlays.editOverlay(rollHandle, { url: "https://s3-us-west-1.amazonaws.com/highfidelity-public/images/rotate-arrow-west-north.png" }); Overlays.editOverlay(rollHandle, { url: "https://public.highfidelity.io/images/rotate-arrow-west-north.png" });
} }
} }

View file

@ -0,0 +1,104 @@
//
// Unittest.js
// examples
//
// Created by Ryan Huffman on 5/4/14
// Copyright 2014 High Fidelity, Inc.
//
// This provides very basic unit testing functionality.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
test = function(name, func) {
print("Running test: " + name);
var unitTest = new UnitTest(name, func);
try {
unitTest.run();
print(" Success: " + unitTest.numAssertions + " assertions passed");
} catch (error) {
print(" Failure: " + error.name + " " + error.message);
}
};
AssertionException = function(expected, actual, message) {
print("Creating exception");
this.message = message + "\n: " + actual + " != " + expected;
this.name = 'AssertionException';
};
UnthrownException = function(message) {
print("Creating exception");
this.message = message + "\n";
this.name = 'UnthrownException';
};
UnitTest = function(name, func) {
this.numAssertions = 0;
this.func = func;
};
UnitTest.prototype.run = function() {
this.func();
};
UnitTest.prototype.assertNotEquals = function(expected, actual, message) {
this.numAssertions++;
if (expected == actual) {
throw new AssertionException(expected, actual, message);
}
};
UnitTest.prototype.assertEquals = function(expected, actual, message) {
this.numAssertions++;
if (expected != actual) {
throw new AssertionException(expected, actual, message);
}
};
UnitTest.prototype.assertContains = function (expected, actual, message) {
this.numAssertions++;
if (actual.indexOf(expected) == -1) {
throw new AssertionException(expected, actual, message);
}
};
UnitTest.prototype.assertHasProperty = function(property, actual, message) {
this.numAssertions++;
if (actual[property] === undefined) {
throw new AssertionException(property, actual, message);
}
};
UnitTest.prototype.assertNull = function(value, message) {
this.numAssertions++;
if (value !== null) {
throw new AssertionException(value, null, message);
}
}
UnitTest.prototype.arrayEqual = function(array1, array2, message) {
this.numAssertions++;
if (array1.length !== array2.length) {
throw new AssertionException(array1.length , array2.length , message);
}
for (var i = 0; i < array1.length; ++i) {
if (array1[i] !== array2[i]) {
throw new AssertionException(array1[i], array2[i], i + " " + message);
}
}
}
UnitTest.prototype.raises = function(func, message) {
this.numAssertions++;
try {
func();
} catch (error) {
return;
}
throw new UnthrownException(message);
}

View file

@ -1,27 +0,0 @@
//
// playSound.js
// examples
//
// Copyright 2014 High Fidelity, Inc.
// Plays a sample audio file at the avatar's current location
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
Script.include("libraries/globals.js");
// First, load a sample sound from a URL
var bird = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Animals/bushtit_1.raw");
function maybePlaySound(deltaTime) {
if (Math.random() < 0.01) {
// Set the location and other info for the sound to play
Audio.playSound(bird, {
position: MyAvatar.position,
volume: 0.5
});
}
}
// Connect a call back that happens every frame
Script.update.connect(maybePlaySound);

View file

@ -11,7 +11,7 @@
// 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
// //
Script.include("Test.js"); Script.include("../../libraries/unitTest.js");
test("Test default request values", function(finished) { test("Test default request values", function(finished) {
var req = new XMLHttpRequest(); var req = new XMLHttpRequest();

View file

@ -11,7 +11,7 @@
// 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
// //
Script.include("libraries/globals.js"); Script.include("../../libraries/globals.js");
var sound = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/220Sine.wav"); var sound = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/220Sine.wav");

View file

@ -11,7 +11,7 @@
// 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
// //
Script.include("libraries/globals.js"); Script.include("../../libraries/globals.js");
// A few sample files you may want to try: // A few sample files you may want to try:

View file

@ -9,9 +9,9 @@
// 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
// //
Script.include("libraries/globals.js"); Script.include("../../libraries/globals.js");
var soundClip = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Voxels/voxel create 3.raw"); var soundClip = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Guitars/Guitar+-+Nylon+A.raw");
var currentTime = 1.570079; // pi/2 var currentTime = 1.570079; // pi/2
var deltaTime = 0.05; var deltaTime = 0.05;
@ -38,6 +38,6 @@ function playSound() {
}); });
} }
Script.setInterval(playSound, 250); Script.setInterval(playSound, 850);

View file

@ -3,7 +3,7 @@ Instructions for adding the RtMidi library to Interface
Stephen Birarda, June 30, 2014 Stephen Birarda, June 30, 2014
1. Download the RtMidi tarball from High Fidelity S3. 1. Download the RtMidi tarball from High Fidelity S3.
http://highfidelity-public.s3.amazonaws.com/dependencies/rtmidi-2.1.0.tar.gz http://public.highfidelity.io/dependencies/rtmidi-2.1.0.tar.gz
2. Copy RtMidi.h to externals/rtmidi/include. 2. Copy RtMidi.h to externals/rtmidi/include.