Пример #1
0
        public static CollisionPlane From3Points(MyVector p1, MyVector p2, MyVector p3)
        {
            MyVector normal = (p2 - p1) ^ (p3 - p1).Normalize();
            CollisionPlane plane = new CollisionPlane(normal, -normal * p1);

            return plane;
        }
Пример #2
0
 public bool IntersectPlane(out MyVector intersectionPoint, out MyVector intersectionNormal, out float collisionTime, MyVector startPoint,
     MyVector endPoint, float dt, CollisionPlane plane)
 {
     intersectionPoint = new MyVector();
     intersectionNormal = new MyVector();
     collisionTime = 0;
     return false;
 }
Пример #3
0
 public static CollisionPlane FromNormal(MyVector p, MyVector normal)
 {
     CollisionPlane plane = new CollisionPlane(normal, -normal * p);
     return plane;
 }
Пример #4
0
 public object Clone()
 {
     CollisionPlane p = new CollisionPlane(this.Normal, this.D);
     return p;
 }
Пример #5
0
        public bool IntersectPlane(out MyVector intersectionPoint, out MyVector intersectionNormal, out float collisionTime, MyVector startPoint, MyVector endPoint, float dt, CollisionPlane plane)
        {
            intersectionPoint = new MyVector();
            intersectionNormal = -plane.Normal;
            MyVector rVelocity = (endPoint - startPoint) / dt;
            MyVector pVel = (rVelocity * plane.Normal) * plane.Normal;
            MyVector translate = (endPoint - startPoint);
            collisionTime = 0;

            float speed;
            float nPoints = 0;

            for (int i = 0; i < m_hardPoints.Length; i++)
            {
                if ((m_hardPoints[i] - endPoint) * pVel > 0)
                {
                    //the line doesn't cross the triangle
                    continue;
                }
                speed = pVel * (m_hardPoints[i] - startPoint);
                if (speed < -0.04)
                    continue;

                if (nPoints > 0 && speed > collisionTime)
                    continue;
                if (nPoints == 0)
                {
                    nPoints = 1;
                    intersectionPoint = m_hardPoints[i];
                    collisionTime = speed;
                }
                else if (speed < collisionTime)
                {
                    nPoints = 1;
                    intersectionPoint = m_hardPoints[i];
                    collisionTime = speed;
                }
                else if (speed == collisionTime && nPoints > 0)
                {
                    nPoints++;
                    intersectionPoint.Add(m_hardPoints[i]);
                }

            }
            if (nPoints > 1)
            {
                intersectionPoint.Divide(nPoints);
            }
            return (nPoints > 0);
        }