Пример #1
0
        private void Sensor_RequestWorldLocation(object sender, PartRequestWorldLocationArgs e)
        {
            try
            {
                if (!(sender is PartBase))
                {
                    throw new ApplicationException("Expected sender to be PartBase");
                }

                PartBase senderCast = (PartBase)sender;

                // These parts aren't part of a ship, so model coords is world coords
                e.Orientation = senderCast.Orientation;
                e.Position = senderCast.Position;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), this.Title, MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
 private void TestCamera_RequestWorldLocation(object sender, PartRequestWorldLocationArgs e)
 {
     e.Position = new Point3D(0, 0, 0);
     e.Orientation = Quaternion.Identity;
 }
Пример #3
0
        /// <summary>
        /// Some parts need to know their location in world coords (sensors).  So this raises an event that needs to be filled out by the owner
        /// of the part.
        /// </summary>
        /// <remarks>
        /// I didn't want the part to have a direct reference to the ship.  There are various test forms that don't use ship.  There could also be
        /// several independent simulations that use a completely different class than ship.  Also, parts could be mounted to movable limbs.
        /// So it's up to the container to know all of that complexity, and just return world coords when asked.
        /// </remarks>
        public Tuple<Point3D, Quaternion> GetWorldLocation()
        {
            if (this.RequestWorldLocation == null)
            {
                //TODO: If this becomes tedious, just return the location in model coords.  I just figured an exception would make it easier to catch plumbing issues
                throw new ApplicationException("There is no event handler for RequestWorldLocation");
            }

            PartRequestWorldLocationArgs args = new PartRequestWorldLocationArgs();

            this.RequestWorldLocation(this, args);

            if (args.Position == null)
            {
                throw new ApplicationException("The event handler for RequestWorldLocation didn't set position");
            }
            else if (args.Orientation == null)
            {
                throw new ApplicationException("The event handler for RequestWorldLocation didn't set orientation");
            }

            return Tuple.Create(args.Position.Value, args.Orientation.Value);
        }
Пример #4
0
        private void Part_RequestWorldLocation(object sender, PartRequestWorldLocationArgs e)
        {
            if (!(sender is PartBase))
            {
                throw new ApplicationException("Expected sender to be PartBase");
            }

            PartBase senderCast = (PartBase)sender;

            e.Orientation = this.PhysicsBody.Rotation.RotateBy(senderCast.Orientation);
            e.Position = this.PositionWorld + this.PhysicsBody.Rotation.GetRotatedVector(senderCast.Position.ToVector());
        }