diff --git a/BUILD.md b/BUILD.md index d068d6d458..c86e34823c 100644 --- a/BUILD.md +++ b/BUILD.md @@ -60,5 +60,5 @@ OS X users who tap our [homebrew formulas repository](https://github.com/highfid ####Devices -You can support external input/output devices such as Leap Motion, Faceplus, Faceshift, PrioVR, MIDI, Razr Hydra and more by adding each individual SDK in the visible building path. Refer to the readme file available in each device folder in [interface/external/](interface/external) for the detailed explanation of the requirements to use the device. +You can support external input/output devices such as Leap Motion, Faceshift, PrioVR, MIDI, Razr Hydra and more by adding each individual SDK in the visible building path. Refer to the readme file available in each device folder in [interface/external/](interface/external) for the detailed explanation of the requirements to use the device. diff --git a/cmake/modules/FindFaceplus.cmake b/cmake/modules/FindFaceplus.cmake deleted file mode 100644 index e97fce3edb..0000000000 --- a/cmake/modules/FindFaceplus.cmake +++ /dev/null @@ -1,24 +0,0 @@ -# Try to find the Faceplus library -# -# You must provide a FACEPLUS_ROOT_DIR which contains lib and include directories -# -# Once done this will define -# -# FACEPLUS_FOUND - system found Faceplus -# FACEPLUS_INCLUDE_DIRS - the Faceplus include directory -# FACEPLUS_LIBRARIES - Link this to use Faceplus -# -# Created on 4/8/2014 by Andrzej Kapolka -# Copyright (c) 2014 High Fidelity -# - -find_path(FACEPLUS_INCLUDE_DIRS faceplus.h ${FACEPLUS_ROOT_DIR}/include) - -if (WIN32) - find_library(FACEPLUS_LIBRARIES faceplus.lib ${FACEPLUS_ROOT_DIR}/win32/) -endif (WIN32) - -include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(Faceplus DEFAULT_MSG FACEPLUS_INCLUDE_DIRS FACEPLUS_LIBRARIES) - -mark_as_advanced(FACEPLUS_INCLUDE_DIRS FACEPLUS_LIBRARIES) \ No newline at end of file diff --git a/cmake/modules/FindGLEW.cmake b/cmake/modules/FindGLEW.cmake index 99d6dfc003..363f346d09 100644 --- a/cmake/modules/FindGLEW.cmake +++ b/cmake/modules/FindGLEW.cmake @@ -21,17 +21,17 @@ if (WIN32) include("${MACRO_DIR}/HifiLibrarySearchHints.cmake") hifi_library_search_hints("glew") - - find_path(GLEW_INCLUDE_DIRS GL/glew.h PATH_SUFFIXES include HINTS ${GLEW_SEARCH_DIRS}) - find_library(GLEW_LIBRARY_RELEASE glew32s PATH_SUFFIXES "lib/Release/Win32" "lib" HINTS ${GLEW_SEARCH_DIRS}) - find_library(GLEW_LIBRARY_DEBUG glew32s PATH_SUFFIXES "lib/Debug/Win32" "lib" HINTS ${GLEW_SEARCH_DIRS}) + find_path(GLEW_INCLUDE_DIRS GL/glew.h PATH_SUFFIXES include HINTS ${GLEW_SEARCH_DIRS}) + + find_library(GLEW_LIBRARY_RELEASE glew32s PATH_SUFFIXES "lib/Release/Win32" "lib" HINTS ${GLEW_SEARCH_DIRS}) + find_library(GLEW_LIBRARY_DEBUG glew32sd PATH_SUFFIXES "lib/Debug/Win32" "lib" HINTS ${GLEW_SEARCH_DIRS}) include(SelectLibraryConfigurations) select_library_configurations(GLEW) endif () -set(GLEW_LIBRARIES "${GLEW_LIBRARY}") +set(GLEW_LIBRARIES ${GLEW_LIBRARY}) include(FindPackageHandleStandardArgs) find_package_handle_standard_args(GLEW DEFAULT_MSG GLEW_INCLUDE_DIRS GLEW_LIBRARIES) diff --git a/examples/botProceduralWayPoints.js b/examples/acScripts/botProceduralWayPoints.js similarity index 99% rename from examples/botProceduralWayPoints.js rename to examples/acScripts/botProceduralWayPoints.js index e20714bd27..b7c1fa1fe2 100644 --- a/examples/botProceduralWayPoints.js +++ b/examples/acScripts/botProceduralWayPoints.js @@ -20,7 +20,7 @@ // //For procedural walk animation -Script.include("libraries/globals.js"); +Script.include("../libraries/globals.js"); Script.include(HIFI_PUBLIC_BUCKET + "scripts/proceduralAnimationAPI.js"); var procAnimAPI = new ProcAnimAPI(); diff --git a/examples/bot_procedural.js b/examples/acScripts/bot_procedural.js similarity index 99% rename from examples/bot_procedural.js rename to examples/acScripts/bot_procedural.js index eec3c8906d..8b96ed36c2 100644 --- a/examples/bot_procedural.js +++ b/examples/acScripts/bot_procedural.js @@ -11,8 +11,8 @@ // //For procedural walk animation -Script.include("libraries/globals.js"); -Script.include(HIFI_PUBLIC_BUCKET + "scripts/proceduralAnimationAPI.js"); +Script.include("../libraries/globals.js"); +Script.include("proceduralAnimationAPI.js"); var procAnimAPI = new ProcAnimAPI(); diff --git a/examples/bot_randomExpression.js b/examples/acScripts/bot_randomExpression.js similarity index 98% rename from examples/bot_randomExpression.js rename to examples/acScripts/bot_randomExpression.js index 44d546e763..32bfb24065 100644 --- a/examples/bot_randomExpression.js +++ b/examples/acScripts/bot_randomExpression.js @@ -12,7 +12,7 @@ // 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) { return Math.random() * (max - min) + min; diff --git a/examples/proceduralAnimationAPI.js b/examples/acScripts/proceduralAnimationAPI.js similarity index 100% rename from examples/proceduralAnimationAPI.js rename to examples/acScripts/proceduralAnimationAPI.js diff --git a/examples/avatarCollision.js b/examples/avatarCollision.js deleted file mode 100644 index ce13daa50d..0000000000 --- a/examples/avatarCollision.js +++ /dev/null @@ -1,72 +0,0 @@ -// -// avatarCollision.js -// examples -// -// Created by Andrew Meadows on 2014-04-09 -// Copyright 2014 High Fidelity, Inc. -// -// Play a sound on collisions with your 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"); - -var SOUND_TRIGGER_CLEAR = 1000; // milliseconds -var SOUND_TRIGGER_DELAY = 200; // milliseconds -var soundExpiry = 0; -var DateObj = new Date(); - -var audioOptions = { - volume: 0.5, - position: { x: 0, y: 0, z: 0 } -} - -var hitSounds = new Array(); -hitSounds[0] = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Collisions-hitsandslaps/Hit1.raw"); -hitSounds[1] = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Collisions-hitsandslaps/Hit2.raw"); -hitSounds[2] = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Collisions-hitsandslaps/Hit3.raw"); -hitSounds[3] = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Collisions-hitsandslaps/Hit4.raw"); -hitSounds[4] = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Collisions-hitsandslaps/Hit5.raw"); -hitSounds[5] = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Collisions-hitsandslaps/Hit6.raw"); -hitSounds[6] = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Collisions-hitsandslaps/Hit7.raw"); -hitSounds[7] = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Collisions-hitsandslaps/Hit8.raw"); -hitSounds[8] = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Collisions-hitsandslaps/Hit9.raw"); -hitSounds[9] = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Collisions-hitsandslaps/Hit10.raw"); -hitSounds[10] = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Collisions-hitsandslaps/Hit11.raw"); -hitSounds[11] = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Collisions-hitsandslaps/Hit12.raw"); -hitSounds[12] = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Collisions-hitsandslaps/Hit13.raw"); -hitSounds[13] = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Collisions-hitsandslaps/Hit14.raw"); -hitSounds[14] = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Collisions-hitsandslaps/Hit15.raw"); -hitSounds[15] = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Collisions-hitsandslaps/Hit16.raw"); -hitSounds[16] = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Collisions-hitsandslaps/Hit17.raw"); -hitSounds[17] = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Collisions-hitsandslaps/Hit18.raw"); -hitSounds[18] = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Collisions-hitsandslaps/Hit19.raw"); -hitSounds[19] = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Collisions-hitsandslaps/Hit20.raw"); -hitSounds[20] = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Collisions-hitsandslaps/Hit21.raw"); -hitSounds[21] = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Collisions-hitsandslaps/Hit22.raw"); - -function playHitSound(mySessionID, theirSessionID, collision) { - var now = new Date(); - var msec = now.getTime(); - if (msec > soundExpiry) { - // this is a new contact --> play a new sound - var soundIndex = Math.floor((Math.random() * hitSounds.length) % hitSounds.length); - audioOptions.position = collision.contactPoint; - Audio.playSound(hitSounds[soundIndex], audioOptions); - - // bump the expiry - soundExpiry = msec + SOUND_TRIGGER_CLEAR; - - // log the collision info - Uuid.print("my sessionID = ", mySessionID); - Uuid.print(" their sessionID = ", theirSessionID); - Vec3.print(" penetration = ", collision.penetration); - Vec3.print(" contactPoint = ", collision.contactPoint); - } else { - // this is a recurring contact --> continue to delay sound trigger - soundExpiry = msec + SOUND_TRIGGER_DELAY; - } -} -MyAvatar.collisionWithAvatar.connect(playHitSound); diff --git a/examples/avatarLocalLight.js b/examples/avatarLocalLight.js deleted file mode 100644 index b1f31888d8..0000000000 --- a/examples/avatarLocalLight.js +++ /dev/null @@ -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); - diff --git a/examples/bot.js b/examples/bot.js deleted file mode 100644 index aadd038eb6..0000000000 --- a/examples/bot.js +++ /dev/null @@ -1,233 +0,0 @@ -// -// bot.js -// examples -// -// Created by Stephen Birarda on 2/20/14. -// Modified by Philip on 3/3/14 -// Copyright 2014 High Fidelity, Inc. -// -// This is an example script that demonstrates an NPC 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"); - -function getRandomFloat(min, max) { - return Math.random() * (max - min) + min; -} - -function getRandomInt (min, max) { - return Math.floor(Math.random() * (max - min + 1)) + min; -} - -function printVector(string, vector) { - print(string + " " + vector.x + ", " + vector.y + ", " + vector.z); -} - -var CHANCE_OF_MOVING = 0.005; -var CHANCE_OF_SOUND = 0.005; -var CHANCE_OF_HEAD_TURNING = 0.05; -var CHANCE_OF_BIG_MOVE = 0.1; -var CHANCE_OF_WAVING = 0.009; - -var shouldReceiveVoxels = true; -var VOXEL_FPS = 60.0; -var lastVoxelQueryTime = 0.0; - -var isMoving = false; -var isTurningHead = false; -var isPlayingAudio = false; -var isWaving = false; -var waveFrequency = 0.0; -var waveAmplitude = 0.0; - -var X_MIN = 5.0; -var X_MAX = 15.0; -var Z_MIN = 5.0; -var Z_MAX = 15.0; -var Y_PELVIS = 1.0; -var SPINE_JOINT_NUMBER = 13; -var SHOULDER_JOINT_NUMBER = 17; -var ELBOW_JOINT_NUMBER = 18; -var JOINT_R_HIP = 1; -var JOINT_R_KNEE = 2; - -var MOVE_RANGE_SMALL = 0.5; -var MOVE_RANGE_BIG = Math.max(X_MAX - X_MIN, Z_MAX - Z_MIN) / 2.0; -var TURN_RANGE = 70.0; -var STOP_TOLERANCE = 0.05; -var MOVE_RATE = 0.05; -var TURN_RATE = 0.15; -var PITCH_RATE = 0.20; -var PITCH_RANGE = 30.0; - -var firstPosition = { x: getRandomFloat(X_MIN, X_MAX), y: Y_PELVIS, z: getRandomFloat(Z_MIN, Z_MAX) }; -var targetPosition = { x: 0, y: 0, z: 0 }; -var targetDirection = { x: 0, y: 0, z: 0, w: 0 }; -var currentDirection = { x: 0, y: 0, z: 0, w: 0 }; -var targetHeadPitch = 0.0; - -var walkFrequency = 5.0; -var walkAmplitude = 45.0; - -var cumulativeTime = 0.0; - -var sounds = []; -loadSounds(); - -function clamp(val, min, max){ - return Math.max(min, Math.min(max, val)) -} - -// Play a random sound from a list of conversational audio clips -var AVERAGE_AUDIO_LENGTH = 8000; -function playRandomSound() { - if (!Agent.isPlayingAvatarSound) { - var whichSound = Math.floor((Math.random() * sounds.length) % sounds.length); - Agent.playAvatarSound(sounds[whichSound]); - } -} - -// pick an integer between 1 and 20 for the face model for this bot -botNumber = getRandomInt(1, 100); - -if (botNumber <= 20) { - newFaceFilePrefix = "bot" + botNumber; - newBodyFilePrefix = "defaultAvatar_body" -} else { - if (botNumber <= 40) { - newFaceFilePrefix = "superhero"; - } else if (botNumber <= 60) { - newFaceFilePrefix = "amber"; - } else if (botNumber <= 80) { - newFaceFilePrefix = "ron"; - } else { - newFaceFilePrefix = "angie"; - } - - newBodyFilePrefix = "bot" + botNumber; -} - -// set the face model fst using the bot number -// there is no need to change the body model - we're using the default -Avatar.faceModelURL = HIFI_PUBLIC_BUCKET + "meshes/" + newFaceFilePrefix + ".fst"; -Avatar.skeletonModelURL = HIFI_PUBLIC_BUCKET + "meshes/" + newBodyFilePrefix + ".fst"; -Avatar.billboardURL = HIFI_PUBLIC_BUCKET + "meshes/billboards/bot" + botNumber + ".png"; - -Agent.isAvatar = true; -Agent.isListeningToAudioStream = true; - -// change the avatar's position to the random one -Avatar.position = firstPosition; -printVector("New bot, position = ", Avatar.position); - -function stopWaving() { - isWaving = false; - Avatar.clearJointData(SHOULDER_JOINT_NUMBER); - Avatar.clearJointData(ELBOW_JOINT_NUMBER); - Avatar.clearJointData(SPINE_JOINT_NUMBER); -} - -function keepWalking() { - Avatar.setJointData(JOINT_R_HIP, Quat.fromPitchYawRollDegrees(walkAmplitude * Math.sin(cumulativeTime * walkFrequency), 0.0, 0.0)); - Avatar.setJointData(JOINT_R_KNEE, Quat.fromPitchYawRollDegrees(walkAmplitude * Math.sin(cumulativeTime * walkFrequency), 0.0, 0.0)); -} - -function stopWalking() { - Avatar.clearJointData(JOINT_R_HIP); - Avatar.clearJointData(JOINT_R_KNEE); -} - -function updateBehavior(deltaTime) { - - cumulativeTime += deltaTime; - - // Hack - right now you need to set the avatar position a bit after the avatar is made to make sure it's there. - - if (CHANCE_OF_MOVING == 0.000) { - Avatar.position = firstPosition; - } - - if (shouldReceiveVoxels && ((cumulativeTime - lastVoxelQueryTime) > (1.0 / VOXEL_FPS))) { - VoxelViewer.setPosition(Avatar.position); - VoxelViewer.setOrientation(Avatar.orientation); - VoxelViewer.queryOctree(); - lastVoxelQueryTime = cumulativeTime; - /* - if (Math.random() < (1.0 / VOXEL_FPS)) { - print("Voxels in view = " + VoxelViewer.getOctreeElementsCount()); - }*/ - } - - if (!isWaving && (Math.random() < CHANCE_OF_WAVING)) { - isWaving = true; - waveFrequency = 3.0 + Math.random() * 5.0; - waveAmplitude = 5.0 + Math.random() * 60.0; - Script.setTimeout(stopWaving, 1000 + Math.random() * 2000); - Avatar.setJointData(ELBOW_JOINT_NUMBER, Quat.fromPitchYawRollDegrees(0.0, 45, 0.0)); // Initially turn the palm outward - } else if (isWaving) { - Avatar.setJointData(SHOULDER_JOINT_NUMBER, Quat.fromPitchYawRollDegrees(0.0, 0.0, 60 + waveAmplitude * Math.sin((cumulativeTime - 0.25) * waveFrequency))); - Avatar.setJointData(ELBOW_JOINT_NUMBER, Quat.fromPitchYawRollDegrees(0.0, 0.0, 25 + waveAmplitude/2.0 * Math.sin(cumulativeTime * 1.2 * waveFrequency))); - Avatar.setJointData(SPINE_JOINT_NUMBER, Quat.fromPitchYawRollDegrees(0.0, 0.0, 60 + waveAmplitude/4.0 * Math.sin(cumulativeTime * waveFrequency))); - - } - - - if (Math.random() < CHANCE_OF_SOUND) { - playRandomSound(); - } - - if (!isTurningHead && (Math.random() < CHANCE_OF_HEAD_TURNING)) { - targetHeadPitch = getRandomFloat(-PITCH_RANGE, PITCH_RANGE); - isTurningHead = true; - } else { - Avatar.headPitch = Avatar.headPitch + (targetHeadPitch - Avatar.headPitch) * PITCH_RATE; - if (Math.abs(Avatar.headPitch - targetHeadPitch) < STOP_TOLERANCE) { - isTurningHead = false; - } - } - if (!isMoving && (Math.random() < CHANCE_OF_MOVING)) { - // Set new target location - targetDirection = Quat.multiply(Avatar.orientation, Quat.angleAxis(getRandomFloat(-TURN_RANGE, TURN_RANGE), { x:0, y:1, z:0 })); - var front = Quat.getFront(targetDirection); - if (Math.random() < CHANCE_OF_BIG_MOVE) { - targetPosition = Vec3.sum(Avatar.position, Vec3.multiply(front, getRandomFloat(0.0, MOVE_RANGE_BIG))); - } else { - targetPosition = Vec3.sum(Avatar.position, Vec3.multiply(front, getRandomFloat(0.0, MOVE_RANGE_SMALL))); - } - targetPosition.x = clamp(targetPosition.x, X_MIN, X_MAX); - targetPosition.z = clamp(targetPosition.z, Z_MIN, Z_MAX); - targetPosition.y = Y_PELVIS; - - isMoving = true; - } else if (isMoving) { - keepWalking(); - Avatar.position = Vec3.sum(Avatar.position, Vec3.multiply(Vec3.subtract(targetPosition, Avatar.position), MOVE_RATE)); - Avatar.orientation = Quat.mix(Avatar.orientation, targetDirection, TURN_RATE); - if (Vec3.length(Vec3.subtract(Avatar.position, targetPosition)) < STOP_TOLERANCE) { - isMoving = false; - stopWalking(); - } - } -} - -Script.update.connect(updateBehavior); - -function loadSounds() { - var sound_filenames = ["AB1.raw", "Anchorman2.raw", "B1.raw", "B1.raw", "Bale1.raw", "Bandcamp.raw", - "Big1.raw", "Big2.raw", "Brian1.raw", "Buster1.raw", "CES1.raw", "CES2.raw", "CES3.raw", "CES4.raw", - "Carrie1.raw", "Carrie3.raw", "Charlotte1.raw", "EN1.raw", "EN2.raw", "EN3.raw", "Eugene1.raw", "Francesco1.raw", - "Italian1.raw", "Japanese1.raw", "Leigh1.raw", "Lucille1.raw", "Lucille2.raw", "MeanGirls.raw", "Murray2.raw", - "Nigel1.raw", "PennyLane.raw", "Pitt1.raw", "Ricardo.raw", "SN.raw", "Sake1.raw", "Samantha1.raw", "Samantha2.raw", - "Spicoli1.raw", "Supernatural.raw", "Swearengen1.raw", "TheDude.raw", "Tony.raw", "Triumph1.raw", "Uma1.raw", - "Walken1.raw", "Walken2.raw", "Z1.raw", "Z2.raw" - ]; - - var SOUND_BASE_URL = HIFI_PUBLIC_BUCKET + "sounds/Cocktail+Party+Snippets/Raws/"; - - for (var i = 0; i < sound_filenames.length; i++) { - sounds.push(SoundCache.getSound(SOUND_BASE_URL + sound_filenames[i])); - } -} diff --git a/examples/gamepad.js b/examples/controllers/gamepad/gamepad.js similarity index 100% rename from examples/gamepad.js rename to examples/controllers/gamepad/gamepad.js diff --git a/examples/airGuitar.js b/examples/controllers/hydra/airGuitar.js similarity index 97% rename from examples/airGuitar.js rename to examples/controllers/hydra/airGuitar.js index 5a62ee3e7b..6d3d374f3a 100644 --- a/examples/airGuitar.js +++ b/examples/controllers/hydra/airGuitar.js @@ -10,7 +10,7 @@ // 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) { return Math.sqrt(v.x * v.x + v.y * v.y + v.z * v.z); @@ -73,7 +73,7 @@ var soundPlaying = false; var selectorPressed = false; var position; -MyAvatar.attach(guitarModel, "Hips", {x: -0.0, y: -0.0, z: 0.0}, Quat.fromPitchYawRollDegrees(0, 0, 0), 1.0); +MyAvatar.attach(guitarModel, "Hips", {x: -0.2, y: 0.0, z: 0.1}, Quat.fromPitchYawRollDegrees(90, 00, 90), 1.0); function checkHands(deltaTime) { for (var palm = 0; palm < 2; palm++) { diff --git a/examples/drumStick.js b/examples/controllers/hydra/drumStick.js similarity index 98% rename from examples/drumStick.js rename to examples/controllers/hydra/drumStick.js index 88ffa36c50..14e1413742 100644 --- a/examples/drumStick.js +++ b/examples/controllers/hydra/drumStick.js @@ -10,7 +10,7 @@ // 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) { return Math.sqrt(v.x * v.x + v.y * v.y + v.z * v.z); diff --git a/examples/frisbee.js b/examples/controllers/hydra/frisbee.js similarity index 95% rename from examples/frisbee.js rename to examples/controllers/hydra/frisbee.js index 2d60827858..a9fd74910d 100644 --- a/examples/frisbee.js +++ b/examples/controllers/hydra/frisbee.js @@ -15,8 +15,8 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -Script.include("libraries/globals.js"); -Script.include("libraries/toolBars.js"); +Script.include("../../libraries/globals.js"); +Script.include("../../libraries/toolBars.js"); const LEFT_PALM = 0; const LEFT_TIP = 1; @@ -192,15 +192,18 @@ function cleanupFrisbees() { } function checkControllerSide(hand) { + // print("cCS"); // If I don't currently have a frisbee in my hand, then try to catch closest one if (!hand.holdingFrisbee && hand.grabButtonPressed()) { var closestEntity = Entities.findClosestEntity(hand.palmPosition(), CATCH_RADIUS); var modelUrl = Entities.getEntityProperties(closestEntity).modelURL; + print("lol2"+closestEntity.isKnownID); if (closestEntity.isKnownID && validFrisbeeURL(Entities.getEntityProperties(closestEntity).modelURL)) { + print("lol"); Entities.editEntity(closestEntity, {modelScale: 1, inHand: true, position: hand.holdPosition(), shouldDie: true}); Entities.deleteEntity(closestEntity); debugPrint(hand.message + " HAND- CAUGHT SOMETHING!!"); - + print("lol"); var properties = { type: "Model", position: hand.holdPosition(), @@ -208,10 +211,10 @@ function checkControllerSide(hand) { gravity: { x: 0, y: 0, z: 0}, inHand: true, dimensions: { x: FRISBEE_RADIUS, y: FRISBEE_RADIUS / 5, z: FRISBEE_RADIUS }, - damping: 0.00001, + damping: 0.999, modelURL: modelUrl, - modelScale: FRISBEE_MODEL_SCALE, - modelRotation: hand.holdRotation(), + scale: FRISBEE_MODEL_SCALE, + rotation: hand.holdRotation(), lifetime: FRISBEE_LIFETIME }; @@ -235,10 +238,10 @@ function checkControllerSide(hand) { gravity: { x: 0, y: 0, z: 0}, inHand: true, dimensions: { x: FRISBEE_RADIUS, y: FRISBEE_RADIUS / 5, z: FRISBEE_RADIUS }, - damping: 0.00001, + damping: 0, modelURL: frisbeeURL(), - modelScale: FRISBEE_MODEL_SCALE, - modelRotation: hand.holdRotation(), + scale: FRISBEE_MODEL_SCALE, + rotation: hand.holdRotation(), lifetime: FRISBEE_LIFETIME }; @@ -270,7 +273,7 @@ function checkControllerSide(hand) { inHand: false, lifetime: FRISBEE_LIFETIME, gravity: { x: 0, y: -GRAVITY_STRENGTH, z: 0}, - modelRotation: hand.holdRotation() + rotation: hand.holdRotation() }; Entities.editEntity(hand.entity, properties); @@ -304,7 +307,7 @@ function hydraCheck() { var numberOfSpatialControls = Controller.getNumberOfSpatialControls(); var controllersPerTrigger = numberOfSpatialControls / numberOfTriggers; hydrasConnected = (numberOfButtons == 12 && numberOfTriggers == 2 && controllersPerTrigger == 2); - return hydrasConnected; + return true;//hydrasConnected; } function checkController(deltaTime) { @@ -314,6 +317,7 @@ function checkController(deltaTime) { } // this is expected for hydras if (hydraCheck()) { +///print("testrr "); checkControllerSide(leftHand); checkControllerSide(rightHand); } @@ -333,7 +337,7 @@ function controlFrisbees(deltaTime) { killSimulations.push(frisbee); 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--) { @@ -444,4 +448,4 @@ Controller.mouseReleaseEvent.connect(mouseReleaseEvent); Menu.menuItemEvent.connect(menuItemEvent); Script.scriptEnding.connect(scriptEnding); Script.update.connect(checkController); -Script.update.connect(controlFrisbees); +Script.update.connect(controlFrisbees); \ No newline at end of file diff --git a/examples/grenadeLauncher.js b/examples/controllers/hydra/gun.js similarity index 90% rename from examples/grenadeLauncher.js rename to examples/controllers/hydra/gun.js index b0f04fec9a..de18317335 100644 --- a/examples/grenadeLauncher.js +++ b/examples/controllers/hydra/gun.js @@ -1,20 +1,20 @@ // -// grenadeLauncher.js +// gun.js // examples -// Created by Ben Arnold on 7/11/14. -// This is a modified version of gun.js by Brad Hefta-Gaub. // +// Created by Brad Hefta-Gaub on 12/31/13. +// 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 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. +// 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 // -Script.include("libraries/globals.js"); +Script.include("../../libraries/globals.js"); function getRandomFloat(min, max) { return Math.random() * (max - min) + min; @@ -26,10 +26,9 @@ var yawFromMouse = 0; var pitchFromMouse = 0; var isMouseDown = false; -var BULLET_VELOCITY = 3.0; +var BULLET_VELOCITY = 5.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; @@ -44,7 +43,7 @@ var targetLaunchSound = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Space%2 var gunModel = "http://public.highfidelity.io/models/attachments/HaloGun.fst"; -var audioOptions { +var audioOptions = { volume: 0.9 } @@ -89,24 +88,24 @@ if (showScore) { }); } + + 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 + var BULLET_SIZE = 0.01; + var BULLET_LIFETIME = 20.0; + var BULLET_GRAVITY = -0.02; Entities.addEntity( { type: "Sphere", position: position, - collisionsWillMove: true, - dimensions: { x: BULLET_SIZE, y: BULLET_SIZE, z: BULLET_SIZE }, + dimensions: { x: BULLET_SIZE, y: BULLET_SIZE, z: BULLET_SIZE }, color: { red: 10, green: 10, blue: 10 }, velocity: velocity, + lifetime: BULLET_LIFETIME, gravity: { x: 0, y: BULLET_GRAVITY, z: 0 }, - lifetime: 10.0, damping: 0 }); // Play firing sounds @@ -121,6 +120,7 @@ function shootBullet(position, velocity) { function shootTarget() { var TARGET_SIZE = 0.25; var TARGET_GRAVITY = -0.6; + var TARGET_LIFETIME = 300.0; var TARGET_UP_VELOCITY = 3.0; var TARGET_FWD_VELOCITY = 5.0; var DISTANCE_TO_LAUNCH_FROM = 3.0; @@ -139,12 +139,11 @@ function shootTarget() { Entities.addEntity( { type: "Sphere", position: newPosition, - collisionsWillMove: true, - dimensions: { x: TARGET_SIZE, y: TARGET_SIZE, z: TARGET_SIZE }, + 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, + lifetime: TARGET_LIFETIME, damping: 0.0001 }); // Record start time @@ -155,11 +154,15 @@ function shootTarget() { Audio.playSound(targetLaunchSound, audioOptions); } + + function entityCollisionWithEntity(entity1, entity2, collision) { score++; if (showScore) { Overlays.editOverlay(text, { text: "Score: " + score } ); } + + // Sort out which entity is which // Record shot time var endTime = new Date(); @@ -191,21 +194,20 @@ function playLoadSound() { 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); +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); // 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 + // Check for mouseLook movement, update rotation + // rotate body yaw for yaw received from 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 + // apply pitch from mouse var newPitch = MyAvatar.headPitch + pitchFromMouse; MyAvatar.headPitch = newPitch; pitchFromMouse = 0; @@ -231,7 +233,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) { @@ -245,8 +246,8 @@ function update(deltaTime) { } } + if (shootABullet) { - var palmController = t * controllersPerTrigger; var palmPosition = Controller.getSpatialControlPosition(palmController); @@ -298,8 +299,7 @@ function mouseReleaseEvent(event) { } function mouseMoveEvent(event) { - //Move the camera if LEFT_BUTTON_1 is pressed - if (Controller.isButtonPressed(LEFT_BUTTON_1)) { + if (isMouseDown) { var MOUSE_YAW_SCALE = -0.25; var MOUSE_PITCH_SCALE = -12.5; var FIXED_MOUSE_TIMESTEP = 0.016; diff --git a/examples/laserPointer.js b/examples/controllers/hydra/laserPointer.js similarity index 100% rename from examples/laserPointer.js rename to examples/controllers/hydra/laserPointer.js diff --git a/examples/squeezeHands.js b/examples/controllers/hydra/squeezeHands.js similarity index 98% rename from examples/squeezeHands.js rename to examples/controllers/hydra/squeezeHands.js index 21da7f9c25..84e5aefb51 100644 --- a/examples/squeezeHands.js +++ b/examples/controllers/hydra/squeezeHands.js @@ -9,7 +9,7 @@ // 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 leftHandAnimation = HIFI_PUBLIC_BUCKET + "animations/LeftHandAnimPhilip.fbx"; diff --git a/examples/toyball.js b/examples/controllers/hydra/toyball.js similarity index 99% rename from examples/toyball.js rename to examples/controllers/hydra/toyball.js index 2cda1fa82a..4dc65703b7 100644 --- a/examples/toyball.js +++ b/examples/controllers/hydra/toyball.js @@ -15,7 +15,7 @@ // 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"); // maybe we should make these constants... var LEFT_PALM = 0; diff --git a/examples/controllers/leap/laserPointer.js b/examples/controllers/leap/laserPointer.js new file mode 100644 index 0000000000..156e9ba298 --- /dev/null +++ b/examples/controllers/leap/laserPointer.js @@ -0,0 +1,93 @@ +// +// laserPointer.js +// examples +// +// Created by Clément Brisset on 7/18/14. +// Copyright 2014 High Fidelity, Inc. +// +// If using Hydra controllers, pulling the triggers makes laser pointers emanate from the respective hands. +// If using a Leap Motion or similar to control your avatar's hands and fingers, pointing with your index fingers makes +// laser pointers emanate from the respective index fingers. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +var laserPointer = (function () { + + var NUM_FINGERs = 4, // Excluding thumb + fingers = [ + [ "LeftHandIndex", "LeftHandMiddle", "LeftHandRing", "LeftHandPinky" ], + [ "RightHandIndex", "RightHandMiddle", "RightHandRing", "RightHandPinky" ] + ]; + + function isHandPointing(hand) { + var MINIMUM_TRIGGER_PULL = 0.9; + return Controller.getTriggerValue(hand) > MINIMUM_TRIGGER_PULL; + } + + function isFingerPointing(hand) { + // Index finger is pointing if final two bones of middle, ring, and pinky fingers are > 90 degrees w.r.t. index finger + + var pointing, + indexDirection, + otherDirection, + f; + + pointing = true; + + indexDirection = Vec3.subtract( + MyAvatar.getJointPosition(fingers[hand][0] + "4"), + MyAvatar.getJointPosition(fingers[hand][0] + "2") + ); + + for (f = 1; f < NUM_FINGERs; f += 1) { + otherDirection = Vec3.subtract( + MyAvatar.getJointPosition(fingers[hand][f] + "4"), + MyAvatar.getJointPosition(fingers[hand][f] + "2") + ); + pointing = pointing && Vec3.dot(indexDirection, otherDirection) < 0; + } + + return pointing; + } + + function update() { + var LEFT_HAND = 0, + RIGHT_HAND = 1, + LEFT_HAND_POINTING_FLAG = 1, + RIGHT_HAND_POINTING_FLAG = 2, + FINGER_POINTING_FLAG = 4, + handState; + + handState = 0; + + if (isHandPointing(LEFT_HAND)) { + handState += LEFT_HAND_POINTING_FLAG; + } + if (isHandPointing(RIGHT_HAND)) { + handState += RIGHT_HAND_POINTING_FLAG; + } + + if (handState === 0) { + if (isFingerPointing(LEFT_HAND)) { + handState += LEFT_HAND_POINTING_FLAG; + } + if (isFingerPointing(RIGHT_HAND)) { + handState += RIGHT_HAND_POINTING_FLAG; + } + if (handState !== 0) { + handState += FINGER_POINTING_FLAG; + } + } + + MyAvatar.setHandState(handState); + } + + return { + update: update + }; + +}()); + +Script.update.connect(laserPointer.update); diff --git a/examples/leapHands.js b/examples/controllers/leap/leapHands.js similarity index 100% rename from examples/leapHands.js rename to examples/controllers/leap/leapHands.js diff --git a/examples/leapOfFaith.js b/examples/controllers/leap/leapOfFaith.js similarity index 100% rename from examples/leapOfFaith.js rename to examples/controllers/leap/leapOfFaith.js diff --git a/examples/virtualKeyboard.js b/examples/controllers/oculus/virtualKeyboard.js similarity index 99% rename from examples/virtualKeyboard.js rename to examples/controllers/oculus/virtualKeyboard.js index ce793c6ea0..dc3c2eb3cc 100644 --- a/examples/virtualKeyboard.js +++ b/examples/controllers/oculus/virtualKeyboard.js @@ -15,7 +15,7 @@ // 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_LOWERCASE_DEFAULT = 1; diff --git a/examples/editEntities.js b/examples/editEntities.js index 632fed088c..b65756e9b4 100644 --- a/examples/editEntities.js +++ b/examples/editEntities.js @@ -42,7 +42,15 @@ gridTool = GridTool({ horizontalGrid: grid }); Script.include("libraries/entityList.js"); var entityListTool = EntityListTool(); -selectionManager.addEventListener(selectionDisplay.updateHandles); +var hasShownPropertiesTool = false; + +selectionManager.addEventListener(function() { + selectionDisplay.updateHandles(); + if (selectionManager.hasSelection() && !hasShownPropertiesTool) { + propertiesTool.setVisible(true); + hasShownPropertiesTool = true; + } +}); var windowDimensions = Controller.getViewportDimensions(); var toolIconUrl = HIFI_PUBLIC_BUCKET + "images/tools/"; @@ -77,7 +85,6 @@ var modelURLs = [ 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:%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-Shed2.fbx", HIFI_PUBLIC_BUCKET + "models/entities/3-Buildings-1-Rustic-Shed4.fbx", @@ -192,8 +199,7 @@ var toolBar = (function () { }); newTextButton = toolBar.addTool({ - //imageURL: toolIconUrl + "add-text.svg", - imageURL: "https://s3-us-west-1.amazonaws.com/highfidelity-public/images/tools/add-text.svg", // temporarily + imageURL: toolIconUrl + "add-text.svg", subImage: { x: 0, y: Tool.IMAGE_WIDTH, width: Tool.IMAGE_WIDTH, height: Tool.IMAGE_HEIGHT }, width: toolWidth, height: toolHeight, @@ -225,10 +231,9 @@ var toolBar = (function () { selectionManager.clearSelections(); cameraManager.disable(); } else { + hasShownPropertiesTool = false; cameraManager.enable(); - entityListTool.setVisible(true); gridTool.setVisible(true); - propertiesTool.setVisible(true); grid.setEnabled(true); } } diff --git a/examples/editModels.js b/examples/editModels.js index 8ec099650a..7cb911b490 100644 --- a/examples/editModels.js +++ b/examples/editModels.js @@ -56,7 +56,6 @@ var modelURLs = [ 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:%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-Shed2.fbx", HIFI_PUBLIC_BUCKET + "models/entities/3-Buildings-1-Rustic-Shed4.fbx", @@ -1215,8 +1214,7 @@ var toolBar = (function () { }); newTextButton = toolBar.addTool({ - //imageURL: toolIconUrl + "add-text.svg", - imageURL: "https://s3-us-west-1.amazonaws.com/highfidelity-public/images/tools/add-text.svg", // temporarily + imageURL: toolIconUrl + "add-text.svg", subImage: { x: 0, y: Tool.IMAGE_WIDTH, width: Tool.IMAGE_WIDTH, height: Tool.IMAGE_HEIGHT }, width: toolWidth, height: toolHeight, diff --git a/examples/entityBirds.js b/examples/entityBirds.js deleted file mode 100644 index 9512597af9..0000000000 --- a/examples/entityBirds.js +++ /dev/null @@ -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); diff --git a/examples/audioBall.js b/examples/example/audio/audioBall.js similarity index 98% rename from examples/audioBall.js rename to examples/example/audio/audioBall.js index e0c0ce7976..91ef7c0759 100644 --- a/examples/audioBall.js +++ b/examples/example/audio/audioBall.js @@ -13,7 +13,7 @@ // 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 CHANCE_OF_PLAYING_SOUND = 0.01; diff --git a/examples/example/audioDeviceExample.js b/examples/example/audio/audioDeviceExample.js similarity index 100% rename from examples/example/audioDeviceExample.js rename to examples/example/audio/audioDeviceExample.js diff --git a/examples/example/audioMuteExample.js b/examples/example/audio/audioMuteExample.js similarity index 100% rename from examples/example/audioMuteExample.js rename to examples/example/audio/audioMuteExample.js diff --git a/examples/audioReverbOn.js b/examples/example/audio/audioReverbOn.js similarity index 91% rename from examples/audioReverbOn.js rename to examples/example/audio/audioReverbOn.js index 479f5bba74..72f2fa97bc 100644 --- a/examples/audioReverbOn.js +++ b/examples/example/audio/audioReverbOn.js @@ -4,6 +4,10 @@ // // Copyright 2014 High Fidelity, Inc. // +// +// Gives the ability to be set various reverb settings. +// +// // Distributed under the Apache License, Version 2.0. // 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, // Seconds - reverbTime: 4, + reverbTime: 10, // Between 0 - 1 damping: 0.50, diff --git a/examples/birdSongs.js b/examples/example/audio/birdSongs.js similarity index 100% rename from examples/birdSongs.js rename to examples/example/audio/birdSongs.js diff --git a/examples/example/radio.js b/examples/example/audio/radio.js similarity index 98% rename from examples/example/radio.js rename to examples/example/audio/radio.js index e8300c00b5..39409df377 100644 --- a/examples/example/radio.js +++ b/examples/example/audio/radio.js @@ -9,7 +9,7 @@ // 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 soundURL = HIFI_PUBLIC_BUCKET + "sounds/family.stereo.raw"; diff --git a/examples/speechControl.js b/examples/example/audio/speechControl.js similarity index 100% rename from examples/speechControl.js rename to examples/example/audio/speechControl.js diff --git a/examples/example/cameraExample.js b/examples/example/avatarcontrol/cameraExample.js similarity index 100% rename from examples/example/cameraExample.js rename to examples/example/avatarcontrol/cameraExample.js diff --git a/examples/example/controllerExample.js b/examples/example/avatarcontrol/controllerExample.js similarity index 100% rename from examples/example/controllerExample.js rename to examples/example/avatarcontrol/controllerExample.js diff --git a/examples/guidedTour.js b/examples/example/avatarcontrol/guidedTour.js similarity index 100% rename from examples/guidedTour.js rename to examples/example/avatarcontrol/guidedTour.js diff --git a/examples/example/hideAvatarExample.js b/examples/example/avatarcontrol/hideAvatarExample.js similarity index 96% rename from examples/example/hideAvatarExample.js rename to examples/example/avatarcontrol/hideAvatarExample.js index 66d85becf1..856a8b3c69 100644 --- a/examples/example/hideAvatarExample.js +++ b/examples/example/avatarcontrol/hideAvatarExample.js @@ -12,7 +12,7 @@ // function keyReleaseEvent(event) { - if (event.text == "F2") { + if (event.text == "r") { MyAvatar.shouldRenderLocally = !MyAvatar.shouldRenderLocally; } } diff --git a/examples/example/lookAtExample.js b/examples/example/avatarcontrol/lookAtExample.js similarity index 93% rename from examples/example/lookAtExample.js rename to examples/example/avatarcontrol/lookAtExample.js index 7e3010eb8a..e21341469d 100644 --- a/examples/example/lookAtExample.js +++ b/examples/example/avatarcontrol/lookAtExample.js @@ -8,8 +8,8 @@ // This is an example script that demonstrates use of the Camera class's lookAt(), keepLookingAt(), and stopLookingAt() // features. // -// To use the script, click on a voxel, and the camera will switch into independent mode and fix it's lookAt on the point -// on the face of the voxel that you clicked. Click again and it will stop looking at that point. While in this fixed mode +// To use the script, click on a entity, and the camera will switch into independent mode and fix it's lookAt on the point +// on the face of the entity that you clicked. Click again and it will stop looking at that point. While in this fixed mode // you can use the arrow keys to change the position of the camera. // // Distributed under the Apache License, Version 2.0. diff --git a/examples/example/multipleCursorsExample.js b/examples/example/avatarcontrol/multipleCursorsExample.js similarity index 100% rename from examples/example/multipleCursorsExample.js rename to examples/example/avatarcontrol/multipleCursorsExample.js diff --git a/examples/example/multitouchExample.js b/examples/example/avatarcontrol/multitouchExample.js similarity index 100% rename from examples/example/multitouchExample.js rename to examples/example/avatarcontrol/multitouchExample.js diff --git a/examples/example/animationStateExample.js b/examples/example/entities/ZZZ-MOVE-TO_DOCS-animationStateExample.js similarity index 100% rename from examples/example/animationStateExample.js rename to examples/example/entities/ZZZ-MOVE-TO_DOCS-animationStateExample.js diff --git a/examples/example/animatedModelExample.js b/examples/example/entities/animatedModelExample.js similarity index 91% rename from examples/example/animatedModelExample.js rename to examples/example/entities/animatedModelExample.js index 3fffdc88d2..00790fecc8 100644 --- a/examples/example/animatedModelExample.js +++ b/examples/example/entities/animatedModelExample.js @@ -12,7 +12,7 @@ // var count = 0; -var moveUntil = 6000; +var moveUntil = 1000; var stopAfter = moveUntil + 100; var pitch = 0.0; @@ -25,16 +25,19 @@ var originalProperties = { position: { x: MyAvatar.position.x, y: MyAvatar.position.y, z: MyAvatar.position.z }, - - radius : 1, + dimensions: { + x: 1.62, + y: 0.41, + z: 1.13 + }, color: { red: 0, green: 255, blue: 0 }, - modelURL: "http://www.fungibleinsight.com/faces/beta.fst", + modelURL: "http://public.highfidelity.io/cozza13/club/dragon/dragon.fbx", rotation: rotation, - animationURL: "http://www.fungibleinsight.com/faces/gangnam_style_2.fbx", + animationURL: "http://public.highfidelity.io/cozza13/club/dragon/flying.fbx", animationIsPlaying: true, }; diff --git a/examples/butterflies.js b/examples/example/entities/butterflies.js similarity index 95% rename from examples/butterflies.js rename to examples/example/entities/butterflies.js index 6eaa4ba66d..336e128d83 100644 --- a/examples/butterflies.js +++ b/examples/example/entities/butterflies.js @@ -82,9 +82,9 @@ function addButterfly() { damping: 0.00001, dimensions: dimensions, 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}", - 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)); } diff --git a/examples/example/collidingEntities.js b/examples/example/entities/collidingEntities.js similarity index 96% rename from examples/example/collidingEntities.js rename to examples/example/entities/collidingEntities.js index 233626df23..37c35e971d 100644 --- a/examples/example/collidingEntities.js +++ b/examples/example/entities/collidingEntities.js @@ -64,7 +64,7 @@ function draw(deltaTime) { y: 1, z: 0 }; - var entitySize = 0.1; + var entitySize = 1.1; print("number of entitys=" + numberEntitiesAdded +"\n"); @@ -99,7 +99,7 @@ function draw(deltaTime) { Script.stop(); } - print("Particles Stats: " + Entities.getLifetimeInSeconds() + " seconds," + + print("Entity Stats: " + Entities.getLifetimeInSeconds() + " seconds," + " Queued packets:" + Entities.getLifetimePacketsQueued() + "," + " PPS:" + Entities.getLifetimePPSQueued() + "," + " BPS:" + Entities.getLifetimeBPSQueued() + "," + diff --git a/examples/example/editEntityExample.js b/examples/example/entities/editEntityExample.js similarity index 92% rename from examples/example/editEntityExample.js rename to examples/example/entities/editEntityExample.js index 422e50b1eb..96132ad471 100644 --- a/examples/example/editEntityExample.js +++ b/examples/example/entities/editEntityExample.js @@ -5,7 +5,7 @@ // Created by Brad Hefta-Gaub on 12/31/13. // Copyright 2014 High Fidelity, Inc. // -// This is an example script that demonstrates creating and editing a particle +// This is an example script that demonstrates creating and editing a particle. Go to the origin of the domain to see the results (0,0,0). // // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html @@ -29,6 +29,11 @@ var originalProperties = { gravity: { x: 0, y: 0, z: 0 }, + dimensions: { + x: 1, + y: 1, + z: 1 + }, color: { red: 0, @@ -74,7 +79,6 @@ function moveEntity(deltaTime) { y: originalProperties.position.y + (count * positionDelta.y), z: originalProperties.position.z + (count * positionDelta.z) }, - radius : 0.25, }; diff --git a/examples/example/editModelExample.js b/examples/example/entities/editModelExample.js similarity index 78% rename from examples/example/editModelExample.js rename to examples/example/entities/editModelExample.js index 5a4efc0746..474d9afe26 100644 --- a/examples/example/editModelExample.js +++ b/examples/example/entities/editModelExample.js @@ -11,7 +11,7 @@ // 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 moveUntil = 2000; @@ -23,22 +23,22 @@ var roll = 180.0; var rotation = Quat.fromPitchYawRollDegrees(pitch, yaw, roll) var originalProperties = { +type: "Model", position: { x: 2.0, y: 2.0, z: 0.5 }, - radius : 0.25, - - color: { red: 0, + dimensions: { + x: 2.16, + y: 3.34, + z: 0.54 + }, + color: { red: 0, green: 255, blue: 0 }, modelURL: HIFI_PUBLIC_BUCKET + "meshes/Feisar_Ship.FBX", - //modelURL: HIFI_PUBLIC_BUCKET + "meshes/birarda/birarda_head.fbx", - //modelURL: HIFI_PUBLIC_BUCKET + "meshes/pug.fbx", - //modelURL: HIFI_PUBLIC_BUCKET + "meshes/newInvader16x16-large-purple.svo", - //modelURL: HIFI_PUBLIC_BUCKET + "meshes/minotaur/mino_full.fbx", - //modelURL: HIFI_PUBLIC_BUCKET + "meshes/Combat_tank_V01.FBX", + rotation: rotation }; @@ -67,10 +67,10 @@ function moveEntity(deltaTime) { return; // break early } - //print("count =" + count); + print("count =" + count); count++; - //print("entityID.creatorTokenID = " + entityID.creatorTokenID); + print("entityID.creatorTokenID = " + entityID.creatorTokenID); var newProperties = { position: { diff --git a/examples/example/entityModelExample.js b/examples/example/entities/entityModelExample.js similarity index 75% rename from examples/example/entityModelExample.js rename to examples/example/entities/entityModelExample.js index 067032fc6b..d09a349cb0 100644 --- a/examples/example/entityModelExample.js +++ b/examples/example/entities/entityModelExample.js @@ -11,30 +11,25 @@ // 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 stopAfter = 100; +var stopAfter = 1000; var modelPropertiesA = { type: "Model", position: { x: 1, y: 1, z: 1 }, velocity: { x: 0.5, y: 0, z: 0.5 }, damping: 0, - dimensions: { x: 0.5, y: 0.5, z: 0.5 }, + dimensions: { + x: 2.16, + y: 3.34, + z: 0.54 + }, modelURL: HIFI_PUBLIC_BUCKET + "meshes/Feisar_Ship.FBX", lifetime: 20 }; -var modelPropertiesB = { - type: "Model", - position: { x: 1, y: 1.5, z: 1 }, - velocity: { x: 0.5, y: 0, z: 0.5 }, - damping: 0, - dimensions: { x: 0.5, y: 0.5, z: 0.5 }, - modelURL: HIFI_PUBLIC_BUCKET + "meshes/orc.fbx", - lifetime: 20 -}; var ballProperties = { type: "Sphere", @@ -47,7 +42,6 @@ var ballProperties = { }; var modelAEntityID = Entities.addEntity(modelPropertiesA); -var modelBEntityID = Entities.addEntity(modelPropertiesB); var ballEntityID = Entities.addEntity(ballProperties); function endAfterAWhile(deltaTime) { diff --git a/examples/example/findEntitiesExample.js b/examples/example/entities/findEntitiesExample.js similarity index 100% rename from examples/example/findEntitiesExample.js rename to examples/example/entities/findEntitiesExample.js diff --git a/examples/flockingBirds.js b/examples/example/entities/flockingBirds.js similarity index 99% rename from examples/flockingBirds.js rename to examples/example/entities/flockingBirds.js index fd59b20c48..b07e7cf4bd 100644 --- a/examples/flockingBirds.js +++ b/examples/example/entities/flockingBirds.js @@ -5,7 +5,7 @@ // Created by Brad Hefta-Gaub on 3/4/14. // Copyright 2014 High Fidelity, Inc. // -// This is an example script that generates particles that act like flocking birds +// This is an example script that generates entities that act like flocking birds // // All birds, even flying solo... // birds don't like to fall too fast diff --git a/examples/example/lightExample.js b/examples/example/entities/lightExample.js similarity index 98% rename from examples/example/lightExample.js rename to examples/example/entities/lightExample.js index 7a90eb8714..58495a02f4 100644 --- a/examples/example/lightExample.js +++ b/examples/example/entities/lightExample.js @@ -27,7 +27,7 @@ var lightID = Entities.addEntity({ angularVelocity: { x: 0, y: 0, z: 0 }, angularDamping: 0, - isSpotlight: false, + isSpotlight: true, diffuseColor: { red: 255, green: 255, blue: 0 }, ambientColor: { red: 0, green: 0, blue: 0 }, specularColor: { red: 255, green: 255, blue: 255 }, diff --git a/examples/example/rideAlongWithAnEntityExample.js b/examples/example/entities/rideAlongWithAnEntityExample.js similarity index 100% rename from examples/example/rideAlongWithAnEntityExample.js rename to examples/example/entities/rideAlongWithAnEntityExample.js diff --git a/examples/example/spotlightExample.js b/examples/example/entities/spotlightExample.js similarity index 100% rename from examples/example/spotlightExample.js rename to examples/example/entities/spotlightExample.js diff --git a/examples/example/cleanupChessboards.js b/examples/example/games/cleanupChessboards.js similarity index 100% rename from examples/example/cleanupChessboards.js rename to examples/example/games/cleanupChessboards.js diff --git a/examples/example/clonedOverlaysExample.js b/examples/example/games/clonedOverlaysExample.js similarity index 97% rename from examples/example/clonedOverlaysExample.js rename to examples/example/games/clonedOverlaysExample.js index 7aea048175..aa475ee518 100644 --- a/examples/example/clonedOverlaysExample.js +++ b/examples/example/games/clonedOverlaysExample.js @@ -15,10 +15,10 @@ const NUM_OF_TREES = 40; const NUM_OF_SANTAS = 20; // Image source: https://openclipart.org/detail/447/christmas-tree-by-theresaknott (heavily edited by Maximillian Merlin) -const CHRISTMAS_TREE_SPRITES_URL = "http://test.thoys.nl/hifi/images/santa/christmas-tree.svg"; +const CHRISTMAS_TREE_SPRITES_URL = "https://s3.amazonaws.com/hifi-public/models/props/xmas/christmas-tree.svg"; // Image source: http://opengameart.org/content/santa-claus (CC-BY 3.0) -const SANTA_SPRITES_URL = "http://test.thoys.nl/hifi/images/santa/Santa.png"; +const SANTA_SPRITES_URL = "https://s3.amazonaws.com/hifi-public/models/props/xmas/Santa.png"; Array.prototype.contains = function(obj) { var i = this.length; diff --git a/examples/example/playChess.js b/examples/example/games/playChess.js similarity index 100% rename from examples/example/playChess.js rename to examples/example/games/playChess.js diff --git a/examples/example/spaceInvadersExample.js b/examples/example/games/spaceInvadersExample.js similarity index 96% rename from examples/example/spaceInvadersExample.js rename to examples/example/games/spaceInvadersExample.js index 832efe7e75..5ad8bbe4f6 100644 --- a/examples/example/spaceInvadersExample.js +++ b/examples/example/games/spaceInvadersExample.js @@ -11,7 +11,7 @@ // 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; @@ -59,7 +59,7 @@ var middleY = gameAt.y + (gameSize.y/2); var invaderSize = 0.4; var shipSize = 0.25; -var missileSize = 0.1; +var missileSize = 1.0; var myShip; var myShipProperties; @@ -101,27 +101,27 @@ var soundInMyHead = true; // models... var invaderModels = new Array(); invaderModels[0] = { - modelURL: HIFI_PUBLIC_BUCKET + "meshes/newInvader16x16-large-purple.svo", + modelURL: HIFI_PUBLIC_BUCKET + "meshes/space_invader.fbx", modelScale: 450, modelTranslation: { x: -1.3, y: -1.3, z: -1.3 }, }; invaderModels[1] = { - modelURL: HIFI_PUBLIC_BUCKET + "meshes/newInvader16x16-large-cyan.svo", + modelURL: HIFI_PUBLIC_BUCKET + "meshes/space_invader.fbx", modelScale: 450, modelTranslation: { x: -1.3, y: -1.3, z: -1.3 }, }; invaderModels[2] = { - modelURL: HIFI_PUBLIC_BUCKET + "meshes/newInvader16x16-medium-cyan.svo", + modelURL: HIFI_PUBLIC_BUCKET + "meshes/space_invader.fbx", modelScale: 450, modelTranslation: { x: -1.3, y: -1.3, z: -1.3 }, }; invaderModels[3] = { - modelURL: HIFI_PUBLIC_BUCKET + "meshes/newInvader16x16-medium-green.svo", + modelURL: HIFI_PUBLIC_BUCKET + "meshes/space_invader.fbx", modelScale: 450, modelTranslation: { x: -1.3, y: -1.3, z: -1.3 }, }; invaderModels[4] = { - modelURL: HIFI_PUBLIC_BUCKET + "meshes/newInvader16x16-small-green.svo", + modelURL: HIFI_PUBLIC_BUCKET + "meshes/space_invader.fbx", modelScale: 450, modelTranslation: { x: -1.3, y: -1.3, z: -1.3 }, }; @@ -141,7 +141,7 @@ function initializeMyShip() { damping: 0, dimensions: { x: shipSize * 2, y: shipSize * 2, z: shipSize * 2 }, color: { red: 0, green: 255, blue: 0 }, - modelURL: HIFI_PUBLIC_BUCKET + "meshes/myCannon16x16.svo", + modelURL: HIFI_PUBLIC_BUCKET + "meshes/space_invader.fbx", lifetime: itemLifetimes }; myShip = Entities.addEntity(myShipProperties); @@ -360,7 +360,7 @@ function keyPressEvent(key) { myShipProperties.position.x = gameAt.x + gameSize.x; } moveShipTo(myShipProperties.position); - } else if (key.text == " ") { + } else if (key.text == "f") { fireMissile(); } else if (key.text == "q") { endGame(); diff --git a/examples/example/globalCollisionsExample.js b/examples/example/globalCollisionsExample.js index 426aebd5d9..5813cb2472 100644 --- a/examples/example/globalCollisionsExample.js +++ b/examples/example/globalCollisionsExample.js @@ -14,13 +14,6 @@ print("hello..."); -function entityCollisionWithVoxel(entity, voxel, collision) { - print("entityCollisionWithVoxel().."); - print(" entity.getID()=" + entity.id); - print(" voxel color...=" + voxel.red + ", " + voxel.green + ", " + voxel.blue); - Vec3.print('penetration=', collision.penetration); - Vec3.print('contactPoint=', collision.contactPoint); -} function entityCollisionWithEntity(entityA, entityB, collision) { print("entityCollisionWithParticle().."); @@ -30,7 +23,6 @@ function entityCollisionWithEntity(entityA, entityB, collision) { Vec3.print('contactPoint=', collision.contactPoint); } -Entities.entityCollisionWithVoxel.connect(entityCollisionWithVoxel); Entities.entityCollisionWithEntity.connect(entityCollisionWithEntity); print("here... hello..."); diff --git a/examples/example/localVoxelsExample.js b/examples/example/localVoxelsExample.js deleted file mode 100644 index d64138b214..0000000000 --- a/examples/example/localVoxelsExample.js +++ /dev/null @@ -1,63 +0,0 @@ -// -// localVoxelsExample.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 -// - -var TREE_SCALE = 16384; -var tree = LocalVoxels("tree"); -tree.setVoxel(0, 0, 0, - 0.5 * TREE_SCALE, - 255, 0, 0); -tree.setVoxel(0.5 * TREE_SCALE, - 0.5 * TREE_SCALE, - 0.5 * TREE_SCALE, - 0.5 * TREE_SCALE, - 0, 255, 0); - -var copy = LocalVoxels("copy"); -tree.pasteFrom(0, 0, 0, TREE_SCALE, "copy"); -tree.pasteFrom(0, 0, 0, TREE_SCALE, "clipboard"); - -var overlay1 = Overlays.addOverlay("localvoxels", { - position: {x: 1, y: 1, z: 1}, - size: 1, - name: "tree" - }); -var overlay2 = Overlays.addOverlay("localvoxels", { - position: {x: 1, y: 2, z: 1}, - size: 1, - name: "tree" - }); -var overlay3 = Overlays.addOverlay("localvoxels", { - position: {x: 1, y: 3, z: 1}, - size: 1, - name: "tree" - }); -var overlay4 = Overlays.addOverlay("localvoxels", { - position: {x: 1, y: 4, z: 1}, - size: 1, - name: "copy" - }); - -var clipboard = Overlays.addOverlay("localvoxels", { - position: {x: 1, y: 5, z: 1}, - size: 1, - name: "clipboard" - }); - - - -// When our script shuts down, we should clean up all of our overlays -function scriptEnding() { - Overlays.deleteOverlay(overlay1); - Overlays.deleteOverlay(overlay2); - Overlays.deleteOverlay(overlay3); - Overlays.deleteOverlay(overlay4); - Overlays.deleteOverlay(clipboard); -} -Script.scriptEnding.connect(scriptEnding); \ No newline at end of file diff --git a/examples/metavoxels.js b/examples/example/metavoxels/metavoxels.js similarity index 100% rename from examples/metavoxels.js rename to examples/example/metavoxels/metavoxels.js diff --git a/examples/example/globalServicesExample.js b/examples/example/misc/globalServicesExample.js similarity index 100% rename from examples/example/globalServicesExample.js rename to examples/example/misc/globalServicesExample.js diff --git a/examples/example/includeExample.js b/examples/example/scripts/includeExample.js similarity index 84% rename from examples/example/includeExample.js rename to examples/example/scripts/includeExample.js index 50a1234772..c9c882156e 100644 --- a/examples/example/includeExample.js +++ b/examples/example/scripts/includeExample.js @@ -15,5 +15,5 @@ Script.include("http://public.highfidelity.io/scripts/lookWithTouch.js"); // You can also include scripts that are relative to the current script -Script.include("editVoxels.js"); -Script.include("../examples/selectAudioDevice.js"); +//Script.include("../../editEntities.js"); +//Script.include("../../examples/selectAudioDevice.js"); diff --git a/examples/loadScriptFromMessage.js b/examples/example/scripts/loadScriptFromMessage.js similarity index 100% rename from examples/loadScriptFromMessage.js rename to examples/example/scripts/loadScriptFromMessage.js diff --git a/examples/example/locationExample.js b/examples/example/scripts/locationExample.js similarity index 100% rename from examples/example/locationExample.js rename to examples/example/scripts/locationExample.js diff --git a/examples/example/rayPickExample.js b/examples/example/scripts/rayPickExample.js similarity index 100% rename from examples/example/rayPickExample.js rename to examples/example/scripts/rayPickExample.js diff --git a/examples/example/settingsExample.js b/examples/example/scripts/settingsExample.js similarity index 96% rename from examples/example/settingsExample.js rename to examples/example/scripts/settingsExample.js index bef347ff07..f8364ff91b 100644 --- a/examples/example/settingsExample.js +++ b/examples/example/scripts/settingsExample.js @@ -15,4 +15,4 @@ print("mySetting: " + Settings.getValue("mySetting")); Settings.setValue("mySetting", "spam"); print("mySetting: " + Settings.getValue("mySetting")); -Script.stop(); \ No newline at end of file +//Script.stop(); \ No newline at end of file diff --git a/examples/example/streetAreaExample.js b/examples/example/scripts/streetAreaExample.js similarity index 100% rename from examples/example/streetAreaExample.js rename to examples/example/scripts/streetAreaExample.js diff --git a/examples/timer.js b/examples/example/scripts/timer.js similarity index 100% rename from examples/timer.js rename to examples/example/scripts/timer.js diff --git a/examples/example/dialogExample.js b/examples/example/ui/dialogExample.js similarity index 100% rename from examples/example/dialogExample.js rename to examples/example/ui/dialogExample.js diff --git a/examples/example/fileBrowserExample.js b/examples/example/ui/fileBrowserExample.js similarity index 100% rename from examples/example/fileBrowserExample.js rename to examples/example/ui/fileBrowserExample.js diff --git a/examples/example/menuExample.js b/examples/example/ui/menuExample.js similarity index 100% rename from examples/example/menuExample.js rename to examples/example/ui/menuExample.js diff --git a/examples/example/overlaysExample.js b/examples/example/ui/overlaysExample.js similarity index 99% rename from examples/example/overlaysExample.js rename to examples/example/ui/overlaysExample.js index 821f8a11d1..4e85512545 100644 --- a/examples/example/overlaysExample.js +++ b/examples/example/ui/overlaysExample.js @@ -11,7 +11,7 @@ // 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 // display different colors as color swatches. The overlays can be clicked on, to change the "selectedSwatch" variable diff --git a/examples/textInputOverlayExample.js b/examples/example/ui/textInputOverlayExample.js similarity index 97% rename from examples/textInputOverlayExample.js rename to examples/example/ui/textInputOverlayExample.js index 258e07fcc8..d212a547cf 100644 --- a/examples/textInputOverlayExample.js +++ b/examples/example/ui/textInputOverlayExample.js @@ -58,7 +58,7 @@ var button1 = Overlays.addOverlay("image", { // green button width: 40, 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, visible: true }); @@ -69,7 +69,7 @@ var button2 = Overlays.addOverlay("image", { // red button width: 40, 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}, visible: true, }); diff --git a/examples/example/windowExample.js b/examples/example/ui/windowExample.js similarity index 100% rename from examples/example/windowExample.js rename to examples/example/ui/windowExample.js diff --git a/examples/fountain.js b/examples/fountain.js deleted file mode 100644 index 0e6ab521f7..0000000000 --- a/examples/fountain.js +++ /dev/null @@ -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); \ No newline at end of file diff --git a/examples/gun.js b/examples/gun.js index af5447c2d6..c5b7b17052 100644 --- a/examples/gun.js +++ b/examples/gun.js @@ -26,14 +26,19 @@ var yawFromMouse = 0; var pitchFromMouse = 0; var isMouseDown = false; -var BULLET_VELOCITY = 5.0; +var BULLET_VELOCITY = 20.0; var MIN_THROWER_DELAY = 1000; var MAX_THROWER_DELAY = 1000; var LEFT_BUTTON_3 = 3; var RELOAD_INTERVAL = 5; +var KICKBACK_ANGLE = 15; +var elbowKickAngle = 0.0; +var rotationBeforeKickback; + 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"); @@ -48,10 +53,11 @@ var audioOptions = { } var shotsFired = 0; - var shotTime = new Date(); -// initialize our triggers +var activeControllers = 0; + +// initialize our controller triggers var triggerPulled = new Array(); var numberOfTriggers = Controller.getNumberOfTriggers(); for (t = 0; t < numberOfTriggers; t++) { @@ -59,9 +65,11 @@ for (t = 0; t < numberOfTriggers; t++) { } var isLaunchButtonPressed = false; - var score = 0; +var bulletID = false; +var targetID = false; + // Create a reticle image in center of screen var screenSize = Controller.getViewportDimensions(); var reticle = Overlays.addOverlay("image", { @@ -74,6 +82,16 @@ var reticle = Overlays.addOverlay("image", { alpha: 1 }); +var offButton = Overlays.addOverlay("image", { + x: screenSize.x - 48, + y: 96, + width: 32, + height: 32, + imageURL: HIFI_PUBLIC_BUCKET + "images/close.png", + color: { red: 255, green: 255, blue: 255}, + alpha: 1 + }); + if (showScore) { var text = Overlays.addOverlay("text", { x: screenSize.x / 2 - 100, @@ -95,18 +113,20 @@ function printVector(string, vector) { } function shootBullet(position, velocity) { - var BULLET_SIZE = 0.01; - var BULLET_LIFETIME = 20.0; + var BULLET_SIZE = 0.07; + var BULLET_LIFETIME = 10.0; var BULLET_GRAVITY = -0.02; - Entities.addEntity( + bulletID = Entities.addEntity( { type: "Sphere", position: position, dimensions: { x: BULLET_SIZE, y: BULLET_SIZE, z: BULLET_SIZE }, - color: { red: 10, green: 10, blue: 10 }, + color: { red: 255, green: 0, blue: 0 }, velocity: velocity, lifetime: BULLET_LIFETIME, - gravity: { x: 0, y: BULLET_GRAVITY, z: 0 }, - damping: 0 }); + gravity: { x: 0, y: BULLET_GRAVITY, z: 0 }, + ignoreCollisions: false, + collisionsWillMove: true + }); // Play firing sounds audioOptions.position = position; @@ -115,36 +135,45 @@ function shootBullet(position, velocity) { if ((shotsFired % RELOAD_INTERVAL) == 0) { Audio.playSound(loadSound, audioOptions); } + + // Kickback the arm + rotationBeforeKickback = MyAvatar.getJointRotation("LeftForeArm"); + var armRotation = MyAvatar.getJointRotation("LeftForeArm"); + armRotation = Quat.multiply(armRotation, Quat.fromPitchYawRollDegrees(0.0, 0.0, KICKBACK_ANGLE)); + MyAvatar.setJointData("LeftForeArm", armRotation); + elbowKickAngle = KICKBACK_ANGLE; } function shootTarget() { - var TARGET_SIZE = 0.25; - var TARGET_GRAVITY = -0.6; + var TARGET_SIZE = 0.50; + var TARGET_GRAVITY = -0.25; var TARGET_LIFETIME = 300.0; - var TARGET_UP_VELOCITY = 3.0; - var TARGET_FWD_VELOCITY = 5.0; + var TARGET_UP_VELOCITY = 0.5; + var TARGET_FWD_VELOCITY = 1.0; var DISTANCE_TO_LAUNCH_FROM = 3.0; + var ANGLE_RANGE_FOR_LAUNCH = 20.0; var camera = Camera.getPosition(); //printVector("camera", camera); - var targetDirection = Quat.angleAxis(getRandomFloat(-20.0, 20.0), { x:0, y:1, z:0 }); + var targetDirection = Quat.angleAxis(getRandomFloat(-ANGLE_RANGE_FOR_LAUNCH, ANGLE_RANGE_FOR_LAUNCH), { 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", + + targetID = Entities.addEntity( + { type: "Box", position: newPosition, dimensions: { x: TARGET_SIZE, y: TARGET_SIZE, z: TARGET_SIZE }, color: { red: 0, green: 200, blue: 200 }, + //angularVelocity: { x: 1, y: 0, z: 0 }, velocity: velocity, gravity: { x: 0, y: TARGET_GRAVITY, z: 0 }, lifetime: TARGET_LIFETIME, - damping: 0.0001 }); + damping: 0.0001, + collisionsWillMove: true }); // Record start time shotTime = new Date(); @@ -157,24 +186,25 @@ function shootTarget() { function entityCollisionWithEntity(entity1, entity2, collision) { - score++; - if (showScore) { - Overlays.editOverlay(text, { text: "Score: " + score } ); - } - - // Sort out which entity is which - // 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); + if (((entity1.id == bulletID.id) || (entity1.id == targetID.id)) && + ((entity2.id == bulletID.id) || (entity2.id == targetID.id))) { + score++; + if (showScore) { + Overlays.editOverlay(text, { text: "Score: " + score } ); + } + + // We will delete the bullet and target in 1/2 sec, but for now we can see them bounce! + Script.setTimeout(deleteBulletAndTarget, 500); + + // Turn the target and the bullet white + Entities.editEntity(entity1, { color: { red: 255, green: 255, blue: 255 }}); + Entities.editEntity(entity2, { color: { red: 255, green: 255, blue: 255 }}); + + // 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) { @@ -186,32 +216,93 @@ function keyPressEvent(event) { shootFromMouse(); } else if (event.text == "r") { playLoadSound(); + } else if (event.text == "s") { + // Hit this key to dump a posture from hydra to log + Quat.print("arm = ", MyAvatar.getJointRotation("LeftArm")); + Quat.print("forearm = ", MyAvatar.getJointRotation("LeftForeArm")); + Quat.print("hand = ", MyAvatar.getJointRotation("LeftHand")); + } } function playLoadSound() { audioOptions.position = Vec3.sum(Camera.getPosition(), Quat.getFront(Camera.getOrientation())); Audio.playSound(loadSound, audioOptions); + // Raise arm to firing posture + takeFiringPose(); +} + +function clearPose() { + MyAvatar.clearJointData("LeftForeArm"); + MyAvatar.clearJointData("LeftArm"); + MyAvatar.clearJointData("LeftHand"); +} + +function deleteBulletAndTarget() { + Entities.deleteEntity(bulletID); + Entities.deleteEntity(targetID); + bulletID = false; + targetID = false; +} + +function takeFiringPose() { + clearPose(); + if (Controller.getNumberOfSpatialControls() == 0) { + MyAvatar.setJointData("LeftForeArm", {x: -0.251919, y: -0.0415449, z: 0.499487, w: 0.827843}); + MyAvatar.setJointData("LeftArm", { x: 0.470196, y: -0.132559, z: 0.494033, w: 0.719219}); + MyAvatar.setJointData("LeftHand", { x: -0.0104815, y: -0.110551, z: -0.352111, w: 0.929333}); + } } -//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) { + if (bulletID && !bulletID.isKnownID) { + print("Trying to identify bullet"); + bulletID = Entities.identifyEntity(bulletID); + } + if (targetID && !targetID.isKnownID) { + targetID = Entities.identifyEntity(targetID); + } // Check for mouseLook movement, update rotation // rotate body yaw for yaw received from mouse var newOrientation = Quat.multiply(MyAvatar.orientation, Quat.fromVec3Radians( { x: 0, y: yawFromMouse, z: 0 } )); - MyAvatar.orientation = newOrientation; + //MyAvatar.orientation = newOrientation; yawFromMouse = 0; // apply pitch from mouse var newPitch = MyAvatar.headPitch + pitchFromMouse; - MyAvatar.headPitch = newPitch; + //MyAvatar.headPitch = newPitch; pitchFromMouse = 0; + + if (activeControllers == 0) { + if (Controller.getNumberOfSpatialControls() > 0) { + activeControllers = Controller.getNumberOfSpatialControls(); + clearPose(); + } + } + + var KICKBACK_DECAY_RATE = 0.125; + if (elbowKickAngle > 0.0) { + if (elbowKickAngle > 0.5) { + var newAngle = elbowKickAngle * KICKBACK_DECAY_RATE; + elbowKickAngle -= newAngle; + var armRotation = MyAvatar.getJointRotation("LeftForeArm"); + armRotation = Quat.multiply(armRotation, Quat.fromPitchYawRollDegrees(0.0, 0.0, -newAngle)); + MyAvatar.setJointData("LeftForeArm", armRotation); + } else { + MyAvatar.setJointData("LeftForeArm", rotationBeforeKickback); + if (Controller.getNumberOfSpatialControls() > 0) { + clearPose(); + } + elbowKickAngle = 0.0; + } + } + // Check hydra controller for launch button press if (!isLaunchButtonPressed && Controller.isButtonPressed(LEFT_BUTTON_3)) { isLaunchButtonPressed = true; @@ -222,15 +313,13 @@ function update(deltaTime) { } - // Check hydra controller for trigger press + // check for trigger press - var numberOfTriggers = Controller.getNumberOfTriggers(); - var numberOfSpatialControls = Controller.getNumberOfSpatialControls(); - var controllersPerTrigger = numberOfSpatialControls / numberOfTriggers; + var numberOfTriggers = 2; + var controllersPerTrigger = 2; - // this is expected for hydras if (numberOfTriggers == 2 && controllersPerTrigger == 2) { - for (var t = 0; t < numberOfTriggers; t++) { + for (var t = 0; t < 2; t++) { var shootABullet = false; var triggerValue = Controller.getTriggerValue(t); if (triggerPulled[t]) { @@ -239,14 +328,13 @@ function update(deltaTime) { triggerPulled[t] = false; // unpulled } } else { - // must pull to at least 0.9 - if (triggerValue > 0.9) { + // must pull to at least + if (triggerValue > 0.5) { triggerPulled[t] = true; // pulled shootABullet = true; } } - if (shootABullet) { var palmController = t * controllersPerTrigger; var palmPosition = Controller.getSpatialControlPosition(palmController); @@ -263,12 +351,8 @@ function update(deltaTime) { 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 }; + + var velocity = Vec3.multiply(BULLET_VELOCITY, Vec3.normalize(palmToFingerTipVector)); shootBullet(position, velocity); } @@ -280,8 +364,12 @@ 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); + + if (Overlays.getOverlayAtPoint({ x: event.x, y: event.y }) === offButton) { + Script.stop(); + } else { + shootFromMouse(); + } } function shootFromMouse() { @@ -312,8 +400,10 @@ function mouseMoveEvent(event) { function scriptEnding() { Overlays.deleteOverlay(reticle); + Overlays.deleteOverlay(offButton); Overlays.deleteOverlay(text); MyAvatar.detachOne(gunModel); + clearPose(); } Entities.entityCollisionWithEntity.connect(entityCollisionWithEntity); diff --git a/examples/html/entityProperties.html b/examples/html/entityProperties.html index 4e22637ad6..a3644d8c3d 100644 --- a/examples/html/entityProperties.html +++ b/examples/html/entityProperties.html @@ -618,7 +618,7 @@ Script URL - + @@ -637,13 +637,13 @@ Model URL - + Animation URL - + diff --git a/examples/html/style.css b/examples/html/style.css index aa23cf97ab..2f43b1c356 100644 --- a/examples/html/style.css +++ b/examples/html/style.css @@ -96,6 +96,10 @@ input { background-color: #eee; } +input.url { + width: 100%; +} + table#entity-table { border-collapse: collapse; font-family: Sans-Serif; @@ -171,7 +175,7 @@ table#properties-table { } #properties-table td { - padding: 5px 0px 5px 10px; + padding: 5px; } col#col-label { diff --git a/examples/libraries/entitySelectionTool.js b/examples/libraries/entitySelectionTool.js index 8aff9c32ed..2b83d7740d 100644 --- a/examples/libraries/entitySelectionTool.js +++ b/examples/libraries/entitySelectionTool.js @@ -590,7 +590,7 @@ SelectionDisplay = (function () { }); 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}, color: rotateHandleColor, alpha: rotateHandleAlpha, @@ -603,7 +603,7 @@ SelectionDisplay = (function () { 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}, color: rotateHandleColor, alpha: rotateHandleAlpha, @@ -616,7 +616,7 @@ SelectionDisplay = (function () { 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}, color: rotateHandleColor, alpha: rotateHandleAlpha, @@ -835,8 +835,8 @@ SelectionDisplay = (function () { 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(rollHandle, { 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://public.highfidelity.io/images/rotate-arrow-west-south.png" }); } else { @@ -867,8 +867,8 @@ SelectionDisplay = (function () { pitchCenter = { x: right, y: boundsCenter.y, z: boundsCenter.z }; 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(rollHandle, { 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://public.highfidelity.io/images/rotate-arrow-west-north.png" }); } } else { @@ -899,8 +899,8 @@ SelectionDisplay = (function () { pitchCenter = { x: left, y: boundsCenter.y, z: boundsCenter.z }; 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(rollHandle, { 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://public.highfidelity.io/images/rotate-arrow-west-north.png" }); } else { @@ -928,8 +928,8 @@ SelectionDisplay = (function () { rollCenter = { x: boundsCenter.x, y: boundsCenter.y, z: near }; 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(rollHandle, { 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://public.highfidelity.io/images/rotate-arrow-west-north.png" }); } } diff --git a/examples/libraries/gridTool.js b/examples/libraries/gridTool.js index f444a67ed1..87b7f907e2 100644 --- a/examples/libraries/gridTool.js +++ b/examples/libraries/gridTool.js @@ -439,7 +439,11 @@ GridTool = function(opts) { } else if (overlay == uiOverlays.snapToGridCheckbox.overlay) { horizontalGrid.setSnapToGrid(!horizontalGrid.getSnapToGrid()); } else if (overlay == uiOverlays.moveToAvatar.overlay) { - horizontalGrid.setPosition(MyAvatar.position); + var position = MyAvatar.getJointPosition("LeftFoot"); + if (position.x == 0 && position.y == 0 && position.z == 0) { + position = MyAvatar.position; + } + horizontalGrid.setPosition(position); } else if (overlay == uiOverlays.moveToSelection.overlay) { var newPosition = selectionManager.worldPosition; newPosition = Vec3.subtract(newPosition, { x: 0, y: selectionManager.worldDimensions.y * 0.5, z: 0 }); diff --git a/examples/libraries/unitTest.js b/examples/libraries/unitTest.js new file mode 100644 index 0000000000..530528e6a3 --- /dev/null +++ b/examples/libraries/unitTest.js @@ -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); +} \ No newline at end of file diff --git a/examples/locationsMenu.js b/examples/locationsMenu.js deleted file mode 100644 index 30fa377a6f..0000000000 --- a/examples/locationsMenu.js +++ /dev/null @@ -1,304 +0,0 @@ -// -// locationsMenu.js -// examples -// -// Created by Ryan Huffman on 5/28/14 -// 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 -// - -Script.include("libraries/globals.js"); - -var scriptUrl = "https://script.google.com/macros/s/AKfycbwIo4lmF-qUwX1Z-9eA_P-g2gse9oFhNcjVyyksGukyDDEFXgU/exec?action=listOwners&domain=alpha.highfidelity.io"; - -var LocationMenu = function(opts) { - var self = this; - - var pageSize = opts.pageSize || 10; - var menuWidth = opts.menuWidth || 150; - var menuHeight = opts.menuItemHeight || 24; - - var inactiveColor = { red: 51, green: 102, blue: 102 }; - var activeColor = { red: 18, green: 66, blue: 66 }; - var prevNextColor = { red: 192, green: 192, blue: 192 }; - var disabledColor = { red: 64, green: 64, blue: 64}; - var position = { x: 0, y: 0 }; - - var locationIconUrl = HIFI_PUBLIC_BUCKET + "images/tools/location.svg"; - var toolHeight = 50; - var toolWidth = 50; - var visible = false; - var menuItemOffset = { - x: 55, - y: 0, - }; - var menuItemPadding = 5; - var margin = 7; - var fullMenuHeight = (2 * menuItemOffset.y) + (menuHeight * (pageSize + 1)); - var menuOffset = -fullMenuHeight + toolHeight; - - var windowDimensions = Controller.getViewportDimensions(); - - this.locations = []; - this.numPages = 1; - this.page = 0; - - this.menuToggleButton = Overlays.addOverlay("image", { - x: position.x, - y: position.y, - width: toolWidth, height: toolHeight, - subImage: { x: 0, y: toolHeight, width: toolWidth, height: toolHeight }, - imageURL: locationIconUrl, - alpha: 0.9 - }); - - this.background = Overlays.addOverlay("text", { - x: 0, - y: 0, - width: menuWidth + 10, - height: (menuHeight * (pageSize + 1)) + 10, - backgroundColor: { red: 0, green: 0, blue: 0}, - topMargin: 4, - leftMargin: 4, - text: "", - visible: visible, - }); - - this.menuItems = []; - for (var i = 0; i < pageSize; i++) { - var menuItem = Overlays.addOverlay("text", { - x: 0, - y: 0, - width: menuWidth, - height: menuHeight, - backgroundColor: inactiveColor, - topMargin: margin, - leftMargin: margin, - text: (i == 0) ? "Loading..." : "", - visible: visible, - }); - this.menuItems.push({ overlay: menuItem, location: null }); - } - - this.previousButton = Overlays.addOverlay("text", { - x: 0, - y: 0, - width: menuWidth / 2, - height: menuHeight, - backgroundColor: disabledColor, - topMargin: margin, - leftMargin: margin, - text: "Previous", - visible: visible, - }); - - this.nextButton = Overlays.addOverlay("text", { - x: 0, - y: 0, - width: menuWidth / 2, - height: menuHeight, - backgroundColor: disabledColor, - topMargin: margin, - leftMargin: margin, - text: "Next", - visible: visible, - }); - - this.reposition = function(force) { - var newWindowDimensions = Controller.getViewportDimensions(); - if (force || newWindowDimensions.y != windowDimensions.y) { - windowDimensions = newWindowDimensions; - - position.x = 8; - position.y = Math.floor(windowDimensions.y / 2) + 25 + 50 + 8; - - Overlays.editOverlay(self.menuToggleButton, { - x: position.x, - y: position.y, - }); - Overlays.editOverlay(self.background, { - x: position.x + menuItemOffset.x, - y: position.y + menuItemOffset.y - 2 * menuItemPadding + menuOffset, - }); - for (var i = 0; i < pageSize; i++) { - Overlays.editOverlay(self.menuItems[i].overlay, { - x: position.x + menuItemOffset.x + menuItemPadding, - y: position.y + menuItemOffset.y - menuItemPadding + (i * menuHeight) + menuOffset, - }); - } - Overlays.editOverlay(self.previousButton, { - x: position.x + menuItemOffset.x + menuItemPadding, - y: position.y + menuItemOffset.y - menuItemPadding + (pageSize * menuHeight) + menuOffset, - }); - Overlays.editOverlay(self.nextButton, { - x: position.x + menuItemOffset.x + menuItemPadding + (menuWidth / 2), - y: position.y + menuItemOffset.y - menuItemPadding + (pageSize * menuHeight) + menuOffset, - }); - } - } - - this.updateLocations = function(locations) { - this.locations = locations; - this.numPages = Math.ceil(locations.length / pageSize); - this.goToPage(0); - } - - this.setError = function() { - Overlays.editOverlay(this.menuItems[0].overlay, { text: "Error loading data" }); - } - - this.toggleMenu = function() { - visible = !visible; - for (var i = 0; i < this.menuItems.length; i++) { - Overlays.editOverlay(this.menuItems[i].overlay, { visible: visible}); - } - Overlays.editOverlay(this.previousButton, { visible: visible}); - Overlays.editOverlay(this.nextButton, { visible: visible}); - Overlays.editOverlay(this.background, { visible: visible}); - if (visible) { - Overlays.editOverlay(this.menuToggleButton, { subImage: { x: 0, y: 0, width: toolWidth, height: toolHeight } }), - } else { - Overlays.editOverlay(this.menuToggleButton, { subImage: { x: 0, y: toolHeight, width: toolWidth, height: toolHeight } }), - } - } - - this.goToPage = function(pageNumber) { - if (pageNumber < 0 || pageNumber >= this.numPages) { - return; - } - - this.page = pageNumber; - var start = pageNumber * pageSize; - for (var i = 0; i < pageSize; i++) { - var update = {}; - var location = null; - if (start + i < this.locations.length) { - location = this.locations[start + i]; - update.text = (start + i + 1) + ". " + location.username; - update.backgroundColor = inactiveColor; - } else { - update.text = ""; - update.backgroundColor = disabledColor; - } - Overlays.editOverlay(this.menuItems[i].overlay, update); - this.menuItems[i].location = location; - } - - this.previousEnabled = pageNumber > 0; - this.nextEnabled = pageNumber < (this.numPages - 1); - - Overlays.editOverlay(this.previousButton, { backgroundColor: this.previousEnabled ? prevNextColor : disabledColor}); - Overlays.editOverlay(this.nextButton, { backgroundColor: this.nextEnabled ? prevNextColor : disabledColor }); - } - - this.mousePressEvent = function(event) { - var clickedOverlay = Overlays.getOverlayAtPoint({x: event.x, y: event.y}); - - if (clickedOverlay == self.menuToggleButton) { - self.toggleMenu(); - } else if (clickedOverlay == self.previousButton) { - if (self.previousEnabled) { - Overlays.editOverlay(clickedOverlay, { backgroundColor: activeColor }); - } - } else if (clickedOverlay == self.nextButton) { - if (self.nextEnabled) { - Overlays.editOverlay(clickedOverlay, { backgroundColor: activeColor }); - } - } else { - for (var i = 0; i < self.menuItems.length; i++) { - if (clickedOverlay == self.menuItems[i].overlay) { - if (self.menuItems[i].location != null) { - Overlays.editOverlay(clickedOverlay, { backgroundColor: activeColor }); - } - break; - } - } - } - } - - this.mouseReleaseEvent = function(event) { - var clickedOverlay = Overlays.getOverlayAtPoint({x: event.x, y: event.y}); - - if (clickedOverlay == self.previousButton) { - if (self.previousEnabled) { - Overlays.editOverlay(clickedOverlay, { backgroundColor: inactiveColor }); - self.goToPage(self.page - 1); - } - } else if (clickedOverlay == self.nextButton) { - if (self.nextEnabled) { - Overlays.editOverlay(clickedOverlay, { backgroundColor: inactiveColor }); - self.goToPage(self.page + 1); - } - } else { - for (var i = 0; i < self.menuItems.length; i++) { - if (clickedOverlay == self.menuItems[i].overlay) { - if (self.menuItems[i].location != null) { - Overlays.editOverlay(clickedOverlay, { backgroundColor: inactiveColor }); - var location = self.menuItems[i].location; - Window.location = "hifi://" + location.domain + "/" - + location.x + "," + location.y + "," + location.z; - } - break; - } - } - } - } - - this.cleanup = function() { - for (var i = 0; i < self.menuItems.length; i++) { - Overlays.deleteOverlay(self.menuItems[i].overlay); - } - Overlays.deleteOverlay(self.menuToggleButton); - Overlays.deleteOverlay(self.previousButton); - Overlays.deleteOverlay(self.nextButton); - Overlays.deleteOverlay(self.background); - } - - Controller.mousePressEvent.connect(this.mousePressEvent); - Controller.mouseReleaseEvent.connect(this.mouseReleaseEvent); - Script.update.connect(this.reposition); - Script.scriptEnding.connect(this.cleanup); - - this.reposition(true); -}; - -var locationMenu = new LocationMenu({ pageSize: 8 }); - -print("Loading strip data from " + scriptUrl); - -var req = new XMLHttpRequest(); -req.responseType = 'json'; - -req.onreadystatechange = function() { - if (req.readyState == req.DONE) { - if (req.status == 200 && req.response != null) { - for (var domain in req.response) { - var locations = req.response[domain]; - var users = []; - for (var i = 0; i < locations.length; i++) { - var loc = locations[i]; - var x1 = loc[1], - x2 = loc[2], - y1 = loc[3], - y2 = loc[4]; - users.push({ - domain: domain, - username: loc[0], - x: x1, - y: 300, - z: y1, - }); - } - locationMenu.updateLocations(users); - } - } else { - print("Error loading data: " + req.status + " " + req.statusText + ", " + req.errorCode + ": " + req.responseText); - locationMenu.setError(); - } - } -} - -req.open("GET", scriptUrl); -req.send(); diff --git a/examples/playSound.js b/examples/playSound.js deleted file mode 100644 index bc21204665..0000000000 --- a/examples/playSound.js +++ /dev/null @@ -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); \ No newline at end of file diff --git a/examples/playSoundOrbit.js b/examples/playSoundOrbit.js deleted file mode 100644 index 16ba5e52af..0000000000 --- a/examples/playSoundOrbit.js +++ /dev/null @@ -1,43 +0,0 @@ -// -// playSoundPath.js -// examples -// -// Created by Craig Hansen-Sturm on 05/27/14. -// 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 -// - -Script.include("libraries/globals.js"); - -var soundClip = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Voxels/voxel create 3.raw"); - -var currentTime = 1.570079; // pi/2 -var deltaTime = 0.05; -var distance = 1; -var debug = 0; - -function playSound() { - currentTime += deltaTime; - - var s = distance * Math.sin(currentTime); - var c = distance * Math.cos(currentTime); - - var soundOffset = { x:s, y:0, z:c }; - - if (debug) { - print("t=" + currentTime + "offset=" + soundOffset.x + "," + soundOffset.y + "," + soundOffset.z); - } - - var avatarPosition = MyAvatar.position; - var soundPosition = Vec3.sum(avatarPosition,soundOffset); - - Audio.playSound(soundClip, { - position: soundPosition - }); -} - -Script.setInterval(playSound, 250); - - diff --git a/examples/sit.js b/examples/sit.js index c3abe9a908..71d909d1e7 100644 --- a/examples/sit.js +++ b/examples/sit.js @@ -10,7 +10,7 @@ // -var buttonImageUrl = "https://worklist-prod.s3.amazonaws.com/attachment/0aca88e1-9bd8-5c1d.svg"; +var buttonImageUrl = "https://public.highfidelity.io/images/tools/sit.svg"; var windowDimensions = Controller.getViewportDimensions(); diff --git a/examples/testModelOverlaySubMeshes.js b/examples/testModelOverlaySubMeshes.js deleted file mode 100644 index 20ec10ef7c..0000000000 --- a/examples/testModelOverlaySubMeshes.js +++ /dev/null @@ -1,88 +0,0 @@ -var position = Vec3.sum(MyAvatar.position, { x: 0, y: -1, z: 0}); - -var scalingFactor = 0.01; - -var sphereNaturalExtentsMin = { x: -1230, y: -1223, z: -1210 }; -var sphereNaturalExtentsMax = { x: 1230, y: 1229, z: 1223 }; -var panelsNaturalExtentsMin = { x: -1181, y: -326, z: 56 }; -var panelsNaturalExtentsMax = { x: 1181, y: 576, z: 1183 }; - -var sphereNaturalDimensions = Vec3.subtract(sphereNaturalExtentsMax, sphereNaturalExtentsMin); -var panelsNaturalDimensions = Vec3.subtract(panelsNaturalExtentsMax, panelsNaturalExtentsMin); -Vec3.print("sphereNaturalDimensions:", sphereNaturalDimensions); -Vec3.print("panelsNaturalDimensions:", panelsNaturalDimensions); - -var sphereNaturalCenter = Vec3.sum(sphereNaturalExtentsMin, Vec3.multiply(sphereNaturalDimensions, 0.5)); -var panelsNaturalCenter = Vec3.sum(panelsNaturalExtentsMin, Vec3.multiply(panelsNaturalDimensions, 0.5)); -Vec3.print("sphereNaturalCenter:", sphereNaturalCenter); -Vec3.print("panelsNaturalCenter:", panelsNaturalCenter); - -var sphereDimensions = Vec3.multiply(sphereNaturalDimensions, scalingFactor); -var panelsDimensions = Vec3.multiply(panelsNaturalDimensions, scalingFactor); -Vec3.print("sphereDimensions:", sphereDimensions); -Vec3.print("panelsDimensions:", panelsDimensions); - -var sphereCenter = Vec3.multiply(sphereNaturalCenter, scalingFactor); -var panelsCenter = Vec3.multiply(panelsNaturalCenter, scalingFactor); -Vec3.print("sphereCenter:", sphereCenter); -Vec3.print("panelsCenter:", panelsCenter); - -var centerShift = Vec3.subtract(panelsCenter, sphereCenter); -Vec3.print("centerShift:", centerShift); - -var spherePosition = position; -Vec3.print("spherePosition:", spherePosition); -var panelsPosition = Vec3.sum(spherePosition, centerShift); -Vec3.print("panelsPosition:", panelsPosition); - - -var screensOverlay = Overlays.addOverlay("model", { - position: panelsPosition, - dimensions: panelsDimensions, - url: "https://s3.amazonaws.com/hifi-public/models/sets/Lobby/LobbyConcepts/Lobby5_IsolatedPanelsFreezeTransforms.fbx" - }); - - -var structureOverlay = Overlays.addOverlay("model", { - position: spherePosition, - dimensions: sphereDimensions, - url: "https://s3.amazonaws.com/hifi-public/models/sets/Lobby/LobbyConcepts/Lobby5_OrbShellOnly.fbx", - ignoreRayIntersection: true, // we don't want to ray pick against any of this - }); - -var statusText = Overlays.addOverlay("text", { - x: 200, - y: 100, - width: 200, - height: 20, - backgroundColor: { red: 0, green: 0, blue: 0}, - alpha: 1.0, - backgroundAlpha: 1.0, - color: { red: 255, green: 255, blue: 255}, - topMargin: 4, - leftMargin: 4, - text: "", - }); - - -Controller.mouseMoveEvent.connect(function(event){ - var pickRay = Camera.computePickRay(event.x, event.y); - var result = Overlays.findRayIntersection(pickRay); - - if (result.intersects) { - if (result.overlayID == screensOverlay) { - Overlays.editOverlay(statusText, { text: "You are pointing at: " + result.extraInfo }); - } else { - Overlays.editOverlay(statusText, { text: "You are not pointing at a panel..." }); - } - } else { - Overlays.editOverlay(statusText, { text: "You are not pointing at a panel..." }); - } -}); - - -Script.scriptEnding.connect(function(){ - Overlays.deleteOverlay(screensOverlay); - Overlays.deleteOverlay(structureOverlay); - Overlays.deleteOverlay(statusText); -}); diff --git a/examples/twoFallingEntities.js b/examples/twoFallingEntities.js deleted file mode 100644 index 2d71344e2c..0000000000 --- a/examples/twoFallingEntities.js +++ /dev/null @@ -1,25 +0,0 @@ -// -// twoFallingEntities.js -// -// Creates a red 0.2 meter diameter ball right in front of your avatar that lives for 60 seconds -// - -var diameter = 0.2; -var position = Vec3.sum(MyAvatar.position, Quat.getFront(MyAvatar.orientation)); -var properties = { - type: "Sphere", - position: position, - velocity: { x: 0, y: 0, z: 0}, - gravity: { x: 0, y: -0.05, z: 0}, - dimensions: { x: diameter, y: diameter, z: diameter }; - damping: 0.00001, - color: { red: 200, green: 0, blue: 0 }, - lifetime: 60 - }; - -var newEntity = Entities.addEntity(properties); -position.x -= 0.5 * diameter; -properties.position = position; -var newEntityTwo = Entities.addEntity(properties); - -Script.stop(); // no need to run anymore diff --git a/examples/testXMLHttpRequest.js b/examples/utilities/diagnostics/XMLHttpRequest.js similarity index 99% rename from examples/testXMLHttpRequest.js rename to examples/utilities/diagnostics/XMLHttpRequest.js index 79d2842464..fb25cb4fad 100644 --- a/examples/testXMLHttpRequest.js +++ b/examples/utilities/diagnostics/XMLHttpRequest.js @@ -11,7 +11,7 @@ // 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) { var req = new XMLHttpRequest(); diff --git a/examples/inWorldTestTone.js b/examples/utilities/diagnostics/inWorldTestTone.js similarity index 95% rename from examples/inWorldTestTone.js rename to examples/utilities/diagnostics/inWorldTestTone.js index 660965569c..1fc3cbc2c8 100644 --- a/examples/inWorldTestTone.js +++ b/examples/utilities/diagnostics/inWorldTestTone.js @@ -11,7 +11,7 @@ // 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"); diff --git a/examples/orbitingSound.js b/examples/utilities/diagnostics/orbitingSound.js similarity index 100% rename from examples/orbitingSound.js rename to examples/utilities/diagnostics/orbitingSound.js diff --git a/examples/playSoundLoop.js b/examples/utilities/diagnostics/playSoundLoop.js similarity index 97% rename from examples/playSoundLoop.js rename to examples/utilities/diagnostics/playSoundLoop.js index f7116cb615..b9d35141d1 100644 --- a/examples/playSoundLoop.js +++ b/examples/utilities/diagnostics/playSoundLoop.js @@ -11,7 +11,7 @@ // 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: diff --git a/examples/playSoundWave.js b/examples/utilities/diagnostics/playSoundWave.js similarity index 100% rename from examples/playSoundWave.js rename to examples/utilities/diagnostics/playSoundWave.js diff --git a/examples/typedArraysUnitTest.js b/examples/utilities/diagnostics/typedArraysUnitTest.js similarity index 99% rename from examples/typedArraysUnitTest.js rename to examples/utilities/diagnostics/typedArraysUnitTest.js index e86a07289d..0688667cc4 100644 --- a/examples/typedArraysUnitTest.js +++ b/examples/utilities/diagnostics/typedArraysUnitTest.js @@ -9,7 +9,7 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -Script.include("Test.js"); +Script.include("../../libraries/unitTest.js"); // e.g. extractbits([0xff, 0x80, 0x00, 0x00], 23, 30); inclusive function extractbits(bytes, lo, hi) { diff --git a/examples/Recorder.js b/examples/utilities/record/recorder.js similarity index 100% rename from examples/Recorder.js rename to examples/utilities/record/recorder.js diff --git a/examples/crazylegs.js b/examples/utilities/tools/crazylegs.js similarity index 93% rename from examples/crazylegs.js rename to examples/utilities/tools/crazylegs.js index 7a6fb68520..38ecaba7c0 100644 --- a/examples/crazylegs.js +++ b/examples/utilities/tools/crazylegs.js @@ -4,6 +4,8 @@ // // Created by Andrzej Kapolka on 3/6/14. // Copyright 2014 High Fidelity, Inc. +// +// Outputs the joint index of an avatar, this is useful for avatar procedural animations // // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html diff --git a/examples/currentAPI.js b/examples/utilities/tools/currentAPI.js similarity index 100% rename from examples/currentAPI.js rename to examples/utilities/tools/currentAPI.js diff --git a/examples/developerMenuItems.js b/examples/utilities/tools/developerMenuItems.js similarity index 100% rename from examples/developerMenuItems.js rename to examples/utilities/tools/developerMenuItems.js diff --git a/interface/CMakeLists.txt b/interface/CMakeLists.txt index 1765fc0fb5..8ddd1153ef 100644 --- a/interface/CMakeLists.txt +++ b/interface/CMakeLists.txt @@ -229,7 +229,7 @@ else (APPLE) # we're using static GLEW, so define GLEW_STATIC add_definitions(-DGLEW_STATIC) - target_link_libraries(${TARGET_NAME} "${GLEW_LIBRARIES}" "${NSIGHT_LIBRARIES}" wsock32.lib opengl32.lib Winmm.lib) + target_link_libraries(${TARGET_NAME} ${GLEW_LIBRARIES} "${NSIGHT_LIBRARIES}" wsock32.lib opengl32.lib Winmm.lib) # try to find the Nsight package and add it to the build if we find it find_package(NSIGHT) diff --git a/interface/external/rtmidi/readme.txt b/interface/external/rtmidi/readme.txt index d0480fce4a..3b9d6603a9 100644 --- a/interface/external/rtmidi/readme.txt +++ b/interface/external/rtmidi/readme.txt @@ -3,7 +3,7 @@ Instructions for adding the RtMidi library to Interface Stephen Birarda, June 30, 2014 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. diff --git a/interface/interface_en.ts b/interface/interface_en.ts index b85628b104..b011f37317 100644 --- a/interface/interface_en.ts +++ b/interface/interface_en.ts @@ -3,11 +3,6 @@ Application - - - Export Voxels - - Sparse Voxel Octree Files (*.svo) @@ -226,45 +221,23 @@ - Voxels - - - - - - Maximum voxels + Octree - Max voxels sent each second + Max packets sent each second QObject - - - - Import Voxels - - Loading ... - - - Place voxels - - - - - <b>Import</b> %1 as voxels - - Cancel diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index bbcf90312e..1364e1b05b 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -535,12 +535,6 @@ void Application::initializeGL() { }*/ #endif - // Before we render anything, let's set up our viewFrustumOffsetCamera with a sufficiently large - // field of view and near and far clip to make it interesting. - //viewFrustumOffsetCamera.setFieldOfView(90.0); - _viewFrustumOffsetCamera.setNearClip(DEFAULT_NEAR_CLIP); - _viewFrustumOffsetCamera.setFarClip(DEFAULT_FAR_CLIP); - initDisplay(); qDebug( "Initialized Display."); @@ -627,32 +621,6 @@ void Application::paintGL() { _myCamera.update(1.0f / _fps); } - // Note: whichCamera is used to pick between the normal camera myCamera for our - // main camera, vs, an alternate camera. The alternate camera we support right now - // is the viewFrustumOffsetCamera. But theoretically, we could use this same mechanism - // to add other cameras. - // - // Why have two cameras? Well, one reason is that because in the case of the renderViewFrustum() - // code, we want to keep the state of "myCamera" intact, so we can render what the view frustum of - // myCamera is. But we also want to do meaningful camera transforms on OpenGL for the offset camera - Camera* whichCamera = &_myCamera; - - if (Menu::getInstance()->isOptionChecked(MenuOption::DisplayFrustum)) { - - ViewFrustumOffset viewFrustumOffset = Menu::getInstance()->getViewFrustumOffset(); - - // set the camera to third-person view but offset so we can see the frustum - glm::quat frustumRotation = glm::quat(glm::radians(glm::vec3(viewFrustumOffset.pitch, viewFrustumOffset.yaw, viewFrustumOffset.roll))); - - _viewFrustumOffsetCamera.setPosition(_myCamera.getPosition() + - frustumRotation * glm::vec3(0.0f, viewFrustumOffset.up, -viewFrustumOffset.distance)); - - _viewFrustumOffsetCamera.setRotation(_myCamera.getRotation() * frustumRotation); - - _viewFrustumOffsetCamera.update(1.0f/_fps); - whichCamera = &_viewFrustumOffsetCamera; - } - if (Menu::getInstance()->getShadowsEnabled()) { updateShadowMap(); } @@ -663,16 +631,16 @@ void Application::paintGL() { glClear(GL_COLOR_BUFFER_BIT); //When in mirror mode, use camera rotation. Otherwise, use body rotation - if (whichCamera->getMode() == CAMERA_MODE_MIRROR) { - OculusManager::display(whichCamera->getRotation(), whichCamera->getPosition(), *whichCamera); + if (_myCamera.getMode() == CAMERA_MODE_MIRROR) { + OculusManager::display(_myCamera.getRotation(), _myCamera.getPosition(), _myCamera); } else { - OculusManager::display(_myAvatar->getWorldAlignedOrientation(), _myAvatar->getDefaultEyePosition(), *whichCamera); + OculusManager::display(_myAvatar->getWorldAlignedOrientation(), _myAvatar->getDefaultEyePosition(), _myCamera); } _myCamera.update(1.0f / _fps); } else if (TV3DManager::isConnected()) { - TV3DManager::display(*whichCamera); + TV3DManager::display(_myCamera); } else { DependencyManager::get()->prepare(); @@ -684,7 +652,7 @@ void Application::paintGL() { glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); - displaySide(*whichCamera); + displaySide(_myCamera); glPopMatrix(); if (Menu::getInstance()->isOptionChecked(MenuOption::FullscreenMirror)) { @@ -721,7 +689,6 @@ void Application::resetCamerasOnResizeGL(Camera& camera, int width, int height) } void Application::resizeGL(int width, int height) { - resetCamerasOnResizeGL(_viewFrustumOffsetCamera, width, height); resetCamerasOnResizeGL(_myCamera, width, height); glViewport(0, 0, width, height); // shouldn't this account for the menu??? @@ -750,13 +717,6 @@ void Application::updateProjectionMatrix(Camera& camera, bool updateViewFrustum) if (updateViewFrustum) { loadViewFrustum(camera, _viewFrustum); _viewFrustum.computeOffAxisFrustum(left, right, bottom, top, nearVal, farVal, nearClipPlane, farClipPlane); - - // If we're in Display Frustum mode, then we want to use the slightly adjust near/far clip values of the - // _viewFrustumOffsetCamera, so that we can see more of the application content in the application's frustum - if (Menu::getInstance()->isOptionChecked(MenuOption::DisplayFrustum)) { - nearVal = _viewFrustumOffsetCamera.getNearClip(); - farVal = _viewFrustumOffsetCamera.getFarClip(); - } } else { ViewFrustum tempViewFrustum; loadViewFrustum(camera, tempViewFrustum); @@ -844,19 +804,6 @@ void Application::keyPressEvent(QKeyEvent* event) { bool isOption = event->modifiers().testFlag(Qt::AltModifier); switch (event->key()) { break; - case Qt::Key_BracketLeft: - case Qt::Key_BracketRight: - case Qt::Key_BraceLeft: - case Qt::Key_BraceRight: - case Qt::Key_ParenLeft: - case Qt::Key_ParenRight: - case Qt::Key_Less: - case Qt::Key_Greater: - case Qt::Key_Comma: - case Qt::Key_Period: - case Qt::Key_QuoteDbl: - Menu::getInstance()->handleViewFrustumOffsetKeyModifier(event->key()); - break; case Qt::Key_L: if (isShifted) { Menu::getInstance()->triggerOption(MenuOption::LodTools); @@ -1058,19 +1005,9 @@ void Application::keyPressEvent(QKeyEvent* event) { case Qt::Key_Slash: Menu::getInstance()->triggerOption(MenuOption::UserInterface); break; - case Qt::Key_F: - if (isShifted) { - Menu::getInstance()->triggerOption(MenuOption::DisplayFrustum); - } - break; case Qt::Key_P: Menu::getInstance()->triggerOption(MenuOption::FirstPerson); break; - case Qt::Key_R: - if (isShifted) { - Menu::getInstance()->triggerOption(MenuOption::FrustumRenderMode); - } - break; case Qt::Key_Percent: Menu::getInstance()->triggerOption(MenuOption::Stats); break; @@ -2707,17 +2644,17 @@ QImage Application::renderAvatarBillboard() { return image; } -void Application::displaySide(Camera& whichCamera, bool selfAvatarOnly, RenderArgs::RenderSide renderSide) { +void Application::displaySide(Camera& theCamera, bool selfAvatarOnly, RenderArgs::RenderSide renderSide) { PROFILE_RANGE(__FUNCTION__); PerformanceTimer perfTimer("display"); PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings), "Application::displaySide()"); // transform by eye offset // load the view frustum - loadViewFrustum(whichCamera, _displayViewFrustum); + loadViewFrustum(theCamera, _displayViewFrustum); // flip x if in mirror mode (also requires reversing winding order for backface culling) - if (whichCamera.getMode() == CAMERA_MODE_MIRROR) { + if (theCamera.getMode() == CAMERA_MODE_MIRROR) { glScalef(-1.0f, 1.0f, 1.0f); glFrontFace(GL_CW); @@ -2725,32 +2662,32 @@ void Application::displaySide(Camera& whichCamera, bool selfAvatarOnly, RenderAr glFrontFace(GL_CCW); } - glm::vec3 eyeOffsetPos = whichCamera.getEyeOffsetPosition(); - glm::quat eyeOffsetOrient = whichCamera.getEyeOffsetOrientation(); + glm::vec3 eyeOffsetPos = theCamera.getEyeOffsetPosition(); + glm::quat eyeOffsetOrient = theCamera.getEyeOffsetOrientation(); glm::vec3 eyeOffsetAxis = glm::axis(eyeOffsetOrient); glRotatef(-glm::degrees(glm::angle(eyeOffsetOrient)), eyeOffsetAxis.x, eyeOffsetAxis.y, eyeOffsetAxis.z); glTranslatef(-eyeOffsetPos.x, -eyeOffsetPos.y, -eyeOffsetPos.z); - // transform view according to whichCamera + // transform view according to theCamera // could be myCamera (if in normal mode) // or could be viewFrustumOffsetCamera if in offset mode - glm::quat rotation = whichCamera.getRotation(); + glm::quat rotation = theCamera.getRotation(); glm::vec3 axis = glm::axis(rotation); glRotatef(-glm::degrees(glm::angle(rotation)), axis.x, axis.y, axis.z); // store view matrix without translation, which we'll use for precision-sensitive objects - updateUntranslatedViewMatrix(-whichCamera.getPosition()); + updateUntranslatedViewMatrix(-theCamera.getPosition()); // Equivalent to what is happening with _untranslatedViewMatrix and the _viewMatrixTranslation // the viewTransofmr object is updatded with the correct values and saved, // this is what is used for rendering the Entities and avatars Transform viewTransform; - viewTransform.setTranslation(whichCamera.getPosition()); + viewTransform.setTranslation(theCamera.getPosition()); viewTransform.setRotation(rotation); viewTransform.postTranslate(eyeOffsetPos); viewTransform.postRotate(eyeOffsetOrient); - if (whichCamera.getMode() == CAMERA_MODE_MIRROR) { + if (theCamera.getMode() == CAMERA_MODE_MIRROR) { viewTransform.setScale(Transform::Vec3(-1.0f, 1.0f, 1.0f)); } if (renderSide != RenderArgs::MONO) { @@ -2796,9 +2733,9 @@ void Application::displaySide(Camera& whichCamera, bool selfAvatarOnly, RenderAr // compute starfield alpha based on distance from atmosphere float alpha = 1.0f; if (Menu::getInstance()->isOptionChecked(MenuOption::Atmosphere)) { - const EnvironmentData& closestData = _environment.getClosestData(whichCamera.getPosition()); - float height = glm::distance(whichCamera.getPosition(), - closestData.getAtmosphereCenter(whichCamera.getPosition())); + const EnvironmentData& closestData = _environment.getClosestData(theCamera.getPosition()); + float height = glm::distance(theCamera.getPosition(), + closestData.getAtmosphereCenter(theCamera.getPosition())); if (height < closestData.getAtmosphereInnerRadius()) { alpha = 0.0f; @@ -2809,7 +2746,7 @@ void Application::displaySide(Camera& whichCamera, bool selfAvatarOnly, RenderAr } // finally render the starfield - _stars.render(whichCamera.getFieldOfView(), whichCamera.getAspectRatio(), whichCamera.getNearClip(), alpha); + _stars.render(theCamera.getFieldOfView(), theCamera.getAspectRatio(), theCamera.getNearClip(), alpha); } if (Menu::getInstance()->isOptionChecked(MenuOption::Wireframe)) { @@ -2821,7 +2758,7 @@ void Application::displaySide(Camera& whichCamera, bool selfAvatarOnly, RenderAr PerformanceTimer perfTimer("atmosphere"); PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings), "Application::displaySide() ... atmosphere..."); - _environment.renderAtmospheres(whichCamera); + _environment.renderAtmospheres(theCamera); } glEnable(GL_LIGHTING); glEnable(GL_DEPTH_TEST); @@ -2867,7 +2804,7 @@ void Application::displaySide(Camera& whichCamera, bool selfAvatarOnly, RenderAr - bool mirrorMode = (whichCamera.getMode() == CAMERA_MODE_MIRROR); + bool mirrorMode = (theCamera.getMode() == CAMERA_MODE_MIRROR); { PerformanceTimer perfTimer("avatars"); _avatarManager.renderAvatars(mirrorMode ? Avatar::MIRROR_RENDER_MODE : Avatar::NORMAL_RENDER_MODE, @@ -2896,20 +2833,12 @@ void Application::displaySide(Camera& whichCamera, bool selfAvatarOnly, RenderAr _nodeBoundsDisplay.draw(); // Render the world box - if (whichCamera.getMode() != CAMERA_MODE_MIRROR && Menu::getInstance()->isOptionChecked(MenuOption::Stats) && + if (theCamera.getMode() != CAMERA_MODE_MIRROR && Menu::getInstance()->isOptionChecked(MenuOption::Stats) && Menu::getInstance()->isOptionChecked(MenuOption::UserInterface)) { PerformanceTimer perfTimer("worldBox"); renderWorldBox(); } - // view frustum for debugging - if (Menu::getInstance()->isOptionChecked(MenuOption::DisplayFrustum) && whichCamera.getMode() != CAMERA_MODE_MIRROR) { - PerformanceTimer perfTimer("viewFrustum"); - PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings), - "Application::displaySide() ... renderViewFrustum..."); - renderViewFrustum(_viewFrustum); - } - // render octree fades if they exist if (_octreeFades.size() > 0) { PerformanceTimer perfTimer("octreeFades"); @@ -3136,167 +3065,6 @@ void Application::renderRearViewMirror(const QRect& region, bool billboard) { updateProjectionMatrix(_myCamera, updateViewFrustum); } -// renderViewFrustum() -// -// Description: this will render the view frustum bounds for EITHER the head -// or the "myCamera". -// -// Frustum rendering mode. For debug purposes, we allow drawing the frustum in a couple of different ways. -// We can draw it with each of these parts: -// * Origin Direction/Up/Right vectors - these will be drawn at the point of the camera -// * Near plane - this plane is drawn very close to the origin point. -// * Right/Left planes - these two planes are drawn between the near and far planes. -// * Far plane - the plane is drawn in the distance. -// Modes - the following modes, will draw the following parts. -// * All - draws all the parts listed above -// * Planes - draws the planes but not the origin vectors -// * Origin Vectors - draws the origin vectors ONLY -// * Near Plane - draws only the near plane -// * Far Plane - draws only the far plane -void Application::renderViewFrustum(ViewFrustum& viewFrustum) { - // Load it with the latest details! - loadViewFrustum(_myCamera, viewFrustum); - - glm::vec3 position = viewFrustum.getOffsetPosition(); - glm::vec3 direction = viewFrustum.getOffsetDirection(); - glm::vec3 up = viewFrustum.getOffsetUp(); - glm::vec3 right = viewFrustum.getOffsetRight(); - - // Get ready to draw some lines - glDisable(GL_LIGHTING); - glColor4f(1.0, 1.0, 1.0, 1.0); - glLineWidth(1.0); - glBegin(GL_LINES); - - if (Menu::getInstance()->getFrustumDrawMode() == FRUSTUM_DRAW_MODE_ALL - || Menu::getInstance()->getFrustumDrawMode() == FRUSTUM_DRAW_MODE_VECTORS) { - // Calculate the origin direction vectors - glm::vec3 lookingAt = position + (direction * 0.2f); - glm::vec3 lookingAtUp = position + (up * 0.2f); - glm::vec3 lookingAtRight = position + (right * 0.2f); - - // Looking At = white - glColor3f(1,1,1); - glVertex3f(position.x, position.y, position.z); - glVertex3f(lookingAt.x, lookingAt.y, lookingAt.z); - - // Looking At Up = purple - glColor3f(1,0,1); - glVertex3f(position.x, position.y, position.z); - glVertex3f(lookingAtUp.x, lookingAtUp.y, lookingAtUp.z); - - // Looking At Right = cyan - glColor3f(0,1,1); - glVertex3f(position.x, position.y, position.z); - glVertex3f(lookingAtRight.x, lookingAtRight.y, lookingAtRight.z); - } - - if (Menu::getInstance()->getFrustumDrawMode() == FRUSTUM_DRAW_MODE_ALL - || Menu::getInstance()->getFrustumDrawMode() == FRUSTUM_DRAW_MODE_PLANES - || Menu::getInstance()->getFrustumDrawMode() == FRUSTUM_DRAW_MODE_NEAR_PLANE) { - // Drawing the bounds of the frustum - // viewFrustum.getNear plane - bottom edge - glColor3f(1,0,0); - glVertex3f(viewFrustum.getNearBottomLeft().x, viewFrustum.getNearBottomLeft().y, viewFrustum.getNearBottomLeft().z); - glVertex3f(viewFrustum.getNearBottomRight().x, viewFrustum.getNearBottomRight().y, viewFrustum.getNearBottomRight().z); - - // viewFrustum.getNear plane - top edge - glVertex3f(viewFrustum.getNearTopLeft().x, viewFrustum.getNearTopLeft().y, viewFrustum.getNearTopLeft().z); - glVertex3f(viewFrustum.getNearTopRight().x, viewFrustum.getNearTopRight().y, viewFrustum.getNearTopRight().z); - - // viewFrustum.getNear plane - right edge - glVertex3f(viewFrustum.getNearBottomRight().x, viewFrustum.getNearBottomRight().y, viewFrustum.getNearBottomRight().z); - glVertex3f(viewFrustum.getNearTopRight().x, viewFrustum.getNearTopRight().y, viewFrustum.getNearTopRight().z); - - // viewFrustum.getNear plane - left edge - glVertex3f(viewFrustum.getNearBottomLeft().x, viewFrustum.getNearBottomLeft().y, viewFrustum.getNearBottomLeft().z); - glVertex3f(viewFrustum.getNearTopLeft().x, viewFrustum.getNearTopLeft().y, viewFrustum.getNearTopLeft().z); - } - - if (Menu::getInstance()->getFrustumDrawMode() == FRUSTUM_DRAW_MODE_ALL - || Menu::getInstance()->getFrustumDrawMode() == FRUSTUM_DRAW_MODE_PLANES - || Menu::getInstance()->getFrustumDrawMode() == FRUSTUM_DRAW_MODE_FAR_PLANE) { - // viewFrustum.getFar plane - bottom edge - glColor3f(0,1,0); - glVertex3f(viewFrustum.getFarBottomLeft().x, viewFrustum.getFarBottomLeft().y, viewFrustum.getFarBottomLeft().z); - glVertex3f(viewFrustum.getFarBottomRight().x, viewFrustum.getFarBottomRight().y, viewFrustum.getFarBottomRight().z); - - // viewFrustum.getFar plane - top edge - glVertex3f(viewFrustum.getFarTopLeft().x, viewFrustum.getFarTopLeft().y, viewFrustum.getFarTopLeft().z); - glVertex3f(viewFrustum.getFarTopRight().x, viewFrustum.getFarTopRight().y, viewFrustum.getFarTopRight().z); - - // viewFrustum.getFar plane - right edge - glVertex3f(viewFrustum.getFarBottomRight().x, viewFrustum.getFarBottomRight().y, viewFrustum.getFarBottomRight().z); - glVertex3f(viewFrustum.getFarTopRight().x, viewFrustum.getFarTopRight().y, viewFrustum.getFarTopRight().z); - - // viewFrustum.getFar plane - left edge - glVertex3f(viewFrustum.getFarBottomLeft().x, viewFrustum.getFarBottomLeft().y, viewFrustum.getFarBottomLeft().z); - glVertex3f(viewFrustum.getFarTopLeft().x, viewFrustum.getFarTopLeft().y, viewFrustum.getFarTopLeft().z); - } - - if (Menu::getInstance()->getFrustumDrawMode() == FRUSTUM_DRAW_MODE_ALL - || Menu::getInstance()->getFrustumDrawMode() == FRUSTUM_DRAW_MODE_PLANES) { - // RIGHT PLANE IS CYAN - // right plane - bottom edge - viewFrustum.getNear to distant - glColor3f(0,1,1); - glVertex3f(viewFrustum.getNearBottomRight().x, viewFrustum.getNearBottomRight().y, viewFrustum.getNearBottomRight().z); - glVertex3f(viewFrustum.getFarBottomRight().x, viewFrustum.getFarBottomRight().y, viewFrustum.getFarBottomRight().z); - - // right plane - top edge - viewFrustum.getNear to distant - glVertex3f(viewFrustum.getNearTopRight().x, viewFrustum.getNearTopRight().y, viewFrustum.getNearTopRight().z); - glVertex3f(viewFrustum.getFarTopRight().x, viewFrustum.getFarTopRight().y, viewFrustum.getFarTopRight().z); - - // LEFT PLANE IS BLUE - // left plane - bottom edge - viewFrustum.getNear to distant - glColor3f(0,0,1); - glVertex3f(viewFrustum.getNearBottomLeft().x, viewFrustum.getNearBottomLeft().y, viewFrustum.getNearBottomLeft().z); - glVertex3f(viewFrustum.getFarBottomLeft().x, viewFrustum.getFarBottomLeft().y, viewFrustum.getFarBottomLeft().z); - - // left plane - top edge - viewFrustum.getNear to distant - glVertex3f(viewFrustum.getNearTopLeft().x, viewFrustum.getNearTopLeft().y, viewFrustum.getNearTopLeft().z); - glVertex3f(viewFrustum.getFarTopLeft().x, viewFrustum.getFarTopLeft().y, viewFrustum.getFarTopLeft().z); - - // focal plane - bottom edge - glColor3f(1.0f, 0.0f, 1.0f); - float focalProportion = (viewFrustum.getFocalLength() - viewFrustum.getNearClip()) / - (viewFrustum.getFarClip() - viewFrustum.getNearClip()); - glm::vec3 focalBottomLeft = glm::mix(viewFrustum.getNearBottomLeft(), viewFrustum.getFarBottomLeft(), focalProportion); - glm::vec3 focalBottomRight = glm::mix(viewFrustum.getNearBottomRight(), - viewFrustum.getFarBottomRight(), focalProportion); - glVertex3f(focalBottomLeft.x, focalBottomLeft.y, focalBottomLeft.z); - glVertex3f(focalBottomRight.x, focalBottomRight.y, focalBottomRight.z); - - // focal plane - top edge - glm::vec3 focalTopLeft = glm::mix(viewFrustum.getNearTopLeft(), viewFrustum.getFarTopLeft(), focalProportion); - glm::vec3 focalTopRight = glm::mix(viewFrustum.getNearTopRight(), viewFrustum.getFarTopRight(), focalProportion); - glVertex3f(focalTopLeft.x, focalTopLeft.y, focalTopLeft.z); - glVertex3f(focalTopRight.x, focalTopRight.y, focalTopRight.z); - - // focal plane - left edge - glVertex3f(focalBottomLeft.x, focalBottomLeft.y, focalBottomLeft.z); - glVertex3f(focalTopLeft.x, focalTopLeft.y, focalTopLeft.z); - - // focal plane - right edge - glVertex3f(focalBottomRight.x, focalBottomRight.y, focalBottomRight.z); - glVertex3f(focalTopRight.x, focalTopRight.y, focalTopRight.z); - } - glEnd(); - glEnable(GL_LIGHTING); - - if (Menu::getInstance()->getFrustumDrawMode() == FRUSTUM_DRAW_MODE_ALL - || Menu::getInstance()->getFrustumDrawMode() == FRUSTUM_DRAW_MODE_KEYHOLE) { - // Draw the keyhole - float keyholeRadius = viewFrustum.getKeyholeRadius(); - if (keyholeRadius > 0.0f) { - glPushMatrix(); - glColor4f(1, 1, 0, 1); - glTranslatef(position.x, position.y, position.z); // where we actually want it! - DependencyManager::get()->renderSphere(keyholeRadius, 20, 20, false); - glPopMatrix(); - } - } -} - void Application::resetSensors() { DependencyManager::get()->reset(); DependencyManager::get()->reset(); diff --git a/interface/src/Application.h b/interface/src/Application.h index 036ede992d..d9ec5a1eae 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -417,7 +417,6 @@ private: void updateShadowMap(); void renderRearViewMirror(const QRect& region, bool billboard = false); - void renderViewFrustum(ViewFrustum& viewFrustum); void checkBandwidthMeterClick(); void setMenuShortcutsEnabled(bool enabled); @@ -481,7 +480,6 @@ private: PrioVR _prioVR; Camera _myCamera; // My view onto the world - Camera _viewFrustumOffsetCamera; // The camera we use to sometimes show the view frustum from an offset mode Camera _mirrorCamera; // Cammera for mirror view QRect _mirrorViewRect; RearMirrorTools* _rearMirrorTools; diff --git a/interface/src/Audio.cpp b/interface/src/Audio.cpp index 045a3d42fb..bd106d9bc6 100644 --- a/interface/src/Audio.cpp +++ b/interface/src/Audio.cpp @@ -66,6 +66,12 @@ Audio::Audio() : _inputRingBuffer(0), _receivedAudioStream(0, RECEIVED_AUDIO_STREAM_CAPACITY_FRAMES, InboundAudioStream::Settings()), _isStereoInput(false), + _outputBufferSizeFrames(DEFAULT_AUDIO_OUTPUT_BUFFER_SIZE_FRAMES), + _outputStarveDetectionEnabled(true), + _outputStarveDetectionStartTimeMsec(0), + _outputStarveDetectionCount(0), + _outputStarveDetectionPeriodMsec(DEFAULT_AUDIO_OUTPUT_STARVE_DETECTION_PERIOD), + _outputStarveDetectionThreshold(DEFAULT_AUDIO_OUTPUT_STARVE_DETECTION_THRESHOLD), _averagedLatency(0.0f), _lastInputLoudness(0.0f), _timeSinceLastClip(-1.0f), @@ -507,9 +513,9 @@ void Audio::setReverbOptions(const AudioEffectOptions* options) { } } -void Audio::addReverb(ty_gverb* gverb, int16_t* samplesData, int numSamples, QAudioFormat& audioFormat) { +void Audio::addReverb(ty_gverb* gverb, int16_t* samplesData, int numSamples, QAudioFormat& audioFormat, bool noEcho) { float wetFraction = DB_CO(_reverbOptions->getWetLevel()); - float dryFraction = (!_shouldEchoLocally) ? 0.0f : (1.0f - wetFraction); + float dryFraction = (noEcho) ? 0.0f : (1.0f - wetFraction); float lValue,rValue; for (int sample = 0; sample < numSamples; sample += audioFormat.channelCount()) { @@ -568,7 +574,7 @@ void Audio::handleLocalEchoAndReverb(QByteArray& inputByteArray) { int16_t* loopbackSamples = reinterpret_cast(loopBackByteArray.data()); int numLoopbackSamples = loopBackByteArray.size() / sizeof(int16_t); updateGverbOptions(); - addReverb(_gverbLocal, loopbackSamples, numLoopbackSamples, _outputFormat); + addReverb(_gverbLocal, loopbackSamples, numLoopbackSamples, _outputFormat, !_shouldEchoLocally); } if (_loopbackOutputDevice) { @@ -947,10 +953,24 @@ bool Audio::switchInputToAudioDevice(const QAudioDeviceInfo& inputDeviceInfo) { void Audio::outputNotify() { int recentUnfulfilled = _audioOutputIODevice.getRecentUnfulfilledReads(); if (recentUnfulfilled > 0) { - qDebug() << "WARNING --- WE HAD at least:" << recentUnfulfilled << "recently unfulfilled readData() calls"; + if (_outputStarveDetectionEnabled) { + quint64 now = usecTimestampNow() / 1000; + quint64 dt = now - _outputStarveDetectionStartTimeMsec; + if (dt > _outputStarveDetectionPeriodMsec) { + _outputStarveDetectionStartTimeMsec = now; + _outputStarveDetectionCount = 0; + } else { + _outputStarveDetectionCount += recentUnfulfilled; + if (_outputStarveDetectionCount > _outputStarveDetectionThreshold) { + int newOutputBufferSizeFrames = _outputBufferSizeFrames + 1; + qDebug() << "Starve detection threshold met, increasing buffer size to " << newOutputBufferSizeFrames; + setOutputBufferSize(newOutputBufferSizeFrames); - // TODO: Ryan Huffman -- add code here to increase the AUDIO_OUTPUT_BUFFER_SIZE_FRAMES... this code only - // runs in cases where the audio device requested data samples, and ran dry because we couldn't fulfill the request + _outputStarveDetectionStartTimeMsec = now; + _outputStarveDetectionCount = 0; + } + } + } } } @@ -978,13 +998,12 @@ bool Audio::switchOutputToAudioDevice(const QAudioDeviceInfo& outputDeviceInfo) outputFormatChanged(); - const int AUDIO_OUTPUT_BUFFER_SIZE_FRAMES = 3; - // setup our general output device for audio-mixer audio _audioOutput = new QAudioOutput(outputDeviceInfo, _outputFormat, this); + _audioOutput->setBufferSize(_outputBufferSizeFrames * _outputFrameSize * sizeof(int16_t)); + connect(_audioOutput, &QAudioOutput::notify, this, &Audio::outputNotify); - _audioOutput->setBufferSize(AUDIO_OUTPUT_BUFFER_SIZE_FRAMES * _outputFrameSize * sizeof(int16_t)); qDebug() << "Output Buffer capacity in frames: " << _audioOutput->bufferSize() / sizeof(int16_t) / (float)_outputFrameSize; _audioOutputIODevice.start(); @@ -1002,6 +1021,21 @@ bool Audio::switchOutputToAudioDevice(const QAudioDeviceInfo& outputDeviceInfo) return supportedFormat; } +void Audio::setOutputBufferSize(int numFrames) { + numFrames = std::min(std::max(numFrames, MIN_AUDIO_OUTPUT_BUFFER_SIZE_FRAMES), MAX_AUDIO_OUTPUT_BUFFER_SIZE_FRAMES); + if (numFrames != _outputBufferSizeFrames) { + qDebug() << "Audio output buffer size (frames): " << numFrames; + _outputBufferSizeFrames = numFrames; + + if (_audioOutput) { + // The buffer size can't be adjusted after QAudioOutput::start() has been called, so + // recreate the device by switching to the default. + QAudioDeviceInfo outputDeviceInfo = defaultAudioDeviceForMode(QAudio::AudioOutput); + switchOutputToAudioDevice(outputDeviceInfo); + } + } +} + // The following constant is operating system dependent due to differences in // the way input audio is handled. The audio input buffer size is inversely // proportional to the accelerator ratio. diff --git a/interface/src/Audio.h b/interface/src/Audio.h index be0e86e0af..edbeac5797 100644 --- a/interface/src/Audio.h +++ b/interface/src/Audio.h @@ -61,6 +61,13 @@ extern "C" { static const int NUM_AUDIO_CHANNELS = 2; +static const int DEFAULT_AUDIO_OUTPUT_BUFFER_SIZE_FRAMES = 3; +static const int MIN_AUDIO_OUTPUT_BUFFER_SIZE_FRAMES = 1; +static const int MAX_AUDIO_OUTPUT_BUFFER_SIZE_FRAMES = 20; +static const int DEFAULT_AUDIO_OUTPUT_STARVE_DETECTION_ENABLED = true; +static const int DEFAULT_AUDIO_OUTPUT_STARVE_DETECTION_THRESHOLD = 3; +static const int DEFAULT_AUDIO_OUTPUT_STARVE_DETECTION_PERIOD = 10 * 1000; // 10 Seconds + class QAudioInput; class QAudioOutput; class QIODevice; @@ -108,7 +115,18 @@ public: float getAudioOutputMsecsUnplayed() const; void setRecorder(RecorderPointer recorder) { _recorder = recorder; } - + + int getOutputBufferSize() { return _outputBufferSizeFrames; } + + bool getOutputStarveDetectionEnabled() { return _outputStarveDetectionEnabled; } + void setOutputStarveDetectionEnabled(bool enabled) { _outputStarveDetectionEnabled = enabled; } + + int getOutputStarveDetectionPeriod() { return _outputStarveDetectionPeriodMsec; } + void setOutputStarveDetectionPeriod(int msecs) { _outputStarveDetectionPeriodMsec = msecs; } + + int getOutputStarveDetectionThreshold() { return _outputStarveDetectionThreshold; } + void setOutputStarveDetectionThreshold(int threshold) { _outputStarveDetectionThreshold = threshold; } + static const float CALLBACK_ACCELERATOR_RATIO; public slots: @@ -137,6 +155,8 @@ public slots: void processReceivedSamples(const QByteArray& inputBuffer, QByteArray& outputBuffer); void sendMuteEnvironmentPacket(); + void setOutputBufferSize(int numFrames); + virtual bool outputLocalInjector(bool isStereo, qreal volume, AudioInjector* injector); bool switchInputToAudioDevice(const QString& inputDeviceName); @@ -184,6 +204,14 @@ private: QString _inputAudioDeviceName; QString _outputAudioDeviceName; + + int _outputBufferSizeFrames; + bool _outputStarveDetectionEnabled; + quint64 _outputStarveDetectionStartTimeMsec; + int _outputStarveDetectionCount; + int _outputStarveDetectionPeriodMsec; + int _outputStarveDetectionThreshold; // Maximum number of starves per _outputStarveDetectionPeriod before increasing buffer size + StDev _stdev; QElapsedTimer _timeSinceLastReceived; @@ -208,7 +236,7 @@ private: // Adds Reverb void initGverb(); void updateGverbOptions(); - void addReverb(ty_gverb* gverb, int16_t* samples, int numSamples, QAudioFormat& format); + void addReverb(ty_gverb* gverb, int16_t* samples, int numSamples, QAudioFormat& format, bool noEcho = false); void handleLocalEchoAndReverb(QByteArray& inputByteArray); diff --git a/interface/src/Camera.cpp b/interface/src/Camera.cpp index 313b7b7774..d08c59eb95 100644 --- a/interface/src/Camera.cpp +++ b/interface/src/Camera.cpp @@ -55,16 +55,44 @@ Camera::Camera() : _farClip(DEFAULT_FAR_CLIP), // default _hmdPosition(), _hmdRotation(), - _targetPosition(), - _targetRotation(), - _scale(1.0f) + _scale(1.0f), + _isKeepLookingAt(false), + _lookingAt(0.0f, 0.0f, 0.0f) { } void Camera::update(float deltaTime) { + if (_isKeepLookingAt) { + lookAt(_lookingAt); + } return; } +void Camera::setPosition(const glm::vec3& position) { + _position = position; +} + +void Camera::setRotation(const glm::quat& rotation) { + _rotation = rotation; + if (_isKeepLookingAt) { + lookAt(_lookingAt); + } +} + +void Camera::setHmdPosition(const glm::vec3& hmdPosition) { + _hmdPosition = hmdPosition; + if (_isKeepLookingAt) { + lookAt(_lookingAt); + } +} + +void Camera::setHmdRotation(const glm::quat& hmdRotation) { + _hmdRotation = hmdRotation; + if (_isKeepLookingAt) { + lookAt(_lookingAt); + } +} + float Camera::getFarClip() const { return (_scale * _farClip < std::numeric_limits::max()) ? _scale * _farClip @@ -81,15 +109,15 @@ void Camera::setFieldOfView(float f) { _fieldOfView = f; } -void Camera::setAspectRatio(float a) { +void Camera::setAspectRatio(float a) { _aspectRatio = a; } -void Camera::setNearClip(float n) { +void Camera::setNearClip(float n) { _nearClip = n; } -void Camera::setFarClip(float f) { +void Camera::setFarClip(float f) { _farClip = f; } @@ -136,3 +164,17 @@ void Camera::setModeString(const QString& mode) { QString Camera::getModeString() const { return modeToString(_mode); } + +void Camera::lookAt(const glm::vec3& lookAt) { + glm::vec3 up = IDENTITY_UP; + glm::mat4 lookAtMatrix = glm::lookAt(_position, lookAt, up); + glm::quat rotation = glm::quat_cast(lookAtMatrix); + rotation.w = -rotation.w; // Rosedale approved + _rotation = rotation; +} + +void Camera::keepLookingAt(const glm::vec3& point) { + lookAt(point); + _isKeepLookingAt = true; + _lookingAt = point; +} diff --git a/interface/src/Camera.h b/interface/src/Camera.h index 7fcf9404cd..7c6951b920 100644 --- a/interface/src/Camera.h +++ b/interface/src/Camera.h @@ -43,9 +43,9 @@ public: void update( float deltaTime ); - void setRotation(const glm::quat& rotation) { _rotation = rotation; }; - void setHmdPosition(const glm::vec3& hmdPosition) { _hmdPosition = hmdPosition; } - void setHmdRotation(const glm::quat& hmdRotation) { _hmdRotation = hmdRotation; }; + void setRotation(const glm::quat& rotation); + void setHmdPosition(const glm::vec3& hmdPosition); + void setHmdRotation(const glm::quat& hmdRotation); void setMode(CameraMode m); void setFieldOfView(float f); @@ -73,13 +73,25 @@ public slots: void setModeString(const QString& mode); glm::vec3 getPosition() const { return _position + _hmdPosition; } - void setPosition(const glm::vec3& position) { _position = position; } + void setPosition(const glm::vec3& position); void setOrientation(const glm::quat& orientation) { setRotation(orientation); } glm::quat getOrientation() const { return getRotation(); } PickRay computePickRay(float x, float y); PickRay computeViewPickRay(float xRatio, float yRatio); + + // These only work on independent cameras + /// one time change to what the camera is looking at + void lookAt(const glm::vec3& value); + + /// fix what the camera is looking at, and keep the camera looking at this even if position changes + void keepLookingAt(const glm::vec3& value); + + /// stops the keep looking at feature, doesn't change what's being looked at, but will stop camera from + /// continuing to update it's orientation to keep looking at the item + void stopLooking() { _isKeepLookingAt = false; } + signals: void modeUpdated(const QString& newMode); @@ -95,9 +107,9 @@ private: glm::quat _rotation; glm::vec3 _hmdPosition; glm::quat _hmdRotation; - glm::vec3 _targetPosition; - glm::quat _targetRotation; float _scale; + bool _isKeepLookingAt; + glm::vec3 _lookingAt; }; #endif // hifi_Camera_h diff --git a/interface/src/Menu.cpp b/interface/src/Menu.cpp index 1399388a60..c50c722d4a 100644 --- a/interface/src/Menu.cpp +++ b/interface/src/Menu.cpp @@ -41,6 +41,7 @@ #include "Application.h" #include "AccountManager.h" +#include "Audio.h" #include "audio/AudioIOStatsRenderer.h" #include "audio/AudioScope.h" #include "devices/Faceshift.h" @@ -78,7 +79,6 @@ Menu* Menu::getInstance() { return _instance; } -const ViewFrustumOffset DEFAULT_FRUSTUM_OFFSET = {-135.0f, 0.0f, 0.0f, 25.0f, 0.0f}; const float DEFAULT_FACESHIFT_EYE_DEFLECTION = 0.25f; const QString DEFAULT_FACESHIFT_HOSTNAME = "localhost"; const float DEFAULT_AVATAR_LOD_DISTANCE_MULTIPLIER = 1.0f; @@ -98,8 +98,6 @@ Menu::Menu() : _realWorldFieldOfView(DEFAULT_REAL_WORLD_FIELD_OF_VIEW_DEGREES), _faceshiftEyeDeflection(DEFAULT_FACESHIFT_EYE_DEFLECTION), _faceshiftHostname(DEFAULT_FACESHIFT_HOSTNAME), - _frustumDrawMode(FRUSTUM_DRAW_MODE_ALL), - _viewFrustumOffset(DEFAULT_FRUSTUM_OFFSET), _jsConsole(NULL), _octreeStatsDialog(NULL), _lodToolsDialog(NULL), @@ -365,7 +363,6 @@ Menu::Menu() : addCheckableActionToQMenuAndActionHash(viewMenu, MenuOption::OffAxisProjection, 0, false); addCheckableActionToQMenuAndActionHash(viewMenu, MenuOption::TurnWithHead, 0, false); - addCheckableActionToQMenuAndActionHash(viewMenu, MenuOption::HeadMouse, 0, false); addDisabledActionAndSeparator(viewMenu, "Stats"); @@ -513,15 +510,6 @@ Menu::Menu() : addCheckableActionToQMenuAndActionHash(timingMenu, MenuOption::PipelineWarnings); addCheckableActionToQMenuAndActionHash(timingMenu, MenuOption::SuppressShortTimings); - QMenu* frustumMenu = developerMenu->addMenu("View Frustum"); - addCheckableActionToQMenuAndActionHash(frustumMenu, MenuOption::DisplayFrustum, Qt::SHIFT | Qt::Key_F); - addActionToQMenuAndActionHash(frustumMenu, - MenuOption::FrustumRenderMode, - Qt::SHIFT | Qt::Key_R, - this, - SLOT(cycleFrustumRenderMode())); - updateFrustumRenderModeAction(); - Audio::SharedPointer audioIO = DependencyManager::get