/// <summary> /// Item1 = Velocity /// Item2 = AngularVelocity /// Item3 = Velocity at point (only returned if a position is passed in) /// NOTE: atPoint is in model coords, and should only be non null if you want the velocity at that point to be calculated /// </summary> public Tuple<Vector3D, Vector3D, Vector3D?> GetWorldSpeed(Point3D? atPoint) { if (this.RequestWorldSpeed == null) { throw new ApplicationException("There is no event handler for RequestWorldSpeed"); } PartRequestWorldSpeedArgs args = new PartRequestWorldSpeedArgs(); args.GetVelocityAtPoint = atPoint; this.RequestWorldSpeed(this, args); if (args.Velocity == null) { throw new ApplicationException("The event handler for RequestWorldSpeed didn't set velocity"); } else if (args.AngularVelocity == null) { throw new ApplicationException("The event handler for RequestWorldSpeed didn't set angular velocity"); } else if (atPoint != null && args.VelocityAtPoint == null) { throw new ApplicationException("The event handler for RequestWorldSpeed didn't set velocity at point"); } return Tuple.Create(args.Velocity.Value, args.AngularVelocity.Value, args.VelocityAtPoint); }
private void Part_RequestWorldSpeed(object sender, PartRequestWorldSpeedArgs e) { if (!(sender is PartBase)) { throw new ApplicationException("Expected sender to be PartBase"); } PartBase senderCast = (PartBase)sender; e.Velocity = this.PhysicsBody.Velocity; e.AngularVelocity = this.PhysicsBody.AngularVelocity; if (e.GetVelocityAtPoint != null) { e.VelocityAtPoint = this.PhysicsBody.GetVelocityAtPoint(this.PhysicsBody.Position + this.PhysicsBody.PositionToWorld(e.GetVelocityAtPoint.Value).ToVector()); } }