mirror of
https://github.com/brunoherbelin/vimix.git
synced 2025-12-11 18:34:58 +01:00
Playing with picking
This commit is contained in:
@@ -21,6 +21,7 @@
|
||||
#include <GLFW/glfw3native.h>
|
||||
|
||||
#include <glm/ext/matrix_transform.hpp> // glm::translate, glm::rotate, glm::scale
|
||||
#include <glm/ext/matrix_projection.hpp> // glm::unproject
|
||||
#include <glm/ext/matrix_clip_space.hpp> // glm::perspective
|
||||
|
||||
// Include GStreamer
|
||||
@@ -318,6 +319,18 @@ glm::mat4 Rendering::Projection()
|
||||
return projection * scale;
|
||||
}
|
||||
|
||||
|
||||
glm::vec3 Rendering::unProject(glm::vec2 screen_coordinate, glm::mat4 modelview)
|
||||
{
|
||||
glm::vec3 point;
|
||||
glm::vec3 coordinates = glm::vec3( glm::vec2(screen_coordinate), 0.f);
|
||||
glm::vec4 viewport = glm::vec4( 0.f, 0.f, main_window_attributes_.viewport.x, main_window_attributes_.viewport.y);
|
||||
|
||||
point = glm::unProject(coordinates, modelview, Projection(), viewport);
|
||||
|
||||
return point;
|
||||
}
|
||||
|
||||
float Rendering::Width() { return main_window_attributes_.viewport.x; }
|
||||
float Rendering::Height() { return main_window_attributes_.viewport.y; }
|
||||
|
||||
|
||||
@@ -75,6 +75,8 @@ public:
|
||||
|
||||
// get projection matrix (for sharers) => Views
|
||||
glm::mat4 Projection();
|
||||
// unproject from window coordinate
|
||||
glm::vec3 unProject(glm::vec2 screen_coordinate, glm::mat4 modelview);
|
||||
|
||||
// for opengl pipeline in gstreamer
|
||||
void LinkPipeline( GstPipeline *pipeline );
|
||||
|
||||
@@ -19,6 +19,11 @@
|
||||
// multiplatform
|
||||
#include <tinyfiledialogs.h>
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/ext/vector_float3.hpp>
|
||||
#include <glm/ext/matrix_float4x4.hpp>
|
||||
#include <glm/ext/matrix_transform.hpp>
|
||||
|
||||
// generic image loader
|
||||
#define STB_IMAGE_IMPLEMENTATION
|
||||
#include <stb_image.h>
|
||||
@@ -155,7 +160,7 @@ void UserInterface::handleMouse()
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
|
||||
// if not on any window
|
||||
if ( !ImGui::IsAnyWindowHovered() )
|
||||
if ( !ImGui::IsAnyWindowHovered() && !ImGui::IsAnyWindowFocused() )
|
||||
{
|
||||
// Mouse wheel over background
|
||||
if ( io.MouseWheel > 0) {
|
||||
@@ -165,6 +170,22 @@ void UserInterface::handleMouse()
|
||||
|
||||
if ( ImGui::IsMouseDown(ImGuiMouseButton_Left)) {
|
||||
|
||||
Log::Info("Mouse press (%.1f,%.1f)", io.MousePos.x, io.MousePos.y);
|
||||
|
||||
glm::mat4 mv = glm::identity<glm::mat4>();
|
||||
glm::vec3 point = Rendering::manager().unProject(glm::vec2(io.MousePos.x, io.MousePos.y), mv);
|
||||
|
||||
Log::Info(" (%.1f,%.1f)", point.x, point.y);
|
||||
|
||||
}
|
||||
|
||||
if ( ImGui::IsMouseDragging(ImGuiMouseButton_Left, 10.0f) )
|
||||
{
|
||||
Log::Info("Mouse drag (%.1f,%.1f)(%.1f,%.1f)", io.MouseClickedPos[0].x, io.MouseClickedPos[0].y, io.MousePos.x, io.MousePos.y);
|
||||
ImGui::GetBackgroundDrawList()->AddRect(io.MouseClickedPos[0], io.MousePos,
|
||||
ImGui::GetColorU32(ImGuiCol_ResizeGripHovered));
|
||||
ImGui::GetBackgroundDrawList()->AddRectFilled(io.MouseClickedPos[0], io.MousePos,
|
||||
ImGui::GetColorU32(ImGuiCol_ResizeGripHovered, 0.3f));
|
||||
}
|
||||
|
||||
if ( ImGui::IsMouseReleased(ImGuiMouseButton_Left) )
|
||||
@@ -177,15 +198,15 @@ void UserInterface::handleMouse()
|
||||
|
||||
void UserInterface::NewFrame()
|
||||
{
|
||||
// deal with keyboard and mouse events
|
||||
handleKeyboard();
|
||||
handleMouse();
|
||||
|
||||
// Start the Dear ImGui frame
|
||||
ImGui_ImplOpenGL3_NewFrame();
|
||||
ImGui_ImplGlfw_NewFrame();
|
||||
ImGui::NewFrame();
|
||||
|
||||
// deal with keyboard and mouse events
|
||||
handleKeyboard();
|
||||
handleMouse();
|
||||
|
||||
// Main window
|
||||
mainwindow.Render();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user