|
1 /* |
|
2 * Copyright (c) 2005 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: Static general reusable methods. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef AMMSUTIL_H |
|
20 #define AMMSUTIL_H |
|
21 |
|
22 // INCLUDES |
|
23 #include <e32base.h> |
|
24 #include "ammsconstants.h" |
|
25 |
|
26 // FORWARD DECLARATIONS |
|
27 class CMMAPlayer; |
|
28 class CMMAControl; |
|
29 |
|
30 // CLASS DECLARATION |
|
31 |
|
32 /** |
|
33 * Static general reusable methods. |
|
34 * |
|
35 * This class contains only static method which can be used in many classes. |
|
36 * |
|
37 * @since 3.0 |
|
38 */ |
|
39 NONSHARABLE_CLASS(AMMSUtil) |
|
40 { |
|
41 public: // New functions |
|
42 /** |
|
43 * Finds the control of a corresponding type that |
|
44 * belongs to the player given as a parameter |
|
45 * |
|
46 * @param aPlayer The Player where to find the Control |
|
47 * @param aControlName Name of the control to look for |
|
48 * @param aControlType Special AMMS type of the Control |
|
49 * @return Control of type aControlName or NULL if not found |
|
50 */ |
|
51 static CMMAControl* FindControl( |
|
52 CMMAPlayer* aPlayer, |
|
53 const TDesC& aControlName, |
|
54 TAMMSControlTypes aControlType = EAMMSBaseControl); |
|
55 |
|
56 /** |
|
57 * Converts vector from spherical to cartesian. |
|
58 * |
|
59 * @param aSphericalVector Spherical vector to be converted |
|
60 * @param aCartesianVector Result cartesian vector |
|
61 */ |
|
62 static void FromSphericalToCartesianL( |
|
63 TInt aSphericalVector[ KAMMSVectorComponents ], |
|
64 TInt aCartesianVector[ KAMMSVectorComponents ]); |
|
65 |
|
66 /* |
|
67 * Rotates a vector round the given axis. The starting point of each |
|
68 * vectors is in the origo, and thus, only coordinates of the ending |
|
69 * point should be given. |
|
70 * |
|
71 * @param aVector X, Y, and Z value of a vector to be rotated |
|
72 * @param aAxisVector X, Y, and Z value of an axis vector |
|
73 * @param aAngle Rotation angle in degrees |
|
74 * @param aRotatedVector X, Y, and Z value of the rotated vector |
|
75 */ |
|
76 static void RotateVectorL(TReal aVector[ KAMMSVectorComponents ], |
|
77 TReal aAxisVector[ KAMMSVectorComponents ], |
|
78 TInt aAngle, |
|
79 TReal aRotatedVector[ KAMMSVectorComponents ]); |
|
80 |
|
81 /** |
|
82 * Rounds each component in the given vector. |
|
83 * |
|
84 * @param aVector A vector to be rounded |
|
85 * @param aRoundedVector Rounded vector |
|
86 */ |
|
87 static void RoundVectorL(TReal aVector[ KAMMSVectorComponents ], |
|
88 TInt aRoundedVector[ KAMMSVectorComponents ]); |
|
89 |
|
90 /** |
|
91 * Multiplies the given vector by the given scalar value. |
|
92 * |
|
93 * @param aVector A vector to be rounded |
|
94 * @param aMultiplier A multiplier |
|
95 */ |
|
96 static void MultiplyVector(TReal aVector[ KAMMSVectorComponents ], |
|
97 TReal aMultiplier); |
|
98 |
|
99 /** |
|
100 * Calculates vector cross product. |
|
101 * @param aA A vector having KAMMSVectorComponents elements |
|
102 * @param aB A vector having KAMMSVectorComponents elements |
|
103 * @param aResultVector Result of the cross product |
|
104 */ |
|
105 static void CrossProduct(TReal aA[ KAMMSVectorComponents ], |
|
106 TReal aB[ KAMMSVectorComponents ], |
|
107 TReal aResultVector[ KAMMSVectorComponents ]); |
|
108 |
|
109 /** |
|
110 * Calculates the length of the given vector. |
|
111 * |
|
112 * @param aVector A vector whose length is calculated |
|
113 */ |
|
114 static TReal VectorLengthL(TReal aVector[ KAMMSVectorComponents ]); |
|
115 |
|
116 /** |
|
117 * Converts the given vector to the unit vector. The original vector |
|
118 * is replaced by the result vector. |
|
119 * |
|
120 * @param aVector A vector that is converted to the unit vector and is |
|
121 * replaced by the result vector |
|
122 */ |
|
123 static void ConvertToUnitVectorL(TReal aVector[ KAMMSVectorComponents ]); |
|
124 |
|
125 /** |
|
126 * Checks whether two given vectors are similar according to the given |
|
127 * maximum error percentage. The function compares each component in |
|
128 * aA to the corresponding component in aB. |
|
129 * |
|
130 * @param aA A vector |
|
131 * @param aB A vector |
|
132 * @param aMaxComponentErrorPercentage Maximum error percentage between |
|
133 * a component in aA and the corresponding component in aB |
|
134 * @return ETrue if difference between each component pair is lower |
|
135 * than the given error, else ETrue is returned |
|
136 */ |
|
137 static TBool AreVectorsSimilar(TReal aA[ KAMMSVectorComponents ], |
|
138 TInt aB[ KAMMSVectorComponents ], |
|
139 TInt aMaxComponentErrorPercentage); |
|
140 |
|
141 /** |
|
142 * Returns the maximum component value in the given vector. |
|
143 * |
|
144 * @param aVector A vector |
|
145 * @return Maximum component value in aVector |
|
146 */ |
|
147 static TReal MaxVectorComponent(TReal aVector[ KAMMSVectorComponents ]); |
|
148 |
|
149 /** |
|
150 * Returns the minimum component value in the given vector. |
|
151 * |
|
152 * @param aVector A vector |
|
153 * @return Minimum component value in aVector |
|
154 */ |
|
155 static TReal MinVectorComponent(TReal aVector[ KAMMSVectorComponents ]); |
|
156 |
|
157 private: |
|
158 /** |
|
159 * C++ default constructor. Private to not allow construction. |
|
160 */ |
|
161 AMMSUtil(); |
|
162 }; |
|
163 |
|
164 #endif // AMMSUTIL_H |
|
165 |
|
166 |