This commit is contained in:
2026-04-12 21:40:13 +02:00
parent 9e283c1b54
commit 2e441f33ab
7 changed files with 107 additions and 18 deletions
+2
View File
@@ -3,3 +3,5 @@ target_sources(FluidSimulation
FluidSimulationGame.cpp
FluidSimulationGame.h
)
add_subdirectory(System/)
+20 -17
View File
@@ -1,8 +1,11 @@
#include "FluidSimulationGame.h"
#include "Actor/CameraActor.h"
#include "Actor/DirectionalLightActor.h"
#include "Actor/PointLightActor.h"
#include "Actor/StaticMeshActor.h"
#include "Asset/AssetRegistry.h"
#include "Component/KeyboardInput.h"
#include "System/FlyCamSystem.h"
using namespace Seele;
@@ -11,24 +14,24 @@ FluidSimulationGame::FluidSimulationGame() {}
FluidSimulationGame::~FluidSimulationGame() {}
void FluidSimulationGame::setupScene(Seele::PScene scene, Seele::PSystemGraph graph) {
mesh = new StaticMeshActor(scene, AssetRegistry::findMesh("rttest", "rttest"));
sun = new DirectionalLightActor(scene, Vector(1, -1, 1), 1, Vector(1, 1, 1));
pointLight = new PointLightActor(scene, Vector(0, 1, 0), 1, Vector(1, 1, 1), 10);
graph->addSystem(new FlyCamSystem(scene));
mesh = new StaticMeshActor(scene, AssetRegistry::findMesh("rttest", "rttest"));
sun = new DirectionalLightActor(scene, Vector(1, -1, 1), 1, Vector(1, 1, 1));
pointLight = new PointLightActor(scene, Vector(0, 1, 0), 1, Vector(1, 1, 1), 10);
cam = new CameraActor(scene);
cam->attachComponent<Component::KeyboardInput>();
cam->getCameraComponent().mainCamera = true;
Seele::Component::Transform transform;
Seele::Component::FluidGrid grid;
grid.cellSize = 0.1f;
grid.viscosity = 0.001f;
grid.diffusion = 0.0001f;
grid.gridSize = {64, 64, 64};
transform.transform.setPosition({0.0f, 0.0f, 0.0f});
scene->getFluidScene()->updateFluidData(0, transform, grid);
Seele::Component::Transform transform;
Seele::Component::FluidGrid grid;
grid.cellSize = 0.1f;
grid.viscosity = 0.001f;
grid.diffusion = 0.0001f;
grid.gridSize = {16, 16, 16};
transform.transform.setPosition({0.0f, 0.0f, 0.0f});
scene->getFluidScene()->updateFluidData(0, transform, grid);
}
extern "C" FluidSimulationGame* createInstance() {
return new FluidSimulationGame();
}
extern "C" FluidSimulationGame *createInstance() { return new FluidSimulationGame(); }
extern "C" void destroyInstance(FluidSimulationGame* game) {
delete game;
}
extern "C" void destroyInstance(FluidSimulationGame *game) { delete game; }
+2
View File
@@ -3,6 +3,7 @@
#include "Actor/PointLightActor.h"
#include "Actor/StaticMeshActor.h"
#include "Game.h"
#include "Graphics/RenderPass/BasePass.h"
class FluidSimulationGame : public Seele::Game {
public:
@@ -13,6 +14,7 @@ private:
Seele::OStaticMeshActor mesh;
Seele::ODirectionalLightActor sun;
Seele::OPointLightActor pointLight;
Seele::OCameraActor cam;
};
extern "C" FluidSimulationGame* createInstance();
+5
View File
@@ -0,0 +1,5 @@
target_sources(FluidSimulation
PUBLIC
FlyCamSystem.h
FlyCamSystem.cpp
)
+54
View File
@@ -0,0 +1,54 @@
#include "FlyCamSystem.h"
#include <iostream>
FlyCamSystem::FlyCamSystem(PScene scene)
: System::ComponentSystem<Component::KeyboardInput, Component::Camera, Component::Transform>(scene) {}
FlyCamSystem::~FlyCamSystem() {}
void FlyCamSystem::update(Component::KeyboardInput& input, Component::Camera& camera, Component::Transform& transform) {
float cameraMove = static_cast<float>(deltaTime) * 4;
if(input.keys[KeyCode::KEY_LEFT_SHIFT])
{
cameraMove *= 10;
}
Vector forward = transform.getForward();
Vector side = transform.getRight();
Vector moveVector = Vector();
if (input.keys[KeyCode::KEY_J])
{
std::cout << transform.getPosition() << std::endl;
}
if(input.keys[KeyCode::KEY_W])
{
moveVector += forward * cameraMove;
}
if(input.keys[KeyCode::KEY_S])
{
moveVector += forward * -cameraMove;
}
if(input.keys[KeyCode::KEY_A])
{
moveVector += side * cameraMove;
}
if(input.keys[KeyCode::KEY_D])
{
moveVector += side * -cameraMove;
}
if(input.keys[KeyCode::KEY_E])
{
moveVector += Vector(0, cameraMove, 0);
}
if(input.keys[KeyCode::KEY_Q])
{
moveVector += Vector(0, -cameraMove, 0);
}
transform.translate(moveVector);
if(input.mouse2)
{
transform.setRotation(glm::rotate(transform.getRotation(), input.deltaX / 500, Vector(0, 1, 0)));
transform.setRotation(glm::rotate(transform.getRotation(), -input.deltaY / 500, transform.getRight()));
}
}
+23
View File
@@ -0,0 +1,23 @@
#pragma once
#include <MinimalEngine.h>
#include <Scene/Scene.h>
#include <System/ComponentSystem.h>
#include <Component/Camera.h>
#include <Component/KeyboardInput.h>
using namespace Seele;
class FlyCamSystem : public System::ComponentSystem<
Component::KeyboardInput,
Component::Camera,
Component::Transform>
{
public:
FlyCamSystem(PScene scene);
virtual ~FlyCamSystem();
virtual void update(Component::KeyboardInput& input, Component::Camera& camera, Component::Transform& transform) override;
private:
float lastMouseX;
float lastMouseY;
};
DEFINE_REF(FlyCamSystem)