Linear Interpolation (LERP)

protected override void Update(GameTime gameTime)
{
totalElapsedTime += (float)gameTime.ElapsedGameTime.TotalSeconds;

// determine how far along the duration value we are (0 to 1), duration=5 sec
float fraction = totalElapsedTime / duration;

// fraction = MathHelper.Clamp(fraction, 0, 1);
while (fraction > 1) fraction -= 1;

// interpolate modelPosition between startPosition and endPosition using fraction
modelPosition = Vector3.Lerp(startPosition, endPosition, fraction);

myModel.World = Matrix.CreateTranslation(modelPosition);

/// 중간생략 …
base.Update(gameTime);
}

Leave a Reply

Your email address will not be published. Required fields are marked *