I am trying to rotate a canvas with canvas.rotate and move an object on it at the same time. The problem is that with the rotation, the coordinate system of the canvas rotates as well, so I get cases when my object is supposed to be moving along the y axis, but the y axis is rotated on place of the x axis. It is a mess. Is there a way to go around this?
views:
37answers:
1
A:
It's using matrix math; if you do things in the opposite order (translate then rotate, or vice versa), you'll get the opposite effect.
Also, use SetMatrix(null) to clear the matrix to the identity between operations; not sure if that's the kind of mess you're having trouble with.
SomeCallMeTim
2010-09-27 03:25:35
Thanks, I have already tried something similar - canvas.save() and canvas.restore() before and after each transformation. The problem is that if I call restore after either translate or rotate, then all objects drawn after that do not translate or rotate, as the matrix of the canvas is cleared. If I do not call it though, the second transformation - translate/rotate - gets screwed up.In theory if I can find the center of my screen after translation so that I set it up as the pivot point for rotate, everything should work.
Kiril
2010-09-27 17:20:37
If your objects can be kept in the coordinate system of the canvas, then you won't have this problem. Then you may just need to do the rotation on the user input before applying it to the position of the object on the canvas. If you have any more info on exactly what you're trying to do, that might help.
SomeCallMeTim
2010-09-29 20:02:13