Formatted EVERYTHING

This commit is contained in:
Dynamitos
2024-06-09 12:20:53 +02:00
parent f18bf8acbe
commit d95dab850c
265 changed files with 8002 additions and 12310 deletions
+11 -22
View File
@@ -7,21 +7,14 @@ using namespace Seele;
using namespace Seele::Component;
using namespace Seele::Math;
Camera::Camera()
: viewMatrix(Matrix4())
, cameraPos(Vector())
, bNeedsViewBuild(false)
{
yaw = -3.1415f/2;
Camera::Camera() : viewMatrix(Matrix4()), cameraPos(Vector()), bNeedsViewBuild(false) {
yaw = -3.1415f / 2;
pitch = 0;
}
Camera::~Camera()
{
}
Camera::~Camera() {}
void Camera::mouseMove(float deltaYaw, float deltaPitch)
{
void Camera::mouseMove(float deltaYaw, float deltaPitch) {
yaw += deltaYaw / 500.f;
pitch += deltaPitch / 500.f;
Vector cameraDirection = glm::normalize(Vector(cos(yaw) * cos(pitch), sin(pitch), sin(yaw) * cos(pitch)));
@@ -30,26 +23,22 @@ void Camera::mouseMove(float deltaYaw, float deltaPitch)
bNeedsViewBuild = true;
}
void Camera::mouseScroll(float x)
{
getTransform().translate(getTransform().getForward()*x);
void Camera::mouseScroll(float x) {
getTransform().translate(getTransform().getForward() * x);
bNeedsViewBuild = true;
}
void Camera::moveX(float amount)
{
getTransform().translate(getTransform().getForward()*amount);
void Camera::moveX(float amount) {
getTransform().translate(getTransform().getForward() * amount);
bNeedsViewBuild = true;
}
void Camera::moveY(float amount)
{
getTransform().translate(getTransform().getRight()*amount);
void Camera::moveY(float amount) {
getTransform().translate(getTransform().getRight() * amount);
bNeedsViewBuild = true;
}
void Camera::buildViewMatrix()
{
void Camera::buildViewMatrix() {
Vector eyePos = getTransform().getPosition();
Vector lookAt = eyePos + getTransform().getForward();
viewMatrix = glm::lookAt(eyePos, lookAt, Vector(0, 1, 0));
+10 -16
View File
@@ -3,34 +3,28 @@
#include "Math/Matrix.h"
#include "Transform.h"
namespace Seele
{
namespace Component
{
struct Camera
{
namespace Seele {
namespace Component {
struct Camera {
REQUIRE_COMPONENT(Transform)
Camera();
~Camera();
Matrix4 getViewMatrix() const
{
assert (!bNeedsViewBuild);
Matrix4 getViewMatrix() const {
assert(!bNeedsViewBuild);
return viewMatrix;
}
Vector getCameraPosition() const
{
return cameraPos;
}
Vector getCameraPosition() const { return cameraPos; }
void mouseMove(float deltaX, float deltaY);
void mouseScroll(float x);
void moveX(float amount);
void moveY(float amount);
void buildViewMatrix();
bool mainCamera = false;
private:
private:
float yaw;
float pitch;
Matrix4 viewMatrix;
+1 -2
View File
@@ -3,8 +3,7 @@
using namespace Seele;
using namespace Seele::Component;
Collider Collider::transform(const Transform& transform) const
{
Collider Collider::transform(const Transform& transform) const {
return Collider{
.type = this->type,
.boundingbox = this->boundingbox.getTransformedBox(transform.toMatrix()),
+4 -8
View File
@@ -2,17 +2,13 @@
#include "Math/AABB.h"
#include "ShapeBase.h"
namespace Seele
{
namespace Component
{
enum class ColliderType
{
namespace Seele {
namespace Component {
enum class ColliderType {
STATIC,
DYNAMIC,
};
struct Collider
{
struct Collider {
ColliderType type = ColliderType::STATIC;
AABB boundingbox;
ShapeBase physicsMesh;
+22 -39
View File
@@ -2,58 +2,41 @@
#include <concepts>
#include <tuple>
namespace Seele
{
template<typename... Types>
struct Dependencies;
template<>
struct Dependencies<>
{
namespace Seele {
template <typename... Types> struct Dependencies;
template <> struct Dependencies<> {
int x;
template<typename... Right>
Dependencies<Right...> operator|(const Dependencies<Right...>&)
{
return Dependencies<Right...>();
}
template <typename... Right> Dependencies<Right...> operator|(const Dependencies<Right...>&) { return Dependencies<Right...>(); }
};
template<typename This, typename... Rest>
struct Dependencies<This, Rest...> : public Dependencies<Rest...>
{
template<typename... Right>
Dependencies<This, Rest..., Right...> operator|(const Dependencies<Right...>&)
{
template <typename This, typename... Rest> struct Dependencies<This, Rest...> : public Dependencies<Rest...> {
template <typename... Right> Dependencies<This, Rest..., Right...> operator|(const Dependencies<Right...>&) {
return Dependencies<This, Rest..., Right...>();
}
int x;
};
namespace Component
{
template<typename Comp>
Comp& getComponent();
namespace Component {
template <typename Comp> Comp& getComponent();
}
template<typename Comp>
template <typename Comp>
concept has_dependencies = requires(Comp) { Comp::dependencies; };
#define REQUIRE_COMPONENT(x) \
private: \
x& get##x() { return getComponent<x>(); } \
const x& get##x() const { return getComponent<x>(); } \
public: \
#define REQUIRE_COMPONENT(x) \
private: \
x& get##x() { return getComponent<x>(); } \
const x& get##x() const { return getComponent<x>(); } \
\
public: \
constexpr static Dependencies<x> dependencies = {};
#define DECLARE_COMPONENT(x) \
void accessComponent(x& val); \
template<> \
x& getComponent<x>();
#define DEFINE_COMPONENT(x) \
thread_local x* tl_##x = nullptr; \
void Seele::Component::accessComponent(x& ref) { tl_##x = &ref; } \
template<> \
x& Seele::Component::getComponent<x>() { return *tl_##x; }
#define DECLARE_COMPONENT(x) \
void accessComponent(x& val); \
template <> x& getComponent<x>();
#define DEFINE_COMPONENT(x) \
thread_local x* tl_##x = nullptr; \
void Seele::Component::accessComponent(x& ref) { tl_##x = &ref; } \
template <> x& Seele::Component::getComponent<x>() { return *tl_##x; }
} // namespace Seele
+3 -6
View File
@@ -1,11 +1,8 @@
#pragma once
#include "Math/Vector.h"
namespace Seele
{
namespace Component
{
struct DirectionalLight
{
namespace Seele {
namespace Component {
struct DirectionalLight {
Vector4 color;
Vector4 direction;
};
+4 -7
View File
@@ -1,12 +1,9 @@
#pragma once
#include "Graphics/Resources.h"
namespace Seele
{
namespace Component
{
struct KeyboardInput
{
namespace Seele {
namespace Component {
struct KeyboardInput {
Seele::StaticArray<bool, static_cast<size_t>(Seele::KeyCode::KEY_LAST)> keys;
bool mouse1;
bool mouse2;
@@ -16,6 +13,6 @@ struct KeyboardInput
float deltaY;
float scrollX;
float scrollY;
};
};
} // namespace Component
} // namespace Seele
+3 -6
View File
@@ -1,12 +1,9 @@
#pragma once
#include "Asset/MeshAsset.h"
namespace Seele
{
namespace Component
{
struct Mesh
{
namespace Seele {
namespace Component {
struct Mesh {
PMeshAsset asset;
bool isStatic = true;
};
+4 -7
View File
@@ -1,14 +1,11 @@
#pragma once
#include "Math/Vector.h"
namespace Seele
{
namespace Component
{
struct PointLight
{
namespace Seele {
namespace Component {
struct PointLight {
Vector4 positionWS;
//Vector4 positionVS;
// Vector4 positionVS;
Vector4 colorRange;
};
} // namespace Component
+3 -6
View File
@@ -1,12 +1,9 @@
#pragma once
#include "Math/AABB.h"
namespace Seele
{
namespace Component
{
struct RigidBody
{
namespace Seele {
namespace Component {
struct RigidBody {
float mass = 1.0f;
Vector force;
Vector torque;
+60 -86
View File
@@ -4,14 +4,12 @@
using namespace Seele;
using namespace Seele::Component;
//https://people.eecs.berkeley.edu/~jfc/mirtich/massProps.html
struct ComputationState
{
// https://people.eecs.berkeley.edu/~jfc/mirtich/massProps.html
struct ComputationState {
// compute physics properties
int A; /* alpha */
int B; /* beta */
int C; /* gamma */
int A; /* alpha */
int B; /* beta */
int C; /* gamma */
/* projection integrals */
float P1, Pa, Pb, Paa, Pab, Pbb, Paaa, Paab, Pabb, Pbbb;
@@ -24,28 +22,25 @@ struct ComputationState
Vector T1, T2, TP;
};
struct Face
{
struct Face {
StaticArray<Vector, 3> vertices;
Vector normal;
float w;
};
void computeProjectionIntegrals(Face& f, ComputationState& state)
{
void computeProjectionIntegrals(Face& f, ComputationState& state) {
state.P1 = state.Pa = state.Pb = state.Paa = state.Pab = state.Pbb = state.Paaa = state.Paab = state.Pabb = state.Pbbb = 0.0;
for(uint32_t i = 0; i < 3; ++i)
{
for (uint32_t i = 0; i < 3; ++i) {
float a0 = f.vertices[i][state.A];
float b0 = f.vertices[i][state.B];
float a1 = f.vertices[(i+1)%3][state.A];
float b1 = f.vertices[(i+1)%3][state.B];
float a1 = f.vertices[(i + 1) % 3][state.A];
float b1 = f.vertices[(i + 1) % 3][state.B];
float da = a1 - a0;
float db = b1 - b0;
float a0_2 = a0 * a0, a0_3 = a0_2 * a0, a0_4 = a0_3 * a0;
float b0_2 = b0 * b0, b0_3 = b0_2 * b0, b0_4 = b0_3 * b0;
float b0_2 = b0 * b0, b0_3 = b0_2 * b0, b0_4 = b0_3 * b0;
float a1_2 = a1 * a1, a1_3 = a1_2 * a1;
float b1_2 = b1 * b1, b1_3 = b1_2 * b1;
@@ -87,10 +82,9 @@ void computeProjectionIntegrals(Face& f, ComputationState& state)
state.Pabb /= -60.0;
}
void computeFaceIntegrals(Face& f, ComputationState& state)
{
void computeFaceIntegrals(Face& f, ComputationState& state) {
computeProjectionIntegrals(f, state);
float k1 = 1.0f/f.normal[state.C];
float k1 = 1.0f / f.normal[state.C];
float k2 = k1 * k1;
float k3 = k2 * k1;
float k4 = k3 * k1;
@@ -104,53 +98,46 @@ void computeFaceIntegrals(Face& f, ComputationState& state)
state.Faa = k1 * state.Paa;
state.Fbb = k1 * state.Pbb;
state.Fcc = k3 * (n[state.A] * n[state.A] * state.Paa
+ 2 * n[state.A] * n[state.B] * state.Pab
+ n[state.B] * n[state.B] * state.Pbb
+ w * (2 * (n[state.A] * state.Pa + n[state.B] * state.Pb) + w * state.P1));
state.Fcc = k3 * (n[state.A] * n[state.A] * state.Paa + 2 * n[state.A] * n[state.B] * state.Pab + n[state.B] * n[state.B] * state.Pbb +
w * (2 * (n[state.A] * state.Pa + n[state.B] * state.Pb) + w * state.P1));
state.Faaa = k1 * state.Paaa;
state.Fbbb = k1 * state.Pbbb;
state.Fccc = -k4 * (n[state.A] * n[state.A] * n[state.A] * state.Paaa
+ 3 * n[state.A] * n[state.A] * n[state.B] * state.Paab
+ 3 * n[state.A] * n[state.B] * n[state.B] * state.Pabb
+ 3 * n[state.B] * n[state.B] * n[state.B] * state.Pbbb
+ 3 * w * (n[state.A] * n[state.A] * state.Paa
+ 2 * n[state.A] * n[state.B] * state.Pa
+ n[state.B] * n[state.B] * state.Pbb)
+ w * w *(3 * (n[state.A]*state.Pa + n[state.B]*state.Pb) + w * state.P1)
);
state.Fccc =
-k4 *
(n[state.A] * n[state.A] * n[state.A] * state.Paaa + 3 * n[state.A] * n[state.A] * n[state.B] * state.Paab +
3 * n[state.A] * n[state.B] * n[state.B] * state.Pabb + 3 * n[state.B] * n[state.B] * n[state.B] * state.Pbbb +
3 * w * (n[state.A] * n[state.A] * state.Paa + 2 * n[state.A] * n[state.B] * state.Pa + n[state.B] * n[state.B] * state.Pbb) +
w * w * (3 * (n[state.A] * state.Pa + n[state.B] * state.Pb) + w * state.P1));
state.Faab = k1 * state.Paab;
state.Fbbc = -k2 * (n[state.A] * state.Paab + n[state.B] * state.Pbbb + w * state.Pbb);
state.Fcca = k3 * (n[state.A] * n[state.A] * state.Paa + 2 * n[state.A] * n[state.B] * state.Paab + n[state.B] * n[state.B] * state.Pabb
+ w * (2 * (n[state.A] * state.Paa + n[state.B] * state.Pab) + w * state.Pa));
state.Fcca = k3 * (n[state.A] * n[state.A] * state.Paa + 2 * n[state.A] * n[state.B] * state.Paab +
n[state.B] * n[state.B] * state.Pabb + w * (2 * (n[state.A] * state.Paa + n[state.B] * state.Pab) + w * state.Pa));
}
void computeVolumeIntegrals(const Array<Vector> vertices, const Array<uint32>& indices, ComputationState& state)
{
void computeVolumeIntegrals(const Array<Vector> vertices, const Array<uint32>& indices, ComputationState& state) {
std::memset(&state, 0, sizeof(ComputationState));
for (size_t i = 0; i < indices.size(); i+=3)
{
for (size_t i = 0; i < indices.size(); i += 3) {
Face f;
f.vertices = {
vertices[indices[i]],
vertices[indices[i+1]],
vertices[indices[i+2]],
vertices[indices[i + 1]],
vertices[indices[i + 2]],
};
Vector e1 = f.vertices[2] - f.vertices[0];
Vector e2 = f.vertices[1] - f.vertices[0];
f.normal = glm::normalize(glm::cross(e1, e2));
f.w = - f.normal.x * f.vertices[0].x
- f.normal.y * f.vertices[0].y
- f.normal.z * f.vertices[0].z;
f.w = -f.normal.x * f.vertices[0].x - f.normal.y * f.vertices[0].y - f.normal.z * f.vertices[0].z;
float nx = std::abs(f.normal.x);
float ny = std::abs(f.normal.y);
float nz = std::abs(f.normal.z);
if (nx > ny && nx > nz) state.C = 0;
else state.C = (ny > nz) ? 1 : 2;
if (nx > ny && nx > nz)
state.C = 0;
else
state.C = (ny > nz) ? 1 : 2;
state.A = (state.C + 1) % 3;
state.B = (state.A + 1) % 3;
@@ -172,8 +159,8 @@ void computeVolumeIntegrals(const Array<Vector> vertices, const Array<uint32>& i
state.TP /= 2.0f;
}
void computePhysicsParamsForMesh(Array<Vector>& vertices, const Array<uint32>& indices, Matrix3& bodyInertia, Vector& centerOfMass, float& mass)
{
void computePhysicsParamsForMesh(Array<Vector>& vertices, const Array<uint32>& indices, Matrix3& bodyInertia, Vector& centerOfMass,
float& mass) {
ComputationState state;
computeVolumeIntegrals(vertices, indices, state);
float density = 1;
@@ -183,9 +170,9 @@ void computePhysicsParamsForMesh(Array<Vector>& vertices, const Array<uint32>& i
bodyInertia[0][0] = density * (state.T2.y + state.T2.z);
bodyInertia[1][1] = density * (state.T2.z + state.T2.x);
bodyInertia[2][2] = density * (state.T2.x + state.T2.y);
bodyInertia[0][1] = bodyInertia[1][0] = - density * state.TP.x;
bodyInertia[1][2] = bodyInertia[2][1] = - density * state.TP.y;
bodyInertia[2][1] = bodyInertia[1][2] = - density * state.TP.z;
bodyInertia[0][1] = bodyInertia[1][0] = -density * state.TP.x;
bodyInertia[1][2] = bodyInertia[2][1] = -density * state.TP.y;
bodyInertia[2][1] = bodyInertia[1][2] = -density * state.TP.z;
bodyInertia[0][0] -= mass * (r.y * r.y + r.z * r.z);
bodyInertia[1][1] -= mass * (r.z * r.z + r.x * r.x);
@@ -195,74 +182,61 @@ void computePhysicsParamsForMesh(Array<Vector>& vertices, const Array<uint32>& i
bodyInertia[2][1] = bodyInertia[1][2] += mass * r.z * r.x;
}
ShapeBase::ShapeBase()
{
}
ShapeBase::ShapeBase() {}
ShapeBase::ShapeBase(Array<Vector> vertices, Array<uint32> indices)
: vertices(vertices)
, indices(indices)
{
ShapeBase::ShapeBase(Array<Vector> vertices, Array<uint32> indices) : vertices(vertices), indices(indices) {
computePhysicsParamsForMesh(vertices, indices, bodyInertia, centerOfMass, mass);
}
ShapeBase ShapeBase::transform(const Component::Transform& transform) const
{
ShapeBase ShapeBase::transform(const Component::Transform& transform) const {
ShapeBase result = *this;
for(auto& vert : result.vertices)
{
for (auto& vert : result.vertices) {
vert = transform.toMatrix() * Vector4(vert, 1.0f);
}
return result;
}
void ShapeBase::addCollider(Array<Vector> verts, Array<uint32> inds, Matrix4 matrix)
{
void ShapeBase::addCollider(Array<Vector> verts, Array<uint32> inds, Matrix4 matrix) {
size_t indOffset = vertices.size();
for(auto vert : verts)
{
for (auto vert : verts) {
vertices.add(Vector(matrix * Vector4(vert, 1.0f)));
}
for(auto ind : inds)
{
for (auto ind : inds) {
indices.add(ind + static_cast<uint32>(indOffset));
}
computePhysicsParamsForMesh(vertices, indices, bodyInertia, centerOfMass, mass);
}
void ShapeBase::visualize() const
{
void ShapeBase::visualize() const {
Array<DebugVertex> verts;
for(uint32 i = 0; i < indices.size(); i+=3)
{
for (uint32 i = 0; i < indices.size(); i += 3) {
verts.add(DebugVertex{
.position = Vector(vertices[indices[i+0]]),
.color = Vector(1, 0, 0),
});
verts.add(DebugVertex{
.position = Vector(vertices[indices[i+1]]),
.position = Vector(vertices[indices[i + 0]]),
.color = Vector(1, 0, 0),
});
verts.add(DebugVertex{
.position = Vector(vertices[indices[i+1]]),
.position = Vector(vertices[indices[i + 1]]),
.color = Vector(1, 0, 0),
});
verts.add(DebugVertex{
.position = Vector(vertices[indices[i+2]]),
.position = Vector(vertices[indices[i + 1]]),
.color = Vector(1, 0, 0),
});
verts.add(DebugVertex{
.position = Vector(vertices[indices[i+2]]),
.position = Vector(vertices[indices[i + 2]]),
.color = Vector(1, 0, 0),
});
verts.add(DebugVertex{
.position = Vector(vertices[indices[i+0]]),
.position = Vector(vertices[indices[i + 2]]),
.color = Vector(1, 0, 0),
});
verts.add(DebugVertex{
.position = Vector(vertices[indices[i + 0]]),
.color = Vector(1, 0, 0),
});
}
+5 -7
View File
@@ -1,14 +1,12 @@
#pragma once
#include "Containers/Array.h"
#include "Transform.h"
#include "Graphics/DebugVertex.h"
#include "Transform.h"
namespace Seele
{
namespace Component
{
struct ShapeBase
{
namespace Seele {
namespace Component {
struct ShapeBase {
ShapeBase();
ShapeBase(Array<Vector> vertices, Array<uint32> indices);
ShapeBase transform(const Component::Transform& transform) const;
+3 -6
View File
@@ -1,12 +1,9 @@
#pragma once
#include "Graphics/Texture.h"
namespace Seele
{
namespace Component
{
struct Skybox
{
namespace Seele {
namespace Component {
struct Skybox {
Gfx::PTextureCube day;
Gfx::PTextureCube night;
Vector fogColor;
+6 -24
View File
@@ -4,29 +4,11 @@ using namespace Seele::Component;
DEFINE_COMPONENT(Transform);
void Transform::setPosition(Vector pos)
{
transform.setPosition(pos);
}
void Transform::setPosition(Vector pos) { transform.setPosition(pos); }
void Transform::setRotation(Quaternion quat)
{
transform.setRotation(quat);
}
void Transform::setRotation(Quaternion quat) { transform.setRotation(quat); }
void Transform::setScale(Vector scale)
{
transform.setScale(scale);
}
void Transform::translate(Vector direction)
{
transform.setPosition(transform.getPosition() + direction);
}
void Transform::rotate(Quaternion quat)
{
transform.setRotation(transform.getRotation() * quat);
}
void Transform::scale(Vector scale)
{
transform.setScale(transform.getScale() + scale);
}
void Transform::setScale(Vector scale) { transform.setScale(scale); }
void Transform::translate(Vector direction) { transform.setPosition(transform.getPosition() + direction); }
void Transform::rotate(Quaternion quat) { transform.setRotation(transform.getRotation() * quat); }
void Transform::scale(Vector scale) { transform.setScale(transform.getScale() + scale); }
+7 -8
View File
@@ -1,13 +1,11 @@
#pragma once
#include "Math/Transform.h"
#include "Component.h"
#include "Math/Transform.h"
namespace Seele
{
namespace Component
{
struct Transform
{
namespace Seele {
namespace Component {
struct Transform {
Vector getPosition() const { return transform.getPosition(); }
Quaternion getRotation() const { return transform.getRotation(); }
Vector getScale() const { return transform.getScale(); }
@@ -24,7 +22,8 @@ struct Transform
void translate(Vector direction);
void rotate(Quaternion quat);
void scale(Vector scale);
private:
private:
Math::Transform transform;
};
DECLARE_COMPONENT(Transform)