示例#1
0
 public Fixture()
 {
     m_userData = null;
     m_body = null;
     m_next = null;
     m_proxies = null;
     m_proxyCount = 0;
     m_shape = null;
     m_filter = new Filter();
 }
示例#2
0
 public FixtureDef()
 {
     shape = null;
     userData = null;
     friction = 0.2f;
     restitution = 0f;
     density = 0f;
     filter = new Filter();
     _isSensor = false;
 }
示例#3
0
 /**
    * The shape, this must be set. The shape will be cloned, so you can create the shape on the
    * stack.
    */
 public void setShape(Shape shape)
 {
     this.shape = shape;
 }
示例#4
0
        public void destroy()
        {
            // The proxies must be destroyed before calling this.
            Debug.Assert(m_proxyCount == 0);

            // Free the child shape.
            m_shape = null;
            m_proxies = null;
            m_next = null;

            // TODO pool shapes
            // TODO pool fixtures
        }
示例#5
0
文件: Body.cs 项目: Nomad1/sharpbox2d
        /**
           * Creates a fixture from a shape and attach it to this body. This is a convenience function. Use
           * FixtureDef if you need to set parameters like friction, restitution, user data, or filtering.
           * If the density is non-zero, this function automatically updates the mass of the body.
           *
           * @param shape the shape to be cloned.
           * @param density the shape density (set to zero for static bodies).
           * @warning This function is locked during callbacks.
           */
        public Fixture createFixture(Shape shape, float density)
        {
            fixDef.shape = shape;
            fixDef.density = density;

            return createFixture(fixDef);
        }
示例#6
0
        // We need separation create/destroy functions from the constructor/destructor because
        // the destructor cannot access the allocator (no destructor arguments allowed by C++).
        public void create(Body body, FixtureDef def)
        {
            m_userData = def.userData;
            m_friction = def.friction;
            m_restitution = def.restitution;

            m_body = body;
            m_next = null;

            m_filter.set(def.filter);

            m_isSensor = def._isSensor;

            m_shape = def.shape.clone();

            // Reserve proxy space
            int childCount = m_shape.getChildCount();
            if (m_proxies == null)
            {
                m_proxies = new FixtureProxy[childCount];
                for (int i = 0; i < childCount; i++)
                {
                    m_proxies[i] = new FixtureProxy();
                    m_proxies[i].fixture = null;
                    m_proxies[i].proxyId = (int) BroadPhaseProxy.Null;
                }
            }

            if (m_proxies.Length < childCount)
            {
                FixtureProxy[] old = m_proxies;
                int newLen = MathUtils.max(old.Length*2, childCount);
                m_proxies = new FixtureProxy[newLen];
                Array.Copy(old, 0, m_proxies, 0, old.Length);
                for (int i = 0; i < newLen; i++)
                {
                    if (i >= old.Length)
                    {
                        m_proxies[i] = new FixtureProxy();
                    }
                    m_proxies[i].fixture = null;
                    m_proxies[i].proxyId = (int) BroadPhaseProxy.Null;
                }
            }
            m_proxyCount = 0;

            m_density = def.density;
        }
示例#7
0
 public virtual void processShape(Shape shape, long tag)
 {
 }
示例#8
0
 public void init(World world, Shape shape, Vec2 velocity)
 {
     this.world = world;
     this.shape = shape;
     this.velocity = velocity;
 }
示例#9
0
 /**
    * Destroy particles inside a shape. This function is locked during callbacks. In addition, this
    * function immediately destroys particles in the shape in contrast to DestroyParticle() which
    * defers the destruction until the next simulation step.
    *
    * @param Shape which encloses particles that should be destroyed.
    * @param Transform applied to the shape.
    * @param Whether to call the world b2DestructionListener for each particle destroyed.
    * @warning This function is locked during callbacks.
    * @return Number of particles destroyed.
    */
 public int destroyParticlesInShape(Shape shape, Transform xf, bool callDestructionListener)
 {
     Debug.Assert(isLocked() == false);
     if (isLocked())
     {
         return 0;
     }
     return m_particleSystem.destroyParticlesInShape(shape, xf, callDestructionListener);
 }
示例#10
0
 public long getTag(Shape shape)
 {
     return default(long);
 }
示例#11
0
 /**
    * Destroy particles inside a shape without enabling the destruction callback for destroyed
    * particles. This function is locked during callbacks. For more information see
    * DestroyParticleInShape(Shape&, Transform&,bool).
    *
    * @param Shape which encloses particles that should be destroyed.
    * @param Transform applied to the shape.
    * @warning This function is locked during callbacks.
    * @return Number of particles destroyed.
    */
 public int destroyParticlesInShape(Shape shape, Transform xf)
 {
     return destroyParticlesInShape(shape, xf, false);
 }
示例#12
0
        /**
        * Determine if two generic shapes overlap.
        *
        * @param shapeA
        * @param shapeB
        * @param xfA
        * @param xfB
        * @return
        */
        public bool testOverlap(Shape shapeA, int indexA, Shape shapeB, int indexB,
            Transform xfA, Transform xfB)
        {
            input.proxyA.set(shapeA, indexA);
            input.proxyB.set(shapeB, indexB);
            input.transformA.set(xfA);
            input.transformB.set(xfB);
            input.useRadii = true;

            cache.count = 0;

            pool.getDistance().distance(output, cache, input);
            // djm note: anything significant about 10.0f?
            return output.distance < 10.0f*Settings.EPSILON;
        }
示例#13
0
        /**
         * Initialize the proxy using the given shape. The shape must remain in scope while the proxy is
         * in use.
         */
        public void set(Shape shape, int index)
        {
            switch (shape.getType())
            {
                case ShapeType.CIRCLE:
                    CircleShape circle = (CircleShape) shape;
                    m_vertices[0].set(circle.m_p);
                    m_count = 1;
                    m_radius = circle.m_radius;

                    break;
                case ShapeType.POLYGON:
                    PolygonShape poly = (PolygonShape) shape;
                    m_count = poly.m_count;
                    m_radius = poly.m_radius;
                    for (int i = 0; i < m_count; i++)
                    {
                        m_vertices[i].set(poly.m_vertices[i]);
                    }
                    break;
                case ShapeType.CHAIN:
                    ChainShape chain = (ChainShape) shape;
                    Debug.Assert(0 <= index && index < chain.m_count);

                    m_buffer[0] = chain.m_vertices[index];
                    if (index + 1 < chain.m_count)
                    {
                        m_buffer[1] = chain.m_vertices[index + 1];
                    }
                    else
                    {
                        m_buffer[1] = chain.m_vertices[0];
                    }

                    m_vertices[0].set(m_buffer[0]);
                    m_vertices[1].set(m_buffer[1]);
                    m_count = 2;
                    m_radius = chain.m_radius;
                    break;
                case ShapeType.EDGE:
                    EdgeShape edge = (EdgeShape) shape;
                    m_vertices[0].set(edge.m_vertex1);
                    m_vertices[1].set(edge.m_vertex2);
                    m_count = 2;
                    m_radius = edge.m_radius;
                    break;
                default:
                    Debug.Assert(false);
                    break;
            }
        }
示例#14
0
 public void switchObjects()
 {
     if (polygon)
     {
         nextShape = m_circle;
     }
     else
     {
         nextShape = m_poly;
     }
     polygon = !polygon;
 }
示例#15
0
        public override void step(TestbedSettings settings)
        {
            if (nextShape != null)
            {
                m_body.destroyFixture(currFixture);
                currFixture = m_body.createFixture(nextShape, 1f);
                nextShape = null;
            }
            // if (stepCount == 12){
            // stepCount += 0;
            // } what is this?

            base.step(settings);

            if (Distance.GJK_CALLS > 0)
            {
                addTextLine(string.Format("gjk calls = {0}, ave gjk iters = {1:F1}, max gjk iters = {2}",
                    Distance.GJK_CALLS, Distance.GJK_ITERS*(1f/Distance.GJK_CALLS), Distance.GJK_MAX_ITERS));
            }

            if (TimeOfImpact.toiCalls > 0)
            {
                int toiCalls = TimeOfImpact.toiCalls;
                int toiIters = TimeOfImpact.toiIters;
                int toiMaxIters = TimeOfImpact.toiMaxIters;
                int toiRootIters = TimeOfImpact.toiRootIters;
                int toiMaxRootIters = TimeOfImpact.toiMaxRootIters;
                addTextLine(string.Format("toi calls = {0}, ave toi iters = %3.1f, max toi iters = {2}",
                    toiCalls, toiIters*1f/toiCalls, toiMaxIters));

                addTextLine(string.Format("ave toi root iters = {0:F1}, max toi root iters = {1}", toiRootIters
                                                                                                   *(1f/toiCalls),
                    toiMaxRootIters));
            }

            addTextLine("Press 'c' to change launch shape");

            if (getStepCount()%60 == 0)
            {
                launch();
            }
        }