mirror of
https://github.com/TheRedShip/RT_GPU.git
synced 2025-09-27 18:48:36 +02:00
~ | Switching to glm vectors
This commit is contained in:
@ -24,7 +24,6 @@
|
||||
# include <iostream>
|
||||
|
||||
# include "Camera.hpp"
|
||||
# include "Vector/Vector.hpp"
|
||||
# include "Window.hpp"
|
||||
# include "Shader.hpp"
|
||||
|
||||
|
@ -26,7 +26,7 @@ class Shader
|
||||
|
||||
// void compile(const char *vertexSource, const char *fragmentSource);
|
||||
void attach(void);
|
||||
void setupVertexBuffer(const RT::Vec2f* vertices, size_t size);
|
||||
void setupVertexBuffer(const glm::vec2* vertices, size_t size);
|
||||
void drawTriangles(size_t size);
|
||||
|
||||
|
||||
@ -34,7 +34,7 @@ class Shader
|
||||
// void setBool(const std::string &name, bool value) const;
|
||||
// void setInt(const std::string &name, int value) const;
|
||||
// void setFloat(const std::string &name, float value) const;
|
||||
void setVec2f(const std::string &name, const RT::Vec2f &value) const;
|
||||
void setVec2f(const std::string &name, const glm::vec2 &value) const;
|
||||
// void setVec3(const std::string &name, const RT::Vec3f &value) const;
|
||||
// void setVec4(const std::string &name, const RT::Vec4f &value) const;
|
||||
// void setMat4(const std::string &name, const RT::Mat4f &value) const;
|
||||
|
@ -1,38 +0,0 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* Vec2.hpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: TheRed <TheRed@students.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/10/13 17:16:11 by TheRed #+# #+# */
|
||||
/* Updated: 2024/10/13 17:16:11 by TheRed ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef RT_VEC2__HPP
|
||||
#define RT_VEC2__HPP
|
||||
|
||||
# include "Vector/Vector.hpp"
|
||||
|
||||
namespace RT
|
||||
{
|
||||
template<typename T>
|
||||
class Vec2 : public Vector<Vec2<T>, T, 2>
|
||||
{
|
||||
public:
|
||||
using Vector<Vec2<T>, T, 2>::Vector;
|
||||
|
||||
constexpr Vec2(T x, T y)
|
||||
{
|
||||
this->data[0] = x;
|
||||
this->data[1] = y;
|
||||
}
|
||||
};
|
||||
|
||||
using Vec2f = Vec2<float>;
|
||||
using Vec2d = Vec2<double>;
|
||||
using Vec2i = Vec2<int>;
|
||||
}
|
||||
|
||||
#endif
|
@ -1,49 +0,0 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* Vec3.hpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: ycontre <ycontre@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/10/13 17:17:04 by TheRed #+# #+# */
|
||||
/* Updated: 2024/10/13 20:32:13 by ycontre ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef RT_VEC3__HPP
|
||||
# define RT_VEC3__HPP
|
||||
|
||||
# include "Vector/Vector.hpp"
|
||||
# include <cmath>
|
||||
|
||||
namespace RT
|
||||
{
|
||||
template<typename T>
|
||||
class Vec3 : public Vector<Vec3<T>, T, 3>
|
||||
{
|
||||
public:
|
||||
using Vector<Vec3<T>, T, 3>::Vector;
|
||||
|
||||
constexpr Vec3(T x, T y, T z)
|
||||
{
|
||||
this->data[0] = x;
|
||||
this->data[1] = y;
|
||||
this->data[2] = z;
|
||||
}
|
||||
|
||||
constexpr T Distance(const Vec3& other) const
|
||||
{
|
||||
T dx = this->data[0] - other.data[0];
|
||||
T dy = this->data[1] - other.data[1];
|
||||
T dz = this->data[2] - other.data[2];
|
||||
|
||||
return std::sqrt(dx * dx + dy * dy + dz * dz);
|
||||
}
|
||||
};
|
||||
|
||||
using Vec3f = Vec3<float>;
|
||||
using Vec3d = Vec3<double>;
|
||||
using Vec3i = Vec3<int>;
|
||||
}
|
||||
|
||||
#endif
|
@ -1,40 +0,0 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* Vec4.hpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: TheRed <TheRed@students.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/10/13 17:18:35 by TheRed #+# #+# */
|
||||
/* Updated: 2024/10/13 17:18:35 by TheRed ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef RT_VEC4__HPP
|
||||
# define RT_VEC4__HPP
|
||||
|
||||
# include "Vector/Vector.hpp"
|
||||
|
||||
namespace RT
|
||||
{
|
||||
template<typename T>
|
||||
class Vec4 : public Vector<Vec4<T>, T, 4>
|
||||
{
|
||||
public:
|
||||
using Vector<Vec4<T>, T, 4>::Vector;
|
||||
|
||||
constexpr Vec4(T r, T g, T b, T a)
|
||||
{
|
||||
this->data[0] = r;
|
||||
this->data[1] = g;
|
||||
this->data[2] = b;
|
||||
this->data[3] = a;
|
||||
}
|
||||
};
|
||||
|
||||
using Vec4f = Vec4<float>;
|
||||
using Vec4d = Vec4<double>;
|
||||
using Vec4i = Vec4<int>;
|
||||
}
|
||||
|
||||
#endif
|
@ -1,111 +0,0 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* Vector.hpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: TheRed <TheRed@students.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/10/13 17:13:03 by TheRed #+# #+# */
|
||||
/* Updated: 2024/10/13 17:13:03 by TheRed ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef RT_VECTOR__HPP
|
||||
#define RT_VECTOR__HPP
|
||||
|
||||
#include <iostream>
|
||||
#include <array>
|
||||
|
||||
namespace RT
|
||||
{
|
||||
template<typename Derived, typename T, std::size_t N>
|
||||
class Vector
|
||||
{
|
||||
public:
|
||||
std::array<T, N> data;
|
||||
|
||||
constexpr Vector() { data.fill(0); }
|
||||
|
||||
constexpr Vector(std::initializer_list<T> values) { std::copy(values.begin(), values.end(), data.begin()); }
|
||||
|
||||
constexpr T& operator[](std::size_t i) { return data[i]; }
|
||||
constexpr const T& operator[](std::size_t i) const { return data[i]; }
|
||||
|
||||
constexpr Derived operator+(const Vector& vec) const
|
||||
{
|
||||
Derived result;
|
||||
for (std::size_t i = 0; i < N; ++i)
|
||||
result[i] = data[i] + vec[i];
|
||||
return result;
|
||||
}
|
||||
constexpr Derived operator-(const Vector& vec) const
|
||||
{
|
||||
Derived result;
|
||||
for (std::size_t i = 0; i < N; ++i)
|
||||
result[i] = data[i] - vec[i];
|
||||
return result;
|
||||
}
|
||||
constexpr Derived operator*(T scalar) const
|
||||
{
|
||||
Derived result;
|
||||
for (std::size_t i = 0; i < N; ++i)
|
||||
result[i] = data[i] * scalar;
|
||||
return result;
|
||||
}
|
||||
constexpr Derived operator/(T scalar) const
|
||||
{
|
||||
Derived result;
|
||||
for (std::size_t i = 0; i < N; ++i)
|
||||
result[i] = data[i] / scalar;
|
||||
return result;
|
||||
}
|
||||
|
||||
constexpr Derived& operator+=(const Vector& vec)
|
||||
{
|
||||
*this = *this + vec;
|
||||
return static_cast<Derived&>(*this);
|
||||
}
|
||||
constexpr Derived& operator-=(const Vector& vec)
|
||||
{
|
||||
*this = *this - vec;
|
||||
return static_cast<Derived&>(*this);
|
||||
}
|
||||
constexpr Derived& operator*=(const Vector& vec)
|
||||
{
|
||||
*this = *this * vec;
|
||||
return static_cast<Derived&>(*this);
|
||||
}
|
||||
constexpr Derived& operator/=(const Vector& vec)
|
||||
{
|
||||
*this = *this / vec;
|
||||
return static_cast<Derived&>(*this);
|
||||
}
|
||||
|
||||
constexpr Derived& operator*=(T scalar)
|
||||
{
|
||||
*this = *this * scalar;
|
||||
return static_cast<Derived&>(*this);
|
||||
}
|
||||
constexpr Derived& operator/=(T scalar)
|
||||
{
|
||||
*this = *this / scalar;
|
||||
return static_cast<Derived&>(*this);
|
||||
}
|
||||
|
||||
void print() const
|
||||
{
|
||||
std::cout << "Vec" << N << "(";
|
||||
for (std::size_t i = 0; i < N; ++i) {
|
||||
std::cout << data[i];
|
||||
if (i < N - 1) std::cout << ", ";
|
||||
}
|
||||
std::cout << ")" << std::endl;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#include "Vector/Vec2.hpp"
|
||||
#include "Vector/Vec3.hpp"
|
||||
#include "Vector/Vec4.hpp"
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user