Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.ComponentModel;
- using System.Windows;
- using System.Windows.Media;
- using FarseerPhysics.Dynamics;
- namespace FarseerTransforms
- {
- public class BodyViewModel : INotifyPropertyChanged
- {
- private Fixture _fixture;
- private CompositeTransform _transform = new CompositeTransform();
- private System.Windows.Media.GeneralTransform _worldToCanvas;
- private double _width;
- private double _height;
- public BodyViewModel(Fixture fixture, double width, double height, System.Windows.Media.GeneralTransform worldToCanvas)
- {
- _fixture = fixture;
- _width = width;
- _height = height;
- _worldToCanvas = worldToCanvas;
- // rotate around center
- _transform.CenterX = width / 2;
- _transform.CenterY = height / 2;
- // adjust for center
- var position = _worldToCanvas.Transform(new Point(_fixture.Body.Position.X, _fixture.Body.Position.Y));
- _transform.TranslateX = position.X - width / 2;
- _transform.TranslateY = position.Y - width / 2;
- _transform.Rotation = _fixture.Body.Rotation * 360 / (2 * Math.PI);
- }
- public event PropertyChangedEventHandler PropertyChanged;
- public double Width
- {
- get { return _width; }
- }
- public double Height
- {
- get { return _height; }
- }
- public CompositeTransform RenderTransform
- {
- get { return _transform; }
- }
- internal void Notify()
- {
- var position = _worldToCanvas.Transform(new Point(_fixture.Body.Position.X, _fixture.Body.Position.Y));
- _transform.TranslateX = position.X - Width / 2;
- _transform.TranslateY = position.Y - Height / 2;
- _transform.Rotation = _fixture.Body.Rotation * 360 / (2 * Math.PI);
- if (PropertyChanged != null)
- {
- PropertyChanged(this, new PropertyChangedEventArgs("RenderTransform"));
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment