这个问题有一个大问题和一个小问题。我相信我在研究中的任何一个问题上都是对的,但不是两者兼而有之。
TotalForce
对于我的物理循环,我做的第一件事是对刚体对象施加重力。TotalForce
然后我使用 my和 my来检查碰撞Velocity
。MyTotalForce
会在每个物理循环之后重置(0, 0, 0)
,尽管我会保留我的velocity
.
我熟悉仅使用速度时在移动球体和静态平面之间进行碰撞检查。但是,如果我还有其他的力velocity
,比如重力呢?我将其他力投入TotalForces
(现在我只有重力)。为了弥补这一点,当我确定球体当前没有与平面重叠时,我会
Vector3 forces = (sphereTotalForces + sphereVelocity);
Vector3 forcesDT = forces * fElapsedTime;
float denom = Vec3Dot(&plane->GetNormal(), &forces);
但是,这对于我认为应该是静止接触的方式来说可能是有问题的。我以为静息接触是由
denom * dist == 0.0f
dist
在哪里
float dist = Vec3Dot(&plane->GetNormal(), &spherePosition) - plane->d;
denom * dist > 0.0f
(作为参考,球体正在远离平面移动的明显含义)
然而,这永远不可能是真的。即使似乎有“休息接触”。这是由于我forces
上面的计算总是至少有一个 .y 为 -9.8(我的重力)。当朝向法线为 (0, 1, 0) 的平面移动时,将产生denom
-9.8 的 ay。
我的问题是
1)我是否按照我在前两个代码片段中提到的方式正确计算了静息接触?
如果是这样的话,
2)应该如何使用我的“其他力量”,例如重力?是我的使用TotalForces
不正确吗?
作为参考,我的时间步长是
mAcceleration = mTotalForces / mMass;
mVelocity += mAcceleration * fElapsedTime;
Vector3 translation = (mVelocity * fElapsedTime);
编辑
由于似乎一些建议的更改会改变我的碰撞代码,这就是我如何检测我的碰撞状态
if(fabs(dist) <= sphereRadius)
{ // There already is a collision }
else
{
Vector3 forces = (sphereTotalForces + sphereVelocity);
float denom = Vec3Dot(&plane->GetNormal(), &forces);
// Resting contact
if(dist == 0) { }
// Sphere is moving away from plane
else if(denom * dist > 0.0f) { }
// There will eventually be a collision
else
{
float fIntersectionTime = (sphereRadius - dist) / denom;
float r;
if(dist > 0.0f)
r = sphereRadius;
else
r = -sphereRadius;
Vector3 collisionPosition = spherePosition + fIntersectionTime * sphereVelocity - r * planeNormal;
}
}