Draw axis aligned bounding boxes, points and lines.
Inheritance: Microsoft.Xna.Framework.DrawableGameComponent, Jitter.IDebugDrawer
コード例 #1
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            Camera          = new Camera(this);
            Camera.Position = new Vector2(0, 10);
            this.Components.Add(Camera);

            DebugDrawer = new DebugDrawer(this);
            this.Components.Add(DebugDrawer);

            Display           = new Display(this);
            Display.DrawOrder = int.MaxValue;
            this.Components.Add(Display);

            this.PhysicScenes = new List <Scenes.Scene>();

            foreach (Type type in Assembly.GetExecutingAssembly().GetTypes())
            {
                if (type.Namespace == "JitterDemo.Scenes" && !type.IsAbstract)
                {
                    if (type.Name == "Pyramid")
                    {
                        currentScene = PhysicScenes.Count;
                    }
                    Scenes.Scene scene = (Scenes.Scene)Activator.CreateInstance(type, this);
                    this.PhysicScenes.Add(scene);
                }
            }

            if (PhysicScenes.Count > 0)
            {
                this.PhysicScenes[currentScene].Build();
            }

            base.Initialize();
        }
コード例 #2
0
        protected override void Initialize()
        {
            Camera = new Camera(this)
            {
                Position = new Vector3(15, 15, 30)
            };
            Camera.Target = Camera.Position + Vector3.Normalize(new Vector3(10, 5, 20));
            Components.Add(Camera);

            DebugDrawer = new DebugDrawer(this);
            Components.Add(DebugDrawer);

            Display = new Display(this)
            {
                DrawOrder = int.MaxValue
            };
            Components.Add(Display);

            primitives[(int)Primitives.box]      = new Primitives3D.BoxPrimitive(GraphicsDevice);
            primitives[(int)Primitives.capsule]  = new Primitives3D.CapsulePrimitive(GraphicsDevice);
            primitives[(int)Primitives.cone]     = new Primitives3D.ConePrimitive(GraphicsDevice);
            primitives[(int)Primitives.cylinder] = new Primitives3D.CylinderPrimitive(GraphicsDevice);
            primitives[(int)Primitives.sphere]   = new Primitives3D.SpherePrimitive(GraphicsDevice);

            BasicEffect = new BasicEffect(GraphicsDevice);
            BasicEffect.EnableDefaultLighting();
            BasicEffect.PreferPerPixelLighting = true;

            PhysicScenes = new List <Scenes.Scene>();

            foreach (var type in Assembly.GetExecutingAssembly().GetTypes())
            {
                if (type.Namespace == "JitterDemo.Scenes" && !type.IsAbstract && type.DeclaringType == null)
                {
                    if (type.Name == "SoftBodyJenga")
                    {
                        currentScene = PhysicScenes.Count;
                    }

                    var scene = (Scenes.Scene)Activator.CreateInstance(type, this);
                    PhysicScenes.Add(scene);
                }
            }

            if (PhysicScenes.Count > 0)
            {
                PhysicScenes[currentScene].Build();
            }

            base.Initialize();
        }
コード例 #3
0
        private void DrawIslands()
        {
            JBBox box;

            foreach (var island in World.Islands)
            {
                box = JBBox.SmallBox;

                foreach (RigidBody body in island.Bodies)
                {
                    box = JBBox.CreateMerged(box, body.BoundingBox);
                }

                DebugDrawer.DrawAabb(box.Min, box.Max, island.IsActive() ? Color.Green : Color.Yellow);
            }
        }
コード例 #4
0
        private void Walk(DynamicTree <SoftBody.Triangle> tree, int index)
        {
            var tn = tree.Nodes[index];

            if (tn.IsLeaf())
            {
                return;
            }
            else
            {
                Walk(tree, tn.Child1);
                Walk(tree, tn.Child2);

                DebugDrawer.DrawAabb(tn.AABB.Min, tn.AABB.Max, Color.Red);
            }
        }
コード例 #5
0
        private void DrawJitterDebugInfo()
        {
            foreach (RigidBody body in World.RigidBodies)
            {
                DebugDrawer.Color = Color.Gray;//rndColors[cc % rndColors.Length];
                body.DebugDraw(DebugDrawer);

                //DebugDrawer.DrawAabb(body.BoundingBox.Min, body.BoundingBox.Max, Color.Pink);

                //if (body.Shape.GetType() == typeof(PolygonShape))
                //{
                //    var ch = body.Shape as PolygonShape;

                //    JMatrix o = JMatrix.CreateRotationZ(body.Orientation);
                //    foreach (var point in ch.vertices)
                //    {
                //        var t = JVector.Transform(point, o);
                //        DebugDrawer.DrawPoint(t + body.Position);
                //    }
                //}

                DebugDrawer.Color = Color.Red;
                foreach (Arbiter item in body.Arbiters)
                {
                    foreach (var contact in item.ContactList)
                    {
                        DebugDrawer.DrawLine(contact.Position1, contact.Position1 + contact.Normal * 0.15f);
                        DebugDrawer.DrawLine(contact.Position2, contact.Position2 + contact.Normal * 0.15f);
                        DebugDrawer.DrawPoint(contact.Position1);
                        DebugDrawer.DrawPoint(contact.Position2);
                    }
                }
            }

            DebugDrawer.Color = Color.Blue;
            foreach (Spring spring in World.Springs)
            {
                spring.DebugDraw(DebugDrawer);
            }

            DebugDrawer.Color = Color.Red;
            foreach (Constraint c in World.Constraints)
            {
                c.DebugDraw(DebugDrawer);
            }
        }
コード例 #6
0
        private void DrawCloth()
        {
            foreach (SoftBody body in World.SoftBodies)
            {
                if (body.Tag is BodyTag && ((BodyTag)body.Tag) == BodyTag.DontDrawMe)
                {
                    return;
                }

                for (int i = 0; i < body.Triangles.Count; i++)
                {
                    //DebugDrawer.DrawTriangle(body.Triangles[i].VertexBody1.Position, body.Triangles[i].VertexBody2.Position, body.Triangles[i].VertexBody3.Position, new Color(0, 0.95f, 0, 0.5f));
                    DebugDrawer.DrawTriangle(body.Triangles[i].VertexBody3.Position, body.Triangles[i].VertexBody2.Position, body.Triangles[i].VertexBody1.Position, new Color(0, 0.95f, 0, 0.5f));
                }
                //DrawDynamicTree(body);
            }
        }
コード例 #7
0
        protected override void Initialize()
        {
            Camera = new Camera(this);
            Camera.Position = new Vector3(15, 15, 30);
            Camera.Target = Camera.Position + Vector3.Normalize(new Vector3(10, 5, 20));

            debugDrawer = new DebugDrawer(this);
            debugDrawer.UpdateOrder = int.MaxValue / 2;

            display = new Display(this);
            display.DrawOrder = int.MaxValue;
            display.DisplayText[5] = "PRESS ENTER TO SHOW SCENE EDITOR";

            quadDrawer = new QuadDrawer(this);

            this.Components.Add(quadDrawer);
            this.Components.Add(display);
            this.Components.Add(debugDrawer);
            this.Components.Add(Camera);
            base.Initialize();
        }
コード例 #8
0
        protected override void Initialize()
        {
            Camera          = new Camera(this);
            Camera.Position = new Vector3(15, 15, 30);
            Camera.Target   = Camera.Position + Vector3.Normalize(new Vector3(10, 5, 20));

            debugDrawer             = new DebugDrawer(this);
            debugDrawer.UpdateOrder = int.MaxValue / 2;

            display                = new Display(this);
            display.DrawOrder      = int.MaxValue;
            display.DisplayText[5] = "PRESS ENTER TO SHOW SCENE EDITOR";

            quadDrawer = new QuadDrawer(this);

            this.Components.Add(quadDrawer);
            this.Components.Add(display);
            this.Components.Add(debugDrawer);
            this.Components.Add(Camera);
            base.Initialize();
        }
コード例 #9
0
ファイル: JitterDemo.cs プロジェクト: reidyd/jitterphysics
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            Camera = new Camera(this);
            Camera.Position = new Vector2(0, 10);
            this.Components.Add(Camera);

            DebugDrawer = new DebugDrawer(this);
            this.Components.Add(DebugDrawer);

            Display = new Display(this);
            Display.DrawOrder = int.MaxValue;
            this.Components.Add(Display);

            this.PhysicScenes = new List<Scenes.Scene>();

            foreach (Type type in Assembly.GetExecutingAssembly().GetTypes())
            {
                if (type.Namespace == "JitterDemo.Scenes" && !type.IsAbstract)
                {
                    if (type.Name == "Pyramid") currentScene = PhysicScenes.Count;
                    Scenes.Scene scene = (Scenes.Scene)Activator.CreateInstance(type, this);
                    this.PhysicScenes.Add(scene);
                }
            }

            if (PhysicScenes.Count > 0)
                this.PhysicScenes[currentScene].Build();

            base.Initialize();
        }
コード例 #10
0
        protected override void Draw(GameTime gameTime) //override
        {
            //riftWatch.Restart();


            // draw scene for both eyes into respective rendertarget
            for (int eye = 0; eye < 2; eye++)
            {
                activeBodies = 0;

                GraphicsDevice.SetRenderTarget(renderTargetEye[eye]);
                GraphicsDevice.Clear(Color.CornflowerBlue);

                GraphicsDevice.BlendState        = BlendState.Opaque;
                GraphicsDevice.DepthStencilState = DepthStencilState.Default;

                Matrix view       = rift.GetEyeViewMatrix(eye, playerMatrix);
                Matrix projection = rift.GetProjectionMatrix(eye);
                //manyCubes.Draw(view, projection);

                DrawCloth();
                //DrawIslands();

                //BasicEffect.View = view;// Camera.View;
                //BasicEffect.Projection = projection;// Camera.Projection;
                //BasicEffect.DiffuseColor = Color.LightGray.ToVector3();

                /*// Draw all shapes
                 * foreach (RigidBody body in World.RigidBodies)
                 * {
                 *
                 *
                 *  if (body.Shape is ConvexHullShape)
                 *  {
                 *
                 *  }
                 *  else
                 *  {
                 *      if (body.IsActive)
                 *      {
                 *          activeBodies++;
                 *      }
                 *
                 *      if (body.Tag is int || body.IsParticle)
                 *      {
                 *          continue;
                 *      }
                 *      AddBodyToDrawList(body);
                 *  }
                 * }
                 *
                 #region Debug Draw All Contacts
                 * //foreach (Arbiter a in World.ArbiterMap)
                 * //{
                 * //    foreach (Contact c in a.ContactList)
                 * //    {
                 * //        DebugDrawer.DrawLine(c.Position1 + 0.5f * JVector.Left, c.Position1 + 0.5f * JVector.Right, Color.Green);
                 * //        DebugDrawer.DrawLine(c.Position1 + 0.5f * JVector.Up, c.Position1 + 0.5f * JVector.Down, Color.Green);
                 * //        DebugDrawer.DrawLine(c.Position1 + 0.5f * JVector.Forward, c.Position1 + 0.5f * JVector.Backward, Color.Green);
                 *
                 * //        DebugDrawer.DrawLine(c.Position2 + 0.5f * JVector.Left, c.Position2 + 0.5f * JVector.Right, Color.Red);
                 * //        DebugDrawer.DrawLine(c.Position2 + 0.5f * JVector.Up, c.Position2 + 0.5f * JVector.Down, Color.Red);
                 * //        DebugDrawer.DrawLine(c.Position2 + 0.5f * JVector.Forward, c.Position2 + 0.5f * JVector.Backward, Color.Red);
                 * //    }
                 * //}
                 *
                 #endregion
                 *
                 *
                 * if (primitives.Length > 0)
                 * {
                 *  foreach (Primitives3D.GeometricPrimitive prim in primitives)
                 *  {
                 *
                 *      prim.Draw(BasicEffect, view, projection);
                 *  }
                 *
                 * }
                 *
                 *
                 *
                 *
                 * if (convexObj.Count > 0)
                 * {
                 *  foreach (ConvexHullObject prim in convexObj)
                 *  {
                 *
                 *      prim.Draw(gameTime, view, projection);
                 *  }
                 * }
                 *
                 *
                 *
                 * //manyCubes.UnDraw(view, projection);
                 */
                DrawJitterDebugInfo();

                if (DebugDrawer != null)
                {
                    //Demo.GraphicsDevice.BlendState = BlendState.Opaque;
                    //Demo.GraphicsDevice.DepthStencilState = DepthStencilState.Default;

                    DebugDrawer.Draw(gameTime, view, projection);
                }

                PhysicScenes[currentScene].Draw(gameTime, view, projection, eye); //gameTime, view, projection, eye

                //base.Draw(gameTime);
            }



            //GraphicsDevice.Clear(backgroundColor);
            //GraphicsDevice.DepthStencilState = DepthStencilState.Default;

            //BasicEffect.View = Camera.View;
            //BasicEffect.Projection = Camera.Projection;

            GraphicsDevice.RasterizerState = cullMode;
            GraphicsDevice.RasterizerState = normal;

            base.Draw(gameTime);

            // submit rendertargets to the Rift


            //riftWatch.Restart();

            /*if (startOVRDrawThread == 0)
             * {
             *  Thread main_thread_update = new Thread(() =>
             *  {
             *  _thread_looper:
             *
             *      try
             *      {
             *
             *      }
             *      catch (Exception ex)
             *      {
             *
             *      }
             *      Thread.Sleep(0);
             *      goto _thread_looper;
             *
             *      //ShutDown();
             *      //ShutDownGraphics();
             *
             *  }, 0);
             *
             *  main_thread_update.IsBackground = true;
             *  main_thread_update.SetApartmentState(ApartmentState.STA);
             *  main_thread_update.Start();
             *  startOVRDrawThread = 1;
             * }*/


            result = rift.SubmitRenderTargets(renderTargetEye[0], renderTargetEye[1]);

            //Console.WriteLine(riftWatch.Elapsed.Milliseconds);


            // show left eye view also on the monitor screen
            DrawEyeViewIntoBackbuffer(0);
            //DrawEyeViewIntoBackbuffer(1);
            //Console.WriteLine(riftWatch.Elapsed.Milliseconds);
        }
コード例 #11
0
        protected override void Initialize()
        {
            Camera          = new Camera(this);
            Camera.Position = new Vector3(15, 15, 30);
            Camera.Target   = Camera.Position + Vector3.Normalize(new Vector3(0, 0, 1));
            this.Components.Add(Camera);

            DebugDrawer = new DebugDrawer(this);
            this.Components.Add(DebugDrawer);

            Display           = new Display(this);
            Display.DrawOrder = int.MaxValue;
            this.Components.Add(Display);

            primitives[(int)Primitives.box]        = new Primitives3D.BoxPrimitive(GraphicsDevice);
            primitives[(int)Primitives.capsule]    = new Primitives3D.CapsulePrimitive(GraphicsDevice);
            primitives[(int)Primitives.cone]       = new Primitives3D.ConePrimitive(GraphicsDevice);
            primitives[(int)Primitives.cylinder]   = new Primitives3D.CylinderPrimitive(GraphicsDevice);
            primitives[(int)Primitives.sphere]     = new Primitives3D.SpherePrimitive(GraphicsDevice);
            primitives[(int)Primitives.convexHull] = new Primitives3D.SpherePrimitive(GraphicsDevice);



            BasicEffect = new BasicEffect(GraphicsDevice);
            BasicEffect.EnableDefaultLighting();
            BasicEffect.PreferPerPixelLighting = true;

            this.PhysicScenes = new List <Scenes.Scene>();


            foreach (Type type in Assembly.GetExecutingAssembly().GetTypes())
            {
                if (type.Namespace == "JitterDemo.Scenes" && !type.IsAbstract && type.DeclaringType == null)
                {
                    if (type.Name == "SoftBodyJenga")
                    {
                        currentScene = PhysicScenes.Count;
                    }
                    Scenes.Scene scene = (Scenes.Scene)Activator.CreateInstance(type, this);
                    this.PhysicScenes.Add(scene);
                }
            }

            if (PhysicScenes.Count > 0)
            {
                this.PhysicScenes[currentScene].Build();
            }



            //Vector3 cameraPosition = new Vector3(30.0f, 30.0f, 30.0f);
            //Vector3 cameraTarget = new Vector3(0.0f, 0.0f, 0.0f); // Look back at the origin

            fovAngle    = MathHelper.ToRadians(90); // convert 45 degrees to radians //(float)Math.PI
            aspectRatio = graphics.PreferredBackBufferWidth / graphics.PreferredBackBufferHeight;
            near        = 0.01f;                    // the near clipping plane distance
            far         = 1000f;                    // the far clipping plane distance

            //worldMatrix = Matrix.CreateTranslation(10.0f, 0.0f, 10.0f);
            //viewMatrix = Matrix.CreateLookAt(cameraPosition, cameraTarget, Vector3.Up);
            //projectionMatrix = Matrix.CreatePerspectiveFieldOfView(fovAngle, aspectRatio, near, far);


            //GraphicsDevice.BlendState = BlendState.Opaque;
            //GraphicsDevice.DepthStencilState = DepthStencilState.Default;
            GraphicsDevice.RasterizerState = cullMode;
            GraphicsDevice.RasterizerState = normal;
            // initialize the Rift
            int result = rift.Init(GraphicsDevice);

            if (result != 0)
            {
                throw new InvalidOperationException("rift.Init result: " + result);
            }
            //manyCubes = new ManyCubes(GraphicsDevice);
            for (int eye = 0; eye < 2; eye++)
            {
                renderTargetEye[eye] = rift.CreateRenderTargetForEye(eye);
            }

            base.Initialize();

            hasInit = 1;
        }
コード例 #12
0
ファイル: JitterDemo.cs プロジェクト: tpb3d/TPB3D
        protected override void Initialize()
        {
            Camera = new Camera(this);
            Camera.Position = new Vector3(15, 15, 30);
            Camera.Target = Camera.Position + Vector3.Normalize(new Vector3(10, 5, 20));
            this.Components.Add(Camera);

            DebugDrawer = new DebugDrawer(this);
            this.Components.Add(DebugDrawer);

            Display = new Display(this);
            Display.DrawOrder = int.MaxValue;
            this.Components.Add(Display);

            primitives[(int)Primitives.box] = new Primitives3D.BoxPrimitive(GraphicsDevice);
            primitives[(int)Primitives.capsule] = new Primitives3D.CapsulePrimitive(GraphicsDevice);
            primitives[(int)Primitives.cone] = new Primitives3D.ConePrimitive(GraphicsDevice);
            primitives[(int)Primitives.cylinder] = new Primitives3D.CylinderPrimitive(GraphicsDevice);
            primitives[(int)Primitives.sphere] = new Primitives3D.SpherePrimitive(GraphicsDevice);

            BasicEffect = new BasicEffect(GraphicsDevice);
            BasicEffect.EnableDefaultLighting();
            BasicEffect.PreferPerPixelLighting = true;

            this.PhysicScenes = new List<Scenes.Scene>();


            foreach (Type type in Assembly.GetExecutingAssembly().GetTypes())
            {
                if (type.Namespace == "JitterDemo.Scenes" && !type.IsAbstract)
                {
                    if (type.Name == "SoftBodyJenga") currentScene = PhysicScenes.Count;
                    Scenes.Scene scene = (Scenes.Scene)Activator.CreateInstance(type, this);
                    this.PhysicScenes.Add(scene);
                }
            }

            if (PhysicScenes.Count > 0)
                this.PhysicScenes[currentScene].Build();

            base.Initialize();
        }