-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathD3d_matrix.h
214 lines (130 loc) · 4.62 KB
/
D3d_matrix.h
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
#ifndef D3d_matrix_stuff
#define D3d_matrix_stuff
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
/*
( x') (x)
( y') = M * (y)
( z') (z)
( 1 ) (1)
instead of (x',y',z',1) = (x,y,z,1) * M
*/
#define SX 0
#define SY 1
#define SZ 2
#define RX 3
#define RY 4
#define RZ 5
#define TX 6
#define TY 7
#define TZ 8
#define NX 9
#define NY 10
#define NZ 11
int D3d_print_mat (double a[4][4]) ;
int D3d_copy_mat (double a[4][4], double b[4][4]) ;
// a = b
int D3d_mat_mult (double res[4][4], double a[4][4], double b[4][4]) ;
// res = a * b
// this is SAFE, i.e. the user can make a call such as
// D3d_mat_mult(p, p,q) or D3d_mat_mult(p, q,p) or D3d_mat_mult(p, p,p)
int D3d_make_identity (double a[4][4]) ;
// a = I
int D3d_translate (double a[4][4], double b[4][4],
double dx, double dy, double dz) ;
// a = translation*a
// b = b*translation_inverse
int D3d_scale (double a[4][4], double b[4][4],
double sx, double sy, double sz) ;
// a = scale*a
// b = b*scale_inverse
int D3d_rotate_x (double a[4][4], double b[4][4], double radians) ;
// a = rotate*a
// b = b*rotate_inverse
int D3d_rotate_y (double a[4][4], double b[4][4], double radians) ;
// a = rotate*a
// b = b*rotate_inverse
int D3d_rotate_z (double a[4][4], double b[4][4], double radians) ;
// a = rotate*a
// b = b*rotate_inverse
int D3d_cs_rotate_x (double a[4][4], double b[4][4], double cs, double sn) ;
// a = rotate*a
// b = b*rotate_inverse
int D3d_cs_rotate_y (double a[4][4], double b[4][4], double cs, double sn) ;
// a = rotate*a
// b = b*rotate_inverse
int D3d_cs_rotate_z (double a[4][4], double b[4][4], double cs, double sn) ;
// a = rotate*a
// b = b*rotate_inverse
int D3d_negate_x (double a[4][4], double b[4][4]) ;
// negate the x....reflects in the yz-plane
// a = reflect*a
// b = b*reflect_inverse
int D3d_negate_y (double a[4][4], double b[4][4]) ;
// negate the y....reflects in the xz-plane
// a = reflect*a
// b = b*reflect_inverse
int D3d_negate_z (double a[4][4], double b[4][4]) ;
// negate the z....reflects in the xy-plane
// a = reflect*a
// b = b*reflect_inverse
int D3d_mat_mult_points (double *X, double *Y, double *Z,
double m[4][4],
double *x, double *y, double *z, int numpoints) ;
// |X0 X1 X2 ...| |x0 x1 x2 ...|
// |Y0 Y1 Y2 ...| = m * |y0 y1 y2 ...|
// |Z0 Z1 Z2 ...| |z0 z1 z2 ...|
// | 1 1 1 ...| | 1 1 1 ...|
// SAFE, user may make a call like D3d_mat_mult_points (x,y,z, m, x,y,z, n) ;
int D3d_mat_mult_pt (double P[3],
double m[4][4],
double Q[3]) ;
// multiplies a SINGLE point by a matrix
// | P[0] | | Q[0] |
// | P[1] | = m * | Q[1] |
// | P[2] | | Q[2] |
// | 1 | | 1 |
// SAFE, user may make a call like
// D3d_mat_mult_pt (q, m,q) ;
int D3d_x_product (double res[3], double a[3], double b[3]) ;
// res = a x b , cross product of two vectors
// SAFE: it is ok to make a call such as
// D3d_x_product (a, a,b) or
// D3d_x_product (b, a,b) or
// D3d_x_product (a, a,a)
double D3d_dot_product(double vect1[3], double vect2[3]) ;
int D3d_make_movement_sequence_matrix (
double mat[4][4],
double inv[4][4],
int num_movements,
int *movement_type_list,
double *parameter_list ) ;
// create a matrix (mat) and its inverse (inv)
// that specify a sequence of movements....
// movement_type_list[k] is an integer that
// specifies the type of matrix to be used in the
// the k-th movement. the parameter that each
// matrix needs is supplied in parameter_list[k].
// return 1 if successful, 0 if error
// the codes for movement_type_list are :
// 0 - scale x
// 1 - scale y
// 2 - scale z
// 3 - rotate x
// 4 - rotate y
// 5 - rotate z
// 6 - translate x
// 7 - translate y
// 8 - translate z
// 9 - negate x...reflect in the yz plane
// 10 - negate y...relfect in the xz plane
// 11 - negate z...reflect in the zy plane
int D3d_view (double view[4][4], double view_inverse[4][4],
double eye_x, double eye_y, double eye_z ,
double coi_x, double coi_y, double coi_z ,
double up_x, double up_y, double up_z ) ;
// Construct the view matrix and its inverse given the location
// of the eye, the center of interest, and an up point.
// return 1 if successful, 0 otherwise.
#endif