Developers and content creators—a complete solution for growing an audience directly.

Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

- Roku Community
- :
- Developers
- :
- Roku Developer Program
- :
- Rotate Center

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

Highlighted
##

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.

Thanks

squirreltown

Level 9

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

12-11-2014
08:35 AM

Rotate Center

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 bitmaps

rotatespy = rotatespy+1

m.screen.drawobject( x , y, circle)

m.screen.DrawRotatedObject( x+(circlewidth/2), y+(circleheight/2), rotatespy , spiral, &hFF )

Thanks

Kinetics Screensavers

13 Replies

Highlighted
##

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

RokuMarkn

Level 7

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

12-11-2014
09:18 AM

Re: Rotate Center

--Mark

Highlighted
##

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.

squirreltown

Level 9

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

12-11-2014
09:30 AM

Re: Rotate Center

It's just a math equation to make the upper left point move in a circular path. but its beyond me.

Kinetics Screensavers

Highlighted
##

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

RokuMarkn

Level 7

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

12-11-2014
09:44 AM

Re: Rotate Center

--Mark

Highlighted
##

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:

squirreltown

Level 9

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

12-11-2014
09:52 AM

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)*radiusand the BS reference includes cos and sin commands. Is this the right direction to follow?

Kinetics Screensavers

Highlighted
##

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.

squirreltown

Level 9

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

12-11-2014
09:58 AM

Re: Rotate Center

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

Highlighted
##

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

RokuMarkn

Level 7

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

12-11-2014
10:10 AM

Re: Rotate Center

--Mark

Highlighted
##

You need to set your x,y pretranslations

Check out the example on "how to draw a triangle" post

NewManLiving

Level 7

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

12-11-2014
10:46 AM

Re: Rotate Center

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 )

Updated: 11-11-2015 - Completed Keyboard interface

The Joel Channel ( Final Beta )

Highlighted
##

viewtopic.php?f=34&t=68705

NewManLiving

Level 7

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

12-11-2014
10:48 AM

Re: Rotate Center

My Channels: 2D API Framework Presentation: https://owner.roku.com/add/2M9LCVC

Updated: 11-11-2015 - Completed Keyboard interface

The Joel Channel ( Final Beta )

Updated: 11-11-2015 - Completed Keyboard interface

The Joel Channel ( Final Beta )

Highlighted
##

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.

squirreltown

Level 9

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

12-11-2014
11:22 AM

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 = 250

sx = 440 : sy = 110

spiral= '500x500 bitmap

theta = theta+1

region = CreateObject( "roRegion", spiral, 0, 0, 500, 500 )

region.SetPretranslation( -x, -y )

m.screen.DrawRotatedObject( sx + x, sy + y, theta, region )

Kinetics Screensavers