Exemple #1
0
        public void Update_SINGLE()
        {
            //const double SIZE = 800;
            const double SIZE = 3000;
            const double HALF = SIZE / 2;

            if (_visual == null)
            {
                #region Create

                _visual = new StarfieldVisual1(SIZE, 10, 1, 1);

                Canvas.SetLeft(_visual, (_canvas.ActualWidth / 2) - HALF);
                Canvas.SetTop(_visual, (_canvas.ActualHeight / 2) - HALF);

                _canvas.Children.Add(_visual);

                #endregion
            }

            TransformGroup transform = new TransformGroup();

            #region Translate

            Point3D position = _player.Ship.PositionWorld;

            transform.Children.Add(new TranslateTransform(-position.X, position.Y));        // don't need to negate Y, because it's already backward

            #endregion
            #region Rotate

            Vector3D desiredUp = new Vector3D(0, -1, 0);
            Vector3D up        = _player.Ship.PhysicsBody.DirectionToWorld(desiredUp);

            double angle = Vector.AngleBetween(desiredUp.ToVector2D(), up.ToVector2D());

            transform.Children.Add(new RotateTransform(angle, HALF, HALF));

            #endregion

            _visual.RenderTransform = transform;
        }
        public void Update_SINGLE()
        {
            //const double SIZE = 800;
            const double SIZE = 3000;
            const double HALF = SIZE / 2;

            if (_visual == null)
            {
                #region Create

                _visual = new StarfieldVisual1(SIZE, 10, 1, 1);

                Canvas.SetLeft(_visual, (_canvas.ActualWidth / 2) - HALF);
                Canvas.SetTop(_visual, (_canvas.ActualHeight / 2) - HALF);

                _canvas.Children.Add(_visual);

                #endregion
            }

            TransformGroup transform = new TransformGroup();

            #region Translate

            Point3D position = _player.Ship.PositionWorld;

            transform.Children.Add(new TranslateTransform(-position.X, position.Y));        // don't need to negate Y, because it's already backward

            #endregion
            #region Rotate

            Vector3D desiredUp = new Vector3D(0, -1, 0);
            Vector3D up = _player.Ship.PhysicsBody.DirectionToWorld(desiredUp);

            double angle = Vector.AngleBetween(desiredUp.ToVector2D(), up.ToVector2D());

            transform.Children.Add(new RotateTransform(angle, HALF, HALF));

            #endregion

            _visual.RenderTransform = transform;
        }