public Add ( ISpaceObject spaceObject ) : void | ||
spaceObject | ISpaceObject | Space object to add. |
리턴 | void |
/// <summary> /// Constructs a new demo. /// </summary> /// <param name="game">Game owning this demo.</param> public ParallelSpaceTestDemo(DemosGame game) : base(game) { for (int i = 0; i < 32; i++) { var space = new Space(null); space.ForceUpdater.Gravity = new Vector3(0, -9.81f, 0); var box = new Box(new Vector3(20 * i, 0, 0), 100, 1, 100); space.Add(box); //game.ModelDrawer.Add(box); for (int j = 0; j < 30; j++) { for (int k = 0; k < 10; k++) { box = new Box(new Vector3(20 * i, 2 + j * 1.1f, 0), 1, 1, 1, 1); entities.Add(box); space.Add(box); //game.ModelDrawer.Add(box); } } spaces.Add(space); } game.Camera.Position = new Vector3(20, 10, 70); }
public void AddToSpace(Space space) { LeftTread.AddToSpace(space); RightTread.AddToSpace(space); Turret.AddToSpace(space); space.Add(Body); }
/// <summary> /// Constructs the character and internal physics character controller. /// </summary> /// <param name="owningSpace">Space to add the character to.</param> /// <param name="camera">Camera to attach to the character.</param> /// <param name="game">The running game.</param> public SphereCharacterControllerInput(Space owningSpace, Camera camera, DemosGame game) { CharacterController = new SphereCharacterController(); CameraControlScheme = new FixedOffsetCameraControlScheme(CharacterController.Body, camera, game); Space = owningSpace; Space.Add(CharacterController); }
/// <summary> /// Constructs the character and internal physics character controller. /// </summary> /// <param name="owningSpace">Space to add the character to.</param> /// <param name="CameraToUse">Camera to attach to the character.</param> public SimpleCharacterControllerInput(Space owningSpace, Camera CameraToUse) { CharacterController = new SimpleCharacterController(Vector3.Zero, 2, .8f, 1f, 20); Space = owningSpace; Space.Add(CharacterController); Camera = CameraToUse; Deactivate(); }
/// <summary> /// Constructs the character and internal physics character controller. /// </summary> /// <param name="owningSpace">Space to add the character to.</param> /// <param name="cameraToUse">Camera to attach to the character.</param> public CharacterControllerInput(Space owningSpace, Camera cameraToUse) { CharacterController = new CharacterController(); Space = owningSpace; Space.Add(CharacterController); Camera = cameraToUse; Deactivate(); }
/// <summary> /// Constructs the character and internal physics character controller. /// </summary> /// <param name="owningSpace">Space to add the character to.</param> /// <param name="CameraToUse">Camera to attach to the character.</param> public CharacterControllerInputOld(Space owningSpace, Camera CameraToUse) { CharacterController = new CharacterControllerOld(Vector3.Zero, 2, .4f, 30f, 1.1f); Space = owningSpace; Space.Add(CharacterController); Camera = CameraToUse; Deactivate(); }
/// <summary> /// /// </summary> /// <param name="game"></param> /// <param name="space"></param> public RigidBody ( Entity entity, World world, float w, float h, float d, float mass ) : base(entity,world) { this.space = ((MPWorld)world).PhysSpace; var ms = new MotionState(); ms.AngularVelocity = MathConverter.Convert( entity.AngularVelocity ); ms.LinearVelocity = MathConverter.Convert( entity.LinearVelocity ); ms.Orientation = MathConverter.Convert( entity.Rotation ); ms.Position = MathConverter.Convert( entity.Position ); box = new Box( ms, w, h, d, mass ); box.PositionUpdateMode = PositionUpdateMode.Continuous; box.Tag = entity; space.Add( box ); }
/// <summary> /// Constructs a new wall. /// </summary> /// <param name="game">Game that this component belongs to.</param> /// <param name="space">Space to which the entities of the wall belong to.</param> /// <param name="detectorModel">Volume to detect incoming enemies.</param> /// <param name="detectorWorldMatrix">Transformation matrix to apply to the detector volume.</param> /// <param name="worldMatrix">Transformation matrix which positions and orients the entities of the wall.</param> /// <param name="blocksAcross">Number of blocks across the wall.</param> /// <param name="blocksTall">Number of blocks tall.</param> /// <param name="wallLength">Total length of the wall.</param> /// <param name="wallHeight">Total height of the wall.</param> /// <param name="blockThickness">Thickness of the wall.</param> public Health(Game game, Space space, Vector3 position) : base(game) { this.space = space; this.position = position; this.game = game; body = new Sphere(position, 15, 5); body.Tag = this; body.EventManager.InitialCollisionDetected += EntityEntersVolume; space.Add(body); isAlive = true; lifeTime = 0f; /*Sphere box = body as Sphere; Matrix scaling = Matrix.CreateScale(body.Radius); Model CubeModel; CubeModel = game.Content.Load<Model>("Models/cube"); EntityModel model1 = new EntityModel(body, CubeModel, scaling, game); game.Components.Add(model1); */ }
public PhysicsEngine() { Display.AtExit += Display_AtExit; for( int i = 0; i < ( Environment.ProcessorCount - 3 ); i++ ) { parallelLooper.AddThread(); } VoxelGridConvexPairHandler.EnsurePairsAreRegistered(); world = new Space(); world.ForceUpdater.Gravity = new Vector3( 0, -9.81f, 0 ); { int n; for( n = 0; n < 10; n++ ) { Vector3 origin = new Vector3( 1800, n * 8, 0 ); test_entitites[n] = new Box( origin, 4, 4, 4, 1 ); world.Add( test_entitites[n] ); } } }
public void AddToSpace(Space space) { foreach (var segment in Segments) { segment.AddToSpace(space); } foreach (var binding in SegmentAngularBindings) { space.Add(binding); } }
// Start is called before the first frame update void Start() { world.ForceUpdater.Gravity = new BEPUutilities.Vector3(0, -9.81f, 0); // floor world.Add(new Box(new BEPUutilities.Vector3(0, -1.0f, 0), 30, 1, 30)); GameObject prefab = Resources.Load("elsa") as GameObject; GameObject actor = MonoBehaviour.Instantiate(prefab, new Vector3(0, 3, 0), Quaternion.Euler(new Vector3(0, 0, 0))) as GameObject; var ac = actor.AddComponent <testActor>(); ac.cc = new BEPUphysics.Character.CharacterController(new BEPUutilities.Vector3(0, 3, 0), 1.0f, 1.0f * 0.7f, 1.0f * 0.3f, 0.5f, 0.001f, 10f, 0.8f, 1.3f, 8f, 3f, 1.5f, 1000f, 0, 0, 0, 0, 0, 0); world.Add(ac.cc); var vertices = new BEPUutilities.Vector3[] { new BEPUutilities.Vector3(-0.454f, 0.087f, -0.413f), new BEPUutilities.Vector3(-0.454f, 0.087f, 0.29f), new BEPUutilities.Vector3(-0.454f, 0.79f, -0.413f), new BEPUutilities.Vector3(0.454f, 0.79f, -0.413f), new BEPUutilities.Vector3(0.454f, 0.087f, 0.29f), new BEPUutilities.Vector3(0.454f, 0.087f, -0.413f), new BEPUutilities.Vector3(-0.333f, 1f, -0.5f), new BEPUutilities.Vector3(-0.333f, 0f, 0.5f), new BEPUutilities.Vector3(0.333f, 1f, -0.5f), new BEPUutilities.Vector3(0.333f, 0f, 0.5f), new BEPUutilities.Vector3(-0.333f, 1f, -0.5f), new BEPUutilities.Vector3(-0.5f, 0f, -0.5f), new BEPUutilities.Vector3(-0.5f, 1f, -0.5f), new BEPUutilities.Vector3(0.5f, 0f, -0.5f), new BEPUutilities.Vector3(0.333f, 1f, -0.5f), new BEPUutilities.Vector3(0.5f, 1f, -0.5f), new BEPUutilities.Vector3(-0.5f, 1f, -0.5f), new BEPUutilities.Vector3(-0.474f, 1.058f, -0.5f), new BEPUutilities.Vector3(-0.355f, 1.058f, -0.5f), new BEPUutilities.Vector3(-0.5f, 0f, -0.5f), new BEPUutilities.Vector3(-0.333f, 0f, 0.5f), new BEPUutilities.Vector3(-0.5f, 0f, 0.5f), new BEPUutilities.Vector3(0.333f, 0f, 0.5f), new BEPUutilities.Vector3(0.5f, 0f, -0.5f), new BEPUutilities.Vector3(0.5f, 0f, 0.5f), new BEPUutilities.Vector3(0.355f, 0.058f, 0.5f), new BEPUutilities.Vector3(0.474f, 1.058f, -0.5f), new BEPUutilities.Vector3(0.355f, 1.058f, -0.5f), new BEPUutilities.Vector3(0.474f, 0.058f, 0.5f), new BEPUutilities.Vector3(-0.355f, 1.058f, -0.5f), new BEPUutilities.Vector3(-0.474f, 1.058f, -0.5f), new BEPUutilities.Vector3(-0.474f, 0.058f, 0.5f), new BEPUutilities.Vector3(-0.355f, 0.058f, 0.5f), new BEPUutilities.Vector3(0.333f, 1f, -0.5f), new BEPUutilities.Vector3(0.474f, 1.058f, -0.5f), new BEPUutilities.Vector3(0.5f, 1f, -0.5f), new BEPUutilities.Vector3(0.355f, 1.058f, -0.5f), new BEPUutilities.Vector3(0.474f, 0.058f, 0.5f), new BEPUutilities.Vector3(0.5f, 0f, 0.5f), new BEPUutilities.Vector3(0.5f, 1f, -0.5f), new BEPUutilities.Vector3(0.474f, 1.058f, -0.5f), new BEPUutilities.Vector3(0.333f, 0f, 0.5f), new BEPUutilities.Vector3(0.5f, 0f, 0.5f), new BEPUutilities.Vector3(0.474f, 0.058f, 0.5f), new BEPUutilities.Vector3(0.355f, 0.058f, 0.5f), new BEPUutilities.Vector3(0.355f, 0.058f, 0.5f), new BEPUutilities.Vector3(0.355f, 1.058f, -0.5f), new BEPUutilities.Vector3(0.333f, 1f, -0.5f), new BEPUutilities.Vector3(0.333f, 0f, 0.5f), new BEPUutilities.Vector3(-0.333f, 0f, 0.5f), new BEPUutilities.Vector3(-0.474f, 0.058f, 0.5f), new BEPUutilities.Vector3(-0.5f, 0f, 0.5f), new BEPUutilities.Vector3(-0.355f, 0.058f, 0.5f), new BEPUutilities.Vector3(-0.474f, 0.058f, 0.5f), new BEPUutilities.Vector3(-0.474f, 1.058f, -0.5f), new BEPUutilities.Vector3(-0.5f, 1f, -0.5f), new BEPUutilities.Vector3(-0.5f, 0f, 0.5f), new BEPUutilities.Vector3(-0.355f, 0.058f, 0.5f), new BEPUutilities.Vector3(-0.333f, 0f, 0.5f), new BEPUutilities.Vector3(-0.333f, 1f, -0.5f), new BEPUutilities.Vector3(-0.355f, 1.058f, -0.5f), new BEPUutilities.Vector3(-0.5f, 0.049f, -0.451f), new BEPUutilities.Vector3(-0.454f, 0.79f, -0.413f), new BEPUutilities.Vector3(-0.5f, 0.882f, -0.451f), new BEPUutilities.Vector3(-0.454f, 0.087f, -0.413f), new BEPUutilities.Vector3(-0.5f, 0.049f, 0.382f), new BEPUutilities.Vector3(-0.5f, 0.882f, -0.451f), new BEPUutilities.Vector3(-0.454f, 0.79f, -0.413f), new BEPUutilities.Vector3(-0.454f, 0.087f, 0.29f), new BEPUutilities.Vector3(-0.5f, 0.049f, -0.451f), new BEPUutilities.Vector3(-0.5f, 0.049f, 0.382f), new BEPUutilities.Vector3(-0.454f, 0.087f, 0.29f), new BEPUutilities.Vector3(-0.454f, 0.087f, -0.413f), new BEPUutilities.Vector3(0.5f, 0.049f, -0.451f), new BEPUutilities.Vector3(0.5f, 0.882f, -0.451f), new BEPUutilities.Vector3(0.454f, 0.79f, -0.413f), new BEPUutilities.Vector3(0.454f, 0.087f, -0.413f), new BEPUutilities.Vector3(0.454f, 0.087f, 0.29f), new BEPUutilities.Vector3(0.5f, 0.049f, -0.451f), new BEPUutilities.Vector3(0.454f, 0.087f, -0.413f), new BEPUutilities.Vector3(0.5f, 0.049f, 0.382f), new BEPUutilities.Vector3(0.5f, 0.049f, 0.382f), new BEPUutilities.Vector3(0.454f, 0.79f, -0.413f), new BEPUutilities.Vector3(0.5f, 0.882f, -0.451f), new BEPUutilities.Vector3(0.454f, 0.087f, 0.29f), new BEPUutilities.Vector3(-0.5f, 0f, -0.5f), new BEPUutilities.Vector3(-0.5f, 0.049f, -0.451f), new BEPUutilities.Vector3(-0.5f, 0.882f, -0.451f), new BEPUutilities.Vector3(-0.5f, 0.049f, 0.382f), new BEPUutilities.Vector3(-0.5f, 1f, -0.5f), new BEPUutilities.Vector3(-0.5f, 0f, 0.5f), new BEPUutilities.Vector3(0.5f, 0.882f, -0.451f), new BEPUutilities.Vector3(0.5f, 0.049f, -0.451f), new BEPUutilities.Vector3(0.5f, 0f, -0.5f), new BEPUutilities.Vector3(0.5f, 0.049f, 0.382f), new BEPUutilities.Vector3(0.5f, 1f, -0.5f), new BEPUutilities.Vector3(0.5f, 0f, 0.5f), }; int[] indices = new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 8, 7, 9, 10, 11, 12, 10, 13, 11, 10, 14, 13, 13, 14, 15, 10, 16, 17, 17, 18, 10, 19, 20, 21, 22, 20, 19, 19, 23, 22, 22, 23, 24, 25, 26, 27, 26, 25, 28, 29, 30, 31, 31, 32, 29, 33, 34, 35, 33, 36, 34, 37, 38, 39, 37, 39, 40, 41, 42, 43, 43, 44, 41, 45, 46, 47, 47, 48, 45, 49, 50, 51, 49, 52, 50, 53, 54, 55, 55, 56, 53, 57, 58, 59, 57, 59, 60, 61, 62, 63, 61, 64, 62, 65, 66, 67, 67, 68, 65, 69, 70, 71, 71, 72, 69, 73, 74, 75, 75, 76, 73, 77, 78, 79, 78, 77, 80, 81, 82, 83, 81, 84, 82, 85, 86, 87, 88, 86, 85, 85, 87, 89, 89, 87, 88, 85, 90, 88, 89, 88, 90, 91, 92, 93, 93, 92, 94, 93, 95, 91, 94, 91, 95, 93, 94, 96, 95, 96, 94 }; var stair = new BEPUphysics.BroadPhaseEntries.StaticMesh(vertices, indices, new BEPUutilities.AffineTransform(new BEPUutilities.Vector3(0.5f, 0.5f, 0.5f), BEPUutilities.Quaternion.Identity, new BEPUutilities.Vector3(0, 0, 0))); world.Add(stair); }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); hudFont = Content.Load<SpriteFont>(@"hudFont"); space = new Space(); space.ForceUpdater.Gravity = new Vector3(0, -9.81f, 0); //space2 = new Space(); //space2.ForceUpdater.Gravity = new Vector3(0, -9.81f, 0); terrain = new BasicModel(this, Content.Load<Model>(@"Models/terrain"), true); StaticMesh terrainMesh = GetTerrainMesh(terrain, Matrix.Identity); //terrainMesh.Material.StaticFriction = 0; //terrainMesh.Material.KineticFriction = 1; space.Add(terrainMesh); terrainMesh.Tag = terrain; // StaticMesh terrainMesh2 = GetTerrainMesh(terrain, Matrix.Identity); // space2.Add(terrainMesh2); // ferns for (int i = 0; i < 20; i++) { Vector3 position = getSafeSpawn(0); Console.WriteLine(position); BasicModel tree = new BasicModel(this, Content.Load<Model>(@"Models/fern"), position, true); StaticMesh treeMesh = GetTerrainMesh(tree, Matrix.CreateTranslation(position)); Components.Add(tree); } // palm trees for (int i = 0; i < 5; i++) { Vector3 position = getSafeSpawn(0); Console.WriteLine(position); BasicModel tree = new BasicModel(this, Content.Load<Model>(@"Models/palmTree"), position, true); StaticMesh treeMesh = GetTerrainMesh(tree, Matrix.CreateTranslation(position)); Components.Add(tree); } //adding character cube = new ControllableModel(this, Content.Load<Model>(@"Models/character"), new Box(new Vector3(0, 10, 0), 1, 1, 1, 2)); space.Add(cube.entity); cube.entity.Material.KineticFriction = 1; cube.entity.Tag = cube; //Adding skydome Matrix skyDomeRotate = Matrix.CreateRotationX(MathHelper.Pi); BasicModel skyDome = new BasicModel(this, Content.Load<Model>(@"Models/skyDome"), skyDomeRotate, true); //adding rings totalRings = 16; for (int i = 0; i < totalRings; i++ ) { makeCoin(getSafeSpawn(r.Next(25,35))); } // baobab trees for (int i = 0; i < 5; i++) { Vector3 position = getSafeSpawn(0); BasicModel tree = new BasicModel(this, Content.Load<Model>(@"Models/baobabTree"),position,true); Cylinder treeBox = new Cylinder(position, 10,3, 1); treeBox.Mass = float.PositiveInfinity; space.Add(treeBox); treeBox.Tag = tree; Components.Add(tree); } Components.Add(skyDome); Components.Add(terrain); Components.Add(cube); // turn off backface culling //RasterizerState rs = new RasterizerState(); //rs.CullMode = CullMode.None; //GraphicsDevice.RasterizerState = rs; }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. _spriteBatch = new SpriteBatch(GraphicsDevice); // load models _footballModel = Content.Load<Model>("mdl/football"); var pitchModel = Content.Load<Model>("mdl/pitch"); // initialise physics simulation space _space = new Space(); _space.ForceUpdater.Gravity = new Vector3(0, -9.81f, 0); Vector3[] vertices; int[] indices; TriangleMesh.GetVerticesAndIndicesFromModel(pitchModel, out vertices, out indices); var mesh = new StaticMesh(vertices, indices, new BEPUphysics.MathExtensions.AffineTransform(new Vector3(0, -40.0f, 0))); _space.Add(mesh); Components.Add(new StaticModel(pitchModel, mesh.WorldTransform.Matrix, this)); var sphere = new Sphere(new Vector3(0, 4, 0), 1, 1); _space.Add(sphere); var scaling = Matrix.CreateScale(sphere.Radius); var model = new EntityModel(sphere, _footballModel, scaling, this); Components.Add(model); //sphere.Tag = model; }
public void AddToSpace(Space space) { space.Add(Entity); space.Add(Motor); space.Add(SuspensionAxisJoint); space.Add(SuspensionLengthLimit); space.Add(SuspensionSpring); space.Add(SuspensionAngularJoint); }
public override void OnAdditionToSpace(Space newSpace) { newSpace.Add(linearMotor); newSpace.Add(angularMotor); }
public void AddToSpace(Space space) { space.Add(Body); space.Add(Barrel); space.Add(TankToTurretJoint); space.Add(TurretBodyToBarrelJoint); }
/// <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); } }
protected override void LoadContent() { //This 1x1x1 cube model will represent the box entities in the space. CubeModel = Content.Load<Model>("cube"); PlaygroundModel = Content.Load<Model>("playground"); //Robert 2. Snowman = Content.Load<Model>("set2"); //Construct a new space for the physics simulation to occur within. space = new Space(); //Set the gravity of the simulation by accessing the simulation settings of the space. //It defaults to (0,0,0); this changes it to an 'earth like' gravity. //Try looking around in the space's simulationSettings to familiarize yourself with the various options. space.ForceUpdater.Gravity = new Vector3(0, -9.81f*2, 0); //Make a box representing the ground and add it to the space. //The Box is an "Entity," the main simulation object type of BEPUphysics. //Examples of other entities include cones, spheres, cylinders, and a bunch more (a full listing is in the BEPUphysics.Entities namespace). //Every entity has a set of constructors. Some half a parameter for mass, others don't. //Constructors that allow the user to specify a mass create 'dynamic' entiites which fall, bounce around, and generally work like expected. //Constructors that have no mass parameter create a create 'kinematic' entities. These can be thought of as having infinite mass. //This box being added is representing the ground, so the width and length are extended and it is kinematic. Box ground = new Box(Vector3.Zero, 30, 1, 30); space.Add(ground); //Now that we have something to fall on, make a few more boxes. //These need to be dynamic, so give them a mass- in this case, 1 will be fine. space.Add(new Box(new Vector3(0, 4, 0), 1, 1, 1, 1)); space.Add(new Box(new Vector3(0, 8, 0), 1, 1, 1, 1)); space.Add(new Sphere(new Vector3(3,0,2), 1,1)); //Create a physical environment from a triangle mesh. //First, collect the the mesh data from the model using a helper function. //This special kind of vertex inherits from the TriangleMeshVertex and optionally includes //friction/bounciness data. //The StaticTriangleGroup requires that this special vertex type is used in lieu of a normal TriangleMeshVertex array. // Vector3[] vertices; // int[] indices; // TriangleMesh.GetVerticesAndIndicesFromModel(Snowman, out vertices, out indices); //Give the mesh information to a new StaticMesh. //Give it a transformation which scoots it down below the kinematic box entity we created earlier. //var mesh = new StaticMesh(vertices, indices, new AffineTransform(new Vector3(0, -20, 0))); //Add it to the space! //space.Add(mesh); //Make it visible too. //Components.Add(new StaticModel(Snowman, mesh.WorldTransform.Matrix, this)); //Robert 2 : ADD YOUR PREVIOUSLY DECLARED MODeL HERE using AddModel: AddModel(Snowman); //Hook an event handler to an entity to handle some game logic. //Refer to the Entity Events documentation for more information. Box deleterBox = new Box(new Vector3(5, 2, 0), 3, 3, 3); space.Add(deleterBox); deleterBox.CollisionInformation.Events.InitialCollisionDetected += HandleCollision; //Go through the list of entities in the space and create a graphical representation for them. foreach (Entity e in space.Entities) { Box box = e as Box; if (box != null) //This won't create any graphics for an entity that isn't a box since the model being used is a box. { Matrix scaling = Matrix.CreateScale(box.Width, box.Height, box.Length); //Since the cube model is 1x1x1, it needs to be scaled to match the size of each individual box. EntityModel model = new EntityModel(e, CubeModel, scaling, this); //Add the drawable game component for this entity to the game. Components.Add(model); e.Tag = model; //set the object tag of this entity to the model so that it's easy to delete the graphics component later if the entity is removed. } } }
public virtual void AddToGame(Space s) { TemporarilyMuteVoice = false; MediaSystem.PlayTrack(levelTheme.Song); overlay = new OpeningOverlay(levelNumber < 12 ? levelNumber : levelNumber - 11, levelNumber > 11, levelName); time = new TimeSpan(); RebuildTiming(); foreach(OperationalMachine m in MachineList.Keys) s.Add(m); s.Add(levelModel); foreach(Tube t in tubeList) s.Add(t); foreach(BaseModel m in glassModels) if(m.Ent.Space == null) s.Add(m); s.Add(dispenser); if(levelTheme.Fluid != null) s.Add(levelTheme.Fluid); addModelsToRenderer(); results = null; ending = badEnding = false; }
void resetScene() { for (int i = 0; i < children.Count(); i++) { if (children[i] is BepuEntity) { children.Remove(children[i]); i--; } } space = null; space = new Space(); space.ForceUpdater.Gravity = new Vector3(0, -9.8f, 0); groundBox = new Box(Vector3.Zero, ground.width, 0.1f, ground.height); space.Add(groundBox); cameraCylindar = new Cylinder(Camera.Position, 5, 2); space.Add(cameraCylindar); createTower(); createWall(); jointDemo(); }
public override void OnAdditionToSpace(Space newSpace) { newSpace.Add(linearMotor); newSpace.Add(angularMotor); }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); space = new Space(); space.ForceUpdater.Gravity = new Vector3(0, -9.81f, 0); Box groundBox = new Box(Vector3.Zero, ground.width, 0.1f, ground.height); space.Add(groundBox); cameraCylindar = new Cylinder(Camera.pos, 5, 5); space.Add(cameraCylindar); createTower(); createWall(); foreach (GameEntity child in children) { child.LoadContent(); } }
public void AddToGame(Space s) { RenderingDevice.Add(buff, blackTex); if(Ent.Space == null) s.Add(Ent); if(BlackSquare.Space == null) s.Add(BlackSquare); }
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> /// Constructs the front end and the internal physics representation of the vehicle. /// </summary> /// <param name="position">Position of the tank.</param> /// <param name="owningSpace">Space to add the vehicle to.</param> /// <param name="camera">Camera to attach to the vehicle.</param> /// <param name="game">Running game.</param> /// <param name="drawer">Drawer used to draw the tank.</param> /// <param name="wheelModel">Model to use for the 'wheels' of the tank.</param> /// <param name="wheelTexture">Texture of the wheels on the tank.</param> public TankInput(Vector3 position, Space owningSpace, Camera camera, DemosGame game, ModelDrawer drawer, Model wheelModel, Texture2D wheelTexture) { var bodies = new List<CompoundShapeEntry>() { new CompoundShapeEntry(new BoxShape(4f, 1, 8), new Vector3(0, 0, 0), 500), new CompoundShapeEntry(new BoxShape(3, .7f, 4f), new Vector3(0, .5f + .35f, .5f), 1) }; var body = new CompoundBody(bodies, 501); body.CollisionInformation.LocalPosition = new Vector3(0, .5f, 0); body.Position = (position); //At first, just keep it out of the way. Vehicle = new Vehicle(body); #region RaycastWheelShapes //The wheel model used is not aligned initially with how a wheel would normally look, so rotate them. MaximumDriveForce = 1800; BaseSlidingFriction = 3; Matrix wheelGraphicRotation = Matrix.CreateFromAxisAngle(Vector3.Forward, MathHelper.PiOver2); for (int i = 0; i < 6; i++) { var toAdd = new Wheel( new RaycastWheelShape(.375f, wheelGraphicRotation), new WheelSuspension(2000, 300f, Vector3.Down, 1.3f, new Vector3(-1.9f, 0, -2.9f + i * 1.15f)), new WheelDrivingMotor(10, MaximumDriveForce, MaximumDriveForce), new WheelBrake(7, 7, 1.0f), new WheelSlidingFriction(BaseSlidingFriction, BaseSlidingFriction)); toAdd.DrivingMotor.GripFrictionBlender = FrictionBlender; toAdd.Brake.FrictionBlender = FrictionBlender; toAdd.SlidingFriction.FrictionBlender = FrictionBlender; Vehicle.AddWheel(toAdd); leftTrack.Add(toAdd); } for (int i = 0; i < 6; i++) { var toAdd = new Wheel( new RaycastWheelShape(.375f, wheelGraphicRotation), new WheelSuspension(2000, 300f, Vector3.Down, 1.3f, new Vector3(1.9f, 0, -2.9f + i * 1.15f)), new WheelDrivingMotor(10, 2000, 1000), new WheelBrake(7, 7, 1.0f), new WheelSlidingFriction(BaseSlidingFriction, BaseSlidingFriction)); toAdd.DrivingMotor.GripFrictionBlender = FrictionBlender; toAdd.Brake.FrictionBlender = FrictionBlender; toAdd.SlidingFriction.FrictionBlender = FrictionBlender; Vehicle.AddWheel(toAdd); rightTrack.Add(toAdd); } #endregion foreach (Wheel wheel in Vehicle.Wheels) { //This is a cosmetic setting that makes it looks like the car doesn't have antilock brakes. wheel.Shape.FreezeWheelsWhileBraking = true; //By default, wheels use as many iterations as the space. By lowering it, //performance can be improved at the cost of a little accuracy. wheel.Suspension.SolverSettings.MaximumIterationCount = 1; wheel.Brake.SolverSettings.MaximumIterationCount = 1; wheel.SlidingFriction.SolverSettings.MaximumIterationCount = 1; wheel.DrivingMotor.SolverSettings.MaximumIterationCount = 1; } Space = owningSpace; Space.Add(Vehicle); ModelDrawer = drawer; DisplayModel model; WheelModels = new List<DisplayModel>(); for (int k = 0; k < Vehicle.Wheels.Count; k++) { Vehicle.Wheels[k].Shape.Detector.Tag = "noDisplayObject"; model = new DisplayModel(wheelModel, ModelDrawer); ModelDrawer.Add(model); WheelModels.Add(model); model.Texture = wheelTexture; } CameraControlScheme = new ChaseCameraControlScheme(Vehicle.Body, new Vector3(0, 0.6f, 0), true, 10, camera, game); }
/// <summary> /// Constructs the front end and the internal physics representation of the Vehicle. /// </summary> /// <param name="position">Position of the Vehicle.</param> /// <param name="space">Space to add the Vehicle to.</param> /// <param name="camera">Camera to attach to the Vehicle.</param> /// <param name="game">The running game.</param> /// <param name="drawer">Drawer used to draw the Vehicle.</param> /// <param name="wheelModel">Model of the wheels.</param> /// <param name="wheelTexture">Texture to use for the wheels.</param> public VehicleInput(Vector3 position, Space space, Camera camera, DemosGame game, ModelDrawer drawer, Model wheelModel, Texture2D wheelTexture) { var bodies = new List<CompoundShapeEntry> { new CompoundShapeEntry(new BoxShape(2.5f, .75f, 4.5f), new Vector3(0, 0, 0), 60), new CompoundShapeEntry(new BoxShape(2.5f, .3f, 2f), new Vector3(0, .75f / 2 + .3f / 2, .5f), 1) }; var body = new CompoundBody(bodies, 61); body.CollisionInformation.LocalPosition = new Vector3(0, .5f, 0); body.Position = position; //At first, just keep it out of the way. Vehicle = new Vehicle(body); var localWheelRotation = Quaternion.CreateFromAxisAngle(new Vector3(0, 0, 1), MathHelper.PiOver2); //The wheel model used is not aligned initially with how a wheel would normally look, so rotate them. Matrix wheelGraphicRotation = Matrix.CreateFromAxisAngle(Vector3.Forward, MathHelper.PiOver2); Vehicle.AddWheel(new Wheel( new CylinderCastWheelShape(.375f, 0.2f, localWheelRotation, wheelGraphicRotation, false), new WheelSuspension(2000, 100f, Vector3.Down, 0.325f, new Vector3(-1.1f, -0.1f, 1.8f)), new WheelDrivingMotor(2.5f, 30000, 10000), new WheelBrake(1.5f, 2, .02f), new WheelSlidingFriction(4, 5))); Vehicle.AddWheel(new Wheel( new CylinderCastWheelShape(.375f, 0.2f, localWheelRotation, wheelGraphicRotation, false), new WheelSuspension(2000, 100f, Vector3.Down, 0.325f, new Vector3(-1.1f, -0.1f, -1.8f)), new WheelDrivingMotor(2.5f, 30000, 10000), new WheelBrake(1.5f, 2, .02f), new WheelSlidingFriction(4, 5))); Vehicle.AddWheel(new Wheel( new CylinderCastWheelShape(.375f, 0.2f, localWheelRotation, wheelGraphicRotation, false), new WheelSuspension(2000, 100f, Vector3.Down, 0.325f, new Vector3(1.1f, -0.1f, 1.8f)), new WheelDrivingMotor(2.5f, 30000, 10000), new WheelBrake(1.5f, 2, .02f), new WheelSlidingFriction(4, 5))); Vehicle.AddWheel(new Wheel( new CylinderCastWheelShape(.375f, 0.2f, localWheelRotation, wheelGraphicRotation, false), new WheelSuspension(2000, 100f, Vector3.Down, 0.325f, new Vector3(1.1f, -0.1f, -1.8f)), new WheelDrivingMotor(2.5f, 30000, 10000), new WheelBrake(1.5f, 2, .02f), new WheelSlidingFriction(4, 5))); foreach (Wheel wheel in Vehicle.Wheels) { //This is a cosmetic setting that makes it looks like the car doesn't have antilock brakes. wheel.Shape.FreezeWheelsWhileBraking = true; //By default, wheels use as many iterations as the space. By lowering it, //performance can be improved at the cost of a little accuracy. //However, because the suspension and friction are not really rigid, //the lowered accuracy is not so much of a problem. wheel.Suspension.SolverSettings.MaximumIterationCount = 1; wheel.Brake.SolverSettings.MaximumIterationCount = 1; wheel.SlidingFriction.SolverSettings.MaximumIterationCount = 1; wheel.DrivingMotor.SolverSettings.MaximumIterationCount = 1; } Space = space; Space.Add(Vehicle); ModelDrawer = drawer; DisplayModel model; WheelModels = new List<DisplayModel>(); for (int k = 0; k < 4; k++) { Vehicle.Wheels[k].Shape.Detector.Tag = "noDisplayObject"; model = new DisplayModel(wheelModel, ModelDrawer); ModelDrawer.Add(model); WheelModels.Add(model); model.Texture = wheelTexture; } CameraControlScheme = new ChaseCameraControlScheme(Vehicle.Body, new Vector3(0, 0.6f, 0), true, 10, camera, game); }
int BuildWallSimulation(Space space) { #if WINDOWS int width = 100; int height = 40; NarrowPhaseHelper.Factories.BoxBox.EnsureCount(20000); #else NarrowPhaseHelper.Factories.BoxBox.EnsureCount(2000); int width = 25; int height = 15; #endif float blockWidth = 2f; float blockHeight = 1f; float blockLength = 3f; 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); toAdd.ActivityInformation.IsAlwaysActive = true; space.Add(toAdd); } } Box ground = new Box(new Vector3(0, -5f, 0), 500, 10, 500); space.Add(ground); #if WINDOWS return 800; #else return 400; #endif }
/// <summary> /// Initializes this cannon ball. /// </summary> /// <param name="manager">Manager of this cannonball.</param> /// <param name="space">Space that the physical form of this cannon ball resides in.</param> /// <param name="position">Point to put the cannon ball.</param> /// <param name="initialVelocity">Initial velocity of the cannon ball.</param> public void Initialize(EnemyCannonBallManager manager, Space space, Vector3 position, Vector3 initialVelocity) { Manager = manager; body.CollisionRules.Group = EnemyCannonBallCollisionGroup; Space = space; Body.CenterPosition = position; Body.LinearVelocity = initialVelocity; Space.Add(Body); // Body.AngularVelocity = new Vector3(2, -3, 1); //random-looking angular velocity. shouldDraw = false; numFramesSinceInitialized = 0; IsActive = true; }
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> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { balls = new List<Cannonball>(); // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); view = Matrix.CreateLookAt(campos, lookat, Vector3.Up); proj = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4, (1.0f / 2.0f), 1.0f, 10000.0f); view2 = Matrix.CreateLookAt(cam2pos, lookat, Vector3.Up); proj2 = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4, (1.0f / 2.0f), 1.0f, 10000.0f); player.LoadContent(Content); ball = new Cannonball(new Vector3(0, 700, 0), Content.Load<Model>("cannonBall"), -90, 0, 40); myterrain = Content.Load<Model>("terrain"); totalview = GraphicsDevice.Viewport; leftview = totalview; rightview = totalview; leftview.Width = leftview.Width / 2; rightview.Width = rightview.Width / 2; rightview.X = leftview.Width; spc = new Space(); ground = new Box(Vector3.Zero, 30, 1, 30); cannon = new Sphere(new Vector3(0, 70, 0), 30, 10); spc.Add(ground); spc.ForceUpdater.Gravity = new Vector3(0, -9.81f, 0); // TODO: use this.Content to load your game content here }
/// <summary> /// Constructs a new wall. /// </summary> /// <param name="game">Game that this component belongs to.</param> /// <param name="space">Space to which the entities of the wall belong to.</param> /// <param name="detectorModel">Volume to detect incoming enemies.</param> /// <param name="detectorWorldMatrix">Transformation matrix to apply to the detector volume.</param> /// <param name="worldMatrix">Transformation matrix which positions and orients the entities of the wall.</param> /// <param name="blocksAcross">Number of blocks across the wall.</param> /// <param name="blocksTall">Number of blocks tall.</param> /// <param name="wallLength">Total length of the wall.</param> /// <param name="wallHeight">Total height of the wall.</param> /// <param name="blockThickness">Thickness of the wall.</param> public Wall(Game game, Space space, Matrix detectorWorldMatrix, Matrix worldMatrix, int blocksAcross, int blocksTall, float wallLength, float wallHeight, float blockThickness) : base(game) { IsAlive = true; DespawnInterval = 0.2f; Space = space; float blockHeight = wallHeight / blocksTall; float blockWidth = wallLength / (blocksAcross + .5f); Vector3 BoduingMin; Vector3 BoduingMax; this.worldMatrix = worldMatrix; orientationMatrix = worldMatrix; orientationMatrix.Translation = Vector3.Zero; Vector3 position; float x, y = blockHeight * .5f; for (int i = 0; i < blocksTall; i++) { if (i % 2 == 0) { x = -blockWidth * (blocksAcross * .5f); position = new Vector3(x, y, 0); Vector3.Transform(ref position, ref worldMatrix, out position); toAddBox = new Box(position, blockWidth / 2, blockHeight, blockThickness); toAddBox.OrientationMatrix = orientationMatrix; space.Add(toAddBox); blocks.Add(toAddBox); x += blockWidth * .75f; } else { x = -blockWidth * (blocksAcross * .5f - .25f); position = new Vector3(x + blockWidth * (blocksAcross - .25f), y, 0); Vector3.Transform(ref position, ref worldMatrix, out position); toAddBox = new Box(position, blockWidth / 2, blockHeight, blockThickness); toAddBox.OrientationMatrix = orientationMatrix; space.Add(toAddBox); blocks.Add(toAddBox); } for (int j = 0; j < blocksAcross; j++) { position = new Vector3(x, y, 0); Vector3.Transform(ref position, ref worldMatrix, out position); toAddBox = new Box(position, blockWidth, blockHeight, blockThickness); toAddBox.OrientationMatrix = orientationMatrix; space.Add(toAddBox); blocks.Add(toAddBox); x += blockWidth; } y += blockHeight; } // BoundingBox float bX,bZ; if (blocks[blocks.Count - 1].WorldTransform.Translation.X > 0) bX = blockThickness; else bX = -blockThickness; if (blocks[blocks.Count - 1].WorldTransform.Translation.Z > 0) bZ = blockThickness; else bZ = -blockThickness; BoduingMin = blocks[0].WorldTransform.Translation ; BoduingMax = blocks[blocks.Count-1].WorldTransform.Translation + new Vector3(bX,0,bZ); Vector3 min = Vector3.Zero; Vector3 max = Vector3.Zero; min.X = Math.Min(BoduingMin.X, BoduingMax.X); min.Y = Math.Min(BoduingMin.Y, BoduingMax.Y); min.Z = Math.Min(BoduingMin.Z, BoduingMax.Z); max.X = Math.Max(BoduingMin.X, BoduingMax.X); max.Y = Math.Max(BoduingMin.Y, BoduingMax.Y); max.Z = Math.Max(BoduingMin.Z, BoduingMax.Z); boundingBox = new BoundingBox(min, max); foreach (Box block in blocks) { block.EventManager.InitialCollisionDetected += EntityEntersVolume; block.Tag = this; } }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); space = new Space(); space.ForceUpdater.Gravity = new Vector3(0, -9.8f, 0); LineDrawer = new BasicEffect(GraphicsDevice); //groundBox = new Box(Vector3.Zero, ground.width, 0.1f, ground.height); //space.Add(groundBox); cameraCylindar = new Cylinder(Camera.Position, 5, 2); space.Add(cameraCylindar); SkySphere skySphere = new SkySphere(); children.Add(skySphere); terrain = new Terrain(); children.Add(terrain); //createTower(); //createWall(); //jointDemo(); Font = Content.Load<SpriteFont>("Verdana"); brTexture = Content.Load<Texture2D>("saveMyBabies5"); crosshairs = Content.Load<Texture2D>("sprites_crosshairs"); foreach (GameEntity child in children) { child.LoadContent(); } }