Page 1 of 1

Making something move in a circle.

Posted: Thu Oct 07, 2004 4:50 pm
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 ?! ;)

Posted: Thu Oct 07, 2004 5:07 pm
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.

Posted: Thu Oct 07, 2004 5:47 pm
by DriakTravo
8O

/me is confused

Posted: Thu Oct 07, 2004 6:56 pm
by dontmailme
Try looking at the math.pb in the HTML helpfile that fred provides for you :lol:

Posted: Thu Oct 07, 2004 8:42 pm
by DriakTravo
OOOOHHHH! Ok I see now. Thanks for the tip ;P

Posted: Thu Oct 07, 2004 10:12 pm
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).

Posted: Fri Oct 08, 2004 3:15 pm
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

Posted: Fri Oct 08, 2004 5:20 pm
by dontmailme
Nice :)

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

:D