various little fixes
This commit is contained in:
@@ -3,8 +3,12 @@
|
||||
|
||||
#include <open_engine.hpp>
|
||||
|
||||
#include "open_engine/events/mouse_event.hpp"
|
||||
#include "open_engine/input/input_system.hpp"
|
||||
#include "open_engine/input/mouse_codes.hpp"
|
||||
#include "open_engine/renderer/render_command.hpp"
|
||||
#include "open_engine/renderer/renderer2d.hpp"
|
||||
#include "open_engine/scene/components.hpp"
|
||||
#include "panels/scene_hierarchy.hpp"
|
||||
|
||||
#include <glm/ext/matrix_transform.hpp>
|
||||
@@ -76,6 +80,20 @@ namespace OpenEngine {
|
||||
|
||||
editor_camera = EditorCamera(30.0f, 1920.0f/1080.0f, 0.1f, 1000.0f);
|
||||
|
||||
/*
|
||||
for (float i = 0; i < 200; i++) {
|
||||
for (float y = 0; y < 200; y++) {
|
||||
Entity entity = scene->CreateEntity("entity");
|
||||
entities.push_back(entity);
|
||||
auto& tc = entity.AddComponents<TransformComponent>();
|
||||
tc.translation = { i / 10, y / 10, 0.0f };
|
||||
tc.scale = { 0.1f, 0.1f, 1.0f };
|
||||
auto& sprite = entity.AddComponents<SpriteRendererComponent>();
|
||||
sprite.color = { i / 100.0f, y / 100.0f, 1.0f, 1.0f };
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
scene_hierarchy.SetContext(scene);
|
||||
}
|
||||
|
||||
@@ -101,7 +119,7 @@ namespace OpenEngine {
|
||||
Renderer2D::ResetStats();
|
||||
RenderCommand::SetClearColor({0.11f, 0.11f, 0.15f, 1.0f});
|
||||
RenderCommand::Clear();
|
||||
RenderCommand::ClearBufferI(1, -1);
|
||||
framebuffer->ClearBufferI(1, -1);
|
||||
|
||||
editor_camera.OnUpdate();
|
||||
|
||||
@@ -117,10 +135,18 @@ namespace OpenEngine {
|
||||
int mouse_x = (int)mx;
|
||||
int mouse_y = (int)my;
|
||||
|
||||
if (mouse_x >= 0 && mouse_y >= 0 && mouse_x < (int)viewport_size.x && (int)viewport_size.y) {
|
||||
int id = framebuffer->ReadPixel(1, mouse_x, mouse_y);
|
||||
if (Input::IsMouseButtonPressed(Mouse::ButtonLeft) && id != -1)
|
||||
scene_hierarchy.SetSelectedEntity({ (entt::entity)id, scene.get() });
|
||||
static bool clicked = false;
|
||||
if (Input::IsMouseButtonPressed(MouseCode::ButtonLeft) && mouse_x >= 0 && mouse_y >= 0 && mouse_x < (int)viewport_size.x && (int)viewport_size.y) {
|
||||
if (!clicked) {
|
||||
int id = framebuffer->ReadPixel(1, mouse_x, mouse_y);
|
||||
|
||||
if (id != -1)
|
||||
scene_hierarchy.SetSelectedEntity({ (entt::entity)id, scene.get() });
|
||||
}
|
||||
|
||||
clicked = true;
|
||||
} else {
|
||||
clicked = false;
|
||||
}
|
||||
|
||||
framebuffer->Unbind();
|
||||
@@ -223,24 +249,14 @@ namespace OpenEngine {
|
||||
|
||||
viewport_size = { viewport_panel_size.x, viewport_panel_size.y };
|
||||
|
||||
ImVec2 imgui_cursor_position = ImGui::GetCursorPos();
|
||||
ImVec2 imgui_cursor_position = ImGui::GetCursorScreenPos();
|
||||
|
||||
uint32_t texture_id = framebuffer->GetColorAttachmentRendererID();
|
||||
ImGui::Image((void*)(uint64_t)texture_id, ImVec2{ viewport_size.x, viewport_size.y }, ImVec2{ 0, 1 }, ImVec2{ 1, 0 });
|
||||
|
||||
int max_x = viewport_size.x + imgui_cursor_position.x;
|
||||
int max_y = viewport_size.y + imgui_cursor_position.y;
|
||||
|
||||
auto window_size = ImGui::GetWindowSize();
|
||||
ImVec2 min_bound = ImGui::GetWindowPos();
|
||||
|
||||
min_bound.x += imgui_cursor_position.x;
|
||||
min_bound.y += imgui_cursor_position.y;
|
||||
|
||||
ImVec2 max_bound = { min_bound.x + window_size.x, min_bound.y + window_size.y };
|
||||
|
||||
viewport_bounds[0] = { min_bound.x, min_bound.y};
|
||||
viewport_bounds[1] = { max_bound.x, max_bound.y};
|
||||
viewport_bounds[0] = { imgui_cursor_position.x, imgui_cursor_position.y };
|
||||
viewport_bounds[1] = { imgui_cursor_position.x + viewport_size.x,
|
||||
imgui_cursor_position.y + viewport_size.y };
|
||||
|
||||
DrawGuizmos();
|
||||
|
||||
@@ -277,9 +293,10 @@ namespace OpenEngine {
|
||||
ImGuizmo::SetDrawlist();
|
||||
ImGuizmo::Enable(!editor_camera.GetMoving());
|
||||
|
||||
auto window_position = ImGui::GetWindowPos();
|
||||
auto window_size = ImGui::GetWindowSize();
|
||||
ImGuizmo::SetRect(window_position.x, window_position.y, window_size.x, window_size.y);
|
||||
ImGuizmo::SetRect(viewport_bounds[0].x, viewport_bounds[0].y,
|
||||
viewport_bounds[1].x - viewport_bounds[0].x,
|
||||
viewport_bounds[1].y - viewport_bounds[0].y);
|
||||
|
||||
|
||||
const glm::mat4& camera_projection = editor_camera.GetProjection();
|
||||
glm::mat4 camera_view = editor_camera.GetViewMatrix();
|
||||
@@ -379,7 +396,7 @@ namespace OpenEngine {
|
||||
int guizmo_operation = -1;
|
||||
|
||||
Ref<Scene> scene;
|
||||
Entity sq_entity;
|
||||
std::vector<Entity> entities;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user