예제 #1
0
        /// <summary>
        /// Called when the <see cref="P:System.Windows.Controls.ContentControl.Content"/> property changes.
        /// </summary>
        /// <param name="oldContent">The old value of the <see cref="P:System.Windows.Controls.ContentControl.Content"/> property.</param>
        /// <param name="newContent">The new value of the <see cref="P:System.Windows.Controls.ContentControl.Content"/> property.</param>
        protected override void OnContentChanged(object oldContent, object newContent)
        {
            timer.IsRunning = false;

            if (Body != null)
            {
                Body.Lifetime.IsExpired = true;
            }

            base.OnContentChanged(oldContent, newContent);

            PhysicsState state = new PhysicsState(new ALVector2D(0, 0, 0));
            IShape       shape = new PolygonShape(VertexHelper.CreateRectangle(5, 5), 1);
            MassInfo     mass  = MassInfo.FromPolygon(shape.Vertexes, 1);

            Body = new Body(state, shape, mass, new Coefficients(0, 1), new Lifespan());
            Body.LinearDamping        = LinearDumping;
            Body.Mass.MomentOfInertia = double.PositiveInfinity;
            Body.Tag = newContent;
            engine.AddBody(Body);

            if (!DesignerProperties.GetIsInDesignMode(this))
            {
                timer.IsRunning = true;
            }
        }
예제 #2
0
        void CreateBody(Window window)
        {
            lock (lockPhysicsLoop)
            {
                double    angle    = window.Angle;
                Rectangle position = window.Position;
                if (position.Width > 0 && position.Height > 0)
                {
                    PhysicsState state = new PhysicsState(new ALVector2D(angle, position.Left + position.Width / 2, position.Top + position.Height / 2));
                    IShape       shape = new PolygonShape(VertexHelper.CreateRectangle(position.Height, position.Width), 2);
                    MassInfo     mass  = MassInfo.FromPolygon(shape.Vertexes, 1);
                    Body         body  = new Body(state, shape, mass, new Coefficients(0, 1), new Lifespan());
                    body.LinearDamping  = 0.95;
                    body.AngularDamping = 0.95;
                    body.IsCollidable   = false;
                    body.Tag            = window;
                    engine.AddBody(body);
                    windowToBody.Add(window, body);

                    try
                    {
                        dwm.SetWindowMatrix(window.HWnd.ToInt32(), 0f, 0f, 1f, 1f, 0f);
                    }
                    catch (Exception e)
                    {
                        HandleDwmCrash(e);
                    }
                }
            }
        }
예제 #3
0
        public BaseModelBody(PhysicsState state, IShape shape, MassInfo massInfo, Coefficients coefficients, Lifespan lifetime, Guid modelId)
            : base(state, shape, massInfo, coefficients, lifetime)
        {
            if (modelId == Guid.Empty)
            {
                throw new ArgumentException("'guid' cannot be empty!");
            }

            ModelId = modelId;
        }
예제 #4
0
        void CreateBody(FrameworkElement frameworkElement)
        {
            double angle = 0;

            //if an element already has rotatetransform, get it's angle.
            RotateTransform rotateTransform = frameworkElement.RenderTransform as RotateTransform;

            if (rotateTransform != null)
            {
                angle = MathHelper.ToRadians(rotateTransform.Angle);
            }

            PhysicsState state = new PhysicsState(new ALVector2D(angle, GetLeft(frameworkElement) + (frameworkElement.ActualWidth / 2),
                                                                 GetTop(frameworkElement) + (frameworkElement.ActualHeight / 2)));
            IShape   shape = new PolygonShape(VertexHelper.CreateRectangle(frameworkElement.ActualWidth, frameworkElement.ActualHeight), 2);
            MassInfo mass  = MassInfo.FromPolygon(shape.Vertexes, 1);
            Body     body  = new Body(state, shape, mass, new Coefficients(0.4, 0.95), new Lifespan());

            body.LinearDamping  = LinearDamping;
            body.AngularDamping = AngularDamping;
            if (EnableWalls)
            {
                body.IsCollidable     = true;
                body.CollisionIgnorer = ignorer;
            }
            else
            {
                body.IsCollidable = false;
            }
            body.Tag = frameworkElement;
            engine.AddBody(body);
            elementToBody.Add(frameworkElement, body);
            elementToScale.Add(frameworkElement, new ScaleState());

            TransformGroup transform = new TransformGroup();

            transform.Children.Add(new ScaleTransform());
            transform.Children.Add(new RotateTransform());
            frameworkElement.RenderTransform = transform;
            SetZTop(frameworkElement);

            SubscribeEventsToChild(frameworkElement);
        }
예제 #5
0
		void CreateNewBody(FrameworkElement element)
		{
			double angle = 0;
			if (element.RenderTransform is RotateTransform)
				angle = ((RotateTransform)element.RenderTransform).Angle;
			PhysicsState state = new PhysicsState(new ALVector2D(angle, Canvas.GetLeft(element) + (element.ActualWidth / 2),
			                                                     Canvas.GetTop(element) + (element.ActualHeight / 2)));

			Shape shape = new PolygonShape(PolygonShape.CreateRectangle(element.ActualHeight, element.ActualWidth), 2);
			MassInfo mass = MassInfo.FromPolygon(shape.Vertexes, 1);
			Body body = new CustomBody(state, shape, mass, new Coefficients(0, 1), new Lifespan());
			body.LinearDamping = 0.95;
			body.AngularDamping = 0.95;
			body.IsCollidable = GetIsCollidable(element);
			body.Tag = element;

			PhysicsController controller = FindParentPhysicsController(element);
			if (controller != null)
				controller.engine.AddBody(body);
			itemToBody.Add(element, body);
		}
예제 #6
0
 /// <summary>
 /// Creates a new Circle Instance.
 /// </summary>
 /// <param name="radius">how large the circle is.</param>
 /// <param name="vertexCount">
 /// The number or vertex that will be generated along the perimeter of the circle.
 /// This is for collision detection.
 /// </param>
 public CircleShape(Scalar radius, int vertexCount)
     : this(radius, vertexCount, MassInfo.InertiaOfSolidCylinder(radius))
 {
 }
예제 #7
0
 public CoreBody(PhysicsState state, IShape shape, MassInfo massInfo, Coefficients coefficients, Lifespan lifetime, Guid modelId)
     : base(state, shape, massInfo, coefficients, lifetime, modelId)
 {
 }
예제 #8
0
 public CustomBody(PhysicsState state, Shape shape, MassInfo massInfo, Coefficients coefficients, Lifespan lifetime)
     : base(state, shape, massInfo, coefficients, lifetime)
 {
     joints = new List <Joint>();
 }
예제 #9
0
 public ChainMember(PhysicsState state, IShape shape, MassInfo mass, Coefficients coefficients, Lifespan lifetime, Guid modelId)
     : base(state, shape, mass, coefficients, lifetime, modelId)
 {
 }