Beispiel #1
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;
        }
Beispiel #2
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;
        }
Beispiel #3
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);
        }
Beispiel #4
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;
        }