WE BE RENDERING BABY

This commit is contained in:
2026-01-07 03:04:20 +01:00
parent c83c423b42
commit e306c5e23f
13 changed files with 377 additions and 37 deletions

View File

@@ -9,6 +9,7 @@
#include <destrum/Graphics/GfxDevice.h>
#include <destrum/Graphics/Renderer.h>
#include <destrum/Input/InputManager.h>
class App {
@@ -41,6 +42,8 @@ protected:
MeshCache meshCache;
InputManager inputManager;
bool isRunning{false};
bool gamePaused{false};

View File

@@ -118,6 +118,12 @@ public:
void SetMovementSpeed(float speed) { m_movementSpeed = speed; }
[[nodiscard]] float GetMovementSpeed() const { return m_movementSpeed; }
void SetRotation(float yawRadians, float pitchRadians);
void SetRotation(const glm::vec2& yawPitchRadians);
float GetYaw() const { return m_yaw; }
float GetPitch() const { return m_pitch; }
private:
float fovAngle{90.f};
float fov{tanf(glm::radians(fovAngle) / 2.f)};
@@ -153,6 +159,9 @@ private:
Frustum m_frustum{};
float m_movementSpeed{2.0f};
float m_yaw = 0.0f; // radians
float m_pitch = 0.0f; // radians
};
#endif //VCAMERA_H

View File

@@ -33,7 +33,11 @@ public:
void cleanup();
void drawMesh(MeshID id, const glm::mat4& transform, MaterialId materialId);
const GPUImage& getDrawImage(const GfxDevice& gfx_device) const;
void resize(GfxDevice& gfxDevice, const glm::ivec2& newSize) {
createDrawImage(gfxDevice, newSize, false);
}
private:
void createDrawImage(GfxDevice& gfxDevice, const glm::ivec2& drawImageSize, bool firstCreate);

View File

@@ -0,0 +1,92 @@
#ifndef INPUTMANAGER_H
#define INPUTMANAGER_H
#include <SDL.h>
#include <unordered_map>
#include <unordered_set>
#include <string>
#include <vector>
class InputManager {
public:
// Call once at startup (optional, but convenient)
void Init();
// Call at the start of every frame
void BeginFrame();
// Feed SDL events into this (call for each SDL_PollEvent)
void ProcessEvent(const SDL_Event& e);
// Call at end of frame if you want (not required)
void EndFrame() {}
// ---- Queries ----
bool IsKeyDown(SDL_Scancode sc) const; // held
bool WasKeyPressed(SDL_Scancode sc) const; // pressed this frame
bool WasKeyReleased(SDL_Scancode sc) const; // released this frame
bool IsMouseDown(Uint8 button) const; // held (SDL_BUTTON_LEFT etc.)
bool WasMousePressed(Uint8 button) const; // pressed this frame
bool WasMouseReleased(Uint8 button) const; // released this frame
// Mouse position (window space)
int MouseX() const { return m_mouseX; }
int MouseY() const { return m_mouseY; }
int MouseDeltaX() const { return m_mouseDX; }
int MouseDeltaY() const { return m_mouseDY; }
// Mouse wheel (accumulated per frame)
int WheelX() const { return m_wheelX; }
int WheelY() const { return m_wheelY; }
// ---- Text input ----
void StartTextInput();
void StopTextInput();
bool IsTextInputActive() const { return m_textInputActive; }
const std::string& GetTextInput() const { return m_textInput; } // captured this frame
// ---- Action mapping ----
enum class Device { Keyboard, MouseButton, MouseWheel };
enum class ButtonState { Down, Pressed, Released };
struct Binding {
Device device;
int code; // SDL_Scancode for keyboard, Uint8 for mouse button, wheel axis sign encoding
// For MouseWheel: code = +1/-1 for Y, +2/-2 for X (simple encoding)
};
void BindAction(const std::string& action, const Binding& binding);
bool GetAction(const std::string& action, ButtonState state) const;
private:
// Key states
std::unordered_set<SDL_Scancode> m_keysDown;
std::unordered_set<SDL_Scancode> m_keysPressed;
std::unordered_set<SDL_Scancode> m_keysReleased;
// Mouse button states
std::unordered_set<Uint8> m_mouseDown;
std::unordered_set<Uint8> m_mousePressed;
std::unordered_set<Uint8> m_mouseReleased;
// Mouse position + delta
int m_mouseX = 0, m_mouseY = 0;
int m_prevMouseX = 0, m_prevMouseY = 0;
int m_mouseDX = 0, m_mouseDY = 0;
// Wheel (per-frame)
int m_wheelX = 0, m_wheelY = 0;
// Text input (per-frame)
bool m_textInputActive = false;
std::string m_textInput;
// Action bindings
std::unordered_map<std::string, std::vector<Binding>> m_bindings;
private:
bool QueryBinding(const Binding& b, ButtonState state) const;
};
#endif //INPUTMANAGER_H