CeresEngine 0.2.0
A game development framework
Loading...
Searching...
No Matches
RotateMesh.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
14
16 template<typename Mesh> class RotateMesh {
17 private:
20
21 public:
24 RotateMesh(Mesh mesh, const Quaternion& rotation)
25 : mTransformMesh{std::move(mesh), [rotation](MeshVertex& value) {
26 value.position = Math::transform(rotation, value.position);
27 value.normal = Math::transform(rotation, value.normal);
28 }} {}
29
33 RotateMesh(Mesh mesh, const double angle, const Vector3& axis) : RotateMesh{std::move(mesh), qrotate(angle, axis)} {}
34
35 RotateMesh(Mesh mesh, const double angle, const Axis axis)
36 : RotateMesh{std::move(mesh),
37 qrotate(angle, axis == Axis::X ? Vector3{1.0, 0.0, 0.0} : (axis == Axis::Y ? Vector3{0.0, 1.0, 0.0} : Vector3{0.0, 0.0, 1.0}))} {}
38
39 using Triangles = typename Impl::Triangles;
40
41 [[nodiscard]] Triangles triangles() const noexcept { return mTransformMesh.triangles(); }
42
43 using Vertices = typename Impl::Vertices;
44
45 [[nodiscard]] Vertices vertices() const noexcept { return mTransformMesh.vertices(); }
46 };
47
48 template<typename Mesh> RotateMesh<Mesh> rotateMesh(Mesh mesh, const Quaternion& rotation) { return RotateMesh<Mesh>{std::move(mesh), rotation}; }
49
50 template<typename Mesh> RotateMesh<Mesh> rotateMesh(Mesh mesh, double angle, const Vector3& axis) { return RotateMesh<Mesh>{std::move(mesh), angle, axis}; }
51
52 template<typename Mesh> RotateMesh<Mesh> rotateMesh(Mesh mesh, double angle, Axis axis) { return RotateMesh<Mesh>{std::move(mesh), angle, axis}; }
53
54} // namespace CeresEngine::MeshGenerator
Definition MeshVertex.hpp:14
Rotates vertices and normals.
Definition RotateMesh.hpp:16
Impl mTransformMesh
Definition RotateMesh.hpp:19
RotateMesh(Mesh mesh, const double angle, const Axis axis)
Definition RotateMesh.hpp:35
Triangles triangles() const noexcept
Definition RotateMesh.hpp:41
typename Impl::Vertices Vertices
Definition RotateMesh.hpp:43
RotateMesh(Mesh mesh, const double angle, const Vector3 &axis)
Definition RotateMesh.hpp:33
RotateMesh(Mesh mesh, const Quaternion &rotation)
Definition RotateMesh.hpp:24
Vertices vertices() const noexcept
Definition RotateMesh.hpp:45
typename Impl::Triangles Triangles
Definition RotateMesh.hpp:39
Apply a mutator function to each vertex.
Definition TransformMesh.hpp:18
typename Impl::Triangles Triangles
Definition TransformMesh.hpp:50
A base class for all mesh implementations.
Definition Mesh.hpp:112
Definition AnyGenerator.hpp:12
RotateMesh< Mesh > rotateMesh(Mesh mesh, const Quaternion &rotation)
Definition RotateMesh.hpp:48
Axis
Definition Axis.hpp:12
auto move(Vector3 position)
Moves a entity to the given position.
Definition Helpers.hpp:22
Axis axis(const StringView &str) noexcept
Returns the Axis constant that is represented by str.
constexpr size_t hash(const T &v)
Generates a hash for the provided type.
Definition Hash.hpp:25
TVector3< T > transform(const TQuaternion< T > &q, const TVector3< T > &v)
Definition Math.hpp:694
Definition Span.hpp:668