本文整理汇总了C#中DemosGame类的典型用法代码示例。如果您正苦于以下问题:C# DemosGame类的具体用法?C# DemosGame怎么用?C# DemosGame使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DemosGame类属于命名空间,在下文中一共展示了DemosGame类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MoreConstraintsTestDemo
/// <summary>
/// Constructs a new demo.
/// </summary>
/// <param name="game">Game owning this demo.</param>
public MoreConstraintsTestDemo(DemosGame game)
: base(game)
{
Box boxA = new Box(new Vector3(0, 5, 0), 1, 2, 1, 10);
Box boxB = new Box(new Vector3(0, 8, 0), 1, 2, 1, 10);
boxA.Orientation = Quaternion.CreateFromYawPitchRoll(0, MathHelper.PiOver4, 0);
boxB.Orientation = Quaternion.CreateFromYawPitchRoll(MathHelper.PiOver4, 0, 0);
WeldJoint weld = new WeldJoint(boxA, boxB);
Space.Add(boxA);
Space.Add(boxB);
Space.Add(weld);
boxA = new Box(new Vector3(3, 5, 0), 1, 2, 1, 10);
boxB = new Box(new Vector3(3, 8, 0), 1, 2, 1, 10);
boxA.Orientation = Quaternion.CreateFromYawPitchRoll(0, MathHelper.PiOver4, 0);
boxB.Orientation = Quaternion.CreateFromYawPitchRoll(MathHelper.PiOver4, 0, 0);
BallSocketJoint ballSocket = new BallSocketJoint(boxA, boxB, (boxA.Position + boxB.Position) / 2);
AngularMotor angularMotor = new AngularMotor(boxA, boxB);
angularMotor.Settings.Mode = MotorMode.Servomechanism;
Space.Add(boxA);
Space.Add(boxB);
Space.Add(ballSocket);
Space.Add(angularMotor);
Box ground = new Box(new Vector3(0, 0, 0), 10, 1, 10);
Space.Add(ground);
game.Camera.Position = new Vector3(0, 6, 15);
}
示例2: PlanetDemo
/// <summary>
/// Constructs a new demo.
/// </summary>
/// <param name="game">Game owning this demo.</param>
public PlanetDemo(DemosGame game)
: base(game)
{
Space.ForceUpdater.Gravity = Vector3.Zero;
//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(1000);
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;
int numColumns = 10;
int numRows = 10;
int numHigh = 10;
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);
}
game.Camera.Position = new Vector3(0, 0, 150);
}
示例3: TwistTestDemo
/// <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);
}
示例4: 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);
}
示例5: RayCastTestDemo
/// <summary>
/// Constructs a new demo.
/// </summary>
/// <param name="game">Game owning this demo.</param>
public RayCastTestDemo(DemosGame game)
: base(game)
{
Space.Add(new Box(new Vector3(0, -0.5f, 0), 50, 1, 50));
//Put whatever you'd like to ray cast here.
var capsule = new Capsule(new Vector3(0, 1.2f, 0), 1, 0.6f);
capsule.AngularVelocity = new Vector3(1, 1, 1);
Space.Add(capsule);
var cylinder = new Cylinder(new Vector3(0, 5, 0), 2, .5f);
cylinder.AngularVelocity = new Vector3(1, -1, 1);
Space.Add(cylinder);
var points = new List<Vector3>();
var random = new Random(0);
for (int k = 0; k < 40; k++)
{
points.Add(new Vector3(1 * (float)random.NextDouble(), 3 * (float)random.NextDouble(), 2 * (float)random.NextDouble()));
}
var convexHull = new ConvexHull(new Vector3(0, 10, 0), points);
convexHull.AngularVelocity = new Vector3(-1, 1, 1);
Space.Add(convexHull);
game.Camera.Position = new Vector3(-10, 5, 10);
game.Camera.Yaw((float)Math.PI / -4f);
game.Camera.Pitch(-(float)Math.PI / 9f);
//Starter ray.
origin = new Vector3(10, 5, 0);
direction = new Vector3(-3, -1, 0);
}
示例6: WallDemo
/// <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 Vector3(0, 6, 15);
}
示例7: MultithreadedScalingTestDemo
/// <summary>
/// Constructs a new demo.
/// </summary>
/// <param name="game">Game owning this demo.</param>
public MultithreadedScalingTestDemo(DemosGame game)
: base(game)
{
simulationBuilders = new Func<Space, int>[]
{
BuildPileSimulation,
BuildWallSimulation,
BuildPlanetSimulation
};
#if WINDOWS
int coreCountMax = Environment.ProcessorCount;
testResults = new double[coreCountMax, simulationBuilders.Length];
int reruns = 1;
for (int i = 0; i < reruns; i++)
{
GC.Collect();
var threadManager = new SpecializedThreadManager();
//Try different thread counts.
for (int j = 0; j < coreCountMax; j++)
{
threadManager.AddThread();
for (int k = 0; k < simulationBuilders.Length; k++)
testResults[j, k] = RunTest(threadManager, simulationBuilders[k]);
GC.Collect();
}
}
#else
testResults = new double[4, simulationBuilders.Length];
int reruns = 10;
for (int i = 0; i < reruns; i++)
{
GC.Collect();
var threadManager = new SpecializedThreadManager();
threadManager.AddThread(delegate { Thread.CurrentThread.SetProcessorAffinity(new[] { 1 }); }, null);
for (int k = 0; k < simulationBuilders.Length; k++)
testResults[0, k] += RunTest(threadManager, simulationBuilders[k]);
GC.Collect();
threadManager.AddThread(delegate { Thread.CurrentThread.SetProcessorAffinity(new[] { 3 }); }, null);
for (int k = 0; k < simulationBuilders.Length; k++)
testResults[1, k] += RunTest(threadManager, simulationBuilders[k]);
GC.Collect();
threadManager.AddThread(delegate { Thread.CurrentThread.SetProcessorAffinity(new[] { 5 }); }, null);
for (int k = 0; k < simulationBuilders.Length; k++)
testResults[2, k] += RunTest(threadManager, simulationBuilders[k]);
GC.Collect();
threadManager.AddThread(delegate { Thread.CurrentThread.SetProcessorAffinity(new[] { 4 }); }, null);
for (int k = 0; k < simulationBuilders.Length; k++)
testResults[3, k] += RunTest(threadManager, simulationBuilders[k]);
GC.Collect();
}
#endif
}
示例8: ColosseumDemo
/// <summary>
/// Constructs a new demo.
/// </summary>
/// <param name="game">Game owning this demo.</param>
public ColosseumDemo(DemosGame game)
: base(game)
{
double angle;
int numBoxesPerRing = 12;
float blockWidth = 2;
float blockHeight = 2;
float blockLength = 6f;
float radius = 15;
Entity toAdd;
Space.Add(new Box(new Vector3(0, -blockHeight / 2 - 1, 0), 100, 2f, 100));
double increment = MathHelper.TwoPi / numBoxesPerRing;
for (int i = 0; i < 8; i++)
{
for (int k = 0; k < numBoxesPerRing; k++)
{
if (i % 2 == 0)
{
angle = k * increment;
toAdd = new Box(new Vector3(-(float) Math.Cos(angle) * radius, i * blockHeight, (float) Math.Sin(angle) * radius), blockWidth, blockHeight, blockLength, 20);
toAdd.Orientation = Quaternion.CreateFromAxisAngle(Vector3.Up, (float) angle);
Space.Add(toAdd);
}
else
{
angle = (k + .5f) * increment;
toAdd = new Box(new Vector3(-(float)Math.Cos(angle) * radius, i * blockHeight, (float)Math.Sin(angle) * radius), blockWidth, blockHeight, blockLength, 20);
toAdd.Orientation = Quaternion.CreateFromAxisAngle(Vector3.Up, (float) angle);
Space.Add(toAdd);
}
}
}
game.Camera.Position = new Vector3(0, 2, 2);
}
示例9: FishInABarrelDemo
/// <summary>
/// Constructs a new demo.
/// </summary>
/// <param name="game">Game owning this demo.</param>
public FishInABarrelDemo(DemosGame game)
: base(game)
{
game.Camera.Position = new Vector3(0, 7, 30);
var detector = new Box(new Vector3(0, 0, 0), 1.5f, 1.5f, 1.5f);
detector.CollisionInformation.CollisionRules.Personal = CollisionRule.NoSolver;
var acceptedTriggerEntity = new Box(new Vector3(5, 0, 0), 1.6f, .7f, .4f, 1);
acceptedTrigger = acceptedTriggerEntity.CollisionInformation;
detector.Tag = "noDisplayObject";
acceptedTriggerEntity.Tag = "noDisplayObject";
Space.Add(detector);
Space.Add(acceptedTriggerEntity);
var fish = game.Content.Load<Model>("fish");
game.ModelDrawer.Add(new DisplayEntityModel(acceptedTriggerEntity, fish, game.ModelDrawer));
var barrelAndPlatform = game.Content.Load<Model>("barrelAndPlatform");
Vector3[] staticTriangleVertices;
int[] staticTriangleIndices;
ModelDataExtractor.GetVerticesAndIndicesFromModel(barrelAndPlatform, out staticTriangleVertices, out staticTriangleIndices);
//Note that the final 'margin' parameter is optional, but can be used to specify a collision margin on triangles in the static triangle group.
var fishDepositoryGroup = new StaticMesh(staticTriangleVertices, staticTriangleIndices);
CollisionRules.AddRule(fishDepositoryGroup, detector, CollisionRule.NoBroadPhase);
Space.Add(fishDepositoryGroup);
game.ModelDrawer.Add(fishDepositoryGroup);
movedBox = new Box(new Vector3(-4, 5, 0), 1, 1, 1, 1);
detector.Space.Add(movedBox);
detector.CollisionInformation.Events.InitialCollisionDetected += InitialCollisionDetected;
detector.CollisionInformation.Events.CollisionEnded += CollisionEnded;
}
示例10: GeneralConvexPairStressDemo
/// <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.5f + (float)random.NextDouble() * 1.5f, 0.5f + (float)random.NextDouble() * 1.5f);
break;
case 1:
shape = new ConeShape(0.5f + (float)random.NextDouble() * 1.5f, 0.5f + (float)random.NextDouble() * 1.5f);
break;
default:
shape = new CapsuleShape(0.5f + (float)random.NextDouble() * 1.5f, 0.5f + (float)random.NextDouble() * 1.5f);
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);
}
示例11: BroadPhaseDemo
/// <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);
}
示例12: BoxBoxTestDemo
/// <summary>
/// Constructs a new demo.
/// </summary>
/// <param name="game">Game owning this demo.</param>
public BoxBoxTestDemo(DemosGame game)
: base(game)
{
//float blockWidth = 2;
//float blockHeight = 2;
//float blockLength = 6f;
//Entity toAdd;
//toAdd = new Box(new Vector3(0, 2,0), blockWidth, blockHeight, blockLength, 20);
//toAdd.ActivityInformation.IsAlwaysActive = true;
//toAdd.AllowStabilization = false;
//Space.Add(toAdd);
int numColumns = 3;
int numRows = 3;
int numHigh = 30;
float xSpacing = 1.01f;
float ySpacing = 1.01f;
float zSpacing = 1.01f;
for (int i = 0; i < numRows; i++)
for (int j = 0; j < numColumns; j++)
for (int k = 0; k < numHigh; k++)
{
Space.Add(new Box(new Vector3(
xSpacing * i - (numRows - 1) * xSpacing / 2f,
1f + k * (ySpacing),
zSpacing * j - (numColumns - 1) * zSpacing / 2f),
.5f, .5f, .5f, 5));
}
Space.Add(new Box(new Vector3(0, 0, 0), 20, 1f, 20));
game.Camera.Position = new Vector3(0, 3, 10);
}
示例13: IncomingDemo
/// <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 Vector3(0, 6, 30);
}
示例14: ConvexHullTestDemo
/// <summary>
/// Constructs a new demo.
/// </summary>
/// <param name="game">Game owning this demo.</param>
public ConvexHullTestDemo(DemosGame game)
: base(game)
{
var random = new Random(5);
for (int i = 0; i < 500000; ++i)
{
List<Vector3> points = new List<Vector3>();
for (int k = 0; k < random.Next(8, 60); k++)
{
points.Add(new Vector3(-100 + 30 * (float)random.NextDouble(), 100 + 500 * (float)random.NextDouble(), 100 + 30 * (float)random.NextDouble()));
}
var convexHull = new ConvexHull(new Vector3(0, 7, 0), points, 10);
Console.WriteLine(convexHull.CollisionInformation.Shape.Vertices.Count);
}
var vertices = new[]
{
new Vector3(0, -1.750886E-9f, -1.5f),
new Vector3(1, 1, 0.5f),
new Vector3(1, -1, 0.5f),
new Vector3(-1, 1, 0.5f),
new Vector3(-1, -1, 0.5f),
};
var hullVertices = new RawList<Vector3>();
ConvexHullHelper.GetConvexHull(vertices, hullVertices);
ConvexHull hull = new ConvexHull(vertices, 5);
Space.Add(hull);
Box ground = new Box(new Vector3(0, -.5f, 0), 50, 1, 50);
Space.Add(ground);
game.Camera.Position = new Vector3(0, 6, 15);
}
示例15: AddRemoveStressDemo
/// <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);
}