Configuration of the box2d physics engine under Python

Source: Internet
Author: User

/*******************************

I Come back!

I'm looking for a job because I've been in senior

has led to the second longest period of time since the blog has not been Updated. To apologize to Everyone.

*******************************/

Objective

box2d Physics engine

Box2D is an open source 2d physics engine, There are many versions, c++,java,html5 and python, etc.

The famous angry bird was developed using this physics ENGINE.

There are also many 2d game engines that have built-in support for the box2d physics engine, such as the COCOS2D,HTML5 2D game engine flag

The box2d physics engine simulates a world in which you can set the gravity of the world and then add various objects to the world, and some of their physical properties, such as mass, friction, damping, etc.

After setting the update frequency for the world, box2d will calculate the position and rotation angle of each object after each Update.

Since box2d itself is not responsible for rendering, when we use the box2d physics engine, we actually change the coordinates of the sprites we need to draw in the project into an object in the box2d inner world,

The box2d physics engine calculates the position and the selection angle of the object each time it is updated, and then we get this position and angle and coordinate transformation into the position of the sprite we need to draw and draw it out

This is a game I used to do on the Windows Phone image bird (http://www.dwz.cn/nD94d)

The inside is box2d physics engine, interested can down, play a play.

first, Configure the Environment

Windows7

python2.7

second, the Configuration method

1. Download python version of the box2d physics engine , we can find that there is a setup.py file in it after Decompression.

( Http://code.google.com/p/pybox2d/wiki/BuildingfromSource This explains the configuration under Windows,linux,os x .

But in english, you can read it yourself and try to configure it.

2. Download MinGW and install and add the bin file under its path to the environment variable (here I am C:\MinGW\bin)

(MinGW (minimalist GNU for Windows), also known as mingw32, is the product of porting the GCC compiler and the GNU binutils to the Win32 platform, including a series of header files (win32api), libraries, and Executables. )

3. Download MSYS and install

(msys is a small GNU environment, including basic bash,make, etc.)

4. Download and install SWIG and install it, add its path to the environment variable (i'm here "D:\swigwin-3.0.2\swigwin-3.0.2")

(swig is a development tool that simplifies the scripting language and the C + + Interface.) In short, Swig is a tool to achieve the purpose of scripting language communication by wrapping and compiling C language Programs)

5. Download python2.7 and install it, add its path to the environment variable (i'm here "D:\Python27")

(here's a way to get the environment variable to take effect immediately is to open cmd,

Note that this is what we typed echo%PATH% to show that the result is not the environment variable that we just added,

We enter set path=c, and then close cmd, when it is opened again,

Type echo%PATH% to see that the environment variable you just added is already shown)

6, Open the Python path \lib\distutils\, create a new distutils.cfg file (i am here "D:\Python27\Lib\distutils")

The contents are:

[build]
Compiler=mingw32
[build_ext]
Compiler=mingw32

7, in order to run box2d under the example of test_, we also need to download the installation Pygame

(pygame is a Cross-platform python module designed for video games, including images, sound FUNCTIONS)

After the installation is successful, we open the Python idle and enter

>>>import Pygame

>>>print Pygame.ver

will show the version of Pygame we installed

8, Open Msys under the MSYS.BAT,CD to the previous download box2d path, to reach and setup.py the same path

and then type

setup.py Build

After success, type again

setup.py Install–force

Success will show the following things.

9, at this point pybox2d has been installed, we can open example under the hello.py run to verify

And any example that starts with test_, such as test_car, for further Verification.

Configuration of the box2d physics engine under Python

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.