A shape is used for collision detection. You can create a shape however you like. Shapes used for simulation in World are created automatically when a Fixture is created. Shapes may encapsulate a one or more child shapes.
コード例 #1
0
ファイル: Fixture.cs プロジェクト: thdtjsdn/box2dnet
 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
ファイル: FixtureDef.cs プロジェクト: gerich-home/box2dnet
 public FixtureDef()
 {
     Shape = null;
     UserData = null;
     Friction = 0.2f;
     Restitution = 0f;
     Density = 0f;
     Filter = new Filter();
     IsSensor = false;
 }
コード例 #3
0
ファイル: FixtureDef.cs プロジェクト: thdtjsdn/box2dnet
 public FixtureDef()
 {
     shape = null;
     userData = null;
     friction = 0.2f;
     restitution = 0f;
     density = 0f;
     filter = new Filter();
     isSensor = false;
 }
コード例 #4
0
ファイル: Body.cs プロジェクト: thdtjsdn/box2dnet
        /// <summary>
        /// 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.
        /// </summary>
        /// <param name="shape">the shape to be cloned.</param>
        /// <param name="density">the shape density (set to zero for static bodies).</param>
        /// <warning>This function is locked during callbacks.</warning>
        public Fixture createFixture(Shape shape, float density)
        {
            fixDef.shape = shape;
            fixDef.density = density;

            return createFixture(fixDef);
        }
コード例 #5
0
ファイル: Collision.cs プロジェクト: thdtjsdn/box2dnet
        /// <summary>
        /// Determine if two generic shapes overlap.
        /// </summary>
        /// <param name="shapeA"></param>
        /// <param name="shapeB"></param>
        /// <param name="xfA"></param>
        /// <param name="xfB"></param>
        /// <returns></returns>
        public bool testOverlap(Shape shapeA, int indexA, Shape shapeB, int indexB, Transform xfA, Transform xfB)
        {
            input.proxyA.set_Renamed(shapeA, indexA);
            input.proxyB.set_Renamed(shapeB, indexB);
            input.transformA.set_Renamed(xfA);
            input.transformB.set_Renamed(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;
        }
コード例 #6
0
ファイル: Distance.cs プロジェクト: thdtjsdn/box2dnet
            /// <summary> Initialize the proxy using the given shape. The shape must remain in scope while the proxy is
            /// in use.
            /// </summary>
            public void set_Renamed(Shape shape, int index)
            {
                switch (shape.Type)
                {

                    case ShapeType.CIRCLE:
                        CircleShape circle = (CircleShape)shape;
                        m_vertices[0].set_Renamed(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_Renamed(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_Renamed(m_buffer[0]);
                        m_vertices[1].set_Renamed(m_buffer[1]);
                        m_count = 2;
                        m_radius = chain.m_radius;
                        break;

                    case ShapeType.EDGE:
                        EdgeShape edge = (EdgeShape)shape;
                        m_vertices[0].set_Renamed(edge.m_vertex1);
                        m_vertices[1].set_Renamed(edge.m_vertex2);
                        m_count = 2;
                        m_radius = edge.m_radius;
                        break;

                    default:
                        Debug.Assert(false);
                        break;

                }
            }
コード例 #7
0
ファイル: Fixture.cs プロジェクト: thdtjsdn/box2dnet
        public virtual 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
        }
コード例 #8
0
ファイル: Fixture.cs プロジェクト: thdtjsdn/box2dnet
        // We need separation create/destroy functions from the constructor/destructor because
        // the destructor cannot access the allocator (no destructor arguments allowed by C++).
        public virtual 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_Renamed(def.filter);

            m_isSensor = def.isSensor;

            m_shape = def.shape.Clone();

            // Reserve proxy space
            int childCount = m_shape.ChildCount;
            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 = BroadPhase.NULL_PROXY;
                }
            }

            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 = BroadPhase.NULL_PROXY;
                }
            }
            m_proxyCount = 0;

            m_density = def.density;
        }
コード例 #9
0
ファイル: Distance.cs プロジェクト: gerich-home/box2dnet
            /// <summary>
            ///  Initialize the proxy using the given shape. The shape must remain in scope while the proxy is in use.
            /// </summary>
            public void Set(Shape shape, int index)
            {
                switch (shape.Type)
                {

                    case ShapeType.Circle:
                        CircleShape circle = (CircleShape)shape;
                        Vertices[0].Set(circle.P);
                        VertexCount = 1;
                        Radius = circle.Radius;

                        break;

                    case ShapeType.Polygon:
                        PolygonShape poly = (PolygonShape)shape;
                        VertexCount = poly.VertexCount;
                        Radius = poly.Radius;
                        for (int i = 0; i < VertexCount; i++)
                        {
                            Vertices[i].Set(poly.Vertices[i]);
                        }
                        break;

                    case ShapeType.Chain:
                        ChainShape chain = (ChainShape)shape;
                        Debug.Assert(0 <= index && index < chain.Count);

                        Buffer[0] = chain.Vertices[index];
                        if (index + 1 < chain.Count)
                        {
                            Buffer[1] = chain.Vertices[index + 1];
                        }
                        else
                        {
                            Buffer[1] = chain.Vertices[0];
                        }

                        Vertices[0].Set(Buffer[0]);
                        Vertices[1].Set(Buffer[1]);
                        VertexCount = 2;
                        Radius = chain.Radius;
                        break;

                    case ShapeType.Edge:
                        EdgeShape edge = (EdgeShape)shape;
                        Vertices[0].Set(edge.Vertex1);
                        Vertices[1].Set(edge.Vertex2);
                        VertexCount = 2;
                        Radius = edge.Radius;
                        break;

                    default:
                        Debug.Assert(false);
                        break;

                }
            }
コード例 #10
0
ファイル: Body.cs プロジェクト: gerich-home/box2dnet
        /// <summary>
        /// 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.
        /// </summary>
        /// <param name="shape">the shape to be cloned.</param>
        /// <param name="density">the shape density (set to zero for static bodies).</param>
        /// <warning>This function is locked during callbacks.</warning>
        public Fixture CreateFixture(Shape shape, float density)
        {
            fixDef.Shape = shape;
            fixDef.Density = density;

            return CreateFixture(fixDef);
        }
コード例 #11
0
ファイル: Collision.cs プロジェクト: gerich-home/box2dnet
        /// <summary>
        /// Determine if two generic shapes overlap.
        /// </summary>
        /// <param name="shapeA"></param>
        /// <param name="indexA"></param>
        /// <param name="shapeB"></param>
        /// <param name="indexB"></param>
        /// <param name="xfA"></param>
        /// <param name="xfB"></param>
        /// <returns></returns>
        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().GetDistance(output, cache, input);
            // djm note: anything significant about 10.0f?
            return output.Distance < 10.0f * Settings.EPSILON;
        }