CeresEngine 0.2.0
A game development framework
Loading...
Searching...
No Matches
AxisSwapMesh.hpp
Go to the documentation of this file.
1//
2// CeresEngine - A game development framework
3//
4// Created by Rogiel Sulzbach.
5// Copyright (c) 2018-2022 Rogiel Sulzbach. All rights reserved.
6//
7
8#pragma once
9
10#include "Axis.hpp"
11#include "TransformMesh.hpp"
12#include "Triangle.hpp"
13
15
17 template<typename Mesh> class AxisSwapMesh {
18 private:
21
22 public:
23 class Triangles {
24 public:
26 Triangle triangle = mTriangles.generate();
27 if(mMesh->mFlip)
28 std::swap(triangle.vertices[0], triangle.vertices[2]);
29 return triangle;
30 }
31
32 [[nodiscard]] bool done() const noexcept { return mTriangles.done(); }
33 void next() { mTriangles.next(); }
34
35 private:
37
39
41
42 friend class AxisSwapMesh;
43 };
44
50 : mTransformMesh{std::move(mesh),
51 [x, y, z](MeshVertex& vertex) {
52 vertex.position = Vector3{vertex.position[static_cast<int>(x)], vertex.position[static_cast<int>(y)],
53 vertex.position[static_cast<int>(z)]};
54 vertex.normal = Vector3{vertex.normal[static_cast<int>(x)], vertex.normal[static_cast<int>(y)], vertex.normal[static_cast<int>(z)]};
55 }},
56 mFlip{true} {
57 if(x != Axis::X) {
58 mFlip = !mFlip;
59 }
60
61 if(y != Axis::Y) {
62 mFlip = !mFlip;
63 }
64
65 if(z != Axis::Z) {
66 mFlip = !mFlip;
67 }
68 }
69
70 [[nodiscard]] Triangles triangles() const noexcept { return {*this}; }
71
72 using Vertices = typename Impl::Vertices;
73 [[nodiscard]] Vertices vertices() const noexcept { return mTransformMesh.vertices(); }
74
75 private:
76 bool mFlip;
77 };
78
79 template<typename Mesh> AxisSwapMesh<Mesh> axisSwapMesh(Mesh mesh, Axis x, Axis y, Axis z) { return AxisSwapMesh<Mesh>{std::move(mesh), x, y, z}; }
80
81} // namespace CeresEngine::MeshGenerator
const AxisSwapMesh * mMesh
Definition AxisSwapMesh.hpp:36
bool done() const noexcept
Definition AxisSwapMesh.hpp:32
void next()
Definition AxisSwapMesh.hpp:33
Triangle generate() const
Definition AxisSwapMesh.hpp:25
Triangles(const AxisSwapMesh &mesh)
Definition AxisSwapMesh.hpp:40
TriangleGeneratorType< TransformMesh< Mesh > >::Type mTriangles
Definition AxisSwapMesh.hpp:38
Swaps any number of axis in the mesh.
Definition AxisSwapMesh.hpp:17
Impl mTransformMesh
Definition AxisSwapMesh.hpp:20
bool mFlip
Definition AxisSwapMesh.hpp:76
typename Impl::Vertices Vertices
Definition AxisSwapMesh.hpp:72
AxisSwapMesh(Mesh mesh, Axis x, Axis y, Axis z)
Definition AxisSwapMesh.hpp:49
Triangles triangles() const noexcept
Definition AxisSwapMesh.hpp:70
Vertices vertices() const noexcept
Definition AxisSwapMesh.hpp:73
Definition MeshVertex.hpp:14
Apply a mutator function to each vertex.
Definition TransformMesh.hpp:18
Will have a type named "Type" that has same type as value returned by method triangles() for type Pri...
Definition Utility.hpp:30
Definition Triangle.hpp:14
A base class for all mesh implementations.
Definition Mesh.hpp:112
Definition AnyGenerator.hpp:12
Axis
Definition Axis.hpp:12
AxisSwapMesh< Mesh > axisSwapMesh(Mesh mesh, Axis x, Axis y, Axis z)
Definition AxisSwapMesh.hpp:79
auto move(Vector3 position)
Moves a entity to the given position.
Definition Helpers.hpp:22
constexpr size_t hash(const T &v)
Generates a hash for the provided type.
Definition Hash.hpp:25
Definition Span.hpp:668