1 | // Copyright (C) 2021 The Qt Company Ltd. |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
3 | |
4 | #include "qquick3dparticleutils_p.h" |
5 | #include <QtQuick3D/private/qquick3dnode_p.h> |
6 | |
7 | QT_BEGIN_NAMESPACE |
8 | |
9 | const float qt_quick3d_sine_table[QT_QUICK3D_SINE_TABLE_SIZE] = { |
10 | float(0.0), |
11 | float(0.024541228522912288), |
12 | float(0.049067674327418015), |
13 | float(0.073564563599667426), |
14 | float(0.098017140329560604), |
15 | float(0.1224106751992162), |
16 | float(0.14673047445536175), |
17 | float(0.17096188876030122), |
18 | float(0.19509032201612825), |
19 | float(0.2191012401568698), |
20 | float(0.24298017990326387), |
21 | float(0.26671275747489837), |
22 | float(0.29028467725446233), |
23 | float(0.31368174039889152), |
24 | float(0.33688985339222005), |
25 | float(0.35989503653498811), |
26 | float(0.38268343236508978), |
27 | float(0.40524131400498986), |
28 | float(0.42755509343028208), |
29 | float(0.44961132965460654), |
30 | float(0.47139673682599764), |
31 | float(0.49289819222978404), |
32 | float(0.51410274419322166), |
33 | float(0.53499761988709715), |
34 | float(0.55557023301960218), |
35 | float(0.57580819141784534), |
36 | float(0.59569930449243336), |
37 | float(0.61523159058062682), |
38 | float(0.63439328416364549), |
39 | float(0.65317284295377676), |
40 | float(0.67155895484701833), |
41 | float(0.68954054473706683), |
42 | float(0.70710678118654746), |
43 | float(0.72424708295146689), |
44 | float(0.74095112535495911), |
45 | float(0.75720884650648446), |
46 | float(0.77301045336273699), |
47 | float(0.78834642762660623), |
48 | float(0.80320753148064483), |
49 | float(0.81758481315158371), |
50 | float(0.83146961230254524), |
51 | float(0.84485356524970701), |
52 | float(0.85772861000027212), |
53 | float(0.87008699110871135), |
54 | float(0.88192126434835494), |
55 | float(0.89322430119551532), |
56 | float(0.90398929312344334), |
57 | float(0.91420975570353069), |
58 | float(0.92387953251128674), |
59 | float(0.93299279883473885), |
60 | float(0.94154406518302081), |
61 | float(0.94952818059303667), |
62 | float(0.95694033573220894), |
63 | float(0.96377606579543984), |
64 | float(0.97003125319454397), |
65 | float(0.97570213003852857), |
66 | float(0.98078528040323043), |
67 | float(0.98527764238894122), |
68 | float(0.98917650996478101), |
69 | float(0.99247953459870997), |
70 | float(0.99518472667219682), |
71 | float(0.99729045667869021), |
72 | float(0.99879545620517241), |
73 | float(0.99969881869620425), |
74 | float(1.0), |
75 | float(0.99969881869620425), |
76 | float(0.99879545620517241), |
77 | float(0.99729045667869021), |
78 | float(0.99518472667219693), |
79 | float(0.99247953459870997), |
80 | float(0.98917650996478101), |
81 | float(0.98527764238894122), |
82 | float(0.98078528040323043), |
83 | float(0.97570213003852857), |
84 | float(0.97003125319454397), |
85 | float(0.96377606579543984), |
86 | float(0.95694033573220894), |
87 | float(0.94952818059303667), |
88 | float(0.94154406518302081), |
89 | float(0.93299279883473885), |
90 | float(0.92387953251128674), |
91 | float(0.91420975570353069), |
92 | float(0.90398929312344345), |
93 | float(0.89322430119551521), |
94 | float(0.88192126434835505), |
95 | float(0.87008699110871146), |
96 | float(0.85772861000027212), |
97 | float(0.84485356524970723), |
98 | float(0.83146961230254546), |
99 | float(0.81758481315158371), |
100 | float(0.80320753148064494), |
101 | float(0.78834642762660634), |
102 | float(0.7730104533627371), |
103 | float(0.75720884650648468), |
104 | float(0.74095112535495899), |
105 | float(0.72424708295146689), |
106 | float(0.70710678118654757), |
107 | float(0.68954054473706705), |
108 | float(0.67155895484701855), |
109 | float(0.65317284295377664), |
110 | float(0.63439328416364549), |
111 | float(0.61523159058062693), |
112 | float(0.59569930449243347), |
113 | float(0.57580819141784545), |
114 | float(0.55557023301960218), |
115 | float(0.53499761988709715), |
116 | float(0.51410274419322177), |
117 | float(0.49289819222978415), |
118 | float(0.47139673682599786), |
119 | float(0.44961132965460687), |
120 | float(0.42755509343028203), |
121 | float(0.40524131400498992), |
122 | float(0.38268343236508989), |
123 | float(0.35989503653498833), |
124 | float(0.33688985339222033), |
125 | float(0.31368174039889141), |
126 | float(0.29028467725446239), |
127 | float(0.26671275747489848), |
128 | float(0.24298017990326407), |
129 | float(0.21910124015687005), |
130 | float(0.19509032201612861), |
131 | float(0.17096188876030122), |
132 | float(0.1467304744553618), |
133 | float(0.12241067519921635), |
134 | float(0.098017140329560826), |
135 | float(0.073564563599667732), |
136 | float(0.049067674327417966), |
137 | float(0.024541228522912326), |
138 | float(0.0), |
139 | float(-0.02454122852291208), |
140 | float(-0.049067674327417724), |
141 | float(-0.073564563599667496), |
142 | float(-0.09801714032956059), |
143 | float(-0.1224106751992161), |
144 | float(-0.14673047445536158), |
145 | float(-0.17096188876030097), |
146 | float(-0.19509032201612836), |
147 | float(-0.2191012401568698), |
148 | float(-0.24298017990326382), |
149 | float(-0.26671275747489825), |
150 | float(-0.29028467725446211), |
151 | float(-0.31368174039889118), |
152 | float(-0.33688985339222011), |
153 | float(-0.35989503653498811), |
154 | float(-0.38268343236508967), |
155 | float(-0.40524131400498969), |
156 | float(-0.42755509343028181), |
157 | float(-0.44961132965460665), |
158 | float(-0.47139673682599764), |
159 | float(-0.49289819222978393), |
160 | float(-0.51410274419322155), |
161 | float(-0.53499761988709693), |
162 | float(-0.55557023301960196), |
163 | float(-0.57580819141784534), |
164 | float(-0.59569930449243325), |
165 | float(-0.61523159058062671), |
166 | float(-0.63439328416364527), |
167 | float(-0.65317284295377653), |
168 | float(-0.67155895484701844), |
169 | float(-0.68954054473706683), |
170 | float(-0.70710678118654746), |
171 | float(-0.72424708295146678), |
172 | float(-0.74095112535495888), |
173 | float(-0.75720884650648423), |
174 | float(-0.77301045336273666), |
175 | float(-0.78834642762660589), |
176 | float(-0.80320753148064505), |
177 | float(-0.81758481315158382), |
178 | float(-0.83146961230254524), |
179 | float(-0.84485356524970701), |
180 | float(-0.85772861000027201), |
181 | float(-0.87008699110871135), |
182 | float(-0.88192126434835494), |
183 | float(-0.89322430119551521), |
184 | float(-0.90398929312344312), |
185 | float(-0.91420975570353047), |
186 | float(-0.92387953251128652), |
187 | float(-0.93299279883473896), |
188 | float(-0.94154406518302081), |
189 | float(-0.94952818059303667), |
190 | float(-0.95694033573220882), |
191 | float(-0.96377606579543984), |
192 | float(-0.97003125319454397), |
193 | float(-0.97570213003852846), |
194 | float(-0.98078528040323032), |
195 | float(-0.98527764238894111), |
196 | float(-0.9891765099647809), |
197 | float(-0.99247953459871008), |
198 | float(-0.99518472667219693), |
199 | float(-0.99729045667869021), |
200 | float(-0.99879545620517241), |
201 | float(-0.99969881869620425), |
202 | float(-1.0), |
203 | float(-0.99969881869620425), |
204 | float(-0.99879545620517241), |
205 | float(-0.99729045667869021), |
206 | float(-0.99518472667219693), |
207 | float(-0.99247953459871008), |
208 | float(-0.9891765099647809), |
209 | float(-0.98527764238894122), |
210 | float(-0.98078528040323043), |
211 | float(-0.97570213003852857), |
212 | float(-0.97003125319454397), |
213 | float(-0.96377606579543995), |
214 | float(-0.95694033573220894), |
215 | float(-0.94952818059303679), |
216 | float(-0.94154406518302092), |
217 | float(-0.93299279883473907), |
218 | float(-0.92387953251128663), |
219 | float(-0.91420975570353058), |
220 | float(-0.90398929312344334), |
221 | float(-0.89322430119551532), |
222 | float(-0.88192126434835505), |
223 | float(-0.87008699110871146), |
224 | float(-0.85772861000027223), |
225 | float(-0.84485356524970723), |
226 | float(-0.83146961230254546), |
227 | float(-0.81758481315158404), |
228 | float(-0.80320753148064528), |
229 | float(-0.78834642762660612), |
230 | float(-0.77301045336273688), |
231 | float(-0.75720884650648457), |
232 | float(-0.74095112535495911), |
233 | float(-0.724247082951467), |
234 | float(-0.70710678118654768), |
235 | float(-0.68954054473706716), |
236 | float(-0.67155895484701866), |
237 | float(-0.65317284295377709), |
238 | float(-0.63439328416364593), |
239 | float(-0.61523159058062737), |
240 | float(-0.59569930449243325), |
241 | float(-0.57580819141784523), |
242 | float(-0.55557023301960218), |
243 | float(-0.53499761988709726), |
244 | float(-0.51410274419322188), |
245 | float(-0.49289819222978426), |
246 | float(-0.47139673682599792), |
247 | float(-0.44961132965460698), |
248 | float(-0.42755509343028253), |
249 | float(-0.40524131400499042), |
250 | float(-0.38268343236509039), |
251 | float(-0.359895036534988), |
252 | float(-0.33688985339222), |
253 | float(-0.31368174039889152), |
254 | float(-0.2902846772544625), |
255 | float(-0.26671275747489859), |
256 | float(-0.24298017990326418), |
257 | float(-0.21910124015687016), |
258 | float(-0.19509032201612872), |
259 | float(-0.17096188876030177), |
260 | float(-0.14673047445536239), |
261 | float(-0.12241067519921603), |
262 | float(-0.098017140329560506), |
263 | float(-0.073564563599667412), |
264 | float(-0.049067674327418091), |
265 | float(-0.024541228522912448) |
266 | }; |
267 | |
268 | QQuick3DNode *getSharedParentNode(QQuick3DNode *node, QQuick3DNode *system) { |
269 | QQuick3DNode *systemSharedParent = nullptr; |
270 | if (node && system) { |
271 | QVector<QQuick3DNode *> parents; |
272 | QQuick3DNode *parent = node->parentNode(); |
273 | while (parent) { |
274 | parents.append(t: parent); |
275 | parent = parent->parentNode(); |
276 | } |
277 | |
278 | parent = system; |
279 | while (parent) { |
280 | if (parents.contains(t: parent)) { |
281 | systemSharedParent = parent; |
282 | break; |
283 | } |
284 | parent = parent->parentNode(); |
285 | } |
286 | } |
287 | return systemSharedParent; |
288 | } |
289 | |
290 | QMatrix4x4 calculateParticleTransform(const QQuick3DNode *parent, const QQuick3DNode *systemSharedParent) |
291 | { |
292 | QMatrix4x4 transform = parent->sceneTransform(); |
293 | if (systemSharedParent) |
294 | transform = systemSharedParent->sceneTransform().inverted() * transform; |
295 | return transform; |
296 | } |
297 | |
298 | QQuaternion calculateParticleRotation(const QQuick3DNode *parent, const QQuick3DNode *systemSharedParent) |
299 | { |
300 | QQuaternion rotation = parent->sceneRotation(); |
301 | if (systemSharedParent) |
302 | rotation = systemSharedParent->sceneRotation().inverted() * rotation; |
303 | return rotation; |
304 | } |
305 | |
306 | QT_END_NAMESPACE |
307 | |