public SpringBox( double px, double py, double w, double h, out PhysicsObject[] objs) { // top left p0 = new RectangleParticle(px - w / 2, py - h / 2, 1, 1); // top right p1 = new RectangleParticle(px + w / 2, py - h / 2, 1, 1); // bottom right p2 = new RectangleParticle(px + w / 2, py + h / 2, 1, 1); // bottom left p3 = new RectangleParticle(px - w / 2, py + h / 2, 1, 1); p0.Visible = false; p1.Visible = false; p2.Visible = false; p3.Visible = false; objs = new PhysicsObject[10]; objs[0] = p0; objs[1] = p1; objs[2] = p2; objs[3] = p3; // edges objs[4] = new SpringConstraint(p0, p1); objs[5] = new SpringConstraint(p1, p2); objs[6] = new SpringConstraint(p2, p3); objs[7] = new SpringConstraint(p3, p0); // crossing braces objs[8] = new SpringConstraint(p0, p2); objs[9] = new SpringConstraint(p1, p3); }
public string GenerateCode(PhysicsObject po) { if (po is RectangleSurface) { RectangleSurface o = po as RectangleSurface; return String.Format("{0} = Rectangle({1:g}, {2:g}, {3:g}, {4:g})", o.name, o.Center.X, o.Center.Y, o.Width, o.Height); } if (po is CircleSurface) { CircleSurface o = po as CircleSurface; return String.Format("{0} = Circle({1:g}, {2:g}, {3:g})", o.name, o.Center.X, o.Center.Y, o.Radius); } if (po is LineSurface) { LineSurface o = po as LineSurface; return String.Format("{0} = Line({1:g}, {2:g}, {3:g}, {4:g})", o.name, o.OP1.X, o.OP1.Y, o.OP2.X, o.OP2.Y); } throw new Exception("unsupported physics object"); }
public EditGizmo(Editor editor, Visual visual) { this.editor = editor; this.editable = visual.source; this.visual = visual; System.IO.Stream s = this.GetType().Assembly.GetManifestResourceStream("SilverStunts.Gizmo.xaml"); content = this.InitializeFromXaml(new System.IO.StreamReader(s).ReadToEnd()) as Canvas; content.Opacity = 0.5; content.Background = Brushes.Gray; visual.content.Children.Add(this); }
//private void OnPropertyChanged( string propertyName ) //{ // if ( PropertyChanged != null ) PropertyChanged( this, new PropertyChangedEventArgs( propertyName ) ); //} public void Remove(PhysicsObject o) { if (o is IParticle) { particles.Remove(o as IParticle); return; } if (o is ISurface) { surfaces.Remove(o as ISurface); return; } if (o is IConstraint) { constraints.Remove(o as IConstraint); return; } throw new Exception("unknown physics object"); }
public Generic(PhysicsObject source, Visual.Family family, string selector) { _visual = new Visual(source, family, selector); Born(); }
public Generic Add(PhysicsObject o, string selector) { Generic g = new Generic(o, Visual.Family.Bike, selector); parts.Add(g); return g; }
public Generic Add(PhysicsObject o) { return Add(o, null); }
public void Remove(PhysicsObject o) { foreach (Generic e in parts) { if (ReferenceEquals(e.visual.source, o)) { e.Destroy(); parts.Remove(e); return; } } }