[android-developers] Re: Text in a circle that rotates on touch
Hi , I have the same requirement, I have to rotate an image of a wheel as the user moves finger on the wheel on screen. Can u pls tell me how I can use this code thr? What is cx, cy, mPreviousX, mPreviousY? Thanks On Mar 6, 2:56 am, Nathan wrote: > On Mar 5, 3:25 am, Bart wrote: > > > Hi, I'd like to display a given String in acircle(so bend the string > > so that the end of the string touches the beginning of the string). > > And Then I'd like to let the user rotate thecircleby grabbing and > > dragging it clockwise or counterclockwise. > > Do you guys know what would be the best (simplest, smoothest) way to > > do this? I already saw that using drawOnPath i can drawtextin a > >circle. Do you have any tips on how to proceed with dragging and > > rotating the textcircle? > > I've done this, and as mentioned, Canvas.translate and canvas.rotate > are the way to go. > > If you are just using a hold and drag, you wouldn't have to worry so > much about angular velocity. Code like this would work: > > @Override > public boolean onTouchEvent(MotionEvent e) { > float x = e.getX(); > float y = e.getY(); > switch (e.getAction()) { > case MotionEvent.ACTION_MOVE: > //find an approximate angle between them. > > float dx = x-cx; > float dy = y-cy; > double a=Math.atan2(dy,dx); > > float dpx= mPreviousX-cx; > float dpy= mPreviousY-cy; > double b=Math.atan2(dpy, dpx); > > double diff = a-b; > this.bearing -= Math.toDegrees(diff); > this.invalidate(); > } > mPreviousX = x; > mPreviousY = y; > return true; > } > > Nathan -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: Text in a circle that rotates on touch
I use canvas.rotate(-bearing) *before* drawing - after drawing won't work. I guess that accounts for the negative sign. Nathan On Mar 6, 7:21 am, Bart wrote: > I tested it and it works like a charm :) > I only had to change the "-=" in this.bearing -= Math.toDegrees(diff) > to "+=", otherwise the rotation was inverted. > > How do you do the rotation exactly? If I just draw the text onto the > canvas in onDraw(Canvas canvas), and then call canvas.rotate, then > nothing seems to happen. But if i do canvas.drawBitmap(bitmap, > matrix,paint) where matrix is a rotation matrix, then it does work. -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: Text in a circle that rotates on touch
I tested it and it works like a charm :) I only had to change the "-=" in this.bearing -= Math.toDegrees(diff) to "+=", otherwise the rotation was inverted. How do you do the rotation exactly? If I just draw the text onto the canvas in onDraw(Canvas canvas), and then call canvas.rotate, then nothing seems to happen. But if i do canvas.drawBitmap(bitmap, matrix,paint) where matrix is a rotation matrix, then it does work. -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: Text in a circle that rotates on touch
Thanks alot. I sort of had it working yesterday, but I think my math was a little off, which caused some strange behavior. So I will try your code. On 5 mrt, 22:56, Nathan wrote: > On Mar 5, 3:25 am, Bart wrote: > > > Hi, I'd like to display a given String in a circle (so bend the string > > so that the end of the string touches the beginning of the string). > > And Then I'd like to let the userrotatethe circle by grabbing and > > dragging it clockwise or counterclockwise. > > Do you guys know what would be the best (simplest, smoothest) way to > > do this? I already saw that using drawOnPath i can drawtextin a > > circle. Do you have any tips on how to proceed with dragging and > > rotating the textcircle? > > I've done this, and as mentioned, Canvas.translate and canvas.rotate > are the way to go. > > If you are just using a hold and drag, you wouldn't have to worry so > much about angular velocity. Code like this would work: > > @Override > public boolean onTouchEvent(MotionEvent e) { > float x = e.getX(); > float y = e.getY(); > switch (e.getAction()) { > case MotionEvent.ACTION_MOVE: > //find an approximate angle between them. > > float dx = x-cx; > float dy = y-cy; > double a=Math.atan2(dy,dx); > > float dpx= mPreviousX-cx; > float dpy= mPreviousY-cy; > double b=Math.atan2(dpy, dpx); > > double diff = a-b; > this.bearing -= Math.toDegrees(diff); > this.invalidate(); > } > mPreviousX = x; > mPreviousY = y; > return true; > } > > Nathan -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: Text in a circle that rotates on touch
On Mar 5, 3:25 am, Bart wrote: > Hi, I'd like to display a given String in a circle (so bend the string > so that the end of the string touches the beginning of the string). > And Then I'd like to let the user rotate the circle by grabbing and > dragging it clockwise or counterclockwise. > Do you guys know what would be the best (simplest, smoothest) way to > do this? I already saw that using drawOnPath i can draw text in a > circle. Do you have any tips on how to proceed with dragging and > rotating the textcircle? I've done this, and as mentioned, Canvas.translate and canvas.rotate are the way to go. If you are just using a hold and drag, you wouldn't have to worry so much about angular velocity. Code like this would work: @Override public boolean onTouchEvent(MotionEvent e) { float x = e.getX(); float y = e.getY(); switch (e.getAction()) { case MotionEvent.ACTION_MOVE: //find an approximate angle between them. float dx = x-cx; float dy = y-cy; double a=Math.atan2(dy,dx); float dpx= mPreviousX-cx; float dpy= mPreviousY-cy; double b=Math.atan2(dpy, dpx); double diff = a-b; this.bearing -= Math.toDegrees(diff); this.invalidate(); } mPreviousX = x; mPreviousY = y; return true; } Nathan -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: Text in a circle that rotates on touch
I'm doing something similar in my current app. It might not apply directly because I'm using GL for my drawing and don't have access to the same API calls. An important thing is to remember that the user is moving finger diagonally in some cases, so you need to calculate the angular velocity in order to move in a natural way. A simple way to attempt it would be to treat the user's initial touch point as the source angle, and the current touch-point as a target and then compute the angle to both from the center of your circle - this would allow you to compute the delta angle as they move. With the delta angle you would transform the path each update. If you handle the touch events directly, you will need to be careful as there are MANY events that get sent, and some of the changes are very small. Sometimes you get really large changes as well. You may also want to get the time between events and reject events that happen too rapidly. On Mar 5, 3:25 am, Bart wrote: > Hi, I'd like to display a given String in a circle (so bend the string > so that the end of the string touches the beginning of the string). > And Then I'd like to let the user rotate the circle by grabbing and > dragging it clockwise or counterclockwise. > Do you guys know what would be the best (simplest, smoothest) way to > do this? I already saw that using drawOnPath i can draw text in a > circle. Do you have any tips on how to proceed with dragging and > rotating the textcircle? -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: Text in a circle that rotates on touch
Bart wrote: > Hi, I'd like to display a given String in a circle (so bend the string > so that the end of the string touches the beginning of the string). > And Then I'd like to let the user rotate the circle by grabbing and > dragging it clockwise or counterclockwise. > Do you guys know what would be the best (simplest, smoothest) way to > do this? I already saw that using drawOnPath i can draw text in a > circle. Do you have any tips on how to proceed with dragging and > rotating the textcircle? use Canvas#translate and Canvas#rotate -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en