Help me math better - trig help needed
BlitzMax Forums/BlitzMax Programming/Help me math better - trig help needed
| ||
Hey guys. I have here a simple pixel moving in a circle, with a line indicating its original starting point. Strict Graphics(640, 480, 0) Global mover:tMovingObj = New tMovingObj FlushKeys() Delta.Start() While Not GetChar() Delta.Update() mover.update() Cls mover.draw() Flip(0) Wend End Type tMovingObj Global x:Float Global xOrigin:Float Global y:Float Global yOrigin:Float Global ctr:Float Global speed:Float Method New() x = 320 xOrigin = x y = 240 yOrigin = y ctr = 0 speed = 200 End Method Method update() x:-Cos(ctr) * speed * Delta.Time() y:+Sin(ctr) * speed * Delta.Time() ctr:+(speed * Delta.Time()) End Method Method draw() Plot(x, y) Plot(xOrigin, yOrigin) DrawLine(xOrigin, yOrigin, x, y) DrawText("x="+x+", y="+y, 0, 11) End Method End Type Type Delta Abstract Global DeltaTime:Float Global TimeDelay:Int Global DeltaSpeed:Float = 0.001 Function Start() TimeDelay = MilliSecs() End Function Function Time:Float() Return DeltaTime End Function Function Update() DeltaTime = ( MilliSecs()- TimeDelay ) * DeltaSpeed TimeDelay = MilliSecs() EndFunction End Type Pretty straightforward. I need some help predicting the motion and my trig game is weak. Currently, I set a starting point and the object moves in a circle starting from that point. The size of the circle is determined arbitrarily, by increasing the ctrvariable. What I need is to be able to specify a point and instead have the object circle around that point at a specified radius. It's a pretty big change from what I have here. Can anyone help? Many thanks. |
| ||
Figured it out. Been too many years since I used this.Method update() x = xOrigin + Sin(ctr) * 10 y = yOrigin + Cos(ctr) * 10 ctr:+(speed * Delta.Time()) End Method |