2 void fixedmakevectors(vector a)
4 // a makevectors that actually inverts vectoangles
10 // angles in fixedmakevectors/fixedvectoangles space
11 vector AnglesTransform_Apply(vector transform, vector v)
13 fixedmakevectors(transform);
14 return v_forward * v_x
19 vector AnglesTransform_Multiply(vector t1, vector t2)
21 vector m_forward, m_up;
22 fixedmakevectors(t2); m_forward = v_forward; m_up = v_up;
23 m_forward = AnglesTransform_Apply(t1, m_forward); m_up = AnglesTransform_Apply(t1, m_up);
24 return fixedvectoangles2(m_forward, m_up);
27 vector AnglesTransform_Invert(vector transform)
29 vector i_forward, i_up;
30 fixedmakevectors(transform);
31 // we want angles that turn v_forward into '1 0 0', v_right into '0 1 0' and v_up into '0 0 1'
32 // but these are orthogonal unit vectors!
33 // so to invert, we can simply fixedvectoangles the TRANSPOSED matrix
34 // TODO is this always -transform?
35 i_forward_x = v_forward_x;
36 i_forward_y = -v_right_x;
41 return fixedvectoangles2(i_forward, i_up);
44 vector AnglesTransform_TurnDirectionFR(vector transform)
46 // turn 180 degrees around v_up
47 // changes in-direction to out-direction
48 //fixedmakevectors(transform);
49 //return fixedvectoangles2(-1 * v_forward, 1 * v_up);
50 transform_x = -transform_x;
51 transform_y = 180 + transform_y;
52 transform_z = -transform_z;
59 vector AnglesTransform_TurnDirectionFU(vector transform)
61 // turn 180 degrees around v_up
62 // changes in-direction to out-direction
63 //fixedmakevectors(transform);
64 //return fixedvectoangles2(-1 * v_forward, 1 * v_up);
65 transform_x = -transform_x;
66 transform_y = 180 + transform_y;
67 transform_z = 180 - transform_z;
71 vector AnglesTransform_Divide(vector to_transform, vector from_transform)
73 return AnglesTransform_Multiply(to_transform, AnglesTransform_Invert(from_transform));
76 vector AnglesTransform_Normalize(vector t, float minimize_roll)
79 // first, bring all angles in their range...
80 t_x = t_x - 360 * rint(t_x / 360);
81 t_y = t_y - 360 * rint(t_y / 360);
82 t_z = t_z - 360 * rint(t_z / 360);
84 need_flip = (t_z > 90 || t_z <= -90);
86 need_flip = (t_x > 90 || t_x < -90); // for pitch we prefer to allow exactly -90 degrees for looking straight down
89 if(t_x >= 0) t_x = 180 - t_x; else t_x = -180 - t_x;
90 if(t_y > 0) t_y -= 180; else t_y += 180;
91 if(t_z > 0) t_z -= 180; else t_z += 180;
96 vector AnglesTransform_ApplyToVAngles(vector transform, vector v)
99 v = AnglesTransform_ApplyToAngles(transform, v);