Time for action – implementing a look-at point
1. Add the following properties to the
Fields
region of theCamera
class:private Vector3 lookAt; private Vector3 baseCameraReference = new Vector3(0, 0, 1); private bool needViewResync = true;
2. Add the following region and method to the
Camera
class:#region Helper Methods private void UpdateLookAt() { Matrix rotationMatrix = Matrix.CreateRotationY(rotation); Vector3 lookAtOffset = Vector3.Transform( baseCameraReference, rotationMatrix); lookAt = position + lookAtOffset; needViewResync = true; } #endregion
3. Define the
MoveTo()
method that is called in the constructor. This method should be placed inside the Helper Methods region you just created:public void MoveTo(Vector3 position, float rotation) { this.position = position; this.rotation = rotation; UpdateLookAt(); }
4. Add two new public properties to the
Properties
region of theCamera
class:public Vector3 Position { get { return...