|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 #ifndef HUIFXVG10TRANSFORMFILTER_H_ |
|
19 #define HUIFXVG10TRANSFORMFILTER_H_ |
|
20 |
|
21 #include <math.h> |
|
22 #include "HuiFxVg10FilterBase.h" |
|
23 |
|
24 class CHuiFxVg10TransformFilter: public CHuiFxVg10FilterBase |
|
25 { |
|
26 public: // from CHuiFxFilter |
|
27 virtual TBool Draw(CHuiFxEngine& aEngine, CHuiGc& aGc, |
|
28 CHuiFxRenderbuffer& aTarget, CHuiFxRenderbuffer& aSource, |
|
29 const TRect& aTargetRect, const TRect& aSourceRect); |
|
30 static CHuiFxVg10TransformFilter* NewL(); |
|
31 void DrawEffect(CHuiFxEngine& /*aEngine*/, VGImage /*aTargetImage*/, VGImage /*aSourceImage*/, TInt /*aWidth*/, TInt /*aHeight*/) {} |
|
32 void CalculateMargin(TMargins &aMargin) const; |
|
33 CHuiFxVg10TransformFilter *CloneL() const; |
|
34 protected: |
|
35 void ConstructL(); |
|
36 |
|
37 void identity() |
|
38 { |
|
39 iMatrix [0] = 1.f; iMatrix [1] = 0.f; iMatrix [2] = 0.f; iMatrix [3] = 0.f; |
|
40 iMatrix [4] = 0.f; iMatrix [5] = 1.f; iMatrix [6] = 0.f; iMatrix [7] = 0.f; |
|
41 iMatrix [8] = 0.f; iMatrix [9] = 0.f; iMatrix[10] = 1.f; iMatrix[11] = 0.f; |
|
42 iMatrix[12] = 0.f; iMatrix[13] = 0.f; iMatrix[14] = 0.f; iMatrix[15] = 1.f; |
|
43 } |
|
44 |
|
45 void translate(TReal32 tx, TReal32 ty, TReal32 tz) |
|
46 { |
|
47 const TReal32 tm[16] = |
|
48 { |
|
49 1.f, 0.f, 0.f, 0.f, |
|
50 0.f, 1.f, 0.f, 0.f, |
|
51 0.f, 0.f, 1.f, 0.f, |
|
52 tx, ty, tz, 1.f |
|
53 }; |
|
54 |
|
55 multiply(tm); |
|
56 } |
|
57 |
|
58 void scale (const TReal32 sx, const TReal32 sy, const TReal32 sz) |
|
59 { |
|
60 const TReal32 sm[16] = |
|
61 { |
|
62 sx, 0.f, 0.f, 0.f, |
|
63 0.f, sy, 0.f, 0.f, |
|
64 0.f, 0.f, sz, 0.f, |
|
65 0.f, 0.f, 0.f, 1.f |
|
66 }; |
|
67 |
|
68 multiply(sm); |
|
69 } |
|
70 |
|
71 void rotate (const TReal32 angle, const TReal32 x, const TReal32 y, const TReal32 z) |
|
72 { |
|
73 static const TReal32 deg_to_rad = 2.f * (TReal32)M_PI / 360.f; |
|
74 // normalised vector components |
|
75 TReal32 x_n; |
|
76 TReal32 y_n; |
|
77 TReal32 z_n; |
|
78 TReal32 angle_rad = angle * deg_to_rad; |
|
79 |
|
80 // normalise if needed |
|
81 const TReal32 length = (TReal32)sqrt(double(x * x) + |
|
82 double(y * y) + |
|
83 double(z * z)); |
|
84 if(fabs(length - 1.0f) > EPSILON) { |
|
85 // in fp calculations, division by zero -> (+/-)inf |
|
86 // can't really help if it's the case. |
|
87 const TReal32 inv_length = 1.f / length; |
|
88 x_n = x * inv_length; |
|
89 y_n = y * inv_length; |
|
90 z_n = z * inv_length; |
|
91 } else { |
|
92 x_n = x; |
|
93 y_n = y; |
|
94 z_n = z; |
|
95 } |
|
96 |
|
97 const TReal32 c = cos(angle_rad); |
|
98 const TReal32 s = sin(angle_rad); |
|
99 const TReal32 c_1 = 1.f - c; |
|
100 |
|
101 const TReal32 rm[16] = |
|
102 { |
|
103 x_n * x_n * c_1 + c, y_n * x_n * c_1 + z_n * s, x_n * z_n * c_1 - y_n * s, 0.f, |
|
104 x_n * y_n * c_1 - z_n * s, y_n * y_n * c_1 + c, y_n * z_n * c_1 + x_n * s, 0.f, |
|
105 x_n * z_n * c_1 + y_n * s, y_n * z_n * c_1 - x_n * s, z_n * z_n * c_1 + c, 0.f, |
|
106 0.f, 0.f, 0.f, 1.f |
|
107 }; |
|
108 |
|
109 multiply(rm); |
|
110 } |
|
111 |
|
112 void frustum (const TReal32 l, const TReal32 r, const TReal32 b, const TReal32 t, const TReal32 n, const TReal32 f) |
|
113 { |
|
114 const TReal32 rl = 1.f / (r - l); |
|
115 const TReal32 tb = 1.f / (t - b); |
|
116 const TReal32 fn = 1.f / (f - n); |
|
117 |
|
118 const TReal32 A = (r + l) * rl; |
|
119 const TReal32 B = (t + b) * tb; |
|
120 const TReal32 C = -(f + n) * fn; |
|
121 const TReal32 D = -2.f * f * n * fn; |
|
122 |
|
123 const TReal32 fm[16] = |
|
124 { |
|
125 2.f * n * rl, 0.f, 0.f, 0.f, |
|
126 0.f, 2.f * n * tb, 0.f, 0.f, |
|
127 A, B, C, -1.f, |
|
128 0.f, 0.f, D, 0.f |
|
129 }; |
|
130 |
|
131 multiply(fm); |
|
132 } |
|
133 |
|
134 void multiply (const TReal32* b) |
|
135 { |
|
136 TReal32 dst[16]; |
|
137 for (int i = 0; i < 4; i++) |
|
138 { |
|
139 for (int j = 0; j < 4; j++) |
|
140 { |
|
141 TReal32 sum = 0.f; |
|
142 for (int k = 0; k < 4; k++) |
|
143 sum += iMatrix[i + 4 * k] * b[k + 4 * j]; |
|
144 |
|
145 dst[i + 4 * j] = sum; |
|
146 } |
|
147 } |
|
148 |
|
149 for (int i = 0; i < 16; i++) |
|
150 iMatrix[i] = dst[i]; |
|
151 } |
|
152 |
|
153 void shear (const TReal32 aX, const TReal32 aY, const TReal32 aZ) |
|
154 { |
|
155 TReal32 shearMatrix[16] = |
|
156 { |
|
157 1.0f, aX, aX, 0.0f, |
|
158 aY, 1.0f, aY, 0.0f, |
|
159 aZ, aZ, 1.0f, 0.0f, |
|
160 0.0f, 0.0f, 0.0f, 1.0f, |
|
161 }; |
|
162 |
|
163 multiply(shearMatrix); |
|
164 |
|
165 } |
|
166 |
|
167 private: |
|
168 TReal32 iTranslationX; |
|
169 TReal32 iTranslationY; |
|
170 TReal32 iTranslationZ; |
|
171 |
|
172 TReal32 iScaleX; |
|
173 TReal32 iScaleY; |
|
174 TReal32 iScaleZ; |
|
175 TReal32 iScaleOriginX; |
|
176 TReal32 iScaleOriginY; |
|
177 TReal32 iScaleOriginZ; |
|
178 |
|
179 TReal32 iRotationOriginX; |
|
180 TReal32 iRotationOriginY; |
|
181 TReal32 iRotationOriginZ; |
|
182 TReal32 iRotationAngle; |
|
183 TReal32 iRotationAxisX; |
|
184 TReal32 iRotationAxisY; |
|
185 TReal32 iRotationAxisZ; |
|
186 |
|
187 TReal32 iSkewAngleX; |
|
188 TReal32 iSkewAngleY; |
|
189 TReal32 iSkewAngleZ; |
|
190 TReal32 iSkewOriginX; |
|
191 TReal32 iSkewOriginY; |
|
192 TReal32 iSkewOriginZ; |
|
193 |
|
194 TReal32 iMatrix[16]; |
|
195 }; |
|
196 |
|
197 #endif |