/// <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; } }
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); } } } }
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; }
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); }
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); }
/// <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)) { }
public CoreBody(PhysicsState state, IShape shape, MassInfo massInfo, Coefficients coefficients, Lifespan lifetime, Guid modelId) : base(state, shape, massInfo, coefficients, lifetime, modelId) { }
public CustomBody(PhysicsState state, Shape shape, MassInfo massInfo, Coefficients coefficients, Lifespan lifetime) : base(state, shape, massInfo, coefficients, lifetime) { joints = new List <Joint>(); }
public ChainMember(PhysicsState state, IShape shape, MassInfo mass, Coefficients coefficients, Lifespan lifetime, Guid modelId) : base(state, shape, mass, coefficients, lifetime, modelId) { }