mirror of
https://github.com/brunoherbelin/vimix.git
synced 2025-12-11 18:34:58 +01:00
PickingVisitor first draft, with prototype integration in UserInterface
This commit is contained in:
@@ -15,6 +15,7 @@ public:
|
||||
void visit(Switch& n);
|
||||
void visit(Animation& n);
|
||||
void visit(Primitive& n);
|
||||
void visit(Surface&) {}
|
||||
void visit(ImageSurface&) {}
|
||||
void visit(MediaSurface& n);
|
||||
void visit(FrameBufferSurface& n);
|
||||
|
||||
@@ -7,28 +7,38 @@
|
||||
#include <glm/gtc/type_ptr.hpp>
|
||||
#include <glm/gtc/matrix_access.hpp>
|
||||
#include <glm/gtc/matrix_transform.hpp>
|
||||
#include <glm/gtx/string_cast.hpp>
|
||||
|
||||
|
||||
PickingVisitor::PickingVisitor(glm::vec2 coordinates) : Visitor(), point_(coordinates), node_(nullptr)
|
||||
PickingVisitor::PickingVisitor(glm::vec2 coordinates) : Visitor(), point_(coordinates)
|
||||
{
|
||||
|
||||
modelview_ = glm::mat4(1.f);
|
||||
}
|
||||
|
||||
void PickingVisitor::visit(Node &n)
|
||||
{
|
||||
|
||||
modelview_ *= n.transform_;
|
||||
// Log::Info("Node %d", n.id());
|
||||
// Log::Info("%s", glm::to_string(modelview_).c_str());
|
||||
}
|
||||
|
||||
void PickingVisitor::visit(Group &n)
|
||||
{
|
||||
// Log::Info("Group %d", n.id());
|
||||
glm::mat4 mv = modelview_;
|
||||
|
||||
for (NodeSet::iterator node = n.begin(); node != n.end(); node++) {
|
||||
(*node)->accept(*this);
|
||||
modelview_ = mv;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void PickingVisitor::visit(Switch &n)
|
||||
{
|
||||
glm::mat4 mv = modelview_;
|
||||
(*n.activeChild())->accept(*this);
|
||||
modelview_ = mv;
|
||||
}
|
||||
|
||||
void PickingVisitor::visit(Animation &n)
|
||||
@@ -41,24 +51,21 @@ void PickingVisitor::visit(Primitive &n)
|
||||
|
||||
}
|
||||
|
||||
void PickingVisitor::visit(ImageSurface &n)
|
||||
void PickingVisitor::visit(Surface &n)
|
||||
{
|
||||
// test if point is inside rectangle
|
||||
|
||||
}
|
||||
// lower left corner
|
||||
glm::vec4 LL = modelview_ * glm::vec4( -1.f, -1.f, 0.f, 0.f );
|
||||
// up right corner
|
||||
glm::vec4 UR = modelview_ * glm::vec4( 1.f, 1.f, 0.f, 0.f );
|
||||
|
||||
void PickingVisitor::visit(FrameBufferSurface &n)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void PickingVisitor::visit(MediaSurface &n)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void PickingVisitor::visit(LineStrip &n)
|
||||
{
|
||||
// Log::Info("Surface %d", n.id());
|
||||
// Log::Info("LL %s", glm::to_string(LL).c_str());
|
||||
// Log::Info("UR %s", glm::to_string(UR).c_str());
|
||||
|
||||
if ( point_.x > LL.x && point_.x < UR.x && point_.y > LL.y && point_.y < UR.y )
|
||||
nodes_.push_back(&n);
|
||||
}
|
||||
|
||||
void PickingVisitor::visit(LineSquare &)
|
||||
@@ -71,11 +78,6 @@ void PickingVisitor::visit(LineCircle &n)
|
||||
|
||||
}
|
||||
|
||||
void PickingVisitor::visit(Mesh &n)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void PickingVisitor::visit(Scene &n)
|
||||
{
|
||||
n.root()->accept(*this);
|
||||
|
||||
@@ -2,17 +2,19 @@
|
||||
#define PICKINGVISITOR_H
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
#include <vector>
|
||||
|
||||
#include "Visitor.h"
|
||||
|
||||
class PickingVisitor: public Visitor
|
||||
{
|
||||
glm::vec2 point_;
|
||||
glm::mat4 modelview_;
|
||||
Node *node_;
|
||||
std::vector<Node *> nodes_;
|
||||
|
||||
public:
|
||||
PickingVisitor(glm::vec2 coordinates);
|
||||
Node *picked() { return node_; }
|
||||
std::vector<Node *> picked() { return nodes_; }
|
||||
|
||||
// Elements of Scene
|
||||
void visit(Scene& n);
|
||||
@@ -21,13 +23,14 @@ public:
|
||||
void visit(Switch& n);
|
||||
void visit(Animation& n);
|
||||
void visit(Primitive& n);
|
||||
void visit(ImageSurface& n);
|
||||
void visit(MediaSurface& n);
|
||||
void visit(FrameBufferSurface& n);
|
||||
void visit(LineStrip& n);
|
||||
void visit(Surface& n);
|
||||
void visit(ImageSurface&){}
|
||||
void visit(MediaSurface&){}
|
||||
void visit(FrameBufferSurface&){}
|
||||
void visit(LineStrip&){}
|
||||
void visit(LineSquare&);
|
||||
void visit(LineCircle& n);
|
||||
void visit(Mesh& n);
|
||||
void visit(Mesh&){}
|
||||
|
||||
// not picking other Elements with attributes
|
||||
void visit(MediaPlayer&) {}
|
||||
|
||||
@@ -104,7 +104,7 @@ void ImageSurface::draw(glm::mat4 modelview, glm::mat4 projection)
|
||||
|
||||
void ImageSurface::accept(Visitor& v)
|
||||
{
|
||||
Primitive::accept(v);
|
||||
Surface::accept(v);
|
||||
v.visit(*this);
|
||||
}
|
||||
|
||||
@@ -154,7 +154,7 @@ void MediaSurface::update( float dt )
|
||||
|
||||
void MediaSurface::accept(Visitor& v)
|
||||
{
|
||||
Primitive::accept(v);
|
||||
Surface::accept(v);
|
||||
v.visit(*this);
|
||||
}
|
||||
|
||||
@@ -189,7 +189,7 @@ void FrameBufferSurface::draw(glm::mat4 modelview, glm::mat4 projection)
|
||||
|
||||
void FrameBufferSurface::accept(Visitor& v)
|
||||
{
|
||||
Primitive::accept(v);
|
||||
Surface::accept(v);
|
||||
v.visit(*this);
|
||||
}
|
||||
|
||||
|
||||
@@ -98,6 +98,11 @@ void SessionVisitor::visit(Primitive &n)
|
||||
}
|
||||
|
||||
|
||||
void SessionVisitor::visit(Surface &n)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void SessionVisitor::visit(ImageSurface &n)
|
||||
{
|
||||
// Node of a different type
|
||||
|
||||
@@ -22,6 +22,7 @@ public:
|
||||
void visit(Switch& n);
|
||||
void visit(Animation& n);
|
||||
void visit(Primitive& n);
|
||||
void visit(Surface& n);
|
||||
void visit(ImageSurface& n);
|
||||
void visit(MediaSurface& n);
|
||||
void visit(FrameBufferSurface& n);
|
||||
|
||||
@@ -40,6 +40,7 @@
|
||||
#include "ImGuiToolkit.h"
|
||||
#include "GstToolkit.h"
|
||||
#include "Mixer.h"
|
||||
#include "PickingVisitor.h"
|
||||
|
||||
static std::thread loadThread;
|
||||
static bool loadThreadDone = false;
|
||||
@@ -195,31 +196,54 @@ void UserInterface::handleMouse()
|
||||
ImGui::SetMouseCursor(ImGuiMouseCursor_Arrow);
|
||||
|
||||
//
|
||||
// RIGHT Mouse button
|
||||
// LEFT Mouse button
|
||||
//
|
||||
static Node *current = nullptr;
|
||||
|
||||
if ( ImGui::IsMouseDown(ImGuiMouseButton_Left)) {
|
||||
|
||||
Log::Info("Mouse press (%.1f,%.1f)", io.MousePos.x, io.MousePos.y);
|
||||
// Log::Info("Mouse press (%.1f,%.1f)", io.MousePos.x, io.MousePos.y);
|
||||
|
||||
glm::vec3 point = Rendering::manager().unProject(glm::vec2(io.MousePos.x, io.MousePos.y),
|
||||
Mixer::manager().currentView()->scene.root()->transform_ );
|
||||
|
||||
Log::Info(" (%.1f,%.1f)", point.x, point.y);
|
||||
PickingVisitor pv(point);
|
||||
Mixer::manager().currentView()->scene.accept(pv);
|
||||
|
||||
if (pv.picked().empty())
|
||||
current = nullptr;
|
||||
else {
|
||||
current = pv.picked().back();
|
||||
}
|
||||
|
||||
|
||||
// Log::Info(" %d picked", pv.picked().size());
|
||||
|
||||
}
|
||||
|
||||
if ( ImGui::IsMouseDragging(ImGuiMouseButton_Left, 10.0f) )
|
||||
{
|
||||
if (current)
|
||||
{
|
||||
// // drag current
|
||||
// Log::Info("Dragging %d", current->id());
|
||||
// current->translation_.x += io.MouseDelta.x * 0.1f;
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
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) )
|
||||
{
|
||||
|
||||
current = nullptr;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ class Switch;
|
||||
class Animation;
|
||||
class Primitive;
|
||||
class Scene;
|
||||
class Surface;
|
||||
class ImageSurface;
|
||||
class MediaSurface;
|
||||
class FrameBufferSurface;
|
||||
@@ -32,6 +33,7 @@ public:
|
||||
virtual void visit (Switch&) = 0;
|
||||
virtual void visit (Animation&) = 0;
|
||||
virtual void visit (Primitive&) = 0;
|
||||
virtual void visit (Surface&) = 0;
|
||||
virtual void visit (ImageSurface&) = 0;
|
||||
virtual void visit (MediaSurface&) = 0;
|
||||
virtual void visit (FrameBufferSurface&) = 0;
|
||||
|
||||
Reference in New Issue
Block a user