Tizen 2.1 base
[framework/osp/uifw.git] / src / ui / inc / FUiAnim_TransformMatrix3Df.h
1 //
2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Flora License, Version 1.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://floralicense.org/license/
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an AS IS BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17
18 /**
19  * @file        FUiAnim_TransformMatrix3Df.h
20  * @brief       Header file of _TransformMatrix3Df class
21  *
22  * This file contains declarations _TransformMatrix3Df class.
23  */
24
25 #ifndef _FUI_ANIM_INTERNAL_TRANSFORM_MATRIX3DF_H_
26 #define _FUI_ANIM_INTERNAL_TRANSFORM_MATRIX3DF_H_
27
28 #include <FBaseSysLog.h>
29 #include <FGrpFloatMatrix4.h>
30
31 namespace Tizen { namespace Ui { namespace Animations {
32
33 enum Matrix4Type
34 {
35         MATRIX4_Identity,
36         MATRIX4_Translation,
37         MATRIX4_Scale,
38         MATRIX4_Generic
39 };
40
41 class _OSP_EXPORT_ _TransformMatrix3Df
42 {
43 public:
44         _TransformMatrix3Df(void);
45         ~_TransformMatrix3Df(void);
46
47 public:
48         void Clear(void);
49         bool SetTransformMatrix(const Tizen::Graphics::FloatMatrix4& transformMatrix);
50         Tizen::Graphics::FloatMatrix4 GetTransformMatrix(void) const;
51         Tizen::Graphics::FloatMatrix4 Interpolate(const _TransformMatrix3Df& transformMatrixFrom, float progress) const;
52
53         void UpdateRotationFromEulerAngles(float x, float y, float z);
54
55         void GetEulerAngles(float& x, float& y, float& z) const;
56         void GetQuaternion(float& x, float& y, float& z, float& w) const;
57         void GetRotationAnchor(float& x, float& y, float& z) const;
58         void SetRotationAnchor(float x, float y, float z);
59         void GetScaleFactors(float& x, float& y, float& z) const;
60         void SetScaleFactors(float x, float y, float z);
61         void GetScaleAnchor(float& x, float& y, float& z) const;
62         void SetScaleAnchor(float x, float y, float z);
63         void GetShearFactors(float& xy, float& xz, float& yz) const;
64         void SetShearFactors(float xy, float xz, float yz);
65         void GetTranslationFactors(float& x, float& y, float& z) const;
66         void SetTranslationFactors(float x, float y, float z);
67         void GetPerspectiveFactors(float& x, float& y, float& z, float& w) const;
68         void SetPerspectiveFactors(float x, float y, float z, float w);
69
70         Matrix4Type GetMatrixType(void) const
71         {
72                 return __transformType;
73         }
74
75 private:
76         class Vector3Df
77         {
78         public:
79                 Vector3Df(void)
80                         : x(0.0f), y(0.0f), z(0.0f)
81                 {
82                 }
83
84                 float GetSquaredLength(void) const
85                 {
86                         return ((x * x) + (y * y) + (z * z));
87                 }
88
89                 float GetLength(void) const
90                 {
91                         return (sqrtf(GetSquaredLength()));
92                 }
93
94                 void Scale(float newLength)
95                 {
96                         float length = GetLength();
97
98                         if (length != 0.0f)
99                         {
100                         x *= newLength / length;
101                                 y *= newLength / length;
102                                 z *= newLength / length;
103                         }
104                 }
105
106                 float Dot(const Vector3Df& vector3D) const
107                 {
108                     return ((x * vector3D.x) + (y * vector3D.y) + (z * vector3D.z));
109                 }
110
111                 Vector3Df Cross(const Vector3Df& vector3D) const
112                 {
113                         Vector3Df cross;
114                         cross.x = (y * vector3D.z) - (z * vector3D.y);
115                         cross.y = (z * vector3D.x) - (x * vector3D.z);
116                         cross.z = (x * vector3D.y) - (y * vector3D.x);
117                         return cross;
118                 }
119
120                 static void Combine(Vector3Df& result, const Vector3Df& a, const Vector3Df& b, float ascl, float bscl)
121                 {
122                         result.x = (ascl * a.x) + (bscl * b.x);
123                         result.y = (ascl * a.y) + (bscl * b.y);
124                         result.z = (ascl * a.z) + (bscl * b.z);
125                 }
126
127
128         public:
129                 float x, y, z;
130         };
131
132         class Vector4Df
133         {
134         public:
135                 Vector4Df(void)
136                         : x(0.0f), y(0.0f), z(0.0f), w(0.0f)
137                 {
138                 }
139
140                 Vector4Df Transform(const Tizen::Graphics::FloatMatrix4& m) const
141                 {
142                         Vector4Df outputVector;
143
144                 /*
145                         outputVector.x = (pin.x * m.Get(0, 0)) + (pin.y * m.Get(1, 0)) + (pin.z * m.Get(2, 0)) + (pin.w * m.Get(3, 0));
146                         outputVector.y = (pin.x * m.Get(0, 1)) + (pin.y * m.Get(1, 1)) + (pin.z * m.Get(2, 1)) + (pin.w * m.Get(3, 1));
147                         outputVector.z = (pin.x * m.Get(0, 2)) + (pin.y * m.Get(1, 2)) + (pin.z * m.Get(2, 2)) + (pin.w * m.Get(3, 2));
148                         outputVector.w = (pin.x * m.Get(0, 3)) + (pin.y * m.Get(1, 3)) + (pin.z * m.Get(2, 3)) + (pin.w * m.Get(3, 3));
149                 */
150
151                         outputVector.x = (x * m.matrix[0][0]) + (y * m.matrix[0][1]) + (z * m.matrix[0][2]) + (w * m.matrix[0][3]);
152                         outputVector.y = (x * m.matrix[1][0]) + (y * m.matrix[1][1]) + (z * m.matrix[1][2]) + (w * m.matrix[1][3]);
153                         outputVector.z = (x * m.matrix[2][0]) + (y * m.matrix[2][1]) + (z * m.matrix[2][2]) + (w * m.matrix[2][3]);
154                         outputVector.w = (x * m.matrix[3][0]) + (y * m.matrix[3][1]) + (z * m.matrix[3][2]) + (w * m.matrix[3][3]);
155
156                         return outputVector;
157                 }
158
159         public:
160                 float x, y, z, w;
161         };
162
163         void DoSlerp(float* result, const float* src1, const float* src2, float t) const;
164 #if 0
165         void CalcEulerAngles(void);
166 #endif
167 #if 0
168         void V4MulPointByMatrix(const _Vector4Df& pin, const Tizen::Graphics::FloatMatrix4& m, _Vector4Df& pout) const;
169         float V3SquaredLength(const _Vector3Df& v) const;
170         float V3Length(const _Vector3Df& v) const;
171         void V3Scale(_Vector3Df& v, float newlen) const;
172         float V3Dot(const _Vector3Df& a, const _Vector3Df& b) const;
173         void V3Combine(const _Vector3Df& a, const _Vector3Df& b, _Vector3Df& result, float ascl, float bscl) const;
174         void V3Cross(const _Vector3Df& a, const _Vector3Df& b, _Vector3Df& c) const;
175 #endif
176
177         void UpdateMatrixType(bool fullCheck);
178
179 private:
180         Matrix4Type __transformType;
181         bool __usePerspective;
182         bool __useScale;
183         bool __useShear;
184         bool __useRotation;
185         bool __useTranslation;
186
187         float __scaleX, __scaleY, __scaleZ;
188         float __shearXY, __shearXZ, __shearYZ;
189         float __quatX, __quatY, __quatZ, __quatW;
190         float __translationX, __translationY, __translationZ;
191         float __perspectiveX, __perspectiveY, __perspectiveZ, __perspectiveW;
192
193         float __rotAnchorX, __rotAnchorY, __rotAnchorZ;
194         float __scaleAnchorX, __scaleAnchorY, __scaleAnchorZ;
195
196         float __rotX, __rotY, __rotZ; // in degree-unit
197 };              // _TransformMatrix3Df
198
199 }}}             // Tizen::Ui::Animations
200
201 #endif  // _FUI_ANIM_INTERNAL_TRANSFORM_MATRIX3DF_H_
202