Jump to content

Photo

How to have an object move in a circle


4 replies to this topic

#1 BNE Jeff OFFLINE  

BNE Jeff

    Chopper Commander

  • 226 posts
  • Location:Virginia, USA

Posted Thu Aug 25, 2016 2:38 AM

Good Morning..

 

If I want to have an object move in a circle, what's the best way to accomplish that?  Can a circle be calculated?  Plotted points on a table?  Something else?



#2 GroovyBee OFFLINE  

GroovyBee

    Games Developer

  • 9,675 posts
  • Busy bee!
  • Location:North, England

Posted Thu Aug 25, 2016 2:43 AM

Use the "C" code from here :-

 

https://en.wikipedia...ircle_algorithm

 

To generate a table of coordinates at the X, Y position and radius you need.



#3 bogax OFFLINE  

bogax

    Dragonstomper

  • 692 posts

Posted Sat Aug 27, 2016 8:28 AM

Use the "C" code from here :-

 

https://en.wikipedia...ircle_algorithm

 

To generate a table of coordinates at the X, Y position and radius you need.

 

Presumably you wont be putting a table in RAM

There are easier ways to generate a table to put in ROM

 

If you mean generating positions on the fly then since you always move one step

in the major direction and sometimes move 0 steps or 1 step in the other direction

I think your speed would vary depending on the angle.

 

If you take 1 pixel in 160 as the minimum tangent ie you're moving in an arc such that

you move eg 160 pixels in the x direction and 1 pixel in the y direction

that's about .36 degrees or about 1/1000 of a circle

if you use a 1 quadrant sine table with linear interpolation and 8 steps per table entry

that's a table with 1000 / ( 4 * 8 ) = ~32 entries

 

But of course you'd use some code (and cycles) doing interpolation and scaling and such

 

That is to say I don't think a sine table itself would take much

whether or not it would be faster or smaller overall would depend on exactly what

you needed to do with it (and you'd still have to determine octants and stuff with

a Bresenham's type algorithm)


Edited by bogax, Sat Aug 27, 2016 8:36 AM.


#4 DanOliver OFFLINE  

DanOliver

    Moonsweeper

  • 311 posts
  • Location:Phoenix AZ

Posted Sat Aug 27, 2016 9:35 AM

Table...simple table. Assuming radius never changes. You can use the math if you want, I wouldn't bother. For example, start with an X,Y table that moves the sprite in a square, pretty easy, radius of say 5 pixels the table might be:

 

{0,-5} , // N

{5,-5} , // NE

{5,0} , // E

{5,5} , // SE

{0,5} , // S

{-5,5} , // SW

{-5,0} , // W

{-5,-5} , // NW

 

Assume bugs in the table, but you get the idea hopefully. The position of the sprite is the center, add each X,Y from the table to get the screen position.

 

To change from a square to a circle you add more entries in the table, 2 entries each for NE,SE,SW,NW while N,E,S,W remain the same. You can use some match if you like, but really you're dealing with low res here so you're only option is 4 instead of 5. See how it looks on screen and tweak as needed. Bigger the circle the smoother the movement because this is all low res.

 

For smaller circles, if you really wanted to get tricky, you might be able to change the sprite art as it goes around to make it look smoother. Depends on the shape you have to work with. I wouldn't bother probably.

 

There's the way you're suppose to do things and there's the getting it done way.


Edited by DanOliver, Sat Aug 27, 2016 9:35 AM.


#5 BNE Jeff OFFLINE  

BNE Jeff

    Chopper Commander

  • Topic Starter
  • 226 posts
  • Location:Virginia, USA

Posted Sun Aug 28, 2016 8:55 AM

Table...simple table. Assuming radius never changes. You can use the math if you want, I wouldn't bother. For example, start with an X,Y table that moves the sprite in a square, pretty easy, radius of say 5 pixels the table might be:

 

{0,-5} , // N

{5,-5} , // NE

{5,0} , // E

{5,5} , // SE

{0,5} , // S

{-5,5} , // SW

{-5,0} , // W

{-5,-5} , // NW

 

OK thanks everybody :)

 

I'm not sure which way to go.

 

I am planning on other movements besides a circle so this might be the way to go.  I can plug in any shape I want this way- correct?

 

The alternative which is scalable is:

 

I don't really need to plot a circle.  I just need to have a position and a bearing for each move I make.

 

The bearing will point to a table which contains proportions of moves that correspond to a full move along the other coordinate for 1/8th of a circle.

 

These results will be translated into the closest matching coordinates for display.

 

Hmm...






0 user(s) are browsing this forum

0 members, 0 guests, 0 anonymous users