private void EnableDocking(EntityUid uid, DockingComponent component) { if (component.Enabled) { return; } if (!TryComp(uid, out PhysicsComponent? physicsComponent)) { return; } component.Enabled = true; // TODO: WTF IS THIS GARBAGE var shape = new PhysShapeCircle { // Want half of the unit vector Position = new Vector2(0f, -0.5f), Radius = DockingRadius }; // Listen it makes intersection tests easier; you can probably dump this but it requires a bunch more boilerplate var fixture = new Fixture(physicsComponent, shape) { ID = DockingFixture, Hard = false, }; // TODO: I want this to ideally be 2 fixtures to force them to have some level of alignment buuuttt // I also need collisionmanager for that yet again so they get dis. _fixtureSystem.CreateFixture(physicsComponent, fixture); }
public void TestRotatedCircleAABB() { var circle = new PhysShapeCircle { Radius = 0.5f }; var aabb = circle.ComputeAABB(_rotatedTransform, 0); Assert.That(aabb.Width, Is.EqualTo(1f)); Assert.That(aabb, Is.EqualTo(new Box2(0.5f, 0.5f, 1.5f, 1.5f))); }
public void TestCirclePoint() { var circle = new PhysShapeCircle { Radius = 0.5f }; var transform = new Transform(0f); var posA = Vector2.One; var posB = Vector2.Zero; var posC = new Vector2(0.1f, 0.3f); Assert.That(_shapeManager.TestPoint(circle, transform, posA), Is.EqualTo(false)); Assert.That(_shapeManager.TestPoint(circle, transform, posB), Is.EqualTo(true)); Assert.That(_shapeManager.TestPoint(circle, transform, posC), Is.EqualTo(true)); }
public void Setup() { _manifoldManager = IoCManager.Resolve <IManifoldManager>(); _circleA = new PhysShapeCircle { Radius = 0.5f }; _circleB = new PhysShapeCircle { Radius = 0.5f }; _polyA = new PolygonShape(); _polyB = new PolygonShape(); _polyA.SetAsBox(0.5f, 0.5f); _polyB.SetAsBox(0.5f, 0.5f); }
public void Setup() { _collisionManager = IoCManager.Resolve <ICollisionManager>(); _circleA = new PhysShapeCircle { Radius = 0.5f }; _circleB = new PhysShapeCircle { Radius = 0.5f }; _polyA = new PolygonShape(); _polyB = new PolygonShape(); _polyA.SetAsBox(-0.5f, 0.5f); _polyB.SetAsBox(-0.5f, 0.5f); }
private void OnStartup(EntityUid uid, FlyBySoundComponent component, ComponentStartup args) { if (!TryComp <PhysicsComponent>(uid, out var body)) { return; } var shape = new PhysShapeCircle() { Radius = component.Range, }; var fixture = new Fixture(body, shape) { Hard = false, ID = FlyByFixture, CollisionLayer = (int)CollisionGroup.MobMask, }; _fixtures.TryCreateFixture(body, fixture); }
public async Task TestCircleStack() { var server = StartServer(); await server.WaitIdleAsync(); var mapManager = server.ResolveDependency <IMapManager>(); var entitySystemManager = server.ResolveDependency <IEntitySystemManager>(); var physicsSystem = entitySystemManager.GetEntitySystem <SharedPhysicsSystem>(); MapId mapId; var columnCount = 1; var rowCount = 15; PhysicsComponent[] bodies = new PhysicsComponent[columnCount * rowCount]; Vector2 firstPos = Vector2.Zero; await server.WaitPost(() => { mapId = mapManager.CreateMap(); physicsSystem.Maps[mapId].Gravity = new Vector2(0, -9.8f); var entityManager = IoCManager.Resolve <IEntityManager>(); // TODO: Need a blank entity we can spawn for testbed. var ground = entityManager.SpawnEntity("BlankEntity", new MapCoordinates(0, 0, mapId)).AddComponent <PhysicsComponent>(); var horizontal = new EdgeShape(new Vector2(-20, 0), new Vector2(20, 0)); var horizontalFixture = new Fixture(ground, horizontal) { CollisionLayer = 1, CollisionMask = 1, Hard = true }; ground.AddFixture(horizontalFixture); var vertical = new EdgeShape(new Vector2(10, 0), new Vector2(10, 10)); var verticalFixture = new Fixture(ground, vertical) { CollisionLayer = 1, CollisionMask = 1, Hard = true }; ground.AddFixture(verticalFixture); var xs = new[] { 0.0f, -10.0f, -5.0f, 5.0f, 10.0f }; PhysShapeCircle shape; for (var j = 0; j < columnCount; j++) { for (var i = 0; i < rowCount; i++) { var x = 0.0f; var circle = entityManager.SpawnEntity("BlankEntity", new MapCoordinates(new Vector2(xs[j] + x, 0.55f + 2.1f * i), mapId)).AddComponent <PhysicsComponent>(); circle.BodyType = BodyType.Dynamic; circle.SleepingAllowed = false; shape = new PhysShapeCircle { Radius = 0.5f }; var fixture = new Fixture(circle, shape) { CollisionMask = 1, CollisionLayer = 1, Hard = true, }; circle.AddFixture(fixture); bodies[j *rowCount + i] = circle; } } firstPos = bodies[0].Owner.Transform.WorldPosition; }); await server.WaitRunTicks(1); // Check that gravity workin await server.WaitAssertion(() => { Assert.That(firstPos != bodies[0].Owner.Transform.WorldPosition); }); // Assert await server.WaitRunTicks(150); // Assert settled, none below 0, etc. await server.WaitAssertion(() => { for (var j = 0; j < columnCount; j++) { for (var i = 0; i < bodies.Length; i++) { var body = bodies[j *columnCount + i]; var worldPos = body.Owner.Transform.WorldPosition; // TODO: Multi-column support but I cbf right now // Can't be more exact as some level of sinking is allowed. Assert.That(worldPos.EqualsApprox(new Vector2(0.0f, i + 0.5f), 0.1f), $"Expected y-value of {i + 0.5f} but found {worldPos.Y}"); } } }); }
private void CreateCircleStack(MapId mapId) { var entityManager = IoCManager.Resolve <IEntityManager>(); var ground = entityManager.SpawnEntity(null, new MapCoordinates(0, 0, mapId)).AddComponent <PhysicsComponent>(); var horizontal = new EdgeShape(new Vector2(-20, 0), new Vector2(20, 0)); var horizontalFixture = new Fixture(ground, horizontal) { CollisionLayer = (int)CollisionGroup.Impassable, CollisionMask = (int)CollisionGroup.Impassable, Hard = true }; var broadphase = EntitySystem.Get <SharedBroadphaseSystem>(); broadphase.CreateFixture(ground, horizontalFixture); var vertical = new EdgeShape(new Vector2(10, 0), new Vector2(10, 10)); var verticalFixture = new Fixture(ground, vertical) { CollisionLayer = (int)CollisionGroup.Impassable, CollisionMask = (int)CollisionGroup.Impassable, Hard = true }; broadphase.CreateFixture(ground, verticalFixture); var xs = new[] { 0.0f, -10.0f, -5.0f, 5.0f, 10.0f }; var columnCount = 1; var rowCount = 15; PhysShapeCircle shape; for (var j = 0; j < columnCount; j++) { for (var i = 0; i < rowCount; i++) { var x = 0.0f; var box = entityManager.SpawnEntity(null, new MapCoordinates(new Vector2(xs[j] + x, 0.55f + 2.1f * i), mapId)).AddComponent <PhysicsComponent>(); box.BodyType = BodyType.Dynamic; shape = new PhysShapeCircle { Radius = 0.5f }; box.FixedRotation = false; // TODO: Need to detect shape and work out if we need to use fixedrotation var fixture = new Fixture(box, shape) { CollisionMask = (int)CollisionGroup.Impassable, CollisionLayer = (int)CollisionGroup.Impassable, Hard = true, }; broadphase.CreateFixture(box, fixture); } } }