two direction connections with blockers working

This commit is contained in:
Sebastian
2024-10-15 02:59:26 +02:00
parent 313bf767c6
commit b74c63a115
5 changed files with 101 additions and 33 deletions
+15 -17
View File
@@ -34,6 +34,9 @@
#include "node.h"
#include "signal.h"
#include "connection.h"
#include "connection-manager.h"
libremidi::observer obs;
libremidi::midi_out midi_out;
@@ -43,8 +46,8 @@ std::vector<libremidi::output_port> midi_out_ports;
std::vector<Node> nodes;
std::vector<Signal> signals;
//std::map<Movable*, std::vector<Node*>> connections;
//std::vector<Connection> connections;
ConnectionManager cm;
Vec2D<float> mouse_pos;
Vec2D<float> drag_start;
@@ -99,7 +102,7 @@ int main(){
}
for(int i = 0; i < 2; i++){
signals.emplace(signals.end(), Signal(0, 0, 5.0f, 2.0f));
signals.emplace(signals.end(), Signal(1280, 720, 5.0f, 2.0f));
signals[i].next = &nodes[0];
}
@@ -108,7 +111,7 @@ int main(){
Vec2D<float> drag_offset;
Node* connecting_from;
while(!WindowShouldClose()){
Vector2 mp = GetScreenToWorld2D(GetMousePosition(), camera);
@@ -155,9 +158,9 @@ int main(){
}
if(mouse_released && (n.hover_connect || n.hover_move)) {
if(&n != connecting_from){
n.connections.push_back(connecting_from);
connecting_from->connections.push_back(&n);
if(&n != connecting_from && connecting_from != nullptr){
cm.connections.emplace(cm.connections.end(), connecting_from, &n);
connecting_from = nullptr;
}
}
@@ -182,19 +185,14 @@ int main(){
n.draw(&mouse_pos);
}
/*for( auto from : connections){*/
/* for( auto to : from.second){*/
/* Vec2D<float> from_position = from.first->position - ((from.first->position - to->position)).norm() * (from.first->radius + 10.0f);*/
/* Vec2D<float> to_position = to->position - ((to->position - from.first->position)).norm() * (to->radius + 10.0f);*/
/* DrawLine(from_position.x, from_position.y, to_position.x, to_position.y, (Color){229, 181, 103, 255});*/
/* }*/
/*}*/
cm.draw();
for( auto& s : signals){
for(auto& s : signals){
s.direction = s.next->position - s.position;
if(s.position.dist(&s.next->position) < s.speed * 1.5) {
if(s.next->connections.size() > 0) {
s.next = s.next->get_next();
Node* n = cm.next(s.next);
if(n != s.next && n != nullptr) {
s.next = n;
midi_out.send_message(libremidi::channel_events::control_change(2, 10, 50));
}
}