Chain physics!

Blitz3D Forums/Blitz3D Programming/Chain physics!

JoshK(Posted 2003) [#1]
Wow. I never thought this would work. Just follow the instructions on the screen and move and dangle the chain. Making a body out of these would be no big deal. The last step would be angle constraints.

No source yet, until I figure out what I'm going to do with this:

http://www.leadwerks.com/storage/physics.zip


Peer(Posted 2003) [#2]
Looking greate!


SSS(Posted 2003) [#3]
very cool :D


EOF(Posted 2003) [#4]
Sweet. I like the way you can wrap the chained object around the pipe.
Making a body out of these would be no big deal
Halo, by this do you mean a kind of skeleton framework which matches the objects shape?
Have you ever seen the Actor demo?
Would be great to have a similar physics demo in Blitz.

www.vividimage.co.uk [Actor]


Sunteam Software(Posted 2003) [#5]
Very nice, I'm going to need to do the same sort of algo for our rpg we are doing. If you'd like to share your code I'd be very happy to credit you (mike@...).


Zenith(Posted 2003) [#6]
Haha that's pimped out!


JoshK(Posted 2003) [#7]
I resolved some problems with bouncing/sliding, and the physics appear to be perfect. Going to add two features, and maybe release it as commercial physics code for Blitz.

First, I need to add arbitrary shapes made up of spheres. I made these out of chains, but I think a new routine should be written for handling these separately. Also note that chains can be connected in any kind of branching fashion.

I personally can't wait to see it when you can bump into a length of tubing suspended from the ceiling at both ends, and watch it sway back and forth.

Second, joint constraints need to be added, so you can do those cool ragdoll physics. This would be an incredible challenge before I wrote this, but now that I have it, only a small bit of code needs to be changed to handle this.


Not Available(Posted 2003) [#8]
Halo,

I've posted this, however looking at what you're doing you might be able to help me...

In the old 8bit Thrust you'll remember that Orb that you pick up and how it exerted it's force on your ship. It's essentially 1 point mass connected to another by an inelastic rod. I imagine it's pretty much the same thing that you're using to do your chain...

I'm wondering how one would go about simulating this given the following variables:

General:
g# gravity constant

Your ship:
X# x position
Y# y position
XV# x velocity
YV# y velocity
M# mass

The orb:
oX# x position
oY# y position
oXV# x velocity
oYV# y velocity
oM# mass

Rope/Bar/Connecting thing that connects ship to orb:
d# length
rM# rope mass (if you want to get pedantic, though probably not really relevant)

It's like a pendulum attached to an asteroids ship, swinging around you when you thrust around the place.

Halo - if you could help me with this you'd be my hero (or not-- whatever you prefer) :)

-R


Anthony Flack(Posted 2003) [#9]
It rocks.


JoshK(Posted 2003) [#10]
I never played that game. I really have no idea what you're asking me.


Not Available(Posted 2003) [#11]
Halo,

Imagine the triangle ship in Asteroids where you can rotate and thrust, now picture pendulum attached to the ship. A line from the centre of the little triangle ship connecting it to a circle. The circle has mass a little heavier than the ship and the pendulum connected to the middle of the ship can rotate 360 degrees with freedom. (this is all 2D)

So when you thrust, the pendulum exerts it's force on the ship and swings around.

-SIMPLE DIAGRAM-

1 At rest in space.

^ Ship
| Connecting Rod
* Heavy Ball, orb or whatever.

2 Turn right and thrust, ball swings to left (and pulls ship down diagonally as it swings)

>
/
*

3 Keep thrusting right, ball is pulled up behind you.

*->


Does that make it clearer for you?

If not I can upload a diagram.

-R


Dock(Posted 2003) [#12]
This would be ideal for plaited hair physics, for 3D characters. ^_^ Nice work Halo!


Chroma(Posted 2003) [#13]
Looks great!


JoshK(Posted 2003) [#14]
If you can, more power to you.


Not Available(Posted 2003) [#15]
Halo,

Thanks for your replies, however it looks like I'm getting the answer from elsewhere - not to waste your time.

Thanks again,
-R


nazca(Posted 2003) [#16]
really cool. Nice job!


DarkEagle(Posted 2003) [#17]
where did you learn this? url or isbn please?


Zenith(Posted 2003) [#18]
He might have well written it himself, but you're best bet on learning it easily would be at: http://freespace.virgin.net/hugo.elias/models/m_main.htm

Under Strings, :) (BASIC code is used, too) Ofcoarse, these are 2d strings, but you would just have to apply more to it.


DarkEagle(Posted 2003) [#19]
Graphics 800,600,0,2
SetBuffer BackBuffer()

Dim String1#(31,1)
Dim String2#(31,1)
Dim Velocity#(31,1)

Const X = 0
Const Y = 1

Const normal_length# = 11
Const damping# = 0.97

For i = 0 To 31
	String1(i,X) = 400+i*3
	String1(i,Y) = i*11
Next

While Not KeyHit(1)
Cls

	For i = 0 To 30
		dx1# = GetDiff(i-1,i,X)
		dy1# = GetDiff(i-1,i,Y)
		mag1# = Length(dx1,dy1)
		ext1# = mag1# - normal_length#
	
		dx2# = GetDiff(i,i+1,X)
		dy2# = GetDiff(i,i+1,Y)
		mag2# = Length(dx2,dy2)
		ext2# = mag2# - normal_length#
	
		xvel# = (dx1 / (mag1 * ext1)) + (dx2 / (mag2 * ext2))
		yvel# = (dy1 / (mag1 * ext1)) + (dy2 / (mag2 * ext2)) + 10	;gravity
		
		Velocity#(i,X) = Velocity#(i,X) * damping# + (xvel# * 0.001)
		Velocity#(i,Y) = Velocity#(i,Y) * damping# + (yvel# * 0.001)
		
		String2(i,X) = String1(i,X) + Velocity(i,X)
		String2(i,Y) = String1(i,Y) + Velocity(i,Y)
	Next
	
	String2(0,X) = 400
	String2(0,Y) = 0
	
	For i = 1 To 31		
		String1(i,X) = String2(i,X)
		String1(i,Y) = String2(i,Y)
		Oval String1(i,X)-5,String1(i,Y)-5,10,10
		Line String1(i,X),String1(i,Y),String1(i-1,X),String1(i-1,Y)
	Next

	If KeyHit(57)
		For i = 0 To 31
			DebugLog i
			DebugLog "X: " + Velocity(i,X)
			DebugLog "Y: " + Velocity(i,Y)
			DebugLog ""
		Next
	End If

Flip
Wend


Function GetDiff#(i1,i2,o)

If (i1<0) Or (i2<0) Or (i1>30) Or (i2>30)
	Return 0
Else
	Return Float(String1(i1,o) - String1(i2,o))
End If

End Function


Function Length#(dx#,dy#)

l# = Sqr(dx^2 + dy^2)

Return l#

End Function


i tried... and failed.

help, anybody? the problem is with the dx2 etc part, ie the next point down...


Chroma(Posted 2003) [#20]
Great link Zenith. About to lose my mind over this. I hope it was just the order of how I was summing everything up.


Zenith(Posted 2003) [#21]
Here's my 2d implemention of it that i wrote ages ago with types - http://zgaming.hypermart.net/bb_src/rope.bb

No comments on the implemention it was just a test-bed, sorry otherwise.


Lane(Posted 2003) [#22]
Very very cool.. :>)


JoshK(Posted 2003) [#23]
You know I posted the source in the Advanved3D forum, right?