Lame note 28-cocos2d-x-3.2 box2d physical engine collision module Introduction

Source: Internet
Author: User

Previous review

This famous saying goes:Never measure the height of a mountain-Unless you have reached the peak, you will know how low the mountains are.[Hamadho]

In the previous article, we learned the common module of one of the three main modules of the box2d physical engine. This module mainly includes settings, memory management, and vector mathematics.

This time, I learned about the collison module.

Introduction

This collision module includes shapes and functions. A Dynamic Tree and broad-phase are included to accelerate the collision system. This module is designed outside of the dynamic system.

Shape

The shapes here describes the collision ry, which can be used independently of physical simulation.

Each shape has a type member and a radius. Radius is even applicable to polygon.

Remember the following two points:

1. When a shape is not attached to the body, its vertex is expressed in the world space.

2. When the shape is attached to the body, its vertices are expressed with local coordinates.

CircleThere is a coordinate and diameter.

PolygonAt least three vertices are required. (These vertices are saved in a counter-clockwise direction. A polygon can have a maximum of eight values, which are determined by the b2_maxpolygonvetices variable .)

We can define a polygon as follows:

B2vec2 vertices [3];

Vertices [0]. Set (0.0f, 0.0f );

Vertices [1]. Set (1.0f, 0.0f );

Vertices [2]. Set (0.0f, 1.0f );

Int32 COUNT = 3;

B2polygonshape polygon;

Polygon. Set (vertices, count );

Edge ShapeIt is actually a line. It can collide with the circle and polygon, but cannot collide with the edge shape.

Chain shapeIt provides a funny method to link edge to build a static game world. Remember not to cross the chain shape.

 

Functions

The function mainly involves collision detection, such as the distance between two shapes and whether the two shapes overlap. Although this is the core of the collison module, I think it is best to continue with our specific example later.

Dynamic Tree

The dynamic tree class is used to efficiently manage a large number of shapes.

Broad-phase

The collision process can be divided into narrow-phase and broad-phase in physical steps.

In the current phase, we remember that if narrow-phase is used, the collision requires a lot of computing, and the use of broad-phase can greatly reduce the call of narrow-phase. We don't need to deal with broad-phase directly. Just take a look.

Summary

This is the learning and record of collision, one of open-source box2d physical engines. It has a small amount of content, so do not throw bricks. OK. The next step is to continue learning the dynamics module.

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.