Exemple #1
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);
		}