示例#1
0
        int indexCount;                       // counter para o numero de indices

        public ClsTerreno(GraphicsDevice device, ContentManager content, ClsCamara cam)
        {
            // Loading das texturas
            heightMap = content.Load <Texture2D>("lh3d1");
            relva     = content.Load <Texture2D>("sand-texture");
            // set da escala para a altura do terreno
            scale = 0.02f;
            // inicialização do efeito a usar
            effect                    = new BasicEffect(device); // instanciar
            effect.Projection         = cam.projectionMatrix;    // Projection matrix será universal
            effect.World              = Matrix.Identity;         // World Matrix representa a posição do objeto no espaço(3D)
            effect.View               = cam.viewMatrix;          // ViewMatrix será universal
            effect.VertexColorEnabled = false;                   // desligar as cores
            effect.TextureEnabled     = true;                    // ligar as texturas
            effect.Texture            = relva;                   // atribuir a relva como textura do terreno

            effect.AmbientLightColor = new Vector3(1, 1, 1);
            effect.LightingEnabled   = true;                                      // liga a iluminação
            effect.DirectionalLight0.DiffuseColor  = new Vector3(1, 1, 1);        // a red light
            effect.DirectionalLight0.Direction     = new Vector3(1, 0, 0);        // coming along the x-axis
            effect.DirectionalLight0.SpecularColor = new Vector3(0.8f, 1f, 0.8f); // with green highlights
            //effect.AmbientLightColor = new Vector3(0.5f, 0.5f, 0.5f);
            //effect.EmissiveColor = new Vector3(1, 1, 0);


            LoadHeightData(heightMap); // Metodo responsável pelos valores das alturas do terreno
            CreateVertices(device);    // Metodo responsável por criar os vértices e os respectivo buffer
            CreateIndices(device);     // Metodo responável por criar os indices e os respectivo buffer
        }
示例#2
0
 public void Draw(GraphicsDevice device, ClsCamara cam)
 {
     // World Matrix
     effect.View       = cam.viewMatrix;
     effect.Projection = cam.projectionMatrix;
     //Indica o efeito para desenhar os eixos
     effect.CurrentTechnique.Passes[0].Apply();
     device.DrawUserPrimitives <VertexPositionColor>(PrimitiveType.LineList, vertices, 0, 3);
 }
示例#3
0
        protected override void Initialize()
        {
            // TODO: Add your initialization logic here
            graphics.PreferredBackBufferWidth  = 480;
            graphics.PreferredBackBufferHeight = 800;

            cam = new ClsCamara(this, GraphicsDevice);

            eixos = new ClsEixos(GraphicsDevice, cam);

            terrain = new ClsTerreno(GraphicsDevice, Content, cam);
            //StartNewRound();
            tanks.Add(new ClsTank(GraphicsDevice, Content, new Vector3(64, 30, 64)));
            base.Initialize();
        }
示例#4
0
        public void DrawModel(ClsCamara cam)
        {
            // Draw the model
            foreach (ModelMesh mesh in model.Meshes)
            {
                foreach (BasicEffect effect in mesh.Effects)
                {
                    effect.World      = boneTransforms[mesh.ParentBone.Index];
                    effect.View       = cam.viewMatrix;
                    effect.Projection = cam.projectionMatrix;

                    effect.EnableDefaultLighting();
                }
                mesh.Draw();
            }
        }
示例#5
0
        public ClsEixos(GraphicsDevice device, ClsCamara cam)
        {
            // Vamos usar um efeito básico
            effect      = new BasicEffect(device);
            worldMatrix = cam.worldMatrix;
            // Calcula a aspectRatio, a view matrix e a projeção
            float aspectRatio = (float)device.Viewport.Width / device.Viewport.Height;

            // Matrix de view
            effect.View = cam.viewMatrix;
            // Matrix de perspective
            effect.Projection         = cam.projectionMatrix;
            effect.LightingEnabled    = false;
            effect.VertexColorEnabled = true;
            // Cria os eixos 3D
            CreateGeometry();
        }
示例#6
0
 public void Draw(GraphicsDevice device, ClsCamara cam)
 {
     // update da View e da Projection Matrix devido ao input do utilizador
     effect.View       = cam.viewMatrix;
     effect.Projection = cam.projectionMatrix;
     // definir o vertexBuffer e indexBuffer a usar;
     device.SetVertexBuffer(vertexBuffer);
     device.Indices = indexBuffer;
     effect.Texture = relva;
     effect.CurrentTechnique.Passes[0].Apply(); // apply das mudanças
     for (int i = 0; i < terrainWidth - 1; i++)
     {
         device.DrawIndexedPrimitives(
             PrimitiveType.TriangleStrip,
             0,                       // offset dos vértices
             i * 2 * terrainWidth,    // offset para desenhar as 127 strips
             (terrainWidth * 2) - 2); // numero de triangulos a desenhar. Largura*2 - 2 porque os dois primeiros vértices não desenham triangulo
     }
 }