3 #include "geometry.hpp"
5 #include <glm/gtx/euler_angles.hpp>
6 #include <glm/gtx/transform.hpp>
13 const glm::mat4 block_transforms[Block::DIR_COUNT * Block::ROT_COUNT] = {
15 glm::eulerAngleY(PI_0p5),
17 glm::eulerAngleY(PI_1p5),
19 glm::eulerAngleYX(PI_0p5, PI),
20 glm::eulerAngleYX(PI, PI),
21 glm::eulerAngleYX(PI_1p5, PI),
22 glm::eulerAngleZ(PI_0p5),
23 glm::eulerAngleYZ(PI_0p5, PI_0p5),
24 glm::eulerAngleYZ(PI, PI_0p5),
25 glm::eulerAngleYZ(PI_1p5, PI_0p5),
26 glm::eulerAngleZ(PI_1p5),
27 glm::eulerAngleYZ(PI_0p5, PI_1p5),
28 glm::eulerAngleYZ(PI, PI_1p5),
29 glm::eulerAngleYZ(PI_1p5, PI_1p5),
30 glm::eulerAngleX(PI_0p5),
31 glm::eulerAngleYX(PI_0p5, PI_0p5),
32 glm::eulerAngleYX(PI, PI_0p5),
33 glm::eulerAngleYX(PI_1p5, PI_0p5),
34 glm::eulerAngleX(PI_1p5),
35 glm::eulerAngleYX(PI_0p5, PI_1p5),
36 glm::eulerAngleYX(PI, PI_1p5),
37 glm::eulerAngleYX(PI_1p5, PI_1p5),
42 const glm::mat4 &Block::Transform() const {
43 return block_transforms[orient];
47 const NullShape BlockType::DEFAULT_SHAPE;
49 BlockType::BlockType(bool v, const glm::vec3 &col, const Shape *s)
52 , outline_color(-1, -1, -1)
55 , fill({ false, false, false, false, false, false }) {
59 void BlockType::FillModel(
61 const glm::mat4 &transform,
62 Model::Index idx_offset
64 shape->Vertices(buf.vertices, buf.normals, buf.indices, transform, idx_offset);
65 buf.colors.insert(buf.colors.end(), shape->VertexCount(), color);
68 void BlockType::FillOutlineModel(
70 const glm::vec3 &pos_offset,
71 OutlineModel::Index idx_offset
73 shape->Outline(model.vertices, model.indices, pos_offset, idx_offset);
74 model.colors.insert(model.colors.end(), shape->OutlineCount(), outline_color);
78 BlockTypeRegistry::BlockTypeRegistry() {
82 Block::Type BlockTypeRegistry::Add(const BlockType &t) {
83 int id = types.size();