Global snap to grid.
This commit is contained in:
+30
-3
@@ -25,8 +25,6 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <ranges>
|
#include <ranges>
|
||||||
#include <algorithm>
|
|
||||||
#include <iterator>
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
using json = nlohmann::json;
|
using json = nlohmann::json;
|
||||||
@@ -170,6 +168,7 @@ int main(){
|
|||||||
|
|
||||||
VEC_SPTR_Node copied_nodes;
|
VEC_SPTR_Node copied_nodes;
|
||||||
|
|
||||||
|
Vec2Df modified_mouse;
|
||||||
|
|
||||||
while(!WindowShouldClose()){
|
while(!WindowShouldClose()){
|
||||||
|
|
||||||
@@ -193,7 +192,35 @@ int main(){
|
|||||||
|
|
||||||
Vec2Df mouse_delta = {GetMouseDelta().x, GetMouseDelta().y};
|
Vec2Df mouse_delta = {GetMouseDelta().x, GetMouseDelta().y};
|
||||||
Vec2Df delta = mouse_delta * (-1.0f/camera.zoom);
|
Vec2Df delta = mouse_delta * (-1.0f/camera.zoom);
|
||||||
|
|
||||||
|
if(IsKeyDown(KEY_LEFT_CONTROL)) {
|
||||||
|
modified_mouse.x = round(mouse_pos.x / app.settings.grid) * app.settings.grid;
|
||||||
|
modified_mouse.y = round(mouse_pos.y / app.settings.grid) * app.settings.grid;
|
||||||
|
} else if(IsKeyDown(KEY_LEFT_SHIFT)){
|
||||||
|
float steps = round((dragNode->neighbors.front()->position.dist(mouse_pos)) / app.settings.grid) * app.settings.grid;
|
||||||
|
if(dragNode->neighbors.size() > 1){
|
||||||
|
Vec2Df dn1 = dragNode->neighbors[0]->position;
|
||||||
|
Vec2Df dn2 = dragNode->neighbors[1]->position;
|
||||||
|
Vec2Df v1_orth = dn1.center(dn2);
|
||||||
|
|
||||||
|
if(dn1.x < dn2.x) std::swap(dn1,dn2);
|
||||||
|
|
||||||
|
float dist = dn1.dist(dn2);
|
||||||
|
float dist_orth = std::sqrt(std::pow(steps,2) - std::pow(dist/2,2));
|
||||||
|
|
||||||
|
if(mouse_pos.y < v1_orth.y) dist_orth *= -1;
|
||||||
|
|
||||||
|
Vec2Df v1_orth_t = v1_orth + (dn1-dn2).norm().orth() * dist_orth;
|
||||||
|
DrawLineV(dn1, dn2, VS_COLOR_RED);
|
||||||
|
DrawLineV(v1_orth, v1_orth_t, VS_COLOR_RED);
|
||||||
|
DrawCircleV(v1_orth, 3.0f, VS_COLOR_RED);
|
||||||
|
dragNode->position = v1_orth_t;
|
||||||
|
} else if(!dragNode->neighbors.empty()){
|
||||||
|
float pol_r = steps;
|
||||||
|
float pol_theta = Vector2Angle(Vec2Df{1,0},(mouse_pos - dragNode->neighbors.front()->position));
|
||||||
|
Vec2Df polar = VISEQ::VMATH::polarToCartesian(pol_r, pol_theta);
|
||||||
|
dragNode->position = dragNode->neighbors.front()->position + polar;
|
||||||
|
}
|
||||||
// auto dragging_nodes = app.gm.nodes | RANGE_FILTER([](SPTR_Node n) { return n->dragging;});
|
// auto dragging_nodes = app.gm.nodes | RANGE_FILTER([](SPTR_Node n) { return n->dragging;});
|
||||||
/*auto connecting_nodes = app.gm.nodes | RANGE_FILTER([](SPTR_Node n) { return n->connecting;});*/
|
/*auto connecting_nodes = app.gm.nodes | RANGE_FILTER([](SPTR_Node n) { return n->connecting;});*/
|
||||||
/*auto selected_nodes = app.gm.nodes | RANGE_FILTER([](SPTR_Node n) { return n->selected && !n->picked_up;}) | std::ranges::to<VEC_SPTR_Node>();*/
|
/*auto selected_nodes = app.gm.nodes | RANGE_FILTER([](SPTR_Node n) { return n->selected && !n->picked_up;}) | std::ranges::to<VEC_SPTR_Node>();*/
|
||||||
|
|||||||
Reference in New Issue
Block a user