OldSchool Library
Maths

Mathematical functions. More...

Macros

#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.
 

Functions

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.
 

Variables

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.
 

Detailed Description

Mathematical functions.

This section provides mathematical utilities, such as trigonometric functions, commonly used in game development.

Macro Definition Documentation

◆ oslAbs

#define oslAbs ( x)
Value:
(((x) < 0) ? (-(x)) : (x))

Returns the absolute value of a number.

This function returns the positive part of the number.

Parameters
xInput value.
Returns
Absolute value of the input.

◆ oslMin

#define oslMin ( x,
y )
Value:
(((x) < (y)) ? (x) : (y))

Returns the smallest value between the two.

This function returns the smaller of the two provided values.

Parameters
xFirst value.
ySecond value.
Returns
Smallest value.

◆ oslMax

#define oslMax ( x,
y )
Value:
(((x) > (y)) ? (x) : (y))

Returns the greatest value between the two.

This function returns the larger of the two provided values.

Parameters
xFirst value.
ySecond 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
xInput value.
minMinimum value.
maxMaximum value.
Returns
Clamped value.

◆ oslNumberof

#define oslNumberof ( n)
Value:
(sizeof(n) / sizeof(*(n)))

Returns the number of objects in an array.

This function calculates the number of elements in an array.

Parameters
nArray.
Returns
Number of elements in the array.

Function Documentation

◆ 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
angleAngle in degrees.
distRadius 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
angleAngle in degrees.
distRadius 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
angleAngle in degrees.
distRadius 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
angleAngle in degrees.
distRadius 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
valInput value.
Returns
Next power of two.

◆ oslSetupFTrigo()

void oslSetupFTrigo ( )
extern

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.

Variable Documentation

◆ osl_isinus

int osl_isinus[361]
extern

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

int osl_icosinus[361]
extern

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.