Chipmunk integration

From X-Moto
Jump to: navigation, search

News

  • First feature set merged into xmoto trunk!
  • Inksmoto svn version supports new Chipmunk features

Features from first round of development

  • Interactions between Chipmunk objects and:
    • Other Chipmunk objects in the level
    • Player Wheels
    • Terrain
  • Physical Properties specified per object in level file:
    • Mass
    • Friction
    • Elasticity
  • Multiplayer/Multiscene support (not as fast as 1-player, but may be optimised in time)
  • Responsive to scripted changes in Gravity

Getting Started

Installation

Follow the regular Subversion build instructions. If you wish to try the latest experimental code, then make one change being the repository path below:

svn co svn://svn.tuxfamily.org/svnroot/xmoto/xmoto/branches/chipmunk chipxmoto

Configpath Change requirement

The database requires an upgrade, so until development stops, or at least the level file changes do, to run both versions then you will need to specify different config paths. E.g.

./xmoto --configpath ~/.xmotophysics

XMoto will create this directory for you if it does not already exist

Test levels

You can find them at

http://download.tuxfamily.org/xmoto/xmoto/dev/chipmunk_levels

Not all are 'playable' in the sense that a number just demonstrate bugs or compare physics settings between ODE/Chipmunk.

Dynamic Objects

Experimental code for interactions between scripted dynamic objects and chipmunk physics objects has been removed. The reason for this is that dynamic objects in XMoto are 'teleported' into position, whereas objects in Chipmunk require force and torque parameters -- these two models are incompatible and resulted in some spectacular bugs.

Rather than support these interactions badly, it was decided not to support them at all -- both types of objects will ignore each other and thus should be used carefully if required in the same level.

Scriptable Chipmunk Physics Objects

These will stay as close as possible to the existing script API developed for dynamic objects e.g.:

  • SetPhysicsBlockTranslation(block, fX, fY, period, startTime, endTime, maxForce)
  • SetPhysicsBlockSelfRotation(block, period, startTime, endTime, maxTorque)
  • SetPhysicsBlockPos(block, fX, fY)

The maxForce and maxTorque would be defining how much potential power the object will have to reach its desired state. The chipmunk scripting commands will differ in this regard, in that a particular position in space cannot be guaranteed, because there may be something in the way.

SetPhysicsBlockPos() is in the development branch.

Background Interactions

Physics objects can be made 'background' objects also. Code in the development branch supports interactions:

  • Between background physics objects and regular physics objects/terrain
  • Not between background physics objects and the player

The level 'Chipmunk Playground 4' demonstrates a use of this with the swinging hanging cages.

Circle Support

Chipmunk optimises collisions involving circles. In the development branch some (very) preliminary code towards that end has been added. Previously all circles were treated as interpolated polygons and passed to the collision code in that way.

Initial tests between ChipmunkBallpit/ChipmunkBallpitCircles show differences in handling and speed.

Unexpectedly, speed improvements were not realised. Possible explanations for this are:

  • Increased number of interactions - polygons find a 'rest' state quicker than circles
  • XMoto collision system may be bottleneck
  • Hundreds of circles together (e.g. a ballpit) may not be the best test

Despite this less than ideal start, support for circles will continue as there are cases where they may be useful. e.g. ball rolling down slope -- less likely to get 'stuck' on vertices.

The_only_dude: on my computer, using circle on the test level divides the cpu usage by 2. The_only_dude: now that i have optimize dynamic blocks, in a level like ChipmunkPlayground4.lvl, 90% of the time is spent in chipmunk code, so using circle collisions will really speed up things.

Features expected for the second merge

  • Scriptable physics objects
  • Background interactions


Other Chipmunk Features

These will be tested and may be phased in over time and future releases:

  • Joints
    • Pin joints
    • Pivot joints
    • Slide joints
    • Groove joints
  • Circles - fastest type of collision object
  • Springs