public void AddToSpace(Space space) { space.Add(Body); space.Add(Barrel); space.Add(TankToTurretJoint); space.Add(TurretBodyToBarrelJoint); }
public static void AddEntity(Entity entity) { if (entity != null) { SimulationSpace.Add(entity); } }
public static void AddEntity(Entity entity) { if (!WorldSpace.Entities.Contains(entity)) { WorldSpace.Add(entity); } }
int BuildPileSimulation(Space space) { Random rand = new Random(0); #if WINDOWS NarrowPhaseHelper.Factories.BoxBox.EnsureCount(30000); BoundingBox box = new BoundingBox(new Vector3(-5, 10, -5), new Vector3(5, 300, 5)); for (int k = 0; k < 5000; k++) #else NarrowPhaseHelper.Factories.BoxBox.EnsureCount(1500); BoundingBox box = new BoundingBox(new Vector3(-5, 10, -5), new Vector3(5, 20, 5)); for (int k = 0; k < 250; k++) #endif { Vector3 position = new Vector3((float)(rand.NextDouble() * (box.Max.X - box.Min.X) + box.Min.X), (float)(rand.NextDouble() * (box.Max.Y - box.Min.Y) + box.Min.Y), (float)(rand.NextDouble() * (box.Max.Z - box.Min.Z) + box.Min.Z)); var toAdd = new Box(position, 1, 1, 1, 1); toAdd.ActivityInformation.IsAlwaysActive = true; space.Add(toAdd); } Box ground = new Box(new Vector3(0, 0, 0), 300, 10, 300); space.Add(ground); #if WINDOWS return(700); #else return(350); #endif }
/// <summary> /// Load content /// </summary> public void LoadContent() { uberShader = Content.Load <Ubershader>("render"); factory = new StateFactory(uberShader, typeof(RenderFlags), Primitive.TriangleList, VertexInputElement.FromStructure <CubeVertex>()); texture = Content.Load <Texture2D>(@"Scenes\lena"); vb = new VertexBuffer(GraphicsDevice, typeof(CubeVertex), 24); ib = new IndexBuffer(GraphicsDevice, 36); // create a new space with physics space = new Space(); // update gravity force space.ForceUpdater.Gravity = new Vector3BEPU(0, -9.81f, 0); // add ground, ground has infinite mass Box ground = new Box(new Vector3BEPU(0, 0, 0), 50, 1, 50); space.Add(ground); // create boxes with random position and add color as a tag, then add box to space for (int i = 0; i < numberOfBoxes; i++) { Vector3Fusion vector = RandomExt.NextVector3(random, new Vector3Fusion(-10, 20, -10), new Vector3Fusion(10, 80, 10)); Box box = new Box(new Vector3BEPU(vector.X, vector.Y, vector.Z), 1, 1, 1, 1); box.Tag = RandomExt.NextColor(random); space.Add(box); } }
public void OnAdditionToSpace(Space newSpace) { newSpace.Add(linearMotor); newSpace.Add(Model.Entity); Model.Entity.CollisionInformation.Events.DetectingInitialCollision += onCollision; Model.Entity.Space.DuringForcesUpdateables.Starting += update; }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { //Set up drawers ModelDrawer = new InstancedModelDrawer(this); //Create the space itself Space = new Space(); var parallelLooper = new ParallelLooper(); //This section lets the engine know that it can make use of multithreaded systems //by adding threads to its thread pool. if (Environment.ProcessorCount > 1) { for (int i = 0; i < Environment.ProcessorCount; i++) { parallelLooper.AddThread(); } } Space = new Space(parallelLooper); Space.ForceUpdater.Gravity = new Vector3(0, -9.81f, 0); Space.Add(new Box(Vector3.Zero, 30, 1, 30)); //Create a bunch of boxes randomly. Random random = new Random(); int boxCount = 100; BoundingBox spawnVolume = new BoundingBox(new Vector3(-10, 10, -10), new Vector3(10, 30, 10)); for (int i = 0; i < boxCount; i++) { Vector3 position = new Vector3((float)(random.NextDouble() - 0.5f) * (spawnVolume.Max.X - spawnVolume.Min.X), (float)(random.NextDouble() - 0.5f) * (spawnVolume.Max.Y - spawnVolume.Min.Y), (float)(random.NextDouble() - 0.5f) * (spawnVolume.Max.Z - spawnVolume.Min.Z)) + (spawnVolume.Min + spawnVolume.Max) / 2; Space.Add(new Box(position, 1, 1, 1, 1)); } #region DisplayObject creation foreach (Entity e in Space.Entities) { if ((string)e.Tag != "noDisplayObject") { ModelDrawer.Add(e); } else//Remove the now unnecessary tag. { e.Tag = null; } } #endregion }
public override void OnAdditionToSpace(Space newSpace) { //Add any supplements to the space too. newSpace.Add(Body); newSpace.Add(HorizontalMotionConstraint); newSpace.Add(VerticalMotionConstraint); //This character controller requires the standard implementation of Space. newSpace.BoundingBoxUpdater.Finishing += ExpandBoundingBox; Body.AngularVelocity = new Vector3(); Body.LinearVelocity = new Vector3(); }
int BuildPlanetSimulation(Space space) { space.ForceUpdater.Gravity = Vector3.Zero; var planet = new Sphere(new Vector3(0, 0, 0), 30); space.Add(planet); var field = new GravitationalField(new InfiniteForceFieldShape(), planet.Position, 66730 / 2f, 100); space.Add(field); //Drop the "meteorites" on the planet. Entity toAdd; #if WINDOWS //By pre-allocating a bunch of box-box pair handlers, the simulation will avoid having to allocate new ones at runtime. NarrowPhaseHelper.Factories.BoxBox.EnsureCount(30000); int numColumns = 25; int numRows = 25; int numHigh = 25; #else NarrowPhaseHelper.Factories.BoxBox.EnsureCount(2000); int numColumns = 10; int numRows = 10; int numHigh = 10; #endif float separation = 5; for (int i = 0; i < numRows; i++) { for (int j = 0; j < numColumns; j++) { for (int k = 0; k < numHigh; k++) { toAdd = new Box(new Vector3(separation * i - numRows * separation / 2, 40 + k * separation, separation * j - numColumns * separation / 2), 1f, 1f, 1f, 5); toAdd.LinearVelocity = new Vector3(30, 0, 0); toAdd.LinearDamping = 0; toAdd.AngularDamping = 0; space.Add(toAdd); } } } #if WINDOWS return(3000); #else return(1000); #endif }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { //Set up drawers modelDrawer = new InstancedModelDrawer(this); //Create the space and tell it that it should keep track of buffered states. This will let the //positions/orientations of entities be interpolated, producing a cleaner appearance. Space = new Space(); Space.BufferedStates.Enabled = true; Space.ForceUpdater.Gravity = new Vector3(0, -9.81f, 0); Space.Add(new Box(Vector3.Zero, 30, 1, 30)); //Make the ground //Create a bunch of boxes randomly. Random random = new Random(); int boxCount = 50; var spawnVolume = new BoundingBox(new Vector3(-5, 15, -5), new Vector3(5, 25, 5)); for (int i = 0; i < boxCount; i++) { var position = new Vector3((float)(random.NextDouble() - 0.5f) * (spawnVolume.Max.X - spawnVolume.Min.X), (float)(random.NextDouble() - 0.5f) * (spawnVolume.Max.Y - spawnVolume.Min.Y), (float)(random.NextDouble() - 0.5f) * (spawnVolume.Max.Z - spawnVolume.Min.Z)) + (spawnVolume.Min + spawnVolume.Max) / 2; Space.Add(new Box(position, 1, 1, 1, 1)); } //Start up the physics loop. physicsThread = new Thread(PhysicsLoop); physicsThread.IsBackground = true; physicsThread.Start(); #region DisplayObject creation foreach (Entity e in Space.Entities) { if ((string)e.Tag != "noDisplayObject") { modelDrawer.Add(e); } else//Remove the now unnecessary tag. { e.Tag = null; } } #endregion }
private void CreateCompoundBody() { List <CompoundShapeEntry> shapes = new List <CompoundShapeEntry>(); // Create parts of compound shape Vector3 blockPos = new Vector3(); for (int z = 0; z < GAME_FIELD_SIZE; ++z) { for (int y = 0; y < GAME_FIELD_SIZE; ++y) { for (int x = 0; x < GAME_FIELD_SIZE; ++x) { blockPos.X = (x - GAME_FIELD_SIZE * 0.5f) * BLOCK_SIZE + BLOCK_SIZE * 0.5f; blockPos.Y = (y - GAME_FIELD_SIZE * 0.5f) * BLOCK_SIZE + BLOCK_SIZE * 0.5f; blockPos.Z = (z - GAME_FIELD_SIZE * 0.5f) * BLOCK_SIZE + BLOCK_SIZE * 0.5f; BoxShape blockShape = new BoxShape(BLOCK_SIZE, BLOCK_SIZE, BLOCK_SIZE); CompoundShapeEntry entry = new CompoundShapeEntry(blockShape, blockPos); shapes.Add(entry); } } } // Create compound body compoundBody = new CompoundBody(shapes, COMPOUND_BODY_MASS); compoundBody.PositionUpdateMode = BEPUphysics.PositionUpdating.PositionUpdateMode.Continuous; compoundBody.AngularDamping = COMPOUND_BODY_ANGULAR_DAMPING; // Add constraint prevents compound body from moving constraint = new MaximumLinearSpeedConstraint(compoundBody, 0.0f); // Create collision group for removed blocks removedBlocksGroup = new CollisionGroup(); // Mark all chapes in compound body to be removed for now foreach (CompoundChild child in compoundBody.CollisionInformation.Children) { child.CollisionInformation.CollisionRules.Group = removedBlocksGroup; } // Add compound body and its constraints to physics space space.Add(compoundBody); space.Add(constraint); //compoundBody.CollisionInformation.Events.ContactCreated += handleContactCreated; }
void FillSpace(Space space, ModelDrawer modelDrawer = null) { Entity ground = new MorphableEntity(new BoxShape(50, 1, 50)); space.Add(ground); space.ForceUpdater.Gravity = new Vector3(0, -10, 0); ModelDataExtractor.GetVerticesAndIndicesFromModel(Game.Content.Load <Model>("playground"), out Vector3[] vertices, out int[] indices); var mesh = new StaticMesh(vertices, indices, new AffineTransform(new Vector3(50, -20, 0))); space.Add(mesh); modelDrawer?.Add(mesh); for (int i = 0; i < 100; i++) { Entity e = new Box(new Vector3(.1f * i, 1 * i + 1, 0), 1, 1, 1, 1); //Entity e = new Capsule(new Vector3(.1f * i, 1 * i + 1, 0), .5f, .5f, 1); //Entity e = new Sphere(new Vector3(.1f * i, 1 * i + 1, 0), .5f, 1); e.ActivityInformation.IsAlwaysActive = true; e.CollisionInformation.Tag = i; space.Add(e); } for (int i = 0; i < 200; i++) { //Entity e = new Box(new Vector3(.1f * i, 1 * i + 1, 2), 1, 1, 1, 1); Entity e = new Capsule(new Vector3(.1f * i, 1 * i + 1, 2), .5f, .5f, 1); //Entity e = new Sphere(new Vector3(.1f * i, 1 * i + 1, 2), .5f, 1); e.ActivityInformation.IsAlwaysActive = true; e.CollisionInformation.Tag = i; space.Add(e); } for (int i = 0; i < 300; i++) { //Entity e = new Box(new Vector3(.1f * i, 1 * i + 1, 4), 1, 1, 1, 1); //Entity e = new Capsule(new Vector3(.1f * i, 1 * i + 1, 4), .5f, .5f, 1); Entity e = new Sphere(new Vector3(.1f * i, 1 * i + 1, 4), .5f, 1); e.ActivityInformation.IsAlwaysActive = true; e.CollisionInformation.Tag = i; space.Add(e); } if (modelDrawer != null) { for (int i = 0; i < space.Entities.Count; ++i) { modelDrawer.Add(space.Entities[i]); } } }
public void ReducedSetValues12Test() { ISpace <int> space = new Space <int>(new Possible() { 1, 2, 3, 4, 5, 6, 7, 8, 9 }); for (int i = 1; i < 10; i++) { space.Add(i, new Possible() { 1, 2, 3, 4, 5, 6, 7, 8, 9 }); } space[1].SetValue(1); space[2].SetValue(2); Keys <int> subset = new Keys <int>() { 1, 2 }; Keys <int> set = new Keys <int>() { 1, 2, 3, 4, 5, 6, 7, 8, 9 }; ReducedSetTester <int> target = new ReducedSetTester <int>(set, space); bool actual = target.ReducedSet(subset); // Have not eliminated 1 and 2 from remaining set so will fail Assert.AreEqual(false, actual); //Assert.AreEqual(2, target.SetProcess.Regions.First().Leaf.Count); }
/// <summary> /// Constructs a new demo. /// </summary> /// <param name="game">Game owning this demo.</param> public PrimitiveSceneBugDemo(DemosGame game) : base(game) { character = new BugShowerCharacterController(Space, game.Camera, game); Space.ForceUpdater.Gravity = new Vector3(0, -16, 0); game.Camera.Position = new Vector3(5, 0.85f, 4); game.Camera.ViewDirection = new Vector3(0, 0, 1); //Since this is the character playground, turn on the character by default. character.Activate(); //Having the character body visible would be a bit distracting. character.CharacterController.Body.Tag = "noDisplayObject"; //Load in mesh data for the environment. Vector3[] staticTriangleVertices; int[] staticTriangleIndices; var playgroundModel = game.Content.Load <Model>("bugPrimitiveRoom"); //This is a little convenience method used to extract vertices and indices from a model. //It doesn't do anything special; any approach that gets valid vertices and indices will work. ModelDataExtractor.GetVerticesAndIndicesFromModel(playgroundModel, out staticTriangleVertices, out staticTriangleIndices); var staticMesh = new StaticMesh(staticTriangleVertices, staticTriangleIndices, new AffineTransform(new Vector3(1, 1, 1), Quaternion.Identity, new Vector3(0, 0, 0))); staticMesh.Sidedness = TriangleSidedness.Counterclockwise; Space.Add(staticMesh); game.ModelDrawer.Add(staticMesh); }
protected override void InitializeSpace() { solver = new IKSolver(); bones = new List <BoneRelationship>(); controls = new List <Control>(); joints = new List <IKJoint>(); dragControl = new DragControl(); Box ground = new Box(new Vector3(0, 0, 0), 30, 1, 30); Space.Add(ground); solver.ActiveSet.UseAutomass = true; solver.AutoscaleControlImpulses = true; solver.AutoscaleControlMaximumForce = Fix64.MaxValue; solver.TimeStepDuration = .1m; solver.ControlIterationCount = 100; solver.FixerIterationCount = 10; solver.VelocitySubiterationCount = 3; BuildActionFigure(new Vector3(5, 6, -8)); BuildActionFigure(new Vector3(5, 6, -3)); BuildActionFigure(new Vector3(5, 6, 3)); BuildActionFigure(new Vector3(5, 6, 8)); dragControl.TargetBone = bones[0].Bone; controls.Add(dragControl); dragControl.LinearMotor.Offset = new Vector3(0, 0, 0.2m); }
/// <summary> /// Constructs a new demo. /// </summary> /// <param name="game">Game owning this demo.</param> public AddRemoveStressDemo(DemosGame game) : base(game) { NarrowPhaseHelper.Factories.BoxBox.EnsureCount(5000); NarrowPhaseHelper.Factories.CompoundCompound.EnsureCount(5000); Space.Remove(vehicle.Vehicle); for (int i = 0; i < 1000; i++) { var position = new Vector3( (float)(random.NextDouble() - 0.5) * width, (float)(random.NextDouble() - 0.5) * height, (float)(random.NextDouble() - 0.5) * length); var toAdd = new CompoundBody(new List <CompoundShapeEntry> { new CompoundShapeEntry(new BoxShape(1, 1, 1), position, 1) }, 10); //var toAdd = new Box(position, 1, 1, 1, 1); toAdd.IsAffectedByGravity = false; toAdd.LinearVelocity = 3 * Vector3.Normalize(toAdd.Position); Space.Add(toAdd); addedEntities.Add(toAdd); } //Box ground = new Box(new Vector3(0, -.5f, 0), 50, 1, 50); //Space.Add(ground); game.Camera.Position = new Vector3(0, 6, 15); }
/// <summary> /// Constructs a new demo. /// </summary> /// <param name="game">Game owning this demo.</param> public WallDemo(DemosGame game) : base(game) { int width = 10; int height = 10; float blockWidth = 2f; float blockHeight = 1f; float blockLength = 1f; for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { var toAdd = new Box( new Vector3( i * blockWidth + .5f * blockWidth * (j % 2) - width * blockWidth * .5f, blockHeight * .5f + j * (blockHeight), 0), blockWidth, blockHeight, blockLength, 10); Space.Add(toAdd); } } Box ground = new Box(new Vector3(0, -.5f, 0), 50, 1, 50); Space.Add(ground); game.Camera.Position = new Microsoft.Xna.Framework.Vector3(0, 6, 15); }
public static Space ToSAM(this TSD.ZoneData zoneData, IEnumerable <SpaceDataType> spaceDataTypes = null) { ParameterSet parameterSet = Create.ParameterSet_Space(ActiveSetting.Setting, zoneData); if (spaceDataTypes != null) { foreach (SpaceDataType spaceDataType in spaceDataTypes) { List <double> values = zoneData.AnnualZoneResult <double>(spaceDataType); if (values == null) { continue; } JArray jArray = new JArray(); values.ForEach(x => jArray.Add(x)); parameterSet.Add(spaceDataType.Text(), jArray); } } Space space = new Space(zoneData.name, null); space.Add(parameterSet); return(space); }
/// <summary> /// Constructs a new demo. /// </summary> /// <param name="game">Game owning this demo.</param> public IncomingDemo(DemosGame game) : base(game) { Entity toAdd; //Build the stack... for (int k = 1; k <= 12; k++) { if (k % 2 == 1) { toAdd = new Box(new Vector3(-3, k, 0), 1, 1, 7, 10); Space.Add(toAdd); toAdd = new Box(new Vector3(3, k, 0), 1, 1, 7, 10); Space.Add(toAdd); } else { toAdd = new Box(new Vector3(0, k, -3), 7, 1, 1, 10); Space.Add(toAdd); toAdd = new Box(new Vector3(0, k, 3), 7, 1, 1, 10); Space.Add(toAdd); } } //And then smash it! toAdd = new Sphere(new Vector3(0, 150, 0), 3, 100); Space.Add(toAdd); Space.Add(new Box(new Vector3(0, 0, 0), 10, 1f, 10)); game.Camera.Position = new Microsoft.Xna.Framework.Vector3(0, 6, 30); }
/// <summary> /// Constructs a new demo. /// </summary> /// <param name="game">Game owning this demo.</param> public StackDemo(DemosGame game) : base(game) { kapow.PositionUpdateMode = BEPUphysics.PositionUpdating.PositionUpdateMode.Continuous; int height = 50; float blockWidth = 3f; float blockHeight = 1f; float blockLength = 3f; for (int i = 0; i < height; i++) { var toAdd = new Box( new Vector3( 0, blockHeight * .5f + i * (blockHeight), 0), blockWidth, blockHeight, blockLength, 10); Space.Add(toAdd); } Box ground = new Box(new Vector3(0, -.5f, 0), 50, 1, 50); Space.Add(ground); game.Camera.Position = new Vector3(0, 6, 15); }
void AddBackWheel(Vector3 wheelOffset, Entity body) { var wheel = new Cylinder(body.Position + wheelOffset, .4m, .5m, 5); wheel.Material.KineticFriction = 2.5m; wheel.Material.StaticFriction = 3.5m; wheel.Orientation = Quaternion.CreateFromAxisAngle(Vector3.Forward, MathHelper.PiOver2); //Preventing the occasional pointless collision pair can speed things up. CollisionRules.AddRule(wheel, body, CollisionRule.NoBroadPhase); //Connect the wheel to the body. var pointOnLineJoint = new PointOnLineJoint(body, wheel, wheel.Position, Vector3.Down, wheel.Position); var suspensionLimit = new LinearAxisLimit(body, wheel, wheel.Position, wheel.Position, Vector3.Down, -1, 0); //This linear axis motor will give the suspension its springiness by pushing the wheels outward. var suspensionSpring = new LinearAxisMotor(body, wheel, wheel.Position, wheel.Position, Vector3.Down); suspensionSpring.Settings.Mode = MotorMode.Servomechanism; suspensionSpring.Settings.Servo.Goal = 0; suspensionSpring.Settings.Servo.SpringSettings.Stiffness = 300; suspensionSpring.Settings.Servo.SpringSettings.Damping = 70; var revoluteAngularJoint = new RevoluteAngularJoint(body, wheel, Vector3.Right); //Add the wheel and connection to the space. Space.Add(wheel); Space.Add(pointOnLineJoint); Space.Add(suspensionLimit); Space.Add(suspensionSpring); Space.Add(revoluteAngularJoint); }
/// <summary> /// Constructs a new demo. /// </summary> /// <param name="game">Game owning this demo.</param> public BroadPhaseDemo(DemosGame game) : base(game) { //Make a fatter kapow sphere. Space.Remove(kapow); kapow = new Sphere(new Vector3(11000, 0, 0), 1.5f, 1000); Space.Add(kapow); Space.Solver.IterationLimit = 1; //Essentially no sustained contacts, so don't need to worry about accuracy. Space.ForceUpdater.Gravity = Vector3.Zero; int numColumns = 15; int numRows = 15; int numHigh = 15; float separation = 3; Entity toAdd; for (int i = 0; i < numRows; i++) { for (int j = 0; j < numColumns; j++) { for (int k = 0; k < numHigh; k++) { toAdd = new Box(new Vector3(separation * i, k * separation, separation * j), 1, 1, 1, 1); toAdd.Material.Bounciness = 1; //Superbouncy boxes help propagate shock waves. toAdd.LinearDamping = 0f; toAdd.AngularDamping = 0f; Space.Add(toAdd); } } } game.Camera.Position = new Vector3(0, 3, -10); game.Camera.ViewDirection = new Vector3(0, 0, 1); }
/// <summary> /// Constructs a new demo. /// </summary> /// <param name="game">Game owning this demo.</param> public TwistTestDemo(DemosGame game) : base(game) { var a = new Box(new Vector3(-2, 2, 0), 1, 2, 2, 5); var b = new Box(new Vector3(2, 2, 0), 1, 2, 2, 5); b.Orientation = Quaternion.CreateFromAxisAngle(new Vector3(0, 1, 0), MathHelper.PiOver4); Space.Add(a); Space.Add(b); var twistJoint = new TwistJoint(a, b, a.OrientationMatrix.Right, b.OrientationMatrix.Right); var twistMotor = new TwistMotor(a, b, a.OrientationMatrix.Right, b.OrientationMatrix.Right); twistMotor.Settings.Mode = MotorMode.Servomechanism; //Space.Add(twistJoint); Space.Add(twistMotor); var ballSocketJoint = new BallSocketJoint(a, b, (a.Position + b.Position) * 0.5f); var swingLimit = new SwingLimit(a, b, a.OrientationMatrix.Right, a.OrientationMatrix.Right, MathHelper.PiOver2); Space.Add(ballSocketJoint); Space.Add(swingLimit); Box ground = new Box(new Vector3(0, -.5f, 0), 50, 1, 50); Space.Add(ground); game.Camera.Position = new Vector3(0, 6, 15); }
/// <summary> /// Allows the game to run logic such as updating the world, /// checking for collisions, gathering input, and playing audio. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Update(GameTime gameTime) { float dt = (float)gameTime.ElapsedGameTime.TotalSeconds; KeyboardState = Keyboard.GetState(); MouseState = Mouse.GetState(); // Allows the game to exit if (KeyboardState.IsKeyDown(Keys.Escape)) { this.Exit(); return; } Camera.Update(dt); if (MouseState.LeftButton == ButtonState.Pressed) { Box toAdd = new Box(Camera.Position, 1, 1, 1, 1); toAdd.LinearVelocity = Camera.WorldMatrix.Forward * 10; Space.Add(toAdd); ModelDrawer.Add(toAdd); } Space.Update(); ModelDrawer.Update(); base.Update(gameTime); }
/// <summary> /// Sets the collision information of the entity to another collidable. /// </summary> /// <param name="newCollisionInformation">New collidable to use.</param> public void SetCollisionInformation(EntityCollidable newCollisionInformation) { //Temporarily remove the object from the space. //The reset process will update any systems that need to be updated. //This is not thread safe, but this operation should not be performed mid-frame anyway. Space space = Space; if (space != null) { Space.Remove(this); } CollisionInformation.Entity = null; if (isDynamic) { Initialize(newCollisionInformation, mass); } else { Initialize(newCollisionInformation); } if (space != null) { space.Add(this); } }
/// <summary> /// Constructs a new demo. /// </summary> /// <param name="game">Game owning this demo.</param> public GeneralConvexPairStressDemo(DemosGame game) : base(game) { Space.Remove(vehicle.Vehicle); //Enable simplex caching. ConfigurationHelper.ApplySuperSpeedySettings(Space); for (int i = 0; i < 2000; i++) { EntityShape shape; switch (i % 3) { case 0: shape = new CylinderShape(0.5m + (Fix64)random.NextDouble() * 1.5m, 0.5m + (Fix64)random.NextDouble() * 1.5m); break; case 1: shape = new ConeShape(0.5m + (Fix64)random.NextDouble() * 1.5m, 0.5m + (Fix64)random.NextDouble() * 1.5m); break; default: shape = new CapsuleShape(0.5m + (Fix64)random.NextDouble() * 1.5m, 0.5m + (Fix64)random.NextDouble() * 1.5m); break; } var toAdd = new Entity(shape, 2); //toAdd.LocalInertiaTensorInverse = new BEPUutilities.Matrix3x3(); RandomizeEntityState(toAdd); Space.Add(toAdd); } Space.ForceUpdater.Gravity = new Vector3(); game.Camera.Position = new Vector3(0, 6, 15); }
private static int ResursePopulateDestinationSpace(int[] start, int[] end, Space source, Space destination, int index = 0, bool inner = false) { if (index < source.Dimensions) { int startValue = start[index]; int sum = 0; for (; start[index] <= end[index]; start[index]++) { sum += ResursePopulateDestinationSpace(start, end, source, destination, index + 1, inner); } start[index] = startValue; return(sum); } bool active = source.Contains(start); if (inner) { return(active ? 1 : 0); } (int[] min, int[] max) = OffsetArrayValuesBy(start, 1); int count = ResursePopulateDestinationSpace(min, max, source, destination, 0, true); if (count == 3 || (active && count == 4)) { destination.Add(start); } return(1); }
public void AddToSpace(Space space) { LeftTread.AddToSpace(space); RightTread.AddToSpace(space); Turret.AddToSpace(space); space.Add(Body); }
/// <summary> ///A test for Do ///</summary> public void ReducedSetNegTestHelper <TKey>() { ISpace <int> space = new Space <int>(new Possible() { 1, 2, 3, 4, 5, 6, 7, 8, 9 }); for (int i = 1; i < 10; i++) { space.Add(i, new Possible() { 1, 2, 3, 4, 5, 6, 7, 8, 9 }); } Keys <int> subset = new Keys <int>() { 8, 9 }; Keys <int> set = new Keys <int>() { 1, 2, 3, 4, 5, 6, 7, 8, 9 }; ReducedSetTester <int> target = new ReducedSetTester <int>(set, space); bool actual = target.ReducedSet(subset); Assert.AreEqual(false, actual); }
/// <summary> /// Constructs a new demo. /// </summary> /// <param name="game">Game owning this demo.</param> public TerrainDemo(DemosGame game) : base(game) { //x and y, in terms of heightmaps, refer to their local x and y coordinates. In world space, they correspond to x and z. //Setup the heights of the terrain. //[The size here is limited by the Reach profile the demos use- the drawer draws the terrain as a big block and runs into primitive drawing limits. //The physics can support far larger terrains!] int xLength = 180; int zLength = 180; float xSpacing = 8f; float zSpacing = 8f; var heights = new float[xLength, zLength]; for (int i = 0; i < xLength; i++) { for (int j = 0; j < zLength; j++) { float x = i - xLength / 2; float z = j - zLength / 2; //heights[i,j] = (float)(x * y / 1000f); heights[i, j] = (float)(10 * (Math.Sin(x / 8) + Math.Sin(z / 8))); //heights[i,j] = 3 * (float)Math.Sin(x * y / 100f); //heights[i,j] = (x * x * x * y - y * y * y * x) / 1000f; } } //Create the terrain. var terrain = new Terrain(heights, new AffineTransform( new Vector3(-xSpacing, 1, -zSpacing), Quaternion.Identity, new Vector3(xLength * xSpacing / 2, 0, zLength * zSpacing / 2))); terrain.Shape.QuadTriangleOrganization = BEPUphysics.CollisionShapes.QuadTriangleOrganization.BottomRightUpperLeft; //terrain.Thickness = 5; //Uncomment this and shoot some things at the bottom of the terrain! They'll be sucked up through the ground. Space.Add(terrain); for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { for (int k = 0; k < 5; k++) { Space.Add(new Box( new Vector3(0 + i * 4, 100 - j * 10, 0 + k * 4), 2 + i * j * k, 2 + i * j * k, 2 + i * j * k, 4 + 20 * i * j * k)); } } } game.ModelDrawer.Add(terrain); game.Camera.Position = new Vector3(0, 30, 20); }
internal void OnAdditionToSpace(Space space) { detector.CollisionInformation.collisionRules.Specific.Add(wheel.vehicle.Body.CollisionInformation.collisionRules, CollisionRule.NoBroadPhase); detector.CollisionInformation.collisionRules.Personal = CollisionRule.NoNarrowPhaseUpdate; detector.CollisionInformation.collisionRules.group = CollisionRules.DefaultDynamicCollisionGroup; //Need to put the detectors in appropriate locations before adding, or else the broad phase would see objects at (0,0,0) and make things gross. UpdateDetectorPosition(); space.Add(detector); }
private void Init() { Music = new MusicPlayer(); Sounds = new SoundManager(); Assets = new Assets(); Assets.Load(); var vm = new SFML.Window.VideoMode(1000, 750, 32); var style = Styles.Close; var settings = new ContextSettings(0, 0, 8); Window = new SFML.Graphics.RenderWindow(vm, "", style, settings); Window.SetView(View); Window.SetVerticalSyncEnabled(true); Window.Closed += (sender, e) => { IsAppExited = true; }; Window.LostFocus += (sender, e) => { IsPaused = true; }; Window.GainedFocus += (sender, e) => { IsPaused = false; }; Window.SetMouseCursorVisible(true); var splash = new Space("Splash", true); var menu = new Space("Menu"); var inGame = new Space("InGame"); var gameOver = new Space("GameOver"); // ----- ----- ----- Splash ----- ----- ----- var images = new SplashImage[] { new SplashImage(Assets.Textures["sfml"], 3, 1, 1), new SplashImage(Assets.Textures["rsas"], 5, 1, 1) }; SplashImage.Prepare(images, e => { splash.IsActive = false; menu.IsActive = true; }); foreach(var image in images) splash.Add(image); // ----- ----- ----- Menu ----- ----- ----- var btnStart = new MenuButton("Play", 40, new Vector(100, 100)); var btnQuit = new MenuButton("Quit", 40, new Vector(100, 200)); var btnDiffEasy = new MenuButton("Easy", 30, new Vector(250, 100)); var btnDiffMedium = new MenuButton("Medium", 30, new Vector(250, 150)); var btnDiffHard = new MenuButton("Hard", 30, new Vector(250, 200)); var infoText = "- Instructions -\n" + "- Run, shoot and survive as long as possible.\n" + "- Collect white powersups to recover health.\n" + "- New weapons are unlocked after each 1000 kills.\n" + "\n" + "- Use WASD keys to move, and mouse to aim and shoot.\n" + "- Use the numbers keys to change weapons.\n" + "- During gameplay, press ESC to pause or F1 to give up."; var btnInfoText = new MenuButton(infoText, 20, new Vector(450, 125)); var highscoreList = new HighscoreList(new Vector2f(50, 300)); Difficulty = RSaS.Difficulty.Medium; btnDiffMedium.Text.Color = Color.Red; btnStart.Click += e => { if (IsGameOver) { IsGameOver = false; InitInGame(inGame); } Music.Play("music"); menu.IsActive = false; inGame.IsActive = true; IsOSCursorVisible = false; }; btnQuit.Click += e => { IsAppExited = true; }; btnDiffEasy.Click += e => { if (!IsGameOver) return; Difficulty = RSaS.Difficulty.Easy; btnDiffEasy.Text.Color = Color.Red; btnDiffMedium.Text.Color = Color.White; btnDiffHard.Text.Color = Color.White; }; btnDiffMedium.Click += e => { if (!IsGameOver) return; Difficulty = RSaS.Difficulty.Medium; btnDiffEasy.Text.Color = Color.White; btnDiffMedium.Text.Color = Color.Red; btnDiffHard.Text.Color = Color.White; }; btnDiffHard.Click += e => { if (!IsGameOver) return; Difficulty = RSaS.Difficulty.Hard; btnDiffEasy.Text.Color = Color.White; btnDiffMedium.Text.Color = Color.White; btnDiffHard.Text.Color = Color.Red; }; menu.Add(btnStart); menu.Add(btnQuit); menu.Add(btnDiffEasy); menu.Add(btnDiffMedium); menu.Add(btnDiffHard); menu.Add(btnInfoText); menu.Add(highscoreList); }
/// <summary> /// Sets up the vehicle's information when being added to the space. /// Called automatically when the space adds the vehicle. /// </summary> /// <param name="newSpace">New owning space.</param> public override void OnAdditionToSpace(Space newSpace) { newSpace.Add(body); foreach (Wheel wheel in Wheels) { wheel.OnAdditionToSpace(newSpace); } }
/// <summary> /// Adds the motors to the space. Called automatically. /// </summary> public override void OnAdditionToSpace(Space newSpace) { newSpace.Add(LinearMotor); }
public MachineLayer() { space = new Space () { Gravity = new PointF (0, -10), }; Add ( new CCSprite ("bg.jpg") { Position = UIDevice.CurrentDevice.IsIPad() ? new PointF(512, 384) : new PointF(240, 160), }); //motorblock, no body, no shape var motorblock = new CCSprite ("motor_block.png") { Position = UIDevice.CurrentDevice.IsIPad() ? new PointF (160, 460) : new PointF (80, 230), }; Add (motorblock); //motorwheel var motorwheel = new CCPhysicsSprite ("motor_wheel.png") { Body = new Body (1, Helper.MomentForCircle (1, 20, 20, PointF.Empty)), Position = UIDevice.CurrentDevice.IsIPad() ? new PointF (160, 460) : new PointF (80, 230), }; Add (motorwheel); space.Add (motorwheel.Body); space.Add (new CircleShape (motorwheel.Body, UIDevice.CurrentDevice.IsIPad() ? 20 : 10, PointF.Empty) {Group = 1}); space.Add ((Constraint)new PivotJoint (space.StaticBody, motorwheel.Body, UIDevice.CurrentDevice.IsIPad() ? new PointF (160,460) : new PointF (80, 230))); space.Add ((Constraint)new SimpleMotor (space.StaticBody, motorwheel.Body, 10f)); //wheel var wheel = new CCPhysicsSprite ("wheel.png") { Body = new Body (25, Helper.MomentForCircle (25, 140, 140, PointF.Empty)), Position = UIDevice.CurrentDevice.IsIPad() ? new PointF (160, 300) : new PointF (80, 150), }; space.Add (wheel.Body); space.Add (new CircleShape (wheel.Body, UIDevice.CurrentDevice.IsIPad() ? 140 : 70, PointF.Empty){Group = 1}); Add (wheel); space.Add ((Constraint)new PivotJoint (space.StaticBody, wheel.Body, UIDevice.CurrentDevice.IsIPad() ? new PointF (160, 300) : new PointF (80, 150))); space.Add ((Constraint)new GearJoint (motorwheel.Body, wheel.Body, 0f, -7f)); //cylinder. no physics body. only a shape Add (new CCSprite ("cylinder.png") { Position = UIDevice.CurrentDevice.IsIPad() ? new PointF (570, 300) : new PointF (285, 150), }); //space.Add (new PolygonShape (space.StaticBody, new [] { // new PointF (350, 160), // new PointF (350, 200), // new PointF (750, 200), // new PointF (750, 160), //}, PointF.Empty)); // //space.Add (new PolygonShape (space.StaticBody, new [] { // new PointF (350, 400), // new PointF (350, 440), // new PointF (750, 440), // new PointF (750, 400), //}, PointF.Empty)); //piston var piston = new CCPhysicsSprite ("piston.png") { Body = new Body (8, float.PositiveInfinity), //never rotates Position = UIDevice.CurrentDevice.IsIPad() ? new PointF (370, 300) : new PointF (185, 150), }; space.Add (piston.Body); space.Add (new PolygonShape (piston.Body, UIDevice.CurrentDevice.IsIPad() ? 100 : 50, UIDevice.CurrentDevice.IsIPad() ? 200 : 50) {Group = 1}); Add (piston); //conrod var conrod = new CCPhysicsSprite ("conrod.png") { Body = new Body (4, Helper.MomentForPolygon (4, new[] { new PointF (-160,-20), new PointF (-160, 20), new PointF (160, 20), new PointF (160, -20), }, PointF.Empty)), Position = UIDevice.CurrentDevice.IsIPad() ? new PointF (190, 300) : new PointF (95, 150) }; space.Add (conrod.Body); space.Add (new PolygonShape (conrod.Body, UIDevice.CurrentDevice.IsIPad() ? 320 : 160, UIDevice.CurrentDevice.IsIPad() ? 40 : 20) {Group = 1}); Add (conrod); space.Add ((Constraint)new PivotJoint (wheel.Body, conrod.Body, UIDevice.CurrentDevice.IsIPad() ? new PointF (40, 300) : new PointF (20, 150))); space.Add ((Constraint)new PivotJoint (conrod.Body, piston.Body, UIDevice.CurrentDevice.IsIPad() ? new PointF (340, 300) : new PointF (170, 150))); space.Add ((Constraint)new GrooveJoint (space.StaticBody, piston.Body, UIDevice.CurrentDevice.IsIPad() ? new PointF (0, 300) : new PointF (0, 150), UIDevice.CurrentDevice.IsIPad() ? new PointF (1024, 300) : new PointF (480, 150), UIDevice.CurrentDevice.IsIPad() ? new PointF (0, 0): new PointF (0, 0))); }
public RandomWalk(int maxFileSize, bool populateSpace = false, bool createBitmap = false, BitmapPoint? startingPoint = null, string bitmapFilePath = null) { int numberDrawn = 0; if (bitmapFilePath == null) _filePath = @"C:\Users\kylan_000\Desktop\Test Projects\Random Bitmaps\RandomArt.2013\WithPointers\"; else _filePath = bitmapFilePath; _space = new Space(); Random randomW = new Random(); //Random randomC = new Random(); Random rr = new Random(); Random rg = new Random(); Random rb = new Random(); Random random = new Random(); Random randomR = new Random(); Random randomG = new Random(); Random randomB = new Random(); Random pc = new Random(); Random myRandom = new Random(); //int LineLength = 1; //int FileSize = 10000000; //in bytes int x = (int)Math.Truncate(Math.Sqrt(maxFileSize / 36)) + 1; int Width = 4 * x; // Screen.GetBounds(new Point(5, 5)).Width; int Height = 3 * x; //Screen.GetBounds( new Point(5,5) ).Height; Random pick = new Random(); Console.WriteLine("Setting up data structure..."); if (createBitmap) { _tBitmap = new TBitmap(Width, Height); Console.WriteLine("Initializing bitmap..."); for (int k = 0; k < _tBitmap.values.Length; k++) { _tBitmap.values[k].R = (byte)0; _tBitmap.values[k].G = (byte)0; _tBitmap.values[k].B = (byte)0; _tBitmap.values[k].A = (byte)0; } } int i; int randomNumber; randomNumber = random.Next(0, 255); //for (int g = 1; g < 10; g++) //{ BitmapPoint ptStart = startingPoint == null ? new BitmapPoint(random.Next(Width), random.Next(Height)) : new BitmapPoint(((BitmapPoint)startingPoint).x,((BitmapPoint)startingPoint).y); double rnd; rnd = pc.Next(0, 8); int PenCase = 4; Color startColor = Color.FromArgb(random.Next(0,255),random.Next(0,255),random.Next(0,255)); BitmapPoint ptEnd = new BitmapPoint(0, 0); Random randomC = new Random(); int iMax = (int)Math.Truncate(Math.Pow(maxFileSize, 0.9)); Console.WriteLine("Generating random walk..."); for (i = 1; i < iMax; i++) //do { //IntPoint[] pts = new IntPoint[2]; int c; Color endColor = new Color(); switch (PenCase) { case 1: { //ptEnd = GetNextPoint(ptStart, random, bpData.Stride, bpData.Height); //ptEnd.Offset(random.Next(-(LineLength), LineLength + 1), random.Next(-(LineLength), LineLength + 1)); break; } case 2: { //black //pn.Width = randomW.Next(0, 5); //ptEnd = GetNextPoint(ptStart, random, bpData.Stride, bpData.Height); break; } case 3: { //all colors, random line width between 0 and 5 px endColor = Color.FromArgb(random.Next(0, 255), random.Next(0, 255), random.Next(0, 255)); //ptEnd = GetNextPoint(ptStart, random, bpData.Stride, bpData.Height); break; } case 4: { //all colors, thinnest line width ptEnd = GetNextPoint(new Point(ptStart.x, ptStart.y), random, Width, Height); endColor = Color.FromArgb(random.Next(0, 255), random.Next(0, 255), random.Next(0, 255), random.Next(0, 255)); //endColor = Blend(startColor, GetPixelColor(ptEnd, tBm), random); if(createBitmap) numberDrawn += DrawToBitmap(ref _tBitmap, ptEnd, endColor); ptStart.x = ptEnd.x; ptStart.y = ptEnd.y; break; } case 5: { //greyscale c = randomC.Next(0, 255); //pn.Color = System.Drawing.Color.FromArgb(c, c, c); //ptEnd = GetNextPoint(ptStart, random, bpData.Stride, bpData.Height); break; } case 6: { //white //pn.Color = System.Drawing.Color.White; //ptEnd.X = ptStart.X; //ptEnd.Y = ptStart.Y; //ptEnd = GetNextPoint(ptStart, random, bpData.Stride, bpData.Height); break; } case 7: { //black thinnest line width //pn.Width = 1; //ptEnd.X = ptStart.X; //ptEnd.Y = ptStart.Y; //ptEnd = GetNextPoint(ptStart, random, bpData.Stride, bpData.Height); break; } case 8: //all colors, wider line width { //pn.Color = System.Drawing.Color.FromArgb( rr.Next(redBottom, redTop), rr.Next(greenBottom, greenCenter), rr.Next(blueBottom, blueTop) ); //pn.Width = randomW.Next(0, 50); //ptEnd.X = ptStart.X; //ptEnd.Y = ptStart.Y; //ptEnd = GetNextPoint(ptStart, random, bpData.Stride, bpData.Height); break; } default: { //ptEnd.X = ptStart.X; //ptEnd.Y = ptStart.Y; //ptEnd = GetNextPoint(ptStart, random, bpData.Stride, bpData.Height); break; } } //end switch if (populateSpace) { _space.Add(new BitmapPoint(ptEnd.x, ptEnd.y)); _size++; } } //} if(createBitmap) WriteDataToStandardBitmap(ref _tBitmap); }
private void InitInGame(Space space) { space.Clear(); space.Add(new HUD()); space.Add(new Player()); space.Add(new Cursor()); space.Add(new EnemySpawner()); }
public override void OnAdditionToSpace(Space newSpace) { //Add any supplements to the space too. newSpace.Add(Body); newSpace.Add(HorizontalMotionConstraint); newSpace.Add(VerticalMotionConstraint); //This character controller requires the standard implementation of Space. newSpace.BoundingBoxUpdater.Finishing += ExpandBoundingBox; Body.AngularVelocity = new Vector3(); Body.LinearVelocity = new Vector3(); }
public static void RunTests() { //test IsSubSpace Space FirstSpace = new Space(); Space SecondSpace = new Space(); for (int i = 0; i < 100; i++) { FirstSpace.Add(new System.Drawing.Point(i, i)); if (i >= 25 && i <= 50) SecondSpace.Add(new System.Drawing.Point(i, i)); } if (SecondSpace.IsSubsetOf(FirstSpace)) Console.WriteLine("Test IsSubSpace passed!"); else Console.WriteLine("Test IsSubSpace failed!"); //test !IsSubSpace FirstSpace = new Space(); SecondSpace = new Space(); for (int i = 0; i < 100; i++) { if (i >= 50) FirstSpace.Add(new System.Drawing.Point(i, i)); if (i <= 25) SecondSpace.Add(new System.Drawing.Point(i, i)); } if (!SecondSpace.IsSubsetOf(FirstSpace)) Console.WriteLine("Test !IsSubSpace passed!"); else Console.WriteLine("Test !IsSubSpace failed!"); //test Contains FirstSpace = new Space(); SecondSpace = new Space(); for (int i = 0; i < 100; i++) { FirstSpace.Add(new System.Drawing.Point(i, i)); if (i >= 25 && i <= 50) SecondSpace.Add(new System.Drawing.Point(i, i)); } if (FirstSpace.Contains(SecondSpace)) Console.WriteLine("Test Contains passed!"); else Console.WriteLine("Test Contains failed!"); //test !Contains FirstSpace = new Space(); SecondSpace = new Space(); for (int i = 0; i < 100; i++) { if( i <= 50) FirstSpace.Add(new System.Drawing.Point(i, i)); if (i >= 75) SecondSpace.Add(new System.Drawing.Point(i, i)); } if (!FirstSpace.Contains(SecondSpace)) Console.WriteLine("Test !Contains passed!"); else Console.WriteLine("Test !Contains failed!"); //test IsSupersetOf FirstSpace = new Space(); SecondSpace = new Space(); for (int i = 0; i < 100; i++) { FirstSpace.Add(new System.Drawing.Point(i, i)); if (i >= 75) SecondSpace.Add(new System.Drawing.Point(i, i)); } if (FirstSpace.IsSupersetOf(SecondSpace)) Console.WriteLine("Test IsSupersetOf passed!"); else Console.WriteLine("Test IsSupersetOf failed!"); //test !IsSupersetOf FirstSpace = new Space(); SecondSpace = new Space(); for (int i = 0; i < 100; i++) { if( i <= 25) FirstSpace.Add(new System.Drawing.Point(i, i)); if (i >= 75) SecondSpace.Add(new System.Drawing.Point(i, i)); } if (!FirstSpace.IsSupersetOf(SecondSpace)) Console.WriteLine("Test !IsSupersetOf passed!"); else Console.WriteLine("Test !IsSupersetOf failed!"); //test GetUnion(Space s1, Space s2)_1 FirstSpace = new Space(); SecondSpace = new Space(); for (int i = 0; i < 100; i++) { if (i <= 25) FirstSpace.Add(new System.Drawing.Point(i, i)); if (i >= 75) SecondSpace.Add(new System.Drawing.Point(i, i)); } Space UnionSpace = new Space(); UnionSpace = Space.GetUnion(FirstSpace, SecondSpace); if ( UnionSpace == FirstSpace + SecondSpace ) Console.WriteLine("Test GetUnion(Space s1, Space s2)_1 passed!"); else Console.WriteLine("Test GetUnion(Space s1, Space s2)_1 failed!"); //test GetUnion(Space s1, Space s2)_2 FirstSpace = new Space(); SecondSpace = new Space(); FirstSpace.Add(new System.Drawing.Point(1, 1)); SecondSpace.Add(new System.Drawing.Point(2, 2)); UnionSpace = new Space(); UnionSpace = Space.GetUnion(FirstSpace, SecondSpace); if (UnionSpace == FirstSpace + SecondSpace) Console.WriteLine("Test GetUnion(Space s1, Space s2)_2 passed!"); else Console.WriteLine("Test GetUnion(Space s1, Space s2)_2 failed!"); //test GetUnion(Space s1, Space s2)_3 FirstSpace = new Space(); SecondSpace = new Space(); FirstSpace.Add(new System.Drawing.Point(1, 1)); FirstSpace.Add(new System.Drawing.Point(2, 2)); SecondSpace.Add(new System.Drawing.Point(2, 2)); UnionSpace = new Space(); UnionSpace = Space.GetUnion(FirstSpace, SecondSpace); if (UnionSpace == FirstSpace + SecondSpace) Console.WriteLine("Test GetUnion(Space s1, Space s2)_3 passed!"); else Console.WriteLine("Test GetUnion(Space s1, Space s2)_3 failed!"); //test GetUnion(Space s1, Space s2)_4 FirstSpace = new Space(); SecondSpace = new Space(); FirstSpace.Add(new System.Drawing.Point(1, 1)); FirstSpace.Add(new System.Drawing.Point(2, 2)); UnionSpace = new Space(); UnionSpace = Space.GetUnion(FirstSpace, SecondSpace); if (UnionSpace == FirstSpace + SecondSpace) Console.WriteLine("Test GetUnion(Space s1, Space s2)_4 passed!"); else Console.WriteLine("Test GetUnion(Space s1, Space s2)_4 failed!"); //test IntersectWith(Space s) FirstSpace = new Space(); SecondSpace = new Space(); FirstSpace.Add(new System.Drawing.Point(1, 1)); SecondSpace.Add(new System.Drawing.Point(2, 2)); SecondSpace.Add(new System.Drawing.Point(1, 1)); FirstSpace.IntersectWith(SecondSpace); if (FirstSpace.Size == 1 && FirstSpace.Points[0].X == 1 && FirstSpace.Points[0].Y == 1) Console.WriteLine("Test IntersectWith(Space s) passed!"); else Console.WriteLine("Test IntersectWith(Space s) failed!"); //test IntersectWith(List<Space> s) FirstSpace = new Space(new List<System.Drawing.Point>() { new System.Drawing.Point(1, 1) }); List<Space> Spaces = new List<Space>(); for (int i = 2; i < 100; i++) { List<System.Drawing.Point> points = new List<System.Drawing.Point>(); points.Add(new System.Drawing.Point(1, 1)); points.Add(new System.Drawing.Point(i, i)); Spaces.Add(new Space(points)); } FirstSpace.IntersectWith(Spaces); if (FirstSpace.Size == 1 && FirstSpace.Points[0].X == 1 && FirstSpace.Points[0].Y == 1) Console.WriteLine("Test IntersectWith(List<Space> s) passed!"); else Console.WriteLine("Test IntersectWith(List<Space> s) failed!"); //test GetEdge(Space s1, Space s2) FirstSpace = new Space(); SecondSpace = new Space(); FirstSpace.Add(new System.Drawing.Point(0, 0)); FirstSpace.Add(new System.Drawing.Point(1, 0)); FirstSpace.Add(new System.Drawing.Point(1, 1)); FirstSpace.Add(new System.Drawing.Point(0, 1)); SecondSpace.Add(new System.Drawing.Point(1, 1)); SecondSpace.Add(new System.Drawing.Point(1, 2)); SecondSpace.Add(new System.Drawing.Point(2, 1)); SecondSpace.Add(new System.Drawing.Point(2, 2)); Space Edge = Space.GetEdge(FirstSpace, SecondSpace); Console.WriteLine("Test for GetEdge(Space s1, Space s2) not implemented."); }