Пример #1
0
    bool VectorIntersectPlane(Vector3 v, Vector3 p, CollisionPlane wall)
    {
        //regarder si intersection entre rayon et plane
        float   d = Vector3.Dot(wall.getPlanePoints()[0], wall.getPlaneNormal());
        Vector3 n = wall.getPlaneNormal();

        //resoudre system equation entre droite du vector et plane de la face
        float alpha = (d - Vector3.Dot(n, p)) / Vector3.Dot(n, v);

        //regarder si intersection est dans vecteur
        if (alpha > 1 || alpha <= 0)
        {
            return(false);
        }
        //regarder si intersection est dans polygon
        Vector3 planeIntersection = p + v * alpha;

        planeIntersection = wall.transform.InverseTransformPoint(planeIntersection);
        if (VerifyIfWithinPolygon(wall.getPlanePointsLocal(), planeIntersection))
        {
            Debug.Log("COLLISION at point:" + p);
            CalculateRebound(n);
            return(true);
        }
        return(false);
    }
Пример #2
0
    bool Intersect(CollisionPlane wall)
    {
        float   d        = Vector3.Dot(wall.getPlanePoints()[0], wall.getPlaneNormal());
        Vector3 n        = wall.getPlaneNormal();
        float   distance = Mathf.Abs(Vector3.Dot(n, center) + d);

        if (Mathf.Abs(Vector3.Dot(n, center) + d) <= radius)
        {
            Vector3 intersectPoint = center + distance * n / n.magnitude;
            intersectPoint = wall.transform.InverseTransformPoint(intersectPoint);
            if (VerifyIfWithinPolygon(wall.getPlanePointsLocal(), intersectPoint))
            {
                Debug.Log("COLLISION AT POINT: " + wall.transform.TransformPoint(intersectPoint));
                CalculateRebound(n);
                return(true);
            }
        }
        return(false);
    }