"Original" is suitable for the simple 3D collision detection of beginners (for 3D programming beginners)

xiaoxiao2021-03-05  60

In general games, it is related to interaction between object motion. In contrast, the collision detection in the 2D picture is much easier, whether using pixel judgment or using an object area and distance judgment.

But there is a lot of trouble in the 3D game. For the calculation capabilities of the PC, it is almost impossible to detect the penetration of the polygon and the vertex of each object, which is almost unfinicable for the PC. So the collision detection used on the PC game is not possible to use too accurate detection. And for 3D collision detection problems, there is no almost perfect solution. Currently, it can only be taken as needed to pay the operation speed and accuracy.

The collision detection that is commonly used in successful commercial 3D games is the use of BSP trees and packaging boxes. Simply put in the use of a description of a square or a spherical body package to hold 3D object objects (or main part), and then calculate whether the collision occurs according to the "Distance to the Package". Of course, in addition to the spheres and the square, other shapes can also be used for packaging, but compared to the calculation amount and convenience, it is more convenient, so other shaped packages are used only in some special parts. The BSP tree is a data description used to control the sequence and direction. Because there may be many objects in a game scene, most of them belong to a remote location or relatively unrelated state, and an object's collision operation is not necessary to traverse these objects while saving an important time.

It is not this 3D collision detection method today. Because we are this article written by people 3D programming. The purpose is to make everyone simply build their own 3D scenes, without having to consume a lot of energy on collision detection on collision detection, so that the attention is placed on the foundation graphic programming.

If you need to carefully study mature 3D collision issues, please refer to other articles, there are many online items. In this article, I will also attach a connection to some related articles.

===== Fengye ======== "Original" Re: "Original" is suitable for beginners, the simple 3D collision detection of beginners (for 3D programming beginners) === 2005040408460704 === Due to the mathematical foundation involved in the following Please refer to the analysis of geometries, triangle functions, linear algebraes. For the description and control of physical movements, please refer to other information. Only 3D collision problems here are described here.

For controllable 3D dynamic scenarios, not only can accurately and timely draw graphics, but also build a control description world in memory. There is no need to consider the specific graphic drawing in this world, but you have to take into account each object that is about to draw on the screen. Establish a surrounding box for each object (or a positioning coordinate group). Each sports object must have state properties, such as motion directions, speed, current location information. This information is used to detect and process collision problems.

We first assume that we have to do a simple racing program. 4 cars, several removable obstacles, and complete plunger barriers.

First of all, for relatively broad scenes, it should be divided into the area, such as dividing the plunger into 4x4 regions (A00-A44). The entire plunger is made of a plurality of rectangular square. In the joint position of 16 regions, the rectangular rectangular of the pitcherus must be intended to prevent detection vulnerabilities. For the sake of simplicity, we don't consider the multi-line processing problem, we use the way to deal with anarchy. Keep the processing data before the last drawn, and the racing status of the previously used. Now, it is now assumed that the car is in the A23 area, which is about to handle the data of the following detection. Then, according to the speed and direction, the next detected racing position (actually calculated is only 8 top points of the box). According to the envelopment box information of the racing, the car is still in the A23 area. It is now possible to calculate whether the 8 top points of the package and all track guards in the A23 area are penetrated. When a penetration is found, the surface of the penetration penetration is calculated immediately, as well as the normal penetration. According to the needs of collision processing, adjust the status of the previously detected racing (to consider whether to copy out data, re-modify it, prevent this time, still other problems need to be recovered?). For example, we can deflect the direction of the vehicle according to the direction of the collision surface and the normal direction. The speed is appropriately reduced based on the pending line and the normal angle. Vehicle rotation, calculates according to the vehicle's penetration top and speed, angle and other information. Do the expected position again, if it is not penetrated, then save the current state and rendered, continue. However, it is likely to penetrate, at this time, according to the possibility of specific games, it is back to the premise and rest? Or continue to be revised in the data that has just been copied? This will see the possibility of specific needs. It can be determined according to its own research. Note that the prerequisite for the above is that the prior detection of successful rendering has been processed, and does not contain objects to penetrate. (Of course, smoke, lighting, etc., do not consider the impact of the impact, is not in the calculation.)

The above test is still a vulnerability, there is a possibility of dead cycling, (this is to see if your track design and exercise description is reasonable) to avoid death cycles, or it is recommended to design a counter, such as an overview of it 8 times, There is still penetration, then stop detection, call emergency processing functions to solve this problem. (For example, reset the vehicle to the center of the track or other places.)

===== fengye ======== "Original" Re: "Original" is suitable for the simple 3D collision detection of beginners (for 3D programming beginners) === 2005040409180904 === The above method can basically build simple The 3D scene world, although there are still many shortcomings.

Calculating an arbitrary method is not ideal, it is best to divide into multiple threads.

In fact, it is not difficult to see that this method is also simplified according to the enclosure box. According to the specific needs, some changes may also be needed, please think about itself.

There are still some questions in specific use to pay attention, I can't think of it, I will add it again.

Also welcome readers to make opinions exchange.

===== Fengye ======== "Original" Re: "Original" is suitable for the simple 3D collision detection of beginners (for 3D programming beginners) === 200504051202504 ===

Www.gameres.com

There are a lot of articles about physics and collision.

转载请注明原文地址:https://www.9cbs.com/read-36640.html

New Post(0)