Gamedev Framework (gf)  0.12.0
A C++14 framework for 2D games
Vectors, matrices and transforms

Table of Contents

gf provides a generic gf::Vector type and a generic gf::Matrix type that are used throughout the library.

Vectors

Vector types

A gf::Vector represents a mathematical vector in a \( N \)-dimensional space. It has a broad range of applications. The most obvious is to represent the position of an object in the world space but it's not the only one.

#include <gf/Vector.h>

The gf::Vector type is totally generic regarding its type but also its dimension \( N \).

Operations on vectors

#include <gf/VectorOps.h>

gf defines common mathematical operators for two vectors but also for a vector and a scalar. In each case, type conversion is made if necessary, following the usual rules of the language. The following table gives the semantics of the main operations between two vectors \( \mathbf{a} \) and \( \mathbf{b} \), or between a vector \( \mathbf{a} \) and a scalar \( \lambda \). These operations are all defined component-wise.

\( \bullet \) \( \mathbf{a} \bullet \mathbf{b} \) \( \mathbf{a} \bullet \lambda \) \( \lambda \bullet \mathbf{a} \)
\( + \) \( a_i + b_i \) \( a_i + \lambda \) \( \lambda + a_i \)
\( - \) \( a_i - b_i \) \( a_i - \lambda \) \( \lambda - a_i \)
\( * \) \( a_i * b_i \) \( a_i * \lambda \) \( \lambda * a_i \)
\( / \) \( a_i / b_i \) \( a_i / \lambda \) \( \lambda / a_i \)

gf also defines equality and inequality operators for vectors.

Functions on vectors

#include <gf/VectorOps.h>

Matrices

Transforms

Simple transformation

A simple transformation in gf is a rotation followed by a translation. A simple rotation is represented by the gf::Rotation type, a simple translation is represented by the gf::Translation type, and the simple transformation is represented by the gf::Transform type.

These simple transformations are useful in the physics engine.

Affine transformation

You can define a generic affine transformation in 2D with a transformation matrix thanks to the gf::Matrix3f type.