| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2014 Google Inc. All rights reserved. | 2 * Copyright (C) 2014 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 258 } | 258 } |
| 259 var scaleAndRotationMatrix = new WebKitCSSMatrix() | 259 var scaleAndRotationMatrix = new WebKitCSSMatrix() |
| 260 .scale(scale, scale, scale) | 260 .scale(scale, scale, scale) |
| 261 .translate(canvasWidth / 2, canvasHeight /
2, 0) | 261 .translate(canvasWidth / 2, canvasHeight /
2, 0) |
| 262 .rotate(rotateX, rotateY, 0) | 262 .rotate(rotateX, rotateY, 0) |
| 263 .scale(viewScale, viewScale, viewScale) | 263 .scale(viewScale, viewScale, viewScale) |
| 264 .translate(-baseWidth / 2, -baseHeight / 2,
0); | 264 .translate(-baseWidth / 2, -baseHeight / 2,
0); |
| 265 | 265 |
| 266 var bounds; | 266 var bounds; |
| 267 for (var i = 0; i < this._rects.length; ++i) | 267 for (var i = 0; i < this._rects.length; ++i) |
| 268 bounds = Common.Geometry.boundsForTransformedPoints(scaleAndRotationMatrix
, this._rects[i].vertices, bounds); | 268 bounds = UI.Geometry.boundsForTransformedPoints(scaleAndRotationMatrix, th
is._rects[i].vertices, bounds); |
| 269 | 269 |
| 270 this._transformController.clampOffsets( | 270 this._transformController.clampOffsets( |
| 271 (paddingX - bounds.maxX) / window.devicePixelRatio, | 271 (paddingX - bounds.maxX) / window.devicePixelRatio, |
| 272 (canvasWidth - paddingX - bounds.minX) / window.devicePixelRatio, | 272 (canvasWidth - paddingX - bounds.minX) / window.devicePixelRatio, |
| 273 (paddingY - bounds.maxY) / window.devicePixelRatio, | 273 (paddingY - bounds.maxY) / window.devicePixelRatio, |
| 274 (canvasHeight - paddingY - bounds.minY) / window.devicePixelRatio); | 274 (canvasHeight - paddingY - bounds.minY) / window.devicePixelRatio); |
| 275 var offsetX = this._transformController.offsetX() * window.devicePixelRatio; | 275 var offsetX = this._transformController.offsetX() * window.devicePixelRatio; |
| 276 var offsetY = this._transformController.offsetY() * window.devicePixelRatio; | 276 var offsetY = this._transformController.offsetY() * window.devicePixelRatio; |
| 277 // Multiply to translation matrix on the right rather than translate (which
would implicitly multiply on the left). | 277 // Multiply to translation matrix on the right rather than translate (which
would implicitly multiply on the left). |
| 278 this._projectionMatrix = new WebKitCSSMatrix().translate(offsetX, offsetY, 0
).multiply(scaleAndRotationMatrix); | 278 this._projectionMatrix = new WebKitCSSMatrix().translate(offsetX, offsetY, 0
).multiply(scaleAndRotationMatrix); |
| (...skipping 820 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1099 * @param {!CSSMatrix} matrix | 1099 * @param {!CSSMatrix} matrix |
| 1100 * @param {number} x0 | 1100 * @param {number} x0 |
| 1101 * @param {number} y0 | 1101 * @param {number} y0 |
| 1102 * @return {(number|undefined)} | 1102 * @return {(number|undefined)} |
| 1103 */ | 1103 */ |
| 1104 intersectWithLine(matrix, x0, y0) { | 1104 intersectWithLine(matrix, x0, y0) { |
| 1105 var i; | 1105 var i; |
| 1106 // Vertices of the quad with transform matrix applied | 1106 // Vertices of the quad with transform matrix applied |
| 1107 var points = []; | 1107 var points = []; |
| 1108 for (i = 0; i < 4; ++i) { | 1108 for (i = 0; i < 4; ++i) { |
| 1109 points[i] = Common.Geometry.multiplyVectorByMatrixAndNormalize( | 1109 points[i] = UI.Geometry.multiplyVectorByMatrixAndNormalize( |
| 1110 new Common.Geometry.Vector(this.vertices[i * 3], this.vertices[i * 3 +
1], this.vertices[i * 3 + 2]), matrix); | 1110 new UI.Geometry.Vector(this.vertices[i * 3], this.vertices[i * 3 + 1],
this.vertices[i * 3 + 2]), matrix); |
| 1111 } | 1111 } |
| 1112 // Calculating quad plane normal | 1112 // Calculating quad plane normal |
| 1113 var normal = Common.Geometry.crossProduct( | 1113 var normal = UI.Geometry.crossProduct( |
| 1114 Common.Geometry.subtract(points[1], points[0]), Common.Geometry.subtract
(points[2], points[1])); | 1114 UI.Geometry.subtract(points[1], points[0]), UI.Geometry.subtract(points[
2], points[1])); |
| 1115 // General form of the equation of the quad plane: A * x + B * y + C * z + D
= 0 | 1115 // General form of the equation of the quad plane: A * x + B * y + C * z + D
= 0 |
| 1116 var A = normal.x; | 1116 var A = normal.x; |
| 1117 var B = normal.y; | 1117 var B = normal.y; |
| 1118 var C = normal.z; | 1118 var C = normal.z; |
| 1119 var D = -(A * points[0].x + B * points[0].y + C * points[0].z); | 1119 var D = -(A * points[0].x + B * points[0].y + C * points[0].z); |
| 1120 // Finding t from the equation | 1120 // Finding t from the equation |
| 1121 var t = -(D + A * x0 + B * y0) / C; | 1121 var t = -(D + A * x0 + B * y0) / C; |
| 1122 // Point of the intersection | 1122 // Point of the intersection |
| 1123 var pt = new Common.Geometry.Vector(x0, y0, t); | 1123 var pt = new UI.Geometry.Vector(x0, y0, t); |
| 1124 // Vectors from the intersection point to vertices of the quad | 1124 // Vectors from the intersection point to vertices of the quad |
| 1125 var tVects = points.map(Common.Geometry.subtract.bind(null, pt)); | 1125 var tVects = points.map(UI.Geometry.subtract.bind(null, pt)); |
| 1126 // Intersection point lies inside of the polygon if scalar products of norma
l of the plane and | 1126 // Intersection point lies inside of the polygon if scalar products of norma
l of the plane and |
| 1127 // cross products of successive tVects are all nonstrictly above or all nons
trictly below zero | 1127 // cross products of successive tVects are all nonstrictly above or all nons
trictly below zero |
| 1128 for (i = 0; i < tVects.length; ++i) { | 1128 for (i = 0; i < tVects.length; ++i) { |
| 1129 var product = Common.Geometry.scalarProduct( | 1129 var product = |
| 1130 normal, Common.Geometry.crossProduct(tVects[i], tVects[(i + 1) % tVect
s.length])); | 1130 UI.Geometry.scalarProduct(normal, UI.Geometry.crossProduct(tVects[i],
tVects[(i + 1) % tVects.length])); |
| 1131 if (product < 0) | 1131 if (product < 0) |
| 1132 return undefined; | 1132 return undefined; |
| 1133 } | 1133 } |
| 1134 return t; | 1134 return t; |
| 1135 } | 1135 } |
| 1136 }; | 1136 }; |
| 1137 | 1137 |
| 1138 | 1138 |
| 1139 /** | 1139 /** |
| 1140 * @unrestricted | 1140 * @unrestricted |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1176 * @return {!Promise} | 1176 * @return {!Promise} |
| 1177 */ | 1177 */ |
| 1178 update(glContext, scale) { | 1178 update(glContext, scale) { |
| 1179 this._gl = glContext; | 1179 this._gl = glContext; |
| 1180 this.scale = scale; | 1180 this.scale = scale; |
| 1181 return this.snapshot.replay(null, null, scale).then(imageURL => imageURL &&
UI.loadImage(imageURL)).then(image => { | 1181 return this.snapshot.replay(null, null, scale).then(imageURL => imageURL &&
UI.loadImage(imageURL)).then(image => { |
| 1182 this.texture = image && LayerViewer.LayerTextureManager._createTextureForI
mage(glContext, image); | 1182 this.texture = image && LayerViewer.LayerTextureManager._createTextureForI
mage(glContext, image); |
| 1183 }); | 1183 }); |
| 1184 } | 1184 } |
| 1185 }; | 1185 }; |
| OLD | NEW |