Let’s talk about vectors.

In mathematics, physics, and engineering, a vector (sometimes called a geometric vector or spatial vector) is a geometric object with magnitude (or length) and direction.

You can find more information about vectors you can check in Wiki, but here we will talk about vectors in-game perspective.

Vector could be in N dimension space, but for games, we need only 3(for now). That’s why it should contain three numeric coordinates, which we are going to call components of a vector:

    \[   v = (v_1, v_2, v_3)\]

Or it is better to present it like that:

    \[   v = (v_x, v_y, v_z)\]

But the most exciting part is how to present it in code. Let’s see an example of a simple data structure:

struct Vector3D {
    float x, y, z;

    Vector3D() = default;

    Vector3D(float x, float y, float z) {
        this->x = x;
        this->y = y;
        this->z = z;

    float &operator[](int i) {
        return ((&x)[i]);

    const float &operator[](int i) const {
        return ((&x)[i]);

That helps us understand where we should move further and how to get our first math engine.