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#include <numeric> // to use iota
6
8{
14 //template <typename VertexType = Vertex>
15 class Cube : public Mesh
16 {
17 public:
21 Cube(const bool mirror_textures = false)
22 {
23 auto generateTexCoords = [mirror_textures](const glm::vec2& input) -> glm::vec2
24 {
25 return glm::vec2((mirror_textures ? (1.f-input.x) : input.x), input.y);
26 };
27
28 /*ComplexMesh<VertexType>::*/_vertices =
29 {
30 {.position = glm::vec3( 0.5f, 0.5f, -0.5f), .tex_coords = generateTexCoords(glm::vec2(0.0f, 0.0f))},
31 {.position = glm::vec3( 0.5f, -0.5f, -0.5f), .tex_coords = generateTexCoords(glm::vec2(0.0f, 1.0f))},
32 {.position = glm::vec3(-0.5f, -0.5f, -0.5f), .tex_coords = generateTexCoords(glm::vec2(1.0f, 1.0f))},
33 {.position = glm::vec3(-0.5f, -0.5f, -0.5f), .tex_coords = generateTexCoords(glm::vec2(1.0f, 1.0f))},
34 {.position = glm::vec3(-0.5f, 0.5f, -0.5f), .tex_coords = generateTexCoords(glm::vec2(1.0f, 0.0f))},
35 {.position = glm::vec3( 0.5f, 0.5f, -0.5f), .tex_coords = generateTexCoords(glm::vec2(0.0f, 0.0f))},
36
37 {.position = glm::vec3(-0.5f, -0.5f, 0.5f), .tex_coords = generateTexCoords(glm::vec2(0.0f, 1.0f))},
38 {.position = glm::vec3( 0.5f, -0.5f, 0.5f), .tex_coords = generateTexCoords(glm::vec2(1.0f, 1.0f))},
39 {.position = glm::vec3( 0.5f, 0.5f, 0.5f), .tex_coords = generateTexCoords(glm::vec2(1.0f, 0.0f))},
40 {.position = glm::vec3( 0.5f, 0.5f, 0.5f), .tex_coords = generateTexCoords(glm::vec2(1.0f, 0.0f))},
41 {.position = glm::vec3(-0.5f, 0.5f, 0.5f), .tex_coords = generateTexCoords(glm::vec2(0.0f, 0.0f))},
42 {.position = glm::vec3(-0.5f, -0.5f, 0.5f), .tex_coords = generateTexCoords(glm::vec2(0.0f, 1.0f))},
43
44 {.position = glm::vec3(-0.5f, 0.5f, 0.5f), .tex_coords = generateTexCoords(glm::vec2(1.0f, 0.0f))},
45 {.position = glm::vec3(-0.5f, 0.5f, -0.5f), .tex_coords = generateTexCoords(glm::vec2(0.0f, 0.0f))},
46 {.position = glm::vec3(-0.5f, -0.5f, -0.5f), .tex_coords = generateTexCoords(glm::vec2(0.0f, 1.0f))},
47 {.position = glm::vec3(-0.5f, -0.5f, -0.5f), .tex_coords = generateTexCoords(glm::vec2(0.0f, 1.0f))},
48 {.position = glm::vec3(-0.5f, -0.5f, 0.5f), .tex_coords = generateTexCoords(glm::vec2(1.0f, 1.0f))},
49 {.position = glm::vec3(-0.5f, 0.5f, 0.5f), .tex_coords = generateTexCoords(glm::vec2(1.0f, 0.0f))},
50
51 {.position = glm::vec3( 0.5f, -0.5f, -0.5f), .tex_coords = generateTexCoords(glm::vec2(1.0f, 1.0f))},
52 {.position = glm::vec3( 0.5f, 0.5f, -0.5f), .tex_coords = generateTexCoords(glm::vec2(1.0f, 0.0f))},
53 {.position = glm::vec3( 0.5f, 0.5f, 0.5f), .tex_coords = generateTexCoords(glm::vec2(0.0f, 0.0f))},
54 {.position = glm::vec3( 0.5f, 0.5f, 0.5f), .tex_coords = generateTexCoords(glm::vec2(0.0f, 0.0f))},
55 {.position = glm::vec3( 0.5f, -0.5f, 0.5f), .tex_coords = generateTexCoords(glm::vec2(0.0f, 1.0f))},
56 {.position = glm::vec3( 0.5f, -0.5f, -0.5f), .tex_coords = generateTexCoords(glm::vec2(1.0f, 1.0f))},
57
58 {.position = glm::vec3(-0.5f, -0.5f, -0.5f), .tex_coords = generateTexCoords(glm::vec2(1.0f, 1.0f))},
59 {.position = glm::vec3( 0.5f, -0.5f, -0.5f), .tex_coords = generateTexCoords(glm::vec2(1.0f, 0.0f))},
60 {.position = glm::vec3( 0.5f, -0.5f, 0.5f), .tex_coords = generateTexCoords(glm::vec2(0.0f, 0.0f))},
61 {.position = glm::vec3( 0.5f, -0.5f, 0.5f), .tex_coords = generateTexCoords(glm::vec2(0.0f, 0.0f))},
62 {.position = glm::vec3(-0.5f, -0.5f, 0.5f), .tex_coords = generateTexCoords(glm::vec2(0.0f, 1.0f))},
63 {.position = glm::vec3(-0.5f, -0.5f, -0.5f), .tex_coords = generateTexCoords(glm::vec2(1.0f, 1.0f))},
64
65 {.position = glm::vec3( 0.5f, 0.5f, 0.5f), .tex_coords = generateTexCoords(glm::vec2(0.0f, 1.0f))},
66 {.position = glm::vec3( 0.5f, 0.5f, -0.5f), .tex_coords = generateTexCoords(glm::vec2(1.0f, 1.0f))},
67 {.position = glm::vec3(-0.5f, 0.5f, -0.5f), .tex_coords = generateTexCoords(glm::vec2(1.0f, 0.0f))},
68 {.position = glm::vec3(-0.5f, 0.5f, -0.5f), .tex_coords = generateTexCoords(glm::vec2(1.0f, 0.0f))},
69 {.position = glm::vec3(-0.5f, 0.5f, 0.5f), .tex_coords = generateTexCoords(glm::vec2(0.0f, 0.0f))},
70 {.position = glm::vec3( 0.5f, 0.5f, 0.5f), .tex_coords = generateTexCoords(glm::vec2(0.0f, 1.0f))}
71 };
72
73 std::vector<index_t> indices(/*ComplexMesh<VertexType>::*/_vertices.size());
74 std::iota(indices.begin(), indices.end(), 0);
75
76 /*ComplexMesh<VertexType>::*/_indices.push_back(indices);
77
78 /*ComplexMesh<VertexType>::*/_aabb = {glm::vec3(-0.5f), glm::vec3(0.5f)};
79
80 /*ComplexMesh<VertexType>::*/generateSmoothNormals();
81 /*ComplexMesh<VertexType>::*/generateTangents();
82 }
83 };
84}
85
86#endif
void generateTangents()
Generate tangents from texture coordinates.
Definition mesh.h:220
void generateSmoothNormals(uint32_t sub_mesh=0)
Smooth mesh normals.
Definition mesh.h:146
Definition mesh.h:333
A cube mesh from (-0.5f, -0.5f, -0.5f) to (0.5f, 0.5f, 0.5f)
Definition cube.h:16
Cube(const bool mirror_textures=false)
Definition cube.h:21
Standard mesh primitives (Cube, Plane, Teapot, etc...)
Definition cube.h:8