Mercurial > hg > dmlib
annotate vecmattest.c @ 239:07c4f1a7ddc6
Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
functions to dmvecmat.h as static inline for speed, etc.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Tue, 09 Oct 2012 12:59:09 +0300 |
parents | 32250b436bca |
children | 04c7e7cefddc |
rev | line source |
---|---|
0 | 1 #include "dmlib.h" |
2 #include "dmvecmat.h" | |
3 | |
4 void printTest(const char *test, int expected, int result) | |
5 { | |
6 fprintf(stderr, "Test '%s': %s\n", test, | |
7 expected == result ? "OK" : "FAILED!"); | |
8 } | |
9 | |
10 #define tst(X, R) printTest(# X, (X), (R)) | |
11 | |
12 | |
13 void dm_vector_fprintf(FILE *f, const char *name, DMVector *v) | |
14 { | |
15 if (name != NULL) | |
16 fprintf(f, "%s=", name); | |
17 | |
18 fprintf(f, "[<%1.3f, %1.3f, %1.3f>=%1.3f]", v->x, v->y, v->z, dm_vector_length(v)); | |
19 | |
20 if (name != NULL) | |
21 fprintf(f, "\n"); | |
22 } | |
23 | |
24 | |
25 void dm_vector_printf(const char *name, DMVector *v) | |
26 { | |
27 dm_vector_fprintf(stdout, name, v); | |
28 } | |
29 | |
30 | |
31 void dm_matrix_fprintf(FILE *f, const char *name, DMMatrix *mat) | |
32 { | |
33 int i, j, k, pad = 0; | |
34 char *tmp = NULL; | |
35 | |
36 if (name != NULL) | |
37 { | |
38 tmp = dm_strdup_printf("%s=", name); | |
39 pad = strlen(tmp); | |
40 } | |
41 | |
42 for (i = 0; i < DM_MATRIX_SIZE; i++) | |
43 { | |
44 if (i == 1) | |
45 fputs(tmp, f); | |
46 else | |
47 for (k = 0; k < pad; k++) | |
48 fputc(' ', f); | |
49 | |
50 fprintf(f, "["); | |
51 for (j = 0; j < DM_MATRIX_SIZE; j++) | |
52 fprintf(f, "% 8.3f%s", mat->m[i][j], j < DM_MATRIX_SIZE - 1 ? " " : ""); | |
53 | |
54 fprintf(f, "]\n"); | |
55 } | |
56 } | |
57 | |
58 | |
59 void dm_matrix_printf(const char *name, DMMatrix *mat) | |
60 { | |
61 dm_matrix_fprintf(stdout, name, mat); | |
62 } | |
63 | |
64 | |
65 int main(int argc, char *argv[]) | |
66 { | |
239
07c4f1a7ddc6
Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
67 DMVector a = { -5, 1, 17, 0 }, b = { 1, 2, 0.5, 0 }; |
0 | 68 DMMatrix m; |
69 | |
70 (void) argc; | |
71 (void) argv; | |
72 | |
73 dm_vector_printf("a", &a); | |
74 dm_vector_printf("b", &a); | |
75 | |
76 dm_matrix_rot_a(&m, 0.5, 0.9, 0.1); | |
77 dm_matrix_printf("m", &m); | |
78 | |
79 dm_vector_mul_by_mat(&b, &a, &m); | |
80 | |
81 dm_vector_printf("nb", &b); | |
82 | |
83 return 0; | |
84 } |