mirror of
https://github.com/Doodle3D/Doodle3D-Core.git
synced 2025-04-20 17:56:24 +02:00
26 lines
818 B
JavaScript
26 lines
818 B
JavaScript
import update from 'react-addons-update';
|
|
import { Matrix } from 'cal';
|
|
import constrainMatrix from './constrainMatrix.js';
|
|
import { MAX_ZOOM } from '../../constants/d2Constants.js';
|
|
|
|
export default function d2WheelZoomReducer(state, action) {
|
|
const { position, wheelDelta, screenMatrixContainer } = action;
|
|
const { canvasMatrix } = state.d2;
|
|
|
|
const targetScale = 1 + wheelDelta / -500;
|
|
|
|
if (canvasMatrix.sx === MAX_ZOOM && targetScale > 1) return state;
|
|
const rotateAround = position.applyMatrix(screenMatrixContainer.inverseMatrix());
|
|
const scaleMatrix = new Matrix().scaleAroundAbsolute(targetScale, targetScale, rotateAround);
|
|
|
|
const matrix = canvasMatrix.multiplyMatrix(scaleMatrix);
|
|
|
|
constrainMatrix(matrix);
|
|
|
|
return update(state, {
|
|
d2: {
|
|
canvasMatrix: { $set: matrix }
|
|
}
|
|
});
|
|
}
|