Exemplo n.º 1
0
        public Starfield()
        {
            var vertex_data = new VertexP3C4[num_stars];

            for (int i = 0; i < num_stars; i++)
            {
                vertex_data[i] = GetStar();
            }

            Mesh(new Mesh <VertexP3C4, uint>(vertex_data));
            Mode = PrimitiveType.Points;
        }
Exemplo n.º 2
0
        public Grid()
        {
            var amount   = 10;
            var space    = 100;
            var vertices = new VertexP3C4[4 + 4 * (2 * amount + 1)];

            vertices[0] = new VertexP3C4(0, 1000, 0, 1, 0, 0, 0.5f);
            vertices[1] = new VertexP3C4(0, 0, 0, 1, 1, 1, 0.5f);
            vertices[2] = new VertexP3C4(0, 0, 0, 1, 1, 1, 0.5f);
            vertices[3] = new VertexP3C4(0, -1000, 0, 1, 0, 0, 0.5f);
            for (var i = -amount; i <= amount; i++)
            {
                vertices[4 + 4 * (i + amount) + 0] = new VertexP3C4(amount * space, 0, i * space, 1, 1, 1, 0.5f);
                vertices[4 + 4 * (i + amount) + 1] = new VertexP3C4(-amount * space, 0, i * space, 1, 1, 1, 0.5f);
                vertices[4 + 4 * (i + amount) + 2] = new VertexP3C4(i * space, 0, amount * space, 1, 1, 1, 0.5f);
                vertices[4 + 4 * (i + amount) + 3] = new VertexP3C4(i * space, 0, -amount * space, 1, 1, 1, 0.5f);
            }

            Mesh(new Mesh <VertexP3C4, uint>(vertices));
            Mode = PrimitiveType.Lines;
        }
Exemplo n.º 3
0
        public Grid(float size, int width, int height)
        {
            Size   = size;
            Width  = width;
            Height = height;

            if (Root.Instance.UserInterface == null)
            {
                return;
            }

            fieldcount  = width * height;
            vertexcount = fieldcount * 4;
            data        = new VertexP3C4[vertexcount];
            int i = 0;

            material            = Material.CreateSimpleMaterial(null);
            material.DepthTest  = true;
            material.DepthWrite = true;
            material.Additive   = true;

            //float cy = 1.0f / (float)height * size;
            //float cy = 1.0f / (float)width * size;
            indices        = new IndexBuffer();
            indices.buffer = new int[fieldcount * 6];

            for (int y = 0; y < height; ++y)
            {
                float yp = (float)y * size - (size * height / 2);
                for (int x = 0; x < width; ++x)
                {
                    float   xp    = (float)x * size - (size * width / 2);
                    Color4f color = new Color4f(VecRandom.Instance.NextFloat(), VecRandom.Instance.NextFloat(), VecRandom.Instance.NextFloat(), 1);

                    data[i].Color        = color;
                    data[i].Position     = new Vector3(xp, 0, yp);
                    data[i + 1].Color    = color;
                    data[i + 1].Position = new Vector3(xp + size, 0, yp);

                    data[i + 2].Color    = color;
                    data[i + 2].Position = new Vector3(xp, 0, yp + size);
                    data[i + 3].Color    = color;
                    data[i + 3].Position = new Vector3(xp + size, 0, yp + size);

                    int idx = i / 4 * 6;
                    indices.buffer[idx]     = i;
                    indices.buffer[idx + 1] = i + 1;
                    indices.buffer[idx + 2] = i + 2;
                    indices.buffer[idx + 3] = i + 1;
                    indices.buffer[idx + 4] = i + 3;
                    indices.buffer[idx + 5] = i + 2;



                    i += 4;
                }
            }
            buffersize      = vertexcount * (3 + 4) * 4;
            vertices        = Root.Instance.UserInterface.Renderer.CreateDynamicVertexBuffer(buffersize);
            vertices.Format = VertexFormat.VF_P3C4;
            vertices.Update(data, buffersize);



            shader = Root.Instance.ResourceManager.LoadShader("simple3d.shader");
        }