Ainakin Aavesoturin vanhoille foorumeilla postaama luurankomato -ohjelma oli melko hidas, vaikka siinä liikuteltiin vain yhtä yksinkertaista ragdoll-matoa. Esimerkiksi kuudella ympäri kenttää hyppivällä ragdoll-Marinella peli hidastuisi luultavasti melko radikaalisti.programmer of DSG wrote:En usko, että ne ragdoll animaatiot olisi liian raskaita, koska olen itse joskus tehnyt sellaista.
Voisitko antaa jonkinlaisen koodinpätkän, jossa havainnollistaisit sitä tekemääsi ragdoll-animaatiosysteemiä?
Tässä on siis tämä Aavesoturin "luurankomato":
Code: Select all
// BONE WORM //
// VERSION: 0.9 / 2005 //
// AUTHOR: Tapio Vierros //
// LICENSE: Free to use //
SCREEN 800,600
SetWindow "Bone Worm Demo - by Aavesoturi 2005"
FrameLimit 40
Dim booleanstring(1) As String 'string array for displaying boolean values
booleanstring(0) = "False"
booleanstring(1) = "True"
'Some constants
Const grav# = 9.81 'gravity g = 9.81 m/s^2
Const maxjoints = 7 'number of bones
Const radius# = 5 'radius of the circle
Const length# = 40 'ideal length
Const diff# = 3 'how much the length can vary
Const amo# = 6 'how much the length is adjusted at one time
Dim joints(maxjoints,2) As Float 'array holds the coordinates of the joints
'Initialize joints' coordinates
For i = 0 To maxjoints
joints(i,0) = 1 'mass
joints(i,1) = ScreenWidth()/2 - (length*i) 'xcor
joints(i,2) = ScreenHeight()/2 'ycor
Next i
ShowMouse ON
PositionMouse ScreenWidth()/2, ScreenHeight()/2
gravity = False 'gravity is off for default
// MAIN LOOP //
Repeat
If MouseHit(2) Then gravity = Not gravity
'Move MasterJoint to mouse and draw it
joints(0,1) = MouseX()
joints(0,2) = MouseY()
Color 255,0,0
Circle joints(0,1)-radius, joints(0,2)-radius, 2 * radius
// LOOP THROUGH OTHER JOINTS //
For i = 1 To maxjoints
If gravity = True And joints(i,2) < ScreenHeight()-(radius*2)-(grav * joints(i,0)) Then joints(i,2) = joints(i,2) + (grav * joints(i,0))
checkdist:
dist# = Distance(joints(i,1), joints(i,2), joints(i-1,1), joints(i-1,2))
'Check if it differs enough from the ideal length
If dist > length + diff Then 'too far away!
a# = GetAngle(joints(i,1), joints(i,2), joints(i-1,1), joints(i-1,2)) 'get angle to previous joint
joints(i,1) = joints(i-1,1) + Cos(a+180) * length 'adjust coordinates to the ideal length
joints(i,2) = joints(i-1,2) - Sin(a+180) * length
If joints(i,2) > ScreenHeight()-(radius*2) Then joints(i,2) = ScreenHeight()-(radius*2): GoTo checkdist
ElseIf dist < length - diff Then 'too close!
a# = GetAngle(joints(i,1), joints(i,2), joints(i-1,1), joints(i-1,2)) 'get angle to previous joint
joints(i,1) = joints(i,1) + Cos(a+180) * amo 'make the joint back away a bit
joints(i,2) = joints(i,2) - Sin(a+180) * amo
If joints(i,2) > ScreenHeight()-(radius*2) Then joints(i,2) = ScreenHeight()-(radius*2): GoTo checkdist
EndIf
'Draw bones & joints
Color 0,255,0
Line joints(i,1), joints(i,2), joints(i-1,1), joints(i-1,2)
Color 255,0,0
Circle joints(i,1)-radius, joints(i,2)-radius, 2 * radius
Next i
// END OF JOINT LOOP //
'Display some info
Color cbOrange
Text 10,10,"Right Click to toggle gravity: " + booleanstring(gravity)
Text 10,25,"FPS: "+FPS()
DrawScreen
Forever
// END OF MAIN LOOP //
Mulla taitaa olla sitten hidas kone, kun FPS laskee aina sinne 30 paikkeille kun matoa vähänkin liikuttelee... :\[/edit]Sami The Great wrote:Ei tuo mato esimerkki minulla pätkinyt yhtään vaikka laitoin tuohon 100 tuollaista nivel kohtaa. FPS oli koko ajan 40