Oxygen Engine
Modern C++ 3D Engine using OpenGL
Loading...
Searching...
No Matches
cube.h
1#ifndef OE_SCENE_PRIMITIVE_CUBE_H
2#define OE_SCENE_PRIMITIVE_CUBE_H
3
4#include "../mesh.h"
5
7{
13 template <typename VertexType = Vertex>
14 struct Cube : public Mesh<VertexType>
15 {
19 Cube(const bool mirror_textures = false)
20 {
21 auto generateTexCoords = [mirror_textures](const glm::vec2& input) -> glm::vec2
22 {
23 return glm::vec2((mirror_textures ? (1.f-input.x) : input.x), input.y);
24 };
25
26 auto& vertices = Mesh<VertexType>::vertices;
27 auto& indices = Mesh<VertexType>::indices;
28 auto& primitives = Mesh<VertexType>::primitives;
29
30 vertices =
31 {
32 {.position = glm::vec3( 0.5f, 0.5f, -0.5f), .tex_coords_0 = generateTexCoords(glm::vec2(0.0f, 0.0f))},
33 {.position = glm::vec3( 0.5f, -0.5f, -0.5f), .tex_coords_0 = generateTexCoords(glm::vec2(0.0f, 1.0f))},
34 {.position = glm::vec3(-0.5f, -0.5f, -0.5f), .tex_coords_0 = generateTexCoords(glm::vec2(1.0f, 1.0f))},
35 {.position = glm::vec3(-0.5f, -0.5f, -0.5f), .tex_coords_0 = generateTexCoords(glm::vec2(1.0f, 1.0f))},
36 {.position = glm::vec3(-0.5f, 0.5f, -0.5f), .tex_coords_0 = generateTexCoords(glm::vec2(1.0f, 0.0f))},
37 {.position = glm::vec3( 0.5f, 0.5f, -0.5f), .tex_coords_0 = generateTexCoords(glm::vec2(0.0f, 0.0f))},
38
39 {.position = glm::vec3(-0.5f, -0.5f, 0.5f), .tex_coords_0 = generateTexCoords(glm::vec2(0.0f, 1.0f))},
40 {.position = glm::vec3( 0.5f, -0.5f, 0.5f), .tex_coords_0 = generateTexCoords(glm::vec2(1.0f, 1.0f))},
41 {.position = glm::vec3( 0.5f, 0.5f, 0.5f), .tex_coords_0 = generateTexCoords(glm::vec2(1.0f, 0.0f))},
42 {.position = glm::vec3( 0.5f, 0.5f, 0.5f), .tex_coords_0 = generateTexCoords(glm::vec2(1.0f, 0.0f))},
43 {.position = glm::vec3(-0.5f, 0.5f, 0.5f), .tex_coords_0 = generateTexCoords(glm::vec2(0.0f, 0.0f))},
44 {.position = glm::vec3(-0.5f, -0.5f, 0.5f), .tex_coords_0 = generateTexCoords(glm::vec2(0.0f, 1.0f))},
45
46 {.position = glm::vec3(-0.5f, 0.5f, 0.5f), .tex_coords_0 = generateTexCoords(glm::vec2(1.0f, 0.0f))},
47 {.position = glm::vec3(-0.5f, 0.5f, -0.5f), .tex_coords_0 = generateTexCoords(glm::vec2(0.0f, 0.0f))},
48 {.position = glm::vec3(-0.5f, -0.5f, -0.5f), .tex_coords_0 = generateTexCoords(glm::vec2(0.0f, 1.0f))},
49 {.position = glm::vec3(-0.5f, -0.5f, -0.5f), .tex_coords_0 = generateTexCoords(glm::vec2(0.0f, 1.0f))},
50 {.position = glm::vec3(-0.5f, -0.5f, 0.5f), .tex_coords_0 = generateTexCoords(glm::vec2(1.0f, 1.0f))},
51 {.position = glm::vec3(-0.5f, 0.5f, 0.5f), .tex_coords_0 = generateTexCoords(glm::vec2(1.0f, 0.0f))},
52
53 {.position = glm::vec3( 0.5f, -0.5f, -0.5f), .tex_coords_0 = generateTexCoords(glm::vec2(1.0f, 1.0f))},
54 {.position = glm::vec3( 0.5f, 0.5f, -0.5f), .tex_coords_0 = generateTexCoords(glm::vec2(1.0f, 0.0f))},
55 {.position = glm::vec3( 0.5f, 0.5f, 0.5f), .tex_coords_0 = generateTexCoords(glm::vec2(0.0f, 0.0f))},
56 {.position = glm::vec3( 0.5f, 0.5f, 0.5f), .tex_coords_0 = generateTexCoords(glm::vec2(0.0f, 0.0f))},
57 {.position = glm::vec3( 0.5f, -0.5f, 0.5f), .tex_coords_0 = generateTexCoords(glm::vec2(0.0f, 1.0f))},
58 {.position = glm::vec3( 0.5f, -0.5f, -0.5f), .tex_coords_0 = generateTexCoords(glm::vec2(1.0f, 1.0f))},
59
60 {.position = glm::vec3(-0.5f, -0.5f, -0.5f), .tex_coords_0 = generateTexCoords(glm::vec2(1.0f, 1.0f))},
61 {.position = glm::vec3( 0.5f, -0.5f, -0.5f), .tex_coords_0 = generateTexCoords(glm::vec2(1.0f, 0.0f))},
62 {.position = glm::vec3( 0.5f, -0.5f, 0.5f), .tex_coords_0 = generateTexCoords(glm::vec2(0.0f, 0.0f))},
63 {.position = glm::vec3( 0.5f, -0.5f, 0.5f), .tex_coords_0 = generateTexCoords(glm::vec2(0.0f, 0.0f))},
64 {.position = glm::vec3(-0.5f, -0.5f, 0.5f), .tex_coords_0 = generateTexCoords(glm::vec2(0.0f, 1.0f))},
65 {.position = glm::vec3(-0.5f, -0.5f, -0.5f), .tex_coords_0 = generateTexCoords(glm::vec2(1.0f, 1.0f))},
66
67 {.position = glm::vec3( 0.5f, 0.5f, 0.5f), .tex_coords_0 = generateTexCoords(glm::vec2(0.0f, 1.0f))},
68 {.position = glm::vec3( 0.5f, 0.5f, -0.5f), .tex_coords_0 = generateTexCoords(glm::vec2(1.0f, 1.0f))},
69 {.position = glm::vec3(-0.5f, 0.5f, -0.5f), .tex_coords_0 = generateTexCoords(glm::vec2(1.0f, 0.0f))},
70 {.position = glm::vec3(-0.5f, 0.5f, -0.5f), .tex_coords_0 = generateTexCoords(glm::vec2(1.0f, 0.0f))},
71 {.position = glm::vec3(-0.5f, 0.5f, 0.5f), .tex_coords_0 = generateTexCoords(glm::vec2(0.0f, 0.0f))},
72 {.position = glm::vec3( 0.5f, 0.5f, 0.5f), .tex_coords_0 = generateTexCoords(glm::vec2(0.0f, 1.0f))}
73 };
74
75 indices.reserve(vertices.size());
76
77 for (auto i = 0u; i<vertices.size(); ++i)
78 {
79 indices.push_back(i);
80 }
81
82 primitives = {{0, vertices.size()}};
83
84 if constexpr (IsVertexWithTangents<Vertex>)
85 {
88 }
89 }
90 };
91}
92
93#endif
Definition vertex.h:39
Standard mesh primitives (Cube, Plane, Teapot, etc...)
Definition cube.h:7
Definition mesh.h:61
constexpr void generateNormals()
Generate mesh normals from vertices positions.
Definition mesh.h:272
constexpr void generateTangents()
Compute Tangents using mikkTSpace.
Definition mesh.h:340
A cube mesh from (-0.5f, -0.5f, -0.5f) to (0.5f, 0.5f, 0.5f)
Definition cube.h:15
Cube(const bool mirror_textures=false)
Definition cube.h:19