| Hi, I've been trying out the code, and i'm fairly confident on how it's working, but could anyone explain this line: 
 
 
 
diff# = ( deltalength - RESTLENGTH ) / (deltalength * ( -p\mass + -p\nxt\mass ) )
 
 What physical quantity does diff# represent?
 
 I've also attempted to modify the code quite significantly (you'll notice my use of arrays, because I'll need them for something else I want to do). It's not working, would anyone mind pointing out anything they see that's wrong with it?
 
 
 
Graphics 640, 480, 16, 0
SetBuffer BackBuffer()
SeedRnd MilliSecs()
TFormFilter False
frameTimer = CreateTimer(60)
timeStep# = 0.016666
g# = 9.81
drag# = 0.995
numLinks = 100
massOfEachLink = 60
restLength# = 20
Type playerType
Field x#, y#, vX#, vY#, aX#, aY#
Field mass#
End Type
player.playerType = New playerType
player\x = 100
player\y = 250
player\mass = 1
Type clawType
Field x#, y#, aX#, aY#
End Type
Type chainLinkType
Field x#, y#, oldX#, oldY#, aX#, aY#, mass#
End Type
Dim chainArray.chainLinkType(numLinks - 1)
For i = 0 To numLinks - 1
  chainArray(i) = New chainLinkType
  chainArray(i)\x = 50 + i * 540 / (numLinks - 1)
  chainArray(i)\y = 50
  chainArray(i)\oldX = chainArray(i)\x
  chainArray(i)\oldY = chainArray(i)\y
  chainArray(i)\mass = massOfEachLink
Next
While Not KeyHit(1)
WaitTimer frameTimer
Cls
  ; Controls
  For i = 0 To numLinks - 1
    ; Apply gravity to particles
    chainArray(i)\aY = chainArray(i)\aY + g / chainArray(i)\mass
    ; Verlet Integration
    tempX# = chainArray(i)\x
    tempY# = chainArray(i)\y
    chainArray(i)\x = chainArray(i)\x * (1 + drag) - drag * chainArray(i)\oldX + chainArray(i)\aX * timeStep * timeStep
    chainArray(i)\y = chainArray(i)\y * (1 + drag) - drag * chainArray(i)\oldY + chainArray(i)\aY * timeStep * timeStep
    chainArray(i)\oldX = tempX
    chainArray(i)\oldY = tempY
    ; Reset acceleration after moving particle
    chainArray(i)\aX = 0 : chainArray(i)\aY = 0
  Next
  ; Make each link experience a force from the surrounding ones
  For i = 0 To numLinks - 2
    temp_dx# = chainArray(i + 1)\x - chainArray(i)\x
    temp_dy# = chainArray(i + 1)\y - chainArray(i)\y
    temp_Separation# = Sqr(temp_dx * temp_dx + temp_dy * temp_dy)
    temp_Extension# = temp_Separation - restLength
    ; Start 
    temp_SpringForce# = temp_Extension / ( temp_Separation * (chainArray(i)\mass + chainArray(i + 1)\mass) )
    chainArray(i)\x = chainArray(i)\x + chainArray(i)\mass * temp_dx * temp_SpringForce
    chainArray(i)\y = chainArray(i)\y + chainArray(i)\mass * temp_dy * temp_SpringForce
    chainArray(i + 1)\x = chainArray(i + 1)\x - chainArray(i + 1)\mass * temp_dx * temp_SpringForce
    chainArray(i + 1)\y = chainArray(i + 1)\y - chainArray(i + 1)\mass * temp_dy * temp_SpringForce
  Next
  chainArray(0)\x = 50
  chainArray(0)\y = 50
  chainArray(numLinks - 1)\x = 590
  chainArray(numLinks - 1)\y = 50
  ; Draw Links
  For i = 0 To numLinks - 1
    Rect chainArray(i)\x, chainArray(i)\y, 1, 1, 1
  Next
Flip
Wend
End
 
 [Edit] Oops, forgot that I was the one that posted last.
 
 
 |