MCPcopy Index your code
hub / github.com/microsoft/SandDance / computeInputData

Function computeInputData

docs/app/js/sanddance-app.js:92873–92904  ·  view source on GitHub ↗

* extend the data with some usable properties like scale, rotate, velocity etc * @param {Object} manager * @param {Object} input

(manager, input)

Source from the content-addressed store, hash-verified

92871 * @param {Object} manager
92872 * @param {Object} input
92873 */ function computeInputData(manager, input) {
92874 var session = manager.session;
92875 var pointers = input.pointers;
92876 var pointersLength = pointers.length;
92877 // store the first input to calculate the distance and direction
92878 if (!session.firstInput) session.firstInput = simpleCloneInputData(input);
92879 // to compute scale and rotation we need to store the multiple touches
92880 if (pointersLength > 1 && !session.firstMultiple) session.firstMultiple = simpleCloneInputData(input);
92881 else if (pointersLength === 1) session.firstMultiple = false;
92882 var firstInput = session.firstInput;
92883 var firstMultiple = session.firstMultiple;
92884 var offsetCenter = firstMultiple ? firstMultiple.center : firstInput.center;
92885 var center = input.center = getCenter(pointers);
92886 input.timeStamp = now();
92887 input.deltaTime = input.timeStamp - firstInput.timeStamp;
92888 input.angle = getAngle(offsetCenter, center);
92889 input.distance = getDistance(offsetCenter, center);
92890 computeDeltaXY(session, input);
92891 input.offsetDirection = getDirection(input.deltaX, input.deltaY);
92892 var overallVelocity = getVelocity(input.deltaTime, input.deltaX, input.deltaY);
92893 input.overallVelocityX = overallVelocity.x;
92894 input.overallVelocityY = overallVelocity.y;
92895 input.overallVelocity = abs(overallVelocity.x) > abs(overallVelocity.y) ? overallVelocity.x : overallVelocity.y;
92896 input.scale = firstMultiple ? getScale(firstMultiple.pointers, pointers) : 1;
92897 input.rotation = firstMultiple ? getRotation(firstMultiple.pointers, pointers) : 0;
92898 input.maxPointers = !session.prevInput ? input.pointers.length : input.pointers.length > session.prevInput.maxPointers ? input.pointers.length : session.prevInput.maxPointers;
92899 computeIntervalInputData(session, input);
92900 // find the correct target
92901 var target = manager.element;
92902 if (hasParent(input.srcEvent.target, target)) target = input.srcEvent.target;
92903 input.target = target;
92904 }
92905 function computeDeltaXY(session, input) {
92906 var center = input.center;
92907 var offset = session.offsetDelta || {};

Callers 1

inputHandlerFunction · 0.70

Calls 12

simpleCloneInputDataFunction · 0.70
getCenterFunction · 0.70
nowFunction · 0.70
getAngleFunction · 0.70
getDistanceFunction · 0.70
computeDeltaXYFunction · 0.70
getDirectionFunction · 0.70
getVelocityFunction · 0.70
getScaleFunction · 0.70
getRotationFunction · 0.70
computeIntervalInputDataFunction · 0.70
hasParentFunction · 0.70

Tested by

no test coverage detected