public void Update_MULTISAME() { //const double SIZE = 800; const double SIZE = 3000; const double HALF = SIZE / 2; if (_visuals1 == null) { #region Create _visuals1 = new Tuple<StarfieldVisual1, double>[5]; for (int cntr = 0; cntr < _visuals1.Length; cntr++) { double starSizeMult = UtilityCore.GetScaledValue(.7, 1.1, 0, _visuals1.Length, cntr); double slideSpeed = UtilityCore.GetScaledValue(.75, 5, 0, _visuals1.Length, cntr); _visuals1[cntr] = Tuple.Create(new StarfieldVisual1(SIZE, 10, _visuals1.Length, starSizeMult), slideSpeed); Canvas.SetLeft(_visuals1[cntr].Item1, (_canvas.ActualWidth / 2) - HALF); Canvas.SetTop(_visuals1[cntr].Item1, (_canvas.ActualHeight / 2) - HALF); // This kills the framerate //_visuals[cntr].Item1.Effect = new BlurEffect() //{ // Radius = 2, //}; _canvas.Children.Add(_visuals1[cntr].Item1); } #endregion } // Figure out angle Vector3D desiredUp = new Vector3D(0, -1, 0); Vector3D up = _player.Ship.PhysicsBody.DirectionToWorld(desiredUp); double angle = Vector.AngleBetween(desiredUp.ToVector2D(), up.ToVector2D()); for (int cntr = 0; cntr < _visuals1.Length; cntr++) { TransformGroup transform = new TransformGroup(); #region Translate Point3D position = _player.Ship.PositionWorld; transform.Children.Add(new TranslateTransform(-position.X * _visuals1[cntr].Item2, position.Y * _visuals1[cntr].Item2)); // don't need to negate Y, because it's already backward #endregion #region Rotate transform.Children.Add(new RotateTransform(angle, HALF, HALF)); #endregion _visuals1[cntr].Item1.RenderTransform = transform; } }
public void Update() { //const double DENSITY = .002; const double DENSITY = .004; //const double SIZE = 800; const double SIZE = 3000; const double HALF = SIZE / 2; const double MARGIN = 10; if (_visuals2 == null) { #region Create _visuals2 = new Tuple<StarfieldVisual2, double>[5]; //NOTE: Playing around with different values. 8,60 looks good with 500x500, but isn't enough for 3000x3000 //Tuple<Vector[], int> vectorField = GetVectorField(8, 60); Tuple<Vector[], int> vectorField = GetVectorField(30, 500); for (int cntr = 0; cntr < _visuals2.Length; cntr++) { double starSizeMult = UtilityCore.GetScaledValue(.7, 1.1, 0, _visuals2.Length, cntr); double slideSpeed = UtilityCore.GetScaledValue(.75, 5, 0, _visuals2.Length, cntr); bool isComplexLayer = cntr == 2; double density = isComplexLayer ? DENSITY * .95 : DENSITY * .05; int numStars = Convert.ToInt32((density / _visuals2.Length) * SIZE * SIZE); if (isComplexLayer) { _visuals2[cntr] = Tuple.Create(new StarfieldVisual2(SIZE, MARGIN, numStars, starSizeMult, vectorField), slideSpeed); } else { _visuals2[cntr] = Tuple.Create(new StarfieldVisual2(SIZE, MARGIN, numStars, starSizeMult), slideSpeed); } Canvas.SetLeft(_visuals2[cntr].Item1, (_canvas.ActualWidth / 2) - HALF); Canvas.SetTop(_visuals2[cntr].Item1, (_canvas.ActualHeight / 2) - HALF); _canvas.Children.Add(_visuals2[cntr].Item1); } #endregion } // Figure out angle Vector3D desiredUp = new Vector3D(0, -1, 0); Vector3D up = _player.Ship.PhysicsBody.DirectionToWorld(desiredUp); double angle = Vector.AngleBetween(desiredUp.ToVector2D(), up.ToVector2D()); for (int cntr = 0; cntr < _visuals2.Length; cntr++) { TransformGroup transform = new TransformGroup(); #region Translate Point3D position = _player.Ship.PositionWorld; transform.Children.Add(new TranslateTransform(-position.X * _visuals2[cntr].Item2, position.Y * _visuals2[cntr].Item2)); // don't need to negate Y, because it's already backward #endregion #region Rotate transform.Children.Add(new RotateTransform(angle, HALF, HALF)); #endregion _visuals2[cntr].Item1.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; }