]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/lib/angle.qc
remove multiple declarations of v_angle, document usage of v_angle and angles
[xonotic/xonotic-data.pk3dir.git] / qcsrc / lib / angle.qc
1 .vector origin;
2
3 // angles of the player's model (as opposed to his view which uses `.vector v_angle;`)
4 // x is pitch, y is yaw, z is roll
5 .vector angles;
6
7 /*
8 * Return a angle within +/- 360.
9 */
10 float anglemods(float v)
11 {
12         v = v - 360 * floor(v / 360);
13
14         if(v >= 180)
15                 return v - 360;
16         else if(v <= -180)
17                 return v + 360;
18         else
19                 return v;
20 }
21
22 /*
23 * Return the short angle
24 */
25 float shortangle_f(float ang1, float ang2)
26 {
27         if(ang1 > ang2)
28         {
29                 if(ang1 > 180)
30                         return ang1 - 360;
31         }
32         else
33         {
34                 if(ang1 < -180)
35                         return ang1 + 360;
36         }
37
38         return ang1;
39 }
40
41 vector shortangle_v(vector ang1, vector ang2)
42 {
43         vector vtmp;
44
45         vtmp_x = shortangle_f(ang1_x,ang2_x);
46         vtmp_y = shortangle_f(ang1_y,ang2_y);
47         vtmp_z = shortangle_f(ang1_z,ang2_z);
48
49         return vtmp;
50 }
51
52 vector shortangle_vxy(vector ang1, vector ang2)
53 {
54         vector vtmp = '0 0 0';
55
56         vtmp_x = shortangle_f(ang1_x,ang2_x);
57         vtmp_y = shortangle_f(ang1_y,ang2_y);
58
59         return vtmp;
60 }
61
62 /*
63 * Return the angle between two enteties
64 */
65 vector angleofs(entity from, entity to)
66 {
67         vector v_res;
68
69         v_res = normalize(to.origin - from.origin);
70         v_res = vectoangles(v_res);
71         v_res = v_res - from.angles;
72
73         if (v_res_x < 0)        v_res_x += 360;
74         if (v_res_x > 180)      v_res_x -= 360;
75
76         if (v_res_y < 0)        v_res_y += 360;
77         if (v_res_y > 180)      v_res_y -= 360;
78
79         return v_res;
80 }
81
82 vector angleofs3(vector from, vector from_a, entity to)
83 {
84         vector v_res;
85
86         v_res = normalize(to.origin - from);
87         v_res = vectoangles(v_res);
88         v_res = v_res - from_a;
89
90         if (v_res_x < 0)        v_res_x += 360;
91         if (v_res_x > 180)      v_res_x -= 360;
92
93         if (v_res_y < 0)        v_res_y += 360;
94         if (v_res_y > 180)      v_res_y -= 360;
95
96         return v_res;
97 }