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 col1row2, double col1row3, double col1row4, |
| 37 double col2row1, double col2row2, double col2row3, double col2row4, |
| 38 double col3row1, double col3row2, double col3row3, double col3row4, |
| 39 double col4row1, double col4row2, double col4row3, double col4row4) |
| 40 : matrix_(SkMatrix44::kUninitialized_Constructor) |
| 41 { |
| 42 // Initialize column 1 |
| 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 col1row2, double col2row1, |
| 69 double col2row2, double x_translation, double y_translation) |
| 70 { |
| 71 matrix_.setDouble(0, 0, col1row1); |
| 72 matrix_.setDouble(1, 0, col1row2); |
| 73 matrix_.setDouble(0, 1, col2row1); |
| 74 matrix_.setDouble(1, 1, col2row2); |
| 75 matrix_.setDouble(0, 3, x_translation); |
| 76 matrix_.setDouble(1, 3, y_translation); |
| 77 } |
| 78 |
35 void Transform::RotateAboutXAxis(double degrees) { | 79 void Transform::RotateAboutXAxis(double degrees) { |
36 double radians = degrees * M_PI / 180; | 80 double radians = degrees * M_PI / 180; |
37 double cosTheta = std::cos(radians); | 81 double cosTheta = std::cos(radians); |
38 double sinTheta = std::sin(radians); | 82 double sinTheta = std::sin(radians); |
39 if (matrix_.isIdentity()) { | 83 if (matrix_.isIdentity()) { |
40 matrix_.set3x3(1, 0, 0, | 84 matrix_.set3x3(1, 0, 0, |
41 0, cosTheta, sinTheta, | 85 0, cosTheta, sinTheta, |
42 0, -sinTheta, cosTheta); | 86 0, -sinTheta, cosTheta); |
43 } else { | 87 } else { |
44 SkMatrix44 rot; | 88 SkMatrix44 rot; |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
252 return false; | 296 return false; |
253 } | 297 } |
254 | 298 |
255 return true; | 299 return true; |
256 } | 300 } |
257 | 301 |
258 void Transform::Transpose() { | 302 void Transform::Transpose() { |
259 matrix_.transpose(); | 303 matrix_.transpose(); |
260 } | 304 } |
261 | 305 |
| 306 void Transform::FlattenTo2d() { |
| 307 matrix_.setDouble(2, 0, 0.0); |
| 308 matrix_.setDouble(2, 1, 0.0); |
| 309 matrix_.setDouble(0, 2, 0.0); |
| 310 matrix_.setDouble(1, 2, 0.0); |
| 311 matrix_.setDouble(2, 2, 1.0); |
| 312 matrix_.setDouble(3, 2, 0.0); |
| 313 matrix_.setDouble(2, 3, 0.0); |
| 314 } |
| 315 |
262 void Transform::TransformPoint(Point& point) const { | 316 void Transform::TransformPoint(Point& point) const { |
263 TransformPointInternal(matrix_, point); | 317 TransformPointInternal(matrix_, point); |
264 } | 318 } |
265 | 319 |
266 void Transform::TransformPoint(Point3F& point) const { | 320 void Transform::TransformPoint(Point3F& point) const { |
267 TransformPointInternal(matrix_, point); | 321 TransformPointInternal(matrix_, point); |
268 } | 322 } |
269 | 323 |
270 bool Transform::TransformPointReverse(Point& point) const { | 324 bool Transform::TransformPointReverse(Point& point) const { |
271 // TODO(sad): Try to avoid trying to invert the matrix. | 325 // 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), | 444 matrix_.getDouble(2, 1), |
391 matrix_.getDouble(2, 2), | 445 matrix_.getDouble(2, 2), |
392 matrix_.getDouble(2, 3), | 446 matrix_.getDouble(2, 3), |
393 matrix_.getDouble(3, 0), | 447 matrix_.getDouble(3, 0), |
394 matrix_.getDouble(3, 1), | 448 matrix_.getDouble(3, 1), |
395 matrix_.getDouble(3, 2), | 449 matrix_.getDouble(3, 2), |
396 matrix_.getDouble(3, 3)); | 450 matrix_.getDouble(3, 3)); |
397 } | 451 } |
398 | 452 |
399 } // namespace gfx | 453 } // namespace gfx |
OLD | NEW |