le2d v0.4.7
2D game engine framework
 
Loading...
Searching...
No Matches
vector_space.hpp
Go to the documentation of this file.
1#pragma once
2#include <kvf/is_positive.hpp>
3#include <kvf/util.hpp>
4
5namespace le {
6namespace uv {
7struct vec2;
8} // namespace uv
9
10namespace ndc {
11struct vec2 : glm::vec2 {
12 using glm::vec2::vec2;
13
14 explicit(false) constexpr vec2(glm::vec2 const in) : glm::vec2(in) {}
15
16 [[nodiscard]] constexpr auto to_target(glm::vec2 const target_size) const -> glm::vec2 { return *this * target_size; }
17
18 [[nodiscard]] constexpr auto to_uv() const -> uv::vec2;
19};
20} // namespace ndc
21
22namespace uv {
23struct vec2 : glm::vec2 {
24 using glm::vec2::vec2;
25
26 explicit(false) constexpr vec2(glm::vec2 const in) : glm::vec2(in) {}
27
28 [[nodiscard]] constexpr auto to_target(glm::vec2 const target_size) const -> glm::vec2 { return *this * target_size; }
29 [[nodiscard]] constexpr auto to_ndc() const -> ndc::vec2;
30};
31} // namespace uv
32
33namespace window {
34template <typename Type>
35struct tvec2 : glm::tvec2<Type> {
36 using glm::tvec2<Type>::tvec2;
37
38 [[nodiscard]] constexpr auto to_ndc(glm::vec2 const window_size) const -> ndc::vec2 {
39 if (!kvf::is_positive(window_size)) { return {}; }
40 return uv::vec2{glm::vec2(*this) / window_size}.to_ndc();
41 }
42};
43
46} // namespace window
47
48constexpr auto ndc::vec2::to_uv() const -> uv::vec2 { return kvf::util::ndc_to_uv(*this); }
49
50constexpr auto uv::vec2::to_ndc() const -> ndc::vec2 { return kvf::util::uv_to_ndc(*this); }
51
52[[nodiscard]] constexpr auto uv_to_world(kvf::UvRect const& uv, glm::vec2 const target_size) -> kvf::Rect<> { return target_size * kvf::util::uv_to_ndc(uv); }
53
54[[nodiscard]] constexpr auto world_to_uv(kvf::Rect<> const& rect) -> kvf::UvRect {
55 auto const size = rect.size();
56 if (!kvf::is_positive(size)) { return {}; }
57 return kvf::util::ndc_to_uv(rect / size);
58}
59} // namespace le
Definition animation.hpp:8
constexpr auto uv_to_world(kvf::UvRect const &uv, glm::vec2 const target_size) -> kvf::Rect<>
Definition vector_space.hpp:52
constexpr auto world_to_uv(kvf::Rect<> const &rect) -> kvf::UvRect
Definition vector_space.hpp:54
Definition vector_space.hpp:11
constexpr auto to_target(glm::vec2 const target_size) const -> glm::vec2
Definition vector_space.hpp:16
constexpr auto to_uv() const -> uv::vec2
Definition vector_space.hpp:48
Definition vector_space.hpp:23
constexpr auto to_target(glm::vec2 const target_size) const -> glm::vec2
Definition vector_space.hpp:28
constexpr auto to_ndc() const -> ndc::vec2
Definition vector_space.hpp:50
Definition vector_space.hpp:35
constexpr auto to_ndc(glm::vec2 const window_size) const -> ndc::vec2
Definition vector_space.hpp:38