mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 11:45:36 +02:00
drag relative to plane where pointer collided selection box
This commit is contained in:
parent
a275d95c59
commit
7fd88793dc
2 changed files with 36 additions and 8 deletions
|
@ -758,7 +758,8 @@ function findClickedEntity(event) {
|
|||
var foundEntity = result.entityID;
|
||||
return {
|
||||
pickRay: pickRay,
|
||||
entityID: foundEntity
|
||||
entityID: foundEntity,
|
||||
intersection: result.intersection
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -978,6 +979,8 @@ function mouseClickEvent(event) {
|
|||
|
||||
if (!event.isShifted) {
|
||||
selectionManager.setSelections([foundEntity]);
|
||||
Vec3.print("found object, intersection = ", result.intersection);
|
||||
selectionManager.setPickPlanePosition(result.intersection);
|
||||
} else {
|
||||
selectionManager.addEntity(foundEntity, true);
|
||||
}
|
||||
|
|
|
@ -16,6 +16,11 @@ HIFI_PUBLIC_BUCKET = "http://s3.amazonaws.com/hifi-public/";
|
|||
SPACE_LOCAL = "local";
|
||||
SPACE_WORLD = "world";
|
||||
|
||||
function objectTranslationPlanePoint(position, dimensions) {
|
||||
var newPosition = { x: position.x, y: position.y, z: position.z };
|
||||
newPosition.y -= dimensions.y / 2.0;
|
||||
return newPosition;
|
||||
}
|
||||
|
||||
SelectionManager = (function() {
|
||||
var that = {};
|
||||
|
@ -82,6 +87,11 @@ SelectionManager = (function() {
|
|||
y: 0,
|
||||
z: 0
|
||||
};
|
||||
that.pickPlanePosition = {
|
||||
x: 0,
|
||||
y: 0,
|
||||
z: 0
|
||||
};
|
||||
|
||||
that.saveProperties = function() {
|
||||
that.savedProperties = {};
|
||||
|
@ -109,6 +119,13 @@ SelectionManager = (function() {
|
|||
that._update();
|
||||
};
|
||||
|
||||
that.setPickPlanePosition = function(position) {
|
||||
that.pickPlanePosition.x = position.x;
|
||||
that.pickPlanePosition.y = position.y;
|
||||
that.pickPlanePosition.z = position.z;
|
||||
Vec3.print("that.pickPlanePosition = ", that.pickPlanePosition);
|
||||
};
|
||||
|
||||
that.addEntity = function(entityID, toggleSelection) {
|
||||
if (entityID) {
|
||||
var idx = -1;
|
||||
|
@ -2252,15 +2269,17 @@ SelectionDisplay = (function() {
|
|||
var constrainMajorOnly = false;
|
||||
var startPosition = null;
|
||||
var duplicatedEntityIDs = null;
|
||||
|
||||
var translateXZTool = {
|
||||
mode: 'TRANSLATE_XZ',
|
||||
pickPlanePosition: { x: 0, y: 0, z: 0 },
|
||||
onBegin: function(event) {
|
||||
SelectionManager.saveProperties();
|
||||
startPosition = SelectionManager.worldPosition;
|
||||
var dimensions = SelectionManager.worldDimensions;
|
||||
|
||||
var pickRay = Camera.computePickRay(event.x, event.y);
|
||||
initialXZPick = rayPlaneIntersection(pickRay, startPosition, {
|
||||
initialXZPick = rayPlaneIntersection(pickRay, translateXZTool.pickPlanePosition, {
|
||||
x: 0,
|
||||
y: 1,
|
||||
z: 0
|
||||
|
@ -2300,13 +2319,23 @@ SelectionDisplay = (function() {
|
|||
onMove: function(event) {
|
||||
pickRay = Camera.computePickRay(event.x, event.y);
|
||||
|
||||
var pick = rayPlaneIntersection(pickRay, SelectionManager.worldPosition, {
|
||||
var pick = rayPlaneIntersection(pickRay, translateXZTool.pickPlanePosition, {
|
||||
x: 0,
|
||||
y: 1,
|
||||
z: 0
|
||||
});
|
||||
|
||||
var vector = Vec3.subtract(pick, initialXZPick);
|
||||
|
||||
Vec3.print("Pick Plane Position", translateXZTool.pickPlanePosition);
|
||||
|
||||
/*
|
||||
if (pickRay.origin.y < this.pickPlanePosition.y) {
|
||||
vector.x *= -1.0;
|
||||
vector.z *= -1.0;
|
||||
} */
|
||||
|
||||
|
||||
// If shifted, constrain to one axis
|
||||
if (event.isShifted) {
|
||||
if (Math.abs(vector.x) > Math.abs(vector.z)) {
|
||||
|
@ -2645,11 +2674,6 @@ SelectionDisplay = (function() {
|
|||
pickRayPosition,
|
||||
planeNormal);
|
||||
|
||||
// Overlays.editOverlay(normalLine, {
|
||||
// start: initialPosition,
|
||||
// end: Vec3.sum(Vec3.multiply(100000, planeNormal), initialPosition),
|
||||
// });
|
||||
|
||||
SelectionManager.saveProperties();
|
||||
};
|
||||
|
||||
|
@ -4093,6 +4117,7 @@ SelectionDisplay = (function() {
|
|||
switch (result.overlayID) {
|
||||
case selectionBox:
|
||||
activeTool = translateXZTool;
|
||||
translateXZTool.pickPlanePosition = result.intersection;
|
||||
mode = translateXZTool.mode;
|
||||
activeTool.onBegin(event);
|
||||
somethingClicked = true;
|
||||
|
|
Loading…
Reference in a new issue