Subversion Repositories Kolibri OS

Rev

Rev 5218 | Rev 5269 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 5218 Rev 5256
Line 68... Line 68...
68
	mov edx,[c]
68
	mov edx,[c]
69
	xor eax,eax
69
	xor eax,eax
70
	.cycle_0: ;i
70
	.cycle_0: ;i
71
		xor ebx,ebx
71
		xor ebx,ebx
72
		.cycle_1: ;j
72
		.cycle_1: ;j
73
			finit
-
 
74
			fldz ;sum=0
73
			fldz ;sum=0
75
			xor ecx,ecx
74
			xor ecx,ecx
76
			M4_reg edi,[a],eax,0
75
			M4_reg edi,[a],eax,0
77
			.cycle_2: ;k
76
			.cycle_2: ;k
78
				fld dword[edi]
77
				fld dword[edi]
79
				add edi,4
78
				add edi,4
80
				M4_reg esi,[b],ecx,ebx
79
				M4_reg esi,[b],ecx,ebx
81
				fmul dword[esi]
80
				fmul dword[esi]
82
				fadd st0,st1 ;sum += a[i][k] * b[k][j]
81
				faddp ;sum += a[i][k] * b[k][j]
83
				inc ecx
82
				inc ecx
84
				cmp ecx,4
83
				cmp ecx,4
85
				jl .cycle_2
84
				jl .cycle_2
86
			fstp dword[edx] ;c[i][j] = sum
85
			fstp dword[edx] ;c[i][j] = sum
87
			add edx,4
86
			add edx,4
Line 89... Line 88...
89
			cmp ebx,4
88
			cmp ebx,4
90
			jl .cycle_1
89
			jl .cycle_1
91
		inc eax
90
		inc eax
92
		cmp eax,4
91
		cmp eax,4
93
		jl .cycle_0
92
		jl .cycle_0
94
	finit
-
 
95
if DEBUG ;gl_M4_Mul
93
if DEBUG ;gl_M4_Mul
96
	stdcall dbg_print,f_m4m,txt_nl
94
	stdcall dbg_print,f_m4m,txt_nl
97
	stdcall gl_print_matrix,[c],4
95
	stdcall gl_print_matrix,[c],4
98
	stdcall dbg_print,txt_sp,txt_nl
96
	stdcall dbg_print,txt_sp,txt_nl
99
end if
97
end if
Line 185... Line 183...
185
;        a->X=b->m[0][0]*c->X+b->m[0][1]*c->Y+b->m[0][2]*c->Z;
183
;        a->X=b->m[0][0]*c->X+b->m[0][1]*c->Y+b->m[0][2]*c->Z;
186
;        a->Y=b->m[1][0]*c->X+b->m[1][1]*c->Y+b->m[1][2]*c->Z;
184
;        a->Y=b->m[1][0]*c->X+b->m[1][1]*c->Y+b->m[1][2]*c->Z;
187
;        a->Z=b->m[2][0]*c->X+b->m[2][1]*c->Y+b->m[2][2]*c->Z;
185
;        a->Z=b->m[2][0]*c->X+b->m[2][1]*c->Y+b->m[2][2]*c->Z;
188
;}
186
;}
Line -... Line 187...
-
 
187
 
-
 
188
align 4
-
 
189
proc gl_M4_MulV4 uses ebx ecx edx, a:dword, b:dword, c:dword ;V4 *a, M4 *b, V4 *c
-
 
190
	mov ebx,[b]
-
 
191
	mov edx,[c]
-
 
192
	fld dword[edx]
-
 
193
	fld dword[edx+4]
-
 
194
	fld dword[edx+8]
-
 
195
	fld dword[edx+12]
-
 
196
	mov edx,[a]
-
 
197
	mov ecx,4
-
 
198
	.cycle_1:
-
 
199
		fld dword[ebx]    ;st0 = m[_][0]
189
 
200
		fmul st0,st4      ;st0 *= c.X
-
 
201
		fld dword[ebx+4]  ;st0 = m[_][1]
-
 
202
		fmul st0,st4      ;st0 *= c.Y
-
 
203
		faddp
-
 
204
		fld dword[ebx+8]  ;st0 = m[_][2]
190
;void gl_M4_MulV4(V4 *a,M4 *b,V4 *c)
205
		fmul st0,st3      ;st0 *= c.Z
191
;{
206
		faddp
-
 
207
		fld dword[ebx+12] ;st0 += m[_][3]
-
 
208
		fmul st0,st2      ;st0 *= c.Z
192
;        a->X=b->m[0][0]*c->X+b->m[0][1]*c->Y+b->m[0][2]*c->Z+b->m[0][3]*c->W;
209
		faddp
193
;        a->Y=b->m[1][0]*c->X+b->m[1][1]*c->Y+b->m[1][2]*c->Z+b->m[1][3]*c->W;
210
		fstp dword[edx]   ;a.X = b.m[_][0]*c.X +b.m[_][1]*c.Y +b.m[_][2]*c.Z +b.m[_][3]*c.W
194
;        a->Z=b->m[2][0]*c->X+b->m[2][1]*c->Y+b->m[2][2]*c->Z+b->m[2][3]*c->W;
211
		add ebx,16 ;ñëåäóùàÿ ñòðîêà ìàòðèöû
-
 
212
		add edx,4  ;ñëåäóùàÿ êîîðäèíàòà âåêòîðà
-
 
213
	loop .cycle_1
-
 
214
	ffree st0
-
 
215
	fincstp
-
 
216
	ffree st0
-
 
217
	fincstp
-
 
218
	ffree st0
-
 
219
	fincstp
-
 
220
	ffree st0
-
 
221
	fincstp
195
;        a->W=b->m[3][0]*c->X+b->m[3][1]*c->Y+b->m[3][2]*c->Z+b->m[3][3]*c->W;
222
	ret
Line 196... Line 223...
196
;}
223
endp
197
 
224
 
198
; transposition of a 4x4 matrix
225
; transposition of a 4x4 matrix
199
align 4
226
align 4
Line 256... Line 283...
256
 
283
 
257
; Inversion of a general nxn matrix.
284
; Inversion of a general nxn matrix.
Line 258... Line 285...
258
; Note : m is destroyed
285
; Note : m is destroyed
259
 
286
 
260
align 4
287
align 4
261
proc Matrix_Inv uses ecx, r:dword, m:dword, n:dword ;(float *r,float *m,int n)
288
proc Matrix_Inv uses ebx ecx edx edi esi, r:dword, m:dword, n:dword ;(float *r,float *m,int n)
262
;        int i,j,k,l;
-
 
263
;        float max,tmp,t;
289
locals
264
 
-
 
265
;        /* identitée dans r */
-
 
266
;        for(i=0;i
-
 
267
;        for(i=0;i
-
 
268
	 
-
 
269
;        for(j=0;j
-
 
270
			
-
 
271
;                       /* recherche du nombre de plus grand module sur la colonne j */
-
 
272
;                       max=m[j*n+j];
-
 
273
;                       k=j;
-
 
274
;                       for(i=j+1;i
-
 
275
;                               if (fabs(m[i*n+j])>fabs(max)) {
-
 
276
;                                        k=i;
-
 
277
;                                        max=m[i*n+j];
290
	max dd ? ;float
278
;                               }
-
 
279
 
-
 
Line 280... Line 291...
280
;      /* non intersible matrix */
291
	tmp dd ?
-
 
292
endl
-
 
293
 
-
 
294
	; identitée dans r
281
;      if (max==0) return 1;
295
	mov eax,0.0
282
 
296
	mov ecx,[n]
-
 
297
	imul ecx,ecx
283
;                       /* permutation des lignes j et k */
298
	mov edi,[r]
284
;                       if (k!=j) {
299
	rep stosd ;for(i=0;i
285
;                                for(i=0;i
300
	mov eax,1.0
286
;                                               tmp=m[j*n+i];
301
	xor ebx,ebx
287
;                                               m[j*n+i]=m[k*n+i];
302
	mov edi,[r]
288
;                                               m[k*n+i]=tmp;
303
	mov ecx,[n]
-
 
304
	shl ecx,2
289
;                                               
305
	@@: ;for(i=0;i
290
;                                               tmp=r[j*n+i];
306
		cmp ebx,[n]
291
;                                               r[j*n+i]=r[k*n+i];
307
		jge .end_0
-
 
308
		stosd ;r[i*n+i]=1
-
 
309
		add edi,ecx
Line -... Line 310...
-
 
310
		inc ebx
-
 
311
		jmp @b
-
 
312
	.end_0:
-
 
313
 
-
 
314
	; ebx -> n
-
 
315
	; ecx -> j
-
 
316
	; edx -> k
-
 
317
	; edi -> i
-
 
318
	; esi -> l
-
 
319
	mov ebx,[n]
292
;                                               r[k*n+i]=tmp;
320
	xor ecx,ecx
-
 
321
	.cycle_0: ;for(j=0;j
-
 
322
	cmp ecx,ebx
-
 
323
	jge .cycle_0_end
-
 
324
		; recherche du nombre de plus grand module sur la colonne j
-
 
325
		mov eax,ecx
-
 
326
		imul eax,ebx
293
;                                }
327
		add eax,ecx
-
 
328
		shl eax,2
-
 
329
		add eax,[m]
-
 
330
		mov eax,[eax]
294
;                       }
331
		mov [max],eax ;max=m[j*n+j]
-
 
332
		mov edx,ecx ;k=j
-
 
333
		mov edi,ecx
-
 
334
		inc edi
-
 
335
		.cycle_1: ;for(i=j+1;i
-
 
336
		cmp edi,ebx
-
 
337
		jge .cycle_1_end
-
 
338
			mov eax,edi
-
 
339
			imul eax,ebx
295
 
340
			add eax,ecx
-
 
341
			shl eax,2
-
 
342
			add eax,[m]
-
 
343
			fld dword[eax]
-
 
344
			fcom dword[max] ;if (fabs(m[i*n+j])>fabs(max))
-
 
345
			fstsw ax
-
 
346
			sahf
-
 
347
			jbe @f
-
 
348
				mov edx,edi ;k=i
-
 
349
				fst dword[max]
-
 
350
			@@:
-
 
351
			ffree st0
-
 
352
			fincstp
296
;                       /* multiplication de la ligne j par 1/max */
353
		inc edi
-
 
354
		jmp .cycle_1
-
 
355
		.cycle_1_end:
-
 
356
 
-
 
357
		; non intersible matrix
-
 
358
		fld dword[max]
-
 
359
		ftst ;if (max==0)
-
 
360
		fstsw ax
-
 
361
		ffree st0
-
 
362
		fincstp
297
;                       max=1/max;
363
		sahf
-
 
364
		jne @f
Line 298... Line 365...
298
;                       for(i=0;i
365
			xor eax,eax
299
;                                m[j*n+i]*=max;
366
			inc eax
-
 
367
			jmp .end_f ;return 1
-
 
368
		@@:
300
;                                r[j*n+i]*=max;
369
 
-
 
370
		; permutation des lignes j et k
-
 
371
		cmp ecx,edx ;if (j!=k)
-
 
372
		je .cycle_2_end
-
 
373
			xor edi,edi
-
 
374
			.cycle_2: ;for(i=0;i
-
 
375
			cmp edi,ebx
-
 
376
			jge .cycle_2_end
-
 
377
				;òóò ïîêà esi != l
-
 
378
				mov eax,ecx
-
 
379
				imul eax,ebx
-
 
380
				add eax,edi
-
 
381
				shl eax,2
-
 
382
				add eax,[m]
-
 
383
				mov esi,[eax]
-
 
384
				mov [tmp],esi ;tmp=m[j*n+i]
301
;                       }
385
				mov esi,edx
-
 
386
				imul esi,ebx
-
 
387
				add esi,edi
-
 
388
				shl esi,2
-
 
389
				add esi,[m]
-
 
390
				m2m dword[eax],dword[esi] ;m[j*n+i]=m[k*n+i]
-
 
391
				mov eax,[tmp]
-
 
392
				mov [esi],eax ;m[k*n+i]=tmp
-
 
393
 
-
 
394
				mov eax,ecx
-
 
395
				imul eax,ebx
-
 
396
				add eax,edi
-
 
397
				shl eax,2
-
 
398
				add eax,[r]
-
 
399
				mov esi,[eax]
-
 
400
				mov [tmp],esi ;tmp=r[j*n+i]
302
 
401
				mov esi,edx
-
 
402
				imul esi,ebx
-
 
403
				add esi,edi
-
 
404
				shl esi,2
-
 
405
				add esi,[r]
-
 
406
				m2m dword[eax],dword[esi] ;r[j*n+i]=r[k*n+i]
-
 
407
				mov eax,[tmp]
303
;                       for(l=0;l
408
				mov [esi],eax ;r[k*n+i]=tmp
-
 
409
			inc edi
-
 
410
			jmp .cycle_2
-
 
411
		.cycle_2_end:
-
 
412
 
-
 
413
		; multiplication de la ligne j par 1/max
-
 
414
		fld1
-
 
415
		fdiv dword[max]
-
 
416
		fst dword[max] ;max=1/max
-
 
417
		xor edi,edi
-
 
418
		mov eax,ecx
-
 
419
		imul eax,ebx
-
 
420
		shl eax,2
-
 
421
		.cycle_3: ;for(i=0;i
-
 
422
		cmp edi,ebx
-
 
423
		jge .cycle_3_end
-
 
424
			add eax,[m]
-
 
425
			fld dword[eax]
-
 
426
			fmul st0,st1
-
 
427
			fstp dword[eax] ;m[j*n+i]*=max
-
 
428
			sub eax,[m]
-
 
429
			add eax,[r]
-
 
430
			fld dword[eax]
-
 
431
			fmul st0,st1
-
 
432
			fstp dword[eax] ;r[j*n+i]*=max
-
 
433
			sub eax,[r]
-
 
434
			add eax,4
-
 
435
		inc edi
-
 
436
		jmp .cycle_3
-
 
437
		.cycle_3_end:
-
 
438
		ffree st0 ;max
-
 
439
		fincstp
304
;                                t=m[l*n+j];
440
 
-
 
441
		xor esi,esi
-
 
442
		.cycle_4: ;for(l=0;l
-
 
443
		cmp esi,ebx
-
 
444
		jge .cycle_4_end
-
 
445
			cmp esi,ecx ;if (l!=j)
-
 
446
			je .cycle_5_end
-
 
447
			mov eax,esi
-
 
448
			imul eax,ebx
-
 
449
			add eax,ecx
-
 
450
			shl eax,2
-
 
451
			add eax,[m]
-
 
452
			fld dword[eax] ;t=m[l*n+j]
-
 
453
			xor edi,edi
-
 
454
			.cycle_5: ;for(i=0;i
-
 
455
			cmp edi,ebx
-
 
456
			jge .cycle_5_end
-
 
457
				mov eax,ecx
-
 
458
				imul eax,ebx
-
 
459
				add eax,edi
-
 
460
				shl eax,2
-
 
461
				add eax,[m]
-
 
462
				fld dword[eax]
-
 
463
				fmul st0,st1
-
 
464
				mov eax,esi
-
 
465
				imul eax,ebx
-
 
466
				add eax,edi
-
 
467
				shl eax,2
-
 
468
				add eax,[m]
-
 
469
				fsub dword[eax]
-
 
470
				fchs
-
 
471
				fstp dword[eax] ;m[l*n+i]-=m[j*n+i]*t
-
 
472
				mov eax,ecx
-
 
473
				imul eax,ebx
-
 
474
				add eax,edi
-
 
475
				shl eax,2
-
 
476
				add eax,[r]
-
 
477
				fld dword[eax]
-
 
478
				fmul st0,st1
-
 
479
				mov eax,esi
-
 
480
				imul eax,ebx
-
 
481
				add eax,edi
305
;                                for(i=0;i
482
				shl eax,2
-
 
483
				add eax,[r]
-
 
484
				fsub dword[eax]
-
 
485
				fchs
-
 
486
				fstp dword[eax] ;r[l*n+i]-=r[j*n+i]*t
-
 
487
			inc edi
-
 
488
			jmp .cycle_5
-
 
489
			.cycle_5_end:
-
 
490
			ffree st0 ;t
-
 
491
			fincstp
-
 
492
		inc esi
Line 306... Line 493...
306
;                                               m[l*n+i]-=m[j*n+i]*t;
493
		jmp .cycle_4
-
 
494
		.cycle_4_end:
307
;                                               r[l*n+i]-=r[j*n+i]*t;
495
	inc ecx
308
;                                }
496
	jmp .cycle_0
Line 309... Line 497...
309
;                       }
497
	.cycle_0_end:
Line 407... Line 595...
407
 
595
 
408
align 4
596
align 4
409
proc gl_V3_Norm uses ebx, a:dword
597
proc gl_V3_Norm uses ebx, a:dword
410
	mov ebx,[a]
598
	mov ebx,[a]
411
	fld dword[ebx]
599
	fld dword[ebx]
412
	fmul dword[ebx]
600
	fmul st0,st0
413
	fld dword[ebx+4]
601
	fld dword[ebx+4]
414
	fmul dword[ebx+4]
602
	fmul st0,st0
415
	faddp
603
	faddp
416
	fld dword[ebx+8]
604
	fld dword[ebx+8]
417
	fmul dword[ebx+8]
605
	fmul st0,st0
418
	faddp
606
	faddp
419
	fsqrt ;st0 = sqrt(a.X^2 +a.Y^2 +a.Z^2)
607
	fsqrt ;st0 = sqrt(a.X^2 +a.Y^2 +a.Z^2)
420
	fldz
608
	fldz
421
	fcomp
609
	fcomp