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 );
        }
Beispiel #2
0
        public SelectionBox( Vector3I start, Vector3I end, FastColour col, IGraphicsApi graphics )
        {
            Graphics = graphics;
            Min = Vector3I.Min( start, end );
            Max = Vector3I.Max( start, end );
            int index = 0;
            Vector3 p1 = (Vector3)Min + new Vector3( 1/16f, 1/16f, 1/16f );
            Vector3 p2 = (Vector3)Max - new Vector3( 1/16f, 1/16f, 1/16f );

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

            col = new FastColour( (byte)~col.R, (byte)~col.G, (byte)~col.B );
            // bottom face
            Line( ref index, p1.X, p1.Y, p1.Z, p2.X, p1.Y, p1.Z, col );
            Line( ref index, p2.X, p1.Y, p1.Z, p2.X, p1.Y, p2.Z, col );
            Line( ref index, p2.X, p1.Y, p2.Z, p1.X, p1.Y, p2.Z, col );
            Line( ref index, p1.X, p1.Y, p2.Z, p1.X, p1.Y, p1.Z, col );
            // top face
            Line( ref index, p1.X, p2.Y, p1.Z, p2.X, p2.Y, p1.Z, col );
            Line( ref index, p2.X, p2.Y, p1.Z, p2.X, p2.Y, p2.Z, col );
            Line( ref index, p2.X, p2.Y, p2.Z, p1.X, p2.Y, p2.Z, col );
            Line( ref index, p1.X, p2.Y, p2.Z, p1.X, p2.Y, p1.Z, col );
            // side faces
            Line( ref index, p1.X, p1.Y, p1.Z, p1.X, p2.Y, p1.Z, col );
            Line( ref index, p2.X, p1.Y, p1.Z, p2.X, p2.Y, p1.Z, col );
            Line( ref index, p2.X, p1.Y, p2.Z, p2.X, p2.Y, p2.Z, col );
            Line( ref index, p1.X, p1.Y, p2.Z, p1.X, p2.Y, p2.Z, col );

            Vb = Graphics.CreateVb( vertices, VertexFormat.Pos3fCol4b, VerticesCount + LineVerticesCount );
        }
 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 );
 }
 public void AddSelection( byte id, Vector3I p1, Vector3I p2, FastColour col )
 {
     RemoveSelection( id );
     SelectionBox selection = new SelectionBox( p1, p2, col );
     selection.ID = id;
     selections.Add( selection );
 }
        public void Render( double delta, Vector3 cameraPos, VertexPos3fCol4b[] vertices, VertexPos3fCol4b[] lineVertices,
		                  ref int index, ref int lineIndex )
        {
            float dist = Math.Min( Utils.DistanceSquared( (Vector3)Min, cameraPos ),
                                  Utils.DistanceSquared( (Vector3)Max, cameraPos ) );
            float offset = dist < 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 );
        }
 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( VertexPos3fCol4b[] vertices, ref int index, float x1, float z1, 
		                  float x2, float z2, float y, FastColour col )
        {
            vertices[index++] = new VertexPos3fCol4b( x1, y, z1, col );
            vertices[index++] = new VertexPos3fCol4b( x1, y, z2, col );
            vertices[index++] = new VertexPos3fCol4b( x2, y, z2, col );
            vertices[index++] = new VertexPos3fCol4b( x2, y, z1, col );
        }
Beispiel #8
0
        /// <summary> Renders the model based on the given entity's position and orientation. </summary>
        public void RenderModel( Player p )
        {
            index = 0;
            pos = p.Position;
            cosA = (float)Math.Cos( p.YawRadians );
            sinA = (float)Math.Sin( p.YawRadians );
            Map map = game.Map;
            col = game.Map.IsLit( Vector3I.Floor( p.EyePosition ) ) ? map.Sunlight : map.Shadowlight;

            graphics.SetBatchFormat( VertexFormat.Pos3fTex2fCol4b );
            DrawPlayerModel( p );
        }
Beispiel #9
0
        public void RenderModel( Player p )
        {
            index = 0;
            pos = p.Position;
            cosA = (float)Math.Cos( p.YawRadians );
            sinA = (float)Math.Sin( p.YawRadians );
            Map map = game.Map;
            col = game.Map.IsLit( Vector3I.Floor( p.EyePosition ) ) ? map.Sunlight : map.Shadowlight;

            graphics.BeginVbBatch( VertexFormat.Pos3fTex2fCol4b );
            DrawPlayerModel( p );
            graphics.DrawDynamicIndexedVb( DrawMode.Triangles, cache.vb, cache.vertices, index, index * 6 / 4 );
        }
        bool Parse(int index, ref FastColour dst)
        {
            byte r, g, b;

            if (!Byte.TryParse(widgets[index + 0].Text, out r) ||
                !Byte.TryParse(widgets[index + 1].Text, out g) ||
                !Byte.TryParse(widgets[index + 2].Text, out b))
            {
                return(false);
            }
            dst.R = r; dst.G = g; dst.B = b;
            return(true);
        }
Beispiel #11
0
        public void Init(Game game)
        {
            this.game = game;
            graphics  = game.Graphics;
            col       = new FastColour(0, 0, 0, 102).Pack();
            col2      = new FastColour(255, 255, 255, 127).Pack();
            //col2 = FastColour.WhitePacked;

            ContextRecreated();
            //game.Events.TerrainAtlasChanged += ResetTextures;
            game.Graphics.ContextLost      += ContextLost;
            game.Graphics.ContextRecreated += ContextRecreated;
        }
Beispiel #12
0
        void RenderBottomCornerFace(TileDrawInfo drawInfo, Vertex[] vertices, int index)
        {
            FastColour colour = TerrainHelper.GetColour(drawInfo.CurrentTile.TerrainId);

            vertices[index]     = new Vertex(X + 0.5f, height, Y, colour);
            vertices[index + 1] = new Vertex(X, z2, Y + 0.5f, colour);
            vertices[index + 2] = new Vertex(X + 0.5f, height, Y + tileWidth, colour);

            vertices[index + 3]      = new Vertex(X + 0.5f, height, Y, colour);
            vertices[index + 4]      = new Vertex(X + tileWidth, z1, Y + 0.5f, colour);
            vertices[index + 5]      = new Vertex(X + 0.5f, height, Y + tileWidth, colour);
            drawInfo.TotalTriangles += 2;
        }
Beispiel #13
0
        public virtual void Draw2DQuad(float x, float y, float width, float height,
                                       FastColour topCol, FastColour bottomCol)
        {
            int c = topCol.Pack();

            quadVerts[0] = new VertexP3fC4b(x, y, 0, c);
            quadVerts[1] = new VertexP3fC4b(x + width, y, 0, c);
            c            = bottomCol.Pack();
            quadVerts[2] = new VertexP3fC4b(x + width, y + height, 0, c);
            quadVerts[3] = new VertexP3fC4b(x, y + height, 0, c);
            SetBatchFormat(VertexFormat.P3fC4b);
            UpdateDynamicIndexedVb(DrawMode.Triangles, quadVb, quadVerts, 4);
        }
Beispiel #14
0
        /// <summary> Sets current shadowlight colour, and raises
        /// EnvVariableChanged event with variable 'ShadowlightColour'. </summary>
        public void SetShadowlight(FastColour col)
        {
            if (col == Shadowlight)
            {
                return;
            }

            Shadowlight = col;
            FastColour.GetShaded(col, out ShadowXSide,
                                 out ShadowZSide, out ShadowYBottom);
            Shadow = Shadowlight.Pack();
            game.WorldEvents.RaiseEnvVariableChanged(EnvVar.ShadowlightColour);
        }
        void DrawScrollbar(IDrawer2D drawer)
        {
            FastColour col = Window.ClassicMode ? new FastColour(80, 80, 80) : LauncherSkin.ButtonBorderCol;

            drawer.Clear(col, Window.Width - 10, Y, 10, Height);
            float scale = Height / (float)Count;

            col = Window.ClassicMode ? new FastColour(160, 160, 160) : LauncherSkin.ButtonForeActiveCol;
            int y1     = (int)(Y + CurrentIndex * scale);
            int height = (int)((maxIndex - CurrentIndex) * scale);

            drawer.Clear(col, Window.Width - 10, y1, 10, height + 1);
        }
Beispiel #16
0
        protected override void RenderTopFace(TileDrawInfo drawInfo, int index)
        {
            FastColour colour = TerrainHelper.GetColour(drawInfo.CurrentTile.TerrainId);

            vertices[index]     = new Vertex(x, z2, y + halfTileLength, colour);
            vertices[index + 1] = new Vertex(x + halfTileWidth, z1, y, colour);
            vertices[index + 2] = new Vertex(x + tileWidth, z1, y + halfTileLength, colour);

            vertices[index + 3]      = new Vertex(x + tileWidth, z1, y + halfTileLength, colour);
            vertices[index + 4]      = new Vertex(x + halfTileWidth, z2, y + tileLength, colour);
            vertices[index + 5]      = new Vertex(x, z2, y + halfTileLength, colour);
            drawInfo.TotalTriangles += 2;
        }
        void WriteColourCompound(string name, FastColour col)
        {
            nbt.Write(NbtTagType.Compound); nbt.Write(name);

            nbt.Write(NbtTagType.Int16);
            nbt.Write("R"); nbt.WriteInt16(col.R);
            nbt.Write(NbtTagType.Int16);
            nbt.Write("G"); nbt.WriteInt16(col.G);
            nbt.Write(NbtTagType.Int16);
            nbt.Write("B"); nbt.WriteInt16(col.B);

            nbt.Write(NbtTagType.End);
        }
        public virtual void Draw2DQuad(int x, int y, int width, int height,
                                       FastColour topCol, FastColour bottomCol)
        {
            int c = topCol.Pack();

            quadVerts[0] = new VertexP3fC4b(x, y, 0, c);
            quadVerts[1] = new VertexP3fC4b(x + width, y, 0, c);
            c            = bottomCol.Pack();
            quadVerts[2] = new VertexP3fC4b(x + width, y + height, 0, c);
            quadVerts[3] = new VertexP3fC4b(x, y + height, 0, c);
            SetBatchFormat(VertexFormat.P3fC4b);
            UpdateDynamicVb_IndexedTris(quadVb, quadVerts, 4);
        }
Beispiel #19
0
        /// <summary> Resets all of the environment properties to their defaults. </summary>
        public void Reset()
        {
            EdgeHeight  = -1; SidesOffset = -2; CloudHeight = -1;
            EdgeBlock   = Block.StillWater; SidesBlock = Block.Bedrock;
            CloudsSpeed = 1; WeatherSpeed = 1; WeatherFade = 1;

            ResetLight();
            SkyCol    = DefaultSkyColour;
            FogCol    = DefaultFogColour;
            CloudsCol = DefaultCloudsColour;
            Weather   = Weather.Sunny;
            ExpFog    = false;
        }
        protected override void DrawModel(Player p)
        {
            // TODO: using 'is' is ugly, but means we can avoid creating
            // a string every single time held block changes.
            if (p is FakePlayer)
            {
                Vector3I   eyePos  = Vector3I.Floor(game.LocalPlayer.EyePosition);
                FastColour baseCol = game.Map.IsLit(eyePos) ? game.Map.Sunlight : game.Map.Shadowlight;
                col   = FastColour.Scale(baseCol, 0.8f);
                block = ((FakePlayer)p).Block;
            }
            else
            {
                block = Byte.Parse(p.ModelName);
            }

            CalcState(block);
            if (game.BlockInfo.IsAir[block])
            {
                return;
            }
            lastTexId = -1;
            atlas     = game.TerrainAtlas1D;

            if (game.BlockInfo.IsSprite[block])
            {
                SpriteXQuad(TileSide.Right, false);
                SpriteZQuad(TileSide.Back, false);

                SpriteZQuad(TileSide.Back, true);
                SpriteXQuad(TileSide.Right, true);
            }
            else
            {
                YQuad(0, TileSide.Bottom, FastColour.ShadeYBottom);
                XQuad(maxBB.X - 0.5f, TileSide.Right, true, FastColour.ShadeX);
                ZQuad(minBB.Z - 0.5f, TileSide.Front, true, FastColour.ShadeZ);

                ZQuad(maxBB.Z - 0.5f, TileSide.Back, false, FastColour.ShadeZ);
                YQuad(height, TileSide.Top, 1.0f);
                XQuad(minBB.X - 0.5f, TileSide.Left, false, FastColour.ShadeX);
            }

            if (index == 0)
            {
                return;
            }
            graphics.BindTexture(lastTexId);
            TransformVertices();
            graphics.UpdateDynamicIndexedVb(DrawMode.Triangles, cache.vb, cache.vertices, index, index * 6 / 4);
        }
Beispiel #21
0
        void RenderTopCornerFaceRotated(TileDrawInfo drawInfo, Vertex[] vertices, int index)
        {
            float      height = this.height + tileHeight;
            FastColour colour = TerrainHelper.GetColour(drawInfo.CurrentTile.TerrainId);

            vertices[index]     = new Vertex(X, height, Y + 0.5f, colour);
            vertices[index + 1] = new Vertex(X + 0.5f, z1, Y, colour);
            vertices[index + 2] = new Vertex(X + tileWidth, height, Y + 0.5f, colour);

            vertices[index + 3]      = new Vertex(X + tileWidth, height, Y + 0.5f, colour);
            vertices[index + 4]      = new Vertex(X + 0.5f, z2, Y + tileWidth, colour);
            vertices[index + 5]      = new Vertex(X, height, Y + 0.5f, colour);
            drawInfo.TotalTriangles += 2;
        }
Beispiel #22
0
        protected override void RenderTopCornerFace(TileDrawInfo drawInfo, int index)
        {
            float      height = this.height + tileHeight;
            FastColour colour = TerrainHelper.GetColour(drawInfo.CurrentTile.TerrainId);

            vertices[index]     = new Vertex(x + 0.5f, height, y, colour);
            vertices[index + 1] = new Vertex(x, z2, y + 0.5f, colour);
            vertices[index + 2] = new Vertex(x + 0.5f, height, y + tileWidth, colour);

            vertices[index + 3]      = new Vertex(x + 0.5f, height, y, colour);
            vertices[index + 4]      = new Vertex(x + tileWidth, z1, y + 0.5f, colour);
            vertices[index + 5]      = new Vertex(x + 0.5f, height, y + tileWidth, colour);
            drawInfo.TotalTriangles += 2;
        }
Beispiel #23
0
        public override void DrawAll()
        {
            MakeWidgets();
            RedrawAllButtonBackgrounds();

            using (drawer) {
                drawer.SetBitmap(game.Framebuffer);
                RedrawAll();
                FastColour col = LauncherSkin.ButtonBorderCol;
                int        midX = game.Width / 2, midY = game.Height / 2;
                game.Drawer.DrawRect(col, midX - 250, midY - 35, 490, 1);
                game.Drawer.DrawRect(col, midX - 250, midY + 35, 490, 1);
            }
        }
Beispiel #24
0
        protected override void ContextRecreated()
        {
            widgets = new Widget[] {
                // Column 1
                MakeOpt(-1, -150, "Clouds col", OnWidgetClick,
                        g => g.World.Env.CloudsCol.ToRGBHexString(),
                        (g, v) => g.World.Env.SetCloudsColour(FastColour.Parse(v))),

                MakeOpt(-1, -100, "Sky col", OnWidgetClick,
                        g => g.World.Env.SkyCol.ToRGBHexString(),
                        (g, v) => g.World.Env.SetSkyColour(FastColour.Parse(v))),

                MakeOpt(-1, -50, "Fog col", OnWidgetClick,
                        g => g.World.Env.FogCol.ToRGBHexString(),
                        (g, v) => g.World.Env.SetFogColour(FastColour.Parse(v))),

                MakeOpt(-1, 0, "Clouds speed", OnWidgetClick,
                        g => g.World.Env.CloudsSpeed.ToString("F2"),
                        (g, v) => g.World.Env.SetCloudsSpeed(Utils.ParseDecimal(v))),

                MakeOpt(-1, 50, "Clouds height", OnWidgetClick,
                        g => g.World.Env.CloudHeight.ToString(),
                        (g, v) => g.World.Env.SetCloudsLevel(Int32.Parse(v))),

                // Column 2
                MakeOpt(1, -150, "Sunlight col", OnWidgetClick,
                        g => g.World.Env.Sunlight.ToRGBHexString(),
                        (g, v) => g.World.Env.SetSunlight(FastColour.Parse(v))),

                MakeOpt(1, -100, "Shadow col", OnWidgetClick,
                        g => g.World.Env.Shadowlight.ToRGBHexString(),
                        (g, v) => g.World.Env.SetShadowlight(FastColour.Parse(v))),

                MakeOpt(1, -50, "Weather", OnWidgetClick,
                        g => g.World.Env.Weather.ToString(),
                        (g, v) => g.World.Env.SetWeather((Weather)Enum.Parse(typeof(Weather), v))),

                MakeOpt(1, 0, "Rain/Snow speed", OnWidgetClick,
                        g => g.World.Env.WeatherSpeed.ToString("F2"),
                        (g, v) => g.World.Env.SetWeatherSpeed(Utils.ParseDecimal(v))),

                MakeOpt(1, 50, "Water level", OnWidgetClick,
                        g => g.World.Env.EdgeHeight.ToString(),
                        (g, v) => g.World.Env.SetEdgeLevel(Int32.Parse(v))),

                MakeBack(false, titleFont,
                         (g, w) => g.Gui.SetNewScreen(new OptionsGroupScreen(g))),
                null, null, null,
            };
        }
Beispiel #25
0
        public override void DrawAll()
        {
            MakeWidgets();
            RedrawAllButtonBackgrounds();

            using (drawer) {
                drawer.SetBitmap(game.Framebuffer);
                RedrawAll();
                FastColour col    = LauncherSkin.ButtonBorderCol;
                int        middle = game.Height / 2;
                game.Drawer.DrawRect(col, game.Width / 2 - 160, middle - 100, 320, 1);
                game.Drawer.DrawRect(col, game.Width / 2 - 160, middle - 5, 320, 1);
            }
        }
Beispiel #26
0
        void RenderTileBorders(TileDrawInfo drawInfo, VertexPos3Col4[] vertices, int index)
        {
            Tile  tile   = drawInfo.CurrentTile;
            float x      = tile.X;
            float y      = tile.Y;
            float height = tile.Height;

            FastColour colour = new FastColour(150, 150, 150);

            vertices[index]          = new VertexPos3Col4(x, height, y + 0.5f, colour);
            vertices[index + 1]      = new VertexPos3Col4(x + 0.5f, height, y, colour);
            vertices[index + 2]      = new VertexPos3Col4(x + tileWidth, height, y + 0.5f, colour);
            vertices[index + 3]      = new VertexPos3Col4(x + 0.5f, height, y + tileWidth, colour);
            drawInfo.TotalTriangles += 2;
        }
Beispiel #27
0
        void DrawTableBackground(FastBitmap dst)
        {
            int       tableHeight = Math.Max(game.Height - tableY - 50, 1);
            Rectangle rec         = new Rectangle(tableX, tableY, game.Width - tableX, tableHeight);

            if (!game.ClassicBackground)
            {
                FastColour col = TableView.backGridCol;
                Drawer2DExt.Clear(dst, rec, col);
            }
            else
            {
                game.ResetArea(rec.X, rec.Y, rec.Width, rec.Height, dst);
            }
        }
        public override void Render(double delta, float t, VertexPos3fTex2fCol4b[] vertices, ref int index)
        {
            Position = Vector3.Lerp(lastPos, nextPos, t);
            Vector3 p111, p121, p212, p222;

            Utils.CalcBillboardPoints(terrainSize, Position, ref game.View,
                                      out p111, out p121, out p212, out p222);
            Map        map = game.Map;
            FastColour col = map.IsLit(Vector3I.Floor(Position)) ? map.Sunlight : map.Shadowlight;

            vertices[index++] = new VertexPos3fTex2fCol4b(p111, rec.U1, rec.V2, col);
            vertices[index++] = new VertexPos3fTex2fCol4b(p121, rec.U1, rec.V1, col);
            vertices[index++] = new VertexPos3fTex2fCol4b(p222, rec.U2, rec.V1, col);
            vertices[index++] = new VertexPos3fTex2fCol4b(p212, rec.U2, rec.V2, col);
        }
        static void Get(string key, ref FastColour col)
        {
            FastColour defaultCol = col;
            string     value      = Options.Get(key);

            if (String.IsNullOrEmpty(value))
            {
                return;
            }

            if (!FastColour.TryParse(value, out col))
            {
                col = defaultCol;
            }
        }
        protected void DoRender(Game game, ref Vector2 size, ref TextureRec rec,
                                VertexP3fT2fC4b[] vertices, ref int index)
        {
            Vector3 p111, p121, p212, p222;

            Utils.CalcBillboardPoints(size, Position, ref game.View,
                                      out p111, out p121, out p212, out p222);
            World      map = game.World;
            FastColour col = map.IsLit(Position) ? map.Env.Sunlight : map.Env.Shadowlight;

            vertices[index++] = new VertexP3fT2fC4b(p111, rec.U1, rec.V2, col);
            vertices[index++] = new VertexP3fT2fC4b(p121, rec.U1, rec.V1, col);
            vertices[index++] = new VertexP3fT2fC4b(p222, rec.U2, rec.V1, col);
            vertices[index++] = new VertexP3fT2fC4b(p212, rec.U2, rec.V2, col);
        }
        void MakeRainForSquare(int x, float y, float height, int z, FastColour col, ref int index)
        {
            float worldV = vOffset + (z & 1) / 2f - (x & 0x0F) / 16f;
            float v1     = y / 6f + worldV;
            float v2     = (y + height) / 6f + worldV;

            vertices[index++] = new VertexP3fT2fC4b(x, y, z, 0, v1, col);
            vertices[index++] = new VertexP3fT2fC4b(x, y + height, z, 0, v2, col);
            vertices[index++] = new VertexP3fT2fC4b(x + 1, y + height, z + 1, 1, v2, col);
            vertices[index++] = new VertexP3fT2fC4b(x + 1, y, z + 1, 1, v1, col);

            vertices[index++] = new VertexP3fT2fC4b(x + 1, y, z, 1, v1, col);
            vertices[index++] = new VertexP3fT2fC4b(x + 1, y + height, z, 1, v2, col);
            vertices[index++] = new VertexP3fT2fC4b(x, y + height, z + 1, 0, v2, col);
            vertices[index++] = new VertexP3fT2fC4b(x, y, z + 1, 0, v1, col);
        }
Beispiel #32
0
        public static void Make2DQuad(ref Texture tex, FastColour col,
                                      VertexP3fT2fC4b[] vertices, ref int index)
        {
            float x1 = tex.X, y1 = tex.Y, x2 = tex.X + tex.Width, y2 = tex.Y + tex.Height;

                        #if USE_DX
            // NOTE: see "https://msdn.microsoft.com/en-us/library/windows/desktop/bb219690(v=vs.85).aspx",
            // i.e. the msdn article called "Directly Mapping Texels to Pixels (Direct3D 9)" for why we have to do this.
            x1 -= 0.5f; x2 -= 0.5f;
            y1 -= 0.5f; y2 -= 0.5f;
                        #endif
            int c = col.Pack();
            vertices[index++] = new VertexP3fT2fC4b(x1, y1, 0, tex.U1, tex.V1, c);
            vertices[index++] = new VertexP3fT2fC4b(x2, y1, 0, tex.U2, tex.V1, c);
            vertices[index++] = new VertexP3fT2fC4b(x2, y2, 0, tex.U2, tex.V2, c);
            vertices[index++] = new VertexP3fT2fC4b(x1, y2, 0, tex.U1, tex.V2, c);
        }
Beispiel #33
0
        protected void DrawPart(ModelPart part)
        {
            float vScale = _64x64 ? 64f : 32f;

            for (int i = 0; i < part.Count; i++)
            {
                ModelVertex model  = vertices[part.Offset + i];
                Vector3     newPos = Utils.RotateY(model.X, model.Y, model.Z, cosA, sinA) + pos;

                FastColour            col    = GetCol(i, part.Count);
                VertexPos3fTex2fCol4b vertex = default(VertexPos3fTex2fCol4b);
                vertex.X = newPos.X; vertex.Y = newPos.Y; vertex.Z = newPos.Z;
                vertex.R = col.R; vertex.G = col.G; vertex.B = col.B; vertex.A = 255;
                AdjustUV(model.U, model.V, vScale, i, ref vertex);
                cache.vertices[index++] = vertex;
            }
        }
        void UpdateStars()
        {
            float skyMul = (float)(Math.Cos(CelestialAngle * (2 * Math.PI)) * 4 + 0.5);

            Utils.Clamp(ref skyMul, 0, 1);
            FastColour newStarColour = FastColour.Lerp2(starColour, starColourHidden, skyMul);

            if (newStarColour != curStarColour)
            {
                int newStarColourPacked = newStarColour.Pack();
                for (int i = 0; i < starCount; i++)
                {
                    vertices4[i].Colour = newStarColourPacked;
                }
                curStarColour = newStarColour;
            }
        }
Beispiel #35
0
        void HandleSetTextColor()
        {
            FastColour col = new FastColour(reader.ReadUInt8(), reader.ReadUInt8(),
                                            reader.ReadUInt8(), reader.ReadUInt8());
            byte code = reader.ReadUInt8();

            if (code <= ' ' || code > '~')
            {
                return;                                        // Control chars, space, extended chars cannot be used
            }
            if (code == '%' || code == '&')
            {
                return;                                         // colour code signifiers cannot be used
            }
            IDrawer2D.Cols[code] = col;
            game.Events.RaiseColourCodeChanged((char)code);
        }
        void DrawTitles(IDrawer2D drawer, Font font)
        {
            int          x    = 0;
            DrawTextArgs args = new DrawTextArgs(null, font, false);

            for (int i = 0; i < elements.Length; i++)
            {
                args.Text = elements[i].Title;
                FastColour col = i == selectedIndex ? new FastColour(30, 30, 30, 200) :
                                 new FastColour(0, 0, 0, 127);;
                Size size = elements[i].TitleSize;

                drawer.Clear(col, x, 0, size.Width, size.Height);
                drawer.DrawText(ref args, x + titleSpacing / 2, 0);
                x += size.Width;
            }
        }
        unsafe void MakeVb()
        {
            VertexP3fT2fC4b *vertices = stackalloc VertexP3fT2fC4b[count];
            IntPtr           start    = (IntPtr)vertices;
            const float      pos      = 0.5f;
            TextureRec       rec;
            FastColour       col = game.World.Env.CloudsCol;

            // Render the front quad
            rec = new TextureRec(1 / 4f, 1 / 2f, 1 / 4f, 1 / 2f);
            *vertices = new VertexP3fT2fC4b(pos, -pos, -pos, rec.U1, rec.V2, col); vertices++;
            *vertices = new VertexP3fT2fC4b(-pos, -pos, -pos, rec.U2, rec.V2, col); vertices++;
            *vertices = new VertexP3fT2fC4b(-pos, pos, -pos, rec.U2, rec.V1, col); vertices++;
            *vertices = new VertexP3fT2fC4b(pos, pos, -pos, rec.U1, rec.V1, col); vertices++;
            // Render the left quad
            rec = new TextureRec(0 / 4f, 1 / 2f, 1 / 4f, 1 / 2f);
            *vertices = new VertexP3fT2fC4b(pos, -pos, pos, rec.U1, rec.V2, col); vertices++;
            *vertices = new VertexP3fT2fC4b(pos, -pos, -pos, rec.U2, rec.V2, col); vertices++;
            *vertices = new VertexP3fT2fC4b(pos, pos, -pos, rec.U2, rec.V1, col); vertices++;
            *vertices = new VertexP3fT2fC4b(pos, pos, pos, rec.U1, rec.V1, col); vertices++;
            // Render the back quad
            rec = new TextureRec(3 / 4f, 1 / 2f, 1 / 4f, 1 / 2f);
            *vertices = new VertexP3fT2fC4b(-pos, -pos, pos, rec.U1, rec.V2, col); vertices++;
            *vertices = new VertexP3fT2fC4b(pos, -pos, pos, rec.U2, rec.V2, col); vertices++;
            *vertices = new VertexP3fT2fC4b(pos, pos, pos, rec.U2, rec.V1, col); vertices++;
            *vertices = new VertexP3fT2fC4b(-pos, pos, pos, rec.U1, rec.V1, col); vertices++;
            // Render the right quad
            rec = new TextureRec(2 / 4f, 1 / 2f, 1 / 4f, 1 / 2f);
            *vertices = new VertexP3fT2fC4b(-pos, -pos, -pos, rec.U1, rec.V2, col); vertices++;
            *vertices = new VertexP3fT2fC4b(-pos, -pos, pos, rec.U2, rec.V2, col); vertices++;
            *vertices = new VertexP3fT2fC4b(-pos, pos, pos, rec.U2, rec.V1, col); vertices++;
            *vertices = new VertexP3fT2fC4b(-pos, pos, -pos, rec.U1, rec.V1, col); vertices++;
            // Render the top quad
            rec = new TextureRec(1 / 4f, 0 / 2f, 1 / 4f, 1 / 2f);
            *vertices = new VertexP3fT2fC4b(-pos, pos, -pos, rec.U2, rec.V2, col); vertices++;
            *vertices = new VertexP3fT2fC4b(-pos, pos, pos, rec.U2, rec.V1, col); vertices++;
            *vertices = new VertexP3fT2fC4b(pos, pos, pos, rec.U1, rec.V1, col); vertices++;
            *vertices = new VertexP3fT2fC4b(pos, pos, -pos, rec.U1, rec.V2, col); vertices++;
            // Render the bottom quad
            rec = new TextureRec(2 / 4f, 0 / 2f, 1 / 4f, 1 / 2f);
            *vertices = new VertexP3fT2fC4b(-pos, -pos, -pos, rec.U2, rec.V2, col); vertices++;
            *vertices = new VertexP3fT2fC4b(-pos, -pos, pos, rec.U2, rec.V1, col); vertices++;
            *vertices = new VertexP3fT2fC4b(pos, -pos, pos, rec.U1, rec.V1, col); vertices++;
            *vertices = new VertexP3fT2fC4b(pos, -pos, -pos, rec.U1, rec.V2, col); vertices++;
            vb = game.Graphics.CreateVb(start, VertexFormat.P3fT2fC4b, count);
        }
Beispiel #38
0
        FastColour GetColour(string key, FastColour def)
        {
            NbtTag tag;

            if (!curCpeExt.TryGetValue(key, out tag))
            {
                return(def);
            }

            NbtCompound compound = (NbtCompound)tag.Value;
            short       r        = (short)compound["R"].Value;
            short       g        = (short)compound["G"].Value;
            short       b        = (short)compound["B"].Value;
            bool        invalid  = r < 0 || r > 255 || g < 0 || g > 255 || b < 0 || b > 255;

            return(invalid ? def : new FastColour(r, g, b));
        }
Beispiel #39
0
        public virtual void Draw2DTexture(ref Texture tex, FastColour col)
        {
            float x1 = tex.X1, y1 = tex.Y1, x2 = tex.X2, y2 = tex.Y2;

                        #if USE_DX
            // NOTE: see "https://msdn.microsoft.com/en-us/library/windows/desktop/bb219690(v=vs.85).aspx",
            // i.e. the msdn article called "Directly Mapping Texels to Pixels (Direct3D 9)" for why we have to do this.
            x1 -= 0.5f; x2 -= 0.5f;
            y1 -= 0.5f; y2 -= 0.5f;
                        #endif
            texVerts[0] = new VertexPos3fTex2fCol4b(x1, y1, 0, tex.U1, tex.V1, col);
            texVerts[1] = new VertexPos3fTex2fCol4b(x2, y1, 0, tex.U2, tex.V1, col);
            texVerts[2] = new VertexPos3fTex2fCol4b(x2, y2, 0, tex.U2, tex.V2, col);
            texVerts[3] = new VertexPos3fTex2fCol4b(x1, y2, 0, tex.U1, tex.V2, col);
            SetBatchFormat(VertexFormat.Pos3fTex2fCol4b);
            UpdateDynamicIndexedVb(DrawMode.Triangles, texVb, texVerts, 4, 6);
        }
		internal void HandleEnvColours() {
			byte variable = reader.ReadUInt8();
			short red = reader.ReadInt16();
			short green = reader.ReadInt16();
			short blue = reader.ReadInt16();
			bool invalid = red < 0 || red > 255 || green < 0 || green > 255 || blue < 0 || blue > 255;
			FastColour col = new FastColour( red, green, blue );

			if( variable == 0 ) {
				game.World.Env.SetSkyColour( invalid ? WorldEnv.DefaultSkyColour : col );
			} else if( variable == 1 ) {
				game.World.Env.SetCloudsColour( invalid ? WorldEnv.DefaultCloudsColour : col );
			} else if( variable == 2 ) {
				game.World.Env.SetFogColour( invalid ? WorldEnv.DefaultFogColour : col );
			} else if( variable == 3 ) {
				game.World.Env.SetShadowlight( invalid ? WorldEnv.DefaultShadowlight : col );
			} else if( variable == 4 ) {
				game.World.Env.SetSunlight( invalid ? WorldEnv.DefaultSunlight : 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 );
 }
        FastColour GetColour( string key, FastColour def )
        {
            NbtTag tag;
            if( !curCpeExt.TryGetValue( key, out tag ) )
                return def;

            NbtCompound compound = (NbtCompound)tag.Value;
            short r = (short)compound["R"].Value;
            short g = (short)compound["G"].Value;
            short b = (short)compound["B"].Value;
            bool invalid = r < 0 || r > 255 || g < 0 || g > 255 || b < 0 || b > 255;
            return invalid ? def : new FastColour( r, g, b );
        }
        void DrawBackground()
        {
            VertexP3fT2fC4b[] vertices = game.ModelCache.vertices;
            int index = 0, atlasIndex = 0;
            int drawnY = 0, height = game.Height;
            FastColour col = new FastColour( 64, 64, 64 );

            int texLoc = game.BlockInfo.GetTextureLoc( (byte)Block.Dirt, Side.Top );
            TerrainAtlas1D atlas = game.TerrainAtlas1D;
            TextureRec tex = atlas.GetTexRec( texLoc, 1, out atlasIndex );
            tex.U2 = (float)game.Width / 64;
            bool bound = false;

            while( drawnY < height ) {
                float x1 = 0, x2 = game.Width;
                float y1 = drawnY, y2 = drawnY + 64;
                #if USE_DX
                // NOTE: see "https://msdn.microsoft.com/en-us/library/windows/desktop/bb219690(v=vs.85).aspx",
                // i.e. the msdn article called "Directly Mapping Texels to Pixels (Direct3D 9)" for why we have to do this.
                x1 -= 0.5f; x2 -= 0.5f;
                y1 -= 0.5f; y2 -= 0.5f;
                #endif

                vertices[index++] = new VertexP3fT2fC4b( x1, y1, 0, tex.U1, tex.V1, col );
                vertices[index++] = new VertexP3fT2fC4b( x2, y1, 0, tex.U2, tex.V1, col );
                vertices[index++] = new VertexP3fT2fC4b( x2, y2, 0, tex.U2, tex.V2, col );
                vertices[index++] = new VertexP3fT2fC4b( x1, y2, 0, tex.U1, tex.V2, col );
                if( index >= vertices.Length )
                    DrawBackgroundVertices( ref index, atlasIndex, ref bound );
                drawnY += 64;
            }
            DrawBackgroundVertices( ref index, atlasIndex, ref bound );
        }
        /// <summary> Renders the model based on the given entity's position and orientation. </summary>
        public void Render( Player p )
        {
            index = 0;
            pos = p.Position;
            if( Bobbing ) pos.Y += p.anim.bobYOffset;
            World map = game.World;
            col = game.World.IsLit( Vector3I.Floor( p.EyePosition ) ) ? map.Sunlight : map.Shadowlight;
            uScale = 1 / 64f; vScale = 1 / 32f;

            cols[0] = col;
            cols[1] = FastColour.Scale( col, FastColour.ShadeYBottom );
            cols[2] = FastColour.Scale( col, FastColour.ShadeZ ); cols[3] = cols[2];
            cols[4] = FastColour.Scale( col, FastColour.ShadeX ); cols[5] = cols[4];

            cosYaw = (float)Math.Cos( p.YawDegrees * Utils.Deg2Rad );
            sinYaw = (float)Math.Sin( p.YawDegrees * Utils.Deg2Rad );
            cosHead = (float)Math.Cos( p.HeadYawDegrees * Utils.Deg2Rad );
            sinHead = (float)Math.Sin( p.HeadYawDegrees * Utils.Deg2Rad );

            graphics.SetBatchFormat( VertexFormat.P3fT2fC4b );
            DrawModel( p );
        }
 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 );
 }
        void DrawSkyY( int x1, int z1, int x2, int z2, int y, int axisSize, FastColour col, VertexPos3fCol4b* vertices )
        {
            int endX = x2, endZ = z2, startZ = z1;

            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++ = new VertexPos3fCol4b( x1, y, z1, col );
                    *vertices++ = new VertexPos3fCol4b( x1, y, z2, col );
                    *vertices++ = new VertexPos3fCol4b( x2, y, z2, col );
                    *vertices++ = new VertexPos3fCol4b( x2, y, z1, col );
                }
            }
        }
        void DrawY( int x1, int z1, int x2, int z2, float y, int axisSize, FastColour col, float offset, ref VertexP3fT2fC4b* vertices )
        {
            int endX = x2, endZ = z2, startZ = z1;
            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;

                    TextureRec rec = new TextureRec( 0, 0, x2 - x1, z2 - z1 );
                    *vertices++ = new VertexP3fT2fC4b( x1 + offset, y + offset, z1 + offset, rec.U1, rec.V1, col );
                    *vertices++ = new VertexP3fT2fC4b( x1 + offset, y + offset, z2 + offset, rec.U1, rec.V2, col );
                    *vertices++ = new VertexP3fT2fC4b( x2 + offset, y + offset, z2 + offset, rec.U2, rec.V2, col );
                    *vertices++ = new VertexP3fT2fC4b( x2 + offset, y + offset, z1 + offset, rec.U2, rec.V1, col );
                }
            }
        }
 public void AddSelection( byte id, Vector3I p1, Vector3I p2, FastColour col )
 {
     SelectionBox selection = new SelectionBox( p1, p2, col, Graphics );
     selection.ID = id;
     selections.Add( selection );
 }
        void CalculateCaretData()
        {
            if( caretPos >= buffer.Length ) caretPos = -1;
            buffer.MakeCoords( caretPos, partLens, out indexX, out indexY );
            DrawTextArgs args = new DrawTextArgs( null, font, true );

            if( indexX == LineLength ) {
                caretTex.X1 = 10 + sizes[indexY].Width;
                caretCol = FastColour.Yellow;
                caretTex.Width = defaultCaretWidth;
            } else {
                args.Text = parts[indexY].Substring( 0, indexX );
                Size trimmedSize = game.Drawer2D.MeasureChatSize( ref args );
                if( indexY == 0 ) trimmedSize.Width += defaultWidth;
                caretTex.X1 = 10 + trimmedSize.Width;
                caretCol = FastColour.Scale( FastColour.White, 0.8f );

                string line = parts[indexY];
                args.Text = indexX < line.Length ? new String( line[indexX], 1 ) : "";
                caretTex.Width = indexX < line.Length ?
                    game.Drawer2D.MeasureChatSize( ref args ).Width : defaultCaretWidth;
            }
            caretTex.Y1 = sizes[0].Height * indexY + Y;
            CalcCaretColour();
        }
 void CalcCaretColour()
 {
     IDrawer2D drawer = game.Drawer2D;
     char code = GetLastColour( indexX, indexY );
     if( code != '\0' )
         caretCol = drawer.Colours[code];
 }
        void DrawZ( int z, int x1, int x2, int y1, int y2, int axisSize, FastColour col, ref VertexP3fT2fC4b* vertices )
        {
            int endX = x2, endY = y2, startY = y1;
            for( ; x1 < endX; x1 += axisSize ) {
                x2 = x1 + axisSize;
                if( x2 > endX ) x2 = endX;
                y1 = startY;
                for( ; y1 < endY; y1 += axisSize ) {
                    y2 = y1 + axisSize;
                    if( y2 > endY ) y2 = endY;

                    TextureRec rec = new TextureRec( 0, 0, x2 - x1, y2 - y1 );
                    *vertices++ = new VertexP3fT2fC4b( x1, y1, z, rec.U1, rec.V2, col );
                    *vertices++ = new VertexP3fT2fC4b( x1, y2, z, rec.U1, rec.V1, col );
                    *vertices++ = new VertexP3fT2fC4b( x2, y2, z, rec.U2, rec.V1, col );
                    *vertices++ = new VertexP3fT2fC4b( x2, y1, z, rec.U2, rec.V2, col );
                }
            }
        }
        void MakeRainForSquare( int x, float y, float height, int z, FastColour col, ref int index )
        {
            float worldV = vOffset + (z & 1) / 2f - (x & 0x0F) / 16f;
            float v1 = y / 6f + worldV;
            float v2 = (y + height) / 6f + worldV;

            vertices[index++] = new VertexP3fT2fC4b( x, y, z, 0, v2, col );
            vertices[index++] = new VertexP3fT2fC4b( x, y + height, z, 0, v1, col );
            vertices[index++] = new VertexP3fT2fC4b( x + 1, y + height, z + 1, 2, v1, col );
            vertices[index++] = new VertexP3fT2fC4b( x + 1, y, z + 1, 2, v2, col );

            vertices[index++] = new VertexP3fT2fC4b( x + 1, y, z, 2, v2, col );
            vertices[index++] = new VertexP3fT2fC4b( x + 1, y + height, z, 2, v1, col );
            vertices[index++] = new VertexP3fT2fC4b( x, y + height, z + 1, 0, v1, col );
            vertices[index++] = new VertexP3fT2fC4b( x, y, z + 1, 0, v2, col );
        }
 static FastColour ParseWomColour( string value, FastColour defaultCol )
 {
     int argb;
     return Int32.TryParse( value, out argb ) ? new FastColour( argb ) : defaultCol;
 }
		internal void HandleSetTextColor() {
			FastColour col = new FastColour( reader.ReadUInt8(), reader.ReadUInt8(),
			                                reader.ReadUInt8(), reader.ReadUInt8() );
			byte code = reader.ReadUInt8();
			
			if( code <= ' ' || code > '~' ) return; // Control chars, space, extended chars cannot be used
			if( (code >= '0' && code <= '9') || (code >= 'a' && code <= 'f')
			   || (code >= 'A' && code <= 'F') ) return; // Standard chars cannot be used.
			if( code == '%' || code == '&' ) return; // colour code signifiers cannot be used
			game.Drawer2D.Colours[code] = col;
			game.Events.RaiseColourCodesChanged();
		}
        void DrawX( int x, int z1, int z2, int y1, int y2, int axisSize, FastColour col, ref VertexP3fT2fC4b* vertices )
        {
            int endZ = z2, endY = y2, startY = y1;
            for( ; z1 < endZ; z1 += axisSize ) {
                z2 = z1 + axisSize;
                if( z2 > endZ ) z2 = endZ;
                y1 = startY;
                for( ; y1 < endY; y1 += axisSize ) {
                    y2 = y1 + axisSize;
                    if( y2 > endY ) y2 = endY;

                    TextureRec rec = new TextureRec( 0, 0, z2 - z1, y2 - y1 );
                    *vertices++ = new VertexP3fT2fC4b( x, y1, z1, rec.U1, rec.V2, col );
                    *vertices++ = new VertexP3fT2fC4b( x, y2, z1, rec.U1, rec.V1, col );
                    *vertices++ = new VertexP3fT2fC4b( x, y2, z2, rec.U2, rec.V1, col );
                    *vertices++ = new VertexP3fT2fC4b( x, y1, z2, rec.U2, rec.V2, col );
                }
            }
        }
 static void CheckShadowTexture( IGraphicsApi graphics )
 {
     if( shadowTex != -1 ) return;
     const int size = 128, half = size / 2;
     using( Bitmap bmp = new Bitmap( size, size ) )
         using( FastBitmap fastBmp = new FastBitmap( bmp, true, false ) )
     {
         int inPix = new FastColour( 0, 0, 0, 200 ).ToArgb();
         int outPix = new FastColour( 0, 0, 0, 0 ).ToArgb();
         for( int y = 0; y < fastBmp.Height; y++ ) {
             int* row = fastBmp.GetRowPtr( y );
             for( int x = 0; x < fastBmp.Width; x++ ) {
                 double dist = (half - (x + 0.5)) * (half - (x + 0.5)) +
                     (half - (y + 0.5)) * (half - (y + 0.5));
                 row[x] = dist < half * half ? inPix : outPix;
             }
         }
         shadowTex = graphics.CreateTexture( fastBmp );
     }
 }
        void WriteColourCompound( string name, FastColour col )
        {
            nbt.Write( NbtTagType.Compound ); nbt.Write( name );

            nbt.Write( NbtTagType.Int16 );
            nbt.Write( "R" ); nbt.WriteInt16( col.R );
            nbt.Write( NbtTagType.Int16 );
            nbt.Write( "G" ); nbt.WriteInt16( col.G );
            nbt.Write( NbtTagType.Int16 );
            nbt.Write( "B" ); nbt.WriteInt16( col.B );

            nbt.Write( NbtTagType.End );
        }
Beispiel #58
0
        void DrawCrosshairs()
        {
            int cenX = game.Width / 2, cenY = game.Height / 2;
            if( game.IconsTex > 0 ) {
                api.Texturing = true;
                int extent = (int)(chExtent * game.Scale( game.Height / 480f ) );
                Texture chTex = new Texture( game.IconsTex, cenX - extent,
                                            cenY - extent, extent * 2, extent * 2, chRec );
                chTex.Render( api );
                api.Texturing = false;
                return;
            }

            int curCol = 150 + (int)(50 * Math.Abs( Math.Sin( game.accumulator ) ));
            FastColour col = new FastColour( curCol, curCol, curCol );
            api.Draw2DQuad( cenX - chExtent, cenY - chWeight, chExtent * 2, chWeight * 2, col );
            api.Draw2DQuad( cenX - chWeight, cenY - chExtent, chWeight * 2, chExtent * 2, col );
        }
		internal void HandleMakeSelection() {
			byte selectionId = reader.ReadUInt8();
			string label = reader.ReadAsciiString();
			short startX = reader.ReadInt16();
			short startY = reader.ReadInt16();
			short startZ = reader.ReadInt16();
			short endX = reader.ReadInt16();
			short endY = reader.ReadInt16();
			short endZ = reader.ReadInt16();
			
			byte r = (byte)reader.ReadInt16();
			byte g = (byte)reader.ReadInt16();
			byte b = (byte)reader.ReadInt16();
			byte a = (byte)reader.ReadInt16();
			
			Vector3I p1 = Vector3I.Min( startX, startY, startZ, endX, endY, endZ );
			Vector3I p2 = Vector3I.Max( startX, startY, startZ, endX, endY, endZ );
			FastColour col = new FastColour( r, g, b, a );
			game.SelectionManager.AddSelection( selectionId, p1, p2, col );
		}
 public SelectionBox( Vector3I start, Vector3I end, FastColour col )
 {
     Min = Vector3I.Min( start, end );
     Max = Vector3I.Max( start, end );
     Colour = col;
 }