mirror of
https://github.com/brunoherbelin/vimix.git
synced 2025-12-08 16:59:59 +01:00
New PickingVisitor for selecting Nodes from mouse clic
Cleanup Mixer and other Visitor classes.
This commit is contained in:
@@ -217,6 +217,7 @@ set(VMIX_SRCS
|
||||
FrameBuffer.cpp
|
||||
RenderingManager.cpp
|
||||
UserInterfaceManager.cpp
|
||||
PickingVisitor.cpp
|
||||
ImGuiToolkit.cpp
|
||||
ImGuiVisitor.cpp
|
||||
GstToolkit.cpp
|
||||
|
||||
@@ -70,11 +70,13 @@ void ImGuiVisitor::visit(Group &n)
|
||||
void ImGuiVisitor::visit(Switch &n)
|
||||
{
|
||||
// TODO : display selection of active child
|
||||
(*n.activeChild())->accept(*this);
|
||||
}
|
||||
|
||||
void ImGuiVisitor::visit(Animation &n)
|
||||
{
|
||||
// TODO : display group and animation parameters
|
||||
|
||||
}
|
||||
|
||||
void ImGuiVisitor::visit(Primitive &n)
|
||||
|
||||
@@ -60,6 +60,8 @@ void Mixer::createSourceMedia(std::string uri)
|
||||
// Mixing Node
|
||||
mixing_.scene.root()->addChild(m->group(View::MIXING));
|
||||
|
||||
// set source as current
|
||||
current_source_ = Source::begin();
|
||||
}
|
||||
|
||||
void Mixer::setCurrentSource(std::string namesource)
|
||||
|
||||
82
PickingVisitor.cpp
Normal file
82
PickingVisitor.cpp
Normal file
@@ -0,0 +1,82 @@
|
||||
#include "PickingVisitor.h"
|
||||
|
||||
#include "Log.h"
|
||||
#include "Primitives.h"
|
||||
#include "Mesh.h"
|
||||
|
||||
#include <glm/gtc/type_ptr.hpp>
|
||||
#include <glm/gtc/matrix_access.hpp>
|
||||
#include <glm/gtc/matrix_transform.hpp>
|
||||
|
||||
|
||||
PickingVisitor::PickingVisitor(glm::vec2 coordinates) : Visitor(), point_(coordinates), node_(nullptr)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void PickingVisitor::visit(Node &n)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void PickingVisitor::visit(Group &n)
|
||||
{
|
||||
for (NodeSet::iterator node = n.begin(); node != n.end(); node++) {
|
||||
(*node)->accept(*this);
|
||||
}
|
||||
}
|
||||
|
||||
void PickingVisitor::visit(Switch &n)
|
||||
{
|
||||
(*n.activeChild())->accept(*this);
|
||||
}
|
||||
|
||||
void PickingVisitor::visit(Animation &n)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void PickingVisitor::visit(Primitive &n)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void PickingVisitor::visit(ImageSurface &n)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void PickingVisitor::visit(FrameBufferSurface &n)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void PickingVisitor::visit(MediaSurface &n)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void PickingVisitor::visit(LineStrip &n)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void PickingVisitor::visit(LineSquare &)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void PickingVisitor::visit(LineCircle &n)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void PickingVisitor::visit(Mesh &n)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void PickingVisitor::visit(Scene &n)
|
||||
{
|
||||
n.root()->accept(*this);
|
||||
}
|
||||
38
PickingVisitor.h
Normal file
38
PickingVisitor.h
Normal file
@@ -0,0 +1,38 @@
|
||||
#ifndef PICKINGVISITOR_H
|
||||
#define PICKINGVISITOR_H
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
#include "Visitor.h"
|
||||
|
||||
class PickingVisitor: public Visitor
|
||||
{
|
||||
glm::vec2 point_;
|
||||
glm::mat4 modelview_;
|
||||
Node *node_;
|
||||
|
||||
public:
|
||||
PickingVisitor(glm::vec2 coordinates);
|
||||
Node *picked() { return node_; }
|
||||
|
||||
// Elements of Scene
|
||||
void visit(Scene& n);
|
||||
void visit(Node& n);
|
||||
void visit(Group& n);
|
||||
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(LineSquare&);
|
||||
void visit(LineCircle& n);
|
||||
void visit(Mesh& n);
|
||||
|
||||
// not picking other Elements with attributes
|
||||
void visit(MediaPlayer&) {}
|
||||
void visit(Shader&) {}
|
||||
void visit(ImageShader&) {}
|
||||
};
|
||||
|
||||
#endif // PICKINGVISITOR_H
|
||||
@@ -272,7 +272,7 @@ void Switch::draw(glm::mat4 modelview, glm::mat4 projection)
|
||||
|
||||
void Switch::accept(Visitor& v)
|
||||
{
|
||||
Group::accept(v);
|
||||
Node::accept(v);
|
||||
v.visit(*this);
|
||||
}
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
using namespace tinyxml2;
|
||||
|
||||
|
||||
SessionVisitor::SessionVisitor()
|
||||
SessionVisitor::SessionVisitor() : Visitor()
|
||||
{
|
||||
xmlDoc_ = new XMLDocument;
|
||||
|
||||
@@ -58,11 +58,19 @@ void SessionVisitor::visit(Switch &n)
|
||||
// Node of a different type
|
||||
xmlCurrent_->SetAttribute("type", "Switch");
|
||||
xmlCurrent_->SetAttribute("active", n.getIndexActiveChild());
|
||||
|
||||
// loop over members of the group
|
||||
XMLElement *group = xmlCurrent_;
|
||||
for (NodeSet::iterator node = n.begin(); node != n.end(); node++) {
|
||||
(*node)->accept(*this);
|
||||
// revert to group as current
|
||||
xmlCurrent_ = group;
|
||||
}
|
||||
}
|
||||
|
||||
void SessionVisitor::visit(Animation &n)
|
||||
{
|
||||
// Node of a different type
|
||||
// Group of a different type
|
||||
xmlCurrent_->SetAttribute("type", "Animation");
|
||||
|
||||
XMLElement *anim = xmlDoc_->NewElement("Movement");
|
||||
|
||||
@@ -27,11 +27,12 @@ Source::Source(std::string name = "") : name_("")
|
||||
// default mixing nodes
|
||||
groups_[View::MIXING] = new Group;
|
||||
Frame *frame = new Frame;
|
||||
frame->translation_.z = 0.1;
|
||||
groups_[View::MIXING]->addChild(frame);
|
||||
groups_[View::MIXING]->scale_ = glm::vec3(0.25f, 0.25f, 1.f);
|
||||
|
||||
// add source to the list
|
||||
sources_.push_back(this);
|
||||
sources_.push_front(this);
|
||||
}
|
||||
|
||||
Source::~Source()
|
||||
|
||||
72
main.cpp
72
main.cpp
@@ -29,6 +29,7 @@
|
||||
|
||||
// mixing
|
||||
#include "Mixer.h"
|
||||
#include "Source.h"
|
||||
#include "RenderingManager.h"
|
||||
#include "UserInterfaceManager.h"
|
||||
#include "FrameBuffer.h"
|
||||
@@ -55,20 +56,22 @@
|
||||
//// ("file:///Users/Herbelin/Movies/mp2test.mpg");
|
||||
|
||||
|
||||
//MediaSurface testnode1("file:///home/bhbn/Videos/iss.mov");
|
||||
MediaSurface testnode2("file:///home/bhbn/Videos/fish.mp4");
|
||||
//ImageSurface testnode3("images/seed_512.jpg");
|
||||
|
||||
|
||||
void drawMediaPlayer()
|
||||
{
|
||||
static GstClockTime begin = GST_CLOCK_TIME_NONE;
|
||||
static GstClockTime end = GST_CLOCK_TIME_NONE;
|
||||
|
||||
if ( !testnode2.getMediaPlayer() || !testnode2.getMediaPlayer()->isOpen() )
|
||||
if ( !Mixer::manager().currentSource())
|
||||
return;
|
||||
|
||||
MediaPlayer *mp = testnode2.getMediaPlayer();
|
||||
MediaSource *s = static_cast<MediaSource *>(Mixer::manager().currentSource());
|
||||
if ( !s )
|
||||
return;
|
||||
|
||||
MediaPlayer *mp = s->mediaplayer();
|
||||
if ( !mp || !mp->isOpen() )
|
||||
return;
|
||||
|
||||
ImGui::SetNextWindowPos(ImVec2(200, 200), ImGuiCond_FirstUseEver);
|
||||
ImGui::SetNextWindowSize(ImVec2(300, 300), ImGuiCond_FirstUseEver);
|
||||
@@ -172,27 +175,6 @@ void drawMediaPlayer()
|
||||
|
||||
void drawScene()
|
||||
{
|
||||
// // compute dt
|
||||
// static gint64 last_time = gst_util_get_timestamp ();
|
||||
// gint64 current_time = gst_util_get_timestamp ();
|
||||
// gint64 dt = current_time - last_time;
|
||||
// last_time = current_time;
|
||||
|
||||
// // recursive update from root of scene
|
||||
// scene.root()->update( static_cast<float>( GST_TIME_AS_MSECONDS(dt)) * 0.001f );
|
||||
|
||||
// // draw in output frame buffer
|
||||
// glm::mat4 MV = glm::identity<glm::mat4>();
|
||||
|
||||
// static glm::mat4 projection = glm::ortho(-SCENE_UNIT, SCENE_UNIT, -SCENE_UNIT, SCENE_UNIT, SCENE_DEPTH, 0.f);
|
||||
// glm::mat4 P = glm::scale( projection, glm::vec3(1.f, output->aspectRatio(), 1.f));
|
||||
// output->begin();
|
||||
// scene.root()->draw(MV, P);
|
||||
// output->end();
|
||||
|
||||
// // draw in main view
|
||||
// scene.root()->draw(MV, Rendering::manager().Projection());
|
||||
|
||||
Mixer::manager().update();
|
||||
|
||||
Mixer::manager().draw();
|
||||
@@ -265,53 +247,21 @@ int main(int, char**)
|
||||
Mixer::manager().createSourceMedia("file:///home/bhbn/Videos/iss.mov");
|
||||
Mixer::manager().createSourceMedia("file:///home/bhbn/Videos/fish.mp4");
|
||||
|
||||
// Mesh disk("mesh/disk.ply", "images/transparencygrid.png");
|
||||
|
||||
// glm::vec4 pink( 0.8f, 0.f, 0.8f, 1.f );
|
||||
// LineCircle circle(pink, 5);
|
||||
|
||||
// glm::vec4 color( 0.8f, 0.8f, 0.f, 1.f);
|
||||
// LineSquare border(color, 5);
|
||||
// Mesh shadow("mesh/shadow.ply", "mesh/shadow.png");
|
||||
// Mesh meshicon("mesh/icon_video.ply");
|
||||
|
||||
// Frame frame;
|
||||
// frame.scale_ = glm::vec3(1.7777778f, 1.f, 1.f);
|
||||
|
||||
// Group g1;
|
||||
// g1.translation_ = glm::vec3(1.f, 1.f, 1.f);
|
||||
// g1.scale_ = glm::vec3(0.8f, 0.8f, 1.f);
|
||||
|
||||
// Group g2;
|
||||
// g2.translation_ = glm::vec3(-1.f, -1.f, 2.f);
|
||||
|
||||
// Animation A;
|
||||
// A.translation_ = glm::vec3(0.f, 0.f, 3.f);
|
||||
// A.speed_ = 0.1f;
|
||||
// A.axis_ = glm::vec3(1.f, 1.f, 1.f);
|
||||
|
||||
//// std::vector<glm::vec3> pts = std::vector<glm::vec3> { glm::vec3( 0.f, 0.f, 0.f ) };
|
||||
//// Points P(pts, pink);
|
||||
//// P.setPointSize(60);
|
||||
// Mesh P("mesh/point.ply");
|
||||
// P.scale_ = glm::vec3(0.15f);
|
||||
|
||||
|
||||
// g1.addChild(&testnode3);
|
||||
// Mixer::manager().currentView()->scene.root()->addChild(&g1);
|
||||
|
||||
// g2.addChild(&testnode1);
|
||||
// g2.addChild(&frame);
|
||||
// Mixer::manager().currentView()->scene.root()->addChild(&g2);
|
||||
|
||||
// A.addChild(&P);
|
||||
// Mixer::manager().currentView()->scene.root()->addChild(&A);
|
||||
|
||||
// init output FBO
|
||||
// preview window
|
||||
Rendering::manager().PushBackDrawCallback(drawPreview);
|
||||
|
||||
// add media player
|
||||
// Rendering::manager().PushBackDrawCallback(drawMediaPlayer);
|
||||
Rendering::manager().PushBackDrawCallback(drawMediaPlayer);
|
||||
|
||||
///
|
||||
/// Main LOOP
|
||||
|
||||
Reference in New Issue
Block a user