OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // MSVC++ requires this to be set before any other includes to get M_PI. | 5 // MSVC++ requires this to be set before any other includes to get M_PI. |
6 #define _USE_MATH_DEFINES | 6 #define _USE_MATH_DEFINES |
7 | 7 |
8 #include "ui/gfx/transform.h" | 8 #include "ui/gfx/transform.h" |
9 | 9 |
10 #include <cmath> | 10 #include <cmath> |
(...skipping 14 matching lines...) Expand all Loading... | |
25 // Taken from SkMatrix44. | 25 // Taken from SkMatrix44. |
26 const double kTooSmallForDeterminant = 1e-8; | 26 const double kTooSmallForDeterminant = 1e-8; |
27 | 27 |
28 double TanDegrees(double degrees) { | 28 double TanDegrees(double degrees) { |
29 double radians = degrees * M_PI / 180; | 29 double radians = degrees * M_PI / 180; |
30 return std::tan(radians); | 30 return std::tan(radians); |
31 } | 31 } |
32 | 32 |
33 } // namespace | 33 } // namespace |
34 | 34 |
35 Transform::Transform( | |
36 double col1row1, double col2row1, double col3row1, double col4row1, | |
37 double col1row2, double col2row2, double col3row2, double col4row2, | |
38 double col1row3, double col2row3, double col3row3, double col4row3, | |
39 double col1row4, double col2row4, double col3row4, double col4row4) | |
40 : matrix_(SkMatrix44::kUninitialized_Constructor) | |
41 { | |
42 // Initialize column 1 | |
danakj
2013/01/11 04:14:12
nit: i dont think these comments are explaining mu
| |
43 matrix_.setDouble(0, 0, col1row1); | |
44 matrix_.setDouble(1, 0, col1row2); | |
45 matrix_.setDouble(2, 0, col1row3); | |
46 matrix_.setDouble(3, 0, col1row4); | |
47 | |
48 // Initialize column 2 | |
49 matrix_.setDouble(0, 1, col2row1); | |
50 matrix_.setDouble(1, 1, col2row2); | |
51 matrix_.setDouble(2, 1, col2row3); | |
52 matrix_.setDouble(3, 1, col2row4); | |
53 | |
54 // Initialize column 3 | |
55 matrix_.setDouble(0, 2, col3row1); | |
56 matrix_.setDouble(1, 2, col3row2); | |
57 matrix_.setDouble(2, 2, col3row3); | |
58 matrix_.setDouble(3, 2, col3row4); | |
59 | |
60 // Initialize column 4 | |
61 matrix_.setDouble(0, 3, col4row1); | |
62 matrix_.setDouble(1, 3, col4row2); | |
63 matrix_.setDouble(2, 3, col4row3); | |
64 matrix_.setDouble(3, 3, col4row4); | |
65 } | |
66 | |
67 Transform::Transform( | |
68 double col1row1, double col2row1, | |
69 double col1row2, double col2row2, | |
70 double x_translation, double y_translation) | |
danakj
2013/01/11 04:14:12
can you make this call matrix_(SkMatrix44::kIdenti
| |
71 { | |
72 matrix_.setDouble(0, 0, col1row1); | |
73 matrix_.setDouble(1, 0, col1row2); | |
74 matrix_.setDouble(0, 1, col2row1); | |
75 matrix_.setDouble(1, 1, col2row2); | |
76 matrix_.setDouble(0, 3, x_translation); | |
77 matrix_.setDouble(1, 3, y_translation); | |
78 } | |
79 | |
35 void Transform::RotateAboutXAxis(double degrees) { | 80 void Transform::RotateAboutXAxis(double degrees) { |
36 double radians = degrees * M_PI / 180; | 81 double radians = degrees * M_PI / 180; |
37 double cosTheta = std::cos(radians); | 82 double cosTheta = std::cos(radians); |
38 double sinTheta = std::sin(radians); | 83 double sinTheta = std::sin(radians); |
39 if (matrix_.isIdentity()) { | 84 if (matrix_.isIdentity()) { |
40 matrix_.set3x3(1, 0, 0, | 85 matrix_.set3x3(1, 0, 0, |
41 0, cosTheta, sinTheta, | 86 0, cosTheta, sinTheta, |
42 0, -sinTheta, cosTheta); | 87 0, -sinTheta, cosTheta); |
43 } else { | 88 } else { |
44 SkMatrix44 rot; | 89 SkMatrix44 rot; |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
252 return false; | 297 return false; |
253 } | 298 } |
254 | 299 |
255 return true; | 300 return true; |
256 } | 301 } |
257 | 302 |
258 void Transform::Transpose() { | 303 void Transform::Transpose() { |
259 matrix_.transpose(); | 304 matrix_.transpose(); |
260 } | 305 } |
261 | 306 |
307 void Transform::FlattenTo2d() { | |
308 matrix_.setDouble(2, 0, 0.0); | |
309 matrix_.setDouble(2, 1, 0.0); | |
310 matrix_.setDouble(0, 2, 0.0); | |
311 matrix_.setDouble(1, 2, 0.0); | |
312 matrix_.setDouble(2, 2, 1.0); | |
313 matrix_.setDouble(3, 2, 0.0); | |
314 matrix_.setDouble(2, 3, 0.0); | |
315 } | |
316 | |
262 void Transform::TransformPoint(Point& point) const { | 317 void Transform::TransformPoint(Point& point) const { |
263 TransformPointInternal(matrix_, point); | 318 TransformPointInternal(matrix_, point); |
264 } | 319 } |
265 | 320 |
266 void Transform::TransformPoint(Point3F& point) const { | 321 void Transform::TransformPoint(Point3F& point) const { |
267 TransformPointInternal(matrix_, point); | 322 TransformPointInternal(matrix_, point); |
268 } | 323 } |
269 | 324 |
270 bool Transform::TransformPointReverse(Point& point) const { | 325 bool Transform::TransformPointReverse(Point& point) const { |
271 // TODO(sad): Try to avoid trying to invert the matrix. | 326 // TODO(sad): Try to avoid trying to invert the matrix. |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
390 matrix_.getDouble(2, 1), | 445 matrix_.getDouble(2, 1), |
391 matrix_.getDouble(2, 2), | 446 matrix_.getDouble(2, 2), |
392 matrix_.getDouble(2, 3), | 447 matrix_.getDouble(2, 3), |
393 matrix_.getDouble(3, 0), | 448 matrix_.getDouble(3, 0), |
394 matrix_.getDouble(3, 1), | 449 matrix_.getDouble(3, 1), |
395 matrix_.getDouble(3, 2), | 450 matrix_.getDouble(3, 2), |
396 matrix_.getDouble(3, 3)); | 451 matrix_.getDouble(3, 3)); |
397 } | 452 } |
398 | 453 |
399 } // namespace gfx | 454 } // namespace gfx |
OLD | NEW |