public override void Update(GameTime gameTime) { Vector3?pickPoint; if (Mouse.GetState().LeftButton == ButtonState.Pressed) { pickPoint = pick.GetCollisionPosition(); if (pickPoint.HasValue) { translation = Matrix.CreateTranslation(pickPoint.Value.X, pickPoint.Value.Y + 20, pickPoint.Value.Z); scale = Matrix.CreateScale(20f); } else { scale = Matrix.CreateScale(0); } } base.Update(gameTime); }
public override void Update(GameTime gameTime) { Vector3?pickPosition; float time = (gameTime.ElapsedGameTime.Milliseconds) / 1000f; position = world.Translation; if (Mouse.GetState().LeftButton == ButtonState.Pressed) { pickPosition = mousePick.GetCollisionPosition(); if (pickPosition.HasValue == true) { destination = pickPosition.Value; velocity = pickPosition.Value - position; velocity.Normalize(); newOrientation = Math.Atan2(velocity.X, velocity.Z); } } if (Math.Pow((newOrientation - currentOrientation), 2) > MathHelper.PiOver4 / 45) { if (newOrientation > currentOrientation) { rotation *= Matrix.CreateRotationY(MathHelper.PiOver4 / 100 * gameTime.ElapsedGameTime.Milliseconds / 10); currentOrientation += MathHelper.PiOver4 / 100 * gameTime.ElapsedGameTime.Milliseconds / 10; } else { rotation *= Matrix.CreateRotationY(-MathHelper.PiOver4 / 100 * gameTime.ElapsedGameTime.Milliseconds / 10); currentOrientation -= MathHelper.PiOver4 / 100 * gameTime.ElapsedGameTime.Milliseconds / 10; } } else if (Math.Pow((destination.X - position.X), 2) > 1f && Math.Pow((destination.Z - position.Z), 2) > 1f) { float distance = Vector3.Distance(destination, position); if (distance > slowRadius) { speed = maxspeed; position += maxspeed * velocity * time; translation = Matrix.CreateTranslation(position); } else { speed = maxspeed * distance / slowRadius; position += speed * velocity * time; translation = Matrix.CreateTranslation(position); } foreach (ModelBone wheel in wheels) { wheel.Transform = Matrix.CreateRotationX(MathHelper.PiOver4 / 10) * wheel.Transform; } } turretBone.Transform *= Matrix.CreateRotationY(MathHelper.PiOver4 / 100); base.Update(gameTime); }