1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
|
#undef TEST_ACTIVE
//#define ACTIVE 1
/**
* blenlib/BLI_arithb.h mar 2001 Nzc
*
* $Id$
*
* ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version. The Blender
* Foundation also sells licenses for use in proprietary software under
* the Blender License. See http://www.blender.org/BL/ for information
* about this.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
* All rights reserved.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*
* The old math stuff from Ton. These will slowly phase out in favour
* of MTC calls. (or even MoTO :) )
* */
#ifndef BLI_ARITHB_H
#define BLI_ARITHB_H
#ifdef __cplusplus
extern "C" {
#endif
#define MAT4_UNITY {{ 1.0, 0.0, 0.0, 0.0},\
{ 0.0, 1.0, 0.0, 0.0},\
{ 0.0, 0.0, 1.0, 0.0},\
{ 0.0, 0.0, 0.0, 1.0}}
#define MAT3_UNITY {{ 1.0, 0.0, 0.0},\
{ 0.0, 1.0, 0.0},\
{ 0.0, 0.0, 1.0}}
/* matrix operations */
/* void Mat4MulMat4(float m1[][4], float m2[][4], float m3[][4]); */
/* void Mat3MulVecfl(float mat[][3], float *vec); */
/* or **mat, but it's the same */
/*void Mat3MulVecd(float mat[][3], double *vec); */
/* void Mat4MulVecfl(float mat[][4], float *vec); */
/* void Mat4MulSerie(float answ[][4], float m1[][4], float m2[][4], */
/* float m3[][4], float m4[][4], float m5[][4], */
/* float m6[][4], float m7[][4], float m8[][4]); */
/* int Mat4Invert(float inverse[][4], float mat[][4]); */
/* m2 to m1 */
/* void Mat3CpyMat4(float m1p[][3], float m2p[][4]); */
/* void Mat3CpyMat4(float *m1p, float *m2p); */
/* m1 to m2 */
/* void Mat3CpyMat3(float m1p[][3], float m2p[][3]); */
/* void Mat3CpyMat3(float *m1p, float *m2p); */
/* m2 to m1 */
/* void Mat4CpyMat3(float m1p[][4], float m2p[][3]); */
/* M1 = M3*M2 */
/* void Mat3MulMat3(float m1[][3], float m2[][3], float m3[][3]); */
/*void Mat3MulMat3(float *m1, float *m3, float *m2); */
/* m1 = m2 * m3, ignore the elements on the 4th row/column of m3 */
/*void Mat3IsMat3MulMat4(float m1[][3], float m2[][3], float m3[][4]); */
/* m1 to m2 */
/* void Mat4CpyMat4(float m1[][4], float m2[][4]); */
/* void Mat4CpyMat4(float *m1, float *m2); */
/* void Mat4Ortho(float mat[][4]); */
/* void Mat4Mul3Vecfl(float mat[][4], float *vec); */
/* void Mat4MulVec4fl(float mat[][4], float *vec); */
/* void Mat4SwapMat4(float *m1, float *m2); */
/* void Mat3Inv(float m1[][3], float m2[][3]); */
/* void Mat4One(float m[][4]); */
/* void Mat3One(float m[][3]); */
void
CalcCent3f(
float *cent, float *v1, float *v2, float *v3
);
void
CalcCent4f(
float *cent, float *v1,
float *v2, float *v3,
float *v4
);
void
Crossf(
float *c, float *a, float *b
);
void
Projf(
float *c, float *v1, float *v2
);
/**
* Euler conversion routines
*/
void
EulToMat3(
float *eul,
float mat[][3]
);
void
EulToMat4(
float* eul,
float mat[][4]
);
void
Mat3ToEul(
float tmat[][3],
float *eul
);
/**
* @section Quaternion arithmetic routines
*/
void
QuatToEul(
float *quat,
float *eul
);
void
QuatOne(
float *
);
void
QuatMul(
float *,
float *,
float *
);
void
NormalQuat(
float *
);
void
VecRotToQuat(
float *vec,
float phi,
float *quat
);
void
QuatSub(
float *q,
float *q1,
float *q2
);
void QuatInterpol(float *result, float *quat1, float *quat2, float t);
void QuatAdd(float *result, float *quat1, float *quat2, float t);
/**
* @section matrix multiplication can copying routines
*/
void
Mat3MulFloat(
float *m,
float f
);
void
Mat4MulFloat(
float *m,
float f
);
void
Mat4MulFloat3(
float *m,
float f
);
void
Mat3Transp(
float mat[][3]
);
void
Mat4Transp(
float mat[][4]
);
int
Mat4Invert(
float inverse[][4],
float mat[][4]
);
void
Mat4InvertSimp(
float inverse[][4],
float mat[][4]
);
void
Mat4Inv(
float *m1,
float *m2
);
void
Mat4InvGG(
float out[][4],
float in[][4]
);
void
Mat3CpyMat4(
float m1[][3],
float m2[][4]
);
void
Mat3Inv(
float m1[][3],
float m2[][3]
);
void
Mat4CpyMat3(
float m1[][4],
float m2[][3]
);
float
Det2x2(
float a,float b,float c,float d
);
float
Det3x3(
float a1, float a2, float a3,
float b1, float b2, float b3,
float c1, float c2, float c3
);
float
Det4x4(
float m[][4]
);
void
Mat4Adj(
float out[][4],
float in[][4]
);
void
Mat3Adj(
float m1[][3],
float m[][3]
);
void
Mat4MulMat4(
float m1[][4],
float m2[][4],
float m3[][4]
);
void
subMat4MulMat4(
float *m1,
float *m2,
float *m3
);
#ifndef TEST_ACTIVE
void
Mat3MulMat3(
float m1[][3],
float m3[][3],
float m2[][3]
);
#else
void
Mat3MulMat3(
float *m1,
float *m3,
float *m2
);
#endif
void
Mat4MulMat34(
float (*m1)[4],
float (*m3)[3],
float (*m2)[4]
);
void
Mat4CpyMat4(
float m1[][4],
float m2[][4]
);
void
Mat4SwapMat4(
float *m1,
float *m2
);
void
Mat3CpyMat3(
float m1[][3],
float m2[][3]
);
void
Mat3MulSerie(
float answ[][3],
float m1[][3], float m2[][3], float m3[][3],
float m4[][3], float m5[][3], float m6[][3],
float m7[][3], float m8[][3]
);
void
Mat4MulSerie(
float answ[][4],
float m1[][4],
float m2[][4], float m3[][4], float m4[][4],
float m5[][4], float m6[][4], float m7[][4],
float m8[][4]
);
void
Mat4Clr(
float *m
);
void
Mat3Clr(
float *m
);
void
Mat3One(
float m[][3]
);
void
Mat4MulVec(
float mat[][4],
int *vec
);
void
VecMat4MulVecfl(
float *in,
float mat[][4],
float *vec
);
void
Mat4MulMat43(
float (*m1)[4],
float (*m3)[4],
float (*m2)[3]
);
void
Mat3IsMat3MulMat4(
float m1[][3],
float m2[][3],
float m3[][4]
);
void
Mat4One(
float m[][4]
);
void
Mat4Mul3Vecfl(
float mat[][4],
float *vec
);
void
Mat4MulVec4fl(
float mat[][4],
float *vec
);
void
Mat3MulVec(
float mat[][3],
int *vec
);
void
Mat4MulVecfl(
float mat[][4],
float *vec
);
void
Mat4ToQuat(
float m[][4],
float *q
);
void
VecUpMat3old(
float *vec,
float mat[][3],
short axis
);
int
FloatCompare(
float *v1,
float *v2,
float limit
);
float
Normalise(
float *n
);
float
CalcNormFloat(
float *v1,
float *v2,
float *v3,
float *n
);
float
CalcNormFloat4(
float *v1,
float *v2,
float *v3,
float *v4,
float *n
);
float
VecLenf(
float *v1,
float *v2
);
void
VecMulf(
float *v1,
float f
);
int
VecCompare(
float *v1,
float *v2,
float limit
);
float
Sqrt3f(
float f
);
double
Sqrt3d(
double d
);
void
euler_rot(
float *beul,
float ang,
char axis
);
float
saacos(
float fac
);
float
sasqrt(
float fac
);
void
printvecf(
char *str,
float v[3]
);
float
Inpf(
float *v1,
float *v2
);
void
VecSubf(
float *v,
float *v1,
float *v2
);
void
VecAddf(
float *v,
float *v1,
float *v2
);
void
VecUpMat3(
float *vec,
float mat[][3],
short axis
);
float
DistVL2Dfl(
float *v1,
float *v2,
float *v3
);
float
PdistVL2Dfl(
float *v1,
float *v2,
float *v3
);
float
AreaF2Dfl(
float *v1,
float *v2,
float *v3
);
float
AreaQ3Dfl(
float *v1,
float *v2,
float *v3,
float *v4
);
float
AreaT3Dfl(
float *v1,
float *v2,
float *v3
);
float
AreaPoly3Dfl(
int nr,
float *verts,
float *normal
);
void
VecRotToMat3(
float *vec,
float phi,
float mat[][3]
);
/* intersect Line-Line
return:
-1: colliniar
0: no intersection of segments
1: exact intersection of segments
2: cross-intersection of segments
*/
extern short IsectLL2Df(float *v1, float *v2, float *v3, float *v4);
extern short IsectLL2Ds(short *v1, short *v2, short *v3, short *v4);
float *
vectoquat(
float *vec,
short axis,
short upflag
);
void
i_lookat(
float vx, float vy,
float vz, float px,
float py, float pz,
float twist, float mat[][4]
);
void
i_window(
float left, float right,
float bottom, float top,
float nearClip, float farClip,
float mat[][4]
);
void
hsv_to_rgb(
float h, float s,
float v, float *r,
float *g, float *b
);
void
rgb_to_hsv(
float r, float g, float b,
float *lh, float *ls, float *lv
);
unsigned int
hsv_to_cpack(
float h, float s, float v
);
unsigned int
rgb_to_cpack(
float r, float g, float b
);
void
cpack_to_rgb(
unsigned int col,
float *r, float *g, float *b
);
void
EulToQuat(
float *eul,
float *quat
);
void
Mat3MulVecfl(
float mat[][3],
float *vec
);
void
Mat3MulVecd(
float mat[][3],
double *vec
);
void
Mat3TransMulVecfl(
float mat[][3],
float *vec
);
void
VecStar(
float mat[][3],
float *vec
);
short
EenheidsMat(
float mat[][3]
);
void
printmatrix3(
char *str, float m[][3]
);
void
QuatToMat3(
float *q,
float m[][3]
);
void
QuatToMat4(
float *q,
float m[][4]
);
void
Mat3ToQuat_is_ok(
float wmat[][3],
float *q
);
void
i_ortho(
float left, float right,
float bottom, float top,
float nearClip, float farClip,
float matrix[][4]
);
void
i_polarview(
float dist, float azimuth, float incidence, float twist,
float Vm[][4]
);
void
Mat3Ortho(
float mat[][3]
);
void
Mat4Ortho(
float mat[][4]
);
void
VecCopyf(
float *v1,
float *v2
);
int
VecLen(
int *v1,
int *v2
);
void
CalcNormShort(
short *v1,
short *v2,
short *v3,
float *n
) /* is ook uitprodukt */;
void
CalcNormLong(
int* v1,
int*v2,
int*v3,
float *n
);
void
MinMax3(
float *min,
float *max,
float *vec
);
void
Mat3ToEuln(
float tmat[][3],
float *eul
);
void
SizeToMat3(
float *size,
float mat[][3]
);
void
printmatrix4(
char *str,
float m[][4]
);
/* uit Sig.Proc.85 pag 253 */
void
Mat3ToQuat(
float wmat[][3],
float *q
);
void
i_translate(
float Tx,
float Ty,
float Tz,
float mat[][4]
);
void
i_multmatrix(
float icand[][4],
float Vm[][4]
);
void
i_rotate(
float angle,
char axis,
float mat[][4]
);
void
VecMidf(
float *v, float *v1, float *v2
);
void
Mat3ToSize(
float mat[][3], float *size
);
void
Mat4ToSize(
float mat[][4], float *size
);
void
triatoquat(
float *v1,
float *v2,
float *v3, float *quat
);
void
MinMaxRGB(
short c[]
);
float
Vec2Lenf(
float *v1,
float *v2
);
void
Vec2Mulf(
float *v1,
float f
);
void
Vec2Addf(
float *v,
float *v1,
float *v2
);
#ifdef __cplusplus
}
#endif
#endif
|