It is currently Fri May 24, 2013 6:36 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 31 posts ]  Go to page Previous  1, 2, 3  Next
Author Message
 Post subject: Re: 2D physics engine (Verlet)
PostPosted: Tue Jan 04, 2011 11:23 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Tue Apr 01, 2008 3:23 pm
Posts: 129
You've done a great work here, idle! :D The "spatial map" idea is really interesting.

A hint for optimization:
I found that (on my PC, with PB 4.51; it may differ with other configs...) lists embedded in structure are slower than other solutions.
I have tested 3 solutions :
- embedded list: structure xxx:... List pointmass.pointmass_struct() ... endstructure
- embedded array: structure xxx:... pointmass.pointmass_struct[maxNbPoints] ... endstructure
- pointer to a memory zone where you store the objects' pointers: structure xxx:... *ptrPointList ... endstructure
=> with drawing disabled and the "F9" scenario, the latter is faster (but harder to implement/read) with 207 FPS, the second isn't far behind with 196 FPS, and the first (even if it's more elegant and easier to read) is significatively slower with 123 FPS.

That's why I originally used the pointers in my code, despite the fact they are a little harder to manipulate.


Top
 Profile  
 
 Post subject: Re: 2D physics engine (Verlet)
PostPosted: Fri Jan 07, 2011 7:35 am 
Offline
Addict
Addict
User avatar

Joined: Fri Sep 21, 2007 5:52 am
Posts: 2488
Location: New Zealand
Made some improvements to the spatial map, it appears to run marginally faster when the objects aren't clumped together, though it still takes a performance hit when the objects are clumped together. (may still be something to fix)

Added a quick sprite test on F1

should we be including texture coordinates into a body and if so how to transform them?

http://www.idlearts.com/verlet.zip


Top
 Profile  
 
 Post subject: Re: 2D physics engine (Verlet)
PostPosted: Fri Jan 07, 2011 8:30 am 
Offline
Addict
Addict
User avatar

Joined: Thu Jun 24, 2004 8:51 am
Posts: 1300
Location: Germany: 49º 45' 21.96" N 10º 38' 4.04" E
idle wrote:
Added a quick sprite test on F1
should we be including texture coordinates into a body and if so how to transform them?

Use the MP3D Engine. It is much faster s the native DirectX9 solution.

_________________
Belive!
<Wrapper>4PB, PB<game>, =QONK=, PetriDish, Movie2Image, PictureManager,...
http://chipmunk4purebasic.freeforums.org/index.php


Top
 Profile  
 
 Post subject: Re: 2D physics engine (Verlet)
PostPosted: Fri Jan 07, 2011 11:20 pm 
Offline
Addict
Addict
User avatar

Joined: Fri Sep 21, 2007 5:52 am
Posts: 2488
Location: New Zealand
Thanks I'll have a look.
I was just thinking aloud about how to go about supporting the mapping of textures, If you only wanted to use PB sprites for rendering objects you need to store texture coordinates in the engine and update them in the verlet integration as they are separate to the bodies vertices if the object isn't rectangular, but if you used opengl for instance, you may not need the additional data all of the time.


Top
 Profile  
 
 Post subject: Re: 2D physics engine (Verlet)
PostPosted: Tue Jan 11, 2011 10:28 pm 
Offline
Addict
Addict
User avatar

Joined: Tue Jan 02, 2007 8:16 pm
Posts: 4328
Location: Cypress TX
MP3D is very interesting... if no can use maybe some of the ideas can eb salvaged into verlet?

_________________
Binarily speaking... it takes 10 to Tango!!!

Image
http://www.bluemesapc.com/


Top
 Profile  
 
 Post subject: Re: 2D physics engine (Verlet)
PostPosted: Fri Jan 14, 2011 12:32 am 
Offline
Addict
Addict
User avatar

Joined: Fri Sep 21, 2007 5:52 am
Posts: 2488
Location: New Zealand
Gave up on the Spatial map couldn't get it to perform better than the original structure.
Fixed some bugs in the verlet.
Have started adding support for PB textures and changed the drawing routines to create n sided convex polygons

There's still some bugs with alignment, seems to be the odd numbered sided shapes and the mapping is currently only symmetric.

Added Attractor and Repel forces, will generalize it later to provide multiple sinks and repels with a variety of force functions
it may be possible to use them to create paths instead of interpolating a spline.

Image

Shape tests keys 3,4,5,6,8,9

http://www.idlearts.com/verlet.zip


Top
 Profile  
 
 Post subject: Re: 2D physics engine (Verlet)
PostPosted: Wed Jan 19, 2011 1:41 am 
Offline
Addict
Addict
User avatar

Joined: Fri Sep 21, 2007 5:52 am
Posts: 2488
Location: New Zealand
Generalized Attractors and Repellers so they can be bound to objects


Top
 Profile  
 
 Post subject: Re: 2D physics engine (Verlet)
PostPosted: Wed Jan 19, 2011 10:54 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Thu May 06, 2010 10:16 am
Posts: 240
Location: Belgium
hi, Kelebrindae and idle,

Very nice, I love your work,
thanks for sharing it with us...

Marc,

_________________
Greetings from Pajottenland - Belgium
I love/hate 3D GAMES and robots
http://www.marc-systems.be - http://www.PVG-3DStudio.be


Top
 Profile  
 
 Post subject: Re: 2D physics engine (Verlet)
PostPosted: Thu Feb 03, 2011 6:21 pm 
Offline
Addict
Addict
User avatar

Joined: Fri Sep 21, 2007 5:52 am
Posts: 2488
Location: New Zealand
Thanks marc

I've added a Pin body and a Join body routine, the join body needs a bit more thought.
There is also an issue in the friction calculations in the collision response that needs to be addressed. When objects are colliding in free fall they loose momentum against gravity which isn't the right response.
I noticed it when I had joined bodies together and flung them around, so they're now given a GroupID which is ok as long as you add a single object to an existing group.

The new tests F3 and F4

http://www.idlearts.com/verlet.zip


Top
 Profile  
 
 Post subject: Re: 2D physics engine (Verlet)
PostPosted: Sun Feb 27, 2011 11:47 pm 
Offline
Addict
Addict
User avatar

Joined: Fri Sep 21, 2007 5:52 am
Posts: 2488
Location: New Zealand
Converted code to run on linux and windows under opengl subsystem.
Added a dirty hull routine to Generate a body template from an image, this should be changed to compute a proper convex hull.
There are also issues to resolve generating constraints which may lead to some bodies being unstable.

Added Body Templates
It makes it easier to manage objects as you can simply refer to them by name
So you generate a body template from an image and then invoke the body from the template

Added a couple of mini game demos (incomplete)
Asteroid osmosis (become the biggest) left click to move
Pool Table (can't be arsed to finish it but the target coords are in the data section)

http://www.idlearts.com/verlet.tar.gz


Top
 Profile  
 
 Post subject: Re: 2D physics engine (Verlet)
PostPosted: Tue May 31, 2011 9:52 pm 
Offline
Enthusiast
Enthusiast

Joined: Wed Sep 06, 2006 6:59 am
Posts: 151
Looks interresting. :) But there seems to be a small bug in line 136 of verlet2D.pbi so the tgz does not work in windows.

CompilerIf #PB_OS_Linux Or #PB_OS_MacOS ; is always true

CompilerIf #PB_Compiler_OS & (#PB_OS_Linux|#PB_OS_MacOS) ; should work

Greetigns,
auser


Top
 Profile  
 
 Post subject: Re: 2D physics engine (Verlet)
PostPosted: Tue May 31, 2011 10:05 pm 
Offline
Addict
Addict
User avatar

Joined: Fri Sep 21, 2007 5:52 am
Posts: 2488
Location: New Zealand
thanks
probably should be

Code:
CompilerIf  (#PB_Compiler_OS = #PB_OS_Linux Or  #PB_Compiler_OS = #PB_OS_MacOS)


I'll update it later


Top
 Profile  
 
 Post subject: Re: 2D physics engine (Verlet)
PostPosted: Wed Jun 01, 2011 10:28 am 
Offline
Addict
Addict

Joined: Fri Oct 23, 2009 2:33 am
Posts: 2862
Location: Wales, UK
....why not just rename the structure and eliminate the CompilerIf?

_________________
IdeasVacuum
If it sounds simple, you have not grasped the complexity.


Top
 Profile  
 
 Post subject: Re: 2D physics engine (Verlet)
PostPosted: Thu Jun 02, 2011 5:01 am 
Offline
Addict
Addict
User avatar

Joined: Fri Sep 21, 2007 5:52 am
Posts: 2488
Location: New Zealand
this would be better
Code:
CompilerIf Defined(point,#PB_Structure)=#False
 Structure point
      x.i
      y.i
   EndStructure 
CompilerEndIf


Top
 Profile  
 
 Post subject: Re: 2D physics engine (Verlet)
PostPosted: Tue Oct 04, 2011 5:16 pm 
Offline
New User
New User

Joined: Tue Jun 28, 2011 5:47 pm
Posts: 8
Soo... hypotethically, if I wanted to actually use this in a game, how do I make the simulation speed independent of framerate?

_________________
~Rudolf Enberg


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 31 posts ]  Go to page Previous  1, 2, 3  Next

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye