Input manager, camera zoom
This commit is contained in:
parent
83f947ce1f
commit
49affdcc38
Binary file not shown.
23
engine-api/include/ee_engine_api/InputInterface.hpp
Normal file
23
engine-api/include/ee_engine_api/InputInterface.hpp
Normal file
@ -0,0 +1,23 @@
|
||||
#pragma once
|
||||
#include <functional>
|
||||
|
||||
namespace ee_engine
|
||||
{
|
||||
struct InputHandlers
|
||||
{
|
||||
std::function<void(float dx, float dy)> zooming;
|
||||
std::function<void(float dx, float dy)> mapScroll;
|
||||
};
|
||||
|
||||
class IInput
|
||||
{
|
||||
public:
|
||||
virtual ~IInput() {};
|
||||
virtual void Poll() = 0;
|
||||
|
||||
protected:
|
||||
InputHandlers handlers;
|
||||
|
||||
explicit IInput(const InputHandlers &handlers) {this->handlers = handlers;};
|
||||
};
|
||||
}
|
||||
@ -39,6 +39,8 @@ namespace ee_engine
|
||||
virtual void ResizeWindow(int width, int height);
|
||||
void SetCamera(const CameraTransform &camera);
|
||||
|
||||
CameraTransform getCamera();
|
||||
|
||||
protected:
|
||||
int screenWidth, screenHeight;
|
||||
float screenAspect;
|
||||
|
||||
@ -66,3 +66,5 @@ void ee_engine::IRenderer::SetCamera(const CameraTransform &camera)
|
||||
|
||||
ApplyCamera();
|
||||
}
|
||||
|
||||
ee_engine::CameraTransform ee_engine::IRenderer::getCamera() {return this->camera;}
|
||||
14
engine/include/Actions.hpp
Normal file
14
engine/include/Actions.hpp
Normal file
@ -0,0 +1,14 @@
|
||||
#pragma once
|
||||
#include <ee_engine_api/InputInterface.hpp>
|
||||
|
||||
class Actions
|
||||
{
|
||||
public:
|
||||
static ee_engine::InputHandlers mappings;
|
||||
|
||||
private:
|
||||
static void Zoom(float dx, float dy);
|
||||
static void MapScroll(float dx, float dy);
|
||||
|
||||
Actions();
|
||||
};
|
||||
@ -1,12 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
#include <GLFW/glfw3.h>
|
||||
#include <ee_engine_api/RenderInterface.hpp>
|
||||
|
||||
#include <ee_engine_api/InputInterface.hpp>
|
||||
#include "AssetManager.hpp"
|
||||
|
||||
class Engine
|
||||
{
|
||||
public:
|
||||
static GLFWwindow *window;
|
||||
static ee_engine::IInput *input;
|
||||
static AssetManager *assetManager;
|
||||
static ee_engine::IRenderer *renderer;
|
||||
|
||||
|
||||
10
engine/include/GLFWInput.hpp
Normal file
10
engine/include/GLFWInput.hpp
Normal file
@ -0,0 +1,10 @@
|
||||
#pragma once
|
||||
#include <ee_engine_api/InputInterface.hpp>
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
class GLFWInput : public ee_engine::IInput
|
||||
{
|
||||
public:
|
||||
GLFWInput(ee_engine::InputHandlers handlers);
|
||||
void Poll() override;
|
||||
};
|
||||
20
engine/src/Actions.cpp
Normal file
20
engine/src/Actions.cpp
Normal file
@ -0,0 +1,20 @@
|
||||
#include "Actions.hpp"
|
||||
#include "Engine.hpp"
|
||||
#include <cmath>
|
||||
|
||||
ee_engine::InputHandlers Actions::mappings {
|
||||
.zooming = Zoom,
|
||||
.mapScroll = MapScroll
|
||||
};
|
||||
|
||||
void Actions::Zoom(float dx, float dy)
|
||||
{
|
||||
ee_engine::CameraTransform cam = Engine::renderer->getCamera();
|
||||
cam.zoom *= pow(1.1f, -dy);
|
||||
Engine::renderer->SetCamera(cam);
|
||||
}
|
||||
|
||||
void Actions::MapScroll(float dx, float dy)
|
||||
{
|
||||
|
||||
}
|
||||
@ -1,11 +1,17 @@
|
||||
#include "Engine.hpp"
|
||||
#include <ee_utils/allocator.hpp>
|
||||
|
||||
GLFWwindow* Engine::window;
|
||||
|
||||
ee_engine::IInput* Engine::input;
|
||||
AssetManager* Engine::assetManager;
|
||||
ee_engine::IRenderer* Engine::renderer;
|
||||
|
||||
void Engine::Shutdown()
|
||||
{
|
||||
if (input != nullptr)
|
||||
Deallocate(input);
|
||||
|
||||
if (renderer != nullptr)
|
||||
{
|
||||
renderer->Shutdown();
|
||||
@ -13,13 +19,14 @@ void Engine::Shutdown()
|
||||
}
|
||||
renderer = nullptr;
|
||||
|
||||
if (Engine::assetManager != nullptr)
|
||||
{ // Wait for asset manager to clean and shutdown
|
||||
Engine::assetManager->Shutdown();
|
||||
while(Engine::assetManager->isRunning.load());
|
||||
}
|
||||
|
||||
if (assetManager != nullptr)
|
||||
{ // Wait for asset manager to clean and shutdown
|
||||
assetManager->Shutdown();
|
||||
while(assetManager->isRunning.load()) {}
|
||||
Deallocate(assetManager);
|
||||
}
|
||||
assetManager = nullptr;
|
||||
|
||||
glfwDestroyWindow(window);
|
||||
glfwTerminate();
|
||||
}
|
||||
20
engine/src/GLFWInput.cpp
Normal file
20
engine/src/GLFWInput.cpp
Normal file
@ -0,0 +1,20 @@
|
||||
#include "GLFWInput.hpp"
|
||||
#include "Engine.hpp"
|
||||
#include "Logger.h"
|
||||
|
||||
GLFWInput::GLFWInput(ee_engine::InputHandlers handlers) : ee_engine::IInput(handlers)
|
||||
{
|
||||
glfwSetWindowUserPointer(Engine::window, this);
|
||||
|
||||
glfwSetScrollCallback(Engine::window, [](GLFWwindow *window, double dx, double dy) {
|
||||
reinterpret_cast<GLFWInput*>(glfwGetWindowUserPointer(window))->
|
||||
handlers.zooming(static_cast<float>(dx), static_cast<float>(dy));
|
||||
});
|
||||
|
||||
LOG(INFO, "Input mappings initialized");
|
||||
}
|
||||
|
||||
void GLFWInput::Poll()
|
||||
{
|
||||
|
||||
}
|
||||
@ -4,6 +4,8 @@
|
||||
#include <ee_utils/allocator.hpp>
|
||||
|
||||
#include "compile_config.hpp"
|
||||
#include "GLFWInput.hpp"
|
||||
#include "Actions.hpp"
|
||||
#include "Engine.hpp"
|
||||
|
||||
#include <GLFW/glfw3.h>
|
||||
@ -33,6 +35,7 @@ int main(int argc, char **argv)
|
||||
else LOG(INFO, "GLFW Window created");
|
||||
|
||||
glfwMakeContextCurrent(window);
|
||||
Engine::window = window;
|
||||
|
||||
// Setup Asset Manager
|
||||
Engine::assetManager = Allocate<AssetManager>();
|
||||
@ -43,6 +46,9 @@ int main(int argc, char **argv)
|
||||
// Load assets
|
||||
Engine::assetManager->LoadAsync(AssetInfo::MAP_MESH, "assets/map/states.map");
|
||||
|
||||
// Setup input manager TODO: builder
|
||||
Engine::input = Allocate<GLFWInput>(Actions::mappings);
|
||||
|
||||
// Setup renderer TODO: builder
|
||||
Engine::renderer = reinterpret_cast<ee_engine::IRenderer*>(Allocate<ee_magnum::MagnumRenderer>(window));
|
||||
|
||||
@ -61,7 +67,7 @@ int main(int argc, char **argv)
|
||||
|
||||
Engine::renderer->Init();
|
||||
Engine::renderer->SetCamera({
|
||||
.position = {1000.0f, 1000.0f},
|
||||
//.position = {1000.0f, 1000.0f},
|
||||
.zoom = 2000.0f
|
||||
});
|
||||
|
||||
@ -75,14 +81,13 @@ int main(int argc, char **argv)
|
||||
Engine::renderer->Draw();
|
||||
|
||||
glfwSwapBuffers(window);
|
||||
Engine::input->Poll();
|
||||
glfwPollEvents();
|
||||
}
|
||||
|
||||
// Free memory
|
||||
LOG(INFO, "Exit...");
|
||||
Engine::Shutdown();
|
||||
glfwDestroyWindow(window);
|
||||
glfwTerminate();
|
||||
//TODO: check Unregister in other threads and make threaded module base class
|
||||
Logger::trace->Unregister_Thread(0);
|
||||
Logger::trace->Release();
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 29 KiB |
BIN
sdk/map/_states.bmp
Normal file
BIN
sdk/map/_states.bmp
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 33 MiB |
Binary file not shown.
|
Before Width: | Height: | Size: 33 MiB After Width: | Height: | Size: 29 KiB |
Loading…
x
Reference in New Issue
Block a user