Roku Developer Program

Developers and content creators—a complete solution for growing an audience directly.
cancel
Showing results for
Show  only  | Search instead for
Did you mean:
Level 9

Rotate Center

I need to rotate an object around its own center on roScreen, and math is not my strong suit to say the least.
Wondering if someone has an equation to do this. I'm rotating a spiral on top of a stationary circle (you know, like...groovy?) Both graphics are the same size.
I have this so far which rotates the spiral while rotating around the edge of the circle.

`'circle and spiral are bitmapsrotatespy = rotatespy+1m.screen.drawobject(   x ,   y,  circle)m.screen.DrawRotatedObject( x+(circlewidth/2), y+(circleheight/2),  rotatespy , spiral, &hFF ) `

Thanks
Kinetics Screensavers
13 REPLIES 13\
Level 8

Re: Rotate Center

I take it you want to rotate an arbitrary amount, not just multiples of 90 degrees? In general this is a pretty hard problem, and I doubt you'd be able to implement a solution that performs adequately (sounds like you're doing animation). One approach you might consider is having a set of bitmaps with your image rotated by small amounts, up to 90 degrees. Then you can just display the appropriate image, possibly rotating by 90, 180 or 270 if needed.

--Mark
Level 9

Re: Rotate Center

Yea, I'm rotating by 1 degree at a time so the object is spinning, and it spins nicely (roku3). I'm afraid having that many bitmaps is not a good solution for this.
It's just a math equation to make the upper left point move in a circular path. but its beyond me.
Kinetics Screensavers
Level 8

Re: Rotate Center

Hm, now I'm confused. Are you actually rotating the bitmap, or just changing the position at which it's drawn? If the latter, the solution shouldn't be hard. Just a little trig.

--Mark
Level 9

Re: Rotate Center

"RokuMarkn" wrote:
Hm, now I'm confused. Are you actually rotating the bitmap, or just changing the position at which it's drawn? If the latter, the solution shouldn't be hard. Just a little trig.

--Mark

Yes I am rotating the bitmap in place. Its also true that its flying around the screen while this is happening, but that is a simple matter of adding the x and y of the location to the results of the (as you say) trig problem. I have found this equation:
`x=cos(theta)*radius, y=sin(theta)*radius`
and the BS reference includes cos and sin commands. Is this the right direction to follow?
Kinetics Screensavers
Level 9

Re: Rotate Center

I found this, which is C# to move a point in a circle. Can this be adapted to BS? Since we're stuck with the upper left point as the reference, I need to move that point in a circle with a radius of the object/2 while rotating the object which BS will do for me.

`public static void DrawCircle(int x0, int y0, int radius){  int x = radius;  int y = 0;  int radiusError = 1-x;   while(x >= y)  {    DrawPixel(x + x0, y + y0);    DrawPixel(y + x0, x + y0);    DrawPixel(-x + x0, y + y0);    DrawPixel(-y + x0, x + y0);    DrawPixel(-x + x0, -y + y0);    DrawPixel(-y + x0, -x + y0);    DrawPixel(x + x0, -y + y0);    DrawPixel(y + x0, -x + y0);    y++;    if (radiusError<0)    {      radiusError += 2 * y + 1;    }    else    {      x--;      radiusError += 2 * (y - x + 1);    }  }}`
Kinetics Screensavers
Level 8

Re: Rotate Center

That code is actually drawing a circle. To just move x,y coordinates in a circular path you're better off with your first approach, using sin and cos. You just need to calculate the appropriate angle theta based on the current time and your desired speed of rotation.

--Mark
Level 8

Re: Rotate Center

You need to set your x,y pretranslations
Check out the example on "how to draw a triangle" post
My Channels: 2D API Framework Presentation: https://owner.roku.com/add/2M9LCVC
Updated: 11-11-2015 - Completed Keyboard interface
The Joel Channel ( Final Beta )
Level 8

Re: Rotate Center

viewtopic.php?f=34&t=68705
My Channels: 2D API Framework Presentation: https://owner.roku.com/add/2M9LCVC
Updated: 11-11-2015 - Completed Keyboard interface
The Joel Channel ( Final Beta )
Level 9

Re: Rotate Center

"NewManLiving" wrote:
You need to set your x,y pretranslations
Check out the example on "how to draw a triangle" post

As usual you are right! I wasn't using regions, so once I did that the pretranslation became an option. Thank you.
this rotates the bitmap on it's center in the center of the screen.

`x = 250  :  y = 250sx = 440  :   sy = 110spiral=   '500x500 bitmaptheta = theta+1region = CreateObject( "roRegion", spiral, 0, 0, 500, 500 )region.SetPretranslation( -x, -y )m.screen.DrawRotatedObject( sx + x, sy + y, theta, region )`
Kinetics Screensavers