Esempio n. 1
0
            //!!!!physics shape
            //!!!!triangle index

            public ResultItem(Component_ObjectInSpace obj, Vector2?position, double distanceScale, Physics2DRayTestItem.ResultItem testResult = null)
            {
                Object        = obj;
                Position      = position;
                DistanceScale = distanceScale;
                RayTestResult = testResult;
            }
Esempio n. 2
0
 static int Compare(Physics2DRayTestItem.ResultItem x, Physics2DRayTestItem.ResultItem y)
 {
     if (x.DistanceScale < y.DistanceScale)
     {
         return(-1);
     }
     if (x.DistanceScale > y.DistanceScale)
     {
         return(1);
     }
     return(0);
 }
Esempio n. 3
0
        public static void Physics2DRayTest(this Component_Scene scene, Physics2DRayTestItem[] items)
        {
            var worldData = Physics2DUtility.GetWorldData(scene, false);

            if (worldData != null)
            {
                //!!!!threading

                foreach (var item in items)
                {
                    var result = new List <Physics2DRayTestItem.ResultItem>();

                    var point1 = Physics2DUtility.Convert(item.Ray.Origin);
                    var point2 = Physics2DUtility.Convert(item.Ray.GetEndPoint());

                    worldData.world.RayCast((f, p, n, fr) =>
                    {
                        if (ShouldCollide(f, item))
                        {
                            var shape = f.Tag as Component_CollisionShape2D;
                            if (shape != null)
                            {
                                var resultItem           = new Physics2DRayTestItem.ResultItem();
                                resultItem.Body          = shape.ParentRigidBody;
                                resultItem.Shape         = shape;
                                resultItem.Position      = Physics2DUtility.Convert(p);
                                resultItem.Normal        = Physics2DUtility.Convert(n);
                                resultItem.DistanceScale = fr;

                                result.Add(resultItem);

                                if (item.Mode == Physics2DRayTestItem.ModeEnum.One)
                                {
                                    return(0);
                                }
                            }
                        }

                        return(1);
                    }, point1, point2);

                    RayTest_PostProcess(item, result);
                }
            }
            else
            {
                foreach (var item in items)
                {
                    item.Result = Array.Empty <Physics2DRayTestItem.ResultItem>();
                }
            }
        }
Esempio n. 4
0
        static Physics2DRayTestItem.ResultItem[] GetResultsOnePerShape(List <Physics2DRayTestItem.ResultItem> list)
        {
            var resultCount = 0;
            var result      = new Physics2DRayTestItem.ResultItem[list.Count];

            for (int i = 0; i < list.Count; i++)
            {
                object shapeBody = list[i].Shape;
                if (shapeBody == null)
                {
                    shapeBody = list[i].Body;
                }

                var added = false;

                for (int idx = 0; idx < resultCount; idx++)
                {
                    object addedShapeBody = result[idx].Shape;
                    if (addedShapeBody == null)
                    {
                        addedShapeBody = result[idx].Body;
                    }

                    if (ReferenceEquals(addedShapeBody, shapeBody))
                    {
                        added = true;
                        break;
                    }
                }

                if (!added)
                {
                    result[resultCount++] = list[i];
                }
            }

            if (resultCount != result.Length)
            {
                Array.Resize(ref result, resultCount);
            }

            return(result);
        }