Пример #1
0
        public virtual Vector2i Draw(MainGameState game)
        {
            float x = X - game.CurrentPlayer.X;
            float z = Z - game.CurrentPlayer.Z;

            float zBackup = z;

            z = game.CurrentPlayer.CosWorldRotation * z - game.CurrentPlayer.SinWorldRotation * x;
            x = game.CurrentPlayer.CosWorldRotation * x + game.CurrentPlayer.SinWorldRotation * zBackup;

            float aspect = Texture.Width / (float)Texture.Height;

            float leftRightOffset = aspect * Scale / 2f;

            Tuple <float, float> y = MathUtils3D.GetYForZ(z);

            int xResult = (int)MathUtils3D.GetXForX(x, y.Item1);

            float xPoss0 = MathUtils3D.GetXForX(x - leftRightOffset, y.Item1);
            float xPoss1 = MathUtils3D.GetXForX(x + leftRightOffset, y.Item1);

            float oringalZ       = MathUtils3D.GetZForY(y.Item1);
            float yDifference    = y.Item1 - y.Item2;
            float altitudeOffset = Altitude * yDifference;

            yDifference *= 1f - Scale;
            y            = new Tuple <float, float>(y.Item1 - altitudeOffset, y.Item2 + yDifference - altitudeOffset);
            int pixelsDrawn = 0;

            if (z > .1f && z < MainGameState.WallsDisappearAt)
            {
                game.DrawPatch(new Vector2(xPoss0, y.Item1), new Vector2(xPoss0, y.Item2), new Vector2(xPoss1, y.Item1), new Vector2(xPoss1, y.Item2),
                               (s, t) => {
                    ++pixelsDrawn;
                    Color texColor = Texture.Get((int)(s * Texture.Width), (int)(t * Texture.Height));
                    return(texColor);
                }, (f, unused) => AlwaysBright ? 1 : oringalZ, this);
            }

            if (pixelsDrawn > 0 && z < MainGameState.WallsDisappearAt)
            {
                return(new Vector2i(xResult, (int)y.Item2));
            }

            return(new Vector2i(short.MinValue, short.MinValue));
        }
Пример #2
0
        public void Draw(MainGameState game)
        {
            float x = X - game.CurrentPlayer.X;
            float z = Z - game.CurrentPlayer.Z;

            float zBackup = z;

            z = game.CurrentPlayer.CosWorldRotation * z - game.CurrentPlayer.SinWorldRotation * x;
            x = game.CurrentPlayer.CosWorldRotation * x + game.CurrentPlayer.SinWorldRotation * zBackup;
            float rotation = Rotation + game.CurrentPlayer.WorldRotation;

            float cosRot      = (float)Math.Cos(rotation);
            float sinRot      = (float)Math.Sin(rotation);
            float secondEdgeZ = cosRot;
            float secondEdgeX = sinRot;

            Tuple <float, float> yPoss0 = MathUtils3D.GetYForZ(z);
            Tuple <float, float> yPoss1 = MathUtils3D.GetYForZ(z + secondEdgeZ);

            float xPoss0 = MathUtils3D.GetXForX(x, yPoss0.Item1);
            float xPoss1 = MathUtils3D.GetXForX(secondEdgeX + x, yPoss1.Item1);

            {
                float yDifference    = yPoss0.Item1 - yPoss0.Item2;
                float altitudeOffset = Altitude * yDifference;
                yPoss0 = new Tuple <float, float>(yPoss0.Item1 - altitudeOffset, yPoss0.Item2 - altitudeOffset);
            }
            {
                float yDifference    = yPoss1.Item1 - yPoss1.Item2;
                float altitudeOffset = Altitude * yDifference;
                yPoss1 = new Tuple <float, float>(yPoss1.Item1 - altitudeOffset, yPoss1.Item2 - altitudeOffset);
            }

            if (z > 0f && z + secondEdgeZ > 0f && z < MainGameState.WallsDisappearAt)
            {
                game.DrawPatch(new Vector2(xPoss0, yPoss0.Item1), new Vector2(xPoss0, yPoss0.Item2), new Vector2(xPoss1, yPoss1.Item1), new Vector2(xPoss1, yPoss1.Item2),
                               (s, t) => {
                    Color texColor   = Texture.Get((int)(s * Texture.Width), (int)(t * Texture.Height));
                    Color decalColor = DecalTexture.Get((int)(s * DecalTexture.Width), (int)(t * DecalTexture.Height));
                    float dR, dG, dB, dA;
                    MathUtils3D.GetFloatsFromColor(decalColor, out dR, out dG, out dB, out dA);
                    float tR, tG, tB, tA;
                    MathUtils3D.GetFloatsFromColor(texColor, out tR, out tG, out tB, out tA);

                    float fR, fG, fB, fA;
                    fA = dA + tA * (1f - dA);
                    fR = (dR * dA + tR * tA * (1f - dA)) / fA;
                    fG = (dG * dA + tG * tA * (1f - dA)) / fA;
                    fB = (dB * dA + tB * tA * (1f - dA)) / fA;

                    return(MathUtils3D.GetColor32(fR, fG, fB, fA));
                }, (yTop, yDifference) => {
                    if (Altitude == 0f)
                    {
                        return(MathUtils3D.GetZForY(yTop));
                    }

                    // should be just a bit different... they probably won't notice because the doors rise so fast
                    return(MathUtils3D.GetZForY(yDifference * Altitude + yTop));
                }, this);
            }
        }