Mathematical functions.
More...
|
#define | oslAbs(x) |
| Returns the absolute value of a number.
|
|
#define | oslMin(x, y) |
| Returns the smallest value between the two.
|
|
#define | oslMax(x, y) |
| Returns the greatest value between the two.
|
|
#define | oslMinMax(x, min, max) |
| Returns a value clamped between a minimum and maximum.
|
|
#define | oslNumberof(n) |
| Returns the number of objects in an array.
|
|
|
float | oslSin (float angle, float dist) |
| Calculates the sine of an angle in degrees multiplied by a radius.
|
|
float | oslCos (float angle, float dist) |
| Calculates the cosine of an angle in degrees multiplied by a radius.
|
|
int | oslSini (int angle, int dist) |
| Returns the sine of an angle in degrees (0 to 360) multiplied by an integer radius.
|
|
int | oslCosi (int angle, int dist) |
| Returns the cosine of an angle in degrees (0 to 360) multiplied by an integer radius.
|
|
int | oslGetNextPower2 (int val) |
| Returns the next (upper) power of two of a number.
|
|
void | oslSetupFTrigo () |
| Sets up the floating-point trigonometric tables.
|
|
|
int | osl_isinus [361] |
| Precomputed sine values for angles from 0 to 360 degrees.
|
|
int | osl_icosinus [361] |
| Precomputed cosine values for angles from 0 to 360 degrees.
|
|
Mathematical functions.
This section provides mathematical utilities, such as trigonometric functions, commonly used in game development.
◆ oslAbs
Value:(((x) < 0) ? (-(x)) : (x))
Returns the absolute value of a number.
This function returns the positive part of the number.
- Parameters
-
- Returns
- Absolute value of the input.
◆ oslMin
Value:(((x) < (y)) ? (x) : (y))
Returns the smallest value between the two.
This function returns the smaller of the two provided values.
- Parameters
-
x | First value. |
y | Second value. |
- Returns
- Smallest value.
◆ oslMax
Value:(((x) > (y)) ? (x) : (y))
Returns the greatest value between the two.
This function returns the larger of the two provided values.
- Parameters
-
x | First value. |
y | Second value. |
- Returns
- Greatest value.
◆ oslMinMax
#define oslMinMax |
( |
| x, |
|
|
| min, |
|
|
| max ) |
Value:((x) < (max) ? ((x) > (min) ? (x) : (min)) : (max))
Returns a value clamped between a minimum and maximum.
This function ensures that the provided value is within the specified range.
- Parameters
-
x | Input value. |
min | Minimum value. |
max | Maximum value. |
- Returns
- Clamped value.
◆ oslNumberof
Value:(sizeof(n) / sizeof(*(n)))
Returns the number of objects in an array.
This function calculates the number of elements in an array.
- Parameters
-
- Returns
- Number of elements in the array.
◆ oslSin()
float oslSin |
( |
float | angle, |
|
|
float | dist ) |
|
extern |
Calculates the sine of an angle in degrees multiplied by a radius.
This function returns the sine of the specified angle, multiplied by the provided radius.
- Parameters
-
angle | Angle in degrees. |
dist | Radius of the circle. |
- Returns
- Sine of the angle multiplied by the radius.
◆ oslCos()
float oslCos |
( |
float | angle, |
|
|
float | dist ) |
|
extern |
Calculates the cosine of an angle in degrees multiplied by a radius.
This function returns the cosine of the specified angle, multiplied by the provided radius.
- Parameters
-
angle | Angle in degrees. |
dist | Radius of the circle. |
- Returns
- Cosine of the angle multiplied by the radius.
◆ oslSini()
int oslSini |
( |
int | angle, |
|
|
int | dist ) |
|
extern |
Returns the sine of an angle in degrees (0 to 360) multiplied by an integer radius.
This function uses a lookup table for faster computation.
- Parameters
-
angle | Angle in degrees. |
dist | Radius of the circle. |
- Returns
- Sine of the angle multiplied by the radius.
◆ oslCosi()
int oslCosi |
( |
int | angle, |
|
|
int | dist ) |
|
extern |
Returns the cosine of an angle in degrees (0 to 360) multiplied by an integer radius.
This function uses a lookup table for faster computation.
- Parameters
-
angle | Angle in degrees. |
dist | Radius of the circle. |
- Returns
- Cosine of the angle multiplied by the radius.
◆ oslGetNextPower2()
int oslGetNextPower2 |
( |
int | val | ) |
|
|
extern |
Returns the next (upper) power of two of a number.
This function calculates the next power of two that is greater than or equal to the input value.
- Parameters
-
- Returns
- Next power of two.
◆ oslSetupFTrigo()
Sets up the floating-point trigonometric tables.
This function initializes internal trigonometric tables that are used for floating-point trigonometric calculations. It must be called during the setup process of OSLib before any floating-point trigonometric functions are used.
- Note
- This setup is necessary for functions like
oslSin
and oslCos
to work properly.
◆ osl_isinus
Precomputed sine values for angles from 0 to 360 degrees.
This array contains the precomputed sine values for each degree from 0 to 360. The values are scaled to a fixed-point format for faster computation in integer-based operations. This array is used by functions like oslSini
for efficient trigonometric calculations without needing to compute sine values at runtime.
- Note
- The array index corresponds directly to the angle in degrees.
◆ osl_icosinus
Precomputed cosine values for angles from 0 to 360 degrees.
This array contains the precomputed cosine values for each degree from 0 to 360. Like osl_isinus
, the values are scaled to a fixed-point format for efficient integer-based operations. This array is used by functions like oslCosi
to quickly obtain cosine values without runtime computation.
- Note
- The array index corresponds directly to the angle in degrees.