Esempio n. 1
0
        // this method is extremely brute force, only use for debugging!
        public void DebugDraw(IDebugDrawer drawer)
        {
            if (this.shape.type == ShapeType.Box)
            {
                BoxShape box = this.shape as BoxShape;
                // get corners
                JVector a = box.GetCorner(0);
                JVector b = box.GetCorner(1);
                JVector c = box.GetCorner(2);
                JVector d = box.GetCorner(3);

                // transform points
                JMatrix xform = JMatrix.CreateRotationZ(this.orientation);
                JVector.Transform(ref a, ref xform, out a);
                JVector.Transform(ref b, ref xform, out b);
                JVector.Transform(ref c, ref xform, out c);
                JVector.Transform(ref d, ref xform, out d);

                a += this.position;
                b += this.position;
                c += this.position;
                d += this.position;

                if (isStatic)
                {
                    drawer.SetColor(0.25f, 0.85f, 0.25f, 1);
                }
                else if (isActive)
                {
                    drawer.SetColor(0.95f, 0.95f, 0.95f, 1);
                }
                else
                {
                    drawer.SetColor(0.65f, 0.65f, 0.65f, 1);
                }

                drawer.DrawTriangle(a, c, b);
                drawer.DrawTriangle(c, a, d);
                // draw outline
                drawer.SetColor(0, 0, 0, 1);
                drawer.DrawLine(a, b);
                drawer.DrawLine(b, c);
                drawer.DrawLine(c, d);
                drawer.DrawLine(d, a);
            }
            else if (this.shape.type == ShapeType.Circle)
            {
                JMatrix o1  = JMatrix.CreateRotationZ(orientation);
                JVector dir = JVector.Up;
                JVector u   = JVector.Zero;
                JVector a;

                for (int i = -1; i <= 36; i++)
                {
                    JVector.TransposedTransform(ref dir, ref o1, out a);
                    // get the support in the given direction
                    JVector s; this.shape.SupportMapping(ref a, out s);
                    // transform the support into world space
                    a = JVector.Transform(s, o1) + position;

                    dir = JVector.Transform(dir, JMatrix.CreateRotationZ(0.0174532925f * 10f));

                    if (i >= 0)
                    {
                        if (isStatic)
                        {
                            drawer.SetColor(0.25f, 0.85f, 0.25f, 1);
                        }
                        else if (isActive)
                        {
                            drawer.SetColor(0.95f, 0.95f, 0.95f, 1);
                        }
                        else
                        {
                            drawer.SetColor(0.65f, 0.65f, 0.65f, 1);
                        }
                        drawer.DrawTriangle(a, u, this.position);
                        drawer.SetColor(0, 0, 0, 1);
                        drawer.DrawLine(a, u);
                    }
                    u = a;
                }
            }

            //JMatrix o1 = JMatrix.CreateRotationZ(orientation);
            //JVector dir = JVector.Up;
            //JVector u = JVector.Zero;
            //JVector a;

            //for (int i = -1; i <= 36; i++)
            //{
            //    JVector.TransposedTransform(ref dir, ref o1, out a);
            //    // get the support in the given direction
            //    JVector s; this.shape.SupportMapping(ref a, out s);
            //    // transform the support into world space
            //    a = JVector.Transform(s, o1) + position;

            //    dir = JVector.Transform(dir, JMatrix.CreateRotationZ(0.0174532925f * 10f));

            //    if (i >= 0)
            //    {
            //        if (isStatic)
            //            drawer.SetColor(0.25f, 0.85f, 0.25f, 1);
            //        else if (isActive)
            //            drawer.SetColor(0.95f, 0.95f, 0.95f, 1);
            //        else
            //            drawer.SetColor(0.65f, 0.65f, 0.65f, 1);
            //        drawer.DrawTriangle(a, u, this.position);
            //        drawer.SetColor(0,0,0, 1);
            //        drawer.DrawLine(a, u);
            //    }
            //    u = a;
            //}

            //JMatrix xForm = JMatrix.CreateRotationZ(orientation);

            //drawer.SetColor(1, 0, 0, 1);
            //drawer.DrawLine(position + JVector.Transform(JVector.Left * 0.25f, xForm), position + JVector.Transform(JVector.Zero, xForm));
            //drawer.SetColor(0, 1, 0, 1);
            //drawer.DrawLine(position + JVector.Transform(JVector.Up * 0.25f, xForm), position + JVector.Transform(JVector.Zero, xForm));
        }