Exemplo n.º 1
0
        void DrawBox(GraphicsDevice device, float bigY, float smallY, float x, float z, float size, Color c)
        {
            VertexPositionNormalColored[] verts = new VertexPositionNormalColored[8];
            for (int i = 0; i < 8; i++)
            {
                verts[i]        = new VertexPositionNormalColored();
                verts[i].Color  = c;
                verts[i].Normal = Vector3.Zero;
            }
            verts[0].Position = new Vector3(x, smallY, z);
            verts[1].Position = new Vector3(x + size, smallY, z);
            verts[2].Position = new Vector3(x + size, smallY, z + size);
            verts[3].Position = new Vector3(x, smallY, z + size);
            verts[4].Position = new Vector3(x, bigY, z);
            verts[5].Position = new Vector3(x + size, bigY, z);
            verts[6].Position = new Vector3(x + size, bigY, z + size);
            verts[7].Position = new Vector3(x, bigY, z + size);
            int[] indices = new int[18];
            indices[0] = 0;
            indices[1] = 1;
            indices[2] = 2;

            indices[3] = 1;
            indices[4] = 2;
            indices[5] = 3;

            indices[6] = 0;
            indices[7] = 4;
            indices[8] = 1;

            indices[9]  = 4;
            indices[10] = 5;
            indices[11] = 1;

            indices[12] = 4;
            indices[13] = 5;
            indices[14] = 6;

            indices[15] = 5;
            indices[16] = 6;
            indices[17] = 7;
            device.DrawUserIndexedPrimitives(PrimitiveType.TriangleList, verts, 0, 8, indices, 0, 6);
        }
Exemplo n.º 2
0
        void drawCameraFustrum(Camera c, GraphicsDevice d)
        {
            //Matrix inv = Matrix.Invert(c.view);
            Matrix inv = Matrix.CreateRotationX(c.pitch);

            inv = inv * Matrix.CreateRotationY(c.yaw);
            inv = inv * Matrix.CreateTranslation(c.pos);
            VertexPositionNormalColored[] verts = new VertexPositionNormalColored[8];
            verts[0].Position = Vector3.Transform(new Vector3(-.5f, .5f * c.aspect, 1.0f), inv);
            verts[1].Position = Vector3.Transform(new Vector3(.5f, .5f * c.aspect, 1.0f), inv);
            verts[2].Position = Vector3.Transform(new Vector3(-.5f, -.5f * c.aspect, 1.0f), inv);
            verts[3].Position = Vector3.Transform(new Vector3(.5f, -.5f * c.aspect, 1.0f), inv);
            verts[4].Position = Vector3.Transform(new Vector3(-.5f * c.farPlane, .5f * c.aspect * c.farPlane, c.farPlane), inv);
            verts[5].Position = Vector3.Transform(new Vector3(.5f * c.farPlane, .5f * c.aspect * c.farPlane, c.farPlane), inv);
            verts[6].Position = Vector3.Transform(new Vector3(-.5f * c.farPlane, -.5f * c.aspect * c.farPlane, c.farPlane), inv);
            verts[7].Position = Vector3.Transform(new Vector3(.5f * c.farPlane, -.5f * c.aspect * c.farPlane, c.farPlane), inv);
            for (int i = 0; i < 8; i++)
            {
                verts[i].Color = Color.Black;
            }
            int[] indices = new int[24];
            indices[0] = 0;
            indices[1] = 4;
            indices[2] = 6;

            indices[3] = 4;
            indices[4] = 6;
            indices[5] = 2;

            indices[6] = 0;
            indices[7] = 4;
            indices[8] = 5;

            indices[9]  = 1;
            indices[10] = 5;
            indices[11] = 4;

            indices[12] = 5;
            indices[13] = 7;
            indices[14] = 1;

            indices[15] = 5;
            indices[16] = 7;
            indices[17] = 3;

            indices[18] = 2;
            indices[19] = 6;
            indices[20] = 3;

            indices[21] = 2;
            indices[22] = 7;
            indices[23] = 3;

            effect.Begin();
            foreach (EffectPass pass in effect.CurrentTechnique.Passes)
            {
                pass.Begin();
                device.VertexDeclaration = terrain.dec;

                foreach (TerrainPatch patch in terrain.patches)
                {
                    device.DrawUserIndexedPrimitives(PrimitiveType.TriangleList, verts, 0, 8, indices, 0, 8);
                }
                pass.End();
            }
            effect.End();
        }