Circle trajectory

BlitzMax Forums/BlitzMax Beginners Area/Circle trajectory

hub(Posted 2006) [#1]
Hi !
This should be easy but i'm crap with maths. I just want that my sprite follow a circle trajectory, and set the movement speed ! (clockwise or anticlockwize). Cos and sin formulae ?


Dreamora(Posted 2006) [#2]
Right :-)

x# = cos(angle) * radius
y# = sin(angle) * radius

' Speed is defined as circular rotations per second so half a circle per second means 0.5
angle :+ speed#*360.0/fps


hub(Posted 2006) [#3]
Thanks dreamora

Strict

Graphics 800,600,32,60

Const CTE_FPS = 60

Global Liste_boulets : TList = CreateList()

Type TBoulet 

	Field x#
	Field y#
	Field CentreX
	Field CentreY
	Field Rayon
	Field angle
	Field Vitesse#
	
	Function Creer:TBoulet(x:Int, y:Int, Rayon:Int, Vitesse:Float)
	
		Local b:Tboulet = New TBoulet
		
		b.CentreX = x
		b.CentreY = y
		b.Rayon   = Rayon
		b.Angle = 0
		b.Vitesse = Vitesse
		
		ListAddLast Liste_boulets, b
		
		Return b
		
	End Function
	
	Method Maj()
	
		Angle = Angle + Vitesse#*360.0/CTE_FPS
	
		x# = Cos(Angle) * Rayon
		y# = Sin(Angle) * Rayon
		
		SetColor 0,0,255
		SetLineWidth 4
		DrawLine CentreX, CentreY, CentreX + x, CentreY + y
		SetColor 255,0,0
		DrawOval CentreX + x-20,CentreY + y-20,40,40
	
	End Method
	
End Type

Local b1:TBoulet = TBoulet.Creer (GraphicsWidth()/2, GraphicsHeight()/2, 200, 0.25)

Local b2:TBoulet = TBoulet.Creer (GraphicsWidth()/2-100, GraphicsHeight()/2+100, 100, -0.40)


While Not KeyDown(KEY_ESCAPE)
	Cls
	b1.Maj()
	b2.Maj()
	Flip

Wend