Global tuning constants based on MKS units and various integer maximums (vertices per shape, pairs, etc.).
Esempio n. 1
0
        protected override void Draw(Settings settings)
        {
            base.Draw(settings);

            if (b2DistanceProxy.b2_gjkCalls > 0)
            {
                m_debugDraw.DrawString(5, m_textLine, "gjk calls = {0}, ave gjk iters = {1:000.0}, max gjk iters = {2}",
                                       b2DistanceProxy.b2_gjkCalls,
                                       b2DistanceProxy.b2_gjkIters / (float)(b2DistanceProxy.b2_gjkCalls),
                                       b2DistanceProxy.b2_gjkMaxIters);
                m_textLine += 15;
            }

            if (b2TimeOfImpact.b2_toiCalls > 0)
            {
                m_debugDraw.DrawString(5, m_textLine, "toi calls = {0}, ave toi iters = {1:000.0}, max toi iters = {2}",
                                       b2TimeOfImpact.b2_toiCalls,
                                       b2TimeOfImpact.b2_toiIters / (float)(b2TimeOfImpact.b2_toiCalls),
                                       b2TimeOfImpact.b2_toiMaxRootIters);
                m_textLine += 15;

                m_debugDraw.DrawString(5, m_textLine, "ave toi root iters = {0:000.0}, max toi root iters = {1}",
                                       b2TimeOfImpact.b2_toiRootIters / (float)(b2TimeOfImpact.b2_toiCalls),
                                       b2TimeOfImpact.b2_toiMaxRootIters);
                m_textLine += 15;
            }
        }
Esempio n. 2
0
        protected override void Draw(Settings settings)
        {
            base.Draw(settings);

            b2Manifold manifold = new b2Manifold();
            b2Collision.b2CollidePolygons(manifold, m_polygonA, ref m_transformA, m_polygonB, ref m_transformB);

            b2WorldManifold worldManifold = new b2WorldManifold();
            worldManifold.Initialize(manifold, ref m_transformA, m_polygonA.Radius, ref m_transformB, m_polygonB.Radius);

            m_debugDraw.DrawString(5, m_textLine, "point count = {0}", manifold.pointCount);
            m_textLine += 15;

            {
                b2Color color = new b2Color(0.9f, 0.9f, 0.9f);
                b2Vec2[] v = new b2Vec2[b2Settings.b2_maxPolygonVertices];
                for (int i = 0; i < m_polygonA.VertexCount; ++i)
                {
                    v[i] = b2Math.b2Mul(m_transformA, m_polygonA.Vertices[i]);
                }
                m_debugDraw.DrawPolygon(v, m_polygonA.VertexCount, color);

                for (int i = 0; i < m_polygonB.VertexCount; ++i)
                {
                    v[i] = b2Math.b2Mul(m_transformB, m_polygonB.Vertices[i]);
                }
                m_debugDraw.DrawPolygon(v, m_polygonB.VertexCount, color);
            }

            for (int i = 0; i < manifold.pointCount; ++i)
            {
                m_debugDraw.DrawPoint(worldManifold.points[i], 4.0f, new b2Color(0.9f, 0.3f, 0.3f));
            }
        }
Esempio n. 3
0
 protected override void Draw(Settings settings)
 {
     base.Draw(settings);
     m_debugDraw.DrawString(5, m_textLine, "Press: (c) create a shape, (d) destroy a shape.");
     m_textLine += 15;
     m_debugDraw.DrawString(5, m_textLine, "sensor = {0}", m_sensor);
     m_textLine += 15;
 }
Esempio n. 4
0
        protected override void Draw(Settings settings)
        {
            base.Draw(settings);

            float ratio = m_joint1.GetRatio();
            float L = m_joint1.GetLengthA() + ratio * m_joint1.GetLengthB();
            m_debugDraw.DrawString(5, m_textLine, "L1 + {0:0000.00} * L2 = {1:0000.00}", ratio, L);
            m_textLine += 15;
        }
Esempio n. 5
0
        protected override void Draw(Settings settings)
        {
            base.Draw(settings);

            m_debugDraw.DrawString(5, m_textLine, "Keys: (l) limits, (m) motors, (s) speed");
            m_textLine += 15;
            float force = m_joint.GetMotorForce(settings.hz);
            m_debugDraw.DrawString(5, m_textLine, "Motor Force = {0:0000}", (float) force);
            m_textLine += 15;
        }
Esempio n. 6
0
        public override void Step(Settings settings)
        {
            base.Step(settings);

            //b2DynamicTree* tree = &m_world->m_contactManager.m_broadPhase.m_tree;

            //if (m_stepCount == 400)
            //{
            //    tree->RebuildBottomUp();
            //}
        }
Esempio n. 7
0
        protected override void Draw(Settings settings)
        {
            base.Draw(settings);

            m_rope.Draw(m_debugDraw);

            m_debugDraw.DrawString(5, m_textLine, "Press (q,e) to adjust target angle");
            m_textLine += 15;
            m_debugDraw.DrawString(5, m_textLine, "Target angle = {0} degrees", m_angle * 180.0f / b2Settings.b2_pi);
            m_textLine += 15;
        }
Esempio n. 8
0
        public override void Step(Settings settings)
        {
            float dt = settings.hz > 0.0f ? 1.0f / settings.hz : 0.0f;

            if (settings.pause && settings.singleStep)
            {
                dt = 0.0f;
            }

            m_rope.Step(dt, 1);

            base.Step(settings);
        }
Esempio n. 9
0
        protected override void Draw(Settings settings)
        {
            base.Draw(settings);

            for (int i = 0; i < e_actorCount; ++i)
            {
                Actor actor = m_actors[i];
                if (actor.proxyId == b2_nullNode)
                    continue;

                b2Color c = new b2Color(0.9f, 0.9f, 0.9f);
                if (actor == m_rayActor && actor.overlap)
                {
                    c.Set(0.9f, 0.6f, 0.6f);
                }
                else if (actor == m_rayActor)
                {
                    c.Set(0.6f, 0.9f, 0.6f);
                }
                else if (actor.overlap)
                {
                    c.Set(0.6f, 0.6f, 0.9f);
                }

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

            b2Color cc = new b2Color(0.7f, 0.7f, 0.7f);
            m_debugDraw.DrawAABB(m_queryAABB, cc);

            m_debugDraw.DrawSegment(m_rayCastInput.p1, m_rayCastInput.p2, cc);

            b2Color c1 = new b2Color(0.2f, 0.9f, 0.2f);
            b2Color c2 = new b2Color(0.9f, 0.2f, 0.2f);
            m_debugDraw.DrawPoint(m_rayCastInput.p1, 6.0f, c1);
            m_debugDraw.DrawPoint(m_rayCastInput.p2, 6.0f, c2);

            if (m_rayActor != null)
            {
                b2Color cr = new b2Color(0.2f, 0.2f, 0.9f);
                b2Vec2 p = m_rayCastInput.p1 + m_rayActor.fraction * (m_rayCastInput.p2 - m_rayCastInput.p1);
                m_debugDraw.DrawPoint(p, 6.0f, cr);
            }

            {
                int height = m_tree.GetHeight();
                m_debugDraw.DrawString(5, m_textLine, "dynamic tree height = {0}", height);
                m_textLine += 15;
            }
        }
Esempio n. 10
0
        public override void Step(Settings settings)
        {
            base.Step(settings);

            //for (int32 i = 0; i < e_count; ++i)
            //{
            //    printf("%g ", m_bodies[i]->GetWorldCenter().y);
            //}

            //for (int32 i = 0; i < e_count; ++i)
            //{
            //    printf("%g ", m_bodies[i]->GetLinearVelocity().y);
            //}

            //printf("\n");
        }
Esempio n. 11
0
        protected override void Draw(Settings settings)
        {
            base.Draw(settings);

            b2DistanceInput input = b2DistanceInput.Create();
            input.proxyA.Set(m_polygonA, 0);
            input.proxyB.Set(m_polygonB, 0);
            input.transformA = m_transformA;
            input.transformB = m_transformB;
            input.useRadii = true;
            b2SimplexCache cache = b2SimplexCache.Create();
            cache.count = 0;
            b2DistanceOutput output = new b2DistanceOutput();
            b2Simplex.b2Distance(ref output, ref cache, ref input);

            m_debugDraw.DrawString(5, m_textLine, "distance = {0}", output.distance);
            m_textLine += 15;

            m_debugDraw.DrawString(5, m_textLine, "iterations = {0}", output.iterations);
            m_textLine += 15;

            {
                b2Color color = new b2Color(0.9f, 0.9f, 0.9f);
                b2Vec2[] v = new b2Vec2[b2Settings.b2_maxPolygonVertices];
                for (int i = 0; i < m_polygonA.VertexCount; ++i)
                {
                    v[i] = b2Math.b2Mul(m_transformA, m_polygonA.Vertices[i]);
                }
                m_debugDraw.DrawPolygon(v, m_polygonA.VertexCount, color);

                for (int i = 0; i < m_polygonB.VertexCount; ++i)
                {
                    v[i] = b2Math.b2Mul(m_transformB, m_polygonB.Vertices[i]);
                }
                m_debugDraw.DrawPolygon(v, m_polygonB.VertexCount, color);
            }

            b2Vec2 x1 = output.pointA;
            b2Vec2 x2 = output.pointB;

            b2Color c1 = new b2Color(1.0f, 0.0f, 0.0f);
            m_debugDraw.DrawPoint(x1, 4.0f, c1);

            b2Color c2 = new b2Color(1.0f, 1.0f, 0.0f);
            m_debugDraw.DrawPoint(x2, 4.0f, c2);
        }
Esempio n. 12
0
        public override void Step(Settings settings)
        {
            base.Step(settings);

            if (m_count < e_count)
            {
                b2BodyDef bd  = new b2BodyDef();
                bd.type = b2BodyType.b2_dynamicBody;
                bd.position.Set(0.0f, 10.0f);
                b2Body body = m_world.CreateBody(bd);

                b2PolygonShape shape = new b2PolygonShape();
                shape.SetAsBox(0.125f, 0.125f);
                body.CreateFixture(shape, 1.0f);

                ++m_count;
            }
        }
Esempio n. 13
0
        protected override void Draw(Settings settings)
        {
            base.Draw(settings);

            m_debugDraw.DrawString(5, m_textLine, "Keys: left = a, brake = s, right = d, hz down = q, hz up = e");
            m_textLine += 15;
            m_debugDraw.DrawString(5, m_textLine, "frequency = {0} hz, damping ratio = {1}", m_hz, m_zeta);
            m_textLine += 15;
        }
Esempio n. 14
0
        public override void Step(Settings settings)
        {
            b2Vec2 v = m_character.LinearVelocity;
            v.x = -5.0f;
            m_character.LinearVelocity = v;

            base.Step(settings);
        }
Esempio n. 15
0
        protected override void Draw(Settings settings)
        {
            base.Draw(settings);

            m_debugDraw.DrawString(5, m_textLine, "This demonstrates a soft distance joint.");
            m_textLine += 15;
            m_debugDraw.DrawString(5, m_textLine, "Press: (b) to delete a body, (j) to delete a joint");
            m_textLine += 15;
        }
Esempio n. 16
0
        protected override void Draw(Settings settings)
        {
            base.Draw(settings);
            m_debugDraw.DrawString(5, m_textLine, "Keys: (l) limits, (m) motor");
            m_textLine += 15;

            //if (m_stepCount == 360)
            //{
            //    m_ball->SetTransform(b2Vec2(0.0f, 0.5f), 0.0f);
            //}

            //float32 torque1 = m_joint1->GetMotorTorque();
            //m_debugDraw.DrawString(5, m_textLine, "Motor Torque = %4.0f, %4.0f : Motor Force = %4.0f", (float) torque1, (float) torque2, (float) force3);
            //m_textLine += 15;
        }
Esempio n. 17
0
        protected override void Draw(Settings settings)
        {
            base.Draw(settings);

            m_debugDraw.DrawString(5, m_textLine, "Keys: left = a, brake = s, right = d, toggle motor = m");
            m_textLine += 15;
        }
Esempio n. 18
0
 public override void Step(Settings settings)
 {
     settings.viewCenter.x = m_car.Position.x;
     base.Step(settings);
 }
Esempio n. 19
0
        public override void Step(Settings settings)
        {
            if (m_stepCount == 12)
            {
                m_stepCount += 0;
            }

            base.Step(settings);

            if (m_stepCount % 60 == 0)
            {
                //Launch();
            }
        }
Esempio n. 20
0
        public override void Step(Settings settings)
        {
            //bool sleeping = true;
            for (b2Body b = m_world.BodyList; b != null; b = b.Next)
            {
                if (b.BodyType != b2BodyType.b2_dynamicBody)
                {
                    continue;
                }

                //if (b->IsAwake())
                //{
                //    sleeping = false;
                //}
            }

            if (m_stepCount == 180)
            {
                m_stepCount += 0;
            }

            //if (sleeping)
            //{
            //    CreateCircle();
            //}

            base.Step(settings);

            for (b2Body b = m_world.BodyList; b != null; b = b.Next)
            {
                if (b.BodyType != b2BodyType.b2_dynamicBody)
                {
                    continue;
                }

                b2Vec2 p = b.Position;
                if (p.x <= -10.0f || 10.0f <= p.x || p.y <= 0.0f || 20.0f <= p.y)
                {
                    p.x += 0.0f;
                }
            }
        }
Esempio n. 21
0
        protected override void Draw(Settings settings)
        {
            base.Draw(settings);

            m_debugDraw.DrawString(5, m_textLine, "Press 1-5 to drop stuff");
            m_textLine += 15;

            float L = 25.0f;
            b2Vec2 point1 = new b2Vec2(0.0f, 10.0f);
            b2Vec2 d = new b2Vec2(L * (float)Math.Cos(m_angle), -L * b2Math.b2Abs((float)Math.Sin(m_angle)));
            b2Vec2 point2 = point1 + d;

            EdgeShapesCallback callback = new EdgeShapesCallback();

            m_world.RayCast(callback, point1, point2);

            if (callback.m_fixture != null)
            {
                m_debugDraw.DrawPoint(callback.m_point, 5.0f, new b2Color(0.4f, 0.9f, 0.4f));

                m_debugDraw.DrawSegment(point1, callback.m_point, new b2Color(0.8f, 0.8f, 0.8f));

                b2Vec2 head = callback.m_point + 0.5f * callback.m_normal;
                m_debugDraw.DrawSegment(callback.m_point, head, new b2Color(0.9f, 0.9f, 0.4f));
            }
            else
            {
                m_debugDraw.DrawSegment(point1, point2, new b2Color(0.8f, 0.8f, 0.8f));
            }
        }
Esempio n. 22
0
        public override void Step(Settings settings)
        {
            m_rayActor = null;
            for (int i = 0; i < e_actorCount; ++i)
            {
                m_actors[i].fraction = 1.0f;
                m_actors[i].overlap = false;
            }

            if (m_automated == true)
            {
                int actionCount = Math.Max(1, e_actorCount >> 2);

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

            Query();
            RayCast();

            ++m_stepCount;
        }
Esempio n. 23
0
        protected override void Draw(Settings settings)
        {
            base.Draw(settings);

            b2ContactManager cm = m_world.ContactManager;
            int height = cm.BroadPhase.GetTreeHeight();
            int leafCount = cm.BroadPhase.GetProxyCount();
            int minimumNodeCount = 2 * leafCount - 1;
            float minimumHeight = (float)Math.Ceiling((float)Math.Log(minimumNodeCount) / (float)Math.Log(2.0f));
            m_debugDraw.DrawString(5, m_textLine, "dynamic tree height = {0}, min = {1}", height, minimumHeight);
            m_textLine += 15;

            m_debugDraw.DrawString(5, m_textLine, "create time = {0:000000.00} ms, fixture count = {1}",
                                   m_createTime, m_fixtureCount);
            m_textLine += 15;
        }
Esempio n. 24
0
        protected override void Draw(Settings settings)
        {
            base.Draw(settings);

            float ratio, value;

            ratio = m_joint4.GetRatio();
            value = m_joint1.GetJointAngle() + ratio * m_joint2.GetJointAngle();
            m_debugDraw.DrawString(5, m_textLine, "theta1 + {0:0000.00} * theta2 = {1:0000.00}", ratio, value);
            m_textLine += 15;

            ratio = m_joint5.GetRatio();
            value = m_joint2.GetJointAngle() + ratio * m_joint3.GetJointTranslation();
            m_debugDraw.DrawString(5, m_textLine, "theta2 + {0:0000.00} * delta = {1:0000.00}", ratio, value);
            m_textLine += 15;
        }
Esempio n. 25
0
        protected override void Draw(Settings settings)
        {
            base.Draw(settings);

            m_debugDraw.DrawString(5, m_textLine, "Press 'a' to control the flippers");
            m_textLine += 15;
        }
Esempio n. 26
0
 protected override void Draw(Settings settings)
 {
     base.Draw(settings);
     m_debugDraw.DrawString(5, m_textLine, "Keys: (f) toggle friction, (m) toggle motor");
     m_textLine += 15;
     float torque = m_joint1.GetMotorTorque(settings.hz);
     m_debugDraw.DrawString(5, m_textLine, "Motor Torque = {0:00000}", torque);
     m_textLine += 15;
 }
Esempio n. 27
0
        public override void Step(Settings settings)
        {
            bool advanceRay = !settings.pause || settings.singleStep;

            base.Step(settings);

            if (advanceRay)
            {
                m_angle += 0.25f * b2Settings.b2_pi / 180.0f;
            }
        }
Esempio n. 28
0
        public override void Step(Settings settings)
        {
            if (m_button)
            {
                m_leftJoint.SetMotorSpeed(20.0f);
                m_rightJoint.SetMotorSpeed(-20.0f);
            }
            else
            {
                m_leftJoint.SetMotorSpeed(-10.0f);
                m_rightJoint.SetMotorSpeed(10.0f);
            }

            base.Step(settings);
        }
Esempio n. 29
0
        protected override void Draw(Settings settings)
        {
            base.Draw(settings);

            m_debugDraw.DrawString(5, m_textLine, "Press 'c' to create a circle.");
            m_textLine += 15;
        }
Esempio n. 30
0
        protected override void Draw(Settings settings)
        {
            base.Draw(settings);

            b2Sweep sweepA = new b2Sweep();
            sweepA.alpha0 = 0;
            sweepA.c0.Set(24.0f, -60.0f);
            sweepA.a0 = 2.95f;
            sweepA.c = sweepA.c0;
            sweepA.a = sweepA.a0;
            sweepA.localCenter.SetZero();

            b2Sweep sweepB = new b2Sweep();
            sweepB.alpha0 = 0;
            sweepB.c0.Set(53.474274f, -50.252514f);
            sweepB.a0 = 513.36676f; // - 162.0f * b2_pi;
            sweepB.c.Set(54.595478f, -51.083473f);
            sweepB.a = 513.62781f; //  - 162.0f * b2_pi;
            sweepB.localCenter.SetZero();

            //sweepB.a0 -= 300.0f * b2_pi;
            //sweepB.a -= 300.0f * b2_pi;

            b2TOIInput input = b2TOIInput.Create();
            input.proxyA.Set(m_shapeA, 0);
            input.proxyB.Set(m_shapeB, 0);
            input.sweepA = sweepA;
            input.sweepB = sweepB;
            input.tMax = 1.0f;

            b2TOIOutput output;
            b2TimeOfImpact.Compute(out output, ref input);

            m_debugDraw.DrawString(5, m_textLine, "toi = {0}", output.t);
            m_textLine += 15;

            m_debugDraw.DrawString(5, m_textLine, "max toi iters = {0}, max root iters = {1}",
                                   b2TimeOfImpact.b2_toiMaxIters, b2TimeOfImpact.b2_toiMaxRootIters);
            m_textLine += 15;

            b2Vec2[] vertices = new b2Vec2[b2Settings.b2_maxPolygonVertices];

            b2Transform transformA;
            sweepA.GetTransform(out transformA, 0.0f);
            for (int i = 0; i < m_shapeA.VertexCount; ++i)
            {
                vertices[i] = b2Math.b2Mul(transformA, m_shapeA.Vertices[i]);
            }
            m_debugDraw.DrawPolygon(vertices, m_shapeA.VertexCount, new b2Color(0.9f, 0.9f, 0.9f));

            b2Transform transformB;
            sweepB.GetTransform(out transformB, 0.0f);

            b2Vec2 localPoint = new b2Vec2(2.0f, -0.1f);

            for (int i = 0; i < m_shapeB.VertexCount; ++i)
            {
                vertices[i] = b2Math.b2Mul(transformB, m_shapeB.Vertices[i]);
            }
            m_debugDraw.DrawPolygon(vertices, m_shapeB.VertexCount, new b2Color(0.5f, 0.9f, 0.5f));

            sweepB.GetTransform(out transformB, output.t);
            for (int i = 0; i < m_shapeB.VertexCount; ++i)
            {
                vertices[i] = b2Math.b2Mul(transformB, m_shapeB.Vertices[i]);
            }
            m_debugDraw.DrawPolygon(vertices, m_shapeB.VertexCount, new b2Color(0.5f, 0.7f, 0.9f));

            sweepB.GetTransform(out transformB, 1.0f);
            for (int i = 0; i < m_shapeB.VertexCount; ++i)
            {
                vertices[i] = b2Math.b2Mul(transformB, m_shapeB.Vertices[i]);
            }
            m_debugDraw.DrawPolygon(vertices, m_shapeB.VertexCount, new b2Color(0.9f, 0.5f, 0.5f));

#if false
        for (float t = 0.0f; t < 1.0f; t += 0.1f)
        {
            sweepB.GetTransform(ref transformB, t);
            for (int i = 0; i < m_shapeB.VertexCount; ++i)
            {
                vertices[i] = b2Math.b2Mul(transformB, m_shapeB.Vertices[i]);
            }
            m_debugDraw.DrawPolygon(vertices, m_shapeB.VertexCount, new b2Color(0.9f, 0.5f, 0.5f));
        }
#endif
        }