From cd0ee0ff1db256882aacf2e5dc1654ecb19b237a Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Sun, 23 Nov 2014 14:58:29 -0800 Subject: [PATCH 01/33] better support for includes in entity scripts --- interface/src/entities/EntityTreeRenderer.cpp | 15 +++++++++++++-- interface/src/entities/EntityTreeRenderer.h | 2 +- libraries/script-engine/src/ScriptEngine.cpp | 11 ++++++++--- libraries/script-engine/src/ScriptEngine.h | 3 +++ 4 files changed, 25 insertions(+), 6 deletions(-) diff --git a/interface/src/entities/EntityTreeRenderer.cpp b/interface/src/entities/EntityTreeRenderer.cpp index 192b42c58b..dfe9505c02 100644 --- a/interface/src/entities/EntityTreeRenderer.cpp +++ b/interface/src/entities/EntityTreeRenderer.cpp @@ -99,13 +99,15 @@ QScriptValue EntityTreeRenderer::loadEntityScript(const EntityItemID& entityItem } -QString EntityTreeRenderer::loadScriptContents(const QString& scriptMaybeURLorText) { +QString EntityTreeRenderer::loadScriptContents(const QString& scriptMaybeURLorText, bool& isURL) { QUrl url(scriptMaybeURLorText); // If the url is not valid, this must be script text... if (!url.isValid()) { + isURL = false; return scriptMaybeURLorText; } + isURL = true; QString scriptContents; // assume empty @@ -168,7 +170,8 @@ QScriptValue EntityTreeRenderer::loadEntityScript(EntityItem* entity) { return QScriptValue(); // no script } - QString scriptContents = loadScriptContents(entity->getScript()); + bool isURL = false; // loadScriptContents() will tell us if this is a URL or just text. + QString scriptContents = loadScriptContents(entity->getScript(), isURL); QScriptSyntaxCheckResult syntaxCheck = QScriptEngine::checkSyntax(scriptContents); if (syntaxCheck.state() != QScriptSyntaxCheckResult::Valid) { @@ -179,6 +182,9 @@ QScriptValue EntityTreeRenderer::loadEntityScript(EntityItem* entity) { return QScriptValue(); // invalid script } + if (isURL) { + _entitiesScriptEngine->setParentURL(entity->getScript()); + } QScriptValue entityScriptConstructor = _entitiesScriptEngine->evaluate(scriptContents); if (!entityScriptConstructor.isFunction()) { @@ -189,9 +195,14 @@ QScriptValue EntityTreeRenderer::loadEntityScript(EntityItem* entity) { } QScriptValue entityScriptObject = entityScriptConstructor.construct(); + EntityScriptDetails newDetails = { entity->getScript(), entityScriptObject }; _entityScripts[entityID] = newDetails; + if (isURL) { + _entitiesScriptEngine->setParentURL(""); + } + return entityScriptObject; // newly constructed } diff --git a/interface/src/entities/EntityTreeRenderer.h b/interface/src/entities/EntityTreeRenderer.h index e5eba79e0d..8b2131691c 100644 --- a/interface/src/entities/EntityTreeRenderer.h +++ b/interface/src/entities/EntityTreeRenderer.h @@ -132,7 +132,7 @@ private: QScriptValue loadEntityScript(const EntityItemID& entityItemID); QScriptValue getPreviouslyLoadedEntityScript(const EntityItemID& entityItemID); QScriptValue getPreviouslyLoadedEntityScript(EntityItem* entity); - QString loadScriptContents(const QString& scriptMaybeURLorText); + QString loadScriptContents(const QString& scriptMaybeURLorText, bool& isURL); QScriptValueList createMouseEventArgs(const EntityItemID& entityID, QMouseEvent* event, unsigned int deviceID); QScriptValueList createMouseEventArgs(const EntityItemID& entityID, const MouseEvent& mouseEvent); diff --git a/libraries/script-engine/src/ScriptEngine.cpp b/libraries/script-engine/src/ScriptEngine.cpp index e6002d7c10..fc1e8ce8bc 100644 --- a/libraries/script-engine/src/ScriptEngine.cpp +++ b/libraries/script-engine/src/ScriptEngine.cpp @@ -618,16 +618,20 @@ void ScriptEngine::stopTimer(QTimer *timer) { } QUrl ScriptEngine::resolvePath(const QString& include) const { - // first lets check to see if it's already a full URL QUrl url(include); + // first lets check to see if it's already a full URL if (!url.scheme().isEmpty()) { return url; } // we apparently weren't a fully qualified url, so, let's assume we're relative // to the original URL of our script - QUrl parentURL(_fileNameString); - + QUrl parentURL; + if (_parentURL.isEmpty()) { + parentURL = QUrl(_fileNameString); + } else { + parentURL = QUrl(_parentURL); + } // if the parent URL's scheme is empty, then this is probably a local file... if (parentURL.scheme().isEmpty()) { parentURL = QUrl::fromLocalFile(_fileNameString); @@ -660,6 +664,7 @@ void ScriptEngine::include(const QString& includeFile) { #else QString fileName = url.toLocalFile(); #endif + QFile scriptFile(fileName); if (scriptFile.open(QFile::ReadOnly | QFile::Text)) { qDebug() << "Including file:" << fileName; diff --git a/libraries/script-engine/src/ScriptEngine.h b/libraries/script-engine/src/ScriptEngine.h index bb279b8887..289436aada 100644 --- a/libraries/script-engine/src/ScriptEngine.h +++ b/libraries/script-engine/src/ScriptEngine.h @@ -93,6 +93,8 @@ public: void setUserLoaded(bool isUserLoaded) { _isUserLoaded = isUserLoaded; } bool isUserLoaded() const { return _isUserLoaded; } + void setParentURL(const QString& parentURL) { _parentURL = parentURL; } + public slots: void stop(); @@ -121,6 +123,7 @@ signals: protected: QString _scriptContents; + QString _parentURL; bool _isFinished; bool _isRunning; bool _isInitialized; From 3ee6d6a6dbb1b661555a81bcff16e444cd9b464e Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Sun, 23 Nov 2014 20:12:52 -0800 Subject: [PATCH 02/33] work in making entity script mixable and inheritable --- examples/entityScripts/changeColorOnHover.js | 35 +- .../entityScripts/changeColorOnHoverClass.js | 55 +++ examples/entityScripts/movable.js | 410 +---------------- examples/entityScripts/movableClass.js | 426 ++++++++++++++++++ examples/entityScripts/sitOnEntity.js | 363 +-------------- examples/entityScripts/sittable.js | 15 + examples/entityScripts/sittableClass.js | 381 ++++++++++++++++ 7 files changed, 888 insertions(+), 797 deletions(-) create mode 100644 examples/entityScripts/changeColorOnHoverClass.js create mode 100644 examples/entityScripts/movableClass.js create mode 100644 examples/entityScripts/sittable.js create mode 100644 examples/entityScripts/sittableClass.js diff --git a/examples/entityScripts/changeColorOnHover.js b/examples/entityScripts/changeColorOnHover.js index 638c1bece4..0cf08adf1d 100644 --- a/examples/entityScripts/changeColorOnHover.js +++ b/examples/entityScripts/changeColorOnHover.js @@ -13,34 +13,7 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -(function(){ - this.oldColor = {}; - this.oldColorKnown = false; - this.storeOldColor = function(entityID) { - var oldProperties = Entities.getEntityProperties(entityID); - this.oldColor = oldProperties.color; - this.oldColorKnown = true; - print("storing old color... this.oldColor=" + this.oldColor.red + "," + this.oldColor.green + "," + this.oldColor.blue); - }; - - this.preload = function(entityID) { - print("preload"); - this.storeOldColor(entityID); - }; - - this.hoverEnterEntity = function(entityID, mouseEvent) { - print("hoverEnterEntity"); - if (!this.oldColorKnown) { - this.storeOldColor(entityID); - } - Entities.editEntity(entityID, { color: { red: 0, green: 255, blue: 255} }); - }; - this.hoverLeaveEntity = function(entityID, mouseEvent) { - print("hoverLeaveEntity"); - if (this.oldColorKnown) { - print("leave restoring old color... this.oldColor=" - + this.oldColor.red + "," + this.oldColor.green + "," + this.oldColor.blue); - Entities.editEntity(entityID, { color: this.oldColor }); - } - }; -}) \ No newline at end of file +(function() { + Script.include("changeColorOnHoverClass.js"); + return new ChangeColorOnHover(); +}) diff --git a/examples/entityScripts/changeColorOnHoverClass.js b/examples/entityScripts/changeColorOnHoverClass.js new file mode 100644 index 0000000000..231469f7e8 --- /dev/null +++ b/examples/entityScripts/changeColorOnHoverClass.js @@ -0,0 +1,55 @@ +// +// changeColorOnHover.js +// examples/entityScripts +// +// Created by Brad Hefta-Gaub on 11/1/14. +// Copyright 2014 High Fidelity, Inc. +// +// This is an example of an entity script which when assigned to a non-model entity like a box or sphere, will +// change the color of the entity when you hover over it. This script uses the JavaScript prototype/class functionality +// to construct an object that has methods for hoverEnterEntity and hoverLeaveEntity; +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + + +ChangeColorOnHover = function(){ + this.oldColor = {}; + this.oldColorKnown = false; +}; + +ChangeColorOnHover.prototype = { + + storeOldColor: function(entityID) { + var oldProperties = Entities.getEntityProperties(entityID); + this.oldColor = oldProperties.color; + this.oldColorKnown = true; + print("storing old color... this.oldColor=" + this.oldColor.red + "," + this.oldColor.green + "," + this.oldColor.blue); + }, + + preload: function(entityID) { + print("preload"); + this.storeOldColor(entityID); + }, + + hoverEnterEntity: function(entityID, mouseEvent) { + print("hoverEnterEntity"); + if (!this.oldColorKnown) { + this.storeOldColor(entityID); + } + Entities.editEntity(entityID, { color: { red: 0, green: 255, blue: 255} }); + }, + + + hoverLeaveEntity: function(entityID, mouseEvent) { + print("hoverLeaveEntity"); + if (this.oldColorKnown) { + print("leave restoring old color... this.oldColor=" + + this.oldColor.red + "," + this.oldColor.green + "," + this.oldColor.blue); + Entities.editEntity(entityID, { color: this.oldColor }); + } + } +}; + + diff --git a/examples/entityScripts/movable.js b/examples/entityScripts/movable.js index 21e6261179..0ea3641c6f 100644 --- a/examples/entityScripts/movable.js +++ b/examples/entityScripts/movable.js @@ -8,412 +8,8 @@ // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -(function(){ - - this.entityID = null; - this.properties = null; - this.graboffset = null; - this.clickedAt = null; - this.firstHolding = true; - this.clicked = { x: -1, y: -1}; - this.lastMovedPosition = { x: -1, y: -1}; - this.lastMovedTime = 0; - this.rotateOverlayTarget = null; - this.rotateOverlayInner = null; - this.rotateOverlayOuter = null; - this.rotateOverlayCurrent = null; - this.rotateMode = false; - this.originalRotation = null; - - this.moveSoundURLS = [ - "http://public.highfidelity.io/sounds/MovingFurniture/FurnitureMove1.wav", - "http://public.highfidelity.io/sounds/MovingFurniture/FurnitureMove2.wav", - "http://public.highfidelity.io/sounds/MovingFurniture/FurnitureMove3.wav" - ]; - - this.turnSoundURLS = [ - - "http://public.highfidelity.io/sounds/MovingFurniture/FurnitureMove1.wav", - "http://public.highfidelity.io/sounds/MovingFurniture/FurnitureMove2.wav", - "http://public.highfidelity.io/sounds/MovingFurniture/FurnitureMove3.wav" - - // TODO: determine if these or other turn sounds work better than move sounds. - //"http://public.highfidelity.io/sounds/MovingFurniture/FurnitureTurn1.wav", - //"http://public.highfidelity.io/sounds/MovingFurniture/FurnitureTurn2.wav", - //"http://public.highfidelity.io/sounds/MovingFurniture/FurnitureTurn3.wav" - ]; - - - this.moveSounds = new Array(); - this.turnSounds = new Array(); - this.moveSound = null; - this.turnSound = null; - this.injector = null; - - var debug = false; - var displayRotateTargets = true; // change to false if you don't want the rotate targets - var rotateOverlayTargetSize = 10000; // really big target - var innerSnapAngle = 22.5; // the angle which we snap to on the inner rotation tool - var innerRadius; - var outerRadius; - var yawCenter; - var yawZero; - var rotationNormal; - var yawNormal; - var stopSoundDelay = 100; // number of msecs of not moving to have sound stop - - this.getRandomInt = function(min, max) { - return Math.floor(Math.random() * (max - min + 1)) + min; - } - - this.downloadSounds = function() { - for (var i = 0; i < this.moveSoundURLS.length; i++) { - this.moveSounds[i] = SoundCache.getSound(this.moveSoundURLS[i]); - } - for (var i = 0; i < this.turnSoundURLS.length; i++) { - this.turnSounds[i] = SoundCache.getSound(this.turnSoundURLS[i]); - } - } - - this.pickRandomSounds = function() { - var moveIndex = this.getRandomInt(0, this.moveSounds.length - 1); - var turnIndex = this.getRandomInt(0, this.turnSounds.length - 1); - if (debug) { - print("Random sounds -- turn:" + turnIndex + " move:" + moveIndex); - } - this.moveSound = this.moveSounds[moveIndex]; - this.turnSound = this.turnSounds[turnIndex]; - } - - // Play move sound - this.playMoveSound = function() { - if (debug) { - print("playMoveSound()"); - } - if (this.moveSound && this.moveSound.downloaded) { - if (debug) { - print("playMoveSound() --- calling this.injector = Audio.playSound(this.moveSound...)"); - } - this.injector = Audio.playSound(this.moveSound, { position: this.properties.position, loop: true, volume: 0.1 }); - } - } - - // Play turn sound - this.playTurnSound = function() { - if (debug) { - print("playTurnSound()"); - } - if (this.turnSound && this.turnSound.downloaded) { - if (debug) { - print("playTurnSound() --- calling this.injector = Audio.playSound(this.turnSound...)"); - } - this.injector = Audio.playSound(this.turnSound, { position: this.properties.position, loop: true, volume: 0.1 }); - } - } - - // stop sound - this.stopSound = function() { - if (debug) { - print("stopSound()"); - } - if (this.injector) { - Audio.stopInjector(this.injector); - this.injector = null; - } - } - - // Pr, Vr are respectively the Ray's Point of origin and Vector director - // Pp, Np are respectively the Plane's Point of origin and Normal vector - this.rayPlaneIntersection = function(Pr, Vr, Pp, Np) { - var d = -Vec3.dot(Pp, Np); - var t = -(Vec3.dot(Pr, Np) + d) / Vec3.dot(Vr, Np); - return Vec3.sum(Pr, Vec3.multiply(t, Vr)); - }; - - // updates the piece position based on mouse input - this.updatePosition = function(mouseEvent) { - var pickRay = Camera.computePickRay(mouseEvent.x, mouseEvent.y) - var upVector = { x: 0, y: 1, z: 0 }; - var intersection = this.rayPlaneIntersection(pickRay.origin, pickRay.direction, - this.properties.position, upVector); - - var newPosition = Vec3.sum(intersection, this.graboffset); - Entities.editEntity(this.entityID, { position: newPosition }); - }; - - this.grab = function(mouseEvent) { - // first calculate the offset - var pickRay = Camera.computePickRay(mouseEvent.x, mouseEvent.y) - var upVector = { x: 0, y: 1, z: 0 }; - var intersection = this.rayPlaneIntersection(pickRay.origin, pickRay.direction, - this.properties.position, upVector); - this.graboffset = Vec3.subtract(this.properties.position, intersection); - }; - - this.stopSoundIfNotMoving = function(mouseEvent) { - var nowDate = new Date(); - var nowMSecs = nowDate.getTime(); - if(mouseEvent.x == this.lastMovedPosition.x && mouseEvent.y == this.lastMovedPosition.y) { - var elapsedSinceLastMove = nowMSecs - this.lastMovedMSecs; - if (debug) { - print("elapsedSinceLastMove:" + elapsedSinceLastMove); - } - if (elapsedSinceLastMove > stopSoundDelay) { - if (debug) { - print("calling stopSound()..."); - } - this.stopSound(); - } - } else { - // if we've moved, then track our last move position and time... - this.lastMovedMSecs = nowMSecs; - this.lastMovedPosition.x = mouseEvent.x; - this.lastMovedPosition.y = mouseEvent.y; - } - } - - this.move = function(mouseEvent) { - this.updatePosition(mouseEvent); - if (this.injector === null) { - this.playMoveSound(); - } - }; - - this.release = function(mouseEvent) { - this.updatePosition(mouseEvent); - }; - - this.rotate = function(mouseEvent) { - var pickRay = Camera.computePickRay(mouseEvent.x, mouseEvent.y) - var result = Overlays.findRayIntersection(pickRay); - - if (result.intersects) { - var center = yawCenter; - var zero = yawZero; - var centerToZero = Vec3.subtract(center, zero); - var centerToIntersect = Vec3.subtract(center, result.intersection); - var angleFromZero = Vec3.orientedAngle(centerToZero, centerToIntersect, rotationNormal); - - var distanceFromCenter = Vec3.distance(center, result.intersection); - var snapToInner = false; - // var innerRadius = (Vec3.length(selectionManager.worldDimensions) / 2) * 1.1; - if (distanceFromCenter < innerRadius) { - angleFromZero = Math.floor(angleFromZero/innerSnapAngle) * innerSnapAngle; - snapToInner = true; - } - - var yawChange = Quat.fromVec3Degrees({ x: 0, y: angleFromZero, z: 0 }); - Entities.editEntity(this.entityID, { rotation: Quat.multiply(yawChange, this.originalRotation) }); - - - // update the rotation display accordingly... - var startAtCurrent = 360-angleFromZero; - var endAtCurrent = 360; - var startAtRemainder = 0; - var endAtRemainder = 360-angleFromZero; - if (angleFromZero < 0) { - startAtCurrent = 0; - endAtCurrent = -angleFromZero; - startAtRemainder = -angleFromZero; - endAtRemainder = 360; - } - - if (snapToInner) { - Overlays.editOverlay(this.rotateOverlayOuter, { startAt: 0, endAt: 360 }); - Overlays.editOverlay(this.rotateOverlayInner, { startAt: startAtRemainder, endAt: endAtRemainder }); - Overlays.editOverlay(this.rotateOverlayCurrent, { startAt: startAtCurrent, endAt: endAtCurrent, size: innerRadius, - majorTickMarksAngle: innerSnapAngle, minorTickMarksAngle: 0, - majorTickMarksLength: -0.25, minorTickMarksLength: 0, }); - } else { - Overlays.editOverlay(this.rotateOverlayInner, { startAt: 0, endAt: 360 }); - Overlays.editOverlay(this.rotateOverlayOuter, { startAt: startAtRemainder, endAt: endAtRemainder }); - Overlays.editOverlay(this.rotateOverlayCurrent, { startAt: startAtCurrent, endAt: endAtCurrent, size: outerRadius, - majorTickMarksAngle: 45.0, minorTickMarksAngle: 5, - majorTickMarksLength: 0.25, minorTickMarksLength: 0.1, }); - } - } - - if (this.injector === null) { - this.playTurnSound(); - } - }; - // All callbacks start by updating the properties - this.updateProperties = function(entityID) { - if (this.entityID === null || !this.entityID.isKnownID) { - this.entityID = Entities.identifyEntity(entityID); - } - this.properties = Entities.getEntityProperties(this.entityID); - }; - - this.cleanupRotateOverlay = function() { - Overlays.deleteOverlay(this.rotateOverlayTarget); - Overlays.deleteOverlay(this.rotateOverlayInner); - Overlays.deleteOverlay(this.rotateOverlayOuter); - Overlays.deleteOverlay(this.rotateOverlayCurrent); - this.rotateOverlayTarget = null; - this.rotateOverlayInner = null; - this.rotateOverlayOuter = null; - this.rotateOverlayCurrent = null; - } - - this.displayRotateOverlay = function(mouseEvent) { - var yawOverlayAngles = { x: 90, y: 0, z: 0 }; - var yawOverlayRotation = Quat.fromVec3Degrees(yawOverlayAngles); - - yawNormal = { x: 0, y: 1, z: 0 }; - yawCenter = this.properties.position; - rotationNormal = yawNormal; - - // Size the overlays to the current selection size - var diagonal = (Vec3.length(this.properties.dimensions) / 2) * 1.1; - var halfDimensions = Vec3.multiply(this.properties.dimensions, 0.5); - innerRadius = diagonal; - outerRadius = diagonal * 1.15; - var innerAlpha = 0.2; - var outerAlpha = 0.2; - - this.rotateOverlayTarget = Overlays.addOverlay("circle3d", { - position: this.properties.position, - size: rotateOverlayTargetSize, - color: { red: 0, green: 0, blue: 0 }, - alpha: 0.0, - solid: true, - visible: true, - rotation: yawOverlayRotation, - ignoreRayIntersection: false - }); - - this.rotateOverlayInner = Overlays.addOverlay("circle3d", { - position: this.properties.position, - size: innerRadius, - innerRadius: 0.9, - alpha: innerAlpha, - color: { red: 51, green: 152, blue: 203 }, - solid: true, - visible: displayRotateTargets, - rotation: yawOverlayRotation, - hasTickMarks: true, - majorTickMarksAngle: innerSnapAngle, - minorTickMarksAngle: 0, - majorTickMarksLength: -0.25, - minorTickMarksLength: 0, - majorTickMarksColor: { red: 0, green: 0, blue: 0 }, - minorTickMarksColor: { red: 0, green: 0, blue: 0 }, - ignoreRayIntersection: true, // always ignore this - }); - - this.rotateOverlayOuter = Overlays.addOverlay("circle3d", { - position: this.properties.position, - size: outerRadius, - innerRadius: 0.9, - startAt: 0, - endAt: 360, - alpha: outerAlpha, - color: { red: 51, green: 152, blue: 203 }, - solid: true, - visible: displayRotateTargets, - rotation: yawOverlayRotation, - - hasTickMarks: true, - majorTickMarksAngle: 45.0, - minorTickMarksAngle: 5, - majorTickMarksLength: 0.25, - minorTickMarksLength: 0.1, - majorTickMarksColor: { red: 0, green: 0, blue: 0 }, - minorTickMarksColor: { red: 0, green: 0, blue: 0 }, - ignoreRayIntersection: true, // always ignore this - }); - - this.rotateOverlayCurrent = Overlays.addOverlay("circle3d", { - position: this.properties.position, - size: outerRadius, - startAt: 0, - endAt: 0, - innerRadius: 0.9, - color: { red: 224, green: 67, blue: 36}, - alpha: 0.8, - solid: true, - visible: displayRotateTargets, - rotation: yawOverlayRotation, - ignoreRayIntersection: true, // always ignore this - hasTickMarks: true, - majorTickMarksColor: { red: 0, green: 0, blue: 0 }, - minorTickMarksColor: { red: 0, green: 0, blue: 0 }, - }); - - var pickRay = Camera.computePickRay(mouseEvent.x, mouseEvent.y) - var result = Overlays.findRayIntersection(pickRay); - yawZero = result.intersection; - - }; - - this.preload = function(entityID) { - this.updateProperties(entityID); // All callbacks start by updating the properties - this.downloadSounds(); - }; - - this.clickDownOnEntity = function(entityID, mouseEvent) { - this.updateProperties(entityID); // All callbacks start by updating the properties - this.grab(mouseEvent); - - var nowDate = new Date(); - var nowMSecs = nowDate.getTime(); - this.clickedAt = nowMSecs; - this.firstHolding = true; - - this.clicked.x = mouseEvent.x; - this.clicked.y = mouseEvent.y; - this.lastMovedPosition.x = mouseEvent.x; - this.lastMovedPosition.y = mouseEvent.y; - this.lastMovedMSecs = nowMSecs; - - this.pickRandomSounds(); - }; - - this.holdingClickOnEntity = function(entityID, mouseEvent) { - - this.updateProperties(entityID); // All callbacks start by updating the properties - - if (this.firstHolding) { - // if we haven't moved yet... - if (this.clicked.x == mouseEvent.x && this.clicked.y == mouseEvent.y) { - var d = new Date(); - var now = d.getTime(); - - if (now - this.clickedAt > 500) { - this.displayRotateOverlay(mouseEvent); - this.firstHolding = false; - this.rotateMode = true; - this.originalRotation = this.properties.rotation; - } - } else { - this.firstHolding = false; - } - } - - if (this.rotateMode) { - this.rotate(mouseEvent); - } else { - this.move(mouseEvent); - } - - this.stopSoundIfNotMoving(mouseEvent); - }; - this.clickReleaseOnEntity = function(entityID, mouseEvent) { - this.updateProperties(entityID); // All callbacks start by updating the properties - if (this.rotateMode) { - this.rotate(mouseEvent); - } else { - this.release(mouseEvent); - } - - if (this.rotateOverlayTarget != null) { - this.cleanupRotateOverlay(); - this.rotateMode = false; - } - - this.firstHolding = false; - this.stopSound(); - }; +(function() { + Script.include("movableClass.js"); + return new Movable(); }) diff --git a/examples/entityScripts/movableClass.js b/examples/entityScripts/movableClass.js new file mode 100644 index 0000000000..26fb643826 --- /dev/null +++ b/examples/entityScripts/movableClass.js @@ -0,0 +1,426 @@ +// +// movableClass.js +// examples/entityScripts +// +// Created by Brad Hefta-Gaub on 11/17/14. +// Copyright 2014 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// +Movable = function() { + + this.entityID = null; + this.properties = null; + this.graboffset = null; + this.clickedAt = null; + this.firstHolding = true; + this.clicked = { x: -1, y: -1}; + this.lastMovedPosition = { x: -1, y: -1}; + this.lastMovedTime = 0; + this.rotateOverlayTarget = null; + this.rotateOverlayInner = null; + this.rotateOverlayOuter = null; + this.rotateOverlayCurrent = null; + this.rotateMode = false; + this.originalRotation = null; + + this.moveSoundURLS = [ + "http://public.highfidelity.io/sounds/MovingFurniture/FurnitureMove1.wav", + "http://public.highfidelity.io/sounds/MovingFurniture/FurnitureMove2.wav", + "http://public.highfidelity.io/sounds/MovingFurniture/FurnitureMove3.wav" + ]; + + this.turnSoundURLS = [ + + "http://public.highfidelity.io/sounds/MovingFurniture/FurnitureMove1.wav", + "http://public.highfidelity.io/sounds/MovingFurniture/FurnitureMove2.wav", + "http://public.highfidelity.io/sounds/MovingFurniture/FurnitureMove3.wav" + + // TODO: determine if these or other turn sounds work better than move sounds. + //"http://public.highfidelity.io/sounds/MovingFurniture/FurnitureTurn1.wav", + //"http://public.highfidelity.io/sounds/MovingFurniture/FurnitureTurn2.wav", + //"http://public.highfidelity.io/sounds/MovingFurniture/FurnitureTurn3.wav" + ]; + + + this.moveSounds = new Array(); + this.turnSounds = new Array(); + this.moveSound = null; + this.turnSound = null; + this.injector = null; + + var debug = false; + var displayRotateTargets = true; // change to false if you don't want the rotate targets + var rotateOverlayTargetSize = 10000; // really big target + var innerSnapAngle = 22.5; // the angle which we snap to on the inner rotation tool + var innerRadius; + var outerRadius; + var yawCenter; + var yawZero; + var rotationNormal; + var yawNormal; + var stopSoundDelay = 100; // number of msecs of not moving to have sound stop + + this.getRandomInt = function(min, max) { + return Math.floor(Math.random() * (max - min + 1)) + min; + } + + this.downloadSounds = function() { + for (var i = 0; i < this.moveSoundURLS.length; i++) { + this.moveSounds[i] = SoundCache.getSound(this.moveSoundURLS[i]); + } + for (var i = 0; i < this.turnSoundURLS.length; i++) { + this.turnSounds[i] = SoundCache.getSound(this.turnSoundURLS[i]); + } + } + + this.pickRandomSounds = function() { + var moveIndex = this.getRandomInt(0, this.moveSounds.length - 1); + var turnIndex = this.getRandomInt(0, this.turnSounds.length - 1); + if (debug) { + print("Random sounds -- turn:" + turnIndex + " move:" + moveIndex); + } + this.moveSound = this.moveSounds[moveIndex]; + this.turnSound = this.turnSounds[turnIndex]; + } + + // Play move sound + this.playMoveSound = function() { + if (debug) { + print("playMoveSound()"); + } + if (this.moveSound && this.moveSound.downloaded) { + if (debug) { + print("playMoveSound() --- calling this.injector = Audio.playSound(this.moveSound...)"); + } + this.injector = Audio.playSound(this.moveSound, { position: this.properties.position, loop: true, volume: 0.1 }); + } + } + + // Play turn sound + this.playTurnSound = function() { + if (debug) { + print("playTurnSound()"); + } + if (this.turnSound && this.turnSound.downloaded) { + if (debug) { + print("playTurnSound() --- calling this.injector = Audio.playSound(this.turnSound...)"); + } + this.injector = Audio.playSound(this.turnSound, { position: this.properties.position, loop: true, volume: 0.1 }); + } + } + + // stop sound + this.stopSound = function() { + if (debug) { + print("stopSound()"); + } + if (this.injector) { + Audio.stopInjector(this.injector); + this.injector = null; + } + } + + // Pr, Vr are respectively the Ray's Point of origin and Vector director + // Pp, Np are respectively the Plane's Point of origin and Normal vector + this.rayPlaneIntersection = function(Pr, Vr, Pp, Np) { + var d = -Vec3.dot(Pp, Np); + var t = -(Vec3.dot(Pr, Np) + d) / Vec3.dot(Vr, Np); + return Vec3.sum(Pr, Vec3.multiply(t, Vr)); + }; + + // updates the piece position based on mouse input + this.updatePosition = function(mouseEvent) { + var pickRay = Camera.computePickRay(mouseEvent.x, mouseEvent.y) + var upVector = { x: 0, y: 1, z: 0 }; + var intersection = this.rayPlaneIntersection(pickRay.origin, pickRay.direction, + this.properties.position, upVector); + + var newPosition = Vec3.sum(intersection, this.graboffset); + Entities.editEntity(this.entityID, { position: newPosition }); + }; + + this.grab = function(mouseEvent) { + // first calculate the offset + var pickRay = Camera.computePickRay(mouseEvent.x, mouseEvent.y) + var upVector = { x: 0, y: 1, z: 0 }; + var intersection = this.rayPlaneIntersection(pickRay.origin, pickRay.direction, + this.properties.position, upVector); + this.graboffset = Vec3.subtract(this.properties.position, intersection); + }; + + this.stopSoundIfNotMoving = function(mouseEvent) { + var nowDate = new Date(); + var nowMSecs = nowDate.getTime(); + if(mouseEvent.x == this.lastMovedPosition.x && mouseEvent.y == this.lastMovedPosition.y) { + var elapsedSinceLastMove = nowMSecs - this.lastMovedMSecs; + if (debug) { + print("elapsedSinceLastMove:" + elapsedSinceLastMove); + } + if (elapsedSinceLastMove > stopSoundDelay) { + if (debug) { + print("calling stopSound()..."); + } + this.stopSound(); + } + } else { + // if we've moved, then track our last move position and time... + this.lastMovedMSecs = nowMSecs; + this.lastMovedPosition.x = mouseEvent.x; + this.lastMovedPosition.y = mouseEvent.y; + } + } + + this.move = function(mouseEvent) { + this.updatePosition(mouseEvent); + if (this.injector === null) { + this.playMoveSound(); + } + }; + + this.release = function(mouseEvent) { + this.updatePosition(mouseEvent); + }; + + this.rotate = function(mouseEvent) { + var pickRay = Camera.computePickRay(mouseEvent.x, mouseEvent.y) + var result = Overlays.findRayIntersection(pickRay); + + if (result.intersects) { + var center = yawCenter; + var zero = yawZero; + var centerToZero = Vec3.subtract(center, zero); + var centerToIntersect = Vec3.subtract(center, result.intersection); + var angleFromZero = Vec3.orientedAngle(centerToZero, centerToIntersect, rotationNormal); + + var distanceFromCenter = Vec3.distance(center, result.intersection); + var snapToInner = false; + // var innerRadius = (Vec3.length(selectionManager.worldDimensions) / 2) * 1.1; + if (distanceFromCenter < innerRadius) { + angleFromZero = Math.floor(angleFromZero/innerSnapAngle) * innerSnapAngle; + snapToInner = true; + } + + var yawChange = Quat.fromVec3Degrees({ x: 0, y: angleFromZero, z: 0 }); + Entities.editEntity(this.entityID, { rotation: Quat.multiply(yawChange, this.originalRotation) }); + + + // update the rotation display accordingly... + var startAtCurrent = 360-angleFromZero; + var endAtCurrent = 360; + var startAtRemainder = 0; + var endAtRemainder = 360-angleFromZero; + if (angleFromZero < 0) { + startAtCurrent = 0; + endAtCurrent = -angleFromZero; + startAtRemainder = -angleFromZero; + endAtRemainder = 360; + } + + if (snapToInner) { + Overlays.editOverlay(this.rotateOverlayOuter, { startAt: 0, endAt: 360 }); + Overlays.editOverlay(this.rotateOverlayInner, { startAt: startAtRemainder, endAt: endAtRemainder }); + Overlays.editOverlay(this.rotateOverlayCurrent, { startAt: startAtCurrent, endAt: endAtCurrent, size: innerRadius, + majorTickMarksAngle: innerSnapAngle, minorTickMarksAngle: 0, + majorTickMarksLength: -0.25, minorTickMarksLength: 0, }); + } else { + Overlays.editOverlay(this.rotateOverlayInner, { startAt: 0, endAt: 360 }); + Overlays.editOverlay(this.rotateOverlayOuter, { startAt: startAtRemainder, endAt: endAtRemainder }); + Overlays.editOverlay(this.rotateOverlayCurrent, { startAt: startAtCurrent, endAt: endAtCurrent, size: outerRadius, + majorTickMarksAngle: 45.0, minorTickMarksAngle: 5, + majorTickMarksLength: 0.25, minorTickMarksLength: 0.1, }); + } + } + + if (this.injector === null) { + this.playTurnSound(); + } + }; + // All callbacks start by updating the properties + this.updateProperties = function(entityID) { + if (this.entityID === null || !this.entityID.isKnownID) { + this.entityID = Entities.identifyEntity(entityID); + } + this.properties = Entities.getEntityProperties(this.entityID); + }; + + this.cleanupRotateOverlay = function() { + Overlays.deleteOverlay(this.rotateOverlayTarget); + Overlays.deleteOverlay(this.rotateOverlayInner); + Overlays.deleteOverlay(this.rotateOverlayOuter); + Overlays.deleteOverlay(this.rotateOverlayCurrent); + this.rotateOverlayTarget = null; + this.rotateOverlayInner = null; + this.rotateOverlayOuter = null; + this.rotateOverlayCurrent = null; + } + + this.displayRotateOverlay = function(mouseEvent) { + var yawOverlayAngles = { x: 90, y: 0, z: 0 }; + var yawOverlayRotation = Quat.fromVec3Degrees(yawOverlayAngles); + + yawNormal = { x: 0, y: 1, z: 0 }; + yawCenter = this.properties.position; + rotationNormal = yawNormal; + + // Size the overlays to the current selection size + var diagonal = (Vec3.length(this.properties.dimensions) / 2) * 1.1; + var halfDimensions = Vec3.multiply(this.properties.dimensions, 0.5); + innerRadius = diagonal; + outerRadius = diagonal * 1.15; + var innerAlpha = 0.2; + var outerAlpha = 0.2; + + this.rotateOverlayTarget = Overlays.addOverlay("circle3d", { + position: this.properties.position, + size: rotateOverlayTargetSize, + color: { red: 0, green: 0, blue: 0 }, + alpha: 0.0, + solid: true, + visible: true, + rotation: yawOverlayRotation, + ignoreRayIntersection: false + }); + + this.rotateOverlayInner = Overlays.addOverlay("circle3d", { + position: this.properties.position, + size: innerRadius, + innerRadius: 0.9, + alpha: innerAlpha, + color: { red: 51, green: 152, blue: 203 }, + solid: true, + visible: displayRotateTargets, + rotation: yawOverlayRotation, + hasTickMarks: true, + majorTickMarksAngle: innerSnapAngle, + minorTickMarksAngle: 0, + majorTickMarksLength: -0.25, + minorTickMarksLength: 0, + majorTickMarksColor: { red: 0, green: 0, blue: 0 }, + minorTickMarksColor: { red: 0, green: 0, blue: 0 }, + ignoreRayIntersection: true, // always ignore this + }); + + this.rotateOverlayOuter = Overlays.addOverlay("circle3d", { + position: this.properties.position, + size: outerRadius, + innerRadius: 0.9, + startAt: 0, + endAt: 360, + alpha: outerAlpha, + color: { red: 51, green: 152, blue: 203 }, + solid: true, + visible: displayRotateTargets, + rotation: yawOverlayRotation, + + hasTickMarks: true, + majorTickMarksAngle: 45.0, + minorTickMarksAngle: 5, + majorTickMarksLength: 0.25, + minorTickMarksLength: 0.1, + majorTickMarksColor: { red: 0, green: 0, blue: 0 }, + minorTickMarksColor: { red: 0, green: 0, blue: 0 }, + ignoreRayIntersection: true, // always ignore this + }); + + this.rotateOverlayCurrent = Overlays.addOverlay("circle3d", { + position: this.properties.position, + size: outerRadius, + startAt: 0, + endAt: 0, + innerRadius: 0.9, + color: { red: 224, green: 67, blue: 36}, + alpha: 0.8, + solid: true, + visible: displayRotateTargets, + rotation: yawOverlayRotation, + ignoreRayIntersection: true, // always ignore this + hasTickMarks: true, + majorTickMarksColor: { red: 0, green: 0, blue: 0 }, + minorTickMarksColor: { red: 0, green: 0, blue: 0 }, + }); + + var pickRay = Camera.computePickRay(mouseEvent.x, mouseEvent.y) + var result = Overlays.findRayIntersection(pickRay); + yawZero = result.intersection; + + }; +}; + +Movable.prototype = { + preload : function(entityID) { + print("Movable.preload()"); + this.updateProperties(entityID); // All callbacks start by updating the properties + this.downloadSounds(); + }, + + clickDownOnEntity : function(entityID, mouseEvent) { + print("Movable.clickDownOnEntity()"); + + this.updateProperties(entityID); // All callbacks start by updating the properties + this.grab(mouseEvent); + + var nowDate = new Date(); + var nowMSecs = nowDate.getTime(); + this.clickedAt = nowMSecs; + this.firstHolding = true; + + this.clicked.x = mouseEvent.x; + this.clicked.y = mouseEvent.y; + this.lastMovedPosition.x = mouseEvent.x; + this.lastMovedPosition.y = mouseEvent.y; + this.lastMovedMSecs = nowMSecs; + + this.pickRandomSounds(); + }, + + holdingClickOnEntity : function(entityID, mouseEvent) { + print("Movable.holdingClickOnEntity()"); + + this.updateProperties(entityID); // All callbacks start by updating the properties + + if (this.firstHolding) { + // if we haven't moved yet... + if (this.clicked.x == mouseEvent.x && this.clicked.y == mouseEvent.y) { + var d = new Date(); + var now = d.getTime(); + + if (now - this.clickedAt > 500) { + this.displayRotateOverlay(mouseEvent); + this.firstHolding = false; + this.rotateMode = true; + this.originalRotation = this.properties.rotation; + } + } else { + this.firstHolding = false; + } + } + + if (this.rotateMode) { + this.rotate(mouseEvent); + } else { + this.move(mouseEvent); + } + + this.stopSoundIfNotMoving(mouseEvent); + }, + + clickReleaseOnEntity : function(entityID, mouseEvent) { + print("Movable.clickReleaseOnEntity()"); + this.updateProperties(entityID); // All callbacks start by updating the properties + if (this.rotateMode) { + this.rotate(mouseEvent); + } else { + this.release(mouseEvent); + } + + if (this.rotateOverlayTarget != null) { + this.cleanupRotateOverlay(); + this.rotateMode = false; + } + + this.firstHolding = false; + this.stopSound(); + }, +}; diff --git a/examples/entityScripts/sitOnEntity.js b/examples/entityScripts/sitOnEntity.js index d5c4fa9c52..080acf61a8 100644 --- a/examples/entityScripts/sitOnEntity.js +++ b/examples/entityScripts/sitOnEntity.js @@ -11,362 +11,7 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -(function(){ - - this.entityID = null; - this.properties = null; - this.standUpButton = null; - this.indicatorsAdded = false; - this.indicator = new Array(); - - - var buttonImageUrl = "https://worklist-prod.s3.amazonaws.com/attachment/0aca88e1-9bd8-5c1d.svg"; - var windowDimensions = Controller.getViewportDimensions(); - var buttonWidth = 37; - var buttonHeight = 46; - var buttonPadding = 50; // inside the normal toolbar position - var buttonPositionX = windowDimensions.x - buttonPadding - buttonWidth; - var buttonPositionY = (windowDimensions.y - buttonHeight) / 2 - (buttonHeight + buttonPadding); - - var passedTime = 0.0; - var startPosition = null; - var startRotation = null; - var animationLenght = 2.0; - - var avatarOldPosition = { x: 0, y: 0, z: 0 }; - - var sittingSettingsHandle = "SitJsSittingPosition"; - var sitting = Settings.getValue(sittingSettingsHandle, false) == "true"; - print("Original sitting status: " + sitting); - var frame = 0; - - var seat = new Object(); - var hiddingSeats = false; - - // This is the pose we would like to end up - var pose = [ - {joint:"RightUpLeg", rotation: {x:100.0, y:15.0, z:0.0}}, - {joint:"RightLeg", rotation: {x:-130.0, y:15.0, z:0.0}}, - {joint:"RightFoot", rotation: {x:30, y:15.0, z:0.0}}, - {joint:"LeftUpLeg", rotation: {x:100.0, y:-15.0, z:0.0}}, - {joint:"LeftLeg", rotation: {x:-130.0, y:-15.0, z:0.0}}, - {joint:"LeftFoot", rotation: {x:30, y:15.0, z:0.0}} - ]; - - var startPoseAndTransition = []; - - function storeStartPoseAndTransition() { - for (var i = 0; i < pose.length; i++){ - var startRotation = Quat.safeEulerAngles(MyAvatar.getJointRotation(pose[i].joint)); - var transitionVector = Vec3.subtract( pose[i].rotation, startRotation ); - startPoseAndTransition.push({joint: pose[i].joint, start: startRotation, transition: transitionVector}); - } - } - - function updateJoints(factor){ - for (var i = 0; i < startPoseAndTransition.length; i++){ - var scaledTransition = Vec3.multiply(startPoseAndTransition[i].transition, factor); - var rotation = Vec3.sum(startPoseAndTransition[i].start, scaledTransition); - MyAvatar.setJointData(startPoseAndTransition[i].joint, Quat.fromVec3Degrees( rotation )); - } - } - - var sittingDownAnimation = function(deltaTime) { - - passedTime += deltaTime; - var factor = passedTime/animationLenght; - - if ( passedTime <= animationLenght ) { - updateJoints(factor); - - var pos = { x: startPosition.x - 0.3 * factor, y: startPosition.y - 0.5 * factor, z: startPosition.z}; - MyAvatar.position = pos; - } else { - Script.update.disconnect(sittingDownAnimation); - if (seat.model) { - MyAvatar.setModelReferential(seat.model.id); - } - } - } - - var standingUpAnimation = function(deltaTime) { - - passedTime += deltaTime; - var factor = 1 - passedTime/animationLenght; - - if ( passedTime <= animationLenght ) { - - updateJoints(factor); - - var pos = { x: startPosition.x + 0.3 * (passedTime/animationLenght), y: startPosition.y + 0.5 * (passedTime/animationLenght), z: startPosition.z}; - MyAvatar.position = pos; - } else { - Script.update.disconnect(standingUpAnimation); - - } - } - - var externalThis = this; - - var goToSeatAnimation = function(deltaTime) { - passedTime += deltaTime; - var factor = passedTime/animationLenght; - - if (passedTime <= animationLenght) { - var targetPosition = Vec3.sum(seat.position, { x: 0.3, y: 0.5, z: 0 }); - MyAvatar.position = Vec3.sum(Vec3.multiply(startPosition, 1 - factor), Vec3.multiply(targetPosition, factor)); - } else if (passedTime <= 2 * animationLenght) { - //Quat.print("MyAvatar: ", MyAvatar.orientation); - //Quat.print("Seat: ", seat.rotation); - MyAvatar.orientation = Quat.mix(startRotation, seat.rotation, factor - 1); - } else { - Script.update.disconnect(goToSeatAnimation); - externalThis.sitDown(); - externalThis.showIndicators(false); - } - } - - var globalMouseClick = function(event) { - var clickedOverlay = Overlays.getOverlayAtPoint({x: event.x, y: event.y}); - if (clickedOverlay == externalThis.standUpButton) { - seat.model = null; - externalThis.standUp(); - Controller.mousePressEvent.disconnect(globalMouseClick); - } - }; - - this.sitDown = function() { - sitting = true; - Settings.setValue(sittingSettingsHandle, sitting); - print("sitDown sitting status: " + Settings.getValue(sittingSettingsHandle, false)); - passedTime = 0.0; - startPosition = MyAvatar.position; - storeStartPoseAndTransition(); - try { - Script.update.disconnect(standingUpAnimation); - } catch(e){ - // no need to handle. if it wasn't connected no harm done - } - Script.update.connect(sittingDownAnimation); - Overlays.editOverlay(this.standUpButton, { visible: true }); - Controller.mousePressEvent.connect(globalMouseClick); - } - - this.standUp = function() { - sitting = false; - Settings.setValue(sittingSettingsHandle, sitting); - print("standUp sitting status: " + Settings.getValue(sittingSettingsHandle, false)); - passedTime = 0.0; - startPosition = MyAvatar.position; - MyAvatar.clearReferential(); - try{ - Script.update.disconnect(sittingDownAnimation); - } catch (e){} - Script.update.connect(standingUpAnimation); - Overlays.editOverlay(this.standUpButton, { visible: false }); - Controller.mousePressEvent.disconnect(globalMouseClick); - } - - function SeatIndicator(modelProperties, seatIndex) { - var halfDiagonal = Vec3.length(modelProperties.dimensions) / 2.0; - - this.position = Vec3.sum(modelProperties.position, - Vec3.multiply(Vec3.multiplyQbyV(modelProperties.rotation, modelProperties.sittingPoints[seatIndex].position), - halfDiagonal)); // hack - - this.orientation = Quat.multiply(modelProperties.rotation, - modelProperties.sittingPoints[seatIndex].rotation); - this.scale = MyAvatar.scale / 3; - - this.sphere = Overlays.addOverlay("billboard", { - subImage: { x: 0, y: buttonHeight, width: buttonWidth, height: buttonHeight}, - url: buttonImageUrl, - position: this.position, - scale: this.scale, - size: this.scale, - solid: true, - color: { red: 255, green: 255, blue: 255 }, - alpha: 0.8, - visible: true, - isFacingAvatar: true - }); - - this.show = function(doShow) { - Overlays.editOverlay(this.sphere, { visible: doShow }); - } - - this.update = function() { - Overlays.editOverlay(this.sphere, { - position: this.position, - size: this.scale - }); - } - - this.cleanup = function() { - Overlays.deleteOverlay(this.sphere); - } - } - - function update(deltaTime){ - var newWindowDimensions = Controller.getViewportDimensions(); - if( newWindowDimensions.x != windowDimensions.x || newWindowDimensions.y != windowDimensions.y ){ - windowDimensions = newWindowDimensions; - var newX = windowDimensions.x - buttonPadding - buttonWidth; - var newY = (windowDimensions.y - buttonHeight) / 2 ; - Overlays.editOverlay( this.standUpButton, {x: newX, y: newY} ); - } - - // For a weird reason avatar joint don't update till the 10th frame - // Set the update frame to 20 to be safe - var UPDATE_FRAME = 20; - if (frame <= UPDATE_FRAME) { - if (frame == UPDATE_FRAME) { - if (sitting == true) { - print("Was seated: " + sitting); - storeStartPoseAndTransition(); - updateJoints(1.0); - } - } - frame++; - } - } - - this.addIndicators = function() { - if (!this.indicatorsAdded) { - if (this.properties.sittingPoints.length > 0) { - for (var i = 0; i < this.properties.sittingPoints.length; ++i) { - this.indicator[i] = new SeatIndicator(this.properties, i); - } - this.indicatorsAdded = true; - } - } - } - - this.removeIndicators = function() { - for (var i = 0; i < this.properties.sittingPoints.length; ++i) { - this.indicator[i].cleanup(); - } - } - - this.showIndicators = function(doShow) { - this.addIndicators(); - if (this.indicatorsAdded) { - for (var i = 0; i < this.properties.sittingPoints.length; ++i) { - this.indicator[i].show(doShow); - } - } - hiddingSeats = !doShow; - } - - function raySphereIntersection(origin, direction, center, radius) { - var A = origin; - var B = Vec3.normalize(direction); - var P = center; - - var x = Vec3.dot(Vec3.subtract(P, A), B); - var X = Vec3.sum(A, Vec3.multiply(B, x)); - var d = Vec3.length(Vec3.subtract(P, X)); - - return (x > 0 && d <= radius); - } - - this.cleanup = function() { - this.standUp(); - MyAvatar.clearReferential(); - for (var i = 0; i < pose.length; i++){ - MyAvatar.clearJointData(pose[i].joint); - } - Overlays.deleteOverlay(this.standUpButton); - for (var i = 0; i < this.indicator.length; ++i) { - this.indicator[i].cleanup(); - } - }; - - - this.createStandupButton = function() { - this.standUpButton = Overlays.addOverlay("image", { - x: buttonPositionX, y: buttonPositionY, width: buttonWidth, height: buttonHeight, - subImage: { x: buttonWidth, y: buttonHeight, width: buttonWidth, height: buttonHeight}, - imageURL: buttonImageUrl, - visible: false, - alpha: 1.0 - }); - }; - - this.handleClickEvent = function(event) { - var clickedOverlay = Overlays.getOverlayAtPoint({x: event.x, y: event.y}); - - if (clickedOverlay == this.standUpButton) { - seat.model = null; - this.standUp(); - } else { - this.addIndicators(); - if (this.indicatorsAdded) { - var pickRay = Camera.computePickRay(event.x, event.y); - - var clickedOnSeat = false; - - for (var i = 0; i < this.properties.sittingPoints.length; ++i) { - if (raySphereIntersection(pickRay.origin, - pickRay.direction, - this.indicator[i].position, - this.indicator[i].scale / 2)) { - clickedOnSeat = true; - seat.model = this.entityID; // ?? - seat.position = this.indicator[i].position; - seat.rotation = this.indicator[i].orientation; - } - } - - if (clickedOnSeat) { - passedTime = 0.0; - startPosition = MyAvatar.position; - startRotation = MyAvatar.orientation; - try{ Script.update.disconnect(standingUpAnimation); } catch(e){} - try{ Script.update.disconnect(sittingDownAnimation); } catch(e){} - Script.update.connect(goToSeatAnimation); - } - } - } - }; - - - // All callbacks start by updating the properties - this.updateProperties = function(entityID) { - if (this.entityID === null || !this.entityID.isKnownID) { - this.entityID = Entities.identifyEntity(entityID); - } - this.properties = Entities.getEntityProperties(this.entityID); - }; - - this.unload = function(entityID) { - this.cleanup(); - Script.update.disconnect(update); - }; - - this.preload = function(entityID) { - this.updateProperties(entityID); // All callbacks start by updating the properties - this.createStandupButton(); - Script.update.connect(update); - }; - - - this.hoverOverEntity = function(entityID, mouseEvent) { - this.updateProperties(entityID); // All callbacks start by updating the properties - this.showIndicators(true); - }; - this.hoverLeaveEntity = function(entityID, mouseEvent) { - this.updateProperties(entityID); // All callbacks start by updating the properties - this.showIndicators(false); - }; - - this.clickDownOnEntity = function(entityID, mouseEvent) { - this.updateProperties(entityID); // All callbacks start by updating the properties - this.handleClickEvent(mouseEvent); - }; - - this.clickReleaseOnEntity = function(entityID, mouseEvent) { - this.updateProperties(entityID); // All callbacks start by updating the properties - }; - -}) \ No newline at end of file +(function() { + Script.include("sittableClass.js"); + return new Sittable(); +}) diff --git a/examples/entityScripts/sittable.js b/examples/entityScripts/sittable.js new file mode 100644 index 0000000000..0753a46d2a --- /dev/null +++ b/examples/entityScripts/sittable.js @@ -0,0 +1,15 @@ +// +// sittable.js +// examples/entityScripts +// +// Created by Brad Hefta-Gaub on 11/17/14. +// Copyright 2014 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +(function() { + Script.include("sittableClass.js"); + return new Sittable(); +}) diff --git a/examples/entityScripts/sittableClass.js b/examples/entityScripts/sittableClass.js new file mode 100644 index 0000000000..c16e026f96 --- /dev/null +++ b/examples/entityScripts/sittableClass.js @@ -0,0 +1,381 @@ +// +// sitOnEntity.js +// examples/entityScripts +// +// Created by Brad Hefta-Gaub on 11/1/14. +// Copyright 2014 High Fidelity, Inc. +// +// This is an example of an entity script for sitting. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +Sittable = function() { + + this.entityID = null; + this.properties = null; + this.standUpButton = null; + this.indicatorsAdded = false; + this.indicator = new Array(); + + + var buttonImageUrl = "https://worklist-prod.s3.amazonaws.com/attachment/0aca88e1-9bd8-5c1d.svg"; + var windowDimensions = Controller.getViewportDimensions(); + var buttonWidth = 37; + var buttonHeight = 46; + var buttonPadding = 50; // inside the normal toolbar position + var buttonPositionX = windowDimensions.x - buttonPadding - buttonWidth; + var buttonPositionY = (windowDimensions.y - buttonHeight) / 2 - (buttonHeight + buttonPadding); + + var passedTime = 0.0; + var startPosition = null; + var startRotation = null; + var animationLenght = 2.0; + + var avatarOldPosition = { x: 0, y: 0, z: 0 }; + + var sittingSettingsHandle = "SitJsSittingPosition"; + var sitting = Settings.getValue(sittingSettingsHandle, false) == "true"; + print("Original sitting status: " + sitting); + var frame = 0; + + var seat = new Object(); + var hiddingSeats = false; + + // This is the pose we would like to end up + var pose = [ + {joint:"RightUpLeg", rotation: {x:100.0, y:15.0, z:0.0}}, + {joint:"RightLeg", rotation: {x:-130.0, y:15.0, z:0.0}}, + {joint:"RightFoot", rotation: {x:30, y:15.0, z:0.0}}, + {joint:"LeftUpLeg", rotation: {x:100.0, y:-15.0, z:0.0}}, + {joint:"LeftLeg", rotation: {x:-130.0, y:-15.0, z:0.0}}, + {joint:"LeftFoot", rotation: {x:30, y:15.0, z:0.0}} + ]; + + var startPoseAndTransition = []; + + function storeStartPoseAndTransition() { + for (var i = 0; i < pose.length; i++){ + var startRotation = Quat.safeEulerAngles(MyAvatar.getJointRotation(pose[i].joint)); + var transitionVector = Vec3.subtract( pose[i].rotation, startRotation ); + startPoseAndTransition.push({joint: pose[i].joint, start: startRotation, transition: transitionVector}); + } + } + + function updateJoints(factor){ + for (var i = 0; i < startPoseAndTransition.length; i++){ + var scaledTransition = Vec3.multiply(startPoseAndTransition[i].transition, factor); + var rotation = Vec3.sum(startPoseAndTransition[i].start, scaledTransition); + MyAvatar.setJointData(startPoseAndTransition[i].joint, Quat.fromVec3Degrees( rotation )); + } + } + + var sittingDownAnimation = function(deltaTime) { + + passedTime += deltaTime; + var factor = passedTime/animationLenght; + + if ( passedTime <= animationLenght ) { + updateJoints(factor); + + var pos = { x: startPosition.x - 0.3 * factor, y: startPosition.y - 0.5 * factor, z: startPosition.z}; + MyAvatar.position = pos; + } else { + Script.update.disconnect(sittingDownAnimation); + if (seat.model) { + MyAvatar.setModelReferential(seat.model.id); + } + } + } + + var standingUpAnimation = function(deltaTime) { + + passedTime += deltaTime; + var factor = 1 - passedTime/animationLenght; + + if ( passedTime <= animationLenght ) { + + updateJoints(factor); + + var pos = { x: startPosition.x + 0.3 * (passedTime/animationLenght), y: startPosition.y + 0.5 * (passedTime/animationLenght), z: startPosition.z}; + MyAvatar.position = pos; + } else { + Script.update.disconnect(standingUpAnimation); + + } + } + + var externalThis = this; + + var goToSeatAnimation = function(deltaTime) { + passedTime += deltaTime; + var factor = passedTime/animationLenght; + + if (passedTime <= animationLenght) { + var targetPosition = Vec3.sum(seat.position, { x: 0.3, y: 0.5, z: 0 }); + MyAvatar.position = Vec3.sum(Vec3.multiply(startPosition, 1 - factor), Vec3.multiply(targetPosition, factor)); + } else if (passedTime <= 2 * animationLenght) { + //Quat.print("MyAvatar: ", MyAvatar.orientation); + //Quat.print("Seat: ", seat.rotation); + MyAvatar.orientation = Quat.mix(startRotation, seat.rotation, factor - 1); + } else { + Script.update.disconnect(goToSeatAnimation); + externalThis.sitDown(); + externalThis.showIndicators(false); + } + } + + var globalMouseClick = function(event) { + var clickedOverlay = Overlays.getOverlayAtPoint({x: event.x, y: event.y}); + if (clickedOverlay == externalThis.standUpButton) { + seat.model = null; + externalThis.standUp(); + Controller.mousePressEvent.disconnect(globalMouseClick); + } + }; + + this.sitDown = function() { + sitting = true; + Settings.setValue(sittingSettingsHandle, sitting); + print("sitDown sitting status: " + Settings.getValue(sittingSettingsHandle, false)); + passedTime = 0.0; + startPosition = MyAvatar.position; + storeStartPoseAndTransition(); + try { + Script.update.disconnect(standingUpAnimation); + } catch(e){ + // no need to handle. if it wasn't connected no harm done + } + Script.update.connect(sittingDownAnimation); + Overlays.editOverlay(this.standUpButton, { visible: true }); + Controller.mousePressEvent.connect(globalMouseClick); + } + + this.standUp = function() { + sitting = false; + Settings.setValue(sittingSettingsHandle, sitting); + print("standUp sitting status: " + Settings.getValue(sittingSettingsHandle, false)); + passedTime = 0.0; + startPosition = MyAvatar.position; + MyAvatar.clearReferential(); + try{ + Script.update.disconnect(sittingDownAnimation); + } catch (e){} + Script.update.connect(standingUpAnimation); + Overlays.editOverlay(this.standUpButton, { visible: false }); + Controller.mousePressEvent.disconnect(globalMouseClick); + } + + function SeatIndicator(modelProperties, seatIndex) { + var halfDiagonal = Vec3.length(modelProperties.dimensions) / 2.0; + + this.position = Vec3.sum(modelProperties.position, + Vec3.multiply(Vec3.multiplyQbyV(modelProperties.rotation, modelProperties.sittingPoints[seatIndex].position), + halfDiagonal)); // hack + + this.orientation = Quat.multiply(modelProperties.rotation, + modelProperties.sittingPoints[seatIndex].rotation); + this.scale = MyAvatar.scale / 3; + + this.sphere = Overlays.addOverlay("billboard", { + subImage: { x: 0, y: buttonHeight, width: buttonWidth, height: buttonHeight}, + url: buttonImageUrl, + position: this.position, + scale: this.scale, + size: this.scale, + solid: true, + color: { red: 255, green: 255, blue: 255 }, + alpha: 0.8, + visible: true, + isFacingAvatar: true + }); + + this.show = function(doShow) { + Overlays.editOverlay(this.sphere, { visible: doShow }); + } + + this.update = function() { + Overlays.editOverlay(this.sphere, { + position: this.position, + size: this.scale + }); + } + + this.cleanup = function() { + Overlays.deleteOverlay(this.sphere); + } + } + + function update(deltaTime){ + var newWindowDimensions = Controller.getViewportDimensions(); + if( newWindowDimensions.x != windowDimensions.x || newWindowDimensions.y != windowDimensions.y ){ + windowDimensions = newWindowDimensions; + var newX = windowDimensions.x - buttonPadding - buttonWidth; + var newY = (windowDimensions.y - buttonHeight) / 2 ; + Overlays.editOverlay( this.standUpButton, {x: newX, y: newY} ); + } + + // For a weird reason avatar joint don't update till the 10th frame + // Set the update frame to 20 to be safe + var UPDATE_FRAME = 20; + if (frame <= UPDATE_FRAME) { + if (frame == UPDATE_FRAME) { + if (sitting == true) { + print("Was seated: " + sitting); + storeStartPoseAndTransition(); + updateJoints(1.0); + } + } + frame++; + } + } + + this.addIndicators = function() { + if (!this.indicatorsAdded) { + if (this.properties.sittingPoints.length > 0) { + for (var i = 0; i < this.properties.sittingPoints.length; ++i) { + this.indicator[i] = new SeatIndicator(this.properties, i); + } + this.indicatorsAdded = true; + } + } + } + + this.removeIndicators = function() { + for (var i = 0; i < this.properties.sittingPoints.length; ++i) { + this.indicator[i].cleanup(); + } + } + + this.showIndicators = function(doShow) { + this.addIndicators(); + if (this.indicatorsAdded) { + for (var i = 0; i < this.properties.sittingPoints.length; ++i) { + this.indicator[i].show(doShow); + } + } + hiddingSeats = !doShow; + } + + function raySphereIntersection(origin, direction, center, radius) { + var A = origin; + var B = Vec3.normalize(direction); + var P = center; + + var x = Vec3.dot(Vec3.subtract(P, A), B); + var X = Vec3.sum(A, Vec3.multiply(B, x)); + var d = Vec3.length(Vec3.subtract(P, X)); + + return (x > 0 && d <= radius); + } + + this.cleanup = function() { + this.standUp(); + MyAvatar.clearReferential(); + for (var i = 0; i < pose.length; i++){ + MyAvatar.clearJointData(pose[i].joint); + } + Overlays.deleteOverlay(this.standUpButton); + for (var i = 0; i < this.indicator.length; ++i) { + this.indicator[i].cleanup(); + } + }; + + + this.createStandupButton = function() { + this.standUpButton = Overlays.addOverlay("image", { + x: buttonPositionX, y: buttonPositionY, width: buttonWidth, height: buttonHeight, + subImage: { x: buttonWidth, y: buttonHeight, width: buttonWidth, height: buttonHeight}, + imageURL: buttonImageUrl, + visible: false, + alpha: 1.0 + }); + }; + + this.handleClickEvent = function(event) { + var clickedOverlay = Overlays.getOverlayAtPoint({x: event.x, y: event.y}); + + if (clickedOverlay == this.standUpButton) { + seat.model = null; + this.standUp(); + } else { + this.addIndicators(); + if (this.indicatorsAdded) { + var pickRay = Camera.computePickRay(event.x, event.y); + + var clickedOnSeat = false; + + for (var i = 0; i < this.properties.sittingPoints.length; ++i) { + if (raySphereIntersection(pickRay.origin, + pickRay.direction, + this.indicator[i].position, + this.indicator[i].scale / 2)) { + clickedOnSeat = true; + seat.model = this.entityID; // ?? + seat.position = this.indicator[i].position; + seat.rotation = this.indicator[i].orientation; + } + } + + if (clickedOnSeat) { + passedTime = 0.0; + startPosition = MyAvatar.position; + startRotation = MyAvatar.orientation; + try{ Script.update.disconnect(standingUpAnimation); } catch(e){} + try{ Script.update.disconnect(sittingDownAnimation); } catch(e){} + Script.update.connect(goToSeatAnimation); + } + } + } + }; + + + // All callbacks start by updating the properties + this.updateProperties = function(entityID) { + if (this.entityID === null || !this.entityID.isKnownID) { + this.entityID = Entities.identifyEntity(entityID); + } + this.properties = Entities.getEntityProperties(this.entityID); + }; +}; + +Sittable.prototype = { + + unload : function(entityID) { + print("Sittable.unload()"); + this.cleanup(); + //Script.update.disconnect(update); + }, + + preload : function(entityID) { + print("Sittable.preload()"); + this.updateProperties(entityID); // All callbacks start by updating the properties + this.createStandupButton(); + //Script.update.connect(update); + }, + + + hoverOverEntity : function(entityID, mouseEvent) { + print("Sittable.hoverOverEntity()"); + this.updateProperties(entityID); // All callbacks start by updating the properties + this.showIndicators(true); + }, + + hoverLeaveEntity : function(entityID, mouseEvent) { + print("Sittable.hoverLeaveEntity()"); + this.updateProperties(entityID); // All callbacks start by updating the properties + this.showIndicators(false); + }, + + clickDownOnEntity : function(entityID, mouseEvent) { + print("Sittable.clickDownOnEntity()"); + this.updateProperties(entityID); // All callbacks start by updating the properties + this.handleClickEvent(mouseEvent); + }, + + clickReleaseOnEntity : function(entityID, mouseEvent) { + print("Sittable.clickReleaseOnEntity()"); + this.updateProperties(entityID); // All callbacks start by updating the properties + } +}; \ No newline at end of file From a95b6dbabd904b220b57cca5ec24b775929fa07d Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Sun, 23 Nov 2014 20:36:33 -0800 Subject: [PATCH 03/33] hacking on global functions --- examples/entityScripts/sittableClass.js | 62 ++++++++++++++----------- 1 file changed, 36 insertions(+), 26 deletions(-) diff --git a/examples/entityScripts/sittableClass.js b/examples/entityScripts/sittableClass.js index c16e026f96..591b7515cb 100644 --- a/examples/entityScripts/sittableClass.js +++ b/examples/entityScripts/sittableClass.js @@ -11,6 +11,40 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // +var activeSittable = null; +function SittableUpdate(deltaTime){ + + // This keeps the standup button in a reasonable place. + var newWindowDimensions = Controller.getViewportDimensions(); + if( newWindowDimensions.x != windowDimensions.x || newWindowDimensions.y != windowDimensions.y ){ + windowDimensions = newWindowDimensions; + var newX = windowDimensions.x - buttonPadding - buttonWidth; + var newY = (windowDimensions.y - buttonHeight) / 2 ; + Overlays.editOverlay( activeSittable.standUpButton, {x: newX, y: newY} ); + } + + + // this appears to be some logic related to storing the original position + /* + + // For a weird reason avatar joint don't update till the 10th frame + // Set the update frame to 20 to be safe + var UPDATE_FRAME = 20; + if (frame <= UPDATE_FRAME) { + if (frame == UPDATE_FRAME) { + if (sitting == true) { + print("Was seated: " + sitting); + activeSittable.storeStartPoseAndTransition(); + activeSittable.updateJoints(1.0); + } + } + frame++; + } + */ +} + + + Sittable = function() { this.entityID = null; @@ -207,30 +241,6 @@ Sittable = function() { } } - function update(deltaTime){ - var newWindowDimensions = Controller.getViewportDimensions(); - if( newWindowDimensions.x != windowDimensions.x || newWindowDimensions.y != windowDimensions.y ){ - windowDimensions = newWindowDimensions; - var newX = windowDimensions.x - buttonPadding - buttonWidth; - var newY = (windowDimensions.y - buttonHeight) / 2 ; - Overlays.editOverlay( this.standUpButton, {x: newX, y: newY} ); - } - - // For a weird reason avatar joint don't update till the 10th frame - // Set the update frame to 20 to be safe - var UPDATE_FRAME = 20; - if (frame <= UPDATE_FRAME) { - if (frame == UPDATE_FRAME) { - if (sitting == true) { - print("Was seated: " + sitting); - storeStartPoseAndTransition(); - updateJoints(1.0); - } - } - frame++; - } - } - this.addIndicators = function() { if (!this.indicatorsAdded) { if (this.properties.sittingPoints.length > 0) { @@ -345,14 +355,14 @@ Sittable.prototype = { unload : function(entityID) { print("Sittable.unload()"); this.cleanup(); - //Script.update.disconnect(update); + //Script.update.disconnect(SittableUpdate); }, preload : function(entityID) { print("Sittable.preload()"); this.updateProperties(entityID); // All callbacks start by updating the properties this.createStandupButton(); - //Script.update.connect(update); + //Script.update.connect(SittableUpdate); }, From 345735fa8c33df7c437638426eb1e578b7504b14 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Sun, 23 Nov 2014 20:50:39 -0800 Subject: [PATCH 04/33] tweaks --- examples/entityScripts/sittableClass.js | 100 ++++++++++++------------ 1 file changed, 51 insertions(+), 49 deletions(-) diff --git a/examples/entityScripts/sittableClass.js b/examples/entityScripts/sittableClass.js index 591b7515cb..1a7b1df25a 100644 --- a/examples/entityScripts/sittableClass.js +++ b/examples/entityScripts/sittableClass.js @@ -43,7 +43,49 @@ function SittableUpdate(deltaTime){ */ } +SeatIndicator = function(modelProperties, seatIndex) { + var buttonImageUrl = "https://worklist-prod.s3.amazonaws.com/attachment/0aca88e1-9bd8-5c1d.svg"; + var buttonWidth = 37; + var buttonHeight = 46; + var halfDiagonal = Vec3.length(modelProperties.dimensions) / 2.0; + + this.position = Vec3.sum(modelProperties.position, + Vec3.multiply(Vec3.multiplyQbyV(modelProperties.rotation, modelProperties.sittingPoints[seatIndex].position), + halfDiagonal)); // hack + + this.orientation = Quat.multiply(modelProperties.rotation, + modelProperties.sittingPoints[seatIndex].rotation); + this.scale = MyAvatar.scale / 3; + + this.sphere = Overlays.addOverlay("billboard", { + subImage: { x: 0, y: buttonHeight, width: buttonWidth, height: buttonHeight}, + url: buttonImageUrl, + position: this.position, + scale: this.scale, + size: this.scale, + solid: true, + color: { red: 255, green: 255, blue: 255 }, + alpha: 0.8, + visible: true, + isFacingAvatar: true + }); + + this.show = function(doShow) { + Overlays.editOverlay(this.sphere, { visible: doShow }); + } + + this.update = function() { + Overlays.editOverlay(this.sphere, { + position: this.position, + size: this.scale + }); + } + + this.cleanup = function() { + Overlays.deleteOverlay(this.sphere); + } +}; Sittable = function() { @@ -65,7 +107,7 @@ Sittable = function() { var passedTime = 0.0; var startPosition = null; var startRotation = null; - var animationLenght = 2.0; + var animationLength = 2.0; var avatarOldPosition = { x: 0, y: 0, z: 0 }; @@ -108,9 +150,9 @@ Sittable = function() { var sittingDownAnimation = function(deltaTime) { passedTime += deltaTime; - var factor = passedTime/animationLenght; + var factor = passedTime/animationLength; - if ( passedTime <= animationLenght ) { + if ( passedTime <= animationLength ) { updateJoints(factor); var pos = { x: startPosition.x - 0.3 * factor, y: startPosition.y - 0.5 * factor, z: startPosition.z}; @@ -126,13 +168,13 @@ Sittable = function() { var standingUpAnimation = function(deltaTime) { passedTime += deltaTime; - var factor = 1 - passedTime/animationLenght; + var factor = 1 - passedTime/animationLength; - if ( passedTime <= animationLenght ) { + if ( passedTime <= animationLength ) { updateJoints(factor); - var pos = { x: startPosition.x + 0.3 * (passedTime/animationLenght), y: startPosition.y + 0.5 * (passedTime/animationLenght), z: startPosition.z}; + var pos = { x: startPosition.x + 0.3 * (passedTime/animationLength), y: startPosition.y + 0.5 * (passedTime/animationLength), z: startPosition.z}; MyAvatar.position = pos; } else { Script.update.disconnect(standingUpAnimation); @@ -144,12 +186,12 @@ Sittable = function() { var goToSeatAnimation = function(deltaTime) { passedTime += deltaTime; - var factor = passedTime/animationLenght; + var factor = passedTime/animationLength; - if (passedTime <= animationLenght) { + if (passedTime <= animationLength) { var targetPosition = Vec3.sum(seat.position, { x: 0.3, y: 0.5, z: 0 }); MyAvatar.position = Vec3.sum(Vec3.multiply(startPosition, 1 - factor), Vec3.multiply(targetPosition, factor)); - } else if (passedTime <= 2 * animationLenght) { + } else if (passedTime <= 2 * animationLength) { //Quat.print("MyAvatar: ", MyAvatar.orientation); //Quat.print("Seat: ", seat.rotation); MyAvatar.orientation = Quat.mix(startRotation, seat.rotation, factor - 1); @@ -201,46 +243,6 @@ Sittable = function() { Controller.mousePressEvent.disconnect(globalMouseClick); } - function SeatIndicator(modelProperties, seatIndex) { - var halfDiagonal = Vec3.length(modelProperties.dimensions) / 2.0; - - this.position = Vec3.sum(modelProperties.position, - Vec3.multiply(Vec3.multiplyQbyV(modelProperties.rotation, modelProperties.sittingPoints[seatIndex].position), - halfDiagonal)); // hack - - this.orientation = Quat.multiply(modelProperties.rotation, - modelProperties.sittingPoints[seatIndex].rotation); - this.scale = MyAvatar.scale / 3; - - this.sphere = Overlays.addOverlay("billboard", { - subImage: { x: 0, y: buttonHeight, width: buttonWidth, height: buttonHeight}, - url: buttonImageUrl, - position: this.position, - scale: this.scale, - size: this.scale, - solid: true, - color: { red: 255, green: 255, blue: 255 }, - alpha: 0.8, - visible: true, - isFacingAvatar: true - }); - - this.show = function(doShow) { - Overlays.editOverlay(this.sphere, { visible: doShow }); - } - - this.update = function() { - Overlays.editOverlay(this.sphere, { - position: this.position, - size: this.scale - }); - } - - this.cleanup = function() { - Overlays.deleteOverlay(this.sphere); - } - } - this.addIndicators = function() { if (!this.indicatorsAdded) { if (this.properties.sittingPoints.length > 0) { From 6beaa3d59a061ee9f111668ee7c90a32f9eb6c95 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Thu, 18 Dec 2014 14:36:15 -0800 Subject: [PATCH 05/33] set policy for shared lib creation on OS X --- CMakeLists.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7a6118bb87..a0d463b766 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,6 +12,10 @@ if (POLICY CMP0043) cmake_policy(SET CMP0043 OLD) endif () +if (POLICY CMP0042) + cmake_policy(SET CMP0042 OLD) +endif () + project(hifi) add_definitions(-DGLM_FORCE_RADIANS) From 6a604ca340f24d514fccdd9f83c776ad43d98f98 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Thu, 18 Dec 2014 14:36:31 -0800 Subject: [PATCH 06/33] fix missing script dependency from shared --- libraries/shared/CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libraries/shared/CMakeLists.txt b/libraries/shared/CMakeLists.txt index 17ccbdc6ce..b5a44c96e2 100644 --- a/libraries/shared/CMakeLists.txt +++ b/libraries/shared/CMakeLists.txt @@ -1,7 +1,8 @@ set(TARGET_NAME shared) # use setup_hifi_library macro to setup our project and link appropriate Qt modules -setup_hifi_library(Network Widgets) +# 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(Network Script Widgets) # call macro to link our dependencies and bubble them up via a property on our target link_shared_dependencies() \ No newline at end of file From ecb17a61d6c7609b218ff92e8bad03a62d404223 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Thu, 18 Dec 2014 14:39:35 -0800 Subject: [PATCH 07/33] fix missing render-utils dependencies --- libraries/render-utils/CMakeLists.txt | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/libraries/render-utils/CMakeLists.txt b/libraries/render-utils/CMakeLists.txt index a6943addcc..881a75636b 100644 --- a/libraries/render-utils/CMakeLists.txt +++ b/libraries/render-utils/CMakeLists.txt @@ -5,11 +5,15 @@ setup_hifi_library(Widgets OpenGL Network Script) include_glm() -link_hifi_libraries(shared gpu) +link_hifi_libraries(fbx shared gpu) -if (WIN32) +if (APPLE) + find_library(GLUT GLUT) + target_link_libraries(${TARGET_NAME} GLUT) +else () find_package(GLUT REQUIRED) include_directories(SYSTEM "${GLUT_INCLUDE_DIRS}") + target_link_libraries(${TARGET_NAME} ${GLUT_LIBRARIES}) endif () # call macro to link our dependencies and bubble them up via a property on our target From 1b5552de1a9e2f0225cde7faf7a4a70284c520b2 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Thu, 18 Dec 2014 14:42:08 -0800 Subject: [PATCH 08/33] fix GLUT library link in render-utils --- libraries/render-utils/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/render-utils/CMakeLists.txt b/libraries/render-utils/CMakeLists.txt index 881a75636b..4108462000 100644 --- a/libraries/render-utils/CMakeLists.txt +++ b/libraries/render-utils/CMakeLists.txt @@ -9,7 +9,7 @@ link_hifi_libraries(fbx shared gpu) if (APPLE) find_library(GLUT GLUT) - target_link_libraries(${TARGET_NAME} GLUT) + target_link_libraries(${TARGET_NAME} ${GLUT}) else () find_package(GLUT REQUIRED) include_directories(SYSTEM "${GLUT_INCLUDE_DIRS}") From 4f4ffc42d35d269ce871d25146edc86eb5829726 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Thu, 18 Dec 2014 14:52:16 -0800 Subject: [PATCH 09/33] add missing link to fbx from avatars --- libraries/avatars/CMakeLists.txt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/libraries/avatars/CMakeLists.txt b/libraries/avatars/CMakeLists.txt index 42b3cf7d3c..20aba226e0 100644 --- a/libraries/avatars/CMakeLists.txt +++ b/libraries/avatars/CMakeLists.txt @@ -5,8 +5,7 @@ setup_hifi_library(Network Script) include_glm() -link_hifi_libraries(shared octree voxels networking physics) -include_hifi_library_headers(fbx) +link_hifi_libraries(audio shared octree voxels networking physics fbx) # call macro to link our dependencies and bubble them up via a property on our target link_shared_dependencies() From e8adc19ac67088c386b56b21c528925829a04644 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Thu, 18 Dec 2014 14:52:31 -0800 Subject: [PATCH 10/33] fix more missing dependencies in render-utils --- libraries/render-utils/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/render-utils/CMakeLists.txt b/libraries/render-utils/CMakeLists.txt index 4108462000..211c7266b3 100644 --- a/libraries/render-utils/CMakeLists.txt +++ b/libraries/render-utils/CMakeLists.txt @@ -5,7 +5,7 @@ setup_hifi_library(Widgets OpenGL Network Script) include_glm() -link_hifi_libraries(fbx shared gpu) +link_hifi_libraries(animation fbx shared gpu) if (APPLE) find_library(GLUT GLUT) From 4bd3a94794ba8352c4dbc69227455587dd5bd7cb Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Thu, 18 Dec 2014 14:53:52 -0800 Subject: [PATCH 11/33] add missing avatars link to entities --- libraries/entities/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/entities/CMakeLists.txt b/libraries/entities/CMakeLists.txt index e48baa7615..d6f503f2ca 100644 --- a/libraries/entities/CMakeLists.txt +++ b/libraries/entities/CMakeLists.txt @@ -5,7 +5,7 @@ setup_hifi_library(Network Script) include_glm() -link_hifi_libraries(shared octree fbx networking animation physics) +link_hifi_libraries(avatars shared octree fbx networking animation physics) # call macro to link our dependencies and bubble them up via a property on our target link_shared_dependencies() From d87e06a9d36ff91f51905f05749c74c55e6ec3f2 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Thu, 18 Dec 2014 14:54:05 -0800 Subject: [PATCH 12/33] add missing metavoxels link to script-engine --- libraries/script-engine/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/script-engine/CMakeLists.txt b/libraries/script-engine/CMakeLists.txt index 3b3a63549d..7118e84443 100644 --- a/libraries/script-engine/CMakeLists.txt +++ b/libraries/script-engine/CMakeLists.txt @@ -5,7 +5,7 @@ setup_hifi_library(Gui Network Script Widgets) include_glm() -link_hifi_libraries(shared octree voxels fbx entities animation audio physics) +link_hifi_libraries(shared octree voxels fbx entities animation audio physics metavoxels) # call macro to link our dependencies and bubble them up via a property on our target link_shared_dependencies() From f474cfc9d0e89abf3ec52758582db575e08514da Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Thu, 18 Dec 2014 15:06:44 -0800 Subject: [PATCH 13/33] link to render-utils from entities renderer --- libraries/entities-renderer/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/entities-renderer/CMakeLists.txt b/libraries/entities-renderer/CMakeLists.txt index 1e77afe544..3b8a214675 100644 --- a/libraries/entities-renderer/CMakeLists.txt +++ b/libraries/entities-renderer/CMakeLists.txt @@ -5,7 +5,7 @@ setup_hifi_library(Widgets OpenGL Network Script) include_glm() -link_hifi_libraries(shared gpu script-engine) +link_hifi_libraries(shared gpu script-engine render-utils) # call macro to link our dependencies and bubble them up via a property on our target link_shared_dependencies() From 114e3bb2ff27ea5e8f9ac67e29cf5ac78c64e60e Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Thu, 18 Dec 2014 16:51:20 -0800 Subject: [PATCH 14/33] rename cmake macro to represent actual purpose --- assignment-client/CMakeLists.txt | 2 +- ...edDependencies.cmake => IncludeDependencyIncludes.cmake} | 6 +++--- domain-server/CMakeLists.txt | 2 +- ice-server/CMakeLists.txt | 2 +- interface/CMakeLists.txt | 2 +- libraries/animation/CMakeLists.txt | 4 ++-- libraries/audio/CMakeLists.txt | 4 ++-- libraries/avatars/CMakeLists.txt | 4 ++-- libraries/embedded-webserver/CMakeLists.txt | 4 ++-- libraries/entities-renderer/CMakeLists.txt | 4 ++-- libraries/entities/CMakeLists.txt | 4 ++-- libraries/fbx/CMakeLists.txt | 4 ++-- libraries/gpu/CMakeLists.txt | 4 ++-- libraries/metavoxels/CMakeLists.txt | 4 ++-- libraries/networking/CMakeLists.txt | 4 ++-- libraries/octree/CMakeLists.txt | 4 ++-- libraries/physics/CMakeLists.txt | 4 ++-- libraries/render-utils/CMakeLists.txt | 4 ++-- libraries/script-engine/CMakeLists.txt | 4 ++-- libraries/shared/CMakeLists.txt | 4 ++-- libraries/voxels/CMakeLists.txt | 4 ++-- tests/audio/CMakeLists.txt | 2 +- tests/jitter/CMakeLists.txt | 2 +- tests/metavoxels/CMakeLists.txt | 2 +- tests/networking/CMakeLists.txt | 2 +- tests/octree/CMakeLists.txt | 2 +- tests/physics/CMakeLists.txt | 2 +- tests/shared/CMakeLists.txt | 2 +- tools/bitstream2json/CMakeLists.txt | 2 +- tools/json2bitstream/CMakeLists.txt | 2 +- tools/mtc/CMakeLists.txt | 2 +- 31 files changed, 49 insertions(+), 49 deletions(-) rename cmake/macros/{LinkSharedDependencies.cmake => IncludeDependencyIncludes.cmake} (86%) diff --git a/assignment-client/CMakeLists.txt b/assignment-client/CMakeLists.txt index 6e31182f0d..88b2b62bd9 100644 --- a/assignment-client/CMakeLists.txt +++ b/assignment-client/CMakeLists.txt @@ -15,4 +15,4 @@ if (UNIX) target_link_libraries(${TARGET_NAME} ${CMAKE_DL_LIBS}) endif (UNIX) -link_shared_dependencies() +include_dependency_includes() diff --git a/cmake/macros/LinkSharedDependencies.cmake b/cmake/macros/IncludeDependencyIncludes.cmake similarity index 86% rename from cmake/macros/LinkSharedDependencies.cmake rename to cmake/macros/IncludeDependencyIncludes.cmake index 9168c5a921..a375404164 100644 --- a/cmake/macros/LinkSharedDependencies.cmake +++ b/cmake/macros/IncludeDependencyIncludes.cmake @@ -1,5 +1,5 @@ # -# LinkSharedDependencies.cmake +# IncludeDependencyIncludes.cmake # cmake/macros # # Copyright 2014 High Fidelity, Inc. @@ -9,7 +9,7 @@ # See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html # -macro(LINK_SHARED_DEPENDENCIES) +macro(INCLUDE_DEPENDENCY_INCLUDES) if (${TARGET_NAME}_DEPENDENCY_INCLUDES) list(REMOVE_DUPLICATES ${TARGET_NAME}_DEPENDENCY_INCLUDES) @@ -19,4 +19,4 @@ macro(LINK_SHARED_DEPENDENCIES) # set the property on this target so it can be retreived by targets linking to us set_target_properties(${TARGET_NAME} PROPERTIES DEPENDENCY_INCLUDES "${${TARGET_NAME}_DEPENDENCY_INCLUDES}") -endmacro(LINK_SHARED_DEPENDENCIES) \ No newline at end of file +endmacro(INCLUDE_DEPENDENCY_INCLUDES) \ No newline at end of file diff --git a/domain-server/CMakeLists.txt b/domain-server/CMakeLists.txt index 482c397b14..421a1da2d4 100644 --- a/domain-server/CMakeLists.txt +++ b/domain-server/CMakeLists.txt @@ -52,4 +52,4 @@ include_directories(SYSTEM "${OPENSSL_INCLUDE_DIR}") # append OpenSSL to our list of libraries to link target_link_libraries(${TARGET_NAME} ${OPENSSL_LIBRARIES}) -link_shared_dependencies() \ No newline at end of file +include_dependency_includes() \ No newline at end of file diff --git a/ice-server/CMakeLists.txt b/ice-server/CMakeLists.txt index c81ba16248..24e780f9aa 100644 --- a/ice-server/CMakeLists.txt +++ b/ice-server/CMakeLists.txt @@ -6,4 +6,4 @@ setup_hifi_project(Network) # link the shared hifi libraries link_hifi_libraries(networking shared) -link_shared_dependencies() \ No newline at end of file +include_dependency_includes() \ No newline at end of file diff --git a/interface/CMakeLists.txt b/interface/CMakeLists.txt index a9688a5919..659ecf600f 100644 --- a/interface/CMakeLists.txt +++ b/interface/CMakeLists.txt @@ -246,4 +246,4 @@ else (APPLE) endif (APPLE) # link any dependencies bubbled up from our linked dependencies -link_shared_dependencies() +include_dependency_includes() diff --git a/libraries/animation/CMakeLists.txt b/libraries/animation/CMakeLists.txt index 3f65c1ab6c..d7cbe43e28 100644 --- a/libraries/animation/CMakeLists.txt +++ b/libraries/animation/CMakeLists.txt @@ -5,5 +5,5 @@ setup_hifi_library(Network Script) link_hifi_libraries(shared fbx) -# call macro to link our dependencies and bubble them up via a property on our target -link_shared_dependencies() \ No newline at end of file +# 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 diff --git a/libraries/audio/CMakeLists.txt b/libraries/audio/CMakeLists.txt index 6ade1fc423..b08d9e88f4 100644 --- a/libraries/audio/CMakeLists.txt +++ b/libraries/audio/CMakeLists.txt @@ -7,5 +7,5 @@ include_glm() link_hifi_libraries(networking shared) -# call macro to link our dependencies and bubble them up via a property on our target -link_shared_dependencies() \ No newline at end of file +# 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 diff --git a/libraries/avatars/CMakeLists.txt b/libraries/avatars/CMakeLists.txt index 20aba226e0..69d0f23717 100644 --- a/libraries/avatars/CMakeLists.txt +++ b/libraries/avatars/CMakeLists.txt @@ -7,5 +7,5 @@ include_glm() link_hifi_libraries(audio shared octree voxels networking physics fbx) -# call macro to link our dependencies and bubble them up via a property on our target -link_shared_dependencies() +# call macro to include our dependency includes and bubble them up via a property on our target +include_dependency_includes() diff --git a/libraries/embedded-webserver/CMakeLists.txt b/libraries/embedded-webserver/CMakeLists.txt index 6e4b92e217..ef2cf1054c 100644 --- a/libraries/embedded-webserver/CMakeLists.txt +++ b/libraries/embedded-webserver/CMakeLists.txt @@ -3,5 +3,5 @@ set(TARGET_NAME embedded-webserver) # use setup_hifi_library macro to setup our project and link appropriate Qt modules setup_hifi_library(Network) -# call macro to link our dependencies and bubble them up via a property on our target -link_shared_dependencies() \ No newline at end of file +# 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 diff --git a/libraries/entities-renderer/CMakeLists.txt b/libraries/entities-renderer/CMakeLists.txt index 3b8a214675..6d7f5ee960 100644 --- a/libraries/entities-renderer/CMakeLists.txt +++ b/libraries/entities-renderer/CMakeLists.txt @@ -7,5 +7,5 @@ include_glm() link_hifi_libraries(shared gpu script-engine render-utils) -# call macro to link our dependencies and bubble them up via a property on our target -link_shared_dependencies() +# call macro to include our dependency includes and bubble them up via a property on our target +include_dependency_includes() diff --git a/libraries/entities/CMakeLists.txt b/libraries/entities/CMakeLists.txt index d6f503f2ca..10aba41ebb 100644 --- a/libraries/entities/CMakeLists.txt +++ b/libraries/entities/CMakeLists.txt @@ -7,5 +7,5 @@ include_glm() link_hifi_libraries(avatars shared octree fbx networking animation physics) -# call macro to link our dependencies and bubble them up via a property on our target -link_shared_dependencies() +# call macro to include our dependency includes and bubble them up via a property on our target +include_dependency_includes() diff --git a/libraries/fbx/CMakeLists.txt b/libraries/fbx/CMakeLists.txt index 5a151deb8b..4f4cb6eb76 100644 --- a/libraries/fbx/CMakeLists.txt +++ b/libraries/fbx/CMakeLists.txt @@ -11,5 +11,5 @@ find_package(ZLIB REQUIRED) include_directories(SYSTEM "${ZLIB_INCLUDE_DIRS}") target_link_libraries(${TARGET_NAME} ${ZLIB_LIBRARIES}) -# call macro to link our dependencies and bubble them up via a property on our target -link_shared_dependencies() +# call macro to include our dependency includes and bubble them up via a property on our target +include_dependency_includes() diff --git a/libraries/gpu/CMakeLists.txt b/libraries/gpu/CMakeLists.txt index 340adcc9e6..1264c1bf5c 100644 --- a/libraries/gpu/CMakeLists.txt +++ b/libraries/gpu/CMakeLists.txt @@ -44,5 +44,5 @@ else () list(APPEND ${TARGET_NAME}_DEPENDENCY_INCLUDES "${OPENGL_INCLUDE_DIR}") endif (APPLE) -# call macro to link our dependencies and bubble them up via a property on our target -link_shared_dependencies() +# call macro to include our dependency includes and bubble them up via a property on our target +include_dependency_includes() diff --git a/libraries/metavoxels/CMakeLists.txt b/libraries/metavoxels/CMakeLists.txt index aab8d2184d..4ead36e51a 100644 --- a/libraries/metavoxels/CMakeLists.txt +++ b/libraries/metavoxels/CMakeLists.txt @@ -10,5 +10,5 @@ link_hifi_libraries(shared networking) include_glm() -# call macro to link our dependencies and bubble them up via a property on our target -link_shared_dependencies() \ No newline at end of file +# 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 diff --git a/libraries/networking/CMakeLists.txt b/libraries/networking/CMakeLists.txt index 934e3e69b9..bc251a42d4 100644 --- a/libraries/networking/CMakeLists.txt +++ b/libraries/networking/CMakeLists.txt @@ -28,5 +28,5 @@ target_link_libraries(${TARGET_NAME} ${OPENSSL_LIBRARIES} ${TBB_LIBRARIES}) # append libcuckoo includes to our list of includes to bubble list(APPEND ${TARGET_NAME}_DEPENDENCY_INCLUDES "${TBB_INCLUDE_DIRS}") -# call macro to link our dependencies and bubble them up via a property on our target -link_shared_dependencies() \ No newline at end of file +# 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 diff --git a/libraries/octree/CMakeLists.txt b/libraries/octree/CMakeLists.txt index e8c6554ff4..cd90857637 100644 --- a/libraries/octree/CMakeLists.txt +++ b/libraries/octree/CMakeLists.txt @@ -15,5 +15,5 @@ include_directories(SYSTEM "${ZLIB_INCLUDE_DIRS}") # append ZLIB and OpenSSL to our list of libraries to link target_link_libraries(${TARGET_NAME} ${ZLIB_LIBRARIES}) -# call macro to link our dependencies and bubble them up via a property on our target -link_shared_dependencies() +# call macro to include our dependency includes and bubble them up via a property on our target +include_dependency_includes() diff --git a/libraries/physics/CMakeLists.txt b/libraries/physics/CMakeLists.txt index 5270f08730..4f74038ff5 100644 --- a/libraries/physics/CMakeLists.txt +++ b/libraries/physics/CMakeLists.txt @@ -15,5 +15,5 @@ link_hifi_libraries(shared) ## append BULLET to our list of libraries to link #list(APPEND ${TARGET_NAME}_LIBRARIES_TO_LINK "${BULLET_LIBRARIES}") -# call macro to link our dependencies and bubble them up via a property on our target -link_shared_dependencies() +# call macro to include our dependency includes and bubble them up via a property on our target +include_dependency_includes() diff --git a/libraries/render-utils/CMakeLists.txt b/libraries/render-utils/CMakeLists.txt index 211c7266b3..99d01760f8 100644 --- a/libraries/render-utils/CMakeLists.txt +++ b/libraries/render-utils/CMakeLists.txt @@ -16,5 +16,5 @@ else () target_link_libraries(${TARGET_NAME} ${GLUT_LIBRARIES}) endif () -# call macro to link our dependencies and bubble them up via a property on our target -link_shared_dependencies() +# call macro to include our dependency includes and bubble them up via a property on our target +include_dependency_includes() diff --git a/libraries/script-engine/CMakeLists.txt b/libraries/script-engine/CMakeLists.txt index 7118e84443..86e6c83b5d 100644 --- a/libraries/script-engine/CMakeLists.txt +++ b/libraries/script-engine/CMakeLists.txt @@ -7,5 +7,5 @@ include_glm() link_hifi_libraries(shared octree voxels fbx entities animation audio physics metavoxels) -# call macro to link our dependencies and bubble them up via a property on our target -link_shared_dependencies() +# call macro to include our dependency includes and bubble them up via a property on our target +include_dependency_includes() diff --git a/libraries/shared/CMakeLists.txt b/libraries/shared/CMakeLists.txt index b5a44c96e2..4b271bfeda 100644 --- a/libraries/shared/CMakeLists.txt +++ b/libraries/shared/CMakeLists.txt @@ -4,5 +4,5 @@ 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(Network Script Widgets) -# call macro to link our dependencies and bubble them up via a property on our target -link_shared_dependencies() \ No newline at end of file +# 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 diff --git a/libraries/voxels/CMakeLists.txt b/libraries/voxels/CMakeLists.txt index 7980094884..75b5143321 100644 --- a/libraries/voxels/CMakeLists.txt +++ b/libraries/voxels/CMakeLists.txt @@ -14,5 +14,5 @@ include_directories(SYSTEM "${ZLIB_INCLUDE_DIRS}") # add it to our list of libraries to link target_link_libraries(${TARGET_NAME} ${ZLIB_LIBRARIES}) -# call macro to link our dependencies and bubble them up via a property on our target -link_shared_dependencies() \ No newline at end of file +# 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 diff --git a/tests/audio/CMakeLists.txt b/tests/audio/CMakeLists.txt index 974b4dcd09..fb6b9c2e11 100644 --- a/tests/audio/CMakeLists.txt +++ b/tests/audio/CMakeLists.txt @@ -7,4 +7,4 @@ include_glm() # link in the shared libraries link_hifi_libraries(shared audio networking) -link_shared_dependencies() \ No newline at end of file +include_dependency_includes() \ No newline at end of file diff --git a/tests/jitter/CMakeLists.txt b/tests/jitter/CMakeLists.txt index d0b366e7ef..93f7caefdd 100644 --- a/tests/jitter/CMakeLists.txt +++ b/tests/jitter/CMakeLists.txt @@ -5,4 +5,4 @@ setup_hifi_project() # link in the shared libraries link_hifi_libraries(shared networking) -link_shared_dependencies() \ No newline at end of file +include_dependency_includes() \ No newline at end of file diff --git a/tests/metavoxels/CMakeLists.txt b/tests/metavoxels/CMakeLists.txt index 732c974f95..7524c5c87c 100644 --- a/tests/metavoxels/CMakeLists.txt +++ b/tests/metavoxels/CMakeLists.txt @@ -9,4 +9,4 @@ setup_hifi_project(Network Script Widgets) # link in the shared libraries link_hifi_libraries(metavoxels networking shared) -link_shared_dependencies() \ No newline at end of file +include_dependency_includes() \ No newline at end of file diff --git a/tests/networking/CMakeLists.txt b/tests/networking/CMakeLists.txt index a7293226b3..113a75ab50 100644 --- a/tests/networking/CMakeLists.txt +++ b/tests/networking/CMakeLists.txt @@ -5,4 +5,4 @@ setup_hifi_project() # link in the shared libraries link_hifi_libraries(shared networking) -link_shared_dependencies() \ No newline at end of file +include_dependency_includes() \ No newline at end of file diff --git a/tests/octree/CMakeLists.txt b/tests/octree/CMakeLists.txt index 7139d4edb6..3382f684cb 100644 --- a/tests/octree/CMakeLists.txt +++ b/tests/octree/CMakeLists.txt @@ -7,4 +7,4 @@ include_glm() # link in the shared libraries link_hifi_libraries(shared octree voxels fbx metavoxels networking entities avatars audio animation script-engine physics) -link_shared_dependencies() +include_dependency_includes() diff --git a/tests/physics/CMakeLists.txt b/tests/physics/CMakeLists.txt index d47b979459..31c741eecf 100644 --- a/tests/physics/CMakeLists.txt +++ b/tests/physics/CMakeLists.txt @@ -7,4 +7,4 @@ include_glm() # link in the shared libraries link_hifi_libraries(shared physics) -link_shared_dependencies() +include_dependency_includes() diff --git a/tests/shared/CMakeLists.txt b/tests/shared/CMakeLists.txt index fe3843e9eb..f067fa52b5 100644 --- a/tests/shared/CMakeLists.txt +++ b/tests/shared/CMakeLists.txt @@ -7,4 +7,4 @@ include_glm() # link in the shared libraries link_hifi_libraries(shared) -link_shared_dependencies() \ No newline at end of file +include_dependency_includes() \ No newline at end of file diff --git a/tools/bitstream2json/CMakeLists.txt b/tools/bitstream2json/CMakeLists.txt index bc23a1e193..2e8bb213be 100644 --- a/tools/bitstream2json/CMakeLists.txt +++ b/tools/bitstream2json/CMakeLists.txt @@ -5,4 +5,4 @@ include_glm() link_hifi_libraries(metavoxels) -link_shared_dependencies() \ No newline at end of file +include_dependency_includes() \ No newline at end of file diff --git a/tools/json2bitstream/CMakeLists.txt b/tools/json2bitstream/CMakeLists.txt index 91b56c18fd..283d450e11 100644 --- a/tools/json2bitstream/CMakeLists.txt +++ b/tools/json2bitstream/CMakeLists.txt @@ -5,4 +5,4 @@ include_glm() link_hifi_libraries(metavoxels) -link_shared_dependencies() \ No newline at end of file +include_dependency_includes() \ No newline at end of file diff --git a/tools/mtc/CMakeLists.txt b/tools/mtc/CMakeLists.txt index 4dfa8421ff..06b9f86d06 100644 --- a/tools/mtc/CMakeLists.txt +++ b/tools/mtc/CMakeLists.txt @@ -1,4 +1,4 @@ set(TARGET_NAME mtc) setup_hifi_project() -link_shared_dependencies() \ No newline at end of file +include_dependency_includes() \ No newline at end of file From 715b3a245e39e1437c242f10ea00d21cb5a8f595 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Fri, 19 Dec 2014 10:53:36 -0800 Subject: [PATCH 15/33] remove GLUT from Cmake files --- cmake/modules/FindGLUT.cmake | 47 --------------------------- interface/CMakeLists.txt | 14 +++----- libraries/render-utils/CMakeLists.txt | 9 ----- 3 files changed, 5 insertions(+), 65 deletions(-) delete mode 100644 cmake/modules/FindGLUT.cmake diff --git a/cmake/modules/FindGLUT.cmake b/cmake/modules/FindGLUT.cmake deleted file mode 100644 index e7bf752aca..0000000000 --- a/cmake/modules/FindGLUT.cmake +++ /dev/null @@ -1,47 +0,0 @@ -# -# FindGLUT.cmake -# -# Try to find GLUT library and include path. -# Once done this will define -# -# GLUT_FOUND -# GLUT_INCLUDE_DIRS -# GLUT_LIBRARIES -# -# Created on 2/6/2014 by Stephen Birarda -# Copyright 2014 High Fidelity, Inc. -# -# Adapted from FindGLUT.cmake available in tlorach's OpenGLText Repository -# https://raw.github.com/tlorach/OpenGLText/master/cmake/FindGLUT.cmake -# -# Distributed under the Apache License, Version 2.0. -# See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -# - -include("${MACRO_DIR}/HifiLibrarySearchHints.cmake") -hifi_library_search_hints("freeglut") - -if (WIN32) - set(GLUT_HINT_DIRS "${FREEGLUT_SEARCH_DIRS} ${OPENGL_INCLUDE_DIR}") - - find_path(GLUT_INCLUDE_DIRS GL/glut.h PATH_SUFFIXES include HINTS ${FREEGLUT_SEARCH_DIRS}) - find_library(GLUT_LIBRARY freeglut PATH_SUFFIXES lib HINTS ${FREEGLUT_SEARCH_DIRS}) -else () - find_path(GLUT_INCLUDE_DIRS GL/glut.h PATH_SUFFIXES include HINTS ${FREEGLUT_SEARCH_DIRS}) - find_library(GLUT_LIBRARY glut PATH_SUFFIXES lib HINTS ${FREEGLUT_SEARCH_DIRS}) -endif () - -include(FindPackageHandleStandardArgs) - -set(GLUT_LIBRARIES "${GLUT_LIBRARY}" "${XMU_LIBRARY}" "${XI_LIBRARY}") - -if (UNIX) - find_library(XI_LIBRARY Xi PATH_SUFFIXES lib HINTS ${FREEGLUT_SEARCH_DIRS}) - find_library(XMU_LIBRARY Xmu PATH_SUFFIXES lib HINTS ${FREEGLUT_SEARCH_DIRS}) - - find_package_handle_standard_args(GLUT DEFAULT_MSG GLUT_INCLUDE_DIRS GLUT_LIBRARIES XI_LIBRARY XMU_LIBRARY) -else () - find_package_handle_standard_args(GLUT DEFAULT_MSG GLUT_INCLUDE_DIRS GLUT_LIBRARIES) -endif () - -mark_as_advanced(GLUT_INCLUDE_DIRS GLUT_LIBRARIES GLUT_LIBRARY XI_LIBRARY XMU_LIBRARY FREEGLUT_SEARCH_DIRS) \ No newline at end of file diff --git a/interface/CMakeLists.txt b/interface/CMakeLists.txt index 659ecf600f..ebbce669ea 100644 --- a/interface/CMakeLists.txt +++ b/interface/CMakeLists.txt @@ -25,15 +25,15 @@ else () endif () if (APPLE) - set(GL_HEADERS "#include \n#include ") + set(GL_HEADERS "#include ") elseif (UNIX) # include the right GL headers for UNIX - set(GL_HEADERS "#include \n#include \n#include ") + set(GL_HEADERS "#include \n#include ") elseif (WIN32) add_definitions(-D_USE_MATH_DEFINES) # apparently needed to get M_PI and other defines from cmath/math.h add_definitions(-DWINDOWS_LEAN_AND_MEAN) # needed to make sure windows doesn't go to crazy with its defines - set(GL_HEADERS "#include \n#include \n#include \n#include ") + set(GL_HEADERS "#include \n#include \n#include ") endif () # set up the external glm library @@ -194,11 +194,10 @@ if (APPLE) # link in required OS X frameworks and include the right GL headers find_library(CoreAudio CoreAudio) find_library(CoreFoundation CoreFoundation) - find_library(GLUT GLUT) find_library(OpenGL OpenGL) find_library(AppKit AppKit) - target_link_libraries(${TARGET_NAME} ${CoreAudio} ${CoreFoundation} ${GLUT} ${OpenGL} ${AppKit}) + target_link_libraries(${TARGET_NAME} ${CoreAudio} ${CoreFoundation} ${OpenGL} ${AppKit}) # install command for OS X bundle INSTALL(TARGETS ${TARGET_NAME} @@ -214,15 +213,12 @@ else (APPLE) ) find_package(OpenGL REQUIRED) - find_package(GLUT REQUIRED) - - include_directories(SYSTEM "${GLUT_INCLUDE_DIRS}") if (${OPENGL_INCLUDE_DIR}) include_directories(SYSTEM "${OPENGL_INCLUDE_DIR}") endif () - target_link_libraries(${TARGET_NAME} "${OPENGL_LIBRARY}" "${GLUT_LIBRARIES}") + target_link_libraries(${TARGET_NAME} "${OPENGL_LIBRARY}") # link target to external libraries if (WIN32) diff --git a/libraries/render-utils/CMakeLists.txt b/libraries/render-utils/CMakeLists.txt index 99d01760f8..97dc9c7bc8 100644 --- a/libraries/render-utils/CMakeLists.txt +++ b/libraries/render-utils/CMakeLists.txt @@ -7,14 +7,5 @@ include_glm() link_hifi_libraries(animation fbx shared gpu) -if (APPLE) - find_library(GLUT GLUT) - target_link_libraries(${TARGET_NAME} ${GLUT}) -else () - find_package(GLUT REQUIRED) - include_directories(SYSTEM "${GLUT_INCLUDE_DIRS}") - target_link_libraries(${TARGET_NAME} ${GLUT_LIBRARIES}) -endif () - # call macro to include our dependency includes and bubble them up via a property on our target include_dependency_includes() From 115dc28c9cabe9e5d35bcb881f7ae93d76f05ea1 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Fri, 19 Dec 2014 10:54:00 -0800 Subject: [PATCH 16/33] add glu includes on OS X to stopgap GLUT removal --- interface/src/Hair.cpp | 5 ++++- interface/src/avatar/Avatar.cpp | 5 +++++ interface/src/ui/ApplicationOverlay.cpp | 5 +++++ interface/src/ui/RearMirrorTools.cpp | 5 +++++ 4 files changed, 19 insertions(+), 1 deletion(-) diff --git a/interface/src/Hair.cpp b/interface/src/Hair.cpp index cb664f39ed..c2d3f78b98 100644 --- a/interface/src/Hair.cpp +++ b/interface/src/Hair.cpp @@ -10,11 +10,14 @@ // // Creates single flexible verlet-integrated strands that can be used for hair/fur/grass -#include "Hair.h" +#include #include "Util.h" #include "world.h" +#include "Hair.h" + + const float HAIR_DAMPING = 0.99f; const float CONSTRAINT_RELAXATION = 10.0f; const float HAIR_ACCELERATION_COUPLING = 0.045f; diff --git a/interface/src/avatar/Avatar.cpp b/interface/src/avatar/Avatar.cpp index 39c528d080..aa94b21d71 100644 --- a/interface/src/avatar/Avatar.cpp +++ b/interface/src/avatar/Avatar.cpp @@ -13,6 +13,11 @@ #include +// TODO: remove calls to gluProject to remove this include +#ifdef __APPLE__ +#include +#endif + #include #include diff --git a/interface/src/ui/ApplicationOverlay.cpp b/interface/src/ui/ApplicationOverlay.cpp index ab85da125c..f82b44a403 100644 --- a/interface/src/ui/ApplicationOverlay.cpp +++ b/interface/src/ui/ApplicationOverlay.cpp @@ -11,6 +11,11 @@ #include "InterfaceConfig.h" +// TODO: remove calls to gluProject to remove this include +#ifdef __APPLE__ +#include +#endif + #include #include diff --git a/interface/src/ui/RearMirrorTools.cpp b/interface/src/ui/RearMirrorTools.cpp index fd3fc34adb..2c671ef548 100644 --- a/interface/src/ui/RearMirrorTools.cpp +++ b/interface/src/ui/RearMirrorTools.cpp @@ -11,6 +11,11 @@ #include "InterfaceConfig.h" +// TODO: remove calls to gluProject to remove this include +#ifdef __APPLE__ +#include +#endif + #include #include From d43ec2ee28cc9b7c9c4c11371631e7d1355cab0f Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Fri, 19 Dec 2014 11:00:41 -0800 Subject: [PATCH 17/33] revert some prototype script stuff for now --- examples/entityScripts/movable.js | 412 ++++++++++++++++++++++- examples/entityScripts/movableClass.js | 426 ------------------------ examples/entityScripts/sitOnEntity.js | 363 +++++++++++++++++++- examples/entityScripts/sittable.js | 15 - examples/entityScripts/sittableClass.js | 393 ---------------------- 5 files changed, 767 insertions(+), 842 deletions(-) delete mode 100644 examples/entityScripts/movableClass.js delete mode 100644 examples/entityScripts/sittable.js delete mode 100644 examples/entityScripts/sittableClass.js diff --git a/examples/entityScripts/movable.js b/examples/entityScripts/movable.js index 0ea3641c6f..35d11116eb 100644 --- a/examples/entityScripts/movable.js +++ b/examples/entityScripts/movable.js @@ -8,8 +8,412 @@ // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // +(function(){ -(function() { - Script.include("movableClass.js"); - return new Movable(); -}) + this.entityID = null; + this.properties = null; + this.graboffset = null; + this.clickedAt = null; + this.firstHolding = true; + this.clicked = { x: -1, y: -1}; + this.lastMovedPosition = { x: -1, y: -1}; + this.lastMovedTime = 0; + this.rotateOverlayTarget = null; + this.rotateOverlayInner = null; + this.rotateOverlayOuter = null; + this.rotateOverlayCurrent = null; + this.rotateMode = false; + this.originalRotation = null; + + this.moveSoundURLS = [ + "http://public.highfidelity.io/sounds/MovingFurniture/FurnitureMove1.wav", + "http://public.highfidelity.io/sounds/MovingFurniture/FurnitureMove2.wav", + "http://public.highfidelity.io/sounds/MovingFurniture/FurnitureMove3.wav" + ]; + + this.turnSoundURLS = [ + + "http://public.highfidelity.io/sounds/MovingFurniture/FurnitureMove1.wav", + "http://public.highfidelity.io/sounds/MovingFurniture/FurnitureMove2.wav", + "http://public.highfidelity.io/sounds/MovingFurniture/FurnitureMove3.wav" + + // TODO: determine if these or other turn sounds work better than move sounds. + //"http://public.highfidelity.io/sounds/MovingFurniture/FurnitureTurn1.wav", + //"http://public.highfidelity.io/sounds/MovingFurniture/FurnitureTurn2.wav", + //"http://public.highfidelity.io/sounds/MovingFurniture/FurnitureTurn3.wav" + ]; + + + this.moveSounds = new Array(); + this.turnSounds = new Array(); + this.moveSound = null; + this.turnSound = null; + this.injector = null; + + var debug = false; + var displayRotateTargets = true; // change to false if you don't want the rotate targets + var rotateOverlayTargetSize = 10000; // really big target + var innerSnapAngle = 22.5; // the angle which we snap to on the inner rotation tool + var innerRadius; + var outerRadius; + var yawCenter; + var yawZero; + var rotationNormal; + var yawNormal; + var stopSoundDelay = 100; // number of msecs of not moving to have sound stop + + this.getRandomInt = function(min, max) { + return Math.floor(Math.random() * (max - min + 1)) + min; + } + + this.downloadSounds = function() { + for (var i = 0; i < this.moveSoundURLS.length; i++) { + this.moveSounds[i] = SoundCache.getSound(this.moveSoundURLS[i]); + } + for (var i = 0; i < this.turnSoundURLS.length; i++) { + this.turnSounds[i] = SoundCache.getSound(this.turnSoundURLS[i]); + } + } + + this.pickRandomSounds = function() { + var moveIndex = this.getRandomInt(0, this.moveSounds.length - 1); + var turnIndex = this.getRandomInt(0, this.turnSounds.length - 1); + if (debug) { + print("Random sounds -- turn:" + turnIndex + " move:" + moveIndex); + } + this.moveSound = this.moveSounds[moveIndex]; + this.turnSound = this.turnSounds[turnIndex]; + } + + // Play move sound + this.playMoveSound = function() { + if (debug) { + print("playMoveSound()"); + } + if (this.moveSound && this.moveSound.downloaded) { + if (debug) { + print("playMoveSound() --- calling this.injector = Audio.playSound(this.moveSound...)"); + } + this.injector = Audio.playSound(this.moveSound, { position: this.properties.position, loop: true, volume: 0.1 }); + } + } + + // Play turn sound + this.playTurnSound = function() { + if (debug) { + print("playTurnSound()"); + } + if (this.turnSound && this.turnSound.downloaded) { + if (debug) { + print("playTurnSound() --- calling this.injector = Audio.playSound(this.turnSound...)"); + } + this.injector = Audio.playSound(this.turnSound, { position: this.properties.position, loop: true, volume: 0.1 }); + } + } + + // stop sound + this.stopSound = function() { + if (debug) { + print("stopSound()"); + } + if (this.injector) { + Audio.stopInjector(this.injector); + this.injector = null; + } + } + + // Pr, Vr are respectively the Ray's Point of origin and Vector director + // Pp, Np are respectively the Plane's Point of origin and Normal vector + this.rayPlaneIntersection = function(Pr, Vr, Pp, Np) { + var d = -Vec3.dot(Pp, Np); + var t = -(Vec3.dot(Pr, Np) + d) / Vec3.dot(Vr, Np); + return Vec3.sum(Pr, Vec3.multiply(t, Vr)); + }; + + // updates the piece position based on mouse input + this.updatePosition = function(mouseEvent) { + var pickRay = Camera.computePickRay(mouseEvent.x, mouseEvent.y) + var upVector = { x: 0, y: 1, z: 0 }; + var intersection = this.rayPlaneIntersection(pickRay.origin, pickRay.direction, + this.properties.position, upVector); + + var newPosition = Vec3.sum(intersection, this.graboffset); + Entities.editEntity(this.entityID, { position: newPosition }); + }; + + this.grab = function(mouseEvent) { + // first calculate the offset + var pickRay = Camera.computePickRay(mouseEvent.x, mouseEvent.y) + var upVector = { x: 0, y: 1, z: 0 }; + var intersection = this.rayPlaneIntersection(pickRay.origin, pickRay.direction, + this.properties.position, upVector); + this.graboffset = Vec3.subtract(this.properties.position, intersection); + }; + + this.stopSoundIfNotMoving = function(mouseEvent) { + var nowDate = new Date(); + var nowMSecs = nowDate.getTime(); + if(mouseEvent.x == this.lastMovedPosition.x && mouseEvent.y == this.lastMovedPosition.y) { + var elapsedSinceLastMove = nowMSecs - this.lastMovedMSecs; + if (debug) { + print("elapsedSinceLastMove:" + elapsedSinceLastMove); + } + if (elapsedSinceLastMove > stopSoundDelay) { + if (debug) { + print("calling stopSound()..."); + } + this.stopSound(); + } + } else { + // if we've moved, then track our last move position and time... + this.lastMovedMSecs = nowMSecs; + this.lastMovedPosition.x = mouseEvent.x; + this.lastMovedPosition.y = mouseEvent.y; + } + } + + this.move = function(mouseEvent) { + this.updatePosition(mouseEvent); + if (this.injector === null) { + this.playMoveSound(); + } + }; + + this.release = function(mouseEvent) { + this.updatePosition(mouseEvent); + }; + + this.rotate = function(mouseEvent) { + var pickRay = Camera.computePickRay(mouseEvent.x, mouseEvent.y) + var result = Overlays.findRayIntersection(pickRay); + + if (result.intersects) { + var center = yawCenter; + var zero = yawZero; + var centerToZero = Vec3.subtract(center, zero); + var centerToIntersect = Vec3.subtract(center, result.intersection); + var angleFromZero = Vec3.orientedAngle(centerToZero, centerToIntersect, rotationNormal); + + var distanceFromCenter = Vec3.distance(center, result.intersection); + var snapToInner = false; + // var innerRadius = (Vec3.length(selectionManager.worldDimensions) / 2) * 1.1; + if (distanceFromCenter < innerRadius) { + angleFromZero = Math.floor(angleFromZero/innerSnapAngle) * innerSnapAngle; + snapToInner = true; + } + + var yawChange = Quat.fromVec3Degrees({ x: 0, y: angleFromZero, z: 0 }); + Entities.editEntity(this.entityID, { rotation: Quat.multiply(yawChange, this.originalRotation) }); + + + // update the rotation display accordingly... + var startAtCurrent = 360-angleFromZero; + var endAtCurrent = 360; + var startAtRemainder = 0; + var endAtRemainder = 360-angleFromZero; + if (angleFromZero < 0) { + startAtCurrent = 0; + endAtCurrent = -angleFromZero; + startAtRemainder = -angleFromZero; + endAtRemainder = 360; + } + + if (snapToInner) { + Overlays.editOverlay(this.rotateOverlayOuter, { startAt: 0, endAt: 360 }); + Overlays.editOverlay(this.rotateOverlayInner, { startAt: startAtRemainder, endAt: endAtRemainder }); + Overlays.editOverlay(this.rotateOverlayCurrent, { startAt: startAtCurrent, endAt: endAtCurrent, size: innerRadius, + majorTickMarksAngle: innerSnapAngle, minorTickMarksAngle: 0, + majorTickMarksLength: -0.25, minorTickMarksLength: 0, }); + } else { + Overlays.editOverlay(this.rotateOverlayInner, { startAt: 0, endAt: 360 }); + Overlays.editOverlay(this.rotateOverlayOuter, { startAt: startAtRemainder, endAt: endAtRemainder }); + Overlays.editOverlay(this.rotateOverlayCurrent, { startAt: startAtCurrent, endAt: endAtCurrent, size: outerRadius, + majorTickMarksAngle: 45.0, minorTickMarksAngle: 5, + majorTickMarksLength: 0.25, minorTickMarksLength: 0.1, }); + } + } + + if (this.injector === null) { + this.playTurnSound(); + } + }; + // All callbacks start by updating the properties + this.updateProperties = function(entityID) { + if (this.entityID === null || !this.entityID.isKnownID) { + this.entityID = Entities.identifyEntity(entityID); + } + this.properties = Entities.getEntityProperties(this.entityID); + }; + + this.cleanupRotateOverlay = function() { + Overlays.deleteOverlay(this.rotateOverlayTarget); + Overlays.deleteOverlay(this.rotateOverlayInner); + Overlays.deleteOverlay(this.rotateOverlayOuter); + Overlays.deleteOverlay(this.rotateOverlayCurrent); + this.rotateOverlayTarget = null; + this.rotateOverlayInner = null; + this.rotateOverlayOuter = null; + this.rotateOverlayCurrent = null; + } + + this.displayRotateOverlay = function(mouseEvent) { + var yawOverlayAngles = { x: 90, y: 0, z: 0 }; + var yawOverlayRotation = Quat.fromVec3Degrees(yawOverlayAngles); + + yawNormal = { x: 0, y: 1, z: 0 }; + yawCenter = this.properties.position; + rotationNormal = yawNormal; + + // Size the overlays to the current selection size + var diagonal = (Vec3.length(this.properties.dimensions) / 2) * 1.1; + var halfDimensions = Vec3.multiply(this.properties.dimensions, 0.5); + innerRadius = diagonal; + outerRadius = diagonal * 1.15; + var innerAlpha = 0.2; + var outerAlpha = 0.2; + + this.rotateOverlayTarget = Overlays.addOverlay("circle3d", { + position: this.properties.position, + size: rotateOverlayTargetSize, + color: { red: 0, green: 0, blue: 0 }, + alpha: 0.0, + solid: true, + visible: true, + rotation: yawOverlayRotation, + ignoreRayIntersection: false + }); + + this.rotateOverlayInner = Overlays.addOverlay("circle3d", { + position: this.properties.position, + size: innerRadius, + innerRadius: 0.9, + alpha: innerAlpha, + color: { red: 51, green: 152, blue: 203 }, + solid: true, + visible: displayRotateTargets, + rotation: yawOverlayRotation, + hasTickMarks: true, + majorTickMarksAngle: innerSnapAngle, + minorTickMarksAngle: 0, + majorTickMarksLength: -0.25, + minorTickMarksLength: 0, + majorTickMarksColor: { red: 0, green: 0, blue: 0 }, + minorTickMarksColor: { red: 0, green: 0, blue: 0 }, + ignoreRayIntersection: true, // always ignore this + }); + + this.rotateOverlayOuter = Overlays.addOverlay("circle3d", { + position: this.properties.position, + size: outerRadius, + innerRadius: 0.9, + startAt: 0, + endAt: 360, + alpha: outerAlpha, + color: { red: 51, green: 152, blue: 203 }, + solid: true, + visible: displayRotateTargets, + rotation: yawOverlayRotation, + + hasTickMarks: true, + majorTickMarksAngle: 45.0, + minorTickMarksAngle: 5, + majorTickMarksLength: 0.25, + minorTickMarksLength: 0.1, + majorTickMarksColor: { red: 0, green: 0, blue: 0 }, + minorTickMarksColor: { red: 0, green: 0, blue: 0 }, + ignoreRayIntersection: true, // always ignore this + }); + + this.rotateOverlayCurrent = Overlays.addOverlay("circle3d", { + position: this.properties.position, + size: outerRadius, + startAt: 0, + endAt: 0, + innerRadius: 0.9, + color: { red: 224, green: 67, blue: 36}, + alpha: 0.8, + solid: true, + visible: displayRotateTargets, + rotation: yawOverlayRotation, + ignoreRayIntersection: true, // always ignore this + hasTickMarks: true, + majorTickMarksColor: { red: 0, green: 0, blue: 0 }, + minorTickMarksColor: { red: 0, green: 0, blue: 0 }, + }); + + var pickRay = Camera.computePickRay(mouseEvent.x, mouseEvent.y) + var result = Overlays.findRayIntersection(pickRay); + yawZero = result.intersection; + + }; + + this.preload = function(entityID) { + this.updateProperties(entityID); // All callbacks start by updating the properties + this.downloadSounds(); + }; + + this.clickDownOnEntity = function(entityID, mouseEvent) { + this.updateProperties(entityID); // All callbacks start by updating the properties + this.grab(mouseEvent); + + var nowDate = new Date(); + var nowMSecs = nowDate.getTime(); + this.clickedAt = nowMSecs; + this.firstHolding = true; + + this.clicked.x = mouseEvent.x; + this.clicked.y = mouseEvent.y; + this.lastMovedPosition.x = mouseEvent.x; + this.lastMovedPosition.y = mouseEvent.y; + this.lastMovedMSecs = nowMSecs; + + this.pickRandomSounds(); + }; + + this.holdingClickOnEntity = function(entityID, mouseEvent) { + + this.updateProperties(entityID); // All callbacks start by updating the properties + + if (this.firstHolding) { + // if we haven't moved yet... + if (this.clicked.x == mouseEvent.x && this.clicked.y == mouseEvent.y) { + var d = new Date(); + var now = d.getTime(); + + if (now - this.clickedAt > 500) { + this.displayRotateOverlay(mouseEvent); + this.firstHolding = false; + this.rotateMode = true; + this.originalRotation = this.properties.rotation; + } + } else { + this.firstHolding = false; + } + } + + if (this.rotateMode) { + this.rotate(mouseEvent); + } else { + this.move(mouseEvent); + } + + this.stopSoundIfNotMoving(mouseEvent); + }; + this.clickReleaseOnEntity = function(entityID, mouseEvent) { + this.updateProperties(entityID); // All callbacks start by updating the properties + if (this.rotateMode) { + this.rotate(mouseEvent); + } else { + this.release(mouseEvent); + } + + if (this.rotateOverlayTarget != null) { + this.cleanupRotateOverlay(); + this.rotateMode = false; + } + + this.firstHolding = false; + this.stopSound(); + }; + +}) \ No newline at end of file diff --git a/examples/entityScripts/movableClass.js b/examples/entityScripts/movableClass.js deleted file mode 100644 index 26fb643826..0000000000 --- a/examples/entityScripts/movableClass.js +++ /dev/null @@ -1,426 +0,0 @@ -// -// movableClass.js -// examples/entityScripts -// -// Created by Brad Hefta-Gaub on 11/17/14. -// Copyright 2014 High Fidelity, Inc. -// -// Distributed under the Apache License, Version 2.0. -// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -// -Movable = function() { - - this.entityID = null; - this.properties = null; - this.graboffset = null; - this.clickedAt = null; - this.firstHolding = true; - this.clicked = { x: -1, y: -1}; - this.lastMovedPosition = { x: -1, y: -1}; - this.lastMovedTime = 0; - this.rotateOverlayTarget = null; - this.rotateOverlayInner = null; - this.rotateOverlayOuter = null; - this.rotateOverlayCurrent = null; - this.rotateMode = false; - this.originalRotation = null; - - this.moveSoundURLS = [ - "http://public.highfidelity.io/sounds/MovingFurniture/FurnitureMove1.wav", - "http://public.highfidelity.io/sounds/MovingFurniture/FurnitureMove2.wav", - "http://public.highfidelity.io/sounds/MovingFurniture/FurnitureMove3.wav" - ]; - - this.turnSoundURLS = [ - - "http://public.highfidelity.io/sounds/MovingFurniture/FurnitureMove1.wav", - "http://public.highfidelity.io/sounds/MovingFurniture/FurnitureMove2.wav", - "http://public.highfidelity.io/sounds/MovingFurniture/FurnitureMove3.wav" - - // TODO: determine if these or other turn sounds work better than move sounds. - //"http://public.highfidelity.io/sounds/MovingFurniture/FurnitureTurn1.wav", - //"http://public.highfidelity.io/sounds/MovingFurniture/FurnitureTurn2.wav", - //"http://public.highfidelity.io/sounds/MovingFurniture/FurnitureTurn3.wav" - ]; - - - this.moveSounds = new Array(); - this.turnSounds = new Array(); - this.moveSound = null; - this.turnSound = null; - this.injector = null; - - var debug = false; - var displayRotateTargets = true; // change to false if you don't want the rotate targets - var rotateOverlayTargetSize = 10000; // really big target - var innerSnapAngle = 22.5; // the angle which we snap to on the inner rotation tool - var innerRadius; - var outerRadius; - var yawCenter; - var yawZero; - var rotationNormal; - var yawNormal; - var stopSoundDelay = 100; // number of msecs of not moving to have sound stop - - this.getRandomInt = function(min, max) { - return Math.floor(Math.random() * (max - min + 1)) + min; - } - - this.downloadSounds = function() { - for (var i = 0; i < this.moveSoundURLS.length; i++) { - this.moveSounds[i] = SoundCache.getSound(this.moveSoundURLS[i]); - } - for (var i = 0; i < this.turnSoundURLS.length; i++) { - this.turnSounds[i] = SoundCache.getSound(this.turnSoundURLS[i]); - } - } - - this.pickRandomSounds = function() { - var moveIndex = this.getRandomInt(0, this.moveSounds.length - 1); - var turnIndex = this.getRandomInt(0, this.turnSounds.length - 1); - if (debug) { - print("Random sounds -- turn:" + turnIndex + " move:" + moveIndex); - } - this.moveSound = this.moveSounds[moveIndex]; - this.turnSound = this.turnSounds[turnIndex]; - } - - // Play move sound - this.playMoveSound = function() { - if (debug) { - print("playMoveSound()"); - } - if (this.moveSound && this.moveSound.downloaded) { - if (debug) { - print("playMoveSound() --- calling this.injector = Audio.playSound(this.moveSound...)"); - } - this.injector = Audio.playSound(this.moveSound, { position: this.properties.position, loop: true, volume: 0.1 }); - } - } - - // Play turn sound - this.playTurnSound = function() { - if (debug) { - print("playTurnSound()"); - } - if (this.turnSound && this.turnSound.downloaded) { - if (debug) { - print("playTurnSound() --- calling this.injector = Audio.playSound(this.turnSound...)"); - } - this.injector = Audio.playSound(this.turnSound, { position: this.properties.position, loop: true, volume: 0.1 }); - } - } - - // stop sound - this.stopSound = function() { - if (debug) { - print("stopSound()"); - } - if (this.injector) { - Audio.stopInjector(this.injector); - this.injector = null; - } - } - - // Pr, Vr are respectively the Ray's Point of origin and Vector director - // Pp, Np are respectively the Plane's Point of origin and Normal vector - this.rayPlaneIntersection = function(Pr, Vr, Pp, Np) { - var d = -Vec3.dot(Pp, Np); - var t = -(Vec3.dot(Pr, Np) + d) / Vec3.dot(Vr, Np); - return Vec3.sum(Pr, Vec3.multiply(t, Vr)); - }; - - // updates the piece position based on mouse input - this.updatePosition = function(mouseEvent) { - var pickRay = Camera.computePickRay(mouseEvent.x, mouseEvent.y) - var upVector = { x: 0, y: 1, z: 0 }; - var intersection = this.rayPlaneIntersection(pickRay.origin, pickRay.direction, - this.properties.position, upVector); - - var newPosition = Vec3.sum(intersection, this.graboffset); - Entities.editEntity(this.entityID, { position: newPosition }); - }; - - this.grab = function(mouseEvent) { - // first calculate the offset - var pickRay = Camera.computePickRay(mouseEvent.x, mouseEvent.y) - var upVector = { x: 0, y: 1, z: 0 }; - var intersection = this.rayPlaneIntersection(pickRay.origin, pickRay.direction, - this.properties.position, upVector); - this.graboffset = Vec3.subtract(this.properties.position, intersection); - }; - - this.stopSoundIfNotMoving = function(mouseEvent) { - var nowDate = new Date(); - var nowMSecs = nowDate.getTime(); - if(mouseEvent.x == this.lastMovedPosition.x && mouseEvent.y == this.lastMovedPosition.y) { - var elapsedSinceLastMove = nowMSecs - this.lastMovedMSecs; - if (debug) { - print("elapsedSinceLastMove:" + elapsedSinceLastMove); - } - if (elapsedSinceLastMove > stopSoundDelay) { - if (debug) { - print("calling stopSound()..."); - } - this.stopSound(); - } - } else { - // if we've moved, then track our last move position and time... - this.lastMovedMSecs = nowMSecs; - this.lastMovedPosition.x = mouseEvent.x; - this.lastMovedPosition.y = mouseEvent.y; - } - } - - this.move = function(mouseEvent) { - this.updatePosition(mouseEvent); - if (this.injector === null) { - this.playMoveSound(); - } - }; - - this.release = function(mouseEvent) { - this.updatePosition(mouseEvent); - }; - - this.rotate = function(mouseEvent) { - var pickRay = Camera.computePickRay(mouseEvent.x, mouseEvent.y) - var result = Overlays.findRayIntersection(pickRay); - - if (result.intersects) { - var center = yawCenter; - var zero = yawZero; - var centerToZero = Vec3.subtract(center, zero); - var centerToIntersect = Vec3.subtract(center, result.intersection); - var angleFromZero = Vec3.orientedAngle(centerToZero, centerToIntersect, rotationNormal); - - var distanceFromCenter = Vec3.distance(center, result.intersection); - var snapToInner = false; - // var innerRadius = (Vec3.length(selectionManager.worldDimensions) / 2) * 1.1; - if (distanceFromCenter < innerRadius) { - angleFromZero = Math.floor(angleFromZero/innerSnapAngle) * innerSnapAngle; - snapToInner = true; - } - - var yawChange = Quat.fromVec3Degrees({ x: 0, y: angleFromZero, z: 0 }); - Entities.editEntity(this.entityID, { rotation: Quat.multiply(yawChange, this.originalRotation) }); - - - // update the rotation display accordingly... - var startAtCurrent = 360-angleFromZero; - var endAtCurrent = 360; - var startAtRemainder = 0; - var endAtRemainder = 360-angleFromZero; - if (angleFromZero < 0) { - startAtCurrent = 0; - endAtCurrent = -angleFromZero; - startAtRemainder = -angleFromZero; - endAtRemainder = 360; - } - - if (snapToInner) { - Overlays.editOverlay(this.rotateOverlayOuter, { startAt: 0, endAt: 360 }); - Overlays.editOverlay(this.rotateOverlayInner, { startAt: startAtRemainder, endAt: endAtRemainder }); - Overlays.editOverlay(this.rotateOverlayCurrent, { startAt: startAtCurrent, endAt: endAtCurrent, size: innerRadius, - majorTickMarksAngle: innerSnapAngle, minorTickMarksAngle: 0, - majorTickMarksLength: -0.25, minorTickMarksLength: 0, }); - } else { - Overlays.editOverlay(this.rotateOverlayInner, { startAt: 0, endAt: 360 }); - Overlays.editOverlay(this.rotateOverlayOuter, { startAt: startAtRemainder, endAt: endAtRemainder }); - Overlays.editOverlay(this.rotateOverlayCurrent, { startAt: startAtCurrent, endAt: endAtCurrent, size: outerRadius, - majorTickMarksAngle: 45.0, minorTickMarksAngle: 5, - majorTickMarksLength: 0.25, minorTickMarksLength: 0.1, }); - } - } - - if (this.injector === null) { - this.playTurnSound(); - } - }; - // All callbacks start by updating the properties - this.updateProperties = function(entityID) { - if (this.entityID === null || !this.entityID.isKnownID) { - this.entityID = Entities.identifyEntity(entityID); - } - this.properties = Entities.getEntityProperties(this.entityID); - }; - - this.cleanupRotateOverlay = function() { - Overlays.deleteOverlay(this.rotateOverlayTarget); - Overlays.deleteOverlay(this.rotateOverlayInner); - Overlays.deleteOverlay(this.rotateOverlayOuter); - Overlays.deleteOverlay(this.rotateOverlayCurrent); - this.rotateOverlayTarget = null; - this.rotateOverlayInner = null; - this.rotateOverlayOuter = null; - this.rotateOverlayCurrent = null; - } - - this.displayRotateOverlay = function(mouseEvent) { - var yawOverlayAngles = { x: 90, y: 0, z: 0 }; - var yawOverlayRotation = Quat.fromVec3Degrees(yawOverlayAngles); - - yawNormal = { x: 0, y: 1, z: 0 }; - yawCenter = this.properties.position; - rotationNormal = yawNormal; - - // Size the overlays to the current selection size - var diagonal = (Vec3.length(this.properties.dimensions) / 2) * 1.1; - var halfDimensions = Vec3.multiply(this.properties.dimensions, 0.5); - innerRadius = diagonal; - outerRadius = diagonal * 1.15; - var innerAlpha = 0.2; - var outerAlpha = 0.2; - - this.rotateOverlayTarget = Overlays.addOverlay("circle3d", { - position: this.properties.position, - size: rotateOverlayTargetSize, - color: { red: 0, green: 0, blue: 0 }, - alpha: 0.0, - solid: true, - visible: true, - rotation: yawOverlayRotation, - ignoreRayIntersection: false - }); - - this.rotateOverlayInner = Overlays.addOverlay("circle3d", { - position: this.properties.position, - size: innerRadius, - innerRadius: 0.9, - alpha: innerAlpha, - color: { red: 51, green: 152, blue: 203 }, - solid: true, - visible: displayRotateTargets, - rotation: yawOverlayRotation, - hasTickMarks: true, - majorTickMarksAngle: innerSnapAngle, - minorTickMarksAngle: 0, - majorTickMarksLength: -0.25, - minorTickMarksLength: 0, - majorTickMarksColor: { red: 0, green: 0, blue: 0 }, - minorTickMarksColor: { red: 0, green: 0, blue: 0 }, - ignoreRayIntersection: true, // always ignore this - }); - - this.rotateOverlayOuter = Overlays.addOverlay("circle3d", { - position: this.properties.position, - size: outerRadius, - innerRadius: 0.9, - startAt: 0, - endAt: 360, - alpha: outerAlpha, - color: { red: 51, green: 152, blue: 203 }, - solid: true, - visible: displayRotateTargets, - rotation: yawOverlayRotation, - - hasTickMarks: true, - majorTickMarksAngle: 45.0, - minorTickMarksAngle: 5, - majorTickMarksLength: 0.25, - minorTickMarksLength: 0.1, - majorTickMarksColor: { red: 0, green: 0, blue: 0 }, - minorTickMarksColor: { red: 0, green: 0, blue: 0 }, - ignoreRayIntersection: true, // always ignore this - }); - - this.rotateOverlayCurrent = Overlays.addOverlay("circle3d", { - position: this.properties.position, - size: outerRadius, - startAt: 0, - endAt: 0, - innerRadius: 0.9, - color: { red: 224, green: 67, blue: 36}, - alpha: 0.8, - solid: true, - visible: displayRotateTargets, - rotation: yawOverlayRotation, - ignoreRayIntersection: true, // always ignore this - hasTickMarks: true, - majorTickMarksColor: { red: 0, green: 0, blue: 0 }, - minorTickMarksColor: { red: 0, green: 0, blue: 0 }, - }); - - var pickRay = Camera.computePickRay(mouseEvent.x, mouseEvent.y) - var result = Overlays.findRayIntersection(pickRay); - yawZero = result.intersection; - - }; -}; - -Movable.prototype = { - preload : function(entityID) { - print("Movable.preload()"); - this.updateProperties(entityID); // All callbacks start by updating the properties - this.downloadSounds(); - }, - - clickDownOnEntity : function(entityID, mouseEvent) { - print("Movable.clickDownOnEntity()"); - - this.updateProperties(entityID); // All callbacks start by updating the properties - this.grab(mouseEvent); - - var nowDate = new Date(); - var nowMSecs = nowDate.getTime(); - this.clickedAt = nowMSecs; - this.firstHolding = true; - - this.clicked.x = mouseEvent.x; - this.clicked.y = mouseEvent.y; - this.lastMovedPosition.x = mouseEvent.x; - this.lastMovedPosition.y = mouseEvent.y; - this.lastMovedMSecs = nowMSecs; - - this.pickRandomSounds(); - }, - - holdingClickOnEntity : function(entityID, mouseEvent) { - print("Movable.holdingClickOnEntity()"); - - this.updateProperties(entityID); // All callbacks start by updating the properties - - if (this.firstHolding) { - // if we haven't moved yet... - if (this.clicked.x == mouseEvent.x && this.clicked.y == mouseEvent.y) { - var d = new Date(); - var now = d.getTime(); - - if (now - this.clickedAt > 500) { - this.displayRotateOverlay(mouseEvent); - this.firstHolding = false; - this.rotateMode = true; - this.originalRotation = this.properties.rotation; - } - } else { - this.firstHolding = false; - } - } - - if (this.rotateMode) { - this.rotate(mouseEvent); - } else { - this.move(mouseEvent); - } - - this.stopSoundIfNotMoving(mouseEvent); - }, - - clickReleaseOnEntity : function(entityID, mouseEvent) { - print("Movable.clickReleaseOnEntity()"); - this.updateProperties(entityID); // All callbacks start by updating the properties - if (this.rotateMode) { - this.rotate(mouseEvent); - } else { - this.release(mouseEvent); - } - - if (this.rotateOverlayTarget != null) { - this.cleanupRotateOverlay(); - this.rotateMode = false; - } - - this.firstHolding = false; - this.stopSound(); - }, -}; diff --git a/examples/entityScripts/sitOnEntity.js b/examples/entityScripts/sitOnEntity.js index 080acf61a8..d5c4fa9c52 100644 --- a/examples/entityScripts/sitOnEntity.js +++ b/examples/entityScripts/sitOnEntity.js @@ -11,7 +11,362 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -(function() { - Script.include("sittableClass.js"); - return new Sittable(); -}) +(function(){ + + this.entityID = null; + this.properties = null; + this.standUpButton = null; + this.indicatorsAdded = false; + this.indicator = new Array(); + + + var buttonImageUrl = "https://worklist-prod.s3.amazonaws.com/attachment/0aca88e1-9bd8-5c1d.svg"; + var windowDimensions = Controller.getViewportDimensions(); + var buttonWidth = 37; + var buttonHeight = 46; + var buttonPadding = 50; // inside the normal toolbar position + var buttonPositionX = windowDimensions.x - buttonPadding - buttonWidth; + var buttonPositionY = (windowDimensions.y - buttonHeight) / 2 - (buttonHeight + buttonPadding); + + var passedTime = 0.0; + var startPosition = null; + var startRotation = null; + var animationLenght = 2.0; + + var avatarOldPosition = { x: 0, y: 0, z: 0 }; + + var sittingSettingsHandle = "SitJsSittingPosition"; + var sitting = Settings.getValue(sittingSettingsHandle, false) == "true"; + print("Original sitting status: " + sitting); + var frame = 0; + + var seat = new Object(); + var hiddingSeats = false; + + // This is the pose we would like to end up + var pose = [ + {joint:"RightUpLeg", rotation: {x:100.0, y:15.0, z:0.0}}, + {joint:"RightLeg", rotation: {x:-130.0, y:15.0, z:0.0}}, + {joint:"RightFoot", rotation: {x:30, y:15.0, z:0.0}}, + {joint:"LeftUpLeg", rotation: {x:100.0, y:-15.0, z:0.0}}, + {joint:"LeftLeg", rotation: {x:-130.0, y:-15.0, z:0.0}}, + {joint:"LeftFoot", rotation: {x:30, y:15.0, z:0.0}} + ]; + + var startPoseAndTransition = []; + + function storeStartPoseAndTransition() { + for (var i = 0; i < pose.length; i++){ + var startRotation = Quat.safeEulerAngles(MyAvatar.getJointRotation(pose[i].joint)); + var transitionVector = Vec3.subtract( pose[i].rotation, startRotation ); + startPoseAndTransition.push({joint: pose[i].joint, start: startRotation, transition: transitionVector}); + } + } + + function updateJoints(factor){ + for (var i = 0; i < startPoseAndTransition.length; i++){ + var scaledTransition = Vec3.multiply(startPoseAndTransition[i].transition, factor); + var rotation = Vec3.sum(startPoseAndTransition[i].start, scaledTransition); + MyAvatar.setJointData(startPoseAndTransition[i].joint, Quat.fromVec3Degrees( rotation )); + } + } + + var sittingDownAnimation = function(deltaTime) { + + passedTime += deltaTime; + var factor = passedTime/animationLenght; + + if ( passedTime <= animationLenght ) { + updateJoints(factor); + + var pos = { x: startPosition.x - 0.3 * factor, y: startPosition.y - 0.5 * factor, z: startPosition.z}; + MyAvatar.position = pos; + } else { + Script.update.disconnect(sittingDownAnimation); + if (seat.model) { + MyAvatar.setModelReferential(seat.model.id); + } + } + } + + var standingUpAnimation = function(deltaTime) { + + passedTime += deltaTime; + var factor = 1 - passedTime/animationLenght; + + if ( passedTime <= animationLenght ) { + + updateJoints(factor); + + var pos = { x: startPosition.x + 0.3 * (passedTime/animationLenght), y: startPosition.y + 0.5 * (passedTime/animationLenght), z: startPosition.z}; + MyAvatar.position = pos; + } else { + Script.update.disconnect(standingUpAnimation); + + } + } + + var externalThis = this; + + var goToSeatAnimation = function(deltaTime) { + passedTime += deltaTime; + var factor = passedTime/animationLenght; + + if (passedTime <= animationLenght) { + var targetPosition = Vec3.sum(seat.position, { x: 0.3, y: 0.5, z: 0 }); + MyAvatar.position = Vec3.sum(Vec3.multiply(startPosition, 1 - factor), Vec3.multiply(targetPosition, factor)); + } else if (passedTime <= 2 * animationLenght) { + //Quat.print("MyAvatar: ", MyAvatar.orientation); + //Quat.print("Seat: ", seat.rotation); + MyAvatar.orientation = Quat.mix(startRotation, seat.rotation, factor - 1); + } else { + Script.update.disconnect(goToSeatAnimation); + externalThis.sitDown(); + externalThis.showIndicators(false); + } + } + + var globalMouseClick = function(event) { + var clickedOverlay = Overlays.getOverlayAtPoint({x: event.x, y: event.y}); + if (clickedOverlay == externalThis.standUpButton) { + seat.model = null; + externalThis.standUp(); + Controller.mousePressEvent.disconnect(globalMouseClick); + } + }; + + this.sitDown = function() { + sitting = true; + Settings.setValue(sittingSettingsHandle, sitting); + print("sitDown sitting status: " + Settings.getValue(sittingSettingsHandle, false)); + passedTime = 0.0; + startPosition = MyAvatar.position; + storeStartPoseAndTransition(); + try { + Script.update.disconnect(standingUpAnimation); + } catch(e){ + // no need to handle. if it wasn't connected no harm done + } + Script.update.connect(sittingDownAnimation); + Overlays.editOverlay(this.standUpButton, { visible: true }); + Controller.mousePressEvent.connect(globalMouseClick); + } + + this.standUp = function() { + sitting = false; + Settings.setValue(sittingSettingsHandle, sitting); + print("standUp sitting status: " + Settings.getValue(sittingSettingsHandle, false)); + passedTime = 0.0; + startPosition = MyAvatar.position; + MyAvatar.clearReferential(); + try{ + Script.update.disconnect(sittingDownAnimation); + } catch (e){} + Script.update.connect(standingUpAnimation); + Overlays.editOverlay(this.standUpButton, { visible: false }); + Controller.mousePressEvent.disconnect(globalMouseClick); + } + + function SeatIndicator(modelProperties, seatIndex) { + var halfDiagonal = Vec3.length(modelProperties.dimensions) / 2.0; + + this.position = Vec3.sum(modelProperties.position, + Vec3.multiply(Vec3.multiplyQbyV(modelProperties.rotation, modelProperties.sittingPoints[seatIndex].position), + halfDiagonal)); // hack + + this.orientation = Quat.multiply(modelProperties.rotation, + modelProperties.sittingPoints[seatIndex].rotation); + this.scale = MyAvatar.scale / 3; + + this.sphere = Overlays.addOverlay("billboard", { + subImage: { x: 0, y: buttonHeight, width: buttonWidth, height: buttonHeight}, + url: buttonImageUrl, + position: this.position, + scale: this.scale, + size: this.scale, + solid: true, + color: { red: 255, green: 255, blue: 255 }, + alpha: 0.8, + visible: true, + isFacingAvatar: true + }); + + this.show = function(doShow) { + Overlays.editOverlay(this.sphere, { visible: doShow }); + } + + this.update = function() { + Overlays.editOverlay(this.sphere, { + position: this.position, + size: this.scale + }); + } + + this.cleanup = function() { + Overlays.deleteOverlay(this.sphere); + } + } + + function update(deltaTime){ + var newWindowDimensions = Controller.getViewportDimensions(); + if( newWindowDimensions.x != windowDimensions.x || newWindowDimensions.y != windowDimensions.y ){ + windowDimensions = newWindowDimensions; + var newX = windowDimensions.x - buttonPadding - buttonWidth; + var newY = (windowDimensions.y - buttonHeight) / 2 ; + Overlays.editOverlay( this.standUpButton, {x: newX, y: newY} ); + } + + // For a weird reason avatar joint don't update till the 10th frame + // Set the update frame to 20 to be safe + var UPDATE_FRAME = 20; + if (frame <= UPDATE_FRAME) { + if (frame == UPDATE_FRAME) { + if (sitting == true) { + print("Was seated: " + sitting); + storeStartPoseAndTransition(); + updateJoints(1.0); + } + } + frame++; + } + } + + this.addIndicators = function() { + if (!this.indicatorsAdded) { + if (this.properties.sittingPoints.length > 0) { + for (var i = 0; i < this.properties.sittingPoints.length; ++i) { + this.indicator[i] = new SeatIndicator(this.properties, i); + } + this.indicatorsAdded = true; + } + } + } + + this.removeIndicators = function() { + for (var i = 0; i < this.properties.sittingPoints.length; ++i) { + this.indicator[i].cleanup(); + } + } + + this.showIndicators = function(doShow) { + this.addIndicators(); + if (this.indicatorsAdded) { + for (var i = 0; i < this.properties.sittingPoints.length; ++i) { + this.indicator[i].show(doShow); + } + } + hiddingSeats = !doShow; + } + + function raySphereIntersection(origin, direction, center, radius) { + var A = origin; + var B = Vec3.normalize(direction); + var P = center; + + var x = Vec3.dot(Vec3.subtract(P, A), B); + var X = Vec3.sum(A, Vec3.multiply(B, x)); + var d = Vec3.length(Vec3.subtract(P, X)); + + return (x > 0 && d <= radius); + } + + this.cleanup = function() { + this.standUp(); + MyAvatar.clearReferential(); + for (var i = 0; i < pose.length; i++){ + MyAvatar.clearJointData(pose[i].joint); + } + Overlays.deleteOverlay(this.standUpButton); + for (var i = 0; i < this.indicator.length; ++i) { + this.indicator[i].cleanup(); + } + }; + + + this.createStandupButton = function() { + this.standUpButton = Overlays.addOverlay("image", { + x: buttonPositionX, y: buttonPositionY, width: buttonWidth, height: buttonHeight, + subImage: { x: buttonWidth, y: buttonHeight, width: buttonWidth, height: buttonHeight}, + imageURL: buttonImageUrl, + visible: false, + alpha: 1.0 + }); + }; + + this.handleClickEvent = function(event) { + var clickedOverlay = Overlays.getOverlayAtPoint({x: event.x, y: event.y}); + + if (clickedOverlay == this.standUpButton) { + seat.model = null; + this.standUp(); + } else { + this.addIndicators(); + if (this.indicatorsAdded) { + var pickRay = Camera.computePickRay(event.x, event.y); + + var clickedOnSeat = false; + + for (var i = 0; i < this.properties.sittingPoints.length; ++i) { + if (raySphereIntersection(pickRay.origin, + pickRay.direction, + this.indicator[i].position, + this.indicator[i].scale / 2)) { + clickedOnSeat = true; + seat.model = this.entityID; // ?? + seat.position = this.indicator[i].position; + seat.rotation = this.indicator[i].orientation; + } + } + + if (clickedOnSeat) { + passedTime = 0.0; + startPosition = MyAvatar.position; + startRotation = MyAvatar.orientation; + try{ Script.update.disconnect(standingUpAnimation); } catch(e){} + try{ Script.update.disconnect(sittingDownAnimation); } catch(e){} + Script.update.connect(goToSeatAnimation); + } + } + } + }; + + + // All callbacks start by updating the properties + this.updateProperties = function(entityID) { + if (this.entityID === null || !this.entityID.isKnownID) { + this.entityID = Entities.identifyEntity(entityID); + } + this.properties = Entities.getEntityProperties(this.entityID); + }; + + this.unload = function(entityID) { + this.cleanup(); + Script.update.disconnect(update); + }; + + this.preload = function(entityID) { + this.updateProperties(entityID); // All callbacks start by updating the properties + this.createStandupButton(); + Script.update.connect(update); + }; + + + this.hoverOverEntity = function(entityID, mouseEvent) { + this.updateProperties(entityID); // All callbacks start by updating the properties + this.showIndicators(true); + }; + this.hoverLeaveEntity = function(entityID, mouseEvent) { + this.updateProperties(entityID); // All callbacks start by updating the properties + this.showIndicators(false); + }; + + this.clickDownOnEntity = function(entityID, mouseEvent) { + this.updateProperties(entityID); // All callbacks start by updating the properties + this.handleClickEvent(mouseEvent); + }; + + this.clickReleaseOnEntity = function(entityID, mouseEvent) { + this.updateProperties(entityID); // All callbacks start by updating the properties + }; + +}) \ No newline at end of file diff --git a/examples/entityScripts/sittable.js b/examples/entityScripts/sittable.js deleted file mode 100644 index 0753a46d2a..0000000000 --- a/examples/entityScripts/sittable.js +++ /dev/null @@ -1,15 +0,0 @@ -// -// sittable.js -// examples/entityScripts -// -// Created by Brad Hefta-Gaub on 11/17/14. -// Copyright 2014 High Fidelity, Inc. -// -// Distributed under the Apache License, Version 2.0. -// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -// - -(function() { - Script.include("sittableClass.js"); - return new Sittable(); -}) diff --git a/examples/entityScripts/sittableClass.js b/examples/entityScripts/sittableClass.js deleted file mode 100644 index 1a7b1df25a..0000000000 --- a/examples/entityScripts/sittableClass.js +++ /dev/null @@ -1,393 +0,0 @@ -// -// sitOnEntity.js -// examples/entityScripts -// -// Created by Brad Hefta-Gaub on 11/1/14. -// Copyright 2014 High Fidelity, Inc. -// -// This is an example of an entity script for sitting. -// -// Distributed under the Apache License, Version 2.0. -// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -// - -var activeSittable = null; -function SittableUpdate(deltaTime){ - - // This keeps the standup button in a reasonable place. - var newWindowDimensions = Controller.getViewportDimensions(); - if( newWindowDimensions.x != windowDimensions.x || newWindowDimensions.y != windowDimensions.y ){ - windowDimensions = newWindowDimensions; - var newX = windowDimensions.x - buttonPadding - buttonWidth; - var newY = (windowDimensions.y - buttonHeight) / 2 ; - Overlays.editOverlay( activeSittable.standUpButton, {x: newX, y: newY} ); - } - - - // this appears to be some logic related to storing the original position - /* - - // For a weird reason avatar joint don't update till the 10th frame - // Set the update frame to 20 to be safe - var UPDATE_FRAME = 20; - if (frame <= UPDATE_FRAME) { - if (frame == UPDATE_FRAME) { - if (sitting == true) { - print("Was seated: " + sitting); - activeSittable.storeStartPoseAndTransition(); - activeSittable.updateJoints(1.0); - } - } - frame++; - } - */ -} - -SeatIndicator = function(modelProperties, seatIndex) { - var buttonImageUrl = "https://worklist-prod.s3.amazonaws.com/attachment/0aca88e1-9bd8-5c1d.svg"; - var buttonWidth = 37; - var buttonHeight = 46; - - var halfDiagonal = Vec3.length(modelProperties.dimensions) / 2.0; - - this.position = Vec3.sum(modelProperties.position, - Vec3.multiply(Vec3.multiplyQbyV(modelProperties.rotation, modelProperties.sittingPoints[seatIndex].position), - halfDiagonal)); // hack - - this.orientation = Quat.multiply(modelProperties.rotation, - modelProperties.sittingPoints[seatIndex].rotation); - this.scale = MyAvatar.scale / 3; - - this.sphere = Overlays.addOverlay("billboard", { - subImage: { x: 0, y: buttonHeight, width: buttonWidth, height: buttonHeight}, - url: buttonImageUrl, - position: this.position, - scale: this.scale, - size: this.scale, - solid: true, - color: { red: 255, green: 255, blue: 255 }, - alpha: 0.8, - visible: true, - isFacingAvatar: true - }); - - this.show = function(doShow) { - Overlays.editOverlay(this.sphere, { visible: doShow }); - } - - this.update = function() { - Overlays.editOverlay(this.sphere, { - position: this.position, - size: this.scale - }); - } - - this.cleanup = function() { - Overlays.deleteOverlay(this.sphere); - } -}; - -Sittable = function() { - - this.entityID = null; - this.properties = null; - this.standUpButton = null; - this.indicatorsAdded = false; - this.indicator = new Array(); - - - var buttonImageUrl = "https://worklist-prod.s3.amazonaws.com/attachment/0aca88e1-9bd8-5c1d.svg"; - var windowDimensions = Controller.getViewportDimensions(); - var buttonWidth = 37; - var buttonHeight = 46; - var buttonPadding = 50; // inside the normal toolbar position - var buttonPositionX = windowDimensions.x - buttonPadding - buttonWidth; - var buttonPositionY = (windowDimensions.y - buttonHeight) / 2 - (buttonHeight + buttonPadding); - - var passedTime = 0.0; - var startPosition = null; - var startRotation = null; - var animationLength = 2.0; - - var avatarOldPosition = { x: 0, y: 0, z: 0 }; - - var sittingSettingsHandle = "SitJsSittingPosition"; - var sitting = Settings.getValue(sittingSettingsHandle, false) == "true"; - print("Original sitting status: " + sitting); - var frame = 0; - - var seat = new Object(); - var hiddingSeats = false; - - // This is the pose we would like to end up - var pose = [ - {joint:"RightUpLeg", rotation: {x:100.0, y:15.0, z:0.0}}, - {joint:"RightLeg", rotation: {x:-130.0, y:15.0, z:0.0}}, - {joint:"RightFoot", rotation: {x:30, y:15.0, z:0.0}}, - {joint:"LeftUpLeg", rotation: {x:100.0, y:-15.0, z:0.0}}, - {joint:"LeftLeg", rotation: {x:-130.0, y:-15.0, z:0.0}}, - {joint:"LeftFoot", rotation: {x:30, y:15.0, z:0.0}} - ]; - - var startPoseAndTransition = []; - - function storeStartPoseAndTransition() { - for (var i = 0; i < pose.length; i++){ - var startRotation = Quat.safeEulerAngles(MyAvatar.getJointRotation(pose[i].joint)); - var transitionVector = Vec3.subtract( pose[i].rotation, startRotation ); - startPoseAndTransition.push({joint: pose[i].joint, start: startRotation, transition: transitionVector}); - } - } - - function updateJoints(factor){ - for (var i = 0; i < startPoseAndTransition.length; i++){ - var scaledTransition = Vec3.multiply(startPoseAndTransition[i].transition, factor); - var rotation = Vec3.sum(startPoseAndTransition[i].start, scaledTransition); - MyAvatar.setJointData(startPoseAndTransition[i].joint, Quat.fromVec3Degrees( rotation )); - } - } - - var sittingDownAnimation = function(deltaTime) { - - passedTime += deltaTime; - var factor = passedTime/animationLength; - - if ( passedTime <= animationLength ) { - updateJoints(factor); - - var pos = { x: startPosition.x - 0.3 * factor, y: startPosition.y - 0.5 * factor, z: startPosition.z}; - MyAvatar.position = pos; - } else { - Script.update.disconnect(sittingDownAnimation); - if (seat.model) { - MyAvatar.setModelReferential(seat.model.id); - } - } - } - - var standingUpAnimation = function(deltaTime) { - - passedTime += deltaTime; - var factor = 1 - passedTime/animationLength; - - if ( passedTime <= animationLength ) { - - updateJoints(factor); - - var pos = { x: startPosition.x + 0.3 * (passedTime/animationLength), y: startPosition.y + 0.5 * (passedTime/animationLength), z: startPosition.z}; - MyAvatar.position = pos; - } else { - Script.update.disconnect(standingUpAnimation); - - } - } - - var externalThis = this; - - var goToSeatAnimation = function(deltaTime) { - passedTime += deltaTime; - var factor = passedTime/animationLength; - - if (passedTime <= animationLength) { - var targetPosition = Vec3.sum(seat.position, { x: 0.3, y: 0.5, z: 0 }); - MyAvatar.position = Vec3.sum(Vec3.multiply(startPosition, 1 - factor), Vec3.multiply(targetPosition, factor)); - } else if (passedTime <= 2 * animationLength) { - //Quat.print("MyAvatar: ", MyAvatar.orientation); - //Quat.print("Seat: ", seat.rotation); - MyAvatar.orientation = Quat.mix(startRotation, seat.rotation, factor - 1); - } else { - Script.update.disconnect(goToSeatAnimation); - externalThis.sitDown(); - externalThis.showIndicators(false); - } - } - - var globalMouseClick = function(event) { - var clickedOverlay = Overlays.getOverlayAtPoint({x: event.x, y: event.y}); - if (clickedOverlay == externalThis.standUpButton) { - seat.model = null; - externalThis.standUp(); - Controller.mousePressEvent.disconnect(globalMouseClick); - } - }; - - this.sitDown = function() { - sitting = true; - Settings.setValue(sittingSettingsHandle, sitting); - print("sitDown sitting status: " + Settings.getValue(sittingSettingsHandle, false)); - passedTime = 0.0; - startPosition = MyAvatar.position; - storeStartPoseAndTransition(); - try { - Script.update.disconnect(standingUpAnimation); - } catch(e){ - // no need to handle. if it wasn't connected no harm done - } - Script.update.connect(sittingDownAnimation); - Overlays.editOverlay(this.standUpButton, { visible: true }); - Controller.mousePressEvent.connect(globalMouseClick); - } - - this.standUp = function() { - sitting = false; - Settings.setValue(sittingSettingsHandle, sitting); - print("standUp sitting status: " + Settings.getValue(sittingSettingsHandle, false)); - passedTime = 0.0; - startPosition = MyAvatar.position; - MyAvatar.clearReferential(); - try{ - Script.update.disconnect(sittingDownAnimation); - } catch (e){} - Script.update.connect(standingUpAnimation); - Overlays.editOverlay(this.standUpButton, { visible: false }); - Controller.mousePressEvent.disconnect(globalMouseClick); - } - - this.addIndicators = function() { - if (!this.indicatorsAdded) { - if (this.properties.sittingPoints.length > 0) { - for (var i = 0; i < this.properties.sittingPoints.length; ++i) { - this.indicator[i] = new SeatIndicator(this.properties, i); - } - this.indicatorsAdded = true; - } - } - } - - this.removeIndicators = function() { - for (var i = 0; i < this.properties.sittingPoints.length; ++i) { - this.indicator[i].cleanup(); - } - } - - this.showIndicators = function(doShow) { - this.addIndicators(); - if (this.indicatorsAdded) { - for (var i = 0; i < this.properties.sittingPoints.length; ++i) { - this.indicator[i].show(doShow); - } - } - hiddingSeats = !doShow; - } - - function raySphereIntersection(origin, direction, center, radius) { - var A = origin; - var B = Vec3.normalize(direction); - var P = center; - - var x = Vec3.dot(Vec3.subtract(P, A), B); - var X = Vec3.sum(A, Vec3.multiply(B, x)); - var d = Vec3.length(Vec3.subtract(P, X)); - - return (x > 0 && d <= radius); - } - - this.cleanup = function() { - this.standUp(); - MyAvatar.clearReferential(); - for (var i = 0; i < pose.length; i++){ - MyAvatar.clearJointData(pose[i].joint); - } - Overlays.deleteOverlay(this.standUpButton); - for (var i = 0; i < this.indicator.length; ++i) { - this.indicator[i].cleanup(); - } - }; - - - this.createStandupButton = function() { - this.standUpButton = Overlays.addOverlay("image", { - x: buttonPositionX, y: buttonPositionY, width: buttonWidth, height: buttonHeight, - subImage: { x: buttonWidth, y: buttonHeight, width: buttonWidth, height: buttonHeight}, - imageURL: buttonImageUrl, - visible: false, - alpha: 1.0 - }); - }; - - this.handleClickEvent = function(event) { - var clickedOverlay = Overlays.getOverlayAtPoint({x: event.x, y: event.y}); - - if (clickedOverlay == this.standUpButton) { - seat.model = null; - this.standUp(); - } else { - this.addIndicators(); - if (this.indicatorsAdded) { - var pickRay = Camera.computePickRay(event.x, event.y); - - var clickedOnSeat = false; - - for (var i = 0; i < this.properties.sittingPoints.length; ++i) { - if (raySphereIntersection(pickRay.origin, - pickRay.direction, - this.indicator[i].position, - this.indicator[i].scale / 2)) { - clickedOnSeat = true; - seat.model = this.entityID; // ?? - seat.position = this.indicator[i].position; - seat.rotation = this.indicator[i].orientation; - } - } - - if (clickedOnSeat) { - passedTime = 0.0; - startPosition = MyAvatar.position; - startRotation = MyAvatar.orientation; - try{ Script.update.disconnect(standingUpAnimation); } catch(e){} - try{ Script.update.disconnect(sittingDownAnimation); } catch(e){} - Script.update.connect(goToSeatAnimation); - } - } - } - }; - - - // All callbacks start by updating the properties - this.updateProperties = function(entityID) { - if (this.entityID === null || !this.entityID.isKnownID) { - this.entityID = Entities.identifyEntity(entityID); - } - this.properties = Entities.getEntityProperties(this.entityID); - }; -}; - -Sittable.prototype = { - - unload : function(entityID) { - print("Sittable.unload()"); - this.cleanup(); - //Script.update.disconnect(SittableUpdate); - }, - - preload : function(entityID) { - print("Sittable.preload()"); - this.updateProperties(entityID); // All callbacks start by updating the properties - this.createStandupButton(); - //Script.update.connect(SittableUpdate); - }, - - - hoverOverEntity : function(entityID, mouseEvent) { - print("Sittable.hoverOverEntity()"); - this.updateProperties(entityID); // All callbacks start by updating the properties - this.showIndicators(true); - }, - - hoverLeaveEntity : function(entityID, mouseEvent) { - print("Sittable.hoverLeaveEntity()"); - this.updateProperties(entityID); // All callbacks start by updating the properties - this.showIndicators(false); - }, - - clickDownOnEntity : function(entityID, mouseEvent) { - print("Sittable.clickDownOnEntity()"); - this.updateProperties(entityID); // All callbacks start by updating the properties - this.handleClickEvent(mouseEvent); - }, - - clickReleaseOnEntity : function(entityID, mouseEvent) { - print("Sittable.clickReleaseOnEntity()"); - this.updateProperties(entityID); // All callbacks start by updating the properties - } -}; \ No newline at end of file From 97d617bd174767a9aeb12eee0f900a5665662338 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Fri, 19 Dec 2014 11:01:35 -0800 Subject: [PATCH 18/33] revert some prototype script stuff for now --- examples/entityScripts/movable.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/entityScripts/movable.js b/examples/entityScripts/movable.js index 35d11116eb..21e6261179 100644 --- a/examples/entityScripts/movable.js +++ b/examples/entityScripts/movable.js @@ -416,4 +416,4 @@ this.stopSound(); }; -}) \ No newline at end of file +}) From e4ce7d11dc8b744dec8ec1c04cb0ee87a21ee055 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Fri, 19 Dec 2014 11:32:52 -0800 Subject: [PATCH 19/33] Fix default scripts url to use s3.amazonaws.com --- interface/src/Application.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index a7b91db315..aae01681e0 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -130,7 +130,7 @@ static QTimer* idleTimer = NULL; const QString CHECK_VERSION_URL = "https://highfidelity.io/latestVersion.xml"; const QString SKIP_FILENAME = QStandardPaths::writableLocation(QStandardPaths::DataLocation) + "/hifi.skipversion"; -const QString DEFAULT_SCRIPTS_JS_URL = "http://public.highfidelity.io/scripts/defaultScripts.js"; +const QString DEFAULT_SCRIPTS_JS_URL = "http://s3.amazonaws.com/hifi-public/scripts/defaultScripts.js"; void messageHandler(QtMsgType type, const QMessageLogContext& context, const QString& message) { QString logMessage = LogHandler::getInstance().printMessage((LogMsgType) type, context, message); From 32ea38b93805d1abd260b1d33f5739dd587661a8 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Fri, 19 Dec 2014 11:33:25 -0800 Subject: [PATCH 20/33] added leaveAllEntities support --- .../entityScripts/playSoundOnEnterOrLeave.js | 2 ++ .../src/EntityTreeRenderer.cpp | 25 +++++++++++++++++-- .../src/EntityTreeRenderer.h | 1 + 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/examples/entityScripts/playSoundOnEnterOrLeave.js b/examples/entityScripts/playSoundOnEnterOrLeave.js index f82c05c580..b95e35ab1d 100644 --- a/examples/entityScripts/playSoundOnEnterOrLeave.js +++ b/examples/entityScripts/playSoundOnEnterOrLeave.js @@ -27,10 +27,12 @@ }; this.enterEntity = function(entityID) { + print("enterEntity("+entityID.id+")"); playSound(); }; this.leaveEntity = function(entityID) { + print("leaveEntity("+entityID.id+")"); playSound(); }; }) diff --git a/libraries/entities-renderer/src/EntityTreeRenderer.cpp b/libraries/entities-renderer/src/EntityTreeRenderer.cpp index e8530d5639..9f1185cfb9 100644 --- a/libraries/entities-renderer/src/EntityTreeRenderer.cpp +++ b/libraries/entities-renderer/src/EntityTreeRenderer.cpp @@ -62,6 +62,7 @@ EntityTreeRenderer::~EntityTreeRenderer() { } void EntityTreeRenderer::clear() { + leaveAllEntities(); foreach (const EntityItemID& entityID, _entityScripts.keys()) { checkAndCallUnload(entityID); } @@ -82,8 +83,7 @@ void EntityTreeRenderer::init() { // make sure our "last avatar position" is something other than our current position, so that on our // first chance, we'll check for enter/leave entity events. - glm::vec3 avatarPosition = _viewState->getAvatarPosition(); - _lastAvatarPosition = avatarPosition + glm::vec3(1.0f, 1.0f, 1.0f); + _lastAvatarPosition = _viewState->getAvatarPosition() + glm::vec3(1.0f, 1.0f, 1.0f); connect(entityTree, &EntityTree::deletingEntity, this, &EntityTreeRenderer::deletingEntity); connect(entityTree, &EntityTree::addingEntity, this, &EntityTreeRenderer::checkAndCallPreload); @@ -297,6 +297,27 @@ void EntityTreeRenderer::checkEnterLeaveEntities() { } } +void EntityTreeRenderer::leaveAllEntities() { + if (_tree) { + _tree->lockForWrite(); // so that our scripts can do edits if they want + + // for all of our previous containing entities, if they are no longer containing then send them a leave event + foreach(const EntityItemID& entityID, _currentEntitiesInside) { + emit leaveEntity(entityID); + QScriptValueList entityArgs = createEntityArgs(entityID); + QScriptValue entityScript = loadEntityScript(entityID); + if (entityScript.property("leaveEntity").isValid()) { + entityScript.property("leaveEntity").call(entityScript, entityArgs); + } + } + _currentEntitiesInside.clear(); + + // make sure our "last avatar position" is something other than our current position, so that on our + // first chance, we'll check for enter/leave entity events. + _lastAvatarPosition = _viewState->getAvatarPosition() + glm::vec3(1.0f, 1.0f, 1.0f); + _tree->unlock(); + } +} void EntityTreeRenderer::render(RenderArgs::RenderMode renderMode, RenderArgs::RenderSide renderSide) { if (_tree) { Model::startScene(renderSide); diff --git a/libraries/entities-renderer/src/EntityTreeRenderer.h b/libraries/entities-renderer/src/EntityTreeRenderer.h index 46c333d70d..92cc2c4dcc 100644 --- a/libraries/entities-renderer/src/EntityTreeRenderer.h +++ b/libraries/entities-renderer/src/EntityTreeRenderer.h @@ -129,6 +129,7 @@ private: QScriptValueList createEntityArgs(const EntityItemID& entityID); void checkEnterLeaveEntities(); + void leaveAllEntities(); glm::vec3 _lastAvatarPosition; QVector _currentEntitiesInside; From d585f8c7073a55915c3de4a76e89c769b18f42d7 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Fri, 19 Dec 2014 12:10:40 -0800 Subject: [PATCH 21/33] replace gluOrtho2D() with glOrtho() --- interface/src/devices/OculusManager.cpp | 2 +- interface/src/ui/ApplicationOverlay.cpp | 4 ++-- interface/src/ui/RearMirrorTools.cpp | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/interface/src/devices/OculusManager.cpp b/interface/src/devices/OculusManager.cpp index 1854c9539d..76a54eb9d8 100644 --- a/interface/src/devices/OculusManager.cpp +++ b/interface/src/devices/OculusManager.cpp @@ -582,7 +582,7 @@ void OculusManager::renderDistortionMesh(ovrPosef eyeRenderPose[ovrEye_Count]) { glLoadIdentity(); GLCanvas::SharedPointer glCanvas = DependencyManager::get(); - gluOrtho2D(0, glCanvas->getDeviceWidth(), 0, glCanvas->getDeviceHeight()); + glOrtho(0, glCanvas->getDeviceWidth(), 0, glCanvas->getDeviceHeight(), -1.0f, 1.0f); glDisable(GL_DEPTH_TEST); diff --git a/interface/src/ui/ApplicationOverlay.cpp b/interface/src/ui/ApplicationOverlay.cpp index ab85da125c..0350726d9c 100644 --- a/interface/src/ui/ApplicationOverlay.cpp +++ b/interface/src/ui/ApplicationOverlay.cpp @@ -180,7 +180,7 @@ void ApplicationOverlay::renderOverlay(bool renderToTexture) { glPushMatrix(); { glLoadIdentity(); - gluOrtho2D(0, glCanvas->width(), glCanvas->height(), 0); + glOrtho(0, glCanvas->width(), glCanvas->height(), 0, -1.0f, 1.0f); renderAudioMeter(); @@ -224,7 +224,7 @@ void ApplicationOverlay::displayOverlayTexture() { glMatrixMode(GL_PROJECTION); glPushMatrix(); { glLoadIdentity(); - gluOrtho2D(0, glCanvas->getDeviceWidth(), glCanvas->getDeviceHeight(), 0); + glOrtho(0, glCanvas->getDeviceWidth(), glCanvas->getDeviceHeight(), 0, -1.0f, 1.0f); glDisable(GL_DEPTH_TEST); glDisable(GL_LIGHTING); glEnable(GL_BLEND); diff --git a/interface/src/ui/RearMirrorTools.cpp b/interface/src/ui/RearMirrorTools.cpp index fd3fc34adb..2287324656 100644 --- a/interface/src/ui/RearMirrorTools.cpp +++ b/interface/src/ui/RearMirrorTools.cpp @@ -128,7 +128,7 @@ void RearMirrorTools::displayIcon(QRect bounds, QRect iconBounds, GLuint texture glPushMatrix(); glLoadIdentity(); - gluOrtho2D(bounds.left(), bounds.right(), bounds.bottom(), bounds.top()); + glOrtho(bounds.left(), bounds.right(), bounds.bottom(), bounds.top(), -1.0f, 1.0f); glDisable(GL_DEPTH_TEST); glDisable(GL_LIGHTING); glEnable(GL_TEXTURE_2D); From 046564ec470dc7587ecd680e904eaf9fc40cca0b Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Fri, 19 Dec 2014 12:35:47 -0800 Subject: [PATCH 22/33] oops double --- interface/src/devices/OculusManager.cpp | 2 +- interface/src/ui/ApplicationOverlay.cpp | 4 ++-- interface/src/ui/RearMirrorTools.cpp | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/interface/src/devices/OculusManager.cpp b/interface/src/devices/OculusManager.cpp index 76a54eb9d8..f59ce639a0 100644 --- a/interface/src/devices/OculusManager.cpp +++ b/interface/src/devices/OculusManager.cpp @@ -582,7 +582,7 @@ void OculusManager::renderDistortionMesh(ovrPosef eyeRenderPose[ovrEye_Count]) { glLoadIdentity(); GLCanvas::SharedPointer glCanvas = DependencyManager::get(); - glOrtho(0, glCanvas->getDeviceWidth(), 0, glCanvas->getDeviceHeight(), -1.0f, 1.0f); + glOrtho(0, glCanvas->getDeviceWidth(), 0, glCanvas->getDeviceHeight(), -1.0, 1.0); glDisable(GL_DEPTH_TEST); diff --git a/interface/src/ui/ApplicationOverlay.cpp b/interface/src/ui/ApplicationOverlay.cpp index 0350726d9c..b2ed9fc77d 100644 --- a/interface/src/ui/ApplicationOverlay.cpp +++ b/interface/src/ui/ApplicationOverlay.cpp @@ -180,7 +180,7 @@ void ApplicationOverlay::renderOverlay(bool renderToTexture) { glPushMatrix(); { glLoadIdentity(); - glOrtho(0, glCanvas->width(), glCanvas->height(), 0, -1.0f, 1.0f); + glOrtho(0, glCanvas->width(), glCanvas->height(), 0, -1.0, 1.0); renderAudioMeter(); @@ -224,7 +224,7 @@ void ApplicationOverlay::displayOverlayTexture() { glMatrixMode(GL_PROJECTION); glPushMatrix(); { glLoadIdentity(); - glOrtho(0, glCanvas->getDeviceWidth(), glCanvas->getDeviceHeight(), 0, -1.0f, 1.0f); + glOrtho(0, glCanvas->getDeviceWidth(), glCanvas->getDeviceHeight(), 0, -1.0, 1.0); glDisable(GL_DEPTH_TEST); glDisable(GL_LIGHTING); glEnable(GL_BLEND); diff --git a/interface/src/ui/RearMirrorTools.cpp b/interface/src/ui/RearMirrorTools.cpp index 2287324656..37f7c6ae23 100644 --- a/interface/src/ui/RearMirrorTools.cpp +++ b/interface/src/ui/RearMirrorTools.cpp @@ -128,7 +128,7 @@ void RearMirrorTools::displayIcon(QRect bounds, QRect iconBounds, GLuint texture glPushMatrix(); glLoadIdentity(); - glOrtho(bounds.left(), bounds.right(), bounds.bottom(), bounds.top(), -1.0f, 1.0f); + glOrtho(bounds.left(), bounds.right(), bounds.bottom(), bounds.top(), -1.0, 1.0); glDisable(GL_DEPTH_TEST); glDisable(GL_LIGHTING); glEnable(GL_TEXTURE_2D); From 1db1914a2efb409d5c1027343e1da4d40ab5b380 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Fri, 19 Dec 2014 13:46:33 -0800 Subject: [PATCH 23/33] replace gluProject() with just the math --- interface/src/avatar/Avatar.cpp | 138 ++++++++++++++++---------------- interface/src/avatar/Avatar.h | 1 + 2 files changed, 72 insertions(+), 67 deletions(-) diff --git a/interface/src/avatar/Avatar.cpp b/interface/src/avatar/Avatar.cpp index 39c528d080..4c309b2c8c 100644 --- a/interface/src/avatar/Avatar.cpp +++ b/interface/src/avatar/Avatar.cpp @@ -669,6 +669,49 @@ glm::vec3 Avatar::getDisplayNamePosition() { return namePosition; } +float Avatar::calculateDisplayNameScaleFactor(const glm::vec3& textPosition, bool inHMD) { + + // We need to compute the scale factor such as the text remains with fixed size respect to window coordinates + // We project a unit vector and check the difference in screen coordinates, to check which is the + // correction scale needed + // save the matrices for later scale correction factor + // The up vector must be relative to the rotation current rotation matrix: + // we set the identity + glm::vec3 testPoint0 = textPosition; + glm::vec3 testPoint1 = textPosition + (Application::getInstance()->getCamera()->getRotation() * IDENTITY_UP); + + double textWindowHeight; + + GLCanvas::SharedPointer glCanvas = DependencyManager::get(); + float windowSizeX = glCanvas->getDeviceWidth(); + float windowSizeY = glCanvas->getDeviceHeight(); + + glm::dmat4 modelViewMatrix; + glm::dmat4 projectionMatrix; + Application::getInstance()->getModelViewMatrix(&modelViewMatrix); + Application::getInstance()->getProjectionMatrix(&projectionMatrix); + + glm::dvec4 p0 = modelViewMatrix * glm::dvec4(testPoint0, 1.0); + p0 = projectionMatrix * p0; + glm::dvec2 result0 = glm::vec2(windowSizeX * (p0.x / p0.w + 1.0f) * 0.5f, windowSizeY * (p0.y / p0.w + 1.0f) * 0.5f); + + glm::dvec4 p1 = modelViewMatrix * glm::dvec4(testPoint1, 1.0); + p1 = projectionMatrix * p1; + glm::vec2 result1 = glm::vec2(windowSizeX * (p1.x / p1.w + 1.0f) * 0.5f, windowSizeY * (p1.y / p1.w + 1.0f) * 0.5f); + textWindowHeight = abs(result1.y - result0.y); + + // need to scale to compensate for the font resolution due to the device + float scaleFactor = QApplication::desktop()->windowHandle()->devicePixelRatio() * + ((textWindowHeight > EPSILON) ? 1.0f / textWindowHeight : 1.0f); + if (inHMD) { + const float HMDMODE_NAME_SCALE = 0.65f; + scaleFactor *= HMDMODE_NAME_SCALE; + } else { + scaleFactor *= Application::getInstance()->getRenderResolutionScale(); + } + return scaleFactor; +} + void Avatar::renderDisplayName() { if (_displayName.isEmpty() || _displayNameAlpha == 0.0f) { @@ -700,78 +743,39 @@ void Avatar::renderDisplayName() { frontAxis = glm::normalize(glm::vec3(frontAxis.z, 0.0f, -frontAxis.x)); float angle = acos(frontAxis.x) * ((frontAxis.z < 0) ? 1.0f : -1.0f); glRotatef(glm::degrees(angle), 0.0f, 1.0f, 0.0f); - - // We need to compute the scale factor such as the text remains with fixed size respect to window coordinates - // We project a unit vector and check the difference in screen coordinates, to check which is the - // correction scale needed - // save the matrices for later scale correction factor - glm::dmat4 modelViewMatrix; - glm::dmat4 projectionMatrix; - GLint viewportMatrix[4]; - Application::getInstance()->getModelViewMatrix(&modelViewMatrix); - Application::getInstance()->getProjectionMatrix(&projectionMatrix); - glGetIntegerv(GL_VIEWPORT, viewportMatrix); - GLdouble result0[3], result1[3]; - - // The up vector must be relative to the rotation current rotation matrix: - // we set the identity - glm::dvec3 testPoint0 = glm::dvec3(textPosition); - glm::dvec3 testPoint1 = glm::dvec3(textPosition) + glm::dvec3(Application::getInstance()->getCamera()->getRotation() * IDENTITY_UP); - bool success; - success = gluProject(testPoint0.x, testPoint0.y, testPoint0.z, - (GLdouble*)&modelViewMatrix, (GLdouble*)&projectionMatrix, viewportMatrix, - &result0[0], &result0[1], &result0[2]); - success = success && - gluProject(testPoint1.x, testPoint1.y, testPoint1.z, - (GLdouble*)&modelViewMatrix, (GLdouble*)&projectionMatrix, viewportMatrix, - &result1[0], &result1[1], &result1[2]); + float scaleFactor = calculateDisplayNameScaleFactor(textPosition, inHMD); + glScalef(scaleFactor, scaleFactor, 1.0); + + glScalef(1.0f, -1.0f, 1.0f); // TextRenderer::draw paints the text upside down in y axis - if (success) { - double textWindowHeight = abs(result1[1] - result0[1]); - // need to scale to compensate for the font resolution due to the device - float scaleFactor = QApplication::desktop()->windowHandle()->devicePixelRatio() * - ((textWindowHeight > EPSILON) ? 1.0f / textWindowHeight : 1.0f); - if (inHMD) { - const float HMDMODE_NAME_SCALE = 0.65f; - scaleFactor *= HMDMODE_NAME_SCALE; - } else { - scaleFactor *= Application::getInstance()->getRenderResolutionScale(); - } - glScalef(scaleFactor, scaleFactor, 1.0); - - glScalef(1.0f, -1.0f, 1.0f); // TextRenderer::draw paints the text upside down in y axis + int text_x = -_displayNameBoundingRect.width() / 2; + int text_y = -_displayNameBoundingRect.height() / 2; - int text_x = -_displayNameBoundingRect.width() / 2; - int text_y = -_displayNameBoundingRect.height() / 2; + // draw a gray background + int left = text_x + _displayNameBoundingRect.x(); + int right = left + _displayNameBoundingRect.width(); + int bottom = text_y + _displayNameBoundingRect.y(); + int top = bottom + _displayNameBoundingRect.height(); + const int border = 8; + bottom -= border; + left -= border; + top += border; + right += border; - // draw a gray background - int left = text_x + _displayNameBoundingRect.x(); - int right = left + _displayNameBoundingRect.width(); - int bottom = text_y + _displayNameBoundingRect.y(); - int top = bottom + _displayNameBoundingRect.height(); - const int border = 8; - bottom -= border; - left -= border; - top += border; - right += border; + // We are drawing coplanar textures with depth: need the polygon offset + glEnable(GL_POLYGON_OFFSET_FILL); + glPolygonOffset(1.0f, 1.0f); - // We are drawing coplanar textures with depth: need the polygon offset - glEnable(GL_POLYGON_OFFSET_FILL); - glPolygonOffset(1.0f, 1.0f); - - glColor4f(0.2f, 0.2f, 0.2f, _displayNameAlpha * DISPLAYNAME_BACKGROUND_ALPHA / DISPLAYNAME_ALPHA); - renderBevelCornersRect(left, bottom, right - left, top - bottom, 3); - - glColor4f(0.93f, 0.93f, 0.93f, _displayNameAlpha); - QByteArray ba = _displayName.toLocal8Bit(); - const char* text = ba.data(); - - glDisable(GL_POLYGON_OFFSET_FILL); - textRenderer(DISPLAYNAME)->draw(text_x, text_y, text); - - - } + glColor4f(0.2f, 0.2f, 0.2f, _displayNameAlpha * DISPLAYNAME_BACKGROUND_ALPHA / DISPLAYNAME_ALPHA); + renderBevelCornersRect(left, bottom, right - left, top - bottom, 3); + + glColor4f(0.93f, 0.93f, 0.93f, _displayNameAlpha); + QByteArray ba = _displayName.toLocal8Bit(); + const char* text = ba.data(); + + glDisable(GL_POLYGON_OFFSET_FILL); + textRenderer(DISPLAYNAME)->draw(text_x, text_y, text); glPopMatrix(); diff --git a/interface/src/avatar/Avatar.h b/interface/src/avatar/Avatar.h index 88ab3b12ca..d862e042c2 100644 --- a/interface/src/avatar/Avatar.h +++ b/interface/src/avatar/Avatar.h @@ -230,6 +230,7 @@ protected: float getPelvisFloatingHeight() const; glm::vec3 getDisplayNamePosition(); + float calculateDisplayNameScaleFactor(const glm::vec3& textPosition, bool inHMD); void renderDisplayName(); virtual void renderBody(RenderMode renderMode, bool postLighting, float glowLevel = 0.0f); virtual bool shouldRenderHead(const glm::vec3& cameraPosition, RenderMode renderMode) const; From 22e2fcf746af7df99a71b2f5caea198d1d63ef1e Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Fri, 19 Dec 2014 13:46:42 -0800 Subject: [PATCH 24/33] add some vec2 debugging --- libraries/shared/src/StreamUtils.cpp | 8 ++++++++ libraries/shared/src/StreamUtils.h | 1 + 2 files changed, 9 insertions(+) diff --git a/libraries/shared/src/StreamUtils.cpp b/libraries/shared/src/StreamUtils.cpp index 85b800efbe..47bb8dd4e4 100644 --- a/libraries/shared/src/StreamUtils.cpp +++ b/libraries/shared/src/StreamUtils.cpp @@ -98,6 +98,14 @@ std::ostream& operator<<(std::ostream& s, const CapsuleShape& capsule) { #ifndef QT_NO_DEBUG_STREAM #include +QDebug& operator<<(QDebug& dbg, const glm::vec2& v) { + dbg.nospace() << "{type='glm::vec2'" + ", x=" << v.x << + ", y=" << v.y << + "}"; + return dbg; +} + QDebug& operator<<(QDebug& dbg, const glm::vec3& v) { dbg.nospace() << "{type='glm::vec3'" ", x=" << v.x << diff --git a/libraries/shared/src/StreamUtils.h b/libraries/shared/src/StreamUtils.h index 6d00c0e354..d176d68e45 100644 --- a/libraries/shared/src/StreamUtils.h +++ b/libraries/shared/src/StreamUtils.h @@ -49,6 +49,7 @@ std::ostream& operator<<(std::ostream& s, const CapsuleShape& capsule); #ifndef QT_NO_DEBUG_STREAM class QDebug; // Add support for writing these to qDebug(). +QDebug& operator<<(QDebug& s, const glm::vec2& v); QDebug& operator<<(QDebug& s, const glm::vec3& v); QDebug& operator<<(QDebug& s, const glm::quat& q); QDebug& operator<<(QDebug& s, const glm::mat4& m); From 2e3a522e73d045d5efa071e8a6ca4417db52dae6 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Fri, 19 Dec 2014 13:53:44 -0800 Subject: [PATCH 25/33] remove glut.h from CmakeLists.txt and fix a compiler issue with Hair.cpp --- interface/CMakeLists.txt | 6 +++--- interface/src/Hair.cpp | 2 ++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/interface/CMakeLists.txt b/interface/CMakeLists.txt index a9688a5919..6d0b6a2f07 100644 --- a/interface/CMakeLists.txt +++ b/interface/CMakeLists.txt @@ -25,15 +25,15 @@ else () endif () if (APPLE) - set(GL_HEADERS "#include \n#include ") + set(GL_HEADERS "#include ") elseif (UNIX) # include the right GL headers for UNIX - set(GL_HEADERS "#include \n#include \n#include ") + set(GL_HEADERS "#include \n#include ") elseif (WIN32) add_definitions(-D_USE_MATH_DEFINES) # apparently needed to get M_PI and other defines from cmath/math.h add_definitions(-DWINDOWS_LEAN_AND_MEAN) # needed to make sure windows doesn't go to crazy with its defines - set(GL_HEADERS "#include \n#include \n#include \n#include ") + set(GL_HEADERS "#include \n#include \n#include ") endif () # set up the external glm library diff --git a/interface/src/Hair.cpp b/interface/src/Hair.cpp index cb664f39ed..6fd326a9b5 100644 --- a/interface/src/Hair.cpp +++ b/interface/src/Hair.cpp @@ -10,6 +10,8 @@ // // Creates single flexible verlet-integrated strands that can be used for hair/fur/grass +#include + #include "Hair.h" #include "Util.h" From 4f478e158f728412006464e0307013d908ad6e4b Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Fri, 19 Dec 2014 13:59:43 -0800 Subject: [PATCH 26/33] remove includes for glu for APPLE --- interface/src/avatar/Avatar.cpp | 5 ----- interface/src/ui/ApplicationOverlay.cpp | 5 ----- interface/src/ui/RearMirrorTools.cpp | 5 ----- 3 files changed, 15 deletions(-) diff --git a/interface/src/avatar/Avatar.cpp b/interface/src/avatar/Avatar.cpp index aa94b21d71..39c528d080 100644 --- a/interface/src/avatar/Avatar.cpp +++ b/interface/src/avatar/Avatar.cpp @@ -13,11 +13,6 @@ #include -// TODO: remove calls to gluProject to remove this include -#ifdef __APPLE__ -#include -#endif - #include #include diff --git a/interface/src/ui/ApplicationOverlay.cpp b/interface/src/ui/ApplicationOverlay.cpp index f82b44a403..ab85da125c 100644 --- a/interface/src/ui/ApplicationOverlay.cpp +++ b/interface/src/ui/ApplicationOverlay.cpp @@ -11,11 +11,6 @@ #include "InterfaceConfig.h" -// TODO: remove calls to gluProject to remove this include -#ifdef __APPLE__ -#include -#endif - #include #include diff --git a/interface/src/ui/RearMirrorTools.cpp b/interface/src/ui/RearMirrorTools.cpp index 2c671ef548..fd3fc34adb 100644 --- a/interface/src/ui/RearMirrorTools.cpp +++ b/interface/src/ui/RearMirrorTools.cpp @@ -11,11 +11,6 @@ #include "InterfaceConfig.h" -// TODO: remove calls to gluProject to remove this include -#ifdef __APPLE__ -#include -#endif - #include #include From 30e2a9c13f13c0e6cd3b13db85f4307b7b3783f4 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Fri, 19 Dec 2014 14:18:44 -0800 Subject: [PATCH 27/33] Add notifications.js to defaultScripts --- examples/defaultScripts.js | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/defaultScripts.js b/examples/defaultScripts.js index d39fce0186..cdb8e76c65 100644 --- a/examples/defaultScripts.js +++ b/examples/defaultScripts.js @@ -15,3 +15,4 @@ Script.load("hydraMove.js"); Script.load("headMove.js"); Script.load("inspect.js"); Script.load("lobby.js"); +Script.load("notifications.js"); From 7e37aaabde2f7597fdff8ef28b0c66ffd931d1dd Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Fri, 19 Dec 2014 14:24:04 -0800 Subject: [PATCH 28/33] windows build hack --- interface/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interface/CMakeLists.txt b/interface/CMakeLists.txt index 6d0b6a2f07..ff813343ab 100644 --- a/interface/CMakeLists.txt +++ b/interface/CMakeLists.txt @@ -232,7 +232,7 @@ else (APPLE) # we're using static GLEW, so define GLEW_STATIC add_definitions(-DGLEW_STATIC) - target_link_libraries(${TARGET_NAME} "${GLEW_LIBRARIES}" "${NSIGHT_LIBRARIES}" wsock32.lib opengl32.lib) + target_link_libraries(${TARGET_NAME} "${GLEW_LIBRARIES}" "${NSIGHT_LIBRARIES}" wsock32.lib opengl32.lib Winmm.lib) # try to find the Nsight package and add it to the build if we find it find_package(NSIGHT) From b7165abd5beaa5498024ed098bcbadcec83a12d5 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Fri, 19 Dec 2014 14:33:45 -0800 Subject: [PATCH 29/33] possible glew warning fix for windows --- libraries/gpu/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/gpu/CMakeLists.txt b/libraries/gpu/CMakeLists.txt index 340adcc9e6..e63495867e 100644 --- a/libraries/gpu/CMakeLists.txt +++ b/libraries/gpu/CMakeLists.txt @@ -19,7 +19,7 @@ elseif (WIN32) # we're using static GLEW, so define GLEW_STATIC add_definitions(-DGLEW_STATIC) - target_link_libraries(${TARGET_NAME} "${GLEW_LIBRARIES}" opengl32.lib) + target_link_libraries(${TARGET_NAME} opengl32.lib) # need to bubble up the GLEW_INCLUDE_DIRS list(APPEND ${TARGET_NAME}_DEPENDENCY_INCLUDES "${GLEW_INCLUDE_DIRS}") From 691be3bf7c4e29b596b44ba3c889f4111c306cb0 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Fri, 19 Dec 2014 14:59:55 -0800 Subject: [PATCH 30/33] add a test to confirm link fail --- libraries/gpu/src/gpu/GLBackend.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libraries/gpu/src/gpu/GLBackend.cpp b/libraries/gpu/src/gpu/GLBackend.cpp index 90639929ca..6663e0b169 100644 --- a/libraries/gpu/src/gpu/GLBackend.cpp +++ b/libraries/gpu/src/gpu/GLBackend.cpp @@ -117,7 +117,8 @@ GLBackend::GLBackend() : _input(), _transform() { - + // TEST FOR SANITY + glewInit(); } GLBackend::~GLBackend() { From d7d11955f3d4eafb3b7258ccd7f785752a1ff343 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Fri, 19 Dec 2014 15:05:13 -0800 Subject: [PATCH 31/33] Revert "add a test to confirm link fail" This reverts commit 691be3bf7c4e29b596b44ba3c889f4111c306cb0. --- libraries/gpu/src/gpu/GLBackend.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/libraries/gpu/src/gpu/GLBackend.cpp b/libraries/gpu/src/gpu/GLBackend.cpp index 6663e0b169..90639929ca 100644 --- a/libraries/gpu/src/gpu/GLBackend.cpp +++ b/libraries/gpu/src/gpu/GLBackend.cpp @@ -117,8 +117,7 @@ GLBackend::GLBackend() : _input(), _transform() { - // TEST FOR SANITY - glewInit(); + } GLBackend::~GLBackend() { From 2780415b1d4d529d91d8d6382d8cbadd8dbb18d1 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Fri, 19 Dec 2014 15:07:31 -0800 Subject: [PATCH 32/33] put glew link back into gpu --- libraries/gpu/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/gpu/CMakeLists.txt b/libraries/gpu/CMakeLists.txt index b4da0d8b03..7f2b475dd2 100644 --- a/libraries/gpu/CMakeLists.txt +++ b/libraries/gpu/CMakeLists.txt @@ -19,7 +19,7 @@ elseif (WIN32) # we're using static GLEW, so define GLEW_STATIC add_definitions(-DGLEW_STATIC) - target_link_libraries(${TARGET_NAME} opengl32.lib) + target_link_libraries(${TARGET_NAME} ${GLEW_LIBRARIES} opengl32.lib) # need to bubble up the GLEW_INCLUDE_DIRS list(APPEND ${TARGET_NAME}_DEPENDENCY_INCLUDES "${GLEW_INCLUDE_DIRS}") From 25a78534aae5eae68b241e9419bffdd21f294fe8 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Fri, 19 Dec 2014 15:52:31 -0800 Subject: [PATCH 33/33] Fix quad vertices for ImageOverlay and TextOverlay --- interface/src/ui/overlays/ImageOverlay.cpp | 13 +++++++++---- interface/src/ui/overlays/TextOverlay.cpp | 13 +++++++++---- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/interface/src/ui/overlays/ImageOverlay.cpp b/interface/src/ui/overlays/ImageOverlay.cpp index f903dfe19c..b14f49737f 100644 --- a/interface/src/ui/overlays/ImageOverlay.cpp +++ b/interface/src/ui/overlays/ImageOverlay.cpp @@ -100,26 +100,31 @@ void ImageOverlay::render(RenderArgs* args) { float w = fromImage.width() / imageWidth; // ?? is this what we want? not sure float h = fromImage.height() / imageHeight; + int left = _bounds.left(); + int right = _bounds.right() + 1; + int top = _bounds.top(); + int bottom = _bounds.bottom() + 1; + glBegin(GL_QUADS); if (_renderImage) { glTexCoord2f(x, 1.0f - y); } - glVertex2f(_bounds.left(), _bounds.top()); + glVertex2f(left, top); if (_renderImage) { glTexCoord2f(x + w, 1.0f - y); } - glVertex2f(_bounds.right(), _bounds.top()); + glVertex2f(right, top); if (_renderImage) { glTexCoord2f(x + w, 1.0f - (y + h)); } - glVertex2f(_bounds.right(), _bounds.bottom()); + glVertex2f(right, bottom); if (_renderImage) { glTexCoord2f(x, 1.0f - (y + h)); } - glVertex2f(_bounds.left(), _bounds.bottom()); + glVertex2f(left, bottom); glEnd(); if (_renderImage) { diff --git a/interface/src/ui/overlays/TextOverlay.cpp b/interface/src/ui/overlays/TextOverlay.cpp index 97d910eb64..03a5c3d846 100644 --- a/interface/src/ui/overlays/TextOverlay.cpp +++ b/interface/src/ui/overlays/TextOverlay.cpp @@ -70,11 +70,16 @@ void TextOverlay::render(RenderArgs* args) { glColor4f(backgroundColor.red / MAX_COLOR, backgroundColor.green / MAX_COLOR, backgroundColor.blue / MAX_COLOR, getBackgroundAlpha()); + int left = _bounds.left(); + int right = _bounds.right() + 1; + int top = _bounds.top(); + int bottom = _bounds.bottom() + 1; + glBegin(GL_QUADS); - glVertex2f(_bounds.left(), _bounds.top()); - glVertex2f(_bounds.right(), _bounds.top()); - glVertex2f(_bounds.right(), _bounds.bottom()); - glVertex2f(_bounds.left(), _bounds.bottom()); + glVertex2f(left, top); + glVertex2f(right, top); + glVertex2f(right, bottom); + glVertex2f(left, bottom); glEnd(); // Same font properties as textSize()