From e883d1dbb7447d67250daffa4b4d3c76d7de9aac Mon Sep 17 00:00:00 2001 From: Thijs Wenker Date: Wed, 17 Dec 2014 21:21:51 +0100 Subject: [PATCH 01/77] 3d mode --- examples/virtualKeyboard.js | 65 +++++++++++++++++++++++++++---------- 1 file changed, 48 insertions(+), 17 deletions(-) diff --git a/examples/virtualKeyboard.js b/examples/virtualKeyboard.js index ce793c6ea0..a788ccd76c 100644 --- a/examples/virtualKeyboard.js +++ b/examples/virtualKeyboard.js @@ -17,6 +17,9 @@ Script.include("libraries/globals.js"); +// experimental 3dmode +const THREE_D_MODE = true; + const KBD_UPPERCASE_DEFAULT = 0; const KBD_LOWERCASE_DEFAULT = 1; const KBD_UPPERCASE_HOVER = 2; @@ -272,14 +275,28 @@ function KeyboardKey(keyboard, keyProperties) { }; for (var i = 0; i < this.bounds.length; i++) { var newOverlay = Overlays.cloneOverlay(this.keyboard.background); - Overlays.editOverlay(newOverlay, { - x: this.keyboard.getX() + this.bounds[i][BOUND_X] * keyboard.scale, - y: this.keyboard.getY() + this.bounds[i][BOUND_Y] * keyboard.scale, - width: this.bounds[i][BOUND_W] * keyboard.scale, - height: this.bounds[i][BOUND_H] * keyboard.scale, - subImage: {width: this.bounds[i][BOUND_W], height: this.bounds[i][BOUND_H], x: this.bounds[i][BOUND_X], y: (KEYBOARD_HEIGHT * this.keyState) + this.bounds[i][BOUND_Y]}, - alpha: 1 - }); + if (THREE_D_MODE) { + Overlays.editOverlay(newOverlay, { + position: { + x: MyAvatar.position.x,// + this.bounds[i][BOUND_X] * 0.01,// /*+ this.keyboard.getX()*/ + this.bounds[i][BOUND_X] * keyboard.scale, + y: MyAvatar.position.y,// - this.bounds[i][BOUND_Y] * 0.01,// /*+ this.keyboard.getY()*/ + this.bounds[i][BOUND_Y] * keyboard.scale, + z: MyAvatar.position.z + }, + width: this.bounds[i][BOUND_W] * keyboard.scale, + height: this.bounds[i][BOUND_H] * keyboard.scale, + subImage: {width: this.bounds[i][BOUND_W], height: this.bounds[i][BOUND_H], x: this.bounds[i][BOUND_X], y: (KEYBOARD_HEIGHT * this.keyState) + this.bounds[i][BOUND_Y]}, + alpha: 1 + }); + } else { + Overlays.editOverlay(newOverlay, { + x: this.keyboard.getX() + this.bounds[i][BOUND_X] * keyboard.scale, + y: this.keyboard.getY() + this.bounds[i][BOUND_Y] * keyboard.scale, + width: this.bounds[i][BOUND_W] * keyboard.scale, + height: this.bounds[i][BOUND_H] * keyboard.scale, + subImage: {width: this.bounds[i][BOUND_W], height: this.bounds[i][BOUND_H], x: this.bounds[i][BOUND_X], y: (KEYBOARD_HEIGHT * this.keyState) + this.bounds[i][BOUND_Y]}, + alpha: 1 + }); + } this.overlays.push(newOverlay); } } @@ -301,15 +318,29 @@ function Keyboard() { this.getY = function() { return windowDimensions.y - this.height(); }; - this.background = Overlays.addOverlay("image", { - x: this.getX(), - y: this.getY(), - width: this.width(), - height: this.height(), - subImage: {width: KEYBOARD_WIDTH, height: KEYBOARD_HEIGHT, y: KEYBOARD_HEIGHT * KBD_BACKGROUND}, - imageURL: KEYBOARD_URL, - alpha: 1 - }); + if (THREE_D_MODE) { + this.background = Overlays.addOverlay("billboard", { + scale: 1, + position: MyAvatar.position, + rotation: MyAvatar.rotation, + width: this.width(), + height: this.height(), + subImage: {width: KEYBOARD_WIDTH, height: KEYBOARD_HEIGHT, y: KEYBOARD_HEIGHT * KBD_BACKGROUND}, + isFacingAvatar: false, + url: KEYBOARD_URL, + alpha: 1 + }); + } else { + this.background = Overlays.addOverlay("image", { + x: this.getX(), + y: this.getY(), + width: this.width(), + height: this.height(), + subImage: {width: KEYBOARD_WIDTH, height: KEYBOARD_HEIGHT, y: KEYBOARD_HEIGHT * KBD_BACKGROUND}, + imageURL: KEYBOARD_URL, + alpha: 1 + }); + } this.rescale = function() { this.scale = windowDimensions.x / KEYBOARD_WIDTH; Overlays.editOverlay(tthis.background, { From e38aa89418bde960d4132a269e6db27ae66a91de Mon Sep 17 00:00:00 2001 From: Thijs Wenker Date: Mon, 29 Dec 2014 21:11:34 +0100 Subject: [PATCH 02/77] Overwrite keypress of Enter key --- examples/virtualKeyboard.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/examples/virtualKeyboard.js b/examples/virtualKeyboard.js index ce793c6ea0..aede5c69d5 100644 --- a/examples/virtualKeyboard.js +++ b/examples/virtualKeyboard.js @@ -26,6 +26,8 @@ const KBD_BACKGROUND = 4; const KEYBOARD_URL = HIFI_PUBLIC_BUCKET + "images/keyboard.svg"; const CURSOR_URL = HIFI_PUBLIC_BUCKET + "images/cursor.svg"; +const RETURN_CHARCODE = 0x01000004; +const ENTER_CHARCODE = 0x01000005; const SPACEBAR_CHARCODE = 32; const KEYBOARD_WIDTH = 1174.7; @@ -576,7 +578,10 @@ function Cursor() { function keyPressEvent(event) { if (event.key === SPACEBAR_CHARCODE) { keyboard.pressFocussedKey(); + } else if (event.key === ENTER_CHARCODE || event.key === RETURN_CHARCODE) { + print("Enter pressed"); } + } function keyReleaseEvent(event) { @@ -591,7 +596,11 @@ function scriptEnding() { Overlays.deleteOverlay(text); Overlays.deleteOverlay(textSizeMeasureOverlay); Controller.releaseKeyEvents({key: SPACEBAR_CHARCODE}); + Controller.releaseKeyEvents({key: RETURN_CHARCODE}); + Controller.releaseKeyEvents({key: ENTER_CHARCODE}); } +Controller.captureKeyEvents({key: RETURN_CHARCODE}); +Controller.captureKeyEvents({key: ENTER_CHARCODE}); Controller.captureKeyEvents({key: SPACEBAR_CHARCODE}); Controller.keyPressEvent.connect(keyPressEvent); Controller.keyReleaseEvent.connect(keyReleaseEvent); From d299f3f0c5e0bb3acf07e6218b6025a264b0ba66 Mon Sep 17 00:00:00 2001 From: Thijs Wenker Date: Mon, 29 Dec 2014 23:10:15 +0100 Subject: [PATCH 03/77] no 3d mode for now --- examples/virtualKeyboard.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/virtualKeyboard.js b/examples/virtualKeyboard.js index a580bc7bcc..24b6cd39a1 100644 --- a/examples/virtualKeyboard.js +++ b/examples/virtualKeyboard.js @@ -18,7 +18,7 @@ Script.include("libraries/globals.js"); // experimental 3dmode -const THREE_D_MODE = true; +const THREE_D_MODE = false; const KBD_UPPERCASE_DEFAULT = 0; const KBD_LOWERCASE_DEFAULT = 1; From 4eec066d691f83baccc59ef1291c7cabb4663b6a Mon Sep 17 00:00:00 2001 From: Thijs Wenker Date: Tue, 30 Dec 2014 19:51:53 +0100 Subject: [PATCH 04/77] split up virtualKeyboard script in a library and two script that will use it: virtualKeyboardLocation.js - Location through virtual keyboard virtualKeyboardTextEntityExample.js - Initial example for virtual keyboard --- examples/{ => libraries}/virtualKeyboard.js | 202 +++---------------- examples/virtualKeyboardLocation.js | 185 +++++++++++++++++ examples/virtualKeyboardTextEntityExample.js | 177 ++++++++++++++++ 3 files changed, 385 insertions(+), 179 deletions(-) rename examples/{ => libraries}/virtualKeyboard.js (75%) create mode 100644 examples/virtualKeyboardLocation.js create mode 100644 examples/virtualKeyboardTextEntityExample.js diff --git a/examples/virtualKeyboard.js b/examples/libraries/virtualKeyboard.js similarity index 75% rename from examples/virtualKeyboard.js rename to examples/libraries/virtualKeyboard.js index 24b6cd39a1..ba9a30974e 100644 --- a/examples/virtualKeyboard.js +++ b/examples/libraries/virtualKeyboard.js @@ -9,8 +9,6 @@ // Usage: Enable VR-mode and go to First person mode, // look at the key that you would like to press, and press the spacebar on your "REAL" keyboard. // -// leased some code from newEditEntities.js for Text Entity example -// // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // @@ -18,26 +16,26 @@ Script.include("libraries/globals.js"); // experimental 3dmode -const THREE_D_MODE = false; +THREE_D_MODE = false; -const KBD_UPPERCASE_DEFAULT = 0; -const KBD_LOWERCASE_DEFAULT = 1; -const KBD_UPPERCASE_HOVER = 2; -const KBD_LOWERCASE_HOVER = 3; -const KBD_BACKGROUND = 4; +KBD_UPPERCASE_DEFAULT = 0; +KBD_LOWERCASE_DEFAULT = 1; +KBD_UPPERCASE_HOVER = 2; +KBD_LOWERCASE_HOVER = 3; +KBD_BACKGROUND = 4; -const KEYBOARD_URL = HIFI_PUBLIC_BUCKET + "images/keyboard.svg"; -const CURSOR_URL = HIFI_PUBLIC_BUCKET + "images/cursor.svg"; +KEYBOARD_URL = HIFI_PUBLIC_BUCKET + "images/keyboard.svg"; +CURSOR_URL = HIFI_PUBLIC_BUCKET + "images/cursor.svg"; -const RETURN_CHARCODE = 0x01000004; -const ENTER_CHARCODE = 0x01000005; -const SPACEBAR_CHARCODE = 32; +RETURN_CHARCODE = 0x01000004; +ENTER_CHARCODE = 0x01000005; +SPACEBAR_CHARCODE = 32; -const KEYBOARD_WIDTH = 1174.7; -const KEYBOARD_HEIGHT = 434.1; +KEYBOARD_WIDTH = 1174.7; +KEYBOARD_HEIGHT = 434.1; -const CURSOR_WIDTH = 33.9; -const CURSOR_HEIGHT = 33.9; +CURSOR_WIDTH = 33.9; +CURSOR_HEIGHT = 33.9; // VIEW_ANGLE can be adjusted to your likings, the smaller the faster movement. // Try setting it to 60 if it goes too fast for you. @@ -52,8 +50,8 @@ const BOUND_Y = 1; const BOUND_W = 2; const BOUND_H = 3; -const KEY_STATE_LOWER = 0; -const KEY_STATE_UPPER = 1; +KEY_STATE_LOWER = 0; +KEY_STATE_UPPER = 1; const TEXT_MARGIN_TOP = 0.15; const TEXT_MARGIN_LEFT = 0.15; @@ -62,131 +60,8 @@ const TEXT_MARGIN_BOTTOM = 0.17; var windowDimensions = Controller.getViewportDimensions(); var cursor = null; -var keyboard = new Keyboard(); -var textFontSize = 9; -var text = null; -var textText = ""; -var textSizeMeasureOverlay = Overlays.addOverlay("text3d", {visible: false}); -function appendChar(char) { - textText += char; - updateTextOverlay(); - Overlays.editOverlay(text, {text: textText}); -} - -function deleteChar() { - if (textText.length > 0) { - textText = textText.substring(0, textText.length - 1); - updateTextOverlay(); - } -} - -function updateTextOverlay() { - var textLines = textText.split("\n"); - var maxLineWidth = 0; - for (textLine in textLines) { - var lineWidth = Overlays.textSize(text, textLines[textLine]).width; - if (lineWidth > maxLineWidth) { - maxLineWidth = lineWidth; - } - } - var suggestedFontSize = (windowDimensions.x / maxLineWidth) * textFontSize * 0.90; - var maxFontSize = 190 / textLines.length; - textFontSize = (suggestedFontSize > maxFontSize) ? maxFontSize : suggestedFontSize; - var topMargin = (250 - (textFontSize * textLines.length)) / 4; - Overlays.editOverlay(text, {text: textText, font: {size: textFontSize}, topMargin: topMargin}); - var maxLineWidth = 0; - for (textLine in textLines) { - var lineWidth = Overlays.textSize(text, textLines[textLine]).width; - if (lineWidth > maxLineWidth) { - maxLineWidth = lineWidth; - } - } - Overlays.editOverlay(text, {leftMargin: (windowDimensions.x - maxLineWidth) / 2}); -} - -keyboard.onKeyPress = function(event) { - if (event.event == 'keypress') { - appendChar(event.char); - } else if (event.event == 'enter') { - appendChar("\n"); - } -}; - -keyboard.onKeyRelease = function(event) { - print("Key release event test"); - // you can cancel a key by releasing its focusing before releasing it - if (event.focus) { - if (event.event == 'delete') { - deleteChar(); - } else if (event.event == 'submit') { - print(textText); - - var position = Vec3.sum(MyAvatar.position, Vec3.multiply(Quat.getFront(MyAvatar.orientation), SPAWN_DISTANCE)); - - var textLines = textText.split("\n"); - var maxLineWidth = 0; - for (textLine in textLines) { - var lineWidth = Overlays.textSize(textSizeMeasureOverlay, textLines[textLine]).width; - if (lineWidth > maxLineWidth) { - maxLineWidth = lineWidth; - } - } - var usernameLine = "--" + GlobalServices.myUsername; - var usernameWidth = Overlays.textSize(textSizeMeasureOverlay, usernameLine).width; - if (maxLineWidth < usernameWidth) { - maxLineWidth = usernameWidth; - } else { - var spaceableWidth = maxLineWidth - usernameWidth; - var spaceWidth = Overlays.textSize(textSizeMeasureOverlay, " ").width; - var numberOfSpaces = Math.floor(spaceableWidth / spaceWidth); - for (var i = 0; i < numberOfSpaces; i++) { - usernameLine = " " + usernameLine; - } - } - var dimension_x = maxLineWidth + TEXT_MARGIN_RIGHT + TEXT_MARGIN_LEFT; - if (position.x > 0 && position.y > 0 && position.z > 0) { - Entities.addEntity({ - type: "Text", - rotation: MyAvatar.orientation, - position: position, - dimensions: { x: dimension_x, y: (textLines.length + 1) * 0.14 + TEXT_MARGIN_TOP + TEXT_MARGIN_BOTTOM, z: DEFAULT_TEXT_DIMENSION_Z }, - backgroundColor: { red: 0, green: 0, blue: 0 }, - textColor: { red: 255, green: 255, blue: 255 }, - text: textText + "\n" + usernameLine - }); - } - textText = ""; - updateTextOverlay(); - } - } -}; - -keyboard.onFullyLoaded = function() { - print("Virtual-keyboard fully loaded."); - var dimensions = Controller.getViewportDimensions(); - text = Overlays.addOverlay("text", { - x: 0, - y: dimensions.y - keyboard.height() - 260, - width: dimensions.x, - height: 250, - backgroundColor: { red: 255, green: 255, blue: 255}, - color: { red: 0, green: 0, blue: 0}, - topMargin: 5, - leftMargin: 0, - font: {size: textFontSize}, - text: "", - alpha: 0.8 - }); - updateTextOverlay(); - // the cursor is being loaded after the keyboard, else it will be on the background of the keyboard - cursor = new Cursor(); - cursor.onUpdate = function(position) { - keyboard.setFocusPosition(position.x, position.y); - }; -}; - -function KeyboardKey(keyboard, keyProperties) { +KeyboardKey = (function(keyboard, keyProperties) { var tthis = this; this._focus = false; this._beingPressed = false; @@ -301,9 +176,9 @@ function KeyboardKey(keyboard, keyProperties) { } this.overlays.push(newOverlay); } -} +}); -function Keyboard() { +Keyboard = (function() { var tthis = this; this.focussed_key = -1; this.scale = windowDimensions.x / KEYBOARD_WIDTH; @@ -548,9 +423,9 @@ function Keyboard() { } }; this.keyboardTextureLoaded_timer = Script.setInterval(this.keyboardTextureLoaded, 250); -} +}); -function Cursor() { +Cursor = (function() { var tthis = this; this.x = windowDimensions.x / 2; this.y = windowDimensions.y / 2; @@ -604,35 +479,4 @@ function Cursor() { } }; Script.update.connect(this.update); -} - -function keyPressEvent(event) { - if (event.key === SPACEBAR_CHARCODE) { - keyboard.pressFocussedKey(); - } else if (event.key === ENTER_CHARCODE || event.key === RETURN_CHARCODE) { - print("Enter pressed"); - } - -} - -function keyReleaseEvent(event) { - if (event.key === SPACEBAR_CHARCODE) { - keyboard.releaseKeys(); - } -} - -function scriptEnding() { - keyboard.remove(); - cursor.remove(); - Overlays.deleteOverlay(text); - Overlays.deleteOverlay(textSizeMeasureOverlay); - Controller.releaseKeyEvents({key: SPACEBAR_CHARCODE}); - Controller.releaseKeyEvents({key: RETURN_CHARCODE}); - Controller.releaseKeyEvents({key: ENTER_CHARCODE}); -} -Controller.captureKeyEvents({key: RETURN_CHARCODE}); -Controller.captureKeyEvents({key: ENTER_CHARCODE}); -Controller.captureKeyEvents({key: SPACEBAR_CHARCODE}); -Controller.keyPressEvent.connect(keyPressEvent); -Controller.keyReleaseEvent.connect(keyReleaseEvent); -Script.scriptEnding.connect(scriptEnding); \ No newline at end of file +}); diff --git a/examples/virtualKeyboardLocation.js b/examples/virtualKeyboardLocation.js new file mode 100644 index 0000000000..a5688c4c34 --- /dev/null +++ b/examples/virtualKeyboardLocation.js @@ -0,0 +1,185 @@ +// +// virtualKeyboardTextEntityExample.js +// examples +// +// Created by Thijs Wenker on 11/18/14. +// Copyright 2014 High Fidelity, Inc. +// +// Control a virtual keyboard using your favorite HMD. +// Usage: Enable VR-mode and go to First person mode, +// look at the key that you would like to press, and press the spacebar on your "REAL" keyboard. +// +// Enter a location URL using your HMD. Press Enter to pop-up the virtual keyboard and location input. +// Press Space on the keyboard or the X button on your gamepad to press a key that you have selected. +// +// 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/virtualKeyboard.js"); + +const SPAWN_DISTANCE = 1; +const DEFAULT_TEXT_DIMENSION_Z = 0.02; + +const TEXT_MARGIN_TOP = 0.15; +const TEXT_MARGIN_LEFT = 0.15; +const TEXT_MARGIN_RIGHT = 0.17; +const TEXT_MARGIN_BOTTOM = 0.17; + +var windowDimensions = Controller.getViewportDimensions(); +var cursor = null; +var keyboard = new Keyboard(); +var textFontSize = 9; +var text = null; +var textText = ""; +var textSizeMeasureOverlay = Overlays.addOverlay("text3d", {visible: false}); + +function appendChar(char) { + textText += char; + updateTextOverlay(); + Overlays.editOverlay(text, {text: textText}); +} + +function deleteChar() { + if (textText.length > 0) { + textText = textText.substring(0, textText.length - 1); + updateTextOverlay(); + } +} + +function updateTextOverlay() { + var textLines = textText.split("\n"); + var maxLineWidth = 0; + for (textLine in textLines) { + var lineWidth = Overlays.textSize(text, textLines[textLine]).width; + if (lineWidth > maxLineWidth) { + maxLineWidth = lineWidth; + } + } + var suggestedFontSize = (windowDimensions.x / maxLineWidth) * textFontSize * 0.90; + var maxFontSize = 190 / textLines.length; + textFontSize = (suggestedFontSize > maxFontSize) ? maxFontSize : suggestedFontSize; + var topMargin = (250 - (textFontSize * textLines.length)) / 4; + Overlays.editOverlay(text, {text: textText, font: {size: textFontSize}, topMargin: topMargin}); + var maxLineWidth = 0; + for (textLine in textLines) { + var lineWidth = Overlays.textSize(text, textLines[textLine]).width; + if (lineWidth > maxLineWidth) { + maxLineWidth = lineWidth; + } + } + Overlays.editOverlay(text, {leftMargin: (windowDimensions.x - maxLineWidth) / 2}); +} + +keyboard.onKeyPress = function(event) { + if (event.event == 'keypress') { + appendChar(event.char); + } else if (event.event == 'enter') { + appendChar("\n"); + } +}; + +keyboard.onKeyRelease = function(event) { + print("Key release event test"); + // you can cancel a key by releasing its focusing before releasing it + if (event.focus) { + if (event.event == 'delete') { + deleteChar(); + } else if (event.event == 'submit') { + print(textText); + + var position = Vec3.sum(MyAvatar.position, Vec3.multiply(Quat.getFront(MyAvatar.orientation), SPAWN_DISTANCE)); + + var textLines = textText.split("\n"); + var maxLineWidth = 0; + for (textLine in textLines) { + var lineWidth = Overlays.textSize(textSizeMeasureOverlay, textLines[textLine]).width; + if (lineWidth > maxLineWidth) { + maxLineWidth = lineWidth; + } + } + var usernameLine = "--" + GlobalServices.myUsername; + var usernameWidth = Overlays.textSize(textSizeMeasureOverlay, usernameLine).width; + if (maxLineWidth < usernameWidth) { + maxLineWidth = usernameWidth; + } else { + var spaceableWidth = maxLineWidth - usernameWidth; + var spaceWidth = Overlays.textSize(textSizeMeasureOverlay, " ").width; + var numberOfSpaces = Math.floor(spaceableWidth / spaceWidth); + for (var i = 0; i < numberOfSpaces; i++) { + usernameLine = " " + usernameLine; + } + } + var dimension_x = maxLineWidth + TEXT_MARGIN_RIGHT + TEXT_MARGIN_LEFT; + if (position.x > 0 && position.y > 0 && position.z > 0) { + Entities.addEntity({ + type: "Text", + rotation: MyAvatar.orientation, + position: position, + dimensions: { x: dimension_x, y: (textLines.length + 1) * 0.14 + TEXT_MARGIN_TOP + TEXT_MARGIN_BOTTOM, z: DEFAULT_TEXT_DIMENSION_Z }, + backgroundColor: { red: 0, green: 0, blue: 0 }, + textColor: { red: 255, green: 255, blue: 255 }, + text: textText + "\n" + usernameLine + }); + } + textText = ""; + updateTextOverlay(); + } + } +}; + +keyboard.onFullyLoaded = function() { + print("Virtual-keyboard fully loaded."); + var dimensions = Controller.getViewportDimensions(); + text = Overlays.addOverlay("text", { + x: 0, + y: dimensions.y - keyboard.height() - 260, + width: dimensions.x, + height: 250, + backgroundColor: { red: 255, green: 255, blue: 255}, + color: { red: 0, green: 0, blue: 0}, + topMargin: 5, + leftMargin: 0, + font: {size: textFontSize}, + text: "", + alpha: 0.8 + }); + updateTextOverlay(); + // the cursor is being loaded after the keyboard, else it will be on the background of the keyboard + cursor = new Cursor(); + cursor.onUpdate = function(position) { + keyboard.setFocusPosition(position.x, position.y); + }; +}; + +function keyPressEvent(event) { + if (event.key === SPACEBAR_CHARCODE) { + keyboard.pressFocussedKey(); + } else if (event.key === ENTER_CHARCODE || event.key === RETURN_CHARCODE) { + print("Enter pressed"); + } + +} + +function keyReleaseEvent(event) { + if (event.key === SPACEBAR_CHARCODE) { + keyboard.releaseKeys(); + } +} + +function scriptEnding() { + keyboard.remove(); + cursor.remove(); + Overlays.deleteOverlay(text); + Overlays.deleteOverlay(textSizeMeasureOverlay); + Controller.releaseKeyEvents({key: SPACEBAR_CHARCODE}); + Controller.releaseKeyEvents({key: RETURN_CHARCODE}); + Controller.releaseKeyEvents({key: ENTER_CHARCODE}); +} + +Controller.captureKeyEvents({key: RETURN_CHARCODE}); +Controller.captureKeyEvents({key: ENTER_CHARCODE}); +Controller.captureKeyEvents({key: SPACEBAR_CHARCODE}); +Controller.keyPressEvent.connect(keyPressEvent); +Controller.keyReleaseEvent.connect(keyReleaseEvent); +Script.scriptEnding.connect(scriptEnding); diff --git a/examples/virtualKeyboardTextEntityExample.js b/examples/virtualKeyboardTextEntityExample.js new file mode 100644 index 0000000000..830c50ab1e --- /dev/null +++ b/examples/virtualKeyboardTextEntityExample.js @@ -0,0 +1,177 @@ +// +// virtualKeyboardTextEntityExample.js +// examples +// +// Created by Thijs Wenker on 11/18/14. +// Copyright 2014 High Fidelity, Inc. +// +// Control a virtual keyboard using your favorite HMD. +// Usage: Enable VR-mode and go to First person mode, +// look at the key that you would like to press, and press the spacebar on your "REAL" keyboard. +// +// leased some code from newEditEntities.js for Text Entity example +// +// 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/virtualKeyboard.js"); + +const SPAWN_DISTANCE = 1; +const DEFAULT_TEXT_DIMENSION_Z = 0.02; + +const TEXT_MARGIN_TOP = 0.15; +const TEXT_MARGIN_LEFT = 0.15; +const TEXT_MARGIN_RIGHT = 0.17; +const TEXT_MARGIN_BOTTOM = 0.17; + +var windowDimensions = Controller.getViewportDimensions(); +var cursor = null; +var keyboard = new Keyboard(); +var textFontSize = 9; +var text = null; +var textText = ""; +var textSizeMeasureOverlay = Overlays.addOverlay("text3d", {visible: false}); + +function appendChar(char) { + textText += char; + updateTextOverlay(); + Overlays.editOverlay(text, {text: textText}); +} + +function deleteChar() { + if (textText.length > 0) { + textText = textText.substring(0, textText.length - 1); + updateTextOverlay(); + } +} + +function updateTextOverlay() { + var textLines = textText.split("\n"); + var maxLineWidth = 0; + for (textLine in textLines) { + var lineWidth = Overlays.textSize(text, textLines[textLine]).width; + if (lineWidth > maxLineWidth) { + maxLineWidth = lineWidth; + } + } + var suggestedFontSize = (windowDimensions.x / maxLineWidth) * textFontSize * 0.90; + var maxFontSize = 190 / textLines.length; + textFontSize = (suggestedFontSize > maxFontSize) ? maxFontSize : suggestedFontSize; + var topMargin = (250 - (textFontSize * textLines.length)) / 4; + Overlays.editOverlay(text, {text: textText, font: {size: textFontSize}, topMargin: topMargin}); + var maxLineWidth = 0; + for (textLine in textLines) { + var lineWidth = Overlays.textSize(text, textLines[textLine]).width; + if (lineWidth > maxLineWidth) { + maxLineWidth = lineWidth; + } + } + Overlays.editOverlay(text, {leftMargin: (windowDimensions.x - maxLineWidth) / 2}); +} + +keyboard.onKeyPress = function(event) { + if (event.event == 'keypress') { + appendChar(event.char); + } else if (event.event == 'enter') { + appendChar("\n"); + } +}; + +keyboard.onKeyRelease = function(event) { + print("Key release event test"); + // you can cancel a key by releasing its focusing before releasing it + if (event.focus) { + if (event.event == 'delete') { + deleteChar(); + } else if (event.event == 'submit') { + print(textText); + + var position = Vec3.sum(MyAvatar.position, Vec3.multiply(Quat.getFront(MyAvatar.orientation), SPAWN_DISTANCE)); + + var textLines = textText.split("\n"); + var maxLineWidth = 0; + for (textLine in textLines) { + var lineWidth = Overlays.textSize(textSizeMeasureOverlay, textLines[textLine]).width; + if (lineWidth > maxLineWidth) { + maxLineWidth = lineWidth; + } + } + var usernameLine = "--" + GlobalServices.myUsername; + var usernameWidth = Overlays.textSize(textSizeMeasureOverlay, usernameLine).width; + if (maxLineWidth < usernameWidth) { + maxLineWidth = usernameWidth; + } else { + var spaceableWidth = maxLineWidth - usernameWidth; + var spaceWidth = Overlays.textSize(textSizeMeasureOverlay, " ").width; + var numberOfSpaces = Math.floor(spaceableWidth / spaceWidth); + for (var i = 0; i < numberOfSpaces; i++) { + usernameLine = " " + usernameLine; + } + } + var dimension_x = maxLineWidth + TEXT_MARGIN_RIGHT + TEXT_MARGIN_LEFT; + if (position.x > 0 && position.y > 0 && position.z > 0) { + Entities.addEntity({ + type: "Text", + rotation: MyAvatar.orientation, + position: position, + dimensions: { x: dimension_x, y: (textLines.length + 1) * 0.14 + TEXT_MARGIN_TOP + TEXT_MARGIN_BOTTOM, z: DEFAULT_TEXT_DIMENSION_Z }, + backgroundColor: { red: 0, green: 0, blue: 0 }, + textColor: { red: 255, green: 255, blue: 255 }, + text: textText + "\n" + usernameLine + }); + } + textText = ""; + updateTextOverlay(); + } + } +}; + +keyboard.onFullyLoaded = function() { + print("Virtual-keyboard fully loaded."); + var dimensions = Controller.getViewportDimensions(); + text = Overlays.addOverlay("text", { + x: 0, + y: dimensions.y - keyboard.height() - 260, + width: dimensions.x, + height: 250, + backgroundColor: { red: 255, green: 255, blue: 255}, + color: { red: 0, green: 0, blue: 0}, + topMargin: 5, + leftMargin: 0, + font: {size: textFontSize}, + text: "", + alpha: 0.8 + }); + updateTextOverlay(); + // the cursor is being loaded after the keyboard, else it will be on the background of the keyboard + cursor = new Cursor(); + cursor.onUpdate = function(position) { + keyboard.setFocusPosition(position.x, position.y); + }; +}; + +function keyPressEvent(event) { + if (event.key === SPACEBAR_CHARCODE) { + keyboard.pressFocussedKey(); + } +} + +function keyReleaseEvent(event) { + if (event.key === SPACEBAR_CHARCODE) { + keyboard.releaseKeys(); + } +} + +function scriptEnding() { + keyboard.remove(); + cursor.remove(); + Overlays.deleteOverlay(text); + Overlays.deleteOverlay(textSizeMeasureOverlay); + Controller.releaseKeyEvents({key: SPACEBAR_CHARCODE}); +} + +Controller.captureKeyEvents({key: SPACEBAR_CHARCODE}); +Controller.keyPressEvent.connect(keyPressEvent); +Controller.keyReleaseEvent.connect(keyReleaseEvent); +Script.scriptEnding.connect(scriptEnding); From a8122e5a85e8927f93b12af9d82d38436a690d86 Mon Sep 17 00:00:00 2001 From: Thijs Wenker Date: Tue, 30 Dec 2014 23:30:48 +0100 Subject: [PATCH 05/77] virtualKeyboard.js - scale 50% virtualKeyboardLocation.js - toggle visibility with Enter/Return key virtualKeyboardTextEntityExample.js - attempt to fix character glyphs --- examples/libraries/virtualKeyboard.js | 112 ++++++++++++------- examples/virtualKeyboardLocation.js | 4 +- examples/virtualKeyboardTextEntityExample.js | 24 +--- 3 files changed, 78 insertions(+), 62 deletions(-) diff --git a/examples/libraries/virtualKeyboard.js b/examples/libraries/virtualKeyboard.js index ba9a30974e..9e5fd4accb 100644 --- a/examples/libraries/virtualKeyboard.js +++ b/examples/libraries/virtualKeyboard.js @@ -37,6 +37,8 @@ KEYBOARD_HEIGHT = 434.1; CURSOR_WIDTH = 33.9; CURSOR_HEIGHT = 33.9; +KEYBOARD_SCALE_MULTIPLIER = 0.50; + // VIEW_ANGLE can be adjusted to your likings, the smaller the faster movement. // Try setting it to 60 if it goes too fast for you. const VIEW_ANGLE = 40.0; @@ -127,6 +129,11 @@ KeyboardKey = (function(keyboard, keyProperties) { }); } }; + this.updateVisibility = function() { + for (var i = 0; i < tthis.bounds.length; i++) { + Overlays.editOverlay(tthis.overlays[i], {visible: tthis.keyboard.visible}); + } + }; this.rescale = function() { for (var i = 0; i < tthis.bounds.length; i++) { Overlays.editOverlay(tthis.overlays[i], { @@ -153,26 +160,26 @@ KeyboardKey = (function(keyboard, keyProperties) { for (var i = 0; i < this.bounds.length; i++) { var newOverlay = Overlays.cloneOverlay(this.keyboard.background); if (THREE_D_MODE) { - Overlays.editOverlay(newOverlay, { - position: { - x: MyAvatar.position.x,// + this.bounds[i][BOUND_X] * 0.01,// /*+ this.keyboard.getX()*/ + this.bounds[i][BOUND_X] * keyboard.scale, - y: MyAvatar.position.y,// - this.bounds[i][BOUND_Y] * 0.01,// /*+ this.keyboard.getY()*/ + this.bounds[i][BOUND_Y] * keyboard.scale, - z: MyAvatar.position.z - }, - width: this.bounds[i][BOUND_W] * keyboard.scale, - height: this.bounds[i][BOUND_H] * keyboard.scale, - subImage: {width: this.bounds[i][BOUND_W], height: this.bounds[i][BOUND_H], x: this.bounds[i][BOUND_X], y: (KEYBOARD_HEIGHT * this.keyState) + this.bounds[i][BOUND_Y]}, - alpha: 1 - }); + Overlays.editOverlay(newOverlay, { + position: { + x: MyAvatar.position.x,// + this.bounds[i][BOUND_X] * 0.01,// /*+ this.keyboard.getX()*/ + this.bounds[i][BOUND_X] * keyboard.scale, + y: MyAvatar.position.y,// - this.bounds[i][BOUND_Y] * 0.01,// /*+ this.keyboard.getY()*/ + this.bounds[i][BOUND_Y] * keyboard.scale, + z: MyAvatar.position.z + }, + width: this.bounds[i][BOUND_W] * keyboard.scale, + height: this.bounds[i][BOUND_H] * keyboard.scale, + subImage: {width: this.bounds[i][BOUND_W], height: this.bounds[i][BOUND_H], x: this.bounds[i][BOUND_X], y: (KEYBOARD_HEIGHT * this.keyState) + this.bounds[i][BOUND_Y]}, + alpha: 1 + }); } else { - Overlays.editOverlay(newOverlay, { - x: this.keyboard.getX() + this.bounds[i][BOUND_X] * keyboard.scale, - y: this.keyboard.getY() + this.bounds[i][BOUND_Y] * keyboard.scale, - width: this.bounds[i][BOUND_W] * keyboard.scale, - height: this.bounds[i][BOUND_H] * keyboard.scale, - subImage: {width: this.bounds[i][BOUND_W], height: this.bounds[i][BOUND_H], x: this.bounds[i][BOUND_X], y: (KEYBOARD_HEIGHT * this.keyState) + this.bounds[i][BOUND_Y]}, - alpha: 1 - }); + Overlays.editOverlay(newOverlay, { + x: this.keyboard.getX() + this.bounds[i][BOUND_X] * keyboard.scale, + y: this.keyboard.getY() + this.bounds[i][BOUND_Y] * keyboard.scale, + width: this.bounds[i][BOUND_W] * keyboard.scale, + height: this.bounds[i][BOUND_H] * keyboard.scale, + subImage: {width: this.bounds[i][BOUND_W], height: this.bounds[i][BOUND_H], x: this.bounds[i][BOUND_X], y: (KEYBOARD_HEIGHT * this.keyState) + this.bounds[i][BOUND_Y]}, + alpha: 1 + }); } this.overlays.push(newOverlay); } @@ -181,8 +188,9 @@ KeyboardKey = (function(keyboard, keyProperties) { Keyboard = (function() { var tthis = this; this.focussed_key = -1; - this.scale = windowDimensions.x / KEYBOARD_WIDTH; + this.scale = (windowDimensions.x / KEYBOARD_WIDTH) * KEYBOARD_SCALE_MULTIPLIER; this.shift = false; + this.visible = true; this.width = function() { return KEYBOARD_WIDTH * tthis.scale; }; @@ -196,30 +204,30 @@ Keyboard = (function() { return windowDimensions.y - this.height(); }; if (THREE_D_MODE) { - this.background = Overlays.addOverlay("billboard", { - scale: 1, - position: MyAvatar.position, - rotation: MyAvatar.rotation, - width: this.width(), - height: this.height(), - subImage: {width: KEYBOARD_WIDTH, height: KEYBOARD_HEIGHT, y: KEYBOARD_HEIGHT * KBD_BACKGROUND}, - isFacingAvatar: false, - url: KEYBOARD_URL, - alpha: 1 - }); + this.background = Overlays.addOverlay("billboard", { + scale: 1, + position: MyAvatar.position, + rotation: MyAvatar.rotation, + width: this.width(), + height: this.height(), + subImage: {width: KEYBOARD_WIDTH, height: KEYBOARD_HEIGHT, y: KEYBOARD_HEIGHT * KBD_BACKGROUND}, + isFacingAvatar: false, + url: KEYBOARD_URL, + alpha: 1 + }); } else { - this.background = Overlays.addOverlay("image", { - x: this.getX(), - y: this.getY(), - width: this.width(), - height: this.height(), - subImage: {width: KEYBOARD_WIDTH, height: KEYBOARD_HEIGHT, y: KEYBOARD_HEIGHT * KBD_BACKGROUND}, - imageURL: KEYBOARD_URL, - alpha: 1 - }); + this.background = Overlays.addOverlay("image", { + x: this.getX(), + y: this.getY(), + width: this.width(), + height: this.height(), + subImage: {width: KEYBOARD_WIDTH, height: KEYBOARD_HEIGHT, y: KEYBOARD_HEIGHT * KBD_BACKGROUND}, + imageURL: KEYBOARD_URL, + alpha: 1 + }); } this.rescale = function() { - this.scale = windowDimensions.x / KEYBOARD_WIDTH; + this.scale = (windowDimensions.x / KEYBOARD_WIDTH) * KEYBOARD_SCALE_MULTIPLIER; Overlays.editOverlay(tthis.background, { x: this.getX(), y: this.getY(), @@ -312,6 +320,28 @@ Keyboard = (function() { } }; + this.show = function() { + tthis.visible = true; + tthis.updateVisibility(); + }; + + this.hide = function() { + tthis.visible = false; + tthis.updateVisibility(); + }; + + this.toggle = function() { + tthis.visible = !tthis.visible; + tthis.updateVisibility(); + }; + + this.updateVisibility = function() { + Overlays.editOverlay(tthis.background, { visible: tthis.visible }); + for (var i = 0; i < this.keys.length; i++) { + this.keys[i].updateVisibility(); + } + }; + this.onKeyPress = null; this.onKeyRelease = null; this.onSubmit = null; diff --git a/examples/virtualKeyboardLocation.js b/examples/virtualKeyboardLocation.js index a5688c4c34..eae6c982b2 100644 --- a/examples/virtualKeyboardLocation.js +++ b/examples/virtualKeyboardLocation.js @@ -2,7 +2,7 @@ // virtualKeyboardTextEntityExample.js // examples // -// Created by Thijs Wenker on 11/18/14. +// Created by Thijs Wenker on 12/28/14. // Copyright 2014 High Fidelity, Inc. // // Control a virtual keyboard using your favorite HMD. @@ -156,7 +156,7 @@ function keyPressEvent(event) { if (event.key === SPACEBAR_CHARCODE) { keyboard.pressFocussedKey(); } else if (event.key === ENTER_CHARCODE || event.key === RETURN_CHARCODE) { - print("Enter pressed"); + keyboard.toggle(); } } diff --git a/examples/virtualKeyboardTextEntityExample.js b/examples/virtualKeyboardTextEntityExample.js index 830c50ab1e..2d46397831 100644 --- a/examples/virtualKeyboardTextEntityExample.js +++ b/examples/virtualKeyboardTextEntityExample.js @@ -2,7 +2,7 @@ // virtualKeyboardTextEntityExample.js // examples // -// Created by Thijs Wenker on 11/18/14. +// Created by Thijs Wenker on 12/28/14. // Copyright 2014 High Fidelity, Inc. // // Control a virtual keyboard using your favorite HMD. @@ -45,29 +45,15 @@ function deleteChar() { updateTextOverlay(); } } - + function updateTextOverlay() { var textLines = textText.split("\n"); - var maxLineWidth = 0; - for (textLine in textLines) { - var lineWidth = Overlays.textSize(text, textLines[textLine]).width; - if (lineWidth > maxLineWidth) { - maxLineWidth = lineWidth; - } - } - var suggestedFontSize = (windowDimensions.x / maxLineWidth) * textFontSize * 0.90; - var maxFontSize = 190 / textLines.length; + var suggestedFontSize = (windowDimensions.x / Overlays.textSize(text, textLines).width) * textFontSize * 0.90; + var maxFontSize = 170 / textLines.length; textFontSize = (suggestedFontSize > maxFontSize) ? maxFontSize : suggestedFontSize; var topMargin = (250 - (textFontSize * textLines.length)) / 4; Overlays.editOverlay(text, {text: textText, font: {size: textFontSize}, topMargin: topMargin}); - var maxLineWidth = 0; - for (textLine in textLines) { - var lineWidth = Overlays.textSize(text, textLines[textLine]).width; - if (lineWidth > maxLineWidth) { - maxLineWidth = lineWidth; - } - } - Overlays.editOverlay(text, {leftMargin: (windowDimensions.x - maxLineWidth) / 2}); + Overlays.editOverlay(text, {leftMargin: (windowDimensions.x - Overlays.textSize(text, textLines).width) / 2}); } keyboard.onKeyPress = function(event) { From 11d66ae83f81da354603f1f311092572a7d53688 Mon Sep 17 00:00:00 2001 From: Thijs Wenker Date: Wed, 31 Dec 2014 00:51:34 +0100 Subject: [PATCH 06/77] fixed text entity height --- examples/virtualKeyboardTextEntityExample.js | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/examples/virtualKeyboardTextEntityExample.js b/examples/virtualKeyboardTextEntityExample.js index 2d46397831..38beb08277 100644 --- a/examples/virtualKeyboardTextEntityExample.js +++ b/examples/virtualKeyboardTextEntityExample.js @@ -48,7 +48,7 @@ function deleteChar() { function updateTextOverlay() { var textLines = textText.split("\n"); - var suggestedFontSize = (windowDimensions.x / Overlays.textSize(text, textLines).width) * textFontSize * 0.90; + var suggestedFontSize = (windowDimensions.x / Overlays.textSize(text, textText).width) * textFontSize * 0.90; var maxFontSize = 170 / textLines.length; textFontSize = (suggestedFontSize > maxFontSize) ? maxFontSize : suggestedFontSize; var topMargin = (250 - (textFontSize * textLines.length)) / 4; @@ -76,13 +76,7 @@ keyboard.onKeyRelease = function(event) { var position = Vec3.sum(MyAvatar.position, Vec3.multiply(Quat.getFront(MyAvatar.orientation), SPAWN_DISTANCE)); var textLines = textText.split("\n"); - var maxLineWidth = 0; - for (textLine in textLines) { - var lineWidth = Overlays.textSize(textSizeMeasureOverlay, textLines[textLine]).width; - if (lineWidth > maxLineWidth) { - maxLineWidth = lineWidth; - } - } + var maxLineWidth = Overlays.textSize(textSizeMeasureOverlay, textText).width; var usernameLine = "--" + GlobalServices.myUsername; var usernameWidth = Overlays.textSize(textSizeMeasureOverlay, usernameLine).width; if (maxLineWidth < usernameWidth) { @@ -104,7 +98,8 @@ keyboard.onKeyRelease = function(event) { dimensions: { x: dimension_x, y: (textLines.length + 1) * 0.14 + TEXT_MARGIN_TOP + TEXT_MARGIN_BOTTOM, z: DEFAULT_TEXT_DIMENSION_Z }, backgroundColor: { red: 0, green: 0, blue: 0 }, textColor: { red: 255, green: 255, blue: 255 }, - text: textText + "\n" + usernameLine + text: textText + "\n" + usernameLine, + lineHeight: 0.1 }); } textText = ""; From e856d302d38bee8d4ab9d421e78674842d757819 Mon Sep 17 00:00:00 2001 From: Thijs Wenker Date: Wed, 31 Dec 2014 01:37:51 +0100 Subject: [PATCH 07/77] - improved keyboard visibility setting - added posibility to teleport to location through hmd --- examples/libraries/virtualKeyboard.js | 19 ++++-- examples/virtualKeyboardLocation.js | 88 +++++---------------------- 2 files changed, 28 insertions(+), 79 deletions(-) diff --git a/examples/libraries/virtualKeyboard.js b/examples/libraries/virtualKeyboard.js index 9e5fd4accb..7e18ba1b5c 100644 --- a/examples/libraries/virtualKeyboard.js +++ b/examples/libraries/virtualKeyboard.js @@ -169,7 +169,8 @@ KeyboardKey = (function(keyboard, keyProperties) { width: this.bounds[i][BOUND_W] * keyboard.scale, height: this.bounds[i][BOUND_H] * keyboard.scale, subImage: {width: this.bounds[i][BOUND_W], height: this.bounds[i][BOUND_H], x: this.bounds[i][BOUND_X], y: (KEYBOARD_HEIGHT * this.keyState) + this.bounds[i][BOUND_Y]}, - alpha: 1 + alpha: 1, + visible: tthis.keyboard.visible }); } else { Overlays.editOverlay(newOverlay, { @@ -178,19 +179,20 @@ KeyboardKey = (function(keyboard, keyProperties) { width: this.bounds[i][BOUND_W] * keyboard.scale, height: this.bounds[i][BOUND_H] * keyboard.scale, subImage: {width: this.bounds[i][BOUND_W], height: this.bounds[i][BOUND_H], x: this.bounds[i][BOUND_X], y: (KEYBOARD_HEIGHT * this.keyState) + this.bounds[i][BOUND_Y]}, - alpha: 1 + alpha: 1, + visible: tthis.keyboard.visible }); } this.overlays.push(newOverlay); } }); -Keyboard = (function() { +Keyboard = (function(params) { var tthis = this; this.focussed_key = -1; this.scale = (windowDimensions.x / KEYBOARD_WIDTH) * KEYBOARD_SCALE_MULTIPLIER; this.shift = false; - this.visible = true; + this.visible = params.visible != undefined ? params.visible :true; this.width = function() { return KEYBOARD_WIDTH * tthis.scale; }; @@ -213,7 +215,8 @@ Keyboard = (function() { subImage: {width: KEYBOARD_WIDTH, height: KEYBOARD_HEIGHT, y: KEYBOARD_HEIGHT * KBD_BACKGROUND}, isFacingAvatar: false, url: KEYBOARD_URL, - alpha: 1 + alpha: 1, + visible: this.visible }); } else { this.background = Overlays.addOverlay("image", { @@ -223,7 +226,8 @@ Keyboard = (function() { height: this.height(), subImage: {width: KEYBOARD_WIDTH, height: KEYBOARD_HEIGHT, y: KEYBOARD_HEIGHT * KBD_BACKGROUND}, imageURL: KEYBOARD_URL, - alpha: 1 + alpha: 1, + visible: this.visible }); } this.rescale = function() { @@ -265,6 +269,9 @@ Keyboard = (function() { }; this.pressFocussedKey = function() { + if (!tthis.visible) { + return tthis; + } if (tthis.focussed_key != -1) { if (tthis.keys[tthis.focussed_key].event == 'shift') { tthis.toggleShift(); diff --git a/examples/virtualKeyboardLocation.js b/examples/virtualKeyboardLocation.js index eae6c982b2..2ff98c4c43 100644 --- a/examples/virtualKeyboardLocation.js +++ b/examples/virtualKeyboardLocation.js @@ -18,64 +18,40 @@ Script.include("libraries/virtualKeyboard.js"); -const SPAWN_DISTANCE = 1; -const DEFAULT_TEXT_DIMENSION_Z = 0.02; - -const TEXT_MARGIN_TOP = 0.15; -const TEXT_MARGIN_LEFT = 0.15; -const TEXT_MARGIN_RIGHT = 0.17; -const TEXT_MARGIN_BOTTOM = 0.17; - var windowDimensions = Controller.getViewportDimensions(); var cursor = null; -var keyboard = new Keyboard(); +var keyboard = new Keyboard({visible: false}); var textFontSize = 9; var text = null; -var textText = ""; -var textSizeMeasureOverlay = Overlays.addOverlay("text3d", {visible: false}); +var locationURL = ""; function appendChar(char) { - textText += char; + locationURL += char; updateTextOverlay(); - Overlays.editOverlay(text, {text: textText}); + Overlays.editOverlay(text, {text: locationURL}); } function deleteChar() { - if (textText.length > 0) { - textText = textText.substring(0, textText.length - 1); + if (locationURL.length > 0) { + locationURL = locationURL.substring(0, locationURL.length - 1); updateTextOverlay(); } } function updateTextOverlay() { - var textLines = textText.split("\n"); - var maxLineWidth = 0; - for (textLine in textLines) { - var lineWidth = Overlays.textSize(text, textLines[textLine]).width; - if (lineWidth > maxLineWidth) { - maxLineWidth = lineWidth; - } - } + var maxLineWidth = Overlays.textSize(text, locationURL).width; var suggestedFontSize = (windowDimensions.x / maxLineWidth) * textFontSize * 0.90; - var maxFontSize = 190 / textLines.length; + var maxFontSize = 140; textFontSize = (suggestedFontSize > maxFontSize) ? maxFontSize : suggestedFontSize; - var topMargin = (250 - (textFontSize * textLines.length)) / 4; - Overlays.editOverlay(text, {text: textText, font: {size: textFontSize}, topMargin: topMargin}); - var maxLineWidth = 0; - for (textLine in textLines) { - var lineWidth = Overlays.textSize(text, textLines[textLine]).width; - if (lineWidth > maxLineWidth) { - maxLineWidth = lineWidth; - } - } + var topMargin = (250 - textFontSize) / 4; + Overlays.editOverlay(text, {text: locationURL, font: {size: textFontSize}, topMargin: topMargin}); + maxLineWidth = Overlays.textSize(text, locationURL).width; Overlays.editOverlay(text, {leftMargin: (windowDimensions.x - maxLineWidth) / 2}); } keyboard.onKeyPress = function(event) { if (event.event == 'keypress') { appendChar(event.char); - } else if (event.event == 'enter') { - appendChar("\n"); } }; @@ -85,44 +61,10 @@ keyboard.onKeyRelease = function(event) { if (event.focus) { if (event.event == 'delete') { deleteChar(); - } else if (event.event == 'submit') { - print(textText); - - var position = Vec3.sum(MyAvatar.position, Vec3.multiply(Quat.getFront(MyAvatar.orientation), SPAWN_DISTANCE)); - - var textLines = textText.split("\n"); - var maxLineWidth = 0; - for (textLine in textLines) { - var lineWidth = Overlays.textSize(textSizeMeasureOverlay, textLines[textLine]).width; - if (lineWidth > maxLineWidth) { - maxLineWidth = lineWidth; - } - } - var usernameLine = "--" + GlobalServices.myUsername; - var usernameWidth = Overlays.textSize(textSizeMeasureOverlay, usernameLine).width; - if (maxLineWidth < usernameWidth) { - maxLineWidth = usernameWidth; - } else { - var spaceableWidth = maxLineWidth - usernameWidth; - var spaceWidth = Overlays.textSize(textSizeMeasureOverlay, " ").width; - var numberOfSpaces = Math.floor(spaceableWidth / spaceWidth); - for (var i = 0; i < numberOfSpaces; i++) { - usernameLine = " " + usernameLine; - } - } - var dimension_x = maxLineWidth + TEXT_MARGIN_RIGHT + TEXT_MARGIN_LEFT; - if (position.x > 0 && position.y > 0 && position.z > 0) { - Entities.addEntity({ - type: "Text", - rotation: MyAvatar.orientation, - position: position, - dimensions: { x: dimension_x, y: (textLines.length + 1) * 0.14 + TEXT_MARGIN_TOP + TEXT_MARGIN_BOTTOM, z: DEFAULT_TEXT_DIMENSION_Z }, - backgroundColor: { red: 0, green: 0, blue: 0 }, - textColor: { red: 255, green: 255, blue: 255 }, - text: textText + "\n" + usernameLine - }); - } - textText = ""; + } else if (event.event == 'submit' || event.event == 'enter') { + print("going to hifi://" + locationURL); + location = "hifi://" + locationURL; + locationURL = ""; updateTextOverlay(); } } From 1365ecede309a2e774729aeba19a085dc2ca9b6e Mon Sep 17 00:00:00 2001 From: Thijs Wenker Date: Wed, 31 Dec 2014 01:42:19 +0100 Subject: [PATCH 08/77] removed unused variables --- examples/libraries/virtualKeyboard.js | 9 --------- 1 file changed, 9 deletions(-) diff --git a/examples/libraries/virtualKeyboard.js b/examples/libraries/virtualKeyboard.js index 7e18ba1b5c..98d8bdf561 100644 --- a/examples/libraries/virtualKeyboard.js +++ b/examples/libraries/virtualKeyboard.js @@ -44,9 +44,6 @@ KEYBOARD_SCALE_MULTIPLIER = 0.50; const VIEW_ANGLE = 40.0; const VIEW_ANGLE_BY_TWO = VIEW_ANGLE / 2; -const SPAWN_DISTANCE = 1; -const DEFAULT_TEXT_DIMENSION_Z = 0.02; - const BOUND_X = 0; const BOUND_Y = 1; const BOUND_W = 2; @@ -55,13 +52,7 @@ const BOUND_H = 3; KEY_STATE_LOWER = 0; KEY_STATE_UPPER = 1; -const TEXT_MARGIN_TOP = 0.15; -const TEXT_MARGIN_LEFT = 0.15; -const TEXT_MARGIN_RIGHT = 0.17; -const TEXT_MARGIN_BOTTOM = 0.17; - var windowDimensions = Controller.getViewportDimensions(); -var cursor = null; KeyboardKey = (function(keyboard, keyProperties) { var tthis = this; From a0e209276b81c42d51044b9f8bd5a9067075173c Mon Sep 17 00:00:00 2001 From: Thijs Wenker Date: Wed, 31 Dec 2014 01:46:01 +0100 Subject: [PATCH 09/77] textbox visibility --- examples/virtualKeyboardLocation.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/examples/virtualKeyboardLocation.js b/examples/virtualKeyboardLocation.js index 2ff98c4c43..c07877f2f1 100644 --- a/examples/virtualKeyboardLocation.js +++ b/examples/virtualKeyboardLocation.js @@ -84,7 +84,8 @@ keyboard.onFullyLoaded = function() { leftMargin: 0, font: {size: textFontSize}, text: "", - alpha: 0.8 + alpha: 0.8, + visible: keyboard.visible }); updateTextOverlay(); // the cursor is being loaded after the keyboard, else it will be on the background of the keyboard @@ -99,8 +100,8 @@ function keyPressEvent(event) { keyboard.pressFocussedKey(); } else if (event.key === ENTER_CHARCODE || event.key === RETURN_CHARCODE) { keyboard.toggle(); + Overlays.editOverlay(text, {visible: keyboard.visible}); } - } function keyReleaseEvent(event) { From 33a4f8030054cc3c63a0e6f6d8d954fdfadb022f Mon Sep 17 00:00:00 2001 From: Thijs Wenker Date: Wed, 31 Dec 2014 01:49:01 +0100 Subject: [PATCH 10/77] hide keyboard after submit --- examples/virtualKeyboardLocation.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/virtualKeyboardLocation.js b/examples/virtualKeyboardLocation.js index c07877f2f1..839fa6e743 100644 --- a/examples/virtualKeyboardLocation.js +++ b/examples/virtualKeyboardLocation.js @@ -44,7 +44,7 @@ function updateTextOverlay() { var maxFontSize = 140; textFontSize = (suggestedFontSize > maxFontSize) ? maxFontSize : suggestedFontSize; var topMargin = (250 - textFontSize) / 4; - Overlays.editOverlay(text, {text: locationURL, font: {size: textFontSize}, topMargin: topMargin}); + Overlays.editOverlay(text, {text: locationURL, font: {size: textFontSize}, topMargin: topMargin, visible: keyboard.visible}); maxLineWidth = Overlays.textSize(text, locationURL).width; Overlays.editOverlay(text, {leftMargin: (windowDimensions.x - maxLineWidth) / 2}); } @@ -65,6 +65,7 @@ keyboard.onKeyRelease = function(event) { print("going to hifi://" + locationURL); location = "hifi://" + locationURL; locationURL = ""; + keyboard.hide(); updateTextOverlay(); } } From 398e88107cbe9a391f05f46564c4e1f6137d464e Mon Sep 17 00:00:00 2001 From: Thijs Wenker Date: Wed, 31 Dec 2014 01:53:10 +0100 Subject: [PATCH 11/77] renamed virtualKeyboardLocation.js to goTo.js as discussed --- examples/{virtualKeyboardLocation.js => goTo.js} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename examples/{virtualKeyboardLocation.js => goTo.js} (99%) diff --git a/examples/virtualKeyboardLocation.js b/examples/goTo.js similarity index 99% rename from examples/virtualKeyboardLocation.js rename to examples/goTo.js index 839fa6e743..13114024ed 100644 --- a/examples/virtualKeyboardLocation.js +++ b/examples/goTo.js @@ -1,5 +1,5 @@ // -// virtualKeyboardTextEntityExample.js +// goTo.js // examples // // Created by Thijs Wenker on 12/28/14. From c73b496cacaafb995762a1d72fae50b3b3dcb62a Mon Sep 17 00:00:00 2001 From: Thijs Wenker Date: Wed, 31 Dec 2014 02:25:55 +0100 Subject: [PATCH 12/77] press X button with gamepad --- examples/goTo.js | 15 +++++++++++++++ examples/libraries/virtualKeyboard.js | 3 +++ examples/virtualKeyboardTextEntityExample.js | 15 +++++++++++++++ 3 files changed, 33 insertions(+) diff --git a/examples/goTo.js b/examples/goTo.js index 13114024ed..ef93bc9268 100644 --- a/examples/goTo.js +++ b/examples/goTo.js @@ -121,6 +121,21 @@ function scriptEnding() { Controller.releaseKeyEvents({key: ENTER_CHARCODE}); } +function reportButtonValue(button, newValue, oldValue) { + if (button == Joysticks.BUTTON_FACE_LEFT) { + if (newValue) { + keyboard.pressFocussedKey(); + } else { + keyboard.releaseKeys(); + } + } +} + +function addJoystick(gamepad) { + gamepad.buttonStateChanged.connect(reportButtonValue); +} + +Joysticks.joystickAdded.connect(addJoystick); Controller.captureKeyEvents({key: RETURN_CHARCODE}); Controller.captureKeyEvents({key: ENTER_CHARCODE}); Controller.captureKeyEvents({key: SPACEBAR_CHARCODE}); diff --git a/examples/libraries/virtualKeyboard.js b/examples/libraries/virtualKeyboard.js index 98d8bdf561..492b49a4aa 100644 --- a/examples/libraries/virtualKeyboard.js +++ b/examples/libraries/virtualKeyboard.js @@ -179,6 +179,9 @@ KeyboardKey = (function(keyboard, keyProperties) { }); Keyboard = (function(params) { + if (params === undefined) { + params = {}; + } var tthis = this; this.focussed_key = -1; this.scale = (windowDimensions.x / KEYBOARD_WIDTH) * KEYBOARD_SCALE_MULTIPLIER; diff --git a/examples/virtualKeyboardTextEntityExample.js b/examples/virtualKeyboardTextEntityExample.js index 38beb08277..a6960d209a 100644 --- a/examples/virtualKeyboardTextEntityExample.js +++ b/examples/virtualKeyboardTextEntityExample.js @@ -152,6 +152,21 @@ function scriptEnding() { Controller.releaseKeyEvents({key: SPACEBAR_CHARCODE}); } +function reportButtonValue(button, newValue, oldValue) { + if (button == Joysticks.BUTTON_FACE_LEFT) { + if (newValue) { + keyboard.pressFocussedKey(); + } else { + keyboard.releaseKeys(); + } + } +} + +function addJoystick(gamepad) { + gamepad.buttonStateChanged.connect(reportButtonValue); +} + +Joysticks.joystickAdded.connect(addJoystick); Controller.captureKeyEvents({key: SPACEBAR_CHARCODE}); Controller.keyPressEvent.connect(keyPressEvent); Controller.keyReleaseEvent.connect(keyReleaseEvent); From 19eec811731f5fd7c8e5ccacf8edeb29a4d0d0b0 Mon Sep 17 00:00:00 2001 From: Thijs Wenker Date: Wed, 7 Jan 2015 20:46:39 +0100 Subject: [PATCH 13/77] moved goTo.js and virtualKeyboardTextEntityExample.js to the right category folder --- examples/{ => controllers/oculus}/goTo.js | 0 .../{ => controllers/oculus}/virtualKeyboardTextEntityExample.js | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename examples/{ => controllers/oculus}/goTo.js (100%) rename examples/{ => controllers/oculus}/virtualKeyboardTextEntityExample.js (100%) diff --git a/examples/goTo.js b/examples/controllers/oculus/goTo.js similarity index 100% rename from examples/goTo.js rename to examples/controllers/oculus/goTo.js diff --git a/examples/virtualKeyboardTextEntityExample.js b/examples/controllers/oculus/virtualKeyboardTextEntityExample.js similarity index 100% rename from examples/virtualKeyboardTextEntityExample.js rename to examples/controllers/oculus/virtualKeyboardTextEntityExample.js From ff6cae738b5ba26d43b25cb58c54b8c5291fb783 Mon Sep 17 00:00:00 2001 From: Thijs Wenker Date: Wed, 7 Jan 2015 20:47:59 +0100 Subject: [PATCH 14/77] fixed library paths --- examples/controllers/oculus/goTo.js | 2 +- examples/controllers/oculus/virtualKeyboardTextEntityExample.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/controllers/oculus/goTo.js b/examples/controllers/oculus/goTo.js index ef93bc9268..50d44d0a28 100644 --- a/examples/controllers/oculus/goTo.js +++ b/examples/controllers/oculus/goTo.js @@ -16,7 +16,7 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -Script.include("libraries/virtualKeyboard.js"); +Script.include("../../libraries/virtualKeyboard.js"); var windowDimensions = Controller.getViewportDimensions(); var cursor = null; diff --git a/examples/controllers/oculus/virtualKeyboardTextEntityExample.js b/examples/controllers/oculus/virtualKeyboardTextEntityExample.js index a6960d209a..9c5ba6dfe5 100644 --- a/examples/controllers/oculus/virtualKeyboardTextEntityExample.js +++ b/examples/controllers/oculus/virtualKeyboardTextEntityExample.js @@ -15,7 +15,7 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -Script.include("libraries/virtualKeyboard.js"); +Script.include("../../libraries/virtualKeyboard.js"); const SPAWN_DISTANCE = 1; const DEFAULT_TEXT_DIMENSION_Z = 0.02; From 4fdcdf095c9af35f2f77e22340eb771dbe440860 Mon Sep 17 00:00:00 2001 From: Thijs Wenker Date: Wed, 7 Jan 2015 21:27:14 +0100 Subject: [PATCH 15/77] trying to fix url --- examples/libraries/virtualKeyboard.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/libraries/virtualKeyboard.js b/examples/libraries/virtualKeyboard.js index 492b49a4aa..aab590e63f 100644 --- a/examples/libraries/virtualKeyboard.js +++ b/examples/libraries/virtualKeyboard.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("globals.js"); // experimental 3dmode THREE_D_MODE = false; From 6771252eab69c000631d82c48ff02a603eb0bb76 Mon Sep 17 00:00:00 2001 From: Thijs Wenker Date: Wed, 7 Jan 2015 21:34:34 +0100 Subject: [PATCH 16/77] seems like you need to offset the include from the script that uses it --- examples/libraries/virtualKeyboard.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/libraries/virtualKeyboard.js b/examples/libraries/virtualKeyboard.js index aab590e63f..893ed929d6 100644 --- a/examples/libraries/virtualKeyboard.js +++ b/examples/libraries/virtualKeyboard.js @@ -13,7 +13,7 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -Script.include("globals.js"); +Script.include("../../libraries/globals.js"); // experimental 3dmode THREE_D_MODE = false; From 527576eebad6a0ec63b1b2bd081afa72d32ae6c1 Mon Sep 17 00:00:00 2001 From: Thijs Wenker Date: Wed, 7 Jan 2015 21:38:31 +0100 Subject: [PATCH 17/77] or not... --- examples/libraries/virtualKeyboard.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/libraries/virtualKeyboard.js b/examples/libraries/virtualKeyboard.js index 893ed929d6..aab590e63f 100644 --- a/examples/libraries/virtualKeyboard.js +++ b/examples/libraries/virtualKeyboard.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("globals.js"); // experimental 3dmode THREE_D_MODE = false; From 40b4a17ba803de674993a1777b27b93564776f35 Mon Sep 17 00:00:00 2001 From: Thijs Wenker Date: Wed, 7 Jan 2015 23:14:31 +0100 Subject: [PATCH 18/77] include globals.js from runnable scripts for now. --- examples/controllers/oculus/goTo.js | 1 + examples/controllers/oculus/virtualKeyboardTextEntityExample.js | 1 + examples/libraries/virtualKeyboard.js | 2 -- 3 files changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/controllers/oculus/goTo.js b/examples/controllers/oculus/goTo.js index 50d44d0a28..3423716698 100644 --- a/examples/controllers/oculus/goTo.js +++ b/examples/controllers/oculus/goTo.js @@ -16,6 +16,7 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // +Script.include("../../libraries/globals.js"); Script.include("../../libraries/virtualKeyboard.js"); var windowDimensions = Controller.getViewportDimensions(); diff --git a/examples/controllers/oculus/virtualKeyboardTextEntityExample.js b/examples/controllers/oculus/virtualKeyboardTextEntityExample.js index 9c5ba6dfe5..a5f5b2bf95 100644 --- a/examples/controllers/oculus/virtualKeyboardTextEntityExample.js +++ b/examples/controllers/oculus/virtualKeyboardTextEntityExample.js @@ -15,6 +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/virtualKeyboard.js"); const SPAWN_DISTANCE = 1; diff --git a/examples/libraries/virtualKeyboard.js b/examples/libraries/virtualKeyboard.js index aab590e63f..854ca58d1d 100644 --- a/examples/libraries/virtualKeyboard.js +++ b/examples/libraries/virtualKeyboard.js @@ -13,8 +13,6 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -Script.include("globals.js"); - // experimental 3dmode THREE_D_MODE = false; From c791422fabf1ce844434242967b7e5ef3ab85eef Mon Sep 17 00:00:00 2001 From: Thijs Wenker Date: Thu, 8 Jan 2015 02:22:08 +0100 Subject: [PATCH 19/77] make gamepads and A (select key) and B (delete character) button function --- examples/controllers/oculus/goTo.js | 9 ++++++++- .../oculus/virtualKeyboardTextEntityExample.js | 9 ++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/examples/controllers/oculus/goTo.js b/examples/controllers/oculus/goTo.js index 3423716698..ba1ee1eb81 100644 --- a/examples/controllers/oculus/goTo.js +++ b/examples/controllers/oculus/goTo.js @@ -123,12 +123,14 @@ function scriptEnding() { } function reportButtonValue(button, newValue, oldValue) { - if (button == Joysticks.BUTTON_FACE_LEFT) { + if (button == Joysticks.BUTTON_FACE_BOTTOM) { if (newValue) { keyboard.pressFocussedKey(); } else { keyboard.releaseKeys(); } + } else if (button == Joysticks.BUTTON_FACE_RIGHT && newValue) { + deleteChar(); } } @@ -136,6 +138,11 @@ function addJoystick(gamepad) { gamepad.buttonStateChanged.connect(reportButtonValue); } +var allJoysticks = Joysticks.getAllJoysticks(); +for (var i = 0; i < allJoysticks.length; i++) { + addJoystick(allJoysticks[i]); +} + Joysticks.joystickAdded.connect(addJoystick); Controller.captureKeyEvents({key: RETURN_CHARCODE}); Controller.captureKeyEvents({key: ENTER_CHARCODE}); diff --git a/examples/controllers/oculus/virtualKeyboardTextEntityExample.js b/examples/controllers/oculus/virtualKeyboardTextEntityExample.js index a5f5b2bf95..794b659bcb 100644 --- a/examples/controllers/oculus/virtualKeyboardTextEntityExample.js +++ b/examples/controllers/oculus/virtualKeyboardTextEntityExample.js @@ -154,12 +154,14 @@ function scriptEnding() { } function reportButtonValue(button, newValue, oldValue) { - if (button == Joysticks.BUTTON_FACE_LEFT) { + if (button == Joysticks.BUTTON_FACE_BOTTOM) { if (newValue) { keyboard.pressFocussedKey(); } else { keyboard.releaseKeys(); } + } else if (button == Joysticks.BUTTON_FACE_RIGHT && newValue) { + deleteChar(); } } @@ -167,6 +169,11 @@ function addJoystick(gamepad) { gamepad.buttonStateChanged.connect(reportButtonValue); } +var allJoysticks = Joysticks.getAllJoysticks(); +for (var i = 0; i < allJoysticks.length; i++) { + addJoystick(allJoysticks[i]); +} + Joysticks.joystickAdded.connect(addJoystick); Controller.captureKeyEvents({key: SPACEBAR_CHARCODE}); Controller.keyPressEvent.connect(keyPressEvent); From 3da5677aafadbb6961951db3118f274412a87257 Mon Sep 17 00:00:00 2001 From: Thijs Wenker Date: Tue, 13 Jan 2015 00:43:16 +0100 Subject: [PATCH 20/77] added HMD interface to toggle magnifier --- interface/src/Application.cpp | 3 ++ .../src/scripting/HMDScriptingInterface.cpp | 17 ++++++++++ .../src/scripting/HMDScriptingInterface.h | 32 +++++++++++++++++++ interface/src/ui/ApplicationOverlay.cpp | 3 +- interface/src/ui/ApplicationOverlay.h | 6 +++- 5 files changed, 59 insertions(+), 2 deletions(-) create mode 100644 interface/src/scripting/HMDScriptingInterface.cpp create mode 100644 interface/src/scripting/HMDScriptingInterface.h diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 1364e1b05b..6260634e25 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -101,6 +101,7 @@ #include "scripting/AccountScriptingInterface.h" #include "scripting/AudioDeviceScriptingInterface.h" #include "scripting/ClipboardScriptingInterface.h" +#include "scripting/HMDScriptingInterface.h" #include "scripting/JoystickScriptingInterface.h" #include "scripting/GlobalServicesScriptingInterface.h" #include "scripting/LocationScriptingInterface.h" @@ -3445,6 +3446,8 @@ void Application::registerScriptEngineWithApplicationServices(ScriptEngine* scri scriptEngine->registerGlobalObject("UndoStack", &_undoStackScriptingInterface); + scriptEngine->registerGlobalObject("HMD", &HMDScriptingInterface::getInstance()); + #ifdef HAVE_RTMIDI scriptEngine->registerGlobalObject("MIDI", &MIDIManager::getInstance()); #endif diff --git a/interface/src/scripting/HMDScriptingInterface.cpp b/interface/src/scripting/HMDScriptingInterface.cpp new file mode 100644 index 0000000000..b9b9b103e4 --- /dev/null +++ b/interface/src/scripting/HMDScriptingInterface.cpp @@ -0,0 +1,17 @@ +// +// HMDScriptingInterface.cpp +// interface/src/scripting +// +// Created by Thijs Wenker on 1/12/15. +// Copyright 2015 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 +// + +#include "HMDScriptingInterface.h" + +HMDScriptingInterface& HMDScriptingInterface::getInstance() { + static HMDScriptingInterface sharedInstance; + return sharedInstance; +} diff --git a/interface/src/scripting/HMDScriptingInterface.h b/interface/src/scripting/HMDScriptingInterface.h new file mode 100644 index 0000000000..4852d9ae6e --- /dev/null +++ b/interface/src/scripting/HMDScriptingInterface.h @@ -0,0 +1,32 @@ +// +// HMDScriptingInterface.h +// interface/src/scripting +// +// Created by Thijs Wenker on 1/12/15. +// Copyright 2015 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 +// + +#ifndef hifi_HMDScriptingInterface_h +#define hifi_HMDScriptingInterface_h + +#include "Application.h" + +class HMDScriptingInterface : public QObject { + Q_OBJECT + Q_PROPERTY(bool magnifier READ getMagnifier) +public: + static HMDScriptingInterface& getInstance(); + +public slots: + void toggleMagnifier() { Application::getInstance()->getApplicationOverlay().toggleMagnifier(); }; + +private: + HMDScriptingInterface() {}; + bool getMagnifier() const { return Application::getInstance()->getApplicationOverlay().hasMagnifier(); }; + +}; + +#endif // hifi_HMDScriptingInterface_h diff --git a/interface/src/ui/ApplicationOverlay.cpp b/interface/src/ui/ApplicationOverlay.cpp index 1d710f29d4..b2bf821af8 100644 --- a/interface/src/ui/ApplicationOverlay.cpp +++ b/interface/src/ui/ApplicationOverlay.cpp @@ -131,6 +131,7 @@ ApplicationOverlay::ApplicationOverlay() : _alpha(1.0f), _oculusUIRadius(1.0f), _crosshairTexture(0), + _magnifier(true), _previousBorderWidth(-1), _previousBorderHeight(-1), _previousMagnifierBottomLeft(), @@ -555,7 +556,7 @@ void ApplicationOverlay::renderPointers() { _reticlePosition[MOUSE] = position; _reticleActive[MOUSE] = true; - _magActive[MOUSE] = true; + _magActive[MOUSE] = _magnifier; _reticleActive[LEFT_CONTROLLER] = false; _reticleActive[RIGHT_CONTROLLER] = false; } else if (application->getLastMouseMoveWasSimulated() && Menu::getInstance()->isOptionChecked(MenuOption::SixenseMouseInput)) { diff --git a/interface/src/ui/ApplicationOverlay.h b/interface/src/ui/ApplicationOverlay.h index e2094f2a8e..554dd5152e 100644 --- a/interface/src/ui/ApplicationOverlay.h +++ b/interface/src/ui/ApplicationOverlay.h @@ -34,6 +34,9 @@ public: QPoint getPalmClickLocation(const PalmData *palm) const; bool calculateRayUICollisionPoint(const glm::vec3& position, const glm::vec3& direction, glm::vec3& result) const; + bool hasMagnifier() const { return _magnifier; } + void toggleMagnifier() { _magnifier = !_magnifier; } + // Converter from one frame of reference to another. // Frame of reference: // Screen: Position on the screen (x,y) @@ -101,7 +104,8 @@ private: bool _magActive[NUMBER_OF_RETICLES]; float _magSizeMult[NUMBER_OF_RETICLES]; quint64 _lastMouseMove; - + bool _magnifier; + float _alpha; float _oculusUIRadius; float _trailingAudioLoudness; From ca4d493ec9b831c9b816e45b51af5e1a3c19326d Mon Sep 17 00:00:00 2001 From: Thijs Wenker Date: Wed, 14 Jan 2015 00:01:50 +0100 Subject: [PATCH 21/77] added HMD.VRMode to HMDScriptingInterface --- interface/src/scripting/HMDScriptingInterface.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/interface/src/scripting/HMDScriptingInterface.h b/interface/src/scripting/HMDScriptingInterface.h index 4852d9ae6e..e2ffc514cd 100644 --- a/interface/src/scripting/HMDScriptingInterface.h +++ b/interface/src/scripting/HMDScriptingInterface.h @@ -13,10 +13,12 @@ #define hifi_HMDScriptingInterface_h #include "Application.h" +#include "devices/OculusManager.h" class HMDScriptingInterface : public QObject { Q_OBJECT Q_PROPERTY(bool magnifier READ getMagnifier) + Q_PROPERTY(bool VRMode READ getVRMode) public: static HMDScriptingInterface& getInstance(); @@ -26,6 +28,7 @@ public slots: private: HMDScriptingInterface() {}; bool getMagnifier() const { return Application::getInstance()->getApplicationOverlay().hasMagnifier(); }; + bool getVRMode() const { return OculusManager::isConnected(); } }; From 0f6ad4eba02c55447b7e70332e854d16a24687d1 Mon Sep 17 00:00:00 2001 From: Thijs Wenker Date: Wed, 14 Jan 2015 00:07:15 +0100 Subject: [PATCH 22/77] HMD.VRMode -> HMD.active , and hooked it to a function which isn't dependent on HMD type, since there will be more HMD's than Oculus supported in the near future. --- interface/src/scripting/HMDScriptingInterface.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/interface/src/scripting/HMDScriptingInterface.h b/interface/src/scripting/HMDScriptingInterface.h index e2ffc514cd..2c485195e5 100644 --- a/interface/src/scripting/HMDScriptingInterface.h +++ b/interface/src/scripting/HMDScriptingInterface.h @@ -13,12 +13,11 @@ #define hifi_HMDScriptingInterface_h #include "Application.h" -#include "devices/OculusManager.h" class HMDScriptingInterface : public QObject { Q_OBJECT Q_PROPERTY(bool magnifier READ getMagnifier) - Q_PROPERTY(bool VRMode READ getVRMode) + Q_PROPERTY(bool active READ isHMDMode) public: static HMDScriptingInterface& getInstance(); @@ -28,7 +27,7 @@ public slots: private: HMDScriptingInterface() {}; bool getMagnifier() const { return Application::getInstance()->getApplicationOverlay().hasMagnifier(); }; - bool getVRMode() const { return OculusManager::isConnected(); } + bool isHMDMode() const { return Application::getInstance()->isHMDMode(); } }; From 38d49854cbfa8254fbdf79de0274bdcac7609383 Mon Sep 17 00:00:00 2001 From: Thijs Wenker Date: Wed, 14 Jan 2015 01:06:44 +0100 Subject: [PATCH 23/77] hide cursor --- examples/controllers/oculus/goTo.js | 7 +++-- examples/libraries/virtualKeyboard.js | 38 +++++++++++++++++++-------- 2 files changed, 32 insertions(+), 13 deletions(-) diff --git a/examples/controllers/oculus/goTo.js b/examples/controllers/oculus/goTo.js index ba1ee1eb81..3966c28a5c 100644 --- a/examples/controllers/oculus/goTo.js +++ b/examples/controllers/oculus/goTo.js @@ -20,7 +20,7 @@ Script.include("../../libraries/globals.js"); Script.include("../../libraries/virtualKeyboard.js"); var windowDimensions = Controller.getViewportDimensions(); -var cursor = null; +var cursor = new Cursor({visible: false}); var keyboard = new Keyboard({visible: false}); var textFontSize = 9; var text = null; @@ -91,7 +91,7 @@ keyboard.onFullyLoaded = function() { }); updateTextOverlay(); // the cursor is being loaded after the keyboard, else it will be on the background of the keyboard - cursor = new Cursor(); + cursor.updateVisibility(keyboard.visible); cursor.onUpdate = function(position) { keyboard.setFocusPosition(position.x, position.y); }; @@ -102,6 +102,9 @@ function keyPressEvent(event) { keyboard.pressFocussedKey(); } else if (event.key === ENTER_CHARCODE || event.key === RETURN_CHARCODE) { keyboard.toggle(); + if (cursor !== undefined) { + cursor.updateVisibility(keyboard.visible); + } Overlays.editOverlay(text, {visible: keyboard.visible}); } } diff --git a/examples/libraries/virtualKeyboard.js b/examples/libraries/virtualKeyboard.js index 854ca58d1d..d93e569af5 100644 --- a/examples/libraries/virtualKeyboard.js +++ b/examples/libraries/virtualKeyboard.js @@ -184,7 +184,7 @@ Keyboard = (function(params) { this.focussed_key = -1; this.scale = (windowDimensions.x / KEYBOARD_WIDTH) * KEYBOARD_SCALE_MULTIPLIER; this.shift = false; - this.visible = params.visible != undefined ? params.visible :true; + this.visible = params.visible != undefined ? params.visible : true; this.width = function() { return KEYBOARD_WIDTH * tthis.scale; }; @@ -320,21 +320,19 @@ Keyboard = (function(params) { }; this.show = function() { - tthis.visible = true; - tthis.updateVisibility(); + tthis.updateVisibility(true); }; this.hide = function() { - tthis.visible = false; - tthis.updateVisibility(); + tthis.updateVisibility(false); }; this.toggle = function() { - tthis.visible = !tthis.visible; - tthis.updateVisibility(); + tthis.updateVisibility(!tthis.visible); }; - - this.updateVisibility = function() { + + this.updateVisibility = function(visible) { + tthis.visible = visible; Overlays.editOverlay(tthis.background, { visible: tthis.visible }); for (var i = 0; i < this.keys.length; i++) { this.keys[i].updateVisibility(); @@ -454,8 +452,12 @@ Keyboard = (function(params) { this.keyboardTextureLoaded_timer = Script.setInterval(this.keyboardTextureLoaded, 250); }); -Cursor = (function() { +Cursor = (function(params) { + if (params === undefined) { + params = {}; + } var tthis = this; + this.visible = params.visible != undefined ? params.visible : true; this.x = windowDimensions.x / 2; this.y = windowDimensions.y / 2; this.overlay = Overlays.addOverlay("image", { @@ -464,7 +466,8 @@ Cursor = (function() { width: CURSOR_WIDTH, height: CURSOR_HEIGHT, imageURL: CURSOR_URL, - alpha: 1 + alpha: 1, + visible: this.visible }); this.remove = function() { Overlays.deleteOverlay(this.overlay); @@ -478,6 +481,19 @@ Cursor = (function() { this.getY = function() { return tthis.y; }; + this.show = function() { + tthis.updateVisibility(true); + }; + this.hide = function() { + tthis.updateVisibility(false); + }; + this.toggle = function() { + tthis.updateVisibility(!tthis.visible); + }; + this.updateVisibility = function(visible) { + tthis.visible = visible; + Overlays.editOverlay(this.overlay, { visible: tthis.visible }); + }; this.onUpdate = null; this.update = function() { var newWindowDimensions = Controller.getViewportDimensions(); From e3c55584702da79509f897601bdbb52843e0ddc2 Mon Sep 17 00:00:00 2001 From: Thijs Wenker Date: Wed, 14 Jan 2015 01:18:53 +0100 Subject: [PATCH 24/77] toggle magnifier when keyboard visibility changes --- examples/libraries/virtualKeyboard.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/examples/libraries/virtualKeyboard.js b/examples/libraries/virtualKeyboard.js index d93e569af5..2671871fac 100644 --- a/examples/libraries/virtualKeyboard.js +++ b/examples/libraries/virtualKeyboard.js @@ -333,6 +333,9 @@ Keyboard = (function(params) { this.updateVisibility = function(visible) { tthis.visible = visible; + if (HMD.magnifier == visible) { + HMD.toggleMagnifier(); + } Overlays.editOverlay(tthis.background, { visible: tthis.visible }); for (var i = 0; i < this.keys.length; i++) { this.keys[i].updateVisibility(); From 12136e5305e9756e1770c6753339b140cb92c7d9 Mon Sep 17 00:00:00 2001 From: Thijs Wenker Date: Thu, 15 Jan 2015 22:25:59 +0100 Subject: [PATCH 25/77] cursor follows look at rotation now --- examples/controllers/oculus/goTo.js | 5 +- examples/libraries/virtualKeyboard.js | 134 +++++++++--------- .../src/scripting/HMDScriptingInterface.h | 20 +++ 3 files changed, 91 insertions(+), 68 deletions(-) diff --git a/examples/controllers/oculus/goTo.js b/examples/controllers/oculus/goTo.js index 3966c28a5c..5038253e17 100644 --- a/examples/controllers/oculus/goTo.js +++ b/examples/controllers/oculus/goTo.js @@ -20,7 +20,7 @@ Script.include("../../libraries/globals.js"); Script.include("../../libraries/virtualKeyboard.js"); var windowDimensions = Controller.getViewportDimensions(); -var cursor = new Cursor({visible: false}); +var cursor = new Cursor({visible: false});; var keyboard = new Keyboard({visible: false}); var textFontSize = 9; var text = null; @@ -66,7 +66,7 @@ keyboard.onKeyRelease = function(event) { print("going to hifi://" + locationURL); location = "hifi://" + locationURL; locationURL = ""; - keyboard.hide(); + keyboard.hide(); updateTextOverlay(); } } @@ -91,6 +91,7 @@ keyboard.onFullyLoaded = function() { }); updateTextOverlay(); // the cursor is being loaded after the keyboard, else it will be on the background of the keyboard + cursor.initialize(); cursor.updateVisibility(keyboard.visible); cursor.onUpdate = function(position) { keyboard.setFocusPosition(position.x, position.y); diff --git a/examples/libraries/virtualKeyboard.js b/examples/libraries/virtualKeyboard.js index 2671871fac..8035f9d701 100644 --- a/examples/libraries/virtualKeyboard.js +++ b/examples/libraries/virtualKeyboard.js @@ -460,71 +460,73 @@ Cursor = (function(params) { params = {}; } var tthis = this; - this.visible = params.visible != undefined ? params.visible : true; - this.x = windowDimensions.x / 2; - this.y = windowDimensions.y / 2; - this.overlay = Overlays.addOverlay("image", { - x: this.x, - y: this.y, - width: CURSOR_WIDTH, - height: CURSOR_HEIGHT, - imageURL: CURSOR_URL, - alpha: 1, - visible: this.visible - }); - this.remove = function() { - Overlays.deleteOverlay(this.overlay); + this.initialize = function() { + this.visible = params.visible != undefined ? params.visible : true; + this.x = windowDimensions.x / 2; + this.y = windowDimensions.y / 2; + this.overlay = Overlays.addOverlay("image", { + x: this.x, + y: this.y, + width: CURSOR_WIDTH, + height: CURSOR_HEIGHT, + imageURL: CURSOR_URL, + alpha: 1, + visible: this.visible + }); + this.remove = function() { + Overlays.deleteOverlay(this.overlay); + }; + this.getPosition = function() { + return {x: tthis.getX(), y: tthis.getY()}; + }; + this.getX = function() { + return tthis.x; + }; + this.getY = function() { + return tthis.y; + }; + this.show = function() { + tthis.updateVisibility(true); + }; + this.hide = function() { + tthis.updateVisibility(false); + }; + this.toggle = function() { + tthis.updateVisibility(!tthis.visible); + }; + this.updateVisibility = function(visible) { + tthis.visible = visible; + Overlays.editOverlay(this.overlay, { visible: tthis.visible }); + }; + this.onUpdate = null; + this.update = function() { + var newWindowDimensions = Controller.getViewportDimensions(); + if (newWindowDimensions.x != windowDimensions.x || newWindowDimensions.y != windowDimensions.y) { + windowDimensions = newWindowDimensions; + keyboard.rescale(); + Overlays.editOverlay(text, { + y: windowDimensions.y - keyboard.height() - 260, + width: windowDimensions.x + }); + } + var editobject = {}; + //if (MyAvatar.getHeadFinalYaw() <= VIEW_ANGLE_BY_TWO && MyAvatar.getHeadFinalYaw() >= -1 * VIEW_ANGLE_BY_TWO) { + //angle = ((-1 * MyAvatar.getHeadFinalYaw()) + VIEW_ANGLE_BY_TWO) / VIEW_ANGLE; + tthis.x = HMD.getHUDLookAtPositionX;//angle * windowDimensions.x; + editobject.x = tthis.x - (CURSOR_WIDTH / 2); + // } + // if (MyAvatar.getHeadFinalPitch() <= VIEW_ANGLE_BY_TWO && MyAvatar.getHeadFinalPitch() >= -1 * VIEW_ANGLE_BY_TWO) { + // angle = ((-1 * MyAvatar.getHeadFinalPitch()) + VIEW_ANGLE_BY_TWO) / VIEW_ANGLE; + tthis.y = HMD.getHUDLookAtPositionY;//angle * windowDimensions.y; + editobject.y = tthis.y - (CURSOR_HEIGHT / 2); + // } + if (Object.keys(editobject).length > 0) { + Overlays.editOverlay(tthis.overlay, editobject); + if (tthis.onUpdate != null) { + tthis.onUpdate(tthis.getPosition()); + } + } + }; + Script.update.connect(this.update); }; - this.getPosition = function() { - return {x: tthis.getX(), y: tthis.getY()}; - }; - this.getX = function() { - return tthis.x; - }; - this.getY = function() { - return tthis.y; - }; - this.show = function() { - tthis.updateVisibility(true); - }; - this.hide = function() { - tthis.updateVisibility(false); - }; - this.toggle = function() { - tthis.updateVisibility(!tthis.visible); - }; - this.updateVisibility = function(visible) { - tthis.visible = visible; - Overlays.editOverlay(this.overlay, { visible: tthis.visible }); - }; - this.onUpdate = null; - this.update = function() { - var newWindowDimensions = Controller.getViewportDimensions(); - if (newWindowDimensions.x != windowDimensions.x || newWindowDimensions.y != windowDimensions.y) { - windowDimensions = newWindowDimensions; - keyboard.rescale(); - Overlays.editOverlay(text, { - y: windowDimensions.y - keyboard.height() - 260, - width: windowDimensions.x - }); - } - var editobject = {}; - if (MyAvatar.getHeadFinalYaw() <= VIEW_ANGLE_BY_TWO && MyAvatar.getHeadFinalYaw() >= -1 * VIEW_ANGLE_BY_TWO) { - angle = ((-1 * MyAvatar.getHeadFinalYaw()) + VIEW_ANGLE_BY_TWO) / VIEW_ANGLE; - tthis.x = angle * windowDimensions.x; - editobject.x = tthis.x - (CURSOR_WIDTH / 2); - } - if (MyAvatar.getHeadFinalPitch() <= VIEW_ANGLE_BY_TWO && MyAvatar.getHeadFinalPitch() >= -1 * VIEW_ANGLE_BY_TWO) { - angle = ((-1 * MyAvatar.getHeadFinalPitch()) + VIEW_ANGLE_BY_TWO) / VIEW_ANGLE; - tthis.y = angle * windowDimensions.y; - editobject.y = tthis.y - (CURSOR_HEIGHT / 2); - } - if (Object.keys(editobject).length > 0) { - Overlays.editOverlay(tthis.overlay, editobject); - if (tthis.onUpdate != null) { - tthis.onUpdate(tthis.getPosition()); - } - } - }; - Script.update.connect(this.update); }); diff --git a/interface/src/scripting/HMDScriptingInterface.h b/interface/src/scripting/HMDScriptingInterface.h index 2c485195e5..a4950008eb 100644 --- a/interface/src/scripting/HMDScriptingInterface.h +++ b/interface/src/scripting/HMDScriptingInterface.h @@ -12,12 +12,17 @@ #ifndef hifi_HMDScriptingInterface_h #define hifi_HMDScriptingInterface_h +#include + #include "Application.h" +#include "devices/OculusManager.h" class HMDScriptingInterface : public QObject { Q_OBJECT Q_PROPERTY(bool magnifier READ getMagnifier) Q_PROPERTY(bool active READ isHMDMode) + Q_PROPERTY(float getHUDLookAtPositionX READ getHUDLookAtPositionX) + Q_PROPERTY(float getHUDLookAtPositionY READ getHUDLookAtPositionY) public: static HMDScriptingInterface& getInstance(); @@ -28,6 +33,21 @@ private: HMDScriptingInterface() {}; bool getMagnifier() const { return Application::getInstance()->getApplicationOverlay().hasMagnifier(); }; bool isHMDMode() const { return Application::getInstance()->isHMDMode(); } + float getHUDLookAtPositionX() const { + float pitch, yaw, roll; + OculusManager::getEulerAngles(yaw, pitch, roll); + glm::vec3 relativePos = OculusManager::getRelativePosition(); + glm::quat rotation = ::rotationBetween(glm::vec3(), relativePos); + glm::vec2 screenPos = Application::getInstance()->getApplicationOverlay().sphericalToOverlay(glm::vec2(yaw, -pitch)); + + return screenPos.x; + } + float getHUDLookAtPositionY() const { + float pitch, yaw, roll; + OculusManager::getEulerAngles(yaw, pitch, roll); + glm::vec2 screenPos = Application::getInstance()->getApplicationOverlay().sphericalToOverlay(glm::vec2(yaw, -pitch)); + return screenPos.y; + } }; From 9e51bece6325c7cc5660fd741bd6fd73ae73c2cc Mon Sep 17 00:00:00 2001 From: Thijs Wenker Date: Wed, 21 Jan 2015 15:07:32 +0100 Subject: [PATCH 26/77] More accurate HMD-cursor on virtual keyboard, thanks Simon and @ctrlaltdavid for the help on this! --- examples/libraries/virtualKeyboard.js | 14 +++++----- interface/src/devices/OculusManager.cpp | 2 +- .../src/scripting/HMDScriptingInterface.cpp | 27 +++++++++++++++++++ .../src/scripting/HMDScriptingInterface.h | 21 +++------------ 4 files changed, 38 insertions(+), 26 deletions(-) diff --git a/examples/libraries/virtualKeyboard.js b/examples/libraries/virtualKeyboard.js index 8035f9d701..0b6ff49d71 100644 --- a/examples/libraries/virtualKeyboard.js +++ b/examples/libraries/virtualKeyboard.js @@ -510,16 +510,14 @@ Cursor = (function(params) { }); } var editobject = {}; - //if (MyAvatar.getHeadFinalYaw() <= VIEW_ANGLE_BY_TWO && MyAvatar.getHeadFinalYaw() >= -1 * VIEW_ANGLE_BY_TWO) { - //angle = ((-1 * MyAvatar.getHeadFinalYaw()) + VIEW_ANGLE_BY_TWO) / VIEW_ANGLE; - tthis.x = HMD.getHUDLookAtPositionX;//angle * windowDimensions.x; + if (tthis.x !== HMD.getHUDLookAtPosition2D.x) { + tthis.x = HMD.getHUDLookAtPosition2D.x; editobject.x = tthis.x - (CURSOR_WIDTH / 2); - // } - // if (MyAvatar.getHeadFinalPitch() <= VIEW_ANGLE_BY_TWO && MyAvatar.getHeadFinalPitch() >= -1 * VIEW_ANGLE_BY_TWO) { - // angle = ((-1 * MyAvatar.getHeadFinalPitch()) + VIEW_ANGLE_BY_TWO) / VIEW_ANGLE; - tthis.y = HMD.getHUDLookAtPositionY;//angle * windowDimensions.y; + } + if (tthis.y !== HMD.getHUDLookAtPosition2D.y) { + tthis.y = HMD.getHUDLookAtPosition2D.y; editobject.y = tthis.y - (CURSOR_HEIGHT / 2); - // } + } if (Object.keys(editobject).length > 0) { Overlays.editOverlay(tthis.overlay, editobject); if (tthis.onUpdate != null) { diff --git a/interface/src/devices/OculusManager.cpp b/interface/src/devices/OculusManager.cpp index 256c09f602..47279a40f9 100644 --- a/interface/src/devices/OculusManager.cpp +++ b/interface/src/devices/OculusManager.cpp @@ -685,7 +685,7 @@ void OculusManager::getEulerAngles(float& yaw, float& pitch, float& roll) { roll = 0.0f; #endif } - + glm::vec3 OculusManager::getRelativePosition() { #if (defined(__APPLE__) || defined(_WIN32)) && HAVE_LIBOVR ovrTrackingState trackingState = ovrHmd_GetTrackingState(_ovrHmd, ovr_GetTimeInSeconds()); diff --git a/interface/src/scripting/HMDScriptingInterface.cpp b/interface/src/scripting/HMDScriptingInterface.cpp index b9b9b103e4..caf37e27be 100644 --- a/interface/src/scripting/HMDScriptingInterface.cpp +++ b/interface/src/scripting/HMDScriptingInterface.cpp @@ -15,3 +15,30 @@ HMDScriptingInterface& HMDScriptingInterface::getInstance() { static HMDScriptingInterface sharedInstance; return sharedInstance; } + +glm::vec3 HMDScriptingInterface::getHUDLookAtPosition3D() const { + Camera* camera = Application::getInstance()->getCamera(); + glm::vec3 position = camera->getPosition(); + glm::quat orientation = camera->getOrientation(); + + glm::vec3 direction = orientation * glm::vec3(0.0f, 0.0f, -1.0f); + + ApplicationOverlay& applicationOverlay = Application::getInstance()->getApplicationOverlay(); + + glm::vec3 result; + applicationOverlay.calculateRayUICollisionPoint(position, direction, result); + return result; +} + +glm::vec2 HMDScriptingInterface::getHUDLookAtPosition2D() const { + MyAvatar* myAvatar = Application::getInstance()->getAvatar(); + glm::vec3 sphereCenter = myAvatar->getDefaultEyePosition(); + + glm::vec3 hudIntersection = getHUDLookAtPosition3D(); + + glm::vec3 direction = glm::inverse(myAvatar->getOrientation()) * (hudIntersection - sphereCenter); + glm::quat rotation = ::rotationBetween(glm::vec3(0.0f, 0.0f, -1.0f), direction); + glm::vec3 eulers = ::safeEulerAngles(rotation); + + return Application::getInstance()->getApplicationOverlay().sphericalToOverlay(glm::vec2(eulers.y, -eulers.x));; +} diff --git a/interface/src/scripting/HMDScriptingInterface.h b/interface/src/scripting/HMDScriptingInterface.h index a4950008eb..cc148d5d5d 100644 --- a/interface/src/scripting/HMDScriptingInterface.h +++ b/interface/src/scripting/HMDScriptingInterface.h @@ -21,8 +21,8 @@ class HMDScriptingInterface : public QObject { Q_OBJECT Q_PROPERTY(bool magnifier READ getMagnifier) Q_PROPERTY(bool active READ isHMDMode) - Q_PROPERTY(float getHUDLookAtPositionX READ getHUDLookAtPositionX) - Q_PROPERTY(float getHUDLookAtPositionY READ getHUDLookAtPositionY) + Q_PROPERTY(glm::vec3 HUDLookAtPosition3D READ getHUDLookAtPosition3D) + Q_PROPERTY(glm::vec2 HUDLookAtPosition2D READ getHUDLookAtPosition2D) public: static HMDScriptingInterface& getInstance(); @@ -33,22 +33,9 @@ private: HMDScriptingInterface() {}; bool getMagnifier() const { return Application::getInstance()->getApplicationOverlay().hasMagnifier(); }; bool isHMDMode() const { return Application::getInstance()->isHMDMode(); } - float getHUDLookAtPositionX() const { - float pitch, yaw, roll; - OculusManager::getEulerAngles(yaw, pitch, roll); - glm::vec3 relativePos = OculusManager::getRelativePosition(); - glm::quat rotation = ::rotationBetween(glm::vec3(), relativePos); - glm::vec2 screenPos = Application::getInstance()->getApplicationOverlay().sphericalToOverlay(glm::vec2(yaw, -pitch)); - - return screenPos.x; - } - float getHUDLookAtPositionY() const { - float pitch, yaw, roll; - OculusManager::getEulerAngles(yaw, pitch, roll); - glm::vec2 screenPos = Application::getInstance()->getApplicationOverlay().sphericalToOverlay(glm::vec2(yaw, -pitch)); - return screenPos.y; - } + glm::vec3 getHUDLookAtPosition3D() const; + glm::vec2 getHUDLookAtPosition2D() const; }; #endif // hifi_HMDScriptingInterface_h From 87b2c362fc02aa6a86a125d865e33f7c34612460 Mon Sep 17 00:00:00 2001 From: Thijs Wenker Date: Wed, 21 Jan 2015 17:19:51 +0100 Subject: [PATCH 27/77] style --- interface/src/scripting/HMDScriptingInterface.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interface/src/scripting/HMDScriptingInterface.cpp b/interface/src/scripting/HMDScriptingInterface.cpp index caf37e27be..e2d150e390 100644 --- a/interface/src/scripting/HMDScriptingInterface.cpp +++ b/interface/src/scripting/HMDScriptingInterface.cpp @@ -40,5 +40,5 @@ glm::vec2 HMDScriptingInterface::getHUDLookAtPosition2D() const { glm::quat rotation = ::rotationBetween(glm::vec3(0.0f, 0.0f, -1.0f), direction); glm::vec3 eulers = ::safeEulerAngles(rotation); - return Application::getInstance()->getApplicationOverlay().sphericalToOverlay(glm::vec2(eulers.y, -eulers.x));; + return Application::getInstance()->getApplicationOverlay().sphericalToOverlay(glm::vec2(eulers.y, -eulers.x)); } From 724b56ed8c1eb63929f7ccdd9826435d6a11eaee Mon Sep 17 00:00:00 2001 From: Thijs Wenker Date: Thu, 22 Jan 2015 01:09:16 +0100 Subject: [PATCH 28/77] HMD.getHUDLookAtPosition2D -> HMD.HUDLookAtPosition2D --- examples/libraries/virtualKeyboard.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/libraries/virtualKeyboard.js b/examples/libraries/virtualKeyboard.js index 0b6ff49d71..c62498685c 100644 --- a/examples/libraries/virtualKeyboard.js +++ b/examples/libraries/virtualKeyboard.js @@ -510,12 +510,12 @@ Cursor = (function(params) { }); } var editobject = {}; - if (tthis.x !== HMD.getHUDLookAtPosition2D.x) { - tthis.x = HMD.getHUDLookAtPosition2D.x; + if (tthis.x !== HMD.HUDLookAtPosition2D.x) { + tthis.x = HMD.HUDLookAtPosition2D.x; editobject.x = tthis.x - (CURSOR_WIDTH / 2); } - if (tthis.y !== HMD.getHUDLookAtPosition2D.y) { - tthis.y = HMD.getHUDLookAtPosition2D.y; + if (tthis.y !== HMD.HUDLookAtPosition2D.y) { + tthis.y = HMD.HUDLookAtPosition2D.y; editobject.y = tthis.y - (CURSOR_HEIGHT / 2); } if (Object.keys(editobject).length > 0) { From 3e4f4ecc6b97dd050a43c052842daa90bca9e781 Mon Sep 17 00:00:00 2001 From: Thijs Wenker Date: Wed, 28 Jan 2015 00:39:19 +0100 Subject: [PATCH 29/77] addOverlay rather than cloneOverlay now that we have a TextureCache for the ImageOverlay --- examples/libraries/virtualKeyboard.js | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/examples/libraries/virtualKeyboard.js b/examples/libraries/virtualKeyboard.js index c62498685c..42185138e3 100644 --- a/examples/libraries/virtualKeyboard.js +++ b/examples/libraries/virtualKeyboard.js @@ -147,9 +147,13 @@ KeyboardKey = (function(keyboard, keyProperties) { return true; }; for (var i = 0; i < this.bounds.length; i++) { - var newOverlay = Overlays.cloneOverlay(this.keyboard.background); if (THREE_D_MODE) { - Overlays.editOverlay(newOverlay, { + this.overlays.push(Overlays.addOverlay("billboard", { + scale: 1, + rotation: MyAvatar.rotation, + isFacingAvatar: false, + url: KEYBOARD_URL, + alpha: 1, position: { x: MyAvatar.position.x,// + this.bounds[i][BOUND_X] * 0.01,// /*+ this.keyboard.getX()*/ + this.bounds[i][BOUND_X] * keyboard.scale, y: MyAvatar.position.y,// - this.bounds[i][BOUND_Y] * 0.01,// /*+ this.keyboard.getY()*/ + this.bounds[i][BOUND_Y] * keyboard.scale, @@ -160,9 +164,10 @@ KeyboardKey = (function(keyboard, keyProperties) { subImage: {width: this.bounds[i][BOUND_W], height: this.bounds[i][BOUND_H], x: this.bounds[i][BOUND_X], y: (KEYBOARD_HEIGHT * this.keyState) + this.bounds[i][BOUND_Y]}, alpha: 1, visible: tthis.keyboard.visible - }); + })); } else { - Overlays.editOverlay(newOverlay, { + this.overlays.push(Overlays.addOverlay("image", { + imageURL: KEYBOARD_URL, x: this.keyboard.getX() + this.bounds[i][BOUND_X] * keyboard.scale, y: this.keyboard.getY() + this.bounds[i][BOUND_Y] * keyboard.scale, width: this.bounds[i][BOUND_W] * keyboard.scale, @@ -170,9 +175,8 @@ KeyboardKey = (function(keyboard, keyProperties) { subImage: {width: this.bounds[i][BOUND_W], height: this.bounds[i][BOUND_H], x: this.bounds[i][BOUND_X], y: (KEYBOARD_HEIGHT * this.keyState) + this.bounds[i][BOUND_Y]}, alpha: 1, visible: tthis.keyboard.visible - }); + })); } - this.overlays.push(newOverlay); } }); @@ -440,13 +444,12 @@ Keyboard = (function(params) { {bounds: [[899, 355, 263, 67]], event: 'submit'} ]; - + for (var i = 0; i < keyProperties.length; i++) { + this.keys.push(new KeyboardKey(this, keyProperties[i])); + } this.keyboardTextureLoaded = function() { if (Overlays.isLoaded(tthis.background)) { Script.clearInterval(tthis.keyboardTextureLoaded_timer); - for (var i = 0; i < keyProperties.length; i++) { - tthis.keys.push(new KeyboardKey(tthis, keyProperties[i])); - } if (keyboard.onFullyLoaded != null) { tthis.onFullyLoaded(); } From d270979f95c373e39cdac000bfabd667da32cb0b Mon Sep 17 00:00:00 2001 From: Thijs Wenker Date: Wed, 4 Feb 2015 23:19:56 +0100 Subject: [PATCH 30/77] Instructions initial --- examples/controllers/oculus/goTo.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/examples/controllers/oculus/goTo.js b/examples/controllers/oculus/goTo.js index 5038253e17..ea3d12417d 100644 --- a/examples/controllers/oculus/goTo.js +++ b/examples/controllers/oculus/goTo.js @@ -19,6 +19,23 @@ Script.include("../../libraries/globals.js"); Script.include("../../libraries/virtualKeyboard.js"); +function Instructions(imageURL) { + this.overlay = Overlays.addOverlay("image", { + imageURL: HIFI_PUBLIC_BUCKET + "images/tutorial-goTo.svg", + x: 0, + y: 0, + alpha: 1, + visible: true + }); + this.remove = function() { + Overlays.deleteOverlay(this.overlay); + }; +}; + +var theInstruction = new Instructions(); + + + var windowDimensions = Controller.getViewportDimensions(); var cursor = new Cursor({visible: false});; var keyboard = new Keyboard({visible: false}); @@ -124,6 +141,7 @@ function scriptEnding() { Controller.releaseKeyEvents({key: SPACEBAR_CHARCODE}); Controller.releaseKeyEvents({key: RETURN_CHARCODE}); Controller.releaseKeyEvents({key: ENTER_CHARCODE}); + theInstruction.remove(); } function reportButtonValue(button, newValue, oldValue) { From 0e663054564016f2ff5d7b0766922b2b6805c07c Mon Sep 17 00:00:00 2001 From: Thijs Wenker Date: Sat, 7 Feb 2015 13:37:33 +0100 Subject: [PATCH 31/77] changed HMDScriptingInterface MyAvatar to new way of retrieving this object --- interface/src/scripting/HMDScriptingInterface.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/interface/src/scripting/HMDScriptingInterface.cpp b/interface/src/scripting/HMDScriptingInterface.cpp index e2d150e390..7b5d4ddac6 100644 --- a/interface/src/scripting/HMDScriptingInterface.cpp +++ b/interface/src/scripting/HMDScriptingInterface.cpp @@ -11,6 +11,8 @@ #include "HMDScriptingInterface.h" +#include + HMDScriptingInterface& HMDScriptingInterface::getInstance() { static HMDScriptingInterface sharedInstance; return sharedInstance; @@ -31,7 +33,7 @@ glm::vec3 HMDScriptingInterface::getHUDLookAtPosition3D() const { } glm::vec2 HMDScriptingInterface::getHUDLookAtPosition2D() const { - MyAvatar* myAvatar = Application::getInstance()->getAvatar(); + MyAvatar* myAvatar = DependencyManager::get()->getMyAvatar(); glm::vec3 sphereCenter = myAvatar->getDefaultEyePosition(); glm::vec3 hudIntersection = getHUDLookAtPosition3D(); From 0a41033c8568ad4b6f1ca0dc365ae60ee71a81df Mon Sep 17 00:00:00 2001 From: Thijs Wenker Date: Sat, 7 Feb 2015 13:58:11 +0100 Subject: [PATCH 32/77] - set cursor invisible when virtual-keyboard is shown. - get rid of the invisible cursor/magnifier states when cleaning up keyboard. --- examples/libraries/virtualKeyboard.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/examples/libraries/virtualKeyboard.js b/examples/libraries/virtualKeyboard.js index 42185138e3..7d7d72ae12 100644 --- a/examples/libraries/virtualKeyboard.js +++ b/examples/libraries/virtualKeyboard.js @@ -321,6 +321,8 @@ Keyboard = (function(params) { for (var i = 0; i < this.keys.length; i++) { this.keys[i].remove(); } + // resets the cursor and magnifier + this.updateVisibility(false); }; this.show = function() { @@ -340,6 +342,7 @@ Keyboard = (function(params) { if (HMD.magnifier == visible) { HMD.toggleMagnifier(); } + Window.cursorVisible = !visible; Overlays.editOverlay(tthis.background, { visible: tthis.visible }); for (var i = 0; i < this.keys.length; i++) { this.keys[i].updateVisibility(); From 8251542b786da7d2e2a908120a496ad061122862 Mon Sep 17 00:00:00 2001 From: Thijs Wenker Date: Sat, 7 Feb 2015 14:35:14 +0100 Subject: [PATCH 33/77] show instructions whenever the first gamepad is plugged since the script is loaded --- examples/controllers/oculus/goTo.js | 30 ++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/examples/controllers/oculus/goTo.js b/examples/controllers/oculus/goTo.js index ea3d12417d..2d2c80e661 100644 --- a/examples/controllers/oculus/goTo.js +++ b/examples/controllers/oculus/goTo.js @@ -20,21 +20,30 @@ Script.include("../../libraries/globals.js"); Script.include("../../libraries/virtualKeyboard.js"); function Instructions(imageURL) { + var tthis = this; + this.visible = false; this.overlay = Overlays.addOverlay("image", { imageURL: HIFI_PUBLIC_BUCKET + "images/tutorial-goTo.svg", x: 0, y: 0, + width: 200, + height: 200, alpha: 1, - visible: true + visible: this.visible }); + this.show = function() { + tthis.visible = true; + Overlays.editOverlay(tthis.overlay, {visible: tthis.visible}); + } this.remove = function() { Overlays.deleteOverlay(this.overlay); + this.visible = false; }; }; var theInstruction = new Instructions(); - +var firstControllerPlugged = false; var windowDimensions = Controller.getViewportDimensions(); var cursor = new Cursor({visible: false});; @@ -84,6 +93,7 @@ keyboard.onKeyRelease = function(event) { location = "hifi://" + locationURL; locationURL = ""; keyboard.hide(); + cursor.hide(); updateTextOverlay(); } } @@ -116,6 +126,9 @@ keyboard.onFullyLoaded = function() { }; function keyPressEvent(event) { + if (theInstruction.visible) { + return; + } if (event.key === SPACEBAR_CHARCODE) { keyboard.pressFocussedKey(); } else if (event.key === ENTER_CHARCODE || event.key === RETURN_CHARCODE) { @@ -128,6 +141,9 @@ function keyPressEvent(event) { } function keyReleaseEvent(event) { + if (theInstruction.visible) { + return; + } if (event.key === SPACEBAR_CHARCODE) { keyboard.releaseKeys(); } @@ -145,7 +161,11 @@ function scriptEnding() { } function reportButtonValue(button, newValue, oldValue) { - if (button == Joysticks.BUTTON_FACE_BOTTOM) { + if (theInstruction.visible) { + if (button == Joysticks.BUTTON_FACE_BOTTOM && newValue) { + theInstruction.remove(); + } + } else if (button == Joysticks.BUTTON_FACE_BOTTOM) { if (newValue) { keyboard.pressFocussedKey(); } else { @@ -158,6 +178,10 @@ function reportButtonValue(button, newValue, oldValue) { function addJoystick(gamepad) { gamepad.buttonStateChanged.connect(reportButtonValue); + if (!firstControllerPlugged) { + firstControllerPlugged = true; + theInstruction.show(); + } } var allJoysticks = Joysticks.getAllJoysticks(); From d810283d5a006550b8d1f380928fdff25d76b6e4 Mon Sep 17 00:00:00 2001 From: Thijs Wenker Date: Mon, 9 Feb 2015 16:47:00 +0100 Subject: [PATCH 34/77] just show the instructions the first 2 times --- examples/controllers/oculus/goTo.js | 50 ++++++++++++++++++++++------- 1 file changed, 39 insertions(+), 11 deletions(-) diff --git a/examples/controllers/oculus/goTo.js b/examples/controllers/oculus/goTo.js index 2d2c80e661..9f3daaea42 100644 --- a/examples/controllers/oculus/goTo.js +++ b/examples/controllers/oculus/goTo.js @@ -19,34 +19,62 @@ Script.include("../../libraries/globals.js"); Script.include("../../libraries/virtualKeyboard.js"); -function Instructions(imageURL) { +const MAX_SHOW_INSTRUCTION_TIMES = 2; +const INSTRUCTIONS_SETTING = "GoToInstructionsShowCounter" + +var windowDimensions = Controller.getViewportDimensions(); + +function Instructions(imageURL, originalWidth, originalHeight) { var tthis = this; + this.originalSize = {w: originalWidth, h: originalHeight}; this.visible = false; this.overlay = Overlays.addOverlay("image", { - imageURL: HIFI_PUBLIC_BUCKET + "images/tutorial-goTo.svg", + imageURL: imageURL, x: 0, y: 0, - width: 200, - height: 200, + width: originalWidth, + height: originalHeight, alpha: 1, visible: this.visible }); + this.show = function() { - tthis.visible = true; - Overlays.editOverlay(tthis.overlay, {visible: tthis.visible}); + var timesShown = Settings.getValue(INSTRUCTIONS_SETTING); + timesShown = timesShown === "" ? 0 : parseInt(timesShown); + print(timesShown); + if (timesShown < MAX_SHOW_INSTRUCTION_TIMES) { + Settings.setValue(INSTRUCTIONS_SETTING, timesShown + 1); + tthis.visible = true; + tthis.rescale(); + Overlays.editOverlay(tthis.overlay, {visible: tthis.visible}); + return; + } + tthis.remove(); } this.remove = function() { - Overlays.deleteOverlay(this.overlay); - this.visible = false; + Overlays.deleteOverlay(tthis.overlay); + tthis.visible = false; }; + this.rescale = function() { + var scale = Math.min(windowDimensions.x / tthis.originalSize.w, windowDimensions.y / tthis.originalSize.h); + var newWidth = tthis.originalSize.w * scale; + var newHeight = tthis.originalSize.h * scale; + Overlays.editOverlay(tthis.overlay, { + x: (windowDimensions.x / 2) - (newWidth / 2), + y: (windowDimensions.y / 2) - (newHeight / 2), + width: newWidth, + height: newHeight + }); + }; + this.rescale(); }; -var theInstruction = new Instructions(); +var theInstruction = new Instructions(HIFI_PUBLIC_BUCKET + "images/tutorial-goTo.svg", 457, 284.1); var firstControllerPlugged = false; -var windowDimensions = Controller.getViewportDimensions(); -var cursor = new Cursor({visible: false});; + +var cursor = new Cursor({visible: false}); var keyboard = new Keyboard({visible: false}); var textFontSize = 9; var text = null; From e53b38e497a5a8547edbedfbee5af5718b065d8f Mon Sep 17 00:00:00 2001 From: Thijs Wenker Date: Mon, 9 Feb 2015 17:16:54 +0100 Subject: [PATCH 35/77] style / make sure the magnifier isn't rendered when we don't want it --- examples/controllers/oculus/goTo.js | 62 +++++++++++++++++-------- interface/src/ui/ApplicationOverlay.cpp | 3 ++ 2 files changed, 46 insertions(+), 19 deletions(-) diff --git a/examples/controllers/oculus/goTo.js b/examples/controllers/oculus/goTo.js index 9f3daaea42..c991d97fda 100644 --- a/examples/controllers/oculus/goTo.js +++ b/examples/controllers/oculus/goTo.js @@ -51,10 +51,12 @@ function Instructions(imageURL, originalWidth, originalHeight) { } tthis.remove(); } + this.remove = function() { Overlays.deleteOverlay(tthis.overlay); tthis.visible = false; }; + this.rescale = function() { var scale = Math.min(windowDimensions.x / tthis.originalSize.w, windowDimensions.y / tthis.originalSize.h); var newWidth = tthis.originalSize.w * scale; @@ -115,14 +117,14 @@ keyboard.onKeyRelease = function(event) { // you can cancel a key by releasing its focusing before releasing it if (event.focus) { if (event.event == 'delete') { - deleteChar(); + deleteChar(); } else if (event.event == 'submit' || event.event == 'enter') { - print("going to hifi://" + locationURL); - location = "hifi://" + locationURL; - locationURL = ""; - keyboard.hide(); - cursor.hide(); - updateTextOverlay(); + print("going to hifi://" + locationURL); + location = "hifi://" + locationURL; + locationURL = ""; + keyboard.hide(); + cursor.hide(); + updateTextOverlay(); } } }; @@ -131,18 +133,18 @@ keyboard.onFullyLoaded = function() { print("Virtual-keyboard fully loaded."); var dimensions = Controller.getViewportDimensions(); text = Overlays.addOverlay("text", { - x: 0, - y: dimensions.y - keyboard.height() - 260, - width: dimensions.x, - height: 250, - backgroundColor: { red: 255, green: 255, blue: 255}, - color: { red: 0, green: 0, blue: 0}, - topMargin: 5, - leftMargin: 0, - font: {size: textFontSize}, - text: "", - alpha: 0.8, - visible: keyboard.visible + x: 0, + y: dimensions.y - keyboard.height() - 260, + width: dimensions.x, + height: 250, + backgroundColor: { red: 255, green: 255, blue: 255}, + color: { red: 0, green: 0, blue: 0}, + topMargin: 5, + leftMargin: 0, + font: {size: textFontSize}, + text: "", + alpha: 0.8, + visible: keyboard.visible }); updateTextOverlay(); // the cursor is being loaded after the keyboard, else it will be on the background of the keyboard @@ -189,6 +191,7 @@ function scriptEnding() { } function reportButtonValue(button, newValue, oldValue) { + print(button); if (theInstruction.visible) { if (button == Joysticks.BUTTON_FACE_BOTTOM && newValue) { theInstruction.remove(); @@ -201,6 +204,27 @@ function reportButtonValue(button, newValue, oldValue) { } } else if (button == Joysticks.BUTTON_FACE_RIGHT && newValue) { deleteChar(); + } else if (button == Joysticks.BUTTON_FACE_LEFT && newValue) { + keyboard.hide(); + if (cursor !== undefined) { + cursor.hide(); + } + Overlays.editOverlay(text, {visible: false}); + } else if (button == Joysticks.BUTTON_RIGHT_SHOULDER && newValue) { + if (keyboard.visible) { + print("going to hifi://" + locationURL); + location = "hifi://" + locationURL; + locationURL = ""; + keyboard.hide(); + cursor.hide(); + updateTextOverlay(); + return; + } + keyboard.show(); + if (cursor !== undefined) { + cursor.show(); + } + Overlays.editOverlay(text, {visible: true}); } } diff --git a/interface/src/ui/ApplicationOverlay.cpp b/interface/src/ui/ApplicationOverlay.cpp index f80acf5801..8fc55921e7 100644 --- a/interface/src/ui/ApplicationOverlay.cpp +++ b/interface/src/ui/ApplicationOverlay.cpp @@ -719,6 +719,9 @@ void ApplicationOverlay::renderPointersOculus(const glm::vec3& eyePos) { //Renders a small magnification of the currently bound texture at the coordinates void ApplicationOverlay::renderMagnifier(glm::vec2 magPos, float sizeMult, bool showBorder) { + if (!_magnifier) { + return; + } auto glCanvas = DependencyManager::get(); const int widgetWidth = glCanvas->width(); From 1d5afba1fac11d7bae4bd8c591cf27ebce5bab51 Mon Sep 17 00:00:00 2001 From: Thijs Wenker Date: Mon, 9 Feb 2015 18:40:36 +0100 Subject: [PATCH 36/77] removed some console noise --- examples/controllers/oculus/goTo.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/examples/controllers/oculus/goTo.js b/examples/controllers/oculus/goTo.js index c991d97fda..91ae8e6141 100644 --- a/examples/controllers/oculus/goTo.js +++ b/examples/controllers/oculus/goTo.js @@ -113,7 +113,6 @@ keyboard.onKeyPress = function(event) { }; keyboard.onKeyRelease = function(event) { - print("Key release event test"); // you can cancel a key by releasing its focusing before releasing it if (event.focus) { if (event.event == 'delete') { @@ -191,7 +190,6 @@ function scriptEnding() { } function reportButtonValue(button, newValue, oldValue) { - print(button); if (theInstruction.visible) { if (button == Joysticks.BUTTON_FACE_BOTTOM && newValue) { theInstruction.remove(); From 2c52c9c3c0d7b3965b98b3624ac8ea83599c02ea Mon Sep 17 00:00:00 2001 From: Thijs Wenker Date: Wed, 11 Feb 2015 22:57:59 +0100 Subject: [PATCH 37/77] fixes for the virtualKeyboardTextEntityExample --- .../virtualKeyboardTextEntityExample.js | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/examples/controllers/oculus/virtualKeyboardTextEntityExample.js b/examples/controllers/oculus/virtualKeyboardTextEntityExample.js index 794b659bcb..c3cb3c6316 100644 --- a/examples/controllers/oculus/virtualKeyboardTextEntityExample.js +++ b/examples/controllers/oculus/virtualKeyboardTextEntityExample.js @@ -27,7 +27,7 @@ const TEXT_MARGIN_RIGHT = 0.17; const TEXT_MARGIN_BOTTOM = 0.17; var windowDimensions = Controller.getViewportDimensions(); -var cursor = null; +var cursor = new Cursor(); var keyboard = new Keyboard(); var textFontSize = 9; var text = null; @@ -70,7 +70,7 @@ keyboard.onKeyRelease = function(event) { // you can cancel a key by releasing its focusing before releasing it if (event.focus) { if (event.event == 'delete') { - deleteChar(); + deleteChar(); } else if (event.event == 'submit') { print(textText); @@ -83,12 +83,14 @@ keyboard.onKeyRelease = function(event) { if (maxLineWidth < usernameWidth) { maxLineWidth = usernameWidth; } else { - var spaceableWidth = maxLineWidth - usernameWidth; - var spaceWidth = Overlays.textSize(textSizeMeasureOverlay, " ").width; - var numberOfSpaces = Math.floor(spaceableWidth / spaceWidth); - for (var i = 0; i < numberOfSpaces; i++) { - usernameLine = " " + usernameLine; - } + var spaceableWidth = maxLineWidth - usernameWidth; + //TODO: WORKAROUND WARNING BELOW Fix this when spaces are not trimmed out of the textsize calculation anymore + var spaceWidth = Overlays.textSize(textSizeMeasureOverlay, "| |").width + - Overlays.textSize(textSizeMeasureOverlay, "||").width; + var numberOfSpaces = Math.floor(spaceableWidth / spaceWidth); + for (var i = 0; i < numberOfSpaces; i++) { + usernameLine = " " + usernameLine; + } } var dimension_x = maxLineWidth + TEXT_MARGIN_RIGHT + TEXT_MARGIN_LEFT; if (position.x > 0 && position.y > 0 && position.z > 0) { @@ -100,7 +102,7 @@ keyboard.onKeyRelease = function(event) { backgroundColor: { red: 0, green: 0, blue: 0 }, textColor: { red: 255, green: 255, blue: 255 }, text: textText + "\n" + usernameLine, - lineHeight: 0.1 + lineHeight: 0.1 }); } textText = ""; @@ -127,7 +129,7 @@ keyboard.onFullyLoaded = function() { }); updateTextOverlay(); // the cursor is being loaded after the keyboard, else it will be on the background of the keyboard - cursor = new Cursor(); + cursor.initialize(); cursor.onUpdate = function(position) { keyboard.setFocusPosition(position.x, position.y); }; From 062c2cbcee34825cac95aa228c3638c7710b72d0 Mon Sep 17 00:00:00 2001 From: Thijs Wenker Date: Thu, 12 Feb 2015 22:55:44 +0100 Subject: [PATCH 38/77] HUD LookAt positions could be NULL now if whenever they're out of range HMD.HUDLookAtPosition2D -> HMD.getHUDLookAtPosition2D() HMD.HUDLookAtPosition3D -> HMD.getHUDLookAtPosition3D() --- examples/libraries/virtualKeyboard.js | 12 +++-- interface/src/Application.cpp | 4 +- .../src/scripting/HMDScriptingInterface.cpp | 44 ++++++++++++------- .../src/scripting/HMDScriptingInterface.h | 9 ++-- libraries/script-engine/src/ScriptEngine.cpp | 6 ++- libraries/script-engine/src/ScriptEngine.h | 2 + 6 files changed, 50 insertions(+), 27 deletions(-) diff --git a/examples/libraries/virtualKeyboard.js b/examples/libraries/virtualKeyboard.js index 7d7d72ae12..a1f952a5eb 100644 --- a/examples/libraries/virtualKeyboard.js +++ b/examples/libraries/virtualKeyboard.js @@ -516,12 +516,16 @@ Cursor = (function(params) { }); } var editobject = {}; - if (tthis.x !== HMD.HUDLookAtPosition2D.x) { - tthis.x = HMD.HUDLookAtPosition2D.x; + var hudLookatPosition = HMD.getHUDLookAtPosition2D(); + if (hudLookatPosition === null) { + return; + } + if (tthis.x !== hudLookatPosition.x) { + tthis.x = hudLookatPosition.x; editobject.x = tthis.x - (CURSOR_WIDTH / 2); } - if (tthis.y !== HMD.HUDLookAtPosition2D.y) { - tthis.y = HMD.HUDLookAtPosition2D.y; + if (tthis.y !== hudLookatPosition.y) { + tthis.y = hudLookatPosition.y; editobject.y = tthis.y - (CURSOR_HEIGHT / 2); } if (Object.keys(editobject).length > 0) { diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index d9bd5ed807..22e52d8eaa 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -3476,7 +3476,9 @@ void Application::registerScriptEngineWithApplicationServices(ScriptEngine* scri scriptEngine->registerGlobalObject("UndoStack", &_undoStackScriptingInterface); - scriptEngine->registerGlobalObject("HMD", &HMDScriptingInterface::getInstance()); + QScriptValue hmdInterface = scriptEngine->registerGlobalObject("HMD", &HMDScriptingInterface::getInstance()); + scriptEngine->registerFunction(hmdInterface, "getHUDLookAtPosition2D", HMDScriptingInterface::getHUDLookAtPosition2D, 0); + scriptEngine->registerFunction(hmdInterface, "getHUDLookAtPosition3D", HMDScriptingInterface::getHUDLookAtPosition3D, 0); #ifdef HAVE_RTMIDI scriptEngine->registerGlobalObject("MIDI", &MIDIManager::getInstance()); diff --git a/interface/src/scripting/HMDScriptingInterface.cpp b/interface/src/scripting/HMDScriptingInterface.cpp index 7b5d4ddac6..fe274b6878 100644 --- a/interface/src/scripting/HMDScriptingInterface.cpp +++ b/interface/src/scripting/HMDScriptingInterface.cpp @@ -1,4 +1,4 @@ -// +// // HMDScriptingInterface.cpp // interface/src/scripting // @@ -18,7 +18,7 @@ HMDScriptingInterface& HMDScriptingInterface::getInstance() { return sharedInstance; } -glm::vec3 HMDScriptingInterface::getHUDLookAtPosition3D() const { +bool HMDScriptingInterface::getHUDLookAtPosition3D(glm::vec3& result) const { Camera* camera = Application::getInstance()->getCamera(); glm::vec3 position = camera->getPosition(); glm::quat orientation = camera->getOrientation(); @@ -27,20 +27,30 @@ glm::vec3 HMDScriptingInterface::getHUDLookAtPosition3D() const { ApplicationOverlay& applicationOverlay = Application::getInstance()->getApplicationOverlay(); + return applicationOverlay.calculateRayUICollisionPoint(position, direction, result); +} + +QScriptValue HMDScriptingInterface::getHUDLookAtPosition2D(QScriptContext* context, QScriptEngine* engine) { + + glm::vec3 hudIntersection; + + if ((&HMDScriptingInterface::getInstance())->getHUDLookAtPosition3D(hudIntersection)) { + MyAvatar* myAvatar = DependencyManager::get()->getMyAvatar(); + glm::vec3 sphereCenter = myAvatar->getDefaultEyePosition(); + glm::vec3 direction = glm::inverse(myAvatar->getOrientation()) * (hudIntersection - sphereCenter); + glm::quat rotation = ::rotationBetween(glm::vec3(0.0f, 0.0f, -1.0f), direction); + glm::vec3 eulers = ::safeEulerAngles(rotation); + return qScriptValueFromValue(engine, Application::getInstance()->getApplicationOverlay() + .sphericalToOverlay(glm::vec2(eulers.y, -eulers.x))); + } + return QScriptValue::NullValue; +} + +QScriptValue HMDScriptingInterface::getHUDLookAtPosition3D(QScriptContext* context, QScriptEngine* engine) { glm::vec3 result; - applicationOverlay.calculateRayUICollisionPoint(position, direction, result); - return result; -} - -glm::vec2 HMDScriptingInterface::getHUDLookAtPosition2D() const { - MyAvatar* myAvatar = DependencyManager::get()->getMyAvatar(); - glm::vec3 sphereCenter = myAvatar->getDefaultEyePosition(); - - glm::vec3 hudIntersection = getHUDLookAtPosition3D(); - - glm::vec3 direction = glm::inverse(myAvatar->getOrientation()) * (hudIntersection - sphereCenter); - glm::quat rotation = ::rotationBetween(glm::vec3(0.0f, 0.0f, -1.0f), direction); - glm::vec3 eulers = ::safeEulerAngles(rotation); - - return Application::getInstance()->getApplicationOverlay().sphericalToOverlay(glm::vec2(eulers.y, -eulers.x)); + HMDScriptingInterface* hmdInterface = &HMDScriptingInterface::getInstance(); + if ((&HMDScriptingInterface::getInstance())->getHUDLookAtPosition3D(result)) { + return qScriptValueFromValue(engine, result); + } + return QScriptValue::NullValue; } diff --git a/interface/src/scripting/HMDScriptingInterface.h b/interface/src/scripting/HMDScriptingInterface.h index cc148d5d5d..bcd458ca5e 100644 --- a/interface/src/scripting/HMDScriptingInterface.h +++ b/interface/src/scripting/HMDScriptingInterface.h @@ -21,11 +21,12 @@ class HMDScriptingInterface : public QObject { Q_OBJECT Q_PROPERTY(bool magnifier READ getMagnifier) Q_PROPERTY(bool active READ isHMDMode) - Q_PROPERTY(glm::vec3 HUDLookAtPosition3D READ getHUDLookAtPosition3D) - Q_PROPERTY(glm::vec2 HUDLookAtPosition2D READ getHUDLookAtPosition2D) public: static HMDScriptingInterface& getInstance(); + static QScriptValue getHUDLookAtPosition2D(QScriptContext* context, QScriptEngine* engine); + static QScriptValue getHUDLookAtPosition3D(QScriptContext* context, QScriptEngine* engine); + public slots: void toggleMagnifier() { Application::getInstance()->getApplicationOverlay().toggleMagnifier(); }; @@ -34,8 +35,8 @@ private: bool getMagnifier() const { return Application::getInstance()->getApplicationOverlay().hasMagnifier(); }; bool isHMDMode() const { return Application::getInstance()->isHMDMode(); } - glm::vec3 getHUDLookAtPosition3D() const; - glm::vec2 getHUDLookAtPosition2D() const; + bool getHUDLookAtPosition3D(glm::vec3& result) const; + }; #endif // hifi_HMDScriptingInterface_h diff --git a/libraries/script-engine/src/ScriptEngine.cpp b/libraries/script-engine/src/ScriptEngine.cpp index 353e215561..d40d3752d2 100644 --- a/libraries/script-engine/src/ScriptEngine.cpp +++ b/libraries/script-engine/src/ScriptEngine.cpp @@ -272,8 +272,12 @@ QScriptValue ScriptEngine::registerGlobalObject(const QString& name, QObject* ob } void ScriptEngine::registerFunction(const QString& name, QScriptEngine::FunctionSignature fun, int numArguments) { + registerFunction(globalObject(), name, fun, numArguments); +} + +void ScriptEngine::registerFunction(QScriptValue parent, const QString& name, QScriptEngine::FunctionSignature fun, int numArguments) { QScriptValue scriptFun = newFunction(fun, numArguments); - globalObject().setProperty(name, scriptFun); + parent.setProperty(name, scriptFun); } void ScriptEngine::registerGetterSetter(const QString& name, QScriptEngine::FunctionSignature getter, diff --git a/libraries/script-engine/src/ScriptEngine.h b/libraries/script-engine/src/ScriptEngine.h index f78a14bffa..7cb1fb59db 100644 --- a/libraries/script-engine/src/ScriptEngine.h +++ b/libraries/script-engine/src/ScriptEngine.h @@ -58,6 +58,8 @@ public: void registerGetterSetter(const QString& name, QScriptEngine::FunctionSignature getter, QScriptEngine::FunctionSignature setter, QScriptValue object = QScriptValue::NullValue); void registerFunction(const QString& name, QScriptEngine::FunctionSignature fun, int numArguments = -1); + void registerFunction(QScriptValue parent, const QString& name, QScriptEngine::FunctionSignature fun, + int numArguments = -1); Q_INVOKABLE void setIsAvatar(bool isAvatar); bool isAvatar() const { return _isAvatar; } From 2c7e225ef75866416026c79d28688d5420ea69ac Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Fri, 13 Feb 2015 10:14:47 -0800 Subject: [PATCH 39/77] use cmake ExternalProject for glm in Interface --- CMakeLists.txt | 1 + cmake/externals/glm/CMakeLists.txt | 11 +++++++++++ cmake/macros/AddDependencyExternalProject.cmake | 15 +++++++++++++++ interface/CMakeLists.txt | 6 ++++-- 4 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 cmake/externals/glm/CMakeLists.txt create mode 100644 cmake/macros/AddDependencyExternalProject.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 04a5f3ee9a..b6eb3b935e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -104,6 +104,7 @@ set(HIFI_LIBRARY_DIR "${CMAKE_CURRENT_SOURCE_DIR}/libraries") set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules/") set(MACRO_DIR "${CMAKE_CURRENT_SOURCE_DIR}/cmake/macros") +set(EXTERNAL_PROJECT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/cmake/externals") file(GLOB HIFI_CUSTOM_MACROS "cmake/macros/*.cmake") foreach(CUSTOM_MACRO ${HIFI_CUSTOM_MACROS}) diff --git a/cmake/externals/glm/CMakeLists.txt b/cmake/externals/glm/CMakeLists.txt new file mode 100644 index 0000000000..0692b9573d --- /dev/null +++ b/cmake/externals/glm/CMakeLists.txt @@ -0,0 +1,11 @@ +include(ExternalProject) +ExternalProject_Add( + glm + URL https://github.com/g-truc/glm/archive/0.9.5.4.zip + CONFIGURE_COMMAND "" + BUILD_COMMAND "" + INSTALL_COMMAND "" + LOG_DOWNLOAD ON +) +ExternalProject_Get_Property(glm source_dir) +set(GLM_INCLUDE_DIRS ${source_dir}/glm) \ No newline at end of file diff --git a/cmake/macros/AddDependencyExternalProject.cmake b/cmake/macros/AddDependencyExternalProject.cmake new file mode 100644 index 0000000000..56cf6d71be --- /dev/null +++ b/cmake/macros/AddDependencyExternalProject.cmake @@ -0,0 +1,15 @@ +# +# SetupExternalProject.cmake +# cmake/macros +# +# Copyright 2015 High Fidelity, Inc. +# Created by Stephen Birarda on February 13, 2014 +# +# Distributed under the Apache License, Version 2.0. +# See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +# + +macro(ADD_DEPENDENCY_EXTERNAL_PROJECT _PROJ_NAME) + add_subdirectory(${EXTERNAL_PROJECT_DIR}/${_PROJ_NAME} ${EXTERNAL_PROJECT_DIR}/${_PROJ_NAME}/build) + add_dependencies(${TARGET_NAME} ${_PROJ_NAME}) +endmacro() \ No newline at end of file diff --git a/interface/CMakeLists.txt b/interface/CMakeLists.txt index 8b23b85e04..8de425d5b0 100644 --- a/interface/CMakeLists.txt +++ b/interface/CMakeLists.txt @@ -32,8 +32,6 @@ elseif (WIN32) set(GL_HEADERS "#include \n#include \n#include ") endif () -# set up the external glm library -include_glm() include_bullet() # create the InterfaceConfig.h file based on GL_HEADERS above @@ -109,6 +107,10 @@ endif() # create the executable, make it a bundle on OS X add_executable(${TARGET_NAME} MACOSX_BUNDLE ${INTERFACE_SRCS} ${QM}) +# set up the external glm library +add_dependency_external_project(glm) +target_include_directories(${TARGET_NAME} PUBLIC ${GLM_INCLUDE_DIRS}) + # link required hifi libraries link_hifi_libraries(shared octree environment gpu model fbx metavoxels networking entities avatars audio audio-client animation script-engine physics From df8e51f8353b099fe1eaf42c23bc01efc45fe0be Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Fri, 13 Feb 2015 10:21:21 -0800 Subject: [PATCH 40/77] use external project glm in more targets --- assignment-client/CMakeLists.txt | 3 ++- cmake/macros/IncludeGLM.cmake | 13 ------------- gvr-interface/CMakeLists.txt | 3 ++- interface/CMakeLists.txt | 2 +- libraries/audio/CMakeLists.txt | 3 ++- 5 files changed, 7 insertions(+), 17 deletions(-) delete mode 100644 cmake/macros/IncludeGLM.cmake diff --git a/assignment-client/CMakeLists.txt b/assignment-client/CMakeLists.txt index b56eea5c90..c2203316f9 100644 --- a/assignment-client/CMakeLists.txt +++ b/assignment-client/CMakeLists.txt @@ -2,7 +2,8 @@ set(TARGET_NAME assignment-client) setup_hifi_project(Core Gui Network Script Widgets) -include_glm() +add_dependency_external_project(glm) +target_link_directories(${TARGET_NAME} PRIVATE ${GLM_INCLUDE_DIRS}) # link in the shared libraries link_hifi_libraries( diff --git a/cmake/macros/IncludeGLM.cmake b/cmake/macros/IncludeGLM.cmake deleted file mode 100644 index 3e4bf9174d..0000000000 --- a/cmake/macros/IncludeGLM.cmake +++ /dev/null @@ -1,13 +0,0 @@ -# -# IncludeGLM.cmake -# -# Copyright 2013 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 -# - -macro(INCLUDE_GLM) - find_package(GLM REQUIRED) - include_directories(SYSTEM "${GLM_INCLUDE_DIRS}") -endmacro(INCLUDE_GLM) \ No newline at end of file diff --git a/gvr-interface/CMakeLists.txt b/gvr-interface/CMakeLists.txt index 37ac6ec050..68eeb86791 100644 --- a/gvr-interface/CMakeLists.txt +++ b/gvr-interface/CMakeLists.txt @@ -24,7 +24,8 @@ endif () include_directories(${Qt5Gui_PRIVATE_INCLUDE_DIRS}) -include_glm() +add_dependency_external_project(glm) +target_link_libraries(${TARGET_NAME} PRIVATE ${GLM_INCLUDE_DIRS}) link_hifi_libraries(shared networking audio-client avatars) include_dependency_includes() diff --git a/interface/CMakeLists.txt b/interface/CMakeLists.txt index 8de425d5b0..2be9f7bee2 100644 --- a/interface/CMakeLists.txt +++ b/interface/CMakeLists.txt @@ -109,7 +109,7 @@ add_executable(${TARGET_NAME} MACOSX_BUNDLE ${INTERFACE_SRCS} ${QM}) # set up the external glm library add_dependency_external_project(glm) -target_include_directories(${TARGET_NAME} PUBLIC ${GLM_INCLUDE_DIRS}) +target_include_directories(${TARGET_NAME} PRIVATE ${GLM_INCLUDE_DIRS}) # link required hifi libraries link_hifi_libraries(shared octree environment gpu model fbx metavoxels networking entities avatars diff --git a/libraries/audio/CMakeLists.txt b/libraries/audio/CMakeLists.txt index b08d9e88f4..c44198ddef 100644 --- a/libraries/audio/CMakeLists.txt +++ b/libraries/audio/CMakeLists.txt @@ -3,7 +3,8 @@ set(TARGET_NAME audio) # use setup_hifi_library macro to setup our project and link appropriate Qt modules setup_hifi_library(Network) -include_glm() +add_dependency_external_project(glm) +target_include_directories(${TARGET_NAME} PUBLIC ${GLM_INCLUDE_DIRS}) link_hifi_libraries(networking shared) From a4752aaab07cefb31730d493348fe88fc4362d4e Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Fri, 13 Feb 2015 10:22:09 -0800 Subject: [PATCH 41/77] use external project glm in avatars --- libraries/avatars/CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libraries/avatars/CMakeLists.txt b/libraries/avatars/CMakeLists.txt index ccb661376d..c227e057e3 100644 --- a/libraries/avatars/CMakeLists.txt +++ b/libraries/avatars/CMakeLists.txt @@ -3,7 +3,8 @@ set(TARGET_NAME avatars) # use setup_hifi_library macro to setup our project and link appropriate Qt modules setup_hifi_library(Network Script) -include_glm() +add_dependency_external_project(glm) +target_include_directories(${TARGET_NAME} PUBLIC ${GLM_INCLUDE_DIRS}) link_hifi_libraries(audio shared networking) From 866295b09e28bab615d5d11325d3f62729de1d17 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Fri, 13 Feb 2015 10:24:46 -0800 Subject: [PATCH 42/77] use external project glm in entities library --- libraries/entities/CMakeLists.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libraries/entities/CMakeLists.txt b/libraries/entities/CMakeLists.txt index 7589599548..8846dbfb89 100644 --- a/libraries/entities/CMakeLists.txt +++ b/libraries/entities/CMakeLists.txt @@ -3,7 +3,9 @@ set(TARGET_NAME entities) # use setup_hifi_library macro to setup our project and link appropriate Qt modules setup_hifi_library(Network Script) -include_glm() +add_dependency_external_project(glm) +target_include_directories(${TARGET_NAME} PUBLIC ${GLM_INCLUDE_DIRS}) + include_bullet() link_hifi_libraries(avatars shared octree gpu model fbx networking animation) From 0e790daa5b373cf808d2c048c3867976b5600aa2 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Fri, 13 Feb 2015 10:26:23 -0800 Subject: [PATCH 43/77] remove glm dependency from entities-renderer --- libraries/entities-renderer/CMakeLists.txt | 2 -- 1 file changed, 2 deletions(-) diff --git a/libraries/entities-renderer/CMakeLists.txt b/libraries/entities-renderer/CMakeLists.txt index 6d7f5ee960..5f3b2298a8 100644 --- a/libraries/entities-renderer/CMakeLists.txt +++ b/libraries/entities-renderer/CMakeLists.txt @@ -3,8 +3,6 @@ set(TARGET_NAME entities-renderer) # use setup_hifi_library macro to setup our project and link appropriate Qt modules setup_hifi_library(Widgets OpenGL Network Script) -include_glm() - link_hifi_libraries(shared gpu script-engine render-utils) # call macro to include our dependency includes and bubble them up via a property on our target From 4d5d647d846ba732c14d9720a4d8ec407fa2c6f4 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Fri, 13 Feb 2015 10:27:24 -0800 Subject: [PATCH 44/77] use external project glm in environment library --- libraries/environment/CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libraries/environment/CMakeLists.txt b/libraries/environment/CMakeLists.txt index 962628cd85..7cd91823d3 100644 --- a/libraries/environment/CMakeLists.txt +++ b/libraries/environment/CMakeLists.txt @@ -3,7 +3,8 @@ set(TARGET_NAME environment) # use setup_hifi_library macro to setup our project and link appropriate Qt modules setup_hifi_library() -include_glm() +add_dependency_external_project(glm) +target_include_directories(${TARGET_NAME} PUBLIC ${GLM_INCLUDE_DIRS}) link_hifi_libraries(shared networking) From 26b93731f827417c963d79379a549791a2af4df8 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Fri, 13 Feb 2015 10:28:06 -0800 Subject: [PATCH 45/77] use glm as external project in fbx library --- libraries/fbx/CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libraries/fbx/CMakeLists.txt b/libraries/fbx/CMakeLists.txt index 67fe920568..7e28f63fc9 100644 --- a/libraries/fbx/CMakeLists.txt +++ b/libraries/fbx/CMakeLists.txt @@ -3,7 +3,8 @@ set(TARGET_NAME fbx) # use setup_hifi_library macro to setup our project and link appropriate Qt modules setup_hifi_library() -include_glm() +add_dependency_external_project(glm) +target_include_directories(${TARGET_NAME} PUBLIC ${GLM_INCLUDE_DIRS}) link_hifi_libraries(shared gpu model networking octree) From 54ce79db5a42e4e35aceaa0beb74de052d534c9d Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Fri, 13 Feb 2015 10:29:19 -0800 Subject: [PATCH 46/77] remove glm dependency in gpu library --- libraries/gpu/CMakeLists.txt | 2 -- 1 file changed, 2 deletions(-) diff --git a/libraries/gpu/CMakeLists.txt b/libraries/gpu/CMakeLists.txt index b6bbba1c0f..789ffdbfeb 100644 --- a/libraries/gpu/CMakeLists.txt +++ b/libraries/gpu/CMakeLists.txt @@ -3,8 +3,6 @@ set(TARGET_NAME gpu) # use setup_hifi_library macro to setup our project and link appropriate Qt modules setup_hifi_library() -include_glm() - link_hifi_libraries(shared) if (APPLE) From 16615b9be021aed93f41ac7fd2e1a593279d18eb Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Fri, 13 Feb 2015 10:30:22 -0800 Subject: [PATCH 47/77] use glm external project in metavoxels library --- libraries/metavoxels/CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libraries/metavoxels/CMakeLists.txt b/libraries/metavoxels/CMakeLists.txt index 4ead36e51a..6143bce2dc 100644 --- a/libraries/metavoxels/CMakeLists.txt +++ b/libraries/metavoxels/CMakeLists.txt @@ -8,7 +8,8 @@ setup_hifi_library(Network Script Widgets) # link in the networking library link_hifi_libraries(shared networking) -include_glm() +add_dependency_external_project(glm) +target_include_directories(${TARGET_NAME} PUBLIC ${GLM_INCLUDE_DIRS}) # call macro to include our dependency includes and bubble them up via a property on our target include_dependency_includes() \ No newline at end of file From 1d90c1c827111d00d71aef52be1b799a9e5fea56 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Fri, 13 Feb 2015 10:31:41 -0800 Subject: [PATCH 48/77] use glm external project in model library --- libraries/model/CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libraries/model/CMakeLists.txt b/libraries/model/CMakeLists.txt index 309f6c3e6d..6d729ea58c 100755 --- a/libraries/model/CMakeLists.txt +++ b/libraries/model/CMakeLists.txt @@ -3,7 +3,8 @@ set(TARGET_NAME model) # use setup_hifi_library macro to setup our project and link appropriate Qt modules setup_hifi_library() -include_glm() +add_dependency_external_project(glm) +target_include_directories(${TARGET_NAME} PUBLIC ${GLM_INCLUDE_DIRS}) link_hifi_libraries(shared gpu) From 8994cc026801570e44cf13cb0a71a5f81b1f364e Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Fri, 13 Feb 2015 10:32:27 -0800 Subject: [PATCH 49/77] use external project glm for octree library --- libraries/octree/CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libraries/octree/CMakeLists.txt b/libraries/octree/CMakeLists.txt index f4ac2263c2..c55f3bae89 100644 --- a/libraries/octree/CMakeLists.txt +++ b/libraries/octree/CMakeLists.txt @@ -3,7 +3,8 @@ set(TARGET_NAME octree) # use setup_hifi_library macro to setup our project and link appropriate Qt modules setup_hifi_library() -include_glm() +add_dependency_external_project(glm) +target_include_directories(${TARGET_NAME} PUBLIC ${GLM_INCLUDE_DIRS}) link_hifi_libraries(shared networking) From d7ce10dedb0b4b493ae456066201a936adeb57d1 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Fri, 13 Feb 2015 10:33:35 -0800 Subject: [PATCH 50/77] use external project glm for physics library --- libraries/physics/CMakeLists.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libraries/physics/CMakeLists.txt b/libraries/physics/CMakeLists.txt index 416ffa49f1..8b48501458 100644 --- a/libraries/physics/CMakeLists.txt +++ b/libraries/physics/CMakeLists.txt @@ -3,7 +3,9 @@ set(TARGET_NAME physics) # use setup_hifi_library macro to setup our project and link appropriate Qt modules setup_hifi_library() -include_glm() +add_dependency_external_project(glm) +target_include_directories(${TARGET_NAME} PUBLIC ${GLM_INCLUDE_DIRS}) + include_bullet() if (BULLET_FOUND) target_link_libraries(${TARGET_NAME} ${BULLET_LIBRARIES}) From fa6f6a6b71d0cf7e3ed88cfb32ad1175e791ca7a Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Fri, 13 Feb 2015 10:34:19 -0800 Subject: [PATCH 51/77] use external project glm in render-utils --- libraries/render-utils/CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libraries/render-utils/CMakeLists.txt b/libraries/render-utils/CMakeLists.txt index ed2dcce858..0bf7e91951 100644 --- a/libraries/render-utils/CMakeLists.txt +++ b/libraries/render-utils/CMakeLists.txt @@ -8,7 +8,8 @@ qt5_add_resources(QT_RESOURCES_FILE "${CMAKE_CURRENT_SOURCE_DIR}/res/fonts/fonts # use setup_hifi_library macro to setup our project and link appropriate Qt modules setup_hifi_library(Widgets OpenGL Network Script) -include_glm() +add_dependency_external_project(glm) +target_include_directories(${TARGET_NAME} PUBLIC ${GLM_INCLUDE_DIRS}) link_hifi_libraries(animation fbx shared gpu) From b7135510873ab205ea8d1e5447970a4cb8a35c8a Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Fri, 13 Feb 2015 10:35:06 -0800 Subject: [PATCH 52/77] use external project glm in script-engine --- libraries/script-engine/CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libraries/script-engine/CMakeLists.txt b/libraries/script-engine/CMakeLists.txt index 7ab73ceefb..2c325e4daf 100644 --- a/libraries/script-engine/CMakeLists.txt +++ b/libraries/script-engine/CMakeLists.txt @@ -3,7 +3,8 @@ set(TARGET_NAME script-engine) # use setup_hifi_library macro to setup our project and link appropriate Qt modules setup_hifi_library(Gui Network Script Widgets) -include_glm() +add_dependency_external_project(glm) +target_include_directories(${TARGET_NAME} PUBLIC ${GLM_INCLUDE_DIRS}) link_hifi_libraries(shared octree gpu model fbx entities animation audio physics metavoxels) From d3973a724c3fe3e9b013c5d638ea85e8b8b4435d Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Fri, 13 Feb 2015 10:35:52 -0800 Subject: [PATCH 53/77] remove glm requirement in audio tests --- tests/audio/CMakeLists.txt | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/audio/CMakeLists.txt b/tests/audio/CMakeLists.txt index fb6b9c2e11..62d0ce5be9 100644 --- a/tests/audio/CMakeLists.txt +++ b/tests/audio/CMakeLists.txt @@ -2,8 +2,6 @@ set(TARGET_NAME audio-tests) setup_hifi_project() -include_glm() - # link in the shared libraries link_hifi_libraries(shared audio networking) From 0e32ed280a059d621ad73eae52634b2f926523f5 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Fri, 13 Feb 2015 10:36:23 -0800 Subject: [PATCH 54/77] put back glm dependency via external proj in entities-renderer --- libraries/entities-renderer/CMakeLists.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libraries/entities-renderer/CMakeLists.txt b/libraries/entities-renderer/CMakeLists.txt index 5f3b2298a8..46d6b8a462 100644 --- a/libraries/entities-renderer/CMakeLists.txt +++ b/libraries/entities-renderer/CMakeLists.txt @@ -3,6 +3,9 @@ set(TARGET_NAME entities-renderer) # use setup_hifi_library macro to setup our project and link appropriate Qt modules setup_hifi_library(Widgets OpenGL Network Script) +add_dependency_external_project(glm) +target_include_directories(${TARGET_NAME} PUBLIC ${GLM_INCLUDE_DIRS}) + link_hifi_libraries(shared gpu script-engine render-utils) # call macro to include our dependency includes and bubble them up via a property on our target From 263afdd22c22f7acb33f8fbeff8cc22745ce8232 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Fri, 13 Feb 2015 10:37:17 -0800 Subject: [PATCH 55/77] use external project glm in physics tests --- tests/physics/CMakeLists.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/physics/CMakeLists.txt b/tests/physics/CMakeLists.txt index 14e6c56df3..89fba47bea 100644 --- a/tests/physics/CMakeLists.txt +++ b/tests/physics/CMakeLists.txt @@ -2,7 +2,9 @@ set(TARGET_NAME physics-tests) setup_hifi_project() -include_glm() +add_dependency_external_project(glm) +target_include_directories(${TARGET_NAME} PUBLIC ${GLM_INCLUDE_DIRS}) + include_bullet() link_hifi_libraries(shared physics) From 9c13bec47686a019d0188c4c442716ed490c1603 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Fri, 13 Feb 2015 10:38:01 -0800 Subject: [PATCH 56/77] remove glm include where no longer required --- tests/metavoxels/CMakeLists.txt | 2 -- tests/octree/CMakeLists.txt | 2 -- tests/render-utils/CMakeLists.txt | 2 -- tests/shared/CMakeLists.txt | 2 -- tools/bitstream2json/CMakeLists.txt | 2 -- tools/json2bitstream/CMakeLists.txt | 2 -- 6 files changed, 12 deletions(-) diff --git a/tests/metavoxels/CMakeLists.txt b/tests/metavoxels/CMakeLists.txt index 7524c5c87c..76f8870b34 100644 --- a/tests/metavoxels/CMakeLists.txt +++ b/tests/metavoxels/CMakeLists.txt @@ -2,8 +2,6 @@ set(TARGET_NAME metavoxel-tests) auto_mtc() -include_glm() - setup_hifi_project(Network Script Widgets) # link in the shared libraries diff --git a/tests/octree/CMakeLists.txt b/tests/octree/CMakeLists.txt index 7fc6b56332..99e3516431 100644 --- a/tests/octree/CMakeLists.txt +++ b/tests/octree/CMakeLists.txt @@ -2,8 +2,6 @@ set(TARGET_NAME octree-tests) setup_hifi_project(Script Network) -include_glm() - # link in the shared libraries link_hifi_libraries(shared octree gpu model fbx metavoxels networking entities avatars audio animation script-engine physics) diff --git a/tests/render-utils/CMakeLists.txt b/tests/render-utils/CMakeLists.txt index 47d80268d8..12a9fe5701 100644 --- a/tests/render-utils/CMakeLists.txt +++ b/tests/render-utils/CMakeLists.txt @@ -2,8 +2,6 @@ set(TARGET_NAME render-utils-tests) setup_hifi_project(Quick Gui OpenGL) -include_glm() - #include_oglplus() # link in the shared libraries diff --git a/tests/shared/CMakeLists.txt b/tests/shared/CMakeLists.txt index f067fa52b5..0402d3c74b 100644 --- a/tests/shared/CMakeLists.txt +++ b/tests/shared/CMakeLists.txt @@ -2,8 +2,6 @@ set(TARGET_NAME shared-tests) setup_hifi_project() -include_glm() - # link in the shared libraries link_hifi_libraries(shared) diff --git a/tools/bitstream2json/CMakeLists.txt b/tools/bitstream2json/CMakeLists.txt index 2e8bb213be..64ffbae5bf 100644 --- a/tools/bitstream2json/CMakeLists.txt +++ b/tools/bitstream2json/CMakeLists.txt @@ -1,8 +1,6 @@ set(TARGET_NAME bitstream2json) setup_hifi_project(Widgets Script) -include_glm() - link_hifi_libraries(metavoxels) include_dependency_includes() \ No newline at end of file diff --git a/tools/json2bitstream/CMakeLists.txt b/tools/json2bitstream/CMakeLists.txt index 283d450e11..d69a8dbe17 100644 --- a/tools/json2bitstream/CMakeLists.txt +++ b/tools/json2bitstream/CMakeLists.txt @@ -1,8 +1,6 @@ set(TARGET_NAME json2bitstream) setup_hifi_project(Widgets Script) -include_glm() - link_hifi_libraries(metavoxels) include_dependency_includes() \ No newline at end of file From 2f875cc08e741a69555deab94d861f9280953c21 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Fri, 13 Feb 2015 10:38:13 -0800 Subject: [PATCH 57/77] remove the glm find module --- cmake/modules/FindGLM.cmake | 28 ---------------------------- 1 file changed, 28 deletions(-) delete mode 100644 cmake/modules/FindGLM.cmake diff --git a/cmake/modules/FindGLM.cmake b/cmake/modules/FindGLM.cmake deleted file mode 100644 index a75730b238..0000000000 --- a/cmake/modules/FindGLM.cmake +++ /dev/null @@ -1,28 +0,0 @@ -# -# FindGLM.cmake -# -# Try to find GLM include path. -# Once done this will define -# -# GLM_INCLUDE_DIRS -# -# Created on 7/17/2014 by Stephen Birarda -# 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 -# - -# setup hints for GLM search -include("${MACRO_DIR}/HifiLibrarySearchHints.cmake") -hifi_library_search_hints("glm") - -# locate header -find_path(GLM_INCLUDE_DIR "glm/glm.hpp" HINTS ${GLM_SEARCH_DIRS}) - -set(GLM_INCLUDE_DIRS "${GLM_INCLUDE_DIR}") - -include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(GLM DEFAULT_MSG GLM_INCLUDE_DIRS) - -mark_as_advanced(GLM_INCLUDE_DIRS GLM_SEARCH_DIRS) \ No newline at end of file From 9136154cd5adc3a566c10ee62b9ab20f21442f18 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Fri, 13 Feb 2015 10:48:27 -0800 Subject: [PATCH 58/77] fix double subdir include, clear up build guide --- BUILD.md | 7 ++++++- assignment-client/CMakeLists.txt | 2 +- cmake/macros/AddDependencyExternalProject.cmake | 5 ++++- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/BUILD.md b/BUILD.md index 82cbf6628c..3065254529 100644 --- a/BUILD.md +++ b/BUILD.md @@ -2,7 +2,6 @@ * [cmake](http://www.cmake.org/cmake/resources/software.html) ~> 2.8.12.2 * [Qt](http://qt-project.org/downloads) ~> 5.3.2 -* [glm](http://glm.g-truc.net/0.9.5/index.html) ~> 0.9.5.4 * [OpenSSL](https://www.openssl.org/related/binaries.html) ~> 1.0.1g * IMPORTANT: OpenSSL 1.0.1g is critical to avoid a security vulnerability. * [Intel Threading Building Blocks](https://www.threadingbuildingblocks.org/) ~> 4.3 @@ -10,6 +9,12 @@ * [Bullet Physics Engine](https://code.google.com/p/bullet/downloads/list) ~> 2.82 * [Gverb](https://github.com/highfidelity/gverb/archive/master.zip) (direct download to latest version) +#### CMake External Project Dependencies + +The following dependencies will be downloaded, built, linked and included automatically by CMake where we require them. The CMakeLists files that handle grabbing each of the following external dependencies can be found in the [cmake/externals folder](cmake/externals). The resulting downloads, source files and binaries will be placed in the `build` directory in each of the subfolders for each external project. These are not placed in your normal build tree when doing an out of source build so that they do not need to be re-downloaded and re-compiled every time the CMake build folder is cleared. + +* [glm](http://glm.g-truc.net/0.9.5/index.html) ~> 0.9.5.4 + ### OS Specific Build Guides * [BUILD_OSX.md](BUILD_OSX.md) - additional instructions for OS X. * [BUILD_LINUX.md](BUILD_LINUX.md) - additional instructions for Linux. diff --git a/assignment-client/CMakeLists.txt b/assignment-client/CMakeLists.txt index c2203316f9..d8d2d44090 100644 --- a/assignment-client/CMakeLists.txt +++ b/assignment-client/CMakeLists.txt @@ -3,7 +3,7 @@ set(TARGET_NAME assignment-client) setup_hifi_project(Core Gui Network Script Widgets) add_dependency_external_project(glm) -target_link_directories(${TARGET_NAME} PRIVATE ${GLM_INCLUDE_DIRS}) +target_include_directories(${TARGET_NAME} PRIVATE ${GLM_INCLUDE_DIRS}) # link in the shared libraries link_hifi_libraries( diff --git a/cmake/macros/AddDependencyExternalProject.cmake b/cmake/macros/AddDependencyExternalProject.cmake index 56cf6d71be..96b3ee44ab 100644 --- a/cmake/macros/AddDependencyExternalProject.cmake +++ b/cmake/macros/AddDependencyExternalProject.cmake @@ -10,6 +10,9 @@ # macro(ADD_DEPENDENCY_EXTERNAL_PROJECT _PROJ_NAME) - add_subdirectory(${EXTERNAL_PROJECT_DIR}/${_PROJ_NAME} ${EXTERNAL_PROJECT_DIR}/${_PROJ_NAME}/build) + if (NOT TARGET ${_PROJ_NAME}) + add_subdirectory(${EXTERNAL_PROJECT_DIR}/${_PROJ_NAME} ${CMAKE_BINARY_DIR}/externals/${_PROJ_NAME}) + endif () + add_dependencies(${TARGET_NAME} ${_PROJ_NAME}) endmacro() \ No newline at end of file From 50c9bb2ae53fedf222a938c0536e6d105b6a5614 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Fri, 13 Feb 2015 12:33:27 -0800 Subject: [PATCH 59/77] remove glm as manual dep in BUILD guides --- BUILD_ANDROID.md | 5 ----- BUILD_OSX.md | 2 +- BUILD_WIN.md | 9 --------- cmake/externals/glm/CMakeLists.txt | 9 ++++----- cmake/macros/AddDependencyExternalProject.cmake | 12 +++++++++++- 5 files changed, 16 insertions(+), 21 deletions(-) diff --git a/BUILD_ANDROID.md b/BUILD_ANDROID.md index 719aa8cfd9..6ff3160775 100644 --- a/BUILD_ANDROID.md +++ b/BUILD_ANDROID.md @@ -127,11 +127,6 @@ To put the Gear VR Service into developer mode you need an application with an O Once the application is on your device, go to `Settings->Application Manager->Gear VR Service->Manage Storage`. Tap on `VR Service Version` six times. It will scan your device to verify that you have an osig file in an application on your device, and then it will let you enable Developer mode. -####GLM - -GLM is a header only library and technically the same GLM used for desktop builds of hifi could be used for the Android build. However, to avoid conflicts with system installations of Android dependencies, CMake will only look for Android headers and libraries in `ANDROID_LIB_DIR` or in your android-ndk install. - -Download the [glm headers](http://sourceforge.net/projects/ogl-math/files/) from their sourceforge page. The version you download should match the requirement shown in the [general build guide](BUILD.md). Extract the archive into your `ANDROID_LIB_DIR` and rename the extracted folder to `glm`. ###CMake diff --git a/BUILD_OSX.md b/BUILD_OSX.md index fce74cf678..2d5460d39d 100644 --- a/BUILD_OSX.md +++ b/BUILD_OSX.md @@ -4,7 +4,7 @@ Please read the [general build guide](BUILD.md) for information on dependencies [Homebrew](http://brew.sh/) is an excellent package manager for OS X. It makes install of all hifi dependencies very simple. brew tap highfidelity/homebrew-formulas - brew install cmake glm openssl tbb libsoxr + brew install cmake openssl tbb libsoxr brew install highfidelity/formulas/qt5 brew link qt5 --force diff --git a/BUILD_WIN.md b/BUILD_WIN.md index 8022fae5b8..ebc0b60f25 100644 --- a/BUILD_WIN.md +++ b/BUILD_WIN.md @@ -56,9 +56,6 @@ The recommended route for CMake to find the external dependencies is to place al -> bin -> include -> lib - -> glm - -> glm - -> glm.hpp -> openssl -> bin -> include @@ -129,12 +126,6 @@ Download the binary package: `glew-1.10.0-win32.zip`. Extract to %HIFI_LIB_DIR%\ Add to the PATH: `%HIFI_LIB_DIR%\glew\bin\Release\Win32` -###GLM - -This package contains only headers, so there's nothing to add to the PATH. - -Be careful with glm. For the folder other libraries would normally call 'include', the folder containing the headers, glm opts to use 'glm'. You will have a glm folder nested inside the top-level glm folder. - ###Gverb 1. Go to https://github.com/highfidelity/gverb diff --git a/cmake/externals/glm/CMakeLists.txt b/cmake/externals/glm/CMakeLists.txt index 0692b9573d..6246993df5 100644 --- a/cmake/externals/glm/CMakeLists.txt +++ b/cmake/externals/glm/CMakeLists.txt @@ -2,10 +2,9 @@ include(ExternalProject) ExternalProject_Add( glm URL https://github.com/g-truc/glm/archive/0.9.5.4.zip - CONFIGURE_COMMAND "" - BUILD_COMMAND "" - INSTALL_COMMAND "" + CMAKE_ARGS -DCMAKE_INSTALL_PREFIX:PATH= LOG_DOWNLOAD ON ) -ExternalProject_Get_Property(glm source_dir) -set(GLM_INCLUDE_DIRS ${source_dir}/glm) \ No newline at end of file +ExternalProject_Get_Property(glm install_dir) + +export(TARGETS glm FILE ${CMAKE_BINARY_DIR}/glm-config.cmake) \ No newline at end of file diff --git a/cmake/macros/AddDependencyExternalProject.cmake b/cmake/macros/AddDependencyExternalProject.cmake index 96b3ee44ab..c4c2c0d005 100644 --- a/cmake/macros/AddDependencyExternalProject.cmake +++ b/cmake/macros/AddDependencyExternalProject.cmake @@ -11,8 +11,18 @@ macro(ADD_DEPENDENCY_EXTERNAL_PROJECT _PROJ_NAME) if (NOT TARGET ${_PROJ_NAME}) - add_subdirectory(${EXTERNAL_PROJECT_DIR}/${_PROJ_NAME} ${CMAKE_BINARY_DIR}/externals/${_PROJ_NAME}) + + if (ANDROID) + set(_PROJ_BINARY_DIR ${EXTERNAL_PROJECT_DIR}/${_PROJ_NAME}/build/android) + else () + set(_PROJ_BINARY_DIR ${EXTERNAL_PROJECT_DIR}/${_PROJ_NAME}/build) + endif () + + add_subdirectory(${EXTERNAL_PROJECT_DIR}/${_PROJ_NAME} ${_PROJ_BINARY_DIR}) endif () + string(TOUPPER ${_PROJ_NAME} _PROJ_NAME_UPPER) + get_target_property(${_PROJ_NAME_UPPER}_INCLUDE_DIRS ${_PROJ_NAME} INCLUDE_DIRS) + add_dependencies(${TARGET_NAME} ${_PROJ_NAME}) endmacro() \ No newline at end of file From 8c998a65eee153ed4ed38765579a1df295ed3ed9 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Fri, 13 Feb 2015 12:50:32 -0800 Subject: [PATCH 60/77] use the glm find_package and check externals --- assignment-client/CMakeLists.txt | 1 + cmake/externals/glm/CMakeLists.txt | 1 + cmake/macros/HifiLibrarySearchHints.cmake | 11 +++++---- cmake/modules/FindGLM.cmake | 28 ++++++++++++++++++++++ interface/CMakeLists.txt | 1 + libraries/audio/CMakeLists.txt | 1 + libraries/avatars/CMakeLists.txt | 1 + libraries/entities-renderer/CMakeLists.txt | 1 + libraries/entities/CMakeLists.txt | 1 + libraries/environment/CMakeLists.txt | 1 + libraries/fbx/CMakeLists.txt | 1 + libraries/metavoxels/CMakeLists.txt | 1 + libraries/model/CMakeLists.txt | 1 + libraries/octree/CMakeLists.txt | 1 + libraries/physics/CMakeLists.txt | 1 + libraries/render-utils/CMakeLists.txt | 1 + libraries/script-engine/CMakeLists.txt | 1 + tests/physics/CMakeLists.txt | 1 + 18 files changed, 50 insertions(+), 5 deletions(-) create mode 100644 cmake/modules/FindGLM.cmake diff --git a/assignment-client/CMakeLists.txt b/assignment-client/CMakeLists.txt index d8d2d44090..b16314811b 100644 --- a/assignment-client/CMakeLists.txt +++ b/assignment-client/CMakeLists.txt @@ -3,6 +3,7 @@ set(TARGET_NAME assignment-client) setup_hifi_project(Core Gui Network Script Widgets) add_dependency_external_project(glm) +find_package(GLM REQUIRED) target_include_directories(${TARGET_NAME} PRIVATE ${GLM_INCLUDE_DIRS}) # link in the shared libraries diff --git a/cmake/externals/glm/CMakeLists.txt b/cmake/externals/glm/CMakeLists.txt index 6246993df5..a3b64b9370 100644 --- a/cmake/externals/glm/CMakeLists.txt +++ b/cmake/externals/glm/CMakeLists.txt @@ -1,6 +1,7 @@ include(ExternalProject) ExternalProject_Add( glm + PREFIX glm URL https://github.com/g-truc/glm/archive/0.9.5.4.zip CMAKE_ARGS -DCMAKE_INSTALL_PREFIX:PATH= LOG_DOWNLOAD ON diff --git a/cmake/macros/HifiLibrarySearchHints.cmake b/cmake/macros/HifiLibrarySearchHints.cmake index e22b442beb..e4b67af15e 100644 --- a/cmake/macros/HifiLibrarySearchHints.cmake +++ b/cmake/macros/HifiLibrarySearchHints.cmake @@ -10,22 +10,23 @@ macro(HIFI_LIBRARY_SEARCH_HINTS LIBRARY_FOLDER) string(TOUPPER ${LIBRARY_FOLDER} LIBRARY_PREFIX) - set(${LIBRARY_PREFIX}_SEARCH_DIRS "") + + set(${LIBRARY_PREFIX}_SEARCH_DIRS "${EXTERNAL_PROJECT_DIR}/${LIBRARY_FOLDER}/build/${LIBRARY_FOLDER}") if (${LIBRARY_PREFIX}_ROOT_DIR) - set(${LIBRARY_PREFIX}_SEARCH_DIRS "${${LIBRARY_PREFIX}_ROOT_DIR}") + list(APPEND ${LIBRARY_PREFIX}_SEARCH_DIRS "${${LIBRARY_PREFIX}_ROOT_DIR}") endif () if (ANDROID) - set(${LIBRARY_PREFIX}_SEARCH_DIRS "${${LIBRARY_PREFIX}_SEARCH_DIRS}" "/${LIBRARY_FOLDER}") + list(APPEND ${LIBRARY_PREFIX}_SEARCH_DIRS "/${LIBRARY_FOLDER}") endif () if (DEFINED ENV{${LIBRARY_PREFIX}_ROOT_DIR}) - set(${LIBRARY_PREFIX}_SEARCH_DIRS "${${LIBRARY_PREFIX}_SEARCH_DIRS}" "$ENV{${LIBRARY_PREFIX}_ROOT_DIR}") + list(APPEND ${LIBRARY_PREFIX}_SEARCH_DIRS "$ENV{${LIBRARY_PREFIX}_ROOT_DIR}") endif () if (DEFINED ENV{HIFI_LIB_DIR}) - set(${LIBRARY_PREFIX}_SEARCH_DIRS "${${LIBRARY_PREFIX}_SEARCH_DIRS}" "$ENV{HIFI_LIB_DIR}/${LIBRARY_FOLDER}") + list(APPEND ${LIBRARY_PREFIX}_SEARCH_DIRS "$ENV{HIFI_LIB_DIR}/${LIBRARY_FOLDER}") endif () endmacro(HIFI_LIBRARY_SEARCH_HINTS _library_folder) \ No newline at end of file diff --git a/cmake/modules/FindGLM.cmake b/cmake/modules/FindGLM.cmake new file mode 100644 index 0000000000..a75730b238 --- /dev/null +++ b/cmake/modules/FindGLM.cmake @@ -0,0 +1,28 @@ +# +# FindGLM.cmake +# +# Try to find GLM include path. +# Once done this will define +# +# GLM_INCLUDE_DIRS +# +# Created on 7/17/2014 by Stephen Birarda +# 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 +# + +# setup hints for GLM search +include("${MACRO_DIR}/HifiLibrarySearchHints.cmake") +hifi_library_search_hints("glm") + +# locate header +find_path(GLM_INCLUDE_DIR "glm/glm.hpp" HINTS ${GLM_SEARCH_DIRS}) + +set(GLM_INCLUDE_DIRS "${GLM_INCLUDE_DIR}") + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(GLM DEFAULT_MSG GLM_INCLUDE_DIRS) + +mark_as_advanced(GLM_INCLUDE_DIRS GLM_SEARCH_DIRS) \ No newline at end of file diff --git a/interface/CMakeLists.txt b/interface/CMakeLists.txt index 2be9f7bee2..7d581284e5 100644 --- a/interface/CMakeLists.txt +++ b/interface/CMakeLists.txt @@ -109,6 +109,7 @@ add_executable(${TARGET_NAME} MACOSX_BUNDLE ${INTERFACE_SRCS} ${QM}) # set up the external glm library add_dependency_external_project(glm) +find_package(GLM REQUIRED) target_include_directories(${TARGET_NAME} PRIVATE ${GLM_INCLUDE_DIRS}) # link required hifi libraries diff --git a/libraries/audio/CMakeLists.txt b/libraries/audio/CMakeLists.txt index c44198ddef..6ec35e00fc 100644 --- a/libraries/audio/CMakeLists.txt +++ b/libraries/audio/CMakeLists.txt @@ -4,6 +4,7 @@ set(TARGET_NAME audio) setup_hifi_library(Network) add_dependency_external_project(glm) +find_package(GLM REQUIRED) target_include_directories(${TARGET_NAME} PUBLIC ${GLM_INCLUDE_DIRS}) link_hifi_libraries(networking shared) diff --git a/libraries/avatars/CMakeLists.txt b/libraries/avatars/CMakeLists.txt index c227e057e3..bb4b8fdde0 100644 --- a/libraries/avatars/CMakeLists.txt +++ b/libraries/avatars/CMakeLists.txt @@ -4,6 +4,7 @@ set(TARGET_NAME avatars) setup_hifi_library(Network Script) add_dependency_external_project(glm) +find_package(GLM REQUIRED) target_include_directories(${TARGET_NAME} PUBLIC ${GLM_INCLUDE_DIRS}) link_hifi_libraries(audio shared networking) diff --git a/libraries/entities-renderer/CMakeLists.txt b/libraries/entities-renderer/CMakeLists.txt index 46d6b8a462..e706b07538 100644 --- a/libraries/entities-renderer/CMakeLists.txt +++ b/libraries/entities-renderer/CMakeLists.txt @@ -4,6 +4,7 @@ set(TARGET_NAME entities-renderer) setup_hifi_library(Widgets OpenGL Network Script) add_dependency_external_project(glm) +find_package(GLM REQUIRED) target_include_directories(${TARGET_NAME} PUBLIC ${GLM_INCLUDE_DIRS}) link_hifi_libraries(shared gpu script-engine render-utils) diff --git a/libraries/entities/CMakeLists.txt b/libraries/entities/CMakeLists.txt index 8846dbfb89..d0c39cac84 100644 --- a/libraries/entities/CMakeLists.txt +++ b/libraries/entities/CMakeLists.txt @@ -4,6 +4,7 @@ set(TARGET_NAME entities) setup_hifi_library(Network Script) add_dependency_external_project(glm) +find_package(GLM REQUIRED) target_include_directories(${TARGET_NAME} PUBLIC ${GLM_INCLUDE_DIRS}) include_bullet() diff --git a/libraries/environment/CMakeLists.txt b/libraries/environment/CMakeLists.txt index 7cd91823d3..e5e7b80701 100644 --- a/libraries/environment/CMakeLists.txt +++ b/libraries/environment/CMakeLists.txt @@ -4,6 +4,7 @@ set(TARGET_NAME environment) setup_hifi_library() add_dependency_external_project(glm) +find_package(GLM REQUIRED) target_include_directories(${TARGET_NAME} PUBLIC ${GLM_INCLUDE_DIRS}) link_hifi_libraries(shared networking) diff --git a/libraries/fbx/CMakeLists.txt b/libraries/fbx/CMakeLists.txt index 7e28f63fc9..da6d471c72 100644 --- a/libraries/fbx/CMakeLists.txt +++ b/libraries/fbx/CMakeLists.txt @@ -4,6 +4,7 @@ set(TARGET_NAME fbx) setup_hifi_library() add_dependency_external_project(glm) +find_package(GLM REQUIRED) target_include_directories(${TARGET_NAME} PUBLIC ${GLM_INCLUDE_DIRS}) link_hifi_libraries(shared gpu model networking octree) diff --git a/libraries/metavoxels/CMakeLists.txt b/libraries/metavoxels/CMakeLists.txt index 6143bce2dc..593ee800a7 100644 --- a/libraries/metavoxels/CMakeLists.txt +++ b/libraries/metavoxels/CMakeLists.txt @@ -9,6 +9,7 @@ setup_hifi_library(Network Script Widgets) link_hifi_libraries(shared networking) add_dependency_external_project(glm) +find_package(GLM REQUIRED) target_include_directories(${TARGET_NAME} PUBLIC ${GLM_INCLUDE_DIRS}) # call macro to include our dependency includes and bubble them up via a property on our target diff --git a/libraries/model/CMakeLists.txt b/libraries/model/CMakeLists.txt index 6d729ea58c..0f71a25047 100755 --- a/libraries/model/CMakeLists.txt +++ b/libraries/model/CMakeLists.txt @@ -4,6 +4,7 @@ set(TARGET_NAME model) setup_hifi_library() add_dependency_external_project(glm) +find_package(GLM REQUIRED) target_include_directories(${TARGET_NAME} PUBLIC ${GLM_INCLUDE_DIRS}) link_hifi_libraries(shared gpu) diff --git a/libraries/octree/CMakeLists.txt b/libraries/octree/CMakeLists.txt index c55f3bae89..3c7e8e7749 100644 --- a/libraries/octree/CMakeLists.txt +++ b/libraries/octree/CMakeLists.txt @@ -4,6 +4,7 @@ set(TARGET_NAME octree) setup_hifi_library() add_dependency_external_project(glm) +find_package(GLM REQUIRED) target_include_directories(${TARGET_NAME} PUBLIC ${GLM_INCLUDE_DIRS}) link_hifi_libraries(shared networking) diff --git a/libraries/physics/CMakeLists.txt b/libraries/physics/CMakeLists.txt index 8b48501458..7fc3f82496 100644 --- a/libraries/physics/CMakeLists.txt +++ b/libraries/physics/CMakeLists.txt @@ -4,6 +4,7 @@ set(TARGET_NAME physics) setup_hifi_library() add_dependency_external_project(glm) +find_package(GLM REQUIRED) target_include_directories(${TARGET_NAME} PUBLIC ${GLM_INCLUDE_DIRS}) include_bullet() diff --git a/libraries/render-utils/CMakeLists.txt b/libraries/render-utils/CMakeLists.txt index 0bf7e91951..054b30d7fb 100644 --- a/libraries/render-utils/CMakeLists.txt +++ b/libraries/render-utils/CMakeLists.txt @@ -9,6 +9,7 @@ qt5_add_resources(QT_RESOURCES_FILE "${CMAKE_CURRENT_SOURCE_DIR}/res/fonts/fonts setup_hifi_library(Widgets OpenGL Network Script) add_dependency_external_project(glm) +find_package(GLM REQUIRED) target_include_directories(${TARGET_NAME} PUBLIC ${GLM_INCLUDE_DIRS}) link_hifi_libraries(animation fbx shared gpu) diff --git a/libraries/script-engine/CMakeLists.txt b/libraries/script-engine/CMakeLists.txt index 2c325e4daf..4e13ddf513 100644 --- a/libraries/script-engine/CMakeLists.txt +++ b/libraries/script-engine/CMakeLists.txt @@ -4,6 +4,7 @@ set(TARGET_NAME script-engine) setup_hifi_library(Gui Network Script Widgets) add_dependency_external_project(glm) +find_package(GLM REQUIRED) target_include_directories(${TARGET_NAME} PUBLIC ${GLM_INCLUDE_DIRS}) link_hifi_libraries(shared octree gpu model fbx entities animation audio physics metavoxels) diff --git a/tests/physics/CMakeLists.txt b/tests/physics/CMakeLists.txt index 89fba47bea..e20f323392 100644 --- a/tests/physics/CMakeLists.txt +++ b/tests/physics/CMakeLists.txt @@ -3,6 +3,7 @@ set(TARGET_NAME physics-tests) setup_hifi_project() add_dependency_external_project(glm) +find_package(GLM REQUIRED) target_include_directories(${TARGET_NAME} PUBLIC ${GLM_INCLUDE_DIRS}) include_bullet() From 6e63c1c1ad2e26e976cd9585b071d10c01b32b53 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Fri, 13 Feb 2015 14:50:12 -0800 Subject: [PATCH 61/77] set the GLM_INCLUDE_DIRS var in cache so find hits it --- cmake/externals/glm/CMakeLists.txt | 12 ++++++++---- cmake/macros/AddDependencyExternalProject.cmake | 3 --- cmake/modules/FindGLM.cmake | 4 +--- libraries/shared/CMakeLists.txt | 4 ++++ 4 files changed, 13 insertions(+), 10 deletions(-) diff --git a/cmake/externals/glm/CMakeLists.txt b/cmake/externals/glm/CMakeLists.txt index a3b64b9370..8bf597ecc3 100644 --- a/cmake/externals/glm/CMakeLists.txt +++ b/cmake/externals/glm/CMakeLists.txt @@ -1,11 +1,15 @@ +set(EXTERNAL_NAME glm) + include(ExternalProject) ExternalProject_Add( - glm - PREFIX glm + ${EXTERNAL_NAME} + PREFIX ${EXTERNAL_NAME} URL https://github.com/g-truc/glm/archive/0.9.5.4.zip CMAKE_ARGS -DCMAKE_INSTALL_PREFIX:PATH= LOG_DOWNLOAD ON ) -ExternalProject_Get_Property(glm install_dir) -export(TARGETS glm FILE ${CMAKE_BINARY_DIR}/glm-config.cmake) \ No newline at end of file +ExternalProject_Get_Property(${EXTERNAL_NAME} install_dir) + +string(TOUPPER ${EXTERNAL_NAME} EXTERNAL_NAME_UPPER) +set(${EXTERNAL_NAME_UPPER}_INCLUDE_DIRS ${install_dir}/include CACHE TYPE STRING) \ No newline at end of file diff --git a/cmake/macros/AddDependencyExternalProject.cmake b/cmake/macros/AddDependencyExternalProject.cmake index c4c2c0d005..71c32e5e69 100644 --- a/cmake/macros/AddDependencyExternalProject.cmake +++ b/cmake/macros/AddDependencyExternalProject.cmake @@ -21,8 +21,5 @@ macro(ADD_DEPENDENCY_EXTERNAL_PROJECT _PROJ_NAME) add_subdirectory(${EXTERNAL_PROJECT_DIR}/${_PROJ_NAME} ${_PROJ_BINARY_DIR}) endif () - string(TOUPPER ${_PROJ_NAME} _PROJ_NAME_UPPER) - get_target_property(${_PROJ_NAME_UPPER}_INCLUDE_DIRS ${_PROJ_NAME} INCLUDE_DIRS) - add_dependencies(${TARGET_NAME} ${_PROJ_NAME}) endmacro() \ No newline at end of file diff --git a/cmake/modules/FindGLM.cmake b/cmake/modules/FindGLM.cmake index a75730b238..ace7360ea7 100644 --- a/cmake/modules/FindGLM.cmake +++ b/cmake/modules/FindGLM.cmake @@ -18,9 +18,7 @@ include("${MACRO_DIR}/HifiLibrarySearchHints.cmake") hifi_library_search_hints("glm") # locate header -find_path(GLM_INCLUDE_DIR "glm/glm.hpp" HINTS ${GLM_SEARCH_DIRS}) - -set(GLM_INCLUDE_DIRS "${GLM_INCLUDE_DIR}") +find_path(GLM_INCLUDE_DIRS "glm/glm.hpp" HINTS ${GLM_SEARCH_DIRS}) include(FindPackageHandleStandardArgs) find_package_handle_standard_args(GLM DEFAULT_MSG GLM_INCLUDE_DIRS) diff --git a/libraries/shared/CMakeLists.txt b/libraries/shared/CMakeLists.txt index 0bbb39fdb5..5af2343ec2 100644 --- a/libraries/shared/CMakeLists.txt +++ b/libraries/shared/CMakeLists.txt @@ -4,5 +4,9 @@ set(TARGET_NAME shared) # TODO: there isn't really a good reason to have Script linked here - let's get what is requiring it out (RegisteredMetaTypes.cpp) setup_hifi_library(Gui Network Script Widgets) +add_dependency_external_project(glm) +find_package(GLM REQUIRED) +target_include_directories(${TARGET_NAME} PRIVATE ${GLM_INCLUDE_DIRS}) + # call macro to include our dependency includes and bubble them up via a property on our target include_dependency_includes() \ No newline at end of file From ab0692229d7952ab359cfe824a2ee49efdfb9d28 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Fri, 13 Feb 2015 14:54:21 -0800 Subject: [PATCH 62/77] fix GLM includes for gvr-interface and shared --- gvr-interface/CMakeLists.txt | 3 ++- libraries/shared/CMakeLists.txt | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/gvr-interface/CMakeLists.txt b/gvr-interface/CMakeLists.txt index 68eeb86791..de0b66165b 100644 --- a/gvr-interface/CMakeLists.txt +++ b/gvr-interface/CMakeLists.txt @@ -25,7 +25,8 @@ endif () include_directories(${Qt5Gui_PRIVATE_INCLUDE_DIRS}) add_dependency_external_project(glm) -target_link_libraries(${TARGET_NAME} PRIVATE ${GLM_INCLUDE_DIRS}) +find_package(GLM REQUIRED) +target_include_directories(${TARGET_NAME} PRIVATE ${GLM_INCLUDE_DIRS}) link_hifi_libraries(shared networking audio-client avatars) include_dependency_includes() diff --git a/libraries/shared/CMakeLists.txt b/libraries/shared/CMakeLists.txt index 5af2343ec2..54cd91deaf 100644 --- a/libraries/shared/CMakeLists.txt +++ b/libraries/shared/CMakeLists.txt @@ -6,7 +6,7 @@ setup_hifi_library(Gui Network Script Widgets) add_dependency_external_project(glm) find_package(GLM REQUIRED) -target_include_directories(${TARGET_NAME} PRIVATE ${GLM_INCLUDE_DIRS}) +target_include_directories(${TARGET_NAME} PUBLIC ${GLM_INCLUDE_DIRS}) # call macro to include our dependency includes and bubble them up via a property on our target include_dependency_includes() \ No newline at end of file From 430083681019cdb7cc785a1ff142a4a1ee36fb59 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Fri, 13 Feb 2015 15:47:35 -0800 Subject: [PATCH 63/77] make gverb a cmake external project --- cmake/externals/glm/CMakeLists.txt | 4 +-- cmake/externals/gverb/CMakeLists.txt | 16 ++++++++++++ cmake/modules/FindGverb.cmake | 26 +++++-------------- libraries/audio-client/CMakeLists.txt | 12 +++------ .../audio-client/external/gverb/readme.txt | 14 ---------- libraries/audio-client/src/AudioClient.cpp | 5 ++++ libraries/audio-client/src/AudioClient.h | 6 ++--- 7 files changed, 35 insertions(+), 48 deletions(-) create mode 100644 cmake/externals/gverb/CMakeLists.txt delete mode 100644 libraries/audio-client/external/gverb/readme.txt diff --git a/cmake/externals/glm/CMakeLists.txt b/cmake/externals/glm/CMakeLists.txt index 8bf597ecc3..928603ecd2 100644 --- a/cmake/externals/glm/CMakeLists.txt +++ b/cmake/externals/glm/CMakeLists.txt @@ -9,7 +9,7 @@ ExternalProject_Add( LOG_DOWNLOAD ON ) -ExternalProject_Get_Property(${EXTERNAL_NAME} install_dir) +ExternalProject_Get_Property(${EXTERNAL_NAME} INSTALL_DIR) string(TOUPPER ${EXTERNAL_NAME} EXTERNAL_NAME_UPPER) -set(${EXTERNAL_NAME_UPPER}_INCLUDE_DIRS ${install_dir}/include CACHE TYPE STRING) \ No newline at end of file +set(${EXTERNAL_NAME_UPPER}_INCLUDE_DIRS ${INSTALL_DIR}/include CACHE TYPE STRING) \ No newline at end of file diff --git a/cmake/externals/gverb/CMakeLists.txt b/cmake/externals/gverb/CMakeLists.txt new file mode 100644 index 0000000000..1954df703e --- /dev/null +++ b/cmake/externals/gverb/CMakeLists.txt @@ -0,0 +1,16 @@ +set(EXTERNAL_NAME gverb) + +include(ExternalProject) +ExternalProject_Add( + ${EXTERNAL_NAME} + PREFIX ${EXTERNAL_NAME} + GIT_REPOSITORY https://github.com/birarda/gverb.git + CMAKE_ARGS -DCMAKE_INSTALL_PREFIX:PATH= + LOG_DOWNLOAD ON +) + +ExternalProject_Get_Property(${EXTERNAL_NAME} INSTALL_DIR) + +string(TOUPPER ${EXTERNAL_NAME} EXTERNAL_NAME_UPPER) +set(${EXTERNAL_NAME_UPPER}_INCLUDE_DIRS ${INSTALL_DIR}/include CACHE TYPE STRING) +set(${EXTERNAL_NAME_UPPER}_LIBRARIES ${INSTALL_DIR}/lib/libgverb.a CACHE TYPE STRING) \ No newline at end of file diff --git a/cmake/modules/FindGverb.cmake b/cmake/modules/FindGverb.cmake index d4d2377c94..7dc233333c 100644 --- a/cmake/modules/FindGverb.cmake +++ b/cmake/modules/FindGverb.cmake @@ -15,25 +15,11 @@ # See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html # -if (GVERB_INCLUDE_DIRS) - # in cache already - set(GVERB_FOUND TRUE) -else (GVERB_INCLUDE_DIRS) +include("${MACRO_DIR}/HifiLibrarySearchHints.cmake") +hifi_library_search_hints("gverb") - include("${MACRO_DIR}/HifiLibrarySearchHints.cmake") - hifi_library_search_hints("gverb") +find_path(GVERB_INCLUDE_DIRS gverb.h PATH_SUFFIXES include HINTS ${GVERB_SEARCH_DIRS}) +find_path(GVERB_LIBRARIES gverb PATH_SUFFIXES lib HINTS ${GVERB_SEARCH_DIRS}) - find_path(GVERB_INCLUDE_DIRS gverb.h PATH_SUFFIXES include HINTS ${GVERB_SEARCH_DIRS} NO_CMAKE_FIND_ROOT_PATH) - find_path(GVERB_SRC_DIRS gverb.c PATH_SUFFIXES src HINTS ${GVERB_SEARCH_DIRS} NO_CMAKE_FIND_ROOT_PATH) - - if (GVERB_INCLUDE_DIRS) - set(GVERB_FOUND TRUE) - endif (GVERB_INCLUDE_DIRS) - - if (GVERB_FOUND) - message(STATUS "Found Gverb: ${GVERB_INCLUDE_DIRS}") - else (GVERB_FOUND) - message(FATAL_ERROR "Could NOT find Gverb. Read ./libraries/audio-client/externals/gverb/readme.txt") - endif (GVERB_FOUND) - -endif(GVERB_INCLUDE_DIRS) \ No newline at end of file +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(GVERB DEFAULT_MSG GVERB_INCLUDE_DIRS GVERB_LIBRARIES) \ No newline at end of file diff --git a/libraries/audio-client/CMakeLists.txt b/libraries/audio-client/CMakeLists.txt index 5477be3bc5..1cd76cf2f5 100644 --- a/libraries/audio-client/CMakeLists.txt +++ b/libraries/audio-client/CMakeLists.txt @@ -8,17 +8,13 @@ link_hifi_libraries(audio) # append audio includes to our list of includes to bubble list(APPEND ${TARGET_NAME}_DEPENDENCY_INCLUDES "${HIFI_LIBRARY_DIR}/audio/src") -set(GVERB_ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/external/gverb") +# have CMake grab Gverb from git and then set up linking and directory include +add_dependency_external_project(gverb) -# As Gverb is currently the only reverb library, it's required. find_package(Gverb REQUIRED) -file(GLOB GVERB_SRCS ${GVERB_SRC_DIRS}/*.c) -add_library(gverb STATIC ${GVERB_SRCS}) -target_link_libraries(${TARGET_NAME} gverb) - -# append gverb includes to our list of includes to bubble -list(APPEND ${TARGET_NAME}_DEPENDENCY_INCLUDES "${GVERB_INCLUDE_DIRS}") +target_link_libraries(${TARGET_NAME} ${GVERB_LIBRARIES}) +target_include_directories(${TARGET_NAME} PRIVATE ${GVERB_INCLUDE_DIRS}) # we use libsoxr for resampling find_package(Soxr REQUIRED) diff --git a/libraries/audio-client/external/gverb/readme.txt b/libraries/audio-client/external/gverb/readme.txt deleted file mode 100644 index bb01e48a74..0000000000 --- a/libraries/audio-client/external/gverb/readme.txt +++ /dev/null @@ -1,14 +0,0 @@ -Instructions for adding the Gverb library to audio-client -(This is a required library) -Clément Brisset, October 22nd, 2014 - -1. Go to https://github.com/highfidelity/gverb - Or download the sources directly via this link: - https://github.com/highfidelity/gverb/archive/master.zip - -2. Extract the archive - -3. Place the directories “include” and “src” in libraries/audio-client/external/gverb - (Normally next to this readme) - -4. Clear your build directory, run cmake, build and you should be all set. diff --git a/libraries/audio-client/src/AudioClient.cpp b/libraries/audio-client/src/AudioClient.cpp index 1919f2bbe5..391d6aaf40 100644 --- a/libraries/audio-client/src/AudioClient.cpp +++ b/libraries/audio-client/src/AudioClient.cpp @@ -33,6 +33,11 @@ #include #include +extern "C" { + #include + #include +} + #include #include diff --git a/libraries/audio-client/src/AudioClient.h b/libraries/audio-client/src/AudioClient.h index e55a116e06..dc4e16d81b 100644 --- a/libraries/audio-client/src/AudioClient.h +++ b/libraries/audio-client/src/AudioClient.h @@ -47,10 +47,7 @@ #pragma warning( disable : 4273 ) #pragma warning( disable : 4305 ) #endif -extern "C" { - #include - #include -} + #ifdef _WIN32 #pragma warning( pop ) #endif @@ -68,6 +65,7 @@ class QAudioInput; class QAudioOutput; class QIODevice; struct soxr; +typedef struct ty_gverb ty_gverb; typedef glm::vec3 (*AudioPositionGetter)(); typedef glm::quat (*AudioOrientationGetter)(); From 48e7aa74330135185ffcd49a4f9bb2444487d0b2 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Fri, 13 Feb 2015 16:06:30 -0800 Subject: [PATCH 64/77] handle android build of gverb for external project --- cmake/externals/gverb/CMakeLists.txt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/cmake/externals/gverb/CMakeLists.txt b/cmake/externals/gverb/CMakeLists.txt index 1954df703e..373089eb2d 100644 --- a/cmake/externals/gverb/CMakeLists.txt +++ b/cmake/externals/gverb/CMakeLists.txt @@ -1,11 +1,15 @@ set(EXTERNAL_NAME gverb) +if (ANDROID) + set(ANDROID_CMAKE_ARGS "-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}" "-DANDROID_NATIVE_API_LEVEL=19") +endif () + include(ExternalProject) ExternalProject_Add( ${EXTERNAL_NAME} PREFIX ${EXTERNAL_NAME} GIT_REPOSITORY https://github.com/birarda/gverb.git - CMAKE_ARGS -DCMAKE_INSTALL_PREFIX:PATH= + CMAKE_ARGS ${ANDROID_CMAKE_ARGS} -DCMAKE_INSTALL_PREFIX:PATH= LOG_DOWNLOAD ON ) From d337cadb106f8787ac40f1afe8b0c50fd023e3c4 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Fri, 13 Feb 2015 16:12:03 -0800 Subject: [PATCH 65/77] add gverb to list of auto-deps --- BUILD.md | 1 + 1 file changed, 1 insertion(+) diff --git a/BUILD.md b/BUILD.md index 3065254529..f7dc22882a 100644 --- a/BUILD.md +++ b/BUILD.md @@ -14,6 +14,7 @@ The following dependencies will be downloaded, built, linked and included automatically by CMake where we require them. The CMakeLists files that handle grabbing each of the following external dependencies can be found in the [cmake/externals folder](cmake/externals). The resulting downloads, source files and binaries will be placed in the `build` directory in each of the subfolders for each external project. These are not placed in your normal build tree when doing an out of source build so that they do not need to be re-downloaded and re-compiled every time the CMake build folder is cleared. * [glm](http://glm.g-truc.net/0.9.5/index.html) ~> 0.9.5.4 +* [gverb](https://github.com/highfidelity/gverb) ### OS Specific Build Guides * [BUILD_OSX.md](BUILD_OSX.md) - additional instructions for OS X. From 691cf2d893ba783a589615b996aef751eb192f78 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Fri, 13 Feb 2015 16:12:47 -0800 Subject: [PATCH 66/77] remove gverb from win build guide --- BUILD_WIN.md | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/BUILD_WIN.md b/BUILD_WIN.md index ebc0b60f25..6f26e8c809 100644 --- a/BUILD_WIN.md +++ b/BUILD_WIN.md @@ -126,20 +126,6 @@ Download the binary package: `glew-1.10.0-win32.zip`. Extract to %HIFI_LIB_DIR%\ Add to the PATH: `%HIFI_LIB_DIR%\glew\bin\Release\Win32` -###Gverb - -1. Go to https://github.com/highfidelity/gverb - Or download the sources directly via this link: - https://github.com/highfidelity/gverb/archive/master.zip - -2. Extract the archive - -3. Place the directories “include” and “src” in interface/external/gverb - (Normally next to this readme) - -4. Clear your build directory, run cmake, build and you should be all set. - - ###Bullet Bullet 2.82 source can be [downloaded here](https://code.google.com/p/bullet/downloads/detail?name=bullet-2.82-r2704.zip). Bullet does not come with prebuilt libraries, you need to make those yourself. From 28fabcb7884670eb3c562de570c9ca68130431cf Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Fri, 13 Feb 2015 16:17:45 -0800 Subject: [PATCH 67/77] avoid ubuntu libssl error by using http links --- cmake/externals/glm/CMakeLists.txt | 2 +- cmake/externals/gverb/CMakeLists.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cmake/externals/glm/CMakeLists.txt b/cmake/externals/glm/CMakeLists.txt index 928603ecd2..4c9745af9f 100644 --- a/cmake/externals/glm/CMakeLists.txt +++ b/cmake/externals/glm/CMakeLists.txt @@ -4,7 +4,7 @@ include(ExternalProject) ExternalProject_Add( ${EXTERNAL_NAME} PREFIX ${EXTERNAL_NAME} - URL https://github.com/g-truc/glm/archive/0.9.5.4.zip + URL http://github.com/g-truc/glm/archive/0.9.5.4.zip CMAKE_ARGS -DCMAKE_INSTALL_PREFIX:PATH= LOG_DOWNLOAD ON ) diff --git a/cmake/externals/gverb/CMakeLists.txt b/cmake/externals/gverb/CMakeLists.txt index 373089eb2d..bd461d349e 100644 --- a/cmake/externals/gverb/CMakeLists.txt +++ b/cmake/externals/gverb/CMakeLists.txt @@ -8,7 +8,7 @@ include(ExternalProject) ExternalProject_Add( ${EXTERNAL_NAME} PREFIX ${EXTERNAL_NAME} - GIT_REPOSITORY https://github.com/birarda/gverb.git + GIT_REPOSITORY http://github.com/birarda/gverb.git CMAKE_ARGS ${ANDROID_CMAKE_ARGS} -DCMAKE_INSTALL_PREFIX:PATH= LOG_DOWNLOAD ON ) From 018b8497bddee1b64a8196975e492d0131221ff5 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Fri, 13 Feb 2015 16:21:19 -0800 Subject: [PATCH 68/77] use non-redirecting glm link to avoid https error --- cmake/externals/glm/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/externals/glm/CMakeLists.txt b/cmake/externals/glm/CMakeLists.txt index 4c9745af9f..b1aed7dd7f 100644 --- a/cmake/externals/glm/CMakeLists.txt +++ b/cmake/externals/glm/CMakeLists.txt @@ -4,7 +4,7 @@ include(ExternalProject) ExternalProject_Add( ${EXTERNAL_NAME} PREFIX ${EXTERNAL_NAME} - URL http://github.com/g-truc/glm/archive/0.9.5.4.zip + URL http://pkgs.fedoraproject.org/repo/pkgs/glm/glm-0.9.5.4.zip/fab76fc982b256b46208e5c750ed456a/glm-0.9.5.4.zip CMAKE_ARGS -DCMAKE_INSTALL_PREFIX:PATH= LOG_DOWNLOAD ON ) From 9683ed92e321cdec5b7607a03f0bf08dd1753fd5 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Fri, 13 Feb 2015 16:40:48 -0800 Subject: [PATCH 69/77] use proper lib path on WIN32 for gverb --- cmake/externals/gverb/CMakeLists.txt | 9 +++++++-- cmake/modules/FindGverb.cmake | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/cmake/externals/gverb/CMakeLists.txt b/cmake/externals/gverb/CMakeLists.txt index bd461d349e..19a44781b1 100644 --- a/cmake/externals/gverb/CMakeLists.txt +++ b/cmake/externals/gverb/CMakeLists.txt @@ -8,7 +8,7 @@ include(ExternalProject) ExternalProject_Add( ${EXTERNAL_NAME} PREFIX ${EXTERNAL_NAME} - GIT_REPOSITORY http://github.com/birarda/gverb.git + GIT_REPOSITORY https://github.com/birarda/gverb.git CMAKE_ARGS ${ANDROID_CMAKE_ARGS} -DCMAKE_INSTALL_PREFIX:PATH= LOG_DOWNLOAD ON ) @@ -17,4 +17,9 @@ ExternalProject_Get_Property(${EXTERNAL_NAME} INSTALL_DIR) string(TOUPPER ${EXTERNAL_NAME} EXTERNAL_NAME_UPPER) set(${EXTERNAL_NAME_UPPER}_INCLUDE_DIRS ${INSTALL_DIR}/include CACHE TYPE STRING) -set(${EXTERNAL_NAME_UPPER}_LIBRARIES ${INSTALL_DIR}/lib/libgverb.a CACHE TYPE STRING) \ No newline at end of file + +if (WIN32) + set(${EXTERNAL_NAME_UPPER}_LIBRARIES ${INSTALL_DIR}/lib/gverb.lib CACHE TYPE STRING) +else () + set(${EXTERNAL_NAME_UPPER}_LIBRARIES ${INSTALL_DIR}/lib/libgverb.a CACHE TYPE STRING) +endif () \ No newline at end of file diff --git a/cmake/modules/FindGverb.cmake b/cmake/modules/FindGverb.cmake index 7dc233333c..e54fba8083 100644 --- a/cmake/modules/FindGverb.cmake +++ b/cmake/modules/FindGverb.cmake @@ -19,7 +19,7 @@ include("${MACRO_DIR}/HifiLibrarySearchHints.cmake") hifi_library_search_hints("gverb") find_path(GVERB_INCLUDE_DIRS gverb.h PATH_SUFFIXES include HINTS ${GVERB_SEARCH_DIRS}) -find_path(GVERB_LIBRARIES gverb PATH_SUFFIXES lib HINTS ${GVERB_SEARCH_DIRS}) +find_library(GVERB_LIBRARIES gverb PATH_SUFFIXES lib HINTS ${GVERB_SEARCH_DIRS}) include(FindPackageHandleStandardArgs) find_package_handle_standard_args(GVERB DEFAULT_MSG GVERB_INCLUDE_DIRS GVERB_LIBRARIES) \ No newline at end of file From a1bf06f004406a3800c76e1d1e65d848993cbd5d Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Mon, 16 Feb 2015 09:10:18 -0800 Subject: [PATCH 70/77] can't use find module for external proj --- cmake/macros/HifiLibrarySearchHints.cmake | 2 -- 1 file changed, 2 deletions(-) diff --git a/cmake/macros/HifiLibrarySearchHints.cmake b/cmake/macros/HifiLibrarySearchHints.cmake index e4b67af15e..2eed364a68 100644 --- a/cmake/macros/HifiLibrarySearchHints.cmake +++ b/cmake/macros/HifiLibrarySearchHints.cmake @@ -11,8 +11,6 @@ macro(HIFI_LIBRARY_SEARCH_HINTS LIBRARY_FOLDER) string(TOUPPER ${LIBRARY_FOLDER} LIBRARY_PREFIX) - set(${LIBRARY_PREFIX}_SEARCH_DIRS "${EXTERNAL_PROJECT_DIR}/${LIBRARY_FOLDER}/build/${LIBRARY_FOLDER}") - if (${LIBRARY_PREFIX}_ROOT_DIR) list(APPEND ${LIBRARY_PREFIX}_SEARCH_DIRS "${${LIBRARY_PREFIX}_ROOT_DIR}") endif () From feaad377514864c1b5347b532566923a66d32173 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Mon, 16 Feb 2015 09:38:53 -0800 Subject: [PATCH 71/77] add a GET_PROJ_NAME var to skip external projects --- .../macros/AddDependencyExternalProject.cmake | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/cmake/macros/AddDependencyExternalProject.cmake b/cmake/macros/AddDependencyExternalProject.cmake index 71c32e5e69..9e958b030b 100644 --- a/cmake/macros/AddDependencyExternalProject.cmake +++ b/cmake/macros/AddDependencyExternalProject.cmake @@ -10,16 +10,23 @@ # macro(ADD_DEPENDENCY_EXTERNAL_PROJECT _PROJ_NAME) - if (NOT TARGET ${_PROJ_NAME}) + + string(TOUPPER ${_PROJ_NAME} _PROJ_NAME_UPPER) + + if (NOT DEFINED GET_${_PROJ_NAME_UPPER} OR GET_${_PROJ_NAME_UPPER}) + if (NOT TARGET ${_PROJ_NAME}) - if (ANDROID) - set(_PROJ_BINARY_DIR ${EXTERNAL_PROJECT_DIR}/${_PROJ_NAME}/build/android) - else () - set(_PROJ_BINARY_DIR ${EXTERNAL_PROJECT_DIR}/${_PROJ_NAME}/build) + if (ANDROID) + set(_PROJ_BINARY_DIR ${EXTERNAL_PROJECT_DIR}/${_PROJ_NAME}/build/android) + else () + set(_PROJ_BINARY_DIR ${EXTERNAL_PROJECT_DIR}/${_PROJ_NAME}/build) + endif () + + add_subdirectory(${EXTERNAL_PROJECT_DIR}/${_PROJ_NAME} ${_PROJ_BINARY_DIR}) endif () + + add_dependencies(${TARGET_NAME} ${_PROJ_NAME}) - add_subdirectory(${EXTERNAL_PROJECT_DIR}/${_PROJ_NAME} ${_PROJ_BINARY_DIR}) endif () - add_dependencies(${TARGET_NAME} ${_PROJ_NAME}) endmacro() \ No newline at end of file From 20b0dee80c0d5b219c5f009ee1a01fec743f308e Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Mon, 16 Feb 2015 12:07:22 -0800 Subject: [PATCH 72/77] add a NULL initializer for the linked data create callback --- libraries/networking/src/LimitedNodeList.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/libraries/networking/src/LimitedNodeList.cpp b/libraries/networking/src/LimitedNodeList.cpp index 13bb2b1ad8..43f4dda565 100644 --- a/libraries/networking/src/LimitedNodeList.cpp +++ b/libraries/networking/src/LimitedNodeList.cpp @@ -39,6 +39,7 @@ const char SOLO_NODE_TYPES[2] = { const QUrl DEFAULT_NODE_AUTH_URL = QUrl("https://metaverse.highfidelity.io"); LimitedNodeList::LimitedNodeList(unsigned short socketListenPort, unsigned short dtlsListenPort) : + linkedDataCreateCallback(NULL), _sessionUUID(), _nodeHash(), _nodeMutex(QReadWriteLock::Recursive), From 42e4eee15e93db6797fbfacd443eeaab0f0c0c55 Mon Sep 17 00:00:00 2001 From: Thijs Wenker Date: Mon, 16 Feb 2015 23:14:27 +0100 Subject: [PATCH 73/77] audio meter background "back in black" / "paint it black" --- interface/src/ui/ApplicationOverlay.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/interface/src/ui/ApplicationOverlay.cpp b/interface/src/ui/ApplicationOverlay.cpp index f9437221e5..0805373ba6 100644 --- a/interface/src/ui/ApplicationOverlay.cpp +++ b/interface/src/ui/ApplicationOverlay.cpp @@ -789,7 +789,7 @@ void ApplicationOverlay::renderAudioMeter() { // Audio VU Meter and Mute Icon const int MUTE_ICON_SIZE = 24; const int MUTE_ICON_PADDING = 10; - const int AUDIO_METER_WIDTH = MIRROR_VIEW_WIDTH - MUTE_ICON_SIZE - MUTE_ICON_PADDING; + const int AUDIO_METER_WIDTH = MIRROR_VIEW_WIDTH - MUTE_ICON_SIZE - MUTE_ICON_PADDING; const int AUDIO_METER_SCALE_WIDTH = AUDIO_METER_WIDTH - 2 ; const int AUDIO_METER_HEIGHT = 8; const int AUDIO_METER_GAP = 5; @@ -845,8 +845,8 @@ void ApplicationOverlay::renderAudioMeter() { audioMeterY += AUDIO_METER_HEIGHT; // Draw audio meter background Quad - DependencyManager::get()->renderQuad(AUDIO_METER_X, audioMeterY, AUDIO_METER_WIDTH, AUDIO_METER_HEIGHT, - glm::vec4(0.298f, 0.757f, 0.722f, 1)); + DependencyManager::get()->renderQuad(AUDIO_METER_X, audioMeterY, AUDIO_METER_WIDTH, AUDIO_METER_HEIGHT, + glm::vec4(0.0f, 0.0f, 0.0f, 1.0f)); if (audioLevel > AUDIO_RED_START) { glm::vec4 quadColor; From 4a3550ce0e5d428ba5f4fcd5a9c5e91b8a3d69aa Mon Sep 17 00:00:00 2001 From: Thijs Wenker Date: Tue, 17 Feb 2015 02:27:07 +0100 Subject: [PATCH 74/77] toggleQAction(); in constructor to make the right initial button connection --- interface/src/ui/LoginDialog.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/interface/src/ui/LoginDialog.cpp b/interface/src/ui/LoginDialog.cpp index 049e5bd1cd..99b60fc232 100644 --- a/interface/src/ui/LoginDialog.cpp +++ b/interface/src/ui/LoginDialog.cpp @@ -41,6 +41,9 @@ LoginDialog::LoginDialog(QWidget* parent) : this, &LoginDialog::handleLoginClicked); connect(_ui->closeButton, &QPushButton::clicked, this, &LoginDialog::close); + + // Initialize toggle connection + toggleQAction(); }; LoginDialog::~LoginDialog() { From d1f7a730ad87610a19e9976b151e2919a7e791c2 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Tue, 17 Feb 2015 08:23:11 -0800 Subject: [PATCH 75/77] Make add-model button non-selectable --- examples/editEntities.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/editEntities.js b/examples/editEntities.js index c6ec5a7f0a..8dbf64a7ae 100644 --- a/examples/editEntities.js +++ b/examples/editEntities.js @@ -127,7 +127,7 @@ var toolBar = (function () { height: toolHeight, alpha: 0.9, visible: true - }, true, false); + }); browseModelsButton = toolBar.addTool({ imageURL: toolIconUrl + "list-icon.svg", From 97e70920cefe2775f55c6e295294bd404f16d61d Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Tue, 17 Feb 2015 08:23:39 -0800 Subject: [PATCH 76/77] Move handling of add model buttons to mouseRelease --- examples/editEntities.js | 48 +++++++++++++++++++++++++++++++--------- 1 file changed, 38 insertions(+), 10 deletions(-) diff --git a/examples/editEntities.js b/examples/editEntities.js index 8dbf64a7ae..61100b4556 100644 --- a/examples/editEntities.js +++ b/examples/editEntities.js @@ -262,6 +262,8 @@ var toolBar = (function () { toolBar.move(toolsX, toolsY); }; + var newModelButtonDown = false; + var browseModelsButtonDown = false; that.mousePressEvent = function (event) { var clickedOverlay, url, @@ -274,19 +276,14 @@ var toolBar = (function () { return true; } + // Handle these two buttons in the mouseRelease event handler so that we don't suppress a mouseRelease event from + // occurring when showing a modal dialog. if (newModelButton === toolBar.clicked(clickedOverlay)) { - url = Window.prompt("Model URL", modelURLs[Math.floor(Math.random() * modelURLs.length)]); - if (url !== null && url !== "") { - addModel(url); - } + newModelButtonDown = true; return true; } - if (browseModelsButton === toolBar.clicked(clickedOverlay)) { - url = Window.s3Browse(".*(fbx|FBX)"); - if (url !== null && url !== "") { - addModel(url); - } + browseModelsButtonDown = true; return true; } @@ -348,6 +345,7 @@ var toolBar = (function () { return true; } + if (newTextButton === toolBar.clicked(clickedOverlay)) { var position = Vec3.sum(MyAvatar.position, Vec3.multiply(Quat.getFront(MyAvatar.orientation), SPAWN_DISTANCE)); @@ -367,10 +365,37 @@ var toolBar = (function () { return true; } - return false; }; + that.mouseReleaseEvent = function(event) { + var handled = false; + if (newModelButtonDown) { + var clickedOverlay = Overlays.getOverlayAtPoint({ x: event.x, y: event.y }); + if (newModelButton === toolBar.clicked(clickedOverlay)) { + url = Window.prompt("Model URL", modelURLs[Math.floor(Math.random() * modelURLs.length)]); + if (url !== null && url !== "") { + addModel(url); + } + handled = true; + } + } else if (browseModelsButtonDown) { + var clickedOverlay = Overlays.getOverlayAtPoint({ x: event.x, y: event.y }); + if (browseModelsButton === toolBar.clicked(clickedOverlay)) { + url = Window.s3Browse(".*(fbx|FBX)"); + if (url !== null && url !== "") { + addModel(url); + } + handled = true; + } + } + + newModelButtonDown = false; + browseModelsButtonDown = false; + + return handled; + } + that.cleanup = function () { toolBar.cleanup(); }; @@ -533,6 +558,9 @@ function highlightEntityUnderCursor(position, accurateRay) { function mouseReleaseEvent(event) { + if (toolBar.mouseReleaseEvent(event)) { + return true; + } if (placingEntityID) { if (isActive) { selectionManager.setSelections([placingEntityID]); From d299f015d1f7e2e549cb14b869e34b5a4fe6a146 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Tue, 17 Feb 2015 09:46:39 -0800 Subject: [PATCH 77/77] use binary dir for externals as well --- cmake/macros/AddDependencyExternalProject.cmake | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/cmake/macros/AddDependencyExternalProject.cmake b/cmake/macros/AddDependencyExternalProject.cmake index 9e958b030b..ff0ced411e 100644 --- a/cmake/macros/AddDependencyExternalProject.cmake +++ b/cmake/macros/AddDependencyExternalProject.cmake @@ -14,15 +14,8 @@ macro(ADD_DEPENDENCY_EXTERNAL_PROJECT _PROJ_NAME) string(TOUPPER ${_PROJ_NAME} _PROJ_NAME_UPPER) if (NOT DEFINED GET_${_PROJ_NAME_UPPER} OR GET_${_PROJ_NAME_UPPER}) - if (NOT TARGET ${_PROJ_NAME}) - - if (ANDROID) - set(_PROJ_BINARY_DIR ${EXTERNAL_PROJECT_DIR}/${_PROJ_NAME}/build/android) - else () - set(_PROJ_BINARY_DIR ${EXTERNAL_PROJECT_DIR}/${_PROJ_NAME}/build) - endif () - - add_subdirectory(${EXTERNAL_PROJECT_DIR}/${_PROJ_NAME} ${_PROJ_BINARY_DIR}) + if (NOT TARGET ${_PROJ_NAME}) + add_subdirectory(${EXTERNAL_PROJECT_DIR}/${_PROJ_NAME} ${CMAKE_BINARY_DIR}/externals/${_PROJ_NAME}) endif () add_dependencies(${TARGET_NAME} ${_PROJ_NAME})