本文整理汇总了C#中BEPUphysics.Space类的典型用法代码示例。如果您正苦于以下问题:C# Space类的具体用法?C# Space怎么用?C# Space使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Space类属于BEPUphysics命名空间,在下文中一共展示了Space类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Explosion
/// <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;
}
示例2: CollisionManager
// _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);
}
}
}
}
示例3: Demo
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);
}
示例4: RemoveFromSpace
public void RemoveFromSpace(Space space)
{
LeftTread.RemoveFromSpace(space);
RightTread.RemoveFromSpace(space);
Turret.RemoveFromSpace(space);
space.Remove(Body);
}
示例5: ApplyHighStabilitySettings
/// <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;
}
示例6: AddToSpace
public void AddToSpace(Space space)
{
LeftTread.AddToSpace(space);
RightTread.AddToSpace(space);
Turret.AddToSpace(space);
space.Add(Body);
}
示例7: PhysicsSimulationComponent
public PhysicsSimulationComponent(Entity parent)
: base(parent, "PhysicsSimulationComponent")
{
space = new Space();
space.ForceUpdater.Gravity = GRAVITY;
space.TimeStepSettings.TimeStepDuration = TIME_STEP_DURATION;
}
示例8: Initialize
public override void Initialize()
{
Children = new System.Collections.Generic.List<Aperture3D.Base.INode>();
physicsSpace = new Space();
Initialized = true;
}
示例9: ParallelSpaceTestDemo
/// <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);
}
示例10: CollisionUtil
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);
}
示例11: Draw
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);
}
}
}
示例12: FindCliff
/// <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;
}
}
示例13: ApplyDefaultSettings
/// <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;
}
示例14: PhysicsQB
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);
}
示例15: SphereCharacterControllerInput
/// <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;
}