Esempio n. 1
0
        public void VertexDeclaration()
        {
            vb = new VertexBuffer(typeof(CustomVertex.PositionNormalColored), 5, device, Usage.Dynamic | Usage.WriteOnly, CustomVertex.PositionNormalColored.Format, Pool.Default);

            //вершины содержат координаты, нормаль и цвет
            vertices    = new CustomVertex.PositionNormalColored[5];
            vertices[0] = new CustomVertex.PositionNormalColored(3f, 0f, 0f, 0f, 0f, 1f, Color.Cyan.ToArgb());
            vertices[1] = new CustomVertex.PositionNormalColored(0f, 3f, 0f, 0f, 0f, 1f, Color.Red.ToArgb());
            vertices[2] = new CustomVertex.PositionNormalColored(-3f, 0f, 0f, 0f, 0f, 1f, Color.Blue.ToArgb());
            vertices[3] = new CustomVertex.PositionNormalColored(-1f, -3f, 0f, 0f, 0f, 1f, Color.Magenta.ToArgb());
            vertices[4] = new CustomVertex.PositionNormalColored(1f, -3f, 0f, 0f, 0f, 1f, Color.Yellow.ToArgb());

            vb.SetData(vertices, 0, LockFlags.None);

            //индексный буфер показывает, как вершины объединить в треугольники
            ib      = new IndexBuffer(typeof(int), 9, device, Usage.WriteOnly, Pool.Default);
            indices = new int[9];

            indices[0] = 0;
            indices[1] = 1;
            indices[2] = 2;
            indices[3] = 4;
            indices[4] = 0;
            indices[5] = 2;
            indices[6] = 3;
            indices[7] = 4;
            indices[8] = 2;

            ib.SetData(indices, 0, LockFlags.None);

            ib = new IndexBuffer(typeof(int), indices.Length, device,
                                 Usage.WriteOnly, Pool.Default);

            ib.SetData(indices, 0, LockFlags.None);
        }
Esempio n. 2
0
        public int SetBuffer2D(S4Camera cam, CustomVertex.PositionNormalColored[] buf, int ptr)
        {
            if (!qBelow)
            {
                return(ptr);
            }
            for (int i = 0; i < Base.NF * 3; i += 3)
            {
                Vector3 v0 = Coords3D[Base.Faces[i]];
                Vector3 v1 = Coords3D[Base.Faces[i + 1]];
                Vector3 v2 = Coords3D[Base.Faces[i + 2]];
                if (v0.Z != WRONGPT && v1.Z != WRONGPT && v2.Z != WRONGPT)
                {
                    bool qinv = true;
#if true
                    Vector3 v1x = v1, v2x = v2;
                    v1x.Subtract(v0); v2x.Subtract(v0);
                    Vector3 n = new Vector3(v1x.Y * v2x.Z - v1x.Z * v2x.Y, v1x.Z * v2x.X - v1x.X * v2x.Z, v1x.X * v2x.Y - v1x.Y * v2x.X);
                    if (n.Z < 0)
                    {
                        n.Scale(-1f); qinv = false;
                    }
                    n.Z += n.Length() / 4;
                    n.Normalize();
#else
                    Vector3 n = new Vector3(0.91f, 0.3f, 0.3f);
#endif
                    buf[ptr++] = new CustomVertex.PositionNormalColored(v0, n, Col);
                    buf[ptr++] = new CustomVertex.PositionNormalColored(qinv ? v1 : v2, n, Col);
                    buf[ptr++] = new CustomVertex.PositionNormalColored(qinv ? v2 : v1, n, Col);
                }
            }
            return(ptr);
        }
Esempio n. 3
0
        void GenerateAllNormalsOfPolys(Polygon[] poly)
        {
            Vector3[] normals = new Vector3[poly.Length];

            for (int i = 0; i < poly.Length; i++)
            {
                Polygon p = poly[i];

                CustomVertex.PositionNormalColored v0 = p.vertex[0];
                CustomVertex.PositionNormalColored v1 = p.vertex[1];
                CustomVertex.PositionNormalColored v2 = p.vertex[2];

                Vector3 A = new Vector3(v2.X - v1.X, v2.Y - v1.Y, v2.Z - v1.Z);
                Vector3 B = new Vector3(v0.X - v1.X, v0.Y - v1.Y, v0.Z - v1.Z);

                normals[i] = Vector3.Cross(A, B);       //这个叉乘居然也是左手的?faint
                normals[i].Normalize();                 //必须标准化
            }

            for (int i = 0; i < poly.Length; i++)
            {
                for (int j = 0; j < poly[i].vertex.Length; j++)
                {
                    poly[i].vertex[j].Normal = normals[i];
                }
            }
        }
Esempio n. 4
0
        public override void Initialize( )
        {
            if (pointBuffer != null)
            {
                pointBuffer.Dispose();
            }

            //Create the vertex buffer
            pointBuffer = new AutoVertexBuffer(d3d, typeof(CustomVertex.PositionNormalColored), positions.Count,
                                               Usage.Dynamic, CustomVertex.PositionNormalColored.Format, Pool.Default);

            CustomVertex.PositionNormalColored[] verts = new CustomVertex.PositionNormalColored[positions.Count];

            int index = 0;

            foreach (CustomVertex.PositionColored vertex in positions)
            {
                verts[index].Position = vertex.Position;
                verts[index].Color    = vertex.Color;
                verts[index].Normal   = new Vector3(0, 0, 1);

                index++;
            }

            pointBuffer.VB.SetData(verts, 0, LockFlags.None);
        }
Esempio n. 5
0
        ////////////////////////////////////////////////////////////////////////////////////
        private void GenerateAllPartitionLines(Polygon[] p)
        {
            int total = 0;             //所有边总和(此处没有重复!)

            for (int i = 0; i < p.Length; i++)
            {
                total += p[i].vertex.Length;
            }

            pvexs = new CustomVertex.PositionColored[total * 2];

            int pos = 0;

            for (int i = 0; i < p.Length; i++)
            {
                Polygon pi = p[i];
                for (int j = 0; j < pi.vertex.Length; j++)
                {
                    CustomVertex.PositionNormalColored from = pi.vertex[j];
                    CustomVertex.PositionNormalColored to   = pi.vertex[(j + 1) % pi.vertex.Length];

                    pvexs[pos++] = new CustomVertex.PositionColored(from.X, from.Y, from.Z, color.ToArgb());
                    pvexs[pos++] = new CustomVertex.PositionColored(to.X, to.Y, to.Z, color.ToArgb());
                }
            }
        }
Esempio n. 6
0
        private RenderDataSource createRenderDataSourceFromNodes(CNode rdsNode, CNode dbNode)
        {
            MiscUtil.Conversion.BigEndianBitConverter bc       = new MiscUtil.Conversion.BigEndianBitConverter();
            CustomVertex.PositionNormalColored[]      vertices = new CustomVertex.PositionNormalColored[(int)dbNode.attributes["elementCount"].data];

            Vector3 pos = new Vector3();
            int     color;
            Vector3 normal      = new Vector3();
            int     vertexCount = 0;

            for (int i = 0; i < (int)dbNode.attributes["size"].data; i += 28)
            {
                pos.X = bc.ToSingle(dbNode.subNodes[3].data, i);
                pos.Y = bc.ToSingle(dbNode.subNodes[3].data, i + 4);
                pos.Z = bc.ToSingle(dbNode.subNodes[3].data, i + 8);

                color = bc.ToInt32(dbNode.subNodes[3].data, i + 12);

                normal.X = bc.ToSingle(dbNode.subNodes[3].data, i + 16);
                normal.Y = bc.ToSingle(dbNode.subNodes[3].data, i + 20);
                normal.Z = bc.ToSingle(dbNode.subNodes[3].data, i + 24);

                vertices[vertexCount] = new CustomVertex.PositionNormalColored(pos, normal, color);
                vertexCount++;
            }

            int indexCount = (int)rdsNode.subNodes[0].attributes["count"].data;

            ushort[] indices = new ushort[indexCount];
            for (int i = 0; i < indexCount; i++)
            {
                indices[i] = bc.ToUInt16(rdsNode.subNodes[0].subNodes[0].data, i * 2);
            }
            return(new RenderDataSource(rdsNode.attributes["id"].value, vertices, indices));
        }
Esempio n. 7
0
        void ColoredByCategory(int category, ref CustomVertex.PositionNormalColored vex)
        {
            switch (category)
            {
            case 0:                     //陆地
                vex.Color = Color.DarkOrange.ToArgb();
                break;

            case 1:                     //雪地
                vex.Color = Color.White.ToArgb();
                break;

            case 2:                     //深水
                vex.Color = Color.Blue.ToArgb();
                break;

            case 3:                     //浅水
                vex.Color = Color.LightBlue.ToArgb();
                break;

            case 4:                     //无
                vex.Color = Color.RoyalBlue.ToArgb();
                break;

            default:
                Debug.Assert(false);
                break;
            }
        }
Esempio n. 8
0
        void ColoredByEnterable(int enterable, ref CustomVertex.PositionNormalColored vex)
        {
            float m     = 0F;
            Color c     = Color.FromArgb(vex.Color);
            int   red   = (int)(c.R * m);
            int   green = (int)(c.G * m);
            int   blue  = (int)(c.B * m);

            if (enterable == 0x4)
            {
                vex.Color = Color.FromArgb(red, green, blue).ToArgb();
            }
            if (enterable == 0x10)
            {
                vex.Color = Color.FromArgb(red, green, blue).ToArgb();
            }
            if (enterable == 0x14)
            {
                vex.Color = Color.FromArgb(red, green, blue).ToArgb();
            }
            if (enterable == 0x16)
            {
                vex.Color = Color.FromArgb(red, green, blue).ToArgb();
            }
        }
Esempio n. 9
0
        protected CustomVertex.PositionNormalColored[] CreateCube()
        {
            float X2 = 0.5f;
            float Y2 = 0.2f;
            float Z2 = 1.0f;

            CustomVertex.PositionNormalColored[] verts = new CustomVertex.PositionNormalColored[36];
            //Front face.
            verts[0] = new CustomVertex.PositionNormalColored(new Vector3(-X2, Y2, Z2), new Vector3(0, 0, 1), _cubecolor.ToArgb());
            verts[1] = new CustomVertex.PositionNormalColored(new Vector3(-X2, -Y2, Z2), new Vector3(0, 0, 1), _cubecolor.ToArgb());
            verts[2] = new CustomVertex.PositionNormalColored(new Vector3(X2, Y2, Z2), new Vector3(0, 0, 1), _cubecolor.ToArgb());
            verts[3] = new CustomVertex.PositionNormalColored(new Vector3(-X2, -Y2, Z2), new Vector3(0, 0, 1), _cubecolor.ToArgb());
            verts[4] = new CustomVertex.PositionNormalColored(new Vector3(X2, -Y2, Z2), new Vector3(0, 0, 1), _cubecolor.ToArgb());
            verts[5] = new CustomVertex.PositionNormalColored(new Vector3(X2, Y2, Z2), new Vector3(0, 0, 1), _cubecolor.ToArgb());

            //Back face.  This is facing away from the camera, so vertices should be clockwise order.
            verts[6]  = new CustomVertex.PositionNormalColored(new Vector3(-X2, Y2, -Z2), new Vector3(0, 0, -1), _cubecolor.ToArgb());
            verts[7]  = new CustomVertex.PositionNormalColored(new Vector3(X2, Y2, -Z2), new Vector3(0, 0, -1), _cubecolor.ToArgb());
            verts[8]  = new CustomVertex.PositionNormalColored(new Vector3(-X2, -Y2, -Z2), new Vector3(0, 0, -1), _cubecolor.ToArgb());
            verts[9]  = new CustomVertex.PositionNormalColored(new Vector3(-X2, -Y2, -Z2), new Vector3(0, 0, -1), _cubecolor.ToArgb());
            verts[10] = new CustomVertex.PositionNormalColored(new Vector3(X2, Y2, -Z2), new Vector3(0, 0, -1), _cubecolor.ToArgb());
            verts[11] = new CustomVertex.PositionNormalColored(new Vector3(X2, -Y2, -Z2), new Vector3(0, 0, -1), _cubecolor.ToArgb());

            //Top face.
            verts[12] = new CustomVertex.PositionNormalColored(new Vector3(-X2, Y2, Z2), new Vector3(0, 1, 0), _cubecolor.ToArgb());
            verts[13] = new CustomVertex.PositionNormalColored(new Vector3(X2, Y2, -Z2), new Vector3(0, 1, 0), _cubecolor.ToArgb());
            verts[14] = new CustomVertex.PositionNormalColored(new Vector3(-X2, Y2, -Z2), new Vector3(0, 1, 0), _cubecolor.ToArgb());
            verts[15] = new CustomVertex.PositionNormalColored(new Vector3(-X2, Y2, Z2), new Vector3(0, 1, 0), _cubecolor.ToArgb());
            verts[16] = new CustomVertex.PositionNormalColored(new Vector3(X2, Y2, Z2), new Vector3(0, 1, 0), _cubecolor.ToArgb());
            verts[17] = new CustomVertex.PositionNormalColored(new Vector3(X2, Y2, -Z2), new Vector3(0, 1, 0), _cubecolor.ToArgb());

            //Bottom face. This is facing away from the camera, so vertices should be clockwise order.
            verts[18] = new CustomVertex.PositionNormalColored(new Vector3(-X2, -Y2, Z2), new Vector3(0, -1, 0), _cubecolor.ToArgb());
            verts[19] = new CustomVertex.PositionNormalColored(new Vector3(-X2, -Y2, -Z2), new Vector3(0, -1, 0), _cubecolor.ToArgb());
            verts[20] = new CustomVertex.PositionNormalColored(new Vector3(X2, -Y2, -Z2), new Vector3(0, -1, 0), _cubecolor.ToArgb());
            verts[21] = new CustomVertex.PositionNormalColored(new Vector3(-X2, -Y2, Z2), new Vector3(0, -1, 0), _cubecolor.ToArgb());
            verts[22] = new CustomVertex.PositionNormalColored(new Vector3(X2, -Y2, -Z2), new Vector3(0, -1, 0), _cubecolor.ToArgb());
            verts[23] = new CustomVertex.PositionNormalColored(new Vector3(X2, -Y2, Z2), new Vector3(0, -1, 0), _cubecolor.ToArgb());

            //Left face.
            verts[24] = new CustomVertex.PositionNormalColored(new Vector3(-X2, Y2, Z2), new Vector3(-1, 0, 0), _cubecolor.ToArgb());
            verts[25] = new CustomVertex.PositionNormalColored(new Vector3(-X2, -Y2, -Z2), new Vector3(-1, 0, 0), _cubecolor.ToArgb());
            verts[26] = new CustomVertex.PositionNormalColored(new Vector3(-X2, -Y2, Z2), new Vector3(-1, 0, 0), _cubecolor.ToArgb());
            verts[27] = new CustomVertex.PositionNormalColored(new Vector3(-X2, Y2, -Z2), new Vector3(-1, 0, 0), _cubecolor.ToArgb());
            verts[28] = new CustomVertex.PositionNormalColored(new Vector3(-X2, -Y2, -Z2), new Vector3(-1, 0, 0), _cubecolor.ToArgb());
            verts[29] = new CustomVertex.PositionNormalColored(new Vector3(-X2, Y2, Z2), new Vector3(-1, 0, 0), _cubecolor.ToArgb());

            //Right face. This is facing away from the camera, so vertices should be clockwise order.
            verts[30] = new CustomVertex.PositionNormalColored(new Vector3(X2, Y2, Z2), new Vector3(1, 0, 0), _cubecolor.ToArgb());
            verts[31] = new CustomVertex.PositionNormalColored(new Vector3(X2, -Y2, Z2), new Vector3(1, 0, 0), _cubecolor.ToArgb());
            verts[32] = new CustomVertex.PositionNormalColored(new Vector3(X2, -Y2, -Z2), new Vector3(1, 0, 0), _cubecolor.ToArgb());
            verts[33] = new CustomVertex.PositionNormalColored(new Vector3(X2, Y2, -Z2), new Vector3(1, 0, 0), _cubecolor.ToArgb());
            verts[34] = new CustomVertex.PositionNormalColored(new Vector3(X2, Y2, Z2), new Vector3(1, 0, 0), _cubecolor.ToArgb());
            verts[35] = new CustomVertex.PositionNormalColored(new Vector3(X2, -Y2, -Z2), new Vector3(1, 0, 0), _cubecolor.ToArgb());

            return(verts);
        }
Esempio n. 10
0
        public void VertexDeclaration()
        {
            vb = new VertexBuffer(typeof(CustomVertex.PositionNormalColored), 5, device, Usage.Dynamic | Usage.WriteOnly, CustomVertex.PositionNormalColored.Format, Pool.Default);

            //вершины содержат координаты, нормаль и цвет
            float a = 0.0f; //координата Y первой точки
            float b = 3.0f; //Длина стороны
            float c = 0.0f; //смещение параллельной стороны относительно начальной стороны по Oy
            float d = 5.0f; //смещение параллельной стороны относительно начальной стороны по Ox

            vertices    = new CustomVertex.PositionNormalColored[5];
            vertices[0] = new CustomVertex.PositionNormalColored(0f, a, 0f, 0f, 0f, 1f, Color.Cyan.ToArgb());
            vertices[1] = new CustomVertex.PositionNormalColored(0f, a + b, 0f, 0f, 0f, 1f, Color.Red.ToArgb());
            vertices[2] = new CustomVertex.PositionNormalColored(d, c + a, 0f, 0f, 0f, 1f, Color.Blue.ToArgb());
            vertices[3] = new CustomVertex.PositionNormalColored(d, c + a + b, 0f, 0f, 0f, 1f, Color.Magenta.ToArgb());
            vertices[4] = new CustomVertex.PositionNormalColored(0f, 0f, 5f, 0f, 0f, 1f, Color.Green.ToArgb());

            vb.SetData(vertices, 0, LockFlags.None);

            //индексный буфер показывает, как вершины объединить в треугольники
            ib      = new IndexBuffer(typeof(int), 18, device, Usage.WriteOnly, Pool.Default);
            indices = new int[18];

            //дно - по часовой стрелке
            indices[0] = 0;
            indices[1] = 2;
            indices[2] = 1;
            indices[3] = 1;
            indices[4] = 2;
            indices[5] = 3;

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

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

            indices[12] = 3;
            indices[13] = 2;
            indices[14] = 4;

            indices[15] = 2;
            indices[16] = 0;
            indices[17] = 4;



            ib.SetData(indices, 0, LockFlags.None);

            ib = new IndexBuffer(typeof(int), indices.Length, device,
                                 Usage.WriteOnly, Pool.Default);

            ib.SetData(indices, 0, LockFlags.None);
        }
Esempio n. 11
0
        ////////////////////////////////////////////////////////////////////////////////////
        #region 基于地形属性进行顶点着色
        void ColoredByIllumination(int brightness, ref CustomVertex.PositionNormalColored vex)
        {
            float m     = (255 - brightness) / (float)255;
            Color c     = Color.FromArgb(vex.Color);
            int   red   = (int)(c.R * m);
            int   green = (int)(c.G * m);
            int   blue  = (int)(c.B * m);

            vex.Color = Color.FromArgb(red, green, blue).ToArgb();
        }
Esempio n. 12
0
        //This method mainly initializes the items in the buffers
        private void OnVertexBufferCreate(object sender, EventArgs e)
        {
            VertexBuffer buffer = (VertexBuffer)sender;

            CustomVertex.PositionNormalColored[] verts = new CustomVertex.PositionNormalColored[108];

            float angle = (float)(Math.PI / 2);
            float change = (float)((2 * Math.PI) / 36);
            float x, z;

            Vector3 top = new Vector3(0.0f, 2.0f, 0.0f);

            //first triangle
            for (int i = 0, j = 0; i < 108; i++, j++)
            {
                if (i % 3 == 0)
                {
                    verts[i].Position = top;
                    if (i != 0)
                    {
                        verts[i - 1].Normal = Vector3.Normalize(Vector3.Cross(Vector3.Subtract(top, verts[i - 1].Position), Vector3.Subtract(verts[i - 2].Position, verts[i - 1].Position)));
                        if (i != 3)
                        {
                            verts[i - 2].Normal = verts[i - 4].Normal;
                        }
                    }
                }
                else
                {
                    x = (float)Math.Cos((double)angle);
                    z = (float)Math.Sin((double)angle);
                    verts[i].Position = new Vector3((2 * x), -1.0f, (2 * z));
                    verts[i].Color    = System.Drawing.Color.White.ToArgb();
                    verts[i].Normal   = new Vector3(0.0f, 1.0f, 0.0f);
                }

                if (j == 1)
                {
                    angle -= change;
                }
                if (j == 2)
                {
                    j = -1;
                }
            }
            //last 2 pair of vertices (base of last triangle) are not given a normal in the loop (normal assignment happens at the start of every new triangle
            verts[107].Normal = Vector3.Normalize(Vector3.Cross(Vector3.Subtract(top, verts[107].Position), Vector3.Subtract(verts[106].Position, verts[107].Position)));
            verts[106].Normal = verts[104].Normal;
            //Since 2nd vertex of a triangle's normal is not assigned in loop (2nd vertex assignment happens from the 2nd triangle onwards
            verts[1].Normal = verts[107].Normal;

            //transfer the vertices data to the buffer
            buffer.SetData(verts, 0, LockFlags.None);
        }
Esempio n. 13
0
        public void UpdateDisplayedPoint(Vector3 newPoint)
        {
            CustomVertex.PositionNormalColored vertex = new CustomVertex.PositionNormalColored();

            model.Position = newPoint;

            vertex.Position = model.Position;
            vertex.Color    = model.ModelColor.ToArgb();
            vertex.Normal   = Direct3dRender.DefaultVertexNormal;
            pointBuffer.VB.SetData(vertex, 0, LockFlags.None);
        }
Esempio n. 14
0
        //计算多边形在XOY平面上投影的面积
        float GetAreaOfXY()
        {
            float result = 0.0F;

            for (int i = 0; i < vertex.Length; i++)
            {
                CustomVertex.PositionNormalColored from = vertex[i];
                CustomVertex.PositionNormalColored to   = vertex[(i + 1) % vertex.Length];
                result += (to.X - from.X) * (to.Y + from.Y) / 2;
            }

            return(-result);            //注意符号问题!
        }
Esempio n. 15
0
 public void AllocateMemory(int quadsCount)
 {
     if (vertex == null)
     {
         vertex = new CustomVertex.PositionNormalColored[4 * quadsCount];
         for (int i = 0; i < vertex.Length; i++)
         {
             vertex[i] = new CustomVertex.PositionNormalColored(new Vector3(0, 0, 0), new Vector3(0, 0, 0), 0);
         }
     }
     if (indices == null)
     {
         indices = new short[6 * quadsCount];
     }
 }
Esempio n. 16
0
        ////////////////////////////////////////////////////////////////////////////////////
        private void GenerateSelectionLines()
        {
            pvexs = new CustomVertex.PositionColored[poly.vertex.Length * 2];

            int pos = 0;

            for (int i = 0; i < poly.vertex.Length; i++)
            {
                CustomVertex.PositionNormalColored from = poly.vertex[i];
                CustomVertex.PositionNormalColored to   = poly.vertex[(i + 1) % poly.vertex.Length];

                pvexs[pos++] = new CustomVertex.PositionColored(from.Position, Color.Aqua.ToArgb());;
                pvexs[pos++] = new CustomVertex.PositionColored(to.Position, Color.Aqua.ToArgb());;
            }
        }
Esempio n. 17
0
 public int SetBuffer1D(S4Camera cam, CustomVertex.PositionNormalColored[] buf, int ptr, int col)
 {
     if (!qBelow)
     {
         return(ptr);
     }
     for (int i = 0; i < Base.NE * 2; i += 2)
     {
         Vector3 v0 = Coords3D[Base.Edges[i]];
         Vector3 v1 = Coords3D[Base.Edges[i + 1]];
         if (v0.Z != WRONGPT && v1.Z != WRONGPT)
         {
             buf[ptr++] = new CustomVertex.PositionNormalColored(v0, new Vector3(0, 0, 1), col);
             buf[ptr++] = new CustomVertex.PositionNormalColored(v1, new Vector3(0, 0, 1), col);
         }
     }
     return(ptr);
 }
Esempio n. 18
0
        public void InitDevice()
        {
            PresentParameters pp = new PresentParameters();

            pp.Windowed   = true;
            pp.SwapEffect = SwapEffect.Discard;
            device        = new Device(0, DeviceType.Hardware, this, CreateFlags.HardwareVertexProcessing, pp);
            device.Transform.Projection = Matrix.PerspectiveFovLH(3.14f / 4, device.Viewport.Width / device.Viewport.Height, 1f, 1000f);
            device.Transform.View       = Matrix.LookAtLH(new Vector3(0, 0, 10), new Vector3(), new Vector3(0, 1, 0));
            device.RenderState.Lighting = false;
            vertex[0] = new CustomVertex.PositionNormalColored(new Vector3(0, 1, 1), new Vector3(1, 0, 1), Color.Red.ToArgb());
            vertex[1] = new CustomVertex.PositionNormalColored(new Vector3(-1, -1, 1), new Vector3(1, 0, 1), Color.Red.ToArgb());
            vertex[2] = new CustomVertex.PositionNormalColored(new Vector3(1, -1, 1), new Vector3(-1, 0, 1), Color.Red.ToArgb());
            device.RenderState.Lighting = true;
            device.Lights[0].Type       = LightType.Directional;
            device.Lights[0].Diffuse    = Color.Plum;
            device.Lights[0].Direction  = new Vector3(0.8f, 0, -1);
            device.Lights[0].Enabled    = true;
        }
Esempio n. 19
0
        Polygon GeneratePolyPos(int idx)
        {
            District d = sec.districts[idx];

            CustomVertex.PositionNormalColored[] v = new CustomVertex.PositionNormalColored[d.num_borders];

            for (int i = d.num_borders - 1; i >= 0; i--)             //右手系->左手系
            {
                Border b = d.borders[i];
                float  z = b.to.x * d.tanX + b.to.y * d.tanY + d.M;

                //这里的-z是将右手系->左手系
                v[d.num_borders - 1 - i]          = new CustomVertex.PositionNormalColored();
                v[d.num_borders - 1 - i].Position = new Vector3(b.to.x, b.to.y, -z);

                if (att_color)
                {
                    //根据区域的地形特征来着色
                    ColoredByCategory(d.attributes[0], ref v[d.num_borders - 1 - i]);
                    ColoredBySubCategory(d.attributes[1], ref v[d.num_borders - 1 - i]);

                    //根据区域是否可进入来着色
                    ColoredByEnterable(d.attributes[4], ref v[d.num_borders - 1 - i]);

                    //根据区域亮度来着色
                    ColoredByIllumination(d.attributes[5], ref v[d.num_borders - 1 - i]);

                    //对边缘上的框架区域着色
                    if (d.attributes[6] == 0x2)
                    {
                        v[d.num_borders - 1 - i].Color = 0x25;                        //非常深的蓝色
                    }
                }
                else
                {
                    v[d.num_borders - 1 - i].Color = color.ToArgb();
                }
            }

            return(new Polygon(v));
        }
Esempio n. 20
0
        //将四边形简化为线、三角形或者是四边形
        CustomVertex.PositionNormalColored[] SimplifyQuadrangle(CustomVertex.PositionNormalColored[] poly4, int offset, float epsilon)
        {
            //poly4为左手系
            CustomVertex.PositionNormalColored v0 = poly4[offset];
            CustomVertex.PositionNormalColored v1 = poly4[offset + 1];
            CustomVertex.PositionNormalColored v2 = poly4[offset + 2];
            CustomVertex.PositionNormalColored v3 = poly4[offset + 3];

            int total = 4;

            bool[] m = new bool[4] {
                true, true, true, true
            };

            if (Math.Abs(v0.Z - v3.Z) < epsilon)
            {
                //合并0-3
                total--;
                m[0] = false;
            }
            if (Math.Abs(v1.Z - v2.Z) < epsilon)
            {
                //合并1-2
                total--;
                m[1] = false;
            }

            CustomVertex.PositionNormalColored[] v = new CustomVertex.PositionNormalColored[total];
            int pos = 0;

            for (int i = 0; i < 4; i++)
            {
                if (m[i])
                {
                    v[pos++] = poly4[offset + i];
                }
            }

            return(v);            //简化成线、三角形或者是四边形
        }
        //This method mainly initializes the items in the buffers
        private void OnVertexBufferCreate(object sender, EventArgs e)
        {
            VertexBuffer buffer = (VertexBuffer)sender;

            CustomVertex.PositionNormalColored[] verts = new CustomVertex.PositionNormalColored[3];

            //first triangle
            verts[0].Position = new Vector3(0.0f, 1.0f, 0.0f);
            verts[0].Normal   = new Vector3(0.0f, 0.0f, -1.0f);
            verts[0].Color    = System.Drawing.Color.Purple.ToArgb();

            verts[1].Position = new Vector3(-1.0f, -1.0f, 1.0f);
            verts[1].Normal   = new Vector3(0.0f, 0.0f, -1.0f);
            verts[1].Color    = System.Drawing.Color.Pink.ToArgb();

            verts[2].Position = new Vector3(1.0f, -1.0f, 1.0f);
            verts[2].Normal   = new Vector3(0.0f, 0.0f, -1.0f);
            verts[2].Color    = System.Drawing.Color.Black.ToArgb();

            //transfer the vertices data to the buffer
            buffer.SetData(verts, 0, LockFlags.None);
        }
Esempio n. 22
0
        public void create(XYZTrianglesList l, Device device)
        {
            // free previous buffer
            if (vertexBuffer != null)
            {
                vertexBuffer.Dispose();
                vertexBuffer = null;
            }

            primitiveCount = l.getTrianglesCount();
            if (primitiveCount == 0)
            {
                // "new VertexBuffer" causes exception if vertex count is 0
                return;
            }
            vertexBuffer = new VertexBuffer(typeof(CustomVertex.PositionNormalColored),
                                            l.getTrianglesCount() * 3, device, 0, CustomVertex.PositionNormalColored.Format, Pool.Default);

            GraphicsStream stm = vertexBuffer.Lock(0, 0, 0);

            CustomVertex.PositionNormalColored[] verts = new CustomVertex.PositionNormalColored[l.getTrianglesCount() * 3];

            // set triangle points
            for (int i = 0; i < l.getVertexCount(); i++)
            {
                Vec3 pos = l.getXYZ(i);
                verts[i].X = (float)pos.getX();
                verts[i].Y = (float)pos.getY();
                verts[i].Z = (float)pos.getZ();
                Vec3 normal;
                l.calcTriangleNormal(i / 3, out normal);
                verts[i].Nx    = (float)normal.getX();
                verts[i].Ny    = (float)normal.getY();
                verts[i].Nz    = (float)normal.getZ();
                verts[i].Color = Color.White.ToArgb();
            }
            stm.Write(verts);
            vertexBuffer.Unlock();
        }
Esempio n. 23
0
        //计算多边形质心位置,其中的Z坐标为所有顶点Z坐标的均值
        public Vector3 GetCentroid()
        {
            float area = GetAreaOfXY();
            float x    = 0;
            float y    = 0;
            float z    = 0;

            for (int i = 0; i < vertex.Length; i++)
            {
                CustomVertex.PositionNormalColored from = vertex[i];
                CustomVertex.PositionNormalColored to   = vertex[(i + 1) % vertex.Length];

                x += (from.X + to.X) * (from.X * to.Y - to.X * from.Y);
                y += (from.Y + to.Y) * (from.X * to.Y - to.X * from.Y);
                z += from.Z;
            }

            //注意符号问题!
            x /= 6 * area;
            y /= 6 * area;
            z /= vertex.Length;

            return(new Vector3(x, y, z));
        }
        /// <summary>
        /// Builds an array of PositionNormalColored vertices that form a 
        /// nX by nY tesselation of a quad given by it's 2 corners
        /// </summary>
        /// <param name="bottomLeft">Bottom left corner of the quad</param>
        /// <param name="topRight">Top right corner of the quad</param>
        /// <param name="nX">amount of X tesselation</param>
        /// <param name="nY">amount of Y tesselation</param>
        /// /// <param name="color">The color of the quad</param>
        /// <returns>An array of PositionNormalColored vertices</returns>        
        public static CustomVertex.PositionNormalColored[] BuildPositionNormalSingleColored(PointF bottomLeft, PointF topRight,
            int nX, int nY, Color color)
        {
            if (nX < 2 || nY < 2)
            {
                throw new Exception("Cannot tesselate with nX or nY below 2");
            }
            float deltaX = (topRight.X - bottomLeft.X) / (float)(nX - 1);
            float deltaY = (topRight.Y - bottomLeft.Y) / (float)(nY - 1);
            float fx, fy;
            CustomVertex.PositionNormalColored[] verts = new CustomVertex.PositionNormalColored[nX * nY];

            for (int y = 0; y < nY; y++)
            {
                if (y == nY - 1)
                    fy = topRight.Y;
                else
                    fy = bottomLeft.Y + (float)y * deltaY;
                for (int x = 0; x < nX; x++)
                {
                    if (x == nX - 1)
                        fx = topRight.X;
                    else
                        fx = bottomLeft.X + (float)x * deltaX;
                    verts[y * nY + x].X = fx;
                    verts[y * nY + x].Y = fy;
                    verts[y * nY + x].Z = 0;
                    verts[y * nY + x].Color = color.ToArgb();
                    verts[y * nY + x].Normal = new Vector3(0, 0, -1f);
                }
            }
            return verts;
        }
Esempio n. 25
0
        /// <summary>
        /// Creates a rectangular portion of a spherical mesh
        /// </summary>
        /// <param name="device">The current direct3D drawing device.</param>
        /// <param name="radius">The sphere's radius</param>
        /// <returns></returns>
        /// <remarks>
        /// </remarks>
        private Mesh MakeFloodMesh(Device device, float radius, double west, double north, double east, double south, Color color)
        {
            int slices      = 128;
            int stacks      = 128;
            int numVertices = (slices + 1) * (stacks + 1);
            int numFaces    = slices * stacks * 2;
            int indexCount  = numFaces * 3;

            double lonSpacing = (east - west) / slices;
            double latSpacing = (north - south) / stacks;

            // Have some transparency
            int alpha = 200;

            color = Color.FromArgb(alpha, color.R, color.G, color.B);

            Mesh mesh = new Mesh(numFaces, numVertices, MeshFlags.Managed, CustomVertex.PositionNormalColored.Format, device);

            // Get the original sphere's vertex buffer.
            int [] ranks = new int[1];
            ranks[0] = mesh.NumberVertices;
            System.Array arr = mesh.VertexBuffer.Lock(0, typeof(CustomVertex.PositionNormalColored), LockFlags.None, ranks);

            // Set the vertex buffer
            int vertIndex = 0;

            double latitude  = south;
            double longitude = west;

            for (int stack = 0; stack <= stacks; stack++)
            {
                for (int slice = 0; slice <= slices; slice++)
                {
                    CustomVertex.PositionNormalColored pnt = new CustomVertex.PositionNormalColored();
                    Vector3 v = MathEngine.SphericalToCartesian(latitude, longitude, radius);
                    pnt.X     = v.X;
                    pnt.Y     = v.Y;
                    pnt.Z     = v.Z;
                    pnt.Color = color.ToArgb();
                    v.Normalize();
                    pnt.Normal = v;
                    arr.SetValue(pnt, vertIndex++);
                    longitude += lonSpacing;
                }
                latitude += latSpacing;
                longitude = west;
            }

            latitude  -= latSpacing;
            longitude -= lonSpacing;
            Console.Write("Final edges (east,north): " + longitude.ToString() + ", " + latitude.ToString() + "\n\n");

            mesh.VertexBuffer.Unlock();
            ranks[0] = indexCount;
            arr      = mesh.LockIndexBuffer(typeof(short), LockFlags.None, ranks);
            int   i            = 0;
            short bottomVertex = 0;
            short topVertex    = 0;

            for (short x = 0; x < stacks; x++)
            {
                //Console.WriteLine("last bottom vertex: " + bottomVertex.ToString());
                bottomVertex = (short)((slices + 1) * x);
                topVertex    = (short)(bottomVertex + slices + 1);
                for (int y = 0; y < slices; y++)
                {
                    arr.SetValue(bottomVertex, i++);
                    arr.SetValue((short)(topVertex + 1), i++);
                    arr.SetValue(topVertex, i++);
                    arr.SetValue(bottomVertex, i++);
                    arr.SetValue((short)(bottomVertex + 1), i++);
                    arr.SetValue((short)(topVertex + 1), i++);
                    bottomVertex++;
                    topVertex++;
                }
            }
            mesh.IndexBuffer.SetData(arr, 0, LockFlags.None);
            //mesh.ComputeNormals();


            return(mesh);
        }
Esempio n. 26
0
        private void UpdateVertices()
        {
            m_verticalExaggeration = World.Settings.VerticalExaggeration;

            CPoint2D[] polygonVertices = new CPoint2D[m_polygonPoints.Length];
            for (int i = 0; i < polygonVertices.Length; i++) {
                polygonVertices[i] = new CPoint2D(m_polygonPoints[i].X, m_polygonPoints[i].Y);
            }

            CPolygonShape cutPolygon = new CPolygonShape(polygonVertices);
            cutPolygon.CutEar();

            ArrayList vertexList = new ArrayList();

            for (int i = 0; i < cutPolygon.NumberOfPolygons; i++) {
                int nPoints = cutPolygon.Polygons(i).Length;

                for (int j = 0; j < nPoints; j++) {
                    Point3d point = new Point3d(cutPolygon.Polygons(i)[j].X, cutPolygon.Polygons(i)[j].Y, 0);

                    foreach (Point3d sourcePoint in m_polygonPoints) {
                        if (sourcePoint.X.Equals(point.X)
                            && sourcePoint.Y.Equals(point.Y)) {
                            point.Z = sourcePoint.Z;
                            break;
                        }
                    }

                    vertexList.Add(point);
                }
            }

            if (m_extrudeHeight > 0) {
                CustomVertex.PositionNormalColored[] vertices = new CustomVertex.PositionNormalColored[vertexList.Count*2];
                int polygonColor = Color.FromArgb(Opacity, m_polygonColor.R, m_polygonColor.G, m_polygonColor.B).ToArgb();
                int vertexOffset = vertices.Length/2;

                // build bottom vertices
                for (int i = 0; i < vertices.Length/2; i++) {
                    Point3d sphericalPoint = (Point3d) vertexList[i];
                    Vector3 xyzVector = MathEngine.SphericalToCartesian(sphericalPoint.Y, sphericalPoint.X, World.EquatorialRadius + m_verticalExaggeration*(sphericalPoint.Z + m_distanceAboveSurface));

                    vertices[i].Color = polygonColor;
                    vertices[i].X = xyzVector.X;
                    vertices[i].Y = xyzVector.Y;
                    vertices[i].Z = xyzVector.Z;
                }

                //build top vertices
                for (int i = vertexOffset; i < vertices.Length; i++) {
                    Point3d sphericalPoint = (Point3d) vertexList[i - vertexOffset];
                    Vector3 xyzVector = MathEngine.SphericalToCartesian(sphericalPoint.Y, sphericalPoint.X, World.EquatorialRadius + m_verticalExaggeration*(sphericalPoint.Z + m_distanceAboveSurface + m_extrudeHeight));

                    vertices[i].Color = polygonColor;
                    vertices[i].X = xyzVector.X;
                    vertices[i].Y = xyzVector.Y;
                    vertices[i].Z = xyzVector.Z;
                }

                m_vertices = vertices;
            }
            else {
                CustomVertex.PositionNormalColored[] vertices = new CustomVertex.PositionNormalColored[vertexList.Count];
                int polygonColor = Color.FromArgb(Opacity, m_polygonColor.R, m_polygonColor.G, m_polygonColor.B).ToArgb();

                for (int i = 0; i < vertices.Length; i++) {
                    Point3d sphericalPoint = (Point3d) vertexList[i];
                    Vector3 xyzVector = MathEngine.SphericalToCartesian(sphericalPoint.Y, sphericalPoint.X, World.EquatorialRadius + m_verticalExaggeration*(sphericalPoint.Z + m_distanceAboveSurface));

                    vertices[i].Color = polygonColor;
                    vertices[i].X = xyzVector.X;
                    vertices[i].Y = xyzVector.Y;
                    vertices[i].Z = xyzVector.Z;
                }

                m_vertices = vertices;
            }

            if (m_extrudeHeight > 0 || m_outline) {
                Point3d[] linePoints = new Point3d[m_polygonPoints.Length + 1];
                for (int i = 0; i < m_polygonPoints.Length; i++) {
                    linePoints[i] = m_polygonPoints[i];
                }

                linePoints[linePoints.Length - 1] = m_polygonPoints[0];

                m_lineFeature = new LineFeature(Name, World, linePoints, m_polygonColor);
                m_lineFeature.ExtrudeHeight = m_extrudeHeight;
                m_lineFeature.DistanceAboveSurface = m_distanceAboveSurface;
                m_lineFeature.ExtrudeUpwards = m_extrudeUpwards;
                m_lineFeature.MinimumDisplayAltitude = m_minimumDisplayAltitude;
                m_lineFeature.MaximumDisplayAltitude = m_maximumDisplayAltitude;
                m_lineFeature.Opacity = Opacity;
                m_lineFeature.Outline = m_outline;
                m_lineFeature.OutlineColor = m_outlineColor;
            }
            else {
                if (m_lineFeature != null) {
                    m_lineFeature.Dispose();
                    m_lineFeature = null;
                }
            }
        }
Esempio n. 27
0
        ////////////////////////////////////////////////////////////////////////////////////
        private void GenerateAllVertexsAndFacets()
        {
            //计算所有垂直矩形的顶点集合
            //顶点数=边数* 4个顶点 * 边可能重复次数(1 or 2) * 垂直面可能重复次数(1 or 2)
            CustomVertex.PositionNormalColored[] v =
                new CustomVertex.PositionNormalColored[sec.num_borders * 4 * 2];

            //用于消除边重复的Hash Table
            Dictionary <ulong, bool> dict = new Dictionary <ulong, bool>(sec.num_borders);

            float epsilon = 0.5F;             //不能小于0.2,否则Tu01ex.sec中三角面不正常
            int   pos     = 0;

            for (int i = 0; i < sec.num_borders; i++)
            {
                Border b = sec.borders[i];
                if (b.belong_district == -1 || b.neighbor_district == -1)
                {
                    continue;                                                                       //特殊面,不画垂直面
                }
                ////////////////////////////////////////////////////////////////////////////////////////////
                //注意!不能用如下方法来消除边重复(例如RY和PT,缺面)
                //if (b.belong_district >= b.neighbor_district) continue; //面已经重复了,没有必要重绘

                //因此,只能采用集合薄记的方式来防止边重复
                bool  ret;
                ulong x   = (ulong)b.belong_district;
                ulong y   = (ulong)b.neighbor_district;
                ulong key = (x << 32) | y;

                if (dict.TryGetValue(key, out ret))
                {
                    //已经登记过了,发生重复了
                    continue;
                }
                else
                {
                    //没有登记过,登记进Hash Table
                    key = (y << 32) | x;
                    dict.Add(key, true);
                }
                ////////////////////////////////////////////////////////////////////////////////////////////

                FPoint   from     = b.from;
                FPoint   to       = b.to;
                District belong   = sec.districts[b.belong_district];
                District neighbor = sec.districts[b.neighbor_district];

                float z1 = from.x * belong.tanX + from.y * belong.tanY + belong.M;
                float z2 = to.x * belong.tanX + to.y * belong.tanY + belong.M;

                float z3 = from.x * neighbor.tanX + from.y * neighbor.tanY + neighbor.M;
                float z4 = to.x * neighbor.tanX + to.y * neighbor.tanY + neighbor.M;

                z1 = -z1;
                z2 = -z2;
                z3 = -z3;
                z4 = -z4;

                if (Math.Abs(z1 - z3) <= epsilon && Math.Abs(z2 - z4) <= epsilon)
                {
                    continue;                                                                               //矩形两边高度均为0,无需画了
                }
                v[pos++] = new CustomVertex.PositionNormalColored(from.x, from.y, z1, 0, 0, 0, color.ToArgb());
                v[pos++] = new CustomVertex.PositionNormalColored(to.x, to.y, z2, 0, 0, 0, color.ToArgb());
                v[pos++] = new CustomVertex.PositionNormalColored(to.x, to.y, z4, 0, 0, 0, color.ToArgb());
                v[pos++] = new CustomVertex.PositionNormalColored(from.x, from.y, z3, 0, 0, 0, color.ToArgb());
            }

            if (pos == 0)
            {
                vexbuf = null;
                return;                 //根本没有垂直面需要画,直接退出!
            }

            vexbuf = new CustomVertex.PositionNormalColored[pos];
            for (int i = 0; i < pos; i++)
            {
                vexbuf[i] = v[i];
            }

            v = null;            //抛弃数组v

            //计算法线,矩形变成了三角形,或者上下边平行时,情况很微妙
            Vector3[] normals = new Vector3[pos / 4];
            for (int i = 0; i < pos / 4; i++)
            {
                CustomVertex.PositionNormalColored v0 = vexbuf[4 * i];
                CustomVertex.PositionNormalColored v1 = vexbuf[4 * i + 1];
                CustomVertex.PositionNormalColored v2 = vexbuf[4 * i + 2];
                CustomVertex.PositionNormalColored v3 = vexbuf[4 * i + 3];

                CustomVertex.PositionNormalColored[] tv = SimplifyQuadrangle(vexbuf, 4 * i, epsilon);
                normals[i] = CalculateNormalOfSimplifiedPolygon(tv);
            }

            for (int i = 0; i < pos; i++)
            {
                vexbuf[i].Normal = normals[i / 4];
            }

            int totalf = vexbuf.Length / 4 * 2;             //三角面总数
            int totalv = vexbuf.Length;                     //顶点总数

            //创建三角面集合
            idxbuf = new short[totalf * 3];             //注意,只能是short! WHY?

            pos = 0;
            for (int i = 0; i < totalf / 2; i++)             //垂直多边形数为totalf/2
            {
                //分解成2个三角形, triangle fans
                for (int j = 0; j < 2; j++)
                {
                    //v0, v1, v2三个点构成了一个左手三角形
                    int v0 = 4 * i;
                    int v1 = v0 + j + 1;
                    int v2 = v1 + 1;

                    idxbuf[pos++] = (short)v0;
                    idxbuf[pos++] = (short)v1;
                    idxbuf[pos++] = (short)v2;
                }
            }
        }
Esempio n. 28
0
        void ColoredBySubCategory(int sub_category, ref CustomVertex.PositionNormalColored vex)
        {
            switch (sub_category)
            {
            case 0:                     //沙子或者土壤
                vex.Color = Color.DarkOrange.ToArgb();
                break;

            case 1:                     //草地
                vex.Color = Color.LimeGreen.ToArgb();
                break;

            case 2:                    //路
                vex.Color = Color.Silver.ToArgb();
                break;

            case 3:                    //不好判断
                break;

            case 4:                    //无
                break;

            case 5:                    //木质地面
                vex.Color = Color.Gold.ToArgb();
                break;

            case 6:                    //泥沙地形,河边的居多,不好判断
                vex.Color = Color.Khaki.ToArgb();
                break;

            case 7:                    //雪地
                vex.Color = Color.White.ToArgb();
                break;

            case 8:                    //无
                break;

            case 9:                    //从河边卵石到土壤,不好判断
                vex.Color = Color.Linen.ToArgb();
                break;

            case 10:                    //无
                break;

            case 11:                     //铁质地形,铁栏杆,铁楼梯
                vex.Color = Color.DarkSlateGray.ToArgb();
                break;

            case 12:                     //无
                break;

            case 13:                     //浅水斜坡
                vex.Color = Color.CornflowerBlue.ToArgb();
                break;

            case 14:                     //深水
                vex.Color = Color.DarkBlue.ToArgb();
                break;

            case 15:                     //卵石
                vex.Color = Color.Gainsboro.ToArgb();
                break;
            }
        }
Esempio n. 29
0
        private void finishTesselation(Point3d[] tesselatorList)
        {
            int alpha        = (int)(((double)m_polygonColor.A / 255 * (double)this.Opacity / 255) * 255);
            int polygonColor = System.Drawing.Color.FromArgb(alpha, m_polygonColor.R, m_polygonColor.G, m_polygonColor.B).ToArgb();

            CustomVertex.PositionNormalColored[] vertices = new CustomVertex.PositionNormalColored[tesselatorList.Length];

            // precalculate feature center (at zero elev)
            Point3d center = new Point3d(0, 0, 0);

            for (int i = 0; i < m_outerRing.Points.Length; i++)
            {
                center += MathEngine.SphericalToCartesianD(
                    Angle.FromDegrees(m_outerRing.Points[i].Y),
                    Angle.FromDegrees(m_outerRing.Points[i].X),
                    World.EquatorialRadius
                    );
            }
            center = center * (1.0 / m_outerRing.Points.Length);
            // round off to nearest 10^5.

            center.X = ((int)(center.X / 10000.0)) * 10000.0;
            center.Y = ((int)(center.Y / 10000.0)) * 10000.0;
            center.Z = ((int)(center.Z / 10000.0)) * 10000.0;

            m_localOrigin = center.Vector3;

            for (int i = 0; i < vertices.Length; i++)
            {
                Point3d sphericalPoint = tesselatorList[i];
                //System.Console.WriteLine("Point" + sphericalPoint.X+" "+sphericalPoint.Y+" "+sphericalPoint.Z);

                double terrainHeight = 0;
                if (m_altitudeMode == AltitudeMode.RelativeToGround)
                {
                    if (World.TerrainAccessor != null)
                    {
                        terrainHeight = World.TerrainAccessor.GetElevationAt(
                            sphericalPoint.Y,
                            sphericalPoint.X,
                            (100.0 / DrawArgs.Camera.ViewRange.Degrees)
                            );
                    }
                }

                Point3d xyzPoint = MathEngine.SphericalToCartesianD(
                    Angle.FromDegrees(sphericalPoint.Y),
                    Angle.FromDegrees(sphericalPoint.X),
                    World.EquatorialRadius
                    + m_verticalExaggeration *
                    (m_geographicBoundingBox.MaximumAltitude
                     + m_distanceAboveSurface + terrainHeight));

                //Vector3 xyzVector = (xyzPoint + center).Vector3;

                vertices[i].Color = polygonColor;
                vertices[i].X     = (float)(xyzPoint.X - center.X);
                vertices[i].Y     = (float)(xyzPoint.Y - center.Y);
                vertices[i].Z     = (float)(xyzPoint.Z - center.Z);
                vertices[i].Nx    = 0;
                vertices[i].Ny    = 0;
                vertices[i].Nz    = 0;
            }

            primList.Add(vertices);

            ComputeNormals((PrimitiveType)primTypes[primList.Count - 1], vertices);
        }
Esempio n. 30
0
        private RenderDataSource createRenderDataSourceFromNodes(CNode rdsNode, CNode dbNode)
        {
            MiscUtil.Conversion.BigEndianBitConverter bc = new MiscUtil.Conversion.BigEndianBitConverter();
            CustomVertex.PositionNormalColored[] vertices = new CustomVertex.PositionNormalColored[(int)dbNode.attributes["elementCount"].data];

            Vector3 pos = new Vector3();
            int color;
            Vector3 normal = new Vector3();
            int vertexCount = 0;
            for (int i = 0; i < (int)dbNode.attributes["size"].data; i += 28) {
                pos.X = bc.ToSingle(dbNode.subNodes[3].data, i);
                pos.Y = bc.ToSingle(dbNode.subNodes[3].data, i + 4);
                pos.Z = bc.ToSingle(dbNode.subNodes[3].data, i + 8);

                color = bc.ToInt32(dbNode.subNodes[3].data, i + 12);

                normal.X = bc.ToSingle(dbNode.subNodes[3].data, i + 16);
                normal.Y = bc.ToSingle(dbNode.subNodes[3].data, i + 20);
                normal.Z = bc.ToSingle(dbNode.subNodes[3].data, i + 24);

                vertices[vertexCount] = new CustomVertex.PositionNormalColored(pos, normal, color);
                vertexCount++;
            }

            int indexCount = (int)rdsNode.subNodes[0].attributes["count"].data;
            ushort[] indices = new ushort[indexCount];
            for (int i = 0; i < indexCount; i++) {
                indices[i] = bc.ToUInt16(rdsNode.subNodes[0].subNodes[0].data, i * 2);
            }
            return new RenderDataSource(rdsNode.attributes["id"].value, vertices, indices);
        }
Esempio n. 31
0
        public void VertexDeclaration()
        {
            vb = new VertexBuffer(typeof(CustomVertex.PositionNormalColored), 10, device, Usage.Dynamic | Usage.WriteOnly, CustomVertex.PositionNormalColored.Format, Pool.Default);

            //вершины содержат координаты, нормаль и цвет
            vertices    = new CustomVertex.PositionNormalColored[10];
            vertices[0] = new CustomVertex.PositionNormalColored(3f, 0f, 0f, 0f, 0f, -1f, Color.Cyan.ToArgb());
            vertices[1] = new CustomVertex.PositionNormalColored(0f, 3f, 0f, 0f, 0f, -1f, Color.Red.ToArgb());
            vertices[2] = new CustomVertex.PositionNormalColored(-3f, 0f, 0f, 0f, 0f, -1f, Color.Blue.ToArgb());
            vertices[3] = new CustomVertex.PositionNormalColored(-1f, -3f, 0f, 0f, 0f, -1f, Color.Magenta.ToArgb());
            vertices[4] = new CustomVertex.PositionNormalColored(1f, -3f, 0f, 0f, 0f, -1f, Color.Yellow.ToArgb());

            vertices[5] = new CustomVertex.PositionNormalColored(4f, 1f, 5f, 0f, 0f, 1f, Color.Green.ToArgb());
            vertices[6] = new CustomVertex.PositionNormalColored(1f, 4f, 5f, 0f, 0f, 1f, Color.Yellow.ToArgb());
            vertices[7] = new CustomVertex.PositionNormalColored(-2f, 1f, 5f, 0f, 0f, 1f, Color.Orange.ToArgb());
            vertices[8] = new CustomVertex.PositionNormalColored(0f, -2f, 5f, 0f, 0f, 1f, Color.Purple.ToArgb());
            vertices[9] = new CustomVertex.PositionNormalColored(2f, -2f, 5f, 0f, 0f, 1f, Color.Violet.ToArgb());

            vb.SetData(vertices, 0, LockFlags.None);

            //индексный буфер показывает, как вершины объединить в треугольники
            ib      = new IndexBuffer(typeof(int), 48, device, Usage.WriteOnly, Pool.Default);
            indices = new int[48];

            //дно
            indices[0] = 3;
            indices[1] = 2;
            indices[2] = 1;
            indices[3] = 4;
            indices[4] = 3;
            indices[5] = 1;
            indices[6] = 0;
            indices[7] = 4;
            indices[8] = 1;

            //крыша
            indices[9]  = 8;
            indices[10] = 6;
            indices[11] = 7;
            indices[12] = 9;
            indices[13] = 6;
            indices[14] = 8;
            indices[15] = 5;
            indices[16] = 6;
            indices[17] = 9;

            //первая
            indices[18] = 1;
            indices[19] = 6;
            indices[20] = 0;
            indices[21] = 0;
            indices[22] = 6;
            indices[23] = 5;

            //вторая
            indices[24] = 0;
            indices[25] = 5;
            indices[26] = 4;
            indices[27] = 4;
            indices[28] = 5;
            indices[29] = 9;

            //третья
            indices[30] = 4;
            indices[31] = 9;
            indices[32] = 3;
            indices[33] = 3;
            indices[34] = 9;
            indices[35] = 8;

            //четвертая
            indices[36] = 3;
            indices[37] = 8;
            indices[38] = 2;
            indices[39] = 2;
            indices[40] = 8;
            indices[41] = 7;

            //пятая
            indices[42] = 2;
            indices[43] = 7;
            indices[44] = 1;
            indices[45] = 1;
            indices[46] = 7;
            indices[47] = 6;


            ib.SetData(indices, 0, LockFlags.None);

            ib = new IndexBuffer(typeof(int), indices.Length, device,
                                 Usage.WriteOnly, Pool.Default);

            ib.SetData(indices, 0, LockFlags.None);
        }
Esempio n. 32
0
        public void Render(S3DirectX d3dDevice)
        {
            int L = 30000;

            d3dDevice.Renderer.SetTransform(TransformType.World, Matrix.Identity);
            d3dDevice.SetupObjectMaterial(Color.FromArgb(unchecked ((int)0x10404040)));

            for (int i = 0; i < NF; i++)
            {
                BPln[i] = ((S4Camera)(d3dDevice.Camera)).AbovePlane(FPoles[i]);
            }

            if (VBuf == null)
            {
                VBuf = GetNewBuffer(d3dDevice.Renderer, L);
            }
            CustomVertex.PositionNormalColored[] cbuf = (CustomVertex.PositionNormalColored[])VBuf.Lock(0, 0);
            int ptr = 0;

            for (int ns = 0; ns < NStk; ns++)
            {
                if (Stks[ns].ExtraTwist == null && BPln[Stks[ns].NFace])
                {
                    continue;
                }
                int l0 = Stks[ns].L2D();
                if (ptr + l0 > L)
                {
                    SendVBuf(d3dDevice, PrimitiveType.TriangleList, ptr / 3);
                    cbuf = (CustomVertex.PositionNormalColored[])VBuf.Lock(0, 0);
                    ptr  = 0;
                }
                Stks[ns].RecalcCoord((S4Camera)(d3dDevice.Camera));
                int m = 1 << Math.Min(11, Stks[ns].Base.Rank);
                if ((m & ShowRank) == 0)
                {
                    continue;
                }
                ptr = Stks[ns].SetBuffer2D((S4Camera)(d3dDevice.Camera), cbuf, ptr);
            }
            SendVBuf(d3dDevice, PrimitiveType.TriangleList, ptr / 3);

            cbuf = (CustomVertex.PositionNormalColored[])VBuf.Lock(0, 0);
            ptr  = 0;
            for (int ns = 0; ns < NStk; ns++) // selected stickers
            {
                if (Stks[ns].ExtraTwist == null && BPln[Stks[ns].NFace])
                {
                    continue;
                }
                int u  = Cube.Field[ns];
                int cl = (u & 0x8000) != 0 ? -1 : unchecked ((int)0xff202020);
                if (ptr + Stks[ns].L1D() > L)
                {
                    SendVBuf(d3dDevice, PrimitiveType.LineList, ptr / 2);
                    cbuf = (CustomVertex.PositionNormalColored[])VBuf.Lock(0, 0);
                    ptr  = 0;
                }
                int m = 1 << Math.Min(11, Stks[ns].Base.Rank);
                if ((m & ShowRank) == 0 && Stks[ns].Base.MinBDim != 0)
                {
                    continue;
                }
                ptr = Stks[ns].SetBuffer1D((S4Camera)(d3dDevice.Camera), cbuf, ptr, cl);
            }
            for (int ns = 0; ns < NF; ns++)
            {
                if (BPln[ns])
                {
                    continue;
                }
                StFaces[ns].RecalcCoord((S4Camera)(d3dDevice.Camera));
                int l0 = StFaces[ns].L1D();
                if (ptr + l0 > L)
                {
                    SendVBuf(d3dDevice, PrimitiveType.LineList, ptr / 2);
                    cbuf = (CustomVertex.PositionNormalColored[])VBuf.Lock(0, 0);
                    ptr  = 0;
                }
                ptr = StFaces[ns].SetBuffer1D((S4Camera)(d3dDevice.Camera), cbuf, ptr, -0x7f7f80);
            }
#if false
            int dim = Cube.Str.Dim;
            for (int i = 0; i < lVN; i += 4)
            {
                if (ptr == L)
                {
                    SendVBuf(d3dDevice, PrimitiveType.LineList, ptr / 2);
                    cbuf = (CustomVertex.PositionNormalColored[])VBuf.Lock(0, 0);
                    ptr  = 0;
                }
                int f1 = VertNetwork[i], f2 = VertNetwork[i + 2];
                if (BPln[f1] || BPln[f2])
                {
                    continue;
                }
                Vector3 p1 = StFaces[f1].Coords3D[VertNetwork[i + 1] / dim];
                Vector3 p2 = StFaces[f2].Coords3D[VertNetwork[i + 3] / dim];
                if (p1.Z != StkMesh.WRONGPT && p2.Z != StkMesh.WRONGPT)
                {
                    cbuf[ptr++] = new CustomVertex.PositionNormalColored(p1, new Vector3(0, 0, 1), -0x7f7f80);
                    cbuf[ptr++] = new CustomVertex.PositionNormalColored(p2, new Vector3(0, 0, 1), -0x7f7f80);
                }
            }
#endif
            SendVBuf(d3dDevice, PrimitiveType.LineList, ptr / 2);
        }
Esempio n. 33
0
        private void UpdateVertices()
        {
            m_verticalExaggeration = World.Settings.VerticalExaggeration;

            CPoint2D[] polygonVertices = new CPoint2D[m_polygonPoints.Length];
            for (int i = 0; i < polygonVertices.Length; i++)
            {
                polygonVertices[i] = new CPoint2D(m_polygonPoints[i].X, m_polygonPoints[i].Y);
            }

            CPolygonShape cutPolygon = new CPolygonShape(polygonVertices);

            cutPolygon.CutEar();

            ArrayList vertexList = new ArrayList();

            for (int i = 0; i < cutPolygon.NumberOfPolygons; i++)
            {
                int nPoints = cutPolygon.Polygons(i).Length;

                for (int j = 0; j < nPoints; j++)
                {
                    Point3d point = new Point3d(cutPolygon.Polygons(i)[j].X, cutPolygon.Polygons(i)[j].Y, 0);

                    foreach (Point3d sourcePoint in m_polygonPoints)
                    {
                        if (sourcePoint.X.Equals(point.X) &&
                            sourcePoint.Y.Equals(point.Y))
                        {
                            point.Z = sourcePoint.Z;
                            break;
                        }
                    }

                    vertexList.Add(point);
                }
            }

            if (m_extrudeHeight > 0)
            {
                CustomVertex.PositionNormalColored[] vertices = new CustomVertex.PositionNormalColored[vertexList.Count * 2];
                int polygonColor = Color.FromArgb(Opacity, m_polygonColor.R, m_polygonColor.G, m_polygonColor.B).ToArgb();
                int vertexOffset = vertices.Length / 2;

                // build bottom vertices
                for (int i = 0; i < vertices.Length / 2; i++)
                {
                    Point3d sphericalPoint = (Point3d)vertexList[i];
                    Vector3 xyzVector      = MathEngine.SphericalToCartesian(sphericalPoint.Y, sphericalPoint.X, World.EquatorialRadius + m_verticalExaggeration * (sphericalPoint.Z + m_distanceAboveSurface));

                    vertices[i].Color = polygonColor;
                    vertices[i].X     = xyzVector.X;
                    vertices[i].Y     = xyzVector.Y;
                    vertices[i].Z     = xyzVector.Z;
                }

                //build top vertices
                for (int i = vertexOffset; i < vertices.Length; i++)
                {
                    Point3d sphericalPoint = (Point3d)vertexList[i - vertexOffset];
                    Vector3 xyzVector      = MathEngine.SphericalToCartesian(sphericalPoint.Y, sphericalPoint.X, World.EquatorialRadius + m_verticalExaggeration * (sphericalPoint.Z + m_distanceAboveSurface + m_extrudeHeight));

                    vertices[i].Color = polygonColor;
                    vertices[i].X     = xyzVector.X;
                    vertices[i].Y     = xyzVector.Y;
                    vertices[i].Z     = xyzVector.Z;
                }

                m_vertices = vertices;
            }
            else
            {
                CustomVertex.PositionNormalColored[] vertices = new CustomVertex.PositionNormalColored[vertexList.Count];
                int polygonColor = Color.FromArgb(Opacity, m_polygonColor.R, m_polygonColor.G, m_polygonColor.B).ToArgb();

                for (int i = 0; i < vertices.Length; i++)
                {
                    Point3d sphericalPoint = (Point3d)vertexList[i];
                    Vector3 xyzVector      = MathEngine.SphericalToCartesian(sphericalPoint.Y, sphericalPoint.X, World.EquatorialRadius + m_verticalExaggeration * (sphericalPoint.Z + m_distanceAboveSurface));

                    vertices[i].Color = polygonColor;
                    vertices[i].X     = xyzVector.X;
                    vertices[i].Y     = xyzVector.Y;
                    vertices[i].Z     = xyzVector.Z;
                }

                m_vertices = vertices;
            }

            if (m_extrudeHeight > 0 || m_outline)
            {
                Point3d[] linePoints = new Point3d[m_polygonPoints.Length + 1];
                for (int i = 0; i < m_polygonPoints.Length; i++)
                {
                    linePoints[i] = m_polygonPoints[i];
                }

                linePoints[linePoints.Length - 1] = m_polygonPoints[0];

                m_lineFeature = new LineFeature(Name, World, linePoints, m_polygonColor);
                m_lineFeature.ExtrudeHeight          = m_extrudeHeight;
                m_lineFeature.DistanceAboveSurface   = m_distanceAboveSurface;
                m_lineFeature.ExtrudeUpwards         = m_extrudeUpwards;
                m_lineFeature.MinimumDisplayAltitude = m_minimumDisplayAltitude;
                m_lineFeature.MaximumDisplayAltitude = m_maximumDisplayAltitude;
                m_lineFeature.Opacity      = Opacity;
                m_lineFeature.Outline      = m_outline;
                m_lineFeature.OutlineColor = m_outlineColor;
            }
            else
            {
                if (m_lineFeature != null)
                {
                    m_lineFeature.Dispose();
                    m_lineFeature = null;
                }
            }
        }
Esempio n. 34
0
		private void finishTesselation(Point3d[] tesselatorList)
		{
			int polygonColor = System.Drawing.Color.FromArgb(m_polygonColor.A, m_polygonColor.R, m_polygonColor.G, m_polygonColor.B).ToArgb();
			CustomVertex.PositionNormalColored[] vertices = new CustomVertex.PositionNormalColored[tesselatorList.Length];
		
			for(int i = 0; i < vertices.Length; i++)
			{
				Point3d sphericalPoint = tesselatorList[i];
					
				double terrainHeight = 0;
				if(m_altitudeMode == AltitudeMode.RelativeToGround)
				{
					if(World.TerrainAccessor != null)
					{
						terrainHeight = World.TerrainAccessor.GetElevationAt(
							sphericalPoint.Y,
							sphericalPoint.X,
							(100.0 / DrawArgs.Camera.ViewRange.Degrees)
							);
					}
				}

				Vector3 xyzVector = MathEngine.SphericalToCartesian(
					sphericalPoint.Y, 
					sphericalPoint.X, 
					World.EquatorialRadius + m_verticalExaggeration * (m_geographicBoundingBox.MaximumAltitude + m_distanceAboveSurface + terrainHeight));

				vertices[i].Color = polygonColor;
				vertices[i].X = xyzVector.X;
				vertices[i].Y = xyzVector.Y;
				vertices[i].Z = xyzVector.Z;
			}

			primList.Add(vertices);
		}
        /// <summary>
        /// Builds an array of PositionNormalColored vertices that form a 
        /// nX by nY tesselation of a quad given by it's 2 corners
        /// </summary>
        /// <param name="bottomLeft">Bottom left corner of the quad</param>
        /// <param name="topRight">Top right corner of the quad</param>
        /// <param name="nX">amount of X tesselation</param>
        /// <param name="nY">amount of Y tesselation</param>
        /// <param name="bRight">The color of bottom right corner</param>
        /// <param name="bLeft">The color of bottom left corner</param>
        /// <param name="tRight">The color of top right corner</param>
        /// <param name="tLeft">The color of top left corner</param>
        /// <returns>An array of PositionNormalColored vertices</returns> 
        public static CustomVertex.PositionNormalColored[] BuildPositionNormalSmoothColored(PointF bottomLeft,
            PointF topRight, int nX, int nY, Color bRight, Color bLeft, Color tRight, Color tLeft)
        {
            if (nX < 2 || nY < 2)
            {
                throw new Exception("Cannot tesselate with nX or nY below 2");
            }
            float deltaX = (topRight.X - bottomLeft.X) / (float)(nX - 1);
            float deltaY = (topRight.Y - bottomLeft.Y) / (float)(nY - 1);
            float fx, fy;
            CustomVertex.PositionNormalColored[] verts = new CustomVertex.PositionNormalColored[nX * nY];

            for (int y = 0; y < nY; y++)
            {
                if (y == nY - 1)
                    fy = topRight.Y;
                else
                    fy = bottomLeft.Y + (float)y * deltaY;
                for (int x = 0; x < nX; x++)
                {

                    if (x == nX - 1)
                        fx = topRight.X;
                    else
                        fx = bottomLeft.X + (float)x * deltaX;

                    float tX = (fx - bottomLeft.X) / (topRight.X - bottomLeft.X);
                    float tY = (fy - bottomLeft.Y) / (topRight.Y - bottomLeft.Y);
                    verts[y * nY + x].X = fx;
                    verts[y * nY + x].Y = fy;
                    verts[y * nY + x].Z = 0;
                    float col1r = (1f - tY) * (float)bLeft.R + tY * (float)tLeft.R;
                    float col2r = (1f - tY) * (float)bRight.R + tY * (float)tRight.R;
                    int col3r = (int)((1f - tX) * col1r + tX * col2r);

                    float col1g = (1f - tY) * (float)bLeft.G + tY * (float)tLeft.G;
                    float col2g = (1f - tY) * (float)bRight.G + tY * (float)tRight.G;
                    int col3g = (int)((1f - tX) * col1g + tX * col2g);

                    float col1b = (1f - tY) * (float)bLeft.B + tY * (float)tLeft.B;
                    float col2b = (1f - tY) * (float)bRight.B + tY * (float)tRight.B;
                    int col3b = (int)((1f - tX) * col1b + tX * col2b);

                    float col1a = (1f - tY) * (float)bLeft.A + tY * (float)tLeft.A;
                    float col2a = (1f - tY) * (float)bRight.A + tY * (float)tRight.A;
                    int col3a = (int)((1f - tX) * col1a + tX * col2a);

                    verts[y * nY + x].Color = (Color.FromArgb(col3a, col3r, col3g, col3b)).ToArgb();
                    verts[y * nY + x].Normal = new Vector3(0, 0, -1f);
                }
            }
            return verts;
        }
        public static Mesh CreateBox(Microsoft.DirectX.Direct3D.Device d3dDevice, float fltX, float fltY, float fltZ, int iXDivs, int iYDivs, int iZDivs)
        {
            //VertexBuffer vb = (VertexBuffer)sender;
            ArrayList aryStrips = new ArrayList();
            ArrayList aryTriangleList;
            CustomVertex.PositionNormalColored[] verts;
            Microsoft.DirectX.Vector3 vNormal = new Vector3();

            float fltXDiv = fltX/iXDivs;
            float fltYDiv = fltY/iYDivs;
            float fltZDiv = fltZ/iZDivs;

            float x1, x2, y1, y2, z1, z2;

            //Go through and create the top and bottom panes.
            y1 = -fltY*0.5f; y2 = fltY*0.5f;
            for(int iXDiv=0; iXDiv<iXDivs; iXDiv++)
            {
                x1 = -fltX*0.5f + (fltXDiv*iXDiv);
                x2 = -fltX*0.5f + (fltXDiv*(iXDiv+1));

                for(int iZDiv=0; iZDiv<iZDivs; iZDiv++)
                {
                    z1 = -fltZ*0.5f + (fltZDiv*iZDiv);
                    z2 = -fltZ*0.5f + (fltZDiv*(iZDiv+1));

                    verts = new CustomVertex.PositionNormalColored[4];
                    verts[0] = new CustomVertex.PositionNormalColored(x1, y1, z1, 0, -1, 0, Color.White.ToArgb());
                    verts[1] = new CustomVertex.PositionNormalColored(x2, y1, z1, 0, -1, 0, Color.White.ToArgb());
                    verts[2] = new CustomVertex.PositionNormalColored(x1, y1, z2, 0, -1, 0, Color.White.ToArgb());
                    verts[3] = new CustomVertex.PositionNormalColored(x2, y1, z2, 0, -1, 0, Color.White.ToArgb());
                    aryStrips.Add(verts);

                    verts = new CustomVertex.PositionNormalColored[4];
                    verts[0] = new CustomVertex.PositionNormalColored(x1, y2, z1, 0, 1, 0, Color.Blue.ToArgb());
                    verts[1] = new CustomVertex.PositionNormalColored(x1, y2, z2, 0, 1, 0, Color.Blue.ToArgb());
                    verts[2] = new CustomVertex.PositionNormalColored(x2, y2, z1, 0, 1, 0, Color.Blue.ToArgb());
                    verts[3] = new CustomVertex.PositionNormalColored(x2, y2, z2, 0, 1, 0, Color.Blue.ToArgb());
                    aryStrips.Add(verts);
                }
            }

            //Go through and create the left and right panes.
            x1 = -fltX*0.5f; x2 = fltX*0.5f;
            for(int iYDiv=0; iYDiv<iYDivs; iYDiv++)
            {
                y1 = -fltY*0.5f + (fltYDiv*iYDiv);
                y2 = -fltY*0.5f + (fltYDiv*(iYDiv+1));

                for(int iZDiv=0; iZDiv<iZDivs; iZDiv++)
                {
                    z1 = -fltZ*0.5f + (fltZDiv*iZDiv);
                    z2 = -fltZ*0.5f + (fltZDiv*(iZDiv+1));

                    verts = new CustomVertex.PositionNormalColored[4];
                    verts[0] = new CustomVertex.PositionNormalColored(x1, y1, z1, -1, 0, 0, Color.Red.ToArgb());
                    verts[1] = new CustomVertex.PositionNormalColored(x1, y1, z2, -1, 0, 0, Color.Red.ToArgb());
                    verts[2] = new CustomVertex.PositionNormalColored(x1, y2, z1, -1, 0, 0, Color.Red.ToArgb());
                    verts[3] = new CustomVertex.PositionNormalColored(x1, y2, z2, -1, 0, 0, Color.Red.ToArgb());
                    aryStrips.Add(verts);

                    verts = new CustomVertex.PositionNormalColored[4];
                    verts[0] = new CustomVertex.PositionNormalColored(x2, y1, z1, 1, 0, 0, Color.Green.ToArgb());
                    verts[1] = new CustomVertex.PositionNormalColored(x2, y2, z1, 1, 0, 0, Color.Green.ToArgb());
                    verts[2] = new CustomVertex.PositionNormalColored(x2, y1, z2, 1, 0, 0, Color.Green.ToArgb());
                    verts[3] = new CustomVertex.PositionNormalColored(x2, y2, z2, 1, 0, 0, Color.Green.ToArgb());
                    aryStrips.Add(verts);
                }
            }

            //Go through and create the front and back panes.
            z1 = -fltZ*0.5f; z2 = fltZ*0.5f;
            for(int iYDiv=0; iYDiv<iYDivs; iYDiv++)
            {
                y1 = -fltY*0.5f + (fltYDiv*iYDiv);
                y2 = -fltY*0.5f + (fltYDiv*(iYDiv+1));

                for(int iXDiv=0; iXDiv<iXDivs; iXDiv++)
                {
                    x1 = -fltX*0.5f + (fltXDiv*iXDiv);
                    x2 = -fltX*0.5f + (fltXDiv*(iXDiv+1));

                    verts = new CustomVertex.PositionNormalColored[4];
                    verts[0] = new CustomVertex.PositionNormalColored(x1, y1, z1, 0, 0, -1, Color.Yellow.ToArgb());
                    verts[1] = new CustomVertex.PositionNormalColored(x1, y2, z1, 0, 0, -1, Color.Yellow.ToArgb());
                    verts[2] = new CustomVertex.PositionNormalColored(x2, y1, z1, 0, 0, -1, Color.Yellow.ToArgb());
                    verts[3] = new CustomVertex.PositionNormalColored(x2, y2, z1, 0, 0, -1, Color.Yellow.ToArgb());
                    aryStrips.Add(verts);

                    verts = new CustomVertex.PositionNormalColored[4];
                    verts[0] = new CustomVertex.PositionNormalColored(x1, y1, z2, 0, 0, 1, Color.Violet.ToArgb());
                    verts[1] = new CustomVertex.PositionNormalColored(x2, y1, z2, 0, 0, 1, Color.Violet.ToArgb());
                    verts[2] = new CustomVertex.PositionNormalColored(x1, y2, z2, 0, 0, 1, Color.Violet.ToArgb());
                    verts[3] = new CustomVertex.PositionNormalColored(x2, y2, z2, 0, 0, 1, Color.Violet.ToArgb());
                    aryStrips.Add(verts);
                }
            }

            aryTriangleList = ConvertTriStripToTriList(aryStrips, true, new CustomVertex.PositionNormalColored(0,0,0,0,0,0,0));
            return CreateMeshFromTriangleList(d3dDevice, aryTriangleList, new CustomVertex.PositionNormalColored(0,0,0,0,0,0,0));
        }