jiayouxjh / grafx2

Automatically exported from code.google.com/p/grafx2
0 stars 0 forks source link

Mouse interpolation in continuous freehand draw #278

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
We already have some code for 4-point Bézier curves (splines), and I was
thinking we could use it to smooth mouse movement when using the continuous
freehand drawing tool.
At the moment, the program draws a straight line from one mouse position to
the next. But, when using big brushes, or moderate brushes with expensive 
effects (smooth, transparency), the frequency of mouse events can reduce,
the distance from one point to the next increases, the lines become jaggy.
The computation of coordinates is going to cause an overhead. But it
doesn't need any memory, so it should not decrease the preceived performance.

This requires fetching the next mouse position in the SDL even queue, ahead
of time(*). With this position, (and recording the previous mouse
position), we compute a 4-point curve. The control points are computed as
forming a continuation of the segment they're connected to, with halved
length. If there's no previous or next mouse position, the control point if
set exactly on the start or end point.

There's a little java app in the following page, to play with cubic Bézier
splines.
http://www.ibiblio.org/e-notes/Splines/Bezier.htm

(*) Will require clipping this position according to current viewport.
Fortunately, in Grafx2, no meaningful key/mouse operation will be taken
into account while freehand is in progress, so this position will be ok.

Original issue reported on code.google.com by yrizoud on 14 Dec 2009 at 1:56

GoogleCodeExporter commented 9 years ago

Original comment by yrizoud on 14 Dec 2009 at 2:20

GoogleCodeExporter commented 9 years ago

Original comment by pulkoma...@gmail.com on 10 Feb 2010 at 12:20

GoogleCodeExporter commented 9 years ago

Original comment by pulkoma...@gmail.com on 9 Aug 2010 at 9:45