Physics File Format: Difference between revisions

From OLPC
Jump to navigation Jump to search
No edit summary
No edit summary
Line 5: Line 5:
The format is XML and is meant to map directly to concepts, names and features of [http://box2d.org/ Box2D]. It was inspired by a similar format made by kne? as part of the Elements project.
The format is XML and is meant to map directly to concepts, names and features of [http://box2d.org/ Box2D]. It was inspired by a similar format made by kne? as part of the Elements project.


...insert simple example...
Here is a simple example:
<pre>
<!-- Physix.app v1.0 -->
<world lowerBound="-10,-10" upperBound="14,18" gravity="0,-9.81">

A square and circle balanced on a teeter-totter.

<body name="window"><box size="4,3" sensor="1"/></body>

<body name="ground" position="0,0" static="1">
Make a hollow box that is 4 wide and 8 tall. The upper half is off screen,
so objects can go off the top, but they can't get away entirely.
<box offset="0,4" size=".1,8"/>
<box offset="2,0" size="4,.1"/>
<box offset="4,4" size=".1,8"/>
<box offset="2,8" size="4,.1"/>
</body>
<body name="pivot" position="2,0" static="1">
<box size="1,1" rotation="45"/>
</body>
<body name="platform" position="2,.75">
<box size="2,.2" density="2" restitution=".5" friction=".15"/>
</body>
<revoluteJoint body1="pivot" body2="platform" anchor="2,.65"/>
<body name="box" position="1.5,3" rotation="0">
<box size=".355,.355" rotation="0" density="1" restitution=".5" friction=".15"/>
</body>
<body name="circle" position="2.5,3">
<circle radius=".2" density="1" restitution=".15" friction=".5"/>
</body>
</world>
</pre>

The defined tags, attributes and structure are as follows. Note that most attributes are given default values if they are not present in the XML. Most defaults are 0. All rotations are in degrees. All 2D vectors are specified as two numbers separated by a comma (see examples for clarity). Booleans are 0 or 1. Distances are measured in meters.

* world
** attribute: sleep = 0 or 1 indicating whether settled objects are allowed to sleep to save computation
** attribute: lowerBound and upperBound = 2D vectors defining the lower and upper corners of the simulation's bounds (different from the visible window, see below)
** attribute: gravity = 2D vector defining the value of gravity in meters per second per second (default = 0,-9.81 which is roughly Earth's gravity)
** children: body, *joint or repeat elements

* body
** name = the name for this body. This is used when specifying the anchors for a joint.
** static = boolean defining whether this body is fixed in place or a dynamic part of the simulation.
** position = 2D vector for the origin/center of this body.
** rotation = rotation in degrees.
** children: 1 or more shapes (box, circle, polygon)

* box, circle or polygon
** attribute:

* repeat = the children of this element are duplicated a number of times with an offset and/or rotation between each repetition
** attribute: count = the number of repetitions (default = 1)
** attribute: offset = 2D vector defining the offset applied between each repetition
** attribute: center = 2D vector defining the base offset applied to the first repetition (in other words: the origin of the children)
** attribute: rotation = rotation in degrees between each repetition


...insert spec...


...insert examples...
...insert examples...

Revision as of 06:51, 11 July 2008

There has been some discussion on how to share 2D scenes between the various Physics frameworks, activities, etc.

Here is a proof of concept, presented here for the purposes of discussion. It was developed for the Mac OS X application Physix written by Jminor The format is XML and is meant to map directly to concepts, names and features of Box2D. It was inspired by a similar format made by kne? as part of the Elements project.

Here is a simple example:

<!-- Physix.app v1.0 -->
<world lowerBound="-10,-10" upperBound="14,18" gravity="0,-9.81">

	A square and circle balanced on a teeter-totter.

    <body name="window"><box size="4,3" sensor="1"/></body>

    <body name="ground" position="0,0" static="1">
        Make a hollow box that is 4 wide and 8 tall.  The upper half is off screen,
        so objects can go off the top, but they can't get away entirely.
        <box offset="0,4" size=".1,8"/>
        <box offset="2,0" size="4,.1"/>
        <box offset="4,4" size=".1,8"/>
        <box offset="2,8" size="4,.1"/>
    </body>
	
    <body name="pivot" position="2,0" static="1">
        <box size="1,1" rotation="45"/>
    </body>
    <body name="platform" position="2,.75">
        <box size="2,.2" density="2" restitution=".5" friction=".15"/>
    </body>
	<revoluteJoint body1="pivot" body2="platform" anchor="2,.65"/>
	
    <body name="box" position="1.5,3" rotation="0">
        <box size=".355,.355" rotation="0" density="1" restitution=".5" friction=".15"/>
    </body>
	
    <body name="circle" position="2.5,3">
        <circle radius=".2" density="1" restitution=".15" friction=".5"/>
    </body>
</world>

The defined tags, attributes and structure are as follows. Note that most attributes are given default values if they are not present in the XML. Most defaults are 0. All rotations are in degrees. All 2D vectors are specified as two numbers separated by a comma (see examples for clarity). Booleans are 0 or 1. Distances are measured in meters.

  • world
    • attribute: sleep = 0 or 1 indicating whether settled objects are allowed to sleep to save computation
    • attribute: lowerBound and upperBound = 2D vectors defining the lower and upper corners of the simulation's bounds (different from the visible window, see below)
    • attribute: gravity = 2D vector defining the value of gravity in meters per second per second (default = 0,-9.81 which is roughly Earth's gravity)
    • children: body, *joint or repeat elements
  • body
    • name = the name for this body. This is used when specifying the anchors for a joint.
    • static = boolean defining whether this body is fixed in place or a dynamic part of the simulation.
    • position = 2D vector for the origin/center of this body.
    • rotation = rotation in degrees.
    • children: 1 or more shapes (box, circle, polygon)
  • box, circle or polygon
    • attribute:
  • repeat = the children of this element are duplicated a number of times with an offset and/or rotation between each repetition
    • attribute: count = the number of repetitions (default = 1)
    • attribute: offset = 2D vector defining the offset applied between each repetition
    • attribute: center = 2D vector defining the base offset applied to the first repetition (in other words: the origin of the children)
    • attribute: rotation = rotation in degrees between each repetition


...insert examples...