public override void Initialize() { Children = new System.Collections.Generic.List<Aperture3D.Base.INode>(); physicsSpace = new Space(); Initialized = true; }
public CollisionUtil(Space world) { World = world; // NonSolid Vs. Solid,NonSolid,WorldSolid (All) CollisionGroup.DefineCollisionRule(NonSolid, WorldSolid, CollisionRule.NoBroadPhase); CollisionGroup.DefineCollisionRule(WorldSolid, NonSolid, CollisionRule.NoBroadPhase); CollisionGroup.DefineCollisionRule(NonSolid, NonSolid, CollisionRule.NoBroadPhase); CollisionGroup.DefineCollisionRule(NonSolid, Solid, CollisionRule.NoBroadPhase); CollisionGroup.DefineCollisionRule(Solid, NonSolid, CollisionRule.NoBroadPhase); // Player Vs. NonSolid,Player CollisionGroup.DefineCollisionRule(Player, NonSolid, CollisionRule.NoBroadPhase); CollisionGroup.DefineCollisionRule(NonSolid, Player, CollisionRule.NoBroadPhase); CollisionGroup.DefineCollisionRule(Player, Player, CollisionRule.NoBroadPhase); // Item Vs. NonSolid (All) CollisionGroup.DefineCollisionRule(Item, NonSolid, CollisionRule.NoBroadPhase); CollisionGroup.DefineCollisionRule(NonSolid, Item, CollisionRule.NoBroadPhase); // Water Vs. NonSolid,Solid,Player,Item (All) CollisionGroup.DefineCollisionRule(Water, NonSolid, CollisionRule.NoBroadPhase); CollisionGroup.DefineCollisionRule(NonSolid, Water, CollisionRule.NoBroadPhase); CollisionGroup.DefineCollisionRule(Water, Solid, CollisionRule.NoBroadPhase); CollisionGroup.DefineCollisionRule(Solid, Water, CollisionRule.NoBroadPhase); CollisionGroup.DefineCollisionRule(Water, Player, CollisionRule.NoBroadPhase); CollisionGroup.DefineCollisionRule(Player, Water, CollisionRule.NoBroadPhase); CollisionGroup.DefineCollisionRule(Water, Item, CollisionRule.NoBroadPhase); CollisionGroup.DefineCollisionRule(Item, Water, CollisionRule.NoBroadPhase); // Non-player Character Vs. NonSolid,Item,Water CollisionGroup.DefineCollisionRule(Character, NonSolid, CollisionRule.NoBroadPhase); CollisionGroup.DefineCollisionRule(NonSolid, Character, CollisionRule.NoBroadPhase); CollisionGroup.DefineCollisionRule(Character, Water, CollisionRule.NoBroadPhase); CollisionGroup.DefineCollisionRule(Water, Character, CollisionRule.NoBroadPhase); CollisionGroup.DefineCollisionRule(Character, Item, CollisionRule.NoBroadPhase); CollisionGroup.DefineCollisionRule(Item, Character, CollisionRule.NoBroadPhase); }
/// <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); }
/// <summary> /// Determines whether there is a cliff nearby. /// </summary> /// <param name="position">Position to look from.</param> /// <param name="facingDirection">Direction to check in.</param> /// <param name="filter">Anonymous function to filter out unwanted objects.</param> /// <param name="space">The space to check for a cliff in.</param> /// <param name="distance">The distance to check at.</param> /// <returns>True if a cliff was detected, false otherwise.</returns> public static bool FindCliff(Vector3 position, Vector3 facingDirection, Func<BroadPhaseEntry, bool> filter, Space space, float distance) { // If there is a wall before the requested distance assume there is no cliff. Ray forwardRay = new Ray(position, new Vector3(facingDirection.X, 0, facingDirection.Z)); RayCastResult forwardResult = new RayCastResult(); space.RayCast(forwardRay, filter, out forwardResult); if ((forwardResult.HitData.Location - position).Length() < distance) { return false; } facingDirection.Normalize(); Ray futureDownRay = new Ray(position + new Vector3(facingDirection.X * distance, 0, facingDirection.Z * distance), Vector3.Down); RayCastResult result = new RayCastResult(); space.RayCast(futureDownRay, filter, out result); Vector3 drop = result.HitData.Location - futureDownRay.Position; if (drop.Y < -6.0f) { return true; } else { return false; } }
/// <summary> /// Scales the configuration settings for collision detection and response to handle /// a different scale interpretation. For example, if you want to increase your gravity to -100 from -10 and consider a 5 unit wide box to be tiny, /// apply a scale of 10 to get the collision response and detection systems to match expectations. /// </summary> /// <param name="space">Space to configure.</param> /// <param name="scale">Scale to apply to relevant configuration settings.</param> public static void ApplyScale(BEPUphysics.Space space, float scale) { //Set all values to default values * scale. space.DeactivationManager.VelocityLowerLimit = 0.26f * scale; CollisionResponseSettings.MaximumPenetrationRecoverySpeed = 2 * scale; CollisionResponseSettings.BouncinessVelocityThreshold = 1 * scale; CollisionResponseSettings.StaticFrictionVelocityThreshold = .2f * scale; CollisionDetectionSettings.ContactInvalidationLength = .1f * scale; CollisionDetectionSettings.ContactMinimumSeparationDistance = .03f * scale; CollisionDetectionSettings.MaximumContactDistance = .1f * scale; CollisionDetectionSettings.DefaultMargin = .04f * scale; CollisionDetectionSettings.AllowedPenetration = .01f * scale; //Adjust epsilons, too. Toolbox.Epsilon = 1e-7f * scale; Toolbox.BigEpsilon = 1e-5f * scale; MPRToolbox.DepthRefinementEpsilon = 1e-4f * scale; MPRToolbox.RayCastSurfaceEpsilon = 1e-9f * scale; MPRToolbox.SurfaceEpsilon = 1e-7f * scale; PairSimplex.DistanceConvergenceEpsilon = 1e-7f * scale; PairSimplex.ProgressionEpsilon = 1e-8f * scale; //While not fully a size-related parameter, you may find that adjusting the SolverSettings.DefaultMinimumImpulse can help the simulation quality. //It is related to 'mass scale' instead of 'size scale.' //Heavy or effectively heavy objects will produce higher impulses and early out slower, taking more time than needed. //Light or effectively light objects will produce smaller impulses and early out faster, producing a lower quality result. }
/// <summary> /// Applies the default settings to the space. /// These values are what the engine starts with; they don't have to be applied unless you just want to get back to the defaults. /// This doesn't cover every single tunable field in the entire engine, just the main ones that this helper class is messing with. /// </summary> /// <param name="space">Space to configure.</param> public static void ApplyDefaultSettings(BEPUphysics.Space space) { MotionSettings.DefaultPositionUpdateMode = PositionUpdateMode.Discrete; SolverSettings.DefaultMinimumIterationCount = 1; space.Solver.IterationLimit = 10; GeneralConvexPairTester.UseSimplexCaching = false; MotionSettings.UseExtraExpansionForContinuousBoundingBoxes = false; //Set all the scaling settings back to their defaults. space.DeactivationManager.VelocityLowerLimit = 0.26f; CollisionResponseSettings.MaximumPenetrationRecoverySpeed = 2; CollisionResponseSettings.BouncinessVelocityThreshold = 1; CollisionResponseSettings.StaticFrictionVelocityThreshold = .2f; CollisionDetectionSettings.ContactInvalidationLength = .1f; CollisionDetectionSettings.ContactMinimumSeparationDistance = .03f; CollisionDetectionSettings.MaximumContactDistance = .1f; CollisionDetectionSettings.DefaultMargin = .04f; CollisionDetectionSettings.AllowedPenetration = .01f; SolverSettings.DefaultMinimumImpulse = 0.001f; //Adjust epsilons back to defaults. Toolbox.Epsilon = 1e-7f; Toolbox.BigEpsilon = 1e-5f; MPRToolbox.DepthRefinementEpsilon = 1e-4f; MPRToolbox.RayCastSurfaceEpsilon = 1e-9f; MPRToolbox.SurfaceEpsilon = 1e-7f; PairSimplex.DistanceConvergenceEpsilon = 1e-7f; PairSimplex.ProgressionEpsilon = 1e-8f; }
/// <summary> /// Applies some high quality, low performance settings. /// By using universal continuous collision detection, missed collisions /// will be much, much rarer. This actually doesn't have a huge performance cost. /// However, increasing the iteration limit and the minimum iterations to 5x the default /// will incur a pretty hefty overhead. /// On the upside, pretty much every simulation will be rock-solid. /// </summary> /// <param name="space">Space to configure.</param> public static void ApplyHighStabilitySettings(BEPUphysics.Space space) { MotionSettings.DefaultPositionUpdateMode = PositionUpdateMode.Continuous; MotionSettings.UseExtraExpansionForContinuousBoundingBoxes = true; SolverSettings.DefaultMinimumIterationCount = 5; space.Solver.IterationLimit = 50; }
public PhysicsSimulationComponent(Entity parent) : base(parent, "PhysicsSimulationComponent") { space = new Space(); space.ForceUpdater.Gravity = GRAVITY; space.TimeStepSettings.TimeStepDuration = TIME_STEP_DURATION; }
public void Draw(Effect effect, Space space) { contactLines.Clear(); int contactCount = 0; foreach (var pair in space.NarrowPhase.Pairs) { var pairHandler = pair as CollidablePairHandler; if (pairHandler != null) { foreach (ContactInformation information in pairHandler.Contacts) { contactCount++; contactLines.Add(new VertexPositionColor(information.Contact.Position, Color.White)); contactLines.Add(new VertexPositionColor(information.Contact.Position + information.Contact.Normal * information.Contact.PenetrationDepth, Color.Red)); contactLines.Add(new VertexPositionColor(information.Contact.Position + information.Contact.Normal * information.Contact.PenetrationDepth, Color.White)); contactLines.Add(new VertexPositionColor(information.Contact.Position + information.Contact.Normal * (information.Contact.PenetrationDepth + .3f), Color.White)); } } } if (contactCount > 0) { foreach (var pass in effect.CurrentTechnique.Passes) { pass.Apply(); game.GraphicsDevice.DrawUserPrimitives(PrimitiveType.LineList, contactLines.Elements, 0, contactLines.Count / 2); } } }
protected Demo(DemosGame game) { Game = game; 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 XBOX360 parallelLooper.AddThread(delegate { Thread.CurrentThread.SetProcessorAffinity(new[] { 1 }); }); parallelLooper.AddThread(delegate { Thread.CurrentThread.SetProcessorAffinity(new[] { 3 }); }); parallelLooper.AddThread(delegate { Thread.CurrentThread.SetProcessorAffinity(new[] { 4 }); }); parallelLooper.AddThread(delegate { Thread.CurrentThread.SetProcessorAffinity(new[] { 5 }); }); #else if (Environment.ProcessorCount > 1) { for (int i = 0; i < Environment.ProcessorCount; i++) { parallelLooper.AddThread(); } } #endif Space = new Space(parallelLooper); game.Camera.LockedUp = Vector3.Up; game.Camera.ViewDirection = new Vector3(0, 0, -1); }
/// <summary> /// Constructs an explosion. /// </summary> /// <param name="pos">Initial position of the explosion.</param> /// <param name="explosionMagnitude">Base strength of the blast as applied in units of impulse.</param> /// <param name="maxDist">Maximum radius of effect.</param> /// <param name="containingSpace">Space in which the explosion resides.</param> public Explosion(Vector3 pos, float explosionMagnitude, float maxDist, Space containingSpace) { Position = pos; Magnitude = explosionMagnitude; MaxDistance = maxDist; Space = containingSpace; }
// _divisions is the divisions in one direction / 2 public CollisionManager(int _width, int _height, int _depth, int _divisions) { width = _width; height = _height; depth = _depth; divisions = _divisions * _divisions * _divisions; toAdd = new LinkedList<CollisionBase>(); toRemove = new LinkedList<CollisionBase>(); /*#if DEBUG drawList = new List<SceneObject>(); #endif*/ space = new Space(); space.Solver.AllowMultithreading = true; space.Solver.IterationLimit = 1; Vector3 offset = new Vector3(-_width / 2, -_height / 2, -_depth / 2); sectors = new CollisionSector[divisions]; // Though we use _divisions for calculating for (int i = 0; i < _divisions; i++) { for (int j = 0; j < _divisions; j++) { for (int l = 0; l < _divisions; l++) { int x = ((i * width) / (2 * _divisions)) + (width / _divisions); int y = ((j * height) / (2 * _divisions)) + (height / _divisions); int z = ((l * depth) / (2 * _divisions)) + (depth / _divisions); sectors[i*_divisions*_divisions + j*_divisions + l] = new CollisionSector(offset + new Vector3(x, y, z), width / _divisions, height / _divisions, depth / _divisions); } } } }
public PhysicsQB() { if (threadManager == null) { threadManager = new BEPUphysics.Threading.SpecializedThreadManager(); //This section lets the engine know that it can make use of multithreaded systems //by adding threads to its thread pool. #if XBOX360 threadManager.AddThread(delegate { Thread.CurrentThread.SetProcessorAffinity(new[] { 1 }); }, null); threadManager.AddThread(delegate { Thread.CurrentThread.SetProcessorAffinity(new[] { 3 }); }, null); threadManager.AddThread(delegate { Thread.CurrentThread.SetProcessorAffinity(new[] { 4 }); }, null); //threadManager.AddThread(delegate { Thread.CurrentThread.SetProcessorAffinity(new[] { 5 }); }, null); #else if (Environment.ProcessorCount > 1) { for (int i = 0; i < Environment.ProcessorCount; i++) { threadManager.AddThread(); } } #endif } space = new Space(threadManager); }
/// <summary> /// Applies some high quality, low performance settings. /// By using universal continuous collision detection, missed collisions /// will be much, much rarer. This actually doesn't have a huge performance cost. /// However, increasing the iteration limit and the minimum iterations to 5x the default /// will incur a pretty hefty overhead. /// On the upside, pretty much every simulation will be rock-solid. /// </summary> /// <param name="space">Space to configure.</param> public static void ApplyHighStabilitySettings(Space space) { MotionSettings.DefaultPositionUpdateMode = PositionUpdateMode.Continuous; MotionSettings.UseExtraExpansionForContinuousBoundingBoxes = true; SolverSettings.DefaultMinimumIterations = 5; space.Solver.IterationLimit = 50; }
public void AddToSpace(Space space) { LeftTread.AddToSpace(space); RightTread.AddToSpace(space); Turret.AddToSpace(space); space.Add(Body); }
public void RemoveFromSpace(Space space) { LeftTread.RemoveFromSpace(space); RightTread.RemoveFromSpace(space); Turret.RemoveFromSpace(space); space.Remove(Body); }
public void Dispose() { foreach( Sector sector in active_sectors ) world.Remove( sector.grid ); active_sectors = null; world = null; }
/// <summary> /// Applies the default settings to the space. /// These values are what the engine starts with; they don't have to be applied unless you just want to get back to the defaults. /// This doesn't cover every single tunable field in the entire engine, just the main ones that this helper class is messing with. /// </summary> /// <param name="space">Space to configure.</param> public static void ApplyDefaultSettings(Space space) { MotionSettings.DefaultPositionUpdateMode = PositionUpdateMode.Discrete; SolverSettings.DefaultMinimumIterationCount = 1; space.Solver.IterationLimit = 10; GeneralConvexPairTester.UseSimplexCaching = false; MotionSettings.UseExtraExpansionForContinuousBoundingBoxes = false; //Set all the scaling settings back to their defaults. space.DeactivationManager.VelocityLowerLimit = 0.26f; CollisionResponseSettings.MaximumPenetrationRecoverySpeed = 2; CollisionResponseSettings.BouncinessVelocityThreshold = 1; CollisionResponseSettings.StaticFrictionVelocityThreshold = .2f; CollisionDetectionSettings.ContactInvalidationLength = .1f; CollisionDetectionSettings.ContactMinimumSeparationDistance = .03f; CollisionDetectionSettings.MaximumContactDistance = .1f; CollisionDetectionSettings.DefaultMargin = .04f; CollisionDetectionSettings.AllowedPenetration = .01f; SolverSettings.DefaultMinimumImpulse = 0.001f; //Adjust epsilons back to defaults. Toolbox.Epsilon = 1e-7f; Toolbox.BigEpsilon = 1e-5f; MPRToolbox.DepthRefinementEpsilon = 1e-4f; MPRToolbox.RayCastSurfaceEpsilon = 1e-9f; MPRToolbox.SurfaceEpsilon = 1e-7f; PairSimplex.DistanceConvergenceEpsilon = 1e-7f; PairSimplex.ProgressionEpsilon = 1e-8f; }
internal PhysicsManager() { instance = this; 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 XBOX360 parallelLooper.AddThread(delegate { Thread.CurrentThread.SetProcessorAffinity(new[] { 1 }); }); parallelLooper.AddThread(delegate { Thread.CurrentThread.SetProcessorAffinity(new[] { 3 }); }); parallelLooper.AddThread(delegate { Thread.CurrentThread.SetProcessorAffinity(new[] { 4 }); }); parallelLooper.AddThread(delegate { Thread.CurrentThread.SetProcessorAffinity(new[] { 5 }); }); #else if (Environment.ProcessorCount > 1) { for (int i = 0; i < Environment.ProcessorCount; i++) { parallelLooper.AddThread(); } } #endif Space = new BEPUphysics.Space(parallelLooper); Space.ForceUpdater.Gravity = new Vector3(0, -9.81f, 0f); Space.TimeStepSettings.MaximumTimeStepsPerFrame = 100; //Set up two stacks which go through each other firstStackGroup = new CollisionGroup(); secondStackGroup = new CollisionGroup(); //Adding this rule to the space's collision group rules will prevent entities belong to these two groups from generating collision pairs with each other. var groupPair = new CollisionGroupPair(firstStackGroup, secondStackGroup); //CollisionRules.CollisionGroupRules.Add(groupPair, CollisionRule.NoBroadPhase); }
/// <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 CharacterControllerInput(Space owningSpace, Camera camera, DemosGame game) { CharacterController = new CharacterController(); Camera = camera; CameraControlScheme = new CharacterCameraControlScheme(CharacterController, camera, game); Space = owningSpace; }
/// <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(); Camera = camera; CameraControlScheme = new FixedOffsetCameraControlScheme(CharacterController.Body, camera, game); Space = owningSpace; }
public void Initialize() { Space = new Space(); Space.ForceUpdater.Gravity = new Vector3(0, -9.8f, 0); Terrain = new TerrainManager(); ClientObjects = new EffectManager(); Ships = new ShipManager(); Objects = new MobileObjectManager(); }
public ModifiableLevel(Level level, Space space) : base(level.Name) { mSpace = space; foreach (Vector3 block in level.Blocks.Keys) { AddNewBlock(block); } }
/// <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> /// Inititalize physics engine<para/> /// Инициализация физического движка /// </summary> public static void Init() { // Create simulation // Создание симуляции World = new Space(); World.ForceUpdater.Gravity = new BEPUutilities.Vector3(0, -9.81f, 0); BEPUphysics.Settings.CollisionDetectionSettings.DefaultMargin = 0f; BEPUphysics.Settings.CollisionDetectionSettings.AllowedPenetration = 0f; //BEPUphysics.Settings.CollisionResponseSettings.PenetrationRecoveryStiffness = 0.005f; }
public BepuPhysicsSystem(Game game) : base(game) { this.looper = new BEPUutilities.Threading.ParallelLooper(); for (int g = 0; g < Environment.ProcessorCount - 1; g++) { this.looper.AddThread(); } this.space = new Space(this.looper); }
/// <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> /// 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(); }
public override void XStart() { nonMonoPhysics = new List <NonMonoBehaviorPhysics> (); dynamicColliders = new List <PhysicsBehaviourX>(); staticColliders = new List <PhysicsBehaviourX>(); _physicsSpace = new BEPUphysics.Space(); _physicsSpace.ForceUpdater.Gravity = Gravity.ToBEPU(); _physicsSpace.BufferedStates.Enabled = BufferedStates; _physicsSpace.Solver.IterationLimit = IterationLimit; //Don't need many iterations, there's not really any stacking going on in this game. _physicsSpace.TimeStepSettings.TimeStepDuration = TimeStep; //A slower timestep gives the Xbox a little breathing }
public void Draw(Effect effect, Space space) { if (space.Entities.Count > 0) { foreach (var e in space.Entities) { Vector3[] boundingBoxCorners = MathConverter.Convert(e.CollisionInformation.BoundingBox.GetCorners()); var color = e.ActivityInformation.IsActive ? Color.DarkRed : new Color(150, 100, 100); boundingBoxLines.Add(new VertexPositionColor(boundingBoxCorners[0], color)); boundingBoxLines.Add(new VertexPositionColor(boundingBoxCorners[1], color)); boundingBoxLines.Add(new VertexPositionColor(boundingBoxCorners[0], color)); boundingBoxLines.Add(new VertexPositionColor(boundingBoxCorners[3], color)); boundingBoxLines.Add(new VertexPositionColor(boundingBoxCorners[0], color)); boundingBoxLines.Add(new VertexPositionColor(boundingBoxCorners[4], color)); boundingBoxLines.Add(new VertexPositionColor(boundingBoxCorners[1], color)); boundingBoxLines.Add(new VertexPositionColor(boundingBoxCorners[2], color)); boundingBoxLines.Add(new VertexPositionColor(boundingBoxCorners[1], color)); boundingBoxLines.Add(new VertexPositionColor(boundingBoxCorners[5], color)); boundingBoxLines.Add(new VertexPositionColor(boundingBoxCorners[2], color)); boundingBoxLines.Add(new VertexPositionColor(boundingBoxCorners[3], color)); boundingBoxLines.Add(new VertexPositionColor(boundingBoxCorners[2], color)); boundingBoxLines.Add(new VertexPositionColor(boundingBoxCorners[6], color)); boundingBoxLines.Add(new VertexPositionColor(boundingBoxCorners[3], color)); boundingBoxLines.Add(new VertexPositionColor(boundingBoxCorners[7], color)); boundingBoxLines.Add(new VertexPositionColor(boundingBoxCorners[4], color)); boundingBoxLines.Add(new VertexPositionColor(boundingBoxCorners[5], color)); boundingBoxLines.Add(new VertexPositionColor(boundingBoxCorners[4], color)); boundingBoxLines.Add(new VertexPositionColor(boundingBoxCorners[7], color)); boundingBoxLines.Add(new VertexPositionColor(boundingBoxCorners[5], color)); boundingBoxLines.Add(new VertexPositionColor(boundingBoxCorners[6], color)); boundingBoxLines.Add(new VertexPositionColor(boundingBoxCorners[6], color)); boundingBoxLines.Add(new VertexPositionColor(boundingBoxCorners[7], color)); } foreach (var pass in effect.CurrentTechnique.Passes) { pass.Apply(); game.GraphicsDevice.DrawUserPrimitives(PrimitiveType.LineList, boundingBoxLines.Elements, 0, space.Entities.Count * 12); } boundingBoxLines.Clear(); } }
/// <summary> /// Constructs an explosion. /// </summary> /// <param name="pos">Initial position of the explosion.</param> /// <param name="explosionMagnitude">Base strength of the blast as applied in units of impulse.</param> /// <param name="maxDist">Maximum radius of effect.</param> /// <param name="containingSpace">Space in which the explosion resides.</param> public Explosion(Entity entity, float explosionMagnitude, float maxDist, Space containingSpace, Game game) : base(game) { this.entity = entity; Position = entity.WorldTransform.Translation; Magnitude = explosionMagnitude; MaxDistance = maxDist; Space = containingSpace; explosionParticles = Game.Services.GetService(typeof(ExplosionParticleSystem)) as ExplosionParticleSystem; explosionSmokeParticles = Game.Services.GetService(typeof(ExplosionSmokeParticleSystem)) as ExplosionSmokeParticleSystem; }
public ActorContainer(Space space, ModelDrawer modelDrawer, LineDrawer constraintDrawer, LightDrawer lightDrawer) { _space = space; _meshes = new List<LPPMesh>(); _deleteList = new List<Actor>(); _actors = new List<Actor>(); _components = new List<Component>(); _modelDrawer = modelDrawer; _constraintDrawer = constraintDrawer; _lightDrawer = lightDrawer; _actorDictionary = new Dictionary<string, Actor>(); Content = Game1.thegame.Content; }
protected override void Initialize() { Space = new Physics.Space(new Physics.PersistentUniformGrid(10)); Space.simulationSettings.gravity = new Vector3(0, -9.81f, 0); FMOD.Factory.System_Create(ref SoundSystem); SoundSystem.init(32, FMOD.INITFLAG.NORMAL, (IntPtr)null); InitializeModules(); InitializeBehaviors(); base.Initialize(); }
/// <summary> /// /// </summary> /// <param name="game"></param> /// <param name="space"></param> public Characters ( Entity entity, World world, float height = 1.7f, float crouchingHeight = 1.19f, float radius = 0.6f, float margin = 0.1f, float mass = 10f, float maximumTractionSlope = 0.8f, float maximumSupportSlope = 1.3f, float standingSpeed = 8f, float crouchingSpeed = 3f, float tractionForce = 1000f, float slidingSpeed = 6f, float slidingForce = 50f, float airSpeed = 1f, float airForce = 250f, float jumpSpeed = 6f, float slidingJumpSpeed = 3f, float maximumGlueForce = 5000f ) : base(entity,world) { this.space = ((MPWorld)world).PhysSpace; var pos = MathConverter.Convert( entity.Position ); controller = new CharacterController( pos, height , crouchingHeight , radius , margin , mass , maximumTractionSlope , maximumSupportSlope , standingSpeed , crouchingSpeed , tractionForce , slidingSpeed , slidingForce , airSpeed , airForce , jumpSpeed , slidingJumpSpeed , maximumGlueForce ); controller.StepManager.MaximumStepHeight = 0.5f; controller.Body.Tag = entity; controller.Tag = entity; space.Add( controller ); }
public Physics(Game game, Player player, ContentManager Content, TanksOnAHeightmap.GameBase.Shapes.Terrain terrain, Space space) { Cannon = new Cannon(game, player.tank); CannonBallManager = new CannonBallManager(game); EnemyCannon.playerTank = player.tank; healthManager = new HealthManager(game, space); this.Content = Content; this.Components = game.Components; this.game = game; this.player = player; this.tank = player.tank; this.terrain = terrain; this.space = space; }
/// <summary> /// Creates the physics scene and sets the defaults parameters. /// </summary> internal static void Initialize() { Scene = new Space(); // NOTE:PERFORMANCE // BEPUphysics uses an iterative system to solve constraints. You can tell it to do more or less iterations. // Less iterations is faster; more iterations makes the result more accurate. // // The amount of iterations needed for a simulation varies. The "Wall" and "Pyramid" simulations are each fairly // solver intensive, but as few as 4 iterations can be used with acceptable results. // The "Jenga" simulation usually needs a few more iterations for stability; 7-9 is a good minimum. // // The Dogbot demo shows how accuracy can smoothly increase with more iterations. // With very few iterations (1-3), it has slightly jaggier movement, as if the parts used to construct it were a little cheap. // As you give it a few more iterations, the motors and constraints get more and more robust. // // Many simulations can work perfectly fine with very few iterations, // and using a low number of iterations can substantially improve performance. // // To change the number of iterations used, uncomment and change the following line (10 iterations is the default): Scene.Solver.IterationLimit = 10; // Setup multithreading #if XBOX360 Scene.ThreadManager.AddThread(delegate(object information) { Thread.CurrentThread.SetProcessorAffinity(new int[] { 1 }); }, null); Scene.ThreadManager.AddThread(delegate(object information) { Thread.CurrentThread.SetProcessorAffinity(new int[] { 3 }); }, null); Scene.ThreadManager.AddThread(delegate(object information) { Thread.CurrentThread.SetProcessorAffinity(new int[] { 4 }); }, null); Scene.ThreadManager.AddThread(delegate(object information) { Thread.CurrentThread.SetProcessorAffinity(new int[] { 5 }); }, null); #else if (ProcessorsInformation.AvailableProcessors > 0) { // On windows, just throw a thread at every processor. // The thread scheduler will take care of where to put them. for (int i = 0; i < ProcessorsInformation.AvailableProcessors + 1; i++) { Scene.ThreadManager.AddThread(); } } #endif } // Initialize
/// <summary> /// Applies some higher quality settings. /// By using universal continuous collision detection, missed collisions /// will be much, much rarer. This actually doesn't have a huge performance cost. /// The increased iterations put this as a midpoint between the normal and high stability settings. /// </summary> /// <param name="space">Space to configure.</param> public static void ApplyMediumHighStabilitySettings(BEPUphysics.Space space) { MotionSettings.DefaultPositionUpdateMode = PositionUpdateMode.Continuous; SolverSettings.DefaultMinimumIterationCount = 2; space.Solver.IterationLimit = 15; }
/// <summary> /// Applies some low quality, high speed settings. /// The main benefit comes from the very low iteration cap. /// By enabling simplex caching, general convex collision detection /// gets a nice chunk faster, but some curved shapes lose collision detection robustness. /// </summary> /// <param name="space">Space to configure.</param> public static void ApplySuperSpeedySettings(BEPUphysics.Space space) { SolverSettings.DefaultMinimumIterationCount = 0; space.Solver.IterationLimit = 5; GeneralConvexPairTester.UseSimplexCaching = true; }