Beispiel #1
0
    protected bool IsOverlapingOnAxis(Vector3[] colliderAVerts, Vector3[] colliderBVerts, Vector3 axis)
    {
        JSegment segmentA = JMeshCollider.GetMeshSegmentOnAxis(colliderAVerts, axis);
        JSegment segmentB = JMeshCollider.GetMeshSegmentOnAxis(colliderBVerts, axis);

        return(JSegment.IsOverlapping(segmentA, segmentB));
    }
Beispiel #2
0
        /// <summary>
        /// Adds the json file to the pipeline
        /// </summary>
        /// <param name="builder"></param>
        /// <param name="jPath">the json path to extract</param>
        /// <returns></returns>
        public static IEnvironmentBuilder WithJson(this IEnvironmentBuilder builder, string jPath)
        {
            //next line wil trigger an exception on malformed syntax
            var expr = JSegment.Parse(jPath).ToList();

            return(builder.WithSource(cfg =>
            {
                if (!cfg.HasValue(typeof(JsonFileParser).FullName))
                {
                    return null;//no json file parser was registered
                }
                var reqType = cfg.GetBuildType();
                var parser = cfg.GetValue <JsonFileParser>(typeof(JsonFileParser).FullName);
                return parser.Value(expr, reqType);
            }, cfg => cfg.WithTrace(jPath, "json")));
        }
Beispiel #3
0
    public static JSegment GetMeshSegmentOnAxis(Vector3[] vertices, Vector3 axis)
    {
        float    projection = Vector3.Dot(axis, vertices[0]);
        JSegment segment    = new JSegment(projection, projection);

        for (int i = 1; i < vertices.Length; i++)
        {
            projection = Vector3.Dot(axis, vertices[i]);
            if (projection < segment.Min)
            {
                segment.Min = projection;
            }
            if (projection > segment.Max)
            {
                segment.Max = projection;
            }
        }
        return(segment);
    }
Beispiel #4
0
    private float FindPenetrationDepth(Vector3[] colliderAVertices, Vector3[] colliderBVertices, Vector3 axis, out bool flipNormals) // 😏
    {
        JSegment segmentA = JMeshCollider.GetMeshSegmentOnAxis(colliderAVertices, axis.normalized);
        JSegment segmentB = JMeshCollider.GetMeshSegmentOnAxis(colliderBVertices, axis.normalized);

        flipNormals = (segmentB.Min < segmentA.Min);

        if (!JSegment.IsOverlapping(segmentA, segmentB))
        {
            return(0);
        }

        float minSegment = Mathf.Min(segmentA.Min, segmentB.Min);
        float maxSegment = Mathf.Max(segmentA.Max, segmentB.Max);

        float length = maxSegment - minSegment;


        return((segmentA.Length + segmentB.Length) - length);
    }
Beispiel #5
0
 private static void FillSegments(TCR.Models.TCRContext context, string[] fields, Receptor receptor)
 {
     string[] alleles = fields[4].Split(new string[] { ", " }, StringSplitOptions.RemoveEmptyEntries);
     foreach (string allele in alleles)
     {
         VSegment segment = context.VSegments.First(s => s.Alleles == allele);
         receptor.VSegments.Add(segment);
     }
     alleles = fields[6].Split(new string[] { ", " }, StringSplitOptions.RemoveEmptyEntries);
     foreach (string allele in alleles)
     {
         DSegment segment = context.DSegments.First(s => s.Alleles == allele);
         receptor.DSegments.Add(segment);
     }
     alleles = fields[5].Split(new string[] { ", " }, StringSplitOptions.RemoveEmptyEntries);
     foreach (string allele in alleles)
     {
         JSegment segment = context.JSegments.First(s => s.Alleles == allele);
         receptor.JSegments.Add(segment);
     }
 }
Beispiel #6
0
    protected override bool CheckCollision(JCuboidCollider colliderA, JCuboidCollider colliderB, out JCollision collision)
    {
        collision = new JCollision();
        Vector3[] axesOfSeperation = GetAxesOfSeperation(colliderA, colliderB);
        Vector3   normal           = Vector3.zero;
        bool      shouldFlip       = false;

        collision.collisionDepth = float.PositiveInfinity;
        collision.colliderA      = colliderA;
        collision.colliderB      = colliderB;

        Vector3[] colliderAVerts = colliderA.GetVertices();
        Vector3[] colliderBVerts = colliderB.GetVertices();

        for (int i = 0; i < axesOfSeperation.Length; i++)
        {
            if (Vector3.SqrMagnitude(axesOfSeperation[i]) < 0.001f)// If out axis has a length of 0, some false positives can happen, soooooo lets just not do that
            {
                continue;
            }
            float depth = FindPenetrationDepth(colliderAVerts, colliderBVerts, axesOfSeperation[i], out shouldFlip);
            if (depth <= 0)
            {
                return(false);
            }
            else if (depth < collision.collisionDepth)
            {
                collision.collisionDepth = depth;
                normal = shouldFlip ? axesOfSeperation[i] * -1.0f :  axesOfSeperation[i];
            }
        }
        if (normal == Vector3.zero)
        {
            return(false);
        }
        Vector3 sharedPlaneAxis = normal.normalized;

        List <Vector3> contacts = new List <Vector3>();

        contacts.AddRange(CuboidIntersectionPoints(colliderB, colliderA));
        contacts.AddRange(CuboidIntersectionPoints(colliderA, colliderB));



        JSegment meshSegment  = JMeshCollider.GetMeshSegmentOnAxis(colliderAVerts, sharedPlaneAxis);
        float    distance     = (meshSegment.Length * 0.5f) - (collision.collisionDepth * 0.5f);
        Vector3  pointOnPlane = colliderA.transform.position + sharedPlaneAxis * distance;

        collision.collisionNormal = sharedPlaneAxis;

        collision.valid = contacts.Count > 0;

        for (int i = 0; i < contacts.Count; i++)
        {
            Vector3 contact = contacts[i];
            contact = contact + (sharedPlaneAxis * Vector3.Dot(sharedPlaneAxis, pointOnPlane - contact));

            bool unique = true;
            for (int j = 0; j < collision.collisionPoints.Count; j++)
            {
                if (Vector3.Distance(contact, collision.collisionPoints[j]) < 0.2f)
                {
                    unique = false;
                }
            }
            if (unique)
            {
                collision.collisionPoints.Add(contact);
            }
        }



        return(collision.valid);
    }
Beispiel #7
0
 public static bool IsOverlapping(JSegment a, JSegment b)
 {
     return((b.Min <= a.Max) && (a.Min <= b.Max));
 }