Air-Trap 1.0.0
A multiplayer R-Type clone game engine built with C++23 and ECS architecture
Loading...
Searching...
No Matches
Vec3.tpp
Go to the documentation of this file.
1/*
2** EPITECH PROJECT, 2025
3** R-Type
4** File description:
5** Vec3.tpp, Vector of 3 class implementation
6*/
7
8/*
9** MIT License
10**
11** Copyright (c) 2025 Robin Toillon
12**
13** Permission is hereby granted, free of charge, to any person obtaining
14** a copy of this software and associated documentation files (the
15** "Software"), to deal in the Software without restriction, including
16** without limitation the rights to use, copy, modify, merge, publish,
17** distribute, sublicense, and/or sell copies of the Software, and to
18** permit persons to whom the Software is furnished to do so, subject to
19** the following conditions:
20**
21** The above copyright notice and this permission notice shall be
22** included in all copies or substantial portions of the Software.
23**
24** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
27** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
28** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
29** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
30** SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31*/
32
33/**
34 * @file Vec3.tpp
35 * @brief Implementation of the 3-dimensional vector class.
36 * @author Robin Toillon
37 */
38
39namespace rtp
40{
41 template<Numeric T>
42 constexpr Vec3<T>::Vec3(T x_, T y_, T z_) noexcept : x{x_}, y{y_}, z{z_}
43 {
44 }
45
46 template <Numeric T>
47 constexpr auto &Vec3<T>::operator[](this auto &self,
48 std::size_t index) noexcept
49 {
50 if (index == 0)
51 return self.x;
52 if (index == 1)
53 return self.y;
54 if (index == 2)
55 return self.z;
56 RTP_ASSERT(false, "Vec3: Index {} out of bounds", index);
57 std::unreachable();
58 }
59
60 template <Numeric T>
61 constexpr auto Vec3<T>::cross(const Vec3 &other) const noexcept
62 -> Vec3
63 {
64 return Vec3{y * other.z - z * other.y,
65 z * other.x - x * other.z,
66 x * other.y - y * other.x};
67 }
68}