framework brl.glmax2d Type position Global rootlist:Tlist Field x:Float=0.0,y:Float=0.0 Field radius:Float=0.0,angle:Float=0.0 Field root:position=Null,parent:position=Null Field child:Tlist = CreateList() Function Create:position(x:Float,y:Float,parent:position=Null) 'create a new position object and attatch it to the correct list Local position:position = New position 'setup position.x = x position.y = y 'check if this position should be parented to another position If parent <> Null 'insert into parent child list ListAddLast(parent.child,position) 'set parent link position.parent = parent 'set root link position.root = parent.root 'calulate initial angle and raidus of child position.CalculateVector() Else 'insert into global list ListAddLast(position.rootlist,position) 'set root link to self position.root = position End If 'return created position Return position End Function Method New() 'check to see if rootlist needs to be initiated If position.rootlist = Null position.rootlist = CreateList() End Method Method Turn(angle:Float) For Local child:position = EachIn Self.child child.angle:+angle child.x = Self.x+Cos(child.angle)*child.radius child.y = Self.y+Sin(child.angle)*child.radius child.Turn(angle) Next End Method Method Update() 'update for this position If Self.parent DrawLine Self.x,Self.y,Self.parent.x,Self.parent.y DrawOval Self.x-5,Self.y-5,10,10 'update children of position For Local child:position = EachIn Self.child child.Update() Next End Method Method CalculateVector() 'calculate radius and angle based on parent -> self offset Self.angle:Float = ATan2(Self.y-Self.parent.y,Self.x-Self.parent.x) If Self.angle < 0 Self.angle = 360:Float + Self.angle Self.radius:Float = Sqr((Self.x-Self.parent.x)^2 + (Self.y-Self.parent.y)^2) End Method End Type Graphics 640,480,32,60 parent:position = position.create(320,240) child1:position = position.create(320,140,parent) child1ofchild1:position = position.create(320,90,child1) child2ofchild1:position = position.create(270,140,child1) child3ofchild1:position = position.create(370,140,child1) child4ofchild1:position = position.create(320,190,child1) child2:position = position.create(220,240,parent) child1ofchild2:position = position.create(220,190,child2) child2ofchild2:position = position.create(170,240,child2) child3ofchild2:position = position.create(270,240,child2) child4ofchild2:position = position.create(220,290,child2) child3:position = position.create(420,240,parent) child1ofchild3:position = position.create(420,190,child3) child2ofchild3:position = position.create(370,240,child3) child3ofchild3:position = position.create(470,240,child3) child4ofchild3:position = position.create(420,290,child3) child4:position = position.create(320,340,parent) child1ofchild4:position = position.create(320,290,child4) child2ofchild4:position = position.create(270,340,child4) child3ofchild4:position = position.create(370,340,child4) child4ofchild4:position = position.create(320,390,child4) While KeyHit(KEY_ESCAPE) = False Cls parent.Turn(1) child1.Turn(-2) child2.Turn(-2) child3.Turn(-2) child4.Turn(-2) parent.Update() Flip Wend
Rotating groups of objects?
BlitzMax Forums/BlitzMax Programming/Rotating groups of objects?The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.