Example #1
0
 // Returns a static mesh for the given model with the XNA/Blender rotation hack applied
 private StaticMesh GetTerrainMesh(BasicModel t, Matrix transform)
 {
     Vector3[] vertices;
     int[] indices;
     TriangleMesh.GetVerticesAndIndicesFromModel(terrain.model, out vertices, out indices);
     // rotate the computed vertices because of the blender to xna axis issue
     for (int i = 0; i < vertices.Count(); i++)
     {
         vertices[i] = Vector3.Transform(vertices[i], Matrix.CreateRotationX(-MathHelper.Pi / 2));
     }
     return new StaticMesh(vertices, indices, new AffineTransform(transform.Translation));
 }
Example #2
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);
            hudFont = Content.Load<SpriteFont>(@"hudFont");

            space = new Space();
            space.ForceUpdater.Gravity = new Vector3(0, -9.81f, 0);
            //space2 = new Space();
            //space2.ForceUpdater.Gravity = new Vector3(0, -9.81f, 0);

            terrain = new BasicModel(this, Content.Load<Model>(@"Models/terrain"), true);
            StaticMesh terrainMesh = GetTerrainMesh(terrain, Matrix.Identity);

            //terrainMesh.Material.StaticFriction = 0;
            //terrainMesh.Material.KineticFriction = 1;
            space.Add(terrainMesh);
            terrainMesh.Tag = terrain;

            // StaticMesh terrainMesh2 = GetTerrainMesh(terrain, Matrix.Identity);
            // space2.Add(terrainMesh2);

            // ferns
            for (int i = 0; i < 20; i++)
            {
                Vector3 position = getSafeSpawn(0);
                Console.WriteLine(position);
                BasicModel tree = new BasicModel(this, Content.Load<Model>(@"Models/fern"), position, true);
                StaticMesh treeMesh = GetTerrainMesh(tree, Matrix.CreateTranslation(position));
                Components.Add(tree);
            }

            // palm trees
            for (int i = 0; i < 5; i++)
            {
                Vector3 position = getSafeSpawn(0);
                Console.WriteLine(position);
                BasicModel tree = new BasicModel(this, Content.Load<Model>(@"Models/palmTree"), position, true);
                StaticMesh treeMesh = GetTerrainMesh(tree, Matrix.CreateTranslation(position));
                Components.Add(tree);
            }

            //adding character
            cube = new ControllableModel(this, Content.Load<Model>(@"Models/character"),
                    new Box(new Vector3(0, 10, 0), 1, 1, 1, 2));
            space.Add(cube.entity);
            cube.entity.Material.KineticFriction = 1;
            cube.entity.Tag = cube;

            //Adding skydome
            Matrix skyDomeRotate = Matrix.CreateRotationX(MathHelper.Pi);
            BasicModel skyDome = new BasicModel(this, Content.Load<Model>(@"Models/skyDome"), skyDomeRotate, true);

            //adding rings
            totalRings = 16;
            for (int i = 0; i < totalRings; i++ )
            {
                makeCoin(getSafeSpawn(r.Next(25,35)));
            }

            // baobab trees
            for (int i = 0; i < 5; i++)
            {
                Vector3 position = getSafeSpawn(0);
                BasicModel tree = new BasicModel(this, Content.Load<Model>(@"Models/baobabTree"),position,true);
                Cylinder treeBox =  new Cylinder(position, 10,3, 1);

                treeBox.Mass = float.PositiveInfinity;
                space.Add(treeBox);
                treeBox.Tag = tree;
                Components.Add(tree);
            }

            Components.Add(skyDome);
            Components.Add(terrain);
            Components.Add(cube);

            // turn off backface culling
            //RasterizerState rs = new RasterizerState();
            //rs.CullMode = CullMode.None;
            //GraphicsDevice.RasterizerState = rs;
        }