Inheritance: Box2DX.Dynamics.DebugDraw
Example #1
0
        public override void Step(Settings settings)
        {
            base.Step(settings);

            OpenGLDebugDraw.DrawString(5, _textLine, "Press: (c) create a shape, (d) destroy a shape.");
            _textLine += 15;
        }
Example #2
0
        public override void Step(Settings settings)
        {
            OpenGLDebugDraw.DrawString(5, _textLine, "Keys: left = a, brake = s, right = d");
            _textLine += 15;

            base.Step(settings);
        }
Example #3
0
        public override void Step(Settings settings)
        {
            base.Step(settings);

            OpenGLDebugDraw.DrawString(5, _textLine, "This demonstrates a soft distance joint.");
            _textLine += 15;
            OpenGLDebugDraw.DrawString(5, _textLine, "Press: (b) to delete a body, (j) to delete a joint");
            _textLine += 15;
        }
Example #4
0
        public override void Step(Settings settings)
        {
            base.Step(settings);
            OpenGLDebugDraw.DrawString(5, _textLine, "Keys: (l) limits, (m) motors, (p) speed");
            _textLine += 15;
            float force = _joint.MotorForce;

            OpenGLDebugDraw.DrawString(5, _textLine, String.Format("Motor Force = {0}", force));
            _textLine += 15;
        }
Example #5
0
        public MainForm()
        {
            InitializeComponent();

#if GLRender
            openGlControl.InitializeContexts();
            OpenGLDebugDraw.InitTextRenderer(openGlControl);
#endif //GLRender

            Init();
            SetView();
        }
Example #6
0
        public override void Step(Settings settings)
        {
            settings.pause = 1;
            base.Step(settings);
            settings.pause = 0;

            Sweep sweep1 = new Sweep();

            sweep1.C0.Set(0.0f, 20.0f);
            sweep1.A0          = 0.0f;
            sweep1.C           = sweep1.C0;
            sweep1.A           = sweep1.A0;
            sweep1.T0          = 0.0f;
            sweep1.LocalCenter = _body1.GetLocalCenter();

            Sweep sweep2 = new Sweep();

            sweep2.C0.Set(9.6363468f, 28.050615f);
            sweep2.A0          = 1.6408679f;
            sweep2.C           = sweep2.C0 + new Vec2(-0.075121880f, 0.27358246f);
            sweep2.A           = sweep2.A0 - 10.434675f;
            sweep2.T0          = 0.0f;
            sweep2.LocalCenter = _body2.GetLocalCenter();
            TOIInput input = new TOIInput
            {
                SweepA = sweep1,
                SweepB = sweep2
            };
            float toi = Collision.TimeOfImpact(input, _shape1, _shape2);

            OpenGLDebugDraw.DrawString(5, _textLine, "toi = " + toi.ToString());
            _textLine += 15;

            XForm xf2 = new XForm();

            sweep2.GetTransform(out xf2, toi);
            int vertexCount = _shape2.VertexCount;

            Vec2[] vertices      = new Vec2[Box2DNet.Common.Settings.MaxPolygonVertices];
            Vec2[] localVertices = _shape2.Vertices;
            for (int i = 0; i < vertexCount; ++i)
            {
                vertices[i] = Box2DNet.Common.Math.Mul(xf2, localVertices[i]);
            }
            _debugDraw.DrawPolygon(vertices, vertexCount, new Color(0.5f, 0.7f, 0.9f));

            localVertices = _shape2.CoreVertices;
            for (int i = 0; i < vertexCount; ++i)
            {
                vertices[i] = Box2DNet.Common.Math.Mul(xf2, localVertices[i]);
            }
            _debugDraw.DrawPolygon(vertices, vertexCount, new Color(0.5f, 0.7f, 0.9f));
        }
Example #7
0
        public override void Step(Settings settings)
        {
            //B2_NOT_USED(settings);

            if (_automated == true)
            {
                int actionCount = Box2DXMath.Max(1, k_actorCount >> 2);

                for (int i = 0; i < actionCount; ++i)
                {
                    Action();
                }
            }

            _broadPhase.Commit();

            for (int i = 0; i < k_actorCount; ++i)
            {
                Actor actor = _actors[i];
                if (actor.proxyId == PairManager.NullProxy)
                {
                    continue;
                }

                Color c = new Color();
                switch (actor.overlapCount)
                {
                case 0:
                    c.R = 0.9f; c.G = 0.9f; c.B = 0.9f;
                    break;

                case 1:
                    c.R = 0.6f; c.G = 0.9f; c.B = 0.6f;
                    break;

                default:
                    c.R = 0.9f; c.G = 0.6f; c.B = 0.6f;
                    break;
                }

                OpenGLDebugDraw.DrawAABB(actor.aabb, c);
            }

            StringBuilder strBld = new StringBuilder();

            strBld.AppendFormat("overlaps = {0}, exact = {1}, diff = {2}",
                                new object[] { _overlapCount, _overlapCountExact, _overlapCount - _overlapCountExact });
            OpenGLDebugDraw.DrawString(5, 30, strBld.ToString());
            Validate();

            ++_stepCount;
        }
Example #8
0
        public override void Step(Settings settings)
        {
            base.Step(settings);

            float         ratio  = _joint1.Ratio;
            float         L      = _joint1.Length1 + ratio * _joint1.Length2;
            StringBuilder strBld = new StringBuilder();

            strBld.AppendFormat("L1 + {0} * L2 = {1}",
                                new object[] { ratio, L });
            OpenGLDebugDraw.DrawString(5, _textLine, strBld.ToString());
            _textLine += 15;
        }
Example #9
0
        public override void Step(Settings settings)
        {
            base.Step(settings);
            OpenGLDebugDraw.DrawString(5, _textLine, "Keys: (f) toggle friction, (m) toggle motor");
            _textLine += 15;
            float         torque = _joint1.MotorTorque;
            StringBuilder strBld = new StringBuilder();

            strBld.AppendFormat("Motor Torque = {0}",
                                new object[] { torque });
            OpenGLDebugDraw.DrawString(5, _textLine, strBld.ToString());
            _textLine += 15;
        }
Example #10
0
        public override void Step(Settings settings)
        {
            base.Step(settings);

            DistanceInput input = new DistanceInput();

            input.TransformA = _transformA;
            input.TransformB = _transformB;
            input.UseRadii   = true;
            SimplexCache cache = new SimplexCache();

            cache.Count = 0;
            DistanceOutput output;

            Collision.Distance(out output, ref cache, ref input, _polygonA, _polygonB);

            StringBuilder strBld = new StringBuilder();

            strBld.AppendFormat("distance = {0}", new object[] { output.Distance });
            OpenGLDebugDraw.DrawString(5, _textLine, strBld.ToString());
            _textLine += 15;

            strBld = new StringBuilder();
            strBld.AppendFormat("iterations = {0}", new object[] { output.Iterations });
            OpenGLDebugDraw.DrawString(5, _textLine, strBld.ToString());
            _textLine += 15;

            {
                Color color = new Color(0.9f, 0.9f, 0.9f);
                int   i;
                for (i = 0; i < _polygonA.VertexCount; ++i)
                {
                    _dv[i] = Math.Mul(_transformA, _polygonA.Vertices[i]);
                }
                _debugDraw.DrawPolygon(_dv, _polygonA.VertexCount, color);

                for (i = 0; i < _polygonB.VertexCount; ++i)
                {
                    _dv[i] = Math.Mul(_transformB, _polygonB.Vertices[i]);
                }
                _debugDraw.DrawPolygon(_dv, _polygonB.VertexCount, color);
            }

            Vec2 x1 = output.PointA;
            Vec2 x2 = output.PointB;

            OpenGLDebugDraw.DrawPoint(x1, 4.0f, new Color(1, 0, 0));
            OpenGLDebugDraw.DrawSegment(x1, x2, new Color(1, 1, 0));
            OpenGLDebugDraw.DrawPoint(x2, 4.0f, new Color(1, 0, 0));
        }
Example #11
0
        public override void Step(Settings settings)
        {
            base.Step(settings);
            OpenGLDebugDraw.DrawString(5, _textLine, "Keys: (l) limits, (m) motors, (p) prismatic speed");
            _textLine += 15;
            float         torque1 = _joint1.MotorTorque;
            float         torque2 = _joint2.MotorTorque;
            float         force3  = _joint3.MotorForce;
            StringBuilder strBld  = new StringBuilder();

            strBld.AppendFormat("Motor Torque = {0}, {1} : Motor Force = {2}",
                                new object[] { torque1, torque2, force3 });
            OpenGLDebugDraw.DrawString(5, _textLine, strBld.ToString());
            _textLine += 15;
        }
Example #12
0
        private void SimulationLoop()
        {
#if GLRender
            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

            CurrentTest.SetTextLine(30);
            CurrentTest.Step(_settings);
            OpenGLDebugDraw.DrawString(5, 15, _testEntry.Name);
            openGlControl.Invalidate();//codeyu
            ErrorCode errorCode = GL.GetError();
            if (errorCode != ErrorCode.NoError)
            {
                redrawTimer.Stop();
            }
#endif
        }
Example #13
0
        private void SimulationLoop()
        {
#if GLRender
            Gl.glClear(Gl.GL_COLOR_BUFFER_BIT | Gl.GL_DEPTH_BUFFER_BIT);

            CurrentTest.SetTextLine(30);
            CurrentTest.Step(settings);
            OpenGLDebugDraw.DrawString(5, 15, testEntry.Name);

            openGlControl.Draw();

            int errorCode = 0;
            if ((errorCode = Gl.glGetError()) > 0)
            {
                redrawTimer.Stop();
            }
#endif
        }
Example #14
0
        private void MainForm_Load(object sender, EventArgs e)
        {
#if GLRender
            openGlControl_Resize(this, EventArgs.Empty);
            OpenGLDebugDraw.InitTextRenderer(openGlControl);
#endif //GLRender

            Init();
            SetView();


            chkbAabbs.Checked      = _settings.drawAABBs == 1;
            chkbCF.Checked         = _settings.drawContactForces == 1;
            chkbCN.Checked         = _settings.drawContactNormals == 1;
            chkbCom.Checked        = _settings.drawCOMs == 1;
            chkbCoreShapes.Checked = _settings.drawCoreShapes == 1;
            chkbCP.Checked         = _settings.drawContactPoints == 1;
            chkbFF.Checked         = _settings.drawFrictionForces == 1;
            chkbJoints.Checked     = _settings.drawJoints == 1 ? true : false;
            chkbObbs.Checked       = _settings.drawOBBs == 1 ? true : false;
            chkbPairs.Checked      = _settings.drawPairs == 1 ? true : false;
            chkbShapes.Checked     = _settings.drawShapes == 1 ? true : false;
            chkbStatistics.Checked = _settings.drawStats == 1 ? true : false;

            chkbToi.Checked       = _settings.enableTOI == 1 ? true : false;
            chkbWarmStart.Checked = _settings.enableWarmStarting == 1 ? true : false;

            nudVelIters.Value = _settings.velocityIterations;
            nudPosIters.Value = _settings.positionIterations;
            nudHz.Value       = (decimal)_settings.hz;

            foreach (TestEntry t in Test.g_testEntries)
            {
                cmbbTests.Items.Add(t);
            }

            _testEntry              = Test.g_testEntries[0];
            CurrentTest             = _testEntry.CreateFcn();
            cmbbTests.SelectedIndex = 0;

            redrawTimer.Interval = 16;
            redrawTimer.Enabled  = true;
        }
Example #15
0
        public override void Step(Settings settings)
        {
            base.Step(settings);

            float ratio, value;

            ratio = _joint4.Ratio;
            value = _joint1.JointAngle + ratio * _joint2.JointAngle;
            StringBuilder strBld = new StringBuilder();

            strBld.AppendFormat("theta1 + {0} * theta2 = {1}", new object[] { ratio, value });
            OpenGLDebugDraw.DrawString(5, _textLine, strBld.ToString());
            _textLine += 15;

            ratio  = _joint5.Ratio;
            value  = _joint2.JointAngle + ratio * _joint3.JointTranslation;
            strBld = new StringBuilder();
            strBld.AppendFormat("theta2 + {0} * delta = {1}", new object[] { ratio, value });
            OpenGLDebugDraw.DrawString(5, _textLine, strBld.ToString());
            _textLine += 15;
        }
Example #16
0
        public override void Step(Settings settings)
        {
            settings.pause = 1;
            base.Step(settings);
            settings.pause = 0;

            Vec2  x1, x2;
            float distance = Collision.Distance(out x1, out x2, _shape1, _body1.GetXForm(), _shape2, _body2.GetXForm());

            StringBuilder strBld = new StringBuilder();

            strBld.AppendFormat("distance = {0}", new object[] { distance });
            OpenGLDebugDraw.DrawString(5, _textLine, strBld.ToString());
            _textLine += 15;

            strBld = new StringBuilder();
            strBld.AppendFormat("iterations = {0}", new object[] { Collision.GJKIterations });
            OpenGLDebugDraw.DrawString(5, _textLine, strBld.ToString());
            _textLine += 15;

            OpenGLDebugDraw.DrawPoint(x1, 4.0f, new Color(1, 0, 0));
            OpenGLDebugDraw.DrawSegment(x1, x2, new Color(1, 0, 0));
            OpenGLDebugDraw.DrawPoint(x2, 4.0f, new Color(1, 0, 0));
        }
Example #17
0
        /*public bool key_comp(MyContactPoint lhs, MyContactPoint rhs)
         * {
         *      if( lhs.shape1 < rhs.shape1 ) return true;
         *      if( lhs.shape1 == rhs.shape1 && lhs.shape2 < rhs.shape2 ) return true;
         *      if( lhs.shape1 == rhs.shape1 && lhs.shape2 == rhs.shape2 && lhs.id.Key < rhs.id.Key ) return true;
         *      return false;
         * }*/

        public override void Step(Settings settings)
        {
            base.Step(settings);
            string oss = string.Empty;

            for (int i = 0; i < _pointCount; ++i)
            {
                switch (_points[i].state)
                {
                case ContactState.ContactAdded:
                {
                    oss = string.Empty;
                    _set.Add(_points[i], null);
                    //if( ! m_set.insert( m_points[i] ).second )
                    //{
                    //	oss << "ERROR ";
                    //}
                    //else
                    //{
                    //	oss << "      ";
                    //}
                    oss += "added:   " + _points[i].shape1.ToString() + " -> " + _points[i].shape2.ToString();
                    oss += " : " + _points[i].id.Key.ToString();
                    _strings.Enqueue(oss);
                    break;
                }

                case ContactState.ContactRemoved:
                {
                    oss = string.Empty;
                    if (!_set.ContainsKey(_points[i]))
                    {
                        oss += "ERROR ";
                    }
                    else
                    {
                        oss += "      ";
                    }
                    oss += "removed: " + _points[i].shape1.ToString() + " -> " + _points[i].shape2.ToString();
                    oss += " : " + _points[i].id.Key.ToString();
                    _strings.Enqueue(oss);
                    _set.Remove(_points[i]);
                    break;
                }

                case ContactState.ContactPersisted:
                {
                    oss = string.Empty;
                    if (!_set.ContainsKey(_points[i]))
                    {
                        oss += "ERROR persist: " + _points[i].shape1.ToString() + " -> ";
                        oss += _points[i].shape2.ToString() + " : " + _points[i].id.Key;
                        _strings.Enqueue(oss);
                    }
                    break;
                }
                }
            }

            while (_strings.Count > 15)
            {
                _strings.Dequeue();
            }

            foreach (string s in _strings)
            {
                OpenGLDebugDraw.DrawString(5, _textLine, s);
                _textLine += 15;
            }
        }
Example #18
0
        public virtual void Step(Settings settings)
        {
            float timeStep = settings.hz > 0.0f ? 1.0f / settings.hz : 0.0f;

            if (settings.pause != 0)
            {
                if (settings.singleStep != 0)
                {
                    settings.singleStep = 0;
                }
                else
                {
                    timeStep = 0.0f;
                }

                OpenGLDebugDraw.DrawString(5, _textLine, "****PAUSED****");
                _textLine += 15;
            }

            uint flags = 0;

            flags           += (uint)settings.drawShapes * (uint)DebugDraw.DrawFlags.Shape;
            flags           += (uint)settings.drawJoints * (uint)DebugDraw.DrawFlags.Joint;
            flags           += (uint)settings.drawCoreShapes * (uint)DebugDraw.DrawFlags.CoreShape;
            flags           += (uint)settings.drawAABBs * (uint)DebugDraw.DrawFlags.Aabb;
            flags           += (uint)settings.drawOBBs * (uint)DebugDraw.DrawFlags.Obb;
            flags           += (uint)settings.drawPairs * (uint)DebugDraw.DrawFlags.Pair;
            flags           += (uint)settings.drawCOMs * (uint)DebugDraw.DrawFlags.CenterOfMass;
            flags           += (uint)settings.drawController * (uint)DebugDraw.DrawFlags.Controller;
            _debugDraw.Flags = (DebugDraw.DrawFlags)flags;

            _world.SetWarmStarting(settings.enableWarmStarting > 0);
            _world.SetContinuousPhysics(settings.enableTOI > 0);

            _pointCount = 0;

            _world.Step(timeStep, settings.velocityIterations, settings.positionIterations);

            _world.Validate();

            if (_bomb != null && _bomb.IsFrozen())
            {
                _world.DestroyBody(_bomb);
                _bomb = null;
            }

            if (settings.drawStats != 0)
            {
                OpenGLDebugDraw.DrawString(5, _textLine, String.Format("proxies(max) = {0}({1}), pairs(max) = {2}({3})",
                                                                       new object[] { _world.GetProxyCount(), Box2DX.Common.Settings.MaxProxies,
                                                                                      _world.GetPairCount(), Box2DX.Common.Settings.MaxProxies }));
                _textLine += 15;

                OpenGLDebugDraw.DrawString(5, _textLine, String.Format("bodies/contacts/joints = {0}/{1}/{2}",
                                                                       new object[] { _world.GetBodyCount(), _world.GetContactCount(), _world.GetJointCount() }));
                _textLine += 15;
            }

            if (_mouseJoint != null)
            {
                Body body = _mouseJoint.GetBody2();
                Vec2 p1   = body.GetWorldPoint(_mouseJoint._localAnchor);
                Vec2 p2   = _mouseJoint._target;

                Gl.glPointSize(4.0f);
                Gl.glColor3f(0.0f, 1.0f, 0.0f);
                Gl.glBegin(Gl.GL_POINTS);
                Gl.glVertex2f(p1.X, p1.Y);
                Gl.glVertex2f(p2.X, p2.Y);
                Gl.glEnd();
                Gl.glPointSize(1.0f);

                Gl.glColor3f(0.8f, 0.8f, 0.8f);
                Gl.glBegin(Gl.GL_LINES);
                Gl.glVertex2f(p1.X, p1.Y);
                Gl.glVertex2f(p2.X, p2.Y);
                Gl.glEnd();
            }

            if (settings.drawContactPoints != 0)
            {
                //float k_forceScale = 0.01f;
                float k_axisScale = 0.3f;

                for (int i = 0; i < _pointCount; ++i)
                {
                    MyContactPoint point = _points[i];

                    if (point.state == ContactState.ContactAdded)
                    {
                        // Add
                        OpenGLDebugDraw.DrawPoint(point.position, 10.0f, new Color(0.3f, 0.95f, 0.3f));
                    }
                    else if (point.state == ContactState.ContactPersisted)
                    {
                        // Persist
                        OpenGLDebugDraw.DrawPoint(point.position, 5.0f, new Color(0.3f, 0.3f, 0.95f));
                    }
                    else
                    {
                        // Remove
                        OpenGLDebugDraw.DrawPoint(point.position, 10.0f, new Color(0.95f, 0.3f, 0.3f));
                    }

                    if (settings.drawContactNormals == 1)
                    {
                        Vec2 p1 = point.position;
                        Vec2 p2 = p1 + k_axisScale * point.normal;
                        OpenGLDebugDraw.DrawSegment(p1, p2, new Color(0.4f, 0.9f, 0.4f));
                    }
                    else if (settings.drawContactForces == 1)
                    {
                        /*Vector2 p1 = point.position;
                         * Vector2 p2 = p1 + k_forceScale * point.normalForce * point.normal;
                         * OpenGLDebugDraw.DrawSegment(p1, p2, new Color(0.9f, 0.9f, 0.3f));*/
                    }

                    if (settings.drawFrictionForces == 1)
                    {
                        /*Vector2 tangent = Vector2.Cross(point.normal, 1.0f);
                         * Vector2 p1 = point.position;
                         * Vector2 p2 = p1 + k_forceScale * point.tangentForce * tangent;
                         * OpenGLDebugDraw.DrawSegment(p1, p2, new Color(0.9f, 0.9f, 0.3f));*/
                    }
                }
            }
        }
Example #19
0
 public override void Step(Settings settings)
 {
     base.Step(settings);
     OpenGLDebugDraw.DrawString(5, _textLine, "Press 1-5 to drop stuff");
     _textLine += 15;
 }
Example #20
0
 public override void Step(Settings settings)
 {
     base.Step(settings);
     OpenGLDebugDraw.DrawString(5, _textLine, "Max toi iters = " + Box2DX.Collision.Collision.MaxToiIters +
                                ", max root iters = " + Box2DX.Collision.Collision.MaxToiRootIters);
 }
Example #21
0
 public override void Step(Settings settings)
 {
     base.Step(settings);
     OpenGLDebugDraw.DrawString(5, _textLine, "Keys: (l) limits, (s) motor");
     _textLine += 15;
 }
Example #22
0
 public override void Step(Settings settings)
 {
     base.Step(settings);
     OpenGLDebugDraw.DrawString(5, _textLine, "Press: B to launch a bullet.");
 }