DaemonEngine / Daemon

The Dæmon game engine. With some bits of ioq3 and XreaL.
https://unvanquished.net
BSD 3-Clause "New" or "Revised" License
298 stars 61 forks source link

confirmation of math functions roles #585

Open ghost opened 2 years ago

ghost commented 2 years ago

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.

necessarily-equal commented 2 years ago
* [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 commented 2 years ago

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)

VReaperV commented 1 month ago

vectoangles() is only ever used in the old shadowmap code, where roll doesn't matter.

axis_t (which is the same as vec3_t[3]) represents the 3 normalised vectors for each of the 3 axes defining rotation, AnglesToAxis() and AxisToAngles() convert between those and Euler angles.