tweaks to translation, reduce redraws of selection handles

This commit is contained in:
ZappoMan 2014-10-02 17:58:18 -07:00
parent a04941bcd5
commit ab58a4e5b8
2 changed files with 66 additions and 4 deletions

View file

@ -14,6 +14,9 @@
SelectionDisplay = (function () {
var that = {};
var lastAvatarPosition = MyAvatar.position;
var lastAvatarOrientation = MyAvatar.orientation;
var currentSelection = { id: -1, isKnownID: false };
var handleHoverColor = { red: 224, green: 67, blue: 36 };
@ -88,6 +91,17 @@ SelectionDisplay = (function () {
lineWidth: 1.0,
});
var grabberMoveUp = Overlays.addOverlay("billboard", {
url: "https://s3-us-west-1.amazonaws.com/highfidelity-public/images/up-arrow.png",
position: { x:0, y: 0, z: 0},
color: { red: 0, green: 0, blue: 0 },
alpha: 1.0,
visible: false,
size: 0.1,
scale: 0.1,
isFacingAvatar: true
});
var grabberLBN = Overlays.addOverlay("cube", grabberPropertiesCorner);
var grabberRBN = Overlays.addOverlay("cube", grabberPropertiesCorner);
var grabberLBF = Overlays.addOverlay("cube", grabberPropertiesCorner);
@ -206,6 +220,7 @@ SelectionDisplay = (function () {
that.cleanup = function () {
Overlays.deleteOverlay(highlightBox);
Overlays.deleteOverlay(selectionBox);
Overlays.deleteOverlay(grabberMoveUp);
Overlays.deleteOverlay(baseOfEntityProjectionOverlay);
Overlays.deleteOverlay(grabberLBN);
Overlays.deleteOverlay(grabberLBF);
@ -263,12 +278,19 @@ SelectionDisplay = (function () {
};
that.select = function(entityID) {
print("select()...... entityID:" + entityID.id);
var properties = Entities.getEntityProperties(entityID);
if (currentSelection.isKnownID == true) {
that.unselect(currentSelection);
}
currentSelection = entityID;
lastAvatarPosition = MyAvatar.position;
lastAvatarOrientation = MyAvatar.orientation;
var diagonal = (Vec3.length(properties.dimensions) / 2) * 1.1;
var halfDimensions = Vec3.multiply(properties.dimensions, 0.5);
var innerRadius = diagonal;
@ -283,6 +305,7 @@ SelectionDisplay = (function () {
}
var rotateHandleOffset = 0.05;
var grabberMoveUpOffset = 0.1;
var left = properties.position.x - halfDimensions.x;
var right = properties.position.x + halfDimensions.x;
@ -397,6 +420,8 @@ SelectionDisplay = (function () {
z: far + rotateHandleOffset};
}
}
Overlays.editOverlay(highlightBox, { visible: false });
Overlays.editOverlay(selectionBox,
{
@ -405,6 +430,9 @@ SelectionDisplay = (function () {
dimensions: properties.dimensions,
rotation: properties.rotation,
});
Overlays.editOverlay(grabberMoveUp, { visible: true, position: { x: center.x, y: top + grabberMoveUpOffset, z: center.z } });
Overlays.editOverlay(grabberLBN, { visible: true, position: { x: left, y: bottom, z: near } });
Overlays.editOverlay(grabberRBN, { visible: true, position: { x: right, y: bottom, z: near } });
@ -507,6 +535,7 @@ SelectionDisplay = (function () {
that.unselect = function (entityID) {
Overlays.editOverlay(selectionBox, { visible: false });
Overlays.editOverlay(baseOfEntityProjectionOverlay, { visible: false });
Overlays.editOverlay(grabberMoveUp, { visible: false });
Overlays.editOverlay(grabberLBN, { visible: false });
Overlays.editOverlay(grabberLBF, { visible: false });
Overlays.editOverlay(grabberRBN, { visible: false });
@ -547,6 +576,23 @@ SelectionDisplay = (function () {
Entities.editEntity(entityID, { localRenderAlpha: 1.0 });
};
that.checkMove = function() {
if (currentSelection.isKnownID &&
(!Vec3.equal(MyAvatar.position, lastAvatarPosition) || !Quat.equal(MyAvatar.orientation, lastAvatarOrientation))){
print("checkMove calling .... select()");
//print("Vec3.equal(MyAvatar.position, lastAvatarPosition):" + Vec3.equal(MyAvatar.position, lastAvatarPosition);
//Vec3.print("MyAvatar.position:", MyAvatar.position);
//Vec3.print("lastAvatarPosition:", lastAvatarPosition);
//print("Quat.equal(MyAvatar.orientation, lastAvatarOrientation):" + Quat.equal(MyAvatar.orientation, lastAvatarOrientation));
//Quat.print("MyAvatar.orientation:", MyAvatar.orientation);
//Quat.print("lastAvatarOrientation:", lastAvatarOrientation);
that.select(currentSelection);
}
};
that.mousePressEvent = function(event) {
};

View file

@ -326,6 +326,7 @@ function isLocked(properties) {
var entitySelected = false;
var moving = false;
var selectedEntityID;
var selectedEntityProperties;
var mouseLastPosition;
@ -409,6 +410,7 @@ function mousePressEvent(event) {
if (0 < x && sizeOK) {
entitySelected = true;
moving = true; // if we are moving we are moving
selectedEntityID = foundEntity;
selectedEntityProperties = properties;
orientation = MyAvatar.orientation;
@ -437,6 +439,7 @@ function mousePressEvent(event) {
print("Clicked on " + selectedEntityID.id + " " + entitySelected);
tooltip.updateText(selectedEntityProperties);
tooltip.show(true);
print("mousePressEvent calling selectionDisplay.select()???");
selectionDisplay.select(selectedEntityID);
}
}
@ -477,20 +480,33 @@ function mouseMoveEvent(event) {
return;
}
if (entitySelected) {
if (entitySelected && moving) {
pickRay = Camera.computePickRay(event.x, event.y);
// translate mode left/right based on view toward entity
var newIntersection = rayPlaneIntersection(pickRay,
selectedEntityProperties.oldPosition,
Quat.getFront(orientation));
var vector = Vec3.subtract(newIntersection, intersection)
// this allows us to use the old editModels "shifted" logic which makes the
// up/down behavior of the mouse move "in"/"out" of the screen.
var i = Vec3.dot(vector, Quat.getRight(orientation));
var j = Vec3.dot(vector, Quat.getUp(orientation));
vector = Vec3.sum(Vec3.multiply(Quat.getRight(orientation), i),
Vec3.multiply(Quat.getFront(orientation), j));
selectedEntityProperties.position = Vec3.sum(selectedEntityProperties.oldPosition, vector);
Entities.editEntity(selectedEntityID, selectedEntityProperties);
tooltip.updateText(selectedEntityProperties);
selectionDisplay.highlightSelectable(selectedEntityID, selectedEntityProperties); // TODO: this should be more than highlighted
// TODO: make this be a "moving state" - which is actually more like highlighted
// but including the change measurements
selectionDisplay.select(selectedEntityID); // TODO: this should be more than highlighted
}
}
@ -502,8 +518,7 @@ function mouseReleaseEvent(event) {
if (entitySelected) {
tooltip.show(false);
}
entitySelected = false;
moving = false;
}
Controller.mousePressEvent.connect(mousePressEvent);
@ -576,6 +591,7 @@ Script.scriptEnding.connect(function() {
Script.update.connect(function (deltaTime) {
toolBar.move();
progressDialog.move();
selectionDisplay.checkMove();
});
function handeMenuEvent(menuItem) {