Ejemplo n.º 1
0
        public void CheckCollision(int index)
        {
            if (m_particleSystem.IsKinematic(index))
            {
                return;
            }

            float px, py, pz;

            m_particleSystem.GetPosition(index, out px, out py, out pz);

            float dx = px - x;
            float dy = py - y;
            float dz = pz - z;

            float dot = m_nX * dx + m_nY * dy + m_nZ * dz;

            if (dot <= 0)
            {
                float fx = dot * m_nX;
                float fy = dot * m_nY;
                float fz = dot * m_nZ;

                px = px - fx;
                py = py - fy;
                pz = pz - fz;
                m_particleSystem.SetPosition(index, px, py, pz, false);
                m_particleSystem.SetForce(index, 0, 0, 0);
            }
        }
Ejemplo n.º 2
0
        public void CheckCollision(int index)
        {
            if (m_particleSystem.IsKinematic(index))
            {
                return;
            }

            float px, py, pz;

            m_particleSystem.GetPosition(index, out px, out py, out pz);

            float dx = px - x;
            float dy = py - y;
            float dz = pz - z;

            float distSqrt = dx * dx + dy * dy + dz * dz;

            if (distSqrt <= m_radiusSqrt)
            {
                float penetration = (m_radiusSqrt / distSqrt) * (m_radiusSqrt - distSqrt) / m_radiusSqrt;

                dx *= penetration;
                dy *= penetration;
                dz *= penetration;
                m_particleSystem.SetPosition(index, px + dx, py + dy, pz + dz, false);
                m_particleSystem.SetForce(index, 0, 0, 0);
            }
        }