예제 #1
0
        internal static void DrawFilledShape(ShapeCache cache, ref Matrix matrix, Color color, BlendState blendState)
        {
            var device = Game.GraphicsDevice;

            VertexPositionColor[] vertices = new VertexPositionColor[cache.Vertices.Length];
            for (int i = 0; i < vertices.Length; i++)
            {
                Vector v = cache.Vertices[i];
                vertices[i] = new VertexPositionColor(new XnaV3((float)v.X, (float)v.Y, 0), color.AsXnaColor());
            }

            Int16[] indices = new Int16[cache.Triangles.Length * 3];
            for (int i = 0; i < cache.Triangles.Length; i++)
            {
                indices[3 * i]     = cache.Triangles[i].i1;
                indices[3 * i + 1] = cache.Triangles[i].i2;
                indices[3 * i + 2] = cache.Triangles[i].i3;
            }

            device.RasterizerState = RasterizerState.CullCounterClockwise;
            device.BlendState      = blendState;
#if WINDOWS_PHONE
            // The WP7 emulator interprets cullmodes incorectly sometimes.
            device.RasterizerState = RasterizerState.CullNone;
#endif

            Effect effect = Graphics.GetColorEffect(ref matrix, LightingEnabled);
            Graphics.SetSamplerState();
            foreach (EffectPass pass in effect.CurrentTechnique.Passes)
            {
                pass.Apply();
                device.DrawUserIndexedPrimitives <VertexPositionColor>(
                    PrimitiveType.TriangleList,
                    vertices, 0, vertices.Length,
                    indices, 0, indices.Length / 3
                    );
            }
            Graphics.ResetSamplerState();
        }
예제 #2
0
 /// <summary>
 /// Piirtää täytetyn yksivärisen muodon
 /// </summary>
 /// <param name="cache">Shapecache</param>
 /// <param name="matrix">Transformaatiomatriisi</param>
 /// <param name="position">Sijainti</param>
 /// <param name="size">Koko</param>
 /// <param name="rotation">Kulma</param>
 /// <param name="color">Väri</param>
 /// <param name="shader">Piirtoon käytettävä shader</param>
 public static void DrawFilledShape(ShapeCache cache, ref Matrix matrix, Vector position, Vector size, float rotation, Color color, IShader shader)
 {
     Graphics.CustomBatch.AddShader(matrix, shader, color, cache, position, size, rotation);
 }
예제 #3
0
파일: RoadMap.cs 프로젝트: Anttifer/Jypeli
        /// <summary>
        /// Luo tien kentälle.
        /// </summary>
        public void Insert()
        {
            if (wayPoints.Length < 2)
            {
                throw new ArgumentException("Must have at least 2 points");
            }

            angles = new Angle[wayPoints.Length];

            Vector first       = wayPoints[0];
            Vector second      = wayPoints[1];
            Vector toBeginning = (first - second).Normalize();
            Vector beginning   = first + toBeginning;

            Vector previousLeft, previousRight;

            CalculatePoints(beginning, first, second, out previousLeft, out previousRight);
            angles[0] = (second - first).Angle;

            Vector secondToLast = wayPoints[wayPoints.Length - 2];
            Vector last         = wayPoints[wayPoints.Length - 1];
            Vector toVeryLast   = (last - secondToLast).Normalize();
            Vector veryLast     = last + toVeryLast;

            for (int i = 1; i < wayPoints.Length; i++)
            {
                Vector previous = wayPoints[i - 1];
                Vector current  = wayPoints[i];
                Vector next;

                Vector toPrevious = (previous - current).Normalize();
                Vector toNext;

                if (i == wayPoints.Length - 1)
                {
                    next   = veryLast;
                    toNext = toVeryLast;
                }
                else
                {
                    next   = wayPoints[i + 1];
                    toNext = (next - current).Normalize();
                }

                Vector left, right;
                CalculatePoints(previous, current, next, out left, out right);
                angles[i] = (next - previous).Angle;

                Vector center = previous + toNext / 2;

                Vector[] vertices = new Vector[4];
                vertices[0] = previousLeft - center;
                vertices[1] = previousRight - center;
                vertices[2] = right - center;
                vertices[3] = left - center;

                IndexTriangle[] triangles = new IndexTriangle[]
                {
                    new IndexTriangle(0, 3, 1),
                    new IndexTriangle(1, 3, 2)
                };

                ShapeCache cache = new ShapeCache(vertices, triangles);
                Polygon    shape = new Polygon(cache, false);

                PhysicsObject segment = CreateSegmentFunction(100, 100, shape);
                segment.Position = center;
                Segments[i - 1]  = segment;

                previousLeft  = left;
                previousRight = right;
            }
        }
예제 #4
0
 internal static void DrawFilledShape(ShapeCache cache, ref Matrix matrix, Color color)
 {
     DrawFilledShape(cache, ref matrix, color, BlendState.NonPremultiplied);
 }
예제 #5
0
파일: Shapes.cs 프로젝트: Anttifer/Jypeli
 public Polygon(ShapeCache cache, bool isUnitSize)
 {
     this._cache     = cache;
     this.isUnitSize = isUnitSize;
 }
예제 #6
0
파일: Shapes.cs 프로젝트: Anttifer/Jypeli
 public Polygon(ShapeCache cache)
     : this(cache, true)
 {
 }