Пример #1
0
        public void Move(Stitch source, float affect)
        {
            if (affect <= 0.1)
            {
                return;
            }

            this.Velocity -= this.Velocity * affect;
            affect *= 0.6f;

            if (this != source)
            {
                Vector2 relative = source.Position - this.Position;
                this.Velocity += relative * affect;
            }

            foreach (Stitch stitch in ReferencingStitches)
            {
                if (stitch != source)
                {
                    stitch.Move(this, affect);
                }
            }
            foreach (Stitch stitch in ReferencedStitches)
            {
                if (stitch != source)
                {
                    stitch.Move(this, affect);
                }
            }
        }
Пример #2
0
        public Textile(int cols,
                       int rows,
                       Vector2 center,
                       float scale,
                       float orientation,
                       Vector3 startColor,
                       Vector3 endColor,
                       Vector2 screenSize)
        {
            Id = nextID++;
            columnCount = cols;
            rowCount = rows;

            Vector2 clothSize = new Vector2(
                cols * TextileConstants.LengthPerStitch,
                rows * TextileConstants.LengthPerStitch);

            Vector2 centerOffset = clothSize / 2;

            manipulation = new ManipulationAdapter(clothSize, new BoundingRect(screenSize / 2f, screenSize));
            manipulation.Scale = scale;
            manipulation.Center = center;
            manipulation.Orientation = orientation;

            int jointCount = 0;
            for (int col = 0; col < cols; col++)
            {
                for (int row = 0; row < rows; row++)
                {
                    Color color = GetColor(col, row, cols, rows, startColor, endColor);
                    Stitch stitch = new Stitch(
                        this,
                        new Vector2(
                            (col * TextileConstants.LengthPerStitch) - centerOffset.X,
                            (row * TextileConstants.LengthPerStitch) - centerOffset.Y),
                            new Vector2((float)col / cols, (float)row /rows),
                            color);

                    if (row > 0)
                    {
                        Stitch upperStitch = stitches[stitches.Count - 1];
                        upperStitch.ReferencedStitches.Add(stitch);
                        stitch.ReferencingStitches.Add(upperStitch);
                        jointCount++;
                    }
                    if (col > 0)
                    {
                        Stitch leftStitch = stitches[stitches.Count - rows];
                        leftStitch.ReferencedStitches.Add(stitch);
                        stitch.ReferencingStitches.Add(leftStitch);
                        jointCount++;
                   }
                    stitches.Add(stitch);
                }
            }

            linesVertices = new VertexPositionColor[jointCount * 2];
            textureVertices = new VertexPositionTexture[stitches.Count];

            RenderStyle = RenderStyles.Wire | RenderStyles.Texture;

            Ripple(manipulation.Transform(Vector2.Zero), clothSize.Length() * (float)random.NextDouble(), -0.2f * (float)random.NextDouble());
        }
Пример #3
0
        private Vector2 GetRelationalVelocity(Stitch target)
        {
            Vector2 relativePos = this.Position - target.Position;

            float length = relativePos.Length();
            if (length < TextileConstants.LengthPerStitch)
            {
                return Vector2.Zero;
            }

            if (length > TextileConstants.PullRange)
            {
                relativePos *= TextileConstants.PullRange / length;
            }

            Vector2 relativeVelocity = this.Velocity - target.Velocity;

            float pull = AverageElementLength(relativePos * relativeVelocity);
            float force = WeightingAdd(length - TextileConstants.LengthPerStitch, pull / TextileConstants.LengthPerStitch,
                          TextileConstants.PullAmplitudeWeight) * TextileConstants.Amplitude;

            return length > 0f ? (relativePos * force / length) : Vector2.Zero;
        }