|
IME_API float | lerp (float min, float max, float ratio) |
| Get a value between two other values on a linear scale. More...
|
|
IME_API int | generateRandomNum (int min, int max) |
| Generate a random number in a range. More...
|
|
static auto | createRandomNumGenerator (int min, int max) |
| Create a callable that generates random numbers in a range. More...
|
|
IME_API Colour | generateRandomColour () |
| Create a random colour. More...
|
|
template<typename Callable , typename... Args> |
void | setTimeoutSync (Time delay, const Callable &callback, Args &&...args) |
| Execute a one time callback function after a delay. More...
|
|
template<typename Callable , typename... Args> |
void | setTimeout (Time delay, const Callable &callback, Args &&...args) |
| Execute a callback function once after a delay. More...
|
|
template<typename Callable , typename... Args> |
void | setIntervalSync (Time delay, const Callable &callback, Args &&...args) |
| Execute a callback function repeatedly after a delay. More...
|
|
template<typename Callable , typename... Args> |
void | setInterval (Time delay, const Callable &callback, Args &&...args) |
| Execute a callback function repeatedly after a delay. More...
|
|
Container for all utility classes and functions.
IME_API float ime::utility::lerp |
( |
float |
min, |
|
|
float |
max, |
|
|
float |
ratio |
|
) |
| |
Get a value between two other values on a linear scale.
- Parameters
-
min | The value to interpolate from |
max | The value to interpolate to |
ratio | The interpolation point between 0 and 1 (inclusive) |
- Returns
- The lerp value
This function is usually used to smoothen a value over time. For example it can be used to change the colour of something gradually over time or smoothly move an object to a new position (look up "linear interpolation" for more info).
The interpolation ratio is used to determine the point to be returned on the scale. It acts like a percentage between min and max:
auto value =
lerp(0, 100.0f, 0.0f); Returns the minimum value
auto value =
lerp(0, 100.0f, 1.0f); Returns the maximum value
auto value =
lerp(0, 100.0f, 0.5f); Returns the 50.0f
auto value =
lerp(0, 100.0f, 0.85f); Returns the 85.0f
IME_API float lerp(float min, float max, float ratio)
Get a value between two other values on a linear scale.
To make the interpolation frame rate independent, multiply the lerp ration by the frame time
- Note
- This function does not account for situations where the interpolation point is less than 0 or greater than 1 or when the minimum value is greater than the maximum value. This means that the program will continue as normal, you may experience an unexpected behavior
void update(
Time deltaTime) {
sprite.setPosition(
lerp(sprite.getX(), 50.0f, 0.3f), sprite.getY());
sprite.getY());
}
Int32 asMilliseconds() const
Get the time value in milliseconds.
template<typename Callable , typename... Args>
void ime::utility::setInterval |
( |
Time |
delay, |
|
|
const Callable & |
callback, |
|
|
Args &&... |
args |
|
) |
| |
Execute a callback function repeatedly after a delay.
- Parameters
-
delay | Time to wait before executing callback |
callback | Function to execute |
args | Arguments to pass to the callback on invocation |
The callback execution is done in a separate thread, therefore this function is not blocking. It will return immediately after initiating the new thread. The callback function will execute forever every delay milliseconds. The interval can be stopped by setting the first argument of the callback to false. This argument must be taken by reference otherwise the callback will continue executing.
- Note
- Provided arguments will be passed to the callback after the first bool argument which is provided by this function, therefore the callback must take at least one argument of type bool&
template<typename Callable , typename... Args>
void ime::utility::setIntervalSync |
( |
Time |
delay, |
|
|
const Callable & |
callback, |
|
|
Args &&... |
args |
|
) |
| |
Execute a callback function repeatedly after a delay.
- Parameters
-
delay | Time to wait before executing callback |
callback | Function to execute |
args | Arguments passed to the callback function on invocation |
This function is blocking as the current thread will wait for the callback execution to finish. The callback function will execute forever every delay milliseconds. The interval can be stopped by setting the first argument of the callback to false. This argument must be taken by reference otherwise the callback will continue executing
- Note
- Provided arguments will be passed to the callback after the first bool argument which is provided by this function, therefore the callback must take at least one argument of type bool&
template<typename Callable , typename... Args>
void ime::utility::setTimeout |
( |
Time |
delay, |
|
|
const Callable & |
callback, |
|
|
Args &&... |
args |
|
) |
| |
Execute a callback function once after a delay.
- Parameters
-
delay | Time to wait before executing callback |
callback | Function to execute |
args | Arguments passed to the callback function on invocation |
The callback execution is done in a separate thread, therefore this function is not blocking. It will return immediately after initiating the new thread