Tizen 2.1 base
[framework/osp/uifw.git] / src / ui / effects / inc / FUiEffects_RuntimeGraphicalSurface.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  * @file        FUiEffects_RuntimeGraphicalSurface.h
19  * @brief       This is the header file for the GraphicalSurface class.
20  */
21
22 #ifndef _FUI_EFFECTS_INTERNAL_RUNTIME_GRAPHICAL_SURFACE_H_
23 #define _FUI_EFFECTS_INTERNAL_RUNTIME_GRAPHICAL_SURFACE_H_
24
25 #include <unique_ptr.h>
26 #include <FUiEffects_PeElementSurface.h>
27 #include "FUiEffects_RuntimeModelSurface.h"
28 #include "FUiEffects_RuntimeRenderDataSurface.h"
29
30 namespace Tizen { namespace Ui { namespace Effects { namespace _Runtime
31 {
32
33 /**
34  * @class       GraphicalSurface
35  * @brief       This class is an abstract for any graphical surface
36  *
37  * @since 2.0
38  *
39  */
40 class GraphicalSurface
41         : public ::Tizen::Ui::Effects::_PhysicsEngine::ElementSurface
42 {
43 public:
44         /**
45          * GraphicalSurface class constructor
46          *
47          * @since 2.0
48          *
49          */
50         GraphicalSurface(long objId, long bitmapID_, float transpar_);
51
52         /**
53          * GraphicalSurface class destructor
54          *
55          * @since 2.0
56          *
57          */
58         virtual ~GraphicalSurface(void);
59
60         /**
61          * Initializes GraphicalSurface's internal parameters and resets accumulated parameters to zero
62          *
63          * @since 2.0
64          *
65          * @remarks             Function is inherited from ElementSurface interface
66          */
67         virtual void Initialize(void);
68
69         /**
70          * Updates graphical points based on physical points
71          *
72          * @since 2.0
73          *
74          */
75         virtual void Update(void) = 0;
76
77         /**
78          * Constructs render data collection
79          *
80          * @since 2.0
81          *
82          */
83         virtual void Construct(TypeElemSurfaceCollection* pElemSurfaceCollection, RenderDataSurfaceCollection* pRenderDataSurfaceCollection);
84
85         /**
86          * Constructs z-coordinate of position
87          * based on intersection point of the ray (from camera to point with coordinates (position.x, position.y)) with some triangle of the surface
88          *
89          * @since 2.0
90          *
91          * @remarks             The algorithm consists of several steps:
92          *                              1. Finds triangles from RenderData structure which are crossed by the ray (position.x, position.y)
93          *                              2. Builds planes passing through 3 vertexes triangles which were found on previous step
94          *                              3. Finds z-coordinate of ray with coordinates (position.x, position.y)
95          *                                 which crosses planes which were built on previous step (for receive maximal z-coordinate)
96          */
97         virtual PropertyCast GetNearestPointsIds(Tizen::Ui::Effects::_Utils::Vec3f &position) const;
98
99         /**
100          * Returns the ID of current bitmap for this graphical surface
101          *
102          * @since 2.0
103          *
104          */
105         long GetBitmapId(void) const;
106
107         /**
108          * Sets the bitmap ID for this graphical surface
109          *
110          * @since 2.0
111          *
112          */
113         void SetBitmapId(long bitmapID);
114
115         /**
116          * Provides reading access to GraphicalSurface's properties values from user's scripts
117          *
118          * @since 2.0
119          *
120          */
121         virtual PropertyCast GetProperty(ElementProperty propName) const;
122
123         /**
124          * Provides writing access to GraphicalSurface's properties values of
125          * boolean type from user's scripts
126          *
127          * @since 2.0
128          *
129          */
130         virtual bool SetProperty(ElementProperty propName, bool PropValue);
131
132         /**
133          * Provides writing access to GraphicalSurface's properties values of
134          * lua_Number type (double or float, or integer etc) from user's scripts
135          *
136          * @since 2.0
137          *
138          */
139         virtual bool SetProperty(ElementProperty propName, LUA_NUMBER propValue);
140
141         /**
142          * Provides writing access to GraphicalSurface's properties values of
143          * Vec3f type from user's scripts
144          *
145          * @since 2.0
146          *
147          */
148         virtual bool SetProperty(ElementProperty propName, const Tizen::Ui::Effects::_Utils::Vec3f &propValue);
149
150         /**
151          * Rotates model matrix by Angle around Axis or (ax, ay, az) in case Axis=AXIS_ARBITRARY
152          *
153          * @since 2.0
154          *
155          * @param [in]  Point: Base point for rotation (the coordinates of this point are not changed)
156          * @param [in]  ax, ay, az: The coordinates of axis around which rotation is performed (in case Axis=AXIS_ARBITRARY)
157          * @param [in]  x0, y0, z0: Base point coordinates in case point=POINT_ARBITRARY
158          */
159         virtual bool RotateSurface(float angle, _Axis axis, _Point point,
160                                                            float ax, float ay, float az, float x0, float y0, float z0) = 0;
161
162         /**
163          * Scales model matrix by multipliers ax, ay, az on the relevant axes
164          * with base Point or (x0, y0, z0) in case Point = POINT_ARBITRARY
165          *
166          * @since 2.0
167          *
168          * @remarks             Note that the base point coordinates do not change
169          */
170         virtual bool ScaleSurface(float ax, float ay, float az, _Point point,
171                                                           float x0, float y0, float z0) = 0;
172
173         /**
174          * Translates model matrix to position (x0, y0, z0)
175          *
176          * @since 2.0
177          *
178          */
179         void MoveSurface(float x0, float y0, float z0);
180
181         /**
182          * Sets identity model matrix
183          *
184          * @since 2.0
185          *
186          */
187         void ResetSurfaceTransformation(void);
188
189         /**
190          * Sets model matrix for this graphical surface
191          *
192          * @since 2.0
193          *
194          */
195         void SetTransformationMatrix(const Tizen::Ui::Effects::_Utils::LuaMatrix4& luaMatrix4);
196
197 protected:
198         /**
199          * Rotates model matrix by Angle around Axis or (ax, ay, az) in case Axis=AXIS_ARBITRARY
200          *
201          * @since 2.0
202          *
203          * @remarks             Differs from previous function that do not uses variable Point
204          *                              (it variable already taken into account in variables x0, y0, z0)
205          */
206         bool RotateSurface(float angle, _Axis axis,
207                                                 float ax, float ay, float az, float x0, float y0, float z0);
208
209         /**
210          * Scales model matrix by multipliers ax, ay, az on the relevant axes
211          *                              with base point (x0, y0, z0)
212          *
213          * @since 2.0
214          *
215          * @remarks             Note that the base point coordinates are not changed
216          */
217         bool ScaleSurface(float ax, float ay, float az, float x0, float y0, float z0);
218
219 private:
220         /**
221          * Hidden copy constructor
222          *
223          * @since 2.0
224          *
225          */
226         GraphicalSurface(const GraphicalSurface& rhs);
227
228         /**
229          * Hidden assignment operator
230          *
231          * @since 2.0
232          *
233          */
234         GraphicalSurface &operator=(const GraphicalSurface& rhs);
235
236         /**
237          * Determines whether a point lies inside the triangle with vertexes which are specified by indices
238          *
239          * @since 2.0
240          *
241          * @param [in]  pos The point Cartesian coordinates
242          * @param [in]  i1, i2, i3 The triangle vertex indices
243          *                              (is represented in RenderData::IndicesCollection)
244          * @return              Returns true if point pos lies in the triangle and false otherwise
245          */
246         bool InTriangle(const Tizen::Ui::Effects::_Utils::Vec3f& pos, short i1, short i2, short i3) const;
247
248         /**
249          * Finds the the z-coordinate of the point pos on
250          * the plane passing through the points with indices i1, i2, i3
251          *
252          * @since 2.0
253          *
254          */
255         float ZInPlane(const Tizen::Ui::Effects::_Utils::Vec3f& pos, short i1, short i2, short i3) const;
256
257 protected:
258
259         std::unique_ptr<RenderDataSurface> _pRenderData;                /**< pointer to data for rendering (for this concrete surface)*/
260
261 private:
262         float __initTransparency;                                                               /**< initial value of surface transparency*/
263         long __initBitmapID;                                                                    /**< initial value of bitmap ID*/
264         Tizen::Ui::Effects::_Utils::Mat4f __initModelMtr;
265
266 }; // GraphicalSurface
267
268 } } } } // Tizen::Ui::Effects::_Runtime
269
270 #endif //_FUI_EFFECTS_INTERNAL_RUNTIME_GRAPHICAL_SURFACE_H_