Exemple #1
0
        private void RedrawGraph(NeatGenome genome)
        {
            IBlackBox box = _experiment.GetBlackBox(genome);

            Color trueColor  = panPlot.TrueColor;
            Color falseColor = panPlot.FalseColor;

            var samples = Enumerable.Range(0, 1000).
                          Select(o =>
            {
                Vector3D pos = Math3D.GetRandomVector(new Vector3D(0, 0, 0), new Vector3D(1, 1, 1));

                box.ResetState();

                //box.InputSignalArray.CopyFrom()
                box.InputSignalArray[0] = pos.X;
                box.InputSignalArray[1] = pos.Y;
                box.InputSignalArray[2] = pos.Z;

                box.Activate();

                double percent = box.OutputSignalArray[0];

                Color color = UtilityWPF.AlphaBlend(trueColor, falseColor, percent);

                return(Tuple.Create(pos.ToPoint(), color));
            });

            panPlot.ClearFrame();
            panPlot.AddDots(samples, .01, false);
        }
Exemple #2
0
        private void btnTest1_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                ClearCubes(_testCubes);

                // Translate Only (negative)
                ModelVisual3D    cube      = CreateCube(_testCubes, UtilityWPF.AlphaBlend(Colors.Gold, Colors.White, .5d), 1d, new Point3D(0, 0, 0));
                Transform3DGroup transform = new Transform3DGroup();
                transform.Children.Add(new TranslateTransform3D(-5, 0, 0));
                cube.Transform = transform;

                // Translate/Rotate
                cube      = CreateCube(_testCubes, UtilityWPF.AlphaBlend(Colors.Gold, Colors.White, 1d), 1d, new Point3D(0, 0, 0));
                transform = new Transform3DGroup();
                transform.Children.Add(new TranslateTransform3D(5, 0, 0));
                transform.Children.Add(new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(0, 0, 1), 45)));
                cube.Transform = transform;

                // Rotate/Translate
                cube      = CreateCube(_testCubes, UtilityWPF.AlphaBlend(Colors.Gold, Colors.White, 0d), 1d, new Point3D(0, 0, 0));
                transform = new Transform3DGroup();
                transform.Children.Add(new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(0, 0, 1), 45)));
                transform.Children.Add(new TranslateTransform3D(5, 0, 0));
                cube.Transform = transform;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), this.Title, MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Exemple #3
0
        private static void ProgressColorChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            ProgressBarGame senderCast = sender as ProgressBarGame;

            if (senderCast == null)
            {
                return;         // this should never happen
            }

            Color color = (Color)e.NewValue;

            // Turn the color into a slight gradient
            LinearGradientBrush brush = new LinearGradientBrush();

            brush.StartPoint = new Point(0, 0);
            brush.EndPoint   = new Point(0, 1);

            GradientStopCollection gradients = new GradientStopCollection();

            gradients.Add(new GradientStop(UtilityWPF.AlphaBlend(Colors.White, color, .5d), 0d));
            gradients.Add(new GradientStop(UtilityWPF.AlphaBlend(Colors.White, color, .25d), .1d));
            gradients.Add(new GradientStop(color, .4d));
            gradients.Add(new GradientStop(UtilityWPF.AlphaBlend(Colors.Black, color, .2d), .9d));
            gradients.Add(new GradientStop(UtilityWPF.AlphaBlend(Colors.Black, color, .25d), 1d));
            brush.GradientStops = gradients;

            // The progress bar is actually tied to this property
            senderCast.ProgressBrush = brush;
        }
Exemple #4
0
            private static ModelVisual3D BuildDot(bool isStatic)
            {
                Color color = UtilityWPF.ColorFromHex(isStatic ? DOTCOLOR_STATIC : DOTCOLOR);

                // Material
                MaterialGroup materials = new MaterialGroup();

                materials.Children.Add(new DiffuseMaterial(new SolidColorBrush(color)));
                materials.Children.Add(new SpecularMaterial(new SolidColorBrush(UtilityWPF.AlphaBlend(color, Colors.White, .5d)), 50d));

                // Geometry Model
                GeometryModel3D geometry = new GeometryModel3D();

                geometry.Material     = materials;
                geometry.BackMaterial = materials;
                geometry.Geometry     = UtilityWPF.GetSphere_LatLon(5, DOTRADIUS, DOTRADIUS, DOTRADIUS);

                // Model Visual
                ModelVisual3D retVal = new ModelVisual3D();

                retVal.Content = geometry;

                // Exit Function
                return(retVal);
            }
Exemple #5
0
        /// <summary>
        /// This places a dot in the viewport that will dissapear in a couble seconds
        /// </summary>
        private void AddDebugDot(Point3D position, double radius, Color color)
        {
            // Material
            MaterialGroup materials = new MaterialGroup();

            materials.Children.Add(new DiffuseMaterial(new SolidColorBrush(color)));
            materials.Children.Add(new SpecularMaterial(new SolidColorBrush(UtilityWPF.AlphaBlend(color, Colors.White, .5d)), 100d));

            // Geometry Model
            GeometryModel3D geometry = new GeometryModel3D();

            geometry.Material     = materials;
            geometry.BackMaterial = materials;
            geometry.Geometry     = UtilityWPF.GetSphere_LatLon(3, radius, radius, radius);

            // Model Visual
            ModelVisual3D model = new ModelVisual3D();

            model.Content   = geometry;
            model.Transform = new TranslateTransform3D(position.ToVector());

            // Temporarily add to the viewport
            _debugVisuals.Add(model);
            _viewport.Children.Add(model);
            _debugVisualTimer.IsEnabled = true;
        }
Exemple #6
0
            private static Brush GetBrush(MapOctree node, Func <MapOctree, double> getValue, double valueMult, Color color)
            {
                const double MAXOPACITY = .25;

                //if (node.Items.Any(o => o.MapObject is ShipPlayer))
                //{
                //    return new SolidColorBrush(UtilityWPF.ColorFromHex("600000FF"));
                //}

                // Add up the resources
                double resourceValue = getValue(node);

                if (resourceValue.IsNearZero())
                {
                    return(null);
                }

                double area = (node.MaxRange.X - node.MinRange.X) * (node.MaxRange.Y - node.MinRange.Y);

                double opacity = (resourceValue * valueMult) / area;

                if (opacity > 1)
                {
                    opacity = 1;
                }

                Color colorFinal = UtilityWPF.AlphaBlend(color, Colors.Transparent, opacity * MAXOPACITY);

                return(new SolidColorBrush(colorFinal));
            }
Exemple #7
0
        private void GetMineralBlipSprtCacheProps()
        {
            // Get the min/max values
            double minDollars = double.MaxValue;
            double maxDollars = double.MinValue;

            SortedList <MineralType, double> dollars = new SortedList <MineralType, double>();

            foreach (MineralType mineralType in Enum.GetValues(typeof(MineralType)))
            {
                if (mineralType == MineralType.Custom)
                {
                    continue;
                }

                decimal suggestedDollars       = Mineral.GetSuggestedValue(mineralType);
                double  suggestedDollarsScaled = Math.Sqrt(Convert.ToDouble(suggestedDollars));   // taking the square root, because the values are exponential, and I want the color scale more linear
                dollars.Add(mineralType, suggestedDollarsScaled);

                if (suggestedDollarsScaled < minDollars)
                {
                    minDollars = suggestedDollarsScaled;
                }

                if (suggestedDollarsScaled > maxDollars)
                {
                    maxDollars = suggestedDollarsScaled;
                }
            }

            // Store color based on those values
            _mineralColors = new SortedList <MineralType, MineralBlipProps>();
            Color maxColor = Colors.Chartreuse;

            foreach (MineralType mineralType in Enum.GetValues(typeof(MineralType)))
            {
                MineralBlipProps props = new MineralBlipProps();

                if (mineralType == MineralType.Custom)
                {
                    props.DiffuseColor  = Colors.HotPink;     // not sure what to do here.  maybe I'll know more if I ever use custom minerals  :)
                    props.SpecularColor = props.DiffuseColor;
                    props.Size          = 4;
                }
                else
                {
                    double dollar = dollars[mineralType];

                    double colorPercent = UtilityCore.GetScaledValue_Capped(.33d, 1d, minDollars, maxDollars, dollar);
                    props.DiffuseColor  = UtilityWPF.AlphaBlend(maxColor, Colors.Transparent, colorPercent);
                    props.SpecularColor = props.DiffuseColor;

                    props.Size = UtilityCore.GetScaledValue_Capped(2d, 5d, minDollars, maxDollars, dollar);
                }

                _mineralColors.Add(mineralType, props);
            }
        }
Exemple #8
0
        private void CreateSpaceStationsSprtBuild(Point3D position)
        {
            SpaceStation spaceStation = new SpaceStation();

            spaceStation.SpinDegreesPerSecond = Math1D.GetNearZeroValue(10d);
            spaceStation.HullColor            = UtilityWPF.AlphaBlend(UtilityWPF.GetRandomColor(108, 148), Colors.Gray, .25);
            spaceStation.CreateStation(_map, position);

            _spaceStations.Add(spaceStation);
        }
Exemple #9
0
        private void CreateShip()
        {
            if (_ship != null)
            {
                throw new ApplicationException("Ship already created");
            }

            _ship                  = new Ship();
            _ship.HullColor        = UtilityWPF.AlphaBlend(UtilityWPF.GetRandomColor(255, 64, 192), Color.FromArgb(255, 64, 64, 64), .5d);
            _ship.ShowDebugVisuals = _showDebugVisuals;
            _ship.CreateShip(_materialManager, _sharedVisuals, _map, progressBarCargo, progressBarFuel);

            _ship.PhysicsBody.ApplyForce += new BodyForceEventHandler(Body_ApplyForce);
        }
Exemple #10
0
        private static Color GetWeightedColor(double weight)
        {
            Color zero = UtilityWPF.ColorFromHex(COLOR_ZERO);

            if (weight > 0d)
            {
                Color positive = UtilityWPF.ColorFromHex(COLOR_POSITIVE);
                return(UtilityWPF.AlphaBlend(positive, zero, weight));
            }
            else
            {
                Color negative = UtilityWPF.ColorFromHex(COLOR_NEGATIVE);
                return(UtilityWPF.AlphaBlend(negative, zero, Math.Abs(weight)));
            }
        }
Exemple #11
0
        private void GetMineralBlipSprtCacheProps()
        {
            // Get the min/max values
            double minDollars = double.MaxValue;
            double maxDollars = double.MinValue;

            SortedList <MineralType, double> dollars = new SortedList <MineralType, double>();

            foreach (MineralType mineralType in Enum.GetValues(typeof(MineralType)))
            {
                //decimal suggestedDollars = Mineral.GetSuggestedCredits(mineralType);
                decimal suggestedDollars       = ItemOptionsAstMin2D.GetCredits_Mineral(mineralType);
                double  suggestedDollarsScaled = Math.Sqrt(Convert.ToDouble(suggestedDollars));   // taking the square root, because the values are exponential, and I want the color scale more linear
                dollars.Add(mineralType, suggestedDollarsScaled);

                if (suggestedDollarsScaled < minDollars)
                {
                    minDollars = suggestedDollarsScaled;
                }

                if (suggestedDollarsScaled > maxDollars)
                {
                    maxDollars = suggestedDollarsScaled;
                }
            }

            // Store color based on those values
            _mineralColors = new SortedList <MineralType, MineralBlipProps>();
            Color maxColor = Colors.Chartreuse;

            foreach (MineralType mineralType in Enum.GetValues(typeof(MineralType)))
            {
                Color  diffuse, specular;
                double size;

                double dollar = dollars[mineralType];

                double colorPercent = UtilityCore.GetScaledValue_Capped(.33d, 1d, minDollars, maxDollars, dollar);
                diffuse  = UtilityWPF.AlphaBlend(maxColor, Colors.Transparent, colorPercent);
                specular = diffuse;

                //size = UtilityCore.GetScaledValue_Capped(2d, 5d, minDollars, maxDollars, dollar);
                size = UtilityCore.GetScaledValue_Capped(4d, 10d, minDollars, maxDollars, dollar);

                _mineralColors.Add(mineralType, new MineralBlipProps(diffuse, specular, size));
            }
        }
Exemple #12
0
        public override bool Update(double elapsedTime)
        {
            bool retVal = base.Update(elapsedTime);

            if (retVal)
            {
                RemoveVisual();
            }
            else
            {
                #region Update Visual

                // Transparency
                double transparency = UtilityCore.GetScaledValue_Capped(0d, 1d, _visualStartRadius, this.MaxRadius * .75d, this.Radius);                // I want it to become invisible sooner
                _material.Brush = new SolidColorBrush(UtilityWPF.AlphaBlend(Colors.Transparent, _baseColor, transparency));

                // Scale (this is what Body.OnBodyMoved does, plus scale)
                //NOTE:  The radius gets huge, but the force drops off quickly, so it doesn't look right if I scale it to full size
                double scale = UtilityCore.GetScaledValue_Capped(1d, (this.MaxRadius * .05d) / _visualStartRadius, _visualStartRadius, this.MaxRadius, this.Radius);

                Transform3DGroup transform = new Transform3DGroup();
                transform.Children.Add(new ScaleTransform3D(scale, scale, scale));

                if (this.Body == null)
                {
                    transform.Children.Add(new TranslateTransform3D(this.Position.ToVector()));
                }
                else
                {
                    transform.Children.Add(new MatrixTransform3D(this.Body.OffsetMatrix));
                }

                _visual.Transform = transform;

                //NOTE:  The shell is smaller than this.Radius (once it overtakes _visualStartRadius)
                if (this.Radius > _visualStartRadius * 2)
                {
                    _pointLight.Range = this.Radius;
                }

                #endregion
            }

            // Exit Function
            return(retVal);
        }
        private void trkMapSize_ValueChanged(object sender, RoutedPropertyChangedEventArgs <double> e)
        {
            if (_world == null || trkMapSize == null)
            {
                return;
            }

            // Clear old
            foreach (ScreenSpaceLines3D line in _lines)
            {
                _viewport.Children.Remove(line);
                line.Dispose();
            }
            _lines.Clear();

            double boundry = trkMapSize.Value;

            lblMapSize.Content = boundry.ToString("N0");

            // Set the new boundry
            List <Point3D[]> innerLines, outerLines;

            _world.SetCollisionBoundry(out innerLines, out outerLines, _viewport, new Vector3D(-boundry, -boundry, -boundry), new Vector3D(boundry, boundry, boundry));

            // Draw the lines
            Color lineColor = UtilityWPF.AlphaBlend(Colors.White, Colors.Gray, .1d);

            foreach (Point3D[] line in innerLines)
            {
                ScreenSpaceLines3D lineModel = new ScreenSpaceLines3D(false);
                lineModel.Thickness = 1d;
                lineModel.Color     = lineColor;
                lineModel.AddLine(line[0], line[1]);

                _viewport.Children.Add(lineModel);
                _lines.Add(lineModel);
            }

            // NOTE:  If this is called from the constructor, then recalculating doesn't do any good.  They must be recalculated
            // in the window load
            RecalculateLineGeometries();
        }
Exemple #14
0
            public Color GetNeuronColor(INeuron neuron)
            {
                if (neuron.IsPositiveOnly)
                {
                    return(UtilityWPF.AlphaBlend(Neuron_One_ZerPos, Neuron_Zero_ZerPos, neuron.Value));
                }
                else
                {
                    double weight = neuron.Value;     // need to grab the value locally, because it could be modified from a different thread

                    if (weight < 0)
                    {
                        return(UtilityWPF.AlphaBlend(Neuron_NegOne_NegPos, Neuron_Zero_NegPos, Math.Abs(weight)));
                    }
                    else
                    {
                        return(UtilityWPF.AlphaBlend(Neuron_One_NegPos, Neuron_Zero_NegPos, weight));
                    }
                }
            }
Exemple #15
0
        public static Model3D CreateShellVisual(bool isFinal, List <MaterialColorProps> materialBrushes, List <EmissiveMaterial> selectionEmissives, ScaleTransform3D scaleTransform)
        {
            GeometryModel3D geometry   = new GeometryModel3D();
            MaterialGroup   material   = new MaterialGroup();
            Color           shellColor = WorldColors.Brain_Color;

            if (!isFinal)
            {
                shellColor = UtilityWPF.AlphaBlend(shellColor, Colors.Transparent, .75d);
            }
            DiffuseMaterial diffuse = new DiffuseMaterial(new SolidColorBrush(shellColor));

            materialBrushes.Add(new MaterialColorProps(diffuse, shellColor));
            material.Children.Add(diffuse);

            SpecularMaterial specular = WorldColors.Brain_Specular;

            materialBrushes.Add(new MaterialColorProps(specular));
            material.Children.Add(specular);

            if (!isFinal)
            {
                EmissiveMaterial selectionEmissive = new EmissiveMaterial(Brushes.Transparent);
                material.Children.Add(selectionEmissive);
                selectionEmissives.Add(selectionEmissive);
            }

            geometry.Material     = material;
            geometry.BackMaterial = material;

            Transform3DGroup transformGroup = new Transform3DGroup();

            transformGroup.Children.Add(scaleTransform);
            transformGroup.Children.Add(new RotateTransform3D(new QuaternionRotation3D(Math3D.GetRandomRotation()))); // this is just so it's not obvious that the brains are shared visuals

            geometry.Geometry  = SharedVisuals.BrainMesh;                                                             // SharedVisuals keeps track of which thread made the request
            geometry.Transform = transformGroup;

            return(geometry);
        }
Exemple #16
0
        private static Visual3D GetSphereVisual(double radius, Color color)
        {
            // Material
            MaterialGroup materials = new MaterialGroup();

            materials.Children.Add(new DiffuseMaterial(new SolidColorBrush(color)));
            materials.Children.Add(new SpecularMaterial(new SolidColorBrush(UtilityWPF.AlphaBlend(color, Colors.White, .5d)), 50d));

            // Geometry Model
            GeometryModel3D geometry = new GeometryModel3D();

            geometry.Material     = materials;
            geometry.BackMaterial = materials;
            geometry.Geometry     = UtilityWPF.GetSphere_LatLon(20, radius, radius, radius);

            // Model Visual
            ModelVisual3D retVal = new ModelVisual3D();

            retVal.Content = geometry;

            return(retVal);
        }
Exemple #17
0
        private void Timer_Tick(object sender, EventArgs e)
        {
            const double FIELDDURATION = 250d;          // It should reach zero after 500 milliseconds

            if (_forceFieldOpacity > 0d)
            {
                #region Still Active

                // Set the colors
                _forceField_DiffuseMaterial.Brush = new SolidColorBrush(UtilityWPF.AlphaBlend(WorldColors.SpaceStationForceField_Color, Colors.Transparent, _forceFieldOpacity));
                _forceField_EmissiveFront.Brush   = new SolidColorBrush(UtilityWPF.AlphaBlend(WorldColors.SpaceStationForceField_Emissive_Front, Colors.Transparent, _forceFieldOpacity));
                _forceField_EmissiveRear.Brush    = new SolidColorBrush(UtilityWPF.AlphaBlend(WorldColors.SpaceStationForceField_Emissive_Back, Colors.Transparent, _forceFieldOpacity));

                // Diminish the opacity for the next tick
                if (_timer.Interval.TotalMilliseconds > FIELDDURATION)
                {
                    _forceFieldOpacity = -1d;
                }
                else
                {
                    _forceFieldOpacity -= (1d / FIELDDURATION) * _timer.Interval.TotalMilliseconds;
                }

                #endregion
            }
            else
            {
                #region Set transparent

                _forceField_DiffuseMaterial.Brush = null; // Brushes.Transparent;
                _forceField_EmissiveFront.Brush   = null; // Brushes.Transparent;
                _forceField_EmissiveRear.Brush    = null; // Brushes.Transparent;

                _timer.Stop();

                #endregion
            }
        }
Exemple #18
0
        private static Visual3D GetVisual_Dot(Point3D position, double radius, Color color)
        {
            // Material
            MaterialGroup materials = new MaterialGroup();

            materials.Children.Add(new DiffuseMaterial(new SolidColorBrush(color)));
            materials.Children.Add(new SpecularMaterial(new SolidColorBrush(UtilityWPF.AlphaBlend(color, Colors.White, .5d)), 50d));

            // Geometry Model
            GeometryModel3D geometry = new GeometryModel3D();

            geometry.Material     = materials;
            geometry.BackMaterial = materials;
            geometry.Geometry     = UtilityWPF.GetSphere_LatLon(3, radius, radius, radius);

            // Model Visual
            ModelVisual3D retVal = new ModelVisual3D();

            retVal.Content   = geometry;
            retVal.Transform = new TranslateTransform3D(position.ToVector());

            return(retVal);
        }
Exemple #19
0
        public GravityCubes2()
        {
            InitializeComponent();

            grdPanel.Background          = SystemColors.ControlBrush;
            chkAttractedToOrigin.Content = "Attracted to\r\nOrigin";

            #region Init World

            _world.InitialiseBodies();
            _world.Gravity = 0d;

            List <Point3D[]> innerLines, outerLines;
            _world.SetCollisionBoundry(out innerLines, out outerLines, _viewport, new Vector3D(-15, -15, -15), new Vector3D(15, 15, 15));

            Color lineColor = UtilityWPF.AlphaBlend(Colors.White, Colors.Gray, .1d);
            foreach (Point3D[] line in innerLines)
            {
                // Need to wait until the window is loaded to call lineModel.CalculateGeometry
                ScreenSpaceLines3D lineModel = new ScreenSpaceLines3D(false);
                lineModel.Thickness = 1d;
                lineModel.Color     = lineColor;
                lineModel.AddLine(line[0], line[1]);

                _viewport.Children.Add(lineModel);
                _lines.Add(lineModel);
            }

            _world.UnPause();

            #endregion

            _trackball                       = new TrackBallRoam(_camera);
            _trackball.EventSource           = grdViewPort;
            _trackball.AllowZoomOnMouseWheel = true;
            _trackball.Mappings.AddRange(TrackBallMapping.GetPrebuilt(TrackBallMapping.PrebuiltMapping.MouseComplete));
        }
Exemple #20
0
        /// <summary>
        /// This adds text into the 3D scene
        /// NOTE: This is affected by WPF's "feature" of semi transparent visuals only showing visuals that were added before
        /// </summary>
        /// <remarks>
        /// Think of the text sitting in a 2D rectangle. position=center, normal=vector sticking out of rect, textDirection=vector along x
        /// </remarks>
        /// <param name="position">The center point of the text</param>
        /// <param name="normal">The direction of the vector that points straight out of the plane of the text (default is 0,0,1)</param>
        /// <param name="textDirection">The direction of the vector that points along the text (default is 1,0,0)</param>
        public void AddText3D(string text, Point3D position, Vector3D normal, double height, Color color, bool isShiny, Vector3D?textDirection = null, double?depth = null, FontFamily font = null, FontStyle?style = null, FontWeight?weight = null, FontStretch?stretch = null)
        {
            Material faceMaterial = GetMaterial(isShiny, color);
            Material edgeMaterial = GetMaterial(false, UtilityWPF.AlphaBlend(color, UtilityWPF.OppositeColor_BW(color), .75));

            ModelVisual3D visual = new ModelVisual3D();

            visual.Content = UtilityWPF.GetText3D(
                text,
                font ?? this.FontFamily,
                faceMaterial,
                edgeMaterial,
                height,
                depth ?? height / 15d,
                style,
                weight,
                stretch);

            Transform3DGroup transform = new Transform3DGroup();

            Quaternion quat;

            if (textDirection == null)
            {
                quat = Math3D.GetRotation(new Vector3D(0, 0, 1), normal);
            }
            else
            {
                quat = Math3D.GetRotation(new DoubleVector(new Vector3D(0, 0, 1), new Vector3D(1, 0, 0)), new DoubleVector(normal, textDirection.Value));
            }
            transform.Children.Add(new RotateTransform3D(new QuaternionRotation3D(quat)));

            transform.Children.Add(new TranslateTransform3D(position.ToVector()));
            visual.Transform = transform;

            _viewport.Children.Add(visual);
        }
        private Visual3D AddDot(Point3D position, Color color, double radius = .03)
        {
            // Material
            MaterialGroup materials = new MaterialGroup();

            materials.Children.Add(new DiffuseMaterial(new SolidColorBrush(color)));
            materials.Children.Add(new SpecularMaterial(new SolidColorBrush(UtilityWPF.AlphaBlend(color, Colors.White, .5d)), 50d));

            // Geometry Model
            GeometryModel3D geometry = new GeometryModel3D();

            geometry.Material     = materials;
            geometry.BackMaterial = materials;
            geometry.Geometry     = UtilityWPF.GetSphere_Ico(radius, 4, true);

            // Model Visual
            ModelVisual3D visual = new ModelVisual3D();

            visual.Content   = geometry;
            visual.Transform = new TranslateTransform3D(position.ToVector());

            _viewport.Children.Add(visual);
            return(visual);
        }
Exemple #22
0
        /// <summary>
        /// Set the properties, then call create
        /// NOTE:  This adds itself to the viewport and world.  In the future, that should be handled by the caller
        /// </summary>
        public void CreateBot(Viewport3D viewport, SharedVisuals sharedVisuals, World world, Point3D worldPosition)
        {
            _viewport = viewport;

            // Thruster
            _origThrustDirection = new Vector3D(0, 4, 0);
            _thruster            = new ThrustLine(_viewport, sharedVisuals, _origThrustDirection, new Vector3D(0, 0, 0));

            MaterialGroup   material = null;
            GeometryModel3D geometry = null;
            ModelVisual3D   model    = null;

            #region Interior Extra Visuals

            // These are visuals that will stay oriented to the ship, but don't count in collision calculations

            #region Core

            // Neutral
            _coreMaterialNeutral = new MaterialGroup();
            _coreMaterialNeutral.Children.Add(new DiffuseMaterial(Brushes.DimGray));
            _coreMaterialNeutral.Children.Add(new SpecularMaterial(Brushes.DimGray, 75d));

            // Attack
            _coreMaterialAttack = new MaterialGroup();
            _coreMaterialAttack.Children.Add(new DiffuseMaterial(new SolidColorBrush(UtilityWPF.AlphaBlend(Colors.Red, UtilityWPF.AlphaBlend(Colors.Black, Colors.DimGray, .5), .15d))));
            _coreMaterialAttack.Children.Add(new SpecularMaterial(new SolidColorBrush(Color.FromArgb(255, 255, 128, 128)), 100d));

            _lightAttack          = new PointLight();
            _lightAttack.Color    = Color.FromArgb(255, 96, 0, 0);
            _lightAttack.Position = new Point3D(0, 0, 0);
            _lightAttack.Range    = _radius * 3;

            // Geometry Model
            _coreGeometry              = new GeometryModel3D();
            _coreGeometry.Material     = _coreMaterialNeutral;
            _coreGeometry.BackMaterial = _coreMaterialNeutral;
            _coreGeometry.Geometry     = UtilityWPF.GetSphere_LatLon(5, _radius * .4, _radius * .4, _radius * .4);
            _coreGeometry.Transform    = new TranslateTransform3D(0, 0, 0);

            // Model Visual
            _core         = new ModelVisual3D();
            _core.Content = _coreGeometry;

            //NOTE: model.Transform is set to the physics body's transform every frame

            // Add to the viewport
            _viewport.Children.Add(_core);

            #endregion

            #endregion

            #region WPF Model

            // Material
            //NOTE:  There seems to be an issue with drawing objects inside a semitransparent object - I think they have to be added in a certain order or something
            Brush skinBrush = new SolidColorBrush(Color.FromArgb(25, 255, 255, 255));  // making the skin semitransparent, so you can see the components inside

            material = new MaterialGroup();
            material.Children.Add(new DiffuseMaterial(skinBrush));
            material.Children.Add(new SpecularMaterial(Brushes.White, 75d));     // more reflective (and white light)

            MaterialGroup backMaterial = new MaterialGroup();
            backMaterial.Children.Add(new DiffuseMaterial(skinBrush));
            backMaterial.Children.Add(new SpecularMaterial(new SolidColorBrush(Color.FromArgb(255, 20, 20, 20)), 10d));       // dark light, and not very reflective

            // Geometry Model
            geometry              = new GeometryModel3D();
            geometry.Material     = material;
            geometry.BackMaterial = backMaterial;
            geometry.Geometry     = UtilityWPF.GetSphere_LatLon(5, _radius, _radius, _radius);

            // Transform
            Transform3DGroup transform = new Transform3DGroup();                // rotate needs to be added before translate
            transform.Children.Add(new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(1, 0, 0), 0)));
            transform.Children.Add(new TranslateTransform3D(worldPosition.ToVector()));

            // Model Visual
            model           = new ModelVisual3D();
            model.Content   = geometry;
            model.Transform = transform;

            // Add to the viewport
            _viewport.Children.Add(model);

            #endregion
            #region Physics Body

            // Make a physics body that represents this shape
            this.PhysicsBody = new ConvexBody3D(world, model);

            this.PhysicsBody.Mass = Convert.ToSingle(this.Mass);

            this.PhysicsBody.LinearDamping = .01f;
            //this.PhysicsBody.AngularDamping = new Vector3D(.01f, .01f, .01f);
            //this.PhysicsBody.AngularDamping = new Vector3D(.01f, .01f, 100000f);		// this doesn't work.  probably to to cap the z back to zero, and any spin to zero
            this.PhysicsBody.AngularDamping = new Vector3D(10f, 10f, 10f);

            this.PhysicsBody.ApplyForce += new BodyForceEventHandler(Body_ApplyForce);
            //this.PhysicsBody.NewtonBody.ApplyForceAndTorque

            #endregion

            #region Exterior Extra Visuals

            // There is a bug in WPF where visuals added after a semitransparent one won't show inside.  So if you want to add exterior
            // bits, this would be the place

            #endregion

            _thruster.IsFiring = true;
        }
Exemple #23
0
        public void CreateStation(Map map, Point3D worldPosition)
        {
            //TODO:  Windows, lights

            _map           = map;
            _positionWorld = worldPosition;
            _visuals       = new List <ModelVisual3D>();

            MaterialGroup   material = null;
            GeometryModel3D geometry = null;
            Model3DGroup    models   = new Model3DGroup();

            #region Interior Visuals

            // These are visuals that will stay oriented to the ship, but don't count in collision calculations

            #region Hull - Torus

            // Material
            material = new MaterialGroup();
            material.Children.Add(new DiffuseMaterial(new SolidColorBrush(_hullColor)));
            material.Children.Add(new SpecularMaterial(Brushes.Silver, 75d));

            // Geometry Model
            geometry              = new GeometryModel3D();
            geometry.Material     = material;
            geometry.BackMaterial = material;
            geometry.Geometry     = UtilityWPF.GetTorus(30, 10, _radius * .15, _radius);

            // Model Group
            models.Children.Add(geometry);

            #endregion
            #region Hull - Spine

            // Material
            material = new MaterialGroup();
            material.Children.Add(new DiffuseMaterial(new SolidColorBrush(_hullColor)));
            material.Children.Add(new SpecularMaterial(Brushes.Silver, 75d));

            // Geometry Model
            geometry              = new GeometryModel3D();
            geometry.Material     = material;
            geometry.BackMaterial = material;
            geometry.Geometry     = UtilityWPF.GetCylinder_AlongX(20, _radius * .07, _radius * .66);
            Transform3DGroup spineTransform2 = new Transform3DGroup();
            spineTransform2.Children.Add(new TranslateTransform3D(_radius * .1, 0, 0));
            spineTransform2.Children.Add(new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(0, -1, 0), 90)));
            geometry.Transform = spineTransform2;

            // Model Group
            models.Children.Add(geometry);

            #endregion
            #region Hull - Spokes

            for (int cntr = 0; cntr < 3; cntr++)
            {
                // Material
                material = new MaterialGroup();
                material.Children.Add(new DiffuseMaterial(new SolidColorBrush(_hullColor)));
                material.Children.Add(new SpecularMaterial(Brushes.Silver, 75d));

                // Geometry Model
                geometry              = new GeometryModel3D();
                geometry.Material     = material;
                geometry.BackMaterial = material;
                geometry.Geometry     = UtilityWPF.GetCylinder_AlongX(20, _radius * .05, _radius * .9);
                Transform3DGroup spokeTransform = new Transform3DGroup();
                spokeTransform.Children.Add(new TranslateTransform3D(_radius * .45, 0, 0));     // the cylinder is built along the x axis, but is centered halfway
                spokeTransform.Children.Add(new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(0, 0, 1), cntr * 120d)));
                geometry.Transform = spokeTransform;

                // Model Group
                models.Children.Add(geometry);
            }

            #endregion
            #region Hull - Top inner

            // Material
            material = new MaterialGroup();
            material.Children.Add(new DiffuseMaterial(new SolidColorBrush(UtilityWPF.AlphaBlend(Colors.White, _hullColor, .25d))));
            material.Children.Add(new SpecularMaterial(Brushes.Silver, 75d));

            // Geometry Model
            geometry              = new GeometryModel3D();
            geometry.Material     = material;
            geometry.BackMaterial = material;
            geometry.Geometry     = UtilityWPF.GetCylinder_AlongX(20, _radius * .11, _radius * .01);
            Transform3DGroup spokeTransform2 = new Transform3DGroup();
            spokeTransform2.Children.Add(new TranslateTransform3D((_radius * .51) - .5, 0, 0));     // the cylinder is built along the x axis, but is centered halfway
            spokeTransform2.Children.Add(new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(0, -1, 0), 90d)));
            geometry.Transform = spokeTransform2;

            // Model Group
            models.Children.Add(geometry);

            #endregion
            #region Hull - Top outer

            //TODO: The two cylinders cause flicker, come up with the definition of a ring

            // Material
            material = new MaterialGroup();
            material.Children.Add(new DiffuseMaterial(new SolidColorBrush(UtilityWPF.AlphaBlend(Colors.Black, _hullColor, .25d))));
            material.Children.Add(new SpecularMaterial(Brushes.Silver, 75d));

            // Geometry Model
            geometry              = new GeometryModel3D();
            geometry.Material     = material;
            geometry.BackMaterial = material;
            geometry.Geometry     = UtilityWPF.GetCylinder_AlongX(20, _radius * .12, _radius * .0095);
            Transform3DGroup spokeTransform3 = new Transform3DGroup();
            spokeTransform3.Children.Add(new TranslateTransform3D((_radius * .5) - .5, 0, 0));     // the cylinder is built along the x axis, but is centered halfway
            spokeTransform3.Children.Add(new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(0, -1, 0), 90d)));
            geometry.Transform = spokeTransform3;

            // Model Group
            models.Children.Add(geometry);

            #endregion

            #endregion

            #region Glass

            // Material
            //NOTE:  There is an issue with drawing objects inside a semitransparent object - they have to be added in order (so stuff added after a semitransparent won't be visible behind it)
            //Brush skinBrush = new SolidColorBrush(Color.FromArgb(25, 190, 240, 240));  // making the skin semitransparent, so you can see the components inside
            Brush skinBrush = new SolidColorBrush(Color.FromArgb(25, 220, 240, 240));  // making the skin semitransparent, so you can see the components inside

            material = new MaterialGroup();
            material.Children.Add(new DiffuseMaterial(skinBrush));
            material.Children.Add(new SpecularMaterial(Brushes.White, 85d));     // more reflective (and white light)

            MaterialGroup backMaterial = new MaterialGroup();
            backMaterial.Children.Add(new DiffuseMaterial(skinBrush));
            backMaterial.Children.Add(new SpecularMaterial(new SolidColorBrush(Color.FromArgb(255, 20, 20, 20)), 10d));       // dark light, and not very reflective

            // Geometry Model
            geometry              = new GeometryModel3D();
            geometry.Material     = material;
            geometry.BackMaterial = backMaterial;
            geometry.Geometry     = UtilityWPF.GetSphere_LatLon(6, _radius * 1, _radius * 1, _radius * .25);

            // Model Group
            models.Children.Add(geometry);

            #endregion

            #region Exterior Visuals

            // There is a bug in WPF where visuals added after a semitransparent one won't show inside.  So if you want to add exterior
            // bits that aren't visible inside, this would be the place

            #endregion

            _mainTransform = new Transform3DGroup();
            _mainTransform.Children.Add(new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(1, 0, 0), 0)));
            _mainTransform.Children.Add(new TranslateTransform3D(worldPosition.ToVector()));

            // Model Visual
            ModelVisual3D model = new ModelVisual3D();      // this is the expensive one.  make as few of these as I can get away with
            model.Content   = models;
            model.Transform = _mainTransform;

            // Add to my list
            _visuals.Add(model);
            _map.Viewport.Children.Add(model);
            _map.AddItem(this);
        }
Exemple #24
0
        /// <summary>
        /// This returns a visual of a graph that can be added to a canvas
        /// </summary>
        public static IEnumerable <UIElement> GetGradientGraph(double width, double height, GradientEntry[] gradient, Color fill, Color stroke)
        {
            if (gradient == null || gradient.Length <= 1)       // need at least two for a gradient
            {
                return(new UIElement[0]);
            }
            else if (width.IsNearZero() || height.IsNearZero())
            {
                return(new UIElement[0]);
            }

            List <UIElement> retVal = new List <UIElement>();

            double maxPercent = gradient.Max(o => o.Percent);

            if (maxPercent > 1)
            {
                #region 100% line

                // Draw a dashed line at 1 (showing the 100% mark)
                Color color100 = UtilityWPF.AlphaBlend(UtilityWPF.AlphaBlend(stroke, Colors.Gray, .85), Colors.Transparent, .66);

                double y100 = ((maxPercent - 1) / maxPercent) * height;

                Line line100 = new Line()
                {
                    Stroke          = new SolidColorBrush(color100),
                    StrokeThickness = 1,
                    StrokeDashArray = new DoubleCollection(new[] { 4d, 2d }),
                    X1 = 0,
                    X2 = width,
                    Y1 = y100,
                    Y2 = y100,
                };

                retVal.Add(line100);

                #endregion
            }

            if (maxPercent < 1)
            {
                // Do this so the graph is to scale (doesn't always go to the top)
                maxPercent = 1;
            }

            double lastGradX = gradient[gradient.Length - 1].Distance;
            if (!Math1D.IsNearZero(lastGradX) && lastGradX > 0)
            {
                Polyline polyLine = new Polyline();
                Polygon  polyFill = new Polygon();

                polyLine.Stroke          = new SolidColorBrush(stroke);
                polyLine.StrokeThickness = 2;

                polyFill.Fill = new SolidColorBrush(fill);

                //NOTE: gradient must be sorted on Item1
                double xScale = width / lastGradX;

                for (int cntr = 0; cntr < gradient.Length; cntr++)
                {
                    double x = gradient[cntr].Distance * xScale;
                    double y = ((maxPercent - gradient[cntr].Percent) / maxPercent) * height;

                    polyLine.Points.Add(new Point(x, y));
                    polyFill.Points.Add(new Point(x, y));
                }

                // Circle back fill to make a polygon
                polyFill.Points.Add(new Point(polyFill.Points[polyFill.Points.Count - 1].X, height));
                polyFill.Points.Add(new Point(polyFill.Points[0].X, height));

                retVal.Add(polyFill);
                retVal.Add(polyLine);
            }

            return(retVal);
        }
Exemple #25
0
        private static void DrawFieldSprtDoIt(byte[] pixels, double[] ink, bool[] blocked, int size, byte[] colorZFront, byte[] colorZBack, AxisFor pixelX, AxisFor pixelY, AxisFor pixelZ)
        {
            List <Mapping_2D_1D> flattened = new List <Mapping_2D_1D>();

            // Setup the pixel array
            //for (int y2D = pixelY.Start; pixelY.IsPos ? y2D <= pixelY.Stop : y2D >= pixelY.Stop; y2D += pixelY.Increment)
            foreach (int y2D in pixelY.Iterate())
            {
                int offsetY = pixelY.GetValueForOffset(y2D) * size;

                //for (int x2D = pixelX.Start; pixelX.IsPos ? x2D <= pixelX.Stop : x2D >= pixelX.Stop; x2D += pixelX.Increment)
                foreach (int x2D in pixelX.Iterate())
                {
                    int offset = offsetY + pixelX.GetValueForOffset(x2D);

                    flattened.Add(new Mapping_2D_1D(x2D, y2D, offset));
                }
            }

            // Each pixel of the output bitmap can be added up independently, so employ some threading
            flattened.AsParallel().ForAll(o =>
            {
                //TODO: Color is 6.5 times slower than byte array
                List <byte[]> colorColumn = new List <byte[]>();

                for (int z2D = pixelZ.Start; pixelZ.IsPos?z2D <= pixelZ.Stop : z2D >= pixelZ.Stop; z2D += pixelZ.Increment)
                {
                    int x = -1, y = -1, z = -1;
                    pixelX.Set3DIndex(ref x, ref y, ref z, o.X);
                    pixelY.Set3DIndex(ref x, ref y, ref z, o.Y);
                    pixelZ.Set3DIndex(ref x, ref y, ref z, z2D);

                    int index = FluidField3D.Get1DIndex(x, y, z, size);
                    if (blocked[index])
                    {
                        // Blocked cells are all white, so save the overlay method a bit of work, and throw out everything behind this
                        colorColumn.Clear();
                        colorColumn.Add(new byte[] { 255, 255, 255, 255 });
                        continue;
                    }

                    double inkCell = ink[index];

                    if (Math1D.IsNearZero(inkCell))
                    {
                        continue;
                    }

                    byte[] depthColor = UtilityWPF.AlphaBlend(colorZBack, colorZFront, UtilityCore.GetScaledValue_Capped(0, 1, 0, size - 1, z));

                    int alpha = Convert.ToInt32(Math.Round(inkCell * 255));
                    if (alpha < 0)
                    {
                        alpha = 0;
                    }
                    else if (alpha > 255)
                    {
                        alpha = 255;
                    }

                    colorColumn.Add(new byte[] { Convert.ToByte(alpha), depthColor[1], depthColor[2], depthColor[3] });
                }

                byte[] color = colorColumn.Count > 0 ? UtilityWPF.OverlayColors(colorColumn) : new byte[] { 0, 0, 0, 0 };

                pixels[o.Offset1D * 4 + 0] = color[3];       // Blue
                pixels[o.Offset1D * 4 + 1] = color[2];       // Green
                pixels[o.Offset1D * 4 + 2] = color[1];       // Red
                pixels[o.Offset1D * 4 + 3] = color[0];       // Alpha
            });
        }
Exemple #26
0
        /// <summary>
        /// Set the properties, then call create
        /// NOTE:  This adds itself to the viewport and world.  In the future, that should be handled by the caller
        /// </summary>
        public void CreateShip(MaterialManager materialManager, SharedVisuals sharedVisuals, Map map, ProgressBarGame progressBarCargo, ProgressBarGame progressBarFuel)
        {
            const double THRUSTLINELENGTH       = .5d;
            const double THRUSTLINELENGTH_EXTRA = .75d;
            const double THRUSTLINELENGTH_TURN  = .3;

            _sharedVisuals    = sharedVisuals;
            _map              = map;
            _progressBarCargo = progressBarCargo;
            _progressBarFuel  = progressBarFuel;

            #region Thrusters

            // These need to be definded before the visuals are created
            double radians = Math1D.DegreesToRadians(225);
            _thrusterOffset_BottomLeft = new Vector3D(this.RadiusX * Math.Cos(radians), this.RadiusY * Math.Sin(radians), 0);
            radians = Math1D.DegreesToRadians(135);
            _thrusterOffset_TopLeft = new Vector3D(this.RadiusX * Math.Cos(radians), this.RadiusY * Math.Sin(radians), 0);

            radians = Math1D.DegreesToRadians(315);
            _thrusterOffset_BottomRight = new Vector3D(this.RadiusX * Math.Cos(radians), this.RadiusY * Math.Sin(radians), 0);
            radians = Math1D.DegreesToRadians(45);
            _thrusterOffset_TopRight = new Vector3D(this.RadiusX * Math.Cos(radians), this.RadiusY * Math.Sin(radians), 0);

            _thrustForce = 100d;
            _torqueballLeftRightThrusterForce = -10d;

            #region Define ThrustLines

            //NOTE: The ThrustLine class will add/remove visuals directly from the viewport.  There's no need for the map to get involved

            // The reference to the fuel tank will be made when I create the tank

            ThrustLine thrustLine;

            // Up
            _thrustLines.Add(Key.Up, new List <ThrustLine>());

            thrustLine = new ThrustLine(_map.Viewport, _sharedVisuals, new Vector3D(0, 1, 0) * _thrustForce, _thrusterOffset_BottomRight);
            thrustLine.LineMaxLength = THRUSTLINELENGTH;
            _thrustLines[Key.Up].Add(thrustLine);

            thrustLine = new ThrustLine(_map.Viewport, _sharedVisuals, new Vector3D(0, 1, 0) * _thrustForce, _thrusterOffset_BottomLeft);
            thrustLine.LineMaxLength = THRUSTLINELENGTH;
            _thrustLines[Key.Up].Add(thrustLine);

            // W
            _thrustLines.Add(Key.W, new List <ThrustLine>());

            thrustLine = new ThrustLine(_map.Viewport, _sharedVisuals, new Vector3D(0, 1, 0) * (_thrustForce * 2d), _thrusterOffset_BottomRight);
            thrustLine.LineMaxLength = THRUSTLINELENGTH_EXTRA;
            _thrustLines[Key.W].Add(thrustLine);

            thrustLine = new ThrustLine(_map.Viewport, _sharedVisuals, new Vector3D(0, 1, 0) * (_thrustForce * 2d), _thrusterOffset_BottomLeft);
            thrustLine.LineMaxLength = THRUSTLINELENGTH_EXTRA;
            _thrustLines[Key.W].Add(thrustLine);

            // Down
            _thrustLines.Add(Key.Down, new List <ThrustLine>());

            thrustLine = new ThrustLine(_map.Viewport, _sharedVisuals, new Vector3D(0, -1, 0) * _thrustForce, _thrusterOffset_TopRight);
            thrustLine.LineMaxLength = THRUSTLINELENGTH;
            _thrustLines[Key.Down].Add(thrustLine);

            thrustLine = new ThrustLine(_map.Viewport, _sharedVisuals, new Vector3D(0, -1, 0) * _thrustForce, _thrusterOffset_TopLeft);
            thrustLine.LineMaxLength = THRUSTLINELENGTH;
            _thrustLines[Key.Down].Add(thrustLine);

            // S
            _thrustLines.Add(Key.S, new List <ThrustLine>());

            thrustLine = new ThrustLine(_map.Viewport, _sharedVisuals, new Vector3D(0, -1, 0) * (_thrustForce * 2d), _thrusterOffset_TopRight);
            thrustLine.LineMaxLength = THRUSTLINELENGTH_EXTRA;
            _thrustLines[Key.S].Add(thrustLine);

            thrustLine = new ThrustLine(_map.Viewport, _sharedVisuals, new Vector3D(0, -1, 0) * (_thrustForce * 2d), _thrusterOffset_TopLeft);
            thrustLine.LineMaxLength = THRUSTLINELENGTH_EXTRA;
            _thrustLines[Key.S].Add(thrustLine);

            // Left
            _thrustLines.Add(Key.Left, new List <ThrustLine>());

            thrustLine = new ThrustLine(_map.Viewport, _sharedVisuals, new Vector3D(0, -1, 0) * _torqueballLeftRightThrusterForce, _thrusterOffset_BottomRight);
            thrustLine.LineMaxLength = THRUSTLINELENGTH_TURN;
            _thrustLines[Key.Left].Add(thrustLine);

            thrustLine = new ThrustLine(_map.Viewport, _sharedVisuals, new Vector3D(0, 1, 0) * _torqueballLeftRightThrusterForce, _thrusterOffset_TopLeft);
            thrustLine.LineMaxLength = THRUSTLINELENGTH_TURN;
            _thrustLines[Key.Left].Add(thrustLine);

            // Right
            _thrustLines.Add(Key.Right, new List <ThrustLine>());

            thrustLine = new ThrustLine(_map.Viewport, _sharedVisuals, new Vector3D(0, 1, 0) * _torqueballLeftRightThrusterForce, _thrusterOffset_TopRight);
            thrustLine.LineMaxLength = THRUSTLINELENGTH_TURN;
            _thrustLines[Key.Right].Add(thrustLine);

            thrustLine = new ThrustLine(_map.Viewport, _sharedVisuals, new Vector3D(0, -1, 0) * _torqueballLeftRightThrusterForce, _thrusterOffset_BottomLeft);
            thrustLine.LineMaxLength = THRUSTLINELENGTH_TURN;
            _thrustLines[Key.Right].Add(thrustLine);

            // A
            _thrustLines.Add(Key.A, new List <ThrustLine>());

            thrustLine = new ThrustLine(_map.Viewport, _sharedVisuals, new Vector3D(-1, 0, 0) * _thrustForce, _thrusterOffset_TopRight);
            thrustLine.LineMaxLength = THRUSTLINELENGTH;
            _thrustLines[Key.A].Add(thrustLine);

            thrustLine = new ThrustLine(_map.Viewport, _sharedVisuals, new Vector3D(-1, 0, 0) * _thrustForce, _thrusterOffset_BottomRight);
            thrustLine.LineMaxLength = THRUSTLINELENGTH;
            _thrustLines[Key.A].Add(thrustLine);

            // D
            _thrustLines.Add(Key.D, new List <ThrustLine>());

            thrustLine = new ThrustLine(_map.Viewport, _sharedVisuals, new Vector3D(1, 0, 0) * _thrustForce, _thrusterOffset_TopLeft);
            thrustLine.LineMaxLength = THRUSTLINELENGTH;
            _thrustLines[Key.D].Add(thrustLine);

            thrustLine = new ThrustLine(_map.Viewport, _sharedVisuals, new Vector3D(1, 0, 0) * _thrustForce, _thrusterOffset_BottomLeft);
            thrustLine.LineMaxLength = THRUSTLINELENGTH;
            _thrustLines[Key.D].Add(thrustLine);

            #endregion

            #endregion

            MaterialGroup   material = null;
            GeometryModel3D geometry = null;
            Model3DGroup    models   = new Model3DGroup();
            ModelVisual3D   model    = null;

            #region Interior Extra Visuals

            // These are visuals that will stay oriented to the ship, but don't count in collision calculations

            #region Thrusters

            // These are the little balls, not the thrust lines

            double thrusterLocScale = 1d;

            models.Children.Add(GetThrusterVisual(_thrusterOffset_BottomLeft * thrusterLocScale));
            models.Children.Add(GetThrusterVisual(_thrusterOffset_BottomRight * thrusterLocScale));
            models.Children.Add(GetThrusterVisual(_thrusterOffset_TopLeft * thrusterLocScale));
            models.Children.Add(GetThrusterVisual(_thrusterOffset_TopRight * thrusterLocScale));

            #endregion
            #region Cargo Bay

            //TODO:  Make a visual for this (probably pretty cube like)

            _cargoBay = new CargoBay(_cargoBayMass, _cargoBayVolume);

            _progressBarCargo.Minimum = 0d;
            _progressBarCargo.Maximum = _cargoBay.MaxVolume;
            _progressBarCargo.Value   = 0d;

            #endregion
            #region Fuel Tank

            //TODO:  This visual should be a pill

            _fuelTank                 = new FuelTank();
            _fuelTank.DryMass         = _fuelTankMass;
            _fuelTank.QuantityMax     = _fuelTankCapacity;
            _fuelTank.QuantityCurrent = _fuelTank.QuantityMax;          // a full tank with the purchace of a new ship!!!
            _fuelTank.FuelDensity     = _fuelDensity;

            _progressBarFuel.Minimum = 0d;
            _progressBarFuel.Maximum = _fuelTank.QuantityMax;
            _progressBarFuel.Value   = _fuelTank.QuantityCurrent;

            // Link to the thrusters
            foreach (List <ThrustLine> thrustLines in _thrustLines.Values)
            {
                foreach (ThrustLine thrustLine1 in thrustLines)
                {
                    thrustLine1.FuelToThrustRatio = _fuelThrustRatio;
                    thrustLine1.FuelTank          = _fuelTank;
                }
            }

            #endregion

            #region Core

            // This just looks stupid.  The idea is that you would see the various components (which would also be point masses).  But until
            // the user can modify their ship, it's just an arbitrary ellipse that is ugly

            //// Material
            //material = new MaterialGroup();
            //material.Children.Add(new DiffuseMaterial(Brushes.DimGray));
            //material.Children.Add(new SpecularMaterial(Brushes.DimGray, 100d));

            //// Geometry Model
            //geometry = new GeometryModel3D();
            //geometry.Material = material;
            //geometry.BackMaterial = material;
            //geometry.Geometry = UtilityWPF.GetSphere(5, .45, .25, .05);
            //geometry.Transform = new TranslateTransform3D(0, this.RadiusY * -.25, 0);

            //// Model Visual
            //model = new ModelVisual3D();
            //model.Content = geometry;

            ////NOTE: model.Transform is set to the physics body's transform every frame

            //// Add to the viewport
            //_viewport.Children.Add(model);

            //_visuals.Add(model);

            #endregion

            // Make a model visual for what I have so far
            model         = new ModelVisual3D(); // this is the expensive one, so as few of these should be made as possible
            model.Content = models;

            _visuals.Add(model);
            _map.Viewport.Children.Add(model);

            #endregion

            #region WPF Collision Model

            // Material
            //NOTE:  There seems to be an issue with drawing objects inside a semitransparent object - I think they have to be added in a certain order or something
            //Brush skinBrush = new SolidColorBrush(Color.FromArgb(50, _hullColor.R, _hullColor.G, _hullColor.B));  // making the skin semitransparent, so you can see the components inside
            Brush skinBrush = new SolidColorBrush(_hullColor);  // decided to make it opaque, since I'm not showing anything inside

            material = new MaterialGroup();
            material.Children.Add(new DiffuseMaterial(skinBrush));
            material.Children.Add(new SpecularMaterial(Brushes.White, 75d));     // more reflective (and white light)

            MaterialGroup backMaterial = new MaterialGroup();
            backMaterial.Children.Add(new DiffuseMaterial(skinBrush));
            backMaterial.Children.Add(new SpecularMaterial(new SolidColorBrush(Color.FromArgb(255, 20, 20, 20)), 10d));       // dark light, and not very reflective

            // Geometry Model
            geometry              = new GeometryModel3D();
            geometry.Material     = material;
            geometry.BackMaterial = backMaterial;
            geometry.Geometry     = UtilityWPF.GetSphere_LatLon(5, this.RadiusX, this.RadiusY, this.RadiusZ);

            // Transform
            Transform3DGroup transform = new Transform3DGroup();                // rotate needs to be added before translate
            transform.Children.Add(new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(1, 0, 0), 0)));
            transform.Children.Add(new TranslateTransform3D(new Vector3D(0, 0, 0)));

            // Model Visual
            model           = new ModelVisual3D();
            model.Content   = geometry;
            model.Transform = transform;

            _physicsModel = model;    // remember this, so I don't set its transform
            _visuals.Add(model);

            // Add to the viewport (the physics body constructor requires it to be added)
            _map.Viewport.Children.Add(model);

            #endregion
            #region Physics Body

            // Make a physics body that represents this shape
            _physicsBody = new ConvexBody3D(_map.World, model);

            _physicsBody.MaterialGroupID = materialManager.ShipMaterialID;

            _physicsBody.NewtonBody.UserData = this;

            _physicsBody.Mass = Convert.ToSingle(this.TotalMass);

            _physicsBody.LinearDamping = .01f;
            //_physicsBody.AngularDamping = new Vector3D(.01f, .01f, .01f);
            //_physicsBody.AngularDamping = new Vector3D(10f, 10f, 10f);
            _physicsBody.AngularDamping = new Vector3D(1f, 1f, 1f);

            _physicsBody.ApplyForce += new BodyForceEventHandler(Body_ApplyForce);

            #endregion

            #region Exterior Extra Visuals

            // There is a bug in WPF where visuals added after a semitransparent one won't show inside.  The cockpit looks stupid when you can see
            // it inside the skin

            #region Cockpit

            // Material
            material = new MaterialGroup();
            material.Children.Add(new DiffuseMaterial(new SolidColorBrush(UtilityWPF.AlphaBlend(Colors.Teal, Colors.DimGray, .2d))));
            material.Children.Add(new SpecularMaterial(Brushes.White, 100d));

            // Geometry Model
            geometry              = new GeometryModel3D();
            geometry.Material     = material;
            geometry.BackMaterial = material;
            //geometry.Geometry = UtilityWPF.GetSphere(3, .4, .2, .3);
            geometry.Geometry  = UtilityWPF.GetSphere_LatLon(3, .45, .25, .25);
            geometry.Transform = new TranslateTransform3D(0, this.RadiusY * .5, 0);

            // Model Visual
            model         = new ModelVisual3D();
            model.Content = geometry;

            // Add to the viewport
            _visuals.Add(model);
            _map.Viewport.Children.Add(model);

            #endregion
            #region Headlight

            SpotLight spotLight = new SpotLight();
            //spotLight.Color = Color.FromArgb(255, 50, 170, 50);
            spotLight.Color          = UtilityWPF.AlphaBlend(Colors.White, _hullColor, .25d);
            spotLight.Direction      = new Vector3D(0, 1, 0);
            spotLight.OuterConeAngle = 25;
            spotLight.InnerConeAngle = 5;
            //spotLight.LinearAttenuation = .1;
            spotLight.QuadraticAttenuation = .0001;
            spotLight.Range = 1000;

            model         = new ModelVisual3D();
            model.Content = spotLight;

            _visuals.Add(model);
            _map.Viewport.Children.Add(model);

            #endregion

            #endregion

            // Add to the map
            _map.AddItem(this);
        }
Exemple #27
0
        private async void grdDisplay_Loaded(object sender, RoutedEventArgs e)
        {
            try
            {
                SOMFieldStats[] columnStats = await Task.Run(() => GetColumnStats(_queryResults));

                DataTable table = new DataTable();

                #region column definitions

                for (int cntr = 0; cntr < _queryResults.ColumnNames.Length; cntr++)
                {
                    DataColumn column;

                    switch (columnStats[cntr].FieldType)
                    {
                    case SOMFieldType.Integer:
                        column = new DataColumn(_queryResults.ColumnNames[cntr], typeof(long));
                        break;

                    case SOMFieldType.FloatingPoint:
                        column = new DataColumn(_queryResults.ColumnNames[cntr], typeof(decimal));
                        break;

                    case SOMFieldType.DateTime:
                        column = new DataColumn(_queryResults.ColumnNames[cntr], typeof(DateTime));
                        break;

                    case SOMFieldType.AlphaNumeric:
                    case SOMFieldType.AnyText:
                    default:
                        column = new DataColumn(_queryResults.ColumnNames[cntr], typeof(string));
                        break;
                    }

                    table.Columns.Add(column);
                }

                #endregion

                #region rows

                var rows = await Task.Run(() => GetMatchingRows(_columns.Columns, _queryResults, _somResult, _nodeIndex));

                foreach (var row in rows)
                {
                    DataRow datarow = table.NewRow();

                    for (int cntr = 0; cntr < row.Row.Length; cntr++)
                    {
                        datarow[cntr] = CastItem(row.Row[cntr], columnStats[cntr].FieldType);
                    }

                    table.Rows.Add(datarow);
                }

                #endregion

                var grid = sender as DataGrid;
                grid.AutoGenerateColumns = true;
                grid.ItemsSource         = table.DefaultView;

                #region misc

                this.Title = string.Format("Node Rows - {0}", rows.Length.ToString("N0"));

                SolidColorBrush backBrush = this.Background as SolidColorBrush;
                if (backBrush != null)
                {
                    grdDisplay.RowBackground = new SolidColorBrush(UtilityWPF.AlphaBlend(Colors.White, backBrush.Color, .9));
                    grdDisplay.Background    = new SolidColorBrush(UtilityWPF.AlphaBlend(Colors.White, backBrush.Color, .5));
                }

                #endregion
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), this.Title, MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Exemple #28
0
        // Second design
        private static Model3DGroup GetModel_Second(WeaponAxeDNA dna, WeaponAxeDNA finalDNA, WeaponMaterialCache materials, bool hasBeard)
        {
            Model3DGroup retVal = new Model3DGroup();
            var          from   = dna.KeyValues;
            var          to     = finalDNA.KeyValues;

            // Define the curves
            AxeSecondProps arg = GetModel_Second_Props(from, to, hasBeard);

            BezierSegment3D[][] segmentSets = GetModel_Second_Curves(arg);

            //TODO: Use WeaponMaterialCache
            MaterialGroup materialMiddle = new MaterialGroup();

            materialMiddle.Children.Add(new DiffuseMaterial(new SolidColorBrush(Colors.DimGray)));
            Color derivedColor = UtilityWPF.AlphaBlend(Colors.DimGray, Colors.White, .8d);

            materialMiddle.Children.Add(new SpecularMaterial(new SolidColorBrush(Color.FromArgb(128, derivedColor.R, derivedColor.G, derivedColor.B)), 2d));

            MaterialGroup materialEdge = new MaterialGroup();

            materialEdge.Children.Add(new DiffuseMaterial(new SolidColorBrush(Colors.GhostWhite)));
            materialEdge.Children.Add(new SpecularMaterial(new SolidColorBrush(UtilityWPF.AlphaBlend(Colors.GhostWhite, Colors.White, .5d)), 5d));

            #region Axe Blade (right)

            Model3D model = GetModel_Second_Axe(segmentSets, materialMiddle, materialEdge);

            double scale = dna.SizeSingle / (((arg.EndBL_2 ?? arg.EndBL_1).Y - arg.EndTL.Y) * 2);

            Transform3DGroup transform = new Transform3DGroup();
            transform.Children.Add(new TranslateTransform3D(-arg.EndTL.X, 0, 0));
            transform.Children.Add(new ScaleTransform3D(scale, scale, scale));

            model.Transform = transform;
            retVal.Children.Add(model);

            #endregion

            if (dna.Sides == WeaponAxeSides.Double)
            {
                #region Axe Blade (left)

                model = GetModel_Second_Axe(segmentSets, materialMiddle, materialEdge);

                transform = new Transform3DGroup();
                transform.Children.Add(new TranslateTransform3D(-arg.EndTL.X, 0, 0));
                transform.Children.Add(new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(0, 1, 0), 180)));
                transform.Children.Add(new ScaleTransform3D(scale, scale, scale));

                model.Transform = transform;

                retVal.Children.Add(model);

                #endregion
            }

            Point3D topLeft    = segmentSets[2][0].EndPoint0;
            Point3D bottomLeft = segmentSets[2][segmentSets[2].Length - 1].EndPoint1;
            double  z          = Math.Abs(segmentSets[0][0].EndPoint0.Z);

            if (dna.Sides == WeaponAxeSides.Single_BackSpike)
            {
                // Spike
                retVal.Children.Add(GetAxeSpike(z * .9, Math.Abs(topLeft.Y - bottomLeft.Y) * WeaponDNA.GetKeyValue("spikeLength", from, to, StaticRandom.NextDouble(.9, 1.4)), scale, -.2, materialMiddle, materialEdge));
            }

            if (dna.Sides != WeaponAxeSides.Double)     // double centerfilled is the only case that shouldn't have a collar
            {
                // Collar
                retVal.Children.Add(GetAxeCylinder(z * 1.33, Math.Abs(topLeft.Y - bottomLeft.Y) * 1.15, scale, -.2, materialMiddle));
            }

            return(retVal);
        }
Exemple #29
0
        public void CreateGuildLines()
        {
            const double SIZE = 50d;

            GuideLines = new ScreenSpaceLines3D(true);

            // Get a color based on the part type
            Color color;

            if (Part3D is AmmoBoxDesign)
            {
                color = WorldColors.AmmoBox_Color;
            }
            else if (Part3D is BeamGunDesign || Part3D is GrappleGunDesign || Part3D is ProjectileGunDesign)
            {
                color = UtilityWPF.AlphaBlend(Colors.White, WorldColors.GunBarrel_Color, .125d);                // shift it white, because it's too dark
            }
            else if (Part3D is BrainDesign || Part3D is BrainNEATDesign || Part3D is BrainRGBRecognizerDesign || Part3D is DirectionControllerRingDesign || Part3D is DirectionControllerSphereDesign)
            {
                color = UtilityWPF.AlphaBlend(Colors.Transparent, WorldColors.Brain_Color, .25d);
            }
            else if (Part3D is CargoBayDesign)
            {
                color = WorldColors.CargoBay_Color;
            }
            else if (Part3D is ConverterEnergyToAmmoDesign || Part3D is ConverterEnergyToFuelDesign || Part3D is ConverterEnergyToPlasmaDesign || Part3D is ConverterFuelToEnergyDesign || Part3D is ConverterMatterToAmmoDesign || Part3D is ConverterMatterToEnergyDesign || Part3D is ConverterMatterToFuelDesign || Part3D is ConverterRadiationToEnergyDesign || Part3D is ConverterMatterToPlasmaDesign)
            {
                color = UtilityWPF.AlphaBlend(Colors.White, WorldColors.ConverterBase_Color, .125d);
            }
            else if (Part3D is EnergyTankDesign)
            {
                color = WorldColors.EnergyTank_Color;
            }
            else if (Part3D is EyeDesign || Part3D is CameraColorRGBDesign || Part3D is CameraHardCodedDesign)
            {
                color = UtilityWPF.AlphaBlend(Colors.White, WorldColors.CameraBase_Color, .15d);
            }
            else if (Part3D is SensorCollisionDesign || Part3D is SensorFluidDesign || Part3D is SensorGravityDesign || Part3D is SensorInternalForceDesign || Part3D is SensorNetForceDesign || Part3D is SensorRadiationDesign || Part3D is SensorSpinDesign || Part3D is SensorTractorDesign || Part3D is SensorVelocityDesign || Part3D is SensorHomingDesign)
            {
                color = UtilityWPF.AlphaBlend(Colors.White, WorldColors.SensorBase_Color, .125d);
            }
            else if (Part3D is FuelTankDesign)
            {
                color = WorldColors.FuelTank_Color;
            }
            else if (Part3D is HangarBayDesign)
            {
                color = UtilityWPF.AlphaBlend(Colors.Transparent, WorldColors.HangarBay_Color, .25d);
            }
            else if (Part3D is SelfRepairDesign)
            {
                color = UtilityWPF.AlphaBlend(Colors.Transparent, WorldColors.SelfRepairBase_Color, .25d);
            }
            else if (Part3D is ShieldEnergyDesign || Part3D is ShieldKineticDesign || Part3D is ShieldTractorDesign)
            {
                color = UtilityWPF.AlphaBlend(Colors.Transparent, WorldColors.ShieldBase_Color, .125d);
            }
            else if (Part3D is ThrusterDesign)
            {
                color = WorldColors.Thruster_Color;
            }
            else if (Part3D is TractorBeamDesign)
            {
                color = WorldColors.TractorBeamBase_Color;
            }
            else if (Part3D is ImpulseEngineDesign)
            {
                color = UtilityWPF.AlphaBlend(Colors.White,
                                              UtilityWPF.AlphaBlend(WorldColors.ImpulseEngineGlowball_Color, WorldColors.ImpulseEngine_Color, .25d),
                                              .125d);
            }
            else if (Part3D is PlasmaTankDesign)
            {
                color = WorldColors.PlasmaTank_Color;
            }
            else if (Part3D is SwarmBayDesign)
            {
                color = WorldColors.SwarmBay_Color;
            }
            else
            {
                color = Colors.Black;
            }

            // Tone the color down a bit
            //color = UtilityWPF.AlphaBlend(color, _colors.Background, .9d);
            color = UtilityWPF.AlphaBlend(color, Colors.Transparent, .66d);

            GuideLines.Color = color;

            GuideLines.Thickness = .5d;
            GuideLines.AddLine(new Point3D(-SIZE, 0, 0), new Point3D(SIZE, 0, 0));
            GuideLines.AddLine(new Point3D(0, -SIZE, 0), new Point3D(0, SIZE, 0));
            GuideLines.AddLine(new Point3D(0, 0, -SIZE), new Point3D(0, 0, SIZE));

            GuideLines.Transform = new TranslateTransform3D(Part3D.Position.ToVector());
        }
Exemple #30
0
        public SpaceStation(Point3D position, World world, int materialID, Quaternion orientation)
        {
            //TODO:  Windows, lights

            MaterialGroup   material = null;
            GeometryModel3D geometry = null;
            Model3DGroup    models   = new Model3DGroup();

            // These are random, so pull them once
            Color            hullColor    = WorldColors.SpaceStationHull_Color;
            SpecularMaterial hullSpecular = WorldColors.SpaceStationHull_Specular;

            double radius = 8;

            this.Radius = radius * 1.25;                // this is the extremes of the force field
            double mass = 10000;

            #region Interior Visuals

            // These are visuals that will stay oriented to the ship, but don't count in collision calculations

            #region Hull - Torus

            // Material
            material = new MaterialGroup();
            material.Children.Add(new DiffuseMaterial(new SolidColorBrush(hullColor)));
            material.Children.Add(hullSpecular);

            // Geometry Model
            geometry              = new GeometryModel3D();
            geometry.Material     = material;
            geometry.BackMaterial = material;
            geometry.Geometry     = UtilityWPF.GetTorus(30, 10, radius * .15, radius);

            // Model Group
            models.Children.Add(geometry);

            #endregion
            #region Hull - Spine

            // Material
            material = new MaterialGroup();
            material.Children.Add(new DiffuseMaterial(new SolidColorBrush(hullColor)));
            material.Children.Add(hullSpecular);

            // Geometry Model
            geometry              = new GeometryModel3D();
            geometry.Material     = material;
            geometry.BackMaterial = material;
            geometry.Geometry     = UtilityWPF.GetCylinder_AlongX(20, radius * .075, radius * .66);
            Transform3DGroup spineTransform2 = new Transform3DGroup();
            spineTransform2.Children.Add(new TranslateTransform3D(radius * .1, 0, 0));
            spineTransform2.Children.Add(new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(0, -1, 0), 90)));
            geometry.Transform = spineTransform2;

            // Model Group
            models.Children.Add(geometry);

            #endregion
            #region Hull - Spokes

            for (int cntr = 0; cntr < 3; cntr++)
            {
                // Material
                material = new MaterialGroup();
                material.Children.Add(new DiffuseMaterial(new SolidColorBrush(hullColor)));
                material.Children.Add(hullSpecular);

                // Geometry Model
                geometry              = new GeometryModel3D();
                geometry.Material     = material;
                geometry.BackMaterial = material;
                geometry.Geometry     = UtilityWPF.GetCylinder_AlongX(20, radius * .05, radius * .9);
                Transform3DGroup spokeTransform = new Transform3DGroup();
                spokeTransform.Children.Add(new TranslateTransform3D(radius * .45, 0, 0));     // the cylinder is built along the y axis, but is centered halfway
                spokeTransform.Children.Add(new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(0, 0, 1), cntr * 120d)));
                geometry.Transform = spokeTransform;

                // Model Group
                models.Children.Add(geometry);
            }

            #endregion
            #region Hull - Top inner

            // Material
            material = new MaterialGroup();
            material.Children.Add(new DiffuseMaterial(new SolidColorBrush(UtilityWPF.AlphaBlend(Colors.White, hullColor, .25d))));
            material.Children.Add(hullSpecular);

            // Geometry Model
            geometry              = new GeometryModel3D();
            geometry.Material     = material;
            geometry.BackMaterial = material;
            geometry.Geometry     = UtilityWPF.GetCylinder_AlongX(20, radius * .11, radius * .01);
            Transform3DGroup spokeTransform2 = new Transform3DGroup();
            spokeTransform2.Children.Add(new TranslateTransform3D((radius * .51) - .5, 0, 0));     // the cylinder is built along the x axis, but is centered halfway
            spokeTransform2.Children.Add(new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(0, -1, 0), 90d)));
            geometry.Transform = spokeTransform2;

            // Model Group
            models.Children.Add(geometry);

            #endregion
            #region Hull - Top outer

            //TODO: The two cylinders cause flicker, come up with the definition of a ring (or do some texture mapping - if so, see if the texture can be vector graphics)

            // Material
            material = new MaterialGroup();
            material.Children.Add(new DiffuseMaterial(new SolidColorBrush(UtilityWPF.AlphaBlend(Colors.Black, hullColor, .25d))));
            material.Children.Add(hullSpecular);

            // Geometry Model
            geometry              = new GeometryModel3D();
            geometry.Material     = material;
            geometry.BackMaterial = material;
            geometry.Geometry     = UtilityWPF.GetCylinder_AlongX(20, radius * .12, radius * .0095);
            Transform3DGroup spokeTransform3 = new Transform3DGroup();
            spokeTransform3.Children.Add(new TranslateTransform3D((radius * .5) - .5, 0, 0));     // the cylinder is built along the y axis, but is centered halfway
            spokeTransform3.Children.Add(new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(0, -1, 0), 90d)));
            geometry.Transform = spokeTransform3;

            // Model Group
            models.Children.Add(geometry);

            #endregion

            #endregion

            #region Glass

            // Material
            //NOTE:  There is an issue with drawing objects inside a semitransparent object - they have to be added in order (so stuff added after a semitransparent won't be visible behind it)
            Brush skinBrush = new SolidColorBrush(WorldColors.SpaceStationGlass_Color);  // the skin is semitransparent, so you can see the components inside

            material = new MaterialGroup();
            material.Children.Add(new DiffuseMaterial(skinBrush));
            material.Children.Add(WorldColors.SpaceStationGlass_Specular_Front);     // more reflective (and white light)

            MaterialGroup backMaterial = new MaterialGroup();
            backMaterial.Children.Add(new DiffuseMaterial(skinBrush));
            backMaterial.Children.Add(WorldColors.SpaceStationGlass_Specular_Back);       // dark light, and not very reflective

            // Geometry Model
            geometry              = new GeometryModel3D();
            geometry.Material     = material;
            geometry.BackMaterial = backMaterial;
            geometry.Geometry     = UtilityWPF.GetSphere_LatLon(6, radius, radius, radius * .25);

            // Model Group
            models.Children.Add(geometry);

            #endregion

            #region Exterior Visuals

            // There is a bug in WPF where visuals added after a semitransparent one won't show inside.  So if you want to add exterior
            // bits that aren't visible inside, this would be the place

            #endregion

            #region Force Field

            Vector3D forceFieldSize = new Vector3D(radius * 1.25, radius * 1.25, radius * .75);

            // Material
            _forceField_DiffuseMaterial = new DiffuseMaterial(null);  //Brushes.Transparent);		// the momentarily brush will change when there is a collision
            _forceField_EmissiveFront   = new EmissiveMaterial(null); //Brushes.Transparent);
            _forceField_EmissiveRear    = new EmissiveMaterial(null); //Brushes.Transparent);

            material = new MaterialGroup();
            material.Children.Add(_forceField_DiffuseMaterial);
            material.Children.Add(_forceField_EmissiveFront);

            backMaterial = new MaterialGroup();
            backMaterial.Children.Add(_forceField_DiffuseMaterial);
            backMaterial.Children.Add(_forceField_EmissiveRear);

            // Geometry Model
            geometry              = new GeometryModel3D();
            geometry.Material     = material;
            geometry.BackMaterial = backMaterial;
            geometry.Geometry     = UtilityWPF.GetSphere_LatLon(6, forceFieldSize.X, forceFieldSize.Y, forceFieldSize.Z);

            // Model Group
            models.Children.Add(geometry);

            #endregion

            this.Model = models;

            // Model Visual
            ModelVisual3D model = new ModelVisual3D();        // this is the expensive one, so as few of these should be made as possible
            model.Content = models;

            #region Physics Body

            Transform3DGroup transform = new Transform3DGroup();
            transform.Children.Add(new RotateTransform3D(new QuaternionRotation3D(orientation)));
            transform.Children.Add(new TranslateTransform3D(position.ToVector()));

            using (CollisionHull hull = CollisionHull.CreateSphere(world, 0, forceFieldSize, null))
            {
                this.PhysicsBody = new Body(hull, transform.Value, mass, new Visual3D[] { model });
                this.PhysicsBody.MaterialGroupID = materialID;
                this.PhysicsBody.LinearDamping   = .01f;
                this.PhysicsBody.AngularDamping  = new Vector3D(.001f, .001f, .001f);
            }

            #endregion

            this.CreationTime = DateTime.UtcNow;
        }