Crimson Engine 1.0.0
A high-performance C++20 game engine prototype showcasing a custom ECS, Vulkan renderer, and ImGui editor.
Loading...
Searching...
No Matches
Primitives.hpp
Go to the documentation of this file.
1#pragma once
2#include "Mesh.hpp"
3
8namespace Primitives {
9
14 inline Mesh makeTriangle() {
15 return Mesh{
16 {
17 Vertex({-0.5f, -0.5f, 0.f}, {0.f,0.f,1.f}, {0.f,0.f}),
18 Vertex({ 0.5f, -0.5f, 0.f}, {0.f,0.f,1.f}, {1.f,0.f}),
19 Vertex({ 0.0f, 0.5f, 0.f}, {0.f,0.f,1.f}, {0.5f,1.f})
20 },
21 {0, 1, 2}
22 };
23 }
24
29 inline Mesh makeQuad() {
30 return Mesh{
31 {
32 Vertex({-0.5f, -0.5f, 0.f}, {0.f,0.f,1.f}, {0.f,0.f}),
33 Vertex({ 0.5f, -0.5f, 0.f}, {0.f,0.f,1.f}, {1.f,0.f}),
34 Vertex({ 0.5f, 0.5f, 0.f}, {0.f,0.f,1.f}, {1.f,1.f}),
35 Vertex({-0.5f, 0.5f, 0.f}, {0.f,0.f,1.f}, {0.f,1.f}),
36 },
37 {0, 1, 2, 2, 3, 0}
38 };
39 }
40
45 inline Mesh makeCube() {
46 std::vector<Vertex> verts = {
47 // front
48 {{-0.5f,-0.5f, 0.5f},{0,0,1},{0,0}},
49 {{ 0.5f,-0.5f, 0.5f},{0,0,1},{1,0}},
50 {{ 0.5f, 0.5f, 0.5f},{0,0,1},{1,1}},
51 {{-0.5f, 0.5f, 0.5f},{0,0,1},{0,1}},
52 // back
53 {{ 0.5f,-0.5f,-0.5f},{0,0,-1},{0,0}},
54 {{-0.5f,-0.5f,-0.5f},{0,0,-1},{1,0}},
55 {{-0.5f, 0.5f,-0.5f},{0,0,-1},{1,1}},
56 {{ 0.5f, 0.5f,-0.5f},{0,0,-1},{0,1}},
57 // right
58 {{ 0.5f,-0.5f, 0.5f},{1,0,0},{0,0}},
59 {{ 0.5f,-0.5f,-0.5f},{1,0,0},{1,0}},
60 {{ 0.5f, 0.5f,-0.5f},{1,0,0},{1,1}},
61 {{ 0.5f, 0.5f, 0.5f},{1,0,0},{0,1}},
62 // left
63 {{-0.5f,-0.5f,-0.5f},{-1,0,0},{0,0}},
64 {{-0.5f,-0.5f, 0.5f},{-1,0,0},{1,0}},
65 {{-0.5f, 0.5f, 0.5f},{-1,0,0},{1,1}},
66 {{-0.5f, 0.5f,-0.5f},{-1,0,0},{0,1}},
67 // top
68 {{-0.5f, 0.5f, 0.5f},{0,1,0},{0,0}},
69 {{ 0.5f, 0.5f, 0.5f},{0,1,0},{1,0}},
70 {{ 0.5f, 0.5f,-0.5f},{0,1,0},{1,1}},
71 {{-0.5f, 0.5f,-0.5f},{0,1,0},{0,1}},
72 // bottom
73 {{-0.5f,-0.5f,-0.5f},{0,-1,0},{0,0}},
74 {{ 0.5f,-0.5f,-0.5f},{0,-1,0},{1,0}},
75 {{ 0.5f,-0.5f, 0.5f},{0,-1,0},{1,1}},
76 {{-0.5f,-0.5f, 0.5f},{0,-1,0},{0,1}},
77 };
78 std::vector<uint32_t> inds = {
79 0, 1, 2, 2, 3, 0, // front
80 4, 5, 6, 6, 7, 4, // back
81 8, 9, 10, 10, 11, 8, // right
82 12, 13, 14, 14, 15, 12, // left
83 16, 17, 18, 18, 19, 16, // top
84 20, 21, 22, 22, 23, 20 // bottom
85 };
86 return Mesh{ verts, inds };
87 }
88
89}
Collection of helper functions for generating standard geometric primitive meshes.
Mesh makeCube()
Creates a 3D cube mesh.
Definition Primitives.hpp:45
Mesh makeQuad()
Creates a 2D quad (square) mesh.
Definition Primitives.hpp:29
Mesh makeTriangle()
Creates a 2D triangle mesh.
Definition Primitives.hpp:14
Represents a mesh component that holds geometry data and its Vulkan buffers.
Definition Mesh.hpp:95
Represents a single vertex in a 3D model, containing position, normal, and UV coordinates.
Definition Mesh.hpp:11