Making something move in a circle.

Just starting out? Need help? Post your questions and find answers here.
DriakTravo
Enthusiast
Enthusiast
Posts: 346
Joined: Fri Oct 10, 2003 12:42 am
Location: Tampa,FL,USA
Contact:

Making something move in a circle.

Post by DriakTravo »

I want to make something move in a circular motion. I want to know if there is an easier, less complicated way of doing so than this:

Creating 2 variables for the position of the object, one X and one Y
Have the X move back and fourth like a pendeulum and the Y move up and down the same way. I would have to have it accelerate and decelerate aslo and I would have to start the x direction all the way to one side and the Y in the middle and UGH! It is all so confusing.

A little help please ?! ;)
aaron_at_work
User
User
Posts: 11
Joined: Tue Jun 01, 2004 7:24 pm

Post by aaron_at_work »

Use polar coordinates (angle and distance from centre of circle) + an angular velocity (+ for clockwise motion and - for counterclockwise motion). in your main program. That way it makes it easy to imagine where and what your 'something' is doing at any particular time. Then write a function which converts from polar to rectangular coordinates (just use sin and cos to quickly convert) and use those coordinates to plot the object.
DriakTravo
Enthusiast
Enthusiast
Posts: 346
Joined: Fri Oct 10, 2003 12:42 am
Location: Tampa,FL,USA
Contact:

Post by DriakTravo »

8O

/me is confused
dontmailme
Enthusiast
Enthusiast
Posts: 537
Joined: Wed Oct 29, 2003 10:35 am

Post by dontmailme »

Try looking at the math.pb in the HTML helpfile that fred provides for you :lol:
Paid up PB User !
DriakTravo
Enthusiast
Enthusiast
Posts: 346
Joined: Fri Oct 10, 2003 12:42 am
Location: Tampa,FL,USA
Contact:

Post by DriakTravo »

OOOOHHHH! Ok I see now. Thanks for the tip ;P
MrMat
Enthusiast
Enthusiast
Posts: 762
Joined: Sun Sep 05, 2004 6:27 am
Location: England

Post by MrMat »

In math.pb, you could change

Code: Select all

x2.f = X*Cos(a) + Y*Sin(a)
y2.f = X*Sin(a) - Y*Cos(a)
to

Code: Select all

x2.f = X*Cos(a)
y2.f = X*Sin(a)


so that the radius of the circle is given by X instead of sqrt(X^2+Y^2).
DriakTravo
Enthusiast
Enthusiast
Posts: 346
Joined: Fri Oct 10, 2003 12:42 am
Location: Tampa,FL,USA
Contact:

Post by DriakTravo »

hehe thanks

Code: Select all

InitSprite()
InitSprite3D()
InitKeyboard()

OpenScreen(800,600,16,"")

ClearScreen(200,0,0)
GrabSprite(0,0,0,16,16,#PB_Sprite_texture)
CreateSprite3D(0,0)

Structure thing
  X.f
  Y.f
  Fade.l
  Size.l
EndStructure

Global X2.f
Global Y2.f
X2.f = 100
Y2.f = 100
A.f = 0
R = 5

NewList thing.thing()

Procedure Addthing(X,Y)
  AddElement(Thing())
  Thing()\X = X
  Thing()\Y = Y
  Thing()\Fade = 255
  Thing()\Size = 1
EndProcedure

Procedure UpdateThing()
  If CountList(Thing()) > 0
    ResetList(Thing())
    While NextElement(Thing())
      Thing()\X - 1
      Thing()\Y - 1
      Thing()\Fade - 3
      thing()\Size + 2
      If Thing()\Fade < 10
        DeleteElement(Thing())
        Continue
      EndIf
      ZoomSprite3D(0,thing()\Size,Thing()\size)
      DisplaySprite3D(0,Thing()\X,Thing()\Y,Thing()\Fade)
    Wend
  EndIf
EndProcedure

Repeat
  ClearScreen(0,0,0)
  
  Start3D()
    Updatething()
  Stop3D()
  Addthing(x2+400+Random(10)-5,y2+300+Random(10)-5)
  a.f+0.1
        
  x2.f = 200*Cos(a) 
  y2.f = 200*Sin(a)
  
  FlipBuffers()
  ExamineKeyboard()
  If KeyboardPushed(#PB_Key_Escape)
    End
  EndIf
ForEver
dontmailme
Enthusiast
Enthusiast
Posts: 537
Joined: Wed Oct 29, 2003 10:35 am

Post by dontmailme »

Nice :)

Now add another going the other way... and so on, and soon we'll have a truly psychedelic display 8O

:D
Paid up PB User !
Post Reply