How to do physics?

BlitzMax Forums/BlitzMax Programming/How to do physics?

ImaginaryHuman(Posted 2005) [#1]
Howdy,

I am working on a new project, part of which will entail the need for some physics to be implemented. I haven't done very much in the way of advanced physics before.

Does anyone have some suggested online reading or advice about how to do physics interactions between a number of `particles of matter`? I basically have a bunch of small `sticky` objects - they need to be able to form groups, but must also be able to break apart under the right conditions of weight/force etc.

I think what I need is something to do with a large number of `deformable bodies` that can act as a single body or break up into parts. It seems from what I've been reading so far that I need to do something like the `Discrete Element Method`.

Any help much appreciated.


Who was John Galt?(Posted 2005) [#2]
search for the hitman paper on the net. 'hitman rigid body' or something like that.


ImaginaryHuman(Posted 2005) [#3]
ok thanks. anything else?


bradford6(Posted 2005) [#4]
physics are hard. wait for the ODE module and focus on something else


ImaginaryHuman(Posted 2005) [#5]
I am finding out also that physics are indeed hard. Every single article I've read on it so far gets much too strongly into heavy maths equasions without explaining them for a novice - you have to already even know what all the symbols mean, yet alone understand what's going on. Maybe I'll have to settle for some kind of `fake` cludgey effect that sort of looks like the real thing.

I just want some 2D routines that will let me throw irregularly shaped objects at each other.


ImaginaryHuman(Posted 2005) [#6]
Waiting is not an option ;-D


Vorderman(Posted 2005) [#7]
Have a look in the code archives - ages ago I posted an example of a simple rigid body physics system using particles attached to each other via spring links. It's very easy to adapt to create blobby objects that will roll around and wobble etc.., and you can make them break apart very easily by checking the forces on the springs and then breaking them at a certain limit - you can see in the demo that the springs turn red as they stretch.

here's the link -
http://www.blitzbasic.com/codearcs/codearcs.php?code=387


Eric(Posted 2005) [#8]
I have always wanted to play around with this stuff. Thank Vorderman
My Code is very basic and poor as I am really just learning to work with Bmax

Regards,

Eric


Strict 
Graphics 1024,768
Global SpringList:TList=New TList
 
Global Index:Int 
Global Particles:Tparticle[20]

Global DD:Int
Global EE:Int
Global SpringStrength:Float=55.15
Type Tparticle

	Field Image:Timage
	Field X:Float
	Field Y:Float
	Field XS:Float
	Field YS:Float
	Field Locked:Int

	Function Create:TParticle(X:Int,Y:Int)
    		Local P:Tparticle
		P:Tparticle= New TParticle
		P.X=X
		p.Y=Y
    		Return P
	End Function
	Function Update()
		For Local Index=0 To 5
		Particles[Index].YS:+.98
		Particles[Index].XS:*.90
		Particles[Index].YS:*.90
		Particles[Index].X:+Particles[Index].XS
		Particles[Index].Y:+Particles[Index].YS
		If Particles[Index].Y>765 And Particles[Index].YS>0.0
			Particles[Index].YS=-Particles[Index].YS*.98
			Particles[Index].Y=765.0
		End If 
		
		DrawOval(Particles[Index].X-3,Particles[Index].Y-3,6,6)
                next
	End Function 
End Type 

Type TSpring

	Field Connection1
	Field Connection2
	Field Length:Float
	Field CurrentLenght:Float
	Field PeakTension:Float
	
	Function Create:TSpring(C1:Int,C2:Int)
    		Local S:TSpring
		Local DX:Float
		Local DY:Float
		S:TSpring= New TSpring
		S.Connection1=C1
		S.Connection2=C2
		DX=Particles[C1].X-Particles[C2].X
		DY=Particles[C1].Y-Particles[C2].Y
		S.Length=Sqr((DX*DX)+(DY*DY))	 	
   	 	ListAddLast SpringList,S
	Return S
	End Function
	Function Update()
		For Local Spring:Tspring=EachIn SpringList
		Local P1=Spring.Connection1
		Local P2=Spring.Connection2
		Local SX:Float = Particles[P1].X-Particles[P2].X
		Local SY:Float = Particles[P1].Y-Particles[P2].Y
		Local Length:Float =Sqr((SX*SX)+(SY*SY))
		Spring.CurrentLenght=Length
		Local NormalLength:Float=Spring.Length
		Local ForceScaler:Float=(Length-NormalLength)/NormalLength
		SX:*(1.0/Length)
		SY:*(1.0/Length)
		Local FX:Float = SX*ForceScaler
		Local FY:Float = SY*ForceScaler
		FX:*SpringStrength
		FY:*SpringStrength
		Local FX2:Float=-FX
		Local FY2:Float=-FY
		
		Particles[P2].XS:+FX
		Particles[P2].YS:+FY
		Particles[P1].XS:-FX 
		Particles[P1].YS:-FY 
		DrawLine(Particles[Spring.Connection1].X,Particles[Spring.Connection1].Y,Particles[Spring.Connection2].X,Particles[Spring.Connection2].Y)
 		Next 
	End Function 
End Type 

RestoreData Parts
For Index=0 To 5
	ReadData DD,EE
	Particles[Index]=TParticle.Create(DD,EE )
Next 
 
RestoreData Springs
For Index=0 To 8
	ReadData DD,EE
	Tspring.Create(DD,EE)
Next 
 
Repeat 
	Cls
 	If MouseDown (1)
		 Local Index=5
		 Particles[Index].YS:+((MouseY()-Particles[Index].Y)/25)
		 Particles[Index].XS:+((MouseX()-Particles[Index].X)/50) 
	End If
	Tparticle.Update() 
	TSpring.Update()
	If KeyDown(Key_A)
		SpringStrength:+.1
	End If 
	If KeyDown(Key_Z)
		SpringStrength:-.1
	End If 
 	DrawText ("Spring Tension A/Z "+SpringStrength,0,24)
	DrawText ("Click the Mouse",0,36)
	Flip
Until KeyHit(Key_Escape)

#Parts 
DefData 500,100
DefData 600,100
DefData 600,200
DefData 500,200
DefData 550,150
DefData 550,10 

#Springs
DefData 0,5,5,1,1,0,0,3,3,2,2,1,1,3,2,4,0,2



bradford6(Posted 2005) [#9]
cool demo Eric.


ImaginaryHuman(Posted 2005) [#10]
Nice bouncy things :-)


Eric(Posted 2005) [#11]
I just tweaked the code a little... It's kinda fun to play around with but I am not sure what to do with it. :)


ImaginaryHuman(Posted 2005) [#12]
It's not quite what I'm trying to do but it's neat.


teamonkey(Posted 2005) [#13]
Are you trying to do something like this? http://www.tinyminions.co.uk/teamonkey/blob1.html

(You'll need Java 1.4 or greater)


Koekelas(Posted 2005) [#14]
I can't help you but maybe a book can. Check out PremierPress's collection of Physics book. It's not free I'm afraid.


Nicolas.


ImaginaryHuman(Posted 2005) [#15]
teamonkey, that looks interesting but no it's not what I'm trying to do. Besides, my blobby objects are faster and better ;-) although they don't use any physics. I'm not working on blobs right now, though.

I think I probably will have to work on it by myself otherwise I would have to give too much away in order to describe it properly. I'm notorious for giving everything away so I'm really trying hard to keep my project under wraps. I just hoped it might be simpler to make particles behave realistically than it appears to be.


Najdorf(Posted 2005) [#16]
if you gave a more precise idea of what you are trying to do maybe we could help you...


ImaginaryHuman(Posted 2005) [#17]
Sorry. I can't tell you. I will have to figure it out myself. Thanks for the offer.


Dreamora(Posted 2005) [#18]
Searching for things like physical particle simulation or things basing on molecular physic system would be a possibility as it seems that you want to have some kind of molecular system ... At least basing on your postings.


ImaginaryHuman(Posted 2005) [#19]
Something along those lines. That's pretty much what I'm finding. I think I will end up having to basically create my own custom engine though, with the physics designed for my specific purpose. I don't think I would be able to do a completely true-to-life simulation because there are obviously many characteristics of particulate matter that can only really be described but a much finer grained universe based on molecules and atoms etc. Too complicated. I will have to approximate.


Najdorf(Posted 2005) [#20]
i did this once:

http://www.radicalrebound.com/particles.zip


ImaginaryHuman(Posted 2005) [#21]
Thanks Najdorf, I'm on a Mac here though.


Sweenie(Posted 2005) [#22]
Check this link...
http://www.aidspan.org/alec/physical/overview_physics.htm

Demos are win32 though, but the screenshots and the downloadable helpfile explains alot.


ImaginaryHuman(Posted 2005) [#23]
Thanks, that's actually very close to what I am wanting to do so it's very useful!

I had to download a Mac CHM viewer to see the file, but it was worth it! :-)

Thanks Sweenie.


matt!(Posted 2005) [#24]
Thanks for the wonderful code, Eric!


Eric(Posted 2005) [#25]
It Was fun Using Vorderman's original code... I wish I had continued.. I never thought of anything good to make with it. I'm not a good "Idea" person. Just a coder. But In any case you are welcome. :)


Vertex(Posted 2005) [#26]
Maybe http://www.amazon.com/exec/obidos/tg/detail/-/1558607323/qid=1124740995/sr=8-1/ref=pd_bbs_1/104-3968993-5999942?v=glance&s=books&n=507846
cu olli


Filax(Posted 2005) [#27]
Any news angeldaniel ? :)


ImaginaryHuman(Posted 2005) [#28]
Hey, thanks for your interest! :-)

Mostly at the moment I only have designs for how the engine/environment works. I've been doing a lot of research/learning into how to simulate various things, learning about springs, fluid dynamics, atomic structure, etc. I have a fairly high level understanding of how it all fits together and works to produce an overall game experience, but then I also realized what I mainly have is an engine which a person could play around in, but with no goals, no theme, no story, none of that traditional game stuff. So it's more of a simulation at the moment. But then again, that's how scorched earth started out - just as a physics simulation. So my engine is a pretty sophisticated physics simulation of a fully destructible and highly detailed environment, albeit on paper.

When it came down to looking into how to actually do the programming for it, to make it a reality, I was quite put off. I used to be more of a programmer years ago but I more or less put it away in order to pursue other priorities, and now that I'm coming back to it I don't have hardly any of that interest/patience/concentration or desire to think and figure stuff out so much. I'm a bit put off by the programming. So I sort of have things on hold at the moment trying to decide whether to do any more with it. I think it would be excellent if I did do it, but it's a matter of finding time and interest to sit there and tolerate the frustrating complexities of writing programs. I wish the routines were already written for me :-) lol

So that's where things are. There has been lots of progress but I'm not sure whether to take it to the next level. Each time I try to go to program it, I find myself sitting there hardly knowing where to start or how to structure it or what order to do things in. I think partly it's because I've developed a nack for considering everything all at once, which is a lot of stuff to keep in mind, which doesn't really help with getting things done.