From 394985ef4538b8c3c3f968cb4bc66cde02035eea Mon Sep 17 00:00:00 2001 From: Philip Rosedale Date: Wed, 14 May 2014 11:52:01 -0700 Subject: [PATCH 01/60] Switched to Halo gun in gun.js, work in progress on hydraMove to add flying --- examples/gun.js | 5 +-- examples/hydraMove.js | 98 ++++++++++++++++++++++++------------------- 2 files changed, 56 insertions(+), 47 deletions(-) diff --git a/examples/gun.js b/examples/gun.js index e404ae1d4d..a5c0ee83e0 100644 --- a/examples/gun.js +++ b/examples/gun.js @@ -39,7 +39,7 @@ var impactSound = new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-pub var targetHitSound = new Sound("http://highfidelity-public.s3-us-west-1.amazonaws.com/sounds/Space%20Invaders/hit.raw"); var targetLaunchSound = new Sound("http://highfidelity-public.s3-us-west-1.amazonaws.com/sounds/Space%20Invaders/shoot.raw"); -var gunModel = "http://highfidelity-public.s3-us-west-1.amazonaws.com/models/attachments/Raygun2.fst"; +var gunModel = "http://public.highfidelity.io/models/attachments/HaloGun.fst"; var audioOptions = new AudioInjectionOptions(); audioOptions.volume = 0.9; @@ -199,7 +199,7 @@ function playLoadSound() { Audio.playSound(loadSound, audioOptions); } -MyAvatar.attach(gunModel, "RightHand", {x: -0.02, y: -.14, z: 0.07}, Quat.fromPitchYawRollDegrees(-70, -151, 72), 0.20); +//MyAvatar.attach(gunModel, "RightHand", {x: -0.02, y: -.14, z: 0.07}, Quat.fromPitchYawRollDegrees(-70, -151, 72), 0.20); MyAvatar.attach(gunModel, "LeftHand", {x: -0.02, y: -.14, z: 0.07}, Quat.fromPitchYawRollDegrees(-70, -151, 72), 0.20); // Give a bit of time to load before playing sound @@ -320,7 +320,6 @@ function scriptEnding() { Overlays.deleteOverlay(reticle); Overlays.deleteOverlay(text); MyAvatar.detachOne(gunModel); - MyAvatar.detachOne(gunModel); } Particles.particleCollisionWithVoxel.connect(particleCollisionWithVoxel); diff --git a/examples/hydraMove.js b/examples/hydraMove.js index ad0eeddfca..638e5fe226 100644 --- a/examples/hydraMove.js +++ b/examples/hydraMove.js @@ -50,6 +50,13 @@ var LEFT_BUTTON_4 = 4; var RIGHT_PALM = 2; var RIGHT_BUTTON_4 = 10; + +function printVector(text, v, decimals) { + print(text + " " + v.x.toFixed(decimals) + ", " + v.y.toFixed(decimals) + ", " + v.z.toFixed(decimals)); +} + +var debug = true; + // Used by handleGrabBehavior() for managing the grab position changes function getAndResetGrabDelta() { var HAND_GRAB_SCALE_DISTANCE = 2.0; @@ -60,24 +67,12 @@ function getAndResetGrabDelta() { return result; } -// Used by handleGrabBehavior() for managing the grab velocity feature -function getAndResetGrabDeltaVelocity() { - var HAND_GRAB_SCALE_VELOCITY = 50.0; - var delta = Vec3.multiply(grabDeltaVelocity, (MyAvatar.scale * HAND_GRAB_SCALE_VELOCITY)); - grabDeltaVelocity = { x: 0, y: 0, z: 0}; - var avatarRotation = MyAvatar.orientation; - var result = Quat.multiply(avatarRotation, Vec3.multiply(delta, -1)); - return result; -} - -// Used by handleGrabBehavior() for managing the grab rotation feature -function getAndResetGrabRotation() { +function getGrabRotation() { var quatDiff = Quat.multiply(grabCurrentRotation, Quat.inverse(grabStartRotation)); - grabStartRotation = grabCurrentRotation; return quatDiff; } -// handles all the grab related behavior: position (crawl), velocity (flick), and rotate (twist) +// When move button is pressed, process results function handleGrabBehavior(deltaTime) { // check for and handle grab behaviors grabbingWithRightHand = Controller.isButtonPressed(RIGHT_BUTTON_4); @@ -88,9 +83,12 @@ function handleGrabBehavior(deltaTime) { if (grabbingWithRightHand && !wasGrabbingWithRightHand) { // Just starting grab, capture starting rotation grabStartRotation = Controller.getSpatialControlRawRotation(RIGHT_PALM); + grabStartPosition = Controller.getSpatialControlPosition(RIGHT_PALM); + if (debug) printVector("start position", grabStartPosition, 3); } if (grabbingWithRightHand) { - grabDelta = Vec3.sum(grabDelta, Vec3.multiply(Controller.getSpatialControlVelocity(RIGHT_PALM), deltaTime)); + //grabDelta = Vec3.sum(grabDelta, Vec3.multiply(Controller.getSpatialControlVelocity(RIGHT_PALM), deltaTime)); + grabDelta = Vec3.subtract(Controller.getSpatialControlPosition(RIGHT_PALM), grabStartPosition); grabCurrentRotation = Controller.getSpatialControlRawRotation(RIGHT_PALM); } if (!grabbingWithRightHand && wasGrabbingWithRightHand) { @@ -102,10 +100,13 @@ function handleGrabBehavior(deltaTime) { if (grabbingWithLeftHand && !wasGrabbingWithLeftHand) { // Just starting grab, capture starting rotation grabStartRotation = Controller.getSpatialControlRawRotation(LEFT_PALM); + grabStartPosition = Controller.getSpatialControlPosition(LEFT_PALM); + if (debug) printVector("start position", grabStartPosition, 3); } if (grabbingWithLeftHand) { - grabDelta = Vec3.sum(grabDelta, Vec3.multiply(Controller.getSpatialControlVelocity(LEFT_PALM), deltaTime)); + //grabDelta = Vec3.sum(grabDelta, Vec3.multiply(Controller.getSpatialControlVelocity(LEFT_PALM), deltaTime)); + grabDelta = Vec3.subtract(Controller.getSpatialControlPosition(LEFT_PALM), grabStartPosition); grabCurrentRotation = Controller.getSpatialControlRawRotation(LEFT_PALM); } if (!grabbingWithLeftHand && wasGrabbingWithLeftHand) { @@ -119,44 +120,53 @@ function handleGrabBehavior(deltaTime) { if (grabbing) { - // move position - var moveFromGrab = getAndResetGrabDelta(); - if (Vec3.length(moveFromGrab) > EPSILON) { - MyAvatar.position = Vec3.sum(MyAvatar.position, moveFromGrab); - velocity = { x: 0, y: 0, z: 0}; - } - - // add some rotation... - var deltaRotation = getAndResetGrabRotation(); - var GRAB_CONTROLLER_TURN_SCALING = 0.5; - var euler = Vec3.multiply(Quat.safeEulerAngles(deltaRotation), GRAB_CONTROLLER_TURN_SCALING); + var headOrientation = MyAvatar.headOrientation; + var front = Quat.getFront(headOrientation); + var right = Quat.getRight(headOrientation); + var up = Quat.getUp(headOrientation); - // Adjust body yaw by yaw from controller - var orientation = Quat.multiply(Quat.angleAxis(-euler.y, {x:0, y: 1, z:0}), MyAvatar.orientation); + //grabDelta = Quat.multiply(headOrientation, grabDelta); + //grabDelta = Quat.multiply(Camera.getOrientation(), grabDelta); + grabDelta = Vec3.multiplyQbyV(MyAvatar.orientation, Vec3.multiply(grabDelta, -1)); + + if (debug) { + printVector("grabDelta: ", grabDelta, 3); + } + + var THRUST_GRAB_SCALING = 0.0; + + var thrustFront = Vec3.multiply(front, MyAvatar.scale * grabDelta.z * THRUST_GRAB_SCALING * deltaTime); + MyAvatar.addThrust(thrustFront); + var thrustRight = Vec3.multiply(right, MyAvatar.scale * grabDelta.x * THRUST_GRAB_SCALING * deltaTime); + MyAvatar.addThrust(thrustRight); + var thrustUp = Vec3.multiply(up, MyAvatar.scale * grabDelta.y * THRUST_GRAB_SCALING * deltaTime); + MyAvatar.addThrust(thrustUp); + + + // add some rotation... + var deltaRotation = getGrabRotation(); + var GRAB_CONTROLLER_PITCH_SCALING = 2.5; + var GRAB_CONTROLLER_YAW_SCALING = 2.5; + var GRAB_CONTROLLER_ROLL_SCALING = 2.5; + var euler = Quat.safeEulerAngles(deltaRotation); + + // Adjust body yaw by roll from controller + var orientation = Quat.multiply(Quat.angleAxis(((euler.y * GRAB_CONTROLLER_YAW_SCALING) + + (euler.z * GRAB_CONTROLLER_ROLL_SCALING)) * deltaTime, {x:0, y: 1, z:0}), MyAvatar.orientation); MyAvatar.orientation = orientation; // Adjust head pitch from controller - MyAvatar.headPitch = MyAvatar.headPitch - euler.x; + MyAvatar.headPitch = MyAvatar.headPitch + (euler.x * GRAB_CONTROLLER_PITCH_SCALING * deltaTime); + + // Add some camera roll proportional to the rate of turn (so it feels like an airplane or roller coaster) + } - // add some velocity... - if (stoppedGrabbing) { - velocity = Vec3.sum(velocity, getAndResetGrabDeltaVelocity()); - } - - // handle residual velocity - if(Vec3.length(velocity) > EPSILON) { - MyAvatar.position = Vec3.sum(MyAvatar.position, Vec3.multiply(velocity, deltaTime)); - // damp velocity - velocity = Vec3.multiply(velocity, damping); - } - - wasGrabbingWithRightHand = grabbingWithRightHand; wasGrabbingWithLeftHand = grabbingWithLeftHand; } -// Main update function that handles flying and grabbing behaviort +// Update for joysticks and move button function flyWithHydra(deltaTime) { var thrustJoystickPosition = Controller.getJoystickPosition(THRUST_CONTROLLER); From 8388255542bf7a340930a64e5a29ed857a520730 Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Wed, 14 May 2014 15:29:16 -0700 Subject: [PATCH 02/60] Working on alternate IK mode. --- interface/src/Menu.cpp | 1 + interface/src/Menu.h | 1 + interface/src/avatar/SkeletonModel.cpp | 9 ++++++++- interface/src/avatar/SkeletonModel.h | 1 + 4 files changed, 11 insertions(+), 1 deletion(-) diff --git a/interface/src/Menu.cpp b/interface/src/Menu.cpp index 2daf5b0240..7c8f1d75a9 100644 --- a/interface/src/Menu.cpp +++ b/interface/src/Menu.cpp @@ -351,6 +351,7 @@ Menu::Menu() : addCheckableActionToQMenuAndActionHash(handOptionsMenu, MenuOption::HandsCollideWithSelf, 0, false); addCheckableActionToQMenuAndActionHash(handOptionsMenu, MenuOption::ShowIKConstraints, 0, false); addCheckableActionToQMenuAndActionHash(handOptionsMenu, MenuOption::AlignForearmsWithWrists, 0, true); + addCheckableActionToQMenuAndActionHash(handOptionsMenu, MenuOption::AlternateIK, 0, false); addDisabledActionAndSeparator(developerMenu, "Testing"); diff --git a/interface/src/Menu.h b/interface/src/Menu.h index 230584bf07..2a521bf59c 100644 --- a/interface/src/Menu.h +++ b/interface/src/Menu.h @@ -267,6 +267,7 @@ private: namespace MenuOption { const QString AboutApp = "About Interface"; const QString AlignForearmsWithWrists = "Align Forearms with Wrists"; + const QString AlternateIK = "Alternate IK"; const QString AmbientOcclusion = "Ambient Occlusion"; const QString Atmosphere = "Atmosphere"; const QString Attachments = "Attachments..."; diff --git a/interface/src/avatar/SkeletonModel.cpp b/interface/src/avatar/SkeletonModel.cpp index e48ebfa63c..1e57481c66 100644 --- a/interface/src/avatar/SkeletonModel.cpp +++ b/interface/src/avatar/SkeletonModel.cpp @@ -176,7 +176,10 @@ void SkeletonModel::applyPalmData(int jointIndex, PalmData& palm) { palmRotation = rotationBetween(palmRotation * glm::vec3(-sign, 0.0f, 0.0f), direction) * palmRotation; // set hand position, rotation - if (Menu::getInstance()->isOptionChecked(MenuOption::AlignForearmsWithWrists)) { + if (Menu::getInstance()->isOptionChecked(MenuOption::AlternateIK)) { + setHandPosition(jointIndex, palm.getPosition(), palmRotation); + + } else if (Menu::getInstance()->isOptionChecked(MenuOption::AlignForearmsWithWrists)) { glm::vec3 forearmVector = palmRotation * glm::vec3(sign, 0.0f, 0.0f); setJointPosition(parentJointIndex, palm.getPosition() + forearmVector * geometry.joints.at(jointIndex).distanceToParent * extractUniformScale(_scale)); @@ -276,3 +279,7 @@ void SkeletonModel::renderJointConstraints(int jointIndex) { glLineWidth(1.0f); } +void SkeletonModel::setHandPosition(int jointIndex, const glm::vec3& position, const glm::quat& rotation) { + +} + diff --git a/interface/src/avatar/SkeletonModel.h b/interface/src/avatar/SkeletonModel.h index 20384829ea..77e6ea33d4 100644 --- a/interface/src/avatar/SkeletonModel.h +++ b/interface/src/avatar/SkeletonModel.h @@ -51,6 +51,7 @@ protected: private: void renderJointConstraints(int jointIndex); + void setHandPosition(int jointIndex, const glm::vec3& position, const glm::quat& rotation); Avatar* _owningAvatar; }; From 7bee0478be2f53fdb8016f5576c0a45fa3d458e7 Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Thu, 15 May 2014 11:30:09 -0700 Subject: [PATCH 03/60] More work on integrating IK solution from Sixense. --- interface/src/avatar/SkeletonModel.cpp | 52 +++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) diff --git a/interface/src/avatar/SkeletonModel.cpp b/interface/src/avatar/SkeletonModel.cpp index 1e57481c66..1921094a0f 100644 --- a/interface/src/avatar/SkeletonModel.cpp +++ b/interface/src/avatar/SkeletonModel.cpp @@ -164,7 +164,8 @@ void SkeletonModel::applyPalmData(int jointIndex, PalmData& palm) { // rotate palm to align with its normal (normal points out of hand's palm) glm::quat palmRotation; - if (Menu::getInstance()->isOptionChecked(MenuOption::AlignForearmsWithWrists)) { + if (!Menu::getInstance()->isOptionChecked(MenuOption::AlternateIK) && + Menu::getInstance()->isOptionChecked(MenuOption::AlignForearmsWithWrists)) { getJointRotation(parentJointIndex, palmRotation, true); } else { getJointRotation(jointIndex, palmRotation, true); @@ -280,6 +281,55 @@ void SkeletonModel::renderJointConstraints(int jointIndex) { } void SkeletonModel::setHandPosition(int jointIndex, const glm::vec3& position, const glm::quat& rotation) { + // this algorithm is from sample code from sixense + const FBXGeometry& geometry = _geometry->getFBXGeometry(); + int elbowJointIndex = geometry.joints.at(jointIndex).parentIndex; + if (elbowJointIndex == -1) { + return; + } + int shoulderJointIndex = geometry.joints.at(elbowJointIndex).parentIndex; + glm::vec3 shoulderPosition; + if (!getJointPosition(shoulderJointIndex, shoulderPosition)) { + return; + } + // precomputed lengths + float scale = extractUniformScale(_scale); + float upperArmLength = geometry.joints.at(elbowJointIndex).distanceToParent * scale; + float lowerArmLength = geometry.joints.at(jointIndex).distanceToParent * scale; + // first set wrist position + glm::vec3 wristPosition = position; + + glm::vec3 shoulderToWrist = wristPosition - shoulderPosition; + float distanceToWrist = glm::length(shoulderToWrist); + + // prevent gimbal lock + if (distanceToWrist > upperArmLength + lowerArmLength - EPSILON) { + distanceToWrist = upperArmLength + lowerArmLength - EPSILON; + shoulderToWrist = glm::normalize(shoulderToWrist) * distanceToWrist; + wristPosition = shoulderPosition + shoulderToWrist; + } + + // cosine of angle from upper arm to hand vector + float cosA = (upperArmLength * upperArmLength + distanceToWrist * distanceToWrist - lowerArmLength * lowerArmLength) / + (2 * upperArmLength * distanceToWrist); + float mid = upperArmLength * cosA; + float height = sqrt(upperArmLength * upperArmLength + mid * mid - 2 * upperArmLength * mid * cosA); + + // direction of the elbow + glm::vec3 handNormal = glm::cross(rotation * glm::vec3(0.0f, 1.0f, 0.0f), shoulderToWrist); // elbow rotating with wrist + glm::vec3 relaxedNormal = glm::cross(glm::vec3(0.0f, 1.0f, 0.0f), shoulderToWrist); // elbow pointing straight down + const float NORMAL_WEIGHT = 0.5f; + glm::vec3 finalNormal = glm::mix(relaxedNormal, handNormal, NORMAL_WEIGHT); + + if((jointIndex == geometry.rightHandJointIndex && finalNormal.y > 0.0f) || + (jointIndex == geometry.leftHandJointIndex && finalNormal.y < 0)) { + finalNormal.y = 0.0f; // dont allow elbows to point inward (y is vertical axis) + } + + glm::vec3 tangent = glm::normalize(glm::cross(shoulderToWrist, finalNormal)); + + // ik solution + glm::vec3 elbowPosition = shoulderPosition + glm::normalize(shoulderToWrist) * mid - tangent * height; } From aac73c36650f329271c155aba554aae1c5e8034f Mon Sep 17 00:00:00 2001 From: Mika Impola Date: Thu, 15 May 2014 21:44:45 +0300 Subject: [PATCH 04/60] Script to make your avatar sit down. --- examples/sit.js | 141 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 141 insertions(+) create mode 100644 examples/sit.js diff --git a/examples/sit.js b/examples/sit.js new file mode 100644 index 0000000000..d67f6f6bb5 --- /dev/null +++ b/examples/sit.js @@ -0,0 +1,141 @@ +// +// sit.js +// examples +// +// Created by Mika Impola on February 8, 2014 +// Copyright 2014 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + + +var buttonImageUrl = "https://worklist-prod.s3.amazonaws.com/attachment/0aca88e1-9bd8-5c1d.svg"; + +var windowDimensions = Controller.getViewportDimensions(); + +var buttonWidth = 37; +var buttonHeight = 45; +var buttonPadding = 10; + +var buttonPositionX = windowDimensions.x - buttonPadding - buttonWidth; +var buttonPositionY = (windowDimensions.y - buttonHeight) / 2 ; + +var sitDownButton = Overlays.addOverlay("image", { + x: buttonPositionX, y: buttonPositionY, width: buttonWidth, height: buttonHeight, + subImage: { x: 0, y: buttonHeight, width: buttonWidth, height: buttonHeight}, + imageURL: buttonImageUrl, + visible: true, + alpha: 1.0 + }); +var 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 + }); + +var passedTime = 0.0; +var startPosition = null; +var animationLenght = 2.0; + +// 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}}, + + {joint:"Spine2", rotation: {x:20, y:0.0, z:0.0}}, + + {joint:"RightShoulder", rotation: {x:0.0, y:40.0, z:0.0}}, + {joint:"LeftShoulder", rotation: {x:0.0, y:-40.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; + } +} + +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; + } +} + +Controller.mousePressEvent.connect(function(event){ + + var clickedOverlay = Overlays.getOverlayAtPoint({x: event.x, y: event.y}); + + if (clickedOverlay == sitDownButton) { + 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(sitDownButton, { visible: false }); + Overlays.editOverlay(standUpButton, { visible: true }); + } else if (clickedOverlay == standUpButton) { + passedTime = 0.0; + startPosition = MyAvatar.position; + try{ + Script.update.disconnect(sittingDownAnimation); + } catch (e){} + Script.update.connect(standingUpAnimation); + Overlays.editOverlay(standUpButton, { visible: false }); + Overlays.editOverlay(sitDownButton, { visible: true }); + } +}) + + +Script.scriptEnding.connect(function() { + + for (var i = 0; i < pose.length; i++){ + MyAvatar.clearJointData(pose[i][0]); + } + + Overlays.deleteOverlay(sitDownButton); + Overlays.deleteOverlay(standUpButton); +}); From 46405874457840396802179c5f6c87926af2e7cc Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Thu, 15 May 2014 12:28:55 -0700 Subject: [PATCH 05/60] more correct model bounding capsule --- interface/src/avatar/Avatar.cpp | 60 +++++---- interface/src/renderer/Model.cpp | 213 ++++++++++++++++++++----------- interface/src/renderer/Model.h | 4 + 3 files changed, 173 insertions(+), 104 deletions(-) diff --git a/interface/src/avatar/Avatar.cpp b/interface/src/avatar/Avatar.cpp index 41dc50b1fa..7dec933b5a 100644 --- a/interface/src/avatar/Avatar.cpp +++ b/interface/src/avatar/Avatar.cpp @@ -214,37 +214,39 @@ void Avatar::render(const glm::vec3& cameraPosition, RenderMode renderMode) { if (Menu::getInstance()->isOptionChecked(MenuOption::Avatars)) { renderBody(renderMode, glowLevel); } - if (renderMode != SHADOW_RENDER_MODE && - Menu::getInstance()->isOptionChecked(MenuOption::RenderSkeletonCollisionShapes)) { - _skeletonModel.updateShapePositions(); - _skeletonModel.renderJointCollisionShapes(0.7f); - } - if (renderMode != SHADOW_RENDER_MODE && - Menu::getInstance()->isOptionChecked(MenuOption::RenderHeadCollisionShapes)) { - if (shouldRenderHead(cameraPosition, renderMode)) { - getHead()->getFaceModel().updateShapePositions(); + if (renderMode != SHADOW_RENDER_MODE) { + bool renderSkeleton = Menu::getInstance()->isOptionChecked(MenuOption::RenderSkeletonCollisionShapes); + bool renderHead = Menu::getInstance()->isOptionChecked(MenuOption::RenderHeadCollisionShapes); + bool renderBounding = Menu::getInstance()->isOptionChecked(MenuOption::RenderBoundingCollisionShapes); + if (renderSkeleton || renderHead || renderBounding) { + updateShapePositions(); + } + + if (Menu::getInstance()->isOptionChecked(MenuOption::RenderSkeletonCollisionShapes)) { + _skeletonModel.renderJointCollisionShapes(0.7f); + } + + if (Menu::getInstance()->isOptionChecked(MenuOption::RenderHeadCollisionShapes) + && shouldRenderHead(cameraPosition, renderMode)) { getHead()->getFaceModel().renderJointCollisionShapes(0.7f); } - } - if (renderMode != SHADOW_RENDER_MODE && - Menu::getInstance()->isOptionChecked(MenuOption::RenderBoundingCollisionShapes)) { - if (shouldRenderHead(cameraPosition, renderMode)) { - getHead()->getFaceModel().updateShapePositions(); + if (Menu::getInstance()->isOptionChecked(MenuOption::RenderBoundingCollisionShapes) + && shouldRenderHead(cameraPosition, renderMode)) { getHead()->getFaceModel().renderBoundingCollisionShapes(0.7f); - _skeletonModel.updateShapePositions(); _skeletonModel.renderBoundingCollisionShapes(0.7f); } - } - // If this is the avatar being looked at, render a little ball above their head - if (renderMode != SHADOW_RENDER_MODE &&_isLookAtTarget) { - const float LOOK_AT_INDICATOR_RADIUS = 0.03f; - const float LOOK_AT_INDICATOR_HEIGHT = 0.60f; - const float LOOK_AT_INDICATOR_COLOR[] = { 0.8f, 0.0f, 0.0f, 0.5f }; - glPushMatrix(); - glColor4fv(LOOK_AT_INDICATOR_COLOR); - glTranslatef(_position.x, _position.y + (getSkeletonHeight() * LOOK_AT_INDICATOR_HEIGHT), _position.z); - glutSolidSphere(LOOK_AT_INDICATOR_RADIUS, 15, 15); - glPopMatrix(); + + // If this is the avatar being looked at, render a little ball above their head + if (_isLookAtTarget) { + const float LOOK_AT_INDICATOR_RADIUS = 0.03f; + const float LOOK_AT_INDICATOR_HEIGHT = 0.60f; + const float LOOK_AT_INDICATOR_COLOR[] = { 0.8f, 0.0f, 0.0f, 0.5f }; + glPushMatrix(); + glColor4fv(LOOK_AT_INDICATOR_COLOR); + glTranslatef(_position.x, _position.y + (getSkeletonHeight() * LOOK_AT_INDICATOR_HEIGHT), _position.z); + glutSolidSphere(LOOK_AT_INDICATOR_RADIUS, 15, 15); + glPopMatrix(); + } } // quick check before falling into the code below: @@ -585,6 +587,12 @@ void Avatar::updateShapePositions() { _skeletonModel.updateShapePositions(); Model& headModel = getHead()->getFaceModel(); headModel.updateShapePositions(); + /* KEEP FOR DEBUG: use this in rather than code above to see shapes + * in their default positions where the bounding shape is computed. + _skeletonModel.resetShapePositions(); + Model& headModel = getHead()->getFaceModel(); + headModel.resetShapePositions(); + */ } bool Avatar::findCollisions(const QVector& shapes, CollisionList& collisions) { diff --git a/interface/src/renderer/Model.cpp b/interface/src/renderer/Model.cpp index e1bfd21bba..8a0286f63c 100644 --- a/interface/src/renderer/Model.cpp +++ b/interface/src/renderer/Model.cpp @@ -39,6 +39,7 @@ Model::Model(QObject* parent) : _scaledToFit(false), _snapModelToCenter(false), _snappedToCenter(false), + _rootIndex(-1), _shapesAreDirty(true), _boundingRadius(0.f), _boundingShape(), @@ -138,6 +139,7 @@ QVector Model::createJointStates(const FBXGeometry& geometry) const FBXJoint& joint = geometry.joints[i]; int parentIndex = joint.parentIndex; if (parentIndex == -1) { + _rootIndex = i; glm::mat4 baseTransform = glm::mat4_cast(_rotation) * glm::scale(_scale) * glm::translate(_offset); glm::quat combinedRotation = joint.preRotation * state.rotation * joint.postRotation; state.transform = baseTransform * geometry.offset * glm::translate(state.translation) * joint.preTransform * @@ -586,66 +588,20 @@ void Model::clearShapes() { void Model::rebuildShapes() { clearShapes(); - if (!_geometry) { + if (!_geometry || _rootIndex == -1) { return; } const FBXGeometry& geometry = _geometry->getFBXGeometry(); - if (geometry.joints.isEmpty()) { return; } - int numJoints = geometry.joints.size(); - QVector transforms; - transforms.fill(glm::mat4(), numJoints); - QVector combinedRotations; - combinedRotations.fill(glm::quat(), numJoints); - QVector shapeIsSet; - shapeIsSet.fill(false, numJoints); - int rootIndex = 0; - + // We create the shapes with proper dimensions, but we set their transforms later. float uniformScale = extractUniformScale(_scale); - int numShapesSet = 0; - int lastNumShapesSet = -1; - while (numShapesSet < numJoints && numShapesSet != lastNumShapesSet) { - lastNumShapesSet = numShapesSet; - for (int i = 0; i < numJoints; ++i) { - if (shapeIsSet[i]) { - continue; - } - const FBXJoint& joint = geometry.joints[i]; - int parentIndex = joint.parentIndex; - if (parentIndex == -1) { - rootIndex = i; - glm::mat4 baseTransform = glm::mat4_cast(_rotation) * uniformScale * glm::translate(_offset); - glm::quat combinedRotation = joint.preRotation * joint.rotation * joint.postRotation; - transforms[i] = baseTransform * geometry.offset * glm::translate(joint.translation) * joint.preTransform * - glm::mat4_cast(combinedRotation) * joint.postTransform; - combinedRotations[i] = _rotation * combinedRotation; - ++numShapesSet; - shapeIsSet[i] = true; - } else if (shapeIsSet[parentIndex]) { - glm::quat combinedRotation = joint.preRotation * joint.rotation * joint.postRotation; - transforms[i] = transforms[parentIndex] * glm::translate(joint.translation) * joint.preTransform * - glm::mat4_cast(combinedRotation) * joint.postTransform; - combinedRotations[i] = combinedRotations[parentIndex] * combinedRotation; - ++numShapesSet; - shapeIsSet[i] = true; - } - } - } - - // joint shapes - Extents totalExtents; - totalExtents.reset(); for (int i = 0; i < _jointStates.size(); i++) { const FBXJoint& joint = geometry.joints[i]; - glm::vec3 worldPosition = extractTranslation(transforms[i]); - Extents shapeExtents; - shapeExtents.reset(); - float radius = uniformScale * joint.boneRadius; float halfHeight = 0.5f * uniformScale * joint.distanceToParent; Shape::Type type = joint.shapeType; @@ -655,47 +611,148 @@ void Model::rebuildShapes() { } if (type == Shape::CAPSULE_SHAPE) { CapsuleShape* capsule = new CapsuleShape(radius, halfHeight); - capsule->setPosition(worldPosition); - capsule->setRotation(combinedRotations[i] * joint.shapeRotation); _jointShapes.push_back(capsule); - - // add the two furthest surface points of the capsule - glm::vec3 axis; - capsule->computeNormalizedAxis(axis); - axis = halfHeight * axis + glm::vec3(radius); - shapeExtents.addPoint(worldPosition + axis); - shapeExtents.addPoint(worldPosition - axis); - - totalExtents.addExtents(shapeExtents); } else if (type == Shape::SPHERE_SHAPE) { - SphereShape* sphere = new SphereShape(radius, worldPosition); + SphereShape* sphere = new SphereShape(radius, glm::vec3(0.0f)); _jointShapes.push_back(sphere); - - glm::vec3 axis = glm::vec3(radius); - shapeExtents.addPoint(worldPosition + axis); - shapeExtents.addPoint(worldPosition - axis); - totalExtents.addExtents(shapeExtents); } else { // this shape type is not handled and the joint shouldn't collide, // however we must have a shape for each joint, // so we make a bogus sphere with zero radius. // TODO: implement collision groups for more control over what collides with what - SphereShape* sphere = new SphereShape(0.f, worldPosition); + SphereShape* sphere = new SphereShape(0.f, glm::vec3(0.0f)); _jointShapes.push_back(sphere); } } - // bounding shape - // NOTE: we assume that the longest side of totalExtents is the yAxis + // This method moves the shapes to their default positions in Model frame + // which is where we compute the bounding shape's parameters. + computeBoundingShape(geometry); + + // finally sync shapes to joint positions + _shapesAreDirty = true; + updateShapePositions(); +} + +void Model::computeBoundingShape(const FBXGeometry& geometry) { + // compute default joint transforms and rotations + // (in local frame, ignoring Model translation and rotation) + int numJoints = geometry.joints.size(); + QVector transforms; + transforms.fill(glm::mat4(), numJoints); + QVector finalRotations; + finalRotations.fill(glm::quat(), numJoints); + + QVector shapeIsSet; + shapeIsSet.fill(false, numJoints); + int numShapesSet = 0; + int lastNumShapesSet = -1; + glm::vec3 rootOffset(0.0f); + while (numShapesSet < numJoints && numShapesSet != lastNumShapesSet) { + lastNumShapesSet = numShapesSet; + for (int i = 0; i < numJoints; i++) { + const FBXJoint& joint = geometry.joints.at(i); + int parentIndex = joint.parentIndex; + + if (parentIndex == -1) { + glm::mat4 baseTransform = glm::scale(_scale) * glm::translate(_offset); + glm::quat combinedRotation = joint.preRotation * joint.rotation * joint.postRotation; + transforms[i] = baseTransform * geometry.offset * glm::translate(joint.translation) * joint.preTransform * glm::mat4_cast(combinedRotation) * joint.postTransform; + rootOffset = extractTranslation(transforms[i]); + finalRotations[i] = combinedRotation; + ++numShapesSet; + shapeIsSet[i] = true; + } else if (shapeIsSet[parentIndex]) { + glm::quat combinedRotation = joint.preRotation * joint.rotation * joint.postRotation; + transforms[i] = transforms[parentIndex] * glm::translate(joint.translation) * joint.preTransform * glm::mat4_cast(combinedRotation) * joint.postTransform; + finalRotations[i] = finalRotations[parentIndex] * combinedRotation; + ++numShapesSet; + shapeIsSet[i] = true; + } + } + } + + // sync shapes to joints + _boundingRadius = 0.0f; + float uniformScale = extractUniformScale(_scale); + for (int i = 0; i < _jointShapes.size(); i++) { + const FBXJoint& joint = geometry.joints[i]; + glm::vec3 jointToShapeOffset = uniformScale * (finalRotations[i] * joint.shapePosition); + glm::vec3 localPosition = extractTranslation(transforms[i]) + jointToShapeOffset- rootOffset; + Shape* shape = _jointShapes[i]; + shape->setPosition(localPosition); + shape->setRotation(finalRotations[i] * joint.shapeRotation); + float distance = glm::length(localPosition) + shape->getBoundingRadius(); + if (distance > _boundingRadius) { + _boundingRadius = distance; + } + } + + // compute bounding box + Extents totalExtents; + totalExtents.reset(); + for (int i = 0; i < _jointShapes.size(); i++) { + Extents shapeExtents; + shapeExtents.reset(); + + Shape* shape = _jointShapes[i]; + glm::vec3 localPosition = shape->getPosition(); + int type = shape->getType(); + if (type == Shape::CAPSULE_SHAPE) { + // add the two furthest surface points of the capsule + CapsuleShape* capsule = static_cast(shape); + glm::vec3 axis; + capsule->computeNormalizedAxis(axis); + float radius = capsule->getRadius(); + float halfHeight = capsule->getHalfHeight(); + axis = halfHeight * axis + glm::vec3(radius); + + shapeExtents.addPoint(localPosition + axis); + shapeExtents.addPoint(localPosition - axis); + totalExtents.addExtents(shapeExtents); + } else if (type == Shape::SPHERE_SHAPE) { + float radius = shape->getBoundingRadius(); + glm::vec3 axis = glm::vec3(radius); + shapeExtents.addPoint(localPosition + axis); + shapeExtents.addPoint(localPosition - axis); + totalExtents.addExtents(shapeExtents); + } + } + + // compute bounding shape parameters + // NOTE: we assume that the longest side of totalExtents is the yAxis... glm::vec3 diagonal = totalExtents.maximum - totalExtents.minimum; - // the radius is half the RMS of the X and Z sides: + // ... and assume the radius is half the RMS of the X and Z sides: float capsuleRadius = 0.5f * sqrtf(0.5f * (diagonal.x * diagonal.x + diagonal.z * diagonal.z)); _boundingShape.setRadius(capsuleRadius); _boundingShape.setHalfHeight(0.5f * diagonal.y - capsuleRadius); + _boundingShapeLocalOffset = 0.5f * (totalExtents.maximum + totalExtents.minimum); +} - glm::quat inverseRotation = glm::inverse(_rotation); - glm::vec3 rootPosition = extractTranslation(transforms[rootIndex]); - _boundingShapeLocalOffset = inverseRotation * (0.5f * (totalExtents.maximum + totalExtents.minimum) - rootPosition); +void Model::resetShapePositions() { + // DEBUG method. + // Moves shapes to the joint default locations for debug visibility into + // how the bounding shape is computed. + + if (!_geometry || _rootIndex == -1) { + // geometry or joints have not yet been created + return; + } + + const FBXGeometry& geometry = _geometry->getFBXGeometry(); + if (geometry.joints.isEmpty() || _jointShapes.size() != geometry.joints.size()) { + return; + } + + // The shapes are moved to their default positions in computeBoundingShape(). + computeBoundingShape(geometry); + + // Then we move them into world frame for rendering at the Model's location. + for (int i = 0; i < _jointShapes.size(); i++) { + Shape* shape = _jointShapes[i]; + shape->setPosition(_translation + _rotation * shape->getPosition()); + shape->setRotation(_rotation * shape->getRotation()); + } _boundingShape.setPosition(_translation + _rotation * _boundingShapeLocalOffset); _boundingShape.setRotation(_rotation); } @@ -711,17 +768,17 @@ void Model::updateShapePositions() { // shape position and rotation need to be in world-frame glm::vec3 jointToShapeOffset = uniformScale * (_jointStates[i].combinedRotation * joint.shapePosition); glm::vec3 worldPosition = extractTranslation(_jointStates[i].transform) + jointToShapeOffset + _translation; - _jointShapes[i]->setPosition(worldPosition); - _jointShapes[i]->setRotation(_jointStates[i].combinedRotation * joint.shapeRotation); - float distance2 = glm::distance2(worldPosition, _translation); - if (distance2 > _boundingRadius) { - _boundingRadius = distance2; + Shape* shape = _jointShapes[i]; + shape->setPosition(worldPosition); + shape->setRotation(_jointStates[i].combinedRotation * joint.shapeRotation); + float distance = glm::distance(worldPosition, _translation) + shape->getBoundingRadius(); + if (distance > _boundingRadius) { + _boundingRadius = distance; } if (joint.parentIndex == -1) { rootPosition = worldPosition; } } - _boundingRadius = sqrtf(_boundingRadius); _shapesAreDirty = false; _boundingShape.setPosition(rootPosition + _rotation * _boundingShapeLocalOffset); _boundingShape.setRotation(_rotation); diff --git a/interface/src/renderer/Model.h b/interface/src/renderer/Model.h index 1a469c8122..d80b2f13fa 100644 --- a/interface/src/renderer/Model.h +++ b/interface/src/renderer/Model.h @@ -185,6 +185,7 @@ public: void clearShapes(); void rebuildShapes(); + void resetShapePositions(); void updateShapePositions(); void renderJointCollisionShapes(float alpha); void renderBoundingCollisionShapes(float alpha); @@ -232,6 +233,7 @@ protected: bool _snapModelToCenter; /// is the model's offset automatically adjusted to center around 0,0,0 in model space bool _snappedToCenter; /// are we currently snapped to center + int _rootIndex; class JointState { public: @@ -291,6 +293,8 @@ protected: void applyRotationDelta(int jointIndex, const glm::quat& delta, bool constrain = true); + void computeBoundingShape(const FBXGeometry& geometry); + private: void applyNextGeometry(); From 49a7f8c9108e8b9a12a58ee3b42d89be931f2975 Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Thu, 15 May 2014 12:42:38 -0700 Subject: [PATCH 06/60] formatting some lines that are too long --- interface/src/renderer/Model.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/interface/src/renderer/Model.cpp b/interface/src/renderer/Model.cpp index 6cb62dbcfd..90ae9e5e46 100644 --- a/interface/src/renderer/Model.cpp +++ b/interface/src/renderer/Model.cpp @@ -674,14 +674,16 @@ void Model::computeBoundingShape(const FBXGeometry& geometry) { if (parentIndex == -1) { glm::mat4 baseTransform = glm::scale(_scale) * glm::translate(_offset); glm::quat combinedRotation = joint.preRotation * joint.rotation * joint.postRotation; - transforms[i] = baseTransform * geometry.offset * glm::translate(joint.translation) * joint.preTransform * glm::mat4_cast(combinedRotation) * joint.postTransform; + transforms[i] = baseTransform * geometry.offset * glm::translate(joint.translation) + * joint.preTransform * glm::mat4_cast(combinedRotation) * joint.postTransform; rootOffset = extractTranslation(transforms[i]); finalRotations[i] = combinedRotation; ++numShapesSet; shapeIsSet[i] = true; } else if (shapeIsSet[parentIndex]) { glm::quat combinedRotation = joint.preRotation * joint.rotation * joint.postRotation; - transforms[i] = transforms[parentIndex] * glm::translate(joint.translation) * joint.preTransform * glm::mat4_cast(combinedRotation) * joint.postTransform; + transforms[i] = transforms[parentIndex] * glm::translate(joint.translation) + * joint.preTransform * glm::mat4_cast(combinedRotation) * joint.postTransform; finalRotations[i] = finalRotations[parentIndex] * combinedRotation; ++numShapesSet; shapeIsSet[i] = true; From 7a3826b72a7fea97770065244812e1b225bff963 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Thu, 15 May 2014 14:35:01 -0700 Subject: [PATCH 07/60] Add Node border display --- interface/src/Application.cpp | 5 + interface/src/Application.h | 7 +- interface/src/Menu.cpp | 13 +++ interface/src/Menu.h | 3 + interface/src/ui/NodeBounds.cpp | 190 ++++++++++++++++++++++++++++++++ interface/src/ui/NodeBounds.h | 45 ++++++++ 6 files changed, 262 insertions(+), 1 deletion(-) create mode 100644 interface/src/ui/NodeBounds.cpp create mode 100644 interface/src/ui/NodeBounds.h diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index fb414311ef..fa19fd620b 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -169,6 +169,7 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : _bytesPerSecond(0), _previousScriptLocation(), _logger(new FileLogger(this)), + _nodeBoundsDisplay(this), _runningScriptsWidget(new RunningScriptsWidget(_window)), _runningScriptsWidgetWasVisible(false) { @@ -2556,6 +2557,9 @@ void Application::displaySide(Camera& whichCamera, bool selfAvatarOnly) { // restore default, white specular glMaterialfv(GL_FRONT, GL_SPECULAR, WHITE_SPECULAR_COLOR); + + _nodeBoundsDisplay.draw(); + } bool mirrorMode = (whichCamera.getInterpolatedMode() == CAMERA_MODE_MIRROR); @@ -2792,6 +2796,7 @@ void Application::displayOverlay() { ? 80 : 20; drawText(_glWidget->width() - 100, _glWidget->height() - timerBottom, 0.30f, 0.0f, 0, frameTimer, WHITE_TEXT); } + _nodeBoundsDisplay.drawOverlay(); _overlays.render2D(); diff --git a/interface/src/Application.h b/interface/src/Application.h index 54e6bcdcac..8a685b9643 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -72,6 +72,7 @@ #include "ui/BandwidthDialog.h" #include "ui/BandwidthMeter.h" #include "ui/ModelsBrowser.h" +#include "ui/NodeBounds.h" #include "ui/OctreeStatsDialog.h" #include "ui/RearMirrorTools.h" #include "ui/LodToolsDialog.h" @@ -189,6 +190,8 @@ public: bool isMouseHidden() const { return _mouseHidden; } const glm::vec3& getMouseRayOrigin() const { return _mouseRayOrigin; } const glm::vec3& getMouseRayDirection() const { return _mouseRayDirection; } + int getMouseX() const { return _mouseX; } + int getMouseY() const { return _mouseY; } Faceplus* getFaceplus() { return &_faceplus; } Faceshift* getFaceshift() { return &_faceshift; } Visage* getVisage() { return &_visage; } @@ -242,7 +245,7 @@ public: void computeOffAxisFrustum(float& left, float& right, float& bottom, float& top, float& nearVal, float& farVal, glm::vec4& nearClipPlane, glm::vec4& farClipPlane) const; - + NodeBounds& getNodeBoundsDisplay() { return _nodeBoundsDisplay; } VoxelShader& getVoxelShader() { return _voxelShader; } PointShader& getPointShader() { return _pointShader; } @@ -520,6 +523,8 @@ private: NodeToOctreeSceneStats _octreeServerSceneStats; QReadWriteLock _octreeSceneStatsLock; + NodeBounds _nodeBoundsDisplay; + std::vector _voxelFades; ControllerScriptingInterface _controllerScriptingInterface; QPointer _logDialog; diff --git a/interface/src/Menu.cpp b/interface/src/Menu.cpp index ad2b220d55..c0e1ab54a2 100644 --- a/interface/src/Menu.cpp +++ b/interface/src/Menu.cpp @@ -42,6 +42,7 @@ #include "ui/MetavoxelEditor.h" #include "ui/ModelsBrowser.h" #include "ui/LoginDialog.h" +#include "ui/NodeBounds.h" Menu* Menu::_instance = NULL; @@ -242,6 +243,18 @@ Menu::Menu() : SLOT(setEnable3DTVMode(bool))); + NodeBounds& nodeBounds = appInstance->getNodeBoundsDisplay(); + addCheckableActionToQMenuAndActionHash(viewMenu, MenuOption::ShowBordersVoxelNodes, + Qt::CTRL | Qt::SHIFT | Qt::Key_1, false, + &nodeBounds, SLOT(setShowVoxelNodes(bool))); + addCheckableActionToQMenuAndActionHash(viewMenu, MenuOption::ShowBordersModelNodes, + Qt::CTRL | Qt::SHIFT | Qt::Key_2, false, + &nodeBounds, SLOT(setShowModelNodes(bool))); + addCheckableActionToQMenuAndActionHash(viewMenu, MenuOption::ShowBordersParticleNodes, + Qt::CTRL | Qt::SHIFT | Qt::Key_3, false, + &nodeBounds, SLOT(setShowParticleNodes(bool))); + + QMenu* avatarSizeMenu = viewMenu->addMenu("Avatar Size"); addActionToQMenuAndActionHash(avatarSizeMenu, diff --git a/interface/src/Menu.h b/interface/src/Menu.h index f1d35fcb81..b108ff8e46 100644 --- a/interface/src/Menu.h +++ b/interface/src/Menu.h @@ -367,6 +367,9 @@ namespace MenuOption { const QString SettingsExport = "Export Settings"; const QString SettingsImport = "Import Settings"; const QString Shadows = "Shadows"; + const QString ShowBordersVoxelNodes = "Show Borders - Voxel Nodes"; + const QString ShowBordersModelNodes = "Show Borders - Model Nodes"; + const QString ShowBordersParticleNodes = "Show Borders - Particle Nodes"; const QString ShowCulledSharedFaces = "Show Culled Shared Voxel Faces"; const QString ShowIKConstraints = "Show IK Constraints"; const QString Stars = "Stars"; diff --git a/interface/src/ui/NodeBounds.cpp b/interface/src/ui/NodeBounds.cpp new file mode 100644 index 0000000000..ffdf52514e --- /dev/null +++ b/interface/src/ui/NodeBounds.cpp @@ -0,0 +1,190 @@ +// +// NodeBounds.cpp +// interface/src/ui +// +// Created by Ryan Huffman on 05/14/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 +// + +#include +#include + +#include "Application.h" +#include "NodeBounds.h" +#include "Util.h" + +NodeBounds::NodeBounds(QObject* parent) : + QObject(parent), + _showVoxelNodes(false), + _showModelNodes(false), + _showParticleNodes(false), + _overlayText("") { + +} + +void NodeBounds::draw() { + NodeToJurisdictionMap& voxelServerJurisdictions = Application::getInstance()->getVoxelServerJurisdictions(); + NodeToJurisdictionMap& modelServerJurisdictions = Application::getInstance()->getModelServerJurisdictions(); + NodeToJurisdictionMap& particleServerJurisdictions = Application::getInstance()->getParticleServerJurisdictions(); + NodeToJurisdictionMap* serverJurisdictions; + + Application* application = Application::getInstance(); + const glm::vec3& mouseRayOrigin = application->getMouseRayOrigin(); + const glm::vec3& mouseRayDirection = application->getMouseRayDirection(); + + float closest = FLT_MAX; + glm::vec3 closestCenter; + float closestScale = 0; + bool closestIsInside = true; + Node* closestNode = NULL; + bool isSelecting = false; + + int num = 0; + NodeList* nodeList = NodeList::getInstance(); + + foreach (const SharedNodePointer& node, nodeList->getNodeHash()) { + NodeType_t nodeType = node->getType(); + + float r = nodeType == NodeType::VoxelServer ? 1.0 : 0.0; + float g = nodeType == NodeType::ParticleServer ? 1.0 : 0.0; + float b = nodeType == NodeType::ModelServer ? 1.0 : 0.0; + + if (nodeType == NodeType::VoxelServer && _showVoxelNodes) { + serverJurisdictions = &voxelServerJurisdictions; + } else if (nodeType == NodeType::ModelServer && _showModelNodes) { + serverJurisdictions = &modelServerJurisdictions; + } else if (nodeType == NodeType::ParticleServer && _showParticleNodes) { + serverJurisdictions = &particleServerJurisdictions; + } else { + continue; + } + + QUuid nodeUUID = node->getUUID(); + if (serverJurisdictions->find(nodeUUID) != serverJurisdictions->end()) { + const JurisdictionMap& map = serverJurisdictions->value(nodeUUID); + + unsigned char* rootCode = map.getRootOctalCode(); + + if (rootCode) { + VoxelPositionSize rootDetails; + voxelDetailsForCode(rootCode, rootDetails); + glm::vec3 location(rootDetails.x, rootDetails.y, rootDetails.z); + location *= (float)TREE_SCALE; + float len = rootDetails.s * TREE_SCALE; + AABox serverBounds(location, rootDetails.s * TREE_SCALE); + + glm::vec3 center = serverBounds.getVertex(BOTTOM_RIGHT_NEAR) + (serverBounds.getVertex(TOP_LEFT_FAR) - serverBounds.getVertex(BOTTOM_RIGHT_NEAR)) / 2.0f; + + float scaleFactor = rootDetails.s * TREE_SCALE; + scaleFactor *= rootDetails.s == 1 ? 1.05 : 0.95; + scaleFactor *= nodeType == NodeType::VoxelServer ? 1.0 : (nodeType == NodeType::ParticleServer ? 0.980 : 0.960); + + drawNodeBorder(center, scaleFactor, r, g, b); + + float distance; + BoxFace face; + bool inside = serverBounds.contains(mouseRayOrigin); + bool colliding = serverBounds.findRayIntersection(mouseRayOrigin, mouseRayDirection, distance, face); + + if (colliding && (!isSelecting || (!inside && (distance < closest || closestIsInside)))) { + closest = distance; + closestCenter = center; + closestScale = scaleFactor; + closestIsInside = inside; + closestNode = node.data(); + isSelecting = true; + } + } + } + } + + if (isSelecting) { + glPushMatrix(); + + glTranslatef(closestCenter.x, closestCenter.y, closestCenter.z); + glScalef(closestScale, closestScale, closestScale); + + NodeType_t selectedNodeType = closestNode->getType(); + float r = selectedNodeType == NodeType::VoxelServer ? 1.0 : 0.0; + float g = selectedNodeType == NodeType::ParticleServer ? 1.0 : 0.0; + float b = selectedNodeType == NodeType::ModelServer ? 1.0 : 0.0; + glColor4f(r, g, b, 0.2); + glutSolidCube(1.0); + + glPopMatrix(); + + HifiSockAddr addr = closestNode->getPublicSocket(); + _overlayText = QString("%1:%2") + .arg(addr.getAddress().toString()) + .arg(addr.getPort()); + } else { + _overlayText = QString(); + } +} + +void NodeBounds::drawNodeBorder(glm::vec3 center, float scale, float red, float green, float blue) { + glPushMatrix(); + + glTranslatef(center.x, center.y, center.z); + glScalef(scale, scale, scale); + + glLineWidth(2.5); + glColor3f(red, green, blue); + glBegin(GL_LINES); + + glVertex3f(-0.5, -0.5, -0.5); + glVertex3f( 0.5, -0.5, -0.5); + + glVertex3f(-0.5, -0.5, -0.5); + glVertex3f(-0.5, 0.5, -0.5); + + glVertex3f(-0.5, -0.5, -0.5); + glVertex3f(-0.5, -0.5, 0.5); + + glVertex3f(-0.5, 0.5, -0.5); + glVertex3f( 0.5, 0.5, -0.5); + + glVertex3f(-0.5, 0.5, -0.5); + glVertex3f(-0.5, 0.5, 0.5); + + + + glVertex3f( 0.5, 0.5, 0.5); + glVertex3f(-0.5, 0.5, 0.5); + + glVertex3f( 0.5, 0.5, 0.5); + glVertex3f( 0.5, -0.5, 0.5); + + glVertex3f( 0.5, 0.5, 0.5); + glVertex3f( 0.5, 0.5, -0.5); + + glVertex3f( 0.5, -0.5, 0.5); + glVertex3f(-0.5, -0.5, 0.5); + + glVertex3f( 0.5, -0.5, 0.5); + glVertex3f( 0.5, -0.5, -0.5); + + + glVertex3f( 0.5, 0.5, -0.5); + glVertex3f( 0.5, -0.5, -0.5); + + glVertex3f(-0.5, 0.5, 0.5); + glVertex3f(-0.5, -0.5, 0.5); + + glEnd(); + + glPopMatrix(); +} + +const float WHITE_TEXT[] = { 0.93f, 0.93f, 0.93f }; +void NodeBounds::drawOverlay() { + if (!_overlayText.isNull() && !_overlayText.isEmpty()) { + QGLWidget* glWidget = Application::getInstance()->getGLWidget(); + Application* application = Application::getInstance(); + drawText(application->getMouseX(), application->getMouseY(), 0.1f, 0.0f, 0, _overlayText.toLocal8Bit().data(), WHITE_TEXT); + // drawText(application->getMouseX(), application->getMouseY(), 0.1f, 0.0f, 0, "durr", WHITE_TEXT); + } +} diff --git a/interface/src/ui/NodeBounds.h b/interface/src/ui/NodeBounds.h new file mode 100644 index 0000000000..c4cd7002bd --- /dev/null +++ b/interface/src/ui/NodeBounds.h @@ -0,0 +1,45 @@ +// +// NodeBounds.h +// interface/src/ui +// +// Created by Ryan Huffman on 05/14/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 +// + +#ifndef hifi_NodeBounds_h +#define hifi_NodeBounds_h + +#include + +class NodeBounds : public QObject { + Q_OBJECT +public: + NodeBounds(QObject* parent = NULL); + + bool getShowVoxelNodes() { return _showVoxelNodes; } + bool getShowModelNodes() { return _showModelNodes; } + bool getShowParticleNodes() { return _showParticleNodes; } + + void draw(); + void drawOverlay(); + +public slots: + void setShowVoxelNodes(bool value) { _showVoxelNodes = value; } + void setShowModelNodes(bool value) { _showModelNodes = value; } + void setShowParticleNodes(bool value) { _showParticleNodes = value; } + +protected: + void drawNodeBorder(glm::vec3 center, float scale, float red, float green, float blue); + +private: + bool _showVoxelNodes; + bool _showModelNodes; + bool _showParticleNodes; + QString _overlayText; + +}; + +#endif // hifi_NodeBounds_h From 3eefb6a93ee73d45c1f0ed4cfa1dd2078fd54b9b Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Thu, 15 May 2014 15:32:32 -0700 Subject: [PATCH 08/60] Rotation bits for alternate IK. --- interface/src/avatar/SkeletonModel.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/interface/src/avatar/SkeletonModel.cpp b/interface/src/avatar/SkeletonModel.cpp index 1921094a0f..540565f5b8 100644 --- a/interface/src/avatar/SkeletonModel.cpp +++ b/interface/src/avatar/SkeletonModel.cpp @@ -322,8 +322,8 @@ void SkeletonModel::setHandPosition(int jointIndex, const glm::vec3& position, c const float NORMAL_WEIGHT = 0.5f; glm::vec3 finalNormal = glm::mix(relaxedNormal, handNormal, NORMAL_WEIGHT); - if((jointIndex == geometry.rightHandJointIndex && finalNormal.y > 0.0f) || - (jointIndex == geometry.leftHandJointIndex && finalNormal.y < 0)) { + bool rightHand = (jointIndex == geometry.rightHandJointIndex); + if (rightHand ? (finalNormal.y > 0.0f) : (finalNormal.y < 0.0f)) { finalNormal.y = 0.0f; // dont allow elbows to point inward (y is vertical axis) } @@ -331,5 +331,17 @@ void SkeletonModel::setHandPosition(int jointIndex, const glm::vec3& position, c // ik solution glm::vec3 elbowPosition = shoulderPosition + glm::normalize(shoulderToWrist) * mid - tangent * height; + + glm::vec3 forwardVector(rightHand ? -1.0f : 1.0f, 0.0f, 0.0f); + + glm::quat shoulderRotation; + getJointRotation(shoulderJointIndex, shoulderRotation, true); + applyRotationDelta(shoulderJointIndex, rotationBetween(shoulderRotation * forwardVector, elbowPosition - shoulderPosition), false); + + glm::quat elbowRotation; + getJointRotation(elbowJointIndex, elbowRotation, true); + applyRotationDelta(elbowJointIndex, rotationBetween(elbowRotation * forwardVector, wristPosition - elbowPosition), false); + + setJointRotation(jointIndex, rotation, true); } From 301234a39773208192066d0903ea4836fbf79bc4 Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Thu, 15 May 2014 15:34:01 -0700 Subject: [PATCH 09/60] Tabs -> spaces. --- interface/src/avatar/SkeletonModel.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/interface/src/avatar/SkeletonModel.cpp b/interface/src/avatar/SkeletonModel.cpp index 540565f5b8..3786280a3c 100644 --- a/interface/src/avatar/SkeletonModel.cpp +++ b/interface/src/avatar/SkeletonModel.cpp @@ -320,16 +320,16 @@ void SkeletonModel::setHandPosition(int jointIndex, const glm::vec3& position, c glm::vec3 handNormal = glm::cross(rotation * glm::vec3(0.0f, 1.0f, 0.0f), shoulderToWrist); // elbow rotating with wrist glm::vec3 relaxedNormal = glm::cross(glm::vec3(0.0f, 1.0f, 0.0f), shoulderToWrist); // elbow pointing straight down const float NORMAL_WEIGHT = 0.5f; - glm::vec3 finalNormal = glm::mix(relaxedNormal, handNormal, NORMAL_WEIGHT); + glm::vec3 finalNormal = glm::mix(relaxedNormal, handNormal, NORMAL_WEIGHT); bool rightHand = (jointIndex == geometry.rightHandJointIndex); if (rightHand ? (finalNormal.y > 0.0f) : (finalNormal.y < 0.0f)) { finalNormal.y = 0.0f; // dont allow elbows to point inward (y is vertical axis) } - glm::vec3 tangent = glm::normalize(glm::cross(shoulderToWrist, finalNormal)); - - // ik solution + glm::vec3 tangent = glm::normalize(glm::cross(shoulderToWrist, finalNormal)); + + // ik solution glm::vec3 elbowPosition = shoulderPosition + glm::normalize(shoulderToWrist) * mid - tangent * height; glm::vec3 forwardVector(rightHand ? -1.0f : 1.0f, 0.0f, 0.0f); From 61fd09e0bd16e985bfc8dfdd490d46ff5ff77b29 Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Thu, 15 May 2014 16:24:31 -0700 Subject: [PATCH 10/60] Add ability to anchor an overlay --- examples/editModels.js | 39 +++++++++++++++----------- interface/src/ui/overlays/Overlay.cpp | 12 ++++++-- interface/src/ui/overlays/Overlay.h | 8 ++++++ interface/src/ui/overlays/Overlays.cpp | 12 ++++++++ 4 files changed, 52 insertions(+), 19 deletions(-) diff --git a/examples/editModels.js b/examples/editModels.js index 70a2e178ae..9a20a7db27 100644 --- a/examples/editModels.js +++ b/examples/editModels.js @@ -76,38 +76,42 @@ function controller(wichSide) { this.oldModelRadius; this.laser = Overlays.addOverlay("line3d", { - position: this.palmPosition, - end: this.tipPosition, + position: { x: 0, y: 0, z: 0 }, + end: { x: 0, y: 0, z: 0 }, color: LASER_COLOR, alpha: 1, visible: false, - lineWidth: LASER_WIDTH + lineWidth: LASER_WIDTH, + anchor: "MyAvatar" }); this.guideScale = 0.02; this.ball = Overlays.addOverlay("sphere", { - position: this.palmPosition, + position: { x: 0, y: 0, z: 0 }, size: this.guideScale, solid: true, color: { red: 0, green: 255, blue: 0 }, alpha: 1, visible: false, + anchor: "MyAvatar" }); this.leftRight = Overlays.addOverlay("line3d", { - position: this.palmPosition, - end: this.tipPosition, + position: { x: 0, y: 0, z: 0 }, + end: { x: 0, y: 0, z: 0 }, color: { red: 0, green: 0, blue: 255 }, alpha: 1, visible: false, - lineWidth: LASER_WIDTH + lineWidth: LASER_WIDTH, + anchor: "MyAvatar" }); this.topDown = Overlays.addOverlay("line3d", { - position: this.palmPosition, - end: this.tipPosition, + position: { x: 0, y: 0, z: 0 }, + end: { x: 0, y: 0, z: 0 }, color: { red: 0, green: 0, blue: 255 }, alpha: 1, visible: false, - lineWidth: LASER_WIDTH + lineWidth: LASER_WIDTH, + anchor: "MyAvatar" }); @@ -170,10 +174,11 @@ function controller(wichSide) { } this.moveLaser = function () { - var endPosition = Vec3.sum(this.palmPosition, Vec3.multiply(this.front, LASER_LENGTH_FACTOR)); + var startPosition = Vec3.subtract(this.palmPosition, MyAvatar.position); + var endPosition = Vec3.sum(startPosition, Vec3.multiply(this.front, LASER_LENGTH_FACTOR)); Overlays.editOverlay(this.laser, { - position: this.palmPosition, + position: startPosition, end: endPosition, visible: true }); @@ -219,11 +224,11 @@ function controller(wichSide) { position: newPosition, modelRotation: newRotation }); - print("Moving " + this.modelID.id); +// print("Moving " + this.modelID.id); // Vec3.print("Old Position: ", this.oldModelPosition); // Vec3.print("Sav Position: ", newPosition); - Quat.print("Old Rotation: ", this.oldModelRotation); - Quat.print("New Rotation: ", newRotation); +// Quat.print("Old Rotation: ", this.oldModelRotation); +// Quat.print("New Rotation: ", newRotation); this.oldModelRotation = newRotation; this.oldModelPosition = newPosition; @@ -301,7 +306,7 @@ var rightController = new controller(RIGHT); function moveModels() { if (leftController.grabbing && rightController.grabbing && rightController.modelID.id == leftController.modelID.id) { - print("Both controllers"); + //print("Both controllers"); var oldLeftPoint = Vec3.sum(leftController.oldPalmPosition, Vec3.multiply(leftController.oldFront, leftController.x)); var oldRightPoint = Vec3.sum(rightController.oldPalmPosition, Vec3.multiply(rightController.oldFront, rightController.x)); @@ -319,7 +324,7 @@ function moveModels() { var newPosition = Vec3.sum(middle, Vec3.multiply(Vec3.subtract(leftController.oldModelPosition, oldMiddle), ratio)); - Vec3.print("Ratio : " + ratio + " New position: ", newPosition); + //Vec3.print("Ratio : " + ratio + " New position: ", newPosition); var rotation = Quat.multiply(leftController.rotation, Quat.inverse(leftController.oldRotation)); rotation = Quat.multiply(rotation, leftController.oldModelRotation); diff --git a/interface/src/ui/overlays/Overlay.cpp b/interface/src/ui/overlays/Overlay.cpp index 3b38addb76..8ec7cbace1 100644 --- a/interface/src/ui/overlays/Overlay.cpp +++ b/interface/src/ui/overlays/Overlay.cpp @@ -23,7 +23,8 @@ Overlay::Overlay() : _parent(NULL), _alpha(DEFAULT_ALPHA), _color(DEFAULT_BACKGROUND_COLOR), - _visible(true) + _visible(true), + _anchor(NO_ANCHOR) { } @@ -51,8 +52,15 @@ void Overlay::setProperties(const QScriptValue& properties) { if (properties.property("alpha").isValid()) { setAlpha(properties.property("alpha").toVariant().toFloat()); } - + if (properties.property("visible").isValid()) { setVisible(properties.property("visible").toVariant().toBool()); } + + if (properties.property("anchor").isValid()) { + QString property = properties.property("anchor").toVariant().toString(); + if (property == "MyAvatar") { + setAnchor(MY_AVATAR); + } + } } diff --git a/interface/src/ui/overlays/Overlay.h b/interface/src/ui/overlays/Overlay.h index 6feb159e05..7667b3d3fd 100644 --- a/interface/src/ui/overlays/Overlay.h +++ b/interface/src/ui/overlays/Overlay.h @@ -28,6 +28,11 @@ class Overlay : public QObject { Q_OBJECT public: + enum Anchor { + NO_ANCHOR, + MY_AVATAR + }; + Overlay(); ~Overlay(); void init(QGLWidget* parent); @@ -38,11 +43,13 @@ public: bool getVisible() const { return _visible; } const xColor& getColor() const { return _color; } float getAlpha() const { return _alpha; } + Anchor getAnchor() const { return _anchor; } // setters void setVisible(bool visible) { _visible = visible; } void setColor(const xColor& color) { _color = color; } void setAlpha(float alpha) { _alpha = alpha; } + void setAnchor(Anchor anchor) { _anchor = anchor; } virtual void setProperties(const QScriptValue& properties); @@ -51,6 +58,7 @@ protected: float _alpha; xColor _color; bool _visible; // should the overlay be drawn at all + Anchor _anchor; }; diff --git a/interface/src/ui/overlays/Overlays.cpp b/interface/src/ui/overlays/Overlays.cpp index 4eb4f030ac..78fe54b267 100644 --- a/interface/src/ui/overlays/Overlays.cpp +++ b/interface/src/ui/overlays/Overlays.cpp @@ -8,6 +8,7 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // +#include #include "Cube3DOverlay.h" #include "ImageOverlay.h" @@ -57,8 +58,19 @@ void Overlays::render2D() { } void Overlays::render3D() { + glm::vec3 myAvatarPosition = Application::getInstance()->getAvatar()->getPosition(); + foreach(Overlay* thisOverlay, _overlays3D) { + glPushMatrix(); + switch (thisOverlay->getAnchor()) { + case Overlay::MY_AVATAR: + glTranslatef(myAvatarPosition.x, myAvatarPosition.y, myAvatarPosition.z); + break; + default: + break; + } thisOverlay->render(); + glPopMatrix(); } } From 6dd08ca1bf0cb98ffa52dad5c7b28352ce2aaaa0 Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Thu, 15 May 2014 17:09:28 -0700 Subject: [PATCH 11/60] Working on joystick support using SDL. --- interface/CMakeLists.txt | 8 +++ interface/src/Application.h | 3 ++ interface/src/devices/JoystickManager.cpp | 63 +++++++++++++++++++++++ interface/src/devices/JoystickManager.h | 52 +++++++++++++++++++ 4 files changed, 126 insertions(+) create mode 100644 interface/src/devices/JoystickManager.cpp create mode 100644 interface/src/devices/JoystickManager.h diff --git a/interface/CMakeLists.txt b/interface/CMakeLists.txt index 96c212add6..3cbeff7801 100644 --- a/interface/CMakeLists.txt +++ b/interface/CMakeLists.txt @@ -136,6 +136,7 @@ find_package(Faceplus) find_package(Faceshift) find_package(LibOVR) find_package(PrioVR) +find_package(SDL) find_package(Sixense) find_package(Visage) find_package(ZLIB) @@ -193,6 +194,13 @@ if (PRIOVR_FOUND AND NOT DISABLE_PRIOVR) target_link_libraries(${TARGET_NAME} "${PRIOVR_LIBRARIES}") endif (PRIOVR_FOUND AND NOT DISABLE_PRIOVR) +# and with SDL for joysticks +if (SDL_FOUND AND NOT DISABLE_SDL) + add_definitions(-DHAVE_SDL) + include_directories(SYSTEM "${SDL_INCLUDE_DIR}") + target_link_libraries(${TARGET_NAME} "${SDL_LIBRARY}") +endif (SDL_FOUND AND NOT DISABLE_SDL) + # and with qxmpp for chat if (QXMPP_FOUND AND NOT DISABLE_QXMPP) add_definitions(-DHAVE_QXMPP -DQXMPP_STATIC) diff --git a/interface/src/Application.h b/interface/src/Application.h index 33ec9ca856..b9b73ac86a 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -58,6 +58,7 @@ #include "avatar/MyAvatar.h" #include "devices/Faceplus.h" #include "devices/Faceshift.h" +#include "devices/JoystickManager.h" #include "devices/PrioVR.h" #include "devices/SixenseManager.h" #include "devices/Visage.h" @@ -196,6 +197,7 @@ public: FaceTracker* getActiveFaceTracker(); SixenseManager* getSixenseManager() { return &_sixenseManager; } PrioVR* getPrioVR() { return &_prioVR; } + JoystickManager* getJoystickManager() { return &_joystickManager; } BandwidthMeter* getBandwidthMeter() { return &_bandwidthMeter; } QUndoStack* getUndoStack() { return &_undoStack; } @@ -449,6 +451,7 @@ private: SixenseManager _sixenseManager; PrioVR _prioVR; + JoystickManager _joystickManager; Camera _myCamera; // My view onto the world Camera _viewFrustumOffsetCamera; // The camera we use to sometimes show the view frustum from an offset mode diff --git a/interface/src/devices/JoystickManager.cpp b/interface/src/devices/JoystickManager.cpp new file mode 100644 index 0000000000..77e53f3dcc --- /dev/null +++ b/interface/src/devices/JoystickManager.cpp @@ -0,0 +1,63 @@ +// +// JoystickManager.cpp +// interface/src/devices +// +// Created by Andrzej Kapolka on 5/15/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 +// + +#include + +#include + +#include + +#include "JoystickManager.h" + +using namespace std; + +JoystickManager::JoystickManager() { +#ifdef HAVE_SDL + SDL_Init(SDL_INIT_JOYSTICK); + int joystickCount = SDL_NumJoysticks(); + for (int i = 0; i < joystickCount; i++) { + SDL_Joystick* joystick = SDL_JoystickOpen(i); + if (joystick) { + JoystickState state = { SDL_JoystickName(i), QVector(SDL_JoystickNumAxes(joystick)), + QVector(SDL_JoystickNumButtons(joystick)) }; + qDebug() << state.name << state.axes.size() << state.buttons.size(); + _joystickStates.append(state); + _joysticks.append(joystick); + } + } +#endif +} + +JoystickManager::~JoystickManager() { +#ifdef HAVE_SDL + foreach (SDL_Joystick* joystick, _joysticks) { + SDL_JoystickClose(joystick); + } + SDL_Quit(); +#endif +} + +void JoystickManager::update() { +#ifdef HAVE_SDL + SDL_JoystickUpdate(); + + for (int i = 0; i < _joystickStates.size(); i++) { + SDL_Joystick* joystick = _joysticks.at(i); + JoystickState& state = _joystickStates[i]; + for (int j = 0; j < state.axes.size(); j++) { + state.axes[j] = glm::round(SDL_JoystickGetAxis(joystick, j) + 0.5f) / numeric_limits::max(); + } + for (int j = 0; j < state.buttons.size(); j++) { + state.buttons[j] = SDL_JoystickGetButton(joystick, j); + } + } +#endif +} diff --git a/interface/src/devices/JoystickManager.h b/interface/src/devices/JoystickManager.h new file mode 100644 index 0000000000..61cc2b2571 --- /dev/null +++ b/interface/src/devices/JoystickManager.h @@ -0,0 +1,52 @@ +// +// JoystickManager.h +// interface/src/devices +// +// Created by Andrzej Kapolka on 5/15/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 +// + +#ifndef hifi_JoystickManager_h +#define hifi_JoystickManager_h + +#include +#include + +#ifdef HAVE_SDL +#include +#endif + +class JoystickState; + +/// Handles joystick input through SDL. +class JoystickManager : public QObject { + Q_OBJECT + +public: + + JoystickManager(); + virtual ~JoystickManager(); + + const QVector& getJoystickStates() const { return _joystickStates; } + + void update(); + +private: + QVector _joystickStates; + +#ifdef HAVE_SDL + QVector _joysticks; +#endif +}; + +class JoystickState { +public: + QString name; + QVector axes; + QVector buttons; +}; + +#endif // hifi_JoystickManager_h From 946e2b574308013375c83aacda0a2a0cde795d62 Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Thu, 15 May 2014 17:15:25 -0700 Subject: [PATCH 12/60] Avoid unused variable warnings in Xcode. --- interface/src/devices/PrioVR.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interface/src/devices/PrioVR.cpp b/interface/src/devices/PrioVR.cpp index 28564f6f2e..e6e948422e 100644 --- a/interface/src/devices/PrioVR.cpp +++ b/interface/src/devices/PrioVR.cpp @@ -17,6 +17,7 @@ #include "PrioVR.h" #include "ui/TextRenderer.h" +#ifdef HAVE_PRIOVR const unsigned int SERIAL_LIST[] = { 0x00000001, 0x00000000, 0x00000008, 0x00000009, 0x0000000A, 0x0000000C, 0x0000000D, 0x0000000E, 0x00000004, 0x00000005, 0x00000010, 0x00000011 }; const unsigned char AXIS_LIST[] = { 9, 43, 37, 37, 37, 13, 13, 13, 52, 52, 28, 28 }; @@ -25,7 +26,6 @@ const int LIST_LENGTH = sizeof(SERIAL_LIST) / sizeof(SERIAL_LIST[0]); const char* JOINT_NAMES[] = { "Neck", "Spine", "LeftArm", "LeftForeArm", "LeftHand", "RightArm", "RightForeArm", "RightHand", "LeftUpLeg", "LeftLeg", "RightUpLeg", "RightLeg" }; -#ifdef HAVE_PRIOVR static int indexOfHumanIKJoint(const char* jointName) { for (int i = 0;; i++) { QByteArray humanIKJoint = HUMANIK_JOINTS[i]; From a544489f3020e21529872aeb1c20291de5a8b71a Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Thu, 15 May 2014 17:44:35 -0700 Subject: [PATCH 13/60] First cut at adding external joysticks to the mix. --- interface/src/devices/JoystickManager.cpp | 1 - interface/src/devices/JoystickManager.h | 1 + .../ControllerScriptingInterface.cpp | 25 +++++++++++++++++-- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/interface/src/devices/JoystickManager.cpp b/interface/src/devices/JoystickManager.cpp index 77e53f3dcc..da3c1834af 100644 --- a/interface/src/devices/JoystickManager.cpp +++ b/interface/src/devices/JoystickManager.cpp @@ -28,7 +28,6 @@ JoystickManager::JoystickManager() { if (joystick) { JoystickState state = { SDL_JoystickName(i), QVector(SDL_JoystickNumAxes(joystick)), QVector(SDL_JoystickNumButtons(joystick)) }; - qDebug() << state.name << state.axes.size() << state.buttons.size(); _joystickStates.append(state); _joysticks.append(joystick); } diff --git a/interface/src/devices/JoystickManager.h b/interface/src/devices/JoystickManager.h index 61cc2b2571..53a255e129 100644 --- a/interface/src/devices/JoystickManager.h +++ b/interface/src/devices/JoystickManager.h @@ -17,6 +17,7 @@ #ifdef HAVE_SDL #include +#undef main #endif class JoystickState; diff --git a/interface/src/scripting/ControllerScriptingInterface.cpp b/interface/src/scripting/ControllerScriptingInterface.cpp index 58a08066d6..929be1df5e 100644 --- a/interface/src/scripting/ControllerScriptingInterface.cpp +++ b/interface/src/scripting/ControllerScriptingInterface.cpp @@ -88,10 +88,24 @@ glm::vec2 ControllerScriptingInterface::getPrimaryJoystickPosition() const { } int ControllerScriptingInterface::getNumberOfButtons() const { - return getNumberOfActivePalms() * NUMBER_OF_BUTTONS_PER_PALM; + int buttonCount = 0; + foreach (const JoystickState& state, Application::getInstance()->getJoystickManager()->getJoystickStates()) { + buttonCount += state.buttons.size(); + } + return buttonCount + getNumberOfActivePalms() * NUMBER_OF_BUTTONS_PER_PALM; } bool ControllerScriptingInterface::isButtonPressed(int buttonIndex) const { + int managedButtonIndex = buttonIndex - getNumberOfActivePalms() * NUMBER_OF_BUTTONS_PER_PALM; + if (managedButtonIndex >= 0) { + foreach (const JoystickState& state, Application::getInstance()->getJoystickManager()->getJoystickStates()) { + if (managedButtonIndex < state.buttons.size()) { + return state.buttons.at(managedButtonIndex); + } + managedButtonIndex -= state.buttons.size(); + } + return false; + } int palmIndex = buttonIndex / NUMBER_OF_BUTTONS_PER_PALM; int buttonOnPalm = buttonIndex % NUMBER_OF_BUTTONS_PER_PALM; const PalmData* palmData = getActivePalm(palmIndex); @@ -129,11 +143,18 @@ float ControllerScriptingInterface::getTriggerValue(int triggerIndex) const { } int ControllerScriptingInterface::getNumberOfJoysticks() const { - return getNumberOfActivePalms() * NUMBER_OF_JOYSTICKS_PER_PALM; + return getNumberOfActivePalms() * NUMBER_OF_JOYSTICKS_PER_PALM + + Application::getInstance()->getJoystickManager()->getJoystickStates().size(); } glm::vec2 ControllerScriptingInterface::getJoystickPosition(int joystickIndex) const { // we know there's one joystick per palm, so the joystickIndex is the palm Index + int managedJoystickIndex = joystickIndex - getNumberOfActivePalms(); + if (managedJoystickIndex >= 0) { + const JoystickState& state = Application::getInstance()->getJoystickManager()->getJoystickStates().at( + managedJoystickIndex); + return glm::vec2(state.axes.size() > 0 ? state.axes.at(0) : 0.0f, state.axes.size() > 1 ? state.axes.at(1) : 0.0f); + } int palmIndex = joystickIndex; const PalmData* palmData = getActivePalm(palmIndex); if (palmData) { From e41500652606212d0bf865706ff754eb60ff2cbc Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Thu, 15 May 2014 18:22:57 -0700 Subject: [PATCH 14/60] Fixed index of out bounds error, issue with head not being tracked in PrioVR. --- interface/src/scripting/ControllerScriptingInterface.cpp | 3 ++- libraries/fbx/src/FBXReader.cpp | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/interface/src/scripting/ControllerScriptingInterface.cpp b/interface/src/scripting/ControllerScriptingInterface.cpp index 929be1df5e..df97af1a16 100644 --- a/interface/src/scripting/ControllerScriptingInterface.cpp +++ b/interface/src/scripting/ControllerScriptingInterface.cpp @@ -150,7 +150,8 @@ int ControllerScriptingInterface::getNumberOfJoysticks() const { glm::vec2 ControllerScriptingInterface::getJoystickPosition(int joystickIndex) const { // we know there's one joystick per palm, so the joystickIndex is the palm Index int managedJoystickIndex = joystickIndex - getNumberOfActivePalms(); - if (managedJoystickIndex >= 0) { + if (managedJoystickIndex >= 0 && managedJoystickIndex < + Application::getInstance()->getJoystickManager()->getJoystickStates().size()) { const JoystickState& state = Application::getInstance()->getJoystickManager()->getJoystickStates().at( managedJoystickIndex); return glm::vec2(state.axes.size() > 0 ? state.axes.at(0) : 0.0f, state.axes.size() > 1 ? state.axes.at(1) : 0.0f); diff --git a/libraries/fbx/src/FBXReader.cpp b/libraries/fbx/src/FBXReader.cpp index 264f58f0d4..44ef3f3aab 100644 --- a/libraries/fbx/src/FBXReader.cpp +++ b/libraries/fbx/src/FBXReader.cpp @@ -585,6 +585,7 @@ const char* HUMANIK_JOINTS[] = { "LeftArm", "LeftForeArm", "LeftHand", + "Neck", "Spine", "Hips", "RightUpLeg", From c29708f22c3a8f2484a486b6d6abcc6884b03ac9 Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Thu, 15 May 2014 19:18:19 -0700 Subject: [PATCH 15/60] Basic joystick integration. --- interface/src/Application.cpp | 1 + interface/src/devices/JoystickManager.cpp | 4 +- interface/src/devices/PrioVR.cpp | 3 ++ interface/src/devices/PrioVR.h | 3 ++ .../ControllerScriptingInterface.cpp | 40 ++++++++++++++----- 5 files changed, 39 insertions(+), 12 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 91e95bb4e3..85fb77908a 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -1990,6 +1990,7 @@ void Application::update(float deltaTime) { _myAvatar->updateLookAtTargetAvatar(); updateMyAvatarLookAtPosition(); _sixenseManager.update(deltaTime); + _joystickManager.update(); _prioVR.update(); updateMyAvatar(deltaTime); // Sample hardware, update view frustum if needed, and send avatar data to mixer/nodes updateThreads(deltaTime); // If running non-threaded, then give the threads some time to process... diff --git a/interface/src/devices/JoystickManager.cpp b/interface/src/devices/JoystickManager.cpp index da3c1834af..005505441c 100644 --- a/interface/src/devices/JoystickManager.cpp +++ b/interface/src/devices/JoystickManager.cpp @@ -52,7 +52,9 @@ void JoystickManager::update() { SDL_Joystick* joystick = _joysticks.at(i); JoystickState& state = _joystickStates[i]; for (int j = 0; j < state.axes.size(); j++) { - state.axes[j] = glm::round(SDL_JoystickGetAxis(joystick, j) + 0.5f) / numeric_limits::max(); + float value = glm::round(SDL_JoystickGetAxis(joystick, j) + 0.5f) / numeric_limits::max(); + const float DEAD_ZONE = 0.1f; + state.axes[j] = glm::abs(value) < DEAD_ZONE ? 0.0f : value; } for (int j = 0; j < state.buttons.size(); j++) { state.buttons[j] = SDL_JoystickGetButton(joystick, j); diff --git a/interface/src/devices/PrioVR.cpp b/interface/src/devices/PrioVR.cpp index e6e948422e..c97d35b9d2 100644 --- a/interface/src/devices/PrioVR.cpp +++ b/interface/src/devices/PrioVR.cpp @@ -9,6 +9,7 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // +#include #include #include @@ -52,6 +53,8 @@ PrioVR::PrioVR() { for (int i = 0; i < LIST_LENGTH; i++) { _humanIKJointIndices.append(jointsDiscovered[i] ? indexOfHumanIKJoint(JOINT_NAMES[i]) : -1); } + const int INITIAL_RESET_DELAY = 5000; + QTimer::singleShot(INITIAL_RESET_DELAY, this, SLOT(reset())); #endif } diff --git a/interface/src/devices/PrioVR.h b/interface/src/devices/PrioVR.h index 8f01574356..59352d2ac4 100644 --- a/interface/src/devices/PrioVR.h +++ b/interface/src/devices/PrioVR.h @@ -44,6 +44,9 @@ public: const QVector& getJointRotations() const { return _jointRotations; } void update(); + +public slots: + void reset(); private slots: diff --git a/interface/src/scripting/ControllerScriptingInterface.cpp b/interface/src/scripting/ControllerScriptingInterface.cpp index df97af1a16..b5619191fa 100644 --- a/interface/src/scripting/ControllerScriptingInterface.cpp +++ b/interface/src/scripting/ControllerScriptingInterface.cpp @@ -90,19 +90,20 @@ glm::vec2 ControllerScriptingInterface::getPrimaryJoystickPosition() const { int ControllerScriptingInterface::getNumberOfButtons() const { int buttonCount = 0; foreach (const JoystickState& state, Application::getInstance()->getJoystickManager()->getJoystickStates()) { - buttonCount += state.buttons.size(); + buttonCount += state.buttons.size() / 2; } return buttonCount + getNumberOfActivePalms() * NUMBER_OF_BUTTONS_PER_PALM; } bool ControllerScriptingInterface::isButtonPressed(int buttonIndex) const { + // as a temporary hack, we consider every other button a trigger int managedButtonIndex = buttonIndex - getNumberOfActivePalms() * NUMBER_OF_BUTTONS_PER_PALM; if (managedButtonIndex >= 0) { foreach (const JoystickState& state, Application::getInstance()->getJoystickManager()->getJoystickStates()) { - if (managedButtonIndex < state.buttons.size()) { - return state.buttons.at(managedButtonIndex); + if (managedButtonIndex * 2 + 1 < state.buttons.size()) { + return state.buttons.at(managedButtonIndex * 2 + 1); } - managedButtonIndex -= state.buttons.size(); + managedButtonIndex -= state.buttons.size() / 2; } return false; } @@ -129,10 +130,24 @@ bool ControllerScriptingInterface::isButtonPressed(int buttonIndex) const { } int ControllerScriptingInterface::getNumberOfTriggers() const { - return getNumberOfActivePalms() * NUMBER_OF_TRIGGERS_PER_PALM; + int buttonCount = 0; + foreach (const JoystickState& state, Application::getInstance()->getJoystickManager()->getJoystickStates()) { + buttonCount += state.buttons.size() / 2; + } + return buttonCount + getNumberOfActivePalms() * NUMBER_OF_TRIGGERS_PER_PALM; } float ControllerScriptingInterface::getTriggerValue(int triggerIndex) const { + int managedButtonIndex = triggerIndex - getNumberOfActivePalms() * NUMBER_OF_TRIGGERS_PER_PALM; + if (managedButtonIndex >= 0) { + foreach (const JoystickState& state, Application::getInstance()->getJoystickManager()->getJoystickStates()) { + if (managedButtonIndex * 2 < state.buttons.size()) { + return state.buttons.at(managedButtonIndex * 2) ? 1.0f : 0.0f; + } + managedButtonIndex -= state.buttons.size() / 2; + } + return false; + } // we know there's one trigger per palm, so the triggerIndex is the palm Index int palmIndex = triggerIndex; const PalmData* palmData = getActivePalm(palmIndex); @@ -149,12 +164,15 @@ int ControllerScriptingInterface::getNumberOfJoysticks() const { glm::vec2 ControllerScriptingInterface::getJoystickPosition(int joystickIndex) const { // we know there's one joystick per palm, so the joystickIndex is the palm Index - int managedJoystickIndex = joystickIndex - getNumberOfActivePalms(); - if (managedJoystickIndex >= 0 && managedJoystickIndex < - Application::getInstance()->getJoystickManager()->getJoystickStates().size()) { - const JoystickState& state = Application::getInstance()->getJoystickManager()->getJoystickStates().at( - managedJoystickIndex); - return glm::vec2(state.axes.size() > 0 ? state.axes.at(0) : 0.0f, state.axes.size() > 1 ? state.axes.at(1) : 0.0f); + int managedAxisIndex = (joystickIndex - getNumberOfActivePalms()) * 2; + if (managedAxisIndex >= 0) { + foreach (const JoystickState& state, Application::getInstance()->getJoystickManager()->getJoystickStates()) { + if (managedAxisIndex + 1 < state.axes.size()) { + return glm::vec2(state.axes.at(managedAxisIndex), -state.axes.at(managedAxisIndex + 1)); + } + managedAxisIndex -= state.axes.size(); + } + return glm::vec2(); } int palmIndex = joystickIndex; const PalmData* palmData = getActivePalm(palmIndex); From e8937852bc2661aef72c9a61d56e7f2bb77c99df Mon Sep 17 00:00:00 2001 From: Kai Ludwig Date: Fri, 16 May 2014 15:12:49 +0200 Subject: [PATCH 16/60] MenuOption::Visage now default to false. --- interface/src/Menu.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interface/src/Menu.cpp b/interface/src/Menu.cpp index 2daf5b0240..3c0ebe4cd2 100644 --- a/interface/src/Menu.cpp +++ b/interface/src/Menu.cpp @@ -331,7 +331,7 @@ Menu::Menu() : #endif #ifdef HAVE_VISAGE - addCheckableActionToQMenuAndActionHash(avatarOptionsMenu, MenuOption::Visage, 0, true, + addCheckableActionToQMenuAndActionHash(avatarOptionsMenu, MenuOption::Visage, 0, false, appInstance->getVisage(), SLOT(updateEnabled())); #endif From 51965fd283e43ea299d5d592175aec96eb7bb996 Mon Sep 17 00:00:00 2001 From: Kai Ludwig Date: Fri, 16 May 2014 15:44:07 +0200 Subject: [PATCH 17/60] changed float specular = max(0.0, dot(normalize(gl_LightSource[0].position + vec4(0.0, 0.0, 1.0, 0.0)), normalizedNormal)); to float specular = max(0.0, dot(gl_LightSource[0].position, normalizedNormal)); Calculation for specular value has to be done like in all other shaders with the unmodified unnormalized lightsource position. Otherwise the specular effect will have weird behaviour. --- interface/resources/shaders/model.frag | 2 +- interface/resources/shaders/model_normal_map.frag | 2 +- interface/resources/shaders/model_normal_specular_map.frag | 2 +- interface/resources/shaders/model_specular_map.frag | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/interface/resources/shaders/model.frag b/interface/resources/shaders/model.frag index 29579d07ac..3964bd5b97 100644 --- a/interface/resources/shaders/model.frag +++ b/interface/resources/shaders/model.frag @@ -24,7 +24,7 @@ void main(void) { gl_FrontLightProduct[0].diffuse * max(0.0, dot(normalizedNormal, gl_LightSource[0].position))); // compute the specular component (sans exponent) - float specular = max(0.0, dot(normalize(gl_LightSource[0].position + vec4(0.0, 0.0, 1.0, 0.0)), normalizedNormal)); + float specular = max(0.0, dot(gl_LightSource[0].position, normalizedNormal)); // modulate texture by base color and add specular contribution gl_FragColor = base * texture2D(diffuseMap, gl_TexCoord[0].st) + diff --git a/interface/resources/shaders/model_normal_map.frag b/interface/resources/shaders/model_normal_map.frag index 2a4af2073a..a4f7a887c5 100644 --- a/interface/resources/shaders/model_normal_map.frag +++ b/interface/resources/shaders/model_normal_map.frag @@ -36,7 +36,7 @@ void main(void) { gl_FrontLightProduct[0].diffuse * max(0.0, dot(viewNormal, gl_LightSource[0].position))); // compute the specular component (sans exponent) - float specular = max(0.0, dot(normalize(gl_LightSource[0].position + vec4(0.0, 0.0, 1.0, 0.0)), viewNormal)); + float specular = max(0.0, dot(gl_LightSource[0].position, viewNormal)); // modulate texture by base color and add specular contribution gl_FragColor = base * texture2D(diffuseMap, gl_TexCoord[0].st) + diff --git a/interface/resources/shaders/model_normal_specular_map.frag b/interface/resources/shaders/model_normal_specular_map.frag index 79761446b1..f5b9d2b06b 100644 --- a/interface/resources/shaders/model_normal_specular_map.frag +++ b/interface/resources/shaders/model_normal_specular_map.frag @@ -39,7 +39,7 @@ void main(void) { gl_FrontLightProduct[0].diffuse * max(0.0, dot(viewNormal, gl_LightSource[0].position))); // compute the specular component (sans exponent) - float specular = max(0.0, dot(normalize(gl_LightSource[0].position + vec4(0.0, 0.0, 1.0, 0.0)), viewNormal)); + float specular = max(0.0, dot(gl_LightSource[0].position, viewNormal)); // modulate texture by base color and add specular contribution gl_FragColor = base * texture2D(diffuseMap, gl_TexCoord[0].st) + vec4(pow(specular, gl_FrontMaterial.shininess) * diff --git a/interface/resources/shaders/model_specular_map.frag b/interface/resources/shaders/model_specular_map.frag index 972a8e2de6..4e2f3d0c98 100644 --- a/interface/resources/shaders/model_specular_map.frag +++ b/interface/resources/shaders/model_specular_map.frag @@ -27,7 +27,7 @@ void main(void) { gl_FrontLightProduct[0].diffuse * max(0.0, dot(normalizedNormal, gl_LightSource[0].position))); // compute the specular component (sans exponent) - float specular = max(0.0, dot(normalize(gl_LightSource[0].position + vec4(0.0, 0.0, 1.0, 0.0)), normalizedNormal)); + float specular = max(0.0, dot(gl_LightSource[0].position, normalizedNormal)); // modulate texture by base color and add specular contribution gl_FragColor = base * texture2D(diffuseMap, gl_TexCoord[0].st) + vec4(pow(specular, gl_FrontMaterial.shininess) * From 337bc8b9472accafb34cfdf4e42779f5f23478a5 Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Fri, 16 May 2014 08:28:36 -0700 Subject: [PATCH 18/60] reuse boolean results rather than recomputing them --- interface/src/avatar/Avatar.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/interface/src/avatar/Avatar.cpp b/interface/src/avatar/Avatar.cpp index 3ebc9f016f..0a3411f858 100644 --- a/interface/src/avatar/Avatar.cpp +++ b/interface/src/avatar/Avatar.cpp @@ -222,16 +222,14 @@ void Avatar::render(const glm::vec3& cameraPosition, RenderMode renderMode) { updateShapePositions(); } - if (Menu::getInstance()->isOptionChecked(MenuOption::RenderSkeletonCollisionShapes)) { + if (renderSkeleton) { _skeletonModel.renderJointCollisionShapes(0.7f); } - if (Menu::getInstance()->isOptionChecked(MenuOption::RenderHeadCollisionShapes) - && shouldRenderHead(cameraPosition, renderMode)) { + if (renderHead && shouldRenderHead(cameraPosition, renderMode)) { getHead()->getFaceModel().renderJointCollisionShapes(0.7f); } - if (Menu::getInstance()->isOptionChecked(MenuOption::RenderBoundingCollisionShapes) - && shouldRenderHead(cameraPosition, renderMode)) { + if (renderBounding && shouldRenderHead(cameraPosition, renderMode)) { getHead()->getFaceModel().renderBoundingCollisionShapes(0.7f); _skeletonModel.renderBoundingCollisionShapes(0.7f); } From 85b94ff71cf6681a4704f85b10bdd723dfb9ec89 Mon Sep 17 00:00:00 2001 From: Philip Rosedale Date: Fri, 16 May 2014 09:20:15 -0700 Subject: [PATCH 19/60] added dead zone to pitch in hydra move, animated models show up where you are --- examples/animatedModelExample.js | 10 +++++----- examples/hydraMove.js | 24 ++++++++++++++++-------- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/examples/animatedModelExample.js b/examples/animatedModelExample.js index 5199eb419f..3fb4ae8bd4 100644 --- a/examples/animatedModelExample.js +++ b/examples/animatedModelExample.js @@ -21,9 +21,9 @@ var roll = 0.0; var rotation = Quat.fromPitchYawRollDegrees(pitch, yaw, roll) var originalProperties = { - position: { x: 10, - y: 0, - z: 0 }, + position: { x: MyAvatar.position.x, + y: MyAvatar.position.y, + z: MyAvatar.position.z }, radius : 1, @@ -58,9 +58,9 @@ function moveModel(deltaTime) { if (animationFPS == 30) { animationFPS = 10; } else if (animationFPS == 10) { - animationFPS = 60; + animationFPS = 10; } else if (animationFPS == 60) { - animationFPS = 30; + animationFPS = 10; } print("animationFPS=" + animationFPS); isPlaying = true; diff --git a/examples/hydraMove.js b/examples/hydraMove.js index 638e5fe226..3a11fa0b5e 100644 --- a/examples/hydraMove.js +++ b/examples/hydraMove.js @@ -145,20 +145,28 @@ function handleGrabBehavior(deltaTime) { // add some rotation... var deltaRotation = getGrabRotation(); - var GRAB_CONTROLLER_PITCH_SCALING = 2.5; - var GRAB_CONTROLLER_YAW_SCALING = 2.5; - var GRAB_CONTROLLER_ROLL_SCALING = 2.5; + var PITCH_SCALING = 2.0; + var PITCH_DEAD_ZONE = 2.0; + var YAW_SCALING = 2.0; + var ROLL_SCALING = 2.0; + var euler = Quat.safeEulerAngles(deltaRotation); + print("dx: " + euler.x); + // Adjust body yaw by roll from controller - var orientation = Quat.multiply(Quat.angleAxis(((euler.y * GRAB_CONTROLLER_YAW_SCALING) + - (euler.z * GRAB_CONTROLLER_ROLL_SCALING)) * deltaTime, {x:0, y: 1, z:0}), MyAvatar.orientation); + var orientation = Quat.multiply(Quat.angleAxis(((euler.y * YAW_SCALING) + + (euler.z * ROLL_SCALING)) * deltaTime, {x:0, y: 1, z:0}), MyAvatar.orientation); MyAvatar.orientation = orientation; // Adjust head pitch from controller - MyAvatar.headPitch = MyAvatar.headPitch + (euler.x * GRAB_CONTROLLER_PITCH_SCALING * deltaTime); - - // Add some camera roll proportional to the rate of turn (so it feels like an airplane or roller coaster) + var pitch = 0.0; + if (Math.abs(euler.x) > PITCH_DEAD_ZONE) { + pitch = (euler.x < 0.0) ? (euler.x + PITCH_DEAD_ZONE) : (euler.x - PITCH_DEAD_ZONE); + } + MyAvatar.headPitch = MyAvatar.headPitch + (pitch * PITCH_SCALING * deltaTime); + + // TODO: Add some camera roll proportional to the rate of turn (so it feels like an airplane or roller coaster) } From f646eda7aaf885f6681224d52ce80dde66911a4d Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Fri, 16 May 2014 09:30:34 -0700 Subject: [PATCH 20/60] Move server borders to a submenu --- interface/src/Menu.cpp | 7 ++++--- interface/src/Menu.h | 6 +++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/interface/src/Menu.cpp b/interface/src/Menu.cpp index a3a7faad2e..3084215d92 100644 --- a/interface/src/Menu.cpp +++ b/interface/src/Menu.cpp @@ -243,14 +243,15 @@ Menu::Menu() : SLOT(setEnable3DTVMode(bool))); + QMenu* nodeBordersMenu = viewMenu->addMenu("Server Borders"); NodeBounds& nodeBounds = appInstance->getNodeBoundsDisplay(); - addCheckableActionToQMenuAndActionHash(viewMenu, MenuOption::ShowBordersVoxelNodes, + addCheckableActionToQMenuAndActionHash(nodeBordersMenu, MenuOption::ShowBordersVoxelNodes, Qt::CTRL | Qt::SHIFT | Qt::Key_1, false, &nodeBounds, SLOT(setShowVoxelNodes(bool))); - addCheckableActionToQMenuAndActionHash(viewMenu, MenuOption::ShowBordersModelNodes, + addCheckableActionToQMenuAndActionHash(nodeBordersMenu, MenuOption::ShowBordersModelNodes, Qt::CTRL | Qt::SHIFT | Qt::Key_2, false, &nodeBounds, SLOT(setShowModelNodes(bool))); - addCheckableActionToQMenuAndActionHash(viewMenu, MenuOption::ShowBordersParticleNodes, + addCheckableActionToQMenuAndActionHash(nodeBordersMenu, MenuOption::ShowBordersParticleNodes, Qt::CTRL | Qt::SHIFT | Qt::Key_3, false, &nodeBounds, SLOT(setShowParticleNodes(bool))); diff --git a/interface/src/Menu.h b/interface/src/Menu.h index b1be5f2cdb..6a1e8bbc05 100644 --- a/interface/src/Menu.h +++ b/interface/src/Menu.h @@ -366,9 +366,9 @@ namespace MenuOption { const QString SettingsExport = "Export Settings"; const QString SettingsImport = "Import Settings"; const QString Shadows = "Shadows"; - const QString ShowBordersVoxelNodes = "Show Borders - Voxel Nodes"; - const QString ShowBordersModelNodes = "Show Borders - Model Nodes"; - const QString ShowBordersParticleNodes = "Show Borders - Particle Nodes"; + const QString ShowBordersVoxelNodes = "Show Voxel Nodes"; + const QString ShowBordersModelNodes = "Show Model Nodes"; + const QString ShowBordersParticleNodes = "Show Particle Nodes"; const QString ShowIKConstraints = "Show IK Constraints"; const QString Stars = "Stars"; const QString Stats = "Stats"; From 8252b01e309c466f53addf6d9077c4083144dbd9 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Fri, 16 May 2014 09:31:36 -0700 Subject: [PATCH 21/60] Cleanup NodeBounds --- interface/src/ui/NodeBounds.cpp | 139 +++++++++++++++++++++----------- interface/src/ui/NodeBounds.h | 3 + 2 files changed, 94 insertions(+), 48 deletions(-) diff --git a/interface/src/ui/NodeBounds.cpp b/interface/src/ui/NodeBounds.cpp index ffdf52514e..96639c44e5 100644 --- a/interface/src/ui/NodeBounds.cpp +++ b/interface/src/ui/NodeBounds.cpp @@ -5,11 +5,13 @@ // Created by Ryan Huffman on 05/14/14. // Copyright 2014 High Fidelity, Inc. // +// This class draws a border around the different Voxel, Model, and Particle nodes on the current domain, +// and a semi-transparent cube around the currently mouse-overed node. +// // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -#include #include #include "Application.h" @@ -26,32 +28,37 @@ NodeBounds::NodeBounds(QObject* parent) : } void NodeBounds::draw() { + if (!(_showVoxelNodes || _showModelNodes || _showParticleNodes)) { + return; + } + NodeToJurisdictionMap& voxelServerJurisdictions = Application::getInstance()->getVoxelServerJurisdictions(); NodeToJurisdictionMap& modelServerJurisdictions = Application::getInstance()->getModelServerJurisdictions(); NodeToJurisdictionMap& particleServerJurisdictions = Application::getInstance()->getParticleServerJurisdictions(); NodeToJurisdictionMap* serverJurisdictions; + // Compute ray to find selected nodes later on. We can't use the pre-computed ray in Application because it centers + // itself after the cursor disappears. Application* application = Application::getInstance(); - const glm::vec3& mouseRayOrigin = application->getMouseRayOrigin(); - const glm::vec3& mouseRayDirection = application->getMouseRayDirection(); + QGLWidget* glWidget = application->getGLWidget(); + float mouseX = application->getMouseX() / (float)glWidget->width(); + float mouseY = application->getMouseY() / (float)glWidget->height(); + glm::vec3 mouseRayOrigin; + glm::vec3 mouseRayDirection; + application->getViewFrustum()->computePickRay(mouseX, mouseY, mouseRayOrigin, mouseRayDirection); - float closest = FLT_MAX; - glm::vec3 closestCenter; - float closestScale = 0; - bool closestIsInside = true; - Node* closestNode = NULL; - bool isSelecting = false; + // Variables to keep track of the selected node and properties to draw the cube later if needed + Node* selectedNode = NULL; + float selectedDistance = FLT_MAX; + bool selectedIsInside = true; + glm::vec3 selectedCenter; + float selectedScale = 0; - int num = 0; NodeList* nodeList = NodeList::getInstance(); foreach (const SharedNodePointer& node, nodeList->getNodeHash()) { NodeType_t nodeType = node->getType(); - float r = nodeType == NodeType::VoxelServer ? 1.0 : 0.0; - float g = nodeType == NodeType::ParticleServer ? 1.0 : 0.0; - float b = nodeType == NodeType::ModelServer ? 1.0 : 0.0; - if (nodeType == NodeType::VoxelServer && _showVoxelNodes) { serverJurisdictions = &voxelServerJurisdictions; } else if (nodeType == NodeType::ModelServer && _showModelNodes) { @@ -61,65 +68,85 @@ void NodeBounds::draw() { } else { continue; } - + QUuid nodeUUID = node->getUUID(); if (serverJurisdictions->find(nodeUUID) != serverJurisdictions->end()) { const JurisdictionMap& map = serverJurisdictions->value(nodeUUID); - + unsigned char* rootCode = map.getRootOctalCode(); - + if (rootCode) { VoxelPositionSize rootDetails; voxelDetailsForCode(rootCode, rootDetails); glm::vec3 location(rootDetails.x, rootDetails.y, rootDetails.z); location *= (float)TREE_SCALE; - float len = rootDetails.s * TREE_SCALE; + AABox serverBounds(location, rootDetails.s * TREE_SCALE); - glm::vec3 center = serverBounds.getVertex(BOTTOM_RIGHT_NEAR) + (serverBounds.getVertex(TOP_LEFT_FAR) - serverBounds.getVertex(BOTTOM_RIGHT_NEAR)) / 2.0f; + glm::vec3 center = serverBounds.getVertex(BOTTOM_RIGHT_NEAR) + + ((serverBounds.getVertex(TOP_LEFT_FAR) - serverBounds.getVertex(BOTTOM_RIGHT_NEAR)) / 2.0f); + + const float VOXEL_NODE_SCALE = 1.00f; + const float MODEL_NODE_SCALE = 0.99f; + const float PARTICLE_NODE_SCALE = 0.98f; float scaleFactor = rootDetails.s * TREE_SCALE; - scaleFactor *= rootDetails.s == 1 ? 1.05 : 0.95; - scaleFactor *= nodeType == NodeType::VoxelServer ? 1.0 : (nodeType == NodeType::ParticleServer ? 0.980 : 0.960); - drawNodeBorder(center, scaleFactor, r, g, b); + // Scale by 0.98 - 1.02 depending on the scale of the node. This allows smaller nodes to scale in + // a bit and not overlap larger nodes. + scaleFactor *= 0.92 + (rootDetails.s * 0.08); + + // Scale different node types slightly differently because it's common for them to overlap. + if (nodeType == NodeType::VoxelServer) { + scaleFactor *= VOXEL_NODE_SCALE; + } else if (nodeType == NodeType::ModelServer) { + scaleFactor *= MODEL_NODE_SCALE; + } else { + scaleFactor *= PARTICLE_NODE_SCALE; + } + + float red, green, blue; + getColorForNodeType(nodeType, red, green, blue); + drawNodeBorder(center, scaleFactor, red, green, blue); float distance; BoxFace face; bool inside = serverBounds.contains(mouseRayOrigin); bool colliding = serverBounds.findRayIntersection(mouseRayOrigin, mouseRayDirection, distance, face); - if (colliding && (!isSelecting || (!inside && (distance < closest || closestIsInside)))) { - closest = distance; - closestCenter = center; - closestScale = scaleFactor; - closestIsInside = inside; - closestNode = node.data(); - isSelecting = true; + // If the camera is inside a node it will be "selected" if you don't have your cursor over another node + // that you aren't inside. + if (colliding && (!selectedNode || (!inside && (distance < selectedDistance || selectedIsInside)))) { + selectedNode = node.data(); + selectedDistance = distance; + selectedIsInside = inside; + selectedCenter = center; + selectedScale = scaleFactor; } } } } - if (isSelecting) { + if (selectedNode) { glPushMatrix(); - glTranslatef(closestCenter.x, closestCenter.y, closestCenter.z); - glScalef(closestScale, closestScale, closestScale); + glTranslatef(selectedCenter.x, selectedCenter.y, selectedCenter.z); + glScalef(selectedScale, selectedScale, selectedScale); - NodeType_t selectedNodeType = closestNode->getType(); - float r = selectedNodeType == NodeType::VoxelServer ? 1.0 : 0.0; - float g = selectedNodeType == NodeType::ParticleServer ? 1.0 : 0.0; - float b = selectedNodeType == NodeType::ModelServer ? 1.0 : 0.0; - glColor4f(r, g, b, 0.2); + NodeType_t selectedNodeType = selectedNode->getType(); + float red, green, blue; + getColorForNodeType(selectedNode->getType(), red, green, blue); + + glColor4f(red, green, blue, 0.2); glutSolidCube(1.0); glPopMatrix(); - HifiSockAddr addr = closestNode->getPublicSocket(); - _overlayText = QString("%1:%2") + HifiSockAddr addr = selectedNode->getPublicSocket(); + _overlayText = QString("%1:%2 %3ms") .arg(addr.getAddress().toString()) - .arg(addr.getPort()); + .arg(addr.getPort()) + .arg(selectedNode->getPingMs()); } else { _overlayText = QString(); } @@ -131,7 +158,7 @@ void NodeBounds::drawNodeBorder(glm::vec3 center, float scale, float red, float glTranslatef(center.x, center.y, center.z); glScalef(scale, scale, scale); - glLineWidth(2.5); + glLineWidth(2.5); glColor3f(red, green, blue); glBegin(GL_LINES); @@ -150,8 +177,6 @@ void NodeBounds::drawNodeBorder(glm::vec3 center, float scale, float red, float glVertex3f(-0.5, 0.5, -0.5); glVertex3f(-0.5, 0.5, 0.5); - - glVertex3f( 0.5, 0.5, 0.5); glVertex3f(-0.5, 0.5, 0.5); @@ -167,7 +192,6 @@ void NodeBounds::drawNodeBorder(glm::vec3 center, float scale, float red, float glVertex3f( 0.5, -0.5, 0.5); glVertex3f( 0.5, -0.5, -0.5); - glVertex3f( 0.5, 0.5, -0.5); glVertex3f( 0.5, -0.5, -0.5); @@ -179,12 +203,31 @@ void NodeBounds::drawNodeBorder(glm::vec3 center, float scale, float red, float glPopMatrix(); } -const float WHITE_TEXT[] = { 0.93f, 0.93f, 0.93f }; +void NodeBounds::getColorForNodeType(NodeType_t nodeType, float& red, float& green, float& blue) { + red = nodeType == NodeType::VoxelServer ? 1.0 : 0.0; + green = nodeType == NodeType::ParticleServer ? 1.0 : 0.0; + blue = nodeType == NodeType::ModelServer ? 1.0 : 0.0; +} + void NodeBounds::drawOverlay() { if (!_overlayText.isNull() && !_overlayText.isEmpty()) { - QGLWidget* glWidget = Application::getInstance()->getGLWidget(); Application* application = Application::getInstance(); - drawText(application->getMouseX(), application->getMouseY(), 0.1f, 0.0f, 0, _overlayText.toLocal8Bit().data(), WHITE_TEXT); - // drawText(application->getMouseX(), application->getMouseY(), 0.1f, 0.0f, 0, "durr", WHITE_TEXT); + + const float TEXT_COLOR[] = { 0.90f, 0.90f, 0.90f }; + const float TEXT_SCALE = 0.1f; + const int TEXT_HEIGHT = 10; + const int PADDING = 10; + const int MOUSE_OFFSET = 10; + const int BACKGROUND_OFFSET_Y = -20; + const int BACKGROUND_BEVEL = 3; + + char* text = _overlayText.toLocal8Bit().data(); + int mouseX = application->getMouseX(), + mouseY = application->getMouseY(), + textWidth = widthText(TEXT_SCALE, 0, text); + glColor4f(0.4, 0.4, 0.4, 0.6); + renderBevelCornersRect(mouseX + MOUSE_OFFSET, mouseY - TEXT_HEIGHT - PADDING, + textWidth + (2 * PADDING), TEXT_HEIGHT + (2 * PADDING), BACKGROUND_BEVEL); + drawText(mouseX + MOUSE_OFFSET + PADDING, mouseY, TEXT_SCALE, 0.0f, 0, text, TEXT_COLOR); } } diff --git a/interface/src/ui/NodeBounds.h b/interface/src/ui/NodeBounds.h index c4cd7002bd..9ef2ab486a 100644 --- a/interface/src/ui/NodeBounds.h +++ b/interface/src/ui/NodeBounds.h @@ -14,6 +14,8 @@ #include +#include + class NodeBounds : public QObject { Q_OBJECT public: @@ -33,6 +35,7 @@ public slots: protected: void drawNodeBorder(glm::vec3 center, float scale, float red, float green, float blue); + void getColorForNodeType(NodeType_t nodeType, float& red, float& green, float& blue); private: bool _showVoxelNodes; From 25f1e180f504c87c3a1ef704d30b24f8eb82fa51 Mon Sep 17 00:00:00 2001 From: Philip Rosedale Date: Fri, 16 May 2014 09:34:54 -0700 Subject: [PATCH 22/60] revert test change --- examples/animatedModelExample.js | 4 ++-- examples/bot.js | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/examples/animatedModelExample.js b/examples/animatedModelExample.js index 3fb4ae8bd4..70e40140eb 100644 --- a/examples/animatedModelExample.js +++ b/examples/animatedModelExample.js @@ -56,11 +56,11 @@ function moveModel(deltaTime) { if (count % adjustFPSEveryWhile == 0) { if (animationFPS == 30) { - animationFPS = 10; + animationFPS = 30; } else if (animationFPS == 10) { animationFPS = 10; } else if (animationFPS == 60) { - animationFPS = 10; + animationFPS = 60; } print("animationFPS=" + animationFPS); isPlaying = true; diff --git a/examples/bot.js b/examples/bot.js index f7a0429c53..e42d234abf 100644 --- a/examples/bot.js +++ b/examples/bot.js @@ -25,7 +25,7 @@ function printVector(string, vector) { } var CHANCE_OF_MOVING = 0.005; -var CHANCE_OF_SOUND = 0.000; +var CHANCE_OF_SOUND = 0.005; var CHANCE_OF_HEAD_TURNING = 0.05; var CHANCE_OF_BIG_MOVE = 0.1; var CHANCE_OF_WAVING = 0.009; @@ -41,11 +41,11 @@ var isWaving = false; var waveFrequency = 0.0; var waveAmplitude = 0.0; -var X_MIN = 20.0; -var X_MAX = 25.0; -var Z_MIN = 20.0; -var Z_MAX = 25.0; -var Y_PELVIS = 2.5; +var X_MIN = 5.0; +var X_MAX = 15.0; +var Z_MIN = 5.0; +var Z_MAX = 15.0; +var Y_PELVIS = 1.0; var SPINE_JOINT_NUMBER = 13; var SHOULDER_JOINT_NUMBER = 17; var ELBOW_JOINT_NUMBER = 18; From 4532c934199b7a0292c4a58ef18cb5dba952c60b Mon Sep 17 00:00:00 2001 From: Philip Rosedale Date: Fri, 16 May 2014 09:36:55 -0700 Subject: [PATCH 23/60] debug off --- examples/hydraMove.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/examples/hydraMove.js b/examples/hydraMove.js index 3a11fa0b5e..9465bd9447 100644 --- a/examples/hydraMove.js +++ b/examples/hydraMove.js @@ -55,7 +55,7 @@ function printVector(text, v, decimals) { print(text + " " + v.x.toFixed(decimals) + ", " + v.y.toFixed(decimals) + ", " + v.z.toFixed(decimals)); } -var debug = true; +var debug = false; // Used by handleGrabBehavior() for managing the grab position changes function getAndResetGrabDelta() { @@ -151,8 +151,6 @@ function handleGrabBehavior(deltaTime) { var ROLL_SCALING = 2.0; var euler = Quat.safeEulerAngles(deltaRotation); - - print("dx: " + euler.x); // Adjust body yaw by roll from controller var orientation = Quat.multiply(Quat.angleAxis(((euler.y * YAW_SCALING) + From 5dcd942e8e562872ed949d074951a7d7a890caa5 Mon Sep 17 00:00:00 2001 From: Philip Rosedale Date: Fri, 16 May 2014 09:44:03 -0700 Subject: [PATCH 24/60] removed dead code --- examples/hydraMove.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/examples/hydraMove.js b/examples/hydraMove.js index 9465bd9447..ff71316886 100644 --- a/examples/hydraMove.js +++ b/examples/hydraMove.js @@ -87,7 +87,6 @@ function handleGrabBehavior(deltaTime) { if (debug) printVector("start position", grabStartPosition, 3); } if (grabbingWithRightHand) { - //grabDelta = Vec3.sum(grabDelta, Vec3.multiply(Controller.getSpatialControlVelocity(RIGHT_PALM), deltaTime)); grabDelta = Vec3.subtract(Controller.getSpatialControlPosition(RIGHT_PALM), grabStartPosition); grabCurrentRotation = Controller.getSpatialControlRawRotation(RIGHT_PALM); } @@ -105,7 +104,6 @@ function handleGrabBehavior(deltaTime) { } if (grabbingWithLeftHand) { - //grabDelta = Vec3.sum(grabDelta, Vec3.multiply(Controller.getSpatialControlVelocity(LEFT_PALM), deltaTime)); grabDelta = Vec3.subtract(Controller.getSpatialControlPosition(LEFT_PALM), grabStartPosition); grabCurrentRotation = Controller.getSpatialControlRawRotation(LEFT_PALM); } @@ -125,9 +123,7 @@ function handleGrabBehavior(deltaTime) { var right = Quat.getRight(headOrientation); var up = Quat.getUp(headOrientation); - //grabDelta = Quat.multiply(headOrientation, grabDelta); - //grabDelta = Quat.multiply(Camera.getOrientation(), grabDelta); - grabDelta = Vec3.multiplyQbyV(MyAvatar.orientation, Vec3.multiply(grabDelta, -1)); + grabDelta = Vec3.multiplyQbyV(MyAvatar.orientation, Vec3.multiply(grabDelta, -1)); if (debug) { printVector("grabDelta: ", grabDelta, 3); From ea5dfbdf28f540373b3a67f6a02d0204a5c62dd5 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Fri, 16 May 2014 09:53:48 -0700 Subject: [PATCH 25/60] Update parameter to const --- interface/src/ui/NodeBounds.cpp | 4 ++-- interface/src/ui/NodeBounds.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/interface/src/ui/NodeBounds.cpp b/interface/src/ui/NodeBounds.cpp index 96639c44e5..4621be6c42 100644 --- a/interface/src/ui/NodeBounds.cpp +++ b/interface/src/ui/NodeBounds.cpp @@ -152,7 +152,7 @@ void NodeBounds::draw() { } } -void NodeBounds::drawNodeBorder(glm::vec3 center, float scale, float red, float green, float blue) { +void NodeBounds::drawNodeBorder(const glm::vec3& center, float scale, float red, float green, float blue) { glPushMatrix(); glTranslatef(center.x, center.y, center.z); @@ -221,7 +221,7 @@ void NodeBounds::drawOverlay() { const int BACKGROUND_OFFSET_Y = -20; const int BACKGROUND_BEVEL = 3; - char* text = _overlayText.toLocal8Bit().data(); + char* text = _overlayText.toLatin1().data(); int mouseX = application->getMouseX(), mouseY = application->getMouseY(), textWidth = widthText(TEXT_SCALE, 0, text); diff --git a/interface/src/ui/NodeBounds.h b/interface/src/ui/NodeBounds.h index 9ef2ab486a..ae2be5f2c1 100644 --- a/interface/src/ui/NodeBounds.h +++ b/interface/src/ui/NodeBounds.h @@ -34,7 +34,7 @@ public slots: void setShowParticleNodes(bool value) { _showParticleNodes = value; } protected: - void drawNodeBorder(glm::vec3 center, float scale, float red, float green, float blue); + void drawNodeBorder(const glm::vec3& center, float scale, float red, float green, float blue); void getColorForNodeType(NodeType_t nodeType, float& red, float& green, float& blue); private: From f5b4e1da37ed8be7ae00b35415969bdaa149aac9 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Fri, 16 May 2014 10:00:35 -0700 Subject: [PATCH 26/60] fix potential floating point error when animations have no frames --- libraries/models/src/ModelItem.cpp | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/libraries/models/src/ModelItem.cpp b/libraries/models/src/ModelItem.cpp index c04f9a76ae..3dd1c99e60 100644 --- a/libraries/models/src/ModelItem.cpp +++ b/libraries/models/src/ModelItem.cpp @@ -714,6 +714,7 @@ void ModelItem::mapJoints(const QStringList& modelJointNames) { if (!_jointMappingCompleted) { QStringList animationJointNames = myAnimation->getJointNames(); + if (modelJointNames.size() > 0 && animationJointNames.size() > 0) { _jointMapping.resize(modelJointNames.size()); for (int i = 0; i < modelJointNames.size(); i++) { @@ -729,13 +730,17 @@ QVector ModelItem::getAnimationFrame() { if (hasAnimation() && _jointMappingCompleted) { Animation* myAnimation = getAnimation(_animationURL); QVector frames = myAnimation->getFrames(); - int animationFrameIndex = (int)std::floor(_animationFrameIndex) % frames.size(); - QVector rotations = frames[animationFrameIndex].rotations; - frameData.resize(_jointMapping.size()); - for (int j = 0; j < _jointMapping.size(); j++) { - int rotationIndex = _jointMapping[j]; - if (rotationIndex != -1 && rotationIndex < rotations.size()) { - frameData[j] = rotations[rotationIndex]; + int frameCount = frames.size(); + + if (frameCount > 0) { + int animationFrameIndex = (int)glm::floor(_animationFrameIndex) % frameCount; + QVector rotations = frames[animationFrameIndex].rotations; + frameData.resize(_jointMapping.size()); + for (int j = 0; j < _jointMapping.size(); j++) { + int rotationIndex = _jointMapping[j]; + if (rotationIndex != -1 && rotationIndex < rotations.size()) { + frameData[j] = rotations[rotationIndex]; + } } } } From dbbd3351efa7d84bb613621b94c600ee9e65f4be Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Fri, 16 May 2014 10:10:50 -0700 Subject: [PATCH 27/60] Fix node bounds overlay blinking QString.to* do not seem to return null terminated strings. --- interface/src/ui/NodeBounds.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/interface/src/ui/NodeBounds.cpp b/interface/src/ui/NodeBounds.cpp index 4621be6c42..e1e37fe21b 100644 --- a/interface/src/ui/NodeBounds.cpp +++ b/interface/src/ui/NodeBounds.cpp @@ -216,18 +216,22 @@ void NodeBounds::drawOverlay() { const float TEXT_COLOR[] = { 0.90f, 0.90f, 0.90f }; const float TEXT_SCALE = 0.1f; const int TEXT_HEIGHT = 10; + const float ROTATION = 0.0f; + const int FONT = 2; const int PADDING = 10; const int MOUSE_OFFSET = 10; const int BACKGROUND_OFFSET_Y = -20; const int BACKGROUND_BEVEL = 3; - char* text = _overlayText.toLatin1().data(); + char textData[_overlayText.length() + 1]; + strcpy(textData, _overlayText.toLatin1().constData()); + int mouseX = application->getMouseX(), mouseY = application->getMouseY(), - textWidth = widthText(TEXT_SCALE, 0, text); + textWidth = widthText(TEXT_SCALE, 0, textData); glColor4f(0.4, 0.4, 0.4, 0.6); renderBevelCornersRect(mouseX + MOUSE_OFFSET, mouseY - TEXT_HEIGHT - PADDING, textWidth + (2 * PADDING), TEXT_HEIGHT + (2 * PADDING), BACKGROUND_BEVEL); - drawText(mouseX + MOUSE_OFFSET + PADDING, mouseY, TEXT_SCALE, 0.0f, 0, text, TEXT_COLOR); + drawText(mouseX + MOUSE_OFFSET + PADDING, mouseY, TEXT_SCALE, ROTATION, FONT, textData, TEXT_COLOR); } } From 91b1910b86c86f41cf7cedc911fe63d304e44403 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Fri, 16 May 2014 10:28:21 -0700 Subject: [PATCH 28/60] Explicitly null-terminate a string --- interface/src/ui/NodeBounds.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/interface/src/ui/NodeBounds.cpp b/interface/src/ui/NodeBounds.cpp index e1e37fe21b..40ae606733 100644 --- a/interface/src/ui/NodeBounds.cpp +++ b/interface/src/ui/NodeBounds.cpp @@ -223,8 +223,10 @@ void NodeBounds::drawOverlay() { const int BACKGROUND_OFFSET_Y = -20; const int BACKGROUND_BEVEL = 3; - char textData[_overlayText.length() + 1]; + int textLength = _overlayText.length(); + char textData[textLength + 1]; strcpy(textData, _overlayText.toLatin1().constData()); + textData[textLength] = '\0'; int mouseX = application->getMouseX(), mouseY = application->getMouseY(), From 59b23efbd84ccd926152a2e946f21a4f302aaa31 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Fri, 16 May 2014 10:37:28 -0700 Subject: [PATCH 29/60] Update old comment --- interface/src/ui/NodeBounds.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interface/src/ui/NodeBounds.cpp b/interface/src/ui/NodeBounds.cpp index 40ae606733..b46b729157 100644 --- a/interface/src/ui/NodeBounds.cpp +++ b/interface/src/ui/NodeBounds.cpp @@ -92,7 +92,7 @@ void NodeBounds::draw() { float scaleFactor = rootDetails.s * TREE_SCALE; - // Scale by 0.98 - 1.02 depending on the scale of the node. This allows smaller nodes to scale in + // Scale by 0.92 - 1.00 depending on the scale of the node. This allows smaller nodes to scale in // a bit and not overlap larger nodes. scaleFactor *= 0.92 + (rootDetails.s * 0.08); From 20eadab9700adb05a3ceb46909d8b59ffcf0500b Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Fri, 16 May 2014 11:18:21 -0700 Subject: [PATCH 30/60] Lock joystick states for thread safety. --- interface/src/devices/JoystickManager.cpp | 6 ++++++ interface/src/devices/JoystickManager.h | 4 +++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/interface/src/devices/JoystickManager.cpp b/interface/src/devices/JoystickManager.cpp index da3c1834af..6b8fd9563f 100644 --- a/interface/src/devices/JoystickManager.cpp +++ b/interface/src/devices/JoystickManager.cpp @@ -44,10 +44,16 @@ JoystickManager::~JoystickManager() { #endif } +QVector JoystickManager::getJoystickStates() { + QMutexLocker locker(&_joystickMutex); + return _joystickStates; +} + void JoystickManager::update() { #ifdef HAVE_SDL SDL_JoystickUpdate(); + QMutexLocker locker(&_joystickMutex); for (int i = 0; i < _joystickStates.size(); i++) { SDL_Joystick* joystick = _joysticks.at(i); JoystickState& state = _joystickStates[i]; diff --git a/interface/src/devices/JoystickManager.h b/interface/src/devices/JoystickManager.h index 53a255e129..1979cf0205 100644 --- a/interface/src/devices/JoystickManager.h +++ b/interface/src/devices/JoystickManager.h @@ -12,6 +12,7 @@ #ifndef hifi_JoystickManager_h #define hifi_JoystickManager_h +#include #include #include @@ -31,12 +32,13 @@ public: JoystickManager(); virtual ~JoystickManager(); - const QVector& getJoystickStates() const { return _joystickStates; } + QVector getJoystickStates(); void update(); private: QVector _joystickStates; + QMutex _joystickMutex; #ifdef HAVE_SDL QVector _joysticks; From c42368594d7035f33327cb8a54884e8e40eea060 Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Fri, 16 May 2014 11:24:45 -0700 Subject: [PATCH 31/60] Scratch that; going to shoehorn joystick data into palms. --- interface/src/devices/JoystickManager.cpp | 6 ----- interface/src/devices/JoystickManager.h | 4 +-- .../ControllerScriptingInterface.cpp | 26 ++----------------- 3 files changed, 3 insertions(+), 33 deletions(-) diff --git a/interface/src/devices/JoystickManager.cpp b/interface/src/devices/JoystickManager.cpp index 6b8fd9563f..da3c1834af 100644 --- a/interface/src/devices/JoystickManager.cpp +++ b/interface/src/devices/JoystickManager.cpp @@ -44,16 +44,10 @@ JoystickManager::~JoystickManager() { #endif } -QVector JoystickManager::getJoystickStates() { - QMutexLocker locker(&_joystickMutex); - return _joystickStates; -} - void JoystickManager::update() { #ifdef HAVE_SDL SDL_JoystickUpdate(); - QMutexLocker locker(&_joystickMutex); for (int i = 0; i < _joystickStates.size(); i++) { SDL_Joystick* joystick = _joysticks.at(i); JoystickState& state = _joystickStates[i]; diff --git a/interface/src/devices/JoystickManager.h b/interface/src/devices/JoystickManager.h index 1979cf0205..53a255e129 100644 --- a/interface/src/devices/JoystickManager.h +++ b/interface/src/devices/JoystickManager.h @@ -12,7 +12,6 @@ #ifndef hifi_JoystickManager_h #define hifi_JoystickManager_h -#include #include #include @@ -32,13 +31,12 @@ public: JoystickManager(); virtual ~JoystickManager(); - QVector getJoystickStates(); + const QVector& getJoystickStates() const { return _joystickStates; } void update(); private: QVector _joystickStates; - QMutex _joystickMutex; #ifdef HAVE_SDL QVector _joysticks; diff --git a/interface/src/scripting/ControllerScriptingInterface.cpp b/interface/src/scripting/ControllerScriptingInterface.cpp index 929be1df5e..286d55081d 100644 --- a/interface/src/scripting/ControllerScriptingInterface.cpp +++ b/interface/src/scripting/ControllerScriptingInterface.cpp @@ -74,7 +74,6 @@ bool ControllerScriptingInterface::isPrimaryButtonPressed() const { return true; } } - return false; } @@ -88,24 +87,10 @@ glm::vec2 ControllerScriptingInterface::getPrimaryJoystickPosition() const { } int ControllerScriptingInterface::getNumberOfButtons() const { - int buttonCount = 0; - foreach (const JoystickState& state, Application::getInstance()->getJoystickManager()->getJoystickStates()) { - buttonCount += state.buttons.size(); - } - return buttonCount + getNumberOfActivePalms() * NUMBER_OF_BUTTONS_PER_PALM; + return getNumberOfActivePalms() * NUMBER_OF_BUTTONS_PER_PALM; } bool ControllerScriptingInterface::isButtonPressed(int buttonIndex) const { - int managedButtonIndex = buttonIndex - getNumberOfActivePalms() * NUMBER_OF_BUTTONS_PER_PALM; - if (managedButtonIndex >= 0) { - foreach (const JoystickState& state, Application::getInstance()->getJoystickManager()->getJoystickStates()) { - if (managedButtonIndex < state.buttons.size()) { - return state.buttons.at(managedButtonIndex); - } - managedButtonIndex -= state.buttons.size(); - } - return false; - } int palmIndex = buttonIndex / NUMBER_OF_BUTTONS_PER_PALM; int buttonOnPalm = buttonIndex % NUMBER_OF_BUTTONS_PER_PALM; const PalmData* palmData = getActivePalm(palmIndex); @@ -143,18 +128,11 @@ float ControllerScriptingInterface::getTriggerValue(int triggerIndex) const { } int ControllerScriptingInterface::getNumberOfJoysticks() const { - return getNumberOfActivePalms() * NUMBER_OF_JOYSTICKS_PER_PALM + - Application::getInstance()->getJoystickManager()->getJoystickStates().size(); + return getNumberOfActivePalms() * NUMBER_OF_JOYSTICKS_PER_PALM; } glm::vec2 ControllerScriptingInterface::getJoystickPosition(int joystickIndex) const { // we know there's one joystick per palm, so the joystickIndex is the palm Index - int managedJoystickIndex = joystickIndex - getNumberOfActivePalms(); - if (managedJoystickIndex >= 0) { - const JoystickState& state = Application::getInstance()->getJoystickManager()->getJoystickStates().at( - managedJoystickIndex); - return glm::vec2(state.axes.size() > 0 ? state.axes.at(0) : 0.0f, state.axes.size() > 1 ? state.axes.at(1) : 0.0f); - } int palmIndex = joystickIndex; const PalmData* palmData = getActivePalm(palmIndex); if (palmData) { From a7234fd8d33e72dba01eb5c9485f408138994a4e Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Fri, 16 May 2014 12:10:21 -0700 Subject: [PATCH 32/60] Stuff the joystick and position bits into the palms. --- interface/src/Application.cpp | 2 +- interface/src/devices/PrioVR.cpp | 87 ++++++++++++++++++- interface/src/devices/PrioVR.h | 2 +- .../ControllerScriptingInterface.cpp | 1 + 4 files changed, 89 insertions(+), 3 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 91e95bb4e3..9f391aa36b 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -1990,7 +1990,7 @@ void Application::update(float deltaTime) { _myAvatar->updateLookAtTargetAvatar(); updateMyAvatarLookAtPosition(); _sixenseManager.update(deltaTime); - _prioVR.update(); + _prioVR.update(deltaTime); updateMyAvatar(deltaTime); // Sample hardware, update view frustum if needed, and send avatar data to mixer/nodes updateThreads(deltaTime); // If running non-threaded, then give the threads some time to process... _avatarManager.updateOtherAvatars(deltaTime); //loop through all the other avatars and simulate them... diff --git a/interface/src/devices/PrioVR.cpp b/interface/src/devices/PrioVR.cpp index e6e948422e..dcc3d314f3 100644 --- a/interface/src/devices/PrioVR.cpp +++ b/interface/src/devices/PrioVR.cpp @@ -37,6 +37,87 @@ static int indexOfHumanIKJoint(const char* jointName) { } } } + +static void setPalm(float deltaTime, int index) { + MyAvatar* avatar = Application::getInstance()->getAvatar(); + Hand* hand = avatar->getHand(); + PalmData* palm; + bool foundHand = false; + for (size_t j = 0; j < hand->getNumPalms(); j++) { + if (hand->getPalms()[j].getSixenseID() == index) { + palm = &(hand->getPalms()[j]); + foundHand = true; + } + } + if (!foundHand) { + PalmData newPalm(hand); + hand->getPalms().push_back(newPalm); + palm = &(hand->getPalms()[hand->getNumPalms() - 1]); + palm->setSixenseID(index); + } + + palm->setActive(true); + + // Read controller buttons and joystick into the hand + if (!Application::getInstance()->getJoystickManager()->getJoystickStates().isEmpty()) { + const JoystickState& state = Application::getInstance()->getJoystickManager()->getJoystickStates().at(0); + if (state.axes.size() >= 4 && state.buttons.size() >= 4) { + if (index == 0) { + palm->setControllerButtons(state.buttons.at(1) ? BUTTON_FWD : 0); + palm->setTrigger(state.buttons.at(0) ? 1.0f : 0.0f); + palm->setJoystick(state.axes.at(0), -state.axes.at(1)); + + } else { + palm->setControllerButtons(state.buttons.at(3) ? BUTTON_FWD : 0); + palm->setTrigger(state.buttons.at(2) ? 1.0f : 0.0f); + palm->setJoystick(state.axes.at(2), -state.axes.at(3)); + } + } + } + + glm::vec3 position; + glm::quat rotation; + + Model* skeletonModel = &Application::getInstance()->getAvatar()->getSkeletonModel(); + int jointIndex; + glm::quat inverseRotation = glm::inverse(skeletonModel->getRotation()); + if (index == 0) { + jointIndex = skeletonModel->getLeftHandJointIndex(); + skeletonModel->getJointRotation(jointIndex, rotation, true); + rotation = inverseRotation * rotation * glm::quat(glm::vec3(0.0f, -PI_OVER_TWO, 0.0f)); + + } else { + jointIndex = skeletonModel->getRightHandJointIndex(); + skeletonModel->getJointRotation(jointIndex, rotation, true); + rotation = inverseRotation * rotation * glm::quat(glm::vec3(0.0f, PI_OVER_TWO, 0.0f)); + } + skeletonModel->getJointPosition(jointIndex, position); + position = inverseRotation * (position - skeletonModel->getTranslation()); + + palm->setRawRotation(rotation); + + // Compute current velocity from position change + glm::vec3 rawVelocity; + if (deltaTime > 0.f) { + rawVelocity = (position - palm->getRawPosition()) / deltaTime; + } else { + rawVelocity = glm::vec3(0.0f); + } + palm->setRawVelocity(rawVelocity); + palm->setRawPosition(position); + + // Store the one fingertip in the palm structure so we can track velocity + const float FINGER_LENGTH = 0.3f; // meters + const glm::vec3 FINGER_VECTOR(0.0f, 0.0f, FINGER_LENGTH); + const glm::vec3 newTipPosition = position + rotation * FINGER_VECTOR; + glm::vec3 oldTipPosition = palm->getTipRawPosition(); + if (deltaTime > 0.f) { + palm->setTipVelocity((newTipPosition - oldTipPosition) / deltaTime); + } else { + palm->setTipVelocity(glm::vec3(0.f)); + } + palm->setTipPosition(newTipPosition); +} #endif PrioVR::PrioVR() { @@ -78,7 +159,7 @@ glm::quat PrioVR::getTorsoRotation() const { return _jointRotations.size() > TORSO_ROTATION_INDEX ? _jointRotations.at(TORSO_ROTATION_INDEX) : glm::quat(); } -void PrioVR::update() { +void PrioVR::update(float deltaTime) { #ifdef HAVE_PRIOVR if (!_skeletalDevice) { return; @@ -96,6 +177,10 @@ void PrioVR::update() { _lastJointRotations[i] = _jointRotations.at(i); _jointRotations[i] = safeMix(lastRotation, _jointRotations.at(i), 0.5f); } + + // convert the joysticks into palm data + setPalm(deltaTime, 0); + setPalm(deltaTime, 1); #endif } diff --git a/interface/src/devices/PrioVR.h b/interface/src/devices/PrioVR.h index 8f01574356..bb563bf807 100644 --- a/interface/src/devices/PrioVR.h +++ b/interface/src/devices/PrioVR.h @@ -43,7 +43,7 @@ public: const QVector& getHumanIKJointIndices() const { return _humanIKJointIndices; } const QVector& getJointRotations() const { return _jointRotations; } - void update(); + void update(float deltaTime); void reset(); private slots: diff --git a/interface/src/scripting/ControllerScriptingInterface.cpp b/interface/src/scripting/ControllerScriptingInterface.cpp index 286d55081d..34c1cc2f1c 100644 --- a/interface/src/scripting/ControllerScriptingInterface.cpp +++ b/interface/src/scripting/ControllerScriptingInterface.cpp @@ -74,6 +74,7 @@ bool ControllerScriptingInterface::isPrimaryButtonPressed() const { return true; } } + return false; } From 32974b40032a29320cb0290e5ff26684a9b1b070 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Fri, 16 May 2014 12:16:42 -0700 Subject: [PATCH 33/60] Remove QGLWidget include from NodeBounds --- interface/src/ui/NodeBounds.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/interface/src/ui/NodeBounds.cpp b/interface/src/ui/NodeBounds.cpp index b46b729157..1f06f60c5c 100644 --- a/interface/src/ui/NodeBounds.cpp +++ b/interface/src/ui/NodeBounds.cpp @@ -12,8 +12,6 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -#include - #include "Application.h" #include "NodeBounds.h" #include "Util.h" From 3f2d08871cef7ddf57fdab915b78a4604031a8b2 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Fri, 16 May 2014 12:24:26 -0700 Subject: [PATCH 34/60] Reorder includes in NodeBounds.cpp --- interface/src/ui/NodeBounds.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/interface/src/ui/NodeBounds.cpp b/interface/src/ui/NodeBounds.cpp index 1f06f60c5c..6d4d809a86 100644 --- a/interface/src/ui/NodeBounds.cpp +++ b/interface/src/ui/NodeBounds.cpp @@ -13,9 +13,10 @@ // #include "Application.h" -#include "NodeBounds.h" #include "Util.h" +#include "NodeBounds.h" + NodeBounds::NodeBounds(QObject* parent) : QObject(parent), _showVoxelNodes(false), From e5d6a66ca9dd354b8d4b15ae80b293c02b5b9beb Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Fri, 16 May 2014 13:21:10 -0700 Subject: [PATCH 35/60] Use char array instead of QString in NodeBounds --- interface/src/ui/NodeBounds.cpp | 24 ++++++++++++------------ interface/src/ui/NodeBounds.h | 4 +++- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/interface/src/ui/NodeBounds.cpp b/interface/src/ui/NodeBounds.cpp index 40ae606733..a7d3ae062d 100644 --- a/interface/src/ui/NodeBounds.cpp +++ b/interface/src/ui/NodeBounds.cpp @@ -23,7 +23,7 @@ NodeBounds::NodeBounds(QObject* parent) : _showVoxelNodes(false), _showModelNodes(false), _showParticleNodes(false), - _overlayText("") { + _overlayText() { } @@ -143,12 +143,17 @@ void NodeBounds::draw() { glPopMatrix(); HifiSockAddr addr = selectedNode->getPublicSocket(); - _overlayText = QString("%1:%2 %3ms") + QString overlay = QString("%1:%2 %3ms") .arg(addr.getAddress().toString()) .arg(addr.getPort()) - .arg(selectedNode->getPingMs()); + .arg(selectedNode->getPingMs()) + .left(MAX_OVERLAY_TEXT_LENGTH); + + // Ideally we'd just use a QString, but I ran into weird blinking issues using + // constData() directly, as if the data was being overwritten. + strcpy(_overlayText, overlay.toLocal8Bit().constData()); } else { - _overlayText = QString(); + _overlayText[0] = '\0'; } } @@ -210,7 +215,7 @@ void NodeBounds::getColorForNodeType(NodeType_t nodeType, float& red, float& gre } void NodeBounds::drawOverlay() { - if (!_overlayText.isNull() && !_overlayText.isEmpty()) { + if (strlen(_overlayText) > 0) { Application* application = Application::getInstance(); const float TEXT_COLOR[] = { 0.90f, 0.90f, 0.90f }; @@ -223,17 +228,12 @@ void NodeBounds::drawOverlay() { const int BACKGROUND_OFFSET_Y = -20; const int BACKGROUND_BEVEL = 3; - int textLength = _overlayText.length(); - char textData[textLength + 1]; - strcpy(textData, _overlayText.toLatin1().constData()); - textData[textLength] = '\0'; - int mouseX = application->getMouseX(), mouseY = application->getMouseY(), - textWidth = widthText(TEXT_SCALE, 0, textData); + textWidth = widthText(TEXT_SCALE, 0, _overlayText); glColor4f(0.4, 0.4, 0.4, 0.6); renderBevelCornersRect(mouseX + MOUSE_OFFSET, mouseY - TEXT_HEIGHT - PADDING, textWidth + (2 * PADDING), TEXT_HEIGHT + (2 * PADDING), BACKGROUND_BEVEL); - drawText(mouseX + MOUSE_OFFSET + PADDING, mouseY, TEXT_SCALE, ROTATION, FONT, textData, TEXT_COLOR); + drawText(mouseX + MOUSE_OFFSET + PADDING, mouseY, TEXT_SCALE, ROTATION, FONT, _overlayText, TEXT_COLOR); } } diff --git a/interface/src/ui/NodeBounds.h b/interface/src/ui/NodeBounds.h index ae2be5f2c1..bd54b84e98 100644 --- a/interface/src/ui/NodeBounds.h +++ b/interface/src/ui/NodeBounds.h @@ -16,6 +16,8 @@ #include +const int MAX_OVERLAY_TEXT_LENGTH = 64; + class NodeBounds : public QObject { Q_OBJECT public: @@ -41,7 +43,7 @@ private: bool _showVoxelNodes; bool _showModelNodes; bool _showParticleNodes; - QString _overlayText; + char _overlayText[MAX_OVERLAY_TEXT_LENGTH + 1]; }; From cc952f9cee0fc5ba7f65560bdaa4814c1db70620 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Fri, 16 May 2014 13:56:28 -0700 Subject: [PATCH 36/60] Reset node bounds overlay text when no nodes are selected --- interface/src/ui/NodeBounds.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/interface/src/ui/NodeBounds.cpp b/interface/src/ui/NodeBounds.cpp index 581093e4c2..735dc66ddf 100644 --- a/interface/src/ui/NodeBounds.cpp +++ b/interface/src/ui/NodeBounds.cpp @@ -28,6 +28,7 @@ NodeBounds::NodeBounds(QObject* parent) : void NodeBounds::draw() { if (!(_showVoxelNodes || _showModelNodes || _showParticleNodes)) { + _overlayText[0] = '\0'; return; } From 956c5d2eb67310d7b0c822a4cca74780e610d2c9 Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Fri, 16 May 2014 14:24:49 -0700 Subject: [PATCH 37/60] More joystick fixes. --- interface/src/Application.cpp | 1 + interface/src/devices/PrioVR.cpp | 18 ++++++++---------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 9f391aa36b..fc23a50f7b 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -1990,6 +1990,7 @@ void Application::update(float deltaTime) { _myAvatar->updateLookAtTargetAvatar(); updateMyAvatarLookAtPosition(); _sixenseManager.update(deltaTime); + _joystickManager.update(); _prioVR.update(deltaTime); updateMyAvatar(deltaTime); // Sample hardware, update view frustum if needed, and send avatar data to mixer/nodes updateThreads(deltaTime); // If running non-threaded, then give the threads some time to process... diff --git a/interface/src/devices/PrioVR.cpp b/interface/src/devices/PrioVR.cpp index f38a2964b4..deba4f82a5 100644 --- a/interface/src/devices/PrioVR.cpp +++ b/interface/src/devices/PrioVR.cpp @@ -63,7 +63,7 @@ static void setPalm(float deltaTime, int index) { if (!Application::getInstance()->getJoystickManager()->getJoystickStates().isEmpty()) { const JoystickState& state = Application::getInstance()->getJoystickManager()->getJoystickStates().at(0); if (state.axes.size() >= 4 && state.buttons.size() >= 4) { - if (index == 0) { + if (index == SIXENSE_CONTROLLER_ID_LEFT_HAND) { palm->setControllerButtons(state.buttons.at(1) ? BUTTON_FWD : 0); palm->setTrigger(state.buttons.at(0) ? 1.0f : 0.0f); palm->setJoystick(state.axes.at(0), -state.axes.at(1)); @@ -71,7 +71,7 @@ static void setPalm(float deltaTime, int index) { } else { palm->setControllerButtons(state.buttons.at(3) ? BUTTON_FWD : 0); palm->setTrigger(state.buttons.at(2) ? 1.0f : 0.0f); - palm->setJoystick(state.axes.at(2), -state.axes.at(3)); + palm->setJoystick(state.axes.at(2), -state.axes.at(3)); } } } @@ -81,16 +81,16 @@ static void setPalm(float deltaTime, int index) { Model* skeletonModel = &Application::getInstance()->getAvatar()->getSkeletonModel(); int jointIndex; - glm::quat inverseRotation = glm::inverse(skeletonModel->getRotation()); - if (index == 0) { + glm::quat inverseRotation = glm::inverse(Application::getInstance()->getAvatar()->getOrientation()); + if (index == SIXENSE_CONTROLLER_ID_LEFT_HAND) { jointIndex = skeletonModel->getLeftHandJointIndex(); skeletonModel->getJointRotation(jointIndex, rotation, true); - rotation = inverseRotation * rotation * glm::quat(glm::vec3(0.0f, -PI_OVER_TWO, 0.0f)); + rotation = inverseRotation * rotation * glm::quat(glm::vec3(0.0f, PI_OVER_TWO, 0.0f)); } else { jointIndex = skeletonModel->getRightHandJointIndex(); skeletonModel->getJointRotation(jointIndex, rotation, true); - rotation = inverseRotation * rotation * glm::quat(glm::vec3(0.0f, PI_OVER_TWO, 0.0f)); + rotation = inverseRotation * rotation * glm::quat(glm::vec3(0.0f, -PI_OVER_TWO, 0.0f)); } skeletonModel->getJointPosition(jointIndex, position); position = inverseRotation * (position - skeletonModel->getTranslation()); @@ -134,8 +134,6 @@ PrioVR::PrioVR() { for (int i = 0; i < LIST_LENGTH; i++) { _humanIKJointIndices.append(jointsDiscovered[i] ? indexOfHumanIKJoint(JOINT_NAMES[i]) : -1); } - const int INITIAL_RESET_DELAY = 5000; - QTimer::singleShot(INITIAL_RESET_DELAY, this, SLOT(reset())); #endif } @@ -182,8 +180,8 @@ void PrioVR::update(float deltaTime) { } // convert the joysticks into palm data - setPalm(deltaTime, 0); - setPalm(deltaTime, 1); + setPalm(deltaTime, SIXENSE_CONTROLLER_ID_LEFT_HAND); + setPalm(deltaTime, SIXENSE_CONTROLLER_ID_RIGHT_HAND); #endif } From 4a23c0cfd938cb1f67f97b983323e8f404ceecec Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Fri, 16 May 2014 16:25:24 -0700 Subject: [PATCH 38/60] Fix for arms' getting twisted up with new IK. --- interface/src/avatar/SkeletonModel.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/interface/src/avatar/SkeletonModel.cpp b/interface/src/avatar/SkeletonModel.cpp index 3786280a3c..09871ad38b 100644 --- a/interface/src/avatar/SkeletonModel.cpp +++ b/interface/src/avatar/SkeletonModel.cpp @@ -334,13 +334,11 @@ void SkeletonModel::setHandPosition(int jointIndex, const glm::vec3& position, c glm::vec3 forwardVector(rightHand ? -1.0f : 1.0f, 0.0f, 0.0f); - glm::quat shoulderRotation; - getJointRotation(shoulderJointIndex, shoulderRotation, true); - applyRotationDelta(shoulderJointIndex, rotationBetween(shoulderRotation * forwardVector, elbowPosition - shoulderPosition), false); + glm::quat shoulderRotation = rotationBetween(forwardVector, elbowPosition - shoulderPosition); + setJointRotation(shoulderJointIndex, shoulderRotation, true); - glm::quat elbowRotation; - getJointRotation(elbowJointIndex, elbowRotation, true); - applyRotationDelta(elbowJointIndex, rotationBetween(elbowRotation * forwardVector, wristPosition - elbowPosition), false); + setJointRotation(elbowJointIndex, rotationBetween(shoulderRotation * forwardVector, + wristPosition - elbowPosition) * shoulderRotation, true); setJointRotation(jointIndex, rotation, true); } From 0e446d0fc5d2e2a0f90fc6d25539fa93a2621a0a Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Fri, 16 May 2014 16:53:14 -0700 Subject: [PATCH 39/60] fix two bugs in models not rendering --- libraries/models/src/ModelTree.cpp | 8 +++++++- libraries/models/src/ModelTree.h | 2 ++ libraries/octree/src/Octree.cpp | 15 ++++----------- libraries/octree/src/Octree.h | 2 ++ 4 files changed, 15 insertions(+), 12 deletions(-) diff --git a/libraries/models/src/ModelTree.cpp b/libraries/models/src/ModelTree.cpp index 4e92544f40..637079560b 100644 --- a/libraries/models/src/ModelTree.cpp +++ b/libraries/models/src/ModelTree.cpp @@ -108,6 +108,7 @@ bool FindAndUpdateModelOperator::PostRecursion(OctreeElement* element) { return !_found; // if we haven't yet found it, keep looking } +// TODO: improve this to not use multiple recursions void ModelTree::storeModel(const ModelItem& model, const SharedNodePointer& senderNode) { // First, look for the existing model in the tree.. FindAndUpdateModelOperator theOperator(model); @@ -118,8 +119,13 @@ void ModelTree::storeModel(const ModelItem& model, const SharedNodePointer& send AABox modelBox = model.getAABox(); ModelTreeElement* element = (ModelTreeElement*)getOrCreateChildElementContaining(model.getAABox()); element->storeModel(model); + + // In the case where we stored it, we also need to mark the entire "path" down to the model as + // having changed. Otherwise viewers won't see this change. So we call this recursion now that + // we know it will be found, this find/update will correctly mark the tree as changed. + recurseTreeWithOperator(&theOperator); } - // what else do we need to do here to get reaveraging to work + _isDirty = true; } diff --git a/libraries/models/src/ModelTree.h b/libraries/models/src/ModelTree.h index 10ef62c0a0..ddd8417db7 100644 --- a/libraries/models/src/ModelTree.h +++ b/libraries/models/src/ModelTree.h @@ -41,6 +41,8 @@ public: virtual int processEditPacketData(PacketType packetType, const unsigned char* packetData, int packetLength, const unsigned char* editData, int maxLength, const SharedNodePointer& senderNode); + virtual bool recurseChildrenWithData() const { return false; } + virtual void update(); void storeModel(const ModelItem& model, const SharedNodePointer& senderNode = SharedNodePointer()); diff --git a/libraries/octree/src/Octree.cpp b/libraries/octree/src/Octree.cpp index 128677ff2b..b352096673 100644 --- a/libraries/octree/src/Octree.cpp +++ b/libraries/octree/src/Octree.cpp @@ -1389,6 +1389,7 @@ int Octree::encodeTreeBitstreamRecursion(OctreeElement* element, keepDiggingDeeper = (inViewNotLeafCount > 0); if (continueThisLevel && keepDiggingDeeper) { + // at this point, we need to iterate the children who are in view, even if not colored // and we need to determine if there's a deeper tree below them that we care about. // @@ -1424,6 +1425,8 @@ int Octree::encodeTreeBitstreamRecursion(OctreeElement* element, int childTreeBytesOut = 0; + // TODO - UPDATE THIS COMMENT!!! + // // XXXBHG - Note, this seems like the correct logic here, if we included the color in this packet, then // the LOD logic determined that the child nodes would not be visible... and if so, we shouldn't recurse // them further. But... for some time now the code has included and recursed into these child nodes, which @@ -1433,7 +1436,7 @@ int Octree::encodeTreeBitstreamRecursion(OctreeElement* element, // // This only applies in the view frustum case, in other cases, like file save and copy/past where // no viewFrustum was requested, we still want to recurse the child tree. - if (!params.viewFrustum || !oneAtBit(childrenColoredBits, originalIndex)) { + if (recurseChildrenWithData() || !params.viewFrustum || !oneAtBit(childrenColoredBits, originalIndex)) { childTreeBytesOut = encodeTreeBitstreamRecursion(childElement, packetData, bag, params, thisLevel, nodeLocationThisView); } @@ -1519,16 +1522,6 @@ int Octree::encodeTreeBitstreamRecursion(OctreeElement* element, } // end keepDiggingDeeper // At this point all our BitMasks are complete... so let's output them to see how they compare... - /** - printf("This Level's BitMasks: childInTree:"); - outputBits(childrenExistInTreeBits, false, true); - printf(" childInPacket:"); - outputBits(childrenExistInPacketBits, false, true); - printf(" childrenColored:"); - outputBits(childrenColoredBits, false, true); - qDebug(""); - **/ - // if we were unable to fit this level in our packet, then rewind and add it to the element bag for // sending later... if (continueThisLevel) { diff --git a/libraries/octree/src/Octree.h b/libraries/octree/src/Octree.h index 84212586f8..1e71884faa 100644 --- a/libraries/octree/src/Octree.h +++ b/libraries/octree/src/Octree.h @@ -209,6 +209,8 @@ public: virtual bool handlesEditPacketType(PacketType packetType) const { return false; } virtual int processEditPacketData(PacketType packetType, const unsigned char* packetData, int packetLength, const unsigned char* editData, int maxLength, const SharedNodePointer& sourceNode) { return 0; } + + virtual bool recurseChildrenWithData() const { return true; } virtual void update() { }; // nothing to do by default From 51ad8194de98883647eb34143be9becac550c265 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Fri, 16 May 2014 16:55:37 -0700 Subject: [PATCH 40/60] fix two bugs in models not rendering --- libraries/octree/src/Octree.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/libraries/octree/src/Octree.cpp b/libraries/octree/src/Octree.cpp index b352096673..3042626a51 100644 --- a/libraries/octree/src/Octree.cpp +++ b/libraries/octree/src/Octree.cpp @@ -1425,8 +1425,6 @@ int Octree::encodeTreeBitstreamRecursion(OctreeElement* element, int childTreeBytesOut = 0; - // TODO - UPDATE THIS COMMENT!!! - // // XXXBHG - Note, this seems like the correct logic here, if we included the color in this packet, then // the LOD logic determined that the child nodes would not be visible... and if so, we shouldn't recurse // them further. But... for some time now the code has included and recursed into these child nodes, which @@ -1436,6 +1434,11 @@ int Octree::encodeTreeBitstreamRecursion(OctreeElement* element, // // This only applies in the view frustum case, in other cases, like file save and copy/past where // no viewFrustum was requested, we still want to recurse the child tree. + // + // NOTE: some octree styles (like models and particles) will store content in parent elements, and child + // elements. In this case, if we stop recursion when we include any data (the colorbits should really be + // called databits), then we wouldn't send the children. So those types of Octree's should tell us to keep + // recursing, by returning TRUE in recurseChildrenWithData(). if (recurseChildrenWithData() || !params.viewFrustum || !oneAtBit(childrenColoredBits, originalIndex)) { childTreeBytesOut = encodeTreeBitstreamRecursion(childElement, packetData, bag, params, thisLevel, nodeLocationThisView); From bb204154a11527e010fe872076fa21e8b2a155fb Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Fri, 16 May 2014 16:59:58 -0700 Subject: [PATCH 41/60] tweak --- libraries/models/src/ModelTree.h | 2 -- libraries/voxels/src/VoxelTree.h | 1 + 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/libraries/models/src/ModelTree.h b/libraries/models/src/ModelTree.h index ddd8417db7..10ef62c0a0 100644 --- a/libraries/models/src/ModelTree.h +++ b/libraries/models/src/ModelTree.h @@ -41,8 +41,6 @@ public: virtual int processEditPacketData(PacketType packetType, const unsigned char* packetData, int packetLength, const unsigned char* editData, int maxLength, const SharedNodePointer& senderNode); - virtual bool recurseChildrenWithData() const { return false; } - virtual void update(); void storeModel(const ModelItem& model, const SharedNodePointer& senderNode = SharedNodePointer()); diff --git a/libraries/voxels/src/VoxelTree.h b/libraries/voxels/src/VoxelTree.h index 2915774fe3..03d07a1649 100644 --- a/libraries/voxels/src/VoxelTree.h +++ b/libraries/voxels/src/VoxelTree.h @@ -55,6 +55,7 @@ public: virtual bool handlesEditPacketType(PacketType packetType) const; virtual int processEditPacketData(PacketType packetType, const unsigned char* packetData, int packetLength, const unsigned char* editData, int maxLength, const SharedNodePointer& node); + virtual bool recurseChildrenWithData() const { return false; } private: // helper functions for nudgeSubTree From e6fa1c55dbd42d14dc73d8fae637f9a5fa621908 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Fri, 16 May 2014 17:06:17 -0700 Subject: [PATCH 42/60] assume we are using a Qt build without bearer management --- interface/CMakeLists.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/interface/CMakeLists.txt b/interface/CMakeLists.txt index 3cbeff7801..b95c0e7b38 100644 --- a/interface/CMakeLists.txt +++ b/interface/CMakeLists.txt @@ -230,6 +230,9 @@ target_link_libraries( "${GNUTLS_LIBRARY}" ) +# assume we are using a Qt build without bearer management +add_definitions(-DQT_NO_BEARERMANAGEMENT) + if (APPLE) # link in required OS X frameworks and include the right GL headers find_library(AppKit AppKit) From 0edcd732fedd420b5fe6bee73473962373b42e4a Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Fri, 16 May 2014 17:36:27 -0700 Subject: [PATCH 43/60] Added rotation and scale to overlay anchers --- examples/editModels.js | 10 ++++++++-- interface/src/ui/overlays/Overlays.cpp | 12 +++++++++++- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/examples/editModels.js b/examples/editModels.js index 9a20a7db27..4bb1453e9d 100644 --- a/examples/editModels.js +++ b/examples/editModels.js @@ -174,8 +174,14 @@ function controller(wichSide) { } this.moveLaser = function () { - var startPosition = Vec3.subtract(this.palmPosition, MyAvatar.position); - var endPosition = Vec3.sum(startPosition, Vec3.multiply(this.front, LASER_LENGTH_FACTOR)); + // the overlays here are anchored to the avatar, which means they are specified in the avatar's local frame + + var inverseRotation = Quat.inverse(MyAvatar.orientation); + var startPosition = Vec3.multiplyQbyV(inverseRotation, Vec3.subtract(this.palmPosition, MyAvatar.position)); + var direction = Vec3.multiplyQbyV(inverseRotation, Vec3.subtract(this.tipPosition, this.palmPosition)); + var distance = Vec3.length(direction); + direction = Vec3.multiply(direction, LASER_LENGTH_FACTOR / distance); + var endPosition = Vec3.sum(startPosition, direction); Overlays.editOverlay(this.laser, { position: startPosition, diff --git a/interface/src/ui/overlays/Overlays.cpp b/interface/src/ui/overlays/Overlays.cpp index 78fe54b267..b769920f24 100644 --- a/interface/src/ui/overlays/Overlays.cpp +++ b/interface/src/ui/overlays/Overlays.cpp @@ -58,13 +58,23 @@ void Overlays::render2D() { } void Overlays::render3D() { - glm::vec3 myAvatarPosition = Application::getInstance()->getAvatar()->getPosition(); + if (_overlays3D.size() == 0) { + return; + } + MyAvatar* avatar = Application::getInstance()->getAvatar(); + glm::quat myAvatarRotation = avatar->getOrientation(); + glm::vec3 myAvatarPosition = avatar->getPosition(); + float angle = glm::degrees(glm::angle(myAvatarRotation)); + glm::vec3 axis = glm::axis(myAvatarRotation); + float myAvatarScale = avatar->getScale(); foreach(Overlay* thisOverlay, _overlays3D) { glPushMatrix(); switch (thisOverlay->getAnchor()) { case Overlay::MY_AVATAR: glTranslatef(myAvatarPosition.x, myAvatarPosition.y, myAvatarPosition.z); + glRotatef(angle, axis.x, axis.y, axis.z); + glScalef(myAvatarScale, myAvatarScale, myAvatarScale); break; default: break; From fd3e871242126eef2473401f8468f3f9dffcd853 Mon Sep 17 00:00:00 2001 From: Mika Impola Date: Sat, 17 May 2014 21:04:27 +0300 Subject: [PATCH 44/60] Updating button position when window is resized. --- examples/sit.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/examples/sit.js b/examples/sit.js index d67f6f6bb5..f503438792 100644 --- a/examples/sit.js +++ b/examples/sit.js @@ -129,6 +129,18 @@ Controller.mousePressEvent.connect(function(event){ } }) +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( standUpButton, {x: newX, y: newY} ); + Overlays.editOverlay( sitDownButton, {x: newX, y: newY} ); + } +} + +Script.update.connect(update); Script.scriptEnding.connect(function() { From cc1bd5d63bd061744a262645baa8f9d49ceab9d9 Mon Sep 17 00:00:00 2001 From: Mika Impola Date: Sat, 17 May 2014 21:24:29 +0300 Subject: [PATCH 45/60] Fixed cropping of the image. --- examples/sit.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/sit.js b/examples/sit.js index f503438792..1df877dba6 100644 --- a/examples/sit.js +++ b/examples/sit.js @@ -15,7 +15,7 @@ var buttonImageUrl = "https://worklist-prod.s3.amazonaws.com/attachment/0aca88e1 var windowDimensions = Controller.getViewportDimensions(); var buttonWidth = 37; -var buttonHeight = 45; +var buttonHeight = 46; var buttonPadding = 10; var buttonPositionX = windowDimensions.x - buttonPadding - buttonWidth; From c8f2dae7bd4882999858b9716dbc82f7280d08db Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Sat, 17 May 2014 18:45:54 -0700 Subject: [PATCH 46/60] Fix for stopping scripts on Windows. --- interface/src/Application.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 17443b3cb0..0d5c75ec09 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -3422,8 +3422,9 @@ ScriptEngine* Application::loadScript(const QString& scriptName, bool loadScript } // start the script on a new thread... - ScriptEngine* scriptEngine = new ScriptEngine(QUrl(scriptName), &_controllerScriptingInterface); - _scriptEnginesHash.insert(scriptName, scriptEngine); + QUrl scriptUrl(scriptName); + ScriptEngine* scriptEngine = new ScriptEngine(scriptUrl, &_controllerScriptingInterface); + _scriptEnginesHash.insert(scriptUrl.toString(), scriptEngine); if (!scriptEngine->hasScript()) { qDebug() << "Application::loadScript(), script failed to load..."; From 5ebb2659a4dffc2f60d203dec092a134378b6f78 Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Sat, 17 May 2014 19:02:14 -0700 Subject: [PATCH 47/60] Fixed initialization order warning. --- 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 0d5c75ec09..487965b3ec 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -169,8 +169,8 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : _voxelHideShowThread(&_voxels), _packetsPerSecond(0), _bytesPerSecond(0), - _previousScriptLocation(), _nodeBoundsDisplay(this), + _previousScriptLocation(), _runningScriptsWidget(new RunningScriptsWidget(_window)), _runningScriptsWidgetWasVisible(false) { From 7d40790260f0a81f298dd2082336c22c05992044 Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Sat, 17 May 2014 22:08:28 -0700 Subject: [PATCH 48/60] Don't compute avatar anchor specs if uneeded --- interface/src/ui/overlays/Overlays.cpp | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/interface/src/ui/overlays/Overlays.cpp b/interface/src/ui/overlays/Overlays.cpp index b769920f24..9e4a594bbc 100644 --- a/interface/src/ui/overlays/Overlays.cpp +++ b/interface/src/ui/overlays/Overlays.cpp @@ -61,17 +61,29 @@ void Overlays::render3D() { if (_overlays3D.size() == 0) { return; } - MyAvatar* avatar = Application::getInstance()->getAvatar(); - glm::quat myAvatarRotation = avatar->getOrientation(); - glm::vec3 myAvatarPosition = avatar->getPosition(); - float angle = glm::degrees(glm::angle(myAvatarRotation)); - glm::vec3 axis = glm::axis(myAvatarRotation); - float myAvatarScale = avatar->getScale(); + bool myAvatarComputed = false; + MyAvatar* avatar; + glm::quat myAvatarRotation; + glm::vec3 myAvatarPosition; + float angle; + glm::vec3 axis; + float myAvatarScale; foreach(Overlay* thisOverlay, _overlays3D) { glPushMatrix(); switch (thisOverlay->getAnchor()) { case Overlay::MY_AVATAR: + if (!myAvatarComputed) { + avatar = Application::getInstance()->getAvatar(); + myAvatarRotation = avatar->getOrientation(); + myAvatarPosition = avatar->getPosition(); + angle = glm::degrees(glm::angle(myAvatarRotation)); + axis = glm::axis(myAvatarRotation); + myAvatarScale = avatar->getScale(); + + myAvatarComputed = true; + } + glTranslatef(myAvatarPosition.x, myAvatarPosition.y, myAvatarPosition.z); glRotatef(angle, axis.x, axis.y, axis.z); glScalef(myAvatarScale, myAvatarScale, myAvatarScale); From 5a7a876697a4da5b7cfdedab1cf6a26ba55927b8 Mon Sep 17 00:00:00 2001 From: Leonardo Murillo Date: Sun, 18 May 2014 18:43:16 -0600 Subject: [PATCH 49/60] CMake find LibOVR --- cmake/modules/FindLibOVR.cmake | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cmake/modules/FindLibOVR.cmake b/cmake/modules/FindLibOVR.cmake index 415eeeb1c5..a028aed7b3 100644 --- a/cmake/modules/FindLibOVR.cmake +++ b/cmake/modules/FindLibOVR.cmake @@ -49,7 +49,8 @@ else (LIBOVR_LIBRARIES AND LIBOVR_INCLUDE_DIRS) set(WINDOWS_LIBOVR_NAME "libovr.lib") endif() - find_library(LIBOVR_LIBRARIES "Lib/Win32/VS2010/${LIBOVR_NAME}" HINTS ${LIBOVR_SEARCH_DIRS}) + # FIX: We shouldn't hardcode VS2010 the path below - fix this. Leo + find_library(LIBOVR_LIBRARIES "Lib/Win32/VS2010/${WINDOWS_LIBOVR_NAME}" HINTS ${LIBOVR_SEARCH_DIRS}) endif () if (LIBOVR_INCLUDE_DIRS AND LIBOVR_LIBRARIES) From 0f198900482df94d8e885e1ed639d2a9e75e0fac Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Sun, 18 May 2014 19:27:43 -0700 Subject: [PATCH 50/60] Fixes filesystem issue between Qt and Windows --- libraries/script-engine/src/ScriptEngine.cpp | 22 ++++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/libraries/script-engine/src/ScriptEngine.cpp b/libraries/script-engine/src/ScriptEngine.cpp index a0ecc88a7b..420529bb6c 100644 --- a/libraries/script-engine/src/ScriptEngine.cpp +++ b/libraries/script-engine/src/ScriptEngine.cpp @@ -608,8 +608,20 @@ void ScriptEngine::include(const QString& includeFile) { QUrl url = resolveInclude(includeFile); QString includeContents; - if (url.scheme() == "file") { + if (url.scheme() == "http" || url.scheme() == "ftp") { + QNetworkAccessManager* networkManager = new QNetworkAccessManager(this); + QNetworkReply* reply = networkManager->get(QNetworkRequest(url)); + qDebug() << "Downloading included script at" << includeFile; + QEventLoop loop; + QObject::connect(reply, SIGNAL(finished()), &loop, SLOT(quit())); + loop.exec(); + includeContents = reply->readAll(); + } else { +#ifdef _WIN32 + QString fileName = url.toString(); +#else QString fileName = url.toLocalFile(); +#endif QFile scriptFile(fileName); if (scriptFile.open(QFile::ReadOnly | QFile::Text)) { qDebug() << "Loading file:" << fileName; @@ -619,14 +631,6 @@ void ScriptEngine::include(const QString& includeFile) { qDebug() << "ERROR Loading file:" << fileName; emit errorMessage("ERROR Loading file:" + fileName); } - } else { - QNetworkAccessManager* networkManager = new QNetworkAccessManager(this); - QNetworkReply* reply = networkManager->get(QNetworkRequest(url)); - qDebug() << "Downloading included script at" << includeFile; - QEventLoop loop; - QObject::connect(reply, SIGNAL(finished()), &loop, SLOT(quit())); - loop.exec(); - includeContents = reply->readAll(); } QScriptValue result = _engine.evaluate(includeContents); From ee8722bc9f1a7e16e5ed2c4dff6bcb97ca64e3b2 Mon Sep 17 00:00:00 2001 From: Leonardo Murillo Date: Sun, 18 May 2014 20:59:41 -0600 Subject: [PATCH 51/60] CMake find LibOVR --- cmake/modules/FindLibOVR.cmake | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/cmake/modules/FindLibOVR.cmake b/cmake/modules/FindLibOVR.cmake index a028aed7b3..f65088e817 100644 --- a/cmake/modules/FindLibOVR.cmake +++ b/cmake/modules/FindLibOVR.cmake @@ -49,8 +49,7 @@ else (LIBOVR_LIBRARIES AND LIBOVR_INCLUDE_DIRS) set(WINDOWS_LIBOVR_NAME "libovr.lib") endif() - # FIX: We shouldn't hardcode VS2010 the path below - fix this. Leo - find_library(LIBOVR_LIBRARIES "Lib/Win32/VS2010/${WINDOWS_LIBOVR_NAME}" HINTS ${LIBOVR_SEARCH_DIRS}) + find_library(LIBOVR_LIBRARIES "Lib/Win32/${WINDOWS_LIBOVR_NAME}" HINTS ${LIBOVR_SEARCH_DIRS}) endif () if (LIBOVR_INCLUDE_DIRS AND LIBOVR_LIBRARIES) From 31ae7ceaffdb817ed003f66c99381c87ee390c04 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Sun, 18 May 2014 20:31:55 -0700 Subject: [PATCH 52/60] added isLocked() to lock the ground plane in hq --- examples/editModels.js | 135 ++++++++++++++++++++++++----------------- 1 file changed, 81 insertions(+), 54 deletions(-) diff --git a/examples/editModels.js b/examples/editModels.js index 4bb1453e9d..35e9f40468 100644 --- a/examples/editModels.js +++ b/examples/editModels.js @@ -117,13 +117,18 @@ function controller(wichSide) { this.grab = function (modelID, properties) { - print("Grabbing " + modelID.id); - this.grabbing = true; - this.modelID = modelID; + if (this.isLocked(properties)) { + print("Model locked " + modelID.id); + } else { + print("Grabbing " + modelID.id); - this.oldModelPosition = properties.position; - this.oldModelRotation = properties.modelRotation; - this.oldModelRadius = properties.radius; + this.grabbing = true; + this.modelID = modelID; + + this.oldModelPosition = properties.position; + this.oldModelRotation = properties.modelRotation; + this.oldModelRadius = properties.radius; + } } this.release = function () { @@ -144,8 +149,24 @@ function controller(wichSide) { this.pressed = false; } } - + + this.isLocked = function (properties) { + // special case to lock the ground plane model in hq. + if (location.hostname == "hq.highfidelity.io" && + properties.modelURL == "https://s3-us-west-1.amazonaws.com/highfidelity-public/ozan/Terrain_Reduce_forAlpha.fbx") { + return true; + } + return false; + } + this.checkModel = function (properties) { + // special case to lock the ground plane model in hq. + if (location.hostname == "hq.highfidelity.io" && + properties.modelURL == "https://s3-us-west-1.amazonaws.com/highfidelity-public/ozan/Terrain_Reduce_forAlpha.fbx") { + return { valid: false }; + } + + // P P - Model // /| A - Palm // / | d B - unit vector toward tip @@ -285,15 +306,18 @@ function controller(wichSide) { } var properties = Models.getModelProperties(foundModels[i]); - print("Checking properties: " + properties.id + " " + properties.isKnownID); - - var check = this.checkModel(properties); - if (check.valid) { - this.grab(foundModels[i], properties); - this.x = check.x; - this.y = check.y; - this.z = check.z; - return; + if (this.isLocked(properties)) { + print("Model locked " + properties.id); + } else { + print("Checking properties: " + properties.id + " " + properties.isKnownID); + var check = this.checkModel(properties); + if (check.valid) { + this.grab(foundModels[i], properties); + this.x = check.x; + this.y = check.y; + this.z = check.z; + return; + } } } } @@ -463,51 +487,54 @@ function mousePressEvent(event) { } var properties = Models.getModelProperties(foundModels[i]); - print("Checking properties: " + properties.id + " " + properties.isKnownID); + if (this.isLocked(properties)) { + print("Model locked " + properties.id); + } else { + print("Checking properties: " + properties.id + " " + properties.isKnownID); + // P P - Model + // /| A - Palm + // / | d B - unit vector toward tip + // / | X - base of the perpendicular line + // A---X----->B d - distance fom axis + // x x - distance from A + // + // |X-A| = (P-A).B + // X == A + ((P-A).B)B + // d = |P-X| - // P P - Model - // /| A - Palm - // / | d B - unit vector toward tip - // / | X - base of the perpendicular line - // A---X----->B d - distance fom axis - // x x - distance from A - // - // |X-A| = (P-A).B - // X == A + ((P-A).B)B - // d = |P-X| + var A = pickRay.origin; + var B = Vec3.normalize(pickRay.direction); + var P = properties.position; - var A = pickRay.origin; - var B = Vec3.normalize(pickRay.direction); - var P = properties.position; + 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)); - 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)); - - if (d < properties.radius && 0 < x && x < LASER_LENGTH_FACTOR) { - modelSelected = true; - selectedModelID = foundModels[i]; - selectedModelProperties = properties; + if (d < properties.radius && 0 < x && x < LASER_LENGTH_FACTOR) { + modelSelected = true; + selectedModelID = foundModels[i]; + selectedModelProperties = properties; - selectedModelProperties.oldRadius = selectedModelProperties.radius; - selectedModelProperties.oldPosition = { - x: selectedModelProperties.position.x, - y: selectedModelProperties.position.y, - z: selectedModelProperties.position.z, - }; - selectedModelProperties.oldRotation = { - x: selectedModelProperties.modelRotation.x, - y: selectedModelProperties.modelRotation.y, - z: selectedModelProperties.modelRotation.z, - w: selectedModelProperties.modelRotation.w, - }; + selectedModelProperties.oldRadius = selectedModelProperties.radius; + selectedModelProperties.oldPosition = { + x: selectedModelProperties.position.x, + y: selectedModelProperties.position.y, + z: selectedModelProperties.position.z, + }; + selectedModelProperties.oldRotation = { + x: selectedModelProperties.modelRotation.x, + y: selectedModelProperties.modelRotation.y, + z: selectedModelProperties.modelRotation.z, + w: selectedModelProperties.modelRotation.w, + }; - orientation = MyAvatar.orientation; - intersection = rayPlaneIntersection(pickRay, P, Quat.getFront(orientation)); - print("Clicked on " + selectedModelID.id + " " + modelSelected); + orientation = MyAvatar.orientation; + intersection = rayPlaneIntersection(pickRay, P, Quat.getFront(orientation)); - return; + print("Clicked on " + selectedModelID.id + " " + modelSelected); + return; + } } } } From b228da34a56fd3bc0fee141a4cd54a0e8e9b85eb Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Sun, 18 May 2014 20:43:27 -0700 Subject: [PATCH 53/60] slight DRY --- examples/editModels.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/examples/editModels.js b/examples/editModels.js index 35e9f40468..a73cf72987 100644 --- a/examples/editModels.js +++ b/examples/editModels.js @@ -161,8 +161,7 @@ function controller(wichSide) { this.checkModel = function (properties) { // special case to lock the ground plane model in hq. - if (location.hostname == "hq.highfidelity.io" && - properties.modelURL == "https://s3-us-west-1.amazonaws.com/highfidelity-public/ozan/Terrain_Reduce_forAlpha.fbx") { + if (this.isLocked(properties)) { return { valid: false }; } From 4f4b4c08bb32fa2bbe74a57450187a730f117373 Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Mon, 19 May 2014 12:29:49 -0700 Subject: [PATCH 54/60] Restore specular lighting--but, per the OpenGL spec, shut off specular contribution if the surface isn't facing the light. --- interface/resources/shaders/model.frag | 7 +++++-- interface/resources/shaders/model_normal_map.frag | 9 ++++++--- .../resources/shaders/model_normal_specular_map.frag | 9 ++++++--- interface/resources/shaders/model_specular_map.frag | 9 ++++++--- 4 files changed, 23 insertions(+), 11 deletions(-) diff --git a/interface/resources/shaders/model.frag b/interface/resources/shaders/model.frag index 3964bd5b97..a9d93f2f6a 100644 --- a/interface/resources/shaders/model.frag +++ b/interface/resources/shaders/model.frag @@ -20,11 +20,14 @@ varying vec4 normal; void main(void) { // compute the base color based on OpenGL lighting model vec4 normalizedNormal = normalize(normal); + float diffuse = dot(normalizedNormal, gl_LightSource[0].position); + float facingLight = step(0.0, diffuse); vec4 base = gl_Color * (gl_FrontLightModelProduct.sceneColor + gl_FrontLightProduct[0].ambient + - gl_FrontLightProduct[0].diffuse * max(0.0, dot(normalizedNormal, gl_LightSource[0].position))); + gl_FrontLightProduct[0].diffuse * (diffuse * facingLight)); // compute the specular component (sans exponent) - float specular = max(0.0, dot(gl_LightSource[0].position, normalizedNormal)); + float specular = facingLight * max(0.0, dot(normalize(gl_LightSource[0].position + vec4(0.0, 0.0, 1.0, 0.0)), + normalizedNormal)); // modulate texture by base color and add specular contribution gl_FragColor = base * texture2D(diffuseMap, gl_TexCoord[0].st) + diff --git a/interface/resources/shaders/model_normal_map.frag b/interface/resources/shaders/model_normal_map.frag index a4f7a887c5..392be1f1cf 100644 --- a/interface/resources/shaders/model_normal_map.frag +++ b/interface/resources/shaders/model_normal_map.frag @@ -32,12 +32,15 @@ void main(void) { // compute the base color based on OpenGL lighting model vec4 viewNormal = vec4(normalizedTangent * localNormal.x + normalizedBitangent * localNormal.y + normalizedNormal * localNormal.z, 0.0); + float diffuse = dot(viewNormal, gl_LightSource[0].position); + float facingLight = step(0.0, diffuse); vec4 base = gl_Color * (gl_FrontLightModelProduct.sceneColor + gl_FrontLightProduct[0].ambient + - gl_FrontLightProduct[0].diffuse * max(0.0, dot(viewNormal, gl_LightSource[0].position))); + gl_FrontLightProduct[0].diffuse * (diffuse * facingLight)); // compute the specular component (sans exponent) - float specular = max(0.0, dot(gl_LightSource[0].position, viewNormal)); - + float specular = facingLight * max(0.0, dot(normalize(gl_LightSource[0].position + vec4(0.0, 0.0, 1.0, 0.0)), + viewNormal)); + // modulate texture by base color and add specular contribution gl_FragColor = base * texture2D(diffuseMap, gl_TexCoord[0].st) + vec4(pow(specular, gl_FrontMaterial.shininess) * gl_FrontLightProduct[0].specular.rgb, 0.0); diff --git a/interface/resources/shaders/model_normal_specular_map.frag b/interface/resources/shaders/model_normal_specular_map.frag index f5b9d2b06b..dbbb343c62 100644 --- a/interface/resources/shaders/model_normal_specular_map.frag +++ b/interface/resources/shaders/model_normal_specular_map.frag @@ -35,12 +35,15 @@ void main(void) { // compute the base color based on OpenGL lighting model vec4 viewNormal = vec4(normalizedTangent * localNormal.x + normalizedBitangent * localNormal.y + normalizedNormal * localNormal.z, 0.0); + float diffuse = dot(viewNormal, gl_LightSource[0].position); + float facingLight = step(0.0, diffuse); vec4 base = gl_Color * (gl_FrontLightModelProduct.sceneColor + gl_FrontLightProduct[0].ambient + - gl_FrontLightProduct[0].diffuse * max(0.0, dot(viewNormal, gl_LightSource[0].position))); + gl_FrontLightProduct[0].diffuse * (diffuse * facingLight)); // compute the specular component (sans exponent) - float specular = max(0.0, dot(gl_LightSource[0].position, viewNormal)); - + float specular = facingLight * max(0.0, dot(normalize(gl_LightSource[0].position + vec4(0.0, 0.0, 1.0, 0.0)), + viewNormal)); + // modulate texture by base color and add specular contribution gl_FragColor = base * texture2D(diffuseMap, gl_TexCoord[0].st) + vec4(pow(specular, gl_FrontMaterial.shininess) * gl_FrontLightProduct[0].specular.rgb * texture2D(specularMap, gl_TexCoord[0].st).rgb, 0.0); diff --git a/interface/resources/shaders/model_specular_map.frag b/interface/resources/shaders/model_specular_map.frag index 4e2f3d0c98..b955b5cfa6 100644 --- a/interface/resources/shaders/model_specular_map.frag +++ b/interface/resources/shaders/model_specular_map.frag @@ -23,12 +23,15 @@ varying vec4 normal; void main(void) { // compute the base color based on OpenGL lighting model vec4 normalizedNormal = normalize(normal); + float diffuse = dot(normalizedNormal, gl_LightSource[0].position); + float facingLight = step(0.0, diffuse); vec4 base = gl_Color * (gl_FrontLightModelProduct.sceneColor + gl_FrontLightProduct[0].ambient + - gl_FrontLightProduct[0].diffuse * max(0.0, dot(normalizedNormal, gl_LightSource[0].position))); + gl_FrontLightProduct[0].diffuse * (diffuse * facingLight)); // compute the specular component (sans exponent) - float specular = max(0.0, dot(gl_LightSource[0].position, normalizedNormal)); - + float specular = facingLight * max(0.0, dot(normalize(gl_LightSource[0].position + vec4(0.0, 0.0, 1.0, 0.0)), + normalizedNormal)); + // modulate texture by base color and add specular contribution gl_FragColor = base * texture2D(diffuseMap, gl_TexCoord[0].st) + vec4(pow(specular, gl_FrontMaterial.shininess) * gl_FrontLightProduct[0].specular.rgb * texture2D(specularMap, gl_TexCoord[0].st).rgb, 0.0); From e066d552a0b699c1dc0066369bca618945212ce6 Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Mon, 19 May 2014 12:48:26 -0700 Subject: [PATCH 55/60] Added missing unlock that was causing a hang. --- interface/src/ui/ModelsBrowser.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/interface/src/ui/ModelsBrowser.cpp b/interface/src/ui/ModelsBrowser.cpp index f65829a8ac..4296a096a0 100644 --- a/interface/src/ui/ModelsBrowser.cpp +++ b/interface/src/ui/ModelsBrowser.cpp @@ -351,6 +351,7 @@ bool ModelHandler::parseHeaders(QNetworkReply* reply) { QList items = _model.findItems(QFileInfo(reply->url().toString()).baseName()); if (items.isEmpty() || items.first()->text() == DO_NOT_MODIFY_TAG) { + _lock.unlock(); return false; } From 0e7615391c46ab65502e830725a9a0fe0eedd22b Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Tue, 20 May 2014 10:35:04 -0700 Subject: [PATCH 56/60] don't look for GnuTLS from cmake --- animation-server/CMakeLists.txt | 15 +--------- assignment-client/CMakeLists.txt | 11 +------ cmake/modules/FindGnuTLS.cmake | 41 -------------------------- domain-server/CMakeLists.txt | 13 ++------ interface/CMakeLists.txt | 9 +----- libraries/animation/CMakeLists.txt | 9 +----- libraries/audio/CMakeLists.txt | 13 +------- libraries/avatars/CMakeLists.txt | 11 +------ libraries/fbx/CMakeLists.txt | 13 ++------ libraries/metavoxels/CMakeLists.txt | 10 +------ libraries/models/CMakeLists.txt | 12 ++------ libraries/networking/CMakeLists.txt | 9 +----- libraries/octree/CMakeLists.txt | 13 ++------ libraries/particles/CMakeLists.txt | 12 ++------ libraries/script-engine/CMakeLists.txt | 10 ++----- libraries/voxels/CMakeLists.txt | 13 ++------ voxel-edit/CMakeLists.txt | 10 +------ 17 files changed, 28 insertions(+), 196 deletions(-) delete mode 100644 cmake/modules/FindGnuTLS.cmake diff --git a/animation-server/CMakeLists.txt b/animation-server/CMakeLists.txt index 5d9f3604bc..d8fa8d97b2 100644 --- a/animation-server/CMakeLists.txt +++ b/animation-server/CMakeLists.txt @@ -30,17 +30,4 @@ link_hifi_library(octree ${TARGET_NAME} "${ROOT_DIR}") link_hifi_library(voxels ${TARGET_NAME} "${ROOT_DIR}") # link the hifi networking library -link_hifi_library(networking ${TARGET_NAME} "${ROOT_DIR}") - -find_package(GnuTLS REQUIRED) - -# include the GnuTLS dir -include_directories(SYSTEM "${GNUTLS_INCLUDE_DIR}") - -# add a definition for ssize_t so that windows doesn't bail on gnutls.h -if (WIN32) - add_definitions(-Dssize_t=long) -endif () - -# link GnuTLS -target_link_libraries(${TARGET_NAME} "${GNUTLS_LIBRARY}") \ No newline at end of file +link_hifi_library(networking ${TARGET_NAME} "${ROOT_DIR}") \ No newline at end of file diff --git a/assignment-client/CMakeLists.txt b/assignment-client/CMakeLists.txt index 6436ffbd75..a088c04ffb 100644 --- a/assignment-client/CMakeLists.txt +++ b/assignment-client/CMakeLists.txt @@ -37,15 +37,6 @@ link_hifi_library(animation ${TARGET_NAME} "${ROOT_DIR}") link_hifi_library(script-engine ${TARGET_NAME} "${ROOT_DIR}") link_hifi_library(embedded-webserver ${TARGET_NAME} "${ROOT_DIR}") -find_package(GnuTLS REQUIRED) - -# add a definition for ssize_t so that windows doesn't bail on gnutls.h -if (WIN32) - add_definitions(-Dssize_t=long) -endif () - -include_directories(SYSTEM "${GNUTLS_INCLUDE_DIR}") - if (UNIX) target_link_libraries(${TARGET_NAME} ${CMAKE_DL_LIBS}) endif (UNIX) @@ -54,4 +45,4 @@ IF (WIN32) target_link_libraries(${TARGET_NAME} Winmm Ws2_32) ENDIF(WIN32) -target_link_libraries(${TARGET_NAME} Qt5::Network Qt5::Widgets Qt5::Script "${GNUTLS_LIBRARY}") +target_link_libraries(${TARGET_NAME} Qt5::Network Qt5::Widgets Qt5::Script) diff --git a/cmake/modules/FindGnuTLS.cmake b/cmake/modules/FindGnuTLS.cmake deleted file mode 100644 index 0e1899864b..0000000000 --- a/cmake/modules/FindGnuTLS.cmake +++ /dev/null @@ -1,41 +0,0 @@ -# -# FindGnuTLS.cmake -# -# Try to find the GnuTLS library -# -# You can provide a GNUTLS_ROOT_DIR which contains lib and include directories -# -# Once done this will define -# -# GNUTLS_FOUND - system found GnuTLS -# GNUTLS_INCLUDE_DIR - the GnuTLS include directory -# GNUTLS_LIBRARY - Link this to use GnuTLS -# -# Created on 3/31/2014 by Stephen Birarda -# Copyright (c) 2014 High Fidelity -# -# Distributed under the Apache License, Version 2.0. -# See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -# - -if (GNUTLS_LIBRARY AND GNUTLS_INCLUDE_DIRS) - # in cache already - set(GNUTLS_FOUND TRUE) -else () - set(GNUTLS_SEARCH_DIRS "${GNUTLS_ROOT_DIR}" "$ENV{HIFI_LIB_DIR}/gnutls") - - find_path(GNUTLS_INCLUDE_DIR gnutls/gnutls.h PATH_SUFFIXES include HINTS ${GNUTLS_SEARCH_DIRS}) - - find_library(GNUTLS_LIBRARY NAMES gnutls libgnutls libgnutls-28 PATH_SUFFIXES lib HINTS ${GNUTLS_SEARCH_DIRS}) - - include(FindPackageHandleStandardArgs) - find_package_handle_standard_args(GNUTLS DEFAULT_MSG GNUTLS_INCLUDE_DIR GNUTLS_LIBRARY) - - if (WIN32 AND NOT GNUTLS_FOUND) - message(STATUS "If you're generating a MSVC environment, you'll need to run the command") - message(STATUS "$GnuTLS-DIR\\bin>lib /def:libgnutls-28.def") - message(STATUS "From the MSVC command prompt to generate the .lib file and copy it into") - message(STATUS "the GnuTLS lib folder. Replace $GnuTLS-DIR in the command with the directory") - message(STATUS "containing GnuTLS.") - endif () -endif () diff --git a/domain-server/CMakeLists.txt b/domain-server/CMakeLists.txt index 4736c2438b..d1f923f4d2 100644 --- a/domain-server/CMakeLists.txt +++ b/domain-server/CMakeLists.txt @@ -17,7 +17,6 @@ include(${MACRO_DIR}/IncludeGLM.cmake) include_glm(${TARGET_NAME} "${ROOT_DIR}") find_package(Qt5Network REQUIRED) -find_package(GnuTLS REQUIRED) include(${MACRO_DIR}/SetupHifiProject.cmake) @@ -38,17 +37,9 @@ link_hifi_library(networking ${TARGET_NAME} "${ROOT_DIR}") link_hifi_library(shared ${TARGET_NAME} "${ROOT_DIR}") link_hifi_library(embedded-webserver ${TARGET_NAME} "${ROOT_DIR}") -# include the GnuTLS dir -include_directories(SYSTEM "${GNUTLS_INCLUDE_DIR}") - -# add a definition for ssize_t so that windows doesn't bail on gnutls.h -if (WIN32) - add_definitions(-Dssize_t=long) -endif () - IF (WIN32) target_link_libraries(${TARGET_NAME} Winmm Ws2_32) ENDIF(WIN32) -# link QtNetwork and GnuTLS -target_link_libraries(${TARGET_NAME} Qt5::Network "${GNUTLS_LIBRARY}") \ No newline at end of file +# link QtNetwork +target_link_libraries(${TARGET_NAME} Qt5::Network) \ No newline at end of file diff --git a/interface/CMakeLists.txt b/interface/CMakeLists.txt index b95c0e7b38..67b993d6c9 100644 --- a/interface/CMakeLists.txt +++ b/interface/CMakeLists.txt @@ -69,7 +69,6 @@ foreach(EXTERNAL_SOURCE_SUBDIR ${EXTERNAL_SOURCE_SUBDIRS}) endforeach(EXTERNAL_SOURCE_SUBDIR) find_package(Qt5 COMPONENTS Core Gui Multimedia Network OpenGL Script Svg WebKit WebKitWidgets Xml UiTools) -find_package(GnuTLS REQUIRED) # grab the ui files in resources/ui file (GLOB_RECURSE QT_UI_FILES ui/*.ui) @@ -212,14 +211,9 @@ endif (QXMPP_FOUND AND NOT DISABLE_QXMPP) # include headers for interface and InterfaceConfig. include_directories("${PROJECT_SOURCE_DIR}/src" "${PROJECT_BINARY_DIR}/includes") -# add a definition for ssize_t so that windows doesn't bail on gnutls.h -if (WIN32) - add_definitions(-Dssize_t=long) -endif () - # include external library headers # use system flag so warnings are supressed -include_directories(SYSTEM "${FACESHIFT_INCLUDE_DIRS}" "${GNUTLS_INCLUDE_DIR}") +include_directories(SYSTEM "${FACESHIFT_INCLUDE_DIRS}") target_link_libraries( ${TARGET_NAME} @@ -227,7 +221,6 @@ target_link_libraries( "${ZLIB_LIBRARIES}" Qt5::Core Qt5::Gui Qt5::Multimedia Qt5::Network Qt5::OpenGL Qt5::Script Qt5::Svg Qt5::WebKit Qt5::WebKitWidgets Qt5::Xml Qt5::UiTools - "${GNUTLS_LIBRARY}" ) # assume we are using a Qt build without bearer management diff --git a/libraries/animation/CMakeLists.txt b/libraries/animation/CMakeLists.txt index 36088ba4bd..35ceb22395 100644 --- a/libraries/animation/CMakeLists.txt +++ b/libraries/animation/CMakeLists.txt @@ -26,12 +26,5 @@ link_hifi_library(fbx ${TARGET_NAME} "${ROOT_DIR}") # link ZLIB find_package(ZLIB) -find_package(GnuTLS REQUIRED) -# add a definition for ssize_t so that windows doesn't bail on gnutls.h -if (WIN32) - add_definitions(-Dssize_t=long) -endif () - -include_directories(SYSTEM "${ZLIB_INCLUDE_DIRS}" "${GNUTLS_INCLUDE_DIR}") -target_link_libraries(${TARGET_NAME} "${ZLIB_LIBRARIES}" "${GNUTLS_LIBRARY}" Qt5::Widgets) +target_link_libraries(${TARGET_NAME} "${ZLIB_LIBRARIES}" Qt5::Widgets) diff --git a/libraries/audio/CMakeLists.txt b/libraries/audio/CMakeLists.txt index d946ae5b34..0bf0ba9904 100644 --- a/libraries/audio/CMakeLists.txt +++ b/libraries/audio/CMakeLists.txt @@ -21,15 +21,4 @@ include_glm(${TARGET_NAME} "${ROOT_DIR}") include(${MACRO_DIR}/LinkHifiLibrary.cmake) link_hifi_library(shared ${TARGET_NAME} "${ROOT_DIR}") -link_hifi_library(networking ${TARGET_NAME} "${ROOT_DIR}") - -# link GnuTLS -find_package(GnuTLS REQUIRED) - -# add a definition for ssize_t so that windows doesn't bail on gnutls.h -if (WIN32) - add_definitions(-Dssize_t=long) -endif () - -include_directories(SYSTEM "${GNUTLS_INCLUDE_DIR}") -target_link_libraries(${TARGET_NAME} "${GNUTLS_LIBRARY}") \ No newline at end of file +link_hifi_library(networking ${TARGET_NAME} "${ROOT_DIR}") \ No newline at end of file diff --git a/libraries/avatars/CMakeLists.txt b/libraries/avatars/CMakeLists.txt index 3fa1ebcfe2..9816282dda 100644 --- a/libraries/avatars/CMakeLists.txt +++ b/libraries/avatars/CMakeLists.txt @@ -28,13 +28,4 @@ link_hifi_library(octree ${TARGET_NAME} "${ROOT_DIR}") link_hifi_library(voxels ${TARGET_NAME} "${ROOT_DIR}") link_hifi_library(networking ${TARGET_NAME} "${ROOT_DIR}") -find_package(GnuTLS REQUIRED) - -# add a definition for ssize_t so that windows doesn't bail on gnutls.h -if (WIN32) - add_definitions(-Dssize_t=long) -endif () - - -include_directories(SYSTEM "${GNUTLS_INCLUDE_DIR}") -target_link_libraries(${TARGET_NAME} Qt5::Script "${GNUTLS_LIBRARY}") \ No newline at end of file +target_link_libraries(${TARGET_NAME} Qt5::Script) \ No newline at end of file diff --git a/libraries/fbx/CMakeLists.txt b/libraries/fbx/CMakeLists.txt index 10dd3f49f5..9ce234bbd4 100644 --- a/libraries/fbx/CMakeLists.txt +++ b/libraries/fbx/CMakeLists.txt @@ -24,15 +24,8 @@ link_hifi_library(networking ${TARGET_NAME} "${ROOT_DIR}") link_hifi_library(octree ${TARGET_NAME} "${ROOT_DIR}") link_hifi_library(voxels ${TARGET_NAME} "${ROOT_DIR}") -# link ZLIB and GnuTLS +# link ZLIB find_package(ZLIB) -find_package(GnuTLS REQUIRED) -# add a definition for ssize_t so that windows doesn't bail on gnutls.h -if (WIN32) - add_definitions(-Dssize_t=long) -endif () - - -include_directories(SYSTEM "${ZLIB_INCLUDE_DIRS}" "${GNUTLS_INCLUDE_DIR}") -target_link_libraries(${TARGET_NAME} "${ZLIB_LIBRARIES}" Qt5::Widgets "${GNUTLS_LIBRARY}") +include_directories(SYSTEM "${ZLIB_INCLUDE_DIRS}") +target_link_libraries(${TARGET_NAME} "${ZLIB_LIBRARIES}" Qt5::Widgets) diff --git a/libraries/metavoxels/CMakeLists.txt b/libraries/metavoxels/CMakeLists.txt index e2a90cb085..7a8319815a 100644 --- a/libraries/metavoxels/CMakeLists.txt +++ b/libraries/metavoxels/CMakeLists.txt @@ -27,12 +27,4 @@ link_hifi_library(networking ${TARGET_NAME} "${ROOT_DIR}") include(${MACRO_DIR}/IncludeGLM.cmake) include_glm(${TARGET_NAME} "${ROOT_DIR}") -find_package(GnuTLS REQUIRED) - -# add a definition for ssize_t so that windows doesn't bail on gnutls.h -if (WIN32) - add_definitions(-Dssize_t=long) -endif () - -include_directories(SYSTEM "${GNUTLS_INCLUDE_DIR}") -target_link_libraries(${TARGET_NAME} Qt5::Network Qt5::Widgets Qt5::Script "${GNUTLS_LIBRARY}") \ No newline at end of file +target_link_libraries(${TARGET_NAME} Qt5::Network Qt5::Widgets Qt5::Script) \ No newline at end of file diff --git a/libraries/models/CMakeLists.txt b/libraries/models/CMakeLists.txt index 1e70942872..7833349319 100644 --- a/libraries/models/CMakeLists.txt +++ b/libraries/models/CMakeLists.txt @@ -33,14 +33,8 @@ link_hifi_library(animation ${TARGET_NAME} "${ROOT_DIR}") # for streamable link_hifi_library(metavoxels ${TARGET_NAME} "${ROOT_DIR}") -# link ZLIB and GnuTLS +# link ZLIB find_package(ZLIB) -find_package(GnuTLS REQUIRED) -# add a definition for ssize_t so that windows doesn't bail on gnutls.h -if (WIN32) - add_definitions(-Dssize_t=long) -endif () - -include_directories(SYSTEM "${ZLIB_INCLUDE_DIRS}" "${GNUTLS_INCLUDE_DIR}") -target_link_libraries(${TARGET_NAME} "${ZLIB_LIBRARIES}" Qt5::Widgets "${GNUTLS_LIBRARY}") +include_directories(SYSTEM "${ZLIB_INCLUDE_DIRS}") +target_link_libraries(${TARGET_NAME} "${ZLIB_LIBRARIES}" Qt5::Widgets) \ No newline at end of file diff --git a/libraries/networking/CMakeLists.txt b/libraries/networking/CMakeLists.txt index 6d805cae6c..f93ba2e5cf 100644 --- a/libraries/networking/CMakeLists.txt +++ b/libraries/networking/CMakeLists.txt @@ -11,7 +11,6 @@ set(TARGET_NAME networking) project(${TARGET_NAME}) find_package(Qt5 COMPONENTS Network) -find_package(GnuTLS REQUIRED) include(${MACRO_DIR}/SetupHifiLibrary.cmake) setup_hifi_library(${TARGET_NAME}) @@ -20,10 +19,4 @@ setup_hifi_library(${TARGET_NAME}) include(${MACRO_DIR}/IncludeGLM.cmake) include_glm(${TARGET_NAME} "${ROOT_DIR}") -# add a definition for ssize_t so that windows doesn't bail on gnutls.h -if (WIN32) - add_definitions(-Dssize_t=long) -endif () - -include_directories(SYSTEM "${GNUTLS_INCLUDE_DIR}") -target_link_libraries(${TARGET_NAME} Qt5::Network "${GNUTLS_LIBRARY}") \ No newline at end of file +target_link_libraries(${TARGET_NAME} Qt5::Network) \ No newline at end of file diff --git a/libraries/octree/CMakeLists.txt b/libraries/octree/CMakeLists.txt index 88554ed5f8..985b3fdba7 100644 --- a/libraries/octree/CMakeLists.txt +++ b/libraries/octree/CMakeLists.txt @@ -24,15 +24,8 @@ include(${MACRO_DIR}/LinkHifiLibrary.cmake) link_hifi_library(shared ${TARGET_NAME} "${ROOT_DIR}") link_hifi_library(networking ${TARGET_NAME} "${ROOT_DIR}") -# link ZLIB and GnuTLS +# link ZLIB find_package(ZLIB) -find_package(GnuTLS REQUIRED) -# add a definition for ssize_t so that windows doesn't bail on gnutls.h -if (WIN32) - add_definitions(-Dssize_t=long) -endif () - - -include_directories(SYSTEM "${ZLIB_INCLUDE_DIRS}" "${GNUTLS_INCLUDE_DIR}") -target_link_libraries(${TARGET_NAME} "${ZLIB_LIBRARIES}" Qt5::Widgets "${GNUTLS_LIBRARY}") \ No newline at end of file +include_directories(SYSTEM "${ZLIB_INCLUDE_DIRS}") +target_link_libraries(${TARGET_NAME} "${ZLIB_LIBRARIES}" Qt5::Widgets) \ No newline at end of file diff --git a/libraries/particles/CMakeLists.txt b/libraries/particles/CMakeLists.txt index 8cd2f30012..7f42854b93 100644 --- a/libraries/particles/CMakeLists.txt +++ b/libraries/particles/CMakeLists.txt @@ -27,14 +27,8 @@ link_hifi_library(fbx ${TARGET_NAME} "${ROOT_DIR}") link_hifi_library(networking ${TARGET_NAME} "${ROOT_DIR}") link_hifi_library(animation ${TARGET_NAME} "${ROOT_DIR}") -# link ZLIB and GnuTLS +# link ZLIB find_package(ZLIB) -find_package(GnuTLS REQUIRED) -# add a definition for ssize_t so that windows doesn't bail on gnutls.h -if (WIN32) - add_definitions(-Dssize_t=long) -endif () - -include_directories(SYSTEM "${ZLIB_INCLUDE_DIRS}" "${GNUTLS_INCLUDE_DIR}") -target_link_libraries(${TARGET_NAME} "${ZLIB_LIBRARIES}" Qt5::Widgets "${GNUTLS_LIBRARY}") +include_directories(SYSTEM "${ZLIB_INCLUDE_DIRS}") +target_link_libraries(${TARGET_NAME} "${ZLIB_LIBRARIES}" Qt5::Widgets) diff --git a/libraries/script-engine/CMakeLists.txt b/libraries/script-engine/CMakeLists.txt index 0374ad570c..ac56f335e1 100644 --- a/libraries/script-engine/CMakeLists.txt +++ b/libraries/script-engine/CMakeLists.txt @@ -31,12 +31,6 @@ link_hifi_library(animation ${TARGET_NAME} "${ROOT_DIR}") # link ZLIB find_package(ZLIB) -find_package(GnuTLS REQUIRED) -# add a definition for ssize_t so that windows doesn't bail on gnutls.h -if (WIN32) - add_definitions(-Dssize_t=long) -endif () - -include_directories(SYSTEM "${ZLIB_INCLUDE_DIRS}" "${GNUTLS_INCLUDE_DIR}") -target_link_libraries(${TARGET_NAME} "${ZLIB_LIBRARIES}" "${GNUTLS_LIBRARY}" Qt5::Widgets) +include_directories(SYSTEM "${ZLIB_INCLUDE_DIRS}") +target_link_libraries(${TARGET_NAME} "${ZLIB_LIBRARIES}" Qt5::Widgets) diff --git a/libraries/voxels/CMakeLists.txt b/libraries/voxels/CMakeLists.txt index bdba388594..dd1020b4d7 100644 --- a/libraries/voxels/CMakeLists.txt +++ b/libraries/voxels/CMakeLists.txt @@ -26,15 +26,8 @@ link_hifi_library(shared ${TARGET_NAME} "${ROOT_DIR}") link_hifi_library(octree ${TARGET_NAME} "${ROOT_DIR}") link_hifi_library(networking ${TARGET_NAME} "${ROOT_DIR}") -# link ZLIB and GnuTLS +# link ZLIB find_package(ZLIB) -find_package(GnuTLS REQUIRED) -# add a definition for ssize_t so that windows doesn't bail on gnutls.h -if (WIN32) - add_definitions(-Dssize_t=long) -endif () - - -include_directories(SYSTEM "${ZLIB_INCLUDE_DIRS}" "${GNUTLS_INCLUDE_DIR}") -target_link_libraries(${TARGET_NAME} "${ZLIB_LIBRARIES}" "${GNUTLS_LIBRARY}" Qt5::Widgets Qt5::Script) \ No newline at end of file +include_directories(SYSTEM "${ZLIB_INCLUDE_DIRS}") +target_link_libraries(${TARGET_NAME} "${ZLIB_LIBRARIES}" Qt5::Widgets Qt5::Script) \ No newline at end of file diff --git a/voxel-edit/CMakeLists.txt b/voxel-edit/CMakeLists.txt index cc0a122bf0..ce3c542691 100644 --- a/voxel-edit/CMakeLists.txt +++ b/voxel-edit/CMakeLists.txt @@ -34,16 +34,8 @@ link_hifi_library(voxels ${TARGET_NAME} "${ROOT_DIR}") # link in the hifi networking library link_hifi_library(networking ${TARGET_NAME} "${ROOT_DIR}") -# link GnuTLS -find_package(GnuTLS REQUIRED) - IF (WIN32) target_link_libraries(${TARGET_NAME} Winmm Ws2_32) - - # add a definition for ssize_t so that windows doesn't bail on gnutls.h - add_definitions(-Dssize_t=long) ENDIF(WIN32) -include_directories(SYSTEM "${GNUTLS_INCLUDE_DIR}") - -target_link_libraries(${TARGET_NAME} Qt5::Script "${GNUTLS_LIBRARY}") \ No newline at end of file +target_link_libraries(${TARGET_NAME} Qt5::Script) \ No newline at end of file From e3dd6509d847aab9e71db1fefe3371e9cdb92267 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Tue, 20 May 2014 10:47:11 -0700 Subject: [PATCH 57/60] remove dependency on GnuTLS for later replacement with OpenSSL --- assignment-client/src/AssignmentClient.cpp | 6 - assignment-client/src/AssignmentClient.h | 1 - domain-server/src/DTLSServerSession.cpp | 18 -- domain-server/src/DTLSServerSession.h | 24 --- domain-server/src/DomainServer.cpp | 195 ++---------------- domain-server/src/DomainServer.h | 11 - interface/src/Application.cpp | 7 +- interface/src/ui/OAuthWebViewHandler.cpp | 27 ++- .../networking/src/DTLSClientSession.cpp | 83 -------- libraries/networking/src/DTLSClientSession.h | 30 --- libraries/networking/src/DTLSSession.cpp | 145 ------------- libraries/networking/src/DTLSSession.h | 44 ---- libraries/networking/src/DomainHandler.cpp | 57 +---- libraries/networking/src/DomainHandler.h | 9 - libraries/networking/src/DummyDTLSSession.cpp | 31 --- libraries/networking/src/DummyDTLSSession.h | 34 --- libraries/networking/src/NodeList.cpp | 41 +--- libraries/networking/src/NodeList.h | 2 - 18 files changed, 47 insertions(+), 718 deletions(-) delete mode 100644 domain-server/src/DTLSServerSession.cpp delete mode 100644 domain-server/src/DTLSServerSession.h delete mode 100644 libraries/networking/src/DTLSClientSession.cpp delete mode 100644 libraries/networking/src/DTLSClientSession.h delete mode 100644 libraries/networking/src/DTLSSession.cpp delete mode 100644 libraries/networking/src/DTLSSession.h delete mode 100644 libraries/networking/src/DummyDTLSSession.cpp delete mode 100644 libraries/networking/src/DummyDTLSSession.h diff --git a/assignment-client/src/AssignmentClient.cpp b/assignment-client/src/AssignmentClient.cpp index ff876596b0..d8383ccd48 100644 --- a/assignment-client/src/AssignmentClient.cpp +++ b/assignment-client/src/AssignmentClient.cpp @@ -39,8 +39,6 @@ AssignmentClient::AssignmentClient(int &argc, char **argv) : QCoreApplication(argc, argv), _assignmentServerHostname(DEFAULT_ASSIGNMENT_SERVER_HOSTNAME) { - DTLSClientSession::globalInit(); - setOrganizationName("High Fidelity"); setOrganizationDomain("highfidelity.io"); setApplicationName("assignment-client"); @@ -106,10 +104,6 @@ AssignmentClient::AssignmentClient(int &argc, char **argv) : this, &AssignmentClient::handleAuthenticationRequest); } -AssignmentClient::~AssignmentClient() { - DTLSClientSession::globalDeinit(); -} - void AssignmentClient::sendAssignmentRequest() { if (!_currentAssignment) { NodeList::getInstance()->sendAssignment(_requestAssignment); diff --git a/assignment-client/src/AssignmentClient.h b/assignment-client/src/AssignmentClient.h index 2df9f4ca40..9834402dbf 100644 --- a/assignment-client/src/AssignmentClient.h +++ b/assignment-client/src/AssignmentClient.h @@ -21,7 +21,6 @@ class AssignmentClient : public QCoreApplication { public: AssignmentClient(int &argc, char **argv); static const SharedAssignmentPointer& getCurrentAssignment() { return _currentAssignment; } - ~AssignmentClient(); private slots: void sendAssignmentRequest(); void readPendingDatagrams(); diff --git a/domain-server/src/DTLSServerSession.cpp b/domain-server/src/DTLSServerSession.cpp deleted file mode 100644 index a80c54ee02..0000000000 --- a/domain-server/src/DTLSServerSession.cpp +++ /dev/null @@ -1,18 +0,0 @@ -// -// DTLSServerSession.cpp -// domain-server/src -// -// Created by Stephen Birarda on 2014-04-01. -// 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 -// - -#include "DTLSServerSession.h" - -DTLSServerSession::DTLSServerSession(QUdpSocket& dtlsSocket, HifiSockAddr& destinationSocket) : - DTLSSession(GNUTLS_SERVER, dtlsSocket, destinationSocket) -{ - -} \ No newline at end of file diff --git a/domain-server/src/DTLSServerSession.h b/domain-server/src/DTLSServerSession.h deleted file mode 100644 index 5fdc602df7..0000000000 --- a/domain-server/src/DTLSServerSession.h +++ /dev/null @@ -1,24 +0,0 @@ -// -// DTLSServerSession.h -// domain-server/src -// -// Created by Stephen Birarda on 2014-04-01. -// 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 -// - -#ifndef hifi_DTLSServerSession_h -#define hifi_DTLSServerSession_h - -#include - -#include - -class DTLSServerSession : public DTLSSession { -public: - DTLSServerSession(QUdpSocket& dtlsSocket, HifiSockAddr& destinationSocket); -}; - -#endif // hifi_DTLSServerSession_h diff --git a/domain-server/src/DomainServer.cpp b/domain-server/src/DomainServer.cpp index d9927f3833..fa8a26b259 100644 --- a/domain-server/src/DomainServer.cpp +++ b/domain-server/src/DomainServer.cpp @@ -28,7 +28,6 @@ #include #include "DomainServerNodeData.h" -#include "DummyDTLSSession.h" #include "DomainServer.h" @@ -39,18 +38,12 @@ DomainServer::DomainServer(int argc, char* argv[]) : _allAssignments(), _unfulfilledAssignments(), _isUsingDTLS(false), - _x509Credentials(NULL), - _dhParams(NULL), - _priorityCache(NULL), - _dtlsSessions(), _oauthProviderURL(), _oauthClientID(), _hostname(), _networkReplyUUIDMap(), _sessionAuthenticationHash() { - gnutls_global_init(); - setOrganizationName("High Fidelity"); setOrganizationDomain("highfidelity.io"); setApplicationName("domain-server"); @@ -64,31 +57,10 @@ DomainServer::DomainServer(int argc, char* argv[]) : qDebug() << "Setting up LimitedNodeList and assignments."; setupNodeListAndAssignments(); - if (_isUsingDTLS) { - LimitedNodeList* nodeList = LimitedNodeList::getInstance(); - - // connect our socket to read datagrams received on the DTLS socket - connect(&nodeList->getDTLSSocket(), &QUdpSocket::readyRead, this, &DomainServer::readAvailableDTLSDatagrams); - } - _networkAccessManager = new QNetworkAccessManager(this); } } -DomainServer::~DomainServer() { - if (_x509Credentials) { - gnutls_certificate_free_credentials(*_x509Credentials); - gnutls_priority_deinit(*_priorityCache); - gnutls_dh_params_deinit(*_dhParams); - - delete _x509Credentials; - delete _priorityCache; - delete _dhParams; - delete _cookieKey; - } - gnutls_global_deinit(); -} - bool DomainServer::optionallyReadX509KeyAndCertificate() { const QString X509_CERTIFICATE_OPTION = "cert"; const QString X509_PRIVATE_KEY_OPTION = "key"; @@ -100,28 +72,28 @@ bool DomainServer::optionallyReadX509KeyAndCertificate() { if (!certPath.isEmpty() && !keyPath.isEmpty()) { // the user wants to use DTLS to encrypt communication with nodes // let's make sure we can load the key and certificate - _x509Credentials = new gnutls_certificate_credentials_t; - gnutls_certificate_allocate_credentials(_x509Credentials); +// _x509Credentials = new gnutls_certificate_credentials_t; +// gnutls_certificate_allocate_credentials(_x509Credentials); QString keyPassphraseString = QProcessEnvironment::systemEnvironment().value(X509_KEY_PASSPHRASE_ENV); qDebug() << "Reading certificate file at" << certPath << "for DTLS."; qDebug() << "Reading key file at" << keyPath << "for DTLS."; - int gnutlsReturn = gnutls_certificate_set_x509_key_file2(*_x509Credentials, - certPath.toLocal8Bit().constData(), - keyPath.toLocal8Bit().constData(), - GNUTLS_X509_FMT_PEM, - keyPassphraseString.toLocal8Bit().constData(), - 0); +// int gnutlsReturn = gnutls_certificate_set_x509_key_file2(*_x509Credentials, +// certPath.toLocal8Bit().constData(), +// keyPath.toLocal8Bit().constData(), +// GNUTLS_X509_FMT_PEM, +// keyPassphraseString.toLocal8Bit().constData(), +// 0); +// +// if (gnutlsReturn < 0) { +// qDebug() << "Unable to load certificate or key file." << "Error" << gnutlsReturn << "- domain-server will now quit."; +// QMetaObject::invokeMethod(this, "quit", Qt::QueuedConnection); +// return false; +// } - if (gnutlsReturn < 0) { - qDebug() << "Unable to load certificate or key file." << "Error" << gnutlsReturn << "- domain-server will now quit."; - QMetaObject::invokeMethod(this, "quit", Qt::QueuedConnection); - return false; - } - - qDebug() << "Successfully read certificate and private key."; +// qDebug() << "Successfully read certificate and private key."; // we need to also pass this certificate and private key to the HTTPS manager // this is used for Oauth callbacks when authorizing users against a data server @@ -176,39 +148,6 @@ bool DomainServer::optionallySetupOAuth() { return true; } -bool DomainServer::optionallySetupDTLS() { - if (_x509Credentials) { - qDebug() << "Generating Diffie-Hellman parameters."; - - // generate Diffie-Hellman parameters - // When short bit length is used, it might be wise to regenerate parameters often. - int dhBits = gnutls_sec_param_to_pk_bits(GNUTLS_PK_DH, GNUTLS_SEC_PARAM_LEGACY); - - _dhParams = new gnutls_dh_params_t; - gnutls_dh_params_init(_dhParams); - gnutls_dh_params_generate2(*_dhParams, dhBits); - - qDebug() << "Successfully generated Diffie-Hellman parameters."; - - // set the D-H paramters on the X509 credentials - gnutls_certificate_set_dh_params(*_x509Credentials, *_dhParams); - - // setup the key used for cookie verification - _cookieKey = new gnutls_datum_t; - gnutls_key_generate(_cookieKey, GNUTLS_COOKIE_KEY_SIZE); - - _priorityCache = new gnutls_priority_t; - const char DTLS_PRIORITY_STRING[] = "PERFORMANCE:-VERS-TLS-ALL:+VERS-DTLS1.2:%SERVER_PRECEDENCE"; - gnutls_priority_init(_priorityCache, DTLS_PRIORITY_STRING, NULL); - - _isUsingDTLS = true; - - qDebug() << "Initial DTLS setup complete."; - } - - return true; -} - void DomainServer::setupNodeListAndAssignments(const QUuid& sessionUUID) { const QString CUSTOM_PORT_OPTION = "port"; @@ -552,8 +491,8 @@ void DomainServer::sendDomainListToNode(const SharedNodePointer& node, const Hif if (nodeInterestList.size() > 0) { - DTLSServerSession* dtlsSession = _isUsingDTLS ? _dtlsSessions[senderSockAddr] : NULL; - int dataMTU = dtlsSession ? (int)gnutls_dtls_get_data_mtu(*dtlsSession->getGnuTLSSession()) : MAX_PACKET_SIZE; +// DTLSServerSession* dtlsSession = _isUsingDTLS ? _dtlsSessions[senderSockAddr] : NULL; + int dataMTU = MAX_PACKET_SIZE; if (nodeData->isAuthenticated()) { // if this authenticated node has any interest types, send back those nodes as well @@ -589,11 +528,7 @@ void DomainServer::sendDomainListToNode(const SharedNodePointer& node, const Hif // we need to break here and start a new packet // so send the current one - if (!dtlsSession) { - nodeList->writeDatagram(broadcastPacket, node, senderSockAddr); - } else { - dtlsSession->writeDatagram(broadcastPacket); - } + nodeList->writeDatagram(broadcastPacket, node, senderSockAddr); // reset the broadcastPacket structure broadcastPacket.resize(numBroadcastPacketLeadBytes); @@ -607,11 +542,7 @@ void DomainServer::sendDomainListToNode(const SharedNodePointer& node, const Hif } // always write the last broadcastPacket - if (!dtlsSession) { - nodeList->writeDatagram(broadcastPacket, node, senderSockAddr); - } else { - dtlsSession->writeDatagram(broadcastPacket); - } + nodeList->writeDatagram(broadcastPacket, node, senderSockAddr); } } @@ -689,86 +620,6 @@ void DomainServer::readAvailableDatagrams() { } } -void DomainServer::readAvailableDTLSDatagrams() { - LimitedNodeList* nodeList = LimitedNodeList::getInstance(); - - QUdpSocket& dtlsSocket = nodeList->getDTLSSocket(); - - static sockaddr senderSockAddr; - static socklen_t sockAddrSize = sizeof(senderSockAddr); - - while (dtlsSocket.hasPendingDatagrams()) { - // check if we have an active DTLS session for this sender - QByteArray peekDatagram(dtlsSocket.pendingDatagramSize(), 0); - - recvfrom(dtlsSocket.socketDescriptor(), peekDatagram.data(), dtlsSocket.pendingDatagramSize(), - MSG_PEEK, &senderSockAddr, &sockAddrSize); - - HifiSockAddr senderHifiSockAddr(&senderSockAddr); - DTLSServerSession* existingSession = _dtlsSessions.value(senderHifiSockAddr); - - if (existingSession) { - if (!existingSession->completedHandshake()) { - // check if we have completed handshake with this user - int handshakeReturn = gnutls_handshake(*existingSession->getGnuTLSSession()); - - if (handshakeReturn == 0) { - existingSession->setCompletedHandshake(true); - } else if (gnutls_error_is_fatal(handshakeReturn)) { - // this was a fatal error handshaking, so remove this session - qDebug() << "Fatal error -" << gnutls_strerror(handshakeReturn) << "- during DTLS handshake with" - << senderHifiSockAddr; - _dtlsSessions.remove(senderHifiSockAddr); - } - } else { - // pull the data from this user off the stack and process it - int receivedBytes = gnutls_record_recv(*existingSession->getGnuTLSSession(), - peekDatagram.data(), peekDatagram.size()); - if (receivedBytes > 0) { - processDatagram(peekDatagram.left(receivedBytes), senderHifiSockAddr); - } else if (gnutls_error_is_fatal(receivedBytes)) { - qDebug() << "Fatal error -" << gnutls_strerror(receivedBytes) << "- during DTLS handshake with" - << senderHifiSockAddr; - } - } - } else { - // first we verify the cookie - // see http://gnutls.org/manual/html_node/DTLS-sessions.html for why this is required - gnutls_dtls_prestate_st prestate; - memset(&prestate, 0, sizeof(prestate)); - int cookieValid = gnutls_dtls_cookie_verify(_cookieKey, &senderSockAddr, sizeof(senderSockAddr), - peekDatagram.data(), peekDatagram.size(), &prestate); - - if (cookieValid < 0) { - // the cookie sent by the client was not valid - // send a valid one - DummyDTLSSession tempServerSession(LimitedNodeList::getInstance()->getDTLSSocket(), senderHifiSockAddr); - - gnutls_dtls_cookie_send(_cookieKey, &senderSockAddr, sizeof(senderSockAddr), &prestate, - &tempServerSession, DTLSSession::socketPush); - - // acutally pull the peeked data off the network stack so that it gets discarded - dtlsSocket.readDatagram(peekDatagram.data(), peekDatagram.size()); - } else { - // cookie valid but no existing session - set up a new session now - DTLSServerSession* newServerSession = new DTLSServerSession(LimitedNodeList::getInstance()->getDTLSSocket(), - senderHifiSockAddr); - gnutls_session_t* gnutlsSession = newServerSession->getGnuTLSSession(); - - gnutls_priority_set(*gnutlsSession, *_priorityCache); - gnutls_credentials_set(*gnutlsSession, GNUTLS_CRD_CERTIFICATE, *_x509Credentials); - gnutls_dtls_prestate_set(*gnutlsSession, &prestate); - - // handshake to begin the session - gnutls_handshake(*gnutlsSession); - - qDebug() << "Beginning DTLS session with node at" << senderHifiSockAddr; - _dtlsSessions[senderHifiSockAddr] = newServerSession; - } - } - } -} - void DomainServer::processDatagram(const QByteArray& receivedPacket, const HifiSockAddr& senderSockAddr) { LimitedNodeList* nodeList = LimitedNodeList::getInstance(); @@ -1210,14 +1061,6 @@ void DomainServer::nodeKilled(SharedNodePointer node) { reinterpret_cast(otherNode->getLinkedData())->getSessionSecretHash().remove(node->getUUID()); } } - - if (_isUsingDTLS) { - // check if we need to remove a DTLS session from our in-memory hash - DTLSServerSession* existingSession = _dtlsSessions.take(nodeData->getSendingSockAddr()); - if (existingSession) { - delete existingSession; - } - } } } diff --git a/domain-server/src/DomainServer.h b/domain-server/src/DomainServer.h index 4c0f9447ea..32d53281f1 100644 --- a/domain-server/src/DomainServer.h +++ b/domain-server/src/DomainServer.h @@ -26,15 +26,12 @@ #include #include -#include "DTLSServerSession.h" - typedef QSharedPointer SharedAssignmentPointer; class DomainServer : public QCoreApplication, public HTTPSRequestHandler { Q_OBJECT public: DomainServer(int argc, char* argv[]); - ~DomainServer(); bool handleHTTPRequest(HTTPConnection* connection, const QUrl& url); bool handleHTTPSRequest(HTTPSConnection* connection, const QUrl& url); @@ -50,11 +47,9 @@ public slots: private slots: void readAvailableDatagrams(); - void readAvailableDTLSDatagrams(); private: void setupNodeListAndAssignments(const QUuid& sessionUUID = QUuid::createUuid()); bool optionallySetupOAuth(); - bool optionallySetupDTLS(); bool optionallyReadX509KeyAndCertificate(); void processDatagram(const QByteArray& receivedPacket, const HifiSockAddr& senderSockAddr); @@ -96,12 +91,6 @@ private: QVariantMap _argumentVariantMap; bool _isUsingDTLS; - gnutls_certificate_credentials_t* _x509Credentials; - gnutls_dh_params_t* _dhParams; - gnutls_datum_t* _cookieKey; - gnutls_priority_t* _priorityCache; - - QHash _dtlsSessions; QNetworkAccessManager* _networkAccessManager; diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 487965b3ec..47ad9af638 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -173,10 +173,7 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : _previousScriptLocation(), _runningScriptsWidget(new RunningScriptsWidget(_window)), _runningScriptsWidgetWasVisible(false) -{ - // init GnuTLS for DTLS with domain-servers - DTLSClientSession::globalInit(); - +{ // read the ApplicationInfo.ini file for Name/Version/Domain information QSettings applicationInfo(Application::resourcesPath() + "info/ApplicationInfo.ini", QSettings::IniFormat); @@ -431,8 +428,6 @@ Application::~Application() { delete _glWidget; AccountManager::getInstance().destroy(); - - DTLSClientSession::globalDeinit(); } void Application::saveSettings() { diff --git a/interface/src/ui/OAuthWebViewHandler.cpp b/interface/src/ui/OAuthWebViewHandler.cpp index 83d900cd5c..e93321212c 100644 --- a/interface/src/ui/OAuthWebViewHandler.cpp +++ b/interface/src/ui/OAuthWebViewHandler.cpp @@ -28,12 +28,35 @@ OAuthWebViewHandler::OAuthWebViewHandler() : } +const char HIGH_FIDELITY_CA[] = "-----BEGIN CERTIFICATE-----\n" + "MIID6TCCA1KgAwIBAgIJANlfRkRD9A8bMA0GCSqGSIb3DQEBBQUAMIGqMQswCQYD\n" + "VQQGEwJVUzETMBEGA1UECBMKQ2FsaWZvcm5pYTEWMBQGA1UEBxMNU2FuIEZyYW5j\n" + "aXNjbzEbMBkGA1UEChMSSGlnaCBGaWRlbGl0eSwgSW5jMRMwEQYDVQQLEwpPcGVy\n" + "YXRpb25zMRgwFgYDVQQDEw9oaWdoZmlkZWxpdHkuaW8xIjAgBgkqhkiG9w0BCQEW\n" + "E29wc0BoaWdoZmlkZWxpdHkuaW8wHhcNMTQwMzI4MjIzMzM1WhcNMjQwMzI1MjIz\n" + "MzM1WjCBqjELMAkGA1UEBhMCVVMxEzARBgNVBAgTCkNhbGlmb3JuaWExFjAUBgNV\n" + "BAcTDVNhbiBGcmFuY2lzY28xGzAZBgNVBAoTEkhpZ2ggRmlkZWxpdHksIEluYzET\n" + "MBEGA1UECxMKT3BlcmF0aW9uczEYMBYGA1UEAxMPaGlnaGZpZGVsaXR5LmlvMSIw\n" + "IAYJKoZIhvcNAQkBFhNvcHNAaGlnaGZpZGVsaXR5LmlvMIGfMA0GCSqGSIb3DQEB\n" + "AQUAA4GNADCBiQKBgQDyo1euYiPPEdnvDZnIjWrrP230qUKMSj8SWoIkbTJF2hE8\n" + "2eP3YOgbgSGBzZ8EJBxIOuNmj9g9Eg6691hIKFqy5W0BXO38P04Gg+pVBvpHFGBi\n" + "wpqGbfsjaUDuYmBeJRcMO0XYkLCRQG+lAQNHoFDdItWAJfC3FwtP3OCDnz8cNwID\n" + "AQABo4IBEzCCAQ8wHQYDVR0OBBYEFCSv2kmiGg6VFMnxXzLDNP304cPAMIHfBgNV\n" + "HSMEgdcwgdSAFCSv2kmiGg6VFMnxXzLDNP304cPAoYGwpIGtMIGqMQswCQYDVQQG\n" + "EwJVUzETMBEGA1UECBMKQ2FsaWZvcm5pYTEWMBQGA1UEBxMNU2FuIEZyYW5jaXNj\n" + "bzEbMBkGA1UEChMSSGlnaCBGaWRlbGl0eSwgSW5jMRMwEQYDVQQLEwpPcGVyYXRp\n" + "b25zMRgwFgYDVQQDEw9oaWdoZmlkZWxpdHkuaW8xIjAgBgkqhkiG9w0BCQEWE29w\n" + "c0BoaWdoZmlkZWxpdHkuaW+CCQDZX0ZEQ/QPGzAMBgNVHRMEBTADAQH/MA0GCSqG\n" + "SIb3DQEBBQUAA4GBAEkQl3p+lH5vuoCNgyfa67nL0MsBEt+5RSBOgjwCjjASjzou\n" + "FTv5w0he2OypgMQb8i/BYtS1lJSFqjPJcSM1Salzrm3xDOK5pOXJ7h6SQLPDVEyf\n" + "Hy2/9d/to+99+SOUlvfzfgycgjOc+s/AV7Y+GBd7uzGxUdrN4egCZW1F6/mH\n" + "-----END CERTIFICATE-----\n"; + void OAuthWebViewHandler::addHighFidelityRootCAToSSLConfig() { QSslConfiguration sslConfig = QSslConfiguration::defaultConfiguration(); // add the High Fidelity root CA to the list of trusted CA certificates - QByteArray highFidelityCACertificate(reinterpret_cast(DTLSSession::highFidelityCADatum()->data), - DTLSSession::highFidelityCADatum()->size); + QByteArray highFidelityCACertificate(HIGH_FIDELITY_CA, sizeof(HIGH_FIDELITY_CA)); sslConfig.setCaCertificates(sslConfig.caCertificates() + QSslCertificate::fromData(highFidelityCACertificate)); // set the modified configuration diff --git a/libraries/networking/src/DTLSClientSession.cpp b/libraries/networking/src/DTLSClientSession.cpp deleted file mode 100644 index 72384fbd10..0000000000 --- a/libraries/networking/src/DTLSClientSession.cpp +++ /dev/null @@ -1,83 +0,0 @@ -// -// DTLSClientSession.cpp -// libraries/networking/src -// -// Created by Stephen Birarda on 2014-04-01. -// 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 -// - -#include "DomainHandler.h" - -#include "DTLSClientSession.h" - -gnutls_certificate_credentials_t DTLSClientSession::_x509CACredentials; - -void DTLSClientSession::globalInit() { - static bool initialized = false; - - if (!initialized) { - gnutls_global_init(); - gnutls_certificate_allocate_credentials(&_x509CACredentials); - - gnutls_certificate_set_x509_trust_mem(_x509CACredentials, DTLSSession::highFidelityCADatum(), GNUTLS_X509_FMT_PEM); - gnutls_certificate_set_verify_function(_x509CACredentials, DTLSClientSession::verifyServerCertificate); - } -} - -void DTLSClientSession::globalDeinit() { - gnutls_certificate_free_credentials(_x509CACredentials); - - gnutls_global_deinit(); -} - -int DTLSClientSession::verifyServerCertificate(gnutls_session_t session) { - unsigned int verifyStatus = 0; - - // grab the hostname from the domain handler that this session is associated with - DomainHandler* domainHandler = reinterpret_cast(gnutls_session_get_ptr(session)); - qDebug() << "Checking for" << domainHandler->getHostname() << "from cert."; - - int certReturn = gnutls_certificate_verify_peers3(session, - domainHandler->getHostname().toLocal8Bit().constData(), - &verifyStatus); - - if (certReturn < 0) { - return GNUTLS_E_CERTIFICATE_ERROR; - } - - gnutls_certificate_type_t typeReturn = gnutls_certificate_type_get(session); - - gnutls_datum_t printOut; - - certReturn = gnutls_certificate_verification_status_print(verifyStatus, typeReturn, &printOut, 0); - - if (certReturn < 0) { - return GNUTLS_E_CERTIFICATE_ERROR; - } - - qDebug() << "Gnutls certificate verification status:" << reinterpret_cast(printOut.data); - -#ifdef WIN32 - free(printOut.data); -#else - gnutls_free(printOut.data); -#endif - - if (verifyStatus != 0) { - qDebug() << "Server provided certificate for DTLS is not trusted. Can not complete handshake."; - return GNUTLS_E_CERTIFICATE_ERROR; - } else { - // certificate is valid, continue handshaking as normal - return 0; - } -} - -DTLSClientSession::DTLSClientSession(QUdpSocket& dtlsSocket, HifiSockAddr& destinationSocket) : - DTLSSession(GNUTLS_CLIENT, dtlsSocket, destinationSocket) -{ - gnutls_priority_set_direct(_gnutlsSession, "PERFORMANCE", NULL); - gnutls_credentials_set(_gnutlsSession, GNUTLS_CRD_CERTIFICATE, _x509CACredentials); -} \ No newline at end of file diff --git a/libraries/networking/src/DTLSClientSession.h b/libraries/networking/src/DTLSClientSession.h deleted file mode 100644 index eeca1aaa68..0000000000 --- a/libraries/networking/src/DTLSClientSession.h +++ /dev/null @@ -1,30 +0,0 @@ -// -// DTLSClientSession.h -// libraries/networking/src -// -// Created by Stephen Birarda on 2014-04-01. -// 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 -// - -#ifndef hifi_DTLSClientSession_h -#define hifi_DTLSClientSession_h - -#include "DTLSSession.h" - -class DTLSClientSession : public DTLSSession { -public: - DTLSClientSession(QUdpSocket& dtlsSocket, HifiSockAddr& destinationSocket); - - static void globalInit(); - static void globalDeinit(); - - static int verifyServerCertificate(gnutls_session_t session); - - static gnutls_certificate_credentials_t _x509CACredentials; - static bool _wasGloballyInitialized; -}; - -#endif // hifi_DTLSClientSession_h diff --git a/libraries/networking/src/DTLSSession.cpp b/libraries/networking/src/DTLSSession.cpp deleted file mode 100644 index f0649e4fc8..0000000000 --- a/libraries/networking/src/DTLSSession.cpp +++ /dev/null @@ -1,145 +0,0 @@ -// -// DTLSSession.cpp -// libraries/networking/src -// -// Created by Stephen Birarda on 2014-04-01. -// 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 -// - -#include - -#include "NodeList.h" -#include "DTLSSession.h" - -int DTLSSession::socketPullTimeout(gnutls_transport_ptr_t ptr, unsigned int ms) { - DTLSSession* session = static_cast(ptr); - QUdpSocket& dtlsSocket = session->_dtlsSocket; - - if (dtlsSocket.hasPendingDatagrams()) { - // peek the data on stack to see if it belongs to this session - static sockaddr senderSockAddr; - static socklen_t sockAddrSize = sizeof(senderSockAddr); - - QByteArray peekDatagram(dtlsSocket.pendingDatagramSize(), 0); - - recvfrom(dtlsSocket.socketDescriptor(), peekDatagram.data(), dtlsSocket.pendingDatagramSize(), - MSG_PEEK, &senderSockAddr, &sockAddrSize); - - if (HifiSockAddr(&senderSockAddr) == session->_destinationSocket) { - // there is data for this session ready to be read - return 1; - } else { - // the next data from the dtlsSocket is not for this session - return 0; - } - } else { - // no data available on the dtlsSocket - return 0; - } -} - -ssize_t DTLSSession::socketPull(gnutls_transport_ptr_t ptr, void* buffer, size_t size) { - DTLSSession* session = static_cast(ptr); - QUdpSocket& dtlsSocket = session->_dtlsSocket; - - HifiSockAddr pulledSockAddr; - qint64 bytesReceived = dtlsSocket.readDatagram(reinterpret_cast(buffer), size, - pulledSockAddr.getAddressPointer(), pulledSockAddr.getPortPointer()); - if (bytesReceived == -1) { - // no data to pull, return -1 -#if DTLS_VERBOSE_DEBUG - qDebug() << "Received no data on call to readDatagram"; -#endif - return bytesReceived; - } - - if (pulledSockAddr == session->_destinationSocket) { - // bytes received from the correct sender, return number of bytes received - -#if DTLS_VERBOSE_DEBUG - qDebug() << "Received" << bytesReceived << "on DTLS socket from" << pulledSockAddr; -#endif - - return bytesReceived; - } - - // we pulled a packet not matching this session, so output that - qDebug() << "Denied connection from" << pulledSockAddr; - - gnutls_transport_set_errno(session->_gnutlsSession, GNUTLS_E_AGAIN); - return -1; -} - -gnutls_datum_t* DTLSSession::highFidelityCADatum() { - static gnutls_datum_t hifiCADatum; - static bool datumInitialized = false; - - static unsigned char HIGHFIDELITY_ROOT_CA_CERT[] = - "-----BEGIN CERTIFICATE-----\n" - "MIID6TCCA1KgAwIBAgIJANlfRkRD9A8bMA0GCSqGSIb3DQEBBQUAMIGqMQswCQYD\n" - "VQQGEwJVUzETMBEGA1UECBMKQ2FsaWZvcm5pYTEWMBQGA1UEBxMNU2FuIEZyYW5j\n" - "aXNjbzEbMBkGA1UEChMSSGlnaCBGaWRlbGl0eSwgSW5jMRMwEQYDVQQLEwpPcGVy\n" - "YXRpb25zMRgwFgYDVQQDEw9oaWdoZmlkZWxpdHkuaW8xIjAgBgkqhkiG9w0BCQEW\n" - "E29wc0BoaWdoZmlkZWxpdHkuaW8wHhcNMTQwMzI4MjIzMzM1WhcNMjQwMzI1MjIz\n" - "MzM1WjCBqjELMAkGA1UEBhMCVVMxEzARBgNVBAgTCkNhbGlmb3JuaWExFjAUBgNV\n" - "BAcTDVNhbiBGcmFuY2lzY28xGzAZBgNVBAoTEkhpZ2ggRmlkZWxpdHksIEluYzET\n" - "MBEGA1UECxMKT3BlcmF0aW9uczEYMBYGA1UEAxMPaGlnaGZpZGVsaXR5LmlvMSIw\n" - "IAYJKoZIhvcNAQkBFhNvcHNAaGlnaGZpZGVsaXR5LmlvMIGfMA0GCSqGSIb3DQEB\n" - "AQUAA4GNADCBiQKBgQDyo1euYiPPEdnvDZnIjWrrP230qUKMSj8SWoIkbTJF2hE8\n" - "2eP3YOgbgSGBzZ8EJBxIOuNmj9g9Eg6691hIKFqy5W0BXO38P04Gg+pVBvpHFGBi\n" - "wpqGbfsjaUDuYmBeJRcMO0XYkLCRQG+lAQNHoFDdItWAJfC3FwtP3OCDnz8cNwID\n" - "AQABo4IBEzCCAQ8wHQYDVR0OBBYEFCSv2kmiGg6VFMnxXzLDNP304cPAMIHfBgNV\n" - "HSMEgdcwgdSAFCSv2kmiGg6VFMnxXzLDNP304cPAoYGwpIGtMIGqMQswCQYDVQQG\n" - "EwJVUzETMBEGA1UECBMKQ2FsaWZvcm5pYTEWMBQGA1UEBxMNU2FuIEZyYW5jaXNj\n" - "bzEbMBkGA1UEChMSSGlnaCBGaWRlbGl0eSwgSW5jMRMwEQYDVQQLEwpPcGVyYXRp\n" - "b25zMRgwFgYDVQQDEw9oaWdoZmlkZWxpdHkuaW8xIjAgBgkqhkiG9w0BCQEWE29w\n" - "c0BoaWdoZmlkZWxpdHkuaW+CCQDZX0ZEQ/QPGzAMBgNVHRMEBTADAQH/MA0GCSqG\n" - "SIb3DQEBBQUAA4GBAEkQl3p+lH5vuoCNgyfa67nL0MsBEt+5RSBOgjwCjjASjzou\n" - "FTv5w0he2OypgMQb8i/BYtS1lJSFqjPJcSM1Salzrm3xDOK5pOXJ7h6SQLPDVEyf\n" - "Hy2/9d/to+99+SOUlvfzfgycgjOc+s/AV7Y+GBd7uzGxUdrN4egCZW1F6/mH\n" - "-----END CERTIFICATE-----\n"; - - if (!datumInitialized) { - hifiCADatum.data = HIGHFIDELITY_ROOT_CA_CERT; - hifiCADatum.size = sizeof(HIGHFIDELITY_ROOT_CA_CERT); - } - - return &hifiCADatum; -} - -DTLSSession::DTLSSession(int end, QUdpSocket& dtlsSocket, HifiSockAddr& destinationSocket) : - DummyDTLSSession(dtlsSocket, destinationSocket), - _completedHandshake(false) -{ - gnutls_init(&_gnutlsSession, end | GNUTLS_DATAGRAM | GNUTLS_NONBLOCK); - - // see http://gnutls.org/manual/html_node/Datagram-TLS-API.html#gnutls_005fdtls_005fset_005fmtu - const unsigned int DTLS_MAX_MTU = 1452; - gnutls_dtls_set_mtu(_gnutlsSession, DTLS_MAX_MTU); - - const unsigned int DTLS_HANDSHAKE_RETRANSMISSION_TIMEOUT = DOMAIN_SERVER_CHECK_IN_MSECS; - const unsigned int DTLS_TOTAL_CONNECTION_TIMEOUT = 2 * NODE_SILENCE_THRESHOLD_MSECS; - gnutls_dtls_set_timeouts(_gnutlsSession, DTLS_HANDSHAKE_RETRANSMISSION_TIMEOUT, DTLS_TOTAL_CONNECTION_TIMEOUT); - - gnutls_transport_set_ptr(_gnutlsSession, this); - gnutls_transport_set_push_function(_gnutlsSession, DummyDTLSSession::socketPush); - gnutls_transport_set_pull_function(_gnutlsSession, socketPull); - gnutls_transport_set_pull_timeout_function(_gnutlsSession, socketPullTimeout); -} - -DTLSSession::~DTLSSession() { - gnutls_deinit(_gnutlsSession); -} - -void DTLSSession::setCompletedHandshake(bool completedHandshake) { - _completedHandshake = completedHandshake; - qDebug() << "Completed DTLS handshake with" << _destinationSocket; -} - -qint64 DTLSSession::writeDatagram(const QByteArray& datagram) { - // we don't need to put a hash in this packet, so just send it off - return gnutls_record_send(_gnutlsSession, datagram.data(), datagram.size()); -} \ No newline at end of file diff --git a/libraries/networking/src/DTLSSession.h b/libraries/networking/src/DTLSSession.h deleted file mode 100644 index 9e9542e147..0000000000 --- a/libraries/networking/src/DTLSSession.h +++ /dev/null @@ -1,44 +0,0 @@ -// -// DTLSSession.h -// libraries/networking/src -// -// Created by Stephen Birarda on 2014-04-01. -// 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 -// - -#ifndef hifi_DTLSSession_h -#define hifi_DTLSSession_h - -#include - -#include - -#include "DummyDTLSSession.h" -#include "HifiSockAddr.h" - -class DTLSSession : public DummyDTLSSession { - Q_OBJECT -public: - DTLSSession(int end, QUdpSocket& dtlsSocket, HifiSockAddr& destinationSocket); - ~DTLSSession(); - - static int socketPullTimeout(gnutls_transport_ptr_t ptr, unsigned int ms); - static ssize_t socketPull(gnutls_transport_ptr_t ptr, void* buffer, size_t size); - - static gnutls_datum_t* highFidelityCADatum(); - - qint64 writeDatagram(const QByteArray& datagram); - - gnutls_session_t* getGnuTLSSession() { return &_gnutlsSession; } - - bool completedHandshake() const { return _completedHandshake; } - void setCompletedHandshake(bool completedHandshake); -protected: - gnutls_session_t _gnutlsSession; - bool _completedHandshake; -}; - -#endif // hifi_DTLSSession_h diff --git a/libraries/networking/src/DomainHandler.cpp b/libraries/networking/src/DomainHandler.cpp index 6c2fb0274a..859af50070 100644 --- a/libraries/networking/src/DomainHandler.cpp +++ b/libraries/networking/src/DomainHandler.cpp @@ -22,16 +22,11 @@ DomainHandler::DomainHandler(QObject* parent) : _sockAddr(HifiSockAddr(QHostAddress::Null, DEFAULT_DOMAIN_SERVER_PORT)), _assignmentUUID(), _isConnected(false), - _dtlsSession(NULL), _handshakeTimer(NULL) { } -DomainHandler::~DomainHandler() { - delete _dtlsSession; -} - void DomainHandler::clearConnectionInfo() { _uuid = QUuid(); _isConnected = false; @@ -41,38 +36,12 @@ void DomainHandler::clearConnectionInfo() { delete _handshakeTimer; _handshakeTimer = NULL; } - - delete _dtlsSession; - _dtlsSession = NULL; } void DomainHandler::reset() { clearConnectionInfo(); _hostname = QString(); _sockAddr.setAddress(QHostAddress::Null); - - delete _dtlsSession; - _dtlsSession = NULL; -} - -const unsigned int DTLS_HANDSHAKE_INTERVAL_MSECS = 100; - -void DomainHandler::initializeDTLSSession() { - if (!_dtlsSession) { - _dtlsSession = new DTLSClientSession(NodeList::getInstance()->getDTLSSocket(), _sockAddr); - - gnutls_session_set_ptr(*_dtlsSession->getGnuTLSSession(), this); - - // start a timer to complete the handshake process - _handshakeTimer = new QTimer(this); - connect(_handshakeTimer, &QTimer::timeout, this, &DomainHandler::completeDTLSHandshake); - - // start the handshake right now - completeDTLSHandshake(); - - // start the timer to finish off the handshake - _handshakeTimer->start(DTLS_HANDSHAKE_INTERVAL_MSECS); - } } void DomainHandler::setSockAddr(const HifiSockAddr& sockAddr, const QString& hostname) { @@ -120,30 +89,6 @@ void DomainHandler::setHostname(const QString& hostname) { } } -void DomainHandler::completeDTLSHandshake() { - int handshakeReturn = gnutls_handshake(*_dtlsSession->getGnuTLSSession()); - - if (handshakeReturn == 0) { - // we've shaken hands, so we're good to go now - _dtlsSession->setCompletedHandshake(true); - - _handshakeTimer->stop(); - delete _handshakeTimer; - _handshakeTimer = NULL; - - // emit a signal so NodeList can handle incoming DTLS packets - emit completedDTLSHandshake(); - - } else if (gnutls_error_is_fatal(handshakeReturn)) { - // this was a fatal error handshaking, so remove this session - qDebug() << "Fatal error -" << gnutls_strerror(handshakeReturn) - << "- during DTLS handshake with DS at" - << qPrintable((_hostname.isEmpty() ? _sockAddr.getAddress().toString() : _hostname)); - - clearConnectionInfo(); - } -} - void DomainHandler::completedHostnameLookup(const QHostInfo& hostInfo) { for (int i = 0; i < hostInfo.addresses().size(); i++) { if (hostInfo.addresses()[i].protocol() == QAbstractSocket::IPv4Protocol) { @@ -179,5 +124,5 @@ void DomainHandler::parseDTLSRequirementPacket(const QByteArray& dtlsRequirement _sockAddr.setPort(dtlsPort); - initializeDTLSSession(); +// initializeDTLSSession(); } \ No newline at end of file diff --git a/libraries/networking/src/DomainHandler.h b/libraries/networking/src/DomainHandler.h index 599f6d4a0f..782332f06a 100644 --- a/libraries/networking/src/DomainHandler.h +++ b/libraries/networking/src/DomainHandler.h @@ -18,7 +18,6 @@ #include #include -#include "DTLSClientSession.h" #include "HifiSockAddr.h" const QString DEFAULT_DOMAIN_HOSTNAME = "sandbox.highfidelity.io"; @@ -32,7 +31,6 @@ class DomainHandler : public QObject { Q_OBJECT public: DomainHandler(QObject* parent = 0); - ~DomainHandler(); void clearConnectionInfo(); @@ -56,29 +54,22 @@ public: bool isConnected() const { return _isConnected; } void setIsConnected(bool isConnected); - DTLSClientSession* getDTLSSession() { return _dtlsSession; } - void parseDTLSRequirementPacket(const QByteArray& dtlsRequirementPacket); private slots: - void completeDTLSHandshake(); void completedHostnameLookup(const QHostInfo& hostInfo); signals: void hostnameChanged(const QString& hostname); void connectedToDomain(const QString& hostname); - void completedDTLSHandshake(); - void DTLSConnectionLost(); private: void reset(); - void initializeDTLSSession(); QUuid _uuid; QString _hostname; HifiSockAddr _sockAddr; QUuid _assignmentUUID; bool _isConnected; - DTLSClientSession* _dtlsSession; QTimer* _handshakeTimer; }; diff --git a/libraries/networking/src/DummyDTLSSession.cpp b/libraries/networking/src/DummyDTLSSession.cpp deleted file mode 100644 index a42e3f1599..0000000000 --- a/libraries/networking/src/DummyDTLSSession.cpp +++ /dev/null @@ -1,31 +0,0 @@ -// -// DummyDTLSSession.cpp -// libraries/networking/src -// -// Created by Stephen Birarda on 2014-04-04. -// 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 -// - -#include "DummyDTLSSession.h" - -ssize_t DummyDTLSSession::socketPush(gnutls_transport_ptr_t ptr, const void* buffer, size_t size) { - DummyDTLSSession* session = static_cast(ptr); - QUdpSocket& dtlsSocket = session->_dtlsSocket; - -#if DTLS_VERBOSE_DEBUG - qDebug() << "Pushing a message of size" << size << "to" << session->_destinationSocket; -#endif - - return dtlsSocket.writeDatagram(reinterpret_cast(buffer), size, - session->_destinationSocket.getAddress(), session->_destinationSocket.getPort()); -} - -DummyDTLSSession::DummyDTLSSession(QUdpSocket& dtlsSocket, const HifiSockAddr& destinationSocket) : - _dtlsSocket(dtlsSocket), - _destinationSocket(destinationSocket) -{ - -} \ No newline at end of file diff --git a/libraries/networking/src/DummyDTLSSession.h b/libraries/networking/src/DummyDTLSSession.h deleted file mode 100644 index 352b2c23e2..0000000000 --- a/libraries/networking/src/DummyDTLSSession.h +++ /dev/null @@ -1,34 +0,0 @@ -// -// DummyDTLSSession.h -// libraries/networking/src -// -// Created by Stephen Birarda on 2014-04-04. -// 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 -// - -#ifndef hifi_DummyDTLSSession_h -#define hifi_DummyDTLSSession_h - -#include - -#include - -#include "HifiSockAddr.h" - -#define DTLS_VERBOSE_DEBUG 0 - -class DummyDTLSSession : public QObject { - Q_OBJECT -public: - DummyDTLSSession(QUdpSocket& dtlsSocket, const HifiSockAddr& destinationSocket); - - static ssize_t socketPush(gnutls_transport_ptr_t ptr, const void* buffer, size_t size); -protected: - QUdpSocket& _dtlsSocket; - HifiSockAddr _destinationSocket; -}; - -#endif // hifi_DummyDTLSSession_h diff --git a/libraries/networking/src/NodeList.cpp b/libraries/networking/src/NodeList.cpp index e3d113a1b5..eea9845f16 100644 --- a/libraries/networking/src/NodeList.cpp +++ b/libraries/networking/src/NodeList.cpp @@ -68,9 +68,6 @@ NodeList::NodeList(char newOwnerType, unsigned short socketListenPort, unsigned // clear our NodeList when logout is requested connect(&AccountManager::getInstance(), &AccountManager::logoutComplete , this, &NodeList::reset); - - // perform a function when DTLS handshake is completed - connect(&_domainHandler, &DomainHandler::completedDTLSHandshake, this, &NodeList::completedDTLSHandshake); } qint64 NodeList::sendStatsToDomainServer(const QJsonObject& statsObject) { @@ -117,30 +114,6 @@ void NodeList::timePingReply(const QByteArray& packet, const SharedNodePointer& } } -void NodeList::completedDTLSHandshake() { - // at this point, we've got a DTLS socket - // make this NodeList the handler of DTLS packets - connect(_dtlsSocket, &QUdpSocket::readyRead, this, &NodeList::processAvailableDTLSDatagrams); -} - -void NodeList::processAvailableDTLSDatagrams() { - while (_dtlsSocket->hasPendingDatagrams()) { - QByteArray dtlsPacket(_dtlsSocket->pendingDatagramSize(), 0); - - // pull the data from this user off the stack and process it - int receivedBytes = gnutls_record_recv(*_domainHandler.getDTLSSession()->getGnuTLSSession(), - dtlsPacket.data(), dtlsPacket.size()); - if (receivedBytes > 0) { - // successful data receive, hand this off to processNodeData - processNodeData(_domainHandler.getSockAddr(), dtlsPacket.left(receivedBytes)); - } else if (gnutls_error_is_fatal(receivedBytes)) { - qDebug() << "Fatal error -" << gnutls_strerror(receivedBytes) << "- receiving DTLS packet from domain-server."; - } else { - qDebug() << "non fatal receive" << receivedBytes; - } - } -} - void NodeList::processNodeData(const HifiSockAddr& senderSockAddr, const QByteArray& packet) { switch (packetTypeForPacket(packet)) { case PacketTypeDomainList: { @@ -365,19 +338,9 @@ void NodeList::sendDomainServerCheckIn() { // send a STUN request to figure it out sendSTUNRequest(); } else if (!_domainHandler.getIP().isNull()) { - - DTLSClientSession* dtlsSession = _domainHandler.getDTLSSession(); + bool isUsingDTLS = false; - if (dtlsSession) { - if (!dtlsSession->completedHandshake()) { - // if the handshake process is not complete then we can't check in, so return - return; - } else { - isUsingDTLS = true; - } - } - PacketType domainPacketType = !_domainHandler.isConnected() ? PacketTypeDomainConnectRequest : PacketTypeDomainListRequest; @@ -405,8 +368,6 @@ void NodeList::sendDomainServerCheckIn() { if (!isUsingDTLS) { writeDatagram(domainServerPacket, _domainHandler.getSockAddr(), QUuid()); - } else { - dtlsSession->writeDatagram(domainServerPacket); } const int NUM_DOMAIN_SERVER_CHECKINS_PER_STUN_REQUEST = 5; diff --git a/libraries/networking/src/NodeList.h b/libraries/networking/src/NodeList.h index c55f08e7f0..c1d5189c6d 100644 --- a/libraries/networking/src/NodeList.h +++ b/libraries/networking/src/NodeList.h @@ -83,8 +83,6 @@ public slots: void reset(); void sendDomainServerCheckIn(); void pingInactiveNodes(); - void completedDTLSHandshake(); - void processAvailableDTLSDatagrams(); signals: void limitOfSilentDomainCheckInsReached(); private: From f22aaf21d2b252790676c2d412c6fe5c24649abc Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Tue, 20 May 2014 10:56:34 -0700 Subject: [PATCH 58/60] remove GnuTLS include across repo --- domain-server/src/DomainServer.cpp | 2 -- libraries/networking/src/DomainHandler.cpp | 2 -- libraries/networking/src/NodeList.cpp | 2 -- 3 files changed, 6 deletions(-) diff --git a/domain-server/src/DomainServer.cpp b/domain-server/src/DomainServer.cpp index fa8a26b259..f6af63fd7a 100644 --- a/domain-server/src/DomainServer.cpp +++ b/domain-server/src/DomainServer.cpp @@ -18,8 +18,6 @@ #include #include -#include - #include #include #include diff --git a/libraries/networking/src/DomainHandler.cpp b/libraries/networking/src/DomainHandler.cpp index 859af50070..95689f8e82 100644 --- a/libraries/networking/src/DomainHandler.cpp +++ b/libraries/networking/src/DomainHandler.cpp @@ -9,8 +9,6 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -#include - #include "NodeList.h" #include "PacketHeaders.h" diff --git a/libraries/networking/src/NodeList.cpp b/libraries/networking/src/NodeList.cpp index eea9845f16..ebd33ef132 100644 --- a/libraries/networking/src/NodeList.cpp +++ b/libraries/networking/src/NodeList.cpp @@ -15,8 +15,6 @@ #include #include -#include - #include "AccountManager.h" #include "Assignment.h" #include "HifiSockAddr.h" From 2ef822d19d195445f983de564e84bf36a039a90a Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Tue, 20 May 2014 11:26:20 -0700 Subject: [PATCH 59/60] remove more gnutls includes --- assignment-client/src/AssignmentClient.cpp | 2 -- domain-server/src/DomainServer.h | 2 -- libraries/networking/src/LimitedNodeList.h | 2 -- libraries/networking/src/NodeList.h | 2 -- 4 files changed, 8 deletions(-) diff --git a/assignment-client/src/AssignmentClient.cpp b/assignment-client/src/AssignmentClient.cpp index d8383ccd48..b3a92f2f54 100644 --- a/assignment-client/src/AssignmentClient.cpp +++ b/assignment-client/src/AssignmentClient.cpp @@ -13,8 +13,6 @@ #include #include -#include - #include #include #include diff --git a/domain-server/src/DomainServer.h b/domain-server/src/DomainServer.h index 32d53281f1..71809d9e16 100644 --- a/domain-server/src/DomainServer.h +++ b/domain-server/src/DomainServer.h @@ -20,8 +20,6 @@ #include #include -#include - #include #include #include diff --git a/libraries/networking/src/LimitedNodeList.h b/libraries/networking/src/LimitedNodeList.h index 2a98dc536f..a4bc8022bf 100644 --- a/libraries/networking/src/LimitedNodeList.h +++ b/libraries/networking/src/LimitedNodeList.h @@ -27,8 +27,6 @@ #include #include -#include - #include "DomainHandler.h" #include "Node.h" diff --git a/libraries/networking/src/NodeList.h b/libraries/networking/src/NodeList.h index c1d5189c6d..af0bfeb368 100644 --- a/libraries/networking/src/NodeList.h +++ b/libraries/networking/src/NodeList.h @@ -27,8 +27,6 @@ #include #include -#include - #include "DomainHandler.h" #include "LimitedNodeList.h" #include "Node.h" From a9c2e3fe717673a0f3b3698a11236e622ca52b59 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Tue, 20 May 2014 11:56:06 -0700 Subject: [PATCH 60/60] put back ssize_t definition --- animation-server/CMakeLists.txt | 7 ++++++- assignment-client/CMakeLists.txt | 5 +++++ domain-server/CMakeLists.txt | 7 ++++++- interface/CMakeLists.txt | 3 +++ libraries/animation/CMakeLists.txt | 5 +++++ libraries/audio/CMakeLists.txt | 7 ++++++- libraries/avatars/CMakeLists.txt | 7 ++++++- libraries/fbx/CMakeLists.txt | 5 +++++ libraries/metavoxels/CMakeLists.txt | 7 ++++++- libraries/models/CMakeLists.txt | 7 ++++++- libraries/networking/CMakeLists.txt | 7 ++++++- libraries/octree/CMakeLists.txt | 7 ++++++- libraries/particles/CMakeLists.txt | 5 +++++ libraries/script-engine/CMakeLists.txt | 5 +++++ libraries/voxels/CMakeLists.txt | 7 ++++++- voxel-edit/CMakeLists.txt | 7 ++++++- 16 files changed, 88 insertions(+), 10 deletions(-) diff --git a/animation-server/CMakeLists.txt b/animation-server/CMakeLists.txt index d8fa8d97b2..42516d2f86 100644 --- a/animation-server/CMakeLists.txt +++ b/animation-server/CMakeLists.txt @@ -30,4 +30,9 @@ link_hifi_library(octree ${TARGET_NAME} "${ROOT_DIR}") link_hifi_library(voxels ${TARGET_NAME} "${ROOT_DIR}") # link the hifi networking library -link_hifi_library(networking ${TARGET_NAME} "${ROOT_DIR}") \ No newline at end of file +link_hifi_library(networking ${TARGET_NAME} "${ROOT_DIR}") + +# add a definition for ssize_t so that windows doesn't bail +if (WIN32) + add_definitions(-Dssize_t=long) +endif () \ No newline at end of file diff --git a/assignment-client/CMakeLists.txt b/assignment-client/CMakeLists.txt index a088c04ffb..873ae761ca 100644 --- a/assignment-client/CMakeLists.txt +++ b/assignment-client/CMakeLists.txt @@ -46,3 +46,8 @@ IF (WIN32) ENDIF(WIN32) target_link_libraries(${TARGET_NAME} Qt5::Network Qt5::Widgets Qt5::Script) + +# add a definition for ssize_t so that windows doesn't bail +if (WIN32) + add_definitions(-Dssize_t=long) +endif () \ No newline at end of file diff --git a/domain-server/CMakeLists.txt b/domain-server/CMakeLists.txt index d1f923f4d2..f9bbeb31fc 100644 --- a/domain-server/CMakeLists.txt +++ b/domain-server/CMakeLists.txt @@ -42,4 +42,9 @@ IF (WIN32) ENDIF(WIN32) # link QtNetwork -target_link_libraries(${TARGET_NAME} Qt5::Network) \ No newline at end of file +target_link_libraries(${TARGET_NAME} Qt5::Network) + +# add a definition for ssize_t so that windows doesn't bail +if (WIN32) + add_definitions(-Dssize_t=long) +endif () \ No newline at end of file diff --git a/interface/CMakeLists.txt b/interface/CMakeLists.txt index 67b993d6c9..cf203c41d9 100644 --- a/interface/CMakeLists.txt +++ b/interface/CMakeLists.txt @@ -285,6 +285,9 @@ else (APPLE) # we're using static GLEW, so define GLEW_STATIC add_definitions(-DGLEW_STATIC) + # add a definition for ssize_t so that windows doesn't bail + add_definitions(-Dssize_t=long) + target_link_libraries(${TARGET_NAME} "${GLEW_LIBRARY}" wsock32.lib opengl32.lib) endif() endif (APPLE) diff --git a/libraries/animation/CMakeLists.txt b/libraries/animation/CMakeLists.txt index 35ceb22395..1e33f50659 100644 --- a/libraries/animation/CMakeLists.txt +++ b/libraries/animation/CMakeLists.txt @@ -28,3 +28,8 @@ link_hifi_library(fbx ${TARGET_NAME} "${ROOT_DIR}") find_package(ZLIB) target_link_libraries(${TARGET_NAME} "${ZLIB_LIBRARIES}" Qt5::Widgets) + +# add a definition for ssize_t so that windows doesn't bail +if (WIN32) + add_definitions(-Dssize_t=long) +endif () \ No newline at end of file diff --git a/libraries/audio/CMakeLists.txt b/libraries/audio/CMakeLists.txt index 0bf0ba9904..60636ba051 100644 --- a/libraries/audio/CMakeLists.txt +++ b/libraries/audio/CMakeLists.txt @@ -21,4 +21,9 @@ include_glm(${TARGET_NAME} "${ROOT_DIR}") include(${MACRO_DIR}/LinkHifiLibrary.cmake) link_hifi_library(shared ${TARGET_NAME} "${ROOT_DIR}") -link_hifi_library(networking ${TARGET_NAME} "${ROOT_DIR}") \ No newline at end of file +link_hifi_library(networking ${TARGET_NAME} "${ROOT_DIR}") + +# add a definition for ssize_t so that windows doesn't bail +if (WIN32) + add_definitions(-Dssize_t=long) +endif () \ No newline at end of file diff --git a/libraries/avatars/CMakeLists.txt b/libraries/avatars/CMakeLists.txt index 9816282dda..fc398fc33d 100644 --- a/libraries/avatars/CMakeLists.txt +++ b/libraries/avatars/CMakeLists.txt @@ -28,4 +28,9 @@ link_hifi_library(octree ${TARGET_NAME} "${ROOT_DIR}") link_hifi_library(voxels ${TARGET_NAME} "${ROOT_DIR}") link_hifi_library(networking ${TARGET_NAME} "${ROOT_DIR}") -target_link_libraries(${TARGET_NAME} Qt5::Script) \ No newline at end of file +target_link_libraries(${TARGET_NAME} Qt5::Script) + +# add a definition for ssize_t so that windows doesn't bail +if (WIN32) + add_definitions(-Dssize_t=long) +endif () \ No newline at end of file diff --git a/libraries/fbx/CMakeLists.txt b/libraries/fbx/CMakeLists.txt index 9ce234bbd4..bc5ac3b3c4 100644 --- a/libraries/fbx/CMakeLists.txt +++ b/libraries/fbx/CMakeLists.txt @@ -29,3 +29,8 @@ find_package(ZLIB) include_directories(SYSTEM "${ZLIB_INCLUDE_DIRS}") target_link_libraries(${TARGET_NAME} "${ZLIB_LIBRARIES}" Qt5::Widgets) + +# add a definition for ssize_t so that windows doesn't bail +if (WIN32) + add_definitions(-Dssize_t=long) +endif () \ No newline at end of file diff --git a/libraries/metavoxels/CMakeLists.txt b/libraries/metavoxels/CMakeLists.txt index 7a8319815a..79c07c6c47 100644 --- a/libraries/metavoxels/CMakeLists.txt +++ b/libraries/metavoxels/CMakeLists.txt @@ -27,4 +27,9 @@ link_hifi_library(networking ${TARGET_NAME} "${ROOT_DIR}") include(${MACRO_DIR}/IncludeGLM.cmake) include_glm(${TARGET_NAME} "${ROOT_DIR}") -target_link_libraries(${TARGET_NAME} Qt5::Network Qt5::Widgets Qt5::Script) \ No newline at end of file +target_link_libraries(${TARGET_NAME} Qt5::Network Qt5::Widgets Qt5::Script) + +# add a definition for ssize_t so that windows doesn't bail +if (WIN32) + add_definitions(-Dssize_t=long) +endif () \ No newline at end of file diff --git a/libraries/models/CMakeLists.txt b/libraries/models/CMakeLists.txt index 7833349319..06578371cc 100644 --- a/libraries/models/CMakeLists.txt +++ b/libraries/models/CMakeLists.txt @@ -37,4 +37,9 @@ link_hifi_library(metavoxels ${TARGET_NAME} "${ROOT_DIR}") find_package(ZLIB) include_directories(SYSTEM "${ZLIB_INCLUDE_DIRS}") -target_link_libraries(${TARGET_NAME} "${ZLIB_LIBRARIES}" Qt5::Widgets) \ No newline at end of file +target_link_libraries(${TARGET_NAME} "${ZLIB_LIBRARIES}" Qt5::Widgets) + +# add a definition for ssize_t so that windows doesn't bail +if (WIN32) + add_definitions(-Dssize_t=long) +endif () \ No newline at end of file diff --git a/libraries/networking/CMakeLists.txt b/libraries/networking/CMakeLists.txt index f93ba2e5cf..fdd2d5830a 100644 --- a/libraries/networking/CMakeLists.txt +++ b/libraries/networking/CMakeLists.txt @@ -19,4 +19,9 @@ setup_hifi_library(${TARGET_NAME}) include(${MACRO_DIR}/IncludeGLM.cmake) include_glm(${TARGET_NAME} "${ROOT_DIR}") -target_link_libraries(${TARGET_NAME} Qt5::Network) \ No newline at end of file +target_link_libraries(${TARGET_NAME} Qt5::Network) + +# add a definition for ssize_t so that windows doesn't bail +if (WIN32) + add_definitions(-Dssize_t=long) +endif () \ No newline at end of file diff --git a/libraries/octree/CMakeLists.txt b/libraries/octree/CMakeLists.txt index 985b3fdba7..5988b4b058 100644 --- a/libraries/octree/CMakeLists.txt +++ b/libraries/octree/CMakeLists.txt @@ -28,4 +28,9 @@ link_hifi_library(networking ${TARGET_NAME} "${ROOT_DIR}") find_package(ZLIB) include_directories(SYSTEM "${ZLIB_INCLUDE_DIRS}") -target_link_libraries(${TARGET_NAME} "${ZLIB_LIBRARIES}" Qt5::Widgets) \ No newline at end of file +target_link_libraries(${TARGET_NAME} "${ZLIB_LIBRARIES}" Qt5::Widgets) + +# add a definition for ssize_t so that windows doesn't bail +if (WIN32) + add_definitions(-Dssize_t=long) +endif () \ No newline at end of file diff --git a/libraries/particles/CMakeLists.txt b/libraries/particles/CMakeLists.txt index 7f42854b93..dbf2995293 100644 --- a/libraries/particles/CMakeLists.txt +++ b/libraries/particles/CMakeLists.txt @@ -32,3 +32,8 @@ find_package(ZLIB) include_directories(SYSTEM "${ZLIB_INCLUDE_DIRS}") target_link_libraries(${TARGET_NAME} "${ZLIB_LIBRARIES}" Qt5::Widgets) + +# add a definition for ssize_t so that windows doesn't bail +if (WIN32) + add_definitions(-Dssize_t=long) +endif () \ No newline at end of file diff --git a/libraries/script-engine/CMakeLists.txt b/libraries/script-engine/CMakeLists.txt index ac56f335e1..d0d05df286 100644 --- a/libraries/script-engine/CMakeLists.txt +++ b/libraries/script-engine/CMakeLists.txt @@ -34,3 +34,8 @@ find_package(ZLIB) include_directories(SYSTEM "${ZLIB_INCLUDE_DIRS}") target_link_libraries(${TARGET_NAME} "${ZLIB_LIBRARIES}" Qt5::Widgets) + +# add a definition for ssize_t so that windows doesn't bail +if (WIN32) + add_definitions(-Dssize_t=long) +endif () \ No newline at end of file diff --git a/libraries/voxels/CMakeLists.txt b/libraries/voxels/CMakeLists.txt index dd1020b4d7..51b83bb650 100644 --- a/libraries/voxels/CMakeLists.txt +++ b/libraries/voxels/CMakeLists.txt @@ -30,4 +30,9 @@ link_hifi_library(networking ${TARGET_NAME} "${ROOT_DIR}") find_package(ZLIB) include_directories(SYSTEM "${ZLIB_INCLUDE_DIRS}") -target_link_libraries(${TARGET_NAME} "${ZLIB_LIBRARIES}" Qt5::Widgets Qt5::Script) \ No newline at end of file +target_link_libraries(${TARGET_NAME} "${ZLIB_LIBRARIES}" Qt5::Widgets Qt5::Script) + +# add a definition for ssize_t so that windows doesn't bail +if (WIN32) + add_definitions(-Dssize_t=long) +endif () \ No newline at end of file diff --git a/voxel-edit/CMakeLists.txt b/voxel-edit/CMakeLists.txt index ce3c542691..6ebf23efba 100644 --- a/voxel-edit/CMakeLists.txt +++ b/voxel-edit/CMakeLists.txt @@ -38,4 +38,9 @@ IF (WIN32) target_link_libraries(${TARGET_NAME} Winmm Ws2_32) ENDIF(WIN32) -target_link_libraries(${TARGET_NAME} Qt5::Script) \ No newline at end of file +target_link_libraries(${TARGET_NAME} Qt5::Script) + +# add a definition for ssize_t so that windows doesn't bail +if (WIN32) + add_definitions(-Dssize_t=long) +endif () \ No newline at end of file