Пример #1
0
        public virtual void PreSolve(Contact contact, ref Manifold oldManifold)
        {
            Manifold manifold;
            contact.GetManifold(out manifold);

	        if (manifold._pointCount == 0)
	        {
		        return;
	        }

	        Fixture fixtureA = contact.GetFixtureA();
	        Fixture fixtureB = contact.GetFixtureB();

            FixedArray2<PointState> state1, state2;
	        Collision.GetPointStates(out state1, out state2, ref oldManifold, ref manifold);

	        WorldManifold worldManifold;
	        contact.GetWorldManifold(out worldManifold);

	        for (int i = 0; i < manifold._pointCount && _pointCount < k_maxContactPoints; ++i)
	        {
                if (fixtureA == null)
                {
                    _points[i] = new ContactPoint();
                }
		        ContactPoint cp = _points[_pointCount];
		        cp.fixtureA = fixtureA;
		        cp.fixtureB = fixtureB;
		        cp.position = worldManifold._points[i];
		        cp.normal = worldManifold._normal;
		        cp.state = state2[i];
                _points[_pointCount] = cp;
		        ++_pointCount;
	        }
        }
Пример #2
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;
                }

                _debugDraw.DrawString(50, _textLine, "****PAUSED****");
                _textLine += 15;
            }

            uint flags = 0;

            flags           += settings.drawShapes * (uint)DebugDrawFlags.Shape;
            flags           += settings.drawJoints * (uint)DebugDrawFlags.Joint;
            flags           += settings.drawAABBs * (uint)DebugDrawFlags.AABB;
            flags           += settings.drawPairs * (uint)DebugDrawFlags.Pair;
            flags           += settings.drawCOMs * (uint)DebugDrawFlags.CenterOfMass;
            _debugDraw.Flags = (DebugDrawFlags)flags;

            _world.WarmStarting      = (settings.enableWarmStarting > 0);
            _world.ContinuousPhysics = (settings.enableContinuous > 0);

            _pointCount = 0;

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

            _world.DrawDebugData();

            if (timeStep > 0.0f)
            {
                ++_stepCount;
            }

            if (settings.drawStats > 0)
            {
                _debugDraw.DrawString(50, _textLine, "bodies/contacts/joints/proxies = {0:n}/{1:n}/{2:n}",
                                      _world.BodyCount, _world.ContactCount, _world.JointCount, _world.ProxyCount);
                _textLine += 15;
            }

            if (_mouseJoint != null)
            {
                Vector2 p1 = _mouseJoint.GetAnchorB();
                Vector2 p2 = _mouseJoint.GetTarget();

                _debugDraw.DrawPoint(p1, 0.5f, new Color(0.0f, 1.0f, 0.0f));
                _debugDraw.DrawPoint(p1, 0.5f, new Color(0.0f, 1.0f, 0.0f));
                _debugDraw.DrawSegment(p1, p2, new Color(0.8f, 0.8f, 0.8f));
            }

            if (_bombSpawning)
            {
                _debugDraw.DrawPoint(_bombSpawnPoint, 0.5f, new Color(0.0f, 0.0f, 1.0f));
                _debugDraw.DrawSegment(_mouseWorld, _bombSpawnPoint, new Color(0.8f, 0.8f, 0.8f));
            }

            if (settings.drawContactPoints > 0)
            {
                //float k_impulseScale = 0.1f;
                const float k_axisScale = 0.3f;

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

                    if (point.state == PointState.Add)
                    {
                        // Add
                        _debugDraw.DrawPoint(point.position, 1.5f, new Color(0.3f, 0.95f, 0.3f));
                    }
                    else if (point.state == PointState.Persist)
                    {
                        // Persist
                        _debugDraw.DrawPoint(point.position, 0.65f, new Color(0.3f, 0.3f, 0.95f));
                    }

                    if (settings.drawContactNormals == 1)
                    {
                        Vector2 p1 = point.position;
                        Vector2 p2 = p1 + k_axisScale * point.normal;
                        _debugDraw.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;
                        //DrawSegment(p1, p2, Color(0.9f, 0.9f, 0.3f));
                    }

                    if (settings.drawFrictionForces == 1)
                    {
                        //Vector2 tangent = b2Cross(point.normal, 1.0f);
                        //Vector2 p1 = point.position;
                        //Vector2 p2 = p1 + k_forceScale * point.tangentForce * tangent;
                        //DrawSegment(p1, p2, Color(0.9f, 0.9f, 0.3f));
                    }
                }
            }
        }