Skip to content

Commit

Permalink
0.10
Browse files Browse the repository at this point in the history
better snap function
  • Loading branch information
Pitto committed Oct 9, 2018
1 parent fc2c6e3 commit f3bab7a
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 1,220 deletions.
3 changes: 2 additions & 1 deletion definitions.bi
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@
#define APP_NAME "Low Poly Editor by Pitto"
#define APP_VERSION "Version 0.10"
#define SCR_W 1024
#define SCR_H 768
#define SCR_H 600
#define MIN_SNAP_DIST 15
#define MIN_SNAP_TO_SNAP_DIST 5
#define MIN_EDGE_SNAP_DIST 20
#define RANDOM_POLYGONS_QTY 200
#define MAX_POLYGONS_NODES 10
Expand Down
32 changes: 26 additions & 6 deletions functions.bi
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ function find_nearest_point (array() as polygon_proto, user_mouse as mouse_proto
'store all segments of all polygons in an array
'and find the distance of line to pointer for each
redim preserve segments(0 to 0) as segment_proto
redim preserve points(0 to 0) as temp_point_proto
dim close_point as point_proto

for j = 0 to Ubound(array) - 1
Expand All @@ -233,6 +234,10 @@ function find_nearest_point (array() as polygon_proto, user_mouse as mouse_proto

segments(i).x1 = head->x
segments(i).y1 = head->y

points(i).x = head->x
points(i).y = head->y
redim preserve points(0 to (Ubound(points)+1))

if (head->next_p->next_p <> NULL) then
segments(i).x2 = head->next_p->x
Expand Down Expand Up @@ -261,13 +266,26 @@ function find_nearest_point (array() as polygon_proto, user_mouse as mouse_proto
segments(i).y2, _
view_area)
next i

quicksort (nearest_points(), Lbound(nearest_points), Ubound(nearest_points))

if UBound(nearest_points) > 0 then
return nearest_points(1)
else
return nearest_points(0)
for i = 0 to Ubound(points)-1
points(i).distance = dist(points(i).x, points(i).y, user_mouse.abs_x, user_mouse.abs_y)
next i

quicksort (points(), Lbound(points), Ubound(points))


if UBound(points) > 0 then
if (points(1).distance < MIN_SNAP_TO_SNAP_DIST) then
return points(1)
else
if UBound(nearest_points) > 0 then
return nearest_points(1)
else
return nearest_points(0)
end if
end if
end if

end function
Expand Down Expand Up @@ -1386,7 +1404,7 @@ sub draw_button (x as integer, y as integer, w as integer,_
Line (x,y)-(x+w,y+h),C_WHITE,B

if (is_selected) then
Line (x,y)-(x+w,y+h),C_DARK_GRAY,BF
Line (x,y)-(x+w,y+h),C_DARK_RED,BF
Line (x,y)-(x+w,y+h),C_GRAY,B
end if

Expand All @@ -1407,6 +1425,8 @@ sub draw_bottom_info ( console_message as string, _
draw_button (BTN_W, SCR_H - BTN_H, BTN_W * 2, BTN_H, console_message,true)
'bitmap show
draw_button (BTN_W*3, SCR_H - BTN_H, BTN_W, BTN_H, "[B]ITMAP", settings.is_bitmap_visible)
'bitmap show
draw_button (BTN_W*3, SCR_H - BTN_H*2, BTN_W, BTN_H, "[X] ALPHA", settings.is_alpha_bitmap_visible)
'wireframe show
draw_button (BTN_W*4, SCR_H - BTN_H, BTN_W, BTN_H, "[W]IREFRAME", settings.is_wireframe_visible)
'snap show
Expand Down
13 changes: 11 additions & 2 deletions main.bas
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,16 @@ do

keyboard_listener ( @input_mode, user_mouse, @view_area,_
@settings, key())
mouse_listener (@user_mouse, @view_area)

'this to avoid unwanted clicks while mouse pointer goes outside the
'working window
if (User_Mouse.res = 0) then
mouse_listener (@user_mouse, @view_area)
else
user_mouse.x = user_mouse.old_x
user_mouse.y = user_mouse.old_y
end if
'-------------------------------------------------------------------

nearest_point = find_nearest_point(polygons(), user_mouse, view_area)
dist_from_nearest_point = int (dist (nearest_point.x,_
Expand Down Expand Up @@ -511,7 +520,7 @@ do
on_screen_help())

workpage = 1 - Workpage ' Swap work pages.
workpage = 1 - Workpage ' Swap work pages.

screenunlock
sleep 20,1

Expand Down
Loading

0 comments on commit f3bab7a

Please sign in to comment.