Commit b0f5a114 authored by Riegel's avatar Riegel
Browse files

Add fine adjustment of position

parent ce1fa9a7
...@@ -12,6 +12,8 @@ let model; ...@@ -12,6 +12,8 @@ let model;
let conditions = [[true, true]]; let conditions = [[true, true]];
let activeMouseEvent; let activeMouseEvent;
let currentMousePosition; let currentMousePosition;
let initialPosition;
let initialPickResult;
let heightDif = 0; let heightDif = 0;
const hpRollMap = new Map(); const hpRollMap = new Map();
let placedModels = []; let placedModels = [];
...@@ -145,7 +147,7 @@ function setupModel(vcsApp, windowPos, url, name) { ...@@ -145,7 +147,7 @@ function setupModel(vcsApp, windowPos, url, name) {
name: name, name: name,
}); });
vcMap.requestRender(); vcMap.requestRender();
const interaction = new MoveInteraction(); const interaction = new PickPlaceInteraction();
interaction.setActive(EventType.CLICKMOVE); interaction.setActive(EventType.CLICKMOVE);
activeMouseEvent = vcsApp.maps.eventHandler.addExclusiveInteraction(interaction, () => {}); activeMouseEvent = vcsApp.maps.eventHandler.addExclusiveInteraction(interaction, () => {});
} }
...@@ -157,6 +159,41 @@ function removePlacedModel(modelToBeRemoved) { ...@@ -157,6 +159,41 @@ function removePlacedModel(modelToBeRemoved) {
} }
class MoveInteraction extends AbstractInteraction { class MoveInteraction extends AbstractInteraction {
async pipe(event) {
if (event.pointerEvent === 2) {
if (activeMouseEvent !== undefined) {
activeMouseEvent();
}
} else if (event.pointerEvent === 3 && model !== undefined) {
const cesiumMap = event.map;
const scene = cesiumMap.getScene();
const pickResult = scene.globe.pick(
event.ray,
scene
);
if (initialPickResult === undefined) {
initialPickResult = pickResult;
}
if (initialPosition === undefined) {
initialPosition = model.position.getValue().clone();
}
let xDif = pickResult.x - initialPickResult.x;
let yDif = pickResult.y - initialPickResult.y;
let zDif = pickResult.z - initialPickResult.z;
// pickResult.z = pickResult.z + heightDif;
let pos = initialPosition.clone();
pos.x = pos.x + xDif;
pos.y = pos.y + yDif;
pos.z = pos.z + zDif;
model.position.setValue(pos);
}
return event;
}
}
class PickPlaceInteraction extends AbstractInteraction {
async pipe(event) { async pipe(event) {
if (event.pointerEvent === 2) { if (event.pointerEvent === 2) {
if (activeMouseEvent !== undefined) { if (activeMouseEvent !== undefined) {
...@@ -384,6 +421,8 @@ export default function smartVillagesPlugin(config, baseUrl) { ...@@ -384,6 +421,8 @@ export default function smartVillagesPlugin(config, baseUrl) {
id: 'move', id: 'move',
name: 'Objekt verschieben', name: 'Objekt verschieben',
callback() { callback() {
initialPosition = undefined;
initialPickResult = undefined;
const interaction = new MoveInteraction(); const interaction = new MoveInteraction();
interaction.setActive(EventType.CLICKMOVE); interaction.setActive(EventType.CLICKMOVE);
activeMouseEvent = vcsApp.maps.eventHandler.addExclusiveInteraction(interaction, () => { console.log("removed") }); activeMouseEvent = vcsApp.maps.eventHandler.addExclusiveInteraction(interaction, () => { console.log("removed") });
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment