summary refs log tree commit diff
path: root/src/World/BlockSide.hpp
blob: 831982ae2551116ad128e9f8b943fc50a50b0e6f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#pragma once

#include "../Common/Sizes.hpp"
#include <vector>
#include <array>
#include "../Math/Vector.hpp"

namespace MC::World {

class BlockSide {
public:
    enum Value : U8 {
        Front,
        Back,

        Top,
        Bottom,

        Right,
        Left,
    };

    BlockSide() = default;
    BlockSide(Value side) : m_side(side) {}

    operator Value() const { return m_side; }

    std::array<Vector<3, F32>, 4> face() {
        // Winding order: (0, 1, 2) (2, 3, 0)
        // Note: OpenGL Coordinate system has a flipped z axis.
        switch (m_side) {
            case Front: return {{
                {0, 1, 1}, {0, 0, 1}, {1, 0, 1}, {1, 1, 1}
            }};
            case Back: return {{
                {0, 1, 0}, {1, 1, 0}, {1, 0, 0}, {0, 0, 0}
            }};
            case Top: return {{
                {0, 1, 1}, {1, 1, 1}, {1, 1, 0}, {0, 1, 0}
            }};
            case Bottom: return {{
                {0, 0, 1}, {0, 0, 0}, {1, 0, 0}, {1, 0, 1}
            }};
            case Right: return {{
                {1, 1, 0}, {1, 1, 1}, {1, 0, 1}, {1, 0, 0}
            }};
            case Left: return {{
                {0, 1, 0}, {0, 0, 0}, {0, 0, 1}, {0, 1, 1}
            }};
        }
    }

    static std::vector<BlockSide> all() {
        return {
            Front, Back, Top, Bottom, Left, Right,
        };
    }
private:
    Value m_side;
};

}