]>
Commit | Line | Data |
---|---|---|
c801d85f KB |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: matrix.h | |
3 | // Purpose: wxTransformMatrix class. NOT YET USED | |
4 | // Author: Chris Breeze, Julian Smart | |
5 | // Modified by: | |
6 | // Created: 01/02/97 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Julian Smart and Markus Holzem | |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #ifndef __MATRIXH__ | |
13 | #define __MATRIXH__ | |
14 | ||
15 | #ifdef __GNUG__ | |
16 | #pragma interface "matrix.h" | |
17 | #endif | |
18 | ||
19 | #include "wx/object.h" | |
20 | ||
21 | // A simple 3x3 matrix. This may be replaced by a more general matrix | |
22 | // class some day. | |
23 | // | |
24 | // Note: this is intended to be used in wxDC at some point to replace | |
25 | // the current system of scaling/translation. It is not yet used. | |
26 | ||
27 | class WXDLLEXPORT wxTransformMatrix: public wxObject | |
28 | { | |
29 | public: | |
30 | wxTransformMatrix(void); | |
31 | wxTransformMatrix(const wxTransformMatrix& mat); | |
32 | ||
33 | double GetValue(int row, int col) const; | |
34 | void SetValue(int row, int col, double value); | |
35 | ||
36 | void operator = (const wxTransformMatrix& mat); | |
37 | bool operator == (const wxTransformMatrix& mat); | |
38 | bool operator != (const wxTransformMatrix& mat); | |
39 | ||
40 | double& operator()(int row, int col); | |
41 | double operator()(int row, int col) const; | |
42 | ||
43 | // Invert matrix | |
44 | bool Invert(void); | |
45 | ||
46 | // Make into identity matrix | |
47 | bool Identity(void); | |
48 | ||
49 | // Is the matrix the identity matrix? | |
50 | // Only returns a flag, which is set whenever an operation | |
51 | // is done. | |
52 | inline bool IsIdentity(void) const { return m_isIdentity; }; | |
53 | ||
54 | // This does an actual check. | |
55 | inline bool IsIdentity1(void) const ; | |
56 | ||
57 | // Isotropic scaling | |
58 | bool Scale(double scale); | |
59 | ||
60 | // Translate | |
61 | bool Translate(double x, double y); | |
62 | ||
63 | // Rotate | |
64 | bool Rotate(double angle); | |
65 | ||
66 | // Transform X value from logical to device | |
67 | inline double TransformX(double x) const; | |
68 | ||
69 | // Transform Y value from logical to device | |
70 | inline double TransformY(double y) const; | |
71 | ||
72 | // Transform a point from logical to device coordinates | |
73 | bool TransformPoint(double x, double y, double& tx, double& ty) const; | |
74 | ||
75 | // Transform a point from device to logical coordinates. | |
76 | ||
77 | // Example of use: | |
78 | // wxTransformMatrix mat = dc.GetTransformation(); | |
79 | // mat.Invert(); | |
80 | // mat.InverseTransformPoint(x, y, x1, y1); | |
81 | // OR (shorthand:) | |
82 | // dc.LogicalToDevice(x, y, x1, y1); | |
83 | // The latter is slightly less efficient if we're doing several | |
84 | // conversions, since the matrix is inverted several times. | |
85 | ||
86 | // N.B. 'this' matrix is the inverse at this point | |
87 | ||
88 | bool InverseTransformPoint(double x, double y, double& tx, double& ty) const; | |
89 | ||
90 | public: | |
91 | double m_matrix[3][3]; | |
92 | bool m_isIdentity; | |
93 | /* | |
94 | double m11, m21, m31; | |
95 | double m12, m22, m32; | |
96 | double m13, m23, m33; | |
97 | */ | |
98 | }; | |
99 | ||
46dc76ba RR |
100 | |
101 | /* | |
102 | The code is wrong and doesn't compile. Chris Breeze als reported, that | |
103 | some functions of wxTransformMatrix cannot work because it is not | |
104 | known if he matrix has been inverted. Be careful when using it. | |
105 | ||
c801d85f KB |
106 | // Transform X value from logical to device |
107 | inline double wxTransformMatrix::TransformX(double x) const | |
108 | { | |
46dc76ba | 109 | return (m_isIdentity ? x : (x * m_matrix[0][0] + y * m_matrix[1][0] + m_matrix[2][0])); |
c801d85f KB |
110 | } |
111 | ||
112 | // Transform Y value from logical to device | |
113 | inline double wxTransformMatrix::TransformY(double y) const | |
114 | { | |
46dc76ba | 115 | return (m_isIdentity ? y : (x * m_matrix[0][1] + y * m_matrix[1][1] + m_matrix[2][1])); |
c801d85f | 116 | } |
46dc76ba | 117 | */ |
c801d85f KB |
118 | |
119 | // Is the matrix the identity matrix? | |
120 | // Perhaps there's some kind of optimization we can do to make this | |
121 | // a faster operation. E.g. each operation (scale, translate etc.) | |
122 | // checks whether it's still the identity matrix and sets a flag. | |
123 | inline bool wxTransformMatrix::IsIdentity1(void) const | |
124 | { | |
125 | return | |
126 | (m_matrix[0][0] == 1.0 && | |
127 | m_matrix[1][1] == 1.0 && | |
128 | m_matrix[2][2] == 1.0 && | |
129 | m_matrix[1][0] == 0.0 && | |
130 | m_matrix[2][0] == 0.0 && | |
131 | m_matrix[0][1] == 0.0 && | |
132 | m_matrix[2][1] == 0.0 && | |
133 | m_matrix[0][2] == 0.0 && | |
134 | m_matrix[1][2] == 0.0) ; | |
135 | } | |
136 | ||
137 | // Calculates the determinant of a 2 x 2 matrix | |
138 | inline double wxCalculateDet(double a11, double a21, double a12, double a22) | |
139 | { | |
140 | return a11 * a22 - a12 * a21; | |
141 | } | |
142 | ||
143 | #endif | |
144 | // __MATRIXH__ |