示例#1
0
        void DrawPoly(List <JVector> poly, JVector pos, JMatrix o, Color color)
        {
            for (int i = 0; i < poly.Count - 1; i++)
            {
                JVector a = JVector.Transform(poly[i], o * JMatrix.CreateTranslation(pos));
                JVector b = JVector.Transform(poly[i + 1], o * JMatrix.CreateTranslation(pos));
                DebugDrawer.DrawLine(a, b, color);
            }
            JVector c = JVector.Transform(poly[0], o * JMatrix.CreateTranslation(pos));
            JVector d = JVector.Transform(poly[poly.Count - 1], o * JMatrix.CreateTranslation(pos));

            DebugDrawer.DrawLine(c, d, color);
        }
示例#2
0
        protected override void Update(GameTime gameTime)
        {
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
            {
                this.Exit();
            }

            KeyboardState keys             = Keyboard.GetState();
            JVector       moveVector       = JVector.Zero;
            float         amountOfMovement = 0.05f;

            if (keys.IsKeyDown(Keys.Right))
            {
                moveVector.X += amountOfMovement;
            }
            if (keys.IsKeyDown(Keys.Left))
            {
                moveVector.X -= amountOfMovement;
            }
            if (keys.IsKeyDown(Keys.Down))
            {
                moveVector.Y -= amountOfMovement;
            }
            if (keys.IsKeyDown(Keys.Up))
            {
                moveVector.Y += amountOfMovement;
            }

            body1.Position += moveVector;

            body1.Orientation += 0.001f;
            body2.Orientation -= 0.001f;

            JMatrix o1   = JMatrix.CreateRotationZ(body1.Orientation);
            JMatrix o2   = JMatrix.CreateRotationZ(body2.Orientation);
            JVector pos1 = body1.Position;
            JVector pos2 = body2.Position;

            JVector point2;

            sw.Start();
            hit = XenoCollide.Detect(body1.Shape, body2.Shape, ref o1, ref o2, ref pos1, ref pos2, out point, out normal, out penetration);
            sw.Stop();

            ticks = sw.ElapsedTicks;
            sw.Reset();

            DebugDrawer.DrawLine(point, point + normal);

            //DebugDrawer.DrawPoint(point2);
            DebugDrawer.DrawPoint(point);
            DebugDrawer.Color = Color.Red;

            DebugDrawer.Color = Color.Black;
            DebugDrawer.DrawLine(JVector.Up, JVector.Down);
            DebugDrawer.DrawLine(JVector.Left, JVector.Right);

            body1.DebugDraw(DebugDrawer);
            body2.DebugDraw(DebugDrawer);

            if (hit)
            {
                var oldPosition = body1.Position;

                body1.Position += normal;
                body1.DebugDraw(DebugDrawer);
                body1.Position = oldPosition;
            }

            base.Update(gameTime);
        }