Example #1
0
        public void Draw(GraphicsDevice graphicsDevice, Effect Effect, Matrix View, Matrix Proj, int L = 0)
        {
            if (model == null)
            {
                return;
            }
            // como uso el mismo modelo para todos los enemigos tengo que actualizar el esqueleto antes de dibujar
            // de paso computo los hitpoints
            computeHitpoints();
            // ahora si dibujo
            Matrix World = Matrix.CreateRotationY(MathF.PI / 2.0f) * CalcularMatrizOrientacion(Position - new Vector3(0, game.soldier_height / 2, 0), Direction);

            model.Draw(graphicsDevice, Effect, World, View, Proj, L);
        }
Example #2
0
        public void Draw(Matrix World, Matrix View, Matrix Proj)
        {
            device.SetVertexBuffer(VertexBuffer);
            Effect.CurrentTechnique = Effect.Techniques["Phong"];
            Effect.Parameters["World"].SetValue(World);
            Effect.Parameters["View"].SetValue(View);
            Effect.Parameters["Projection"].SetValue(Proj);
            Effect.Parameters["Lightmap"].SetValue(lightmap);

            //device.BlendState = BlendState.AlphaBlend;
            device.BlendState = BlendState.Opaque;

            // escenario estatico
            var pos = 0;

            for (var i = 0; i < cant_subsets; i++)
            {
                var cant_tri   = subset[i].cant_items;
                var cant_items = cant_tri * 3;
                if (cant_items > 0)
                {
                    if (mostrar_tools || !subset[i].image_name.StartsWith("TOOLS"))
                    //if (i == current_subset)
                    {
                        Effect.Parameters["ModelTexture"].SetValue(texture[i] != null ? texture[i] : texture_default);
                        foreach (var pass in Effect.CurrentTechnique.Passes)
                        {
                            pass.Apply();
                            device.DrawPrimitives(PrimitiveType.TriangleList, pos, cant_tri);
                        }
                    }
                    pos += cant_items;
                }
            }


            // modelos estaticos
            // primero layers opacos luego transparentes
            EffectMesh.CurrentTechnique = EffectMesh.Techniques["TextureDrawing"];
            device.BlendState           = BlendState.Opaque;
            for (var L = 0; L < 2; ++L)
            {
                for (var i = 0; i < cant_modelos; ++i)
                {
                    Matrix    world  = modelos[i].world();
                    CSMDModel p_mesh = mesh_pool.meshes[modelos[i].nro_mesh];
                    p_mesh.Draw(device, EffectMesh, world, View, Proj, L);
                }

                // paso al layer transparente
                // activo el Blend y desactivo el zwrite
                device.BlendState = BlendState.AlphaBlend;
                // mejor lo activo, porque como no puedo dibujar en orden correcto, crea muchos artifacts
                //device.DepthStencilState = DepthStencilState.DepthRead;
            }
            //device.DepthStencilState = DepthStencilState.Default;

            // decals
            Effect.CurrentTechnique  = Effect.Techniques["Phong"];
            device.BlendState        = BlendState.NonPremultiplied;
            device.DepthStencilState = DepthStencilState.DepthRead;
            device.SetVertexBuffer(decalsVertexBuffer);
            for (int i = 0; i < cant_decals; ++i)
            {
                if (!decals[i].blood)
                {
                    Effect.Parameters["ModelTexture"].SetValue(decals[i].texture != null ? decals[i].texture : texture_default);
                    foreach (var pass in Effect.CurrentTechnique.Passes)
                    {
                        pass.Apply();
                        device.DrawPrimitives(PrimitiveType.TriangleStrip, i * 4, 2);
                    }
                }
            }

            // sangre
            Effect.CurrentTechnique = Effect.Techniques["Blood"];
            for (int i = 0; i < cant_decals; ++i)
            {
                if (decals[i].blood)
                {
                    Effect.Parameters["ModelTexture"].SetValue(decals[i].texture != null ? decals[i].texture : texture_default);
                    foreach (var pass in Effect.CurrentTechnique.Passes)
                    {
                        pass.Apply();
                        device.DrawPrimitives(PrimitiveType.TriangleStrip, i * 4, 2);
                    }
                }
            }

            device.DepthStencilState = DepthStencilState.Default;

            // debug bbb
            if (cant_debug_bb > 0)
            {
                device.SetVertexBuffer(bbVertexBuffer);
                Effect.CurrentTechnique = Effect.Techniques["DebugBB"];
                foreach (var pass in Effect.CurrentTechnique.Passes)
                {
                    pass.Apply();
                    device.DrawPrimitives(PrimitiveType.TriangleList, 0, cant_debug_bb / 3);
                }
            }

            // env sprites
            EffectMesh.CurrentTechnique = EffectMesh.Techniques["SpriteDrawing"];
            var ant_blend_state = device.BlendState;

            device.BlendState = BlendState.Additive;
            var ant_z_state = device.DepthStencilState;
            var depthState  = new DepthStencilState();

            depthState.DepthBufferEnable      = true;
            depthState.DepthBufferWriteEnable = false;
            device.DepthStencilState          = depthState;

            EffectMesh.Parameters["View"].SetValue(Matrix.Identity);
            EffectMesh.Parameters["Projection"].SetValue(Proj);
            for (var i = 0; i < cant_sprites; ++i)
            {
                sprites[i].Draw(spriteVertexBuffer, EffectMesh, View);
            }


            device.BlendState        = ant_blend_state;
            device.DepthStencilState = ant_z_state;
        }
Example #3
0
        public void DrawMap(CPlayer player, CEnemy [] enemigo)
        {
            Vector3 Position  = player.Position;
            Vector3 Direction = player.Direction;

            Viewport ant_vp = device.Viewport;
            var      vp     = new Viewport();

            vp.X = 10;
            vp.Y = 50;
            float aspect = (float)ant_vp.Width / (float)ant_vp.Height;

            vp.Width               = vp.Height = 200;
            vp.MinDepth            = 0;
            vp.MaxDepth            = 1;
            device.Viewport        = vp;
            device.RasterizerState = RasterizerState.CullNone;

            device.DepthStencilState = DepthStencilState.None;
            Effect.CurrentTechnique  = Effect.Techniques["ClearScreen"];
            Effect.Parameters["World"].SetValue(Matrix.Identity);
            Effect.Parameters["View"].SetValue(Matrix.Identity);
            Effect.Parameters["Projection"].SetValue(Matrix.Identity);
            device.SetVertexBuffer(spriteVertexBuffer);
            foreach (var pass in Effect.CurrentTechnique.Passes)
            {
                pass.Apply();
                device.DrawPrimitives(PrimitiveType.TriangleList, 0, 2);
            }
            device.Clear(ClearOptions.DepthBuffer, Color.White, 1.0f, 0);

            Direction.Y = 0;
            Direction.Normalize();
            Matrix View  = Matrix.CreateLookAt(Position, Position + Direction * 100, new Vector3(0, 1, 0));
            Matrix World = Matrix.Identity;
            float  kx    = 1.0f / size.X;
            float  ky    = 1.0f / size.Y;
            float  kz    = 1.0f / size.Z;

            kx *= 5 * aspect;
            kz *= 5;
            Matrix S = new Matrix(-kx, 0, 0, 0,
                                  0, 0, ky, 0,
                                  0, -kz, 0, 0,
                                  0, 0, 0.5f, 1);

            Matrix Proj = S;

            device.SetVertexBuffer(VertexBuffer);
            Effect.CurrentTechnique = Effect.Techniques["Map"];
            Effect.Parameters["World"].SetValue(World);
            Effect.Parameters["View"].SetValue(View);
            Effect.Parameters["Projection"].SetValue(Proj);
            Effect.Parameters["Lightmap"].SetValue(lightmap);

            device.BlendState = BlendState.AlphaBlend;

            // escenario estatico
            var pos = 0;

            for (var i = 0; i < cant_subsets; i++)
            {
                var cant_tri   = subset[i].cant_items;
                var cant_items = cant_tri * 3;
                if (cant_items > 0)
                {
                    if (mostrar_tools || !subset[i].image_name.StartsWith("TOOLS"))
                    {
                        Effect.Parameters["ModelTexture"].SetValue(texture[i] != null ? texture[i] : texture_default);
                        foreach (var pass in Effect.CurrentTechnique.Passes)
                        {
                            pass.Apply();
                            device.DrawPrimitives(PrimitiveType.TriangleList, pos, cant_tri);
                        }
                    }
                    pos += cant_items;
                }
            }

            // modelos estaticos
            EffectMesh.CurrentTechnique = EffectMesh.Techniques["Map"];
            for (var L = 0; L < 1; ++L)
            {
                for (var i = 0; i < cant_modelos; ++i)
                {
                    Matrix    world  = modelos[i].world();
                    CSMDModel p_mesh = mesh_pool.meshes[modelos[i].nro_mesh];
                    p_mesh.Draw(device, EffectMesh, world, View, Proj, L);
                }
            }


            BeginDrawImage();
            int W = device.Viewport.Width;
            int H = device.Viewport.Height;

            // dibujo la posicion del cero
            device.BlendState = BlendState.Additive;
            DrawImage(0, W / 2, H / 2, 20, 20);

            // dibujo la pos. de los enemigos
            Matrix T = World * View * Proj;

            for (int i = 0; i < enemigo.Length; ++i)
            {
                Vector4 v = Vector4.Transform(enemigo[i].Position, T);
                if (v.W > 0)
                {
                    float x = v.X / v.W;
                    float y = v.Y / v.W;
                    float d = x * x + y * y;
                    if (d < 0.9f)
                    {
                        int xs = (int)(W * (0.5f + x / 2));
                        int ys = (int)(H * (0.5 - y / 2));
                        DrawImage(2, xs - 5, ys - 5, 10, 10);
                    }
                }
            }
            device.Viewport          = ant_vp;
            device.DepthStencilState = DepthStencilState.Default;
        }