├── tests ├── __init__.py ├── basics.py ├── test_edgechain.py ├── test_world.py ├── test_color.py ├── test_kwargs.py └── test_body.py ├── examples ├── __init__.py ├── backends │ └── __init__.py ├── opencv │ └── journal_image.png ├── data │ └── themes │ │ ├── default │ │ ├── box.xcf │ │ ├── dot.xcf │ │ ├── out.tga │ │ ├── up.png │ │ ├── x.png │ │ ├── Vera.ttf │ │ ├── check.png │ │ ├── down.png │ │ ├── left.png │ │ ├── list.png │ │ ├── radio.png │ │ ├── right.png │ │ ├── box.down.png │ │ ├── console.png │ │ ├── desktop.png │ │ ├── desktop.xcf │ │ ├── dialog.png │ │ ├── dot.down.png │ │ ├── hslider.tga │ │ ├── slider.tga │ │ ├── vslider.tga │ │ ├── box.hover.png │ │ ├── box.normal.png │ │ ├── dialog.bar.png │ │ ├── dot.hover.png │ │ ├── dot.normal.png │ │ ├── menu.down.tga │ │ ├── menu.hover.tga │ │ ├── rdot.down.png │ │ ├── rdot.hover.png │ │ ├── tool.down.tga │ │ ├── tool.hover.tga │ │ ├── vdot.down.png │ │ ├── vdot.hover.png │ │ ├── vslider.up.tga │ │ ├── button.down.tga │ │ ├── button.hover.tga │ │ ├── button.normal.tga │ │ ├── hslider.left.tga │ │ ├── hslider.right.tga │ │ ├── idot.normal.png │ │ ├── input.focus.png │ │ ├── input.normal.png │ │ ├── listitem.down.tga │ │ ├── menu.normal.tga │ │ ├── progressbar.tga │ │ ├── rdot.normal.png │ │ ├── sbox.normal.png │ │ ├── select.arrow.png │ │ ├── tool.normal.tga │ │ ├── vbox.normal.png │ │ ├── vdot.normal.png │ │ ├── vsbox.normal.png │ │ ├── vslider.down.tga │ │ ├── list.item.down.png │ │ ├── list.item.hover.png │ │ ├── listitem.hover.tga │ │ ├── listitem.normal.tga │ │ ├── progressbar.bar.tga │ │ ├── radio.off.hover.tga │ │ ├── radio.on.hover.tga │ │ ├── radio.on.normal.tga │ │ ├── select.options.png │ │ ├── checkbox.off.hover.tga │ │ ├── checkbox.on.hover.tga │ │ ├── checkbox.on.normal.tga │ │ ├── dialog.close.down.tga │ │ ├── dialog.close.hover.tga │ │ ├── filebrowser.folder.png │ │ ├── hslider.bar.hover.tga │ │ ├── hslider.bar.normal.tga │ │ ├── list.item.normal.png │ │ ├── radio.off.normal.tga │ │ ├── scroller.slide.h.tga │ │ ├── scroller.slide.v.tga │ │ ├── select.arrow.down.tga │ │ ├── select.arrow.hover.tga │ │ ├── slider.bar.hover.tga │ │ ├── slider.bar.normal.tga │ │ ├── vslider.bar.hover.tga │ │ ├── vslider.bar.normal.tga │ │ ├── checkbox.off.normal.tga │ │ ├── console.input.focus.png │ │ ├── console.input.normal.png │ │ ├── dialog.close.normal.tga │ │ ├── select.arrow.normal.tga │ │ ├── select.option.hover.png │ │ ├── select.option.normal.png │ │ ├── select.selected.down.tga │ │ ├── select.selected.hover.tga │ │ ├── select.selected.normal.tga │ │ ├── scroller.slide.bar.hover.tga │ │ ├── scroller.slide.bar.normal.tga │ │ └── notes.txt │ │ ├── gray │ │ ├── Vera.ttf │ │ ├── dialog.png │ │ ├── list.png │ │ ├── slider.png │ │ ├── box.down.png │ │ ├── console.png │ │ ├── desktop.png │ │ ├── box.normal.png │ │ ├── button.down.png │ │ ├── dialog.bar.png │ │ ├── input.focus.png │ │ ├── menu.down.png │ │ ├── menu.hover.png │ │ ├── menu.normal.png │ │ ├── tool.down.png │ │ ├── tool.normal.png │ │ ├── button.normal.png │ │ ├── input.normal.png │ │ ├── radio.on.down.png │ │ ├── select.arrow.png │ │ ├── checkbox.on.down.png │ │ ├── list.item.normal.png │ │ ├── radio.off.down.png │ │ ├── radio.off.normal.png │ │ ├── radio.on.normal.png │ │ ├── select.options.png │ │ ├── checkbox.off.down.png │ │ ├── checkbox.on.normal.png │ │ ├── dialog.close.down.png │ │ ├── filebrowser.folder.png │ │ ├── menu.option.hover.png │ │ ├── menu.option.normal.png │ │ ├── select.arrow.down.png │ │ ├── slider.bar.normal.png │ │ ├── checkbox.off.normal.png │ │ ├── console.input.focus.png │ │ ├── console.input.normal.png │ │ ├── dialog.close.normal.png │ │ ├── select.arrow.normal.png │ │ ├── select.option.normal.png │ │ └── select.selected.normal.png │ │ └── tools │ │ ├── icons48.bkgr.tga │ │ ├── icons48.code.tga │ │ ├── icons48.draw.tga │ │ ├── icons48.fill.tga │ │ ├── icons48.line.tga │ │ ├── icons48.tile.tga │ │ ├── icons48.eraser.tga │ │ ├── icons48.pixel.tga │ │ ├── icons48.select.tga │ │ └── config.txt ├── pgu │ ├── gui │ │ ├── readme.txt │ │ ├── pguglobals.py │ │ ├── const.py │ │ ├── style.py │ │ ├── misc.py │ │ ├── group.py │ │ ├── __init__.py │ │ ├── keysym.py │ │ ├── deprecated.py │ │ ├── document.py │ │ └── form.py │ └── __init__.py ├── simple_cv.py ├── restitution.py ├── pyramid.py ├── edge_test.py ├── hello.py ├── chain.py ├── conveyor_belt.py ├── pulley.py ├── tumbler.py ├── bullet.py ├── confined.py ├── mobile.py ├── motor_joint.py ├── empty.py ├── convex_hull.py ├── tiles.py ├── one_sided_platform.py ├── vertical_stack.py └── simple │ └── simple_02.py ├── doc_release.cmd ├── library └── Box2D │ ├── __init__.py │ ├── Box2D.py │ ├── _Box2D.pyd │ └── b2 │ └── __init__.py ├── .gitattributes ├── .gitignore ├── README.md ├── deploy.sh ├── config.sh ├── MANIFEST.in ├── devel ├── release.cmd ├── find_extended.py ├── windows_release.py ├── dict_replacement.py ├── init_kwargs.py ├── test.py └── find_results ├── environ-26.cmd ├── Box2D ├── Box2D-License.txt ├── pybox2d_license_header.txt ├── Common │ ├── b2Draw.cpp │ ├── b2Settings.cpp │ ├── b2Timer.h │ ├── b2StackAllocator.h │ ├── b2BlockAllocator.h │ ├── b2GrowableStack.h │ ├── b2StackAllocator.cpp │ ├── b2Timer.cpp │ ├── b2Math.cpp │ └── b2Draw.h ├── Dynamics │ ├── Contacts │ │ ├── b2NullContact.h │ │ ├── b2CircleContact.h │ │ ├── b2PolygonContact.h │ │ ├── b2EdgeAndCircleContact.h │ │ ├── b2EdgeAndPolygonContact.h │ │ ├── b2PolygonAndCircleContact.h │ │ ├── b2ChainAndCircleContact.h │ │ ├── b2ChainAndPolygonContact.h │ │ ├── b2EdgeAndCircleContact.cpp │ │ ├── b2EdgeAndPolygonContact.cpp │ │ ├── b2CircleContact.cpp │ │ ├── b2PolygonAndCircleContact.cpp │ │ ├── b2PolygonContact.cpp │ │ ├── b2ChainAndCircleContact.cpp │ │ ├── b2ChainAndPolygonContact.cpp │ │ └── b2ContactSolver.h │ ├── b2WorldCallbacks.cpp │ ├── b2ContactManager.h │ ├── b2TimeStep.h │ └── b2Island.h ├── Collision │ ├── b2TimeOfImpact.h │ └── Shapes │ │ ├── b2EdgeShape.h │ │ └── b2CircleShape.h └── Box2D.h ├── LICENSE └── .travis.yml /tests/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /examples/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /examples/backends/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /doc_release.cmd: -------------------------------------------------------------------------------- 1 | cd doc 2 | @call release 3 | -------------------------------------------------------------------------------- /library/Box2D/__init__.py: -------------------------------------------------------------------------------- 1 | raise NotImplementedError 2 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | 3 | *.cmd text eol=crlf 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | build/* 2 | dist/* 3 | *.py[oc] 4 | *.swo 5 | *.swp 6 | *.so 7 | -------------------------------------------------------------------------------- /library/Box2D/Box2D.py: -------------------------------------------------------------------------------- 1 | raise NotImplementedError('This should be auto-generated by swig') 2 | 3 | -------------------------------------------------------------------------------- /library/Box2D/_Box2D.pyd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openai/box2d-py/HEAD/library/Box2D/_Box2D.pyd -------------------------------------------------------------------------------- /examples/opencv/journal_image.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openai/box2d-py/HEAD/examples/opencv/journal_image.png -------------------------------------------------------------------------------- /examples/data/themes/default/box.xcf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openai/box2d-py/HEAD/examples/data/themes/default/box.xcf -------------------------------------------------------------------------------- /examples/data/themes/default/dot.xcf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openai/box2d-py/HEAD/examples/data/themes/default/dot.xcf -------------------------------------------------------------------------------- /examples/data/themes/default/out.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openai/box2d-py/HEAD/examples/data/themes/default/out.tga -------------------------------------------------------------------------------- /examples/data/themes/default/up.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openai/box2d-py/HEAD/examples/data/themes/default/up.png -------------------------------------------------------------------------------- /examples/data/themes/default/x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openai/box2d-py/HEAD/examples/data/themes/default/x.png -------------------------------------------------------------------------------- /examples/data/themes/gray/Vera.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openai/box2d-py/HEAD/examples/data/themes/gray/Vera.ttf -------------------------------------------------------------------------------- /examples/data/themes/gray/dialog.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openai/box2d-py/HEAD/examples/data/themes/gray/dialog.png -------------------------------------------------------------------------------- /examples/data/themes/gray/list.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openai/box2d-py/HEAD/examples/data/themes/gray/list.png -------------------------------------------------------------------------------- /examples/data/themes/gray/slider.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openai/box2d-py/HEAD/examples/data/themes/gray/slider.png -------------------------------------------------------------------------------- /examples/data/themes/default/Vera.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openai/box2d-py/HEAD/examples/data/themes/default/Vera.ttf -------------------------------------------------------------------------------- /examples/data/themes/default/check.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openai/box2d-py/HEAD/examples/data/themes/default/check.png -------------------------------------------------------------------------------- /examples/data/themes/default/down.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openai/box2d-py/HEAD/examples/data/themes/default/down.png -------------------------------------------------------------------------------- /examples/data/themes/default/left.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openai/box2d-py/HEAD/examples/data/themes/default/left.png -------------------------------------------------------------------------------- /examples/data/themes/default/list.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openai/box2d-py/HEAD/examples/data/themes/default/list.png -------------------------------------------------------------------------------- /examples/data/themes/default/radio.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openai/box2d-py/HEAD/examples/data/themes/default/radio.png -------------------------------------------------------------------------------- /examples/data/themes/default/right.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openai/box2d-py/HEAD/examples/data/themes/default/right.png -------------------------------------------------------------------------------- /examples/data/themes/gray/box.down.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openai/box2d-py/HEAD/examples/data/themes/gray/box.down.png -------------------------------------------------------------------------------- /examples/data/themes/gray/console.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openai/box2d-py/HEAD/examples/data/themes/gray/console.png -------------------------------------------------------------------------------- /examples/data/themes/gray/desktop.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openai/box2d-py/HEAD/examples/data/themes/gray/desktop.png -------------------------------------------------------------------------------- /examples/data/themes/default/box.down.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openai/box2d-py/HEAD/examples/data/themes/default/box.down.png -------------------------------------------------------------------------------- /examples/data/themes/default/console.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openai/box2d-py/HEAD/examples/data/themes/default/console.png -------------------------------------------------------------------------------- /examples/data/themes/default/desktop.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openai/box2d-py/HEAD/examples/data/themes/default/desktop.png -------------------------------------------------------------------------------- /examples/data/themes/default/desktop.xcf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openai/box2d-py/HEAD/examples/data/themes/default/desktop.xcf -------------------------------------------------------------------------------- /examples/data/themes/default/dialog.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openai/box2d-py/HEAD/examples/data/themes/default/dialog.png -------------------------------------------------------------------------------- /examples/data/themes/default/dot.down.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openai/box2d-py/HEAD/examples/data/themes/default/dot.down.png -------------------------------------------------------------------------------- /examples/data/themes/default/hslider.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openai/box2d-py/HEAD/examples/data/themes/default/hslider.tga -------------------------------------------------------------------------------- /examples/data/themes/default/slider.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openai/box2d-py/HEAD/examples/data/themes/default/slider.tga -------------------------------------------------------------------------------- /examples/data/themes/default/vslider.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openai/box2d-py/HEAD/examples/data/themes/default/vslider.tga -------------------------------------------------------------------------------- /examples/data/themes/gray/box.normal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openai/box2d-py/HEAD/examples/data/themes/gray/box.normal.png -------------------------------------------------------------------------------- /examples/data/themes/gray/button.down.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openai/box2d-py/HEAD/examples/data/themes/gray/button.down.png -------------------------------------------------------------------------------- /examples/data/themes/gray/dialog.bar.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openai/box2d-py/HEAD/examples/data/themes/gray/dialog.bar.png -------------------------------------------------------------------------------- /examples/data/themes/gray/input.focus.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openai/box2d-py/HEAD/examples/data/themes/gray/input.focus.png -------------------------------------------------------------------------------- /examples/data/themes/gray/menu.down.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openai/box2d-py/HEAD/examples/data/themes/gray/menu.down.png -------------------------------------------------------------------------------- /examples/data/themes/gray/menu.hover.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openai/box2d-py/HEAD/examples/data/themes/gray/menu.hover.png -------------------------------------------------------------------------------- /examples/data/themes/gray/menu.normal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openai/box2d-py/HEAD/examples/data/themes/gray/menu.normal.png -------------------------------------------------------------------------------- /examples/data/themes/gray/tool.down.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openai/box2d-py/HEAD/examples/data/themes/gray/tool.down.png -------------------------------------------------------------------------------- /examples/data/themes/gray/tool.normal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openai/box2d-py/HEAD/examples/data/themes/gray/tool.normal.png -------------------------------------------------------------------------------- /examples/pgu/gui/readme.txt: -------------------------------------------------------------------------------- 1 | This is the GUI module from Phil's pyGame Utilities: 2 | http://www.imitationpickles.org/pgu/wiki/index -------------------------------------------------------------------------------- /examples/data/themes/default/box.hover.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openai/box2d-py/HEAD/examples/data/themes/default/box.hover.png -------------------------------------------------------------------------------- /examples/data/themes/default/box.normal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openai/box2d-py/HEAD/examples/data/themes/default/box.normal.png -------------------------------------------------------------------------------- /examples/data/themes/default/dialog.bar.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openai/box2d-py/HEAD/examples/data/themes/default/dialog.bar.png -------------------------------------------------------------------------------- /examples/data/themes/default/dot.hover.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openai/box2d-py/HEAD/examples/data/themes/default/dot.hover.png -------------------------------------------------------------------------------- /examples/data/themes/default/dot.normal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openai/box2d-py/HEAD/examples/data/themes/default/dot.normal.png -------------------------------------------------------------------------------- /examples/data/themes/default/menu.down.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openai/box2d-py/HEAD/examples/data/themes/default/menu.down.tga -------------------------------------------------------------------------------- /examples/data/themes/default/menu.hover.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openai/box2d-py/HEAD/examples/data/themes/default/menu.hover.tga -------------------------------------------------------------------------------- /examples/data/themes/default/rdot.down.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openai/box2d-py/HEAD/examples/data/themes/default/rdot.down.png -------------------------------------------------------------------------------- /examples/data/themes/default/rdot.hover.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openai/box2d-py/HEAD/examples/data/themes/default/rdot.hover.png -------------------------------------------------------------------------------- /examples/data/themes/default/tool.down.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openai/box2d-py/HEAD/examples/data/themes/default/tool.down.tga -------------------------------------------------------------------------------- /examples/data/themes/default/tool.hover.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openai/box2d-py/HEAD/examples/data/themes/default/tool.hover.tga -------------------------------------------------------------------------------- /examples/data/themes/default/vdot.down.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openai/box2d-py/HEAD/examples/data/themes/default/vdot.down.png -------------------------------------------------------------------------------- /examples/data/themes/default/vdot.hover.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openai/box2d-py/HEAD/examples/data/themes/default/vdot.hover.png -------------------------------------------------------------------------------- /examples/data/themes/default/vslider.up.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openai/box2d-py/HEAD/examples/data/themes/default/vslider.up.tga -------------------------------------------------------------------------------- /examples/data/themes/gray/button.normal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openai/box2d-py/HEAD/examples/data/themes/gray/button.normal.png -------------------------------------------------------------------------------- /examples/data/themes/gray/input.normal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openai/box2d-py/HEAD/examples/data/themes/gray/input.normal.png -------------------------------------------------------------------------------- /examples/data/themes/gray/radio.on.down.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openai/box2d-py/HEAD/examples/data/themes/gray/radio.on.down.png -------------------------------------------------------------------------------- /examples/data/themes/gray/select.arrow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openai/box2d-py/HEAD/examples/data/themes/gray/select.arrow.png -------------------------------------------------------------------------------- /examples/data/themes/tools/icons48.bkgr.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openai/box2d-py/HEAD/examples/data/themes/tools/icons48.bkgr.tga -------------------------------------------------------------------------------- /examples/data/themes/tools/icons48.code.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openai/box2d-py/HEAD/examples/data/themes/tools/icons48.code.tga -------------------------------------------------------------------------------- /examples/data/themes/tools/icons48.draw.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openai/box2d-py/HEAD/examples/data/themes/tools/icons48.draw.tga -------------------------------------------------------------------------------- /examples/data/themes/tools/icons48.fill.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openai/box2d-py/HEAD/examples/data/themes/tools/icons48.fill.tga -------------------------------------------------------------------------------- /examples/data/themes/tools/icons48.line.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openai/box2d-py/HEAD/examples/data/themes/tools/icons48.line.tga -------------------------------------------------------------------------------- /examples/data/themes/tools/icons48.tile.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openai/box2d-py/HEAD/examples/data/themes/tools/icons48.tile.tga -------------------------------------------------------------------------------- /examples/data/themes/default/button.down.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openai/box2d-py/HEAD/examples/data/themes/default/button.down.tga -------------------------------------------------------------------------------- /examples/data/themes/default/button.hover.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openai/box2d-py/HEAD/examples/data/themes/default/button.hover.tga -------------------------------------------------------------------------------- /examples/data/themes/default/button.normal.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openai/box2d-py/HEAD/examples/data/themes/default/button.normal.tga -------------------------------------------------------------------------------- /examples/data/themes/default/hslider.left.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openai/box2d-py/HEAD/examples/data/themes/default/hslider.left.tga -------------------------------------------------------------------------------- /examples/data/themes/default/hslider.right.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openai/box2d-py/HEAD/examples/data/themes/default/hslider.right.tga -------------------------------------------------------------------------------- /examples/data/themes/default/idot.normal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openai/box2d-py/HEAD/examples/data/themes/default/idot.normal.png -------------------------------------------------------------------------------- /examples/data/themes/default/input.focus.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openai/box2d-py/HEAD/examples/data/themes/default/input.focus.png -------------------------------------------------------------------------------- /examples/data/themes/default/input.normal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openai/box2d-py/HEAD/examples/data/themes/default/input.normal.png -------------------------------------------------------------------------------- /examples/data/themes/default/listitem.down.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openai/box2d-py/HEAD/examples/data/themes/default/listitem.down.tga -------------------------------------------------------------------------------- /examples/data/themes/default/menu.normal.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openai/box2d-py/HEAD/examples/data/themes/default/menu.normal.tga -------------------------------------------------------------------------------- /examples/data/themes/default/progressbar.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openai/box2d-py/HEAD/examples/data/themes/default/progressbar.tga -------------------------------------------------------------------------------- /examples/data/themes/default/rdot.normal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openai/box2d-py/HEAD/examples/data/themes/default/rdot.normal.png -------------------------------------------------------------------------------- /examples/data/themes/default/sbox.normal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openai/box2d-py/HEAD/examples/data/themes/default/sbox.normal.png -------------------------------------------------------------------------------- /examples/data/themes/default/select.arrow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openai/box2d-py/HEAD/examples/data/themes/default/select.arrow.png -------------------------------------------------------------------------------- /examples/data/themes/default/tool.normal.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openai/box2d-py/HEAD/examples/data/themes/default/tool.normal.tga -------------------------------------------------------------------------------- /examples/data/themes/default/vbox.normal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openai/box2d-py/HEAD/examples/data/themes/default/vbox.normal.png -------------------------------------------------------------------------------- /examples/data/themes/default/vdot.normal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openai/box2d-py/HEAD/examples/data/themes/default/vdot.normal.png -------------------------------------------------------------------------------- /examples/data/themes/default/vsbox.normal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openai/box2d-py/HEAD/examples/data/themes/default/vsbox.normal.png -------------------------------------------------------------------------------- /examples/data/themes/default/vslider.down.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openai/box2d-py/HEAD/examples/data/themes/default/vslider.down.tga -------------------------------------------------------------------------------- /examples/data/themes/gray/checkbox.on.down.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openai/box2d-py/HEAD/examples/data/themes/gray/checkbox.on.down.png -------------------------------------------------------------------------------- /examples/data/themes/gray/list.item.normal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openai/box2d-py/HEAD/examples/data/themes/gray/list.item.normal.png -------------------------------------------------------------------------------- /examples/data/themes/gray/radio.off.down.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openai/box2d-py/HEAD/examples/data/themes/gray/radio.off.down.png -------------------------------------------------------------------------------- /examples/data/themes/gray/radio.off.normal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openai/box2d-py/HEAD/examples/data/themes/gray/radio.off.normal.png -------------------------------------------------------------------------------- /examples/data/themes/gray/radio.on.normal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openai/box2d-py/HEAD/examples/data/themes/gray/radio.on.normal.png -------------------------------------------------------------------------------- /examples/data/themes/gray/select.options.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openai/box2d-py/HEAD/examples/data/themes/gray/select.options.png -------------------------------------------------------------------------------- /examples/data/themes/tools/icons48.eraser.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openai/box2d-py/HEAD/examples/data/themes/tools/icons48.eraser.tga -------------------------------------------------------------------------------- /examples/data/themes/tools/icons48.pixel.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openai/box2d-py/HEAD/examples/data/themes/tools/icons48.pixel.tga -------------------------------------------------------------------------------- /examples/data/themes/tools/icons48.select.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openai/box2d-py/HEAD/examples/data/themes/tools/icons48.select.tga -------------------------------------------------------------------------------- /examples/data/themes/default/list.item.down.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openai/box2d-py/HEAD/examples/data/themes/default/list.item.down.png -------------------------------------------------------------------------------- /examples/data/themes/default/list.item.hover.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openai/box2d-py/HEAD/examples/data/themes/default/list.item.hover.png -------------------------------------------------------------------------------- /examples/data/themes/default/listitem.hover.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openai/box2d-py/HEAD/examples/data/themes/default/listitem.hover.tga -------------------------------------------------------------------------------- /examples/data/themes/default/listitem.normal.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openai/box2d-py/HEAD/examples/data/themes/default/listitem.normal.tga -------------------------------------------------------------------------------- /examples/data/themes/default/progressbar.bar.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openai/box2d-py/HEAD/examples/data/themes/default/progressbar.bar.tga -------------------------------------------------------------------------------- /examples/data/themes/default/radio.off.hover.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openai/box2d-py/HEAD/examples/data/themes/default/radio.off.hover.tga -------------------------------------------------------------------------------- /examples/data/themes/default/radio.on.hover.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openai/box2d-py/HEAD/examples/data/themes/default/radio.on.hover.tga -------------------------------------------------------------------------------- /examples/data/themes/default/radio.on.normal.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openai/box2d-py/HEAD/examples/data/themes/default/radio.on.normal.tga -------------------------------------------------------------------------------- /examples/data/themes/default/select.options.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openai/box2d-py/HEAD/examples/data/themes/default/select.options.png -------------------------------------------------------------------------------- /examples/data/themes/gray/checkbox.off.down.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openai/box2d-py/HEAD/examples/data/themes/gray/checkbox.off.down.png -------------------------------------------------------------------------------- /examples/data/themes/gray/checkbox.on.normal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openai/box2d-py/HEAD/examples/data/themes/gray/checkbox.on.normal.png -------------------------------------------------------------------------------- /examples/data/themes/gray/dialog.close.down.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openai/box2d-py/HEAD/examples/data/themes/gray/dialog.close.down.png -------------------------------------------------------------------------------- /examples/data/themes/gray/filebrowser.folder.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openai/box2d-py/HEAD/examples/data/themes/gray/filebrowser.folder.png -------------------------------------------------------------------------------- /examples/data/themes/gray/menu.option.hover.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openai/box2d-py/HEAD/examples/data/themes/gray/menu.option.hover.png -------------------------------------------------------------------------------- /examples/data/themes/gray/menu.option.normal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openai/box2d-py/HEAD/examples/data/themes/gray/menu.option.normal.png -------------------------------------------------------------------------------- /examples/data/themes/gray/select.arrow.down.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openai/box2d-py/HEAD/examples/data/themes/gray/select.arrow.down.png -------------------------------------------------------------------------------- /examples/data/themes/gray/slider.bar.normal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openai/box2d-py/HEAD/examples/data/themes/gray/slider.bar.normal.png -------------------------------------------------------------------------------- /examples/data/themes/default/checkbox.off.hover.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openai/box2d-py/HEAD/examples/data/themes/default/checkbox.off.hover.tga -------------------------------------------------------------------------------- /examples/data/themes/default/checkbox.on.hover.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openai/box2d-py/HEAD/examples/data/themes/default/checkbox.on.hover.tga -------------------------------------------------------------------------------- /examples/data/themes/default/checkbox.on.normal.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openai/box2d-py/HEAD/examples/data/themes/default/checkbox.on.normal.tga -------------------------------------------------------------------------------- /examples/data/themes/default/dialog.close.down.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openai/box2d-py/HEAD/examples/data/themes/default/dialog.close.down.tga -------------------------------------------------------------------------------- /examples/data/themes/default/dialog.close.hover.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openai/box2d-py/HEAD/examples/data/themes/default/dialog.close.hover.tga -------------------------------------------------------------------------------- /examples/data/themes/default/filebrowser.folder.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openai/box2d-py/HEAD/examples/data/themes/default/filebrowser.folder.png -------------------------------------------------------------------------------- /examples/data/themes/default/hslider.bar.hover.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openai/box2d-py/HEAD/examples/data/themes/default/hslider.bar.hover.tga -------------------------------------------------------------------------------- /examples/data/themes/default/hslider.bar.normal.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openai/box2d-py/HEAD/examples/data/themes/default/hslider.bar.normal.tga -------------------------------------------------------------------------------- /examples/data/themes/default/list.item.normal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openai/box2d-py/HEAD/examples/data/themes/default/list.item.normal.png -------------------------------------------------------------------------------- /examples/data/themes/default/radio.off.normal.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openai/box2d-py/HEAD/examples/data/themes/default/radio.off.normal.tga -------------------------------------------------------------------------------- /examples/data/themes/default/scroller.slide.h.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openai/box2d-py/HEAD/examples/data/themes/default/scroller.slide.h.tga -------------------------------------------------------------------------------- /examples/data/themes/default/scroller.slide.v.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openai/box2d-py/HEAD/examples/data/themes/default/scroller.slide.v.tga -------------------------------------------------------------------------------- /examples/data/themes/default/select.arrow.down.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openai/box2d-py/HEAD/examples/data/themes/default/select.arrow.down.tga -------------------------------------------------------------------------------- /examples/data/themes/default/select.arrow.hover.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openai/box2d-py/HEAD/examples/data/themes/default/select.arrow.hover.tga -------------------------------------------------------------------------------- /examples/data/themes/default/slider.bar.hover.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openai/box2d-py/HEAD/examples/data/themes/default/slider.bar.hover.tga -------------------------------------------------------------------------------- /examples/data/themes/default/slider.bar.normal.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openai/box2d-py/HEAD/examples/data/themes/default/slider.bar.normal.tga -------------------------------------------------------------------------------- /examples/data/themes/default/vslider.bar.hover.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openai/box2d-py/HEAD/examples/data/themes/default/vslider.bar.hover.tga -------------------------------------------------------------------------------- /examples/data/themes/default/vslider.bar.normal.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openai/box2d-py/HEAD/examples/data/themes/default/vslider.bar.normal.tga -------------------------------------------------------------------------------- /examples/data/themes/gray/checkbox.off.normal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openai/box2d-py/HEAD/examples/data/themes/gray/checkbox.off.normal.png -------------------------------------------------------------------------------- /examples/data/themes/gray/console.input.focus.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openai/box2d-py/HEAD/examples/data/themes/gray/console.input.focus.png -------------------------------------------------------------------------------- /examples/data/themes/gray/console.input.normal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openai/box2d-py/HEAD/examples/data/themes/gray/console.input.normal.png -------------------------------------------------------------------------------- /examples/data/themes/gray/dialog.close.normal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openai/box2d-py/HEAD/examples/data/themes/gray/dialog.close.normal.png -------------------------------------------------------------------------------- /examples/data/themes/gray/select.arrow.normal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openai/box2d-py/HEAD/examples/data/themes/gray/select.arrow.normal.png -------------------------------------------------------------------------------- /examples/data/themes/gray/select.option.normal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openai/box2d-py/HEAD/examples/data/themes/gray/select.option.normal.png -------------------------------------------------------------------------------- /examples/data/themes/default/checkbox.off.normal.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openai/box2d-py/HEAD/examples/data/themes/default/checkbox.off.normal.tga -------------------------------------------------------------------------------- /examples/data/themes/default/console.input.focus.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openai/box2d-py/HEAD/examples/data/themes/default/console.input.focus.png -------------------------------------------------------------------------------- /examples/data/themes/default/console.input.normal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openai/box2d-py/HEAD/examples/data/themes/default/console.input.normal.png -------------------------------------------------------------------------------- /examples/data/themes/default/dialog.close.normal.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openai/box2d-py/HEAD/examples/data/themes/default/dialog.close.normal.tga -------------------------------------------------------------------------------- /examples/data/themes/default/select.arrow.normal.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openai/box2d-py/HEAD/examples/data/themes/default/select.arrow.normal.tga -------------------------------------------------------------------------------- /examples/data/themes/default/select.option.hover.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openai/box2d-py/HEAD/examples/data/themes/default/select.option.hover.png -------------------------------------------------------------------------------- /examples/data/themes/default/select.option.normal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openai/box2d-py/HEAD/examples/data/themes/default/select.option.normal.png -------------------------------------------------------------------------------- /examples/data/themes/default/select.selected.down.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openai/box2d-py/HEAD/examples/data/themes/default/select.selected.down.tga -------------------------------------------------------------------------------- /examples/data/themes/gray/select.selected.normal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openai/box2d-py/HEAD/examples/data/themes/gray/select.selected.normal.png -------------------------------------------------------------------------------- /examples/pgu/__init__.py: -------------------------------------------------------------------------------- 1 | """Phil's pyGame Utilities 2 | 3 | 4 | """ 5 | __version__ = '0.14' 6 | 7 | # vim: set filetype=python sts=4 sw=4 noet si : 8 | -------------------------------------------------------------------------------- /examples/data/themes/default/select.selected.hover.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openai/box2d-py/HEAD/examples/data/themes/default/select.selected.hover.tga -------------------------------------------------------------------------------- /examples/data/themes/default/select.selected.normal.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openai/box2d-py/HEAD/examples/data/themes/default/select.selected.normal.tga -------------------------------------------------------------------------------- /examples/data/themes/default/scroller.slide.bar.hover.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openai/box2d-py/HEAD/examples/data/themes/default/scroller.slide.bar.hover.tga -------------------------------------------------------------------------------- /examples/data/themes/default/scroller.slide.bar.normal.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openai/box2d-py/HEAD/examples/data/themes/default/scroller.slide.bar.normal.tga -------------------------------------------------------------------------------- /examples/data/themes/default/notes.txt: -------------------------------------------------------------------------------- 1 | dot and box.xcf: 2 | 3 | color -170 4 | 5 | .down 6 | .hover +64 brightness 7 | .normal, grayscale +127 brightness, +48 contrast 8 | 9 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | **Status:** Maintenance (expect bug fixes and minor updates) 2 | 3 | This is a repackaged version of [pybox2d](https://github.com/pybox2d/pybox2d). For all information, see that repo. For licensing information, see `LICENSE`. 4 | -------------------------------------------------------------------------------- /deploy.sh: -------------------------------------------------------------------------------- 1 | set -ex 2 | 3 | if [[ ! -z "$TRAVIS_TAG" ]]; then 4 | ls -lht ./wheelhouse 5 | pip install twine 6 | twine upload ./wheelhouse/box2d_py-* 7 | 8 | if [[ ! -z "$DEPLOY_SDIST" ]]; then 9 | python setup.py sdist 10 | twine upload dist/* 11 | fi 12 | fi 13 | 14 | -------------------------------------------------------------------------------- /config.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | function pre_build { 3 | set -ex 4 | build_swig 5 | pip install . 6 | pip install nose coverage 7 | nosetests -v -w tests/ --with-coverage --cover-package=Box2D 8 | } 9 | 10 | function run_tests { 11 | pip install gym[box2d] 12 | python -c "import gym; gym.make('LunarLander-v2')" 13 | } 14 | 15 | -------------------------------------------------------------------------------- /examples/data/themes/tools/config.txt: -------------------------------------------------------------------------------- 1 | tool.draw image icons48.draw.tga 2 | tool.pixel image icons48.pixel.tga 3 | tool.line image icons48.line.tga 4 | tool.fill image icons48.fill.tga 5 | 6 | tool.select image icons48.select.tga 7 | tool.eraser image icons48.eraser.tga 8 | 9 | tool.tile image icons48.tile.tga 10 | tool.code image icons48.code.tga 11 | tool.bkgr image icons48.bkgr.tga 12 | -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | include INSTALL 2 | include LICENSE 3 | include MANIFEST.in 4 | include MANIFEST 5 | include README 6 | include setup.py 7 | include distribute_setup.py 8 | recursive-include examples *.py 9 | recursive-include examples/data *.png *.tga *.txt *.ttf 10 | recursive-include examples/pgu * 11 | recursive-include library *.py 12 | recursive-include Box2D *.py *.i *.cpp *.h *.c *.txt 13 | -------------------------------------------------------------------------------- /devel/release.cmd: -------------------------------------------------------------------------------- 1 | set HOME=C:\Users\Ken\ 2 | set NAME="Ken Lauer" 3 | 4 | cd .. 5 | del /s /f /q build 6 | C:\Python27\python.exe setup.py bdist_egg upload --identity=%NAME% --sign --quiet 7 | C:\Python27\python.exe setup.py bdist_wininst --target-version=2.7 register upload --identity=%NAME% --sign --quiet 8 | C:\Python27\python.exe setup.py sdist upload --identity=%NAME% --sign 9 | cd devel 10 | -------------------------------------------------------------------------------- /examples/pgu/gui/pguglobals.py: -------------------------------------------------------------------------------- 1 | """Contains the global reference to the PGU application.""" 2 | 3 | # pguglobals.py - A place to stick global variables that need to be accessed 4 | # from other modules. To avoid problems with circular imports 5 | # this module should not import any other PGU module. 6 | 7 | # A global reference to the application instance (App class) 8 | app = None 9 | 10 | -------------------------------------------------------------------------------- /tests/basics.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | import unittest 4 | import sys 5 | 6 | class testBasic (unittest.TestCase): 7 | # def setUp(self): 8 | # pass 9 | 10 | def test_import(self): 11 | try: 12 | import Box2D 13 | except ImportError: 14 | self.fail("Unable to import Box2D library (%s)" % sys.exc_info()[1]) 15 | 16 | if __name__ == '__main__': 17 | unittest.main() 18 | 19 | -------------------------------------------------------------------------------- /environ-26.cmd: -------------------------------------------------------------------------------- 1 | @echo off 2 | set LC_ALL=en_US 3 | set EDITOR=c:\vim72\vim.exe 4 | set PYTHON_PATH=C:\python26\ 5 | set SWIG_PATH=C:\swigwin-1.3.40\ 6 | set PATH=%PATH%;%PYTHON_PATH%;%SWIG_PATH% 7 | echo Using Python in %PYTHON_PATH% 8 | echo Checking version... 9 | echo --- 10 | python.exe -V 11 | echo --- 12 | echo Using SWIG in %SWIG_PATH% 13 | echo Checking version... 14 | echo --- 15 | swig.exe -version 16 | echo --- 17 | echo Type 'setup.py build', and then 'setup.py install' to install. 18 | -------------------------------------------------------------------------------- /examples/pgu/gui/const.py: -------------------------------------------------------------------------------- 1 | """Constants. 2 | 3 | From pygame: 4 | QUIT 5 | MOUSEBUTTONDOWN 6 | MOUSEBUTTONUP 7 | MOUSEMOTION 8 | KEYDOWN 9 | 10 | PGU specific: 11 | ENTER 12 | EXIT 13 | BLUR 14 | FOCUS 15 | CLICK 16 | CHANGE 17 | OPEN 18 | CLOSE 19 | INIT 20 | 21 | Other: 22 | NOATTR 23 | 24 | """ 25 | import pygame 26 | 27 | from pygame.locals import QUIT, MOUSEBUTTONDOWN, MOUSEBUTTONUP, MOUSEMOTION, KEYDOWN, USEREVENT 28 | ENTER = pygame.locals.USEREVENT + 0 29 | EXIT = pygame.locals.USEREVENT + 1 30 | BLUR = pygame.locals.USEREVENT + 2 31 | FOCUS = pygame.locals.USEREVENT + 3 32 | CLICK = pygame.locals.USEREVENT + 4 33 | CHANGE = pygame.locals.USEREVENT + 5 34 | OPEN = pygame.locals.USEREVENT + 6 35 | CLOSE = pygame.locals.USEREVENT + 7 36 | INIT = 'init' 37 | 38 | class NOATTR: 39 | pass 40 | 41 | 42 | -------------------------------------------------------------------------------- /Box2D/Box2D-License.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com 2 | 3 | This software is provided 'as-is', without any express or implied 4 | warranty. In no event will the authors be held liable for any damages 5 | arising from the use of this software. 6 | 7 | Permission is granted to anyone to use this software for any purpose, 8 | including commercial applications, and to alter it and redistribute it 9 | freely, subject to the following restrictions: 10 | 11 | 1. The origin of this software must not be misrepresented; you must not 12 | claim that you wrote the original software. If you use this software 13 | in a product, an acknowledgment in the product documentation would be 14 | appreciated but is not required. 15 | 2. Altered source versions must be plainly marked as such, and must not be 16 | misrepresented as being the original software. 17 | 3. This notice may not be removed or altered from any source distribution. 18 | 19 | -------------------------------------------------------------------------------- /Box2D/pybox2d_license_header.txt: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # 3 | # C++ version copyright 2010 Erin Catto http://www.gphysics.com 4 | # Python version copyright 2010 Ken Lauer / sirkne at gmail dot com 5 | # 6 | # This software is provided 'as-is', without any express or implied 7 | # warranty. In no event will the authors be held liable for any damages 8 | # arising from the use of this software. 9 | # Permission is granted to anyone to use this software for any purpose, 10 | # including commercial applications, and to alter it and redistribute it 11 | # freely, subject to the following restrictions: 12 | # 1. The origin of this software must not be misrepresented; you must not 13 | # claim that you wrote the original software. If you use this software 14 | # in a product, an acknowledgment in the product documentation would be 15 | # appreciated but is not required. 16 | # 2. Altered source versions must be plainly marked as such, and must not be 17 | # misrepresented as being the original software. 18 | # 3. This notice may not be removed or altered from any source distribution. 19 | # 20 | -------------------------------------------------------------------------------- /examples/pgu/gui/style.py: -------------------------------------------------------------------------------- 1 | """ 2 | """ 3 | 4 | from . import pguglobals 5 | 6 | class Style: 7 | """The class used by widget for the widget.style 8 | 9 | This object is used mainly as a dictionary, accessed via widget.style.attr, 10 | as opposed to widget.style['attr']. It automatically grabs information 11 | from the theme via value = theme.get(widget.cls,widget.pcls,attr) 12 | 13 | """ 14 | def __init__(self, obj, dict): 15 | self.obj = obj 16 | for k,v in dict.items(): self.__dict__[k]=v 17 | 18 | def __getattr__(self, attr): 19 | value = pguglobals.app.theme.get(self.obj.cls, self.obj.pcls, attr) 20 | 21 | if attr in ( 22 | 'border_top','border_right','border_bottom','border_left', 23 | 'padding_top','padding_right','padding_bottom','padding_left', 24 | 'margin_top','margin_right','margin_bottom','margin_left', 25 | 'align','valign','width','height', 26 | ): self.__dict__[attr] = value 27 | return value 28 | 29 | def __setattr__(self, attr, value): 30 | self.__dict__[attr] = value 31 | 32 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | This software is covered under the zlib license. 2 | 3 | C++ version Copyright (c) 2006-2011 Erin Catto http://www.box2d.org 4 | Python version Copyright (c) 2008-2011 Ken Lauer / sirkne at gmail dot com 5 | 6 | Implemented using the pybox2d SWIG interface for Box2D (pybox2d.googlecode.com) 7 | 8 | This software is provided 'as-is', without any express or implied 9 | warranty. In no event will the authors be held liable for any damages 10 | arising from the use of this software. 11 | Permission is granted to anyone to use this software for any purpose, 12 | including commercial applications, and to alter it and redistribute it 13 | freely, subject to the following restrictions: 14 | 1. The origin of this software must not be misrepresented; you must not 15 | claim that you wrote the original software. If you use this software 16 | in a product, an acknowledgment in the product documentation would be 17 | appreciated but is not required. 18 | 2. Altered source versions must be plainly marked as such, and must not be 19 | misrepresented as being the original software. 20 | 3. This notice may not be removed or altered from any source distribution. 21 | 22 | -------------------------------------------------------------------------------- /examples/pgu/gui/misc.py: -------------------------------------------------------------------------------- 1 | from .const import * 2 | from . import widget 3 | from . import pguglobals 4 | 5 | class ProgressBar(widget.Widget): 6 | """A progress bar widget. 7 | 8 | Example: 9 | w = gui.ProgressBar(0,0,100) 10 | w.value = 25 11 | 12 | """ 13 | 14 | _value = None 15 | 16 | def __init__(self,value,min,max,**params): 17 | params.setdefault('cls','progressbar') 18 | widget.Widget.__init__(self,**params) 19 | self.min,self.max,self.value = min,max,value 20 | 21 | def paint(self,s): 22 | if (self.value != None): 23 | r = pygame.rect.Rect(0,0,self.rect.w,self.rect.h) 24 | r.w = r.w*(self.value-self.min)/(self.max-self.min) 25 | self.bar = r 26 | pguglobals.app.theme.render(s,self.style.bar,r) 27 | 28 | @property 29 | def value(self): 30 | return self._value 31 | 32 | @value.setter 33 | def value(self, val): 34 | val = int(val) 35 | val = max(val, self.min) 36 | val = min(val, self.max) 37 | oldval = self._value 38 | self._value = val 39 | if (oldval != val): 40 | self.send(CHANGE) 41 | self.repaint() 42 | 43 | 44 | -------------------------------------------------------------------------------- /devel/find_extended.py: -------------------------------------------------------------------------------- 1 | from __future__ import print_function 2 | import glob 3 | import re 4 | import os 5 | from all_classes import * 6 | 7 | files = glob.glob('../Box2D/Box2D_*.i') 8 | classes = {} 9 | ignore_files = [ 10 | 'Box2D_kwargs.i', 11 | 'Box2D_dir.i', 12 | ] 13 | 14 | def find_extended(path): 15 | f = open(path, "r") 16 | fn = os.path.split(path)[1] 17 | for line in f.readlines(): 18 | m=re.search('%extend\s*(.*)\s*{', line) 19 | if m: 20 | cls=m.groups()[0].strip() 21 | if cls in classes: 22 | if fn not in classes[cls]: 23 | classes[cls].append(fn) 24 | else: 25 | classes[cls] = [fn] 26 | 27 | f.close() 28 | 29 | for file in files: 30 | if os.path.split(file)[1] not in ignore_files: 31 | find_extended(file) 32 | 33 | print("%19s %s" % ('Class', 'Extended in')) 34 | remaining=list(all_classes) 35 | for key, value in list(classes.items()): 36 | print("%20s %s" % (key, ', '.join(value))) 37 | remaining.remove(key) 38 | 39 | ignore_unmodified=[s for s in remaining if s[-3:] == 'Def'] 40 | #ignore_unmodified += [] 41 | 42 | print() 43 | print("Unmodified classes") 44 | for cls in remaining: 45 | if cls not in ignore_unmodified: 46 | print(cls) 47 | -------------------------------------------------------------------------------- /examples/pgu/gui/group.py: -------------------------------------------------------------------------------- 1 | """ 2 | """ 3 | from .const import * 4 | from . import widget 5 | 6 | class Group(widget.Widget): 7 | """An object for grouping together Form elements. 8 | 9 | When the value changes, an gui.CHANGE event is sent. Although note, 10 | that when the value is a list, it may have to be sent by hand via 11 | g.send(gui.CHANGE). 12 | 13 | """ 14 | 15 | _value = None 16 | widgets = None 17 | 18 | def __init__(self,name=None,value=None): 19 | """Create Group instance. 20 | 21 | Arguments: 22 | name -- name as used in the Form 23 | value -- values that are currently selected in the group 24 | 25 | """ 26 | widget.Widget.__init__(self,name=name,value=value) 27 | self.widgets = [] 28 | 29 | def add(self,w): 30 | """Add a widget to this group.""" 31 | self.widgets.append(w) 32 | 33 | @property 34 | def value(self): 35 | return self._value 36 | 37 | @value.setter 38 | def value(self, val): 39 | oldval = self._value 40 | self._value = val 41 | if (oldval != val): 42 | self._change() 43 | 44 | def _change(self): 45 | self.send(CHANGE) 46 | if (self.widgets): 47 | for w in self.widgets: 48 | w.repaint() 49 | 50 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | env: 2 | global: 3 | - REPO_DIR=. 4 | - BUILD_COMMIT=$TRAVIS_COMMIT 5 | - PLAT=x86_64 6 | 7 | install: 8 | - git clone https://github.com/multi-build/multibuild 9 | - . multibuild/common_utils.sh 10 | - . multibuild/travis_steps.sh 11 | - before_install 12 | # - clean_code $REPO_DIR $BUILD_COMMIT 13 | - build_wheel $REPO_DIR $PLAT 14 | script: 15 | - install_run $PLAT 16 | 17 | after_success: 18 | - ./deploy.sh 19 | 20 | matrix: 21 | include: 22 | 23 | - os: linux 24 | env: 25 | - MB_PYTHON_VERSION=3.6 26 | 27 | - os: linux 28 | env: 29 | - MB_PYTHON_VERSION=3.7 30 | 31 | - os: linux 32 | env: 33 | - MB_PYTHON_VERSION=3.8 34 | 35 | - os: linux 36 | env: 37 | - MB_PYTHON_VERSION=3.9 38 | 39 | 40 | - os: osx 41 | osx_image: xcode8.3 42 | env: 43 | - MB_PYTHON_VERSION=3.5 44 | - DEPLOY_SDIST=true 45 | 46 | - os: osx 47 | osx_image: xcode8.3 48 | env: 49 | - MB_PYTHON_VERSION=3.6 50 | 51 | - os: osx 52 | osx_image: xcode8.3 53 | env: 54 | - MB_PYTHON_VERSION=3.7 55 | 56 | - os: osx 57 | osx_image: xcode8.3 58 | env: 59 | - MB_PYTHON_VERSION=3.8 60 | 61 | - os: osx 62 | osx_image: xcode8.3 63 | env: 64 | - MB_PYTHON_VERSION=3.9 65 | 66 | 67 | -------------------------------------------------------------------------------- /Box2D/Common/b2Draw.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Erin Catto http://box2d.org 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked as such, and must not be 15 | * misrepresented as being the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | #include 20 | 21 | b2Draw::b2Draw() 22 | { 23 | m_drawFlags = 0; 24 | } 25 | 26 | void b2Draw::SetFlags(uint32 flags) 27 | { 28 | m_drawFlags = flags; 29 | } 30 | 31 | uint32 b2Draw::GetFlags() const 32 | { 33 | return m_drawFlags; 34 | } 35 | 36 | void b2Draw::AppendFlags(uint32 flags) 37 | { 38 | m_drawFlags |= flags; 39 | } 40 | 41 | void b2Draw::ClearFlags(uint32 flags) 42 | { 43 | m_drawFlags &= ~flags; 44 | } 45 | -------------------------------------------------------------------------------- /examples/pgu/gui/__init__.py: -------------------------------------------------------------------------------- 1 | """Modules for creating a widget-based user interface. See the examples folder 2 | for sample scripts that use this module.""" 3 | 4 | import pygame 5 | 6 | # The basestring class was removed in Python 3, but we want to keep it to maintain 7 | # compatibility with previous versions of python. 8 | try: 9 | __builtins__["basestring"] 10 | except KeyError: 11 | __builtins__["basestring"] = str 12 | 13 | from .theme import Theme 14 | from .style import Style 15 | from .widget import Widget 16 | from .surface import subsurface, ProxySurface 17 | from .const import * 18 | 19 | from .container import Container 20 | from .app import App, Desktop 21 | from .table import Table 22 | from .document import Document 23 | #html 24 | from .area import SlideBox, ScrollArea, List 25 | 26 | from .form import Form 27 | from .group import Group 28 | 29 | from .basic import Spacer, Color, Label, Image, parse_color 30 | from .button import Icon, Button, Switch, Checkbox, Radio, Tool, Link 31 | from .input import Input, Password 32 | from .keysym import Keysym 33 | from .slider import VSlider, HSlider, VScrollBar, HScrollBar 34 | from .select import Select 35 | from .misc import ProgressBar 36 | 37 | from .menus import Menus 38 | from .dialog import Dialog, FileDialog 39 | from .textarea import TextArea 40 | 41 | from .deprecated import Toolbox, action_open, action_setvalue, action_quit, action_exec 42 | -------------------------------------------------------------------------------- /Box2D/Dynamics/Contacts/b2NullContact.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2009 Erin Catto http://www.gphysics.com 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked as such, and must not be 15 | * misrepresented as being the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | #ifndef B2_NULL_CONTACT_H 20 | #define B2_NULL_CONTACT_H 21 | 22 | #include 23 | 24 | class b2NullContact : public b2Contact 25 | { 26 | public: 27 | b2NullContact() {} 28 | void Evaluate() {} 29 | float32 ComputeTOI(const b2Sweep& sweepA, const b2Sweep& sweepB) const 30 | { 31 | B2_NOT_USED(sweepA); 32 | B2_NOT_USED(sweepB); 33 | return 1.0f; 34 | } 35 | }; 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /tests/test_edgechain.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | import unittest 4 | import Box2D as b2 5 | import sys 6 | 7 | class testEdgeChain (unittest.TestCase): 8 | def setUp(self): 9 | pass 10 | 11 | def test_create_edge_chain(self): 12 | world = b2.b2World() 13 | 14 | ground = world.CreateBody(position=(0, 20)) 15 | 16 | try: 17 | ground.CreateEdgeChain([]) 18 | except ValueError: 19 | pass #good 20 | except Exception: 21 | self.fail("Failed to create empty edge chain (%s)" % sys.exc_info()[1]) 22 | 23 | try: 24 | ground.CreateEdgeChain( 25 | [ (-20,-20), 26 | (-20, 20), 27 | ( 20, 20), 28 | ( 20,-20), 29 | (-20,-20) ] 30 | ) 31 | except Exception: 32 | self.fail("Failed to create valid edge chain (%s)" % sys.exc_info()[1]) 33 | 34 | def test_b2EdgeShape(self): 35 | world = b2.b2World() 36 | 37 | v1=(-10.0, 0.0) 38 | v2=(-7.0, -1.0) 39 | v3=(-4.0, 0.0) 40 | 41 | ground=world.CreateStaticBody(shapes= 42 | [b2.b2EdgeShape(vertices=[None, v1, v2, v3])]) 43 | 44 | if __name__ == '__main__': 45 | unittest.main() 46 | 47 | -------------------------------------------------------------------------------- /Box2D/Common/b2Settings.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2009 Erin Catto http://www.box2d.org 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked as such, and must not be 15 | * misrepresented as being the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | b2Version b2_version = {2, 3, 0}; 25 | 26 | // Memory allocators. Modify these to use your own allocator. 27 | void* b2Alloc(int32 size) 28 | { 29 | return malloc(size); 30 | } 31 | 32 | void b2Free(void* mem) 33 | { 34 | free(mem); 35 | } 36 | 37 | // You can modify this to use your logging facility. 38 | void b2Log(const char* string, ...) 39 | { 40 | va_list args; 41 | va_start(args, string); 42 | vprintf(string, args); 43 | va_end(args); 44 | } 45 | -------------------------------------------------------------------------------- /Box2D/Dynamics/Contacts/b2CircleContact.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2009 Erin Catto http://www.box2d.org 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked as such, and must not be 15 | * misrepresented as being the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | #ifndef B2_CIRCLE_CONTACT_H 20 | #define B2_CIRCLE_CONTACT_H 21 | 22 | #include 23 | 24 | class b2BlockAllocator; 25 | 26 | class b2CircleContact : public b2Contact 27 | { 28 | public: 29 | static b2Contact* Create( b2Fixture* fixtureA, int32 indexA, 30 | b2Fixture* fixtureB, int32 indexB, b2BlockAllocator* allocator); 31 | static void Destroy(b2Contact* contact, b2BlockAllocator* allocator); 32 | 33 | b2CircleContact(b2Fixture* fixtureA, b2Fixture* fixtureB); 34 | ~b2CircleContact() {} 35 | 36 | void Evaluate(b2Manifold* manifold, const b2Transform& xfA, const b2Transform& xfB); 37 | }; 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /Box2D/Dynamics/Contacts/b2PolygonContact.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2009 Erin Catto http://www.box2d.org 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked as such, and must not be 15 | * misrepresented as being the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | #ifndef B2_POLYGON_CONTACT_H 20 | #define B2_POLYGON_CONTACT_H 21 | 22 | #include 23 | 24 | class b2BlockAllocator; 25 | 26 | class b2PolygonContact : public b2Contact 27 | { 28 | public: 29 | static b2Contact* Create( b2Fixture* fixtureA, int32 indexA, 30 | b2Fixture* fixtureB, int32 indexB, b2BlockAllocator* allocator); 31 | static void Destroy(b2Contact* contact, b2BlockAllocator* allocator); 32 | 33 | b2PolygonContact(b2Fixture* fixtureA, b2Fixture* fixtureB); 34 | ~b2PolygonContact() {} 35 | 36 | void Evaluate(b2Manifold* manifold, const b2Transform& xfA, const b2Transform& xfB); 37 | }; 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /Box2D/Common/b2Timer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Erin Catto http://box2d.org 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked as such, and must not be 15 | * misrepresented as being the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | #ifndef B2_TIMER_H 20 | #define B2_TIMER_H 21 | 22 | #include 23 | 24 | /// Timer for profiling. This has platform specific code and may 25 | /// not work on every platform. 26 | class b2Timer 27 | { 28 | public: 29 | 30 | /// Constructor 31 | b2Timer(); 32 | 33 | /// Reset the timer. 34 | void Reset(); 35 | 36 | /// Get the time since construction or the last reset. 37 | float32 GetMilliseconds() const; 38 | 39 | private: 40 | 41 | #if defined(_WIN32) 42 | float64 m_start; 43 | static float64 s_invFrequency; 44 | #elif defined(__linux__) || defined (__APPLE__) 45 | unsigned long m_start_sec; 46 | unsigned long m_start_msec; 47 | #endif 48 | }; 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /Box2D/Dynamics/Contacts/b2EdgeAndCircleContact.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2009 Erin Catto http://www.box2d.org 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked as such, and must not be 15 | * misrepresented as being the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | #ifndef B2_EDGE_AND_CIRCLE_CONTACT_H 20 | #define B2_EDGE_AND_CIRCLE_CONTACT_H 21 | 22 | #include 23 | 24 | class b2BlockAllocator; 25 | 26 | class b2EdgeAndCircleContact : public b2Contact 27 | { 28 | public: 29 | static b2Contact* Create( b2Fixture* fixtureA, int32 indexA, 30 | b2Fixture* fixtureB, int32 indexB, b2BlockAllocator* allocator); 31 | static void Destroy(b2Contact* contact, b2BlockAllocator* allocator); 32 | 33 | b2EdgeAndCircleContact(b2Fixture* fixtureA, b2Fixture* fixtureB); 34 | ~b2EdgeAndCircleContact() {} 35 | 36 | void Evaluate(b2Manifold* manifold, const b2Transform& xfA, const b2Transform& xfB); 37 | }; 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /Box2D/Dynamics/Contacts/b2EdgeAndPolygonContact.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2009 Erin Catto http://www.box2d.org 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked as such, and must not be 15 | * misrepresented as being the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | #ifndef B2_EDGE_AND_POLYGON_CONTACT_H 20 | #define B2_EDGE_AND_POLYGON_CONTACT_H 21 | 22 | #include 23 | 24 | class b2BlockAllocator; 25 | 26 | class b2EdgeAndPolygonContact : public b2Contact 27 | { 28 | public: 29 | static b2Contact* Create( b2Fixture* fixtureA, int32 indexA, 30 | b2Fixture* fixtureB, int32 indexB, b2BlockAllocator* allocator); 31 | static void Destroy(b2Contact* contact, b2BlockAllocator* allocator); 32 | 33 | b2EdgeAndPolygonContact(b2Fixture* fixtureA, b2Fixture* fixtureB); 34 | ~b2EdgeAndPolygonContact() {} 35 | 36 | void Evaluate(b2Manifold* manifold, const b2Transform& xfA, const b2Transform& xfB); 37 | }; 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /Box2D/Dynamics/Contacts/b2PolygonAndCircleContact.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2009 Erin Catto http://www.box2d.org 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked as such, and must not be 15 | * misrepresented as being the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | #ifndef B2_POLYGON_AND_CIRCLE_CONTACT_H 20 | #define B2_POLYGON_AND_CIRCLE_CONTACT_H 21 | 22 | #include 23 | 24 | class b2BlockAllocator; 25 | 26 | class b2PolygonAndCircleContact : public b2Contact 27 | { 28 | public: 29 | static b2Contact* Create(b2Fixture* fixtureA, int32 indexA, b2Fixture* fixtureB, int32 indexB, b2BlockAllocator* allocator); 30 | static void Destroy(b2Contact* contact, b2BlockAllocator* allocator); 31 | 32 | b2PolygonAndCircleContact(b2Fixture* fixtureA, b2Fixture* fixtureB); 33 | ~b2PolygonAndCircleContact() {} 34 | 35 | void Evaluate(b2Manifold* manifold, const b2Transform& xfA, const b2Transform& xfB); 36 | }; 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /Box2D/Dynamics/Contacts/b2ChainAndCircleContact.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2009 Erin Catto http://www.box2d.org 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked as such, and must not be 15 | * misrepresented as being the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | #ifndef B2_CHAIN_AND_CIRCLE_CONTACT_H 20 | #define B2_CHAIN_AND_CIRCLE_CONTACT_H 21 | 22 | #include 23 | 24 | class b2BlockAllocator; 25 | 26 | class b2ChainAndCircleContact : public b2Contact 27 | { 28 | public: 29 | static b2Contact* Create( b2Fixture* fixtureA, int32 indexA, 30 | b2Fixture* fixtureB, int32 indexB, b2BlockAllocator* allocator); 31 | static void Destroy(b2Contact* contact, b2BlockAllocator* allocator); 32 | 33 | b2ChainAndCircleContact(b2Fixture* fixtureA, int32 indexA, b2Fixture* fixtureB, int32 indexB); 34 | ~b2ChainAndCircleContact() {} 35 | 36 | void Evaluate(b2Manifold* manifold, const b2Transform& xfA, const b2Transform& xfB); 37 | }; 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /Box2D/Dynamics/Contacts/b2ChainAndPolygonContact.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2009 Erin Catto http://www.box2d.org 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked as such, and must not be 15 | * misrepresented as being the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | #ifndef B2_CHAIN_AND_POLYGON_CONTACT_H 20 | #define B2_CHAIN_AND_POLYGON_CONTACT_H 21 | 22 | #include 23 | 24 | class b2BlockAllocator; 25 | 26 | class b2ChainAndPolygonContact : public b2Contact 27 | { 28 | public: 29 | static b2Contact* Create( b2Fixture* fixtureA, int32 indexA, 30 | b2Fixture* fixtureB, int32 indexB, b2BlockAllocator* allocator); 31 | static void Destroy(b2Contact* contact, b2BlockAllocator* allocator); 32 | 33 | b2ChainAndPolygonContact(b2Fixture* fixtureA, int32 indexA, b2Fixture* fixtureB, int32 indexB); 34 | ~b2ChainAndPolygonContact() {} 35 | 36 | void Evaluate(b2Manifold* manifold, const b2Transform& xfA, const b2Transform& xfB); 37 | }; 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /Box2D/Dynamics/b2WorldCallbacks.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2009 Erin Catto http://www.box2d.org 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked as such, and must not be 15 | * misrepresented as being the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | #include 20 | #include 21 | 22 | // Return true if contact calculations should be performed between these two shapes. 23 | // If you implement your own collision filter you may want to build from this implementation. 24 | bool b2ContactFilter::ShouldCollide(b2Fixture* fixtureA, b2Fixture* fixtureB) 25 | { 26 | const b2Filter& filterA = fixtureA->GetFilterData(); 27 | const b2Filter& filterB = fixtureB->GetFilterData(); 28 | 29 | if (filterA.groupIndex == filterB.groupIndex && filterA.groupIndex != 0) 30 | { 31 | return filterA.groupIndex > 0; 32 | } 33 | 34 | bool collide = (filterA.maskBits & filterB.categoryBits) != 0 && (filterA.categoryBits & filterB.maskBits) != 0; 35 | return collide; 36 | } 37 | -------------------------------------------------------------------------------- /Box2D/Dynamics/b2ContactManager.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2009 Erin Catto http://www.box2d.org 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked as such, and must not be 15 | * misrepresented as being the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | #ifndef B2_CONTACT_MANAGER_H 20 | #define B2_CONTACT_MANAGER_H 21 | 22 | #include 23 | 24 | class b2Contact; 25 | class b2ContactFilter; 26 | class b2ContactListener; 27 | class b2BlockAllocator; 28 | 29 | // Delegate of b2World. 30 | class b2ContactManager 31 | { 32 | public: 33 | b2ContactManager(); 34 | 35 | // Broad-phase callback. 36 | void AddPair(void* proxyUserDataA, void* proxyUserDataB); 37 | 38 | void FindNewContacts(); 39 | 40 | void Destroy(b2Contact* c); 41 | 42 | void Collide(); 43 | 44 | b2BroadPhase m_broadPhase; 45 | b2Contact* m_contactList; 46 | int32 m_contactCount; 47 | b2ContactFilter* m_contactFilter; 48 | b2ContactListener* m_contactListener; 49 | b2BlockAllocator* m_allocator; 50 | }; 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /library/Box2D/b2/__init__.py: -------------------------------------------------------------------------------- 1 | # pybox2d -- http://pybox2d.googlecode.com 2 | # 3 | # Copyright (c) 2010 Ken Lauer / sirkne at gmail dot com 4 | # 5 | # This software is provided 'as-is', without any express or implied 6 | # warranty. In no event will the authors be held liable for any damages 7 | # arising from the use of this software. 8 | # Permission is granted to anyone to use this software for any purpose, 9 | # including commercial applications, and to alter it and redistribute it 10 | # freely, subject to the following restrictions: 11 | # 1. The origin of this software must not be misrepresented; you must not 12 | # claim that you wrote the original software. If you use this software 13 | # in a product, an acknowledgment in the product documentation would be 14 | # appreciated but is not required. 15 | # 2. Altered source versions must be plainly marked as such, and must not be 16 | # misrepresented as being the original software. 17 | # 3. This notice may not be removed or altered from any source distribution. 18 | 19 | __author__='Ken Lauer' 20 | __license__='zlib' 21 | __date__="$Date$" 22 | __version__="$Revision$" 23 | __doc__=""" 24 | This module holds the full usable contents of pybox2d. 25 | It offers an alternative syntax in the form of: 26 | 27 | from Box2D.b2 import * 28 | a = vec2(1,1) + vec2(2,2) 29 | 30 | This is fully equivalent to: 31 | 32 | from Box2D import * 33 | a = b2Vec2(1,1) + b2Vec2(2,2) 34 | 35 | All classes that exist in the main module that are prefixed 36 | by b2 or b2_ have been stripped. Beware that importing * 37 | from a module is generally frowned upon -- this is mainly 38 | here for convenience in debugging sessions where typing 39 | b2Vec2 repeatedly gets very old very quickly (trust me, 40 | I know.) 41 | """ 42 | 43 | # Populated by the parent package (see the end of ../Box2D.py) 44 | pass 45 | -------------------------------------------------------------------------------- /Box2D/Common/b2StackAllocator.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2009 Erin Catto http://www.box2d.org 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked as such, and must not be 15 | * misrepresented as being the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | #ifndef B2_STACK_ALLOCATOR_H 20 | #define B2_STACK_ALLOCATOR_H 21 | 22 | #include 23 | 24 | const int32 b2_stackSize = 100 * 1024; // 100k 25 | const int32 b2_maxStackEntries = 32; 26 | 27 | struct b2StackEntry 28 | { 29 | char* data; 30 | int32 size; 31 | bool usedMalloc; 32 | }; 33 | 34 | // This is a stack allocator used for fast per step allocations. 35 | // You must nest allocate/free pairs. The code will assert 36 | // if you try to interleave multiple allocate/free pairs. 37 | class b2StackAllocator 38 | { 39 | public: 40 | b2StackAllocator(); 41 | ~b2StackAllocator(); 42 | 43 | void* Allocate(int32 size); 44 | void Free(void* p); 45 | 46 | int32 GetMaxAllocation() const; 47 | 48 | private: 49 | 50 | char m_data[b2_stackSize]; 51 | int32 m_index; 52 | 53 | int32 m_allocation; 54 | int32 m_maxAllocation; 55 | 56 | b2StackEntry m_entries[b2_maxStackEntries]; 57 | int32 m_entryCount; 58 | }; 59 | 60 | #endif 61 | -------------------------------------------------------------------------------- /devel/windows_release.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | for platform in ['win32', 'win-amd64']: 4 | versions=['2.5', '2.6', '2.7', '3.0', '3.1', '3.2'] 5 | 6 | def get_path(platform, version): 7 | if platform=='win32': 8 | version_path='' 9 | else: 10 | version_path='-x64' 11 | return r'c:\python%s%s\python.exe'%(version.replace('.', ''), version_path) 12 | 13 | interpreters=[get_path(platform, version) for version in versions] 14 | lib_paths=[r'build\lib.%s-%s' % (platform, version) for version in versions] 15 | 16 | print '@echo off' 17 | print 'echo ---Start--- > test_results.txt' 18 | print 'echo ---Start--- > build_results.txt' 19 | 20 | do_stuff=''' 21 | echo * %(version)s %(platform)s 22 | echo -------- %(version)s %(platform)s -------- >> build_results.txt 23 | echo -------- %(version)s %(platform)s -------- >> test_results.txt 24 | %(interpreter)s setup.py clean -a >> build_results.txt 2>&1 25 | %(interpreter)s setup.py build --force >> build_results.txt 2>&1 26 | 27 | type Box2D\pybox2d_license_header.txt > Box2D_.py 28 | type %(lib_path)s\Box2D\Box2D.py >> Box2D_.py 29 | move /y Box2D_.py %(lib_path)s\Box2D\Box2D.py 30 | %(interpreter)s setup.py develop >> build_results.txt 2>&1 31 | %(interpreter)s setup.py test >> test_results.txt 2>&1 32 | %(interpreter)s setup.py bdist_wininst -t"pybox2d" -dinstaller >> build_results.txt 2>&1 33 | %(interpreter)s setup.py bdist_egg >> build_results.txt 2>&1 34 | ''' 35 | 36 | distutils_cfg='''[build] 37 | compiler=mingw32''' 38 | 39 | for version, interpreter, lib_path in zip(versions, interpreters, lib_paths): 40 | python_path=os.path.split(interpreter)[0] 41 | if version < '2.6': 42 | cfg_file=r'%s\lib\distutils\distutils.cfg' % python_path 43 | try: 44 | open(cfg_file, 'w').write(distutils_cfg) 45 | except: 46 | pass 47 | print do_stuff % locals() 48 | -------------------------------------------------------------------------------- /examples/simple_cv.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | """ 4 | A small self contained example showing how to use OpencvDrawFuncs 5 | to integrate pybox2d into an opencv mainloop 6 | 7 | In short: 8 | One static body: 9 | + One fixture: big polygon to represent the ground 10 | Two dynamic bodies: 11 | + One fixture: a polygon 12 | + One fixture: a circle 13 | And some drawing code that extends the shape classes. 14 | 15 | John Stowers 16 | """ 17 | import cv2 18 | 19 | import Box2D 20 | from Box2D.b2 import (polygonShape, world) 21 | from opencv_draw import OpencvDrawFuncs 22 | 23 | # --- constants --- 24 | # Box2D deals with meters, but we want to display pixels, 25 | # so define a conversion factor: 26 | TARGET_FPS = 60 27 | TIME_STEP = 1.0 / TARGET_FPS 28 | 29 | # --- pybox2d world setup --- 30 | # Create the world 31 | world = world(gravity=(0, -10), doSleep=True) 32 | 33 | # And a static body to hold the ground shape 34 | ground_body = world.CreateStaticBody( 35 | position=(0, 0), 36 | shapes=polygonShape(box=(50, 1)), 37 | ) 38 | 39 | # Create a couple dynamic bodies 40 | bodyc = world.CreateDynamicBody(position=(20, 45)) 41 | circle = bodyc.CreateCircleFixture(radius=0.5, density=1, friction=0.3) 42 | 43 | bodyb = world.CreateDynamicBody(position=(30, 45), angle=15) 44 | box = bodyb.CreatePolygonFixture(box=(2, 1), density=1, friction=0.3) 45 | 46 | world.CreateWeldJoint(bodyA=bodyc, bodyB=bodyb, anchor=bodyb.worldCenter) 47 | 48 | drawer = OpencvDrawFuncs(w=640, h=480, ppm=20) 49 | drawer.install() 50 | 51 | while True: 52 | key = 0xFF & cv2.waitKey(int(TIME_STEP * 1000)) # milliseconds 53 | if key == 27: 54 | break 55 | drawer.clear_screen() 56 | 57 | drawer.draw_world(world) 58 | 59 | # Make Box2D simulate the physics of our world for one step. 60 | world.Step(TIME_STEP, 10, 10) 61 | 62 | # Flip the screen and try to keep at the target FPS 63 | cv2.imshow("world", drawer.screen) 64 | -------------------------------------------------------------------------------- /Box2D/Dynamics/b2TimeStep.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2011 Erin Catto http://www.box2d.org 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked as such, and must not be 15 | * misrepresented as being the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | #ifndef B2_TIME_STEP_H 20 | #define B2_TIME_STEP_H 21 | 22 | #include 23 | 24 | /// Profiling data. Times are in milliseconds. 25 | struct b2Profile 26 | { 27 | float32 step; 28 | float32 collide; 29 | float32 solve; 30 | float32 solveInit; 31 | float32 solveVelocity; 32 | float32 solvePosition; 33 | float32 broadphase; 34 | float32 solveTOI; 35 | }; 36 | 37 | /// This is an internal structure. 38 | struct b2TimeStep 39 | { 40 | float32 dt; // time step 41 | float32 inv_dt; // inverse time step (0 if dt == 0). 42 | float32 dtRatio; // dt * inv_dt0 43 | int32 velocityIterations; 44 | int32 positionIterations; 45 | bool warmStarting; 46 | }; 47 | 48 | /// This is an internal structure. 49 | struct b2Position 50 | { 51 | b2Vec2 c; 52 | float32 a; 53 | }; 54 | 55 | /// This is an internal structure. 56 | struct b2Velocity 57 | { 58 | b2Vec2 v; 59 | float32 w; 60 | }; 61 | 62 | /// Solver Data 63 | struct b2SolverData 64 | { 65 | b2TimeStep step; 66 | b2Position* positions; 67 | b2Velocity* velocities; 68 | }; 69 | 70 | #endif 71 | -------------------------------------------------------------------------------- /tests/test_world.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | import unittest 4 | import Box2D 5 | import sys 6 | 7 | class testWorld (unittest.TestCase): 8 | def setUp(self): 9 | pass 10 | 11 | def test_world(self): 12 | try: 13 | world = Box2D.b2World(Box2D.b2Vec2(0.0, -10.0), True) 14 | world = Box2D.b2World((0.0, -10.0), True) 15 | world = Box2D.b2World([0.0, -10.0], False) 16 | world = Box2D.b2World([0.0, -10.0]) 17 | world = Box2D.b2World() 18 | world = Box2D.b2World(gravity=[0.0, -10.0]) 19 | except Exception: 20 | self.fail("Failed to create world (%s)" % sys.exc_info()[1]) 21 | 22 | def test_helloworld(self): 23 | gravity = Box2D.b2Vec2(0, -10) 24 | 25 | doSleep = True 26 | 27 | world = Box2D.b2World(gravity, doSleep) 28 | 29 | groundBodyDef = Box2D.b2BodyDef() 30 | groundBodyDef.position = [0, -10] 31 | 32 | groundBody = world.CreateBody(groundBodyDef) 33 | 34 | groundBox = Box2D.b2PolygonShape() 35 | 36 | groundBox.SetAsBox(50, 10) 37 | 38 | groundBody.CreateFixturesFromShapes(groundBox) 39 | 40 | bodyDef = Box2D.b2BodyDef() 41 | bodyDef.type = Box2D.b2_dynamicBody 42 | bodyDef.position = (0, 4) 43 | body = world.CreateBody(bodyDef) 44 | 45 | dynamicBox = Box2D.b2PolygonShape() 46 | dynamicBox.SetAsBox(1, 1) 47 | 48 | fixtureDef = Box2D.b2FixtureDef() 49 | fixtureDef.shape = dynamicBox 50 | 51 | fixtureDef.density = 1 52 | 53 | fixtureDef.friction = 0.3 54 | 55 | body.CreateFixture(fixtureDef) 56 | 57 | timeStep = 1.0 / 60 58 | vel_iters, pos_iters = 6, 2 59 | 60 | for i in range(60): 61 | world.Step(timeStep, vel_iters, pos_iters) 62 | world.ClearForces() 63 | 64 | if __name__ == '__main__': 65 | unittest.main() 66 | 67 | -------------------------------------------------------------------------------- /tests/test_color.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | import unittest 4 | from Box2D import b2Color 5 | 6 | class testColor (unittest.TestCase): 7 | def checkAlmostEqual(self, v1, v2, msg, places=3): 8 | for i, (a, b) in enumerate(zip(v1, v2)): 9 | self.assertAlmostEqual(a, b, places=places, 10 | msg="(index %d) %s, a=%f b=%f from %s, %s" % (i, msg, a, b, v1, v2)) 11 | 12 | def test_color(self): 13 | x, y, z = 1.0, 2.0, 3.0 14 | c1 = b2Color(x, y, z) 15 | c2 = b2Color(z, y, x) 16 | 17 | c = c1 + c2 18 | self.checkAlmostEqual(c, (x+z, y+y, z+x), msg='b2Color +') 19 | c = c1 - c2 20 | self.checkAlmostEqual(c, (x-z, y-y, z-x), msg='b2Color -') 21 | c = 2.0 * c1 22 | self.checkAlmostEqual(c, (x+x, y+y, z+z), msg='float * b2Color') 23 | c = c1 * 2.0 24 | self.checkAlmostEqual(c, (x+x, y+y, z+z), msg='b2Color * float') 25 | c = c1 / 2.0 26 | self.checkAlmostEqual(c, (x/2.0, y/2.0, z/2.0), msg='b2Color / float') 27 | 28 | c = c1.copy() 29 | c *= 2.0 30 | self.checkAlmostEqual(c, (x+x, y+y, z+z), msg='b2Color *= float') 31 | c = b2Color(c1) 32 | c /= 2.0 33 | self.checkAlmostEqual(c, (x/2.0, y/2.0, z/2.0), msg='b2Color /= float') 34 | c1 += (1.0, 1.0, 1.0) 35 | self.checkAlmostEqual(c1, (x+1, y+1, z+1), msg='b2Color +=') 36 | c1 -= (1.0, 1.0, 1.0) 37 | self.checkAlmostEqual(c1, (x, y, z), msg='b2Color -=') 38 | 39 | bytes=b2Color(1, 1, 1).bytes 40 | self.assertEqual(bytes, [255,255,255], msg='bytes (1,1,1)=>%s'%bytes) 41 | bytes=b2Color(0, 0, 0).bytes 42 | self.assertEqual(bytes, [0,0,0], msg='bytes (1,1,1)=>%s'%bytes) 43 | 44 | self.assertEqual(c1[0], x) 45 | self.assertEqual(c1[1], y) 46 | self.assertEqual(c1[2], z) 47 | 48 | c1.list = (x*2, y*2, z*2) 49 | self.checkAlmostEqual(c1, (x+x, y+y, z+z), msg='b2Color.list') 50 | 51 | if __name__ == '__main__': 52 | unittest.main() 53 | 54 | 55 | -------------------------------------------------------------------------------- /examples/restitution.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # 4 | # C++ version Copyright (c) 2006-2007 Erin Catto http://www.box2d.org 5 | # Python version by Ken Lauer / sirkne at gmail dot com 6 | # 7 | # This software is provided 'as-is', without any express or implied 8 | # warranty. In no event will the authors be held liable for any damages 9 | # arising from the use of this software. 10 | # Permission is granted to anyone to use this software for any purpose, 11 | # including commercial applications, and to alter it and redistribute it 12 | # freely, subject to the following restrictions: 13 | # 1. The origin of this software must not be misrepresented; you must not 14 | # claim that you wrote the original software. If you use this software 15 | # in a product, an acknowledgment in the product documentation would be 16 | # appreciated but is not required. 17 | # 2. Altered source versions must be plainly marked as such, and must not be 18 | # misrepresented as being the original software. 19 | # 3. This notice may not be removed or altered from any source distribution. 20 | 21 | from .framework import (Framework, main) 22 | from Box2D import (b2CircleShape, b2EdgeShape, b2FixtureDef) 23 | 24 | 25 | class Restitution (Framework): 26 | name = "Restitution example" 27 | description = "Note the difference in bounce height of the circles" 28 | 29 | def __init__(self): 30 | super(Restitution, self).__init__() 31 | 32 | # The ground 33 | ground = self.world.CreateStaticBody( 34 | shapes=b2EdgeShape(vertices=[(-20, 0), (20, 0)]) 35 | ) 36 | 37 | radius = 1.0 38 | density = 1.0 39 | # The bodies 40 | for i, restitution in enumerate([0.0, 0.1, 0.3, 0.5, 0.75, 0.9, 1.0]): 41 | self.world.CreateDynamicBody( 42 | position=(-10 + 3.0 * i, 20), 43 | fixtures=b2FixtureDef( 44 | shape=b2CircleShape(radius=radius), 45 | density=density, restitution=restitution) 46 | ) 47 | 48 | if __name__ == "__main__": 49 | main(Restitution) 50 | -------------------------------------------------------------------------------- /examples/pgu/gui/keysym.py: -------------------------------------------------------------------------------- 1 | """ 2 | """ 3 | import pygame 4 | from pygame.locals import * 5 | 6 | from .const import * 7 | from . import widget 8 | 9 | class Keysym(widget.Widget): 10 | """A keysym input. This is deprecated and is scheduled to be removed from PGU.""" 11 | 12 | _value = None 13 | 14 | def __init__(self,value=None,**params): 15 | params.setdefault('cls','keysym') 16 | widget.Widget.__init__(self,**params) 17 | self.value = value 18 | 19 | self.font = self.style.font 20 | w,h = self.font.size("Right Super") #"Right Shift") 21 | self.style.width,self.style.height = w,h 22 | #self.rect.w=w+self.style.padding_left+self.style.padding_right 23 | #self.rect.h=h+self.style.padding_top+self.style.padding_bottom 24 | 25 | def event(self,e): 26 | used = None 27 | if e.type == FOCUS or e.type == BLUR: self.repaint() 28 | elif e.type == KEYDOWN: 29 | if e.key != K_TAB: 30 | self.value = e.key 31 | self.repaint() 32 | self.send(CHANGE) 33 | used = True 34 | self.next() 35 | self.pcls = "" 36 | if self.container.myfocus is self: self.pcls = "focus" 37 | return used 38 | 39 | def paint(self,s): 40 | r = pygame.rect.Rect(0,0,self.rect.w,self.rect.h) 41 | #render_box(s,self.style.background,r) 42 | if self.value == None: return 43 | name = "" 44 | for p in pygame.key.name(self.value).split(): name += p.capitalize()+" " 45 | #r.x = self.style.padding_left; 46 | #r.y = self.style.padding_bottom; 47 | s.blit(self.style.font.render(name, 1, self.style.color), r) 48 | 49 | @property 50 | def value(self): 51 | return self._value 52 | 53 | @value.setter 54 | def value(self, val): 55 | if (val != None): 56 | val = int(val) 57 | oldval = self._value 58 | self._value = val 59 | if (oldval != val): 60 | self.send(CHANGE) 61 | self.repaint() 62 | 63 | 64 | -------------------------------------------------------------------------------- /Box2D/Collision/b2TimeOfImpact.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2009 Erin Catto http://www.box2d.org 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked as such, and must not be 15 | * misrepresented as being the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | #ifndef B2_TIME_OF_IMPACT_H 20 | #define B2_TIME_OF_IMPACT_H 21 | 22 | #include 23 | #include 24 | 25 | /// Input parameters for b2TimeOfImpact 26 | struct b2TOIInput 27 | { 28 | b2DistanceProxy proxyA; 29 | b2DistanceProxy proxyB; 30 | b2Sweep sweepA; 31 | b2Sweep sweepB; 32 | float32 tMax; // defines sweep interval [0, tMax] 33 | }; 34 | 35 | // Output parameters for b2TimeOfImpact. 36 | struct b2TOIOutput 37 | { 38 | enum State 39 | { 40 | e_unknown, 41 | e_failed, 42 | e_overlapped, 43 | e_touching, 44 | e_separated 45 | }; 46 | 47 | State state; 48 | float32 t; 49 | }; 50 | 51 | /// Compute the upper bound on time before two shapes penetrate. Time is represented as 52 | /// a fraction between [0,tMax]. This uses a swept separating axis and may miss some intermediate, 53 | /// non-tunneling collision. If you change the time interval, you should call this function 54 | /// again. 55 | /// Note: use b2Distance to compute the contact point and normal at the time of impact. 56 | void b2TimeOfImpact(b2TOIOutput* output, const b2TOIInput* input); 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /Box2D/Common/b2BlockAllocator.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2009 Erin Catto http://www.box2d.org 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked as such, and must not be 15 | * misrepresented as being the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | #ifndef B2_BLOCK_ALLOCATOR_H 20 | #define B2_BLOCK_ALLOCATOR_H 21 | 22 | #include 23 | 24 | const int32 b2_chunkSize = 16 * 1024; 25 | const int32 b2_maxBlockSize = 640; 26 | const int32 b2_blockSizes = 14; 27 | const int32 b2_chunkArrayIncrement = 128; 28 | 29 | struct b2Block; 30 | struct b2Chunk; 31 | 32 | /// This is a small object allocator used for allocating small 33 | /// objects that persist for more than one time step. 34 | /// See: http://www.codeproject.com/useritems/Small_Block_Allocator.asp 35 | class b2BlockAllocator 36 | { 37 | public: 38 | b2BlockAllocator(); 39 | ~b2BlockAllocator(); 40 | 41 | /// Allocate memory. This will use b2Alloc if the size is larger than b2_maxBlockSize. 42 | void* Allocate(int32 size); 43 | 44 | /// Free memory. This will use b2Free if the size is larger than b2_maxBlockSize. 45 | void Free(void* p, int32 size); 46 | 47 | void Clear(); 48 | 49 | private: 50 | 51 | b2Chunk* m_chunks; 52 | int32 m_chunkCount; 53 | int32 m_chunkSpace; 54 | 55 | b2Block* m_freeLists[b2_blockSizes]; 56 | 57 | static int32 s_blockSizes[b2_blockSizes]; 58 | static uint8 s_blockSizeLookup[b2_maxBlockSize + 1]; 59 | static bool s_blockSizeLookupInitialized; 60 | }; 61 | 62 | #endif 63 | -------------------------------------------------------------------------------- /examples/pyramid.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # 4 | # C++ version Copyright (c) 2006-2007 Erin Catto http://www.box2d.org 5 | # Python version by Ken Lauer / sirkne at gmail dot com 6 | # 7 | # This software is provided 'as-is', without any express or implied 8 | # warranty. In no event will the authors be held liable for any damages 9 | # arising from the use of this software. 10 | # Permission is granted to anyone to use this software for any purpose, 11 | # including commercial applications, and to alter it and redistribute it 12 | # freely, subject to the following restrictions: 13 | # 1. The origin of this software must not be misrepresented; you must not 14 | # claim that you wrote the original software. If you use this software 15 | # in a product, an acknowledgment in the product documentation would be 16 | # appreciated but is not required. 17 | # 2. Altered source versions must be plainly marked as such, and must not be 18 | # misrepresented as being the original software. 19 | # 3. This notice may not be removed or altered from any source distribution. 20 | 21 | from .framework import (Framework, main) 22 | from Box2D import (b2EdgeShape, b2FixtureDef, b2PolygonShape, b2Vec2) 23 | 24 | 25 | class Pyramid (Framework): 26 | name = "Pyramid" 27 | 28 | def __init__(self): 29 | super(Pyramid, self).__init__() 30 | # The ground 31 | ground = self.world.CreateStaticBody( 32 | shapes=b2EdgeShape(vertices=[(-40, 0), (40, 0)]) 33 | ) 34 | 35 | box_half_size = (0.5, 0.5) 36 | box_density = 5.0 37 | box_rows = 20 38 | 39 | x = b2Vec2(-7, 0.75) 40 | deltaX = (0.5625, 1.25) 41 | deltaY = (1.125, 0) 42 | 43 | for i in range(box_rows): 44 | y = x.copy() 45 | 46 | for j in range(i, box_rows): 47 | self.world.CreateDynamicBody( 48 | position=y, 49 | fixtures=b2FixtureDef( 50 | shape=b2PolygonShape(box=box_half_size), 51 | density=box_density) 52 | ) 53 | 54 | y += deltaY 55 | 56 | x += deltaX 57 | 58 | if __name__ == "__main__": 59 | main(Pyramid) 60 | -------------------------------------------------------------------------------- /Box2D/Dynamics/Contacts/b2EdgeAndCircleContact.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2010 Erin Catto http://www.box2d.org 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked as such, and must not be 15 | * misrepresented as being the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | #include 24 | using namespace std; 25 | 26 | b2Contact* b2EdgeAndCircleContact::Create(b2Fixture* fixtureA, int32, b2Fixture* fixtureB, int32, b2BlockAllocator* allocator) 27 | { 28 | void* mem = allocator->Allocate(sizeof(b2EdgeAndCircleContact)); 29 | return new (mem) b2EdgeAndCircleContact(fixtureA, fixtureB); 30 | } 31 | 32 | void b2EdgeAndCircleContact::Destroy(b2Contact* contact, b2BlockAllocator* allocator) 33 | { 34 | ((b2EdgeAndCircleContact*)contact)->~b2EdgeAndCircleContact(); 35 | allocator->Free(contact, sizeof(b2EdgeAndCircleContact)); 36 | } 37 | 38 | b2EdgeAndCircleContact::b2EdgeAndCircleContact(b2Fixture* fixtureA, b2Fixture* fixtureB) 39 | : b2Contact(fixtureA, 0, fixtureB, 0) 40 | { 41 | b2Assert(m_fixtureA->GetType() == b2Shape::e_edge); 42 | b2Assert(m_fixtureB->GetType() == b2Shape::e_circle); 43 | } 44 | 45 | void b2EdgeAndCircleContact::Evaluate(b2Manifold* manifold, const b2Transform& xfA, const b2Transform& xfB) 46 | { 47 | b2CollideEdgeAndCircle( manifold, 48 | (b2EdgeShape*)m_fixtureA->GetShape(), xfA, 49 | (b2CircleShape*)m_fixtureB->GetShape(), xfB); 50 | } 51 | -------------------------------------------------------------------------------- /Box2D/Dynamics/Contacts/b2EdgeAndPolygonContact.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2010 Erin Catto http://www.box2d.org 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked as such, and must not be 15 | * misrepresented as being the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | #include 24 | using namespace std; 25 | 26 | b2Contact* b2EdgeAndPolygonContact::Create(b2Fixture* fixtureA, int32, b2Fixture* fixtureB, int32, b2BlockAllocator* allocator) 27 | { 28 | void* mem = allocator->Allocate(sizeof(b2EdgeAndPolygonContact)); 29 | return new (mem) b2EdgeAndPolygonContact(fixtureA, fixtureB); 30 | } 31 | 32 | void b2EdgeAndPolygonContact::Destroy(b2Contact* contact, b2BlockAllocator* allocator) 33 | { 34 | ((b2EdgeAndPolygonContact*)contact)->~b2EdgeAndPolygonContact(); 35 | allocator->Free(contact, sizeof(b2EdgeAndPolygonContact)); 36 | } 37 | 38 | b2EdgeAndPolygonContact::b2EdgeAndPolygonContact(b2Fixture* fixtureA, b2Fixture* fixtureB) 39 | : b2Contact(fixtureA, 0, fixtureB, 0) 40 | { 41 | b2Assert(m_fixtureA->GetType() == b2Shape::e_edge); 42 | b2Assert(m_fixtureB->GetType() == b2Shape::e_polygon); 43 | } 44 | 45 | void b2EdgeAndPolygonContact::Evaluate(b2Manifold* manifold, const b2Transform& xfA, const b2Transform& xfB) 46 | { 47 | b2CollideEdgeAndPolygon( manifold, 48 | (b2EdgeShape*)m_fixtureA->GetShape(), xfA, 49 | (b2PolygonShape*)m_fixtureB->GetShape(), xfB); 50 | } 51 | -------------------------------------------------------------------------------- /examples/edge_test.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # 4 | # C++ version Copyright (c) 2006-2007 Erin Catto http://www.box2d.org 5 | # Python version Copyright (c) 2010 kne / sirkne at gmail dot com 6 | # 7 | # This software is provided 'as-is', without any express or implied 8 | # warranty. In no event will the authors be held liable for any damages 9 | # arising from the use of this software. 10 | # Permission is granted to anyone to use this software for any purpose, 11 | # including commercial applications, and to alter it and redistribute it 12 | # freely, subject to the following restrictions: 13 | # 1. The origin of this software must not be misrepresented; you must not 14 | # claim that you wrote the original software. If you use this software 15 | # in a product, an acknowledgment in the product documentation would be 16 | # appreciated but is not required. 17 | # 2. Altered source versions must be plainly marked as such, and must not be 18 | # misrepresented as being the original software. 19 | # 3. This notice may not be removed or altered from any source distribution. 20 | 21 | from .framework import (Framework, main) 22 | from Box2D import (b2EdgeShape, b2PolygonShape) 23 | 24 | 25 | class EdgeTest (Framework): 26 | name = "EdgeTest" 27 | description = "Utilizes b2EdgeShape" 28 | 29 | def __init__(self): 30 | super(EdgeTest, self).__init__() 31 | 32 | v1 = (-10.0, 0.0) 33 | v2 = (-7.0, -1.0) 34 | v3 = (-4.0, 0.0) 35 | v4 = (0.0, 0.0) 36 | v5 = (4.0, 0.0) 37 | v6 = (7.0, 1.0) 38 | v7 = (10.0, 0.0) 39 | 40 | shapes = [b2EdgeShape(vertices=[None, v1, v2, v3]), 41 | b2EdgeShape(vertices=[v1, v2, v3, v4]), 42 | b2EdgeShape(vertices=[v2, v3, v4, v5]), 43 | b2EdgeShape(vertices=[v3, v4, v5, v6]), 44 | b2EdgeShape(vertices=[v4, v5, v6, v7]), 45 | b2EdgeShape(vertices=[v5, v6, v7]) 46 | ] 47 | ground = self.world.CreateStaticBody(shapes=shapes) 48 | 49 | box = self.world.CreateDynamicBody( 50 | position=(0.5, 0.6), 51 | allowSleep=False, 52 | shapes=b2PolygonShape(box=(0.5, 0.5)) 53 | ) 54 | 55 | if __name__ == "__main__": 56 | main(EdgeTest) 57 | -------------------------------------------------------------------------------- /Box2D/Dynamics/Contacts/b2CircleContact.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2009 Erin Catto http://www.box2d.org 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked as such, and must not be 15 | * misrepresented as being the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | #include 27 | using namespace std; 28 | 29 | b2Contact* b2CircleContact::Create(b2Fixture* fixtureA, int32, b2Fixture* fixtureB, int32, b2BlockAllocator* allocator) 30 | { 31 | void* mem = allocator->Allocate(sizeof(b2CircleContact)); 32 | return new (mem) b2CircleContact(fixtureA, fixtureB); 33 | } 34 | 35 | void b2CircleContact::Destroy(b2Contact* contact, b2BlockAllocator* allocator) 36 | { 37 | ((b2CircleContact*)contact)->~b2CircleContact(); 38 | allocator->Free(contact, sizeof(b2CircleContact)); 39 | } 40 | 41 | b2CircleContact::b2CircleContact(b2Fixture* fixtureA, b2Fixture* fixtureB) 42 | : b2Contact(fixtureA, 0, fixtureB, 0) 43 | { 44 | b2Assert(m_fixtureA->GetType() == b2Shape::e_circle); 45 | b2Assert(m_fixtureB->GetType() == b2Shape::e_circle); 46 | } 47 | 48 | void b2CircleContact::Evaluate(b2Manifold* manifold, const b2Transform& xfA, const b2Transform& xfB) 49 | { 50 | b2CollideCircles(manifold, 51 | (b2CircleShape*)m_fixtureA->GetShape(), xfA, 52 | (b2CircleShape*)m_fixtureB->GetShape(), xfB); 53 | } 54 | -------------------------------------------------------------------------------- /Box2D/Dynamics/Contacts/b2PolygonAndCircleContact.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2009 Erin Catto http://www.box2d.org 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked as such, and must not be 15 | * misrepresented as being the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | #include 24 | using namespace std; 25 | 26 | b2Contact* b2PolygonAndCircleContact::Create(b2Fixture* fixtureA, int32, b2Fixture* fixtureB, int32, b2BlockAllocator* allocator) 27 | { 28 | void* mem = allocator->Allocate(sizeof(b2PolygonAndCircleContact)); 29 | return new (mem) b2PolygonAndCircleContact(fixtureA, fixtureB); 30 | } 31 | 32 | void b2PolygonAndCircleContact::Destroy(b2Contact* contact, b2BlockAllocator* allocator) 33 | { 34 | ((b2PolygonAndCircleContact*)contact)->~b2PolygonAndCircleContact(); 35 | allocator->Free(contact, sizeof(b2PolygonAndCircleContact)); 36 | } 37 | 38 | b2PolygonAndCircleContact::b2PolygonAndCircleContact(b2Fixture* fixtureA, b2Fixture* fixtureB) 39 | : b2Contact(fixtureA, 0, fixtureB, 0) 40 | { 41 | b2Assert(m_fixtureA->GetType() == b2Shape::e_polygon); 42 | b2Assert(m_fixtureB->GetType() == b2Shape::e_circle); 43 | } 44 | 45 | void b2PolygonAndCircleContact::Evaluate(b2Manifold* manifold, const b2Transform& xfA, const b2Transform& xfB) 46 | { 47 | b2CollidePolygonAndCircle( manifold, 48 | (b2PolygonShape*)m_fixtureA->GetShape(), xfA, 49 | (b2CircleShape*)m_fixtureB->GetShape(), xfB); 50 | } 51 | -------------------------------------------------------------------------------- /Box2D/Common/b2GrowableStack.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010 Erin Catto http://www.box2d.org 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked as such, and must not be 15 | * misrepresented as being the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | #ifndef B2_GROWABLE_STACK_H 20 | #define B2_GROWABLE_STACK_H 21 | #include 22 | #include 23 | 24 | /// This is a growable LIFO stack with an initial capacity of N. 25 | /// If the stack size exceeds the initial capacity, the heap is used 26 | /// to increase the size of the stack. 27 | template 28 | class b2GrowableStack 29 | { 30 | public: 31 | b2GrowableStack() 32 | { 33 | m_stack = m_array; 34 | m_count = 0; 35 | m_capacity = N; 36 | } 37 | 38 | ~b2GrowableStack() 39 | { 40 | if (m_stack != m_array) 41 | { 42 | b2Free(m_stack); 43 | m_stack = NULL; 44 | } 45 | } 46 | 47 | void Push(const T& element) 48 | { 49 | if (m_count == m_capacity) 50 | { 51 | T* old = m_stack; 52 | m_capacity *= 2; 53 | m_stack = (T*)b2Alloc(m_capacity * sizeof(T)); 54 | std::memcpy(m_stack, old, m_count * sizeof(T)); 55 | if (old != m_array) 56 | { 57 | b2Free(old); 58 | } 59 | } 60 | 61 | m_stack[m_count] = element; 62 | ++m_count; 63 | } 64 | 65 | T Pop() 66 | { 67 | b2Assert(m_count > 0); 68 | --m_count; 69 | return m_stack[m_count]; 70 | } 71 | 72 | int32 GetCount() 73 | { 74 | return m_count; 75 | } 76 | 77 | private: 78 | T* m_stack; 79 | T m_array[N]; 80 | int32 m_count; 81 | int32 m_capacity; 82 | }; 83 | 84 | 85 | #endif 86 | -------------------------------------------------------------------------------- /devel/dict_replacement.py: -------------------------------------------------------------------------------- 1 | from all_classes import * 2 | 3 | print(""" 4 | /* 5 | * pybox2d -- http://pybox2d.googlecode.com 6 | * 7 | * Copyright (c) 2010 Ken Lauer / sirkne at gmail dot com 8 | * 9 | * This software is provided 'as-is', without any express or implied 10 | * warranty. In no event will the authors be held liable for any damages 11 | * arising from the use of this software. 12 | * Permission is granted to anyone to use this software for any purpose, 13 | * including commercial applications, and to alter it and redistribute it 14 | * freely, subject to the following restrictions: 15 | * 1. The origin of this software must not be misrepresented; you must not 16 | * claim that you wrote the original software. If you use this software 17 | * in a product, an acknowledgment in the product documentation would be 18 | * appreciated but is not required. 19 | * 2. Altered source versions must be plainly marked as such, and must not be 20 | * misrepresented as being the original software. 21 | * 3. This notice may not be removed or altered from any source distribution. 22 | */ 23 | 24 | %pythoncode %{ 25 | 26 | def _dir_filter(self): 27 | # Using introspection, mimic dir() by adding up all of the __dicts__ 28 | # for the current class and all base classes (type(self).__mro__ returns 29 | # all of the classes that make it up) 30 | # Basically filters by: 31 | # __x__ OK 32 | # __x bad 33 | # _classname bad 34 | def check(s): 35 | if s[:2]=='__': 36 | if s[-2:]=='__': 37 | return True 38 | else: 39 | return False 40 | else: 41 | for typename in typenames: 42 | if typename in s: 43 | return False 44 | return True 45 | 46 | keys=sum([c.__dict__.keys() for c in type(self).__mro__], []) 47 | typenames = ["_%s" % c.__name__ for c in type(self).__mro__] 48 | ret=[s for s in list(set(keys)) if check(s)] 49 | ret.sort() 50 | return ret 51 | 52 | %} 53 | """) 54 | 55 | extend_string=""" 56 | %%extend %s { 57 | %%pythoncode %%{ 58 | __dir__ = _dir_filter 59 | %%} 60 | } 61 | """ 62 | 63 | for c in all_classes: 64 | print(extend_string % c) 65 | -------------------------------------------------------------------------------- /Box2D/Dynamics/Contacts/b2PolygonContact.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2009 Erin Catto http://www.box2d.org 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked as such, and must not be 15 | * misrepresented as being the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | #include 27 | using namespace std; 28 | 29 | b2Contact* b2PolygonContact::Create(b2Fixture* fixtureA, int32, b2Fixture* fixtureB, int32, b2BlockAllocator* allocator) 30 | { 31 | void* mem = allocator->Allocate(sizeof(b2PolygonContact)); 32 | return new (mem) b2PolygonContact(fixtureA, fixtureB); 33 | } 34 | 35 | void b2PolygonContact::Destroy(b2Contact* contact, b2BlockAllocator* allocator) 36 | { 37 | ((b2PolygonContact*)contact)->~b2PolygonContact(); 38 | allocator->Free(contact, sizeof(b2PolygonContact)); 39 | } 40 | 41 | b2PolygonContact::b2PolygonContact(b2Fixture* fixtureA, b2Fixture* fixtureB) 42 | : b2Contact(fixtureA, 0, fixtureB, 0) 43 | { 44 | b2Assert(m_fixtureA->GetType() == b2Shape::e_polygon); 45 | b2Assert(m_fixtureB->GetType() == b2Shape::e_polygon); 46 | } 47 | 48 | void b2PolygonContact::Evaluate(b2Manifold* manifold, const b2Transform& xfA, const b2Transform& xfB) 49 | { 50 | b2CollidePolygons( manifold, 51 | (b2PolygonShape*)m_fixtureA->GetShape(), xfA, 52 | (b2PolygonShape*)m_fixtureB->GetShape(), xfB); 53 | } 54 | -------------------------------------------------------------------------------- /Box2D/Common/b2StackAllocator.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2009 Erin Catto http://www.box2d.org 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked as such, and must not be 15 | * misrepresented as being the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | #include 20 | #include 21 | 22 | b2StackAllocator::b2StackAllocator() 23 | { 24 | m_index = 0; 25 | m_allocation = 0; 26 | m_maxAllocation = 0; 27 | m_entryCount = 0; 28 | } 29 | 30 | b2StackAllocator::~b2StackAllocator() 31 | { 32 | b2Assert(m_index == 0); 33 | b2Assert(m_entryCount == 0); 34 | } 35 | 36 | void* b2StackAllocator::Allocate(int32 size) 37 | { 38 | b2Assert(m_entryCount < b2_maxStackEntries); 39 | 40 | b2StackEntry* entry = m_entries + m_entryCount; 41 | entry->size = size; 42 | if (m_index + size > b2_stackSize) 43 | { 44 | entry->data = (char*)b2Alloc(size); 45 | entry->usedMalloc = true; 46 | } 47 | else 48 | { 49 | entry->data = m_data + m_index; 50 | entry->usedMalloc = false; 51 | m_index += size; 52 | } 53 | 54 | m_allocation += size; 55 | m_maxAllocation = b2Max(m_maxAllocation, m_allocation); 56 | ++m_entryCount; 57 | 58 | return entry->data; 59 | } 60 | 61 | void b2StackAllocator::Free(void* p) 62 | { 63 | b2Assert(m_entryCount > 0); 64 | b2StackEntry* entry = m_entries + m_entryCount - 1; 65 | b2Assert(p == entry->data); 66 | if (entry->usedMalloc) 67 | { 68 | b2Free(p); 69 | } 70 | else 71 | { 72 | m_index -= entry->size; 73 | } 74 | m_allocation -= entry->size; 75 | --m_entryCount; 76 | 77 | p = NULL; 78 | } 79 | 80 | int32 b2StackAllocator::GetMaxAllocation() const 81 | { 82 | return m_maxAllocation; 83 | } 84 | -------------------------------------------------------------------------------- /devel/init_kwargs.py: -------------------------------------------------------------------------------- 1 | from all_classes import * 2 | 3 | print(""" 4 | /* 5 | * pybox2d -- http://pybox2d.googlecode.com 6 | * 7 | * Copyright (c) 2010 Ken Lauer / sirkne at gmail dot com 8 | * 9 | * This software is provided 'as-is', without any express or implied 10 | * warranty. In no event will the authors be held liable for any damages 11 | * arising from the use of this software. 12 | * Permission is granted to anyone to use this software for any purpose, 13 | * including commercial applications, and to alter it and redistribute it 14 | * freely, subject to the following restrictions: 15 | * 1. The origin of this software must not be misrepresented; you must not 16 | * claim that you wrote the original software. If you use this software 17 | * in a product, an acknowledgment in the product documentation would be 18 | * appreciated but is not required. 19 | * 2. Altered source versions must be plainly marked as such, and must not be 20 | * misrepresented as being the original software. 21 | * 3. This notice may not be removed or altered from any source distribution. 22 | */ 23 | 24 | %pythoncode %{ 25 | def _init_kwargs(self, **kwargs): 26 | for key, value in list(kwargs.items()): 27 | try: 28 | setattr(self, key, value) 29 | except Exception as ex: 30 | raise ex.__class__('Failed on kwargs, class="%s" key="%s": %s' 31 | % (self.__class__.__name__, key, ex)) 32 | %} 33 | """) 34 | 35 | extend_string=""" 36 | %%feature("shadow") %s::%s() { 37 | def __init__(self, **kwargs): 38 | _Box2D.%s_swiginit(self,_Box2D.new_%s()) 39 | _init_kwargs(self, **kwargs) 40 | } 41 | """ 42 | 43 | director_string=""" 44 | %%feature("shadow") %s::%s() { 45 | def __init__(self, **kwargs): 46 | if self.__class__ == %s: 47 | _self = None 48 | else: 49 | _self = self 50 | _Box2D.%s_swiginit(self,_Box2D.new_%s(_self, )) 51 | _init_kwargs(self, **kwargs) 52 | } 53 | """ 54 | all_classes.remove('b2World') 55 | 56 | director_classes = ['b2ContactFilter', 'b2ContactListener', 'b2QueryCallback', 'b2DebugDraw', 'b2DestructionListener' ] 57 | abstract_classes = ['b2Joint', 'b2Shape', 'b2RayCastCallback', 'b2Contact'] 58 | for c in abstract_classes: 59 | # print(director_string % tuple([c]*4)) 60 | all_classes.remove(c) 61 | for c in director_classes: 62 | print(director_string % tuple([c]*5)) 63 | all_classes.remove(c) 64 | for c in all_classes: 65 | print(extend_string % tuple([c]*4)) 66 | -------------------------------------------------------------------------------- /Box2D/Dynamics/Contacts/b2ChainAndCircleContact.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2010 Erin Catto http://www.box2d.org 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked as such, and must not be 15 | * misrepresented as being the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | #include 26 | using namespace std; 27 | 28 | b2Contact* b2ChainAndCircleContact::Create(b2Fixture* fixtureA, int32 indexA, b2Fixture* fixtureB, int32 indexB, b2BlockAllocator* allocator) 29 | { 30 | void* mem = allocator->Allocate(sizeof(b2ChainAndCircleContact)); 31 | return new (mem) b2ChainAndCircleContact(fixtureA, indexA, fixtureB, indexB); 32 | } 33 | 34 | void b2ChainAndCircleContact::Destroy(b2Contact* contact, b2BlockAllocator* allocator) 35 | { 36 | ((b2ChainAndCircleContact*)contact)->~b2ChainAndCircleContact(); 37 | allocator->Free(contact, sizeof(b2ChainAndCircleContact)); 38 | } 39 | 40 | b2ChainAndCircleContact::b2ChainAndCircleContact(b2Fixture* fixtureA, int32 indexA, b2Fixture* fixtureB, int32 indexB) 41 | : b2Contact(fixtureA, indexA, fixtureB, indexB) 42 | { 43 | b2Assert(m_fixtureA->GetType() == b2Shape::e_chain); 44 | b2Assert(m_fixtureB->GetType() == b2Shape::e_circle); 45 | } 46 | 47 | void b2ChainAndCircleContact::Evaluate(b2Manifold* manifold, const b2Transform& xfA, const b2Transform& xfB) 48 | { 49 | b2ChainShape* chain = (b2ChainShape*)m_fixtureA->GetShape(); 50 | b2EdgeShape edge; 51 | chain->GetChildEdge(&edge, m_indexA); 52 | b2CollideEdgeAndCircle( manifold, &edge, xfA, 53 | (b2CircleShape*)m_fixtureB->GetShape(), xfB); 54 | } 55 | -------------------------------------------------------------------------------- /Box2D/Dynamics/Contacts/b2ChainAndPolygonContact.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2010 Erin Catto http://www.box2d.org 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked as such, and must not be 15 | * misrepresented as being the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | #include 26 | using namespace std; 27 | 28 | b2Contact* b2ChainAndPolygonContact::Create(b2Fixture* fixtureA, int32 indexA, b2Fixture* fixtureB, int32 indexB, b2BlockAllocator* allocator) 29 | { 30 | void* mem = allocator->Allocate(sizeof(b2ChainAndPolygonContact)); 31 | return new (mem) b2ChainAndPolygonContact(fixtureA, indexA, fixtureB, indexB); 32 | } 33 | 34 | void b2ChainAndPolygonContact::Destroy(b2Contact* contact, b2BlockAllocator* allocator) 35 | { 36 | ((b2ChainAndPolygonContact*)contact)->~b2ChainAndPolygonContact(); 37 | allocator->Free(contact, sizeof(b2ChainAndPolygonContact)); 38 | } 39 | 40 | b2ChainAndPolygonContact::b2ChainAndPolygonContact(b2Fixture* fixtureA, int32 indexA, b2Fixture* fixtureB, int32 indexB) 41 | : b2Contact(fixtureA, indexA, fixtureB, indexB) 42 | { 43 | b2Assert(m_fixtureA->GetType() == b2Shape::e_chain); 44 | b2Assert(m_fixtureB->GetType() == b2Shape::e_polygon); 45 | } 46 | 47 | void b2ChainAndPolygonContact::Evaluate(b2Manifold* manifold, const b2Transform& xfA, const b2Transform& xfB) 48 | { 49 | b2ChainShape* chain = (b2ChainShape*)m_fixtureA->GetShape(); 50 | b2EdgeShape edge; 51 | chain->GetChildEdge(&edge, m_indexA); 52 | b2CollideEdgeAndPolygon( manifold, &edge, xfA, 53 | (b2PolygonShape*)m_fixtureB->GetShape(), xfB); 54 | } 55 | -------------------------------------------------------------------------------- /examples/hello.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | """ 5 | This is a simple example of building and running a simulation using Box2D. Here 6 | we create a large ground box and a small dynamic box. 7 | 8 | ** NOTE ** 9 | There is no graphical output for this simple example, only text. 10 | """ 11 | 12 | from Box2D import (b2PolygonShape, b2World) 13 | 14 | world = b2World() # default gravity is (0,-10) and doSleep is True 15 | groundBody = world.CreateStaticBody(position=(0, -10), 16 | shapes=b2PolygonShape(box=(50, 10)), 17 | ) 18 | 19 | # Create a dynamic body at (0, 4) 20 | body = world.CreateDynamicBody(position=(0, 4)) 21 | 22 | # And add a box fixture onto it (with a nonzero density, so it will move) 23 | box = body.CreatePolygonFixture(box=(1, 1), density=1, friction=0.3) 24 | 25 | # Prepare for simulation. Typically we use a time step of 1/60 of a second 26 | # (60Hz) and 6 velocity/2 position iterations. This provides a high quality 27 | # simulation in most game scenarios. 28 | timeStep = 1.0 / 60 29 | vel_iters, pos_iters = 6, 2 30 | 31 | # This is our little game loop. 32 | for i in range(60): 33 | # Instruct the world to perform a single step of simulation. It is 34 | # generally best to keep the time step and iterations fixed. 35 | world.Step(timeStep, vel_iters, pos_iters) 36 | 37 | # Clear applied body forces. We didn't apply any forces, but you should 38 | # know about this function. 39 | world.ClearForces() 40 | 41 | # Now print the position and angle of the body. 42 | print(body.position, body.angle) 43 | 44 | 45 | # You can also work closer to the C++ Box2D library, not using the niceties 46 | # supplied by pybox2d. Creating a world and a few bodies becomes much more 47 | # verbose: 48 | ''' 49 | from Box2D import (b2BodyDef, b2FixtureDef) 50 | # Construct a world object, which will hold and simulate the rigid bodies. 51 | world = b2World(gravity=(0, -10), doSleep=True) 52 | 53 | # Define the ground body. 54 | groundBodyDef = b2BodyDef() 55 | groundBodyDef.position = (0, -10) 56 | 57 | # Make a body fitting this definition in the world. 58 | groundBody = world.CreateBody(groundBodyDef) 59 | 60 | # Create a big static box to represent the ground 61 | groundBox = b2PolygonShape(box=(50, 10)) 62 | 63 | # And create a fixture definition to hold the shape 64 | groundBoxFixture = b2FixtureDef(shape=groundBox) 65 | 66 | # Add the ground shape to the ground body. 67 | groundBody.CreateFixture(groundBoxFixture) 68 | ''' 69 | -------------------------------------------------------------------------------- /examples/chain.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # 4 | # C++ version Copyright (c) 2006-2007 Erin Catto http://www.box2d.org 5 | # Python version by Ken Lauer / sirkne at gmail dot com 6 | # 7 | # This software is provided 'as-is', without any express or implied 8 | # warranty. In no event will the authors be held liable for any damages 9 | # arising from the use of this software. 10 | # Permission is granted to anyone to use this software for any purpose, 11 | # including commercial applications, and to alter it and redistribute it 12 | # freely, subject to the following restrictions: 13 | # 1. The origin of this software must not be misrepresented; you must not 14 | # claim that you wrote the original software. If you use this software 15 | # in a product, an acknowledgment in the product documentation would be 16 | # appreciated but is not required. 17 | # 2. Altered source versions must be plainly marked as such, and must not be 18 | # misrepresented as being the original software. 19 | # 3. This notice may not be removed or altered from any source distribution. 20 | 21 | from .framework import (Framework, main) 22 | from Box2D.b2 import (edgeShape, polygonShape, fixtureDef) 23 | 24 | # This test uses the alternative syntax offered by Box2D.b2, so you'll notice 25 | # that all of the classes that normally have 'b2' in front of them no longer 26 | # do. The choice of which to use is mostly stylistic and is left up to the 27 | # user. 28 | 29 | 30 | class Chain (Framework): 31 | name = "Chain" 32 | 33 | def __init__(self): 34 | super(Chain, self).__init__() 35 | 36 | # The ground 37 | ground = self.world.CreateBody( 38 | shapes=edgeShape(vertices=[(-40, 0), (40, 0)]) 39 | ) 40 | 41 | plank = fixtureDef( 42 | shape=polygonShape(box=(0.6, 0.125)), 43 | density=20, 44 | friction=0.2, 45 | ) 46 | 47 | # Create one Chain (Only the left end is fixed) 48 | prevBody = ground 49 | y = 25 50 | numPlanks = 30 51 | for i in range(numPlanks): 52 | body = self.world.CreateDynamicBody( 53 | position=(0.5 + i, y), 54 | fixtures=plank, 55 | ) 56 | 57 | # You can try a WeldJoint for a slightly different effect. 58 | # self.world.CreateWeldJoint( 59 | self.world.CreateRevoluteJoint( 60 | bodyA=prevBody, 61 | bodyB=body, 62 | anchor=(i, y), 63 | ) 64 | 65 | prevBody = body 66 | 67 | if __name__ == "__main__": 68 | main(Chain) 69 | -------------------------------------------------------------------------------- /tests/test_kwargs.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | import unittest 4 | from Box2D import * 5 | 6 | class cl (b2ContactListener): 7 | pass 8 | 9 | class test_kwargs (unittest.TestCase): 10 | def setUp(self): 11 | pass 12 | 13 | def test_kwargs(self): 14 | self.cont_list=cl() 15 | world = b2World(gravity=(0,-10), doSleep=True, contactListener=self.cont_list) 16 | groundBody = world.CreateBody(b2BodyDef(position=(0,-10))) 17 | 18 | groundBody.CreateFixturesFromShapes(b2PolygonShape(box=(50,10))) 19 | 20 | body = world.CreateBody(b2BodyDef(type=b2_dynamicBody, position=(0,4), 21 | fixtures=[])) 22 | 23 | body = world.CreateBody( 24 | type=b2_dynamicBody, 25 | position=(0,4), 26 | fixtures=b2FixtureDef(shape=b2PolygonShape(box=(2,1)), density=1.0) 27 | ) 28 | 29 | body = world.CreateBody( 30 | type=b2_dynamicBody, 31 | position=(0,4), 32 | shapes=(b2PolygonShape(box=(2,1)), b2PolygonShape(box=(2,1))), 33 | shapeFixture=b2FixtureDef(density=1.0), 34 | ) 35 | 36 | body = world.CreateBody( 37 | type=b2_dynamicBody, 38 | position=(0,4), 39 | fixtures=b2FixtureDef(shape=b2CircleShape(radius=1), density=1, friction=0.3), 40 | shapes=(b2PolygonShape(box=(2,1)), b2PolygonShape(box=(2,1))), 41 | shapeFixture=b2FixtureDef(density=1.0), 42 | ) 43 | 44 | body.CreateFixture(shape=b2CircleShape(radius=1), density=1, friction=0.3) 45 | timeStep = 1.0 / 60 46 | vel_iters, pos_iters = 6, 2 47 | 48 | for i in range(60): 49 | world.Step(timeStep, vel_iters, pos_iters) 50 | world.ClearForces() 51 | 52 | def test_body(self): 53 | world = b2World(gravity=(0,-10), doSleep=True) 54 | body = world.CreateBody(b2BodyDef()) 55 | body2 = world.CreateBody(position=(1,1)) 56 | 57 | def test_joints(self): 58 | world = b2World(gravity=(0,-10), doSleep=True) 59 | body = world.CreateBody(b2BodyDef()) 60 | body2 = world.CreateBody(position=(1,1)) 61 | world.CreateJoint(type=b2RevoluteJoint, bodyA=body, bodyB=body2) 62 | world.CreateJoint(type=b2RevoluteJointDef, bodyA=body, bodyB=body2) 63 | 64 | kwargs=dict(type=b2RevoluteJointDef, bodyA=body, bodyB=body2) 65 | world.CreateJoint(**kwargs) 66 | 67 | if __name__ == '__main__': 68 | unittest.main() 69 | 70 | -------------------------------------------------------------------------------- /Box2D/Collision/Shapes/b2EdgeShape.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2010 Erin Catto http://www.box2d.org 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked as such, and must not be 15 | * misrepresented as being the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | #ifndef B2_EDGE_SHAPE_H 20 | #define B2_EDGE_SHAPE_H 21 | 22 | #include 23 | 24 | /// A line segment (edge) shape. These can be connected in chains or loops 25 | /// to other edge shapes. The connectivity information is used to ensure 26 | /// correct contact normals. 27 | class b2EdgeShape : public b2Shape 28 | { 29 | public: 30 | b2EdgeShape(); 31 | 32 | /// Set this as an isolated edge. 33 | void Set(const b2Vec2& v1, const b2Vec2& v2); 34 | 35 | /// Implement b2Shape. 36 | b2Shape* Clone(b2BlockAllocator* allocator) const; 37 | 38 | /// @see b2Shape::GetChildCount 39 | int32 GetChildCount() const; 40 | 41 | /// @see b2Shape::TestPoint 42 | bool TestPoint(const b2Transform& transform, const b2Vec2& p) const; 43 | 44 | /// Implement b2Shape. 45 | bool RayCast(b2RayCastOutput* output, const b2RayCastInput& input, 46 | const b2Transform& transform, int32 childIndex) const; 47 | 48 | /// @see b2Shape::ComputeAABB 49 | void ComputeAABB(b2AABB* aabb, const b2Transform& transform, int32 childIndex) const; 50 | 51 | /// @see b2Shape::ComputeMass 52 | void ComputeMass(b2MassData* massData, float32 density) const; 53 | 54 | /// These are the edge vertices 55 | b2Vec2 m_vertex1, m_vertex2; 56 | 57 | /// Optional adjacent vertices. These are used for smooth collision. 58 | b2Vec2 m_vertex0, m_vertex3; 59 | bool m_hasVertex0, m_hasVertex3; 60 | }; 61 | 62 | inline b2EdgeShape::b2EdgeShape() 63 | { 64 | m_type = e_edge; 65 | m_radius = b2_polygonRadius; 66 | m_vertex0.x = 0.0f; 67 | m_vertex0.y = 0.0f; 68 | m_vertex3.x = 0.0f; 69 | m_vertex3.y = 0.0f; 70 | m_hasVertex0 = false; 71 | m_hasVertex3 = false; 72 | } 73 | 74 | #endif 75 | -------------------------------------------------------------------------------- /examples/conveyor_belt.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # 4 | # C++ version Copyright (c) 2006-2007 Erin Catto http://www.box2d.org 5 | # Python version by Ken Lauer / sirkne at gmail dot com 6 | # 7 | # This software is provided 'as-is', without any express or implied 8 | # warranty. In no event will the authors be held liable for any damages 9 | # arising from the use of this software. 10 | # Permission is granted to anyone to use this software for any purpose, 11 | # including commercial applications, and to alter it and redistribute it 12 | # freely, subject to the following restrictions: 13 | # 1. The origin of this software must not be misrepresented; you must not 14 | # claim that you wrote the original software. If you use this software 15 | # in a product, an acknowledgment in the product documentation would be 16 | # appreciated but is not required. 17 | # 2. Altered source versions must be plainly marked as such, and must not be 18 | # misrepresented as being the original software. 19 | # 3. This notice may not be removed or altered from any source distribution. 20 | 21 | from .framework import (Framework, main) 22 | from Box2D import (b2EdgeShape, b2FixtureDef, b2PolygonShape) 23 | 24 | 25 | class ConveyorBelt (Framework): 26 | name = "ConveyorBelt" 27 | 28 | def __init__(self): 29 | Framework.__init__(self) 30 | 31 | self.using_contacts = True 32 | ground = self.world.CreateStaticBody( 33 | shapes=[b2EdgeShape(vertices=[(-20, 0), (20, 0)])], 34 | ) 35 | 36 | # Platform 37 | self.platform = self.world.CreateStaticBody( 38 | position=(-5, 5), 39 | allowSleep=False, 40 | fixtures=b2FixtureDef(friction=0.8, 41 | shape=b2PolygonShape(box=(10.0, 5.0)),), 42 | ) 43 | 44 | self.platform_fixture = self.platform.fixtures[0] 45 | 46 | # Boxes 47 | for i in range(5): 48 | self.platform = self.world.CreateDynamicBody( 49 | position=(-10.0 + 2.0 * i, 7.0), 50 | fixtures=b2FixtureDef(density=20.0, 51 | shape=b2PolygonShape(box=(0.5, 0.5)),), 52 | ) 53 | 54 | def PreSolve(self, contact, old_manifold): 55 | Framework.PreSolve(self, contact, old_manifold) 56 | 57 | fixture_a, fixture_b = contact.fixtureA, contact.fixtureB 58 | 59 | if fixture_a == self.platform_fixture: 60 | contact.tangentSpeed = 5.0 61 | elif fixture_b == self.platform_fixture: 62 | contact.tangentSpeed = -5.0 63 | 64 | if __name__ == "__main__": 65 | main(ConveyorBelt) 66 | -------------------------------------------------------------------------------- /examples/pgu/gui/deprecated.py: -------------------------------------------------------------------------------- 1 | import pygame 2 | 3 | from .const import * 4 | from . import table 5 | from . import group 6 | from . import button, basic 7 | from . import pguglobals 8 | 9 | def action_open(value): 10 | print('gui.action_open',"Scheduled to be deprecated.") 11 | value.setdefault('x',None) 12 | value.setdefault('y',None) 13 | value['container'].open(value['window'],value['x'],value['y']) 14 | 15 | def action_setvalue(value): 16 | print('gui.action_setvalue',"Scheduled to be deprecated.") 17 | a,b = value 18 | b.value = a.value 19 | 20 | def action_quit(value): 21 | print('gui.action_quit',"Scheduled to be deprecated.") 22 | value.quit() 23 | 24 | def action_exec(value): 25 | print('gui.action_exec',"Scheduled to be deprecated.") 26 | exec(value['script'],globals(),value['dict']) 27 | 28 | class Toolbox(table.Table): 29 | def __setattr__(self,k,v): 30 | _v = self.__dict__.get(k,NOATTR) 31 | self.__dict__[k]=v 32 | if k == 'value' and _v != NOATTR and _v != v: 33 | self.group.value = v 34 | for w in self.group.widgets: 35 | if w.value != v: w.pcls = "" 36 | else: w.pcls = "down" 37 | self.repaint() 38 | 39 | def _change(self,value): 40 | self.value = self.group.value 41 | self.send(CHANGE) 42 | 43 | def __init__(self,data,cols=0,rows=0,tool_cls='tool',value=None,**params): 44 | print('gui.Toolbox','Scheduled to be deprecated.') 45 | params.setdefault('cls','toolbox') 46 | table.Table.__init__(self,**params) 47 | 48 | if cols == 0 and rows == 0: cols = len(data) 49 | if cols != 0 and rows != 0: rows = 0 50 | 51 | self.tools = {} 52 | 53 | _value = value 54 | 55 | g = group.Group() 56 | self.group = g 57 | g.connect(CHANGE,self._change,None) 58 | self.group.value = _value 59 | 60 | x,y,p,s = 0,0,None,1 61 | for ico,value in data: 62 | #from __init__ import theme 63 | img = pguglobals.app.theme.get(tool_cls+"."+ico,"","image") 64 | if img: 65 | i = basic.Image(img) 66 | else: i = basic.Label(ico,cls=tool_cls+".label") 67 | p = button.Tool(g,i,value,cls=tool_cls) 68 | self.tools[ico] = p 69 | #p.style.hexpand = 1 70 | #p.style.vexpand = 1 71 | self.add(p,x,y) 72 | s = 0 73 | if cols != 0: x += 1 74 | if cols != 0 and x == cols: x,y = 0,y+1 75 | if rows != 0: y += 1 76 | if rows != 0 and y == rows: x,y = x+1,0 77 | -------------------------------------------------------------------------------- /examples/pulley.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # 4 | # C++ version Copyright (c) 2006-2007 Erin Catto http://www.box2d.org 5 | # Python version by Ken Lauer / sirkne at gmail dot com 6 | # 7 | # This software is provided 'as-is', without any express or implied 8 | # warranty. In no event will the authors be held liable for any damages 9 | # arising from the use of this software. 10 | # Permission is granted to anyone to use this software for any purpose, 11 | # including commercial applications, and to alter it and redistribute it 12 | # freely, subject to the following restrictions: 13 | # 1. The origin of this software must not be misrepresented; you must not 14 | # claim that you wrote the original software. If you use this software 15 | # in a product, an acknowledgment in the product documentation would be 16 | # appreciated but is not required. 17 | # 2. Altered source versions must be plainly marked as such, and must not be 18 | # misrepresented as being the original software. 19 | # 3. This notice may not be removed or altered from any source distribution. 20 | 21 | from .framework import (Framework, main) 22 | from Box2D.b2 import (edgeShape, circleShape, fixtureDef, polygonShape) 23 | 24 | 25 | class Pulley (Framework): 26 | name = "Pulley" 27 | 28 | def __init__(self): 29 | super(Pulley, self).__init__() 30 | y, L, a, b = 16.0, 12.0, 1.0, 2.0 31 | # The ground 32 | ground = self.world.CreateStaticBody( 33 | shapes=[edgeShape(vertices=[(-40, 0), (40, 0)]), 34 | circleShape(radius=2, pos=(-10.0, y + b + L)), 35 | circleShape(radius=2, pos=(10.0, y + b + L))] 36 | ) 37 | 38 | bodyA = self.world.CreateDynamicBody( 39 | position=(-10, y), 40 | fixtures=fixtureDef(shape=polygonShape(box=(a, b)), density=5.0), 41 | ) 42 | bodyB = self.world.CreateDynamicBody( 43 | position=(10, y), 44 | fixtures=fixtureDef(shape=polygonShape(box=(a, b)), density=5.0), 45 | ) 46 | 47 | self.pulley = self.world.CreatePulleyJoint( 48 | bodyA=bodyA, 49 | bodyB=bodyB, 50 | anchorA=(-10.0, y + b), 51 | anchorB=(10.0, y + b), 52 | groundAnchorA=(-10.0, y + b + L), 53 | groundAnchorB=(10.0, y + b + L), 54 | ratio=1.5, 55 | ) 56 | 57 | def Step(self, settings): 58 | super(Pulley, self).Step(settings) 59 | 60 | ratio = self.pulley.ratio 61 | L = self.pulley.length1 + self.pulley.length2 * ratio 62 | self.Print('L1 + %4.2f * L2 = %4.2f' % (ratio, L)) 63 | 64 | if __name__ == "__main__": 65 | main(Pulley) 66 | -------------------------------------------------------------------------------- /Box2D/Box2D.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2009 Erin Catto http://www.box2d.org 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked as such, and must not be 15 | * misrepresented as being the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | #ifndef BOX2D_H 20 | #define BOX2D_H 21 | 22 | /** 23 | \mainpage Box2D API Documentation 24 | 25 | \section intro_sec Getting Started 26 | 27 | For documentation please see http://box2d.org/documentation.html 28 | 29 | For discussion please visit http://box2d.org/forum 30 | */ 31 | 32 | // These include files constitute the main Box2D API 33 | 34 | #include 35 | #include 36 | #include 37 | 38 | #include 39 | #include 40 | #include 41 | #include 42 | 43 | #include 44 | #include 45 | #include 46 | #include 47 | 48 | #include 49 | #include 50 | #include 51 | #include 52 | #include 53 | 54 | #include 55 | 56 | #include 57 | #include 58 | #include 59 | #include 60 | #include 61 | #include 62 | #include 63 | #include 64 | #include 65 | #include 66 | #include 67 | 68 | #endif 69 | -------------------------------------------------------------------------------- /devel/test.py: -------------------------------------------------------------------------------- 1 | classname = "b2DebugDraw" 2 | gets = "GetFlags SetFlags ClearFlags AppendFlags".split(" ") 3 | sets = "".split(" ") 4 | kwargs = True 5 | 6 | # remove duplicates 7 | gets = list(set(gets)) 8 | sets = list(set(sets)) 9 | 10 | renames = ["%%rename(__%s) %s::%s;" % (s, classname, s) for s in gets+sets 11 | if s not in ('GetAnchorA', 'GetAnchorB', '')] 12 | 13 | gets_mod=[] 14 | for s in gets: 15 | if s[:3]=="Get": 16 | gets_mod.append(s[3:]) 17 | elif s[:2]=="Is": 18 | gets_mod.append(s[2:]) 19 | else: 20 | gets_mod.append(s) 21 | 22 | sets_mod=[] 23 | for s in sets: 24 | if s[:3]=="Set": 25 | sets_mod.append(s[3:]) 26 | else: 27 | sets_mod.append(s) 28 | 29 | done = [] 30 | getter_setter = [] 31 | getter = [] 32 | 33 | for i, s in enumerate(gets_mod): 34 | if s in sets_mod: 35 | orig_set=sets[ sets_mod.index(s) ] 36 | orig_get = gets[i] 37 | getter_setter.append( (s, orig_get, orig_set) ) 38 | sets[sets_mod.index(s)] = None 39 | else: 40 | getter.append( (s, gets[i]) ) 41 | 42 | setter = [s for s in sets if s is not None] 43 | 44 | if kwargs: 45 | print ''' 46 | /**** %s ****/ 47 | %%extend %s { 48 | public: 49 | %%pythoncode %%{ 50 | def __init__(self, **kwargs): 51 | """__init__(self, **kwargs) -> %s """ 52 | _Box2D.%s_swiginit(self,_Box2D.new_%s()) 53 | for key, value in kwargs.items(): 54 | setattr(self, key, value) 55 | 56 | # Read-write properties 57 | ''' % tuple([classname[2:]] + [classname]*4) 58 | else: 59 | print ''' 60 | /**** %s ****/ 61 | %%extend %s { 62 | public: 63 | %%pythoncode %%{ 64 | # Read-write properties 65 | ''' % (classname[2:], classname) 66 | 67 | for name, g, s in getter_setter: 68 | newname= name[0].lower() + name[1:] 69 | print " %s = property(__%s, __%s)" % (newname, g, s) 70 | 71 | print " # Read-only" 72 | for name, g in getter: 73 | newname= name[0].lower() + name[1:] 74 | if newname in ('anchorA', 'anchorB'): 75 | print " %s = property(lambda self: self._b2Joint__%s(), None)" % (newname, name) 76 | else: 77 | print " %s = property(__%s, None)" % (newname, g) 78 | 79 | print " # Write-only" 80 | for s in setter: 81 | if not s: continue 82 | if s[:3]=='Set': 83 | name = s[3:] 84 | else: 85 | name = s 86 | newname= name[0].lower() + name[1:] 87 | print " %s = property(None, __%s)" % (newname, s) 88 | 89 | print """ 90 | %} 91 | } 92 | """ 93 | print " ", 94 | print "\n ".join(renames) 95 | -------------------------------------------------------------------------------- /examples/tumbler.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # 4 | # C++ version Copyright (c) 2006-2007 Erin Catto http://www.box2d.org 5 | # Python version by Ken Lauer / sirkne at gmail dot com 6 | # 7 | # This software is provided 'as-is', without any express or implied 8 | # warranty. In no event will the authors be held liable for any damages 9 | # arising from the use of this software. 10 | # Permission is granted to anyone to use this software for any purpose, 11 | # including commercial applications, and to alter it and redistribute it 12 | # freely, subject to the following restrictions: 13 | # 1. The origin of this software must not be misrepresented; you must not 14 | # claim that you wrote the original software. If you use this software 15 | # in a product, an acknowledgment in the product documentation would be 16 | # appreciated but is not required. 17 | # 2. Altered source versions must be plainly marked as such, and must not be 18 | # misrepresented as being the original software. 19 | # 3. This notice may not be removed or altered from any source distribution. 20 | 21 | 22 | from .framework import (Framework, main) 23 | from Box2D import (b2FixtureDef, b2PolygonShape, b2_pi) 24 | 25 | 26 | class Tumbler (Framework): 27 | name = "Tumbler" 28 | description = '' 29 | count = 800 30 | 31 | def __init__(self): 32 | Framework.__init__(self) 33 | 34 | ground = self.world.CreateBody() 35 | 36 | body = self.world.CreateDynamicBody( 37 | position=(0, 10), 38 | allowSleep=False, 39 | shapeFixture=b2FixtureDef(density=5.0), 40 | shapes=[ 41 | b2PolygonShape(box=(0.5, 10, (10, 0), 0)), 42 | b2PolygonShape(box=(0.5, 10, (-10, 0), 0)), 43 | b2PolygonShape(box=(10, 0.5, (0, 10), 0)), 44 | b2PolygonShape(box=(10, 0.5, (0, -10), 0)), 45 | ] 46 | ) 47 | 48 | self.joint = self.world.CreateRevoluteJoint(bodyA=ground, bodyB=body, 49 | localAnchorA=(0, 10), localAnchorB=(0, 0), 50 | referenceAngle=0, motorSpeed=0.05 * b2_pi, 51 | enableMotor=True, maxMotorTorque=1.0e8) 52 | 53 | def Step(self, settings): 54 | Framework.Step(self, settings) 55 | 56 | self.count -= 1 57 | if self.count == 0: 58 | return 59 | 60 | self.world.CreateDynamicBody( 61 | position=(0, 10), 62 | allowSleep=False, 63 | fixtures=b2FixtureDef( 64 | density=1.0, shape=b2PolygonShape(box=(0.125, 0.125))), 65 | ) 66 | 67 | if __name__ == "__main__": 68 | main(Tumbler) 69 | -------------------------------------------------------------------------------- /examples/bullet.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # 4 | # C++ version Copyright (c) 2006-2007 Erin Catto http://www.box2d.org 5 | # Python version Copyright (c) 2010 kne / sirkne at gmail dot com 6 | # 7 | # This software is provided 'as-is', without any express or implied 8 | # warranty. In no event will the authors be held liable for any damages 9 | # arising from the use of this software. 10 | # Permission is granted to anyone to use this software for any purpose, 11 | # including commercial applications, and to alter it and redistribute it 12 | # freely, subject to the following restrictions: 13 | # 1. The origin of this software must not be misrepresented; you must not 14 | # claim that you wrote the original software. If you use this software 15 | # in a product, an acknowledgment in the product documentation would be 16 | # appreciated but is not required. 17 | # 2. Altered source versions must be plainly marked as such, and must not be 18 | # misrepresented as being the original software. 19 | # 3. This notice may not be removed or altered from any source distribution. 20 | 21 | from .framework import (Framework, main) 22 | from Box2D import (b2EdgeShape, b2FixtureDef, b2PolygonShape, b2Random) 23 | 24 | 25 | class Bullet (Framework): 26 | name = "Bullet" 27 | description = 'A test for very fast moving objects (bullets)' 28 | 29 | def __init__(self): 30 | super(Bullet, self).__init__() 31 | 32 | ground = self.world.CreateStaticBody( 33 | position=(0, 0), 34 | shapes=[b2EdgeShape(vertices=[(-10, 0), (10, 0)]), 35 | b2PolygonShape(box=(0.2, 1, (0.5, 1), 0))] 36 | ) 37 | 38 | self._x = 0.20352793 39 | self.body = self.world.CreateDynamicBody( 40 | position=(0, 4), 41 | fixtures=b2FixtureDef( 42 | shape=b2PolygonShape(box=(2, 0.1)), density=1.0), 43 | ) 44 | 45 | self.bullet = self.world.CreateDynamicBody( 46 | position=(self._x, 10), 47 | bullet=True, 48 | fixtures=b2FixtureDef(shape=b2PolygonShape( 49 | box=(0.25, 0.25)), density=100.0), 50 | linearVelocity=(0, -50) 51 | ) 52 | 53 | def Launch(self): 54 | self.body.transform = [(0, 4), 0] 55 | self.body.linearVelocity = (0, 0) 56 | self.body.angularVelocity = 0 57 | 58 | self.x = b2Random() 59 | self.bullet.transform = [(self.x, 10), 0] 60 | self.bullet.linearVelocity = (0, -50) 61 | self.bullet.angularVelocity = 0 62 | 63 | def Step(self, settings): 64 | super(Bullet, self).Step(settings) 65 | 66 | if (self.stepCount % 60) == 0: 67 | self.Launch() 68 | 69 | if __name__ == "__main__": 70 | main(Bullet) 71 | -------------------------------------------------------------------------------- /Box2D/Common/b2Timer.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Erin Catto http://box2d.org 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked as such, and must not be 15 | * misrepresented as being the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | #include 20 | 21 | #if defined(_WIN32) 22 | 23 | float64 b2Timer::s_invFrequency = 0.0f; 24 | 25 | #include 26 | 27 | b2Timer::b2Timer() 28 | { 29 | LARGE_INTEGER largeInteger; 30 | 31 | if (s_invFrequency == 0.0f) 32 | { 33 | QueryPerformanceFrequency(&largeInteger); 34 | s_invFrequency = float64(largeInteger.QuadPart); 35 | if (s_invFrequency > 0.0f) 36 | { 37 | s_invFrequency = 1000.0f / s_invFrequency; 38 | } 39 | } 40 | 41 | QueryPerformanceCounter(&largeInteger); 42 | m_start = float64(largeInteger.QuadPart); 43 | } 44 | 45 | void b2Timer::Reset() 46 | { 47 | LARGE_INTEGER largeInteger; 48 | QueryPerformanceCounter(&largeInteger); 49 | m_start = float64(largeInteger.QuadPart); 50 | } 51 | 52 | float32 b2Timer::GetMilliseconds() const 53 | { 54 | LARGE_INTEGER largeInteger; 55 | QueryPerformanceCounter(&largeInteger); 56 | float64 count = float64(largeInteger.QuadPart); 57 | float32 ms = float32(s_invFrequency * (count - m_start)); 58 | return ms; 59 | } 60 | 61 | #elif defined(__linux__) || defined (__APPLE__) 62 | 63 | #include 64 | 65 | b2Timer::b2Timer() 66 | { 67 | Reset(); 68 | } 69 | 70 | void b2Timer::Reset() 71 | { 72 | timeval t; 73 | gettimeofday(&t, 0); 74 | m_start_sec = t.tv_sec; 75 | m_start_msec = t.tv_usec * 0.001f; 76 | } 77 | 78 | float32 b2Timer::GetMilliseconds() const 79 | { 80 | timeval t; 81 | gettimeofday(&t, 0); 82 | return (t.tv_sec - m_start_sec) * 1000 + t.tv_usec * 0.001f - m_start_msec; 83 | } 84 | 85 | #else 86 | 87 | b2Timer::b2Timer() 88 | { 89 | } 90 | 91 | void b2Timer::Reset() 92 | { 93 | } 94 | 95 | float32 b2Timer::GetMilliseconds() const 96 | { 97 | return 0.0f; 98 | } 99 | 100 | #endif 101 | -------------------------------------------------------------------------------- /examples/confined.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # 4 | # C++ version Copyright (c) 2006-2007 Erin Catto http://www.box2d.org 5 | # Python version by Ken Lauer / sirkne at gmail dot com 6 | # 7 | # This software is provided 'as-is', without any express or implied 8 | # warranty. In no event will the authors be held liable for any damages 9 | # arising from the use of this software. 10 | # Permission is granted to anyone to use this software for any purpose, 11 | # including commercial applications, and to alter it and redistribute it 12 | # freely, subject to the following restrictions: 13 | # 1. The origin of this software must not be misrepresented; you must not 14 | # claim that you wrote the original software. If you use this software 15 | # in a product, an acknowledgment in the product documentation would be 16 | # appreciated but is not required. 17 | # 2. Altered source versions must be plainly marked as such, and must not be 18 | # misrepresented as being the original software. 19 | # 3. This notice may not be removed or altered from any source distribution. 20 | 21 | from random import random 22 | 23 | from .framework import (Framework, Keys, main) 24 | from Box2D import (b2CircleShape, b2EdgeShape, b2FixtureDef) 25 | 26 | 27 | class Confined (Framework): 28 | name = "Confined space" 29 | description = "Press c to create a circle" 30 | 31 | def __init__(self): 32 | super(Confined, self).__init__() 33 | 34 | # The ground 35 | ground = self.world.CreateStaticBody( 36 | shapes=[b2EdgeShape(vertices=[(-10, 0), (10, 0)]), 37 | b2EdgeShape(vertices=[(-10, 0), (-10, 20)]), 38 | b2EdgeShape(vertices=[(10, 0), (10, 20)]), 39 | b2EdgeShape(vertices=[(-10, 20), (10, 20)]), 40 | ]) 41 | 42 | # The bodies 43 | self.radius = radius = 0.5 44 | columnCount = 5 45 | rowCount = 5 46 | 47 | for j in range(columnCount): 48 | for i in range(rowCount): 49 | self.CreateCircle((-10 + (2.1 * j + 1 + 0.01 * i) * radius, 50 | (2 * i + 1) * radius)) 51 | 52 | self.world.gravity = (0, 0) 53 | 54 | def CreateCircle(self, pos): 55 | fixture = b2FixtureDef(shape=b2CircleShape(radius=self.radius, 56 | pos=(0, 0)), 57 | density=1, friction=0.1) 58 | 59 | self.world.CreateDynamicBody( 60 | position=pos, 61 | fixtures=fixture 62 | ) 63 | 64 | def Keyboard(self, key): 65 | if key == Keys.K_c: 66 | self.CreateCircle((2.0 * random() - 1.0, 67 | self.radius * (1.0 + random()))) 68 | 69 | if __name__ == "__main__": 70 | main(Confined) 71 | -------------------------------------------------------------------------------- /Box2D/Dynamics/Contacts/b2ContactSolver.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2009 Erin Catto http://www.box2d.org 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked as such, and must not be 15 | * misrepresented as being the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | #ifndef B2_CONTACT_SOLVER_H 20 | #define B2_CONTACT_SOLVER_H 21 | 22 | #include 23 | #include 24 | #include 25 | 26 | class b2Contact; 27 | class b2Body; 28 | class b2StackAllocator; 29 | struct b2ContactPositionConstraint; 30 | 31 | struct b2VelocityConstraintPoint 32 | { 33 | b2Vec2 rA; 34 | b2Vec2 rB; 35 | float32 normalImpulse; 36 | float32 tangentImpulse; 37 | float32 normalMass; 38 | float32 tangentMass; 39 | float32 velocityBias; 40 | }; 41 | 42 | struct b2ContactVelocityConstraint 43 | { 44 | b2VelocityConstraintPoint points[b2_maxManifoldPoints]; 45 | b2Vec2 normal; 46 | b2Mat22 normalMass; 47 | b2Mat22 K; 48 | int32 indexA; 49 | int32 indexB; 50 | float32 invMassA, invMassB; 51 | float32 invIA, invIB; 52 | float32 friction; 53 | float32 restitution; 54 | float32 tangentSpeed; 55 | int32 pointCount; 56 | int32 contactIndex; 57 | }; 58 | 59 | struct b2ContactSolverDef 60 | { 61 | b2TimeStep step; 62 | b2Contact** contacts; 63 | int32 count; 64 | b2Position* positions; 65 | b2Velocity* velocities; 66 | b2StackAllocator* allocator; 67 | }; 68 | 69 | class b2ContactSolver 70 | { 71 | public: 72 | b2ContactSolver(b2ContactSolverDef* def); 73 | ~b2ContactSolver(); 74 | 75 | void InitializeVelocityConstraints(); 76 | 77 | void WarmStart(); 78 | void SolveVelocityConstraints(); 79 | void StoreImpulses(); 80 | 81 | bool SolvePositionConstraints(); 82 | bool SolveTOIPositionConstraints(int32 toiIndexA, int32 toiIndexB); 83 | 84 | b2TimeStep m_step; 85 | b2Position* m_positions; 86 | b2Velocity* m_velocities; 87 | b2StackAllocator* m_allocator; 88 | b2ContactPositionConstraint* m_positionConstraints; 89 | b2ContactVelocityConstraint* m_velocityConstraints; 90 | b2Contact** m_contacts; 91 | int m_count; 92 | }; 93 | 94 | #endif 95 | 96 | -------------------------------------------------------------------------------- /Box2D/Dynamics/b2Island.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2009 Erin Catto http://www.box2d.org 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked as such, and must not be 15 | * misrepresented as being the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | #ifndef B2_ISLAND_H 20 | #define B2_ISLAND_H 21 | 22 | #include 23 | #include 24 | #include 25 | 26 | class b2Contact; 27 | class b2Joint; 28 | class b2StackAllocator; 29 | class b2ContactListener; 30 | struct b2ContactVelocityConstraint; 31 | struct b2Profile; 32 | 33 | /// This is an internal class. 34 | class b2Island 35 | { 36 | public: 37 | b2Island(int32 bodyCapacity, int32 contactCapacity, int32 jointCapacity, 38 | b2StackAllocator* allocator, b2ContactListener* listener); 39 | ~b2Island(); 40 | 41 | void Clear() 42 | { 43 | m_bodyCount = 0; 44 | m_contactCount = 0; 45 | m_jointCount = 0; 46 | } 47 | 48 | void Solve(b2Profile* profile, const b2TimeStep& step, const b2Vec2& gravity, bool allowSleep); 49 | 50 | void SolveTOI(const b2TimeStep& subStep, int32 toiIndexA, int32 toiIndexB); 51 | 52 | void Add(b2Body* body) 53 | { 54 | b2Assert(m_bodyCount < m_bodyCapacity); 55 | body->m_islandIndex = m_bodyCount; 56 | m_bodies[m_bodyCount] = body; 57 | ++m_bodyCount; 58 | } 59 | 60 | void Add(b2Contact* contact) 61 | { 62 | b2Assert(m_contactCount < m_contactCapacity); 63 | m_contacts[m_contactCount++] = contact; 64 | } 65 | 66 | void Add(b2Joint* joint) 67 | { 68 | b2Assert(m_jointCount < m_jointCapacity); 69 | m_joints[m_jointCount++] = joint; 70 | } 71 | 72 | void Report(const b2ContactVelocityConstraint* constraints); 73 | 74 | b2StackAllocator* m_allocator; 75 | b2ContactListener* m_listener; 76 | 77 | b2Body** m_bodies; 78 | b2Contact** m_contacts; 79 | b2Joint** m_joints; 80 | 81 | b2Position* m_positions; 82 | b2Velocity* m_velocities; 83 | 84 | int32 m_bodyCount; 85 | int32 m_jointCount; 86 | int32 m_contactCount; 87 | 88 | int32 m_bodyCapacity; 89 | int32 m_contactCapacity; 90 | int32 m_jointCapacity; 91 | }; 92 | 93 | #endif 94 | -------------------------------------------------------------------------------- /examples/mobile.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # 4 | # C++ version Copyright (c) 2006-2007 Erin Catto http://www.box2d.org 5 | # Python version by Ken Lauer / sirkne at gmail dot com 6 | # 7 | # This software is provided 'as-is', without any express or implied 8 | # warranty. In no event will the authors be held liable for any damages 9 | # arising from the use of this software. 10 | # Permission is granted to anyone to use this software for any purpose, 11 | # including commercial applications, and to alter it and redistribute it 12 | # freely, subject to the following restrictions: 13 | # 1. The origin of this software must not be misrepresented; you must not 14 | # claim that you wrote the original software. If you use this software 15 | # in a product, an acknowledgment in the product documentation would be 16 | # appreciated but is not required. 17 | # 2. Altered source versions must be plainly marked as such, and must not be 18 | # misrepresented as being the original software. 19 | # 3. This notice may not be removed or altered from any source distribution. 20 | 21 | from .framework import (Framework, main) 22 | from Box2D import (b2EdgeShape, b2FixtureDef, b2PolygonShape) 23 | 24 | 25 | class Mobile (Framework): 26 | name = "Mobile" 27 | max_depth = 4 28 | 29 | def __init__(self): 30 | Framework.__init__(self) 31 | 32 | ground = self.world.CreateStaticBody( 33 | position=(0, 20), 34 | shapes=[b2EdgeShape(vertices=[(-20, 0), (20, 0)])], 35 | ) 36 | 37 | a = 0.5 38 | depth = 0 39 | self.root = self.add_node(ground, (0, 0), depth, 3.0, a) 40 | 41 | self.world.CreateRevoluteJoint(bodyA=ground, bodyB=self.root, 42 | localAnchorA=(0, 0), localAnchorB=(0, a)) 43 | 44 | def add_node(self, parent, local_anchor, depth, offset, a): 45 | density = 20.0 46 | h = (0, a) 47 | 48 | p = parent.position + local_anchor - h 49 | 50 | fixture = b2FixtureDef(shape=b2PolygonShape(box=(0.25 * a, a)), 51 | density=density) 52 | body = self.world.CreateDynamicBody(position=p, fixtures=fixture) 53 | 54 | if depth == self.max_depth: 55 | return body 56 | 57 | a1 = (offset, -a) 58 | a2 = (-offset, -a) 59 | body1 = self.add_node(body, a1, depth + 1, 0.5 * offset, a) 60 | body2 = self.add_node(body, a2, depth + 1, 0.5 * offset, a) 61 | 62 | self.world.CreateRevoluteJoint(bodyA=body, bodyB=body1, 63 | localAnchorA=a1, localAnchorB=h) 64 | self.world.CreateRevoluteJoint(bodyA=body, bodyB=body2, 65 | localAnchorA=a2, localAnchorB=h) 66 | 67 | return body 68 | 69 | if __name__ == "__main__": 70 | main(Mobile) 71 | -------------------------------------------------------------------------------- /examples/motor_joint.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # 4 | # C++ version Copyright (c) 2006-2007 Erin Catto http://www.box2d.org 5 | # Python version by Ken Lauer / sirkne at gmail dot com 6 | # 7 | # This software is provided 'as-is', without any express or implied 8 | # warranty. In no event will the authors be held liable for any damages 9 | # arising from the use of this software. 10 | # Permission is granted to anyone to use this software for any purpose, 11 | # including commercial applications, and to alter it and redistribute it 12 | # freely, subject to the following restrictions: 13 | # 1. The origin of this software must not be misrepresented; you must not 14 | # claim that you wrote the original software. If you use this software 15 | # in a product, an acknowledgment in the product documentation would be 16 | # appreciated but is not required. 17 | # 2. Altered source versions must be plainly marked as such, and must not be 18 | # misrepresented as being the original software. 19 | # 3. This notice may not be removed or altered from any source distribution. 20 | 21 | from math import sin 22 | 23 | from .framework import (Framework, Keys, main) 24 | from Box2D import (b2Color, b2EdgeShape, b2FixtureDef, b2PolygonShape) 25 | 26 | 27 | class MotorJoint (Framework): 28 | name = "MotorJoint" 29 | description = 'g to stop/go' 30 | count = 800 31 | 32 | def __init__(self): 33 | Framework.__init__(self) 34 | 35 | ground = self.world.CreateStaticBody( 36 | shapes=[b2EdgeShape(vertices=[(-20, 0), (20, 0)])], 37 | ) 38 | 39 | # Define motorized body 40 | body = self.world.CreateDynamicBody( 41 | position=(0, 8), 42 | allowSleep=False, 43 | fixtures=b2FixtureDef(density=2.0, friction=0.6, 44 | shape=b2PolygonShape(box=(2.0, 0.5)),), 45 | ) 46 | 47 | self.joint = self.world.CreateMotorJoint(bodyA=ground, bodyB=body, 48 | maxForce=1000, maxTorque=1000) 49 | 50 | self.go = False 51 | self.time = 0.0 52 | 53 | def Keyboard(self, key): 54 | if key == Keys.K_g: 55 | self.go = not self.go 56 | 57 | def Step(self, settings): 58 | Framework.Step(self, settings) 59 | 60 | if self.go and settings.hz > 0.0: 61 | self.time += 1.0 / settings.hz 62 | 63 | linear_offset = (6 * sin(2.0 * self.time), 8.0 + 64 | 4.0 * sin(1.0 * self.time)) 65 | angular_offset = 4.0 * self.time 66 | 67 | self.joint.linearOffset = linear_offset 68 | self.joint.angularOffset = angular_offset 69 | 70 | renderer = self.renderer 71 | renderer.DrawPoint(renderer.to_screen( 72 | linear_offset), 4, b2Color(0.9, 0.9, 0.9)) 73 | 74 | if __name__ == "__main__": 75 | main(MotorJoint) 76 | -------------------------------------------------------------------------------- /Box2D/Collision/Shapes/b2CircleShape.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2009 Erin Catto http://www.box2d.org 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked as such, and must not be 15 | * misrepresented as being the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | #ifndef B2_CIRCLE_SHAPE_H 20 | #define B2_CIRCLE_SHAPE_H 21 | 22 | #include 23 | 24 | /// A circle shape. 25 | class b2CircleShape : public b2Shape 26 | { 27 | public: 28 | b2CircleShape(); 29 | 30 | /// Implement b2Shape. 31 | b2Shape* Clone(b2BlockAllocator* allocator) const; 32 | 33 | /// @see b2Shape::GetChildCount 34 | int32 GetChildCount() const; 35 | 36 | /// Implement b2Shape. 37 | bool TestPoint(const b2Transform& transform, const b2Vec2& p) const; 38 | 39 | /// Implement b2Shape. 40 | bool RayCast(b2RayCastOutput* output, const b2RayCastInput& input, 41 | const b2Transform& transform, int32 childIndex) const; 42 | 43 | /// @see b2Shape::ComputeAABB 44 | void ComputeAABB(b2AABB* aabb, const b2Transform& transform, int32 childIndex) const; 45 | 46 | /// @see b2Shape::ComputeMass 47 | void ComputeMass(b2MassData* massData, float32 density) const; 48 | 49 | /// Get the supporting vertex index in the given direction. 50 | int32 GetSupport(const b2Vec2& d) const; 51 | 52 | /// Get the supporting vertex in the given direction. 53 | const b2Vec2& GetSupportVertex(const b2Vec2& d) const; 54 | 55 | /// Get the vertex count. 56 | int32 GetVertexCount() const { return 1; } 57 | 58 | /// Get a vertex by index. Used by b2Distance. 59 | const b2Vec2& GetVertex(int32 index) const; 60 | 61 | /// Position 62 | b2Vec2 m_p; 63 | }; 64 | 65 | inline b2CircleShape::b2CircleShape() 66 | { 67 | m_type = e_circle; 68 | m_radius = 0.0f; 69 | m_p.SetZero(); 70 | } 71 | 72 | inline int32 b2CircleShape::GetSupport(const b2Vec2 &d) const 73 | { 74 | B2_NOT_USED(d); 75 | return 0; 76 | } 77 | 78 | inline const b2Vec2& b2CircleShape::GetSupportVertex(const b2Vec2 &d) const 79 | { 80 | B2_NOT_USED(d); 81 | return m_p; 82 | } 83 | 84 | inline const b2Vec2& b2CircleShape::GetVertex(int32 index) const 85 | { 86 | B2_NOT_USED(index); 87 | b2Assert(index == 0); 88 | return m_p; 89 | } 90 | 91 | #endif 92 | -------------------------------------------------------------------------------- /examples/pgu/gui/document.py: -------------------------------------------------------------------------------- 1 | """ 2 | """ 3 | import pygame 4 | 5 | from . import container 6 | from . import layout 7 | 8 | class _document_widget: 9 | def __init__(self,w,align=None): 10 | #w.rect.w,w.rect.h = w.resize() 11 | #self.rect = w.rect 12 | self.widget = w 13 | if align != None: self.align = align 14 | 15 | class Document(container.Container): 16 | """A document is a container that structures widgets in a left-to-right flow.""" 17 | 18 | def __init__(self,**params): 19 | params.setdefault('cls','document') 20 | container.Container.__init__(self,**params) 21 | self.layout = layout.Layout(pygame.Rect(0,0,self.rect.w,self.rect.h)) 22 | 23 | def add(self,e,align=None): 24 | """Add a widget to the document flow. 25 | 26 | Arguments: 27 | e -- widget 28 | align -- alignment (None,-1,0,1) 29 | 30 | """ 31 | dw = _document_widget(e,align) 32 | self.layout.add(dw) 33 | e.container = self 34 | e._c_dw = dw 35 | self.widgets.append(e) 36 | self.chsize() 37 | 38 | def remove(self,e): 39 | self.layout._widgets.remove(e._c_dw) 40 | self.widgets.remove(e) 41 | self.chsize() 42 | 43 | 44 | def block(self,align): 45 | """Start a new block given the alignment (-1, 0, 1)""" 46 | self.layout.add(align) 47 | 48 | def space(self, size): 49 | """Add a spacer given the size.""" 50 | self.layout.add(size) 51 | 52 | def br(self,height): 53 | """Add a line break, given the height.""" 54 | self.layout.add((0, height)) 55 | 56 | def resize(self,width=None,height=None): 57 | if self.style.width: width = self.style.width 58 | if self.style.height: height = self.style.height 59 | 60 | for w in self.widgets: 61 | w.rect.w,w.rect.h = w.resize() 62 | 63 | if (width != None and w.rect.w > width) or (height != None and w.rect.h > height): 64 | w.rect.w,w.rect.h = w.resize(width,height) 65 | 66 | dw = w._c_dw 67 | dw.rect = pygame.Rect(0,0,w.rect.w,w.rect.h) 68 | 69 | if width == None: width = 65535 70 | self.layout.rect = pygame.Rect(0,0,width,0) 71 | self.layout.resize() 72 | 73 | _max_w = 0 74 | 75 | for w in self.widgets: 76 | #xt,xl,xb,xr = w.getspacing() 77 | dw = w._c_dw 78 | w.style.x,w.style.y,w.rect.w,w.rect.h = dw.rect.x,dw.rect.y,dw.rect.w,dw.rect.h 79 | #w.resize() 80 | w.rect.x,w.rect.y = w.style.x,w.style.y 81 | _max_w = max(_max_w,w.rect.right) 82 | 83 | #self.rect.w = _max_w #self.layout.rect.w 84 | #self.rect.h = self.layout.rect.h 85 | #print 'document',_max_w,self.layout.rect.h 86 | return _max_w,self.layout.rect.h 87 | 88 | -------------------------------------------------------------------------------- /examples/pgu/gui/form.py: -------------------------------------------------------------------------------- 1 | """ 2 | """ 3 | from . import widget 4 | 5 | class Form(widget.Widget): 6 | """A form that automatically will contain all named widgets. 7 | 8 | After a form is created, all named widget that are subsequently created are 9 | added to that form. You may use dict style access to access named widgets. 10 | 11 | Example: 12 | 13 | f = gui.Form() 14 | 15 | w = gui.Input("Phil",name="firstname") 16 | w = gui.Input("Hassey",name="lastname") 17 | 18 | print f.results() 19 | print '' 20 | print f.items() 21 | print '' 22 | print f['firstname'].value 23 | print f['lastname'].value 24 | 25 | """ 26 | 27 | # The current form instance 28 | form = None 29 | # The list of PGU widgets that are tracked by this form 30 | _elist = None 31 | # A mapping of PGU widgets tracked by this form (name -> instance) 32 | _emap = None 33 | # The dirty flag is set when a new widget is added to the form 34 | _dirty = 0 35 | 36 | def __init__(self): 37 | widget.Widget.__init__(self,decorate=False) 38 | self._elist = [] 39 | self._emap = {} 40 | self._dirty = 0 41 | # Register this form as the one used by new widgets 42 | Form.form = self 43 | 44 | def add(self,e,name=None,value=None): 45 | """Adds a PGU widget to this form""" 46 | if name != None: e.name = name 47 | if value != None: e.value = value 48 | self._elist.append(e) 49 | self._dirty = 1 50 | 51 | def _clean(self): 52 | # Remove elements from our list if they no longer have an assigned name 53 | for e in self._elist[:]: 54 | if not hasattr(e,'name') or e.name == None: 55 | self._elist.remove(e) 56 | # Update the name-to-widget mapping 57 | self._emap = {} 58 | for e in self._elist: 59 | self._emap[e.name] = e 60 | self._dirty = 0 61 | 62 | def __getitem__(self,k): 63 | """Returns the widget instance given the name of the widget""" 64 | if self._dirty: self._clean() 65 | return self._emap[k] 66 | 67 | def __contains__(self,k): 68 | """Returns true if this form contains the named widget""" 69 | if self._dirty: self._clean() 70 | if k in self._emap: return True 71 | return False 72 | 73 | def results(self): 74 | """Return a dict of name, widget-value pairs.""" 75 | if self._dirty: self._clean() 76 | r = {} 77 | for e in self._elist: 78 | # Make sure the widget has a 'value' (eg tables do not) 79 | if (hasattr(e, "value")): 80 | r[e.name] = e.value 81 | else: 82 | r[e.name] = None 83 | return r 84 | 85 | def items(self): 86 | """Return a list of name, widget pairs.""" 87 | return self.results().items() 88 | 89 | 90 | -------------------------------------------------------------------------------- /examples/empty.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # 4 | # C++ version Copyright (c) 2006-2007 Erin Catto http://www.box2d.org 5 | # Python version Copyright (c) 2010 kne / sirkne at gmail dot com 6 | # 7 | # Implemented using the pybox2d SWIG interface for Box2D (pybox2d.googlecode.com) 8 | # 9 | # This software is provided 'as-is', without any express or implied 10 | # warranty. In no event will the authors be held liable for any damages 11 | # arising from the use of this software. 12 | # Permission is granted to anyone to use this software for any purpose, 13 | # including commercial applications, and to alter it and redistribute it 14 | # freely, subject to the following restrictions: 15 | # 1. The origin of this software must not be misrepresented; you must not 16 | # claim that you wrote the original software. If you use this software 17 | # in a product, an acknowledgment in the product documentation would be 18 | # appreciated but is not required. 19 | # 2. Altered source versions must be plainly marked as such, and must not be 20 | # misrepresented as being the original software. 21 | # 3. This notice may not be removed or altered from any source distribution. 22 | 23 | from .framework import (Framework, main) 24 | 25 | 26 | class Empty(Framework): 27 | """You can use this class as an outline for your tests.""" 28 | name = "Empty" # Name of the class to display 29 | description = "The description text goes here" 30 | 31 | def __init__(self): 32 | """ 33 | Initialize all of your objects here. 34 | Be sure to call the Framework's initializer first. 35 | """ 36 | super(Empty, self).__init__() 37 | 38 | # Initialize all of the objects 39 | 40 | def Keyboard(self, key): 41 | """ 42 | The key is from Keys.K_* 43 | (e.g., if key == Keys.K_z: ... ) 44 | """ 45 | pass 46 | 47 | def Step(self, settings): 48 | """Called upon every step. 49 | You should always call 50 | -> super(Your_Test_Class, self).Step(settings) 51 | at the beginning or end of your function. 52 | 53 | If placed at the beginning, it will cause the actual physics step to happen first. 54 | If placed at the end, it will cause the physics step to happen after your code. 55 | """ 56 | 57 | super(Empty, self).Step(settings) 58 | 59 | # do stuff 60 | 61 | # Placed after the physics step, it will draw on top of physics objects 62 | self.Print("*** Base your own testbeds on me! ***") 63 | 64 | def ShapeDestroyed(self, shape): 65 | """ 66 | Callback indicating 'shape' has been destroyed. 67 | """ 68 | pass 69 | 70 | def JointDestroyed(self, joint): 71 | """ 72 | The joint passed in was removed. 73 | """ 74 | pass 75 | 76 | # More functions can be changed to allow for contact monitoring and such. 77 | # See the other testbed examples for more information. 78 | 79 | if __name__ == "__main__": 80 | main(Empty) 81 | -------------------------------------------------------------------------------- /devel/find_results: -------------------------------------------------------------------------------- 1 | Total classes: 95 2 | Ignored classes: 29 3 | Remaining classes: 66 4 | Class Extended in 5 | b2Shape Box2D_shapes.i 6 | b2Fixture Box2D_bodyfixture.i, Box2D_userdata.i 7 | b2MouseJoint Box2D_joints.i 8 | b2PulleyJoint Box2D_joints.i 9 | b2LineJoint Box2D_joints.i 10 | b2Vec2 Box2D_vectors.i 11 | b2Vec3 Box2D_vectors.i 12 | b2AABB Box2D_vectors.i 13 | b2FixtureDef Box2D_bodyfixture.i, Box2D_userdata.i 14 | b2BodyDef Box2D_bodyfixture.i, Box2D_userdata.i 15 | b2Manifold Box2D_contact.i 16 | b2WorldManifold Box2D_contact.i 17 | b2World Box2D_userdata.i, Box2D_world.i 18 | b2PrismaticJoint Box2D_joints.i 19 | b2CircleShape Box2D_shapes.i 20 | b2Joint Box2D_joints.i, Box2D_userdata.i 21 | b2GearJoint Box2D_joints.i 22 | b2WeldJoint Box2D_joints.i 23 | b2RevoluteJoint Box2D_joints.i 24 | b2Mat22 Box2D_vectors.i 25 | b2JointDef Box2D_userdata.i 26 | b2Transform Box2D_vectors.i 27 | b2Color Box2D_misc.i 28 | b2PolygonShape Box2D_shapes.i 29 | b2Contact Box2D_contact.i 30 | b2DistanceJoint Box2D_joints.i 31 | b2Body Box2D_bodyfixture.i, Box2D_userdata.i 32 | b2FrictionJoint Box2D_joints.i 33 | 34 | Newly modified, to check/test 35 | ----------------------------- 36 | b2DistanceProxy # Needed for b2DistanceInput 37 | b2Mat33 # Add support for b2Mat33 * b2Vec3 / TODO: test all matrix math, and add a test 38 | b2Segment # TestSegment with output 39 | b2Version # TODO: __repr__ modification 40 | 41 | Unmodified classes 42 | ------------------ 43 | b2ContactImpulse # TODO: check this (PostSolve) 44 | b2RayCastCallback # Director added, should be ok (TODO: check raycasts) 45 | b2DebugDraw # Director added, should be ok 46 | b2DestructionList. # Director added, should be ok 47 | b2QueryCallback # Director added, should be ok 48 | b2BlockAllocator # Could possibly be used with b2Shape.Clone(), 49 | # but not without access to the block allocator. Ignoring this and the clone function. 50 | b2Sweep # Actually should be ok 51 | b2ClipVertex # Basic struct 52 | b2ContactPoint # Created in Box2D_contact.i 53 | b2ContactEdge # Basic struct 54 | b2ContactFilter # Director added, should be ok 55 | b2ContactID # Basic union 56 | b2ContactListener # Director added, should be ok 57 | b2ContactRegister # Added to ignore list, shouldn't be used 58 | b2DistanceInput # Should be ok unmodified. Basic struct 59 | b2DistanceOutput # Basic struct 60 | b2Filter # Basic struct 61 | b2Jacobian # Basic struct with a couple functions. 62 | b2JointEdge # Basic struct 63 | b2ManifoldPoint # Basic struct 64 | b2MassData # Basic struct 65 | b2Pair # Basic struct 66 | b2RayCastInput # Basic struct 67 | b2RayCastOutput # Basic struct 68 | b2TOIInput # Basic struct 69 | -------------------------------------------------------------------------------- /Box2D/Common/b2Math.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007-2009 Erin Catto http://www.box2d.org 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked as such, and must not be 15 | * misrepresented as being the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | #include 20 | 21 | const b2Vec2 b2Vec2_zero(0.0f, 0.0f); 22 | 23 | /// Solve A * x = b, where b is a column vector. This is more efficient 24 | /// than computing the inverse in one-shot cases. 25 | b2Vec3 b2Mat33::Solve33(const b2Vec3& b) const 26 | { 27 | float32 det = b2Dot(ex, b2Cross(ey, ez)); 28 | if (det != 0.0f) 29 | { 30 | det = 1.0f / det; 31 | } 32 | b2Vec3 x; 33 | x.x = det * b2Dot(b, b2Cross(ey, ez)); 34 | x.y = det * b2Dot(ex, b2Cross(b, ez)); 35 | x.z = det * b2Dot(ex, b2Cross(ey, b)); 36 | return x; 37 | } 38 | 39 | /// Solve A * x = b, where b is a column vector. This is more efficient 40 | /// than computing the inverse in one-shot cases. 41 | b2Vec2 b2Mat33::Solve22(const b2Vec2& b) const 42 | { 43 | float32 a11 = ex.x, a12 = ey.x, a21 = ex.y, a22 = ey.y; 44 | float32 det = a11 * a22 - a12 * a21; 45 | if (det != 0.0f) 46 | { 47 | det = 1.0f / det; 48 | } 49 | b2Vec2 x; 50 | x.x = det * (a22 * b.x - a12 * b.y); 51 | x.y = det * (a11 * b.y - a21 * b.x); 52 | return x; 53 | } 54 | 55 | /// 56 | void b2Mat33::GetInverse22(b2Mat33* M) const 57 | { 58 | float32 a = ex.x, b = ey.x, c = ex.y, d = ey.y; 59 | float32 det = a * d - b * c; 60 | if (det != 0.0f) 61 | { 62 | det = 1.0f / det; 63 | } 64 | 65 | M->ex.x = det * d; M->ey.x = -det * b; M->ex.z = 0.0f; 66 | M->ex.y = -det * c; M->ey.y = det * a; M->ey.z = 0.0f; 67 | M->ez.x = 0.0f; M->ez.y = 0.0f; M->ez.z = 0.0f; 68 | } 69 | 70 | /// Returns the zero matrix if singular. 71 | void b2Mat33::GetSymInverse33(b2Mat33* M) const 72 | { 73 | float32 det = b2Dot(ex, b2Cross(ey, ez)); 74 | if (det != 0.0f) 75 | { 76 | det = 1.0f / det; 77 | } 78 | 79 | float32 a11 = ex.x, a12 = ey.x, a13 = ez.x; 80 | float32 a22 = ey.y, a23 = ez.y; 81 | float32 a33 = ez.z; 82 | 83 | M->ex.x = det * (a22 * a33 - a23 * a23); 84 | M->ex.y = det * (a13 * a23 - a12 * a33); 85 | M->ex.z = det * (a12 * a23 - a13 * a22); 86 | 87 | M->ey.x = M->ex.y; 88 | M->ey.y = det * (a11 * a33 - a13 * a13); 89 | M->ey.z = det * (a13 * a12 - a11 * a23); 90 | 91 | M->ez.x = M->ex.z; 92 | M->ez.y = M->ey.z; 93 | M->ez.z = det * (a11 * a22 - a12 * a12); 94 | } 95 | -------------------------------------------------------------------------------- /Box2D/Common/b2Draw.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Erin Catto http://box2d.org 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked as such, and must not be 15 | * misrepresented as being the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | #ifndef B2_DRAW_H 20 | #define B2_DRAW_H 21 | 22 | #include 23 | 24 | /// Color for debug drawing. Each value has the range [0,1]. 25 | struct b2Color 26 | { 27 | b2Color() {} 28 | b2Color(float32 r, float32 g, float32 b) : r(r), g(g), b(b) {} 29 | void Set(float32 ri, float32 gi, float32 bi) { r = ri; g = gi; b = bi; } 30 | float32 r, g, b; 31 | }; 32 | 33 | /// Implement and register this class with a b2World to provide debug drawing of physics 34 | /// entities in your game. 35 | class b2Draw 36 | { 37 | public: 38 | b2Draw(); 39 | 40 | virtual ~b2Draw() {} 41 | 42 | enum 43 | { 44 | e_shapeBit = 0x0001, ///< draw shapes 45 | e_jointBit = 0x0002, ///< draw joint connections 46 | e_aabbBit = 0x0004, ///< draw axis aligned bounding boxes 47 | e_pairBit = 0x0008, ///< draw broad-phase pairs 48 | e_centerOfMassBit = 0x0010 ///< draw center of mass frame 49 | }; 50 | 51 | /// Set the drawing flags. 52 | void SetFlags(uint32 flags); 53 | 54 | /// Get the drawing flags. 55 | uint32 GetFlags() const; 56 | 57 | /// Append flags to the current flags. 58 | void AppendFlags(uint32 flags); 59 | 60 | /// Clear flags from the current flags. 61 | void ClearFlags(uint32 flags); 62 | 63 | /// Draw a closed polygon provided in CCW order. 64 | virtual void DrawPolygon(const b2Vec2* vertices, int32 vertexCount, const b2Color& color) = 0; 65 | 66 | /// Draw a solid closed polygon provided in CCW order. 67 | virtual void DrawSolidPolygon(const b2Vec2* vertices, int32 vertexCount, const b2Color& color) = 0; 68 | 69 | /// Draw a circle. 70 | virtual void DrawCircle(const b2Vec2& center, float32 radius, const b2Color& color) = 0; 71 | 72 | /// Draw a solid circle. 73 | virtual void DrawSolidCircle(const b2Vec2& center, float32 radius, const b2Vec2& axis, const b2Color& color) = 0; 74 | 75 | /// Draw a line segment. 76 | virtual void DrawSegment(const b2Vec2& p1, const b2Vec2& p2, const b2Color& color) = 0; 77 | 78 | /// Draw a transform. Choose your own length scale. 79 | /// @param xf a transform. 80 | virtual void DrawTransform(const b2Transform& xf) = 0; 81 | 82 | protected: 83 | uint32 m_drawFlags; 84 | }; 85 | 86 | #endif 87 | -------------------------------------------------------------------------------- /examples/convex_hull.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # 4 | # C++ version Copyright (c) 2006-2007 Erin Catto http://www.box2d.org 5 | # Python version by Ken Lauer / sirkne at gmail dot com 6 | # 7 | # This software is provided 'as-is', without any express or implied 8 | # warranty. In no event will the authors be held liable for any damages 9 | # arising from the use of this software. 10 | # Permission is granted to anyone to use this software for any purpose, 11 | # including commercial applications, and to alter it and redistribute it 12 | # freely, subject to the following restrictions: 13 | # 1. The origin of this software must not be misrepresented; you must not 14 | # claim that you wrote the original software. If you use this software 15 | # in a product, an acknowledgment in the product documentation would be 16 | # appreciated but is not required. 17 | # 2. Altered source versions must be plainly marked as such, and must not be 18 | # misrepresented as being the original software. 19 | # 3. This notice may not be removed or altered from any source distribution. 20 | 21 | from .framework import (Framework, Keys, main) 22 | from Box2D import (b2Clamp, b2Color, b2PolygonShape, b2Random, 23 | b2_maxPolygonVertices) 24 | 25 | 26 | class ConvexHull (Framework): 27 | name = "ConvexHull" 28 | description = ('Press g to generate a new random convex hull, a to switch ' 29 | 'to automatic mode') 30 | 31 | def __init__(self): 32 | Framework.__init__(self) 33 | 34 | self.auto = False 35 | 36 | self.generate() 37 | 38 | def generate(self): 39 | lower = (-8, -8) 40 | upper = (8, 8) 41 | 42 | self.verts = verts = [] 43 | for i in range(b2_maxPolygonVertices): 44 | x = 10.0 * b2Random(0.0, 10.0) 45 | y = 10.0 * b2Random(0.0, 10.0) 46 | 47 | # Clamp onto a square to help create collinearities. 48 | # This will stress the convex hull algorithm. 49 | verts.append(b2Clamp((x, y), lower, upper)) 50 | 51 | def Keyboard(self, key): 52 | if key == Keys.K_a: 53 | self.auto = not self.auto 54 | elif key == Keys.K_g: 55 | self.generate() 56 | 57 | def Step(self, settings): 58 | Framework.Step(self, settings) 59 | 60 | renderer = self.renderer 61 | 62 | try: 63 | poly = b2PolygonShape(vertices=self.verts) 64 | except AssertionError as ex: 65 | self.Print('b2PolygonShape failed: %s' % ex) 66 | else: 67 | self.Print('Valid: %s' % poly.valid) 68 | 69 | renderer.DrawPolygon([renderer.to_screen(v) 70 | for v in self.verts], b2Color(0.9, 0.9, 0.9)) 71 | for i, v in enumerate(self.verts): 72 | renderer.DrawPoint(renderer.to_screen(v), 2.0, 73 | b2Color(0.9, 0.5, 0.5)) 74 | 75 | x, y = renderer.to_screen(v) 76 | self.DrawStringAt(x + 0.05, y + 0.05, '%d' % i) 77 | 78 | if self.auto: 79 | self.generate() 80 | 81 | if __name__ == "__main__": 82 | main(ConvexHull) 83 | -------------------------------------------------------------------------------- /examples/tiles.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # 4 | # C++ version Copyright (c) 2006-2007 Erin Catto http://www.box2d.org 5 | # Python version Copyright (c) 2010 kne / sirkne at gmail dot com 6 | # 7 | # This software is provided 'as-is', without any express or implied 8 | # warranty. In no event will the authors be held liable for any damages 9 | # arising from the use of this software. 10 | # Permission is granted to anyone to use this software for any purpose, 11 | # including commercial applications, and to alter it and redistribute it 12 | # freely, subject to the following restrictions: 13 | # 1. The origin of this software must not be misrepresented; you must not 14 | # claim that you wrote the original software. If you use this software 15 | # in a product, an acknowledgment in the product documentation would be 16 | # appreciated but is not required. 17 | # 2. Altered source versions must be plainly marked as such, and must not be 18 | # misrepresented as being the original software. 19 | # 3. This notice may not be removed or altered from any source distribution. 20 | 21 | from math import ceil, log 22 | 23 | from .framework import (Framework, main) 24 | from Box2D import (b2FixtureDef, b2PolygonShape, b2Vec2) 25 | 26 | 27 | class Tiles (Framework): 28 | name = "Tiles" 29 | description = ('This stress tests the dynamic tree broad-phase. This also' 30 | 'shows that tile based collision\nis _not_ smooth due to ' 31 | 'Box2D not knowing about adjacency.') 32 | 33 | def __init__(self): 34 | super(Tiles, self).__init__() 35 | 36 | a = 0.5 37 | 38 | def ground_positions(): 39 | N = 200 40 | M = 10 41 | position = b2Vec2(0, 0) 42 | for i in range(M): 43 | position.x = -N * a 44 | for j in range(N): 45 | yield position 46 | position.x += 2.0 * a 47 | position.y -= 2.0 * a 48 | 49 | ground = self.world.CreateStaticBody( 50 | position=(0, -a), 51 | shapes=[b2PolygonShape(box=(a, a, position, 0)) 52 | for position in ground_positions()] 53 | ) 54 | 55 | count = 20 56 | 57 | def dynamic_positions(): 58 | x = b2Vec2(-7.0, 0.75) 59 | deltaX = (0.5625, 1.25) 60 | deltaY = (1.125, 0.0) 61 | for i in range(count): 62 | y = x.copy() 63 | for j in range(i, count): 64 | yield y 65 | y += deltaY 66 | x += deltaX 67 | 68 | for pos in dynamic_positions(): 69 | self.world.CreateDynamicBody( 70 | position=pos, 71 | fixtures=b2FixtureDef( 72 | shape=b2PolygonShape(box=(a, a)), density=5) 73 | ) 74 | 75 | def Step(self, settings): 76 | super(Tiles, self).Step(settings) 77 | cm = self.world.contactManager 78 | height = cm.broadPhase.treeHeight 79 | leafCount = cm.broadPhase.proxyCount 80 | minNodeCount = 2 * leafCount - 1 81 | minHeight = ceil(log(float(minNodeCount)) / log(2)) 82 | self.Print('Dynamic tree height=%d, min=%d' % (height, minHeight)) 83 | 84 | if __name__ == "__main__": 85 | main(Tiles) 86 | -------------------------------------------------------------------------------- /examples/one_sided_platform.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # 4 | # C++ version Copyright (c) 2006-2007 Erin Catto http://www.box2d.org 5 | # Python version by Ken Lauer / sirkne at gmail dot com 6 | # 7 | # This software is provided 'as-is', without any express or implied 8 | # warranty. In no event will the authors be held liable for any damages 9 | # arising from the use of this software. 10 | # Permission is granted to anyone to use this software for any purpose, 11 | # including commercial applications, and to alter it and redistribute it 12 | # freely, subject to the following restrictions: 13 | # 1. The origin of this software must not be misrepresented; you must not 14 | # claim that you wrote the original software. If you use this software 15 | # in a product, an acknowledgment in the product documentation would be 16 | # appreciated but is not required. 17 | # 2. Altered source versions must be plainly marked as such, and must not be 18 | # misrepresented as being the original software. 19 | # 3. This notice may not be removed or altered from any source distribution. 20 | 21 | from .framework import (Framework, main) 22 | from Box2D import (b2CircleShape, b2EdgeShape, b2FixtureDef, b2PolygonShape, 23 | b2_linearSlop) 24 | 25 | 26 | class OneSidedPlatform (Framework): 27 | name = "One-sided Platform" 28 | description = ("Try to move the shape with the mouse through the platform " 29 | "from all directions") 30 | 31 | def __init__(self): 32 | super(OneSidedPlatform, self).__init__() 33 | 34 | # The ground 35 | ground = self.world.CreateBody( 36 | shapes=b2EdgeShape(vertices=[(-20, 0), (20, 0)]) 37 | ) 38 | 39 | # The platform 40 | half_height = 0.5 41 | ypos = 10 42 | body = self.world.CreateBody( 43 | position=(0, ypos), 44 | shapes=b2PolygonShape(box=(3, half_height)) 45 | ) 46 | self.platform = body.fixtures[0] 47 | 48 | # The circular character 49 | self.character_radius = 0.5 50 | body = self.world.CreateDynamicBody( 51 | position=(0, 12), 52 | fixtures=b2FixtureDef(shape=b2CircleShape( 53 | radius=self.character_radius), density=1.0), 54 | ) 55 | 56 | self.character = body.fixtures[0] 57 | body.linearVelocity = (0, -50) 58 | 59 | self.bottom = ypos - half_height # The bottom of the platform 60 | self.top = ypos + half_height # The top of the platform 61 | self.state = 'unknown' 62 | 63 | def PreSolve(self, contact, oldManifold): 64 | super(OneSidedPlatform, self).PreSolve(contact, oldManifold) 65 | 66 | # Make sure we're dealing with the platform and the character 67 | if (contact.fixtureA != self.platform and 68 | contact.fixtureA != self.character): 69 | return 70 | if (contact.fixtureB != self.platform and 71 | contact.fixtureB != self.character): 72 | return 73 | 74 | # If below the top of the platform, disable the collision response 75 | pos = (self.character.body.position.y - self.character_radius + 76 | 3.0 * b2_linearSlop) 77 | if pos < self.top: 78 | contact.enabled = False 79 | 80 | if __name__ == "__main__": 81 | main(OneSidedPlatform) 82 | -------------------------------------------------------------------------------- /examples/vertical_stack.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # 4 | # C++ version Copyright (c) 2006-2007 Erin Catto http://www.box2d.org 5 | # Python version by Ken Lauer / sirkne at gmail dot com 6 | # 7 | # This software is provided 'as-is', without any express or implied 8 | # warranty. In no event will the authors be held liable for any damages 9 | # arising from the use of this software. 10 | # Permission is granted to anyone to use this software for any purpose, 11 | # including commercial applications, and to alter it and redistribute it 12 | # freely, subject to the following restrictions: 13 | # 1. The origin of this software must not be misrepresented; you must not 14 | # claim that you wrote the original software. If you use this software 15 | # in a product, an acknowledgment in the product documentation would be 16 | # appreciated but is not required. 17 | # 2. Altered source versions must be plainly marked as such, and must not be 18 | # misrepresented as being the original software. 19 | # 3. This notice may not be removed or altered from any source distribution. 20 | 21 | from .framework import (Framework, Keys, main) 22 | from Box2D import (b2CircleShape, b2EdgeShape, b2FixtureDef, b2PolygonShape) 23 | 24 | 25 | class VerticalStack (Framework): 26 | name = "Vertical Stack" 27 | description = ("Tests the stability of stacking circles and boxes\n" 28 | "Press B to launch a horizontal bullet") 29 | bullet = None 30 | 31 | def __init__(self): 32 | super(VerticalStack, self).__init__() 33 | 34 | columns = 5 35 | rows = 16 36 | 37 | ground = self.world.CreateStaticBody( 38 | shapes=[ 39 | b2EdgeShape(vertices=[(-40, 0), (40, 0)]), 40 | b2EdgeShape(vertices=[(20, 0), (20, 20)]), 41 | ] 42 | ) 43 | 44 | box = b2FixtureDef( 45 | shape=b2PolygonShape(box=(0.5, 0.5)), 46 | density=1, 47 | friction=0.3) 48 | circle = b2FixtureDef( 49 | shape=b2CircleShape(radius=0.5), 50 | density=1, 51 | friction=0.3) 52 | 53 | box_start = -10 54 | box_space = 2.5 55 | circle_start = 8 56 | circle_space = 2.5 57 | for j in range(columns): 58 | for i in range(rows): 59 | self.world.CreateDynamicBody( 60 | fixtures=box, 61 | position=(box_start + box_space * j, 0.752 + 1.54 * i) 62 | ) 63 | self.world.CreateDynamicBody( 64 | fixtures=circle, 65 | position=(circle_start + circle_space * 66 | j, 0.752 + 1.54 * i) 67 | ) 68 | 69 | def Step(self, settings): 70 | super(VerticalStack, self).Step(settings) 71 | 72 | def Keyboard(self, key): 73 | if key == Keys.K_b: 74 | if self.bullet: 75 | self.world.DestroyBody(self.bullet) 76 | self.bullet = None 77 | circle = b2FixtureDef( 78 | shape=b2CircleShape(radius=0.25), 79 | density=20, 80 | restitution=0.05) 81 | self.bullet = self.world.CreateDynamicBody( 82 | position=(-31, 5), 83 | bullet=True, 84 | fixtures=circle, 85 | linearVelocity=(400, 0), 86 | ) 87 | 88 | if __name__ == "__main__": 89 | main(VerticalStack) 90 | -------------------------------------------------------------------------------- /tests/test_body.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | import unittest 4 | from Box2D import * 5 | import Box2D 6 | 7 | class cl (b2ContactListener): 8 | pass 9 | 10 | class test_body (unittest.TestCase): 11 | def setUp(self): 12 | pass 13 | 14 | def test_world(self): 15 | world = b2World(gravity=(0,-10), doSleep=True) 16 | world = b2World((0,-10), True) 17 | world = b2World((0,-10), doSleep=True) 18 | 19 | def test_extended(self): 20 | world = b2World() 21 | fixture1=b2FixtureDef(shape=b2CircleShape(radius=1), density=1, friction=0.3) 22 | fixture2=b2FixtureDef(shape=b2CircleShape(radius=2), density=1, friction=0.3) 23 | shape1=b2PolygonShape(box=(5,1)) 24 | shape2=b2PolygonShape(box=(5,1)) 25 | shapefixture=b2FixtureDef(density=2.0, friction=0.3) 26 | 27 | world.CreateStaticBody(fixtures=[fixture1, fixture2], 28 | shapes=[shape1, shape2], shapeFixture=shapefixture) 29 | 30 | # make sure that 4 bodies were created 31 | self.assertEqual(len(world.bodies[-1].fixtures), 4) 32 | 33 | world.CreateKinematicBody(fixtures=[fixture1, fixture2], 34 | shapes=[shape1, shape2], shapeFixture=shapefixture) 35 | self.assertEqual(len(world.bodies[-1].fixtures), 4) 36 | world.CreateDynamicBody(fixtures=[fixture1, fixture2], 37 | shapes=[shape1, shape2], shapeFixture=shapefixture) 38 | self.assertEqual(len(world.bodies[-1].fixtures), 4) 39 | 40 | def test_body(self): 41 | self.cont_list=cl() 42 | world = b2World(gravity=(0,-10), doSleep=True, contactListener=self.cont_list) 43 | groundBody = world.CreateBody(b2BodyDef(position=(0,-10))) 44 | 45 | groundBody.CreateFixturesFromShapes(shapes=b2PolygonShape(box=(50,10))) 46 | 47 | body = world.CreateBody(b2BodyDef(type=b2_dynamicBody, position=(0,4))) 48 | 49 | body.CreateFixture(b2FixtureDef(shape=b2CircleShape(radius=1), density=1, friction=0.3)) 50 | 51 | timeStep = 1.0 / 60 52 | vel_iters, pos_iters = 6, 2 53 | 54 | for i in range(60): 55 | world.Step(timeStep, vel_iters, pos_iters) 56 | world.ClearForces() 57 | 58 | def test_new_createfixture(self): 59 | world = b2World(gravity=(0,-10), doSleep=True) 60 | body=world.CreateDynamicBody(position=(0,0)) 61 | body.CreateCircleFixture(radius=0.2, friction=0.2, density=1.0) 62 | body.fixtures[0] 63 | body.fixtures[0].friction 64 | body.fixtures[0].density 65 | body.fixtures[0].shape.radius 66 | 67 | body.CreatePolygonFixture(box=(1,1), friction=0.2, density=1.0) 68 | body.fixtures[1] 69 | body.fixtures[1].friction 70 | body.fixtures[1].density 71 | body.fixtures[1].shape.vertices 72 | 73 | v1=(-10, 0) 74 | v2=(-7, -1) 75 | v3=(-4, 0) 76 | v4=(0, 0) 77 | body.CreateEdgeFixture(vertices=[v1,v2,v3,v4], friction=0.3, density=1.0) 78 | body.fixtures[2] 79 | body.fixtures[2].friction 80 | body.fixtures[2].density 81 | body.fixtures[2].shape.vertices 82 | 83 | #TODO Loop shapes 84 | 85 | def test_fixture_without_shape(self): 86 | world = b2World(gravity=(0,-10), doSleep=True) 87 | body = world.CreateDynamicBody(position=(0,0)) 88 | 89 | self.assertRaises(ValueError, body.CreateFixture) 90 | 91 | 92 | if __name__ == '__main__': 93 | unittest.main() 94 | 95 | -------------------------------------------------------------------------------- /examples/simple/simple_02.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | """ 4 | An attempt at some simple, self-contained pygame-based examples. 5 | Example 02 6 | 7 | In short: 8 | One static body: 9 | + One fixture: big polygon to represent the ground 10 | Two dynamic bodies: 11 | + One fixture: a polygon 12 | + One fixture: a circle 13 | And some drawing code that extends the shape classes. 14 | 15 | kne 16 | """ 17 | import pygame 18 | from pygame.locals import (QUIT, KEYDOWN, K_ESCAPE) 19 | 20 | import Box2D # The main library 21 | # Box2D.b2 maps Box2D.b2Vec2 to vec2 (and so on) 22 | from Box2D.b2 import (world, polygonShape, circleShape, staticBody, dynamicBody) 23 | 24 | # --- constants --- 25 | # Box2D deals with meters, but we want to display pixels, 26 | # so define a conversion factor: 27 | PPM = 20.0 # pixels per meter 28 | TARGET_FPS = 60 29 | TIME_STEP = 1.0 / TARGET_FPS 30 | SCREEN_WIDTH, SCREEN_HEIGHT = 640, 480 31 | 32 | # --- pygame setup --- 33 | screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT), 0, 32) 34 | pygame.display.set_caption('Simple pygame example') 35 | clock = pygame.time.Clock() 36 | 37 | # --- pybox2d world setup --- 38 | # Create the world 39 | world = world(gravity=(0, -10), doSleep=True) 40 | 41 | # And a static body to hold the ground shape 42 | ground_body = world.CreateStaticBody( 43 | position=(0, 0), 44 | shapes=polygonShape(box=(50, 1)), 45 | ) 46 | 47 | # Create a couple dynamic bodies 48 | body = world.CreateDynamicBody(position=(20, 45)) 49 | circle = body.CreateCircleFixture(radius=0.5, density=1, friction=0.3) 50 | 51 | body = world.CreateDynamicBody(position=(30, 45), angle=15) 52 | box = body.CreatePolygonFixture(box=(2, 1), density=1, friction=0.3) 53 | 54 | colors = { 55 | staticBody: (255, 255, 255, 255), 56 | dynamicBody: (127, 127, 127, 255), 57 | } 58 | 59 | # Let's play with extending the shape classes to draw for us. 60 | 61 | 62 | def my_draw_polygon(polygon, body, fixture): 63 | vertices = [(body.transform * v) * PPM for v in polygon.vertices] 64 | vertices = [(v[0], SCREEN_HEIGHT - v[1]) for v in vertices] 65 | pygame.draw.polygon(screen, colors[body.type], vertices) 66 | polygonShape.draw = my_draw_polygon 67 | 68 | 69 | def my_draw_circle(circle, body, fixture): 70 | position = body.transform * circle.pos * PPM 71 | position = (position[0], SCREEN_HEIGHT - position[1]) 72 | pygame.draw.circle(screen, colors[body.type], [int( 73 | x) for x in position], int(circle.radius * PPM)) 74 | # Note: Python 3.x will enforce that pygame get the integers it requests, 75 | # and it will not convert from float. 76 | circleShape.draw = my_draw_circle 77 | 78 | # --- main game loop --- 79 | 80 | running = True 81 | while running: 82 | # Check the event queue 83 | for event in pygame.event.get(): 84 | if event.type == QUIT or (event.type == KEYDOWN and event.key == K_ESCAPE): 85 | # The user closed the window or pressed escape 86 | running = False 87 | 88 | screen.fill((0, 0, 0, 0)) 89 | # Draw the world 90 | for body in world.bodies: 91 | for fixture in body.fixtures: 92 | fixture.shape.draw(body, fixture) 93 | 94 | # Make Box2D simulate the physics of our world for one step. 95 | world.Step(TIME_STEP, 10, 10) 96 | 97 | # Flip the screen and try to keep at the target FPS 98 | pygame.display.flip() 99 | clock.tick(TARGET_FPS) 100 | 101 | pygame.quit() 102 | print('Done!') 103 | --------------------------------------------------------------------------------