rebranding moment

This commit is contained in:
2024-07-09 19:29:22 +03:00
parent 528b8a0ca9
commit 13e7adc8f6
24 changed files with 105 additions and 70 deletions

75
include/omath/Vector3.h Normal file
View File

@@ -0,0 +1,75 @@
//
// Created by vlad on 10/28/23.
//
#pragma once
namespace omath
{
class Vector3 {
public:
float x = 0.f;
float y = 0.f;
float z = 0.f;
Vector3(const float x, const float y, const float z)
{
this->x = x;
this->y = y;
this->z = z;
}
Vector3() = default;
bool operator==(const Vector3& src) const;
bool operator!=(const Vector3& src) const;
Vector3& operator+=(const Vector3& v);
Vector3& operator-=(const Vector3& v);
Vector3& operator*=(float fl);
Vector3& operator*=(const Vector3& v);
Vector3& operator/=(const Vector3& v);
Vector3& operator+=(float fl);
Vector3& operator/=(float fl);
Vector3& operator-=(float fl);
[[nodiscard]] float DistTo(const Vector3& vOther) const;
Vector3& Abs();
[[nodiscard]] float DistToSqr(const Vector3& vOther) const;
[[nodiscard]] float Dot(const Vector3& vOther) const;
[[nodiscard]] float Length() const;
[[nodiscard]] float LengthSqr() const;
[[nodiscard]] float Length2D() const;
Vector3 operator-() const;
Vector3 operator+(const Vector3& v) const;
Vector3 operator-(const Vector3& v) const;
Vector3 operator*(float fl) const;
Vector3 operator*(const Vector3& v) const;
Vector3 operator/(float fl) const;
Vector3 operator/(const Vector3& v) const;
template<class type>
const type& As() const
{
return *reinterpret_cast<const type*>(this);
}
template<class type>
type& As()
{
return *reinterpret_cast<type*>(this);
}
[[nodiscard]] Vector3 Cross(const Vector3 &v) const;
[[nodiscard]] static Vector3 CreateVelocity(float pitch, float yaw, float speed);
[[nodiscard]] float Sum() const;
[[nodiscard]] float Sum2D() const;
[[nodiscard]] Vector3 ViewAngleTo(const Vector3& other) const;
[[nodiscard]] static Vector3 ForwardVector(float pitch, float yaw);
[[nodiscard]] static Vector3 RightVector(float pitch, float yaw, float roll);
[[nodiscard]] static Vector3 UpVector(float pitch, float yaw, float roll);
[[nodiscard]]
Vector3 Normalized() const;
};
}

62
include/omath/Vector4.h Normal file
View File

@@ -0,0 +1,62 @@
//
// Vector4.h
//
#pragma once
#include <omath/Vector3.h>
namespace omath
{
class Vector4 : public Vector3
{
public:
float w = 0.f;
Vector4(const float x = 0.f, const float y = 0.f, const float z = 0.f, const float w = 0.f) : Vector3(x, y, z), w(w) {}
Vector4() = default;
[[nodiscard]]
bool operator==(const Vector4& src) const;
[[nodiscard]]
bool operator!=(const Vector4& src) const;
Vector4& operator+=(const Vector4& v);
Vector4& operator-=(const Vector4& v);
Vector4& operator*=(float scalar);
Vector4& operator*=(const Vector4& v);
Vector4& operator/=(float scalar);
Vector4& operator/=(const Vector4& v);
[[nodiscard]] float Length() const;
[[nodiscard]] float LengthSqr() const;
[[nodiscard]] float Dot(const Vector4& vOther) const;
Vector4& Abs();
Vector4& Clamp(float min, float max);
[[nodiscard]]
Vector4 operator-() const;
[[nodiscard]]
Vector4 operator+(const Vector4& v) const;
[[nodiscard]]
Vector4 operator-(const Vector4& v) const;
[[nodiscard]]
Vector4 operator*(float scalar) const;
[[nodiscard]]
Vector4 operator*(const Vector4& v) const;
[[nodiscard]]
Vector4 operator/(float scalar) const;
[[nodiscard]]
Vector4 operator/(const Vector4& v) const;
[[nodiscard]]
float Sum() const;
};
}

11
include/omath/angles.h Normal file
View File

@@ -0,0 +1,11 @@
//
// Created by vlad on 11/6/23.
//
#pragma once
namespace omath::angles
{
[[nodiscard]] constexpr float RadiansToDegrees(float rads);
[[nodiscard]] constexpr float DegreesToRadians(float degrees);
}

47
include/omath/color.h Normal file
View File

@@ -0,0 +1,47 @@
//
// Created by vlad on 2/4/24.
//
#pragma once
#include "omath/Vector3.h"
#include <cstdint>
#include "omath/Vector4.h"
namespace omath::color
{
struct HSV
{
float m_hue{};
float m_saturation{};
float m_value{};
};
[[nodiscard]]
Vector3 Blend(const Vector3& first, const Vector3& second, float ratio);
class Color : public Vector4
{
public:
Color(float r, float g, float b, float a);
[[nodiscard]]
static Color FromRGBA(uint8_t r, uint8_t g, uint8_t b, uint8_t a);
[[nodiscard]]
static Color FromHSV(float hue, float saturation, float value);
[[nodiscard]]
HSV ToHSV() const;
explicit Color(Vector4 vec);
[[nodiscard]]
Color Blend(const Color& other, float ratio) const;
[[nodiscard]] static Color Red() {return {1.f, 0.f, 0.f, 1.f};}
[[nodiscard]] static Color Green() {return {0.f, 1.f, 0.f, 1.f};}
[[nodiscard]] static Color Blue() {return {0.f, 0.f, 1.f, 1.f};}
};
}

95
include/omath/matrix.h Normal file
View File

@@ -0,0 +1,95 @@
#pragma once
#include <vector>
#include <memory>
#include <string>
namespace omath
{
class Vector3;
class matrix
{
public:
matrix(size_t rows, size_t columns);
explicit matrix(const std::vector<std::vector<float>> &rows);
[[nodiscard]]
static matrix to_screen_matrix(float screenWidth, float screenHeight);
matrix(const matrix &other);
matrix(size_t rows, size_t columns, const float *pRaw);
matrix(matrix &&other) noexcept;
[[nodiscard]]
size_t get_rows_count() const noexcept;
[[nodiscard]]
size_t get_columns_count() const noexcept;
[[nodiscard]]
std::pair<size_t, size_t> get_size() const noexcept;
[[nodiscard]]
float &at(size_t iRow, size_t iCol);
[[nodiscard]]
float get_sum();
void set_from_raw(const float* pRawMatrix);
[[nodiscard]]
matrix transpose();
void set(float val);
[[nodiscard]]
const float &at(size_t iRow, size_t iCol) const;
matrix operator*(const matrix &other) const;
matrix operator*(float f) const;
matrix operator*(const Vector3 &vec3) const;
matrix &operator*=(float f);
matrix &operator/=(float f);
void clear();
[[nodiscard]]
matrix strip(size_t row, size_t column) const;
[[nodiscard]]
float minor(size_t i, size_t j) const;
[[nodiscard]]
float alg_complement(size_t i, size_t j) const;
[[nodiscard]]
float det() const;
[[nodiscard]]
const float* raw() const;
matrix &operator=(const matrix &other);
matrix &operator=(matrix &&other) noexcept;
matrix operator/(float f) const;
[[nodiscard]]
std::string to_string() const;
~matrix();
private:
size_t m_rows = 0;
size_t m_columns = 0;
std::unique_ptr<float[]> m_pData = nullptr;
};
}

View File

@@ -0,0 +1,39 @@
//
// Created by Vlad on 6/9/2024.
//
#pragma once
#include <optional>
#include "omath/Vector3.h"
#include "omath/prediction/Projectile.h"
#include "omath/prediction/Target.h"
namespace omath::prediction
{
class Engine
{
public:
explicit Engine(float gravityConstant, float simulationTimeStep,
float maximumSimulationTime, float distanceTolerance);
[[nodiscard]]
std::optional<Vector3> MaybeCalculateAimPoint(const Projectile& projectile, const Target& target) const;
private:
const float m_gravityConstant;
const float m_simulationTimeStep;
const float m_maximumSimulationTime;
const float m_distanceTolerance;
[[nodiscard]]
std::optional<float> MaybeCalculateProjectileLaunchPitchAngle(const Projectile& projectile,
const Vector3& targetPosition) const;
[[nodiscard]]
bool IsProjectileReachedTarget(const Vector3& targetPosition, const Projectile& projectile, float pitch, float time) const;
};
}

View File

@@ -0,0 +1,25 @@
//
// Created by Vlad on 6/9/2024.
//
#pragma once
#include "omath/Vector3.h"
namespace omath::prediction
{
class Projectile final
{
public:
[[nodiscard]]
Vector3 CalculateVelocity(float pitch, float yaw) const;
[[nodiscard]]
Vector3 PredictPosition(float pitch, float yaw, float time, float gravity) const;
Vector3 m_origin;
float m_launchSpeed{};
float m_gravityScale{};
};
}

View File

@@ -0,0 +1,22 @@
//
// Created by Vlad on 6/9/2024.
//
#pragma once
#include "omath/Vector3.h"
namespace omath::prediction
{
class Target final
{
public:
[[nodiscard]]
Vector3 PredictPosition(float time, float gravity) const;
Vector3 m_origin;
Vector3 m_velocity;
bool m_isAirborne{};
};
}