CHAPTER 4 ■ WORKING WITH MODELS
299
maximum acceleration and rotation speed inside a model structure. Furthermore, you need to
pass the user input, as well as the friction value.
private float Accelerate(ref Vector3 position, ref float angle,
➥
ref Vector3 velocity, float forwardReq, float rotationReq, ➥
float elapsedTime, float maxAccel, float maxRotSpeed, float friction)
{
Matrix rotMatrix = Matrix.CreateRotationY(angle);
Vector3 forwardDir = Vector3.Transform(new Vector3(0, 0, -1), rotMatrix);
velocity = velocity * (1 - friction * elapsedTime) +
➥
elapsedTime * forwardReq * maxAccel *forwardDir;
float forwardSpeed = Vector3.Dot(velocity, forwardDir);
velocity = forwardSpeed * forwardDir;
modelPosition += velocity * elapsedTime;
modelYRot ...