annotate src/dmvecmat.h @ 2298:b5abfff07ca9

Add new DMGrowBuf helper functions dmGrowBufCopyOffsSize() and dmGrowBufConstCopyOffsSize().
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 04 Jul 2019 10:54:16 +0300
parents 27949209238b
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1 /*
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
2 * DMLib
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
3 * -- Vector and matrix functions
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
4 * Programmed and designed by Matti 'ccr' Hamalainen
863
27949209238b Update copyrights.
Matti Hamalainen <ccr@tnsp.org>
parents: 812
diff changeset
5 * (C) Copyright 2011-2015 Tecnic Software productions (TNSP)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
6 */
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
7 #ifndef DMVECMAT_H
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
8 #define DMVECMAT_H
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
9 #include "dmlib.h"
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
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
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
13 #ifdef __cplusplus
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
14 extern "C" {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
15 #endif
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
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
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
18
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
19 typedef struct
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
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
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
22 } DMVector;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
23
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
24 typedef struct
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
25 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
26 DMFloat m[DM_MATRIX_SIZE][DM_MATRIX_SIZE];
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
27 } DMMatrix;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
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
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
36 void dm_vector_mul_by_mat_n(DMVector *list, const int nlist, const DMMatrix *mat);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
37
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
38 void dm_matrix_unit(DMMatrix *mat);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
39 void dm_matrix_transpose(DMMatrix *mat1, const DMMatrix *mat2);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
40
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
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
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
43 void dm_matrix_mul_n(DMMatrix *list, const int nlist, const DMMatrix *mat);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
44
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
45 void dm_matrix_rot(DMMatrix *mat,
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
46 const DMFloat sx, const DMFloat sy, const DMFloat sz,
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
47 const DMFloat cx, const DMFloat cy, const DMFloat cz);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
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
00785510b743 Constify.
Matti Hamalainen <ccr@tnsp.org>
parents: 239
diff changeset
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 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
61 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
62 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
63 }
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
64
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
65
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
66 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
67 {
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
68 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
69 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
70 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
71 }
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
72
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 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
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 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
77 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
78 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
79 }
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
80
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
81
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
82 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
83 {
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
84 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
85 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
86 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
87 }
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
88
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
89
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
90 /* 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
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 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
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 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
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
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
97
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
98 /* 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
99 */
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
100 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
101 {
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
102 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
103 }
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
104
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
105
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
106 /* 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
107 */
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
108 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
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 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
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 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
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 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
115 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
116 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
117 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
118 }
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
119 }
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
120
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
121
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
122 /* 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
123 */
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
124 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
125 {
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
126 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
127 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
128 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
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
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 /* 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
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 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
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 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
137 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
138 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
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
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 /* 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
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 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
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 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
147 }
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
148
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
149
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
150 #ifdef __cplusplus
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
151 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
152 #endif
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
153 #endif // DMVECMAT_H