Botcraft 1.21.4
Loading...
Searching...
No Matches
Face.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <array>
4#include <vector>
5
7
9
10namespace Botcraft
11{
12 namespace Renderer
13 {
14 struct FaceTransformation;
15 struct IMatrix;
16
17 class Face
18 {
19 public:
20 Face();
21 Face(const FaceTransformation& transformations, const Orientation orientation);
22
23 bool operator ==(const Face& other) const
24 {
25 //Texture doesn't matter
26 for (int i = 0; i < 16; ++i)
27 {
28 if (model_matrix[i] != other.model_matrix[i])
29 {
30 return false;
31 }
32 }
33 return true;
34 }
35
36 void SetTransparencyData(const Transparency transparency);
38 void SetDisplayBackface(const bool display_backface);
39
40 const std::array<float, 16>& GetMatrix() const;
41 std::array<float, 16>& GetMatrix();
42 void SetTextureMultipliers(const std::array<unsigned int, 2>& mult);
43 const std::array<float, 4>& GetTextureCoords(const bool overlay) const;
44 void SetTextureCoords(const std::array<float, 4>& coords, const bool overlay);
45
46 void UpdateMatrix(const FaceTransformation& transformations, const Orientation orientation);
47
48 static const std::vector<float> base_face;
49
50 private:
51 // Model matrix, 16 floats
52 std::array<float, 16> model_matrix;
53
54 // Texture coordinates for both base texture and optional overlay
55 // (u1, v1, u2, v2)
56 std::array<float, 4> texture_coords;
57 std::array<float, 4> texture_coords_overlay;
58
59 //One int with all textures data packed inside
60 //(unused : 26 bits, use_overlay : 1 bit, rotation : 2 bits, display_backface: 1 bit, transparency_data : 2 bit)
61 unsigned int texture_data;
62
63 //One int with texture multiplier packed inside (rgba) x2 for one optional overlay
64 std::array<unsigned int, 2> texture_multipliers;
65 };
66 } // Renderer
67} // Botcraft
68
69namespace std
70{
71 template<>
72 struct hash<Botcraft::Renderer::Face>
73 {
74 inline size_t operator()(const Botcraft::Renderer::Face& f) const
75 {
76 const std::array<float, 16>& matrix = f.GetMatrix();
77 std::hash<float> hasher;
78 size_t value = hasher(matrix[0]);
79
80 for (int i = 1; i < 16; ++i)
81 {
82 value ^= hasher(matrix[i]) + 0x9e3779b9 + (value << 6) + (value >> 2);
83 }
84 return value;
85 }
86 };
87}
std::array< float, 4 > texture_coords_overlay
Definition Face.hpp:57
void SetTransparencyData(const Transparency transparency)
Definition Face.cpp:122
const std::array< float, 16 > & GetMatrix() const
Definition Face.cpp:169
std::array< unsigned int, 2 > texture_multipliers
Definition Face.hpp:64
void SetTextureMultipliers(const std::array< unsigned int, 2 > &mult)
Definition Face.cpp:179
static const std::vector< float > base_face
Definition Face.hpp:48
const std::array< float, 4 > & GetTextureCoords(const bool overlay) const
Definition Face.cpp:184
unsigned int texture_data
Definition Face.hpp:61
std::array< float, 4 > texture_coords
Definition Face.hpp:56
std::array< float, 16 > model_matrix
Definition Face.hpp:52
bool operator==(const Face &other) const
Definition Face.hpp:23
void SetDisplayBackface(const bool display_backface)
Definition Face.cpp:157
void SetTextureCoords(const std::array< float, 4 > &coords, const bool overlay)
Definition Face.cpp:193
Transparency GetTransparencyData() const
Definition Face.cpp:142
void UpdateMatrix(const FaceTransformation &transformations, const Orientation orientation)
Definition Face.cpp:207
Transparency
Transparency values for textures.
Definition Enums.hpp:9
STL namespace.
size_t operator()(const Botcraft::Renderer::Face &f) const
Definition Face.hpp:74