ADD: Move Camera
This commit is contained in:
parent
ef72cb56c6
commit
92e3092d3b
@ -4,6 +4,9 @@
|
|||||||
|
|
||||||
#include "CameraController.h"
|
#include "CameraController.h"
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <ostream>
|
||||||
|
|
||||||
#include "GLFW/glfw3.h"
|
#include "GLFW/glfw3.h"
|
||||||
#include "glm/vec3.hpp"
|
#include "glm/vec3.hpp"
|
||||||
#include "renderer/entities/Camera.h"
|
#include "renderer/entities/Camera.h"
|
||||||
@ -11,8 +14,9 @@
|
|||||||
void engine::CameraController::update(const Keyboard &keyboard, Camera &camera, float deltaTime) {
|
void engine::CameraController::update(const Keyboard &keyboard, Camera &camera, float deltaTime) {
|
||||||
if (!m_stack.isActive(*m_gameContext.get())) return;
|
if (!m_stack.isActive(*m_gameContext.get())) return;
|
||||||
|
|
||||||
if (keyboard.isKeyDown(GLFW_KEY_W)) camera.moveRelative(glm::vec3(0.0f, 0.0f, 1.0f), 10.0f * deltaTime, deltaTime);
|
|
||||||
if (keyboard.isKeyDown(GLFW_KEY_S)) camera.moveRelative(glm::vec3(0.0f, 0.0f, -1.0f), 10.0f * deltaTime, deltaTime);
|
if (keyboard.isKeyDown(GLFW_KEY_W)) camera.moveRelative(glm::vec3(0.0f, 0.0f, 1.0f), 10.0f, deltaTime);
|
||||||
if (keyboard.isKeyDown(GLFW_KEY_A)) camera.moveRelative(glm::vec3(-1.0f, 0.0f, 0.0f), 10.0f * deltaTime, deltaTime);
|
if (keyboard.isKeyDown(GLFW_KEY_S)) camera.moveRelative(glm::vec3(0.0f, 0.0f, -1.0f), 10.0f, deltaTime);
|
||||||
if (keyboard.isKeyDown(GLFW_KEY_D)) camera.moveRelative(glm::vec3(1.0f, 0.0f, 0.0f), 10.0f * deltaTime, deltaTime);
|
if (keyboard.isKeyDown(GLFW_KEY_A)) camera.moveRelative(glm::vec3(-1.0f, 0.0f, 0.0f), 10.0f, deltaTime);
|
||||||
|
if (keyboard.isKeyDown(GLFW_KEY_D)) camera.moveRelative(glm::vec3(1.0f, 0.0f, 0.0f), 10.0f, deltaTime);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -17,7 +17,7 @@ namespace engine {
|
|||||||
virtual ~Layer() = default;
|
virtual ~Layer() = default;
|
||||||
void onAttach(InputContextStack& inputStack);
|
void onAttach(InputContextStack& inputStack);
|
||||||
void onDetach(InputContextStack& inputStack);
|
void onDetach(InputContextStack& inputStack);
|
||||||
virtual void onUpdate() {}
|
virtual void onUpdate(float deltaTime) {}
|
||||||
virtual void onRender() {}
|
virtual void onRender() {}
|
||||||
protected:
|
protected:
|
||||||
virtual void onAttachImpl() {}
|
virtual void onAttachImpl() {}
|
||||||
|
|||||||
@ -10,9 +10,9 @@
|
|||||||
|
|
||||||
#include "core/inputsOutputs/context/InputContextStack.h"
|
#include "core/inputsOutputs/context/InputContextStack.h"
|
||||||
|
|
||||||
void engine::Scene::onUpdate() {
|
void engine::Scene::onUpdate(float deltaTime) {
|
||||||
for (const auto& layer : m_layers) {
|
for (const auto& layer : m_layers) {
|
||||||
layer->onUpdate();
|
layer->onUpdate(deltaTime);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -31,7 +31,7 @@ namespace engine {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void onUpdate();
|
void onUpdate(float deltaTime);
|
||||||
void onRender();
|
void onRender();
|
||||||
|
|
||||||
void onRegisterLoadedAsset(LoadedAsset loadedAsset);
|
void onRegisterLoadedAsset(LoadedAsset loadedAsset);
|
||||||
|
|||||||
@ -22,7 +22,7 @@ void engine::SceneManager::switchTo(std::unique_ptr<Scene> scene, std::function<
|
|||||||
assetLoader.start();
|
assetLoader.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
void engine::SceneManager::update() {
|
void engine::SceneManager::update(float deltaTime) {
|
||||||
if (nextScene) {
|
if (nextScene) {
|
||||||
auto uploadedAssets = assetLoader.processUploadQueue(2);
|
auto uploadedAssets = assetLoader.processUploadQueue(2);
|
||||||
std::cout << "Uploaded Assets: " << uploadedAssets.size() << std::endl;
|
std::cout << "Uploaded Assets: " << uploadedAssets.size() << std::endl;
|
||||||
@ -49,7 +49,7 @@ void engine::SceneManager::update() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (currentScene) {
|
if (currentScene) {
|
||||||
currentScene->onUpdate();
|
currentScene->onUpdate(deltaTime);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -16,7 +16,7 @@ namespace engine {
|
|||||||
public:
|
public:
|
||||||
explicit SceneManager(InputContextStack& inputStack) :m_inputStack(inputStack) {}
|
explicit SceneManager(InputContextStack& inputStack) :m_inputStack(inputStack) {}
|
||||||
void switchTo(std::unique_ptr<Scene> scene, std::function<void()> onSceneLoaded = nullptr);
|
void switchTo(std::unique_ptr<Scene> scene, std::function<void()> onSceneLoaded = nullptr);
|
||||||
void update();
|
void update(float deltaTime);
|
||||||
void render() const;
|
void render() const;
|
||||||
~SceneManager() = default;
|
~SceneManager() = default;
|
||||||
|
|
||||||
|
|||||||
@ -3,6 +3,9 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
#include "Camera.h"
|
#include "Camera.h"
|
||||||
|
|
||||||
|
#include <format>
|
||||||
|
#include <iostream>
|
||||||
#include <glm/gtc/matrix_transform.hpp>
|
#include <glm/gtc/matrix_transform.hpp>
|
||||||
glm::vec3 engine::Camera::getForward() const {
|
glm::vec3 engine::Camera::getForward() const {
|
||||||
// Yaw um Y-Achse, Pitch um lokale X-Achse — Standard-FPS-Konvention
|
// Yaw um Y-Achse, Pitch um lokale X-Achse — Standard-FPS-Konvention
|
||||||
@ -27,7 +30,6 @@ void engine::Camera::moveRelative(const glm::vec3 &direction, float speed, float
|
|||||||
if (worldOffset != glm::vec3(0.0f)) {
|
if (worldOffset != glm::vec3(0.0f)) {
|
||||||
worldOffset = glm::normalize(worldOffset);
|
worldOffset = glm::normalize(worldOffset);
|
||||||
}
|
}
|
||||||
|
|
||||||
m_position += worldOffset * speed * deltaTime;
|
m_position += worldOffset * speed * deltaTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -12,7 +12,7 @@
|
|||||||
|
|
||||||
|
|
||||||
void ColorRaceApp::onUpdate(float deltaTime) {
|
void ColorRaceApp::onUpdate(float deltaTime) {
|
||||||
getSceneManager().update();
|
getSceneManager().update(deltaTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ColorRaceApp::onRender() {
|
void ColorRaceApp::onRender() {
|
||||||
|
|||||||
@ -26,8 +26,8 @@ void GameLayer::onDetachImpl() {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameLayer::onUpdate() {
|
void GameLayer::onUpdate(float deltaTime) {
|
||||||
Layer::onUpdate();
|
Layer::onUpdate(deltaTime);
|
||||||
|
|
||||||
auto transformComponentPool = m_entityRegistry.getPool<TransformComponent>();
|
auto transformComponentPool = m_entityRegistry.getPool<TransformComponent>();
|
||||||
for (const auto& [entity, transform] : transformComponentPool) {
|
for (const auto& [entity, transform] : transformComponentPool) {
|
||||||
@ -37,7 +37,7 @@ void GameLayer::onUpdate() {
|
|||||||
m_entityRegistry.addComponent<TransformComponent>(entity, updatedTransform);
|
m_entityRegistry.addComponent<TransformComponent>(entity, updatedTransform);
|
||||||
}
|
}
|
||||||
|
|
||||||
m_cameraController->update(getKeyboard(), *m_camera, 1);
|
m_cameraController->update(getKeyboard(), *m_camera, deltaTime);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -20,7 +20,7 @@ public:
|
|||||||
engine::Keyboard& keyboard, engine::Mouse& mouse)
|
engine::Keyboard& keyboard, engine::Mouse& mouse)
|
||||||
: Layer(keyboard, mouse), m_entityRegistry(entityRegistry), m_camera(std::move(cam)), m_renderer(std::make_unique<engine::MeshRenderer>()), m_pointLight(std::move(light)){}
|
: Layer(keyboard, mouse), m_entityRegistry(entityRegistry), m_camera(std::move(cam)), m_renderer(std::make_unique<engine::MeshRenderer>()), m_pointLight(std::move(light)){}
|
||||||
|
|
||||||
void onUpdate() override;
|
void onUpdate(float deltaTime) override;
|
||||||
void onRender() override;
|
void onRender() override;
|
||||||
protected:
|
protected:
|
||||||
void onAttachImpl() override;
|
void onAttachImpl() override;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user