public void Render( double delta, VertexP3fC4b[] vertices, VertexP3fC4b[] lineVertices,
            ref int index, ref int lineIndex)
        {
            float offset = MinDist < 32 * 32 ? 1/32f : 1/16f;
            Vector3 p1 = (Vector3)Min - new Vector3( offset );
            Vector3 p2 = (Vector3)Max + new Vector3( offset );
            FastColour col = Colour;

            YQuad( vertices, ref index, p1.X, p1.Z, p2.X, p2.Z, p1.Y, col ); // bottom
            YQuad( vertices, ref index, p1.X, p1.Z, p2.X, p2.Z, p2.Y, col ); // top
            XQuad( vertices, ref index, p1.X, p1.Y, p2.X, p2.Y, p1.Z, col ); // sides
            XQuad( vertices, ref index, p1.X, p1.Y, p2.X, p2.Y, p2.Z, col );
            ZQuad( vertices, ref index, p1.Z, p1.Y, p2.Z, p2.Y, p1.X, col );
            ZQuad( vertices, ref index, p1.Z, p1.Y, p2.Z, p2.Y, p2.X, col );

            col = new FastColour( (byte)~col.R, (byte)~col.G, (byte)~col.B );
            // bottom face
            Line( lineVertices, ref lineIndex, p1.X, p1.Y, p1.Z, p2.X, p1.Y, p1.Z, col );
            Line( lineVertices, ref lineIndex, p2.X, p1.Y, p1.Z, p2.X, p1.Y, p2.Z, col );
            Line( lineVertices, ref lineIndex, p2.X, p1.Y, p2.Z, p1.X, p1.Y, p2.Z, col );
            Line( lineVertices, ref lineIndex, p1.X, p1.Y, p2.Z, p1.X, p1.Y, p1.Z, col );
            // top face
            Line( lineVertices, ref lineIndex, p1.X, p2.Y, p1.Z, p2.X, p2.Y, p1.Z, col );
            Line( lineVertices, ref lineIndex, p2.X, p2.Y, p1.Z, p2.X, p2.Y, p2.Z, col );
            Line( lineVertices, ref lineIndex, p2.X, p2.Y, p2.Z, p1.X, p2.Y, p2.Z, col );
            Line( lineVertices, ref lineIndex, p1.X, p2.Y, p2.Z, p1.X, p2.Y, p1.Z, col );
            // side faces
            Line( lineVertices, ref lineIndex, p1.X, p1.Y, p1.Z, p1.X, p2.Y, p1.Z, col );
            Line( lineVertices, ref lineIndex, p2.X, p1.Y, p1.Z, p2.X, p2.Y, p1.Z, col );
            Line( lineVertices, ref lineIndex, p2.X, p1.Y, p2.Z, p2.X, p2.Y, p2.Z, col );
            Line( lineVertices, ref lineIndex, p1.X, p1.Y, p2.Z, p1.X, p2.Y, p2.Z, col );
        }
 void HorQuad(ref int index, float x1, float z1, float x2, float z2, float y, FastColour col)
 {
     vertices[index++] = new VertexP3fC4b(x1, y, z1, col);
     vertices[index++] = new VertexP3fC4b(x1, y, z2, col);
     vertices[index++] = new VertexP3fC4b(x2, y, z2, col);
     vertices[index++] = new VertexP3fC4b(x2, y, z1, col);
 }
 void VerQuad( ref int index, float x1, float y1, float z1, float x2, float y2, float z2, FastColour col )
 {
     vertices[index++] = new VertexP3fC4b( x1, y1, z1, col );
     vertices[index++] = new VertexP3fC4b( x1, y2, z1, col );
     vertices[index++] = new VertexP3fC4b( x2, y2, z2, col );
     vertices[index++] = new VertexP3fC4b( x2, y1, z2, col );
 }
        void DrawSkyY(int x1, int z1, int x2, int z2, int y, int axisSize, int col, VertexP3fC4b[] vertices)
        {
            int endX = x2, endZ = z2, startZ = z1;
            int i = 0;

            for (; x1 < endX; x1 += axisSize)
            {
                x2 = x1 + axisSize;
                if (x2 > endX)
                {
                    x2 = endX;
                }
                z1 = startZ;
                for (; z1 < endZ; z1 += axisSize)
                {
                    z2 = z1 + axisSize;
                    if (z2 > endZ)
                    {
                        z2 = endZ;
                    }

                    vertices[i++] = new VertexP3fC4b(x1, y, z1, col);
                    vertices[i++] = new VertexP3fC4b(x1, y, z2, col);
                    vertices[i++] = new VertexP3fC4b(x2, y, z2, col);
                    vertices[i++] = new VertexP3fC4b(x2, y, z1, col);
                }
            }
        }
 void XQuad(float x, float z1, float y1, float z2, float y2)
 {
     vertices[index++] = new VertexP3fC4b(x, y1, z1, col);
     vertices[index++] = new VertexP3fC4b(x, y2, z1, col);
     vertices[index++] = new VertexP3fC4b(x, y2, z2, col);
     vertices[index++] = new VertexP3fC4b(x, y1, z2, col);
 }
 void ZQuad(float z, float x1, float y1, float x2, float y2)
 {
     vertices[index++] = new VertexP3fC4b(x1, y1, z, col);
     vertices[index++] = new VertexP3fC4b(x1, y2, z, col);
     vertices[index++] = new VertexP3fC4b(x2, y2, z, col);
     vertices[index++] = new VertexP3fC4b(x2, y1, z, col);
 }
 void InitData()
 {
     vertices     = new VertexP3fC4b[256 * VerticesCount];
     lineVertices = new VertexP3fC4b[256 * LineVerticesCount];
     vb           = Graphics.CreateDynamicVb(VertexFormat.P3fC4b, vertices.Length);
     lineVb       = Graphics.CreateDynamicVb(VertexFormat.P3fC4b, lineVertices.Length);
 }
 void YQuad(float y, float x1, float z1, float x2, float z2)
 {
     vertices[index++] = new VertexP3fC4b(x1, y, z1, col);
     vertices[index++] = new VertexP3fC4b(x1, y, z2, col);
     vertices[index++] = new VertexP3fC4b(x2, y, z2, col);
     vertices[index++] = new VertexP3fC4b(x2, y, z1, col);
 }
 static void XQuad( VertexP3fC4b[] vertices, ref int index, float x1, float y1, 
     float x2, float y2, float z, FastColour col)
 {
     vertices[index++] = new VertexP3fC4b( x1, y1, z, col );
     vertices[index++] = new VertexP3fC4b( x1, y2, z, col );
     vertices[index++] = new VertexP3fC4b( x2, y2, z, col );
     vertices[index++] = new VertexP3fC4b( x2, y1, z, col );
 }
 static void XQuad(VertexP3fC4b[] vertices, ref int index, float x1, float y1,
                   float x2, float y2, float z, FastColour col)
 {
     vertices[index++] = new VertexP3fC4b(x1, y1, z, col);
     vertices[index++] = new VertexP3fC4b(x1, y2, z, col);
     vertices[index++] = new VertexP3fC4b(x2, y2, z, col);
     vertices[index++] = new VertexP3fC4b(x2, y1, z, col);
 }
 static void YQuad(VertexP3fC4b[] vertices, ref int index, float x1, float z1,
                   float x2, float z2, float y, FastColour col)
 {
     vertices[index++] = new VertexP3fC4b(x1, y, z1, col);
     vertices[index++] = new VertexP3fC4b(x1, y, z2, col);
     vertices[index++] = new VertexP3fC4b(x2, y, z2, col);
     vertices[index++] = new VertexP3fC4b(x2, y, z1, col);
 }
 static void ZQuad(VertexP3fC4b[] vertices, ref int index, float z1, float y1,
                   float z2, float y2, float x, FastColour col)
 {
     vertices[index++] = new VertexP3fC4b(x, y1, z1, col);
     vertices[index++] = new VertexP3fC4b(x, y2, z1, col);
     vertices[index++] = new VertexP3fC4b(x, y2, z2, col);
     vertices[index++] = new VertexP3fC4b(x, y1, z2, col);
 }
Example #13
0
 internal static void HorQuad(VertexP3fC4b[] vertices, ref int index, int col,
                              float x1, float z1, float x2, float z2, float y)
 {
     vertices[index++] = new VertexP3fC4b(x1, y, z1, col);
     vertices[index++] = new VertexP3fC4b(x1, y, z2, col);
     vertices[index++] = new VertexP3fC4b(x2, y, z2, col);
     vertices[index++] = new VertexP3fC4b(x2, y, z1, col);
 }
Example #14
0
        void DrawPlane(int x1, int x2, int z1, int z2, int y1, int y2, int col, VertexP3fC4b[] vertices, ref int index)
        {
            const int scale = 8;

            x1 *= scale; x2 *= scale; z1 *= scale; z2 *= scale;
            vertices[index++] = new VertexP3fC4b(x1, y1 + 0.1f, z1, col);
            vertices[index++] = new VertexP3fC4b(x1, y2 + 0.1f, z1, col);
            vertices[index++] = new VertexP3fC4b(x2, y2 + 0.1f, z2, col);
            vertices[index++] = new VertexP3fC4b(x2, y1 + 0.1f, z2, col);
        }
        void RebuildSky(int extent, int axisSize)
        {
            extent = Utils.AdjViewDist(extent);
            int x1 = -extent, x2 = map.Width + extent;
            int z1 = -extent, z2 = map.Length + extent;

            skyVertices = Utils.CountVertices(x2 - x1, z2 - z1, axisSize);

            VertexP3fC4b[] vertices = new VertexP3fC4b[skyVertices];
            int            height = Math.Max(map.Height + 2 + 6, map.Env.CloudHeight + 6);

            DrawSkyY(x1, z1, x2, z2, height, axisSize, map.Env.SkyCol.Pack(), vertices);
            skyVb = gfx.CreateVb(vertices, VertexFormat.P3fC4b, skyVertices);
        }
Example #16
0
        void RebuildSky(int extent, int axisSize)
        {
            extent = Utils.AdjViewDist(extent);
            int x1 = -extent, x2 = map.Width + extent;
            int z1 = -extent, z2 = map.Length + extent;

            skyVertices = Utils.CountVertices(x2 - x1, z2 - z1, axisSize);

            VertexP3fC4b[] vertices = new VertexP3fC4b[skyVertices];
            int            height = Math.Max(map.Height + 2 + 6, map.Env.CloudHeight + 6);

            DrawSkyY(x1, z1, x2, z2, height, axisSize, map.Env.SkyCol, vertices);
            fixed(VertexP3fC4b *ptr = vertices)
            {
                skyVb = game.Graphics.CreateVb((IntPtr)ptr, VertexFormat.P3fC4b, skyVertices);
            }
        }
Example #17
0
        public void Render(double delta)
        {
            if (selections.Count == 0 || game.Graphics.LostContext)
            {
                return;
            }

            // TODO: Proper selection box sorting. But this is very difficult because
            // we can have boxes within boxes, intersecting boxes, etc. Probably not worth it.
            Vector3 camPos = game.CurrentCameraPos;

            for (int i = 0; i < selections.Count; i++)
            {
                comparer.Intersect(selections[i], camPos);
            }
            selections.Sort(comparer);

            if (vertices == null)               // lazy init as most servers don't use this.
            {
                vertices     = new VertexP3fC4b[256 * VerticesCount];
                lineVertices = new VertexP3fC4b[256 * LineVerticesCount];
                ContextRecreated();
            }

            int index = 0, lineIndex = 0;

            for (int i = 0; i < selections.Count; i++)
            {
                SelectionBox box = selections[i];
                box.Render(delta, vertices, lineVertices, ref index, ref lineIndex);
            }

            IGraphicsApi gfx = game.Graphics;

            gfx.SetBatchFormat(VertexFormat.P3fC4b);
            gfx.UpdateDynamicVb_Lines(lineVb, lineVertices,
                                      selections.Count * LineVerticesCount);

            gfx.DepthWrite    = false;
            gfx.AlphaBlending = true;
            gfx.UpdateDynamicVb_IndexedTris(vb, vertices,
                                            selections.Count * VerticesCount);
            gfx.DepthWrite    = true;
            gfx.AlphaBlending = false;
        }
 void XQuad( float x, float z1, float y1, float z2, float y2 )
 {
     vertices[index++] = new VertexP3fC4b( x, y1, z1, col );
     vertices[index++] = new VertexP3fC4b( x, y2, z1, col );
     vertices[index++] = new VertexP3fC4b( x, y2, z2, col );
     vertices[index++] = new VertexP3fC4b( x, y1, z2, col );
 }
        void DrawSkyY( int x1, int z1, int x2, int z2, int y, int axisSize, FastColour col, VertexP3fC4b[] vertices )
        {
            int endX = x2, endZ = z2, startZ = z1;
            int i = 0;

            for( ; x1 < endX; x1 += axisSize ) {
                x2 = x1 + axisSize;
                if( x2 > endX ) x2 = endX;
                z1 = startZ;
                for( ; z1 < endZ; z1 += axisSize ) {
                    z2 = z1 + axisSize;
                    if( z2 > endZ ) z2 = endZ;

                    vertices[i++] = new VertexP3fC4b( x1, y, z1, col );
                    vertices[i++] = new VertexP3fC4b( x1, y, z2, col );
                    vertices[i++] = new VertexP3fC4b( x2, y, z2, col );
                    vertices[i++] = new VertexP3fC4b( x2, y, z1, col );
                }
            }
        }
 void ZQuad( float z, float x1, float y1, float x2, float y2 )
 {
     vertices[index++] = new VertexP3fC4b( x1, y1, z, col );
     vertices[index++] = new VertexP3fC4b( x1, y2, z, col );
     vertices[index++] = new VertexP3fC4b( x2, y2, z, col );
     vertices[index++] = new VertexP3fC4b( x2, y1, z, col );
 }
 void YQuad( float y, float x1, float z1, float x2, float z2 )
 {
     vertices[index++] = new VertexP3fC4b( x1, y, z1, col );
     vertices[index++] = new VertexP3fC4b( x1, y, z2, col );
     vertices[index++] = new VertexP3fC4b( x2, y, z2, col );
     vertices[index++] = new VertexP3fC4b( x2, y, z1, col );
 }
Example #22
0
 static void Line(VertexP3fC4b[] vertices, ref int index, float x1, float y1, float z1,
                  float x2, float y2, float z2, int col)
 {
     vertices[index++] = new VertexP3fC4b(x1, y1, z1, col);
     vertices[index++] = new VertexP3fC4b(x2, y2, z2, col);
 }
        void ResetSky( int extent, int axisSize )
        {
            extent = Utils.AdjViewDist( extent );
            int x1 = -extent, x2 = map.Width + extent;
            int z1 = -extent, z2 = map.Length + extent;
            skyVertices = Utils.CountVertices( x2 - x1, z2 - z1, axisSize );

            VertexP3fC4b[] vertices = new VertexP3fC4b[skyVertices];
            int height = Math.Max( map.Height + 2 + 6, map.Env.CloudHeight + 6);

            DrawSkyY( x1, z1, x2, z2, height, axisSize, map.Env.SkyCol, vertices );
            skyVb = graphics.CreateVb( vertices, VertexFormat.P3fC4b, skyVertices );
        }
 static void YQuad( VertexP3fC4b[] vertices, ref int index, float x1, float z1, 
     float x2, float z2, float y, FastColour col)
 {
     vertices[index++] = new VertexP3fC4b( x1, y, z1, col );
     vertices[index++] = new VertexP3fC4b( x1, y, z2, col );
     vertices[index++] = new VertexP3fC4b( x2, y, z2, col );
     vertices[index++] = new VertexP3fC4b( x2, y, z1, col );
 }
 static void Line( VertexP3fC4b[] vertices, ref int index, float x1, float y1, float z1, 
     float x2, float y2, float z2, FastColour col)
 {
     vertices[index++] = new VertexP3fC4b( x1, y1, z1, col );
     vertices[index++] = new VertexP3fC4b( x2, y2, z2, col );
 }
 static void ZQuad( VertexP3fC4b[] vertices, ref int index, float z1, float y1, 
     float z2, float y2, float x, FastColour col)
 {
     vertices[index++] = new VertexP3fC4b( x, y1, z1, col );
     vertices[index++] = new VertexP3fC4b( x, y2, z1, col );
     vertices[index++] = new VertexP3fC4b( x, y2, z2, col );
     vertices[index++] = new VertexP3fC4b( x, y1, z2, col );
 }
Example #27
0
        void CalcClouds(FastBitmap fastBmp)
        {
            Console.WriteLine("BEGIN CLOUDS!");
            int elements = 0;
            int col      = map.Env.CloudsCol.Pack();

            for (int y = 0; y < fastBmp.Height; y++)
            {
                int *row = fastBmp.GetRowPtr(y);
                for (int x = 0; x < fastBmp.Width; x++)
                {
                    if ((row[x] & 0xFFFFFF) != 0)
                    {
                        if (!IsSolid(x - 1, y, fastBmp))
                        {
                            elements++;
                        }
                        if (!IsSolid(x + 1, y, fastBmp))
                        {
                            elements++;
                        }
                        if (!IsSolid(x, y - 1, fastBmp))
                        {
                            elements++;
                        }
                        if (!IsSolid(x, y + 1, fastBmp))
                        {
                            elements++;
                        }
                    }
                }
            }

            cloudsJoinVertices = elements * 4;
            VertexP3fC4b[] vertices = new VertexP3fC4b[cloudsJoinVertices];
            int            index    = 0;

            // Pass #2: Make the vertices.
            int cloudY = map.Height + 2;

            for (int y = 0; y < fastBmp.Height; y++)
            {
                int *row = fastBmp.GetRowPtr(y);
                for (int x = 0; x < fastBmp.Width; x++)
                {
                    if ((row[x] & 0xFFFFFF) != 0)
                    {
                        if (!IsSolid(x - 1, y, fastBmp))
                        {
                            DrawPlane(x, x, y, y + 1, cloudY, cloudY + 5, col, vertices, ref index);
                        }
                        if (!IsSolid(x + 1, y, fastBmp))
                        {
                            DrawPlane(x + 1, x + 1, y, y + 1, cloudY, cloudY + 5, col, vertices, ref index);
                        }
                        if (!IsSolid(x, y - 1, fastBmp))
                        {
                            DrawPlane(x, x + 1, y, y, cloudY, cloudY + 5, col, vertices, ref index);
                        }
                        if (!IsSolid(x, y + 1, fastBmp))
                        {
                            DrawPlane(x, x + 1, y + 1, y + 1, cloudY, cloudY + 5, col, vertices, ref index);
                        }
                    }
                }
            }

            gfx.DeleteVb(ref cloudsJoinVb);
            fixed(VertexP3fC4b *ptr = vertices)
            {
                cloudsJoinVb = gfx.CreateVb((IntPtr)ptr, VertexFormat.P3fC4b, cloudsJoinVertices);
            }
        }
 void InitData()
 {
     vertices = new VertexP3fC4b[256 * VerticesCount];
     lineVertices = new VertexP3fC4b[256 * LineVerticesCount];
     vb = Graphics.CreateDynamicVb( VertexFormat.P3fC4b, vertices.Length );
     lineVb = Graphics.CreateDynamicVb( VertexFormat.P3fC4b, lineVertices.Length );
 }