OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2005, 2006 Apple Computer, Inc. All rights reserved. | 2 * Copyright (C) 2005, 2006 Apple Computer, Inc. All rights reserved. |
3 * Copyright (C) 2009 Torch Mobile, Inc. | 3 * Copyright (C) 2009 Torch Mobile, Inc. |
4 * Copyright (C) 2013 Google Inc. All rights reserved. | 4 * Copyright (C) 2013 Google Inc. All rights reserved. |
5 * | 5 * |
6 * Redistribution and use in source and binary forms, with or without | 6 * Redistribution and use in source and binary forms, with or without |
7 * modification, are permitted provided that the following conditions | 7 * modification, are permitted provided that the following conditions |
8 * are met: | 8 * are met: |
9 * 1. Redistributions of source code must retain the above copyright | 9 * 1. Redistributions of source code must retain the above copyright |
10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
(...skipping 615 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
626 TransformationMatrix::TransformationMatrix(const AffineTransform& t) | 626 TransformationMatrix::TransformationMatrix(const AffineTransform& t) |
627 { | 627 { |
628 setMatrix(t.a(), t.b(), t.c(), t.d(), t.e(), t.f()); | 628 setMatrix(t.a(), t.b(), t.c(), t.d(), t.e(), t.f()); |
629 } | 629 } |
630 | 630 |
631 TransformationMatrix& TransformationMatrix::scale(double s) | 631 TransformationMatrix& TransformationMatrix::scale(double s) |
632 { | 632 { |
633 return scaleNonUniform(s, s); | 633 return scaleNonUniform(s, s); |
634 } | 634 } |
635 | 635 |
636 TransformationMatrix& TransformationMatrix::rotateFromVector(double x, double y) | |
637 { | |
638 return rotate(rad2deg(atan2(y, x))); | |
639 } | |
640 | |
641 TransformationMatrix& TransformationMatrix::flipX() | |
642 { | |
643 return scaleNonUniform(-1.0, 1.0); | |
644 } | |
645 | |
646 TransformationMatrix& TransformationMatrix::flipY() | |
647 { | |
648 return scaleNonUniform(1.0, -1.0); | |
649 } | |
650 | |
651 FloatPoint TransformationMatrix::projectPoint(const FloatPoint& p, bool* clamped
) const | 636 FloatPoint TransformationMatrix::projectPoint(const FloatPoint& p, bool* clamped
) const |
652 { | 637 { |
653 // This is basically raytracing. We have a point in the destination | 638 // This is basically raytracing. We have a point in the destination |
654 // plane with z=0, and we cast a ray parallel to the z-axis from that | 639 // plane with z=0, and we cast a ray parallel to the z-axis from that |
655 // point to find the z-position at which it intersects the z=0 plane | 640 // point to find the z-position at which it intersects the z=0 plane |
656 // with the transform applied. Once we have that point we apply the | 641 // with the transform applied. Once we have that point we apply the |
657 // inverse transform to find the corresponding point in the source | 642 // inverse transform to find the corresponding point in the source |
658 // space. | 643 // space. |
659 // | 644 // |
660 // Given a plane with normal Pn, and a ray starting at point R0 and | 645 // Given a plane with normal Pn, and a ray starting at point R0 and |
(...skipping 973 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1634 if (m_matrix[3][2]) | 1619 if (m_matrix[3][2]) |
1635 return false; | 1620 return false; |
1636 | 1621 |
1637 // Check for non-integer translate X/Y. | 1622 // Check for non-integer translate X/Y. |
1638 if (static_cast<int>(m_matrix[3][0]) != m_matrix[3][0] || static_cast<int>(m
_matrix[3][1]) != m_matrix[3][1]) | 1623 if (static_cast<int>(m_matrix[3][0]) != m_matrix[3][0] || static_cast<int>(m
_matrix[3][1]) != m_matrix[3][1]) |
1639 return false; | 1624 return false; |
1640 | 1625 |
1641 return true; | 1626 return true; |
1642 } | 1627 } |
1643 | 1628 |
1644 TransformationMatrix TransformationMatrix::to2dTransform() const | |
1645 { | |
1646 return TransformationMatrix(m_matrix[0][0], m_matrix[0][1], 0, m_matrix[0][3
], | |
1647 m_matrix[1][0], m_matrix[1][1], 0, m_matrix[1][3
], | |
1648 0, 0, 1, 0, | |
1649 m_matrix[3][0], m_matrix[3][1], 0, m_matrix[3][3
]); | |
1650 } | |
1651 | |
1652 FloatSize TransformationMatrix::to2DTranslation() const | 1629 FloatSize TransformationMatrix::to2DTranslation() const |
1653 { | 1630 { |
1654 ASSERT(isIdentityOr2DTranslation()); | 1631 ASSERT(isIdentityOr2DTranslation()); |
1655 return FloatSize(m_matrix[3][0], m_matrix[3][1]); | 1632 return FloatSize(m_matrix[3][0], m_matrix[3][1]); |
1656 } | 1633 } |
1657 | 1634 |
1658 void TransformationMatrix::toColumnMajorFloatArray(FloatMatrix4& result) const | 1635 void TransformationMatrix::toColumnMajorFloatArray(FloatMatrix4& result) const |
1659 { | 1636 { |
1660 result[0] = m11(); | 1637 result[0] = m11(); |
1661 result[1] = m12(); | 1638 result[1] = m12(); |
(...skipping 29 matching lines...) Expand all Loading... |
1691 ret.setDouble(2, 2, matrix.m33()); | 1668 ret.setDouble(2, 2, matrix.m33()); |
1692 ret.setDouble(2, 3, matrix.m43()); | 1669 ret.setDouble(2, 3, matrix.m43()); |
1693 ret.setDouble(3, 0, matrix.m14()); | 1670 ret.setDouble(3, 0, matrix.m14()); |
1694 ret.setDouble(3, 1, matrix.m24()); | 1671 ret.setDouble(3, 1, matrix.m24()); |
1695 ret.setDouble(3, 2, matrix.m34()); | 1672 ret.setDouble(3, 2, matrix.m34()); |
1696 ret.setDouble(3, 3, matrix.m44()); | 1673 ret.setDouble(3, 3, matrix.m44()); |
1697 return ret; | 1674 return ret; |
1698 } | 1675 } |
1699 | 1676 |
1700 } | 1677 } |
OLD | NEW |