2020-02-23 06:34:41 +00:00
|
|
|
using OpenTK;
|
|
|
|
|
|
|
|
namespace RecrownedGTK.Graphics {
|
2020-04-04 22:35:06 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Basic camera handling up to x, y and z axis.
|
|
|
|
/// </summary>
|
2020-02-23 06:34:41 +00:00
|
|
|
public class Camera {
|
|
|
|
private Vector3 scale = new Vector3(1f), translate, rotation;
|
2020-04-04 22:35:06 +00:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Scale factor multiplied to the camera coordinates.
|
|
|
|
/// </summary>
|
|
|
|
/// <value>The value to be multiplied.</value>
|
2020-02-23 06:34:41 +00:00
|
|
|
public Vector3 Scale {
|
|
|
|
get {
|
|
|
|
return scale;
|
|
|
|
}
|
|
|
|
set {
|
|
|
|
updated = true;
|
|
|
|
scale = value;
|
|
|
|
}
|
|
|
|
}
|
2020-04-04 22:35:06 +00:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// The translation applied after scaling and rotating.
|
|
|
|
/// </summary>
|
|
|
|
/// <value></value>
|
2020-02-23 06:34:41 +00:00
|
|
|
public Vector3 Translate {
|
|
|
|
set {
|
|
|
|
updated = true;
|
|
|
|
translate = value;
|
|
|
|
}
|
|
|
|
}
|
2020-04-04 22:35:06 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Rotation applied before translation.
|
|
|
|
/// </summary>
|
|
|
|
/// <value></value>
|
2020-02-23 06:34:41 +00:00
|
|
|
public Vector3 Rotation {
|
|
|
|
set {
|
|
|
|
updated = true;
|
|
|
|
rotation = value;
|
|
|
|
}
|
|
|
|
get {
|
|
|
|
return rotation;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
private Matrix4 transform;
|
|
|
|
|
2020-04-04 22:35:06 +00:00
|
|
|
/// <summary>
|
|
|
|
/// If values have updated, recalculate transformation matrix.
|
|
|
|
/// </summary>
|
|
|
|
/// <value>The transformation matrix.</value>
|
2020-02-23 06:34:41 +00:00
|
|
|
public Matrix4 Transform {
|
|
|
|
get {
|
|
|
|
if (!updated) return transform;
|
|
|
|
updated = true;
|
|
|
|
transform =
|
|
|
|
Matrix4.CreateScale(scale) *
|
|
|
|
Matrix4.CreateRotationX(rotation.X) *
|
|
|
|
Matrix4.CreateRotationY(rotation.Y) *
|
|
|
|
Matrix4.CreateRotationZ(rotation.Z) *
|
|
|
|
Matrix4.CreateTranslation(translate);
|
|
|
|
transform = Matrix4.Transpose(transform);
|
|
|
|
return transform;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
private bool updated;
|
|
|
|
}
|
|
|
|
}
|