I've been working on a C# WPF program that deals with graphics. In this program the user is able to move graphics around by dragging. In a past lifetime I handled this sort of thing by doing arithmetic in the mouse handlers.
onmousedown:
o set deltaX, deltaY to 0 and store location of mouse
onmousemove:
o figure out cumulative deltaX, deltaY based on current mouse location and the stored mouse location
o draw item, displaced by deltaX, deltaY
onmouseup:
o update global displacement using deltaX, deltaY
Today I did it the same way, except instead of dealing with individual X and Y coordinates, I used point and vector structures. The .NET framework comes with a conversion between them, and I don't even have to cast explicitly. The result of arithmetic on points (like say mouseCurrent - mouseInitial) is a vector. Nice.
Tuesday, July 14, 2009
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment