neoGFX
Cross-platform C++ app/game engine
Loading...
Searching...
No Matches
shapes.hpp
Go to the documentation of this file.
1// shapes.cpp
2/*
3 neogfx C++ App/Game Engine
4 Copyright (c) 2015, 2020 Leigh Johnston. All Rights Reserved.
5
6 This program is free software: you can redistribute it and / or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
18*/
19#pragma once
20
21#include <neogfx/neogfx.hpp>
24
25namespace neogfx
26{
27 enum class mesh_type
28 {
32 };
33
34 struct unsupported_mesh_type : std::logic_error { unsupported_mesh_type() : std::logic_error("neogfx::unsupported_mesh_type") {} };
35
36 template <std::size_t VertexCount, typename CoordinateType, logical_coordinate_system CoordinateSystem>
37 inline void calc_rect_vertices(vec3_array<VertexCount>& aResult, const basic_rect<CoordinateType, CoordinateSystem>& aRect, mesh_type aType, const optional_mat44& aTransformation = {})
38 {
39 auto const& transformableRect = aTransformation ? aRect.with_centered_origin() : aRect;
40 aResult.clear();
41 switch(aType)
42 {
44 aResult.push_back(transformableRect.center().to_vec3());
45 aResult.push_back(transformableRect.top_left().to_vec3());
46 aResult.push_back(transformableRect.top_right().to_vec3());
47 aResult.push_back(transformableRect.bottom_right().to_vec3());
48 aResult.push_back(transformableRect.bottom_left().to_vec3());
49 aResult.push_back(transformableRect.top_left().to_vec3());
50 break;
52 aResult.push_back(transformableRect.top_left().to_vec3());
53 aResult.push_back(transformableRect.top_right().to_vec3());
54 aResult.push_back(transformableRect.bottom_left().to_vec3());
55 aResult.push_back(transformableRect.top_right().to_vec3());
56 aResult.push_back(transformableRect.bottom_right().to_vec3());
57 aResult.push_back(transformableRect.bottom_left().to_vec3());
58 break;
60 aResult.push_back(transformableRect.top_left().to_vec3());
61 aResult.push_back(transformableRect.top_right().to_vec3());
62 aResult.push_back(transformableRect.top_right().to_vec3());
63 aResult.push_back(transformableRect.bottom_right().to_vec3());
64 aResult.push_back(transformableRect.bottom_right().to_vec3());
65 aResult.push_back(transformableRect.bottom_left().to_vec3());
66 aResult.push_back(transformableRect.bottom_left().to_vec3());
67 aResult.push_back(transformableRect.top_left().to_vec3());
68 break;
69 }
70 if (aTransformation)
71 for (auto& v : aResult)
72 v = *aTransformation * v + aRect.center().to_vec3();
73 }
74
75 template <typename CoordinateType, logical_coordinate_system CoordinateSystem>
76 inline vec3_array<8> const& rect_vertices(const basic_rect<CoordinateType, CoordinateSystem>& aRect, mesh_type aType, const optional_mat44& aTransformation = {})
77 {
78 thread_local vec3_array<8> result;
79 calc_rect_vertices(result, aRect, aType, aTransformation);
80 return result;
81 };
82 vertices arc_vertices(const point& aCenter, dimension aRadius, angle aStartAngle, angle aEndAngle, const point& aOrigin, mesh_type aType, uint32_t aArcSegments = 0);
83 vertices circle_vertices(const point& aCenter, dimension aRadius, angle aStartAngle, mesh_type aType, uint32_t aArcSegments = 0);
84 vertices rounded_rect_vertices(const rect& aRect, dimension aRadius, mesh_type aType, uint32_t aArcSegments = 0);
85}
self_type with_centered_origin() const
void push_back(const value_type &value)
Definition vecarray.hpp:566
void calc_rect_vertices(vec3_array< VertexCount > &aResult, const basic_rect< CoordinateType, CoordinateSystem > &aRect, mesh_type aType, const optional_mat44 &aTransformation={})
Definition shapes.hpp:37
vertices arc_vertices(const point &aCenter, dimension aRadius, angle aStartAngle, angle aEndAngle, const point &aOrigin, mesh_type aType, uint32_t aArcSegments=0)
default_geometry_value_type dimension
vertices rounded_rect_vertices(const rect &aRect, dimension aRadius, mesh_type aType, uint32_t aArcSegments=0)
vertices circle_vertices(const point &aCenter, dimension aRadius, angle aStartAngle, mesh_type aType, uint32_t aArcSegments=0)
vec3_array< 8 > const & rect_vertices(const basic_rect< CoordinateType, CoordinateSystem > &aRect, mesh_type aType, const optional_mat44 &aTransformation={})
Definition shapes.hpp:76
mesh_type
Definition shapes.hpp:28
vec3_list vertices