Rev 1245 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1245 | hidnplayr | 1 | x3d equ 0 |
2 | y3d equ 2 |
||
3 | z3d equ 4 |
||
4 | vec_x equ 0 |
||
5 | vec_y equ 4 |
||
6 | vec_z equ 8 |
||
7 | ; 3d point - triple integer word coordinate |
||
8 | ; vector - triple float dword coordinate |
||
9 | ;----------------------in: -------------------------------- |
||
10 | ;------------------------ esi - pointer to 1st 3d point --- |
||
11 | ;------------------------ edi - pointer to 2nd 3d point --- |
||
12 | ;------------------------ ebx - pointer to result vector -- |
||
13 | ;---------------------- out : none ------------------------ |
||
14 | if 0 |
||
15 | make_vector: |
||
16 | fninit |
||
17 | fild word[edi+x3d] ;edi+x3d |
||
18 | fisub word[esi+x3d] ;esi+x3d |
||
19 | fstp dword[ebx+vec_x] |
||
20 | |||
21 | fild word[edi+y3d] |
||
22 | fisub word[esi+y3d] |
||
23 | fstp dword[ebx+vec_y] |
||
24 | |||
25 | fild word[edi+z3d] |
||
26 | fisub word[esi+z3d] |
||
27 | fstp dword[ebx+vec_z] |
||
28 | |||
29 | ret |
||
30 | end if |
||
31 | make_vector_r: |
||
32 | fninit |
||
33 | fld dword[edi] ;edi+x3d |
||
34 | fsub dword[esi] ;esi+x3d |
||
35 | fstp dword[ebx+vec_x] |
||
36 | |||
37 | fld dword[edi+4] |
||
38 | fsub dword[esi+4] |
||
39 | fstp dword[ebx+vec_y] |
||
40 | |||
41 | fld dword[edi+8] |
||
42 | fsub dword[esi+8] |
||
43 | fstp dword[ebx+vec_z] |
||
44 | |||
45 | ret |
||
46 | ;---------------------- in: ------------------------------- |
||
47 | ;--------------------------- esi - pointer to 1st vector -- |
||
48 | ;--------------------------- edi - pointer to 2nd vector -- |
||
49 | ;--------------------------- ebx - pointer to result vector |
||
50 | ;---------------------- out : none |
||
51 | cross_product: |
||
52 | fninit |
||
53 | fld dword [esi+vec_y] |
||
54 | fmul dword [edi+vec_z] |
||
55 | fld dword [esi+vec_z] |
||
56 | fmul dword [edi+vec_y] |
||
57 | fsubp ;st1 ,st |
||
58 | fstp dword [ebx+vec_x] |
||
59 | |||
60 | fld dword [esi+vec_z] |
||
61 | fmul dword [edi+vec_x] |
||
62 | fld dword [esi+vec_x] |
||
63 | fmul dword [edi+vec_z] |
||
64 | fsubp ;st1 ,st |
||
65 | fstp dword [ebx+vec_y] |
||
66 | |||
67 | fld dword [esi+vec_x] |
||
68 | fmul dword [edi+vec_y] |
||
69 | fld dword [esi+vec_y] |
||
70 | fmul dword [edi+vec_x] |
||
71 | fsubp ;st1 ,st |
||
72 | fstp dword [ebx+vec_z] |
||
73 | ret |
||
74 | ;----------------------- in: ------------------------------ |
||
75 | ;---------------------------- edi - pointer to vector ----- |
||
76 | ;----------------------- out : none |
||
77 | normalize_vector: |
||
78 | fninit |
||
79 | fld dword [edi+vec_x] |
||
80 | fmul st, st |
||
81 | fld dword [edi+vec_y] |
||
82 | fmul st, st |
||
83 | fld dword [edi+vec_z] |
||
84 | fmul st, st |
||
85 | faddp st1, st |
||
86 | faddp st1, st |
||
87 | fsqrt |
||
88 | |||
89 | ftst |
||
90 | fstsw ax |
||
91 | sahf |
||
92 | jnz @f |
||
93 | |||
94 | fst dword [edi+vec_x] |
||
95 | fst dword [edi+vec_y] |
||
96 | fstp dword [edi+vec_z] |
||
97 | ret |
||
98 | @@: |
||
99 | fld st |
||
100 | fld st |
||
101 | fdivr dword [edi+vec_x] |
||
102 | fstp dword [edi+vec_x] |
||
103 | fdivr dword [edi+vec_y] |
||
104 | fstp dword [edi+vec_y] |
||
105 | fdivr dword [edi+vec_z] |
||
106 | fstp dword [edi+vec_z] |
||
107 | ret |
||
108 | ;------------------in: ------------------------- |
||
109 | ;------------------ esi - pointer to 1st vector |
||
110 | ;------------------ edi - pointer to 2nd vector |
||
111 | ;------------------out: ------------------------ |
||
112 | ;------------------ st0 - dot-product |
||
113 | dot_product: |
||
114 | fninit |
||
115 | fld dword [esi+vec_x] |
||
116 | fmul dword [edi+vec_x] |
||
117 | fld dword [esi+vec_y] |
||
118 | fmul dword [edi+vec_y] |
||
119 | fld dword [esi+vec_z] |
||
120 | fmul dword [edi+vec_z] |
||
121 | faddp |
||
122 | faddp |
||
123 | ret |
||
124 | |||
125 | ; DOS version Coded by Mikolaj Felix aka Majuma |
||
126 | ; mfelix@polbox.com |
||
127 | ; www.majuma.xt.pl |
||
128 | ; into FASM translation by Macgub |
||
129 | init_sincos_tab: |
||
130 | .counter equ dword [ebp-4] ; cur angle |
||
131 | |||
132 | push ebp |
||
133 | mov ebp,esp |
||
134 | |||
135 | xor eax,eax |
||
136 | push eax ; init .counter |
||
137 | mov edi,cos_tab |
||
138 | mov esi,sin_tab |
||
139 | mov ecx,256 |
||
140 | fninit |
||
141 | |||
142 | fld .counter |
||
143 | @@: |
||
144 | fld st |
||
145 | fsincos |
||
146 | fstp dword [edi] |
||
147 | fstp dword [esi] |
||
148 | ; fadd [piD180] |
||
149 | fadd [piD128] |
||
150 | add esi,4 |
||
151 | add edi,4 |
||
152 | loop @b |
||
153 | ffree st |
||
154 | |||
155 | mov esp,ebp |
||
156 | pop ebp |
||
157 | ret |
||
158 | ;------ |
||
159 | ; esi - offset (pointer) to angles, edi offset to 3x3 matrix |
||
160 | make_rotation_matrix: |
||
161 | .sinx equ dword[ebp-4] |
||
162 | .cosx equ dword[ebp-8] |
||
163 | .siny equ dword[ebp-12] |
||
164 | .cosy equ dword[ebp-16] |
||
165 | .sinz equ dword[ebp-20] |
||
166 | .cosz equ dword[ebp-24] |
||
167 | push ebp |
||
168 | mov ebp,esp |
||
169 | sub esp,24 |
||
170 | |||
171 | movzx ebx,word[esi] |
||
172 | shl ebx,2 |
||
173 | mov eax,dword[sin_tab+ebx] |
||
174 | mov .sinx,eax |
||
175 | mov edx,dword[cos_tab+ebx] |
||
176 | mov .cosx,edx |
||
177 | |||
178 | movzx ebx,word[esi+2] |
||
179 | shl ebx,2 |
||
180 | mov eax,dword[sin_tab+ebx] |
||
181 | mov .siny,eax |
||
182 | mov edx,dword[cos_tab+ebx] |
||
183 | mov .cosy,edx |
||
184 | |||
185 | movzx ebx,word[esi+4] |
||
186 | shl ebx,2 |
||
187 | mov eax,dword[sin_tab+ebx] |
||
188 | mov .sinz,eax |
||
189 | mov edx,dword[cos_tab+ebx] |
||
190 | mov .cosz,edx |
||
191 | |||
192 | fninit |
||
193 | fld .cosy |
||
194 | fmul .cosz |
||
195 | fstp dword[edi] |
||
196 | |||
197 | fld .sinx |
||
198 | fmul .siny |
||
199 | fmul .cosz |
||
200 | fld .cosx |
||
201 | fmul .sinz |
||
202 | fchs |
||
203 | faddp |
||
204 | fstp dword[edi+12] |
||
205 | |||
206 | fld .cosx |
||
207 | fmul .siny |
||
208 | fmul .cosz |
||
209 | fld .sinx |
||
210 | fmul .sinz |
||
211 | faddp |
||
212 | fstp dword[edi+24] |
||
213 | |||
214 | fld .siny |
||
215 | fmul .sinz |
||
216 | fstp dword[edi+4] |
||
217 | |||
218 | fld .sinx |
||
219 | fmul .siny |
||
220 | fmul .sinz |
||
221 | fld .cosx |
||
222 | fmul .cosz |
||
223 | faddp |
||
224 | fstp dword[edi+16] |
||
225 | |||
226 | fld .cosx |
||
227 | fmul .siny |
||
228 | fmul .sinz |
||
229 | fld .sinx |
||
230 | fchs |
||
231 | fmul .cosz |
||
232 | faddp |
||
233 | fstp dword[edi+28] |
||
234 | |||
235 | fld .siny |
||
236 | fchs |
||
237 | fstp dword[edi+8] |
||
238 | |||
239 | fld .cosy |
||
240 | fmul .sinx |
||
241 | fstp dword[edi+20] |
||
242 | |||
243 | fld .cosx |
||
244 | fmul .cosy |
||
245 | fstp dword[edi+32] |
||
246 | |||
247 | mov esp,ebp |
||
248 | pop ebp |
||
249 | ret |
||
250 | ;--------------------- |
||
251 | ; in: esi - ptr to points(normals], each point(normal) coeficient as dword |
||
252 | ; edi - ptr to rotated points(normals) |
||
253 | ; ebx - ptr to 3x3 (9 dwords, 36 bytes) rotation matrix |
||
254 | ; ecx - number of points(normals) |
||
255 | rotary: |
||
256 | if Ext |
||
257 | fninit |
||
258 | .again: |
||
259 | |||
260 | fld dword[esi] |
||
261 | fmul dword[ebx] |
||
262 | fld dword[esi+4] |
||
263 | fmul dword[ebx+12] |
||
264 | faddp |
||
265 | fld dword[esi+8] |
||
266 | fmul dword[ebx+24] |
||
267 | faddp |
||
268 | fstp dword[edi] |
||
269 | |||
270 | |||
271 | fld dword[esi+4] |
||
272 | fmul dword[ebx+16] |
||
273 | fld dword[esi] |
||
274 | fmul dword[ebx+4] |
||
275 | faddp |
||
276 | fld dword[esi+8] |
||
277 | fmul dword[ebx+28] |
||
278 | faddp |
||
279 | fstp dword[edi+4] |
||
280 | |||
281 | |||
282 | fld dword[esi+8] |
||
283 | fmul dword[ebx+32] |
||
284 | fld dword[esi] |
||
285 | fmul dword[ebx+8] |
||
286 | fld dword[esi+4] |
||
287 | fmul dword[ebx+20] |
||
288 | faddp |
||
289 | faddp |
||
290 | fstp dword[edi+8] |
||
291 | |||
292 | |||
293 | add esi,12 |
||
294 | add edi,12 |
||
295 | loop .again |
||
296 | mov [edi],dword -1 |
||
297 | else |
||
298 | ; Copyright (C) 1999-2001 Brian Paul |
||
299 | ; Copyright (C) Maciej Guba |
||
300 | ;--------------------- |
||
301 | ; in: esi - ptr to points(normals], each point(normal) coeficient as dword |
||
302 | ; edi - ptr to rotated points(normals) |
||
303 | ; ebx - ptr to 3x3 (9 dwords, 36 bytes) rotation matrix |
||
304 | ; ecx - number of points(normals) |
||
305 | ;align 32 |
||
306 | movups xmm4,[ebx] |
||
2881 | leency | 307 | ; lddqu xmm4,[ebx] ; I tried sse3 :D |
1245 | hidnplayr | 308 | movups xmm5,[ebx+12] |
309 | movups xmm6,[ebx+24] |
||
310 | ;align 32 |
||
311 | .again: |
||
312 | movss xmm0,dword[esi] |
||
313 | shufps xmm0,xmm0,0 |
||
314 | mulps xmm0,xmm4 |
||
315 | |||
316 | movss xmm1,dword[esi+4] |
||
317 | shufps xmm1,xmm1,0 |
||
318 | mulps xmm1,xmm5 |
||
319 | |||
320 | movss xmm2,dword[esi+8] |
||
321 | shufps xmm2,xmm2,0 |
||
322 | mulps xmm2,xmm6 |
||
323 | |||
324 | addps xmm0,xmm1 |
||
325 | addps xmm0,xmm2 |
||
326 | |||
327 | movups [edi],xmm0 |
||
328 | |||
329 | add esi,12 |
||
330 | add edi,12 |
||
331 | dec ecx |
||
332 | jne .again |
||
333 | mov [edi],dword -1 |
||
334 | end if |
||
335 | ret |
||
336 | ;---------------------------------------------- |
||
337 | ; esi - pointer to 3x3 matrix |
||
338 | add_scale_to_matrix: |
||
339 | fninit |
||
340 | fld [rsscale] |
||
341 | fld dword[esi] ;----- |
||
342 | fmul st,st1 |
||
343 | fstp dword[esi] |
||
344 | fld dword[esi+12] ; x scale |
||
345 | fmul st,st1 |
||
346 | fstp dword[esi+12] |
||
347 | fld dword[esi+24] |
||
348 | fmul st,st1 |
||
349 | fstp dword[esi+24] ;------ |
||
350 | |||
351 | fld dword[esi+4] ;----- |
||
352 | fmul st,st1 |
||
353 | fstp dword[esi+4] |
||
354 | fld dword[esi+16] ; y scale |
||
355 | fmul st,st1 |
||
356 | fstp dword[esi+16] |
||
357 | fld dword[esi+28] |
||
358 | fmul st,st1 |
||
359 | fstp dword[esi+28] ;------ |
||
360 | |||
361 | |||
362 | fld dword[esi+8] ;----- |
||
363 | fmul st,st1 |
||
364 | fstp dword[esi+8] |
||
365 | fld dword[esi+20] ; z scale |
||
366 | fmul st,st1 |
||
367 | fstp dword[esi+20] |
||
368 | fld dword[esi+32] |
||
369 | fmulp st1,st |
||
370 | fstp dword[esi+32] ;------ |
||
371 | |||
372 | ret |
||
373 | |||
374 | ;in esi - offset to 3d points (point as 3 dwords float) |
||
375 | ; edi - offset to 2d points ( as 3 words integer) |
||
376 | ; ecx - number of points |
||
377 | translate_points: ; just convert into integer; z coord still needed |
||
378 | fninit |
||
379 | .again: |
||
380 | fld dword[esi+8] |
||
381 | ; fmul [rsscale] |
||
382 | fist word[edi+4] |
||
383 | |||
384 | fisub [zobs] |
||
385 | fchs |
||
386 | |||
387 | fld dword[esi] |
||
388 | ; fmul [rsscale] |
||
389 | fisub [xobs] |
||
390 | fimul [zobs] |
||
391 | fdiv st0,st1 |
||
392 | |||
393 | fiadd [xobs] |
||
394 | fiadd [vect_x] |
||
395 | fistp word[edi] |
||
396 | |||
397 | fld dword[esi+4] |
||
398 | ; fmul [rsscale] |
||
399 | fisub [yobs] |
||
400 | fimul [zobs] |
||
401 | fdivrp ; st0,st1 |
||
402 | |||
403 | fiadd [yobs] |
||
404 | fiadd [vect_y] |
||
405 | fistp word[edi+2] |
||
406 | |||
407 | add esi,12 |
||
408 | add edi,6 |
||
409 | dec ecx |
||
410 | jnz .again |
||
411 | |||
412 | ret |