public ThrustLine(Viewport3D viewport, SharedVisuals sharedVisuals, Vector3D forceDirection, Vector3D localOffset)
        {
            this.Viewport = viewport;
            _forceDirection = forceDirection;
            _forceStrength = forceDirection.Length;       // this way they don't have to set this if they don't want
            this.BodyOffset = new TranslateTransform3D(localOffset);       // just setting it to something so it's not null

            #region Create Visual

            // I'll create the visual, but won't add it until they fire the thruster

            // Material
            MaterialGroup materials = new MaterialGroup();
            materials.Children.Add(new DiffuseMaterial(Brushes.Coral));
            materials.Children.Add(new SpecularMaterial(Brushes.Gold, 100d));

            // Geometry Model
            // Create a skinny 3D rectangle along the x axis
            GeometryModel3D geometry = new GeometryModel3D();
            geometry.Material = materials;
            geometry.BackMaterial = materials;
            geometry.Geometry = sharedVisuals.ThrustLineMesh;


            // Figure out how much to rotate the cube to be along the opposite of the force line.  I do the opposite, because
            // thruster flames shoot in the opposite direction that they're pushing
            Vector3D flameLine = forceDirection;
            flameLine.Negate();

            Vector3D axis;
            double radians;
            Math3D.GetRotation(out axis, out radians, new Vector3D(1, 0, 0), flameLine);

            if (radians == 0d)
            {
                _initialRotate = null;
            }
            else
            {
                _initialRotate = new RotateTransform3D(new AxisAngleRotation3D(axis, Math1D.RadiansToDegrees(radians)));
            }

            //// Transform
            //Transform3DGroup transform = new Transform3DGroup();		// rotate needs to be added before translate
            //transform.Children.Add(new RotateTransform3D(new AxisAngleRotation3D(axis, Math3D.RadiansToDegrees(radians))));
            //transform.Children.Add(new TranslateTransform3D(from));




            // Model Visual
            _model = new ModelVisual3D();
            _model.Content = geometry;
            _model.Transform = new TranslateTransform3D();        // I won't do anything with this right now

            #endregion
        }
Exemple #2
0
        public ThrustLine(Viewport3D viewport, SharedVisuals sharedVisuals, Vector3D forceDirection, Vector3D localOffset)
        {
            this.Viewport   = viewport;
            _forceDirection = forceDirection;
            _forceStrength  = forceDirection.Length;                 // this way they don't have to set this if they don't want
            this.BodyOffset = new TranslateTransform3D(localOffset); // just setting it to something so it's not null

            #region Create Visual

            // I'll create the visual, but won't add it until they fire the thruster

            // Material
            MaterialGroup materials = new MaterialGroup();
            materials.Children.Add(new DiffuseMaterial(Brushes.Coral));
            materials.Children.Add(new SpecularMaterial(Brushes.Gold, 100d));

            // Geometry Model
            // Create a skinny 3D rectangle along the x axis
            GeometryModel3D geometry = new GeometryModel3D();
            geometry.Material     = materials;
            geometry.BackMaterial = materials;
            geometry.Geometry     = sharedVisuals.ThrustLineMesh;


            // Figure out how much to rotate the cube to be along the opposite of the force line.  I do the opposite, because
            // thruster flames shoot in the opposite direction that they're pushing
            Vector3D flameLine = forceDirection;
            flameLine.Negate();

            Quaternion rotation = Math3D.GetRotation(new Vector3D(1, 0, 0), flameLine);

            if (rotation.IsIdentity)
            {
                _initialRotate = null;
            }
            else
            {
                _initialRotate = new RotateTransform3D(new QuaternionRotation3D(rotation));
            }

            //// Transform
            //Transform3DGroup transform = new Transform3DGroup();		// rotate needs to be added before translate
            //transform.Children.Add(new RotateTransform3D(new AxisAngleRotation3D(axis, Math3D.RadiansToDegrees(radians))));
            //transform.Children.Add(new TranslateTransform3D(from));



            // Model Visual
            _model           = new ModelVisual3D();
            _model.Content   = geometry;
            _model.Transform = new TranslateTransform3D();        // I won't do anything with this right now

            #endregion
        }
Exemple #3
0
        public Mineral(MineralType mineralType, Point3D position, double volumeInCubicMeters, World world, int materialID, SharedVisuals sharedVisuals, double densityMult = 1d, double scale = 1d, decimal credits = 0m)
        {
            this.MineralType = mineralType;
            this.VolumeInCubicMeters = volumeInCubicMeters;
            this.Scale = scale;
            this.Credits = credits;

            this.Model = GetNewVisual(mineralType, sharedVisuals, scale);

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

            this.Density = GetSettingsForMineralType(mineralType).Density * densityMult;

            #region Physics Body

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

            ScaleTransform3D scaleTransform = new ScaleTransform3D(scale, scale, scale);
            Point3D[] hullPoints = UtilityWPF.GetPointsFromMesh((MeshGeometry3D)sharedVisuals.GetMineralMesh(mineralType), scaleTransform);

            using (CollisionHull hull = CollisionHull.CreateConvexHull(world, 0, hullPoints))
            {
                this.PhysicsBody = new Body(hull, transform.Value, this.Density * volumeInCubicMeters, new Visual3D[] { visual });
                this.PhysicsBody.MaterialGroupID = materialID;
                this.PhysicsBody.LinearDamping = .01f;
                this.PhysicsBody.AngularDamping = new Vector3D(.01f, .01f, .01f);

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

            #endregion

            // Calculate radius
            Point3D aabbMin, aabbMax;
            this.PhysicsBody.GetAABB(out aabbMin, out aabbMax);
            this.Radius = (aabbMax - aabbMin).Length / 2d;

            this.CreationTime = DateTime.UtcNow;
        }
Exemple #4
0
        public void CollidedMineral(Mineral mineral, World world, int materialID, SharedVisuals sharedVisuals)
        {
            //TODO: Let the user specify thresholds for which minerals to take ($, density, mass, type).  Also give an option to be less picky if near empty
            //TODO: Let the user specify thresholds for swapping lesser minerals for better ones
            //TODO: Add a portion

            if (base.CargoBays == null)
            {
                return;
            }
            else if (mineral.IsDisposed)
            {
                return;
            }

            var quantity = base.CargoBays.CargoVolume;

            if (quantity.Item2 - quantity.Item1 < mineral.VolumeInCubicMeters)
            {
                // The cargo bays are too full
                return;
            }

            // Save location in case it needs to be brought back
            Point3D position = mineral.PositionWorld;

            // Convert it to cargo
            Cargo_Mineral cargo = new Cargo_Mineral(mineral.MineralType, mineral.Density, mineral.VolumeInCubicMeters);

            // Try to add this to the cargo bays - the total volume may be enough, but the mineral may be too large for any
            // one cargo bay (or some of the cargo bays could be destroyed)
            if (base.CargoBays.Add(cargo))
            {
                // Finish removing it from the real world
                _map.RemoveItem(mineral, true);

                ShouldRecalcMass_Large = true;
            }
        }
Exemple #5
0
        /// <param name="intensity">brightness from 0 to 1</param>
        private static Model3D GetRixiumTorusVisual(Vector3D location, double radius, double intensity, SharedVisuals sharedVisuals)
        {
            // Material
            MaterialGroup material = new MaterialGroup();

            //material.Children.Add(new DiffuseMaterial(new SolidColorBrush(Color.FromArgb(32, 44, 9, 82))));       // purple color
            material.Children.Add(new DiffuseMaterial(new SolidColorBrush(Color.FromArgb(32, 30, 160, 189))));       // teal color
            //material.Children.Add(new SpecularMaterial(new SolidColorBrush(Color.FromArgb(128, 104, 79, 130)), 100d));     // purple reflection
            material.Children.Add(new SpecularMaterial(new SolidColorBrush(Color.FromArgb(128, 60, 134, 150)), 100d));

            byte emissiveAlpha = Convert.ToByte(140 * intensity);

            //material.Children.Add(new EmissiveMaterial(new SolidColorBrush(Color.FromArgb(64, 85, 50, 122))));
            material.Children.Add(new EmissiveMaterial(new SolidColorBrush(Color.FromArgb(emissiveAlpha, 85, 50, 122))));

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

            geometry.Material     = material;
            geometry.BackMaterial = material;
            geometry.Geometry     = sharedVisuals.GetRixiumTorusMesh(radius);

            Transform3DGroup transforms = new Transform3DGroup();

            transforms.Children.Add(new TranslateTransform3D(location));                // this is in model coords
            geometry.Transform = transforms;

            // Exit Function
            return(geometry);
        }
Exemple #6
0
        public Mineral(MineralType mineralType, Point3D position, double volumeInCubicMeters, World world, int materialID, SharedVisuals sharedVisuals, double densityMult = 1d, double scale = 1d, decimal credits = 0m)
        {
            this.MineralType         = mineralType;
            this.VolumeInCubicMeters = volumeInCubicMeters;
            this.Scale   = scale;
            this.Credits = credits;

            this.Model = GetNewVisual(mineralType, sharedVisuals, scale);

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

            visual.Content = this.Model;

            this.Density = GetSettingsForMineralType(mineralType).Density *densityMult;

            #region Physics Body

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

            ScaleTransform3D scaleTransform = new ScaleTransform3D(scale, scale, scale);
            Point3D[]        hullPoints     = UtilityWPF.GetPointsFromMesh((MeshGeometry3D)sharedVisuals.GetMineralMesh(mineralType), scaleTransform);

            using (CollisionHull hull = CollisionHull.CreateConvexHull(world, 0, hullPoints))
            {
                this.PhysicsBody = new Body(hull, transform.Value, this.Density * volumeInCubicMeters, new Visual3D[] { visual });
                this.PhysicsBody.MaterialGroupID = materialID;
                this.PhysicsBody.LinearDamping   = .01f;
                this.PhysicsBody.AngularDamping  = new Vector3D(.01f, .01f, .01f);

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

            #endregion

            // Calculate radius
            Point3D aabbMin, aabbMax;
            this.PhysicsBody.GetAABB(out aabbMin, out aabbMax);
            this.Radius = (aabbMax - aabbMin).Length / 2d;

            this.CreationTime = DateTime.UtcNow;
        }
Exemple #7
0
        public static Model3D GetNewVisual(MineralType mineralType, SharedVisuals sharedVisuals = null, double scale = 1d)
        {
            if (sharedVisuals == null)
            {
                sharedVisuals = _sharedVisuals.Value;
            }

            MineralStats stats = GetSettingsForMineralType(mineralType);

            Model3DGroup retVal = new Model3DGroup();

            // Material
            MaterialGroup materials = new MaterialGroup();

            if (stats.DiffuseColor.A > 0)
            {
                materials.Children.Add(new DiffuseMaterial(new SolidColorBrush(stats.DiffuseColor)));
            }

            if (stats.SpecularColor.A > 0)
            {
                materials.Children.Add(new SpecularMaterial(new SolidColorBrush(stats.SpecularColor), stats.SpecularPower));
            }

            if (stats.EmissiveColor.A > 0)
            {
                materials.Children.Add(new EmissiveMaterial(new SolidColorBrush(stats.EmissiveColor)));
            }

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

            geometry.Material     = materials;
            geometry.BackMaterial = materials;
            geometry.Geometry     = sharedVisuals.GetMineralMesh(mineralType);

            retVal.Children.Add(geometry);

            if (mineralType == MineralType.Rixium)
            {
                #region Rixium Visuals

                // These need to be added after the main crystal, because they are semitransparent

                retVal.Children.Add(GetRixiumTorusVisual(new Vector3D(0, 0, -.6), .38, .5, sharedVisuals));
                retVal.Children.Add(GetRixiumTorusVisual(new Vector3D(0, 0, -.3), .44, .75, sharedVisuals));
                retVal.Children.Add(GetRixiumTorusVisual(new Vector3D(0, 0, 0), .5, 1, sharedVisuals));
                retVal.Children.Add(GetRixiumTorusVisual(new Vector3D(0, 0, .3), .44, .75, sharedVisuals));
                retVal.Children.Add(GetRixiumTorusVisual(new Vector3D(0, 0, .6), .38, .5, sharedVisuals));

                //TODO:  Look at the global lighting options
                PointLight pointLight = new PointLight();
                pointLight.Color             = Color.FromArgb(255, 54, 147, 168);
                pointLight.Range             = 20;
                pointLight.LinearAttenuation = .33;
                retVal.Children.Add(pointLight);

                #endregion
            }

            geometry.Transform = new ScaleTransform3D(scale, scale, scale);

            return(retVal);
        }
        //TODO:  Support variable thrust (the force part is easy, the harder part is scaling the visual)

        public ThrustLine(Viewport3D viewport, SharedVisuals sharedVisuals, Vector3D forceDirection)
            : this(viewport, sharedVisuals, forceDirection, new Vector3D()) { }
Exemple #9
0
        /// <param name="intensity">brightness from 0 to 1</param>
        private static Model3D GetRixiumTorusVisual(Vector3D location, double radius, double intensity, SharedVisuals sharedVisuals)
        {
            // Material
            MaterialGroup material = new MaterialGroup();
            //material.Children.Add(new DiffuseMaterial(new SolidColorBrush(Color.FromArgb(32, 44, 9, 82))));       // purple color
            material.Children.Add(new DiffuseMaterial(new SolidColorBrush(Color.FromArgb(32, 30, 160, 189))));       // teal color
            //material.Children.Add(new SpecularMaterial(new SolidColorBrush(Color.FromArgb(128, 104, 79, 130)), 100d));     // purple reflection
            material.Children.Add(new SpecularMaterial(new SolidColorBrush(Color.FromArgb(128, 60, 134, 150)), 100d));

            byte emissiveAlpha = Convert.ToByte(140 * intensity);

            //material.Children.Add(new EmissiveMaterial(new SolidColorBrush(Color.FromArgb(64, 85, 50, 122))));
            material.Children.Add(new EmissiveMaterial(new SolidColorBrush(Color.FromArgb(emissiveAlpha, 85, 50, 122))));

            // Geometry Model
            GeometryModel3D geometry = new GeometryModel3D();
            geometry.Material = material;
            geometry.BackMaterial = material;
            geometry.Geometry = sharedVisuals.GetRixiumTorusMesh(radius);

            Transform3DGroup transforms = new Transform3DGroup();
            transforms.Children.Add(new TranslateTransform3D(location));		// this is in model coords
            geometry.Transform = transforms;

            // Exit Function
            return geometry;
        }
Exemple #10
0
        public static Model3D GetNewVisual(MineralType mineralType, SharedVisuals sharedVisuals = null, double scale = 1d)
        {
            if (sharedVisuals == null)
            {
                sharedVisuals = _sharedVisuals.Value;
            }

            MineralStats stats = GetSettingsForMineralType(mineralType);

            Model3DGroup retVal = new Model3DGroup();

            // Material
            MaterialGroup materials = new MaterialGroup();
            if (stats.DiffuseColor.A > 0)
            {
                materials.Children.Add(new DiffuseMaterial(new SolidColorBrush(stats.DiffuseColor)));
            }

            if (stats.SpecularColor.A > 0)
            {
                materials.Children.Add(new SpecularMaterial(new SolidColorBrush(stats.SpecularColor), stats.SpecularPower));
            }

            if (stats.EmissiveColor.A > 0)
            {
                materials.Children.Add(new EmissiveMaterial(new SolidColorBrush(stats.EmissiveColor)));
            }

            // Geometry Model
            GeometryModel3D geometry = new GeometryModel3D();
            geometry.Material = materials;
            geometry.BackMaterial = materials;
            geometry.Geometry = sharedVisuals.GetMineralMesh(mineralType);

            retVal.Children.Add(geometry);

            if (mineralType == MineralType.Rixium)
            {
                #region Rixium Visuals

                // These need to be added after the main crystal, because they are semitransparent

                retVal.Children.Add(GetRixiumTorusVisual(new Vector3D(0, 0, -.6), .38, .5, sharedVisuals));
                retVal.Children.Add(GetRixiumTorusVisual(new Vector3D(0, 0, -.3), .44, .75, sharedVisuals));
                retVal.Children.Add(GetRixiumTorusVisual(new Vector3D(0, 0, 0), .5, 1, sharedVisuals));
                retVal.Children.Add(GetRixiumTorusVisual(new Vector3D(0, 0, .3), .44, .75, sharedVisuals));
                retVal.Children.Add(GetRixiumTorusVisual(new Vector3D(0, 0, .6), .38, .5, sharedVisuals));

                //TODO:  Look at the global lighting options
                PointLight pointLight = new PointLight();
                pointLight.Color = Color.FromArgb(255, 54, 147, 168);
                pointLight.Range = 20;
                pointLight.LinearAttenuation = .33;
                retVal.Children.Add(pointLight);

                #endregion
            }

            geometry.Transform = new ScaleTransform3D(scale, scale, scale);

            return retVal;
        }
Exemple #11
0
        /// <summary>
        /// This will take the mineral if it fits
        /// NOTE: This method removes the mineral from the map
        /// </summary>
        private void CollidedMineral_ORIG(Mineral mineral, World world, int materialID, SharedVisuals sharedVisuals)
        {
            //TODO: Let the user specify thresholds for which minerals to take ($, density, mass, type).  Also give an option to be less picky if near empty
            //TODO: Let the user specify thresholds for swapping lesser minerals for better ones

            if (base.CargoBays == null)
            {
                return;
            }
            else if (mineral.IsDisposed)
            {
                return;
            }

            var quantity = base.CargoBays.CargoVolume;

            if (quantity.Item2 - quantity.Item1 < mineral.VolumeInCubicMeters)
            {
                // The cargo bays are too full
                return;
            }

            // Save location in case it needs to be brought back
            Point3D position = mineral.PositionWorld;

            // Try to pop this out of the map
            if (!_map.RemoveItem(mineral, true, false))
            {
                // It's already gone
                return;
            }

            // Convert it to cargo
            Cargo_Mineral cargo = new Cargo_Mineral(mineral.MineralType, mineral.Density, mineral.VolumeInCubicMeters);

            // Try to add this to the cargo bays - the total volume may be enough, but the mineral may be too large for any
            // one cargo bay
            if (base.CargoBays.Add(cargo))
            {
                // Finish removing it from the real world
                mineral.PhysicsBody.Dispose();

                this.ShouldRecalcMass_Large = true;
            }
            else
            {
                // It didn't fit, give it back to the map
                Mineral clone = new Mineral(mineral.MineralType, position, mineral.VolumeInCubicMeters, world, materialID, sharedVisuals, ItemOptionsAstMin2D.MINERAL_DENSITYMULT, mineral.Scale, mineral.Credits);
                _map.AddItem(clone);
            }
        }
Exemple #12
0
        //TODO:  Support variable thrust (the force part is easy, the harder part is scaling the visual)

        public ThrustLine(Viewport3D viewport, SharedVisuals sharedVisuals, Vector3D forceDirection)
            : this(viewport, sharedVisuals, forceDirection, new Vector3D())
        {
        }