private ShipSelectorWindow(NewtonDynamics.World world)
        {
            InitializeComponent();

            this.Background = SystemColors.ControlBrush;

            _world = world;
        }
        public ShipSelectorWindow(string foldername, NewtonDynamics.World world)
            : this(world)
        {
            grdFolder.Visibility = Visibility.Visible;
            lblStatus.Visibility = Visibility.Visible;

            // Let the textchange event load the listbox
            txtFoldername.Text = foldername;
        }
        public ShipSelectorWindow(ShipDNA[] dna, NewtonDynamics.World world)
            : this(world)
        {
            grdFolder.Visibility = Visibility.Collapsed;
            lblStatus.Visibility = Visibility.Collapsed;

            foreach (ShipDNA item in dna)
            {
                AddItem(item, null);
            }
        }
예제 #4
0
        public Icon3D(string name, ShipDNA dna, NewtonDynamics.World world)
        {
            InitializeComponent();

            this.ItemName = name;
            this.ShipDNA = dna;

            lblName.Text = name;
            lblName.Visibility = _showName ? Visibility.Visible : Visibility.Collapsed;

            InitializeTrackball();

            // Load the ship asyncronously
            FinishLoadingShipAsync(world);
        }
예제 #5
0
        //TODO: Make a static method off of Ship, and don't rely on world: public static Visual3D CreateVisual(ShipDNA dna, bool isDesign)
        private async Task RenderShipAsync(NewtonDynamics.World world)
        {
            ShipExtraArgs args = new ShipExtraArgs()
            {
                RunNeural = false,
                RepairPartPositions = false,
            };

            //using (Ship ship = await Ship.GetNewShipAsync(this.ShipDNA, world, 0, null, args))
            using (Bot bot = new Bot(BotConstructor.ConstructBot(this.ShipDNA, new ShipCoreArgs() { World = world }, args)))
            {
                if (bot.PhysicsBody.Visuals != null)		// this will never be null
                {
                    // The model coords may not be centered, so move the ship so that it's centered on the origin
                    Point3D minPoint, maxPoint;
                    bot.PhysicsBody.GetAABB(out minPoint, out maxPoint);
                    Vector3D offset = (minPoint + ((maxPoint - minPoint) / 2d)).ToVector();

                    bot.PhysicsBody.Position = (-offset).ToPoint();

                    // Add the visuals
                    foreach (Visual3D visual in bot.PhysicsBody.Visuals)
                    {
                        _viewport.Children.Add(visual);
                    }

                    // Pull the camera back to a good distance
                    _camera.Position = (_camera.Position.ToVector().ToUnit() * (bot.Radius * 2.1d)).ToPoint();
                }
            }
        }
예제 #6
0
        private async Task FinishLoadingShipAsync(NewtonDynamics.World world)
        {
            // Show the ship
            await RenderShipAsync(world);

            // Lights
            InitializeLight();
        }
        public override CollisionHull CreateCollisionHull(NewtonDynamics.WorldBase world)
        {
            // Get points
            if (this.Vertices == null)
            {
                CreateGeometry(this.IsFinalModel);
            }

            Vector3D scale = this.Scale;

            double halfThick = THICKNESS * .5d * scale.Z;

            List<Point3D> points = new List<Point3D>();
            points.AddRange(this.Vertices.Select(o => new Point3D(o.X * scale.X, o.Y * scale.Y, -halfThick)));
            points.AddRange(this.Vertices.Select(o => new Point3D(o.X * scale.X, o.Y * scale.Y, halfThick)));

            // Transform
            Transform3DGroup transform = new Transform3DGroup();
            //transform.Children.Add(new ScaleTransform3D(this.Scale));		// it ignores scale
            transform.Children.Add(new RotateTransform3D(new QuaternionRotation3D(this.Orientation)));
            transform.Children.Add(new TranslateTransform3D(this.Position.ToVector()));

            // Exit Function
            return CollisionHull.CreateConvexHull(world, 0, points, transform.Value);
        }
        private void PhysicsBody_ApplyForceAndTorque(object sender, NewtonDynamics.BodyApplyForceAndTorqueArgs e)
        {
            // Clear visual
            if (_springVisual != null)
            {
                _springVisual.Points.Clear();
            }

            // See if there is anything to do
            if (_desiredPoint == null)
            {
                return;
            }

            Point3D current = e.Body.PositionToWorld(this.Offset.ToPoint());
            Point3D desired = _desiredPoint.Value;

            // I decided to add x^2, because a linear spring is too weak
            // f = k x^2
            Vector3D spring = desired - current;
            double length = spring.Length;
            spring = spring.ToUnit() * (_springConstant * this.SpringForceMultiplier * length * length);

            // Apply the force
            if (_shouldSpringCauseTorque)
            {
                e.Body.AddForceAtPoint(spring, current);
            }
            else
            {
                e.Body.AddForce(spring);
            }

            if (_isDamped)      // this.ShouldDampenWhenSpring is taken into account before setting _isDamped to true
            {
                // Body.LinearDamping isn't strong enough, so do some more
                //Vector3D drag = e.Body.Velocity * (-_springConstant * this.SpringForceMultiplier * .33d);
                Vector3D drag = e.Body.Velocity * (-_springConstant * .33d);
                e.Body.AddForce(drag);
            }

            // Update visual
            if (_springVisual != null)
            {
                _springVisual.AddLine(current, desired);
            }
        }