衝突判定
A triangle mesh object is commonly used in 3D body modeling. Normally the collision function is a triangle to triangle intercept or a bounding shape associated with the mesh. A triangle centroid is a center of mass location such that it would balance on a pencil tip. The simulation need only add a centroid dimension to the physics parameters. Given centroid points in both object and target it is possible to define the line segment connecting these two points.
The position vector of the centroid of a triangle is the average of the position vectors of its vertices.
Physical simulators differ in the way they react on a collision. Some use the softness of the material to calculate a force, which will resolve the collision in the following time steps like it is in reality. Due to the low softness of some materials this is very CPU intensive. Some simulators estimate the time of collision by linear interpolation, roll back the simulation, and calculate the collision by the more abstract methods of conservation laws.
Some iterate the linear interpolation (Newton's method) to calculate the time of collision with a much higher precision than the rest of the simulation. Collision detection utilizes time coherence to allow even finer time steps without much increasing CPU demand, such as in air traffic control.
In the a posteriori case, we advance the physical simulation by a small time step, then check if any objects are intersecting, or are somehow so close to each other that we deem them to be intersecting. At each simulation step, a list of all intersecting bodies is created, and the positions and trajectories of these objects are somehow "fixed" to account for the collision. We say that this method is a posteriori because we typically miss the actual instant of collision, and only catch the collision after it has actually happened.
In the a priori methods, we write a collision detection algorithm which will be able to predict very precisely the trajectories of the physical bodies.
3D空間においては、衝突判定を取りたい双方のオブジェクトを「直方体」とみなし、幅・高さ・奥行き(lx, ly, lz) で表す以外は上と同じである。
ヒットボックス方式の主な実装方法は、上で述べた他に、境界球方式、AABB方式、OBB方式、凸包方式、などがある。後者に行くにしたがって精密な衝突判定が行えるが、計算コストが大きくなり、特に凸包方式はゲームではまず使われない。2010年代以降には凸包同士の衝突計算をGJKアルゴリズムを用いてGPUでリアルタイムで実行するための研究が進んでおり、今後のゲームエンジンに実装される可能性もある(すでに実装されている可能性もある)が、複雑なオブジェクト同士の衝突判定を行う伝統的な方法としては、複数のヒットボックスを組み合わせて近似する方式が使われる。