public void DrawObject(Context ctx, DrawingObject body) { if (body == null) return; ctx.Save (); ctx.Color = new Cairo.Color (0, 0, 0); ctx.LineWidth = 1; foreach (Tuple<PointDouble, PointDouble> line in body.lines) { ctx.MoveTo (line.Item1.toPointD()); ctx.LineTo (line.Item2.toPointD()); } if (body.points.Count > 1) ctx.Rectangle(body._centerOfMass.X - 5, body._centerOfMass.Y - 5, 10, 10); ctx.Stroke (); foreach (PointDouble point in body.points) { ctx.Rectangle (point.X - 5, point.Y - 5, 10, 10); ctx.Fill (); } foreach (Tuple<PointDouble, double, double> force in body._forces) { DrawForce (ctx, force); } foreach (Tuple<PointDouble, double> moment in body._moments) { DrawMoment (ctx, moment); } ctx.Restore (); }
public void AddBody(DrawingObject body) { var newController = new RigidBodyController(body); _bodyToController.Add(body, newController); _controllers.Add(newController); }
public void AddObject(DrawingObject obj) { //should do something smart here... So that we get a more balanced tree. //things todo foreach (PointDouble pt in obj.points) { addPoint(pt); } }
public void ButtonPressed(uint button) { DoubleInputView dialogView; DoubleInputModel dialogModel; switch (button) { case 1: switch (selectedTool) { case ToolBarViewModel.Tools.SELECTION: IsClicked = true; GrabActiveObject(); break; case ToolBarViewModel.Tools.JOINT: if (!IsJoiningPoints) { IsJoiningPoints = true; GrabActiveObject(); } else { IsJoiningPoints = false; var point1 = ActivePoint; var body1 = ActiveObject; GrabActiveObject(); _model.Controller.AddJoint(point1, ActivePoint); } break; case ToolBarViewModel.Tools.FORCE: //popup dialog that asks for mag/dir dialogModel = new DoubleInputModel(2, new string[]{"Angle", "Magnitude"}); dialogView = new DoubleInputView(dialogModel); dialogView.ShowAll(); dialogView.Run(); GrabActiveObject(); if (ActiveObject != null && dialogModel._inputs != null) ActiveObject.AddForce (new Tuple<PointDouble,double, double> (ActivePoint,dialogModel._inputs[0],dialogModel._inputs[1])); //_model.Controller.AddForce(new Tuple<PointDouble,double, double> (ActivePoint,dialogModel._inputs[0],dialogModel._inputs[1])); break; case ToolBarViewModel.Tools.MOMENT: //popup dialog that asks for mag dialogModel = new DoubleInputModel(1, new string[]{"Magnitude"}); dialogView = new DoubleInputView(dialogModel); dialogView.ShowAll(); dialogView.Run(); GrabActiveObject(); if (ActiveObject != null && dialogModel._inputs != null) ActiveObject.AddMoment (new Tuple<PointDouble,double> (ActivePoint,dialogModel._inputs[0])); //_model.Controller.AddForce(new Tuple<PointDouble,double> (ActivePoint,dialogModel._inputs[0])); break; case ToolBarViewModel.Tools.CONNECTED: if (!IsDrawingObject) { BeginDrawingBody (); TemporaryObject = new ConnectedObject(); } ActivePoint = MousePos; _model.TemporaryObject.AddPoint (ActivePoint); break; case ToolBarViewModel.Tools.UNCONNECTED: if (!IsDrawingObject) { BeginDrawingBody (); TemporaryObject = new UnconnectedObject(); } ActivePoint = MousePos; _model.TemporaryObject.AddPoint (ActivePoint); break; default: break; } _lastX = _mouseX; _lastY = _mouseY; break; case 3: if (IsDrawingObject) { _model.TemporaryObject.AddPoint (MousePos); switch (selectedTool) { case ToolBarViewModel.Tools.CONNECTED: EndDrawingConnected (); break; case ToolBarViewModel.Tools.UNCONNECTED: EndDrawingUnconnected (); break; } } break; } VMMessenger.getMessenger ().sendMessage<RequestRedrawMessage> (new RequestRedrawMessage ()); }
public RigidBodyController(DrawingObject body) { rigidBody = body; }