Esempio n. 1
0
        public override void Initialize()
        {
            PhysicsSimulator            = new PhysicsSimulator(new Vector2(0, 50));
            PhysicsSimulator.BiasFactor = .3f;
            //for stacked objects, simultaneous collision are the bottlenecks so limit them to 2 per geometric pair.
            PhysicsSimulator.MaxContactsToDetect = 2;

            PhysicsSimulatorView = new PhysicsSimulatorView(PhysicsSimulator);
            PhysicsSimulatorView.EnableEdgeView = false;

            // POINT OF INTEREST
            // Create a physics processor based on the physics processor
            _physicsProcessor = new PhysicsProcessor(PhysicsSimulator);
            // POINT OF INTEREST
            // Create the physics thread with the StartThinking function as the entry point.
            // The StartThinking is going to be the main function of the physics thread.
            _physicsThread = new Thread(_physicsProcessor.StartThinking);
            // POINT OF INTEREST
            // Name the thread for debugging purposes
            _physicsThread.Name = "PhysicsThread";
            // POINT OF INTEREST
            // And now start the thread
            _physicsThread.Start();

            base.Initialize();
        }
Esempio n. 2
0
        public override void Dispose()
        {
            // POINT OF INTEREST
            // On screen destroy Dispose the physics processor and use Join to wait the thread to exit
            _physicsProcessor.Dispose();
            _physicsProcessor = null;
            //_physicsThread.Abort();
            _physicsThread.Join();
            _physicsThread = null;

            base.Dispose();
        }
        public void Load(PhysicsSimulator physicsSimulator, PhysicsProcessor physicsProcessor)
        {
            int count = _bottomRowBlockCount * (1 + _bottomRowBlockCount) / 2;

            _blockBody = new Body[count];
            _blockGeom = new Geom[count];
            _blockLink = new ObjectLinker[count];

            for (int i = 0; i < _blockBody.Length; i++)
            {
                _blockBody[i] = BodyFactory.Instance.CreateBody(physicsSimulator, _referenceBody);
                _blockGeom[i] = GeomFactory.Instance.CreateGeom(physicsSimulator, _blockBody[i], _referenceGeom);
                // POINT OF INTEREST
                // Create the link for each body, and register it into the phyisics processor
                _blockLink[i] = new ObjectLinker(_blockBody[i]);
                physicsProcessor.AddLink(_blockLink[i]);
            }

            CreatePyramid();
        }