Ptm_ratio of box2d

Source: Internet
Author: User

Link: http://blog.csdn.net/zhangxaochen/article/details/8009508

According to the help documentation of box2d:

1.7 units

Box2d works with floating point numbers and tolerances have to be used to make box2d perform well. These tolerances have been tuned to work well
Withmeters-kilogram-second (mks) units. In particle, box2d has been tuned to work well with moving objects between 0.1 and 10 meters.
So this means objects between soup cans and buses in size shocould work well. static objects may be up to 50 meters big without too much trouble.

Being a 2D physics engine, it is tempting to use pixels as your units. unfortunately this will lead to a poor simulation and possibly weird behavior. an object of length 200 pixels wocould be seen by box2d as the size of a 45 story
Building.

Box2d uses the mks: meter-kg-second unit system, because the documentation says his floating point operation is the best in this unit.

In general, we want to map the screen, for example, 480*320, to around 10 meters, so we are used to setting the pixel-meter ratio to 32, that is
# Define ptm_ratio 32 [PTM: pixel to meter], then we map the screen to a small world like 15 m * 10 m.

We can quickly accept this concept. However, yesterday I suddenly had a strange idea:

How does box2d know how big my ptm_ratio is? In other words, no matter whether ptm_ratio is set to 32 or 64, why is the outer border of the groundbox always filled with screens?

It took a long time to understand. In fact, box2d never knows or cares about the size of ptm_ratio. This physical engine is a blind-eyed mathematical expert who has been computing and computing, but he is not responsible for the presentation of graphics. The cocos2d code we wrote calls opengles for plotting.

If we set # define ptm_ratio 32, the screen will be mapped to 15*10 square meters, and displayed -- that is, when the meter is changed to the screen coordinate, generally, 'coordinate * prm_ratio 'is used to zoom in 32 times on the screen.

If # define ptm_ratio 64, although the screen is mapped to a world of 7.5*5 square meters, it seems to be small (the physical world is indeed small), but when we draw, because we said to cocos2d, "zoom in 64 times and draw it out", it seems that the groundbox box is still full of screens...

That's it.

Link: http://blog.csdn.net/zhangxaochen/article/details/8009508

{Over }}

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.