Ejemplo n.º 1
0
		FixedSlidingHingeJoint CreateBorderJoint(Orientation orientation)
		{
			FixedSlidingHingeJoint joint = new FixedSlidingHingeJoint(Body, new Vector2D(0, 0), new Lifespan(), orientation);
			joint.Softness = borderSoftness;
			engine.AddJoint(joint);
			return joint;
		}
Ejemplo n.º 2
0
		void PhysicsTimerCallback(double dt, double trueDt)
		{
			engine.Update(dt, trueDt);

			if (Body != null)
			{

				Vector2D position = -Body.State.Position.Linear;
				Dispatcher.Invoke(DispatcherPriority.Normal, (Action)(() =>
				{
					ScrollToHorizontalOffset(position.X);
					ScrollToVerticalOffset(position.Y);
				}));

				if (position.X < ContentDecorator.BORDER)
				{
					if (horizontalJoint == null)
					{
						Body.State.Position.Linear = new Vector2D(-ContentDecorator.BORDER, -position.Y);
						horizontalJoint = CreateBorderJoint(Orientation.Horizontal);
					}
				}
				else if (position.X > ScrollableWidth - ContentDecorator.BORDER)
				{
					if (horizontalJoint == null)
					{
						Body.State.Position.Linear = new Vector2D(-ScrollableWidth + ContentDecorator.BORDER, -position.Y);
						horizontalJoint = CreateBorderJoint(Orientation.Horizontal);
					}
				}
				else if (firstContactId.HasValue && horizontalJoint != null)
				{
					horizontalJoint.Lifetime.IsExpired = true;
					horizontalJoint = null;
				}

				if (position.Y < ContentDecorator.BORDER)
				{
					if (verticalJoint == null)
					{
						Body.State.Position.Linear = new Vector2D(-position.X, -ContentDecorator.BORDER);
						verticalJoint = CreateBorderJoint(Orientation.Vertical);
					}
				}
				else if (position.Y > ScrollableHeight - ContentDecorator.BORDER)
				{
					if (verticalJoint == null)
					{
						Body.State.Position.Linear = new Vector2D(-position.X, -ScrollableHeight + ContentDecorator.BORDER);
						verticalJoint = CreateBorderJoint(Orientation.Vertical);
					}
				}
				else if (firstContactId.HasValue && verticalJoint != null)
				{
					verticalJoint.Lifetime.IsExpired = true;
					verticalJoint = null;
				}
			}
		}