Ejemplo n.º 1
0
        public void DrawCircle(SpriteReference sprite, SamplerState samplerState, Vector2 center, int precision, float angleStart, float angleEnd, float radius, float texOffset, float texPrecision, float start, float end, ColorMatrix color, BlendState blend)
        {
            if (start == end)
            {
                return;
            }

            SetupColorMatrix(color, WorldTransform, Projection);
            PrimitiveBatch.Begin(PrimitiveType.TriangleStrip, texture: sprite?.Texture ?? Pixel, blendState: blend, rasterizerState: RasterizerState, samplerState: samplerState, transform: WorldTransform, projection: Projection, effect: Shader);

            for (int i = 0; i < precision; i++)
            {
                float   angleSlide = (float)i / (precision - 1);
                Vector2 offset     = Util.AngleToVector(MathHelper.Lerp(angleStart, angleEnd, angleSlide));
                var     inside     = center;// + offset * radius * MathHelper.Clamp(start, 0, 1);
                var     outside    = center + offset * radius * MathHelper.Clamp(end, 0, 1);

                var texHorizontal = texPrecision * angleSlide + texOffset;
                var texInside     = 1 - Util.ReverseLerp(MathHelper.Clamp(0, 0, 1), start, end);
                var texOutside    = 1 - Util.ReverseLerp(MathHelper.Clamp(end, 0, 1), start, end);

                PrimitiveBatch.AddVertex(new VertexPositionColorTexture(new Vector3(inside, 0), Color.White, new Vector2(texHorizontal, texInside)));
                PrimitiveBatch.AddVertex(new VertexPositionColorTexture(new Vector3(outside, 0), Color.White, new Vector2(texHorizontal, texOutside)));
            }

            PrimitiveBatch.End();
        }
Ejemplo n.º 2
0
        private void DrawGround()
        {
            var grass = SpriteLoader.Instance.AddSprite("content/title_grass");

            float  precision  = 50;
            float  skewAmount = 0.1f * 0;
            Matrix skew       = skew = new Matrix(
                1, 0, 0, 0,
                skewAmount, 1, 0, 0,
                0, 0, 1, 0,
                0, 0, 0, 1
                );
            Matrix idiotRotate = Matrix.CreateRotationX(0.01f * Frame) * Matrix.CreateRotationY(0.03f * Frame) * Matrix.CreateRotationZ(0.07f * Frame);

            GroundTransform = Matrix.CreateRotationY(-MathHelper.PiOver2) * skew * Matrix.CreateScale(Viewport.Width * 0.7f, 300, 1) * Matrix.CreateTranslation(Viewport.Width * 0.55f, Viewport.Height, 0);

            SetupLight(new Vector3(0, 3, 2), GroundTransform * WorldTransform, Projection);
            FloorBatch.Begin(PrimitiveType.TriangleList, texture: GrassMap, blendState: BlendState.Opaque, rasterizerState: RasterizerState.CullNone, samplerState: SamplerState.PointWrap, transform: GroundTransform * WorldTransform, projection: Projection, effect: ShaderLight);

            float alphaOffset = +MathHelper.PiOver2;
            float betaOffset  = 0;
            float precisionX  = precision / 2;
            float precisionY  = precision / 2;

            for (int i = 0; i < precisionX; i++)
            {
                float alphaMin = alphaOffset + i * MathHelper.TwoPi / precision;
                float alphaMax = alphaOffset + (i + 1) * MathHelper.TwoPi / precision;
                float uMin     = i / precisionX;
                float uMax     = (i + 1) / precisionX;

                float xyMin = (float)Math.Cos(alphaMin);
                float xyMax = (float)Math.Cos(alphaMax);
                float zMin  = (float)Math.Sin(alphaMin);
                float zMax  = (float)Math.Sin(alphaMax);

                for (int j = 0; j < precisionY; j++)
                {
                    float betaMin = betaOffset + j * MathHelper.TwoPi / precision;
                    float betaMax = betaOffset + (j + 1) * MathHelper.TwoPi / precision;
                    float vMin    = j / precisionY;
                    float vMax    = (j + 1) / precisionY;

                    Vector3 a = new Vector3(xyMin * (float)Math.Cos(betaMin), xyMin * (float)Math.Sin(betaMin), zMin);
                    Vector3 b = new Vector3(xyMin * (float)Math.Cos(betaMax), xyMin * (float)Math.Sin(betaMax), zMin);
                    Vector3 c = new Vector3(xyMax * (float)Math.Cos(betaMin), xyMax * (float)Math.Sin(betaMin), zMax);
                    Vector3 d = new Vector3(xyMax * (float)Math.Cos(betaMax), xyMax * (float)Math.Sin(betaMax), zMax);

                    FloorBatch.AddVertex(new VertexPositionNormalTexture(a, a, new Vector2(uMin, vMin)));
                    FloorBatch.AddVertex(new VertexPositionNormalTexture(b, b, new Vector2(uMin, vMax)));
                    FloorBatch.AddVertex(new VertexPositionNormalTexture(c, c, new Vector2(uMax, vMin)));
                    FloorBatch.AddVertex(new VertexPositionNormalTexture(b, b, new Vector2(uMin, vMax)));
                    FloorBatch.AddVertex(new VertexPositionNormalTexture(d, d, new Vector2(uMax, vMax)));
                    FloorBatch.AddVertex(new VertexPositionNormalTexture(c, c, new Vector2(uMax, vMin)));
                }
            }

            FloorBatch.End();
        }
Ejemplo n.º 3
0
        public void DrawLine(SpriteReference sprite, Vector2 pos1, Vector2 pos2, float widthMod, float lengthMod, float offset, ColorMatrix color, BlendState blend)
        {
            var delta = pos2 - pos1;
            var dist  = delta.Length();
            var side  = (delta / dist).TurnLeft();
            var width = sprite.Height;

            //SetupNormal(WorldTransform, Projection);
            SetupColorMatrix(color, WorldTransform, Projection);
            PrimitiveBatch.Begin(PrimitiveType.TriangleStrip, texture: sprite.Texture, blendState: blend, rasterizerState: RasterizerState.CullNone, samplerState: SamplerState.PointWrap, transform: WorldTransform, projection: Projection, effect: Shader);
            PrimitiveBatch.AddVertex(new VertexPositionColorTexture(new Vector3(pos1 + side * width * widthMod / 2, 0), Color.White, new Vector2(-offset / sprite.Width, 1)));
            PrimitiveBatch.AddVertex(new VertexPositionColorTexture(new Vector3(pos1 - side * width * widthMod / 2, 0), Color.White, new Vector2(-offset / sprite.Width, 0)));
            PrimitiveBatch.AddVertex(new VertexPositionColorTexture(new Vector3(pos2 + side * width * widthMod / 2, 0), Color.White, new Vector2((dist * lengthMod - offset) / sprite.Width, 1)));
            PrimitiveBatch.AddVertex(new VertexPositionColorTexture(new Vector3(pos2 - side * width * widthMod / 2, 0), Color.White, new Vector2((dist * lengthMod - offset) / sprite.Width, 0)));
            PrimitiveBatch.End();
        }
Ejemplo n.º 4
0
        public void DrawGrappleLine(Vector2 start, Vector2 end, float waveAmplitude, float waveOffset, float waveFrequency, int precision, LerpHelper.Delegate lerp, Color color, BlendState blend)
        {
            SetupColorMatrix(ColorMatrix.Identity, WorldTransform, Projection);
            PrimitiveBatch.Begin(PrimitiveType.LineStrip, texture: Pixel, blendState: blend, rasterizerState: RasterizerState, samplerState: SamplerState.PointWrap, transform: WorldTransform, projection: Projection, effect: Shader);

            var delta   = end - start;
            var lateral = Vector2.Normalize(new Vector2(-delta.Y, delta.X));

            for (int i = 0; i < precision; i++)
            {
                float slide    = (float)i / (precision - 1);
                float posSlide = (float)lerp(0, 1, slide);
                var   offset   = lateral * (float)Math.Sin((slide * waveFrequency + waveOffset) * MathHelper.TwoPi) * (float)Math.Sin(MathHelper.Pi * slide) * waveAmplitude;
                var   pos      = start + posSlide * delta + offset;

                PrimitiveBatch.AddVertex(new VertexPositionColorTexture(new Vector3(pos, 0), color, new Vector2(0, 0)));
            }

            PrimitiveBatch.End();
        }
Ejemplo n.º 5
0
        public void DrawMissileCurve(SpriteReference sprite, Func <float, Vector2> curve, int precision, Func <float, float> thickness, float start, float end, ColorMatrix color, BlendState blend)
        {
            List <Vector2> points  = new List <Vector2>();
            List <float>   lengths = new List <float>();
            List <Vector2> pivots  = new List <Vector2>();

            LineSet line = new LineSet();

            for (int i = 0; i <= precision; i++)
            {
                line.AddPoint(curve((float)i / precision));
            }

            line.GetBeam(start, end, points, pivots, lengths);

            var dist  = line.TotalDistance;
            var width = sprite.Height;

            SetupColorMatrix(color, WorldTransform, Projection);
            PrimitiveBatch.Begin(PrimitiveType.TriangleStrip, texture: sprite.Texture, blendState: blend, rasterizerState: RasterizerState.CullNone, samplerState: SamplerState.PointWrap, transform: WorldTransform, projection: Projection, effect: Shader);

            for (int i = 0; i < points.Count; i++)
            {
                var point    = points[i];
                var side     = pivots[i];
                var len      = lengths[i];
                var slide    = len / dist;
                var tex      = (slide - start) / (end - start);
                var widthMod = thickness(slide);

                PrimitiveBatch.AddVertex(new VertexPositionColorTexture(new Vector3(point + side * width * widthMod / 2, 0), Color.White, new Vector2(tex, 1)));
                PrimitiveBatch.AddVertex(new VertexPositionColorTexture(new Vector3(point - side * width * widthMod / 2, 0), Color.White, new Vector2(tex, 0)));
            }

            PrimitiveBatch.End();
        }