97 lines
2.6 KiB
C++
97 lines
2.6 KiB
C++
/*
|
|
Copyright (C) 2026 iikorni
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
modify it under the terms of the GNU General Public License
|
|
as published by the Free Software Foundation; either version 2
|
|
of the License, or (at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
See the GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program; if not, write to the Free Software
|
|
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
#pragma once
|
|
#include <tuple>
|
|
#include <GL/gl.h>
|
|
|
|
namespace math {
|
|
constexpr std::floating_point auto degrees_to_radians(std::floating_point auto angle) {
|
|
return angle * (std::numbers::pi / 180.0);
|
|
}
|
|
|
|
struct vec3f;
|
|
struct vec4f;
|
|
|
|
struct vec3f {
|
|
float x, y, z;
|
|
|
|
constexpr vec3f() : x(0), y(0), z(0) {}
|
|
constexpr vec3f(const float x, const float y, const float z) : x(x), y(y), z(z) {
|
|
}
|
|
|
|
[[nodiscard]] float dot(const vec3f &rhs) const;
|
|
|
|
[[nodiscard]] double ddot(const vec3f &rhs) const;
|
|
|
|
[[nodiscard]] float dot(const vec4f &rhs) const;
|
|
|
|
[[nodiscard]] double ddot(const vec4f &rhs) const;
|
|
|
|
float operator*(const vec3f &rhs) const;
|
|
|
|
float operator*(const vec4f &rhs) const;
|
|
|
|
vec3f operator*(const float rhs) const;
|
|
|
|
vec3f operator+(const vec3f &rhs) const;
|
|
|
|
vec3f operator-(const vec3f &rhs) const;
|
|
|
|
bool operator==(const vec3f &rhs) const;
|
|
|
|
float& operator[](std::size_t i);
|
|
|
|
vec3f normalize() const;
|
|
|
|
vec3f multiply_add(const vec3f &rhs, float scale) const;
|
|
|
|
vec3f cross(const vec3f &rhs) const;
|
|
|
|
float magnitude() const;
|
|
|
|
vec3f operator-() const;
|
|
|
|
vec3f perpendicular() const;
|
|
|
|
std::array<float, 3> into_array() const;
|
|
|
|
static vec3f to_angles(vec3f forward);
|
|
|
|
static std::tuple<vec3f, vec3f, vec3f> from_angles(const vec3f &angles);
|
|
|
|
static vec3f turn(const vec3f &forward, const vec3f &side, float angle);
|
|
};
|
|
|
|
|
|
struct vec4f {
|
|
float x, y, z, w;
|
|
|
|
constexpr vec4f() : x(0), y(0), z(0), w(1.0) {}
|
|
constexpr vec4f(const float x, const float y, const float z, const float w) : x(x), y(y), z(z), w(w) {}
|
|
explicit constexpr vec4f(const vec3f &v) : x(v.x), y(v.y), z(v.z), w(1.0f) {}
|
|
|
|
float &operator[](std::size_t i);
|
|
};
|
|
|
|
constexpr vec3f ORIGIN = { 0.0f, 0.0f, 0.0f };
|
|
|
|
}
|