Latest UploadsPlatdude SpottingJayenkaiNom nom nomJayenkaiRainbow TroutPakzKing SalmonPakzSnookerJayenkaiYou've ... o have youJayenkai
 Code Snippets > Collisions and Physics ( Created 12 September 2010 | Last Edited 12 September 2010)

 Soft Body Physics by Scherererer | No VotesSimple demo of roughly how soft bodies work Written inBlitz This demo is very rudimentary, but basically it demonstrates kind of how soft bodies work. The basic idea is to pretend that the lines connecting vertices have on them a spring and a damper. Then, when a force is exerted on some point (or series of points), that force can be reflected across the other points. More points means more realistic looking surfaces. Spring coefficient [0,1]: higher number->more spring, lower number->less spring Damping coefficient [0,1]: higher number->more damping; not to be confused with less springyness. "spring" resists displacement, whereas "damping" resists change in displacement (velocity). The forces applied effect the change in the change in displacement (change in velocity (acceleration)) See Calculus:erivatives and Wikipedia: Damping for more on this. The spring/dampers in this example are only connected along the square "grid" lines, however in typical/modern configurations, additional connections are made on the diagonals and over other points to compensate for polygon folding and other issues. Const Mass = 1 Const K# = .5 Const Cd# = .5;.8 Global F1# = 2, F2# = 1 Const dt# = .1 Graphics3D 800,600,32,2 Type Vertex Field v Field x#, y#, z# Field xd#, yd#, zd# Field xdd#, ydd#, zdd# End Type m=CreateMesh() s=CreateSurface( m ) Dim verts.Vertex(4,5) i=0 For r=0 To 3 For c=0 To 4 verts(r,c) = New Vertex verts(r,c)\x = r verts(r,c)\y = c AddVertex s, r, c, 0 verts(r,c)\v = i VertexColor s, verts(r,c)\v, Rnd(0,255), Rnd(0,255), Rnd(0,255) i = i + 1 Next Next For r=0 To 2 For c=0 To 3 AddTriangle s, verts(r,c)\v, verts(r,c+1)\v, verts(r+1,c+1)\v AddTriangle s, verts(r,c)\v, verts(r+1,c+1)\v, verts(r+1,c)\v Next Next EntityFX m, 2 light = CreateLight(2) camera = CreateCamera() MoveEntity camera, -.1, -.1, -3 TurnEntity camera, -20, -20, 0 While (Not KeyDown(1)) For r=1 To 2 For c=1 To 3 v.Vertex = verts(r,c) v\xdd = K*(DiplacementX#(r, c)) + Cd*(DiplacementXD#(r, c)) v\ydd = K*(DiplacementY#(r, c)) + Cd*(DiplacementYD#(r, c)) v\zdd = K*(DiplacementZ#(r, c)) + Cd*(DiplacementZD#(r, c)) If (c = 2 And r = 1) v\zdd = v\zdd + F1 EndIf If (c = 2 And r = 2) v\zdd = v\zdd + F2 EndIf v\xd = v\xd + v\xdd*dt v\yd = v\yd + v\ydd*dt v\zd = v\zd + v\zdd*dt v\x = v\x + (v\xd)*dt v\y = v\y + (v\yd)*dt v\z = v\z + (v\zd)*dt VertexCoords s, v\v, v\x, v\y, v\z Next Next If (KeyDown(200)) F1 = F1 + .1 ElseIf (KeyDown(208)) F1 = F1 - .1 EndIf UpdateWorld RenderWorld Text 0,00,"Force 1: " + F1 Text 0,13,"Force 2: " + F2 Text 0,26,"Spring Coeff: " + K Text 0,39,"Damping Coeff: " + Cd VWait : Flip False Wend Function DiplacementX#(r%, c%) Return verts(r+1,c)\x + verts(r-1,c)\x + verts(r,c+1)\x + verts(r,c-1)\x - (verts(r,c)\x*4) End Function Function DiplacementY#(r%, c%) Return verts(r+1,c)\y + verts(r-1,c)\y + verts(r,c+1)\y + verts(r,c-1)\y - (verts(r,c)\y*4) End Function Function DiplacementZ#(r%, c%) Return verts(r+1,c)\z + verts(r-1,c)\z + verts(r,c+1)\z + verts(r,c-1)\z - (verts(r,c)\z*4) End Function Function DiplacementXD#(r%, c%) Return verts(r+1,c)\xd + verts(r-1,c)\xd + verts(r,c+1)\xd + verts(r,c-1)\xd - (verts(r,c)\xd*4) End Function Function DiplacementYD#(r%, c%) Return verts(r+1,c)\yd + verts(r-1,c)\yd + verts(r,c+1)\yd + verts(r,c-1)\yd - (verts(r,c)\yd*4) End Function Function DiplacementZD#(r%, c%) Return verts(r+1,c)\zd + verts(r-1,c)\zd + verts(r,c+1)\zd + verts(r,c-1)\zd - (verts(r,c)\zd*4) End Function -->

Posted : Sunday, 12 September 2010, 23:48
Jayenkai

ooooh, bouncy!

-=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- (c) WidthPadding Industries 1987 619|0 -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=-
 Latest PostsTechnology on Planes therevillsgames Sat 17:00 Laptop Aaargh... Jayenkai Sat 15:18 London Car/Stab Incident steve_ancell Sat 12:10 A New Korg Gadget! Jayenkai Sat 04:53 GamerBlock rockford Fri 16:51 Happy Birthday, Spinal Jayenkai Fri 08:40 Watch Switch - Fitbit Blaze rockford Fri 03:52 Happy Birthday Evil Roy Ferguson rockford Wed 16:21 Spinal's Return to Android Jayenkai Tue 13:41 AGameAWeek : 2017 - Part One Jayenkai Tue 08:10 More

 Latest Items Blog : My Arduino experience.steve_ancell Fri 13:45 Snippet : Skylinesspinal Fri 06:13 Showcase : Infinitronrychan Tue 03:02 Dev-Diary : PS2 to N64 Adapterspinal Sun 10:49 Link : Vector Tutorials/Help page.Pakz Thu 23:00 Blog : mini projectspinal Sun 10:13 Showcase : Blockman ReturnsJayenkai Fri 03:04 Snippet : Wall Tracing on Random Maps (rpg)rskgames Wed 22:48 Snippet : Path FollowingPakz Mon 16:25 Snippet : Flowers (Jan 2017)Kuron Thu 01:13 Showcase : Clusters of Hextherevillsgames Mon 15:01 Article : Maths 101 - Episode 1: Basic Trigonometryshroom_monk Sun 14:07 Article : Maths 101 - Episode 5: Line Intersectionshroom_monk Sun 14:02 Dev-Diary : Normals and Dot productsPakz Sat 20:37 Pets : Molly On The CouchJayenkai Thu 04:32More

Who's Online
rskgames
Sat, at 19:26
Jayenkai
Sat, at 19:04
Evil Roy Ferguson
Sat, at 17:19
therevillsgames
Sat, at 17:00
steve_ancell
Sat, at 16:03
rockford
Sat, at 15:39
spinal
Sat, at 14:59
Sat, at 14:16
Pakz
Sat, at 13:27
rychan
Sat, at 08:09