BRE12
GeometryGenerator.h
1 #pragma once
2 
3 #include <DirectXMath.h>
4 #include <vector>
5 
6 namespace BRE {
7 // To generate procedurally the geometry of
8 // common mathematical objects.
9 //
10 // All triangles are generated "outward" facing.
11 namespace GeometryGenerator {
12 struct Vertex {
13  Vertex() = default;
14  explicit Vertex(const DirectX::XMFLOAT3& position,
15  const DirectX::XMFLOAT3& normal,
16  const DirectX::XMFLOAT3& tangent,
17  const DirectX::XMFLOAT2& uv);
18 
19  ~Vertex() = default;
20  Vertex(const Vertex&) = default;
21  Vertex(Vertex&&) = default;
22  Vertex& operator=(Vertex&&) = default;
23 
24  DirectX::XMFLOAT3 mPosition = { 0.0f, 0.0f, 0.0f };
25  DirectX::XMFLOAT3 mNormal = { 0.0f, 0.0f, 0.0f };
26  DirectX::XMFLOAT3 mTangent = { 0.0f, 0.0f, 0.0f };
27  DirectX::XMFLOAT2 mUV = { 0.0f, 0.0f };
28 };
29 
30 struct MeshData {
31  std::vector<Vertex> mVertices;
32  std::vector<std::uint32_t> mIndices32;
33  std::vector<std::uint16_t>& GetIndices16() noexcept;
34 
35 private:
36  std::vector<std::uint16_t> mIndices16{};
37 };
38 
39 // Centered at the origin.
40 // Preconditions:
41 // -
42 void CreateBox(const float width,
43  const float height,
44  const float depth,
45  const std::uint32_t numSubdivisions,
46  MeshData& meshData) noexcept;
47 
48 // Centered at the origin.
49 void CreateSphere(const float radius,
50  const std::uint32_t sliceCount,
51  const std::uint32_t stackCount,
52  MeshData& meshData) noexcept;
53 
54 // Centered at the origin.
55 void CreateGeosphere(const float radius,
56  const std::uint32_t numSubdivisions,
57  MeshData& meshData) noexcept;
58 
59 // Creates a cylinder parallel to the y-axis, and centered about the origin.
60 // The bottom and top radius can vary to form various cone shapes rather than true
61 // cylinders. The slices and stacks parameters control the degree of tessellation.
62 void CreateCylinder(const float bottomRadius,
63  const float topRadius,
64  const float height,
65  const std::uint32_t sliceCount,
66  const std::uint32_t stackCount,
67  MeshData& meshData) noexcept;
68 
69 // Creates an row x columns grid in the xz-plane with rows rows and columns columns, centered
70 // at the origin with the specified width and depth.
71 void CreateGrid(const float width,
72  const float depth,
73  const std::uint32_t rows,
74  const std::uint32_t columns,
75  MeshData& meshData) noexcept;
76 }
77 }
78 
Definition: Camera.cpp:8
Definition: GeometryGenerator.h:12
Definition: GeometryGenerator.h:30