Ejemplo n.º 1
0
 public BoxQueryAlgorithm(string name, BufferPool pool, Func <int, BoxQueryAlgorithm, int> worker, int timingSampleCount = 16)
 {
     Name           = name;
     Timings        = new TimingsRingBuffer(timingSampleCount, pool);
     this.worker    = worker;
     internalWorker = ExecuteWorker;
 }
Ejemplo n.º 2
0
        public unsafe override void Initialize(ContentArchive content, Camera camera)
        {
            camera.Position = new Vector3(-20f, 13, -20f);
            camera.Yaw      = MathHelper.Pi * 3f / 4;
            camera.Pitch    = MathHelper.Pi * 0.1f;
            Simulation      = Simulation.Create(BufferPool, new DemoNarrowPhaseCallbacks(), new DemoPoseIntegratorCallbacks(new Vector3(0, -10, 0)));

            var shape = new Sphere(0.5f);

            shape.ComputeInertia(1, out var sphereInertia);
            var       shapeIndex        = Simulation.Shapes.Add(shape);
            const int width             = 64;
            const int height            = 64;
            const int length            = 64;
            var       spacing           = new Vector3(1.01f);
            var       halfSpacing       = spacing / 2;
            float     randomization     = 0.9f;
            var       randomizationSpan = (spacing - new Vector3(1)) * randomization;
            var       randomizationBase = randomizationSpan * -0.5f;
            var       random            = new Random(5);

            for (int i = 0; i < width; ++i)
            {
                for (int j = 0; j < height; ++j)
                {
                    for (int k = 0; k < length; ++k)
                    {
                        var r        = new Vector3((float)random.NextDouble(), (float)random.NextDouble(), (float)random.NextDouble());
                        var location = spacing * (new Vector3(i, j, k) + new Vector3(-width, 1, -length)) + randomizationBase + r * randomizationSpan;
                        if ((i + j + k) % 2 == 1)
                        {
                            var bodyDescription = new BodyDescription
                            {
                                Activity = new BodyActivityDescription {
                                    MinimumTimestepCountUnderThreshold = 32, SleepThreshold = -0.1f
                                },
                                Pose = new RigidPose
                                {
                                    Orientation = Quaternion.Identity,
                                    Position    = location
                                },
                                Collidable = new CollidableDescription
                                {
                                    Continuity = new ContinuousDetectionSettings {
                                        Mode = ContinuousDetectionMode.Discrete
                                    },
                                    SpeculativeMargin = 0.1f,
                                    Shape             = shapeIndex
                                },
                                LocalInertia = sphereInertia
                            };
                            Simulation.Bodies.Add(bodyDescription);
                        }
                        else
                        {
                            var staticDescription = new StaticDescription
                            {
                                Pose = new RigidPose
                                {
                                    Orientation = Quaternion.Identity,
                                    Position    = location
                                },
                                Collidable = new CollidableDescription
                                {
                                    Continuity = new ContinuousDetectionSettings {
                                        Mode = ContinuousDetectionMode.Discrete
                                    },
                                    SpeculativeMargin = 0.1f,
                                    Shape             = shapeIndex
                                }
                            };
                            Simulation.Statics.Add(staticDescription);
                        }
                    }
                }
            }
            refineTimes = new TimingsRingBuffer(sampleCount, BufferPool);
            testTimes   = new TimingsRingBuffer(sampleCount, BufferPool);
        }