public Dot(bool isStatic, Point3D position)
            {
                this.IsStatic = isStatic;
                _position = position;

                ModelVisual3D model = BuildDot(isStatic);
                this.Visual = model;

                _transform = new TranslateTransform3D(position.ToVector());
                model.Transform = _transform;
            }
            public Dot(bool isStatic, Point3D position, double repulseMult = 1d)
            {
                this.IsStatic = isStatic;
                _position = position;
                this.RepulseMult = repulseMult;

                ModelVisual3D model = BuildDot(isStatic, repulseMult);
                this.Visual = model;

                _transform = new TranslateTransform3D(position.ToVector());
                model.Transform = _transform;
            }
Пример #3
0
        public Egg(Point3D position, World world, int materialID, ItemOptions itemOptions, ShipDNA dna)
        {
            // The radius should be 20% the size of the adult ship
            this.Radius = dna.PartsByLayer.SelectMany(o => o.Value).
                Max(o => o.Position.ToVector().Length + Math1D.Max(o.Scale.X, o.Scale.Y, o.Scale.Z))
                * .2d;

            Vector3D scale = new Vector3D(.75d, .75d, 1d);

            #region WPF Model

            // Material
            MaterialGroup materials = new MaterialGroup();
            materials.Children.Add(new DiffuseMaterial(new SolidColorBrush(WorldColors.EggColor)));
            materials.Children.Add(WorldColors.EggSpecular);

            // Geometry Model
            GeometryModel3D geometry = new GeometryModel3D();
            geometry.Material = materials;
            geometry.BackMaterial = materials;
            geometry.Geometry = UtilityWPF.GetSphere_LatLon(5, this.Radius);
            geometry.Transform = new ScaleTransform3D(scale);

            this.Model = geometry;

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

            #endregion

            #region Physics Body

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

            double volume = (4d / 3d) * Math.PI * scale.X * this.Radius * scale.Y * this.Radius * scale.Z * this.Radius;
            double mass = volume * itemOptions.Egg_Density;

            using (CollisionHull hull = CollisionHull.CreateSphere(world, 0, scale * this.Radius, 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;
        }
Пример #4
0
        public Projectile(double radius, double mass, Point3D position, World world, int materialID, Color? color = null, double? maxAge = null, Map map = null)
        {
            if (maxAge != null && map == null)
            {
                throw new ArgumentException("Map must be populated if max age is set");
            }

            this.Radius = radius;
            _maxAge = maxAge;
            _map = map;

            #region WPF Model

            this.Model = GetModel(color);
            this.Model.Transform = new ScaleTransform3D(radius, radius, radius);

            // Model Visual
            ModelVisual3D visual = new ModelVisual3D();
            visual.Content = this.Model;

            #endregion

            #region Physics Body

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

            using (CollisionHull hull = CollisionHull.CreateSphere(world, 0, new Vector3D(radius, radius, radius), null))
            {
                this.PhysicsBody = new Body(hull, transform.Value, mass, new Visual3D[] { visual });
                //this.PhysicsBody.IsContinuousCollision = true;
                this.PhysicsBody.MaterialGroupID = materialID;
                this.PhysicsBody.LinearDamping = .01d;
                this.PhysicsBody.AngularDamping = new Vector3D(.01d, .01d, .01d);

                //this.PhysicsBody.ApplyForceAndTorque += new EventHandler<BodyApplyForceAndTorqueArgs>(Body_ApplyForceAndTorque);
            }

            #endregion

            this.CreationTime = DateTime.UtcNow;
        }
Пример #5
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;
        }
Пример #6
0
        private void AddDot(Point3D position, double radius, Color color, bool isHiRes = true)
        {
            // Material
            MaterialGroup materials = new MaterialGroup();
            materials.Children.Add(new DiffuseMaterial(new SolidColorBrush(color)));
            materials.Children.Add(new SpecularMaterial(new SolidColorBrush(UtilityWPF.AlphaBlend(Colors.White, color, .3d)), 30d));

            // Geometry Model
            GeometryModel3D geometry = new GeometryModel3D();
            geometry.Material = materials;
            geometry.BackMaterial = materials;
            geometry.Geometry = UtilityWPF.GetSphere_Ico(radius, isHiRes ? 3 : 0, true);

            // Model Visual
            ModelVisual3D visual = new ModelVisual3D();
            visual.Content = geometry;
            visual.Transform = new TranslateTransform3D(position.ToVector());

            // Temporarily add to the viewport
            _viewport.Children.Add(visual);
            _visuals.Add(visual);
        }
Пример #7
0
        private void AddText3D(string text, Point3D center, double height, Color color)
        {
            MaterialGroup faceMaterial = new MaterialGroup();
            faceMaterial.Children.Add(new DiffuseMaterial(new SolidColorBrush(color)));
            faceMaterial.Children.Add(new SpecularMaterial(new SolidColorBrush(UtilityWPF.ColorFromHex("60FFFFFF")), 5d));

            MaterialGroup edgeMaterial = new MaterialGroup();
            edgeMaterial.Children.Add(new DiffuseMaterial(new SolidColorBrush(UtilityWPF.OppositeColor(color))));
            edgeMaterial.Children.Add(new SpecularMaterial(new SolidColorBrush(UtilityWPF.ColorFromHex("80808080")), 1d));

            double edgeDepth = height / 15;

            ModelVisual3D visual = new ModelVisual3D();
            visual.Content = UtilityWPF.GetText3D(text, _font.Value, faceMaterial, edgeMaterial, height, edgeDepth);
            visual.Transform = new TranslateTransform3D(center.ToVector());

            // Temporarily add to the viewport
            _viewport.Children.Add(visual);
            _visuals.Add(visual);
        }
Пример #8
0
        private static void GetModel_Rod_Moon(Model3DGroup geometries, WeaponHandleDNA dna, WeaponHandleDNA finalDNA, WeaponMaterialCache materials)
        {
            const double PERCENT = 1;

            Random rand = StaticRandom.GetRandomForThread();
            var from = dna.KeyValues;
            var to = finalDNA.KeyValues;

            #region Shaft

            GeometryModel3D shaft = new GeometryModel3D();

            shaft.Material = materials.Handle_Moon;
            shaft.BackMaterial = shaft.Material;

            double maxRad1 = WeaponDNA.GetKeyValue("maxRad1", from, to, rand.NextDouble(.7, 1.02));
            double maxRad2 = WeaponDNA.GetKeyValue("maxRad2", from, to, rand.NextDouble(.7, 1.02));
            double maxRad12 = Math.Max(maxRad1, maxRad2);       // this is used in several places

            List<TubeRingBase> rings = new List<TubeRingBase>();

            rings.Add(new TubeRingRegularPolygon(0, false, maxRad1 * .4, maxRad1 * .4, true));
            rings.Add(new TubeRingRegularPolygon(WeaponDNA.GetKeyValue("tube1", from, to, rand.NextPercent(.25, PERCENT)), false, maxRad1 * .8, maxRad1 * .8, false));
            rings.Add(new TubeRingRegularPolygon(WeaponDNA.GetKeyValue("tube2", from, to, rand.NextPercent(.3, PERCENT)), false, maxRad1 * .85, maxRad1 * .85, false));
            rings.Add(new TubeRingRegularPolygon(WeaponDNA.GetKeyValue("tube3", from, to, rand.NextPercent(.75, PERCENT)), false, maxRad1 * .6, maxRad1 * .6, false));

            rings.Add(new TubeRingRegularPolygon(WeaponDNA.GetKeyValue("tube4", from, to, rand.NextPercent(20, PERCENT)), false, maxRad2 * .8, maxRad2 * .8, false));
            rings.Add(new TubeRingRegularPolygon(WeaponDNA.GetKeyValue("tube5", from, to, rand.NextPercent(1, PERCENT)), false, maxRad2 * .9, maxRad2 * .9, false));
            rings.Add(new TubeRingRegularPolygon(WeaponDNA.GetKeyValue("tube6", from, to, rand.NextPercent(1, PERCENT)), false, maxRad2 * 1, maxRad2 * 1, false));
            rings.Add(new TubeRingDome(WeaponDNA.GetKeyValue("tube7", from, to, rand.NextPercent(2.5, PERCENT)), false, 4));

            rings = TubeRingBase.FitNewSize(rings, maxRad12 * dna.Radius, maxRad12 * dna.Radius, dna.Length);

            shaft.Geometry = UtilityWPF.GetMultiRingedTube(10, rings, true, true, new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(0, 1, 0), -90)));      // the tube builds along z, but this class wants along x

            #endregion

            // Number of gems
            int numIfNew = 0;
            if (rand.NextDouble() > .66d)       // only 33% will get gems
            {
                // Of the handles with gems, only 5% will get 2
                numIfNew = rand.NextDouble() > .95 ? 2 : 1;
            }

            int numGems = Convert.ToInt32(WeaponDNA.GetKeyValue("numGems", from, to, numIfNew));

            if (numGems == 0)
            {
                geometries.Children.Add(shaft);
                return;
            }

            #region Gems

            List<double> percents = new List<double>();

            for (int cntr = 0; cntr < numGems; cntr++)
            {
                string keyPrefix = "gem" + cntr.ToString();

                // Get a placement for this gem
                double percentIfNew = 0;
                do
                {
                    percentIfNew = rand.NextDouble(.15, .85);

                    if (percents.Count == 0)
                    {
                        break;
                    }
                } while (percents.Any(o => Math.Abs(percentIfNew - o) < .15));

                double percent = WeaponDNA.GetKeyValue(keyPrefix + "Percent", from, to, percentIfNew);

                percents.Add(percent);

                // Gem
                GeometryModel3D gem = new GeometryModel3D();

                gem.Material = materials.Handle_MoonGem;
                gem.BackMaterial = gem.Material;

                double width = WeaponDNA.GetKeyValue(keyPrefix + "Width", from, to, rand.NextDouble(maxRad12 * 1d, maxRad12 * 1.4d));

                gem.Geometry = UtilityWPF.GetSphere_LatLon(5, dna.Radius * width);
                Point3D position = new Point3D((dna.Length * percent) - (dna.Length / 2d), 0, 0);
                gem.Transform = new TranslateTransform3D(position.ToVector());

                // Light
                PointLight pointLight = new PointLight(materials.Handle_MoonGemLight, position);
                UtilityWPF.SetAttenuation(pointLight, dna.Radius * 120d, .1d);

                geometries.Children.Add(pointLight);
                geometries.Children.Add(gem);
            }

            // Adding this after so that you don't see the shaft through the gems
            geometries.Children.Add(shaft);

            #endregion
        }
Пример #9
0
        internal static CollisionHull CreateCollisionHull(WorldBase world, Vector3D scale, Quaternion orientation, Point3D position)
        {
            Transform3DGroup transform = new Transform3DGroup();
            //transform.Children.Add(new ScaleTransform3D(scale));		// it ignores scale
            transform.Children.Add(new RotateTransform3D(new QuaternionRotation3D(orientation)));
            transform.Children.Add(new TranslateTransform3D(position.ToVector()));

            Vector3D size = new Vector3D(scale.X * .5d, scale.Y * .5d, scale.Z * .5d);

            return CollisionHull.CreateSphere(world, 0, size, transform.Value);
        }
Пример #10
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);
        }
Пример #11
0
        private void Brain_StraightToTarget_VelocityAware2()
        {
            // Velocity should be zero when touching the chase point

            //TODO:  Implement this (when not attacking, velocity should slow to a max speed the closer to the chase point)



            // Convert everything to local coords
            Point3D position = new Point3D(0, 0, 0);
            Point3D chasePoint = this.PhysicsBody.PositionFromWorld(_chasePoint);

            Vector3D directionToGo = chasePoint.ToVector() - position.ToVector();

            Vector3D axis;
            double radians;

            #region Adjust for current velocity attempt1a

            Vector3D currentVelocity = this.VelocityWorld;

            if (!Math1D.IsNearZero(currentVelocity.LengthSquared))
            {
                currentVelocity = this.PhysicsBody.DirectionFromWorld(currentVelocity);

                Math3D.GetRotation(out axis, out radians, directionToGo, currentVelocity);

                // This is how much to rotate direction to align with current velocity, I want to go against the current velocity (if aligned,
                // the angle will be zero, so negating won't make a difference)
                radians *= -1;

                // If it's greater than 90 degrees, then just use the original direction (because it will pull the velocity in line
                // eventually)  I don't multiply by .5, because when it is very close to 90 degrees, the bot will thrash a bit
                if (Math.Abs(radians) < Math.PI * .4d)
                {
                    // Change the direction by the angle
                    directionToGo = directionToGo.GetRotatedVector(axis, Math1D.RadiansToDegrees(radians));
                }
            }

            #endregion

            // Now that I know where to go, rotate the original thruster direction (0,1,0) to line up with the desired direction
            Math3D.GetRotation(out axis, out radians, _origThrustDirection, directionToGo);

            // Thrust Direction
            _thrustTransform = new RotateTransform3D(new AxisAngleRotation3D(axis, Math1D.RadiansToDegrees(radians)));

            // Thrust Strength
            if (_isAttacking)
            {
                _thrustPercent = 1d;
            }
            else
            {
                _thrustPercent = .5d;
            }
        }
Пример #12
0
        public Neuron_SensorPosition(Point3D position, bool isPositiveOnly, bool ignoreSetValue = true)
        {
            _position = position;
            _isPositiveOnly = isPositiveOnly;
            _ignoreSetValue = ignoreSetValue;

            if (Math3D.IsNearZero(position))
            {
                _positionUnit = null;
                _positionLength = 0d;
            }
            else
            {
                _positionUnit = position.ToVector().ToUnit();
                _positionLength = position.ToVector().Length;
            }
        }
Пример #13
0
        private void AddDot(Point3D position, Color color, double radius = .1)
        {
            // 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 model = new ModelVisual3D();
            model.Content = geometry;
            model.Transform = new TranslateTransform3D(position.ToVector());

            // Temporarily add to the viewport
            _viewport.Children.Add(model);
            _visuals.Add(model);
        }
Пример #14
0
        internal static CollisionHull CreateTankCollisionHull(WorldBase world, Vector3D scale, Quaternion orientation, Point3D position)
        {
            Transform3DGroup transform = new Transform3DGroup();
            //transform.Children.Add(new ScaleTransform3D(this.Scale));		// it ignores scale
            transform.Children.Add(new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(0, 1, 0), 90)));		// the physics hull is along x, but dna is along z
            transform.Children.Add(new RotateTransform3D(new QuaternionRotation3D(orientation)));
            transform.Children.Add(new TranslateTransform3D(position.ToVector()));

            double radius = RADIUSPERCENTOFSCALE * (scale.X + scale.Y) * .5d;
            double height = scale.Z;

            if (height < radius * 2d)
            {
                // Newton keeps the capsule caps spherical, but the visual scales them.  So when the height is less than the radius, newton
                // make a sphere.  So just make a cylinder instead
                //return CollisionHull.CreateChamferCylinder(world, 0, radius, height, transform.Value);
                return CollisionHull.CreateCylinder(world, 0, radius, height, transform.Value);
            }
            else
            {
                //NOTE: The visual changes the caps around, but I want the physics to be a capsule
                return CollisionHull.CreateCapsule(world, 0, radius, height, transform.Value);
            }
        }
        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;
        }
Пример #16
0
        public TreasureBox(Point3D position, double mass, double hitPoints, int materialID, World world, WeaponDamage damageMultipliers, object[] containedTreasureDNA = null)
        {
            const double RADIUS = .75d / 2d;
            const double HEIGHT = 1.5d;

            const double RING_Z1 = (HEIGHT / 2d) * .5d;     // this is distance from the end cap
            const double RING_Z2 = (HEIGHT / 2d) - RING_Z1;     // this one is distance from the origin

            const double RINGRADIUS_INNER = RADIUS * .5d;
            const double RINGRADIUS_OUTER = RADIUS * 1.05d;
            const double RINGHEIGHT = HEIGHT * .05d;

            const int DOMESEGMENTS = 3;
            const int CYLINDERSEGMENTS = 8;
            const int RINGSEGMENTS = 8;

            #region WPF Model

            Model3DGroup geometries = new Model3DGroup();

            #region Barrel

            // Material
            MaterialGroup material = new MaterialGroup();
            material.Children.Add(new DiffuseMaterial(new SolidColorBrush(UtilityWPF.ColorFromHex("413D34"))));
            material.Children.Add(new SpecularMaterial(new SolidColorBrush(UtilityWPF.ColorFromHex("60C5CAA7")), 2d));// .25d));

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

            List<TubeRingBase> rings = new List<TubeRingBase>();
            rings.Add(new TubeRingDome(0d, false, DOMESEGMENTS));
            rings.Add(new TubeRingRegularPolygon(RING_Z1, false, RADIUS, RADIUS, false));
            rings.Add(new TubeRingRegularPolygon(HEIGHT - (RING_Z1 * 2), false, RADIUS, RADIUS, false));
            rings.Add(new TubeRingDome(RING_Z1, false, DOMESEGMENTS));
            geometry.Geometry = UtilityWPF.GetMultiRingedTube(CYLINDERSEGMENTS, rings, true, true);

            geometries.Children.Add(geometry);

            #endregion

            #region Rings

            // Material
            material = new MaterialGroup();
            //material.Children.Add(new DiffuseMaterial(new SolidColorBrush(UtilityWPF.ColorFromHex("736E56"))));
            //material.Children.Add(new SpecularMaterial(new SolidColorBrush(UtilityWPF.ColorFromHex("B0EEF2CE")), .8d));
            material.Children.Add(new DiffuseMaterial(new SolidColorBrush(UtilityWPF.ColorFromHex("CCBF81"))));
            material.Children.Add(new SpecularMaterial(new SolidColorBrush(UtilityWPF.ColorFromHex("B0D9D78D")), 8));// .8d));

            // Ring 1
            // Geometry Model
            geometry = new GeometryModel3D();
            geometry.Material = material;
            geometry.BackMaterial = material;
            geometry.Geometry = UtilityWPF.GetRing(RINGSEGMENTS, RINGRADIUS_INNER, RINGRADIUS_OUTER, RINGHEIGHT, new TranslateTransform3D(0, 0, -RING_Z2), false);

            geometries.Children.Add(geometry);

            // Ring 2
            // Geometry Model
            geometry = new GeometryModel3D();
            geometry.Material = material;
            geometry.BackMaterial = material;
            geometry.Geometry = UtilityWPF.GetRing(RINGSEGMENTS, RINGRADIUS_INNER, RINGRADIUS_OUTER, RINGHEIGHT, new TranslateTransform3D(0, 0, RING_Z2), false);

            geometries.Children.Add(geometry);

            // Ring 3
            // Geometry Model
            geometry = new GeometryModel3D();
            geometry.Material = material;
            geometry.BackMaterial = material;
            geometry.Geometry = UtilityWPF.GetRing(RINGSEGMENTS, RINGRADIUS_INNER, RINGRADIUS_OUTER, RINGHEIGHT);

            geometries.Children.Add(geometry);

            #endregion

            geometries.Transform = new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(0, 1, 0), 90));     // make this go along x instead of z

            this.Model = geometries;

            // 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;

            #endregion

            #region Physics Body

            Transform3DGroup transform = new Transform3DGroup();
            //transform.Children.Add(new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(0, 0, 1), 90)));
            transform.Children.Add(new TranslateTransform3D(position.ToVector()));

            using (CollisionHull hull = CollisionHull.CreateCylinder(world, 0, RADIUS, HEIGHT, null))
            {
                this.PhysicsBody = new Body(hull, transform.Value, mass, new Visual3D[] { visual });
                this.PhysicsBody.MaterialGroupID = materialID;
                this.PhysicsBody.LinearDamping = 1d;
                this.PhysicsBody.AngularDamping = new Vector3D(.01d, .01d, .01d);

                //this.PhysicsBody.ApplyForceAndTorque += new EventHandler<BodyApplyForceAndTorqueArgs>(PhysicsBody_ApplyForceAndTorque);
            }

            #endregion

            this.Radius = Math.Sqrt((RADIUS * RADIUS) + ((HEIGHT / 2d) * (HEIGHT / 2d)));

            this.ReceiveDamageMultipliers = damageMultipliers ?? new WeaponDamage();

            this.HitPoints = new Container() { QuantityMax = hitPoints, QuantityCurrent = hitPoints };

            this.ContainedTreasureDNA = containedTreasureDNA;

            this.CreationTime = DateTime.UtcNow;
        }
        private ModelVisual3D CreateCube(List<ModelVisual3D> cubeContainer, Color color, double size, Point3D location)
        {
            // Material
            MaterialGroup materials = new MaterialGroup();
            materials.Children.Add(new DiffuseMaterial(new SolidColorBrush(color)));
            materials.Children.Add(new SpecularMaterial(Brushes.White, 100d));

            // Geometry Model
            GeometryModel3D geometry = new GeometryModel3D();
            geometry.Material = materials;
            geometry.Geometry = UtilityWPF.GetCube(size);
            //geometry.Geometry = UtilityWPF.GetRectangle3D()

            // Transform
            Transform3DGroup transform = new Transform3DGroup();		// rotate needs to be added before translate
            //transform.Children.Add(new RotateTransform3D(new AxisAngleRotation3D(Math3D.GetRandomVectorSpherical(_rand, 10), Math3D.GetNearZeroValue(_rand, 360d))));
            transform.Children.Add(new TranslateTransform3D(location.ToVector()));

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

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

            cubeContainer.Add(retVal);

            // Exit Function
            return retVal;
        }
Пример #18
0
        private void CreateCube(Color color, Point3D location)
        {
            #region WPF Model

            // Material
            MaterialGroup materials = new MaterialGroup();
            materials.Children.Add(new DiffuseMaterial(new SolidColorBrush(color)));
            materials.Children.Add(new SpecularMaterial(Brushes.White, 100d));

            // Geometry Model
            GeometryModel3D geometry = new GeometryModel3D();
            geometry.Material = materials;
            geometry.Geometry = UtilityWPF.GetCube(1d);
            //geometry.Geometry = UtilityWPF.GetRectangle3D()

            // Transform
            Transform3DGroup transform = new Transform3DGroup();		// rotate needs to be added before translate
            //transform.Children.Add(new RotateTransform3D(new AxisAngleRotation3D(Math3D.GetRandomVectorSpherical(_rand, 10), Math3D.GetNearZeroValue(_rand, 360d))));
            transform.Children.Add(new TranslateTransform3D(location.ToVector()));

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

            #endregion

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

            // Make a physics body that represents this cube
            ConvexBody3D body = new ConvexBody3D(_world, model);
            body.Mass = 1f;

            _cubes.Add(body);
        }
Пример #19
0
        internal static CollisionHull CreateSensorCollisionHull(WorldBase world, Vector3D scale, Quaternion orientation, Point3D position)
        {
            Transform3DGroup transform = new Transform3DGroup();
            //transform.Children.Add(new ScaleTransform3D(scale));		// it ignores scale
            transform.Children.Add(new RotateTransform3D(new QuaternionRotation3D(orientation)));
            transform.Children.Add(new TranslateTransform3D(position.ToVector()));

            // Scale X and Y should be identical, but average them to be safe
            double radius = ((SIZEPERCENTOFSCALE_XY * scale.X) + (SIZEPERCENTOFSCALE_XY * scale.Y)) / 2d;

            return CollisionHull.CreateCylinder(world, 0, radius, SIZEPERCENTOFSCALE_Z * scale.Z, transform.Value);
        }
        private void AddRope(Point3D bodyAttachPoint, Point3D anchorPoint, double? radianLimit)
        {
            const double SEGMENTLENGTH = .25d;

            if (_body == null)
            {
                throw new InvalidOperationException("The body must be created before this method is called");
            }

            // Figure out how many rope segments to make
            Vector3D dir = anchorPoint - bodyAttachPoint;
            int numSegments = Convert.ToInt32(dir.Length / SEGMENTLENGTH);
            if (numSegments == 0)
            {
                numSegments = 1;
            }

            double segmentLength = dir.Length / numSegments;

            DoubleVector dirDbl = new DoubleVector(dir, Math3D.GetArbitraryOrhonganal(dir));

            #region Anchor

            #region WPF Model

            // Material
            MaterialGroup materials = new MaterialGroup();
            materials.Children.Add(new DiffuseMaterial(new SolidColorBrush(_colors.Anchor)));
            materials.Children.Add(_colors.AnchorSpecular);

            // Geometry Mesh
            MeshGeometry3D mesh = UtilityWPF.GetSphere_LatLon(5, .1d);

            // Geometry Model
            GeometryModel3D geometry = new GeometryModel3D();
            geometry.Material = materials;
            geometry.BackMaterial = materials;
            geometry.Geometry = mesh;

            // Transform
            Transform3DGroup transform = new Transform3DGroup();		// rotate needs to be added before translate
            //rotation = _defaultDirectionFacing.GetAngleAroundAxis(dirDbl);
            //transform.Children.Add(new RotateTransform3D(new QuaternionRotation3D(rotation)));
            transform.Children.Add(new TranslateTransform3D(anchorPoint.ToVector()));

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

            #endregion

            // Body
            CollisionHull hull = CollisionHull.CreateNull(_world);
            Body body = new Body(hull, model.Transform.Value, 0, new Visual3D[] { model });
            hull.Dispose();

            _anchorBodies.Add(body);

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

            #endregion

            #region Rope

            for (int cntr = 0; cntr < numSegments; cntr++)
            {
                #region WPF Model

                // Material
                materials = new MaterialGroup();
                materials.Children.Add(new DiffuseMaterial(new SolidColorBrush(_colors.Rope)));
                materials.Children.Add(_colors.RopeSpecular);

                // Geometry Mesh
                mesh = UtilityWPF.GetCylinder_AlongX(7, .03d, segmentLength);
                CollisionHull ropeHull = CollisionHull.CreateCylinder(_world, 0, .03d, segmentLength, null);

                // Geometry Model
                geometry = new GeometryModel3D();
                geometry.Material = materials;
                geometry.BackMaterial = materials;
                geometry.Geometry = mesh;

                // Transform
                transform = new Transform3DGroup();		// rotate needs to be added before translate
                //Quaternion rotation = _defaultDirectionFacing.GetAngleAroundAxis(dirDbl);

                Vector3D axisStandard;
                double radiansStandard;
                Math3D.GetRotation(out axisStandard, out radiansStandard, _defaultDirectionFacing.Standard, dirDbl.Standard);
                Quaternion rotationStandard = new Quaternion(axisStandard, Math1D.RadiansToDegrees(radiansStandard));

                //Vector3D axisOrth;
                //double radiansOrth;
                //Math3D.GetRotation(out axisOrth, out radiansOrth, _defaultDirectionFacing.Orth, dirDbl.Orth);
                //Quaternion rotationOrth = new Quaternion(axisOrth, Math3D.RadiansToDegrees(radiansOrth));

                //Quaternion rotation = rotationStandard.ToUnit() * rotationOrth.ToUnit();
                //Quaternion rotation = rotationOrth;
                Quaternion rotation = rotationStandard;		// adding the orth in just messes it up

                transform.Children.Add(new RotateTransform3D(new QuaternionRotation3D(rotation)));
                Vector3D segmentPosition = new Vector3D((segmentLength / 2d) + (segmentLength * cntr), 0, 0);
                segmentPosition = rotation.GetRotatedVector(segmentPosition);
                segmentPosition += bodyAttachPoint.ToVector();
                transform.Children.Add(new TranslateTransform3D(segmentPosition));

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

                #endregion

                // Body
                body = new Body(ropeHull, model.Transform.Value, .1, new Visual3D[] { model });
                ropeHull.Dispose();

                #region Joint

                if (cntr == 0)
                {
                    _ropeJoints.Add(JointBallAndSocket.CreateBallAndSocket(_world, bodyAttachPoint, _body, body));
                }
                else
                {
                    Vector3D connectPosition2 = new Vector3D(segmentLength * cntr, 0, 0);
                    connectPosition2 = rotation.GetRotatedVector(connectPosition2);
                    connectPosition2 += bodyAttachPoint.ToVector();

                    _ropeJoints.Add(JointBallAndSocket.CreateBallAndSocket(_world, connectPosition2.ToPoint(), _ropeBodies[_ropeBodies.Count - 1], body));
                }

                if (cntr == numSegments - 1)
                {
                    Vector3D connectPosition1 = new Vector3D(segmentLength * numSegments, 0, 0);
                    connectPosition1 = rotation.GetRotatedVector(connectPosition1);
                    connectPosition1 += bodyAttachPoint.ToVector();

                    _ropeJoints.Add(JointBallAndSocket.CreateBallAndSocket(_world, connectPosition1.ToPoint(), body, _anchorBodies[_anchorBodies.Count - 1]));
                }

                #endregion

                _ropeBodies.Add(body);

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

            if (radianLimit != null)
            {
                for (int cntr = 0; cntr < _ropeJoints.Count - 1; cntr++)		// the connection between the anchor point and rope will never have a limit
                {
                    ((JointBallAndSocket)_ropeJoints[cntr]).SetConeLimits(dir, radianLimit.Value, null);
                }
            }

            #endregion
        }
Пример #21
0
        /// <summary>
        /// This isn't meant to be used by anything.  It's just a pure implementation of a dome that can be a template for the
        /// real methods
        /// </summary>
        private static MeshGeometry3D GetDome_Template(int numSegmentsTheta, int numSegmentsPhi, double radiusX, double radiusY, double radiusZ)
        {
            // This will be along the z axis.  It will go from z=0 to z=radiusZ

            if (numSegmentsTheta < 3)
            {
                throw new ArgumentException("numSegments must be at least 3: " + numSegmentsTheta.ToString(), "numSegments");
            }

            MeshGeometry3D retVal = new MeshGeometry3D();

            #region Initial calculations

            //Transform3D transform = Transform3D.Identity;

            double deltaTheta = 2d * Math.PI / numSegmentsTheta;

            Point[] pointsTheta = new Point[numSegmentsTheta];		// these define a unit circle

            for (int cntr = 0; cntr < numSegmentsTheta; cntr++)
            {
                pointsTheta[cntr] = new Point(Math.Cos(deltaTheta * cntr), Math.Sin(deltaTheta * cntr));
            }

            // NOTE: There is one more than what the passed in
            Point[] pointsPhi = new Point[numSegmentsPhi + 1];

            pointsPhi[0] = new Point(1d, 0d);		// along the equator
            pointsPhi[numSegmentsPhi] = new Point(0d, 1d);		// north pole

            if (pointsPhi.Length > 2)
            {
                //double halfPi = Math.PI * .5d;
                ////double deltaPhi = halfPi / numSegmentsPhi;
                //double deltaPhi = halfPi / pointsPhi.Length;		// there is one more point than numSegmentsPhi
                ////double deltaPhi = Math.PI / numSegmentsPhi;

                //for (int cntr = 1; cntr < numSegmentsPhi; cntr++)
                //{
                //    double phi = halfPi + (deltaPhi * cntr);		// phi goes from 0 to pi for a full sphere, so start halfway up
                //    //double phi = deltaPhi * cntr;
                //    pointsPhi[cntr] = new Point(Math.Cos(phi), Math.Sin(phi));
                //}



                // Need to go from 0 to half pi
                double halfPi = Math.PI * .5d;
                double deltaPhi = halfPi / pointsPhi.Length;		// there is one more point than numSegmentsPhi

                for (int cntr = 1; cntr < numSegmentsPhi; cntr++)
                {
                    double phi = deltaPhi * cntr;		// phi goes from 0 to pi for a full sphere, so start halfway up
                    pointsPhi[cntr] = new Point(Math.Cos(phi), Math.Sin(phi));
                }


            }

            #endregion

            #region Positions/Normals

            //for (int phiCntr = 0; phiCntr < numSegmentsPhi; phiCntr++)		// The top point will be added after this loop
            for (int phiCntr = pointsPhi.Length - 1; phiCntr > 0; phiCntr--)
            {
                for (int thetaCntr = 0; thetaCntr < numSegmentsTheta; thetaCntr++)
                {

                    // I think phi points are going from bottom to equator.  

                    Point3D point = new Point3D(
                        radiusX * pointsTheta[thetaCntr].X * pointsPhi[phiCntr].Y,
                        radiusY * pointsTheta[thetaCntr].Y * pointsPhi[phiCntr].Y,
                        radiusZ * pointsPhi[phiCntr].X);

                    //point = transform.Transform(point);

                    retVal.Positions.Add(point);

                    //TODO: For a standalone dome, the bottom ring's will point straight out.  But for something like a snow cone, the normal will have to be averaged with the cone
                    retVal.Normals.Add(point.ToVector().ToUnit());		// the normal is the same as the point for a sphere
                }
            }

            // This is north pole point
            //retVal.Positions.Add(transform.Transform(new Point3D(0, 0, radiusZ)));
            //retVal.Normals.Add(transform.Transform(new Vector3D(0, 0, 1)));
            retVal.Positions.Add(new Point3D(0, 0, radiusZ));
            retVal.Normals.Add(new Vector3D(0, 0, 1));

            #endregion

            #region Triangles - Rings

            int zOffsetBottom = 0;
            int zOffsetTop;

            for (int phiCntr = 0; phiCntr < numSegmentsPhi - 1; phiCntr++)		// The top cone will be added after this loop
            {
                zOffsetTop = zOffsetBottom + numSegmentsTheta;

                for (int thetaCntr = 0; thetaCntr < numSegmentsTheta - 1; thetaCntr++)
                {
                    // Top/Left triangle
                    retVal.TriangleIndices.Add(zOffsetBottom + thetaCntr + 0);
                    retVal.TriangleIndices.Add(zOffsetTop + thetaCntr + 1);
                    retVal.TriangleIndices.Add(zOffsetTop + thetaCntr + 0);

                    // Bottom/Right triangle
                    retVal.TriangleIndices.Add(zOffsetBottom + thetaCntr + 0);
                    retVal.TriangleIndices.Add(zOffsetBottom + thetaCntr + 1);
                    retVal.TriangleIndices.Add(zOffsetTop + thetaCntr + 1);
                }

                // Connecting the last 2 points to the first 2
                // Top/Left triangle
                retVal.TriangleIndices.Add(zOffsetBottom + (numSegmentsTheta - 1) + 0);
                retVal.TriangleIndices.Add(zOffsetTop);		// wrapping back around
                retVal.TriangleIndices.Add(zOffsetTop + (numSegmentsTheta - 1) + 0);

                // Bottom/Right triangle
                retVal.TriangleIndices.Add(zOffsetBottom + (numSegmentsTheta - 1) + 0);
                retVal.TriangleIndices.Add(zOffsetBottom);
                retVal.TriangleIndices.Add(zOffsetTop);

                // Prep for the next ring
                zOffsetBottom = zOffsetTop;
            }

            #endregion
            #region Triangles - Cap

            int topIndex = retVal.Positions.Count - 1;

            for (int cntr = 0; cntr < numSegmentsTheta - 1; cntr++)
            {
                retVal.TriangleIndices.Add(zOffsetBottom + cntr + 0);
                retVal.TriangleIndices.Add(zOffsetBottom + cntr + 1);
                retVal.TriangleIndices.Add(topIndex);
            }

            // The last triangle links back to zero
            retVal.TriangleIndices.Add(zOffsetBottom + numSegmentsTheta - 1 + 0);
            retVal.TriangleIndices.Add(zOffsetBottom + 0);
            retVal.TriangleIndices.Add(topIndex);

            #endregion

            // Exit Function
            //retVal.Freeze();
            return retVal;
        }
Пример #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>
        protected void CreateBot(Viewport3D viewport, SharedVisuals sharedVisuals, World world, Point3D worldPosition)
        {
            _viewport = viewport;
            _sharedVisuals = sharedVisuals;
            _world = world;

            // Thruster
            _origThrustDirection = new Vector3D(0, _thrustForce, 0);
            _thruster = new ThrustLine(_viewport, sharedVisuals, _origThrustDirection, new Vector3D(0, 0, 0));
            _thruster.LineMaxLength = this.ThrustLineStandardLength * _thrustLineMultiplier;

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

            _visuals = new List<ModelVisual3D>();

            #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();
            _coreMaterialNeutralColor = new DiffuseMaterial(new SolidColorBrush(_coreColor));
            _coreMaterialNeutral.Children.Add(_coreMaterialNeutralColor);
            _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

            _visuals.Add(_core);

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

            #endregion

            #endregion

            #region Glass Shell

            // 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;

            _visuals.Add(model);

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

            #endregion
            #region Physics Body

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

            //NOTE:  Not setting material _physicsBody.MaterialGroupID, so it takes the default material

            _physicsBody.NewtonBody.UserData = this;

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

            _physicsBody.LinearDamping = .01f;
            _physicsBody.AngularDamping = new Vector3D(10f, 10f, 10f);   // fairly heavy damping (the bot doesn't try to cancel its spin, so I'll let Newt do it for me)

            _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.  So if you want to add exterior
            // bits that aren't visible inside, this would be the place

            #endregion

            _thruster.IsFiring = true;

            // Show the proper core
            this.IsAttacking = _isAttacking;
        }
Пример #23
0
        private void CreateBoundryBody(Point3D min, Point3D max)
        {
            Vector3D size = new Vector3D(max.X - min.X, max.Y - min.Y, max.Z - min.Z);
            CollisionHull hull = CollisionHull.CreateBox(this, BOUNDRYBODYID, size, null);

            Vector3D offset = min.ToVector() + (size / 2d);
            TranslateTransform3D transform = new TranslateTransform3D(offset);

            Body body = new Body(hull, transform.Value, 0, null);		// by giving it zero mass, it will be a static object
            hull.Dispose();

            _boundry.Add(body);
        }
        private void AddVisual(MeshGeometry3D mesh, Point3D position)
        {
            GeometryModel3D model = new GeometryModel3D();

            model.Material = _material;
            model.BackMaterial = _material;

            model.Geometry = mesh;

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

            Transform3DGroup transform = new Transform3DGroup();
            AxisAngleRotation3D rotation = new AxisAngleRotation3D(Math3D.GetRandomVector_Spherical(1), StaticRandom.NextDouble(360));
            transform.Children.Add(new RotateTransform3D(rotation));
            transform.Children.Add(new TranslateTransform3D(position.ToVector()));

            visual.Transform = transform;

            _viewport.Children.Add(visual);
            _visuals.Add(new VisualTracker(rotation));
        }
Пример #25
0
        private static ModelVisual3D GetWPFModel(out DiffuseMaterial bodyMaterial, Color color, Color reflectionColor, double reflectionIntensity, double radius, Point3D position)
        {
            // Material
            MaterialGroup materials = new MaterialGroup();
            bodyMaterial = new DiffuseMaterial(new SolidColorBrush(color));
            materials.Children.Add(bodyMaterial);
            materials.Children.Add(new SpecularMaterial(new SolidColorBrush(reflectionColor), reflectionIntensity));

            // Geometry Model
            GeometryModel3D geometry = new GeometryModel3D();
            geometry.Material = materials;
            geometry.BackMaterial = materials;
            geometry.Geometry = UtilityWPF.GetSphere_LatLon(5, radius, radius, radius);

            // Transform
            TranslateTransform3D transform = new TranslateTransform3D(position.ToVector());

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

            // Exit Function
            return retVal;
        }
Пример #26
0
 public Point3D DirectionToWorld(Point3D directionLocal)
 {
     //NOTE:  This transform method acts different based on whether a vector or point is passed in
     return this.VisualMatrix.Transform(directionLocal.ToVector()).ToPoint();
 }
Пример #27
0
        public SwarmBot1a(double radius, Point3D position, World world, Map map, SwarmObjectiveStrokes strokes, int materialID, Color? color = null)
        {
            _map = map;
            _strokes = strokes;

            this.Radius = radius;
            this.SearchRadius = radius * 100;

            _settings_OtherBot_Chase = CreateForceSettingInitial_OtherBot_Chase();
            _settings_OtherBot_Passive = CreateForceSettingInitial_OtherBot_Passive();
            _settings_Asteroid = CreateForceSettingInitial_Asteroid();

            #region WPF Model

            this.Model = GetModel(radius, color);
            this.Model.Transform = new ScaleTransform3D(radius, radius, radius);

            // Model Visual
            ModelVisual3D visual = new ModelVisual3D();
            visual.Content = this.Model;

            #endregion

            #region Physics Body

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

            double mass = GetMass(radius);

            using (CollisionHull hull = CollisionHull.CreateSphere(world, 0, new Vector3D(radius / 2, radius / 2, radius / 2), null))
            {
                this.PhysicsBody = new Body(hull, transform.Value, mass, new Visual3D[] { visual });
                //this.PhysicsBody.IsContinuousCollision = true;
                this.PhysicsBody.MaterialGroupID = materialID;
                this.PhysicsBody.LinearDamping = .01d;
                this.PhysicsBody.AngularDamping = new Vector3D(.01d, .01d, .01d);

                this.PhysicsBody.ApplyForceAndTorque += new EventHandler<BodyApplyForceAndTorqueArgs>(Body_ApplyForceAndTorque);
            }

            #endregion

            this.CreationTime = DateTime.UtcNow;
        }
Пример #28
0
        public Point3D DirectionFromWorld(Point3D directionWorld)
        {
            Matrix3D matrix = this.VisualMatrix;
            matrix.Invert();

            //NOTE:  This transform method acts different based on whether a vector or point is passed in
            return matrix.Transform(directionWorld.ToVector()).ToPoint();
        }
Пример #29
0
        // These take in params in world coords, but the vector returned is in local coords
        // These will return the vectors with a magnitude from 0 to 1, but will go up to 10 if things get urgent
        /// <summary>
        /// Just the vector from here to the point passed in
        /// </summary>
        protected Vector3D GetDirection_StraightToTarget(Point3D targetPointWorld)
        {
            // Convert everything to local coords
            Point3D position = new Point3D(0, 0, 0);
            Point3D targetPointLocal = _physicsBody.PositionFromWorld(targetPointWorld);

            // Always return a length of 1
            Vector3D retVal = targetPointLocal.ToVector() - position.ToVector();
            retVal.Normalize();

            // Exit Function
            return retVal;
        }
        internal static CollisionHull CreateCollisionHull(WorldBase world, Vector3D scale, Quaternion orientation, Point3D position)
        {
            Transform3DGroup transform = new Transform3DGroup();
            //transform.Children.Add(new ScaleTransform3D(scale));		// it ignores scale
            transform.Children.Add(new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(0, 1, 0), 90)));		// the physics hull is along x, but dna is along z
            transform.Children.Add(new RotateTransform3D(new QuaternionRotation3D(orientation)));
            transform.Children.Add(new TranslateTransform3D(position.ToVector()));

            double radius = RADIUSPERCENTOFSCALE * (scale.X + scale.Y) * .5d;
            double height = scale.Z * HEIGHTPERCENTOFSCALE;

            //return CollisionHull.CreateChamferCylinder(world, 0, radius, height, transform.Value);
            return CollisionHull.CreateCylinder(world, 0, radius, height, transform.Value);
        }