Unravel Engine C++ Reference
Loading...
Searching...
No Matches
rotate_mesh.hpp
Go to the documentation of this file.
1#ifndef GENERATOR_ROTATEMESH_HPP
2#define GENERATOR_ROTATEMESH_HPP
3
4#include "axis.hpp"
5#include "transform_mesh.hpp"
6
7namespace generator
8{
9
11template<typename mesh_t>
13{
14private:
16 impl_t transform_mesh_;
17
18public:
21 rotate_mesh_t(mesh_t mesh, const gml::dquat& rotation)
22 : transform_mesh_{std::move(mesh),
23 [rotation](mesh_vertex_t& value)
24 {
25 value.position = gml::transform(rotation, value.position);
26 value.normal = gml::transform(rotation, value.normal);
27 }}
28 {
29 }
30
34 rotate_mesh_t(mesh_t mesh, double angle, const gml::dvec3& axis)
35 : rotate_mesh_t{std::move(mesh), gml::qrotate(angle, axis)}
36 {
37 }
38
39 rotate_mesh_t(mesh_t mesh, double angle, axis_t axis)
40 : rotate_mesh_t{std::move(mesh),
41 gml::qrotate(angle,
42 axis == axis_t::X
43 ? gml::dvec3{1.0, 0.0, 0.0}
44 : (axis == axis_t::Y ? gml::dvec3{0.0, 1.0, 0.0} : gml::dvec3{0.0, 0.0, 1.0}))}
45 {
46 }
47
49
50 triangles_t triangles() const noexcept
51 {
52 return transform_mesh_.triangles();
53 }
54
56
57 vertices_t vertices() const noexcept
58 {
59 return transform_mesh_.vertices();
60 }
61};
62
63template<typename mesh_t>
64rotate_mesh_t<mesh_t> rotate_mesh(mesh_t mesh, const gml::dquat& rotation)
65{
66 return rotate_mesh_t<mesh_t>{std::move(mesh), rotation};
67}
68
69template<typename mesh_t>
70rotate_mesh_t<mesh_t> rotate_mesh(mesh_t mesh, double angle, const gml::dvec3& axis)
71{
72 return rotate_mesh_t<mesh_t>{std::move(mesh), angle, axis};
73}
74
75template<typename mesh_t>
76rotate_mesh_t<mesh_t> rotate_mesh(mesh_t mesh, double angle, axis_t axis)
77{
78 return rotate_mesh_t<mesh_t>{std::move(mesh), angle, axis};
79}
80} // namespace generator
81
82#endif
Rotates vertices and normals.
vertices_t vertices() const noexcept
typename impl_t::triangles_t triangles_t
typename impl_t::vertices_t vertices_t
triangles_t triangles() const noexcept
rotate_mesh_t(mesh_t mesh, double angle, const gml::dvec3 &axis)
rotate_mesh_t(mesh_t mesh, const gml::dquat &rotation)
rotate_mesh_t(mesh_t mesh, double angle, axis_t axis)
Apply a mutator function to each vertex.
typename impl_t::triangles_t triangles_t
rotate_mesh_t< mesh_t > rotate_mesh(mesh_t mesh, const gml::dquat &rotation)
Definition math.hpp:13
glm::tvec3< T > transform(const glm::tquat< T > &q, const glm::tvec3< T > &v)
Definition math.hpp:114