示例#1
0
        private static void DoBodyCount(Window window, Viewport viewport2, Scene scene1, Scene scene2, Vector2D pos)
        {
            List <Body> bodies = DemoHelper.AddText(new DemoOpenInfo(window, viewport2, scene2), "Bodies: 000000", pos, 20);

            foreach (Body body in bodies)
            {
                SpriteDrawable s = body.Shape.Tag as SpriteDrawable;
                s.Color = new ScalarColor4(.1f, .1f, 1, 1);
            }
            bodies.RemoveRange(0, 7);
            Vector2D[] positions = new Vector2D[bodies.Count];
            for (int index = 0; index < positions.Length; index++)
            {
                positions[index] = bodies[index].State.Position.Linear - numbers2[0].Offset;
            }
            EventHandler <CollectionEventArgs <Body> > handler = delegate(object sender, CollectionEventArgs <Body> e)
            {
                string val = scene1.Engine.Bodies.Count.ToString();
                SetBodiesText(bodies, positions, val);
            };

            scene1.Engine.BodiesAdded   += handler;
            scene1.Engine.BodiesRemoved += handler;
        }
示例#2
0
        private static void DoFPS(Window window, Viewport viewport2, Scene scene1, Scene scene2, Vector2D pos)
        {
            List <Body> bodies = DemoHelper.AddText(new DemoOpenInfo(window, viewport2, scene2), "FPS: 000", pos, 20);

            foreach (Body body in bodies)
            {
                SpriteDrawable s = body.Shape.Tag as SpriteDrawable;
                s.Color = new ScalarColor4(.1f, .1f, 1, 1);
            }
            bodies.RemoveRange(0, 4);
            Vector2D[] positions = new Vector2D[bodies.Count];
            for (int index = 0; index < positions.Length; index++)
            {
                positions[index] = bodies[index].State.Position.Linear - numbers2[0].Offset;
            }
            int    frames       = 100;
            Scalar frameSeconds = 1;

            viewport2.BeginDrawing += delegate(object sender, DrawEventArgs e)
            {
                if (frames >= 10)
                {
                    frames       /= 2;
                    frameSeconds /= 2;
                }
                frames++;
                frameSeconds += e.DrawInfo.TrueDt;
                int ups = (int)(frames / frameSeconds);
                if (ups < 0)
                {
                    ups = 0;
                }
                string val = ups.ToString();
                SetBodiesText(bodies, positions, val);
            };
        }
示例#3
0
        public static void AddStarField(DemoOpenInfo info, int count, BoundingRectangle rect)
        {
            Vector2D[]     stars      = new Vector2D[count];
            ScalarColor3[] starColors = new ScalarColor3[stars.Length];
            for (int index = 0; index < stars.Length; ++index)
            {
                stars[index]      = new Vector2D(NextScalar(rect.Min.X, rect.Max.X), NextScalar(rect.Min.Y, rect.Max.Y));
                starColors[index] = new ScalarColor3(DemoHelper.NextScalar(), DemoHelper.NextScalar(), DemoHelper.NextScalar());
            }
            Colored3VertexesDrawable stardrawable = new Colored3VertexesDrawable(Gl.GL_POINTS, stars, starColors);
            Graphic stargraphic = new Graphic(stardrawable, Matrix2x3.Identity, new Lifespan());

            stargraphic.ZOrder = -1;
            stargraphic.DrawProperties.Add(new PointSizeProperty(1));
            info.Scene.AddGraphic(stargraphic);
        }