Daemon icon indicating copy to clipboard operation
Daemon copied to clipboard

confirmation of math functions roles

Open ghost opened this issue 4 years ago • 3 comments

To ease glm migration in unvanquished, I would like confirmation of some q_math.cpp functions role (that I have seen a lot). It as to be noted that I think everything works in degrees, but I am not actually certain about it.

ghost avatar Feb 25 '22 14:02 ghost

* [void vectoangles( const vec3_t value1, vec3_t angles )](https://github.com/DaemonEngine/Daemon/blob/master/src/engine/qcommon/q_math.cpp#L415-L469)
  
  * Transforms a vector (vec3_t) into pitch, yaw, roll, in degrees.
  * The value it returns as a roll is always 0, so I suspect I do not understand what it really does (and sees even less how to properly replace it)

I think your assesment is correct. Basically it turns a vector of carthesian coordinates into polar coordinates, without the angle. It uses a 0 for the third value (roll), which would be the rotation along the vector: if you look where the vector points, it would be the tilt of your head.

Note however that those are "reversed" as the vectors are not oriented correctly ("repère orthonormé indirect" instead of "direct"). If you start doing vector math with it you must be cautious because e.g. vector products get a minus sign. That's why AnglesToAxis exist.

In this conversion, the magnitude (length) of the vector is lost.

* [AngleVectors ( vec3_t dst, const vec3_t src )  ](https://github.com/DaemonEngine/Daemon/blob/master/src/engine/qcommon/q_math.cpp#L1112)
  
  * takes roll/yaw/pitch angles and generates direction, and thus normalized, vectors describing orientations upward, forward, and rightward.

Exactly. And the magnitude of these vectors should be 1 (I only checked for the forward one though). Which means that they should be axis vectors.

Note the roll information would be ignored as it can't be represented in this notation.

* [void  AnglesToAxis( const vec3_t angles, vec3_t axis[ 3 ] )](https://github.com/DaemonEngine/Daemon/blob/master/src/engine/qcommon/q_math.cpp#L476-L483)
  
  * no idea

It returns whatever AngleVectors returns, except it negates the second. So it returns (forward, left, up) instead of (forward, right, up). It's a proper axis definition and you can do physics with it without fear.

* [void  AxisToAngles( /_const_/ vec3_t axis[ 3 ], vec3_t angles )](https://github.com/DaemonEngine/Daemon/blob/master/src/engine/qcommon/q_math.cpp#L1390-L1461)
  
  * the inverse of "no idea" is still "no idea"

I have some doubts that it is actually the opposite of AnglesToAxis. It looks similar to AngleVectors but manages to define roll somehow??? Haven't looked much at it, I may look for an answer another day.

necessarily-equal avatar Aug 03 '22 12:08 necessarily-equal

You may like http://www.songho.ca/opengl/gl_anglestoaxes.html as it seems quite similar. The convention may be a bit different, such as which axis are which, and which directions may change — e.g. (x, -z, y)

necessarily-equal avatar Aug 03 '22 17:08 necessarily-equal