public Fixture() { m_userData = null; m_body = null; m_next = null; m_proxies = null; m_proxyCount = 0; m_shape = null; m_filter = new Filter(); }
public FixtureDef() { Shape = null; UserData = null; Friction = 0.2f; Restitution = 0f; Density = 0f; Filter = new Filter(); IsSensor = false; }
public FixtureDef() { shape = null; userData = null; friction = 0.2f; restitution = 0f; density = 0f; filter = new Filter(); isSensor = false; }
/// <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); }
/// <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; }
/// <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; } }
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 }
// 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; }
/// <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; } }
/// <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); }
/// <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; }