CeresEngine 0.2.0
A game development framework
Loading...
Searching...
No Matches
AxisFlipMesh.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 "TransformMesh.hpp"
11#include "Triangle.hpp"
12
14
18 template<typename Mesh> class AxisFlipMesh {
19 private:
22
23 public:
24 class Triangles {
25 public:
27 Triangle triangle = mTriangles.generate();
28 if(mMesh->mFlip)
29 std::swap(triangle.vertices[0], triangle.vertices[2]);
30 return triangle;
31 }
32
33 [[nodiscard]] bool done() const noexcept { return mTriangles.done(); }
34 void next() { mTriangles.next(); }
35
36 private:
38
40
42
43 friend class AxisFlipMesh;
44 };
45
50 AxisFlipMesh(Mesh mesh, bool x, bool y, bool z)
51 : mTransformMesh{std::move(mesh),
52 [x, y, z](MeshVertex& vertex) {
53 if(x) {
54 vertex.position[0] *= -1.0;
55 vertex.normal[0] *= -1.0;
56 }
57
58 if(y) {
59 vertex.position[1] *= -1.0;
60 vertex.normal[1] *= -1.0;
61 }
62
63 if(z) {
64 vertex.position[2] *= -1.0;
65 vertex.normal[2] *= -1.0;
66 }
67 }},
68 mFlip{false} {
69 if(x) {
70 mFlip = !mFlip;
71 }
72
73 if(y) {
74 mFlip = !mFlip;
75 }
76
77 if(z) {
78 mFlip = !mFlip;
79 }
80 }
81
82 [[nodiscard]] Triangles triangles() const noexcept { return {*this}; }
83
84 using Vertices = typename Impl::Vertices;
85 [[nodiscard]] Vertices vertices() const noexcept { return mTransformMesh.vertices(); }
86
87 private:
88 bool mFlip;
89 };
90
91 template<typename Mesh> AxisFlipMesh<Mesh> axisFlipMesh(Mesh mesh, bool x, bool y, bool z) { return AxisFlipMesh<Mesh>{std::move(mesh), x, y, z}; }
92
93} // namespace CeresEngine::MeshGenerator
TriangleGeneratorType< TransformMesh< Mesh > >::Type mTriangles
Definition AxisFlipMesh.hpp:39
bool done() const noexcept
Definition AxisFlipMesh.hpp:33
void next()
Definition AxisFlipMesh.hpp:34
Triangle generate() const
Definition AxisFlipMesh.hpp:26
const AxisFlipMesh * mMesh
Definition AxisFlipMesh.hpp:37
Triangles(const AxisFlipMesh &mesh)
Definition AxisFlipMesh.hpp:41
Flips (mirrors) the mesh along one or more axis.
Definition AxisFlipMesh.hpp:18
bool mFlip
Definition AxisFlipMesh.hpp:88
Impl mTransformMesh
Definition AxisFlipMesh.hpp:21
Vertices vertices() const noexcept
Definition AxisFlipMesh.hpp:85
AxisFlipMesh(Mesh mesh, bool x, bool y, bool z)
Definition AxisFlipMesh.hpp:50
typename Impl::Vertices Vertices
Definition AxisFlipMesh.hpp:84
Triangles triangles() const noexcept
Definition AxisFlipMesh.hpp:82
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
AxisFlipMesh< Mesh > axisFlipMesh(Mesh mesh, bool x, bool y, bool z)
Definition AxisFlipMesh.hpp:91
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