在此处执行鼠标滚轮操作时,将鼠标滚轮移入或移出时对象前后移动。我也想知道公式的目的
point.x = point.x * 2 - 1;
point.y = -point.y * 2 + 1;
这里我附加了代码的功能,您可以在计算中发现错误,该错误是来回放大或缩小的,但不是正常方式
private actionMouseWheel = (): Function => {
const that = this;
const cameraManager = that._cameraHandler;
const zoomStart = new Vector2(0, 0); //center of the position
const zoomEnd = new Vector2(0, 0); //center of the position
const zoomSpeed = 1.015; //speed of mouse wheel
const zoomFactor = 2.015;
let w;
let xy = new Vector2();
let dist = 0;
let detail = {};
let closestPoint = new Vector3();
closestPoint = cameraManager.Target;
const dispatchEvent = () => {
that._orbitController.trigger('zoom', {
type: 'zoom',
detail: detail
});
};
const interval = 15;
let marker = true,
counter1 = 0,
counter2;
function wheelStart() {
marker = false;
that._layerHandler.isFrustumCulled = true;
dispatchEvent();
wheelAct();
}
function wheelAct() {
counter2 = counter1;
}
function wheelEnd() {
marker = true,
counter1 = 0,
counter2 = 0;
that._layerHandler.isFrustumCulled = false;
that.render();
}
let pPoint = null;
const callback = (resp) => {
objCallback(xy, resp);
};
const objCallback = (point, id) => {
point.x = point.x * 2 - 1;
point.y = -point.y * 2 + 1;
pPoint = null;
const obj = that._pickingHandler.getPickingDataById(id);
if (obj) {
pPoint = that.updatePivotOrbitPoint(point, obj);
}
update(point);
console.log("point on mouse wheel");
console.log(point);
};
const update = (point) => {
const dd = 1000; // 3048 * 0.5; // 3048mm = 10ft
const ddd = 1000;
if (pPoint !== null) {
closestPoint = pPoint;
dist = cameraManager.Eye.distanceTo(pPoint);
}
else {
dist = cameraManager.Eye.distanceTo(closestPoint) > cameraManager.Dist ? cameraManager.Dist : cameraManager.Eye.distanceTo(closestPoint);
}
dist = dist < dd ? dd : dist;
dist = Math.ceil(dist / (0.1 * 100));
const _factor = dd + (dist + (zoomEnd.y - zoomStart.y)) * zoomSpeed;
detail = {
x: point.x,
y: point.y,
d: w.f,
factor: _factor,
callback: () => { }
};
wheelStart();
};
return ((e): void => {
w = e.detail;
if (!w) { return; }
zoomEnd.copy(zoomStart);
zoomStart.y -= w.f * 0.00025;
xy = that.getMouseOnScreen(w.x, w.y);
that.validatePickingIntersection(that.get2dMouseOnScreen(w.x, w.y), callback);
zoomStart.copy(zoomEnd);
});
}