示例#1
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));
            }
        }
示例#2
0
        public override CollisionHull CreateCollisionHull(NewtonDynamics.WorldBase world)
        {
            // Get points
            if (this.Vertices == null)
            {
                CreateGeometry(this.IsFinalModel);
            }

            Vector3D scale = this.Scale;

            double halfThick = THICKNESS * .5d * scale.Z;

            List <Point3D> points = new List <Point3D>();

            points.AddRange(this.Vertices.Select(o => new Point3D(o.X * scale.X, o.Y * scale.Y, -halfThick)));
            points.AddRange(this.Vertices.Select(o => new Point3D(o.X * scale.X, o.Y * scale.Y, halfThick)));

            // Transform
            Transform3DGroup transform = new Transform3DGroup();

            //transform.Children.Add(new ScaleTransform3D(this.Scale));		// it ignores scale
            transform.Children.Add(new RotateTransform3D(new QuaternionRotation3D(this.Orientation)));
            transform.Children.Add(new TranslateTransform3D(this.Position.ToVector()));

            // Exit Function
            return(CollisionHull.CreateConvexHull(world, 0, points, transform.Value));
        }
示例#3
0
 public Player(Region region, Vector3 <decimal> position)
     : base(region, position, Team.Player, 500.0, SpriteSets.Player["Idle"])
 {
     CollisionHull.AddShape(new CollisionShape(Vector3 <float> .Zero, 0.5f));
     HasShadow   = true;
     ShadowSize  = 0.6f;
     ShadowAlpha = 0.6f;
 }
示例#4
0
        public AeSprite()
        {
            Animator    = new AeAnimator();
            RenderColor = new AeColor();

            CollisionHull.SetSize((int)SizeX, (int)SizeY);
            AddComponent(Animator);
            AddComponent(RenderColor);
        }
示例#5
0
        public override CollisionHull CreateCollisionHull(WorldBase world)
        {
            Transform3DGroup transform = new Transform3DGroup();

            //transform.Children.Add(new ScaleTransform3D(this.Scale));		// it ignores scale
            transform.Children.Add(new RotateTransform3D(new QuaternionRotation3D(this.Orientation)));
            transform.Children.Add(new TranslateTransform3D(this.Position.ToVector()));

            return(CollisionHull.CreateBox(world, 0, this.Scale * ConverterMatterToFuelDesign.SCALE, transform.Value));
        }
示例#6
0
        private void LoadAnimator(Texture2D texture)
        {
            AeAnimation      animation = new AeAnimation(texture, Animator);
            AeAnimationFrame frame1    = new AeAnimationFrame(0, 0, animation.Texture.Width, animation.Texture.Height, -1);

            SizeX = animation.Texture.Width;
            SizeY = animation.Texture.Height;
            animation.AddFrame(frame1);
            Animator.Add("default", animation);
            CollisionHull.SetSize((int)SizeX, (int)SizeY);
        }
示例#7
0
        public override CollisionHull CreateCollisionHull(WorldBase world)
        {
            Transform3DGroup transform = new Transform3DGroup();

            //transform.Children.Add(new ScaleTransform3D(this.Scale));		// it ignores scale
            transform.Children.Add(new RotateTransform3D(new QuaternionRotation3D(this.Orientation)));
            transform.Children.Add(new TranslateTransform3D(this.Position.ToVector()));

            Vector3D scale = this.Scale;

            return(CollisionHull.CreateSphere(world, 0, new Vector3D(scale.X * RADIUSPERCENTOFSCALE, scale.Y * RADIUSPERCENTOFSCALE, scale.Z * HEIGHTPERCENTOFSCALE), transform.Value));
        }
示例#8
0
        public 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()));

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

            return(CollisionHull.CreateBox(world, 0, size, transform.Value));
        }
示例#9
0
        public override CollisionHull CreateCollisionHull(WorldBase world)
        {
            Transform3DGroup transform = new Transform3DGroup();

            //transform.Children.Add(new ScaleTransform3D(scale));		// it ignores scale
            transform.Children.Add(new RotateTransform3D(new QuaternionRotation3D(this.Orientation)));
            transform.Children.Add(new TranslateTransform3D(this.Position.ToVector()));

            Vector3D size = new Vector3D(this.Scale.X * DirectionControllerRingDesign.SIZEPERCENTOFSCALE * .5d, this.Scale.Y * DirectionControllerRingDesign.SIZEPERCENTOFSCALE * .5d, this.Scale.Z * DirectionControllerRingDesign.SIZEPERCENTOFSCALE * .5d);

            return(CollisionHull.CreateSphere(world, 0, size, transform.Value));
        }
示例#10
0
        // Just going with a sphere for the physics
        internal static CollisionHull CreateCameraCollisionHull(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 * SCALE * .5d, scale.Y * SCALE * .5d, scale.Z * SCALE * .5d);

            return(CollisionHull.CreateSphere(world, 0, size, transform.Value));
        }
示例#11
0
        public override CollisionHull CreateCollisionHull(WorldBase world)
        {
            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 * SCALE * .5d, Scale.Y * SCALE * .5d, Scale.Z * SCALE * .5d);

            return(CollisionHull.CreateSphere(world, 0, size, transform.Value));
        }
示例#12
0
        public override CollisionHull CreateCollisionHull(WorldBase world)
        {
            Transform3DGroup transform = new Transform3DGroup();

            //transform.Children.Add(new ScaleTransform3D(this.Scale));		// it ignores scale
            transform.Children.Add(new RotateTransform3D(new QuaternionRotation3D(this.Orientation)));
            transform.Children.Add(new TranslateTransform3D(this.Position.ToVector()));

            Vector3D scale = this.Scale;
            Vector3D size  = new Vector3D(1d * scale.X, RATIOY * scale.Y, RATIOZ * scale.Z);

            return(CollisionHull.CreateBox(world, 0, size, transform.Value));
        }
示例#13
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 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()));

            // Scale X and Y should be identical, but average them to be safe
            double radius = SIZEPERCENTOFSCALE_XY * Math1D.Avg(scale.X, scale.Y) * .5;      // multiplying by .5 to turn diameter into radius
            double height = SIZEPERCENTOFSCALE_Z * scale.Z;

            return(CollisionHull.CreateCylinder(world, 0, radius, height, transform.Value));
        }
示例#14
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 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));
        }
示例#15
0
        public override CollisionHull CreateCollisionHull(WorldBase world)
        {
            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(this.Orientation)));
            transform.Children.Add(new TranslateTransform3D(this.Position.ToVector()));

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

            return(CollisionHull.CreateCylinder(world, 0, radius, height, transform.Value));
        }
示例#16
0
        public Egg(Point3D position, double radius, World world, int materialID, ItemOptions itemOptions, T contents)
        {
            this.Radius = radius;
            Vector3D scale = new Vector3D(.75d, .75d, 1d);

            #region WPF Model

            // Material
            MaterialGroup materials = new MaterialGroup();
            materials.Children.Add(new DiffuseMaterial(new SolidColorBrush(WorldColors.Egg_Color)));
            materials.Children.Add(WorldColors.Egg_Specular);

            // 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;
        }
示例#17
0
        public virtual CollisionHull CreateCollisionHull(World world)
        {
            if (_isLooseProps)
            {
                Transform3DGroup transform = new Transform3DGroup();
                //transform.Children.Add(new ScaleTransform3D(this.Scale));		// it ignores scale
                transform.Children.Add(new RotateTransform3D(new QuaternionRotation3D(_orientation)));
                transform.Children.Add(new TranslateTransform3D(_position.ToVector()));

                return(CollisionHull.CreateConvexHull(world, 0, _convexPoints, transform.Value));
            }
            else
            {
                return(_part.CreateCollisionHull(world));
            }
        }
示例#18
0
        public BodyBall(World world)
        {
            this.Model = GetModel();
            ModelVisual3D visual = new ModelVisual3D();

            visual.Content = this.Model;

            using (CollisionHull hull = CollisionHull.CreateNull(world))
            {
                this.PhysicsBody = new Body(hull, Matrix3D.Identity, 100, new[] { visual });
            }

            this.Radius = 2;

            this.CreationTime = DateTime.UtcNow;
        }
示例#19
0
 void Start()
 {
     colliders        = new List <CollisionHull>();
     startingCollider = GetComponent <PolygonCollider2D>();
     if (startingCollider == null)
     {
         message("Warning: No PolygonCollider2D found on root node. Using default empty collider.");
     }
     else
     {
         var foo = new CollisionHull();
         foo.externalHull = new CSGshape(new List <Vector2>(startingCollider.GetPath(0)));
         colliders.Add(foo);
     }
     if (BaseTexture == null)
     {
         message("Warning: Missing Base Texture");
     }
     if (GroundShader != null)
     {
         groundMaterial = new Material(GroundShader);
         groundMaterial.SetTexture("_MainTex", basetex);
         groundMaterial.SetFloat("_SCALE", 10);
     }
     else
     {
         message("Error! Missing Ground Shader");
     }
     if (HoleShader != null)
     {
         holeMaterial = new Material(HoleShader);
     }
     else
     {
         message("Error! Missing Hole Shader");
     }
     groundMesh = new Mesh();
     holeMesh   = new Mesh();
     //holeCamera = gameObject.AddComponent<Camera>();
     //holeCamera.CopyFrom(Camera.main);
     if (holeTexture == null)
     {
         holeTexture = new RenderTexture(Camera.main.pixelWidth, Camera.main.pixelWidth, 0);
     }
     //holeCamera.targetTexture = holeTexture;
     //groundMaterial.SetTexture("_MaskTex",holeTexture);
 }
示例#20
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;
        }
示例#21
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;
        }
示例#22
0
    private void ShapeOp(CSGshape other, bool isNot)
    {
        List <CollisionHull> hulls = new List <CollisionHull>();
        bool isShapeUsedUp         = false;

        foreach (var coll in colliders)
        {
            if (!isShapeUsedUp || isNot == false)
            {
                var result = CSGshape.not(coll.externalHull, other, isNot, out isShapeUsedUp, coll.holes);
                hulls.AddRange(result);
            }
        }
        if (!isShapeUsedUp && !isNot)
        {
            var foo = new CollisionHull();
            foo.externalHull = other;
            hulls.Add(foo);
        }
        colliders = hulls;
    }
示例#23
0
 //TODO switch to update/doupdate pattern so alive bool will work
 public virtual void Update(GameTime gameTime)
 {
     if (!_isInitialized)
     {
         _isInitialized = true;
         Init();
     }
     if (Alive)
     {
         CollisionHull.SetPosition((int)Transform.X, (int)Transform.Y);
         foreach (var cmp in _privateComponents)
         {
             cmp.Update(gameTime);
         }
         foreach (var cmp in Components)
         {
             cmp.Update(gameTime);
         }
         foreach (var child in Entities)
         {
             child.Update(gameTime);
         }
     }
 }
示例#24
0
        public SpaceStation(Point3D position, World world, int materialID, Quaternion orientation)
        {
            //TODO:  Windows, lights

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

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

            double radius = 8;

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

            #region Interior Visuals

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

            #region Hull - Torus

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

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

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

            #endregion
            #region Hull - Spine

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

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

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

            #endregion
            #region Hull - Spokes

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

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

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

            #endregion
            #region Hull - Top inner

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

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

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

            #endregion
            #region Hull - Top outer

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

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

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

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

            #endregion

            #endregion

            #region Glass

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

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

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

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

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

            #endregion

            #region Exterior Visuals

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

            #endregion

            #region Force Field

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

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

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

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

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

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

            #endregion

            this.Model = models;

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

            #region Physics Body

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

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

            #endregion

            this.CreationTime = DateTime.UtcNow;
        }
示例#25
0
    //collision hull.hull or whatever is null if nothing is left
    public static List <CollisionHull> not(CSGshape shape, CSGshape other, bool isNot, out bool usedFlag, List <CSGshape> holes = null)
    {
        //start with a point on me thats not in the other shape
        //List<CSGshape> retr = new List<CSGshape>();
        List <CollisionHull> hulls            = new List <CollisionHull>();
        List <CSGsegment>    externalSegments = shape.getExternalSegments(other);

        usedFlag = !isNot;
        if (other.segments.TrueForAll(i => !shape.doesIntersect(i)) && !isNot)
        {
            var foo = new CollisionHull();
            foo.externalHull = shape;
            foo.holes        = holes;

            /*var bar = new CollisionHull();
             * bar.externalHull = other;*/
            hulls.Add(foo);
            //hulls.Add(bar);
            usedFlag = false;
            return(hulls);
        }
        else if (externalSegments.Count == 0)        //other completely surrounds this
        {
            if (isNot)
            {
                return(hulls);
            }
            else
            {
                hulls.Add(new CollisionHull());
                hulls[0].externalHull = other;
                return(hulls);
            }
        }
        else if (externalSegments.Count == shape.segments.Count && other.segments.TrueForAll(a => shape.isPointInside(a.start)))        //this completely surrounds other
        {
            if (isNot)
            {
                var foo = new List <CSGshape>();
                foo.Add(other);
                if (holes != null)
                {
                    foo.AddRange(holes);
                }
                foo = andAll(foo);
                var hull = new CollisionHull();
                hull.externalHull = shape;
                hull.holes.Add(other);
                hulls.Add(hull);
            }
            else
            {
                hulls.Add(new CollisionHull());
                hulls[0].externalHull = shape;
            }
            return(hulls);
            //throw new NotImplementedException();

            /*float closestDist = float.PositiveInfinity;
             * CSGsegment closestItem = null;
             * CSGsegment closestInnerItem = null;
             * if (!other.isClockwise())
             * {
             * other.antiRotate();
             * }
             * foreach (var i in shape.segments)
             * {
             * foreach (var j in other.segments)
             * {
             * var dist = (i.end - j.start).magnitude;
             * if (dist < closestDist)
             * {
             * closestItem = i;
             * closestInnerItem = j;
             * closestDist = dist;
             * }
             * }
             * }
             * var enter = new CSGsegment(closestItem.end, closestInnerItem.start);
             * var exit = new CSGsegment(closestInnerItem.start, closestItem.end);
             * var oldnext = closestItem.endSegment;
             * var oldinnernext = closestInnerItem.startSegment;
             * oldnext.startSegment = exit;
             * closestItem.endSegment = enter;
             * enter.endSegment = closestInnerItem;
             * exit.endSegment = oldnext;
             * oldinnernext.endSegment = exit;
             * enter.startSegment = closestItem;
             * closestInnerItem.startSegment = enter;
             * exit.startSegment = oldinnernext;
             *
             * CSGsegment curr = enter;
             * List<Vector2> newPoints = new List<Vector2>();
             * do
             * {
             * newPoints.Add(curr.getPoint(true));
             * curr = curr.next(true);
             * } while (curr!=enter);
             * retr.Add(new CSGshape(newPoints));
             * return retr;*/
        }
        else
        {
            while (externalSegments.Count > 0)
            {
                List <Vector2> newPoints       = new List <Vector2>();
                bool           isMovingForward = true;
                var            first           = externalSegments[0];//better to remove at start or end? look this up
                var            curr            = first;
                var            isStart         = true;
                externalSegments.RemoveAt(0);
                int counter = 0;
                while (true)
                {
                    if (counter > 100)                    //remove this?
                    {
                        throw new Exception("Linerider exceeded 100 steps");
                        //break;
                    }
                    counter++;
                    var partialPath = curr.ridePathUntilIntersection(other, externalSegments, isMovingForward, first, isStart);
                    foreach (var i in partialPath.first)
                    {
                        newPoints.Add(i.getPoint(isMovingForward));
                    }
                    if (partialPath.second == null)
                    {
                        break;
                    }
                    var intersectionPoint = partialPath.first[partialPath.first.Count - 1].intersectionPoint(partialPath.second);
                    isMovingForward = shape.getDirection(partialPath.second, isNot, intersectionPoint);                    //toggle this to add instead of subtract
                    isStart         = false;
                    //now we must enter this shape, so test the two points
                    var exitPoint     = partialPath.second.getPoint(!isMovingForward);                //!isMovingForward so we get end instead of start
                    var entrancePoint = intersectionPoint + smallDelta * (exitPoint - intersectionPoint).normalized;
                    if (isMovingForward)
                    {
                        curr = new CSGsegment(entrancePoint, exitPoint);
                    }
                    else
                    {
                        curr = new CSGsegment(exitPoint, entrancePoint);
                    }
                    curr.startSegment = partialPath.second.startSegment;
                    curr.endSegment   = partialPath.second.endSegment;
                    ////////////////////////now inside this
                    partialPath = curr.ridePathUntilIntersection(shape, externalSegments, isMovingForward, null);                    //null because it can't end inside
                    foreach (var i in partialPath.first)
                    {
                        newPoints.Add(i.getPoint(isMovingForward));
                    }
                    intersectionPoint = partialPath.first[partialPath.first.Count - 1].intersectionPoint(partialPath.second);
                    isMovingForward   = other.getDirection(partialPath.second, false, intersectionPoint);
                    //now we gotta leave this shape
                    exitPoint     = partialPath.second.getPoint(!isMovingForward);                //!isMovingForward so we get end instead of start
                    entrancePoint = intersectionPoint + smallDelta * (exitPoint - intersectionPoint).normalized;
                    if (isMovingForward)
                    {
                        curr = new CSGsegment(entrancePoint, exitPoint);
                    }
                    else
                    {
                        curr = new CSGsegment(exitPoint, entrancePoint);
                    }
                    curr.startSegment = partialPath.second.startSegment;
                    curr.endSegment   = partialPath.second.endSegment;
                }
                var foo      = new CollisionHull();
                var newShape = new CSGshape(newPoints);
                foo.externalHull = newShape;
                hulls.Add(foo);
            }
            return(hulls);
        }
    }
示例#26
0
        public TreasureBox(Point3D position, double mass, double hitPoints, int materialID, World world, DamageProps 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

            _sensorVisionPoints = GetSensorVisionPoints_Model(RADIUS, HEIGHT);

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

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

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

            this.ContainedTreasureDNA = containedTreasureDNA;

            this.CreationTime = DateTime.UtcNow;
        }
示例#27
0
 public Actor(Region region, Vector3 <decimal> position, Team team, double health) : base(region, position)
 {
     CollisionHull        = new CollisionHull(this, team);
     HealthPool           = new HealthPool(this, health);
     HealthPool.Depleted += Kill;
 }
示例#28
0
        private Body GetJointBodyPairSprtBody(CollisionShapeType bodyType, Point3D centerPoint, RotateTransform3D rotation, Color color)
        {
            #region WPF Model (plus collision hull)

            // 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.BackMaterial = materials;

            CollisionHull hull = null;
            switch (bodyType)
            {
            case CollisionShapeType.Box:
                geometry.Geometry = UtilityWPF.GetCube_IndependentFaces(new Point3D(-1, -1, -1d), new Point3D(1d, 1d, 1d));
                hull = CollisionHull.CreateBox(_world, 0, new Vector3D(2d, 2d, 2d), null);
                break;

            case CollisionShapeType.Sphere:
                geometry.Geometry = UtilityWPF.GetSphere_LatLon(5, 1d, 1d, 1d);
                hull = CollisionHull.CreateSphere(_world, 0, new Vector3D(1d, 1d, 1d), null);
                break;

            case CollisionShapeType.Cylinder:
                geometry.Geometry = UtilityWPF.GetCylinder_AlongX(20, 1d, 2d);
                hull = CollisionHull.CreateCylinder(_world, 0, 1d, 2d, null);
                break;

            case CollisionShapeType.Cone:
                geometry.Geometry = UtilityWPF.GetCone_AlongX(20, 1d, 2d);
                hull = CollisionHull.CreateCone(_world, 0, 1d, 2d, null);
                break;

            case CollisionShapeType.Capsule:
            case CollisionShapeType.ChamferCylinder:
                throw new ApplicationException("finish this");

            default:
                throw new ApplicationException("Unknown ConvexBody3D.CollisionShape: " + bodyType.ToString());
            }

            // Transform
            Transform3DGroup transform = new Transform3DGroup();                // rotate needs to be added before translate
            transform.Children.Add(rotation);
            transform.Children.Add(new TranslateTransform3D(centerPoint.ToVector()));

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

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

            #endregion

            #region Physics Body

            // Make a physics body that represents this shape
            Body body = new Body(hull, transform.Value, 1d, new Visual3D[] { model });          // being lazy with mass, but since size is fixed, it won't be too noticable
            hull.Dispose();
            body.Velocity = Math3D.GetRandomVector_Circular(1d);

            //body.LinearDamping = .01f;
            //body.AngularDamping = new Vector3D(.01f, .01f, .01f);

            body.ApplyForceAndTorque += new EventHandler <BodyApplyForceAndTorqueArgs>(Body_ApplyForceAndTorque);

            // This will be done later
            //_bodySets.Add(body);

            #endregion

            // Exit Function
            return(body);
        }
示例#29
0
        private void addSimple1_AddBody(object sender, AddBodyArgs e)
        {
            try
            {
                #region WPF Model (plus collision hull)

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

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

                CollisionHull hull = null;
                switch (e.CollisionShape)
                {
                case CollisionShapeType.Box:
                    Vector3D halfSize = e.Size / 2d;
                    geometry.Geometry = UtilityWPF.GetCube_IndependentFaces(new Point3D(-halfSize.X, -halfSize.Y, -halfSize.Z), new Point3D(halfSize.X, halfSize.Y, halfSize.Z));
                    hull = CollisionHull.CreateBox(_world, 0, e.Size, null);
                    break;

                case CollisionShapeType.Sphere:
                    geometry.Geometry = UtilityWPF.GetSphere_LatLon(5, e.Size.X, e.Size.Y, e.Size.Z);
                    hull = CollisionHull.CreateSphere(_world, 0, e.Size, null);
                    break;

                case CollisionShapeType.Cylinder:
                    geometry.Geometry = UtilityWPF.GetCylinder_AlongX(20, e.Radius, e.Height);
                    hull = CollisionHull.CreateCylinder(_world, 0, e.Radius, e.Height, null);
                    break;

                case CollisionShapeType.Cone:
                    geometry.Geometry = UtilityWPF.GetCone_AlongX(20, e.Radius, e.Height);
                    hull = CollisionHull.CreateCone(_world, 0, e.Radius, e.Height, null);
                    break;

                case CollisionShapeType.Capsule:
                case CollisionShapeType.ChamferCylinder:
                    MessageBox.Show("finish this");
                    return;

                default:
                    throw new ApplicationException("Unknown ConvexBody3D.CollisionShape: " + e.CollisionShape.ToString());
                }

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

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

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

                #endregion

                #region Physics Body

                // Make a physics body that represents this shape
                Body body = new Body(hull, transform.Value, e.Mass, new Visual3D[] { model });
                hull.Dispose();
                body.Velocity = Math3D.GetRandomVector_Circular(1d);

                //body.LinearDamping = .01f;
                //body.AngularDamping = new Vector3D(.01f, .01f, .01f);

                body.ApplyForceAndTorque += new EventHandler <BodyApplyForceAndTorqueArgs>(Body_ApplyForceAndTorque);

                Body[] bodySet = new Body[] { body };
                _bodySets.Add(bodySet);

                #endregion

                BodiesAdded(bodySet);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), this.Title, MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }