rendered paste body public class
{
protected Matrix view;
protected Matrix projection;
protected Vector3 position;
protected float pitch = 0;
protected float yaw = 0;
protected float fov = 45;
protected float aspect = 1.333333333f;
protected float nearClip = 1f;
protected float farClip = 10000f;
private bool viewChanged = true;
public Vector3 Position
{
get { return position; }
set { position = value; viewChanged = true; }
}
public Matrix Projection
{
get { return projection; }
}
public Matrix View
{
get
{
// Try and avoid a few matrix operations by only updating the view when it has changed
if (viewChanged)
{
view = Matrix.CreateRotationX(MathHelper.ToRadians(yaw)) * Matrix.CreateRotationY(MathHelper.ToRadians(pitch));
view.M41 = position.X;
view.M42 = position.Y;
view.M43 = position.Z;
viewChanged = false;
}
return Matrix.Invert(view);
}
set { view = value; }
}
public Camera()
{
position = Vector3.Zero;
BuildProjectionMatrix(fov, aspect);
}
private void BuildProjectionMatrix(float FieldOfView, float AspectRatio)
{
projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45), AspectRatio, nearClip, farClip);
}
public void Translate(Vector3 Movement)
{
// Move Right
position.X += Movement.X * view.Right.X;
position.Y += Movement.X * view.Right.Y;
position.Z += Movement.X * view.Right.Z;
// Move Up
position.X += Movement.Y * view.Up.X;
position.Y += Movement.Y * view.Up.Y;
position.Z += Movement.Y * view.Up.Z;
// Move Forward
position.X += Movement.Z * view.Forward.X;
position.Y += Movement.Z * view.Forward.Y;
position.Z += Movement.Z * view.Forward.Z;
viewChanged = true;
}
public void SetAngle(Vector3 Rotation)
{
yaw = Rotation.X;
pitch = Rotation.Y;
viewChanged = true;
}
public void Rotate(Vector3 Rotation)
{
yaw += Rotation.X;
pitch += Rotation.Y;
viewChanged = true;
}
}