-
Notifications
You must be signed in to change notification settings - Fork 1
/
bc_lib.bc
73 lines (65 loc) · 1.36 KB
/
bc_lib.bc
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
/* Subtract the second vector from the first vector */
define vec_diff(v1[], v2[], *vdiff[]) {
auto i
for (i = 0; i < 3; ++i)
vdiff[i] = v1[i] - v2[i]
}
/* Dot product of two vectors */
define dot_prod(v1[], v2[]) {
auto i, prod
for (i = 0; i < 3; ++i)
prod += v1[i] * v2[i]
return prod
}
/* Cross product of two vectors */
define cross_prod(v1[], v2[], *vcr[]) {
vcr[0] = v1[1] * v2[2] - v1[2] * v2[1]
vcr[1] = v1[2] * v2[0] - v1[0] * v2[2]
vcr[2] = v1[0] * v2[1] - v1[1] * v2[0]
}
/* Normalize a vector */
define normalize(*v[]) {
auto len, i
len = sqrt(v[0]^2 + v[1]^2 + v[2]^2)
for (i = 0; i < 3; ++i)
v[i] /= len
}
/* Invert a vector */
define invert(*v[]) {
auto i
for (i = 0; i < 3; ++i)
v[i] *= -1
}
/* Absolute value */
define abs(val) {
if (val > 0) {
return val
} else {
return -val
}
}
/* Floor towards next smaller number (and not zero)
pay attention to scale, should be 0 */
define floor(val) {
if (val > 0) {
return val - (val % 1)
} else {
return val - (val % 1) - 1
}
}
/* Return smaller of two values */
define min(a, b) {
if (a < b) {
return a
} else {
return b
}
}
/* Return larger of two values */
define max(a, b) {
if (a > b) {
return a
} else {
return b
}
}