示例#1
0
        public override void Update(Particle part)
        {
            Vector2 force = point - part.position;

            MathExtra.SetVectorLength(ref force, strength);
            part.AddForce(force);
        }
示例#2
0
        public virtual void Update()
        {
            if (life != -1)
            {
                normalizedLifetime = 1 - ((float)(life--) / lifeLength);
            }
            else
            {
                normalizedLifetime = 1;
            }
            if (life == 0)
            {
                engine.DestroyParticle(this);
            }

            foreach (ParticleMethod method in methods)
            {
                method.Update(this);
            }

            velocity += acceleration;
            MathExtra.RestrictVectorLength(ref velocity, maxSpeed);
            position    += velocity;
            acceleration = Vector2.Zero;
        }
示例#3
0
        /// <summary>
        /// Restricts a vector based on different components.
        /// </summary>
        public static void RestrictComponentLength(ref Vector2 vector, Vector2 xDirection, float x, float y)
        {
            Vector2 _xPart = MathExtra.GetProjectionVector(vector, xDirection);
            Vector2 _yPart = vector - _xPart;

            RestrictVectorLength(ref _xPart, x);
            RestrictVectorLength(ref _yPart, y);
            vector = _xPart + _yPart;
        }
示例#4
0
        public static void DrawCircle(SpriteBatch spriteBatch, Vector2 position, float radius, Color color, int resolution)
        {
            Vector2 first = position + new Vector2(MathExtra.ComponentX(radius, 0f), MathExtra.ComponentY(radius, 0f));
            Vector2 prev  = first;

            for (int i = 1; i < resolution; i++)
            {
                float   angle = (float)((float)i * 2.0f * Math.PI / resolution);
                Vector2 p     = position + new Vector2(MathExtra.ComponentX(radius, angle), MathExtra.ComponentY(radius, angle));
                DrawLine(spriteBatch, prev, p, color);
                prev = p;
            }
            DrawLine(spriteBatch, prev, first, color);
        }