/// <summary>
        /// Initializes a new instance of the <see cref="TriangleMeshObject"/> 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>
        public TriangleMeshObject(IModelo model, Vector3 pos, Matrix? rotation = null, Vector3? scale= null, MaterialDescription materialDescription = null)
        {
            if (materialDescription == null)
                materialDescription = MaterialDescription.DefaultBepuMaterial();

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

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

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

            this.rotation = rotation.Value;
            this.scale = scale.Value;
            this.position = pos;
            Vector3[] vertices = null;
            int[] indices = null;
            ExtractData(ref vertices, ref indices, model);
            triangleGroup = new StaticMesh(vertices, indices, new AffineTransform(scale.Value, Quaternion.CreateFromRotationMatrix(rotation.Value), position));
            faceVector = Vector3.Transform(Vector3.Forward, triangleGroup.WorldTransform.Matrix);
            triangleGroup.Material = new BEPUphysics.Materials.Material(materialDescription.StaticFriction, materialDescription.DynamicFriction, materialDescription.Bounciness);
            
        }
        ///<summary>
        /// Initializes the pair handler.
        ///</summary>
        ///<param name="entryA">First entry in the pair.</param>
        ///<param name="entryB">Second entry in the pair.</param>
        public override void Initialize(BroadPhaseEntry entryA, BroadPhaseEntry entryB)
        {

            mesh = entryA as StaticMesh;
            convex = entryB as ConvexCollidable;

            if (mesh == null || convex == null)
            {
                mesh = entryB as StaticMesh;
                convex = entryA as ConvexCollidable;

                if (mesh == null || convex == null)
                    throw new Exception("Inappropriate types used to initialize pair.");
            }

            //Contact normal goes from A to B.
            broadPhaseOverlap.entryA = convex;
            broadPhaseOverlap.entryB = mesh;

            UpdateMaterialProperties(convex.entity != null ? convex.entity.material : null, mesh.material);

            base.Initialize(entryA, entryB);




        }
예제 #3
0
        /// <summary>
        /// Constructs a new demo.
        /// </summary>
        /// <param name="game">Game owning this demo.</param>
        public FishInABarrelDemo(DemosGame game)
            : base(game)
        {
            game.Camera.Position = new Vector3(0, 7, 30);

            var detector = new Box(new Vector3(0, 0, 0), 1.5f, 1.5f, 1.5f);
            detector.CollisionInformation.CollisionRules.Personal = CollisionRule.NoSolver;
            var acceptedTriggerEntity = new Box(new Vector3(5, 0, 0), 1.6f, .7f, .4f, 1);
            acceptedTrigger = acceptedTriggerEntity.CollisionInformation;

            detector.Tag = "noDisplayObject";
            acceptedTriggerEntity.Tag = "noDisplayObject";
            Space.Add(detector);
            Space.Add(acceptedTriggerEntity);

            var fish = game.Content.Load<Model>("fish");
            game.ModelDrawer.Add(new DisplayEntityModel(acceptedTriggerEntity, fish, game.ModelDrawer));

            var barrelAndPlatform = game.Content.Load<Model>("barrelAndPlatform");
            Vector3[] staticTriangleVertices;
            int[] staticTriangleIndices;
            TriangleMesh.GetVerticesAndIndicesFromModel(barrelAndPlatform, out staticTriangleVertices, out staticTriangleIndices);

            //Note that the final 'margin' parameter is optional, but can be used to specify a collision margin on triangles in the static triangle group.
            var fishDepositoryGroup = new StaticMesh(staticTriangleVertices, staticTriangleIndices);
            CollisionRules.AddRule(fishDepositoryGroup, detector, CollisionRule.NoBroadPhase);
            Space.Add(fishDepositoryGroup);
            game.ModelDrawer.Add(fishDepositoryGroup);

            movedBox = new Box(new Vector3(-4, 5, 0), 1, 1, 1, 1);
            detector.Space.Add(movedBox);
            detector.CollisionInformation.Events.InitialCollisionDetected += InitialCollisionDetected;
            detector.CollisionInformation.Events.CollisionEnded += CollisionEnded;
        }
        ///<summary>
        /// Cleans up the pair handler.
        ///</summary>
        public override void CleanUp()
        {

            base.CleanUp();
            mesh = null;


        }
예제 #5
0
 public void SetCollision()
 {
     AffineTransform transform = new AffineTransform(initscale, initorient, Position);
     Vector3[] staticTriangleVertices;
     int[] staticTriangleIndices;
     TriangleMesh.GetVerticesAndIndicesFromModel(_model, out staticTriangleVertices, out staticTriangleIndices);
     _physmesh = new StaticMesh(staticTriangleVertices, staticTriangleIndices, transform);
     Game1.space.Add(_physmesh);
     Game1.thegame.ModelDrawer.Add(_physmesh.Mesh);
 }
        /// <summary>
        /// Creates a new instance
        /// </summary>
        /// <param name="collisionObject">The ParentObject this instance will be associated with</param>
        /// <param name="model">The Model used to compute the BEPUPgysics StaticMesh</param>
        public StaticMeshCollisionMove(ICollisionObject collisionObject, Model model) : base(collisionObject)
        {
            Vector3[] vertices;
            int[] indices;

            TriangleMesh.GetVerticesAndIndicesFromModel(model, out vertices, out indices);

            ParentObject.World.Decompose(out _collisionObjectScale, out _collisionObjectRotation, out _collisionObjectTranslation);

            SpaceObject = new StaticMesh(vertices, indices, new AffineTransform(_collisionObjectScale, _collisionObjectRotation, _collisionObjectTranslation));
        }
예제 #7
0
        ///<summary>
        /// Initializes the manifold.
        ///</summary>
        ///<param name="newCollidableA">First collidable.</param>
        ///<param name="newCollidableB">Second collidable.</param>
        public override void Initialize(Collidable newCollidableA, Collidable newCollidableB)
        {
            convex = newCollidableA as ConvexCollidable;
            mesh = newCollidableB as StaticMesh;


            if (convex == null || mesh == null)
            {
                convex = newCollidableB as ConvexCollidable;
                mesh = newCollidableA as StaticMesh;
                if (convex == null || mesh == null)
                    throw new Exception("Inappropriate types used to initialize contact manifold.");
            }

        }
        ///<summary>
        /// Initializes the pair handler.
        ///</summary>
        ///<param name="entryA">First entry in the pair.</param>
        ///<param name="entryB">Second entry in the pair.</param>
        public override void Initialize(BroadPhaseEntry entryA, BroadPhaseEntry entryB)
        {
            mesh = entryA as StaticMesh;
            if (mesh == null)
            {
                mesh = entryB as StaticMesh;
                if (mesh == null)
                {
                    throw new Exception("Inappropriate types used to initialize pair.");
                }
            }


            base.Initialize(entryA, entryB);
        }
        public void add(String file, Leoni game, AffineTransform pos)
        {
            //Load Model
            Model model = game.Content.Load<Model>(file);

            //change the model to a mesh to create vertici collision
            Vector3[] vertices;
            int[] indices;
            TriangleMesh.GetVerticesAndIndicesFromModel(model, out vertices, out indices);
            var mesh = new StaticMesh(vertices, indices, pos);

            //Add it to the space!
            game.space.Add(mesh);

            //Make it visible too.
            StaticModel tmpModel = new StaticModel(model, mesh.WorldTransform.Matrix, game);

            game.Components.Add(tmpModel);
        }
예제 #10
0
        public static void addMapToPhysics(Model model, ModelCategory category)
        {
            if (category == ModelCategory.Track || category == ModelCategory.Wall || category == ModelCategory.InvisibleWall)
            {
                Vector3[] vertices;
                int[] indices;

                GetVerticesAndIndicesFromModelPipeline(model, out vertices, out indices);
                StaticMesh physicsMesh = new StaticMesh(vertices, indices);

                if (category == ModelCategory.Wall)
                {
                    //physicsMesh.Material.KineticFriction = 0.9f;//Improves wall collisions by slowing ship down
                    //physicsMesh.Material.StaticFriction = 0.9f;//Improves wall collisions by slowing ship down
                    //physicsMesh.Material.Bounciness = 0;
                    physicsMesh.CollisionRules.Personal = CollisionRule.NoSolver;
                    physicsMesh.Sidedness = BEPUphysics.CollisionShapes.ConvexShapes.TriangleSidedness.Counterclockwise;//Only collide with the outside of walls.
                    currentTrackWall = physicsMesh;
                }
                if (category == ModelCategory.InvisibleWall)
                {
                    physicsMesh.CollisionRules.Personal = CollisionRule.NoSolver;
                    currentTrackInvisibleWall = physicsMesh;
                }
                if (category == ModelCategory.Track)
                {
                    physicsMesh.Material.Bounciness = 0.3f;
                    physicsMesh.Material.KineticFriction = 0.1f;

                    physicsMesh.CollisionRules.Personal = CollisionRule.NoSolver;//No collisions with track
                    //CollisionGroup noSelfCollideGroup = new CollisionGroup();
                    currentTrackFloor = physicsMesh;
                    // currentTrackFloor.Events.InitialCollisionDetected += new BEPUphysics.NarrowPhaseSystems.CollisionInformations.Events.InitialCollisionDetectedEventHandler<Entity>(trackCollisionFn);
                }

                currentPhysicsObjects.Add(physicsMesh);
                Physics.space.Add(physicsMesh);
            }
        }
예제 #11
0
        /// <summary>
        /// Constructs a new demo.
        /// </summary>
        /// <param name="game">Game owning this demo.</param>
        public StaticMeshDemo(DemosGame game)
            : base(game)
        {
            //Load in mesh data and create the collision mesh.
            Vector3[] staticTriangleVertices;
            int[] staticTriangleIndices;

            var playgroundModel = game.Content.Load<Model>("playground");
            //This is a little convenience method used to extract vertices and indices from a model.
            //It doesn't do anything special; any approach that gets valid vertices and indices will work.
            TriangleMesh.GetVerticesAndIndicesFromModel(playgroundModel, out staticTriangleVertices, out staticTriangleIndices);
            var staticMesh = new StaticMesh(staticTriangleVertices, staticTriangleIndices, new AffineTransform(Matrix3X3.CreateFromAxisAngle(Vector3.Up, MathHelper.Pi), new Vector3(0, -10, 0)));
            staticMesh.Sidedness = TriangleSidedness.Counterclockwise;

            Space.Add(staticMesh);
            game.ModelDrawer.Add(staticMesh);

            //Dump some boxes on top of it for fun.
            int numColumns = 8;
            int numRows = 8;
            int numHigh = 1;
            float separation = 8;
            for (int i = 0; i < numRows; i++)
                for (int j = 0; j < numColumns; j++)
                    for (int k = 0; k < numHigh; k++)
                    {
                        var toAdd = new Box(
                            new Vector3(
                            separation * i - numRows * separation / 2,
                            30f + k * separation,
                            separation * j - numColumns * separation / 2),
                            2, 2, 2, 15);
                        Space.Add(toAdd);
                    }

            game.Camera.Position = new Vector3(0, 10, 15);
        }
예제 #12
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            _spriteBatch = new SpriteBatch(GraphicsDevice);

            // load models
            _footballModel = Content.Load<Model>("mdl/football");
            var pitchModel = Content.Load<Model>("mdl/pitch");

            // initialise physics simulation space
            _space = new Space();
            _space.ForceUpdater.Gravity = new Vector3(0, -9.81f, 0);

            Vector3[] vertices;
            int[] indices;
            TriangleMesh.GetVerticesAndIndicesFromModel(pitchModel, out vertices, out indices);
            var mesh = new StaticMesh(vertices, indices, new BEPUphysics.MathExtensions.AffineTransform(new Vector3(0, -40.0f, 0)));
            _space.Add(mesh);
            Components.Add(new StaticModel(pitchModel, mesh.WorldTransform.Matrix, this));

            var sphere = new Sphere(new Vector3(0, 4, 0), 1, 1);
            _space.Add(sphere);

            var scaling = Matrix.CreateScale(sphere.Radius);
            var model = new EntityModel(sphere, _footballModel, scaling, this);
            Components.Add(model);
            //sphere.Tag = model;
        }
예제 #13
0
 public StaticMeshComponent(Game1 game, GameEntity entity)
     : base(game, entity)
 {
     this.collidable = Entity.GetSharedData(typeof(StaticMesh)) as StaticMesh;
 }
예제 #14
0
        public void DrawTerrain()
        {
            //===============================TERRAIN================================================
            //Create a physical environment from a triangle mesh.
            //First, collect the the mesh data from the model using a helper function.
            //This special kind of vertex inherits from the TriangleMeshVertex and optionally includes
            //friction/bounciness data.
            //The StaticTriangleGroup requires that this special vertex type is used in lieu of a normal TriangleMeshVertex array.
            Vector3[] vertices;
            int[] indices;
            TriangleMesh.GetVerticesAndIndicesFromModel(terrain, out vertices, out indices);
            //Give the mesh information to a new StaticMesh.
            //Give it a transformation which scoots it down below the kinematic box entity we created earlier.
            var mesh = new StaticMesh(vertices, indices, new AffineTransform(new Vector3(0, -30, 0)));

            //Add it to the space!
            space.Add(mesh);
            //Make it visible too.

            Components.Add(new StaticModel(terrain, mesh.WorldTransform.Matrix, this));
            //======================================================================================
        }
예제 #15
0
        /// <summary>
        /// Constructs a new demo.
        /// </summary>
        /// <param name="game">Game owning this demo.</param>
        public ScaleDemo(DemosGame game)
            : base(game)
        {
            //Pick a scale!
            //Beware: If you go too far (say, 0.01 or 100), numerical issues will start to crop up.
            //There are two reasons:
            //1) Limited numerical precision in 32 bit floats. There are far fewer discrete values between 100,000 and 100,001 than there are between 10 and 11.
            //This manifests most noticeably in general case collision detection.
            //2) Numerical tolerances that are not adjusted by the ConfigurationHelper.ApplyScale method below.
            //These other tolerances are defined as constants in the engine as they aren't usually the limiting factor, but you can still
            //go into the source code and change them if you want.  The most used ones are the Epsilon and BigEpsilon in the Toolbox class.
            //Some other systems have custom epsilons as well, though they are typically far smaller.
            //Note that extremely large scales can force various epsilon-reliant systems to do more work than necessary, resulting in slightly lower performance.
            //On the flip side, extremely small scales may cause exits too quickly, resulting in odd behavior.
            float scale = 1f;

            //Load in mesh data and create the collision mesh.
            //The 'mesh' will be a supergiant triangle.
            //Triangles in meshes have a collision detection system which bypasses most numerical issues for collisions on the face of the triangle.
            //Edge collisions fall back to the general case collision detection system which is susceptible to numerical issues at extreme scales.
            //For our simulation, the edges will be too far away to worry about!
            Vector3[] vertices;
            int[] indices;
            vertices = new Vector3[] { new Vector3(-10000, 0, -10000), new Vector3(-10000, 0, 20000), new Vector3(20000, 0, -10000) };
            indices = new int[] { 2, 1, 0 };
            var staticMesh = new StaticMesh(vertices, indices, new AffineTransform(Matrix3X3.CreateFromAxisAngle(Vector3.Up, MathHelper.Pi), new Vector3(0, 0, 0)));
            staticMesh.Sidedness = TriangleSidedness.Counterclockwise;

            Space.Add(staticMesh);
            game.ModelDrawer.Add(staticMesh);

            //Since everything's pretty large, increase the gravity a whole bunch to make things fall fast.
            Space.ForceUpdater.Gravity *= scale;

            //Change the various engine tuning factors so that collision detection and collision response handle the changed scale better.
            ConfigurationHelper.ApplyScale(scale);

            //When dealing with objects that generally have high velocities and accelerations relative to their size, having a shorter time step duration can boost quality
            //a whole lot.  Once the configuration is set properly, most of any remaining 'unsmoothness' in the simulation is due to a lack of temporal resolution;
            //one discrete step can take an object from a valid state to an unpleasing state due to the high rates of motion.
            //To simulate the same amount of time with a smaller time step duration requires taking more time steps.
            //This is a quality-performance tradeoff.  If you want to do this, set the time step duration like so:

            //Space.TimeStepSettings.TimeStepDuration = 1 / 120f;

            //And then, in the update, either call the Space.Update() method proportionally more often or use the Space.Update(dt) version, which takes as many timesteps are necessary to simulate dt time.
            //Watch out: when using the internal timestepping method, you may notice slight motion jitter since the number of updates per frame isn't fixed.  Interpolation buffers can be used
            //to address this; check the Asynchronous Update documentation for more information on using internal time stepping.
            //[Asynchronously updating isn't required to use internal timestepping, but it is a common use case.]

            //Dump some boxes on top of it for fun.
            int numColumns = 8;
            int numRows = 8;
            int numHigh = 1;
            float separation = 2 * scale;
            float baseWidth = 0.5f;
            float baseHeight = 1;
            float baseLength = 1.5f;
            Entity toAdd;
            for (int i = 0; i < numRows; i++)
                for (int j = 0; j < numColumns; j++)
                    for (int k = 0; k < numHigh; k++)
                    {
                        toAdd = new Box(
                            new Vector3(
                            separation * i - numRows * separation / 2,
                            2 * scale + k * separation,
                            separation * j - numColumns * separation / 2),
                            baseWidth * scale, baseHeight * scale, baseLength * scale, 15);

                        Space.Add(toAdd);
                    }

            //Dump some stuff on top of it that use general case collision detection when they collide with boxes.
            numColumns = 3;
            numRows = 3;
            numHigh = 4;
            separation = 2 * scale;
            baseWidth = 1f;
            baseHeight = 1;
            for (int i = 0; i < numRows; i++)
                for (int j = 0; j < numColumns; j++)
                    for (int k = 0; k < numHigh; k++)
                    {
                        toAdd = new Cylinder(
                            new Vector3(
                            separation * i - numRows * separation / 2,
                            8 * scale + k * separation,
                            separation * j - numColumns * separation / 2),
                            baseHeight * scale, 0.5f * baseWidth * scale,  15);

                        Space.Add(toAdd);
                    }

            game.Camera.Position = scale * new Vector3(0, 4, 10);
        }
예제 #16
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            //This 1x1x1 cube model will represent the box entities in the space.
            CubeModel = Content.Load<Model>("cube");

            PlaygroundModel = Content.Load<Model>("playground");

            //Construct a new space for the physics simulation to occur within.
            space = new Space();

            //Set the gravity of the simulation by accessing the simulation settings of the space.
            //It defaults to (0,0,0); this changes it to an 'earth like' gravity.
            //Try looking around in the space's simulationSettings to familiarize yourself with the various options.
            space.ForceUpdater.Gravity = new Vector3(0, -9.81f, 0);

            //Make a box representing the ground and add it to the space.
            //The Box is an "Entity," the main simulation object type of BEPUphysics.
            //Examples of other entities include cones, spheres, cylinders, and a bunch more (a full listing is in the BEPUphysics.Entities namespace).

            //Every entity has a set of constructors.  Some half a parameter for mass, others don't.
            //Constructors that allow the user to specify a mass create 'dynamic' entiites which fall, bounce around, and generally work like expected.
            //Constructors that have no mass parameter create a create 'kinematic' entities.  These can be thought of as having infinite mass.
            //This box being added is representing the ground, so the width and length are extended and it is kinematic.
            Box ground = new Box(Vector3.Zero, 30, 1, 30);
            space.Add(ground);

            //Now that we have something to fall on, make a few more boxes.
            //These need to be dynamic, so give them a mass- in this case, 1 will be fine.
            space.Add(new Box(new Vector3(0, 4, 0), 1, 1, 1, 1));
            space.Add(new Box(new Vector3(0, 8, 0), 1, 1, 1, 1));
            space.Add(new Box(new Vector3(0, 12, 0), 1, 1, 1, 1));

            //Create a physical environment from a triangle mesh.
            //First, collect the the mesh data from the model using a helper function.
            //This special kind of vertex inherits from the TriangleMeshVertex and optionally includes
            //friction/bounciness data.
            //The StaticTriangleGroup requires that this special vertex type is used in lieu of a normal TriangleMeshVertex array.
            Vector3[] vertices;
            int[] indices;
            TriangleMesh.GetVerticesAndIndicesFromModel(PlaygroundModel, out vertices, out indices);
            //Give the mesh information to a new StaticMesh.
            //Give it a transformation which scoots it down below the kinematic box entity we created earlier.
            var mesh = new StaticMesh(vertices, indices, new AffineTransform(new Vector3(0, -40, 0)));

            //Add it to the space!
            space.Add(mesh);
            //Make it visible too.
            Components.Add(new StaticModel(PlaygroundModel, mesh.WorldTransform.Matrix, this));

            //Hook an event handler to an entity to handle some game logic.
            //Refer to the Entity Events documentation for more information.
            Box deleterBox = new Box(new Vector3(5, 2, 0), 3, 3, 3);
            space.Add(deleterBox);
            deleterBox.CollisionInformation.Events.InitialCollisionDetected += HandleCollision;

            //Go through the list of entities in the space and create a graphical representation for them.
            foreach (Entity e in space.Entities)
            {
                Box box = e as Box;
                if (box != null) //This won't create any graphics for an entity that isn't a box since the model being used is a box.
                {

                    Matrix scaling = Matrix.CreateScale(box.Width, box.Height, box.Length); //Since the cube model is 1x1x1, it needs to be scaled to match the size of each individual box.
                    EntityModel model = new EntityModel(e, CubeModel, scaling, this);
                    //Add the drawable game component for this entity to the game.
                    Components.Add(model);
                    e.Tag = model; //set the object tag of this entity to the model so that it's easy to delete the graphics component later if the entity is removed.
                }
            }
        }
 /// <summary>
 /// Raises the appropriate ParentObject collision events depending on its CollisionType value
 /// </summary>
 /// <param name="sender">The current ISpaceObject instance</param>
 /// <param name="other">The ISpaceObject instance which collided</param>
 /// <param name="pair"/>
 private void OnStaticMeshCollisionDetected(StaticMesh sender, Collidable other, CollidablePairHandler pair)
 {
     OnCollisionDetected(sender, other, pair);
 }
예제 #18
0
파일: PlayScreen.cs 프로젝트: Lele/bob_foo
        //metodo che inizializza il livello
        public void nextLevel()
        {
            Vector3[] vertices;
            int[] indices;

            //pista
            //Ricevo i vertici e gli indici del modello 3d
            TriangleMesh.GetVerticesAndIndicesFromModel(stage[currLevel], out vertices, out indices);
            //creo il modello fisico
            //per la vecchia pista
            //stageMesh = new StaticMesh(vertices, indices, new AffineTransform(Matrix3X3.CreateScale(6f), Vector3.Zero));
            //per la nuova pista
            stageMesh = new StaticMesh(vertices, indices, new AffineTransform(Matrix3X3.CreateScale(6f),Vector3.Zero));
            //lo aggiungo allo spazio fisico
            space.Add(stageMesh);
            //creo il modello 3d collegato al modello fisico
            stageMod = new StaticModel(stage[currLevel], stageMesh.WorldTransform.Matrix, Game, this);
            //calcolo i punti per la costruzione del piano che determina la fine del livello
            EndPoint = stageMod.getBonePosition("Finish");

            Game.Components.Add(stageMod);
            stageMod.Visible = true;
            stageMod.Enabled = true;

            //stessa cosa per il bg e per il bob

            //background
            TriangleMesh.GetVerticesAndIndicesFromModel(BackGroundMod, out vertices, out indices);
            var bgMesh = new StaticMesh(vertices, indices, new AffineTransform(new Vector3(0, -100, 0)));
            space.Add(bgMesh);
            bgMod = new StaticModel(BackGroundMod, bgMesh.WorldTransform.Matrix, Game, this);
            Game.Components.Add(bgMod);
            bgMod.Enabled = true;
            bgMod.Visible = true;

            //Bob
            bobBox = new Box(Vector3.Zero, 0.20f, 0.13f, 0.5f, 15);
            bobBox.WorldTransform = Camera.WorldMatrix;
            //per la vecchia pista
            //bobBox.Position = new Vector3(0, 0.1f, 0);
            //per la nuova pista
            bobBox.Position = new Vector3(0, -0.3f, 0);
            //per la pista09.2
            //bobBox.Position = new Vector3(0, 4f, 0);
            Matrix scaling = Matrix.CreateScale(0.03f, 0.03f, 0.03f);
            //scaling = scaling * Matrix.CreateRotationZ(MathHelper.Pi);
            //Matrix rotation = Matrix.CreateFromYawPitchRoll(MathHelper.PiOver2,0,0);
            bobEntity = new EntityModel(bobBox, bobMod, scaling, Game, this);
            Game.Components.Add(bobEntity);
            bobBox.Tag = bobEntity;
            space.Add(bobBox);
            bobEntity.Visible = true;
            bobEntity.Enabled = true;

            //space.Add(finalBox);

            //sposto la telecamera per avere effetto introduzione
            Camera.Position = new Vector3(400, 400, 400);

            songInstance = song.CreateInstance();
            hyperspaceInsance = hyperspace.CreateInstance();
            engineInstance = engine.CreateInstance();

            gamemenu = new gameMenu(Game, timeFont);
            Game.Components.Add(gamemenu);
        }
예제 #19
0
파일: Chunk.cs 프로젝트: nasdf/Boxel-Engine
        /// <summary>
        /// Creates the vertex buffer for the chunk
        /// </summary>
        private void BuildVertexBuffer()
        {
            List<int> indices = new List<int>();
            List<Vector3> verts = new List<Vector3>();
            List<BoxelVertex> vertices = new List<BoxelVertex>();

            for (int y = 0; y < SIZE; y++)
            {
                for (int x = 0; x < SIZE; x++)
                {
                    for (int z = 0; z < SIZE; z++)
                    {
                        double xWorld = (Position.X + x);
                        double yWorld = (Position.Y + y);
                        double zWorld = (Position.Z + z);

                        int index = (int)(xWorld + (SIZE * ChunkManager.SIZE) * (yWorld + (SIZE * ChunkManager.SIZE) * zWorld));

                        BoxelType boxel = ChunkManager.Instance.Boxels[index];

                        if (boxel != BoxelType.NONE)
                        {
                            Color color = Color.Purple;

                            Vector3b relativePosition = new Vector3b((byte)x, (byte)y, (byte)z);
                            Vector3 worldPosition = relativePosition.AsVector3() + Position;

                            switch (boxel)
                            {
                                case BoxelType.GRASS:

                                    //color = new Color(102, 205, 0);

                                    color = GameResources.Color;

                                    color.R = (byte)(xWorld + color.R);
                                    color.G = (byte)(yWorld + color.G);
                                    color.B = (byte)(zWorld + color.B);

                                    break;

                                case BoxelType.DIRT:

                                    color = new Color(139, 101, 8);

                                    color.R = (byte)((GameResources.Random.Next(40)) + color.R);
                                    color.G = (byte)((GameResources.Random.Next(40)) + color.G);
                                    color.B = (byte)((GameResources.Random.Next(40)) + color.B);

                                    break;
                            }

                            // Calculate the position of the vertices on the top face.
                            Vector3 topLeftFront = new Vector3(-0.5f, 0.5f, -0.5f) + worldPosition;
                            Vector3 topLeftBack = new Vector3(-0.5f, 0.5f, 0.5f) + worldPosition;
                            Vector3 topRightFront = new Vector3(0.5f, 0.5f, -0.5f) + worldPosition;
                            Vector3 topRightBack = new Vector3(0.5f, 0.5f, 0.5f) + worldPosition;

                            // Calculate the position of the vertices on the bottom face.
                            Vector3 btmLeftFront = new Vector3(-0.5f, -0.5f, -0.5f) + worldPosition;
                            Vector3 btmLeftBack = new Vector3(-0.5f, -0.5f, 0.5f) + worldPosition;
                            Vector3 btmRightFront = new Vector3(0.5f, -0.5f, -0.5f) + worldPosition;
                            Vector3 btmRightBack = new Vector3(0.5f, -0.5f, 0.5f) + worldPosition;

                            // Calculate the position of the vertices on the top face.
                            Vector3b topLeftFrontb = new Vector3b(1, 2, 1) + relativePosition;
                            Vector3b topLeftBackb = new Vector3b(1, 2, 2) + relativePosition;
                            Vector3b topRightFrontb = new Vector3b(2, 2, 1) + relativePosition;
                            Vector3b topRightBackb = new Vector3b(2, 2, 2) + relativePosition;

                            // Calculate the position of the vertices on the bottom face.
                            Vector3b btmLeftFrontb = new Vector3b(1, 1, 1) + relativePosition;
                            Vector3b btmLeftBackb = new Vector3b(1, 1, 2) + relativePosition;
                            Vector3b btmRightFrontb = new Vector3b(2, 1, 1) + relativePosition;
                            Vector3b btmRightBackb = new Vector3b(2, 1, 2) + relativePosition;

                            Vector3b normalFront = new Vector3b(3, 3, 2);
                            Vector3b normalBack = new Vector3b(3, 3, 4);
                            Vector3b normalTop = new Vector3b(3, 4, 3);
                            Vector3b normalBottom = new Vector3b(3, 2, 3);
                            Vector3b normalLeft = new Vector3b(2, 3, 3);
                            Vector3b normalRight = new Vector3b(4, 3, 3);

                            if (!HasNeighbor(boxel, BoxelFace.FRONT, relativePosition))
                            {
                                // Add the vertices for the FRONT face.
                                vertices.Add(new BoxelVertex(topLeftFrontb, color, normalFront));
                                vertices.Add(new BoxelVertex(btmLeftFrontb, color, normalFront));
                                vertices.Add(new BoxelVertex(topRightFrontb, color, normalFront));
                                vertices.Add(new BoxelVertex(btmLeftFrontb, color, normalFront));
                                vertices.Add(new BoxelVertex(btmRightFrontb, color, normalFront));
                                vertices.Add(new BoxelVertex(topRightFrontb, color, normalFront));

                                int offset = verts.Count;

                                verts.Add(topLeftFront);    // 0
                                verts.Add(btmLeftFront);    // 1
                                verts.Add(topRightFront);   // 2
                                verts.Add(btmRightFront);   // 3

                                indices.Add(0 + offset);
                                indices.Add(1 + offset);
                                indices.Add(2 + offset);
                                indices.Add(3 + offset);
                                indices.Add(2 + offset);
                                indices.Add(1 + offset);
                            }

                            if (!HasNeighbor(boxel, BoxelFace.BACK, relativePosition))
                            {
                                // Add the verts for the BACK face.
                                vertices.Add(new BoxelVertex(topLeftBackb, color, normalBack));
                                vertices.Add(new BoxelVertex(topRightBackb, color, normalBack));
                                vertices.Add(new BoxelVertex(btmLeftBackb, color, normalBack));
                                vertices.Add(new BoxelVertex(btmLeftBackb, color, normalBack));
                                vertices.Add(new BoxelVertex(topRightBackb, color, normalBack));
                                vertices.Add(new BoxelVertex(btmRightBackb, color, normalBack));

                                int offset = verts.Count;

                                verts.Add(topLeftBack);     // 0
                                verts.Add(topRightBack);    // 1
                                verts.Add(btmLeftBack);     // 2
                                verts.Add(btmRightBack);    // 3

                                indices.Add(0 + offset);
                                indices.Add(1 + offset);
                                indices.Add(2 + offset);
                                indices.Add(3 + offset);
                                indices.Add(2 + offset);
                                indices.Add(1 + offset);
                            }

                            if (!HasNeighbor(boxel, BoxelFace.TOP, relativePosition))
                            {
                                // Add the verts for the TOP face.
                                vertices.Add(new BoxelVertex(topLeftFrontb, color, normalTop));
                                vertices.Add(new BoxelVertex(topRightBackb, color, normalTop));
                                vertices.Add(new BoxelVertex(topLeftBackb, color, normalTop));
                                vertices.Add(new BoxelVertex(topLeftFrontb, color, normalTop));
                                vertices.Add(new BoxelVertex(topRightFrontb, color, normalTop));
                                vertices.Add(new BoxelVertex(topRightBackb, color, normalTop));

                                int offset = verts.Count;

                                verts.Add(topLeftFront);    // 0
                                verts.Add(topRightBack);    // 1
                                verts.Add(topLeftBack);     // 2
                                verts.Add(topRightFront);   // 3

                                indices.Add(0 + offset);
                                indices.Add(1 + offset);
                                indices.Add(2 + offset);
                                indices.Add(3 + offset);
                                indices.Add(1 + offset);
                                indices.Add(0 + offset);
                            }

                            if (!HasNeighbor(boxel, BoxelFace.BOTTOM, relativePosition))
                            {
                                // Add the verts for the BOTTOM face.
                                vertices.Add(new BoxelVertex(btmLeftFrontb, color, normalBottom));
                                vertices.Add(new BoxelVertex(btmLeftBackb, color, normalBottom));
                                vertices.Add(new BoxelVertex(btmRightBackb, color, normalBottom));
                                vertices.Add(new BoxelVertex(btmLeftFrontb, color, normalBottom));
                                vertices.Add(new BoxelVertex(btmRightBackb, color, normalBottom));
                                vertices.Add(new BoxelVertex(btmRightFrontb, color, normalBottom));

                                int offset = verts.Count;

                                verts.Add(btmLeftFront);    // 0
                                verts.Add(btmLeftBack);     // 1
                                verts.Add(btmRightBack);    // 2
                                verts.Add(btmRightFront);   // 3

                                indices.Add(0 + offset);
                                indices.Add(1 + offset);
                                indices.Add(2 + offset);
                                indices.Add(3 + offset);
                                indices.Add(0 + offset);
                                indices.Add(2 + offset);
                            }

                            if (!HasNeighbor(boxel, BoxelFace.LEFT, relativePosition))
                            {
                                // Add the verts for the LEFT face.
                                vertices.Add(new BoxelVertex(topLeftFrontb, color, normalLeft));
                                vertices.Add(new BoxelVertex(btmLeftBackb, color, normalLeft));
                                vertices.Add(new BoxelVertex(btmLeftFrontb, color, normalLeft));
                                vertices.Add(new BoxelVertex(topLeftBackb, color, normalLeft));
                                vertices.Add(new BoxelVertex(btmLeftBackb, color, normalLeft));
                                vertices.Add(new BoxelVertex(topLeftFrontb, color, normalLeft));

                                int offset = verts.Count;

                                verts.Add(topLeftFront);    // 0
                                verts.Add(btmLeftBack);     // 1
                                verts.Add(btmLeftFront);    // 2
                                verts.Add(topLeftBack);     // 3

                                indices.Add(0 + offset);
                                indices.Add(1 + offset);
                                indices.Add(2 + offset);
                                indices.Add(3 + offset);
                                indices.Add(1 + offset);
                                indices.Add(0 + offset);
                            }

                            if (!HasNeighbor(boxel, BoxelFace.RIGHT, relativePosition))
                            {
                                // Add the verts for the RIGHT face.
                                vertices.Add(new BoxelVertex(topRightFrontb, color, normalRight));
                                vertices.Add(new BoxelVertex(btmRightFrontb, color, normalRight));
                                vertices.Add(new BoxelVertex(btmRightBackb, color, normalRight));
                                vertices.Add(new BoxelVertex(topRightBackb, color, normalRight));
                                vertices.Add(new BoxelVertex(topRightFrontb, color, normalRight));
                                vertices.Add(new BoxelVertex(btmRightBackb, color, normalRight));

                                int offset = verts.Count;

                                verts.Add(topRightFront);   // 0
                                verts.Add(btmRightFront);   // 1
                                verts.Add(btmRightBack);    // 2
                                verts.Add(topRightBack);    // 3

                                indices.Add(0 + offset);
                                indices.Add(1 + offset);
                                indices.Add(2 + offset);
                                indices.Add(3 + offset);
                                indices.Add(0 + offset);
                                indices.Add(1 + offset);
                            }
                        }
                    }
                }
            }

            if (vertices.Count > 0)
            {
                _vertexBuffer = new VertexBuffer(GameResources.GraphicsDevice, BoxelVertex.VertexDeclaration, vertices.Count, BufferUsage.None);
                _vertexBuffer.SetData(vertices.ToArray());

                _collisionMesh = new StaticMesh(verts.ToArray(), indices.ToArray());

                ChunkManager.Instance.FaceCount += indices.Count / 3;

                PhysicsManager.Instance.Space.Add(_collisionMesh);
            }
        }
예제 #20
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        /// 
        //add a model to scene - a LoadContent Helper method
        public void AddModel(Model model)
        {
            Vector3[] vertices;
            int[] indices;
            TriangleMesh.GetVerticesAndIndicesFromModel(model, out vertices, out indices);
            //Give the mesh information to a new StaticMesh.
            //Give it a transformation which scoots it down below the kinematic box entity we created earlier.
            var mesh = new StaticMesh(vertices, indices, new AffineTransform(new Vector3(0, -20, 0)));

            //Add it to the space!
            space.Add(mesh);
            //Make it visible too.
            Components.Add(new StaticModel(model, mesh.WorldTransform.Matrix, this));
        }
예제 #21
0
 ///<summary>
 /// Cleans up the manifold.
 ///</summary>
 public override void CleanUp()
 {
     mesh = null;
     convex = null;
     base.CleanUp();
 }
예제 #22
0
        /// <summary>
        /// Constructs a new demo.
        /// </summary>
        /// <param name="game">Game owning this demo.</param>
        public CharacterPlaygroundDemo(DemosGame game)
            : base(game)
        {
            game.Camera.Position = new Vector3(-10, 7, 5);
            game.Camera.Yaw = MathHelper.Pi;
            //Since this is the character playground, turn on the character by default.
            character.Activate();
            //Having the character body visible would be a bit distracting.
            character.CharacterController.Body.Tag = "noDisplayObject";

            //Load in mesh data for the environment.
            Vector3[] staticTriangleVertices;
            int[] staticTriangleIndices;

            var playgroundModel = game.Content.Load<Model>("CharacterControllerTestTerrain");
            //This is a little convenience method used to extract vertices and indices from a model.
            //It doesn't do anything special; any approach that gets valid vertices and indices will work.
            TriangleMesh.GetVerticesAndIndicesFromModel(playgroundModel, out staticTriangleVertices, out staticTriangleIndices);
            var staticMesh = new StaticMesh(staticTriangleVertices, staticTriangleIndices, new AffineTransform(new Vector3(.01f, .01f, .01f), Quaternion.Identity, new Vector3(0, 0, 0)));
            staticMesh.Sidedness = TriangleSidedness.Counterclockwise;

            Space.Add(staticMesh);
            game.ModelDrawer.Add(staticMesh);

            //Add a spinning blade for the character to ram itself into.
            var fanBase = new Cylinder(new Vector3(-13, .5f, 50), 1.1f, 1);
            var fanBlade = new Box(fanBase.Position + new Vector3(0, .8f, 0), 5, .1f, 1f, 5);
            var fanJoint = new RevoluteJoint(fanBase, fanBlade, (fanBase.Position + fanBlade.Position) * .5f, Vector3.Up);
            fanJoint.Motor.IsActive = true;
            fanJoint.Motor.Settings.VelocityMotor.GoalVelocity = 30;
            fanJoint.Motor.Settings.MaximumForce = 300;
            Space.Add(fanBase);
            Space.Add(fanBlade);
            Space.Add(fanJoint);

            //Add a bridge connecting the two towers.
            Vector3 startPosition = new Vector3(-19.3f, 10.5f - .25f, 23 - .85f);
            var startPlatform = new Box(startPosition - new Vector3(0, 0, 2.2f), 4, .5f, 6);
            Space.Add(startPlatform);
            Vector3 offset = new Vector3(0, 0, 1.7f);
            Box previousLink = startPlatform;
            Vector3 position = new Vector3();
            for (int i = 1; i <= 7; i++)
            {
                position = startPosition + offset * i;
                Box link = new Box(position, 3, .3f, 1.5f, 50);
                link.LinearDamping = .1f;
                link.AngularDamping = .1f;
                Space.Add(link);
                Space.Add(new RevoluteJoint(previousLink, link, position - offset * .5f, Vector3.Right));

                previousLink = link;
            }
            var endPlatform = new Box(position - new Vector3(0, 0, -3.8f), 4, .5f, 6);
            Space.Add(endPlatform);

            Space.Add(new RevoluteJoint(previousLink, endPlatform, position + offset * .5f, Vector3.Right));

            //Add in a floating platform controlled by a curve to serve as an elevator.
            Entity movingEntity = new Box(new Vector3(-10, 0, -10), 3, 1, 3);

            var positionCurve = new CardinalSpline3D();

            positionCurve.PreLoop = CurveEndpointBehavior.Mirror;
            positionCurve.PostLoop = CurveEndpointBehavior.Mirror;

            positionCurve.ControlPoints.Add(-1, new Vector3(-19.3f, 0, 43));
            positionCurve.ControlPoints.Add(0, new Vector3(-19.3f, 0, 43));
            positionCurve.ControlPoints.Add(2, new Vector3(-19.3f, 0, 43));
            positionCurve.ControlPoints.Add(3, new Vector3(-19.3f, 0, 43));
            positionCurve.ControlPoints.Add(4, new Vector3(-19.3f, 5, 43));
            positionCurve.ControlPoints.Add(5f, new Vector3(-19.3f, 10, 43));
            positionCurve.ControlPoints.Add(6f, new Vector3(-19.3f, 10, 43));
            positionCurve.ControlPoints.Add(8f, new Vector3(-19.3f, 10, 43));
            positionCurve.ControlPoints.Add(9f, new Vector3(-19.3f, 10, 43));

            elevatorMover = new EntityMover(movingEntity);
            Space.Add(elevatorMover);
            Space.Add(movingEntity);

            elevatorPath = positionCurve;

            //Add in another floating platform controlled by a curve for horizontal transport.
            movingEntity = new Box(new Vector3(-10, 0, -10), 2.5f, .5f, 2.5f);

            var platformCurve = new LinearInterpolationCurve3D();

            platformCurve.PreLoop = CurveEndpointBehavior.Mirror;
            platformCurve.PostLoop = CurveEndpointBehavior.Mirror;

            platformCurve.ControlPoints.Add(0, new Vector3(-1.75f, 10, 21.5f));
            platformCurve.ControlPoints.Add(2, new Vector3(-1.75f, 10, 21.5f));
            platformCurve.ControlPoints.Add(5, new Vector3(-1.75f, 10, 15.5f));
            platformCurve.ControlPoints.Add(10, new Vector3(-19.3f, 10, 15.5f));
            platformCurve.ControlPoints.Add(12, new Vector3(-19.3f, 10, 15.5f));
            platformCurve.ControlPoints.Add(15, new Vector3(-25, 10, 15.5f));
            platformCurve.ControlPoints.Add(22, new Vector3(-25, 10, 38));
            platformCurve.ControlPoints.Add(23, new Vector3(-22.75f, 10, 38));
            platformCurve.ControlPoints.Add(25, new Vector3(-22.75f, 10, 38));

            //Make it spin too.  That'll be fun.  Or something.
            var platformRotationCurve = new QuaternionSlerpCurve();
            platformRotationCurve.PreLoop = CurveEndpointBehavior.Mirror;
            platformRotationCurve.PostLoop = CurveEndpointBehavior.Mirror;
            platformRotationCurve.ControlPoints.Add(0, Quaternion.Identity);
            platformRotationCurve.ControlPoints.Add(15, Quaternion.Identity);
            platformRotationCurve.ControlPoints.Add(22, Quaternion.CreateFromAxisAngle(Vector3.Up, MathHelper.PiOver2));
            platformRotationCurve.ControlPoints.Add(25, Quaternion.CreateFromAxisAngle(Vector3.Up, MathHelper.PiOver2));

            platformMover = new EntityMover(movingEntity);
            platformRotator = new EntityRotator(movingEntity);
            Space.Add(platformMover);
            Space.Add(platformRotator);
            Space.Add(movingEntity);

            platformPath = platformCurve;
            platformOrientationPath = platformRotationCurve;

            //Add in a diving board.

            Box divingBoardBase = new Box(new Vector3(-9, 10, 39.3f), 5, 1, 3);
            Box divingBoard = new Box(divingBoardBase.Position + new Vector3(-2, 0, 3.5f), 1, .3f, 3, 5);
            var divingBoardJoint = new RevoluteJoint(divingBoardBase, divingBoard, divingBoard.Position + new Vector3(0, 0, -1.5f), Vector3.Right);
            divingBoardJoint.Motor.IsActive = true;
            divingBoardJoint.Motor.Settings.Mode = MotorMode.Servomechanism;
            divingBoardJoint.Motor.Settings.Servo.Goal = 0;
            divingBoardJoint.Motor.Settings.Servo.SpringSettings.StiffnessConstant = 5000;
            divingBoardJoint.Motor.Settings.Servo.SpringSettings.DampingConstant = 0;

            Space.Add(divingBoardBase);
            Space.Add(divingBoard);
            Space.Add(divingBoardJoint);

            //Add a second diving board for comparison.

            Box divingBoard2 = new Box(divingBoardBase.Position + new Vector3(2, 0, 5f), 1, .3f, 6, 5);
            var divingBoardJoint2 = new RevoluteJoint(divingBoardBase, divingBoard2, divingBoard2.Position + new Vector3(0, 0, -3), Vector3.Right);
            divingBoardJoint2.Motor.IsActive = true;
            divingBoardJoint2.Motor.Settings.Mode = MotorMode.Servomechanism;
            divingBoardJoint2.Motor.Settings.Servo.Goal = 0;
            divingBoardJoint2.Motor.Settings.Servo.SpringSettings.StiffnessConstant = 10000;
            divingBoardJoint2.Motor.Settings.Servo.SpringSettings.DampingConstant = 0;

            Space.Add(divingBoard2);
            Space.Add(divingBoardJoint2);

            //Add a seesaw for people to jump on.
            Box seesawBase = new Box(new Vector3(-7, .45f, 52), 1, .9f, .3f);
            Box seesawPlank = new Box(seesawBase.Position + new Vector3(0, .65f, 0), 1.2f, .2f, 6, 3);
            RevoluteJoint seesawJoint = new RevoluteJoint(seesawBase, seesawPlank, seesawPlank.Position, Vector3.Right);
            Space.Add(seesawJoint);
            Space.Add(seesawBase);
            Space.Add(seesawPlank);

            Space.Add(new Box(seesawPlank.Position + new Vector3(0, 1.3f, 2), 1, 1, 1, 5));

            //Add in some boxes to bump and jump on.
            int numColumns = 3;
            int numRows = 3;
            int numHigh = 3;
            float xSpacing = 1.01f;
            float ySpacing = 1.01f;
            float zSpacing = 1.01f;
            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(
                                                 5 + xSpacing * i - (numRows - 1) * xSpacing / 2f,
                                                 1.58f + k * (ySpacing),
                                                 45 + zSpacing * j - (numColumns - 1) * zSpacing / 2f),
                                             .5f, .5f, .5f, 5));
                    }

            //Add a log to roll!
            //Make it a compound so some boxes can be added to let the player know it's actually spinning.
            CompoundBody log = new CompoundBody(new List<CompoundShapeEntry>()
            {
                new CompoundShapeEntry(new CylinderShape(4, 1.8f), Quaternion.CreateFromAxisAngle(Vector3.Forward, MathHelper.PiOver2), 20),
                new CompoundShapeEntry(new BoxShape(.5f, .5f, 3.7f),  new Vector3(1.75f, 0,0), 0),
                new CompoundShapeEntry(new BoxShape(.5f, 3.7f, .5f), new Vector3(1.75f, 0,0), 0),
                new CompoundShapeEntry(new BoxShape(.5f, .5f, 3.7f),  new Vector3(-1.75f, 0,0), 0),
                new CompoundShapeEntry(new BoxShape(.5f, 3.7f, .5f), new Vector3(-1.75f, 0,0), 0)
            }, 50);
            log.Position = new Vector3(-14.5f, 10, 41);
            log.AngularDamping = 0;

            RevoluteJoint logJointA = new RevoluteJoint(divingBoardBase, log, log.Position + new Vector3(2.5f, 0, 0), Vector3.Right);
            RevoluteJoint logJointB = new RevoluteJoint(endPlatform, log, log.Position + new Vector3(-2.5f, 0, 0), Vector3.Right);
            Space.Add(logJointA);
            Space.Add(logJointB);

            Space.Add(log);

            //Put some planks to stand on that show various slopes.
            int numPads = 10;
            for (int i = 0; i < numPads; i++)
            {
                offset = new Vector3(0, 0, 4);
                Box a = new Box(new Vector3(i * 1.5f + 3.5f, 10, 24), 1.5f, 1, 4);
                Box b = new Box(new Vector3(i * 1.5f + 3.5f, 10, 24), 1.5f, 1, 4);
                float angle = -i * MathHelper.PiOver2 / numPads;
                b.Orientation = Quaternion.CreateFromAxisAngle(Vector3.Right, angle);
                b.Position += offset * .5f + Vector3.Transform(offset * .5f, b.Orientation);

                Space.Add(a);
                Space.Add(b);
            }
        }
예제 #23
0
파일: Chunk.cs 프로젝트: nasdf/Boxel-Engine
        public void Unload()
        {
            _vertexBuffer = null;

            if (_collisionMesh != null)
            {
                PhysicsManager.Instance.Space.Remove(_collisionMesh);

                _collisionMesh = null;
            }

            _isBuilt = false;
        }
예제 #24
0
        public void CreateLevel()
        {
            Vector3 levelScale = new Vector3(5);
            GameEntity entity = new GameEntity("environment");

            Entity locationHolder = new Box(Vector3.Zero, 1, 1, 1);
            entity.AddSharedData(typeof(Entity), locationHolder);

            Model roomModel = GetUnanimatedModel("Models\\welch");
            Vector3[] vertices;
            int[] indices;
            TriangleMesh.GetVerticesAndIndicesFromModel(roomModel, out vertices, out indices);
            StaticMesh roomMesh = new StaticMesh(vertices, indices, new AffineTransform(levelScale, Quaternion.Identity, Vector3.Zero));
            entity.AddSharedData(typeof(StaticMesh), roomMesh);

            StaticMeshComponent roomPhysics = new StaticMeshComponent(mainGame, entity);
            entity.AddComponent(typeof(StaticMeshComponent), roomPhysics);
            genComponentManager.AddComponent(roomPhysics);

            UnanimatedModelComponent graphics = new UnanimatedModelComponent(mainGame, entity, roomModel, levelScale, Vector3.Zero, 0, 0, 0);
            entity.AddComponent(typeof(UnanimatedModelComponent), graphics);
            modelManager.AddComponent(graphics);

            level = entity;

            Matrix transform = Matrix.CreateScale(levelScale) * Matrix.CreateRotationY(MathHelper.PiOver2);
            LevelTagData tag = roomModel.Tag as LevelTagData;
            if (tag != null)
            {
                List<Vector3> lightPoles = tag.lightPoleLocations;
                foreach (Vector3 vec in lightPoles)
                {
                    CreateLightPole(Vector3.Transform(vec, transform) + Vector3.Up * 15);
                }

                List<Vector3> cars = tag.cars;
                foreach (Vector3 vec in cars)
                {
                    CreateCar(Vector3.Transform(vec, transform) + Vector3.Up * 15);
                }

                List<Vector3> boxes1 = tag.mailbox1;
                foreach (Vector3 vec in boxes1)
                {
                    CreateMailbox1(Vector3.Transform(vec, transform) + Vector3.Up * 5);
                }

                List<Vector3> boxes2 = tag.mailbox2;
                foreach (Vector3 vec in boxes2)
                {
                    CreateMailbox2(Vector3.Transform(vec, transform) + Vector3.Up * 5);
                }

                List<Vector3> beer = tag.beer;
                foreach (Vector3 vec in beer)
                {
                    CreateBeer(Vector3.Transform(vec, transform) + Vector3.Up * 5);
                }

                CreateBeer(new Vector3(10000, 10000, 10000));
            }

            CreateSkybox();
        }
예제 #25
0
 private void ParameterChanged()
 {
     mPhysicsStaticMesh = null;
 }