From 65c9157910452897bbcc5cdaa3758ecfeb012b64 Mon Sep 17 00:00:00 2001 From: Shariq Shah Date: Mon, 29 Apr 2019 14:55:42 +1000 Subject: [PATCH] Implemented functionality to handle arc drawing when arc size is greater than 360 or less than -360 --- src/game/editor.c | 3 ++- src/game/im_render.c | 11 ++++++++--- todo.txt | 5 +++++ 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/game/editor.c b/src/game/editor.c index f2691ce..a3cc204 100755 --- a/src/game/editor.c +++ b/src/game/editor.c @@ -121,6 +121,7 @@ void editor_init(struct Editor* editor) editor->grid_scale = 1.f; editor->tool_mesh_draw_enabled = 1; editor->tool_snap_enabled = 1; + editor->tool_rotate_amount = 0.f; editor->tool_rotate_arc_radius = 5.f; editor->tool_rotate_arc_segments = 50.f; editor->tool_rotate_axis_selection_enabled = true; @@ -560,7 +561,7 @@ void editor_on_mousebutton_release(const struct Event* event) } - if(editor->selected_entity && event->mousebutton.button == MSB_LEFT) + if(editor->selected_entity && event->mousebutton.button == MSB_LEFT && nk_item_is_any_active(&gui->context) == 0) { if(editor->current_mode == EDITOR_MODE_TRANSLATE) { diff --git a/src/game/im_render.c b/src/game/im_render.c index 1a4628d..df020b5 100755 --- a/src/game/im_render.c +++ b/src/game/im_render.c @@ -170,19 +170,24 @@ void im_arc(float radius, float angle_start, float angle_end, int num_divisions, { im_begin(position, rotation, (vec3) { 1.f, 1.f, 1.f }, color, filled ? GDM_TRIANGLE_FAN : GDM_LINE_LOOP, draw_order); float arc_degrees = angle_end - angle_start; - float increment = arc_degrees / num_divisions; if(arc_degrees != 360) im_pos(0.f, 0.f, 0.f); + if(arc_degrees > 360.f) + arc_degrees = (int)arc_degrees % 360; + if(arc_degrees < -360.f) + arc_degrees = (int)arc_degrees % -360; + + float increment = arc_degrees / num_divisions; if(angle_start < angle_end) { - for(float i = angle_start; i <= angle_end; i += increment) + for(float i = angle_start; i <= arc_degrees; i += increment) im_pos(sinf(i * M_PI / 180.f) * radius, cosf(i * M_PI / 180.f) * radius, 0.f); } else { - for(float i = angle_start; i >= angle_end; i += increment) + for(float i = angle_start; i >= arc_degrees; i += increment) im_pos(sinf(i * M_PI / 180.f) * radius, cosf(i * M_PI / 180.f) * radius, 0.f); } diff --git a/todo.txt b/todo.txt index f7f1d88..448cdf4 100644 --- a/todo.txt +++ b/todo.txt @@ -1,4 +1,5 @@ Todo: + - Rotation degree snapping - Only show rotation gizmo for one axis at a time - Rotate mesh along mouse movement or show what the rotation is going to look like by using a wireframe version of mesh when rotating - Match amount to be rotate with actual axes and the gizmo arc being drawn @@ -12,6 +13,9 @@ Todo: - Scale Mode - Color picker - Color palette, picker and dropper + - Key binding and function to snap editor camera to selected entity + location + - Key binding and function to orient entity to camera orientation - Mouse warp to opposite side of the window when it reaches bounds - Add other axis combinations like YZ and XY to transform tool - Transformation space selection for translation, rotation and scale. @@ -259,4 +263,5 @@ Done: * Handle negative values in im_arc * Rotate mode tool widget * Complete rotate mode + * Implement arc values greater than 360 or -360