Utils

Scalar Utils

namespace glen::ScalarUtils

Various helper methods for working with scalar values.

Functions

template<typename T1, typename T2>
T1 min_value(T1 first, T2 second)

Return

The argument that is the smallest of the two.

template<typename T1, typename T2, typename ...Args>
T1 min_value(T1 first, T2 second, Args... args)

Return

The argument out of all provided which is the smallest.

template<typename T1, typename T2>
T1 max_value(T1 first, T2 second)

Return

The argument that is the largest of the two

template<typename T1, typename T2, typename ...Args>
T1 max_value(T1 first, T2 second, Args... args)

Return

The argument out of all provided which is the largest.

template<typename T>
T lerp(const T &a, const T &b, const T &amount)

linearly interpolate between a and b by amount.

Vector Utils

namespace glen::VectorUtils

Functions

template<typename T, typename ...Args>
std::vector<T> combine_vectors(std::vector<T> &s_first, Args... args)

Combine multiple std::vectors into one.

Return

The combined std::vector.

template<typename T>
std::vector<T> combine_vectors(std::vector<T> &s_first, std::vector<T> &s_second)

Combine two std::vectors into one.

Return

The combined std::vector.

template<typename ...Args>
glm::vec3 vector_average(Args... args)

Return

The average vector of the combination of all provided vec3s.

GLfloat distance_squared(glm::vec2, glm::vec2)

The square is used because this is a faster calculation than finding the actual distance.

Return

The square of the distance between two points in 2D space.

GLfloat distance_squared(glm::vec3, glm::vec3)

The square is used because this is a faster calculation than finding the actual distance.

Return

The square of the distance between two points in 3D space.

template<typename T>
bool is_near(T s_point_1, T s_point_2, float threshold)

Return

True if s_point_1 and s_point_2 are within threshold distance of each other.

bool is_less_than(const glm::vec2&, const glm::vec2&, const float threshold)

Return

True if both the x and y coordinates of the first point are less than those of the second (but not within threshold distance).

bool is_less_than(const glm::vec3&, const glm::vec3&, float threshold)

Return

True if x, y and z coordinates of the first point are less than those of the second (but not within threshold distance).

template<typename T1, typename T2>
void quick_sort_pair_vector(std::vector<std::pair<T1, T2>> &s_pairs)

Sort the std::vector of pairs.

template<typename T>
glm::tvec3<T> extract_position(const glm::tmat4x4<T> &transform)

Return

3D position coordinate described by transform.

template<typename T>
void set_position(glm::tmat4x4<T> &transform, const glm::tvec3<T> &position)

Modify transform so that it specifies coordinate at position.

template<typename T>
void add_position_to_transform(glm::tmat4x4<T> &transform, const glm::tvec3<T> &position)

Add position to existing transfrom.

template<typename T>
glm::tmat4x4<T> translate_rotate_scale(const glm::tmat3x3<T> &trans_rot_scale, std::string s_rotate_order = "xyz")

Creates a 4x4 transform matrix for a 3x3 translate rotate scale matrix

Input matrix should be of the form {translate vector, rotate vector, scale vector} Optionally take a string specifying the rotate order.

Timer

struct glen::Timer

Basic high accuracy timer. Gives change in time and total time since initialisation Optional multiplier to adjust overall timegit s

Public Functions

Timer()

Constructor.

Timer(const double multiplier)

Constructor.

Parameters
  • multiplier: Set the apparant speed of time. Lower values will slow everything down.

void update()

Mark the passage of another frame.

void debug_update()

Mark the passage of another frame (with debug info printed to terminal).

const double total_time_s() const

Return

The total number of seconds passed since the timer was started.

const double total_time_ms() const

Return

The total number of milliseconds passed since the timer was started.

const double delta_time_s() const

Return

The number of seconds passed since the last update.

const double delta_time_ms() const

Return

The number of milliseconds passed since the last update.

const char *fps()

Return

The current frame rate.

void set_multiplier(const double multiplier)

Change the multiplier used to either speed up or slow down time.

void set_fps_update_time(const float update_time)

How frequently (in seconds) to update the frame rate output.