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

This commit is contained in:
Seth Alves 2015-05-21 18:07:52 -07:00
commit 90a5dd6dd1
4 changed files with 305 additions and 239 deletions

View file

@ -254,12 +254,15 @@ $(document).ready(function(){
}); });
$('#' + Settings.FORM_ID).on('click', '#' + Settings.DISCONNECT_ACCOUNT_BTN_ID, function(e){ $('#' + Settings.FORM_ID).on('click', '#' + Settings.DISCONNECT_ACCOUNT_BTN_ID, function(e){
$(this).blur();
disonnectHighFidelityAccount(); disonnectHighFidelityAccount();
e.preventDefault();
}); });
$('#' + Settings.FORM_ID).on('click', '#' + Settings.CONNECT_ACCOUNT_BTN_ID, function(e){ $('#' + Settings.FORM_ID).on('click', '#' + Settings.CONNECT_ACCOUNT_BTN_ID, function(e){
$(this).blur(); $(this).blur();
prepareAccessTokenPrompt(); prepareAccessTokenPrompt();
e.preventDefault();
}); });
var panelsSource = $('#panels-template').html() var panelsSource = $('#panels-template').html()
@ -345,7 +348,7 @@ function disonnectHighFidelityAccount() {
+ "</br></br>This could cause your domain to appear offline and no longer be reachable via any place names.", + "</br></br>This could cause your domain to appear offline and no longer be reachable via any place names.",
type: "warning", type: "warning",
html: true, html: true,
showCancelButton: true, showCancelButton: true
}, function(){ }, function(){
// we need to post to settings to clear the access-token // we need to post to settings to clear the access-token
$(Settings.ACCESS_TOKEN_SELECTOR).val('').change(); $(Settings.ACCESS_TOKEN_SELECTOR).val('').change();

View file

@ -18,3 +18,4 @@ Script.load("notifications.js");
Script.load("look.js"); Script.load("look.js");
Script.load("users.js"); Script.load("users.js");
Script.load("grab.js"); Script.load("grab.js");
Script.load("pointer.js");

View file

@ -25,8 +25,18 @@ var ALTITUDE_RATE = 200.0;
var RADIUS_RATE = 1.0 / 100.0; var RADIUS_RATE = 1.0 / 100.0;
var PAN_RATE = 50.0; var PAN_RATE = 50.0;
var Y_AXIS = { x: 0, y: 1, z: 0 }; var Y_AXIS = {
var X_AXIS = { x: 1, y: 0, z: 0 }; x: 0,
y: 1,
z: 0
};
var X_AXIS = {
x: 1,
y: 0,
z: 0
};
var LOOK_AT_TIME = 500;
var alt = false; var alt = false;
var shift = false; var shift = false;
@ -46,9 +56,21 @@ var mouseLastX = 0;
var mouseLastY = 0; var mouseLastY = 0;
var center = { x: 0, y: 0, z: 0 }; var center = {
var position = { x: 0, y: 0, z: 0 }; x: 0,
var vector = { x: 0, y: 0, z: 0 }; y: 0,
z: 0
};
var position = {
x: 0,
y: 0,
z: 0
};
var vector = {
x: 0,
y: 0,
z: 0
};
var radius = 0.0; var radius = 0.0;
var azimuth = 0.0; var azimuth = 0.0;
var altitude = 0.0; var altitude = 0.0;
@ -56,244 +78,262 @@ var altitude = 0.0;
var avatarPosition; var avatarPosition;
var avatarOrientation; var avatarOrientation;
var rotatingTowardsTarget = false;
var targetCamOrientation;
var oldPosition, oldOrientation;
function orientationOf(vector) { function orientationOf(vector) {
var direction, var direction,
yaw, yaw,
pitch; pitch;
direction = Vec3.normalize(vector); direction = Vec3.normalize(vector);
yaw = Quat.angleAxis(Math.atan2(direction.x, direction.z) * RAD_TO_DEG, Y_AXIS); yaw = Quat.angleAxis(Math.atan2(direction.x, direction.z) * RAD_TO_DEG, Y_AXIS);
pitch = Quat.angleAxis(Math.asin(-direction.y) * RAD_TO_DEG, X_AXIS); pitch = Quat.angleAxis(Math.asin(-direction.y) * RAD_TO_DEG, X_AXIS);
return Quat.multiply(yaw, pitch); return Quat.multiply(yaw, pitch);
} }
function handleRadialMode(dx, dy) { function handleRadialMode(dx, dy) {
azimuth += dx / AZIMUTH_RATE; azimuth += dx / AZIMUTH_RATE;
radius += radius * dy * RADIUS_RATE; radius += radius * dy * RADIUS_RATE;
if (radius < 1) { if (radius < 1) {
radius = 1; radius = 1;
} }
vector = { x: (Math.cos(altitude) * Math.cos(azimuth)) * radius, vector = {
y: Math.sin(altitude) * radius, x: (Math.cos(altitude) * Math.cos(azimuth)) * radius,
z: (Math.cos(altitude) * Math.sin(azimuth)) * radius }; y: Math.sin(altitude) * radius,
position = Vec3.sum(center, vector); z: (Math.cos(altitude) * Math.sin(azimuth)) * radius
Camera.setPosition(position); };
Camera.setOrientation(orientationOf(vector)); position = Vec3.sum(center, vector);
Camera.setPosition(position);
Camera.setOrientation(orientationOf(vector));
} }
function handleOrbitMode(dx, dy) { function handleOrbitMode(dx, dy) {
azimuth += dx / AZIMUTH_RATE; azimuth += dx / AZIMUTH_RATE;
altitude += dy / ALTITUDE_RATE; altitude += dy / ALTITUDE_RATE;
if (altitude > PI / 2.0) { if (altitude > PI / 2.0) {
altitude = PI / 2.0; altitude = PI / 2.0;
} }
if (altitude < -PI / 2.0) { if (altitude < -PI / 2.0) {
altitude = -PI / 2.0; altitude = -PI / 2.0;
} }
vector = { x:(Math.cos(altitude) * Math.cos(azimuth)) * radius, vector = {
y:Math.sin(altitude) * radius, x: (Math.cos(altitude) * Math.cos(azimuth)) * radius,
z:(Math.cos(altitude) * Math.sin(azimuth)) * radius }; y: Math.sin(altitude) * radius,
position = Vec3.sum(center, vector); z: (Math.cos(altitude) * Math.sin(azimuth)) * radius
Camera.setPosition(position); };
Camera.setOrientation(orientationOf(vector)); position = Vec3.sum(center, vector);
Camera.setPosition(position);
Camera.setOrientation(orientationOf(vector));
} }
function handlePanMode(dx, dy) { function handlePanMode(dx, dy) {
var up = Quat.getUp(Camera.getOrientation()); var up = Quat.getUp(Camera.getOrientation());
var right = Quat.getRight(Camera.getOrientation()); var right = Quat.getRight(Camera.getOrientation());
var distance = Vec3.length(vector); var distance = Vec3.length(vector);
var dv = Vec3.sum(Vec3.multiply(up, - distance * dy / PAN_RATE), Vec3.multiply(right, distance * dx / PAN_RATE)); var dv = Vec3.sum(Vec3.multiply(up, -distance * dy / PAN_RATE), Vec3.multiply(right, distance * dx / PAN_RATE));
center = Vec3.sum(center, dv); center = Vec3.sum(center, dv);
position = Vec3.sum(position, dv); position = Vec3.sum(position, dv);
Camera.setPosition(position); Camera.setPosition(position);
Camera.setOrientation(orientationOf(vector)); Camera.setOrientation(orientationOf(vector));
} }
function saveCameraState() { function saveCameraState() {
oldMode = Camera.mode; oldMode = Camera.mode;
var oldPosition = Camera.getPosition(); oldPosition = Camera.getPosition();
Camera.mode = "independent"; oldOrientation = Camera.getOrientation();
Camera.setPosition(oldPosition);
Camera.mode = "independent";
Camera.setPosition(oldPosition);
} }
function restoreCameraState() { function restoreCameraState() {
Camera.mode = oldMode; Camera.mode = oldMode;
Camera.setPosition(oldPosition);
Camera.setOrientation(oldOrientation);
} }
function handleModes() { function handleModes() {
var newMode = (mode == noMode) ? noMode : detachedMode; var newMode = (mode == noMode) ? noMode : detachedMode;
if (alt) { if (alt) {
if (control) { if (control) {
if (shift) { if (shift) {
newMode = panningMode; newMode = panningMode;
} else { } else {
newMode = orbitMode; newMode = orbitMode;
} }
} else { } else {
newMode = radialMode; newMode = radialMode;
}
}
// if entering detachMode
if (newMode == detachedMode && mode != detachedMode) {
avatarPosition = MyAvatar.position;
avatarOrientation = MyAvatar.orientation;
}
// if leaving detachMode
if (mode == detachedMode && newMode == detachedMode &&
(avatarPosition.x != MyAvatar.position.x ||
avatarPosition.y != MyAvatar.position.y ||
avatarPosition.z != MyAvatar.position.z ||
avatarOrientation.x != MyAvatar.orientation.x ||
avatarOrientation.y != MyAvatar.orientation.y ||
avatarOrientation.z != MyAvatar.orientation.z ||
avatarOrientation.w != MyAvatar.orientation.w)) {
newMode = noMode;
} }
}
if (mode == noMode && newMode != noMode && Camera.mode == "independent") { // if entering detachMode
newMode = noMode; if (newMode == detachedMode && mode != detachedMode) {
} avatarPosition = MyAvatar.position;
avatarOrientation = MyAvatar.orientation;
}
// if leaving detachMode
if (mode == detachedMode && newMode == detachedMode &&
(avatarPosition.x != MyAvatar.position.x ||
avatarPosition.y != MyAvatar.position.y ||
avatarPosition.z != MyAvatar.position.z ||
avatarOrientation.x != MyAvatar.orientation.x ||
avatarOrientation.y != MyAvatar.orientation.y ||
avatarOrientation.z != MyAvatar.orientation.z ||
avatarOrientation.w != MyAvatar.orientation.w)) {
newMode = noMode;
}
// if leaving noMode if (mode == noMode && newMode != noMode && Camera.mode == "independent") {
if (mode == noMode && newMode != noMode) { newMode = noMode;
saveCameraState(); }
}
// if entering noMode // if leaving noMode
if (newMode == noMode && mode != noMode) { if (mode == noMode && newMode != noMode) {
restoreCameraState(); saveCameraState();
} }
// if entering noMode
mode = newMode; if (newMode == noMode && mode != noMode) {
restoreCameraState();
}
mode = newMode;
} }
function keyPressEvent(event) { function keyPressEvent(event) {
var changed = false; var changed = false;
if (event.text == "ALT") { if (event.text == "ALT") {
alt = true; alt = true;
changed = true; changed = true;
} }
if (event.text == "CONTROL") { if (event.text == "CONTROL") {
control = true; control = true;
changed = true; changed = true;
} }
if (event.text == "SHIFT") { if (event.text == "SHIFT") {
shift = true; shift = true;
changed = true; changed = true;
} }
if (changed) { if (changed) {
handleModes(); handleModes();
} }
} }
function keyReleaseEvent(event) { function keyReleaseEvent(event) {
var changed = false; var changed = false;
if (event.text == "ALT") { if (event.text == "ALT") {
alt = false; alt = false;
changed = true; changed = true;
} mode = noMode;
if (event.text == "CONTROL") { restoreCameraState();
control = false; }
changed = true; if (event.text == "CONTROL") {
} control = false;
if (event.text == "SHIFT") { changed = true;
shift = false; }
changed = true; if (event.text == "SHIFT") {
} shift = false;
changed = true;
if (changed) { }
handleModes();
} if (changed) {
handleModes();
}
} }
function mousePressEvent(event) { function mousePressEvent(event) {
if (alt && !isActive) { if (alt && !isActive) {
mouseLastX = event.x; mouseLastX = event.x;
mouseLastY = event.y; mouseLastY = event.y;
// Compute trajectories related values // Compute trajectories related values
var pickRay = Camera.computePickRay(mouseLastX, mouseLastY); var pickRay = Camera.computePickRay(mouseLastX, mouseLastY);
var modelIntersection = Entities.findRayIntersection(pickRay); var modelIntersection = Entities.findRayIntersection(pickRay, true);
position = Camera.getPosition(); position = Camera.getPosition();
var avatarTarget = MyAvatar.getTargetAvatarPosition(); var avatarTarget = MyAvatar.getTargetAvatarPosition();
var distance = -1; var distance = -1;
var string; var string;
if (modelIntersection.intersects && modelIntersection.accurate) { if (modelIntersection.intersects && modelIntersection.accurate) {
distance = modelIntersection.distance; distance = modelIntersection.distance;
center = modelIntersection.properties.position; center = modelIntersection.intersection;
string = "Inspecting model"; string = "Inspecting model";
} //We've selected our target, now orbit towards it automatically
rotatingTowardsTarget = true;
if ((distance == -1 || Vec3.length(Vec3.subtract(avatarTarget, position)) < distance) && //calculate our target cam rotation
(avatarTarget.x != 0 || avatarTarget.y != 0 || avatarTarget.z != 0)) { Script.setTimeout(function() {
distance = Vec3.length(Vec3.subtract(avatarTarget, position)); rotatingTowardsTarget = false;
center = avatarTarget; }, LOOK_AT_TIME);
string = "Inspecting avatar";
} vector = Vec3.subtract(position, center);
targetCamOrientation = orientationOf(vector);
if (distance == -1) { radius = Vec3.length(vector);
return; azimuth = Math.atan2(vector.z, vector.x);
} altitude = Math.asin(vector.y / Vec3.length(vector));
vector = Vec3.subtract(position, center); isActive = true;
radius = Vec3.length(vector);
azimuth = Math.atan2(vector.z, vector.x);
altitude = Math.asin(vector.y / Vec3.length(vector));
print(string);
isActive = true;
} }
}
} }
function mouseReleaseEvent(event) { function mouseReleaseEvent(event) {
if (isActive) { if (isActive) {
isActive = false; isActive = false;
} }
} }
function mouseMoveEvent(event) { function mouseMoveEvent(event) {
if (isActive && mode != noMode) { if (isActive && mode != noMode && !rotatingTowardsTarget) {
if (mode == radialMode) { if (mode == radialMode) {
handleRadialMode(event.x - mouseLastX, event.y - mouseLastY); handleRadialMode(event.x - mouseLastX, event.y - mouseLastY);
}
if (mode == orbitMode) {
handleOrbitMode(event.x - mouseLastX, event.y - mouseLastY);
}
if (mode == panningMode) {
handlePanMode(event.x - mouseLastX, event.y - mouseLastY);
}
mouseLastX = event.x;
mouseLastY = event.y;
} }
if (mode == orbitMode) {
handleOrbitMode(event.x - mouseLastX, event.y - mouseLastY);
}
if (mode == panningMode) {
handlePanMode(event.x - mouseLastX, event.y - mouseLastY);
}
}
mouseLastX = event.x;
mouseLastY = event.y;
} }
function update() { function update() {
handleModes(); handleModes();
if (rotatingTowardsTarget) {
rotateTowardsTarget();
}
}
function rotateTowardsTarget() {
var newOrientation = Quat.mix(Camera.getOrientation(), targetCamOrientation, .1);
Camera.setOrientation(newOrientation);
} }
function scriptEnding() { function scriptEnding() {
if (mode != noMode) { if (mode != noMode) {
restoreCameraState(); restoreCameraState();
} }
} }
Controller.keyPressEvent.connect(keyPressEvent); Controller.keyPressEvent.connect(keyPressEvent);

View file

@ -1,77 +1,99 @@
var lineEntityID = null; var lineEntityID = null;
var lineIsRezzed = false; var lineIsRezzed = false;
var altHeld = false;
var lineCreated = false;
function nearLinePoint(targetPosition) { function nearLinePoint(targetPosition) {
var handPosition = MyAvatar.getRightPalmPosition(); var handPosition = MyAvatar.getRightPalmPosition();
var along = Vec3.subtract(targetPosition, handPosition); var along = Vec3.subtract(targetPosition, handPosition);
along = Vec3.normalize(along); along = Vec3.normalize(along);
along = Vec3.multiply(along, 0.4); along = Vec3.multiply(along, 0.4);
return Vec3.sum(handPosition, along); return Vec3.sum(handPosition, along);
} }
function removeLine() { function removeLine() {
if (lineIsRezzed) { if (lineIsRezzed) {
Entities.deleteEntity(lineEntityID); Entities.deleteEntity(lineEntityID);
lineEntityID = null; lineEntityID = null;
lineIsRezzed = false; lineIsRezzed = false;
} }
} }
function createOrUpdateLine(event) { function createOrUpdateLine(event) {
var pickRay = Camera.computePickRay(event.x, event.y); var pickRay = Camera.computePickRay(event.x, event.y);
var intersection = Entities.findRayIntersection(pickRay, true); // accurate picking var intersection = Entities.findRayIntersection(pickRay, true); // accurate picking
var props = Entities.getEntityProperties(intersection.entityID); var props = Entities.getEntityProperties(intersection.entityID);
if (intersection.intersects) { if (intersection.intersects) {
var dim = Vec3.subtract(intersection.intersection, nearLinePoint(intersection.intersection)); var dim = Vec3.subtract(intersection.intersection, nearLinePoint(intersection.intersection));
if (lineIsRezzed) { if (lineIsRezzed) {
Entities.editEntity(lineEntityID, { Entities.editEntity(lineEntityID, {
position: nearLinePoint(intersection.intersection), position: nearLinePoint(intersection.intersection),
dimensions: dim, dimensions: dim,
lifetime: 15 + props.lifespan // renew lifetime lifetime: 15 + props.lifespan // renew lifetime
}); });
} else {
lineIsRezzed = true;
lineEntityID = Entities.addEntity({
type: "Line",
position: nearLinePoint(intersection.intersection),
dimensions: dim,
color: { red: 255, green: 255, blue: 255 },
lifetime: 15 // if someone crashes while pointing, don't leave the line there forever.
});
}
} else { } else {
removeLine(); lineIsRezzed = true;
lineEntityID = Entities.addEntity({
type: "Line",
position: nearLinePoint(intersection.intersection),
dimensions: dim,
color: {
red: 255,
green: 255,
blue: 255
},
lifetime: 15 // if someone crashes while pointing, don't leave the line there forever.
});
} }
} else {
removeLine();
}
} }
function mousePressEvent(event) { function mousePressEvent(event) {
if (!event.isLeftButton) { if (!event.isLeftButton || altHeld) {
return; return;
} }
Controller.mouseMoveEvent.connect(mouseMoveEvent); Controller.mouseMoveEvent.connect(mouseMoveEvent);
createOrUpdateLine(event); createOrUpdateLine(event);
} lineCreated = true;
}
function mouseMoveEvent(event) { function mouseMoveEvent(event) {
createOrUpdateLine(event); createOrUpdateLine(event);
} }
function mouseReleaseEvent(event) { function mouseReleaseEvent(event) {
if (!event.isLeftButton) { if (!lineCreated) {
return; return;
} }
Controller.mouseMoveEvent.disconnect(mouseMoveEvent); Controller.mouseMoveEvent.disconnect(mouseMoveEvent);
removeLine(); removeLine();
lineCreated = false;
}
function keyPressEvent(event) {
if (event.text == "ALT") {
altHeld = true;
}
}
function keyReleaseEvent(event) {
if (event.text == "ALT") {
altHeld = false;
}
} }
Controller.mousePressEvent.connect(mousePressEvent); Controller.mousePressEvent.connect(mousePressEvent);
Controller.mouseReleaseEvent.connect(mouseReleaseEvent); Controller.mouseReleaseEvent.connect(mouseReleaseEvent);
Controller.keyPressEvent.connect(keyPressEvent);
Controller.keyReleaseEvent.connect(keyReleaseEvent);