connection split button added, but no functionality yes

This commit is contained in:
Sebastian
2024-10-30 11:27:37 +01:00
parent c0f5138765
commit ba5874837c
6 changed files with 2982 additions and 46 deletions
+11 -13
View File
@@ -3,7 +3,6 @@
#include "connection.h"
#include "node-manager.h"
#include "raylib.h"
#include "raymath.h"
#include <map>
#include <vector>
@@ -28,19 +27,12 @@ class ConnectionManager{
std::vector<int> next_node_ids;
for(auto& c : connections){
if((c.v1 == current && c.v1_v2) || (c.v2 == current && c.v2_v1)) {
if((c.node_id_start == current && c.v1_v2) || (c.node_id_end == current && c.v2_v1)) {
c.active = false;
possible_connections.push_back(&c);
next_node_ids.push_back( c.v1 == current ? c.v2 : c.v1 );
next_node_ids.push_back( c.node_id_start == current ? c.node_id_end : c.node_id_start );
}
}
/*if(possible_connections.size() == 2) {*/
/* int next = next_node_ids[0] == last ? next_node_ids[1] : next_node_ids[0];*/
/* if(possible_connections[0]->v1 == next || possible_connections[0]->v2 == next) possible_connections[0]->active = true;*/
/* if(possible_connections[1]->v1 == next || possible_connections[1]->v2 == next) possible_connections[1]->active = true;*/
/* return next;*/
/*}*/
if(possible_connections.empty()) return -1;
@@ -50,7 +42,7 @@ class ConnectionManager{
Vec2D<float> coming_from = (nm->nodes.at(current).position - nm->nodes.at(last).position).norm();
int i = 0;
for(auto n : possible_connections){
int next_position = n->v1 == current ? n->v2 : n->v1;
int next_position = n->node_id_start == current ? n->node_id_end : n->node_id_start;
float angle_v1_v2 = coming_from.norm().dot((nm->nodes.at(next_position).position - nm->nodes.at(current).position).norm());
if(angle_v1_v2 > angle) {
return_path = i;
@@ -74,16 +66,22 @@ class ConnectionManager{
}
possible_connections.at(return_path)->active = true;
return possible_connections.at(return_path)->v1 == current ? possible_connections.at(return_path)->v2 : possible_connections.at(return_path)->v1;
return possible_connections.at(return_path)->node_id_start == current ? possible_connections.at(return_path)->node_id_end : possible_connections.at(return_path)->node_id_start;
}
void addConnection(int from, int to){
connections.emplace_back(&nm->nodes, from, to);
connections.emplace_back(nm, from, to);
}
void splitConnection(Connection *c){
Vec2D<float> center = c->node_start->position.center(c->node_end->position);
}
void drawConnections(Vec2D<float> *mouse_pos, Camera2D *cam){
std::erase_if(connections, [](Connection c){ return c.remove == true;});
for(auto& c : connections){
if(c.split) splitConnection(&c);
c.draw(mouse_pos, cam);
}
}