Compare commits

...

3 Commits

Author SHA1 Message Date
OusmBlueNinja
95b15827d6 Fixed Stupid Compilation errors. 2025-01-06 13:52:46 -06:00
OusmBlueNinja
24a5a4fbbe Updated Input Handler 2025-01-06 12:43:18 -06:00
OusmBlueNinja
a428ba3a0e Added release Build Options 2025-01-05 18:41:30 -06:00
10 changed files with 370 additions and 120 deletions

102
Makefile
View File

@ -1,31 +1,49 @@
# ------------------------------------------------------------------------------
# ---------------------------------------------------------------------------
# Compiler and Base Flags
# ------------------------------------------------------------------------------
# ---------------------------------------------------------------------------
CXX := g++
CXXFLAGS := -Wall -Wextra -std=c++17 -g -DDEBUG -DTIMERS
# ------------------------------------------------------------------------------
# Common flags (for both Debug and Release)
CXXFLAGS_BASE := -Wall -Wextra -std=c++17
# Debug flags (includes TIMERS and DEBUG, plus -g)
CXXFLAGS_DEBUG := $(CXXFLAGS_BASE) -g -DDEBUG -DTIMERS
# Release flags (optimized, no debug macros, no timers)
CXXFLAGS_RELEASE := $(CXXFLAGS_BASE) -O2 -DNDEBUG
# By default, we build in Debug mode:
BUILD_TYPE ?= debug
# Well dynamically set BUILD_DIR and CXXFLAGS based on BUILD_TYPE
ifeq ($(BUILD_TYPE),debug)
BUILD_DIR := build
CXXFLAGS := $(CXXFLAGS_DEBUG)
else ifeq ($(BUILD_TYPE),release)
BUILD_DIR := release
CXXFLAGS := $(CXXFLAGS_RELEASE)
else
$(error Unknown BUILD_TYPE '$(BUILD_TYPE)'. Valid options: debug or release)
endif
# ---------------------------------------------------------------------------
# Detect Platform
# ------------------------------------------------------------------------------
# ---------------------------------------------------------------------------
ifeq ($(OS),Windows_NT)
# -------------------- Windows --------------------
EXE_EXT := .exe
# Example paths (adjust if you have your libs somewhere else):
# Include directories for GLFW, GLEW, etc.
GLFW_INCLUDE := C:/libs/glfw/include
GLEW_INCLUDE := C:/libs/glew/include
# Library search paths
LIB_PATHS := -LC:/libs/glfw/lib \
-LC:/libs/glew/lib \
-Llib
# Libraries to link against (adjust if needed)
LIBS := -lglfw3 -lopengl32 -lgdi32 -limm32 -lole32 -loleaut32 -luuid \
-lwinmm -lglew32 -lglu32 -lyaml-cpp -llua54
# A Windows-compatible "mkdir" command:
define MKDIR_P
if not exist "$(1)" mkdir "$(1)" >nul 2>&1
endef
@ -34,34 +52,29 @@ else
# -------------------- Linux (or other Unix-likes) --------------------
EXE_EXT :=
# If libs are installed system-wide, you usually only need -lGL, -lGLEW, etc.
# But you can still point to custom paths if needed:
GLFW_INCLUDE := /usr/include
GLEW_INCLUDE := /usr/include
# Library search paths (often not needed if system-wide)
LIB_PATHS :=
# Libraries on Linux
LIBS := -lglfw -lGL -lGLEW -lGLU -lyaml-cpp -llua
# A Linux-compatible "mkdir -p" command:
define MKDIR_P
mkdir -p "$(1)"
endef
endif
# ------------------------------------------------------------------------------
# ---------------------------------------------------------------------------
# Directories
# ------------------------------------------------------------------------------
# ---------------------------------------------------------------------------
SRC_DIR := src
VENDOR_DIRS := vendor/imgui-docking vendor/stb vendor/ImGuizmo
BUILD_DIR := build
# BUILD_DIR is determined by $(BUILD_TYPE) above: either `build` or `release`
# ------------------------------------------------------------------------------
# ---------------------------------------------------------------------------
# Include Directories
# ------------------------------------------------------------------------------
# ---------------------------------------------------------------------------
INCLUDE_DIRS := \
$(SRC_DIR) \
$(VENDOR_DIRS) \
@ -72,12 +85,11 @@ INCLUDE_DIRS := \
vendor/ImGuizmo \
vendor/gcml
# Add them to compiler flags:
CXXFLAGS += $(foreach inc,$(INCLUDE_DIRS),-I$(inc))
# ------------------------------------------------------------------------------
# ---------------------------------------------------------------------------
# Source Files
# ------------------------------------------------------------------------------
# ---------------------------------------------------------------------------
SRC_FILES := $(wildcard $(SRC_DIR)/*.cpp) \
$(wildcard $(SRC_DIR)/**/*.cpp)
@ -85,43 +97,51 @@ VENDOR_SRC := $(foreach dir, $(VENDOR_DIRS), $(wildcard $(dir)/*.cpp))
STB_SRC := $(wildcard vendor/stb/src/*.cpp) # If stb has .cpp files
ALL_SRC := $(SRC_FILES) $(VENDOR_SRC) $(STB_SRC)
# ------------------------------------------------------------------------------
# ---------------------------------------------------------------------------
# Object Files
# ------------------------------------------------------------------------------
OBJ_FILES := $(patsubst %.cpp, $(BUILD_DIR)/%.o, $(ALL_SRC))
# ---------------------------------------------------------------------------
OBJ_FILES := $(patsubst %.cpp,$(BUILD_DIR)/%.o,$(ALL_SRC))
# ------------------------------------------------------------------------------
# Target
# ------------------------------------------------------------------------------
TARGET := TesseractEngine$(EXE_EXT)
# ---------------------------------------------------------------------------
# Target (goes into the same directory as object files)
# ---------------------------------------------------------------------------
TARGET := $(BUILD_DIR)/TesseractEngine$(EXE_EXT)
# ------------------------------------------------------------------------------
# ---------------------------------------------------------------------------
# Phony Targets
# ------------------------------------------------------------------------------
.PHONY: all clean
# ---------------------------------------------------------------------------
.PHONY: all clean debug release
# Default target
# Default target uses whatever BUILD_TYPE is (default = debug)
all: $(TARGET)
# ------------------------------------------------------------------------------
## "debug" target => override BUILD_TYPE
debug:
@$(MAKE) BUILD_TYPE=debug all
## "release" target => override BUILD_TYPE
release:
@$(MAKE) BUILD_TYPE=release all
# ---------------------------------------------------------------------------
# Link all object files to create the executable
# ------------------------------------------------------------------------------
# ---------------------------------------------------------------------------
$(TARGET): $(OBJ_FILES)
@echo Linking $@...
$(CXX) $(CXXFLAGS) -o $@ $^ $(LIB_PATHS) $(LIBS)
# ------------------------------------------------------------------------------
# ---------------------------------------------------------------------------
# Pattern rule to compile .cpp files to .o files
# ------------------------------------------------------------------------------
# ---------------------------------------------------------------------------
$(BUILD_DIR)/%.o: %.cpp
@$(call MKDIR_P,$(dir $@))
@echo Compiling $<...
$(CXX) $(CXXFLAGS) -c $< -o $@
# ------------------------------------------------------------------------------
# ---------------------------------------------------------------------------
# Clean build artifacts
# ------------------------------------------------------------------------------
# ---------------------------------------------------------------------------
clean:
@echo Cleaning up...
rm -rf "$(BUILD_DIR)"
rm -f "$(TARGET)"
rm -rf build
rm -rf release

View File

@ -4,7 +4,7 @@ Size=1280,720
Collapsed=0
[Window][Debug##Default]
ViewportPos=926,1030
ViewportPos=1168,966
ViewportId=0x16723995
Size=400,400
Collapsed=0
@ -181,7 +181,7 @@ Column 0 Width=30
Column 1 Weight=1.0000
[Docking][Data]
DockSpace ID=0x14621557 Window=0x3DA2F1DE Pos=146,189 Size=1264,684 Split=X Selected=0xF7365A5A
DockSpace ID=0x14621557 Window=0x3DA2F1DE Pos=250,293 Size=1264,684 Split=X Selected=0xF7365A5A
DockNode ID=0x00000020 Parent=0x14621557 SizeRef=884,684 Split=X
DockNode ID=0x00000013 Parent=0x00000020 SizeRef=335,1142 Split=Y Selected=0x818D04BB
DockNode ID=0x0000001B Parent=0x00000013 SizeRef=264,551 HiddenTabBar=1 Selected=0x1D5D92B6

View File

@ -32,6 +32,32 @@ void TransformComponent::Update(float _deltaTime)
return;
}
void TransformComponent::LookAt(const glm::vec3& target, const glm::vec3& up) {
// Calculate the direction vector from position to target
glm::vec3 direction = glm::normalize(target - position);
// Handle the case when direction is parallel to up vector
if (glm::length(direction) == 0.0f) {
// Cannot look at the same position; no rotation needed
return;
}
// Create a lookAt matrix
glm::mat4 lookAtMatrix = glm::lookAt(position, target, up);
// Extract the rotation part of the matrix
glm::mat4 rotationMatrix = glm::mat4(glm::mat3(lookAtMatrix));
// Convert the rotation matrix to a quaternion
glm::quat rotationQuat = glm::quat_cast(rotationMatrix);
// Extract Euler angles from the quaternion
glm::vec3 eulerRadians = glm::eulerAngles(rotationQuat);
// Convert radians to degrees and set the rotation
rotation = glm::degrees(eulerRadians);
}
// New Methods
glm::mat4 TransformComponent::GetTransformMatrix() const
{

View File

@ -1,10 +1,18 @@
// Transform.h
#pragma once
#define GLM_ENABLE_EXPERIMENTAL
#include "Component.h"
#include <glm/glm.hpp>
#include <yaml-cpp/yaml.h>
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp> // For glm::lookAt
#include <glm/gtc/quaternion.hpp> // For glm::quat
#include <glm/gtx/quaternion.hpp> // For glm::quat_cast
#include <glm/gtc/constants.hpp> // For glm::pi
#include <glm/gtc/matrix_access.hpp> // For glm::eulerAngles
class TransformComponent : public Component
{
public:
@ -32,6 +40,14 @@ public:
rotation = {x, y, z};
}
/**
* @brief Orients the transform to face the target position.
*
* @param target The target position to look at.
* @param up The up vector to use for orientation.
*/
void LookAt(const glm::vec3& target, const glm::vec3& up);
TransformComponent();
virtual const std::string &GetName() const override;
static const std::string &GetStaticName();
@ -44,7 +60,6 @@ public:
glm::mat4 GetTransformMatrix() const;
void SetTransformMatrix(const glm::mat4& transform);
private:
static const std::string name;
};

View File

@ -304,7 +304,7 @@ void MyEngine::Run()
{
ScopedTimer timer("RenderGame");
m_RenderWindow->Show(&m_GameRunning); // The spinning triangle as ImGui::Image
m_RenderWindow->Show(&m_GameRunning, m_Ms); // The spinning triangle as ImGui::Image
}
{
ScopedTimer timer("ShowEditor");

View File

@ -1,29 +1,92 @@
// InputManager.cpp
#include "InputManager.h"
#include <GLFW/glfw3.h>
#include <algorithm> // For std::clamp
void InputManager::Update(GLFWwindow* window)
// Constructor
InputManager::InputManager()
: m_MouseDeltaX(0.0f), m_MouseDeltaY(0.0f), m_ScrollDelta(0.0f)
{
if (!window)
{
Initialize();
}
// Initialize method to set up state vectors
void InputManager::Initialize() {
// Initialize key states
m_KeyStates.resize(GLFW_KEY_LAST + 1, false);
m_PreviousKeyStates.resize(GLFW_KEY_LAST + 1, false);
// Initialize mouse button states
m_MouseButtonStates.resize(GLFW_MOUSE_BUTTON_LAST + 1, false);
m_PreviousMouseButtonStates.resize(GLFW_MOUSE_BUTTON_LAST + 1, false);
}
// Update method to poll input states
void InputManager::Update(GLFWwindow* window) {
if (!window) {
return;
}
// Update the state of each key
for (int key = 0; key <= GLFW_KEY_LAST; ++key)
{
// Update previous key states
m_PreviousKeyStates = m_KeyStates;
// Update current key states
for (int key = 0; key <= GLFW_KEY_LAST; ++key) {
m_KeyStates[key] = glfwGetKey(window, key) == GLFW_PRESS;
}
// Update previous mouse button states
m_PreviousMouseButtonStates = m_MouseButtonStates;
// Update current mouse button states
for (int button = 0; button <= GLFW_MOUSE_BUTTON_LAST; ++button) {
m_MouseButtonStates[button] = glfwGetMouseButton(window, button) == GLFW_PRESS;
}
// Reset mouse deltas and scroll delta for this frame
m_MouseDeltaX = 0.0f;
m_MouseDeltaY = 0.0f;
m_ScrollDelta = 0.0f;
}
bool InputManager::IsKeyPressed(KeyCode key) const
{
// Keyboard input query
bool InputManager::IsKeyPressed(KeyCode key) const {
int keyInt = static_cast<int>(key);
if (keyInt >= 0 && keyInt <= GLFW_KEY_LAST)
{
if (keyInt >= 0 && keyInt <= GLFW_KEY_LAST) {
return m_KeyStates[keyInt];
}
return false;
}
// Mouse button input query
bool InputManager::IsMouseButtonPressed(MouseButton button) const {
int buttonInt = static_cast<int>(button);
if (buttonInt >= 0 && buttonInt <= GLFW_MOUSE_BUTTON_LAST) {
return m_MouseButtonStates[buttonInt];
}
return false;
}
// Mouse button just pressed (edge detection)
bool InputManager::IsMouseButtonJustPressed(MouseButton button) const {
int buttonInt = static_cast<int>(button);
if (buttonInt >= 0 && buttonInt <= GLFW_MOUSE_BUTTON_LAST) {
return m_MouseButtonStates[buttonInt] && !m_PreviousMouseButtonStates[buttonInt];
}
return false;
}
// Mouse button just released (edge detection)
bool InputManager::IsMouseButtonJustReleased(MouseButton button) const {
int buttonInt = static_cast<int>(button);
if (buttonInt >= 0 && buttonInt <= GLFW_MOUSE_BUTTON_LAST) {
return !m_MouseButtonStates[buttonInt] && m_PreviousMouseButtonStates[buttonInt];
}
return false;
}
// Reset deltas after handling input
void InputManager::ResetDeltas() {
m_MouseDeltaX = 0.0f;
m_MouseDeltaY = 0.0f;
m_ScrollDelta = 0.0f;
}

View File

@ -3,18 +3,50 @@
#include "KeyCode.h"
#include <GLFW/glfw3.h>
#include <vector>
class InputManager
{
class InputManager {
public:
// Update key states (to be called every frame)
// Constructor
InputManager();
// Update method to poll input states
void Update(GLFWwindow* window);
// Check if a key is pressed
// Keyboard input query
bool IsKeyPressed(KeyCode key) const;
// Mouse button input queries
bool IsMouseButtonPressed(MouseButton button) const;
bool IsMouseButtonJustPressed(MouseButton button) const;
bool IsMouseButtonJustReleased(MouseButton button) const;
// Mouse movement deltas
float GetMouseDeltaX() const { return m_MouseDeltaX; }
float GetMouseDeltaY() const { return m_MouseDeltaY; }
// Scroll delta
float GetScrollDelta() const { return m_ScrollDelta; }
// Call this after handling input to reset deltas
void ResetDeltas();
private:
// Array or map storing key states
bool m_KeyStates[GLFW_KEY_LAST + 1] = { false };
// Storage for key states
std::vector<bool> m_KeyStates;
std::vector<bool> m_PreviousKeyStates;
// Storage for mouse button states
std::vector<bool> m_MouseButtonStates;
std::vector<bool> m_PreviousMouseButtonStates;
// Mouse movement deltas
float m_MouseDeltaX;
float m_MouseDeltaY;
// Scroll delta
float m_ScrollDelta;
// Initialization helper
void Initialize();
};

View File

@ -126,3 +126,16 @@ enum class KeyCode
RightSuper = GLFW_KEY_RIGHT_SUPER,
Menu = GLFW_KEY_MENU
};
// Enum for mouse buttons
enum class MouseButton {
LEFT = GLFW_MOUSE_BUTTON_LEFT,
RIGHT = GLFW_MOUSE_BUTTON_RIGHT,
MIDDLE = GLFW_MOUSE_BUTTON_MIDDLE,
BUTTON4 = GLFW_MOUSE_BUTTON_4,
BUTTON5 = GLFW_MOUSE_BUTTON_5,
BUTTON6 = GLFW_MOUSE_BUTTON_6,
BUTTON7 = GLFW_MOUSE_BUTTON_7,
BUTTON8 = GLFW_MOUSE_BUTTON_8,
LAST = GLFW_MOUSE_BUTTON_LAST
};

View File

@ -1,30 +1,51 @@
#include "RenderWindow.h"
#include "imgui.h"
#include <GL/glew.h>
#include <vector>
#include <GL/glew.h>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtc/type_ptr.hpp>
#include "Components/GameObject.h"
#include "Components/mesh.h"
#include "Components/transform.h"
#include "Components/CameraComponent.h"
#include "Engine/AssetManager.h"
#include "Engine/Settings.h"
#include "Engine/InputManager.h"
#include "Engine/KeyCode.h"
#include "Rendering/Shader.h"
#include "ImGuizmo.h"
#include "gcml.h"
#include "Icons.h"
#include "imgui.h"
#define CAM_FOV 45.0f
#define CAM_NEAR_PLAIN 0.1f
#define CAM_FAR_PLAIN 2048.0f
float editorYaw = -90.0f; // Horizontal angle, initialized to face along negative Z-axis
float editorPitch = 0.0f; // Vertical angle
float editorDistance = 5.0f; // Distance from the target
glm::vec3 editorTarget(0.0f, 0.0f, 0.0f); // The point the camera orbits around
// Configuration Parameters
const float rotationSpeed = 0.1f; // Sensitivity for mouse rotation
const float zoomSpeed = 2.0f; // Sensitivity for zooming
const float movementSpeed = 5.0f; // Speed for panning
const float minZoom = 2.0f; // Minimum zoom distance
const float maxZoom = 20.0f; // Maximum zoom distance
// Managers
extern AssetManager g_AssetManager;
extern Settings g_SettingsManager;
extern InputManager g_InputManager;
// Settings
extern bool DrawBBBO;
@ -222,7 +243,7 @@ enum GizmoOperation
// Initialize with a default operation
GizmoOperation currentOperation = GIZMO_TRANSLATE;
void RenderWindow::Show(bool *GameRunning)
void RenderWindow::Show(bool *GameRunning, double deltaTime)
{
// Begin the ImGui window with an icon and label
ImGui::Begin(ICON_FA_GAMEPAD " Editor##EditorWindow");
@ -300,70 +321,120 @@ void RenderWindow::Show(bool *GameRunning)
// Obtain view and projection matrices from the active camera
glm::mat4 viewMatrix;
glm::mat4 projectionMatrix;
// Camera Selection and Setup Logic (e.g., within your rendering or update function)
if (m_ActiveCamera) // Ensure m_ActiveCamera is correctly initialized
if (m_ActiveCamera)
{
// Use the existing active camera
viewMatrix = m_ActiveCamera->GetViewMatrix();
projectionMatrix = m_ActiveCamera->GetProjectionMatrix();
}
else
{
// Fallback view matrix
viewMatrix = glm::lookAt(glm::vec3(0.0f, 0.0f, 5.0f),
glm::vec3(0.0f, 0.0f, 0.0f),
glm::vec3(0.0f, 1.0f, 0.0f));
m_ActiveCamera = m_EditorCamera->GetComponent<CameraComponent>();
// Fallback projection matrix
float aspect = (h != 0) ? static_cast<float>(w) / static_cast<float>(h) : 1.0f;
projectionMatrix = glm::perspective(glm::radians(45.0f), aspect, 0.1f, 100.0f);
}
static ImGuizmo::OPERATION currentOperation = ImGuizmo::TRANSLATE;
if (ImGui::IsWindowFocused() && ImGui::IsWindowHovered())
{
if (ImGui::IsKeyPressed(ImGuiKey_T))
// 1. Mouse Input for Rotation
if (g_InputManager.IsMouseButtonPressed(MouseButton::RIGHT))
{
currentOperation = ImGuizmo::TRANSLATE;
}
if (ImGui::IsKeyPressed(ImGuiKey_R))
{
currentOperation = ImGuizmo::ROTATE;
float deltaX = g_InputManager.GetMouseDeltaX();
float deltaY = g_InputManager.GetMouseDeltaY();
editorYaw += deltaX * rotationSpeed;
editorPitch += deltaY * rotationSpeed;
// Clamp the pitch to prevent flipping
if (editorPitch > 89.0f)
editorPitch = 89.0f;
if (editorPitch < -89.0f)
editorPitch = -89.0f;
}
if (ImGui::IsKeyPressed(ImGuiKey_S))
// 2. Scroll Input for Zooming
float scrollDelta = g_InputManager.GetScrollDelta();
editorDistance -= scrollDelta * zoomSpeed;
editorDistance = glm::clamp(editorDistance, minZoom, maxZoom);
// 3. Keyboard Input for Panning (WASD)
glm::vec3 forward = glm::normalize(editorTarget - m_EditorCamera->GetComponent<TransformComponent>()->GetPosition());
glm::vec3 right = glm::normalize(glm::cross(forward, glm::vec3(0.0f, 1.0f, 0.0f)));
glm::vec3 up = glm::vec3(0.0f, 1.0f, 0.0f);
deltaTime = static_cast<float>(deltaTime);
if (g_InputManager.IsKeyPressed(KeyCode::W))
editorTarget += up.y * movementSpeed * deltaTime;
if (g_InputManager.IsKeyPressed(KeyCode::S))
editorTarget -= up.y * movementSpeed * deltaTime;
if (g_InputManager.IsKeyPressed(KeyCode::A))
editorTarget -= right.x * movementSpeed * deltaTime;
if (g_InputManager.IsKeyPressed(KeyCode::D))
editorTarget += right.x * movementSpeed * deltaTime;
// 4. Calculate the New Camera Position
glm::vec3 direction;
direction.x = cos(glm::radians(editorYaw)) * cos(glm::radians(editorPitch));
direction.y = sin(glm::radians(editorPitch));
direction.z = sin(glm::radians(editorYaw)) * cos(glm::radians(editorPitch));
direction = glm::normalize(direction);
glm::vec3 newPosition = editorTarget - direction * editorDistance;
// 5. Update the Editor Camera's Transform
auto editorTransform = m_EditorCamera->GetComponent<TransformComponent>();
editorTransform->SetPosition(newPosition.x,newPosition.y,newPosition.z);
editorTransform->LookAt(editorTarget, up);
// 6. Retrieve Updated Matrices
viewMatrix = m_ActiveCamera->GetViewMatrix();
projectionMatrix = m_ActiveCamera->GetProjectionMatrix();
static ImGuizmo::OPERATION currentOperation = ImGuizmo::TRANSLATE;
if (ImGui::IsWindowFocused() && ImGui::IsWindowHovered())
{
currentOperation = ImGuizmo::SCALE;
if (ImGui::IsKeyPressed(ImGuiKey_T))
{
currentOperation = ImGuizmo::TRANSLATE;
}
if (ImGui::IsKeyPressed(ImGuiKey_R))
{
currentOperation = ImGuizmo::ROTATE;
}
if (ImGui::IsKeyPressed(ImGuiKey_S))
{
currentOperation = ImGuizmo::SCALE;
}
}
}
// Define snap settings
bool snap = false; // Enable snapping if needed
float snapValue = 0.1f; // Snap increment
// Define snap settings
bool snap = false; // Enable snapping if needed
float snapValue = 0.1f; // Snap increment
// Set the ImGuizmo rectangle to the window's position and size
ImVec2 windowPos = ImGui::GetWindowPos();
ImVec2 windowSize = ImGui::GetWindowSize();
ImGuizmo::SetRect(windowPos.x, windowPos.y, windowSize.x, windowSize.y);
// Set the ImGuizmo rectangle to the window's position and size
ImVec2 windowPos = ImGui::GetWindowPos();
ImVec2 windowSize = ImGui::GetWindowSize();
ImGuizmo::SetRect(windowPos.x, windowPos.y, windowSize.x, windowSize.y);
// Render the gizmo and handle user interaction
projectionMatrix[1][1] *= -1.0f; // Flip Image Internaly
ImGuizmo::Manipulate(
glm::value_ptr(viewMatrix),
glm::value_ptr(projectionMatrix),
currentOperation,
ImGuizmo::LOCAL,
glm::value_ptr(modelMatrix),
nullptr, // Optional delta matrix
snap ? &snapValue : nullptr // Optional snap values
);
// Render the gizmo and handle user interaction
projectionMatrix[1][1] *= -1.0f; // Flip Image Internaly
ImGuizmo::Manipulate(
glm::value_ptr(viewMatrix),
glm::value_ptr(projectionMatrix),
currentOperation,
ImGuizmo::LOCAL,
glm::value_ptr(modelMatrix),
nullptr, // Optional delta matrix
snap ? &snapValue : nullptr // Optional snap values
);
// Check if the gizmo is being used (i.e., if the user is interacting with it)
if (ImGuizmo::IsUsing())
{
// Update the TransformComponent with the modified matrix
transform->SetTransformMatrix(modelMatrix);
// Check if the gizmo is being used (i.e., if the user is interacting with it)
if (ImGuizmo::IsUsing())
{
// Update the TransformComponent with the modified matrix
transform->SetTransformMatrix(modelMatrix);
}
}
}
}
@ -387,6 +458,12 @@ void RenderWindow::InitGLResources()
// throw this in here cus we dont have a constructor
m_ActiveCamera = nullptr;
m_EditorCamera = std::make_shared<GameObject>(-1, "EditorCamera");
// Setup the editor camera
m_EditorCamera->AddComponent(std::make_shared<CameraComponent>());
m_EditorCamera->AddComponent(std::make_shared<TransformComponent>());
{
std::shared_ptr<Shader> shaderAsset = g_AssetManager.loadAsset<Shader>(AssetType::SHADER, "assets/shaders/UnlitMaterial");
if (!shaderAsset)

View File

@ -5,11 +5,13 @@
#include <memory>
#include "Rendering/Shader.h" //
#include "Components/CameraComponent.h"
#include "Components/GameObject.h"
#include "Engine/InputManager.h"
class RenderWindow
{
public:
void Show(bool *GameRunning);
void Show(bool *GameRunning, double deltaTime);
private:
void InitGLResources();
@ -39,6 +41,8 @@ private:
// The loaded shader program (via AssetManager)
Shader* m_ShaderPtr = nullptr;
Shader* m_LineShaderPtr = nullptr;
std::shared_ptr<GameObject> m_EditorCamera;
};