Ejemplo n.º 1
0
 public void Init()
 {
     SetupGrids();
     m_System           = new PhysicsSystem();
     m_System.particles = m_Particles;
     m_System.springs   = m_Springs;
 }
Ejemplo n.º 2
0
        public void Integrate(PhysicsSystem physicsSystem)
        {
            Particle particle = null;

            for (int i = 0, l = physicsSystem.particles.Count; i < l; ++i)
            {
                particle = physicsSystem.particles[i];
                float deltaTimeMass = m_StepInterval / particle.mass;
                particle.velocity = particle.velocity + particle.resultantForce * deltaTimeMass;
                //原算法使用旧的速度。但实际测试会出问题。改为当前速度。
                particle.position = particle.position + particle.velocity * m_StepInterval;
            }
        }
Ejemplo n.º 3
0
        public void Integrate(PhysicsSystem physicsSystem)
        {
            Vector3  lastPosition;
            Particle particle = null;

            for (int i = 0, l = physicsSystem.particles.Count; i < l; ++i)
            {
                particle     = physicsSystem.particles[i];
                lastPosition = particle.position;
                float doubleDeltaMass = m_DoubleStepInterval / particle.mass;
                particle.position = particle.position * 2 - particle.previousPosition + doubleDeltaMass * particle.resultantForce;
                if (particle.position.y < 0)
                {
                    var p = particle.position;
                    p.y = 0;
                    particle.position = p;
                }
                particle.previousPosition = lastPosition;
                particle.velocity         = (particle.position - particle.previousPosition) / m_StepInterval;
            }
        }