public SolitudeObject(Vector2 position, World world, Shape shape, float width, float height) { body = BodyFactory.CreateBody(world, position); //currently in wall class: fixture = new Fixture(body, shape); fixture.OnCollision += new OnCollisionEventHandler(OnCollision); //################### drawOrigin = new Vector2(width, height); drawRectangle = new Rectangle(0, 0, (int)width, (int)height); }
/// <summary> /// Creates a fixture and attach it to this body. /// If the density is non-zero, this function automatically updates the mass of the body. /// Contacts are not created until the next time step. /// Warning: This function is locked during callbacks. /// </summary> /// <param name="shape">The shape.</param> /// <param name="userData">Application specific data</param> /// <returns></returns> public Fixture CreateFixture(Shape shape, Object userData) { return new Fixture(this, shape, userData); }
public Fixture(Body body, Shape shape, Object userData) { CollisionFilter = new CollisionFilter(this); //Fixture defaults Friction = 0.2f; Restitution = 0; IsSensor = false; Body = body; UserData = userData; if (Settings.ConserveMemory) Shape = shape; else Shape = shape.Clone(); // Reserve proxy space int childCount = Shape.ChildCount; Proxies = new FixtureProxy[childCount]; for (int i = 0; i < childCount; ++i) { Proxies[i] = new FixtureProxy(); Proxies[i].Fixture = null; Proxies[i].ProxyId = BroadPhase.NullProxy; } ProxyCount = 0; FixtureId = _fixtureIdCounter++; if ((Body.Flags & BodyFlags.Enabled) == BodyFlags.Enabled) { BroadPhase broadPhase = Body.World.ContactManager.BroadPhase; CreateProxies(broadPhase, ref Body.Xf); } Body.FixtureList.Add(this); // Adjust mass properties if needed. if (Shape._density > 0.0f) { Body.ResetMassData(); } // Let the world know we have a new fixture. This will cause new contacts // to be created at the beginning of the next time step. Body.World.Flags |= WorldFlags.NewFixture; if (Body.World.FixtureAdded != null) { Body.World.FixtureAdded(this); } }
/// <summary> /// Creates a fixture and attach it to this body. /// If the density is non-zero, this function automatically updates the mass of the body. /// Contacts are not created until the next time step. /// Warning: This function is locked during callbacks. /// </summary> /// <param name="shape">The shape.</param> /// <returns></returns> public Fixture CreateFixture(Shape shape) { return new Fixture(this, shape); }
public Fixture(Body body, Shape shape) : this(body, shape, null) { }
/// <summary> /// Initialize the proxy using the given shape. The shape /// must remain in scope while the proxy is in use. /// </summary> /// <param name="shape">The shape.</param> /// <param name="index">The index.</param> public void Set(Shape shape, int index) { switch (shape.ShapeType) { case ShapeType.Circle: { CircleShape circle = (CircleShape) shape; Vertices = new Vertices(1); Vertices.Add(circle.Position); Radius = circle.Radius; } break; case ShapeType.Polygon: { PolygonShape polygon = (PolygonShape) shape; Vertices = polygon.Vertices; Radius = polygon.Radius; } break; case ShapeType.Loop: { LoopShape loop = (LoopShape) shape; Debug.Assert(0 <= index && index < loop.Vertices.Count); Buffer[0] = loop.Vertices[index]; if (index + 1 < loop.Vertices.Count) { Buffer[1] = loop.Vertices[index + 1]; } else { Buffer[1] = loop.Vertices[0]; } Vertices = new Vertices(2); Vertices.Add(Buffer[0]); Vertices.Add(Buffer[1]); Radius = loop.Radius; } break; case ShapeType.Edge: { EdgeShape edge = (EdgeShape) shape; Vertices = new Vertices(2); Vertices.Add(edge.Vertex1); Vertices.Add(edge.Vertex2); Radius = edge.Radius; } break; default: Debug.Assert(false); break; } }
public static List<Body> EvenlyDistributeShapesAlongPath(World world, Path path, Shape shape, BodyType type, int copies) { return EvenlyDistributeShapesAlongPath(world, path, shape, type, copies, null); }
/// <summary> /// Duplicates the given Body along the given path for approximatly the given copies. /// </summary> /// <param name="world">The world.</param> /// <param name="path">The path.</param> /// <param name="shape">The shape.</param> /// <param name="type">The type.</param> /// <param name="copies">The copies.</param> /// <returns></returns> public static List<Body> EvenlyDistributeShapesAlongPath(World world, Path path, Shape shape, BodyType type, int copies, Object userData) { List<Shape> shapes = new List<Shape>(1); shapes.Add(shape); return EvenlyDistributeShapesAlongPath(world, path, shapes, type, copies, userData); }
public static bool TestOverlap(Shape shapeA, int indexA, Shape shapeB, int indexB, ref Transform xfA, ref Transform xfB) { DistanceInput input = new DistanceInput(); input.ProxyA.Set(shapeA, indexA); input.ProxyB.Set(shapeB, indexB); input.TransformA = xfA; input.TransformB = xfB; input.UseRadii = true; SimplexCache cache; DistanceOutput output; Distance.ComputeDistance(out output, out cache, ref input); return output.Distance < 10.0f*Settings.Epsilon; }