Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision |
math [2019/04/20 19:57] – [Pi and Tau] korshun | math [2019/07/04 20:44] – [AnglesToVector] korshun |
---|
| |
==== e ==== | ==== e ==== |
''fixed MATH_E = 2.7182818284590452353602874713526624977572470937;'' | ''#define MATH_E 2.7182818284590452353602874713526624977572470937'' |
| |
The number [[wp>E_(mathematical_constant)|e]]. Called ''MATH_E'' to avoid conflicts with variable name ''e''. | The number [[wp>E_(mathematical_constant)|e]]. Called ''MATH_E'' to avoid conflicts with variable name ''e''. |
Precalculated to maximum precision. The precalculated logarithms are used to implement ''ln'' and ''log10''. | Precalculated to maximum precision. The precalculated logarithms are used to implement ''ln'' and ''log10''. |
| |
* ''fixed SQRT_2 = 1.41421356237;'' -- sqrt(2) | * ''#define SQRT_2 1.41421356237'' -- sqrt(2) |
* ''fixed LOG2_E = 1.44269504089;'' -- log2(e) | * ''#define LOG2_E 1.44269504089'' -- log2(e) |
* ''fixed LOG2_10 = 3.32192809489;'' -- log2(10) | * ''#define LOG2_10 3.32192809489'' -- log2(10) |
| |
===== Generic math functions ===== | ===== Generic math functions ===== |
Converts the vector's direction to a pair of angles (angle, pitch) and returns them using [[multiple return values]]. | Converts the vector's direction to a pair of angles (angle, pitch) and returns them using [[multiple return values]]. |
| |
<note important>Remember that ZDoom uses inverted pitch angles on actors. ACSUtils functions don't invert pitches.</note> | <note important>Remember that ZDoom uses negated pitch angles on actors. ACSUtils functions don't invert pitches.</note> |
| |
=== Example usage === | === Example usage === |
int pitch = r2; | int pitch = r2; |
SetActorAngle(tid, angle); | SetActorAngle(tid, angle); |
SetActorPitch(tid, -pitch); // SetActorPitch expects inverted pitch. | SetActorPitch(tid, -pitch); // SetActorPitch expects negated pitch. |
} | } |
</code> | </code> |
Converts a pair of angles (angle, pitch) to a 3D vector of length ''1.0'', which points in the same direction, and returns it using [[multiple return values]]. | Converts a pair of angles (angle, pitch) to a 3D vector of length ''1.0'', which points in the same direction, and returns it using [[multiple return values]]. |
| |
<note important>Remember that ZDoom uses inverted pitches on actors. ACSUtils functions don't invert pitches.</note> | <note important>Remember that ZDoom uses negated pitch angles on actors. ACSUtils functions don't use negated pitches.</note> |
| |
| === Example usage === |
| |
| <code> |
| AnglesToVector(GetActorAngle(0), -GetActorPitch(0)); // Un-negate actor pitch |
| int dirX = r1; |
| int dirY = r2; |
| int dirZ = r3; |
| </code> |
| |
===== Logarithms ===== | ===== Logarithms ===== |
| |
<note important>Only bases higher than ''1.0'' are supported.</note> | <note important>Only bases higher than ''1.0'' are supported.</note> |
| |
<note important>Using ''ilogb'' with bases very close to ''1.0'' may produce a result that doesn't fit into a fixed.</note> | <note important>Using these functions with bases very close to ''1.0'' may produce a result that doesn't fit into a fixed.</note> |
| |
Note that even the integer version has a fixed-point base. | Note that even the integer version has a fixed-point base. |
| |