Esempio n. 1
0
        public GameModel(Entity e, Vector3 origin, Model m, GameTexture t, bool rippable = true)
        {
            Model       = m;
            texture     = t;
            Origin      = origin;
            CanBeRipped = rippable;

            Model.Tag = this;
            Transform = Matrix.Identity;

            if (e == null)
            {
                BEPUutilities.Vector3[] verts;
                int[] indices;
                ModelDataExtractor.GetVerticesAndIndicesFromModel(Model, out verts, out indices);

                Entity    = new MobileMesh(verts, indices, BEPUutilities.AffineTransform.Identity, MobileMeshSolidity.Solid, Texture.PhysicsProperties.Mass);
                Transform = Matrix.CreateTranslation(-Entity.Position);
            }
            else
            {
                Entity = e;
            }

            Entity.Tag = this;
            Entity.CollisionInformation.Tag = this;

            Entity.Position += ConversionHelper.MathConverter.Convert(Origin);

            Texture.ApplyToModel(this, null); // sets rest of physics/game props
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="MobileMeshObject "/> class.
        /// </summary>
        /// <param name="model">The model.</param>
        /// <param name="pos">The pos.</param>
        /// <param name="rotation">The rotation.</param>
        /// <param name="scale">The scale.</param>
        /// <param name="materialDescription">The material description.</param>
        /// <param name="MobileMeshSolidity">The mobile mesh solidity.</param>
        /// <param name="mass">The mass.</param>
        public MobileMeshObject(IModelo model, Vector3 pos, Matrix?rotation = null, Vector3?scale = null, MaterialDescription materialDescription = null, MobileMeshSolidity MobileMeshSolidity = MobileMeshSolidity.Solid, float mass = 10)
        {
            if (materialDescription == null)
            {
                materialDescription = MaterialDescription.DefaultBepuMaterial();
            }

            if (!rotation.HasValue)
            {
                rotation = Matrix.Identity;
            }

            if (!scale.HasValue)
            {
                scale = Vector3.One;
            }


            System.Diagnostics.Debug.Assert(scale != Vector3.Zero);
            System.Diagnostics.Debug.Assert(model != null);

            this.scale = scale.Value;
            Vector3[] vertices = null;
            int[]     indices  = null;
            ExtractData(ref vertices, ref indices, model);
            triangleGroup          = new MobileMesh(vertices, indices, new AffineTransform(scale.Value, Quaternion.CreateFromRotationMatrix(rotation.Value), pos), MobileMeshSolidity, mass);
            triangleGroup.Material = new BEPUphysics.Materials.Material(materialDescription.StaticFriction, materialDescription.DynamicFriction, materialDescription.Bounciness);
        }
Esempio n. 3
0
        private void RebuildCollider()
        {
            if (Nine.Serialization.ContentProperties.IsContentBuild)
            {
                // Fake an entity when we are compiling the model collider.
                NotifyColliderChanged(new Sphere(Vector3.Zero, 1));
                return;
            }

            if (source == null)
            {
                NotifyColliderChanged(null);
                return;
            }

            Vector3[] vertices;
            int[]     indices;
            GetVerticesAndIndicesFromModel(source, collisionMesh, out vertices, out indices);

            if (isStatic)
            {
                NotifyColliderChanged(new StaticMesh(vertices, indices));
                return;
            }

            // Entities in Bepu is centered, so need to adjust the graphical transform accordingly.
            var mesh = new MobileMesh(vertices, indices, AffineTransform.Identity, MobileMeshSolidity.Counterclockwise);

            Offset        = -mesh.Position;
            mesh.Position = Vector3.Zero;

            NotifyColliderChanged(mesh);
        }
 public MobileMeshModel(Game game, MobileMesh mesh, Model model, float scale, GameManager manager)
     : base(game)
 {
     this._mesh = mesh;
     this._model = model;
     this._scale = scale;
     this._manager = manager;
     this._controlled = false;
 }
Esempio n. 5
0
        /// <summary>
        /// Constructs a new demo.
        /// </summary>
        /// <param name="game">Game owning this demo.</param>
        public MobileMeshDemo(DemosGame game)
            : base(game)
        {
            Vector3[] vertices;
            int[]     indices;

            //Create a big hollow sphere (squished into an ellipsoid).
            ModelDataExtractor.GetVerticesAndIndicesFromModel(game.Content.Load <Model>("hollowsphere"), out vertices, out indices);
            var transform = new AffineTransform(new Vector3(.06f, .04f, .06f), Quaternion.Identity, new Vector3(0, 0, 0));

            //Note that meshes can also be made solid (MobileMeshSolidity.Solid).  This gives meshes a solid collidable volume, instead of just
            //being thin shells.  However, enabling solidity is more expensive.
            var mesh = new MobileMesh(vertices, indices, transform, MobileMeshSolidity.Counterclockwise);

            mesh.Position = new Vector3(0, 0, 0);
            //Make the mesh spin a bit!
            mesh.AngularVelocity = new Vector3(0, 1, 0);
            Space.Add(mesh);

            //Add another mobile mesh inside.
            ModelDataExtractor.GetVerticesAndIndicesFromModel(game.Content.Load <Model>("tube"), out vertices, out indices);
            transform     = new AffineTransform(new Vector3(1, 1, 1), Quaternion.Identity, new Vector3(0, 0, 0));
            mesh          = new MobileMesh(vertices, indices, transform, MobileMeshSolidity.Counterclockwise, 10);
            mesh.Position = new Vector3(0, 10, 0);
            Space.Add(mesh);

            //Create a bunch of boxes.
#if WINDOWS
            int numColumns = 5;
            int numRows    = 5;
            int numHigh    = 5;
#else
            //Keep the simulation a bit smaller on the xbox.
            int numColumns = 4;
            int numRows    = 4;
            int numHigh    = 4;
#endif
            float separation = 1.5f;


            for (int i = 0; i < numRows; i++)
            {
                for (int j = 0; j < numColumns; j++)
                {
                    for (int k = 0; k < numHigh; k++)
                    {
                        Space.Add(new Box(new Vector3(separation * i, k * separation, separation * j), 1, 1, 1, 5));
                    }
                }
            }

            //Space.Add(new Box(new Vector3(0, -10, 0), 1, 1, 1));
            game.Camera.Position = new Microsoft.Xna.Framework.Vector3(0, -10, 5);
            game.Camera.Yaw      = 0;
            game.Camera.Pitch    = 0;
        }
 public MobileMeshModel(Game game, MobileMesh mesh, Model model, float scale, GameManager manager, bool controlled)
     : base(game)
 {
     this._mesh = mesh;
     this._model = model;
     this._scale = scale;
     this._manager = manager;
     this._controlled = controlled;
     if (controlled)
         Resources.Instance.Ship = _mesh;
 }
        /// <summary>
        /// Constructs a new demo.
        /// </summary>
        /// <param name="game">Game owning this demo.</param>
        public MobileMeshDemo(DemosGame game)
            : base(game)
        {


            Vector3[] vertices;
            int[] indices;

            //Create a big hollow sphere (squished into an ellipsoid).
            ModelDataExtractor.GetVerticesAndIndicesFromModel(game.Content.Load<Model>("hollowsphere"), out vertices, out indices);
            var transform = new AffineTransform(new Vector3(.06f, .04f, .06f), Quaternion.Identity, new Vector3(0, 0, 0));

            //Note that meshes can also be made solid (MobileMeshSolidity.Solid).  This gives meshes a solid collidable volume, instead of just
            //being thin shells.  However, enabling solidity is more expensive.
            var mesh = new MobileMesh(vertices, indices, transform, MobileMeshSolidity.Counterclockwise);
            mesh.Position = new Vector3(0, 0, 0);
            //Make the mesh spin a bit!
            mesh.AngularVelocity = new Vector3(0, 1, 0);
            Space.Add(mesh);

            //Add another mobile mesh inside.
            ModelDataExtractor.GetVerticesAndIndicesFromModel(game.Content.Load<Model>("tube"), out vertices, out indices);
            transform = new AffineTransform(new Vector3(1, 1, 1), Quaternion.Identity, new Vector3(0, 0, 0));
            mesh = new MobileMesh(vertices, indices, transform, MobileMeshSolidity.Counterclockwise, 10);
            mesh.Position = new Vector3(0, 10, 0);
            Space.Add(mesh);

            //Create a bunch of boxes.
#if WINDOWS
            int numColumns = 5;
            int numRows = 5;
            int numHigh = 5;
#else
            //Keep the simulation a bit smaller on the xbox.
            int numColumns = 4;
            int numRows = 4;
            int numHigh = 4;
#endif
            float separation = 1.5f;


            for (int i = 0; i < numRows; i++)
                for (int j = 0; j < numColumns; j++)
                    for (int k = 0; k < numHigh; k++)
                    {
                        Space.Add(new Box(new Vector3(separation * i, k * separation, separation * j), 1, 1, 1, 5));
                    }

            //Space.Add(new Box(new Vector3(0, -10, 0), 1, 1, 1));
            game.Camera.Position = new Vector3(0, -10, 5);


        }
Esempio n. 8
0
        public MobileMeshColliderComponent(object tag, List <Microsoft.Xna.Framework.Vector3> verts, int[] indices)
        {
            if (tag != null)
            {
                Tag = tag;
            }

            ParentObject = tag as GameObject;

            List <BEPUutilities.Vector3> bepuVerts =
                MathConverter.Convert(verts.ToArray())
                .ToList();

            mobileMesh = new MobileMesh(bepuVerts.ToArray(), indices, AffineTransform.Identity, MobileMeshSolidity.Counterclockwise);
            offset     = mobileMesh.WorldTransform.Translation.ToXNAVector();

            mobileMesh.CollisionInformation.Tag = this.Tag;

            SystemCore.PhysicsSimulation.SpaceObjectBuffer.Add(mobileMesh);
        }
Esempio n. 9
0
 public BepuEntity createWheel(Vector3 position, string mesh, float scale)
 {
     BepuEntity entity = new BepuEntity();
     entity.modelName = "Wheels7";
     entity.LoadContent();
     Vector3[] vertices;
     int[] indices;
     TriangleMesh.GetVerticesAndIndicesFromModel(entity.model, out vertices, out indices);
     AffineTransform localTransform = new AffineTransform(new Vector3(scale, scale, scale), Quaternion.Identity, new Vector3(0, 0, 0));
     MobileMesh mobileMesh = new MobileMesh(vertices, indices, localTransform, BEPUphysics.CollisionShapes.MobileMeshSolidity.Counterclockwise, 1);
     //Correct Scale for 'Wheels6:'
     //      entity.localTransform = Matrix.CreateScale(4.5f, 4.5f, 4.5f);
     entity.localTransform = Matrix.CreateScale(2.75f, 2.75f, 2.75f);
     entity.body = mobileMesh;
     entity.HasColor = true;
        entity.body.Position = position;
     XNAGame.Instance().space.Add(entity.body);
     XNAGame.Instance().children.Add(entity);
     //modelDrawer.Add(entity.body);
     return entity;
 }
Esempio n. 10
0
        BepuEntity createFromMesh(Vector3 position, string mesh, float scale)
        {
            BepuEntity entity = new BepuEntity();

            entity.modelName = mesh;
            entity.LoadContent();
            Vector3[] vertices;
            int[]     indices;
            TriangleMesh.GetVerticesAndIndicesFromModel(entity.model, out vertices, out indices);
            AffineTransform localTransform = new AffineTransform(new Vector3(scale, scale, scale), Quaternion.Identity, new Vector3(0, 0, 0));
            MobileMesh      mobileMesh     = new MobileMesh(vertices, indices, localTransform, BEPUphysics.CollisionShapes.MobileMeshSolidity.Counterclockwise, 1);

            entity.localTransform = Matrix.CreateScale(scale, scale, scale);
            entity.body           = mobileMesh;
            entity.HasColor       = true;
            entity.diffuse        = new Vector3((float)random.NextDouble(), (float)random.NextDouble(), (float)random.NextDouble());
            entity.body.Position  = position;
            space.Add(entity.body);
            children.Add(entity);
            return(entity);
        }
        public CollisionMesh(Model _model, Vector3 _position, Quaternion _rotation)
        {
            model = _model;
            base.Position = _position;
            rotation = _rotation;
            Vector3[] vertices;
            int[] indices;
            TriangleMesh.GetVerticesAndIndicesFromModel(_model, out vertices, out indices);
            AffineTransform transform = new AffineTransform(Quaternion.Identity, Vector3.Zero);
            meshCollider = new MobileMesh(vertices, indices, transform, MobileMeshSolidity.Counterclockwise);
            //meshCollider = new ConvexHull(vertices);
            meshCollider.CollisionInformation.Tag = this;
            meshCollider.CollisionInformation.LocalPosition = meshCollider.Position;
            meshCollider.Position = _position;
            meshCollider.Orientation = _rotation;
            meshCollider.PositionUpdateMode = PositionUpdateMode.Passive;

            /*if (!groupSet)
            {
                meshGroup = new CollisionGroup();
                CollisionGroupPair pair = new CollisionGroupPair(meshGroup, meshGroup);
                CollisionRules.CollisionGroupRules.Add(pair, CollisionRule.NoBroadPhase);
                groupSet = true;
            }
            else { }*/

            // meshCollider.CollisionInformation.CollisionRules.Group = meshGroup;

            #if DEBUG
            if (wireFrame == null)
            {
                wireFrame = new RasterizerState();
                wireFrame.FillMode = FillMode.WireFrame;
            }
            else { }
            #endif

            visibilityScale = new Vector3(RESCALE, RESCALE, RESCALE);
        }
Esempio n. 12
0
        public BepuEntity createCylinder(Vector3 position, string mesh, float scale)
        {
            BepuEntity entity = new BepuEntity();
                  entity.modelName = "SlaveCylinder";
                  entity.LoadContent();
                  entity.Mass = 0;
                  Vector3[] vertices;
                  int[] indices;

                  TriangleMesh.GetVerticesAndIndicesFromModel(entity.model, out vertices, out indices);
                  AffineTransform localTransform = new AffineTransform(new Vector3(.4f, .4f, .4f), Quaternion.Identity, new Vector3(0, 0, 0));
                  MobileMesh mobileMesh = new MobileMesh(vertices, indices, localTransform, BEPUphysics.CollisionShapes.MobileMeshSolidity.Counterclockwise, 1);
                  entity.localTransform = Matrix.CreateScale(1f, 1f,1f);
                  entity.body = mobileMesh;
                  entity.HasColor = true;
                  entity.body.Position = position;
                  entity.body.Orientation = Quaternion.CreateFromAxisAngle(new Vector3(1, 0, 0), MathHelper.PiOver2);
                  XNAGame.Instance().space.Add(entity.body);
                  XNAGame.Instance().children.Add(entity);
                 // modelDrawer.Add(entity.body);
                  return entity;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="MobileMeshObject "/> class.
        /// </summary>
        /// <param name="model">The model.</param>
        /// <param name="pos">The pos.</param>
        /// <param name="rotation">The rotation.</param>
        /// <param name="scale">The scale.</param>
        /// <param name="materialDescription">The material description.</param>
        /// <param name="MobileMeshSolidity">The mobile mesh solidity.</param>
        /// <param name="mass">The mass.</param>
        public MobileMeshObject(IModelo model, Vector3 pos, Matrix? rotation = null, Vector3? scale = null, MaterialDescription materialDescription = null,MobileMeshSolidity MobileMeshSolidity = MobileMeshSolidity.Solid,float mass = 10)
        {
            if (materialDescription == null)
                materialDescription = MaterialDescription.DefaultBepuMaterial();

            if (!rotation.HasValue)
                rotation = Matrix.Identity;

            if (!scale.HasValue)
                scale = Vector3.One;


            System.Diagnostics.Debug.Assert(scale != Vector3.Zero);
            System.Diagnostics.Debug.Assert(model != null);
            
            this.scale = scale.Value;            
            Vector3[] vertices = null;
            int[] indices = null;
            ExtractData(ref vertices, ref indices, model);
            triangleGroup = new MobileMesh(vertices, indices, new AffineTransform(scale.Value, Quaternion.CreateFromRotationMatrix(rotation.Value), pos), MobileMeshSolidity,mass);        
            triangleGroup.Material = new BEPUphysics.Materials.Material(materialDescription.StaticFriction, materialDescription.DynamicFriction, materialDescription.Bounciness);
        }
Esempio n. 14
0
        private void CreateAsteroids()
        {
            Vector3[] vertices = new Vector3[0];
            int[] indices = new int[0];
            Model asteroidPicked = Resources.Instance.GetModel("asteroid1");
            int mass = 0;
            Vector3 scale = new Vector3(0, 0, 0);

            List<Vector3> asteroidLocations = spawner.GetAsteroidLocations();
            for (int i = 0; i < asteroidLocations.Count; i++)
            {
                int rand = GameInformation.Instance.Rand.Next(0, 5);
                switch (rand)
                {
                    case 0:
                        ModelDataExtractor.GetVerticesAndIndicesFromModel(Resources.Instance.GetModel("asteroid1"), out vertices, out indices);
                        asteroidPicked = Resources.Instance.GetModel("asteroid1");
                        scale = new Vector3(3, 3, 3);
                        mass = 5;
                        break;
                    case 1:
                        ModelDataExtractor.GetVerticesAndIndicesFromModel(Resources.Instance.GetModel("asteroid2"), out vertices, out indices);
                        asteroidPicked = Resources.Instance.GetModel("asteroid2");
                        scale = new Vector3(3, 3, 3);
                        mass = 5;
                        break;
                    case 2:
                        ModelDataExtractor.GetVerticesAndIndicesFromModel(Resources.Instance.GetModel("asteroid3"), out vertices, out indices);
                        asteroidPicked = Resources.Instance.GetModel("asteroid3");
                        scale = new Vector3(5, 5, 5);
                        mass = 30;
                        break;
                    case 3:
                        ModelDataExtractor.GetVerticesAndIndicesFromModel(Resources.Instance.GetModel("asteroid4"), out vertices, out indices);
                        asteroidPicked = Resources.Instance.GetModel("asteroid4");
                        scale = new Vector3(5, 5, 5);
                        mass = 30;
                        break;
                    case 4:
                        ModelDataExtractor.GetVerticesAndIndicesFromModel(Resources.Instance.GetModel("asteroid5"), out vertices, out indices);
                        asteroidPicked = Resources.Instance.GetModel("asteroid5");
                        scale = new Vector3(6, 6, 6);
                        mass = 45;
                        break;
                    case 5:
                        ModelDataExtractor.GetVerticesAndIndicesFromModel(Resources.Instance.GetModel("asteroid6"), out vertices, out indices);
                        asteroidPicked = Resources.Instance.GetModel("asteroid6");
                        scale = new Vector3(6, 6, 6);
                        mass = 45;
                        break;
                }

                MobileMesh mobMesh = new MobileMesh(vertices, indices, new AffineTransform(scale, BEPUutilities.Quaternion.Identity, asteroidLocations[i]), BEPUphysics.CollisionShapes.MobileMeshSolidity.Solid, mass);
                mobMesh.CollisionInformation.Tag = i.ToString();
                space.Add(mobMesh);
                mobMesh.AngularDamping = 0;
                mobMesh.LinearDamping = 0;
                mobMesh.LinearVelocity = new Vector3(GameInformation.Instance.Rand.Next(0, 30) - 15, GameInformation.Instance.Rand.Next(0, 30) - 15, GameInformation.Instance.Rand.Next(0, 30) - 15);
                mobMesh.AngularVelocity = new Vector3(GameInformation.Instance.Rand.Next(1, 10) - 5, GameInformation.Instance.Rand.Next(1, 10) - 5, GameInformation.Instance.Rand.Next(1, 10) - 5);
                MobileMeshModel model = new MobileMeshModel(game, mobMesh, asteroidPicked, scale.X, this);
                modelLookup.Add(i, model);
                game.Components.Add(model);
            }
        }
        /// <summary>
        /// Constructs a new demo.
        /// </summary>
        /// <param name="game">Game owning this demo.</param>
        public MobileMeshSolidityTestDemo(DemosGame game)
            : base(game)
        {
            Vector3[] vertices;
            int[]     indices;

            //Hardcoded box
            vertices = new Vector3[]
            {
                new Vector3(0.5m, 0.5m, 0.5m),
                new Vector3(0.5m, 0.5m, -0.5m),
                new Vector3(-0.5000001m, 0.5m, -0.4999999m),
                new Vector3(-0.4999998m, 0.5m, 0.5000002m),
                new Vector3(-0.4999998m, -0.5m, 0.5000002m),
                new Vector3(-0.5000001m, -0.5m, -0.4999999m),
                new Vector3(0.5m, -0.5m, -0.5m),
                new Vector3(0.5m, -0.5m, 0.5m),
                new Vector3(0.5m, 0.5m, 0.5m),
                new Vector3(0.5m, -0.5m, 0.5m),
                new Vector3(0.5m, -0.5m, -0.5m),
                new Vector3(0.5m, 0.5m, -0.5m),
                new Vector3(0.5m, 0.5m, -0.5m),
                new Vector3(0.5m, -0.5m, -0.5m),
                new Vector3(-0.5000001m, -0.5m, -0.4999999m),
                new Vector3(-0.5000001m, 0.5m, -0.4999999m),
                new Vector3(-0.5000001m, 0.5m, -0.4999999m),
                new Vector3(-0.5000001m, -0.5m, -0.4999999m),
                new Vector3(-0.4999998m, -0.5m, 0.5000002m),
                new Vector3(-0.4999998m, 0.5m, 0.5000002m),
                new Vector3(-0.4999998m, 0.5m, 0.5000002m),
                new Vector3(-0.4999998m, -0.5m, 0.5000002m),
                new Vector3(0.5m, -0.5m, 0.5m),
                new Vector3(0.5m, 0.5m, 0.5m)
            };

            indices = new[]
            {
                2, 1, 0,
                3, 2, 0,
                6, 5, 4,
                7, 6, 4,
                10, 9, 8,
                11, 10, 8,
                14, 13, 12,
                15, 14, 12,
                18, 17, 16,
                19, 18, 16,
                22, 21, 20,
                23, 22, 20
            };

            var mesh = new MobileMesh(vertices, indices, AffineTransform.Identity, MobileMeshSolidity.Solid, 10);

            Space.Add(mesh);

            //Tube
            ModelDataExtractor.GetVerticesAndIndicesFromModel(game.Content.Load <Model>("tube"), out vertices, out indices);
            mesh          = new MobileMesh(vertices, indices, AffineTransform.Identity, MobileMeshSolidity.Solid, 10);
            mesh.Position = new Vector3(-10, 10, 0);
            Space.Add(mesh);

            //Cube
            ModelDataExtractor.GetVerticesAndIndicesFromModel(game.Content.Load <Model>("cube"), out vertices, out indices);
            mesh          = new MobileMesh(vertices, indices, AffineTransform.Identity, MobileMeshSolidity.Solid, 10);
            mesh.Position = new Vector3(10, 0, 0);
            Space.Add(mesh);

            //Guy
            ModelDataExtractor.GetVerticesAndIndicesFromModel(game.Content.Load <Model>("guy"), out vertices, out indices);
            mesh          = new MobileMesh(vertices, indices, AffineTransform.Identity, MobileMeshSolidity.Solid, 10);
            mesh.Position = new Vector3(0, 0, 10);
            Space.Add(mesh);

            //Barrel Platform
            ModelDataExtractor.GetVerticesAndIndicesFromModel(game.Content.Load <Model>("barrelandplatform"), out vertices, out indices);
            mesh          = new MobileMesh(vertices, indices, AffineTransform.Identity, MobileMeshSolidity.Solid, 10);
            mesh.Position = new Vector3(0, 0, -10);
            Space.Add(mesh);

            //FloaterTube
            ModelDataExtractor.GetVerticesAndIndicesFromModel(game.Content.Load <Model>("tube"), out vertices, out indices);
            mesh          = new MobileMesh(vertices, indices, new AffineTransform(new Vector3(1, 1, 1), Quaternion.Identity, new Vector3(0, 0, 0)), MobileMeshSolidity.Solid);
            mesh.Position = new Vector3(5, 18, 0);
            Space.Add(mesh);

            //Float a box through the last mesh to check contact generation controllably.
            var solidityTester = new Box(new Vector3(5, 8, 0), 1, 1, 1);

            solidityTester.LinearVelocity = new Vector3(0, 1, 0);
            CollisionRules.AddRule(solidityTester, mesh, CollisionRule.NoSolver);
            Space.Add(solidityTester);


            Space.Add(new Box(new Vector3(0, -5, 0), 50, 1, 50));

            game.Camera.Position = new Vector3(0, 10, 20);
        }
Esempio n. 16
0
 /// <summary>
 /// Constructs the RadialSensor as a sphere.
 /// </summary>
 /// <param name="radius">
 /// The radius of the RadialSensor's sphere.
 /// </param>
 public ConeSensor(MobileMesh body)
     : base(body)
 {
     mCollidingCreatures = new List<Creature>();
 }
        /// <summary>
        /// Constructs a new demo.
        /// </summary>
        /// <param name="game">Game owning this demo.</param>
        public MobileMeshSolidityTestDemo(DemosGame game)
            : base(game)
        {
            Vector3[] vertices;
            int[] indices;

            //Hardcoded box
            vertices = new Vector3[]
            {
                new Vector3(0.5f, 0.5f, 0.5f),
                new Vector3(0.5f,0.5f,-0.5f),
                new Vector3(-0.5000001f,0.5f ,-0.4999999f),
                new Vector3(-0.4999998f ,0.5f ,0.5000002f),
                new Vector3(-0.4999998f ,-0.5f ,0.5000002f),
                new Vector3(-0.5000001f ,-0.5f ,-0.4999999f),
                new Vector3(0.5f ,-0.5f ,-0.5f),
                new Vector3(0.5f ,-0.5f ,0.5f),
                new Vector3(0.5f ,0.5f ,0.5f),
                new Vector3(0.5f ,-0.5f ,0.5f),
                new Vector3(0.5f ,-0.5f ,-0.5f),
                new Vector3(0.5f ,0.5f ,-0.5f),
                new Vector3(0.5f,0.5f ,-0.5f),
                new Vector3(0.5f ,-0.5f ,-0.5f),
                new Vector3(-0.5000001f ,-0.5f ,-0.4999999f),
                new Vector3(-0.5000001f,0.5f ,-0.4999999f),
                new Vector3(-0.5000001f ,0.5f ,-0.4999999f),
                new Vector3(-0.5000001f ,-0.5f ,-0.4999999f),
                new Vector3(-0.4999998f ,-0.5f ,0.5000002f),
                new Vector3(-0.4999998f ,0.5f ,0.5000002f),
                new Vector3(-0.4999998f,0.5f ,0.5000002f),
                new Vector3(-0.4999998f ,-0.5f ,0.5000002f),
                new Vector3(0.5f ,-0.5f,0.5f) ,
                new Vector3(0.5f ,0.5f ,0.5f)
            };

            indices = new[]
            {
                2, 1, 0,
                3, 2, 0,
                6, 5 ,4,
                7, 6 ,4,
                10, 9, 8,
                11, 10, 8,
                14, 13, 12,
                15, 14, 12,
                18, 17, 16,
                19, 18, 16,
                22, 21, 20,
                23, 22, 20
            };

            var mesh = new MobileMesh(vertices, indices, AffineTransform.Identity, MobileMeshSolidity.Solid, 10);
            Space.Add(mesh);

            //Tube
            ModelDataExtractor.GetVerticesAndIndicesFromModel(game.Content.Load<Model>("tube"), out vertices, out indices);
            mesh = new MobileMesh(vertices, indices, AffineTransform.Identity, MobileMeshSolidity.Solid, 10);
            mesh.Position = new Vector3(-10, 10, 0);
            Space.Add(mesh);

            //Cube
            ModelDataExtractor.GetVerticesAndIndicesFromModel(game.Content.Load<Model>("cube"), out vertices, out indices);
            mesh = new MobileMesh(vertices, indices, AffineTransform.Identity, MobileMeshSolidity.Solid, 10);
            mesh.Position = new Vector3(10, 0, 0);
            Space.Add(mesh);

            //Guy
            ModelDataExtractor.GetVerticesAndIndicesFromModel(game.Content.Load<Model>("guy"), out vertices, out indices);
            mesh = new MobileMesh(vertices, indices, AffineTransform.Identity, MobileMeshSolidity.Solid, 10);
            mesh.Position = new Vector3(0, 0, 10);
            Space.Add(mesh);

            //Barrel Platform
            ModelDataExtractor.GetVerticesAndIndicesFromModel(game.Content.Load<Model>("barrelandplatform"), out vertices, out indices);
            mesh = new MobileMesh(vertices, indices, AffineTransform.Identity, MobileMeshSolidity.Solid, 10);
            mesh.Position = new Vector3(0, 0, -10);
            Space.Add(mesh);

            //FloaterTube
            ModelDataExtractor.GetVerticesAndIndicesFromModel(game.Content.Load<Model>("tube"), out vertices, out indices);
            mesh = new MobileMesh(vertices, indices, new AffineTransform(new Vector3(1, 1, 1), Quaternion.Identity, new Vector3(0, 0, 0)), MobileMeshSolidity.Solid);
            mesh.Position = new Vector3(5, 18, 0);
            Space.Add(mesh);

            //Float a box through the last mesh to check contact generation controllably.
            var solidityTester = new Box(new Vector3(5, 8, 0), 1, 1, 1);
            solidityTester.LinearVelocity = new Vector3(0, 1, 0);
            CollisionRules.AddRule(solidityTester, mesh, CollisionRule.NoSolver);
            Space.Add(solidityTester);

            Space.Add(new Box(new Vector3(0, -5, 0), 50, 1, 50));

            game.Camera.Position = new Vector3(0, 10, 20);
        }
        /// <summary>
        /// Creates a BaseModel.
        /// </summary>
        /// <param name="model">The Model to use. Cannot be null.</param>
        /// <param name="glass">If true, the model is rendered as glass.</param>
        /// <param name="mobile">True if the model is dynamic, false if kinetic. Null means 
        /// kinetic but moves via velocity.</param>
        /// <param name="origin">The position of the model. Use Vector3.Zero if mobile is false.</param>
        public BaseModel(ModelDelegate modelDelegate, bool glass, bool? mobile, Vector3 origin)
        {
            UseCustomAlpha = false;
            this.modelDelegate = modelDelegate;

            Transform = Matrix.Identity;
            RenderAsGlass = glass;
            Origin = origin;
            OriginalOrientation = Quaternion.Identity;
            //this.ignoreLight = ignoreLight;

            Vector3[] verts;
            int[] indices;
            TriangleMesh.GetVerticesAndIndicesFromModel(Model, out verts, out indices);
            Model.Tag = this;

            if(mobile.HasValue)
            {
                if(mobile.Value)
                {
                    // If it's mobile, it's a box!
                    if(Model == Resources.boxModel || Model == Resources.blueBoxModel || Model == Resources.blackBoxModel)
                    {
                        Ent = new BEPUphysics.Entities.Prefabs.Box(Origin, 1.45f, 2.05f, 1.25f, 7); // originally 1.4x2x1.2
                        Ent.ActivityInformation.IsAlwaysActive = true;
                        Ent.Material = boxMaterial;
                        //Ent.CollisionInformation.CollisionRules.Group = dynamicGroup;
                        Ent.CollisionInformation.CollisionRules.Group = noSolverGroupB;
                    }
                    else
                    {
                        // unless it's not a box.
                        Ent = new BEPUphysics.Entities.Prefabs.Box(Origin, 0.592f, 1.193f, 2f, 0.05f);
                        Ent.Material = machineMaterial;
                        Ent.CollisionInformation.CollisionRules.Group = machineGroup;
                    }
                }
                else
                {
                    // If false, it never moves.
                    Ent = new MobileMesh(verts, indices, AffineTransform.Identity, MobileMeshSolidity.DoubleSided);
                    //Transform = mesh.WorldTransform.Matrix;
                    Ent.Material = machineMaterial; // Make it slippery.
                    Ent.CollisionInformation.CollisionRules.Group = kinematicGroup;
                    //Transform = Ent.WorldTransform;
                    //Ent.Position = Origin;
                    IsTerrain = true;
                }
            }
            else
            {
                // If null, it is kinematic, but does move. (no longer true)
                //Ent = new MobileMesh(verts, indices, AffineTransform.Identity, solid ? MobileMeshSolidity.Solid : MobileMeshSolidity.Counterclockwise);
                Ent = new MobileMesh(verts, indices, AffineTransform.Identity, MobileMeshSolidity.DoubleSided, 30);
                Ent.CollisionInformation.CollisionRules.Group = machineGroup;
                //Ent.IsAffectedByGravity = false;
                Transform = Matrix.CreateTranslation(-Ent.Position);
                Ent.Position += Origin;
                Ent.Material = machineMaterial; // Make it slippery.
                Ent.CollisionInformation.Tag = this;
            }

            //foreach(ModelMesh mesh in internalModel.Meshes)
            //    foreach(BasicEffect effect in mesh.Effects)
            //        effect.EnableDefaultLighting();

            //if(Ent != null)
            //{
            OriginalOrientation = Ent.Orientation;
            Ent.Tag = this;
            //}
            //if(Mesh != null)
            //    Mesh.Tag = this;
        }
Esempio n. 19
0
        private void LoadShip()
        {
            Vector3[] vertices = new Vector3[0];
            int[] indices = new int[0];
            Model shipModel = Resources.Instance.GetModel("ship");
            int mass = 5;
            Vector3 scale = new Vector3(3, 3, 3);

            ModelDataExtractor.GetVerticesAndIndicesFromModel(Resources.Instance.GetModel("asteroid1"), out vertices, out indices);
            MobileMesh mobMesh = new MobileMesh(vertices, indices, new AffineTransform(scale, BEPUutilities.Quaternion.Identity, BEPUutilities.Vector3.Zero), BEPUphysics.CollisionShapes.MobileMeshSolidity.Solid, mass);
            mobMesh.Tag = "ship";
            mobMesh.CollisionInformation.Events.InitialCollisionDetected += HandleCollision;
            space.Add(mobMesh);
            mobMesh.AngularDamping = 0;
            mobMesh.LinearDamping = 0;
            mobMesh.LinearVelocity = BEPUutilities.Vector3.Zero;
            mobMesh.AngularVelocity = BEPUutilities.Vector3.Zero;
            MobileMeshModel model = new MobileMeshModel(game, mobMesh, shipModel, scale.X, this, true);
            Ship = model;
            game.Components.Add(model);
        }
Esempio n. 20
0
 BepuEntity createFromMesh(Vector3 position, string mesh, float scale)
 {
     BepuEntity entity = new BepuEntity();
     entity.modelName = mesh;
     entity.LoadContent();
     Vector3[] vertices;
     int[] indices;
     TriangleMesh.GetVerticesAndIndicesFromModel(entity.model, out vertices, out indices);
     AffineTransform localTransform = new AffineTransform(new Vector3(scale, scale, scale), Quaternion.Identity, new Vector3(0, 0, 0));
     MobileMesh mobileMesh = new MobileMesh(vertices, indices, localTransform, BEPUphysics.CollisionShapes.MobileMeshSolidity.Counterclockwise, 1);
     entity.localTransform = Matrix.CreateScale(scale, scale, scale);
     entity.body = mobileMesh;
     entity.HasColor = true;
     entity.diffuse = new Vector3((float)random.NextDouble(), (float)random.NextDouble(), (float)random.NextDouble());
     entity.body.Position = position;
     space.Add(entity.body);
     children.Add(entity);
     return entity;
 }