我正在开发一个计算着色器,它允许流体粒子引擎(NVidia Flex)和刚体物理引擎(Unity3D Engine)之间的双向物理交互。
基本上对于计算着色器,我使用 5 个输入缓冲区:
(float4)粒子速度/形状接触指数
(float4)形状质心
(int)形状标志 - 动态与静态等
(int)粒子指数
(float4)粒子位置和质量
和 2 个输出缓冲区:
(float3) 速度增量
(float3) 旋转速度增量
我正在寻找的功能是最小的,不需要准确,它只需要有点可信,因为我主要只是将它用于视觉效果。我知道我可以使用 NVidia flex 粒子创建刚体约束并使用它,但在我的情况下,这不切实际,因为我的流体模拟使用非常小的粒子,而中等大小的rigiddodies 将使用 NVidia 刚性约束的粒子比文档多得多建议每个身体说。
所以无论如何,我已经到了这样的程度,在我的着色器中,我需要一个物理公式来获取世界空间中力的原点、力矢量、世界空间中形状的质心,我需要它给我形状的净增量速度(假设密度均匀)和形状的净旋转速度。对于每个形状与粒子之间的每次接触,此功能将多次应用于每个形状。
这是一些伪代码:
// The velocity of the particle at the time of contact
float4 contactVelocity;
// The index of the shape that the particle collided with
int shapeIndex;
// The particle's position in the world (which should be the same as the contact point)
float3 pos;
// The mass of the particle
float mass;
// The shape's center of mass
float3 shapeOrigin;
// TODO: define ApplyVelForce & ApplyRotForce
velDelta[shapeIndex] = velDelta[shapeIndex] + GetVelForce(shapeOrigin, contactVelocity * mass, pos);
rotVelDelta[shapeIndex] = rotVelDelta[shapeIndex] + GetRotForce(shapeOrigin, contactVelocity * mass, pos);
// function definitions
float3 GetVelForce(float3 shapeCentroid, float3 force, float3 forcePoint){ /* TODO define */ }
float3 GetRotForce(float3 shapeCentroid, float3 force, float3 forcePoint){ /* TODO define */ }
如果有人知道一个相对简单的公式来合理有效地计算甚至近似这些速度和旋转力,请告诉我。我搜索了谷歌,但所有关于此的文章似乎都超出了我的想象。我只是认为我没有足够的运动学经验和知识,还无法自己弄清楚这些公式。