Re: NSBezierPath lineToPoint: Rate
Re: NSBezierPath lineToPoint: Rate
- Subject: Re: NSBezierPath lineToPoint: Rate
- From: Graham Cox <email@hidden>
- Date: Sat, 13 Sep 2008 10:04:25 +1000
On 13 Sep 2008, at 2:18 am, Ian was here wrote:
I have an app that uses a pen tool. If I move the mouse slowly, the
free-hand drawing looks smooth, but as I increase the speed at which
I move the mouse, the line gets bumpy. I am calling lineToPoint: in
the mouseDragged: method of my view.
Has anyone found a solution to this problem.
The problem is that if you move the mouse quickly, the distance
between each successive mouse point delivered to your app increases.
If you simply join successive points with a line, it's bound to get
bumpy. There's no built-in solution since events are delivered at
pretty much a fixed maximum rate.
Instead, you could be smarter about how you build your line, using
curveTo elements to join successive points.
Bear in mind that a curve starts off heading in a direction that is
tangent to the line between the first point and the first control
point (cp1), and finishes on the tangent between the last point and
the last control point (cp2). Using these facts, you can set up the
positions of cp1 and cp2 according to the direction that the mouse is
heading in when you sample its position. You can find that out easily
using the deltaX and deltaY fields of the event. This will also tell
you the "velocity" of the mouse as well as its direction, so you can
make the radius of the control point proportional to the velocity. A
bit of trigonometry is all that is required, and by joining each mouse
point with the resulting curve, you'll get smooth lines.
hth,
Graham
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden