protected virtual void CreateRegularGrid(int xTiles, int yTiles)
 {
     using (MeshFactory fact = new MeshFactory())
     {
         Mesh grid = fact.CreateGrid(15, 15, xTiles, yTiles, true);
         CopyFromMesh(grid);
     }
 }
 public void CreateSquare()
 {
     using (MeshFactory factory = new MeshFactory())
     {
         Mesh mesh = factory.CreateSquare(2, 2);
         PrintMesh(mesh);
         mesh.Dispose();
     }
 }
 public void CreateSphereWithFactory()
 {
     using (MeshFactory factory = new MeshFactory())
     {
         Mesh mesh = factory.CreateSphere(1, 4, 4);
         PrintMesh(mesh);
         mesh.Dispose();
     }
 }
 public void CreateMassiveSphere()
 {
     using (MeshFactory factory = new MeshFactory())
     {
         Mesh mesh = factory.CreateSphere(3, 150, 100);
         Console.WriteLine("Sphere has: " + mesh.Vertices.Length + " vertices");
         mesh.Dispose();
     }
 }
 void AddCustomGeometry()
 {
     engine.Geometry.Clear();	// This clears any meshes created by the Engine
     using (MeshFactory factory = new MeshFactory())
     {
         Mesh mesh1 = factory.CreateGrid(4, 4, 4, 4,false);
         Mesh mesh2 = factory.CreateGrid(4, 4, 4, 4, false);
         mesh2.Translation = new Vector3(2, 0, 2);
         MeshOptimiser.AddMesh(mesh1, mesh2);
         engine.BindMesh(mesh1, 2);
     }
 }
        public void TestBoxCast()
        {
            Mesh mesh;
            using (MeshFactory factory = new MeshFactory())
            {
                mesh = factory.CreateBox(1,1,1);
                PrintMesh(mesh);
            }
            Vertex[] castVerts = mesh.Vertices.Select<Vertex, Vertex>(i => { return VertexTypes.Cast(i, typeof(VertexTypes.PositionNormalTextured)); }).ToArray();

            PrintArray(castVerts);
            mesh.Dispose();
        }
        private static void CreateShapes(Direct3DEngine engine)
        {
            Mesh mesh = CreateSimpleMesh();
            engine.Geometry.Add(mesh);
            mesh.BindToPass(engine.D3DDevice, engine.Effect, 1);
            using (MeshFactory factory = new MeshFactory())
            {
                mesh = factory.CreateSphere(0.5f, 12, 12);
                engine.Geometry.Add(mesh);
                mesh.BindToPass(engine.D3DDevice, engine.Effect, 2);

                mesh = factory.CreateTorus(0.5f, 2, 12, 20);
                engine.Geometry.Add(mesh);
                mesh.BindToPass(engine.D3DDevice, engine.Effect, 2);

                mesh = factory.CreateBox(1, 0, 1);
                engine.Geometry.Add(mesh);
                mesh.BindToPass(engine.D3DDevice, engine.Effect, 2);
            }
        }
 private void CreateAndBindMarkerSpheres()
 {
     using (MeshFactory fact = new MeshFactory())
     {
         float sphereHeight = 5;
         for(double y = -1; y <= 1; y+=0.5)
             for (double x = -1; x <= 1; x+=0.5)
             {
                 Mesh sphere = fact.CreateSphere(10, 10, 10);
                 sphere.Translation = new Vector3(DegreesToWorldUnits(x + initialCameraLocation.X), sphereHeight, DegreesToWorldUnits(y+initialCameraLocation.Y));
                 engine.BindMesh(sphere, "P2");
             }
     }
 }
        void OnInitComplete()
        {
            engine.CameraInput.Camera.FarZ = 12000;

            heightMap = ReadHgtFile(hgtFile, MapSize);

            landscape = new Landscape();
            //landscape.SplitFunction = SplitFromHeight;
            landscape.VisibleFunction = IsTriVisible;
            landscape.FetchFunction = MapFetchFunction;
            landscape.MAP_SIZE = heightMap.GetLength(0)-1;
            landscape.NUM_PATCHES_PER_SIDE = NumPatches;
            landscape.Init();
            landscape.Scale = new Vector3(1, 0.0005f, 1);
            landscape.BindToPass(engine.D3DDevice, engine.Effect, "Terrain");
            engine.Geometry.Add(landscape);

            using (MeshFactory fact = new MeshFactory())
                person = fact.CreateSphere(0.5f, 20, 20);

            float h = GetHeightAtPoint(2.5f,2.5f);

            person.Translation = new Vector3(2.5f, h+1, 2.5f);
            person.BindToPass(engine.D3DDevice, engine.Effect, 2);
            engine.Geometry.Add(person);

            engine.D3DDevice.FillMode = SlimDX.Direct3D10.FillMode.Wireframe;

            engine.CameraInput.LookAt(new Vector3(MapSize/2, 100, 0), new Vector3(MapSize/2, 0, MapSize/2));
        }
 void AddObject()
 {
     if (watch.ElapsedMilliseconds > 2000)
     {
         watch.Restart();
         Console.WriteLine("Add a shape");
         double x = 2 * rand.NextDouble() - 1;
         double y = 2 * rand.NextDouble() - 1;
         double z = 2 * rand.NextDouble() - 1;
         using (MeshFactory fact = new MeshFactory())
         {
             Mesh mesh = fact.CreateSphere(0.1f, 150, 150);
             mesh.Translation = new Vector3((float)x, (float)y, (float)z);
             mesh.BindToPass(engine.D3DDevice, engine.Effect, 2);
             engine.Geometry.Add(mesh);
         }
     }
 }
        void AddCustomGeometry()
        {
            engine.Geometry.Clear();	// This clears any meshes created by the Engine
            using (MeshFactory factory = new MeshFactory())
            {

                Mesh mesh = factory.CreateGrid(10, 10, 4, 4, true);
                mesh.Translation = new Vector3(0, -20, 0);
                engine.BindMesh(mesh, 2);

                mesh = factory.CreateBox(0.2f, 0.5f, 1);
                mesh.BindToPass(engine.D3DDevice, engine.Effect, 2);
                engine.Geometry.Add(mesh);
                mesh.Translation = new Vector3(-1, 0, 4);

                mesh = factory.CreateSquare(5, 5);
                mesh.Translation = new Vector3(0,1,0);
                mesh.BindToPass(engine.D3DDevice, engine.Effect, 2);
                engine.Geometry.Add(mesh);

                mesh = factory.CreateSphere(2, 50, 50);
                mesh.BindToPass(engine.D3DDevice, engine.Effect, 2);
                engine.Geometry.Add(mesh);
                mesh.Translation = new Vector3(4, 0, -1);

                //mesh = factory.CreateTeapot();
                //mesh.BindToPass(engine.D3DDevice, engine.Effect, "P2");
                //engine.Geometry.Add(mesh);

                mesh = new ExpandedPlane();
                (mesh as ExpandedPlane).Segments = new System.Drawing.Size(8, 8);
                mesh.Translation = new Vector3(0, -1, 0);
                mesh.Scale = new Vector3(10, 1, 10);
                engine.BindMesh(mesh, 2);
            }
        }