D
This sounds like advanced mathematics. So there's no built-in function in GML that can do this?What you need to do is keep track of the previous position of the mouse each step and then use a line algorithm (like bresenham's) to join the current position and previous position together, rather than just using whatever grid the mouse is over each step.
Mmm, if you think about the sudo logic, it doesnāt sound too advanced, more like a good challenge with a morning coffeeThis sounds like advanced mathematics. So there's no built-in function in GML that can do this?
Too bad the only one I found on the GM marketplace was for the GM 1.4. :\ I'll see what I can do with the link you sent me.Not that I'm aware of. I imagine there's already a bresenham's line algo somewhere out there for GMS, I know I have made one in the past. Maybe check GMLscripts.com and see if they have a script for it.
function line(x0, y0, x1, y1)
{
deltax = x1 - x0;
deltay = y1 - y0;
deltaerr = abs(deltay / deltax); // Assume deltax != 0 (line is not vertical),
// note that this division needs to be done in a way that preserves the fractional part
error = 0.0 // No error at start
gr_msy = y0
for (gr_msx = x0; x0 < x1; x0++)
{
for (gr_msy = y0; y0 < y1; y0++)
{
gridlasso[# x0, y0]=1;
}
}
error = error + deltaerr
if error >= 0.5 then
gr_msy = gr_msx + sign(deltay)
error = error - 1.0
}
if mouse_check_button_pressed(mb_left) && global.lasso = true
{
lxx=floor(mouse_x/sizelassox)
lyy=floor(mouse_y/sizelassoy)
line(lxx,lyy,mouse_x,mouse_y)
old_mouse_x11 = mouse_x
old_mouse_y11 = mouse_y
}
if mouse_check_button(mb_left) && (mouse_x != old_mouse_x11 || mouse_y != old_mouse_y11)
&& global.lasso = true
{
//Get vector from old mouse pos to new
vxx2 = mouse_x - old_mouse_x11
vyy2 = mouse_y - old_mouse_y11
//Get distance
dd2 = point_distance(0, 0, vxx2, vyy2)
//Normalize the vector
vxx2 /= dd2
vyy2 /= dd2
//Create temp position starting at the old pos, which will be incremented until it reaches the new pos
pxx11 = old_mouse_x11
pyy11 = old_mouse_y11
//Set old mouse to the current pos
old_mouse_x11 = lxx
old_mouse_y11 = lyy
repeat dd2
{
//increment temp pos by the vector
pxx11 += vxx2
pyy11 += vyy2
lxx=floor(pxx11/sizelassox)
lyy=floor(pyy11/sizelassoy)
line(lxx,lyy,mouse_x,mouse_y)
}
}
lxx=floor(mouse_x/sizelassox)
lyy=floor(mouse_y/sizelassoy)
line(lxx,lyy,mouse_x,mouse_y)