Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
20 | pmbaty | 1 | #ifndef BR_INLINE_FUNCS_H |
2 | #define BR_INLINE_FUNCS_H |
||
3 | |||
4 | #include "br_defs.h" |
||
5 | |||
6 | #define BrVector2Set(v1, s1, s2) \ |
||
7 | do { \ |
||
8 | (v1)->v[0] = (s1); \ |
||
9 | (v1)->v[1] = (s2); \ |
||
10 | } while (0) |
||
11 | |||
12 | #define BrVector3Length(v1) BR_LENGTH3((v1)->v[0], (v1)->v[1], (v1)->v[2]) |
||
13 | #define BrVector3LengthSquared(v1) BR_SQR3((v1)->v[0], (v1)->v[1], (v1)->v[2]) |
||
14 | #define BrVector3Dot(v1, v2) BR_MAC3((v1)->v[0], (v2)->v[0], (v1)->v[1], (v2)->v[1], (v1)->v[2], (v2)->v[2]) |
||
15 | |||
16 | #define BrVector3Copy(v1, v2) \ |
||
17 | do { \ |
||
18 | (v1)->v[0] = (v2)->v[0]; \ |
||
19 | (v1)->v[1] = (v2)->v[1]; \ |
||
20 | (v1)->v[2] = (v2)->v[2]; \ |
||
21 | } while (0) |
||
22 | |||
23 | #define BrVector3Negate(v1, v2) \ |
||
24 | do { \ |
||
25 | (v1)->v[0] = -(v2)->v[0]; \ |
||
26 | (v1)->v[1] = -(v2)->v[1]; \ |
||
27 | (v1)->v[2] = -(v2)->v[2]; \ |
||
28 | } while (0) |
||
29 | |||
30 | #define BrVector3Set(v1, s1, s2, s3) \ |
||
31 | do { \ |
||
32 | (v1)->v[0] = (s1); \ |
||
33 | (v1)->v[1] = (s2); \ |
||
34 | (v1)->v[2] = (s3); \ |
||
35 | } while (0) |
||
36 | |||
37 | #define BrVector3Cross(v1, v2, v3) \ |
||
38 | do { \ |
||
39 | (v1)->v[0] = (v2)->v[1] * (v3)->v[2] - (v2)->v[2] * (v3)->v[1]; \ |
||
40 | (v1)->v[1] = (v2)->v[2] * (v3)->v[0] - (v2)->v[0] * (v3)->v[2]; \ |
||
41 | (v1)->v[2] = (v2)->v[0] * (v3)->v[1] - (v2)->v[1] * (v3)->v[0]; \ |
||
42 | } while (0) |
||
43 | |||
44 | #define BrVector3Add(v1, v2, v3) \ |
||
45 | do { \ |
||
46 | (v1)->v[0] = (v2)->v[0] + (v3)->v[0]; \ |
||
47 | (v1)->v[1] = (v2)->v[1] + (v3)->v[1]; \ |
||
48 | (v1)->v[2] = (v2)->v[2] + (v3)->v[2]; \ |
||
49 | } while (0) |
||
50 | |||
51 | #define BrVector3Sub(v1, v2, v3) \ |
||
52 | do { \ |
||
53 | (v1)->v[0] = (v2)->v[0] - (v3)->v[0]; \ |
||
54 | (v1)->v[1] = (v2)->v[1] - (v3)->v[1]; \ |
||
55 | (v1)->v[2] = (v2)->v[2] - (v3)->v[2]; \ |
||
56 | } while (0) |
||
57 | |||
58 | #define BrVector3Mul(v1, v2, v3) \ |
||
59 | do { \ |
||
60 | (v1)->v[0] = (v2)->v[0] * (v3)->v[0]; \ |
||
61 | (v1)->v[1] = (v2)->v[1] * (v3)->v[1]; \ |
||
62 | (v1)->v[2] = (v2)->v[2] * (v3)->v[2]; \ |
||
63 | } while (0) |
||
64 | |||
65 | #define BrVector3Accumulate(v1, v2) \ |
||
66 | do { \ |
||
67 | (v1)->v[0] += (v2)->v[0]; \ |
||
68 | (v1)->v[1] += (v2)->v[1]; \ |
||
69 | (v1)->v[2] += (v2)->v[2]; \ |
||
70 | } while (0) |
||
71 | |||
72 | #define BrVector3Scale(v1, v2, s) \ |
||
73 | do { \ |
||
74 | (v1)->v[0] = (v2)->v[0] * (s); \ |
||
75 | (v1)->v[1] = (v2)->v[1] * (s); \ |
||
76 | (v1)->v[2] = (v2)->v[2] * (s); \ |
||
77 | } while (0) |
||
78 | |||
79 | #define BrVector3InvScale(v1, v2, s) \ |
||
80 | do { \ |
||
81 | br_scalar __scale = 1.0f / (s); \ |
||
82 | (v1)->v[0] = (v2)->v[0] * __scale; \ |
||
83 | (v1)->v[1] = (v2)->v[1] * __scale; \ |
||
84 | (v1)->v[2] = (v2)->v[2] * __scale; \ |
||
85 | } while (0) |
||
86 | |||
87 | #define BrVector3Normalise(v1, v2) \ |
||
88 | do { \ |
||
89 | br_scalar _scale; \ |
||
90 | _scale = BR_LENGTH3((v2)->v[0], (v2)->v[1], (v2)->v[2]); \ |
||
91 | if (_scale > BR_SCALAR_EPSILON * 2) { \ |
||
92 | _scale = 1.0 / (_scale); \ |
||
93 | (v1)->v[0] = (v2)->v[0] * _scale; \ |
||
94 | (v1)->v[1] = (v2)->v[1] * _scale; \ |
||
95 | (v1)->v[2] = (v2)->v[2] * _scale; \ |
||
96 | } else { \ |
||
97 | (v1)->v[0] = 1.0f; \ |
||
98 | (v1)->v[1] = 0.0f; \ |
||
99 | (v1)->v[2] = 0.0f; \ |
||
100 | } \ |
||
101 | } while (0) |
||
102 | |||
103 | #define BrVector3NormaliseQuick(v1, v2) \ |
||
104 | do { \ |
||
105 | br_scalar _scale; \ |
||
106 | _scale = 1.0f / (BR_LENGTH3((v2)->v[0], (v2)->v[1], (v2)->v[2])); \ |
||
107 | BrVector3Scale(v1, v2, _scale); \ |
||
108 | } while (0) |
||
109 | |||
110 | #define BR_ONE_LS (0x00010000) |
||
111 | #define BrFixedToFloat(s) ((float)((s) * (1.0 / (float)BR_ONE_LS))) |
||
112 | #endif |