Skip to content

Commit f725e75

Browse files
authored
Introduce IMouseDrag interface (#570)
1 parent 8328c77 commit f725e75

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

packages/base/src/3dview/helpers.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,14 @@ export interface IPickedResult {
5656
position: THREE.Vector3;
5757
}
5858

59+
/**
60+
* The interface defining a mouse drag by its start and end position in pixels.
61+
*/
62+
export interface IMouseDrag {
63+
start: THREE.Vector2;
64+
end: THREE.Vector2;
65+
}
66+
5967
export function projectVector(options: {
6068
vector: THREE.Vector3;
6169
camera: THREE.Camera;

packages/base/src/3dview/mainview.tsx

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ import {
4848
SELECTION_BOUNDING_BOX,
4949
buildShape,
5050
computeExplodedState,
51-
projectVector
51+
projectVector,
52+
IMouseDrag
5253
} from './helpers';
5354
import { MainViewModel } from './mainviewmodel';
5455
import { Spinner } from './spinner';
@@ -293,14 +294,12 @@ export class MainView extends React.Component<IProps, IStates> {
293294
this._controls.dampingFactor = 0.15;
294295

295296
this._renderer.domElement.addEventListener('mousedown', e => {
296-
this._startMousePosition.set(e.clientX, e.clientY);
297+
this._mouseDrag.start.set(e.clientX, e.clientY);
297298
});
298299

299300
this._renderer.domElement.addEventListener('mouseup', e => {
300-
this._endMousePosition.set(e.clientX, e.clientY);
301-
const distance = this._endMousePosition.distanceTo(
302-
this._startMousePosition
303-
);
301+
this._mouseDrag.end.set(e.clientX, e.clientY);
302+
const distance = this._mouseDrag.end.distanceTo(this._mouseDrag.start);
304303

305304
if (distance <= CLICK_THRESHOLD) {
306305
this._onClick(e);
@@ -1713,8 +1712,10 @@ export class MainView extends React.Component<IProps, IStates> {
17131712
private _refLength: number | null = null; // Length of bounding box of current object
17141713
private _sceneAxe: THREE.Object3D | null; // Array of X, Y and Z axe
17151714
private _controls: OrbitControls; // Camera controls
1716-
private _startMousePosition = new THREE.Vector2(); // Start mouse position when dragging the camera controls
1717-
private _endMousePosition = new THREE.Vector2(); // End mouse position when dragging the camera controls
1715+
private _mouseDrag: IMouseDrag = {
1716+
start: new THREE.Vector2(),
1717+
end: new THREE.Vector2()
1718+
}; // Current mouse drag
17181719
private _clipPlaneTransformControls: TransformControls; // Clip plane position/rotation controls
17191720
private _transformControls: TransformControls; // Mesh position controls
17201721
private _pointer3D: IPointer | null = null;

0 commit comments

Comments
 (0)