|
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: AknPhysics engine |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef C_AKNPHYSICSENGINE_H |
|
20 #define C_AKNPHYSICSENGINE_H |
|
21 |
|
22 |
|
23 #include <e32base.h> |
|
24 #include <ode/ode.h> |
|
25 |
|
26 class CAknPhysics; |
|
27 class RAlfDirectClient; |
|
28 |
|
29 /** |
|
30 * Physics engine |
|
31 * |
|
32 * @lib aknphysics |
|
33 * @since S60 v5.0 |
|
34 */ |
|
35 NONSHARABLE_CLASS( CAknPhysicsEngine ) : public CBase |
|
36 { |
|
37 |
|
38 public: |
|
39 |
|
40 /** |
|
41 * Collision definitions. |
|
42 */ |
|
43 enum TAknPhysicsCollision |
|
44 { |
|
45 EAknPhysicsNoCollision, |
|
46 EAknPhysicsBottomCollision, |
|
47 EAknPhysicsTopCollision |
|
48 }; |
|
49 |
|
50 /** |
|
51 * Two-phased constructor. |
|
52 */ |
|
53 static CAknPhysicsEngine* NewL( CAknPhysics* aPhysics ); |
|
54 |
|
55 /** |
|
56 * Two-phased constructor. |
|
57 */ |
|
58 static CAknPhysicsEngine* NewLC( CAknPhysics* aPhysics ); |
|
59 |
|
60 /** |
|
61 * Destructor. |
|
62 */ |
|
63 virtual ~CAknPhysicsEngine(); |
|
64 |
|
65 /** |
|
66 * Return ETrue if ODE world exists. |
|
67 * |
|
68 * @return ETrue if ODE world exists. |
|
69 */ |
|
70 TBool WorldExists() const; |
|
71 |
|
72 /** |
|
73 * Creates ODE world. |
|
74 * |
|
75 * @param aGravity World gravity factor. |
|
76 */ |
|
77 void CreateWorld( const TInt& aGravity ); |
|
78 |
|
79 /** |
|
80 * Creates ODE planes. |
|
81 * |
|
82 * @param aIh |
|
83 * @param aX |
|
84 * @param aY |
|
85 * @param aR |
|
86 */ |
|
87 void CreatePlanes( const TInt64& aIh, |
|
88 const TInt64& aX, |
|
89 const TInt64& aY, |
|
90 const TInt64& aR ); |
|
91 |
|
92 /** |
|
93 * Creates ODE view body. |
|
94 * |
|
95 * @param aWidth View width. |
|
96 * @param aHeight View height. |
|
97 * @param aMass View mass. |
|
98 */ |
|
99 void CreateViewBody( const TInt64& aWidth, |
|
100 const TInt64& aHeight, |
|
101 const TInt64& aMass ); |
|
102 |
|
103 /** |
|
104 * Set view body position. |
|
105 * |
|
106 * @param aPosition View body position. |
|
107 */ |
|
108 void SetViewBodyPosition( const TPoint& aPosition ); |
|
109 |
|
110 /** |
|
111 * Get view body position. |
|
112 * |
|
113 * @param aPosition New view body position. |
|
114 */ |
|
115 void GetViewBodyPosition( TPoint& aPosition ); |
|
116 |
|
117 /** |
|
118 * Resets view body force and velocity. |
|
119 */ |
|
120 void ResetViewBodyForceAndVelocity(); |
|
121 |
|
122 /** |
|
123 * Enables view body. |
|
124 */ |
|
125 void EnableViewBody(); |
|
126 |
|
127 /** |
|
128 * Returns ETrue if view body is enabled. |
|
129 * |
|
130 * @return ETrue if view body is enabled. |
|
131 */ |
|
132 TBool IsViewBodyEnabled() const; |
|
133 |
|
134 /** |
|
135 * Applies force factor. |
|
136 * |
|
137 * @param aDrag Dragging distance. |
|
138 * @param aMoveTime Dragging move time. |
|
139 */ |
|
140 void ApplyDragForce( const TPoint& aDrag, |
|
141 const TInt& aMoveTime ); |
|
142 |
|
143 /** |
|
144 * Returns collision state. |
|
145 * |
|
146 * @return Collision state. |
|
147 */ |
|
148 const TAknPhysicsCollision& CollisionState(); |
|
149 |
|
150 /** |
|
151 * Resets collision state. |
|
152 */ |
|
153 void ResetCollisionState(); |
|
154 |
|
155 /** |
|
156 * Takes physics step. |
|
157 */ |
|
158 void TakePhysicsStep(); |
|
159 |
|
160 /** |
|
161 * Deletes physics. |
|
162 */ |
|
163 void DeletePhysics(); |
|
164 |
|
165 /** |
|
166 * Sets friction. |
|
167 * |
|
168 * @param aFriction New friction value. |
|
169 */ |
|
170 void SetFriction( TReal aFriction ); |
|
171 |
|
172 /** |
|
173 * Resets friction. |
|
174 */ |
|
175 void ResetFriction(); |
|
176 |
|
177 /** |
|
178 * Starts FPS logging. |
|
179 */ |
|
180 void StartFpsLogging(); |
|
181 |
|
182 /** |
|
183 * Stops FPS logging. |
|
184 */ |
|
185 void StopFpsLogging(); |
|
186 |
|
187 private: |
|
188 |
|
189 /** |
|
190 * C++ constructor. |
|
191 */ |
|
192 CAknPhysicsEngine( CAknPhysics* aPhysics ); |
|
193 |
|
194 /** |
|
195 * Symbian second-phase constructor. |
|
196 */ |
|
197 void ConstructL(); |
|
198 |
|
199 /** |
|
200 * Physics collision step callback function. |
|
201 * |
|
202 * @param aData Pointer to CAknPhysicsEngine instance. |
|
203 * @param o0 |
|
204 * @param o1 |
|
205 */ |
|
206 static void CallbackFunc( void* aData, dGeomID o0, dGeomID o1 ); |
|
207 |
|
208 /** |
|
209 * Physics collision handling function. |
|
210 * |
|
211 * @param o0 |
|
212 * @param o1 |
|
213 */ |
|
214 void HandleCollisionBetween( dGeomID aObject1, dGeomID aObject2 ); |
|
215 |
|
216 private: // data |
|
217 |
|
218 /** |
|
219 * ODE world. |
|
220 */ |
|
221 dWorldID iWorldId; |
|
222 |
|
223 /** |
|
224 * ODE collision space. |
|
225 */ |
|
226 dSpaceID iSpace; |
|
227 |
|
228 /** |
|
229 * ODE collision contact group. |
|
230 */ |
|
231 dJointGroupID iContactGroup; |
|
232 |
|
233 /** |
|
234 * ODE top plane. |
|
235 */ |
|
236 dGeomID iPlaneTop; |
|
237 |
|
238 /** |
|
239 * ODE bottom plane. |
|
240 */ |
|
241 dGeomID iPlaneBottom; |
|
242 |
|
243 /** |
|
244 * ODE left plane. |
|
245 */ |
|
246 dGeomID iPlaneLeft; |
|
247 |
|
248 /** |
|
249 * ODE right plane. |
|
250 */ |
|
251 dGeomID iPlaneRight; |
|
252 |
|
253 /** |
|
254 * ODE friction plane. |
|
255 */ |
|
256 dGeomID iPlaneFriction; |
|
257 |
|
258 /** |
|
259 * ODE view box geom. |
|
260 */ |
|
261 dGeomID iViewBox; |
|
262 |
|
263 /** |
|
264 * ODE view box body. |
|
265 */ |
|
266 dBodyID iViewBody; |
|
267 |
|
268 /** |
|
269 * Collision state. |
|
270 */ |
|
271 TAknPhysicsCollision iCollision; |
|
272 |
|
273 /** |
|
274 * Friction value. |
|
275 */ |
|
276 TReal iFriction; |
|
277 |
|
278 /** |
|
279 * Pointer to CAknPhysics. |
|
280 * Not own. |
|
281 */ |
|
282 CAknPhysics* iPhysics; |
|
283 |
|
284 /** |
|
285 * View position. |
|
286 */ |
|
287 TPoint iViewPosition; |
|
288 |
|
289 /** |
|
290 * Client to Alf, used for FPS logging. |
|
291 * Own. |
|
292 */ |
|
293 RAlfDirectClient* iAlfClient; |
|
294 |
|
295 /** |
|
296 * Using application's UID. Used for FPS logging. |
|
297 */ |
|
298 TUid iLogUid; |
|
299 }; |
|
300 |
|
301 #endif // C_AKNPHYSICSENGINE_H |