two node snap for triangles
This commit is contained in:
+23
-5
@@ -289,12 +289,30 @@ int main(){
|
||||
dragNode->position.x = round((mouse_pos.x + dragNode->drag_offset.x) / app.settings.grid) * app.settings.grid;
|
||||
dragNode->position.y = round((mouse_pos.y + dragNode->drag_offset.y) / app.settings.grid) * app.settings.grid;
|
||||
} else if(IsKeyDown(KEY_LEFT_SHIFT)){
|
||||
float steps = round((dragNode->neighbor->position.dist(mouse_pos)) / app.settings.grid) * app.settings.grid;
|
||||
float pol_r = steps;
|
||||
float pol_theta = Vector2Angle(Vec2Df{1,0},(mouse_pos - dragNode->neighbor->position));
|
||||
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);
|
||||
|
||||
Vec2Df polar = VISEQ::VMATH::polarToCartesian(pol_r, pol_theta);
|
||||
dragNode->position = dragNode->neighbor->position + polar;
|
||||
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;
|
||||
}
|
||||
} else {
|
||||
dragNode->position = mouse_pos + dragNode->drag_offset;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user