Not sure if you want it, but here's a bit of code I made thisafternoon... You inspired me, so I'm going to make the same kinda thing... I bet they both turn out really differently
The code isn't commented very well, but you should get the drift of it
Also, the way it works is, you click once to add the start of a bone, click again to add the end of that bone.
To join bones together when making them ( haven't implimented selecting or draging etc ), hold "j" and click near the end of another bone, and they'll be snapped together. Only opposite ends of bones can be joined though.
Sync On : Sync Rate 0
Set Display Mode 800,600,32
Set Window On
Randomize Timer()
#Constant dim1 = 2
#Constant dim2 = 3
Global totalbones As Integer = 0
`The radius of the circle at the end of the Bone
Global ebr As Integer = 2
Global jdist As Integer = 10
Dim bones(30,1,3) As Integer
`Array works like this:
`bones(x,0,0) = X pos of Start of Bone
`bones(x,0,1) = Y pos of Start of Bone
`bones(x,0,2) = Bone Number that start of Bone is attached to ( 0 or null for none )
`bones(x,0,3) = Lenght of line... This just assists in Drawing Speeds.
`bones(x,1,0) = X pos of End of Bone
`bones(x,1,1) = Y pos of End of Bone
`bones(x,1,2) = Bone Number that end of bone is attached to
making = 0
Do
Cls
If MouseClick() = 0
If md = 1
`Do this if Left Mouse Is Released
making = ( making - 1 ) * -1 `just switches the value between 1 and 0
If InKey$() = "j" Then join = 1 Else join = 0
_place_joint(MouseX(),MouseY(),making,join)
md = 0
EndIf
If md = 2
`Do this if Right Mouse Is Released
md = 0
EndIf
Else
If md = 0
md = MouseClick()
EndIf
EndIf
_draw_bones()
Print "Current Bone Info"
Print "StartX = ";Str$(bones(totalbones,0,0))
Print "StartY = ";Str$(bones(totalbones,0,1))
Print "EndX = ";Str$(bones(totalbones,1,0))
Print "EndY = ";Str$(bones(totalbones,1,1))
Print
Print "Total Bones = ";Str$(totalbones)
Print
Print "ReFresh Rate = ";Screen FPS()
If InKey$() = "j" Then Text 0,Screen Height() - 20,"Join Joints Mode"
Sync
Loop
Function _place_joint(x As Integer,y As Integer,start As Integer, join As Integer)
`x is xpos
`y is ypos
`start is wheather or not it's the start or end of a bone, 1 for start, 0 for end.
`join is wheather or not the joint is to be attached to the closest joint, 1 for attach, 0 for dont.
If start
` Array Insert At Bottom bones(0)
totalbones = totalbones + 1
a = 0
Else
a = 1
EndIf
If join
i = _find_closest(x,y,start)
If i <> 0
x = bones(i,start,0)
y = bones(i,start,1)
EndIf
EndIf
bones(totalbones,a,0) = x
bones(totalbones,a,1) = y
bones(totalbones,a,2) = i
If a = 1 Then bones(totalbones,0,3) = Int(Sqrt((x - bones(totalbones,0,0))^2 + (y - bones(totalbones,0,1))^2))
EndFunction
Function _draw_bones()
If totalbones > 0
For i = 1 To totalbones
x1 = bones(i,0,0)
y1 = bones(i,0,1)
x2 = bones(i,1,0)
y2 = bones(i,1,1)
angle = ATanFull(x2 - x1,y2 - y1)
trix2 = NewXValue(x1,angle + 2,bones(i,0,3) - 4)
triy2 = NewZValue(y1,angle + 2,bones(i,0,3) - 4)
trix3 = NewXValue(x1,angle - 2,bones(i,0,3) - 4)
triy3 = NewZValue(y1,angle - 2,bones(i,0,3) - 4)
Circle x1,y1,ebr
Line x1,y1,trix2,triy2
Line trix2,triy2,x2,y2
Line x2,y2,trix3,triy3
Line trix3,triy3,x1,y1
Next i
EndIf
EndFunction
Function _find_closest(x As Integer,y As Integer,start As Integer)
For i = 1 To totalbones
If Abs((bones(i,start,0) - x)*(bones(i,start,0) - x) + (bones(i,start,1) - y)*(bones(i,start,1) - y)) < jdist * jdist
ExitFunction i
EndIf
Next x
EndFunction 0
Have a Good One
Jess.
[EDIT]
And there may be some un-needed commands or lines in there, cos I tend to put in alot of extra stuff for debug purposes.
[/EDIT]
Team EOD :: Programmer/Logical Engineer/All-Round Nice Guy