public void DrawPhysicsDebugView()
        {
            if (MainEditor.ShowPhysicsShapes)
            {
                // Matrix projection und Matrix view for PhysicsDebugView
                //
                // Calculate the projection and view adjustments for the debug view
                Projection = Matrix.CreateOrthographicOffCenter(0f, ViewportWidth / MeterInPixels,
                                                                ViewportHeight / MeterInPixels, 0f, 0f,
                                                                1f);

                // Draw the physics debug view
                PhysicsDebugView.RenderDebugData(ref Projection);
            }
        }
        public void UpdatePhysics(GameTime gameTime)
        {
            #region DebugView Update Flags

            if (MainEditor.ShowPhysicsShapes)
            {
                PhysicsDebugView.AppendFlags(DebugViewFlags.Shape);
            }
            else
            {
                PhysicsDebugView.RemoveFlags(DebugViewFlags.Shape);
            }

            if (MainEditor.ShowPolygonPoints)
            {
                PhysicsDebugView.AppendFlags(DebugViewFlags.PolygonPoints);
            }
            else
            {
                PhysicsDebugView.RemoveFlags(DebugViewFlags.PolygonPoints);
            }

            if (MainEditor.ShowJoints)
            {
                PhysicsDebugView.AppendFlags(DebugViewFlags.Joint);
            }
            else
            {
                PhysicsDebugView.RemoveFlags(DebugViewFlags.Joint);
            }

            if (MainEditor.ShowControllers)
            {
                PhysicsDebugView.AppendFlags(DebugViewFlags.Controllers);
            }
            else
            {
                PhysicsDebugView.RemoveFlags(DebugViewFlags.Controllers);
            }

            if (MainEditor.ShowContactPoints)
            {
                PhysicsDebugView.AppendFlags(DebugViewFlags.ContactPoints);
            }
            else
            {
                PhysicsDebugView.RemoveFlags(DebugViewFlags.ContactPoints);
            }

            if (MainEditor.ShowCenterOfMass)
            {
                PhysicsDebugView.AppendFlags(DebugViewFlags.CenterOfMass);
            }
            else
            {
                PhysicsDebugView.RemoveFlags(DebugViewFlags.CenterOfMass);
            }

            if (MainEditor.ShowAABB)
            {
                PhysicsDebugView.AppendFlags(DebugViewFlags.AABB);
            }
            else
            {
                PhysicsDebugView.RemoveFlags(DebugViewFlags.AABB);
            }

            if (MainEditor.ShowPerformanceGraph)
            {
                PhysicsDebugView.AppendFlags(DebugViewFlags.PerformanceGraph);
            }
            else
            {
                PhysicsDebugView.RemoveFlags(DebugViewFlags.PerformanceGraph);
            }

            if (MainEditor.ShowDebugPanel)
            {
                PhysicsDebugView.AppendFlags(DebugViewFlags.DebugPanel);
            }
            else
            {
                PhysicsDebugView.RemoveFlags(DebugViewFlags.DebugPanel);
            }

            #endregion

            _World.BodyList.ForEach(a =>
            {
                if (a.UserData != null)
                {
                    if (a.UserData is PivotBodyFlags)
                    {
                        if (((PivotBodyFlags)a.UserData).ConnectedObject != null)
                        {
                            ((PivotBodyFlags)a.UserData).ConnectedObject.Position = ConvertUnits.ToDisplayUnits(a.Position);
                        }

                        ((PivotBodyFlags)a.UserData).ConnectedObject.Update();
                    }
                }
            });

            // We update the world
            _World.Step((float)gameTime.ElapsedGameTime.TotalMilliseconds * 0.001f);
        }
예제 #3
0
파일: Game.cs 프로젝트: lab132/owlicity
        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
        {
            float deltaSeconds = (float)gameTime.ElapsedGameTime.TotalSeconds;

            base.Draw(gameTime);

            GraphicsDevice.Clear(Color.CornflowerBlue);
            CameraData cam              = ActiveCamera.CameraComponent.CamData;
            Matrix     viewMatrix       = cam.Effect.View;
            Matrix     projectionMatrix = cam.Effect.Projection;

            if (MainDrawingEnabled)
            {
                WorldRenderer.Begin(sortMode: SpriteSortMode.BackToFront, effect: cam.Effect);

                foreach (GameObject go in GameObjects)
                {
                    go.Draw(WorldRenderer);
                }

                WorldRenderer.End();
            }

            if (HudEnabled)
            {
                UIRenderer.Begin(SpriteSortMode.Texture);
                Hud.Draw(UIRenderer, deltaSeconds);
                UIRenderer.End();
            }

            if (DebugDrawingEnabled)
            {
                PhysicsDebugView.BeginCustomDraw(ref projectionMatrix, ref viewMatrix);

                foreach (DebugDrawCommand drawCommand in DebugDrawCommands)
                {
                    drawCommand(PhysicsDebugView);
                }

                for (int slot = 0; slot < Perf.NumSlots; slot++)
                {
                    TimeSpan slotMin = TimeSpan.MaxValue;
                    TimeSpan slotMax = TimeSpan.MinValue;
                    TimeSpan slotAvg = TimeSpan.Zero;
                    for (int sampleIndex = 0; sampleIndex < Perf.NumSamplesPerFrame; sampleIndex++)
                    {
                        TimeSpan sampleValue = Perf.Samples[slot, sampleIndex].Elapsed;
                        if (sampleValue < slotMin)
                        {
                            slotMin = sampleValue;
                        }
                        if (sampleValue > slotMax)
                        {
                            slotMax = sampleValue;
                        }
                        slotAvg += sampleValue;
                    }
                    slotAvg = new TimeSpan(ticks: slotAvg.Ticks / Perf.NumSamplesPerFrame);

                    Vector2 pos = new Vector2(20, 30 * slot + 20);
                    Func <TimeSpan, string> f = ts => $"{ts.TotalMilliseconds.ToString("N04", System.Globalization.CultureInfo.InvariantCulture)}ms";
                    PhysicsDebugView.DrawString(pos, $"{(PerformanceSlots)slot}: min {f(slotMin)} | max {f(slotMax)} | avg {f(slotAvg)}");
                }

                PhysicsDebugView.EndCustomDraw();
            }

            PhysicsDebugView.RenderDebugData(ref projectionMatrix, ref viewMatrix);
        }
예제 #4
0
파일: Game.cs 프로젝트: lab132/owlicity
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            WorldRenderer.Initialize(GraphicsDevice);
            UIRenderer.Initialize(GraphicsDevice);

            PhysicsDebugView.LoadContent(GraphicsDevice, Content);

            CurrentLevel = new Level(Content)
            {
                ContentNameFormat_Ground    = "level01/level1_ground_{0}{1}",
                ContentNameFormat_Collision = "level01/static_collision/static_collision_{0}{1}",
                ContentNameFormat_Layout    = "level01/layout/layout_{0}{1}",
            };

            for (int x = 0; x < 4; x++)
            {
                for (int y = 0; y < 7; y++)
                {
                    CurrentLevel.CreateScreen(x, y);
                }
            }

            {
                Owliver = new Owliver();
                Owliver.Spatial.Position += Conversion.ToMeters(450, 600);
                AddGameObject(Owliver);

                CurrentLevel.CullingCenter = Owliver;
            }

            CurrentLevel.LoadContent();

            {
                ActiveCamera = new CameraObject();

                ActiveCamera.CameraComponent.VisibilityBounds = CurrentLevel.LevelBounds;
                ActiveCamera.CameraComponent.OnGraphicsDeviceReset(GraphicsDevice);
                Window.ClientSizeChanged += (o, e) =>
                {
                    ActiveCamera.CameraComponent.OnGraphicsDeviceReset(GraphicsDevice);
                };

                ActiveCamera.SpringArm.BeforeInitialize += () =>
                {
                    ActiveCamera.SpringArm.Target = Owliver;
                };

                AddGameObject(ActiveCamera);
            }

#if true
            {
                var testSlurp = GameObjectFactory.CreateKnown(KnownGameObject.Slurp);
                testSlurp.Spatial.Position += Conversion.ToMeters(300, 250);
                AddGameObject(testSlurp);
            }

            {
                var testTankton = new Tankton();
                testTankton.Spatial.Position += Conversion.ToMeters(900, 350);
                AddGameObject(testTankton);
            }

            {
                Random rand = new Random();

                Global.SpawnGameObjectsInRingFormation(
                    center: Conversion.ToMeters(2400, 500),
                    radius: 2.5f,
                    numToSpawn: 15,
                    rand: rand,
                    types: new[] { KnownGameObject.Bonbon_Gold, KnownGameObject.Bonbon_Red });

                Global.SpawnGameObjectsInRingFormation(
                    center: Conversion.ToMeters(2400, 500),
                    radius: 1.0f,
                    numToSpawn: 5,
                    rand: rand,
                    types: new[] { KnownGameObject.Bonbon_Gold, KnownGameObject.Bonbon_Red });
            }

            {
                var testKey = new KeyPickup()
                {
                    KeyType = KeyType.Gold
                };
                testKey.Spatial.Position += Conversion.ToMeters(700, 720);
                AddGameObject(testKey);
            }

            {
                var testGate = new Gate();
                testGate.Spatial.Position += Conversion.ToMeters(2300, 1100);
                AddGameObject(testGate);
            }

            {
                var testShop = new Shop();
                testShop.Spatial.Position += Conversion.ToMeters(1300, 500);
                AddGameObject(testShop);

                var testFruitBowl = new ShopItem()
                {
                    ItemType = ShopItemType.FruitBowl
                };
                testFruitBowl.Price = ShopItemPriceType._20;
                testFruitBowl.AttachTo(testShop);
                testFruitBowl.Spatial.Position += Conversion.ToMeters(-110.0f, -90.0f);
                AddGameObject(testFruitBowl);

                var testRod = new ShopItem()
                {
                    ItemType = ShopItemType.FishingRod
                };
                testRod.Price = ShopItemPriceType._100;
                testRod.AttachTo(testShop);
                testRod.Spatial.Position += Conversion.ToMeters(128.0f, -80.0f);
                AddGameObject(testRod);
            }

            {
                var testSinger = new Singer();
                testSinger.Spatial.Position += Conversion.ToMeters(2600, 300);
                AddGameObject(testSinger);
            }

            {
                var testTrap = new SpikeTrap()
                {
                    Orientation = SpikeTrapOrientation.Vertical,
                    SensorReach = 4.0f,
                };
                testTrap.Spatial.Position += Conversion.ToMeters(1600, 500);
                AddGameObject(testTrap);
            }
#endif

            {
                var BackgroundMusic = Content.Load <Song>("snd/FiluAndDina_-_Video_Game_Background_-_Edit");
                MediaPlayer.IsRepeating = true;
#if false
                MediaPlayer.Play(BackgroundMusic);
#endif
            }

            Hud.Initialize();
            Hud.ResetLayout(GraphicsDevice.Viewport.Bounds);
            Window.ClientSizeChanged += (o, e) =>
            {
                Hud.ResetLayout(GraphicsDevice.Viewport.Bounds);
            };
        }