コード例 #1
0
        public static Body AddBody(Scene Scene)
        {
            Body body = new Body();

            ArrayUtilities.Add(ref Scene.Bodies, body);

            body.Orientation = Matrix2.Identity;

            return(body);
        }
コード例 #2
0
        public static async Task GetRemoteUrlSources()
        {
            string remoteUrlSourceFile = await httpClient.GetStringAsync(AppSettings.RemoteUrlSourceUrl);

            if (!String.IsNullOrWhiteSpace(remoteUrlSourceFile))
            {
                // Parse the file into a list of strings.  Split by either carraige return, or
                //  line feed to account for platform  differences in the platform that created
                //  the RemoteUrlSource feeds list file.
                string[] arrayCRLF        = { "\r", "\n" };
                string[] RemoteUrlSources = remoteUrlSourceFile.Split(arrayCRLF, StringSplitOptions.RemoveEmptyEntries);

                // Now parse each additional feed and add it to the master collection.
                foreach (string RemoteUrlSourceAsStr in RemoteUrlSources)
                {
                    UrlSource source = stringToUrlSource(RemoteUrlSourceAsStr);

                    switch (source.Type)
                    {
                    case "RssService":
                        ArrayUtilities.Add(ref AppSettings.RssAddressCollection, source);
                        AppSettings.EnableRssService = true;
                        break;

                    case "YoutubeService":
                        ArrayUtilities.Add(ref AppSettings.YoutubeAddressCollection, source);
                        AppSettings.EnableYoutubeService = true;
                        break;

                    case "TwitterService":
                        ArrayUtilities.Add(ref AppSettings.TwitterAddressCollection, source);
                        //Twitter should be enabled prior to app submission on account of Oauth requirements
                        break;

                    default:
                        ServiceLocator.MessageService.ShowErrorAsync("Unable to add UrlSource of type " + source.Type + " to a valid collection, source will not be retrieved", "Application Error");
                        break;
                    }
                }
            }
        }
コード例 #3
0
        private static void DispatchPolygonToPolygon(Manifold Manifold)
        {
            PolygonShape a = (PolygonShape)Manifold.BodyA.Shape;
            PolygonShape b = (PolygonShape)Manifold.BodyB.Shape;

            Manifold.Points = null;

            // Check for a separating axis with A's face planes
            uint   faceA;
            Number penetrationA;

            FindAxisLeastPenetration(Manifold.BodyA, Manifold.BodyB, out faceA, out penetrationA);
            if (penetrationA >= 0)
            {
                return;
            }

            // Check for a separating axis with B's face planes
            uint   faceB;
            Number penetrationB;

            FindAxisLeastPenetration(Manifold.BodyB, Manifold.BodyA, out faceB, out penetrationB);
            if (penetrationB >= 0)
            {
                return;
            }

            uint referenceIndex;
            bool flip;             // Always point from a to b

            Body refBody;
            Body incBody;

            PolygonShape refPoly;
            PolygonShape incPoly;

            // Determine which shape contains reference face
            if (Math.BiasGreaterThan(penetrationA, penetrationB))
            {
                refBody = Manifold.BodyA;
                refPoly = a;

                incBody = Manifold.BodyB;
                incPoly = b;

                referenceIndex = faceA;
                flip           = false;
            }
            else
            {
                refBody = Manifold.BodyB;
                refPoly = b;

                incBody = Manifold.BodyA;
                incPoly = a;

                referenceIndex = faceB;
                flip           = true;
            }

            Matrix2 refBodyOrientation = refBody.Orientation;

            // World space incident face
            Vector2[] incidentFace = new Vector2[2];
            FindIncidentFace(incidentFace, refBody, refPoly, incBody, incPoly, referenceIndex);

            //        y
            //        ^  ->n       ^
            //      +---c ------posPlane--
            //  x < | i |\
            //      +---+ c-----negPlane--
            //             \       v
            //              r
            //
            //  r : reference face
            //  i : incident poly
            //  c : clipped point
            //  n : incident normal

            // Setup reference face vertices
            Vector2 v1 = refPoly.Vertices[referenceIndex];

            referenceIndex = referenceIndex + 1 == refPoly.Vertices.Length ? 0 : referenceIndex + 1;
            Vector2 v2 = refPoly.Vertices[referenceIndex];

            // Transform vertices to world space
            v1 = refBodyOrientation * v1 + refBody.Position;
            v2 = refBodyOrientation * v2 + refBody.Position;

            // Calculate reference face side normal in world space
            Vector2 sidePlaneNormal = (v2 - v1);

            sidePlaneNormal.Normalize();

            // Orthogonalize
            Vector2 refFaceNormal = new Vector2(sidePlaneNormal.Y, -sidePlaneNormal.X);

            // ax + by = c
            // c is distance from origin
            Number refC    = refFaceNormal.Dot(v1);
            Number negSide = -sidePlaneNormal.Dot(v1);
            Number posSide = sidePlaneNormal.Dot(v2);

            // Clip incident face to reference face side planes
            if (Clip(-sidePlaneNormal, negSide, incidentFace) < 2)
            {
                return;                 // Due to floating point error, possible to not have required points
            }
            if (Clip(sidePlaneNormal, posSide, incidentFace) < 2)
            {
                return;                 // Due to floating point error, possible to not have required points
            }
            // Flip
            Manifold.Normal = refFaceNormal * (flip ? -1 : 1);

            // Keep points behind reference face
            uint   cp         = 0;   // clipped points behind reference face
            Number separation = refFaceNormal.Dot(incidentFace[0]) - refC;

            if (separation <= 0)
            {
                ArrayUtilities.Add(ref Manifold.Points, incidentFace[0]);
                Manifold.Penetration = -separation;
                ++cp;
            }
            else
            {
                Manifold.Penetration = 0;
            }

            separation = refFaceNormal.Dot(incidentFace[1]) - refC;
            if (separation <= 0)
            {
                ArrayUtilities.Add(ref Manifold.Points, incidentFace[1]);

                Manifold.Penetration += -separation;
                ++cp;

                // Average penetration
                Manifold.Penetration /= (int)cp;
            }
        }