我目前正在研究3D刚体仿真程序。我目前设法让刚体与地板碰撞并使用冲动正确弹跳。然而,我的问题是,一旦它们反弹,它们会不断加速,尽管使用摩擦矢量试图减慢它们。
当你到达地面时,这是代码
Rvector fDirection(m_Bodies[i].Vel.x,0.0,m_Bodies[i].Vel.z);
Rvector relativeVelocities = m_Bodies[i].Vel - floorVelocity;
fDirection.normalize();
Real impulse = -(1+e) * (Rvector::dotProduct(relativeVelocities,floorNormal))
/ (1/m_Bodies[i].mass + floorMass);
Rvector friction = fDirection*mu*gravity.length()*m_Bodies[i].mass;
Rvector collision_forces = Rvector(0,1,0)*impulse;
collision_forces += friction ;
m_Bodies[i].Vel += (collision_forces/m_Bodies[i].mass);
由于
编辑: 这是集成代码。
void RigidBodySimulation::eulerIntegration(float dTime)
{
Rvector newVel;
Rvector newPos;
Rvector zero(0.0, 0.0, 0.0);
Real one_over_mass;
Rvector accel;
for( unsigned int i = 0 ; i < m_Bodies.size(); i++)
{
one_over_mass = 1/m_Bodies[i].mass;
newVel = m_Bodies[i].Vel + m_Bodies[i].force*one_over_mass*dTime;
newPos = m_Bodies[i].Pos + m_Bodies[i].Vel*dTime;
accel = m_Bodies[i].force / m_Bodies[i].mass;
m_Bodies[i].acceleration = accel;
m_Bodies[i].newPos = newPos;
m_Bodies[i].Vel = newVel;
m_Bodies[i].Pos = newPos;
}
}
答案 0 :(得分:0)
摩擦是倒退,不是吗?
Rvector fDirection(m_Bodies[i].Vel.x,0.0,m_Bodies[i].Vel.z);
这是速度的方向。然后将它乘以一些常数,然后将其加到速度(连同脉冲)
collision_forces += friction ;
m_Bodies[i].Vel += (collision_forces/m_Bodies[i].mass);
这样可以提高地板的速度。
还有其他一些奇怪的事情:
你的冲动词有:(1/m_Bodies[i].mass + floorMass)
这是质量加1 /质量。不应该是(1/(m_Bodies[i].mass + floorMass))
然后在积分器中,您可以计算力的加速度,但是从不对它进行积分,您也可以直接对力进行加速。那么acceleration
成员是什么?