Mercurial > hg > dmlib
annotate dmvecmat.h @ 269:159264c27929
Add some new vector and matrix operations, and introduce some SSE inline
assembler optimized versions.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Wed, 10 Oct 2012 16:35:43 +0300 |
parents | 00785510b743 |
children | 4d42b8910d7e |
rev | line source |
---|---|
0 | 1 /* |
2 * DMLib | |
3 * -- Vector and matrix functions | |
4 * Programmed and designed by Matti 'ccr' Hamalainen | |
5 * (C) Copyright 2011 Tecnic Software productions (TNSP) | |
6 */ | |
7 #ifndef DMVECMAT_H | |
8 #define DMVECMAT_H | |
9 #include "dmlib.h" | |
10 | |
239
07c4f1a7ddc6
Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
11 #include <math.h> |
07c4f1a7ddc6
Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
12 |
0 | 13 #ifdef __cplusplus |
14 extern "C" { | |
15 #endif | |
16 | |
239
07c4f1a7ddc6
Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
17 #define DM_MATRIX_SIZE (4) |
0 | 18 |
19 typedef struct | |
20 { | |
239
07c4f1a7ddc6
Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
21 DMFloat x, y, z, W; |
0 | 22 } DMVector; |
23 | |
24 typedef struct | |
25 { | |
26 DMFloat m[DM_MATRIX_SIZE][DM_MATRIX_SIZE]; | |
27 } DMMatrix; | |
28 | |
269
159264c27929
Add some new vector and matrix operations, and introduce some SSE inline
Matti Hamalainen <ccr@tnsp.org>
parents:
244
diff
changeset
|
29 |
159264c27929
Add some new vector and matrix operations, and introduce some SSE inline
Matti Hamalainen <ccr@tnsp.org>
parents:
244
diff
changeset
|
30 void dm_vector_add_n(DMVector *dst, const DMVector *src, const int nlist); |
159264c27929
Add some new vector and matrix operations, and introduce some SSE inline
Matti Hamalainen <ccr@tnsp.org>
parents:
244
diff
changeset
|
31 void dm_vector_add_r_n(DMVector *dst, const DMVector *src1, const DMVector *src2, const int nlist); |
159264c27929
Add some new vector and matrix operations, and introduce some SSE inline
Matti Hamalainen <ccr@tnsp.org>
parents:
244
diff
changeset
|
32 void dm_vector_sub_n(DMVector *dst, const DMVector *src, const int nlist); |
159264c27929
Add some new vector and matrix operations, and introduce some SSE inline
Matti Hamalainen <ccr@tnsp.org>
parents:
244
diff
changeset
|
33 void dm_vector_sub_r_n(DMVector *dst, const DMVector *src1, const DMVector *src2, const int nlist); |
159264c27929
Add some new vector and matrix operations, and introduce some SSE inline
Matti Hamalainen <ccr@tnsp.org>
parents:
244
diff
changeset
|
34 |
159264c27929
Add some new vector and matrix operations, and introduce some SSE inline
Matti Hamalainen <ccr@tnsp.org>
parents:
244
diff
changeset
|
35 void dm_vector_mul_by_mat(DMVector *vd, const DMVector *vs, const DMMatrix *mat); |
0 | 36 void dm_vector_mul_by_mat_n(DMVector *list, const int nlist, const DMMatrix *mat); |
37 | |
38 void dm_matrix_unit(DMMatrix *mat); | |
39 void dm_matrix_transpose(DMMatrix *mat1, const DMMatrix *mat2); | |
40 | |
41 void dm_matrix_mul(DMMatrix *mat1, const DMMatrix *mat2); | |
269
159264c27929
Add some new vector and matrix operations, and introduce some SSE inline
Matti Hamalainen <ccr@tnsp.org>
parents:
244
diff
changeset
|
42 void dm_matrix_mul_r(DMMatrix *dst, const DMMatrix *mat1, const DMMatrix *mat2); |
0 | 43 void dm_matrix_mul_n(DMMatrix *list, const int nlist, const DMMatrix *mat); |
44 | |
45 void dm_matrix_rot(DMMatrix *mat, | |
46 const DMFloat sx, const DMFloat sy, const DMFloat sz, | |
47 const DMFloat cx, const DMFloat cy, const DMFloat cz); | |
48 | |
239
07c4f1a7ddc6
Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
49 |
269
159264c27929
Add some new vector and matrix operations, and introduce some SSE inline
Matti Hamalainen <ccr@tnsp.org>
parents:
244
diff
changeset
|
50 /* Basic vector operations |
159264c27929
Add some new vector and matrix operations, and introduce some SSE inline
Matti Hamalainen <ccr@tnsp.org>
parents:
244
diff
changeset
|
51 */ |
244 | 52 static inline void dm_vector_copy(DMVector *vd, const DMVector *vs) |
239
07c4f1a7ddc6
Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
53 { |
07c4f1a7ddc6
Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
54 memcpy(vd, vs, sizeof(DMVector)); |
07c4f1a7ddc6
Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
55 } |
07c4f1a7ddc6
Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
56 |
07c4f1a7ddc6
Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
57 |
07c4f1a7ddc6
Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
58 static inline void dm_vector_add(DMVector *vr, const DMVector *v2) |
07c4f1a7ddc6
Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
59 { |
07c4f1a7ddc6
Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
60 #ifdef DM_USE_SIMD |
07c4f1a7ddc6
Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
61 asm("movups %2, %%xmm1\n" |
07c4f1a7ddc6
Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
62 "movups %1, %%xmm2\n" |
07c4f1a7ddc6
Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
63 "addps %%xmm2, %%xmm1\n" |
07c4f1a7ddc6
Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
64 "movups %%xmm1, %0\n" |
07c4f1a7ddc6
Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
65 : "=m" (*vr) |
07c4f1a7ddc6
Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
66 : "m" (*vr), "m" (*v2) |
07c4f1a7ddc6
Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
67 : "memory", "%xmm1", "%xmm2"); |
07c4f1a7ddc6
Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
68 #else |
07c4f1a7ddc6
Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
69 vr->x += v2->x; |
07c4f1a7ddc6
Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
70 vr->y += v2->y; |
07c4f1a7ddc6
Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
71 vr->z += v2->z; |
07c4f1a7ddc6
Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
72 #endif |
07c4f1a7ddc6
Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
73 } |
07c4f1a7ddc6
Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
74 |
07c4f1a7ddc6
Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
75 |
07c4f1a7ddc6
Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
76 static inline void dm_vector_add_r(DMVector *vr, const DMVector *v1, const DMVector *v2) |
07c4f1a7ddc6
Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
77 { |
07c4f1a7ddc6
Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
78 #ifdef DM_USE_SIMD |
07c4f1a7ddc6
Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
79 asm("movups %2, %%xmm1\n" |
07c4f1a7ddc6
Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
80 "movups %1, %%xmm2\n" |
07c4f1a7ddc6
Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
81 "addps %%xmm2, %%xmm1\n" |
07c4f1a7ddc6
Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
82 "movups %%xmm1, %0\n" |
07c4f1a7ddc6
Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
83 : "=m" (*vr) |
07c4f1a7ddc6
Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
84 : "m" (*v1), "m" (*v2) |
07c4f1a7ddc6
Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
85 : "memory", "%xmm1", "%xmm2"); |
07c4f1a7ddc6
Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
86 #else |
07c4f1a7ddc6
Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
87 vr->x = v1->x + v2->x; |
07c4f1a7ddc6
Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
88 vr->y = v1->y + v2->y; |
07c4f1a7ddc6
Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
89 vr->z = v1->z + v2->z; |
07c4f1a7ddc6
Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
90 #endif |
07c4f1a7ddc6
Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
91 } |
07c4f1a7ddc6
Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
92 |
07c4f1a7ddc6
Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
93 |
07c4f1a7ddc6
Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
94 static inline void dm_vector_sub(DMVector *vr, const DMVector *v2) |
07c4f1a7ddc6
Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
95 { |
07c4f1a7ddc6
Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
96 #ifdef DM_USE_SIMD |
07c4f1a7ddc6
Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
97 asm("movups %2, %%xmm1\n" |
07c4f1a7ddc6
Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
98 "movups %1, %%xmm2\n" |
07c4f1a7ddc6
Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
99 "subps %%xmm2, %%xmm1\n" |
07c4f1a7ddc6
Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
100 "movups %%xmm1, %0\n" |
07c4f1a7ddc6
Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
101 : "=m" (*vr) |
07c4f1a7ddc6
Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
102 : "m" (*vr), "m" (*v2) |
07c4f1a7ddc6
Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
103 : "memory", "%xmm1", "%xmm2"); |
07c4f1a7ddc6
Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
104 #else |
07c4f1a7ddc6
Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
105 vr->x -= v2->x; |
07c4f1a7ddc6
Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
106 vr->y -= v2->y; |
07c4f1a7ddc6
Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
107 vr->z -= v2->z; |
07c4f1a7ddc6
Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
108 #endif |
07c4f1a7ddc6
Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
109 } |
07c4f1a7ddc6
Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
110 |
07c4f1a7ddc6
Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
111 |
07c4f1a7ddc6
Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
112 static inline void dm_vector_sub_r(DMVector *vr, const DMVector *v1, const DMVector *v2) |
07c4f1a7ddc6
Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
113 { |
07c4f1a7ddc6
Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
114 #ifdef DM_USE_SIMD |
07c4f1a7ddc6
Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
115 asm("movups %2, %%xmm1\n" |
07c4f1a7ddc6
Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
116 "movups %1, %%xmm2\n" |
07c4f1a7ddc6
Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
117 "subps %%xmm2, %%xmm1\n" |
07c4f1a7ddc6
Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
118 "movups %%xmm1, %0\n" |
07c4f1a7ddc6
Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
119 : "=m" (*vr) |
07c4f1a7ddc6
Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
120 : "m" (*v1), "m" (*v2) |
07c4f1a7ddc6
Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
121 : "memory", "%xmm1", "%xmm2"); |
07c4f1a7ddc6
Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
122 #else |
07c4f1a7ddc6
Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
123 vr->x = v1->x - v2->x; |
07c4f1a7ddc6
Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
124 vr->y = v1->y - v2->y; |
07c4f1a7ddc6
Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
125 vr->z = v1->z - v2->z; |
07c4f1a7ddc6
Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
126 #endif |
07c4f1a7ddc6
Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
127 } |
07c4f1a7ddc6
Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
128 |
07c4f1a7ddc6
Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
129 |
07c4f1a7ddc6
Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
130 /* Returns dot-product of two given vectors |
07c4f1a7ddc6
Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
131 */ |
07c4f1a7ddc6
Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
132 static inline DMFloat dm_vector_dot(const DMVector *v1, const DMVector *v2) |
07c4f1a7ddc6
Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
133 { |
07c4f1a7ddc6
Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
134 return (v1->x * v2->x) + (v1->y * v2->y) + (v1->z * v2->z); |
07c4f1a7ddc6
Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
135 } |
07c4f1a7ddc6
Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
136 |
07c4f1a7ddc6
Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
137 |
07c4f1a7ddc6
Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
138 /* Return vector length |
07c4f1a7ddc6
Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
139 */ |
07c4f1a7ddc6
Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
140 static inline DMFloat dm_vector_length(const DMVector *vs) |
07c4f1a7ddc6
Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
141 { |
07c4f1a7ddc6
Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
142 return sqrt((vs->x * vs->x) + (vs->y * vs->y) + (vs->z * vs->z)); |
07c4f1a7ddc6
Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
143 } |
07c4f1a7ddc6
Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
144 |
07c4f1a7ddc6
Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
145 |
07c4f1a7ddc6
Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
146 /* Normalize vector |
07c4f1a7ddc6
Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
147 */ |
07c4f1a7ddc6
Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
148 static inline void dm_vector_normalize(DMVector *vec) |
07c4f1a7ddc6
Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
149 { |
07c4f1a7ddc6
Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
150 DMFloat l = dm_vector_length(vec); |
07c4f1a7ddc6
Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
151 |
07c4f1a7ddc6
Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
152 if (l > 0.0f) |
07c4f1a7ddc6
Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
153 { |
07c4f1a7ddc6
Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
154 l = 1.0f / l; |
07c4f1a7ddc6
Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
155 vec->x *= l; |
07c4f1a7ddc6
Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
156 vec->y *= l; |
07c4f1a7ddc6
Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
157 vec->z *= l; |
07c4f1a7ddc6
Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
158 } |
07c4f1a7ddc6
Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
159 } |
07c4f1a7ddc6
Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
160 |
07c4f1a7ddc6
Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
161 |
07c4f1a7ddc6
Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
162 /* Scale given vector |
07c4f1a7ddc6
Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
163 */ |
07c4f1a7ddc6
Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
164 static inline void dm_vector_scale(DMVector * vec, const DMFloat k) |
07c4f1a7ddc6
Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
165 { |
07c4f1a7ddc6
Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
166 vec->x *= k; |
07c4f1a7ddc6
Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
167 vec->y *= k; |
07c4f1a7ddc6
Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
168 vec->z *= k; |
07c4f1a7ddc6
Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
169 } |
07c4f1a7ddc6
Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
170 |
07c4f1a7ddc6
Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
171 |
07c4f1a7ddc6
Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
172 /* Returns cross-product of two given vectors |
07c4f1a7ddc6
Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
173 */ |
07c4f1a7ddc6
Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
174 static inline void dm_vector_cross(DMVector *vr, const DMVector *v1, const DMVector *v2) |
07c4f1a7ddc6
Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
175 { |
07c4f1a7ddc6
Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
176 vr->x = (v1->y * v2->z) - (v1->z * v2->y); |
07c4f1a7ddc6
Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
177 vr->y = (v1->z * v2->x) - (v1->x * v2->z); |
07c4f1a7ddc6
Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
178 vr->z = (v1->x * v2->y) - (v1->y * v2->x); |
07c4f1a7ddc6
Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
179 } |
07c4f1a7ddc6
Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
180 |
07c4f1a7ddc6
Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
181 |
07c4f1a7ddc6
Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
182 /* Make rotation matrix from given angles (radians) |
07c4f1a7ddc6
Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
183 */ |
07c4f1a7ddc6
Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
184 static inline void dm_matrix_rot_a(DMMatrix *mat, const DMFloat ax, const DMFloat ay, const DMFloat az) |
07c4f1a7ddc6
Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
185 { |
07c4f1a7ddc6
Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
186 dm_matrix_rot(mat, sin(ax), sin(ay), sin(az), cos(ax), cos(ay), cos(az)); |
07c4f1a7ddc6
Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
187 } |
0 | 188 |
189 | |
190 #ifdef __cplusplus | |
191 } | |
192 #endif | |
193 #endif // DMVECMAT_H |