Ejemplo n.º 1
0
 public override void step(TestbedSettings settings)
 {
     base.step(settings);
     float hz = settings.getSetting(TestbedSettings.Hz).value;
     if (hz > 0)
     {
         m_time += 1/hz;
     }
     m_joint.setMotorSpeed(0.05f*MathUtils.cos(m_time)*MathUtils.PI);
 }
Ejemplo n.º 2
0
        public override void step(TestbedSettings settings)
        {
            float hz = settings.getSetting(TestbedSettings.Hz).value;
            if (m_go && hz > 0.0f)
            {
                m_time += 1.0f/hz;
            }

            linearOffset.x = 6.0f*MathUtils.sin(2.0f*m_time);
            linearOffset.y = 8.0f + 4.0f*MathUtils.sin(1.0f*m_time);

            float angularOffset = 4.0f*m_time;

            m_joint.setLinearOffset(linearOffset);
            m_joint.setAngularOffset(angularOffset);

            getDebugDraw().drawPoint(linearOffset, 4.0f, color);
            base.step(settings);
            addTextLine("Keys: (s) pause");
        }
Ejemplo n.º 3
0
        public virtual void step(TestbedSettings settings)
        {
            float hz = settings.getSetting(TestbedSettings.Hz).value;
            float timeStep = hz > 0f ? 1f/hz : 0;
            if (settings.singleStep && !settings.pause)
            {
                settings.pause = true;
            }

            DebugDraw debugDraw = model.getDebugDraw();
            m_textLine = 20;

            if (title != null)
            {
                debugDraw.drawString(camera.getTransform().getExtents().x, 15, title, Color4f.WHITE);
                m_textLine += TEXT_LINE_SPACE;
            }

            if (settings.pause)
            {
                if (settings.singleStep)
                {
                    settings.singleStep = false;
                }
                else
                {
                    timeStep = 0;
                }

                debugDraw.drawString(5, m_textLine, "****PAUSED****", Color4f.WHITE);
                m_textLine += TEXT_LINE_SPACE;
            }

            DebugDrawFlags flags = 0;
            flags |= settings.getSetting(TestbedSettings.DrawShapes).enabled ? DebugDrawFlags.Shapes : 0;
            flags |= settings.getSetting(TestbedSettings.DrawJoints).enabled ? DebugDrawFlags.Joints : 0;
            flags |= settings.getSetting(TestbedSettings.DrawAABBs).enabled ? DebugDrawFlags.AABB : 0;
            flags |=
                settings.getSetting(TestbedSettings.DrawCOMs).enabled ? DebugDrawFlags.CenterOfMass : 0;
            flags |= settings.getSetting(TestbedSettings.DrawTree).enabled ? DebugDrawFlags.DynamicTree : 0;
            flags |=
                settings.getSetting(TestbedSettings.DrawWireframe).enabled
                    ? DebugDrawFlags.Wireframe
                    : 0;
            debugDraw.setFlags(flags);

            m_world.setAllowSleep(settings.getSetting(TestbedSettings.AllowSleep).enabled);
            m_world.setWarmStarting(settings.getSetting(TestbedSettings.WarmStarting).enabled);
            m_world.setSubStepping(settings.getSetting(TestbedSettings.SubStepping).enabled);
            m_world.setContinuousPhysics(settings.getSetting(TestbedSettings.ContinuousCollision).enabled);

            pointCount = 0;

            m_world.step(timeStep, settings.getSetting(TestbedSettings.VelocityIterations).value,
                settings.getSetting(TestbedSettings.PositionIterations).value);

            m_world.drawDebugData();

            if (timeStep > 0f)
            {
                ++stepCount;
            }

            debugDraw.drawString(5, m_textLine, "Engine Info", color4);
            m_textLine += TEXT_LINE_SPACE;
            debugDraw.drawString(5, m_textLine, "Framerate: " + (int) model.getCalculatedFps(),
                Color4f.WHITE);
            m_textLine += TEXT_LINE_SPACE;

            if (settings.getSetting(TestbedSettings.DrawStats).enabled)
            {
                int particleCount = m_world.getParticleCount();
                int groupCount = m_world.getParticleGroupCount();
                debugDraw.drawString(
                    5,
                    m_textLine,
                    "bodies/contacts/joints/proxies/particles/groups = " + m_world.getBodyCount() + "/"
                    + m_world.getContactCount() + "/" + m_world.getJointCount() + "/"
                    + m_world.getProxyCount() + "/" + particleCount + "/" + groupCount, Color4f.WHITE);
                m_textLine += TEXT_LINE_SPACE;

                debugDraw.drawString(5, m_textLine, "World mouse position: " + mouseWorld.ToString(),
                    Color4f.WHITE);
                m_textLine += TEXT_LINE_SPACE;

                statsList.Clear();
                Dynamics.Profile profile = getWorld().getProfile();
                profile.toDebugStrings(statsList);

                foreach (string s in statsList)
                {
                    debugDraw.drawString(5, m_textLine, s, Color4f.WHITE);
                    m_textLine += TEXT_LINE_SPACE;
                }
                m_textLine += TEXT_SECTION_SPACE;
            }

            if (settings.getSetting(TestbedSettings.DrawHelp).enabled)
            {
                debugDraw.drawString(5, m_textLine, "Help", color4);
                m_textLine += TEXT_LINE_SPACE;
                List<string> help = model.getImplSpecificHelp();
                foreach (string s in help)
                {
                    debugDraw.drawString(5, m_textLine, s, Color4f.WHITE);
                    m_textLine += TEXT_LINE_SPACE;
                }
                m_textLine += TEXT_SECTION_SPACE;
            }

            if (textList.Count != 0)
            {
                debugDraw.drawString(5, m_textLine, "Test Info", color4);
                m_textLine += TEXT_LINE_SPACE;
                foreach (string s in textList)
                {
                    debugDraw.drawString(5, m_textLine, s, Color4f.WHITE);
                    m_textLine += TEXT_LINE_SPACE;
                }
                textList.Clear();
            }

            if (mouseTracing && mouseJoint == null)
            {
                float delay = 0.1f;
                acceleration.x =
                    2/delay*(1/delay*(mouseWorld.x - mouseTracerPosition.x) - mouseTracerVelocity.x);
                acceleration.y =
                    2/delay*(1/delay*(mouseWorld.y - mouseTracerPosition.y) - mouseTracerVelocity.y);
                mouseTracerVelocity.x += timeStep*acceleration.x;
                mouseTracerVelocity.y += timeStep*acceleration.y;
                mouseTracerPosition.x += timeStep*mouseTracerVelocity.x;
                mouseTracerPosition.y += timeStep*mouseTracerVelocity.y;
                pshape.m_p.set(mouseTracerPosition);
                pshape.m_radius = 2;
                pcallback.init(m_world, pshape, mouseTracerVelocity);
                pshape.computeAABB(paabb, identity, 0);
                m_world.queryAABB(pcallback, paabb);
            }

            if (mouseJoint != null)
            {
                mouseJoint.getAnchorB(ref p1);
                Vec2 p2 = mouseJoint.getTarget();

                debugDraw.drawSegment(p1, p2, mouseColor);
            }

            if (bombSpawning)
            {
                debugDraw.drawSegment(bombSpawnPoint, bombMousePoint, Color4f.WHITE);
            }

            if (settings.getSetting(TestbedSettings.DrawContactPoints).enabled)
            {
                float k_impulseScale = 0.1f;
                float axisScale = 0.3f;

                for (int i = 0; i < pointCount; i++)
                {

                    ContactPoint point = points[i];

                    if (point.state == Collision.Collision.PointState.ADD_STATE)
                    {
                        debugDraw.drawPoint(point.position, 10f, color1);
                    }
                    else if (point.state == Collision.Collision.PointState.PERSIST_STATE)
                    {
                        debugDraw.drawPoint(point.position, 5f, color2);
                    }

                    if (settings.getSetting(TestbedSettings.DrawContactNormals).enabled)
                    {
                        p1.set(point.position);
                        p2.set(point.normal);
                        p2.mulLocal(axisScale);
                        p2.addLocal(p1);
                        debugDraw.drawSegment(p1, p2, color3);

                    }
                    else if (settings.getSetting(TestbedSettings.DrawContactImpulses).enabled)
                    {
                        p1.set(point.position);
                        p2.set(point.normal);
                        p2.mulLocal(k_impulseScale);
                        p2.mulLocal(point.normalImpulse);
                        p2.addLocal(p1);
                        debugDraw.drawSegment(p1, p2, color5);
                    }

                    if (settings.getSetting(TestbedSettings.DrawFrictionImpulses).enabled)
                    {
                        Vec2.crossToOutUnsafe(point.normal, 1, ref tangent);
                        p1.set(point.position);
                        p2.set(tangent);
                        p2.mulLocal(k_impulseScale);
                        p2.mulLocal(point.tangentImpulse);
                        p2.addLocal(p1);
                        debugDraw.drawSegment(p1, p2, color5);
                    }
                }
            }
        }
Ejemplo n.º 4
0
        public override void step(TestbedSettings 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 = MathUtils.max(1, _e_actorCount >> 2);

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

            Query();
            RayCast();
            Vec2[] vecs = vecPool.get(4);

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

                Color4f c = new Color4f(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);
                }
                actor.aabb.getVertices(vecs);
                getDebugDraw().drawPolygon(vecs, 4, c);
            }

            Color4f c2 = new Color4f(0.7f, 0.7f, 0.7f);
            m_queryAABB.getVertices(vecs);
            getDebugDraw().drawPolygon(vecs, 4, c2);

            getDebugDraw().drawSegment(m_rayCastInput.p1, m_rayCastInput.p2, c2);

            Color4f c1 = new Color4f(0.2f, 0.9f, 0.2f);
            Color4f c3 = new Color4f(0.9f, 0.2f, 0.2f);
            getDebugDraw().drawPoint(m_rayCastInput.p1, 6.0f, c1);
            getDebugDraw().drawPoint(m_rayCastInput.p2, 6.0f, c3);

            if (m_rayActor != null)
            {
                Color4f cr = new Color4f(0.2f, 0.2f, 0.9f);
                m_rayCastInput.p2.sub(m_rayCastInput.p1);
                m_rayCastInput.p2.mulLocal(m_rayActor.fraction);
                m_rayCastInput.p2.addLocal(m_rayCastInput.p1);
                Vec2 p = m_rayCastInput.p2;
                getDebugDraw().drawPoint(p, 6.0f, cr);
            }

            ++m_stepCount;

            if (settings.getSetting(TestbedSettings.DrawTree).enabled)
            {
                m_tree.drawTree(getDebugDraw());
            }

            getDebugDraw().drawString(5, 30,
                "(c)reate proxy, (d)estroy proxy, (a)utomate", Color4f.WHITE);
        }