hopefully this isnt too much to ask, and ive seen all that great 3d verlet stuff from you lot... so i was hoping that you might be able to implement collisions in this for me? i really dont have a clue where to start. its taken from the article on gamasutra, and it seems to work ok...
thanks
thanks
Graphics 800,600,0,2 SetBuffer BackBuffer() Const TIMESTEP# = 0.05 Const ITERATIONS = 5 Type particle Field x#,y# Field oldx#,oldy# Field xvel#,yvel# Field xacc#,yacc# Field mass# End Type Type link Field p0.particle Field p1.particle Field length# End Type a.particle = particle(400-100,300-50) b.particle = particle(400-50,300+50) c.particle = particle(400+50,300+50) d.particle = particle(400+50,300-50) link a,b,100 link b,c,100 link c,d,100 link d,a,100 link a,c,Sqr(100^2 + 100^2) link b,d,Sqr(100^2 + 100^2) While Not KeyHit(1) Cls Verlet SatisfyConstraints RenderParticles RenderLinks ApplyGlobalAcc 0,10 If MouseDown(1) a\x = MouseX() a\y = MouseY() End If Flip Wend End Function Particle.particle(x#,y#,mass#=0.1) p.particle = New particle p\x = x p\y = y p\oldx = p\x p\oldy = p\y p\mass = mass Return p End Function Function Link.link(p0.particle,p1.particle,Length#=10) l.link = New link l\p0 = p0 l\p1 = p1 l\length = length Return l End Function Function ApplyGlobalAcc(x#,y#) For p.particle = Each particle p\xacc = x p\yacc = y Next End Function Function Verlet() For p.particle = Each particle tmpX# = p\x# tmpY# = p\y# p\x# = tmpX# + tmpX# - p\oldx# + p\xacc# * TIMESTEP# * TIMESTEP# p\y# = tmpY# + tmpY# - p\oldy# + p\yacc# * TIMESTEP# * TIMESTEP# p\oldx# = tmpX# p\oldy# = tmpY# Next End Function Function SatisfyConstraints() For j = 1 To ITERATIONS For p.particle = Each particle If p\x < 50 Then p\x = 50 If p\y < 50 Then p\y = 50 If p\x > 750 Then p\x = 750 If p\y > 550 Then p\y = 550 Next For l.link = Each link delX# = l\p1\x - l\p0\x delY# = l\p1\y - l\p0\y deltalength# = Sqr(delX * delX + delY * delY) diff# = (deltalength# - l\length#) / (deltalength# * (-l\p0\mass# + -l\p1\mass#)) l\p0\x# = l\p0\x# + delX# * -l\p0\mass# * diff# l\p0\y# = l\p0\y# + delY# * -l\p0\mass# * diff# l\p1\x# = l\p1\x# - delX# * -l\p1\mass# * diff# l\p1\y# = l\p1\y# - delY# * -l\p1\mass# * diff# Next Next End Function Function RenderParticles() For p.particle = Each particle Oval p\x-4,p\y-4,8,8 Next End Function Function RenderLinks() For l.link = Each link Line l\p0\x,l\p0\y,l\p1\x,l\p1\y Next End Function