Пример #1
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();
            });
        }
Пример #2
0
 public Window(Size size)
 {
     this.size      = size;
     this.drawTimer = new PhysicsTimer(GraphicsProcess, .01f);
     this.viewports = new PendableCollection <Window, Viewport>(this);
     this.syncRoot  = new object();
     this.rwLock    = new AdvReaderWriterLock();
 }
Пример #3
0
		public PhysicsController()
		{
			itemToBody = new Dictionary<FrameworkElement, Body>();
			engine = new PhysicsEngine();
			engine.BroadPhase = new SweepAndPruneDetector();
			engine.Solver = new SequentialImpulsesSolver();
			timer = new PhysicsTimer(PhysicsTimerCallback, 0.01);
			if(!ViewUtility.IsDesignTime)
				timer.IsRunning = true;
		}
Пример #4
0
 private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
 {
     PhysicsTimer.Stop();                //When Window Close Stop All Threads
     JumpTimerM.Stop();                  //When Window Close Stop All Threads
     JumpTimerT.Stop();                  //When Window Close Stop All Threads
     RightTimerM.Stop();                 //When Window Close Stop All Threads
     LeftTimerM.Stop();                  //When Window Close Stop All Threads
     RightTimerT.Stop();                 //When Window Close Stop All Threads
     LeftTimerT.Stop();                  //When Window Close Stop All Threads
 }
Пример #5
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>();
 }
Пример #6
0
        /// <summary>
        /// Initializes methods common to all NeHe lessons
        /// </summary>
        protected void Initialize(BaseDisplayDemo demo)
        {
#if Release
            try
            {
#endif
            //Mixer.Open(22050, AudioFormat.Default, 2, 2048);



            // Sets keyboard events
            // Sets the ticker to update OpenGL Context
            Events.Tick += new TickEventHandler(this.Tick);
            // Sets the resize window event
            Events.VideoResize += new VideoResizeEventHandler(Events_VideoResize);
            Events.Quit        += new QuitEventHandler(Events_Quit);
            // Set the Frames per second.
            Events.Fps = 60;
            targetDT   = (float)1 / (float)Events.Fps;
            // Creates SDL.NET Surface to hold an OpenGL scene
            //screen = Video.SetVideoModeWindowOpenGL(width, height, true);
            //Environment.
            //screen = Video.SetVideoModeOpenGL(width, height, 16);
            screen = Video.SetVideoModeWindowOpenGL(System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width / 2, System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height / 2, true);

            //Video.WindowIcon();
            // Video.
            //Video.SetVideoModeWindowOpenGL(Video.Screen.Width,Video.Screen.Height,true);
            //Tao.Sdl.Sdl.SDL_WM_IconifyWindow();


            // Sets Window icon and title
            this.WindowAttributes();

            MeleeMusic.PlayDefault();
            this.demo    = demo;
            physicsTimer = new PhysicsTimer(Update2, 1 / (float)Events.Fps, 3);
            physicsTimer.Start(false);

#if Release
        }
        catch (Exception ex)
        {
            ErrorBox.DisplayError(ex);
            throw;
        }
#endif
        }
Пример #7
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;
        }
Пример #8
0
        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);
        }
Пример #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
 public static void PausePhysics()
 {
     PhysicsTimer.Stop();
     PhysicsStopwatch.Stop();
 }
Пример #11
0
 public static void ResumeRender()
 {
     PhysicsTimer.Start();
     PhysicsStopwatch.Reset();
     PhysicsStopwatch.Start();
 }
Пример #12
0
        static void Main(string[] args)
        {
            GroupCollection collection1 = new GroupCollection();
            GroupCollection collection2 = new GroupCollection();

            /* collection1.AddRange(new int[] { 1 });
            *  collection1.AddRange(new int[] {  3 });
            *  collection1.AddRange(new int[] {  2 });*/
            collection1.Add(1);
            collection1.Add(3);
            collection1.Add(2);
            collection2.Add(1);
            Console.WriteLine(GroupCollection.Intersect(collection1, collection2));

            Console.ReadLine();
            return;

            PhysicsEngine engine = new PhysicsEngine();

            engine.BroadPhase = new Physics2DDotNet.Detectors.SelectiveSweepDetector();
            engine.Solver     = new Physics2DDotNet.Solvers.SequentialImpulsesSolver();

            PhysicsTimer timer = new PhysicsTimer(engine.Update, .01f);

            timer.IsRunning = true;



            Coefficients coffecients = new Coefficients(/*restitution*/ 1, /*friction*/ .5f);


            IShape shape1 = new CircleShape(8, 7);
            IShape shape2 = new PolygonShape(VertexHelper.CreateRectangle(20, 10), 3);

            Scalar mass  = 5;
            Body   body1 = new Body(new PhysicsState(), shape1, mass, coffecients, new Lifespan());
            Body   body2 = new Body(new PhysicsState(), shape2, mass, coffecients, new Lifespan());

            engine.AddBody(body1);
            engine.AddBody(body2);
            Joint joint = new HingeJoint(body1, body2, Vector2D.Zero, new Lifespan());

            engine.AddJoint(joint);
            joint.Lifetime.IsExpired = true;

            engine.AddJoint(new HingeJoint(body1, body2, Vector2D.Zero, new Lifespan()));
            engine.Update(0, 0);

            body1.Lifetime.IsExpired = true;

            timer.IsRunning = false;
            engine.AddProxy(body1, body2, Matrix2x2.Identity);
            //  b1.RemoveFromProxy();



            BinaryFormatter formatter = new BinaryFormatter();
            MemoryStream    stream    = new MemoryStream();

            formatter.Serialize(stream, engine);
            stream.Seek(0, SeekOrigin.Begin);
            PhysicsEngine engine2 = (PhysicsEngine)formatter.Deserialize(stream);



            Console.WriteLine();

            /*
             *
             * Vector2D[] vertexes1 = new Vector2D[]
             * {
             *  new Vector2D(-1,1),
             *  new Vector2D(-3,1),
             *  new Vector2D(-3,-1),
             *  new Vector2D(-1,-1),
             * };
             * Vector2D[] vertexes2 = new Vector2D[]
             * {
             *  new Vector2D(1,-1),
             *  new Vector2D(3,-1),
             *  new Vector2D(3,1),
             *  new Vector2D(1,1),
             * };
             * Vector2D[][] polygons = new Vector2D[2][];
             * polygons[0] = vertexes1;
             * polygons[1] = vertexes2;
             * Console.WriteLine(MultiPartPolygon.GetCentroid(polygons));
             * Console.WriteLine(MultiPartPolygon.GetArea(polygons));
             */
            Console.WriteLine("Finished");
            Console.ReadLine();
        }