OLD | NEW |
---|---|
1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 /** | 5 /** |
6 * @constructor | 6 * @constructor |
7 * @extends {WebInspector.VBox} | 7 * @extends {WebInspector.VBox} |
8 */ | 8 */ |
9 WebInspector.SensorsView = function() | 9 WebInspector.SensorsView = function() |
10 { | 10 { |
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
309 | 309 |
310 cellElement.appendChild(createTextButton(WebInspector.UIString("Reset"), this._resetDeviceOrientation.bind(this), "accelerometer-reset-button")); | 310 cellElement.appendChild(createTextButton(WebInspector.UIString("Reset"), this._resetDeviceOrientation.bind(this), "accelerometer-reset-button")); |
311 return fieldsetElement; | 311 return fieldsetElement; |
312 }, | 312 }, |
313 | 313 |
314 /** | 314 /** |
315 * @param {!WebInspector.DeviceOrientation} deviceOrientation | 315 * @param {!WebInspector.DeviceOrientation} deviceOrientation |
316 */ | 316 */ |
317 _setBoxOrientation: function(deviceOrientation) | 317 _setBoxOrientation: function(deviceOrientation) |
318 { | 318 { |
319 var matrix = new WebKitCSSMatrix(); | 319 var matrix = this._screenSpaceMatrix(true); |
320 this._boxMatrix = matrix.rotate(90-deviceOrientation.beta, deviceOrienta tion.gamma, -deviceOrientation.alpha); | 320 this._boxMatrix = matrix.rotate(-deviceOrientation.beta, deviceOrientati on.gamma, -deviceOrientation.alpha); |
321 | |
321 this._boxElement.classList.add("is-animating"); | 322 this._boxElement.classList.add("is-animating"); |
322 this._boxElement.style.webkitTransform = this._boxMatrix.toString(); | 323 this._boxElement.style.webkitTransform = this._boxMatrix.toString(); |
323 }, | 324 }, |
324 | 325 |
325 /** | 326 /** |
327 * @param {boolean=} toScreenSpace | |
328 * @return {!CSSMatrix} | |
329 */ | |
330 _screenSpaceMatrix: function(toScreenSpace) | |
331 { | |
332 // The default orientation [0, 0, 0] represents a device with | |
333 // screen facing up. This transformation shifts the | |
334 // orientation displayed in the 3D preview to be front-facing | |
335 // instead of top-down. | |
336 var betaRotate = toScreenSpace ? 90 : -90; | |
337 var matrix = new WebKitCSSMatrix(); | |
338 return matrix.rotate(betaRotate, 0, 0); | |
339 }, | |
340 | |
341 /** | |
326 * @param {!MouseEvent} event | 342 * @param {!MouseEvent} event |
327 * @return {boolean} | 343 * @return {boolean} |
328 */ | 344 */ |
329 _onBoxDrag: function(event) | 345 _onBoxDrag: function(event) |
330 { | 346 { |
331 var mouseMoveVector = this._calculateRadiusVector(event.x, event.y); | 347 var mouseMoveVector = this._calculateRadiusVector(event.x, event.y); |
332 if (!mouseMoveVector) | 348 if (!mouseMoveVector) |
333 return true; | 349 return true; |
334 | 350 |
335 event.consume(true); | 351 event.consume(true); |
336 var axis, angle; | 352 var axis, angle; |
337 if (event.shiftKey) { | 353 if (event.shiftKey) { |
338 axis = new WebInspector.Geometry.Vector(0, 0, 1); | 354 axis = new WebInspector.Geometry.Vector(0, 0, -1); |
339 angle = (this._mouseDownVector.x - mouseMoveVector.x)*WebInspector.S ensorsView.ShiftDragOrientationSpeed; | 355 angle = (this._mouseDownVector.x - mouseMoveVector.x)*WebInspector.S ensorsView.ShiftDragOrientationSpeed; |
340 } else { | 356 } else { |
341 axis = WebInspector.Geometry.crossProduct(this._mouseDownVector, mou seMoveVector); | 357 axis = WebInspector.Geometry.crossProduct(this._mouseDownVector, mou seMoveVector); |
342 axis.normalize(); | 358 axis.normalize(); |
343 angle = WebInspector.Geometry.calculateAngle(this._mouseDownVector, mouseMoveVector); | 359 angle = WebInspector.Geometry.calculateAngle(this._mouseDownVector, mouseMoveVector); |
344 } | 360 } |
345 var matrix = new WebKitCSSMatrix(); | 361 var matrix = new WebKitCSSMatrix(); |
346 var rotationMatrix = matrix.rotateAxisAngle(axis.x, axis.y, axis.z, angl e); | 362 var rotationMatrix = matrix.rotateAxisAngle(axis.x, axis.y, axis.z, angl e); |
347 this._currentMatrix = rotationMatrix.multiply(this._boxMatrix); | 363 this._currentMatrix = rotationMatrix.multiply(this._boxMatrix); |
364 this._boxElement.style.webkitTransform = this._currentMatrix; | |
lushnikov
2016/05/06 18:04:47
let's use transform here
luoe
2016/05/06 18:14:32
Done.
| |
348 | 365 |
349 var mat90 = new WebKitCSSMatrix(); | 366 var transformFromScreen = this._screenSpaceMatrix(); |
350 mat90.rotate(90); | 367 var correctedMatrix = this._currentMatrix.multiply(transformFromScreen); |
351 this._boxElement.style.webkitTransform = mat90.multiply(this._currentMat rix); | 368 var eulerAngles = WebInspector.Geometry.EulerAngles.fromRotationMatrix(c orrectedMatrix); |
352 var eulerAngles = WebInspector.Geometry.EulerAngles.fromRotationMatrix(t his._currentMatrix); | |
353 var newOrientation = new WebInspector.DeviceOrientation(-eulerAngles.alp ha, -eulerAngles.beta, eulerAngles.gamma); | 369 var newOrientation = new WebInspector.DeviceOrientation(-eulerAngles.alp ha, -eulerAngles.beta, eulerAngles.gamma); |
354 this._setDeviceOrientation(newOrientation, WebInspector.SensorsView.Devi ceOrientationModificationSource.UserDrag); | 370 this._setDeviceOrientation(newOrientation, WebInspector.SensorsView.Devi ceOrientationModificationSource.UserDrag); |
355 this._setSelectElementLabel(this._orientationSelectElement, WebInspector .SensorsView.NonPresetOptions.Custom); | 371 this._setSelectElementLabel(this._orientationSelectElement, WebInspector .SensorsView.NonPresetOptions.Custom); |
356 return false; | 372 return false; |
357 }, | 373 }, |
358 | 374 |
359 /** | 375 /** |
360 * @param {!MouseEvent} event | 376 * @param {!MouseEvent} event |
361 * @return {boolean} | 377 * @return {boolean} |
362 */ | 378 */ |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
498 * @return {boolean} | 514 * @return {boolean} |
499 */ | 515 */ |
500 handleAction: function(context, actionId) | 516 handleAction: function(context, actionId) |
501 { | 517 { |
502 WebInspector.inspectorView.showViewInDrawer("sensors"); | 518 WebInspector.inspectorView.showViewInDrawer("sensors"); |
503 return true; | 519 return true; |
504 } | 520 } |
505 } | 521 } |
506 | 522 |
507 WebInspector.SensorsView.ShiftDragOrientationSpeed = 16; | 523 WebInspector.SensorsView.ShiftDragOrientationSpeed = 16; |
OLD | NEW |