示例#1
0
 internal void OnAddedInternal(PhysicsEngine engine)
 {
     if (this.engine != null) { throw new InvalidOperationException("The IPhysicsEntity cannot be added to more then one engine or added twice."); }
     this.engine = engine;
     OnAdded();
     if (Added != null) { Added(this, EventArgs.Empty); }
 }
 internal void OnAddedInternal(PhysicsEngine engine)
 {
     if (this.engine != null) { throw new InvalidOperationException(); }
     this.engine = engine;
     OnAdded();
     this.AddBodyRange(engine.bodies);
 }
示例#3
0
		public Desktop()
		{
			windowToBody = new Dictionary<Window, Body>();
			contactJoints = new Dictionary<int, FixedHingeJoint>();
			engine = new PhysicsEngine();
			engine.BroadPhase = new SweepAndPruneDetector();
			engine.Solver = new SequentialImpulsesSolver();
			timer = new PhysicsTimer(PhysicsTimerCallback, 0.01);
			timer.IsRunning = true;

			injectorClass = new DWMInjectorClass();
			if (!injectorClass.IsInjected)
				injectorClass.Inject();
			injectorClass.GetDWMExObject(out dwm);
			Debug.Assert(dwm != null, "DWM is NULL");

			windowManager = new WindowManager();
			windowManager.WindowCreated += windowManager_WindowCreated;
			windowManager.WindowDestroyed += windowManager_WindowDestroyed;
			windowManager.Register(MessageEvents.Handle);

			ThreadPool.QueueUserWorkItem(delegate
										 {
											 hook = new LowLevelMouseHook(MouseHook);
											 hook.StartHook();
											 Application.Run();
										 });
		}
示例#4
0
        public override void Init(PrototypingFramework.engine.GameEngine game)
        {
            base.Init(game);
            world = new PhysicsEngine();
            world.BroadPhase = new Physics2DDotNet.Detectors.SelectiveSweepDetector();
            world.Solver = new Physics2DDotNet.Solvers.SequentialImpulsesSolver();

            PhysicsTimer timer = new PhysicsTimer(world.Update, .01f);
            timer.IsRunning = true;

            rs = new RectangleShape(new SFML.Window.Vector2f(10, 10));
            rs.FillColor = Color.Black;
            rs.Position = new SFML.Window.Vector2f(10, 5);

            Coefficients coffecients = new Coefficients(/*restitution*/1, /*friction*/.5f);
            IShape shape2 = new PolygonShape(VertexHelper.CreateRectangle(10, 20), 3);
             body2 = new Body(new PhysicsState(new ALVector2D(0,10,5)), shape2, 5, coffecients, new Lifespan());

            world.AddBody(body2);

            PhysicsLogic logGravity;

            logGravity = (PhysicsLogic)new GravityField(new Vector2D(0f, 200f), new Lifespan());
            //pretty basic, create a downward force

            world.AddLogic(logGravity);

            Body bdyFloor;
            PhysicsState flrState;
            PolygonShape flrShape;
            Coefficients flrCoff;
            Lifespan flrLife;

            flrState = new PhysicsState(new ALVector2D((float)0.0, 0, (float)_game.Window.Size.Y-64));
            //create the state, centering the x-axis on screen and bottom of the y-axis

            flrShape = new PolygonShape(VertexHelper.CreateRectangle(_game.Window.Size.X, 64), 2);
            //create form.widthX64 rectangle (sq) with grid spacing at 2

            flrCoff = new Coefficients(0.5f, 0.4f, 0.4f);
            //might require tuning to your liking...

            flrLife = new Lifespan();
            //forever and ever

            bdyFloor = new Body(flrState, flrShape, float.PositiveInfinity, flrCoff, flrLife);
            //never ending mass means it isn't going to move on impact

            bdyFloor.IgnoresGravity = true;
            //make sure the floor stays

            world.AddBody(bdyFloor);

            floor = new RectangleShape(new SFML.Window.Vector2f( _game.Window.Size.X,64));
            floor.Position = new SFML.Window.Vector2f(0, _game.Window.Size.Y - 64);
            floor.FillColor = Color.Red;
        }
 internal void OnAddedInternal(PhysicsEngine engine)
 {
     if (this.engine != null)
     {
         throw new InvalidOperationException("A broadphsed Detector cannot be added to more then one engine.");
     }
     this.engine = engine;
     OnAdded();
     this.AddBodyRange(engine.bodies);
 }
示例#6
0
        internal void OnRemoved()
        {
            bool          wasPending = this.IsPending;
            PhysicsEngine engine     = this.engine;

            this.engine  = null;
            this.id      = -1;
            this.isAdded = false;
            this.RemoveFromProxy();
            if (Removed != null)
            {
                Removed(this, new RemovedEventArgs(engine, wasPending));
            }
        }
示例#7
0
文件: Will.cs 项目: homoluden/fukami
        private Will()
        {
            _engine = new PhysicsEngine
                {
                    BroadPhase = new Physics2DDotNet.Detectors.SelectiveSweepDetector(),
                    Solver = new Physics2DDotNet.Solvers.SequentialImpulsesSolver
                        {
                            AllowedPenetration = 0.0001f
                        }
                };
            _engine.AddLogic(new GravityField(new Vector2D(0, -300), new Lifespan()));

            _engine.Updated += OnEngineUpdated;

            _timer = new PhysicsTimer(_engine.Update, .005f);
        }
示例#8
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TouchablePanel"/> class.
        /// </summary>
        public TouchablePanel()
        {
			elementToBody = new Dictionary<FrameworkElement, Body>();
            shouldCreateBody = new List<FrameworkElement>();
            shouldRemoveBody = new List<FrameworkElement>();
            contactJoints = new Dictionary<int, FixedHingeJoint>();
            elementToScale = new Dictionary<FrameworkElement, ScaleState>();
            ignorer = new ObjectIgnorer();

            engine = new PhysicsEngine();
            engine.BroadPhase = new SweepAndPruneDetector();
            engine.Solver = new SequentialImpulsesSolver();
            timer = new PhysicsTimer(PhysicsTimerCallback, 0.01);

            Loaded += TouchablePanel_Loaded;
        }
示例#9
0
		/// <summary>
		/// Initializes a new instance of the <see cref="ScrollViewer"/> class.
		/// </summary>
		public ScrollViewer()
		{
			borderSoftness = BorderSoftness;

			AddHandler(MultitouchScreen.NewContactEvent, (NewContactEventHandler)OnNewContact);
			AddHandler(MultitouchScreen.ContactMovedEvent, (ContactEventHandler)OnContactMoved);
			AddHandler(MultitouchScreen.ContactRemovedEvent, (ContactEventHandler)OnContactRemoved);
			AddHandler(MultitouchScreen.ContactLeaveEvent, (ContactEventHandler)OnContactLeave);	

			engine = new PhysicsEngine();
			engine.BroadPhase = new SweepAndPruneDetector();
			engine.Solver = new SequentialImpulsesSolver();
			engine.AddLogic(new BoundsConstrainLogic(this));
			timer = new PhysicsTimer(PhysicsTimerCallback, 0.01);

			Loaded += ScrollViewer_Loaded;
		}
示例#10
0
        /// <summary>
        /// Creates the physics object used in the game.
        /// </summary>
        public Physics()
        {
            // Set up the basic engine
            engine = new PhysicsEngine();

            // Set up the collision detector
            engine.BroadPhase = new SweepAndPruneDetector();
            //engine.BroadPhase = new SelectiveSweepDetector();
            //engine.BroadPhase = new BruteForceDetector();

            // Set up the solver
            SequentialImpulsesSolver solver = new SequentialImpulsesSolver();
            engine.Solver = solver;
            solver.Iterations = 12;
            solver.SplitImpulse = true;
            //solver.BiasFactor = 0.7f;
            //solver.AllowedPenetration = 0f;
        }
示例#11
0
文件: Demo.cs 项目: bsvercl/physics2d
        /// <summary>
        /// initializes the PhysicsEngine
        /// </summary>
        void CreateEngine()
        {
            //creates it
            engine = new PhysicsEngine();

            //sets the broadphase
            //engine.BroadPhase = new Physics2DDotNet.Detectors.BruteForceDetector();
            //engine.BroadPhase = new Physics2DDotNet.Detectors.SweepAndPruneDetector();
            engine.BroadPhase = new Physics2DDotNet.Detectors.SelectiveSweepDetector();
            //engine.BroadPhase = new Physics2DDotNet.Detectors.FrameCoherentSAPDetector();
            //engine.BroadPhase = new Physics2DDotNet.Detectors.SpatialHashDetector();
            //engine.BroadPhase = new Physics2DDotNet.Detectors.SpatialHashDetector2();
            
            //setups the Solver and sets it.
            Physics2DDotNet.Solvers.SequentialImpulsesSolver solver = new Physics2DDotNet.Solvers.SequentialImpulsesSolver();
            solver.Iterations = 12;
            solver.SplitImpulse = true;
            solver.BiasFactor = .7f;
            //solver.BiasFactor = .3f;
            solver.AllowedPenetration = .1f;
            engine.Solver = solver;

            engine.BodiesAdded += new EventHandler<CollectionEventArgs<Body>>(engine_BodiesAdded);
            engine.BodiesRemoved += new EventHandler<CollectionEventArgs<Body>>(engine_BodiesRemoved);
        }
示例#12
0
 internal void OnRemovedInternal()
 {
     engine = null;
     OnRemoved();
     if (Removed != null) { Removed(this, EventArgs.Empty); }
 }
示例#13
0
 internal void OnRemovedInternal()
 {
     engine = null;
     Clear();
     OnRemoved();
 }
示例#14
0
        void InitializePhysicsEngine()
        {
            //create a new PhysicsEngine.
            engine = new PhysicsEngine();

            //set its broad phase to SweepAndPrune.
            engine.BroadPhase = new Physics2DDotNet.Detectors.SweepAndPruneDetector();

            //create a new solver.
            Physics2DDotNet.Solvers.SequentialImpulsesSolver solver = new Physics2DDotNet.Solvers.SequentialImpulsesSolver();
            //optionaly set its options.
            solver.SplitImpulse = true;
            solver.Iterations = 13;
            solver.BiasFactor = .7f;
            solver.AllowedPenetration = .01f;
            //set the engines solver to it.
            engine.Solver = solver;
        }
 public RemovedEventArgs(PhysicsEngine engine, bool wasPending)
 {
     this.wasPending = wasPending;
     this.engine = engine;
 }
 private void InitializePhysicsEngine()
 {
     _engine = new PhysicsEngine();
     _engine.BroadPhase = new SpatialHashDetector();
     _engine.Solver = new SequentialImpulsesSolver();
     _timer = new PhysicsTimer(PhysicsTimerCallback, 0.02f);
 }
示例#17
0
 public RemovedEventArgs(PhysicsEngine engine, bool wasPending)
 {
     this.wasPending = wasPending;
     this.engine     = engine;
 }
示例#18
0
 public Scene()
 {
     this.syncRoot = new object();
     this.engine = new PhysicsEngine();
     this.rwLock = new AdvReaderWriterLock();
     this.timer = new PhysicsTimer(Update, .01f);
     this.graphics = new PendableCollection<Scene, Graphic>(this);
     this.viewports = new List<Viewport>();
     this.bodies = new List<Body>();
     this.joints = new List<Joint>();
     this.physicsLogics = new List<PhysicsLogic>();
 }