5 using SiliconStudio.Paradox.Games.Mathematics;
23 private float orthographicSize;
24 private bool isOrthographic;
25 private float nearClipPlane;
26 private float farClipPlane;
28 private float fieldOfView;
30 private Matrix projection;
32 private Matrix worldToCamera;
51 public Camera(
Vector3 position,
Vector3 target,
float fov,
float width,
float height,
float aspect,
float nearClipPlane,
float farClipPlane)
53 this.orthographicSize = 1;
54 this.mode = CameraMode.Target;
55 this.position = position;
57 this.fieldOfView = fov;
61 this.nearClipPlane = nearClipPlane;
62 this.farClipPlane = farClipPlane;
63 UpdateWorldToCamera();
78 public Camera(
Vector3 position,
float yaw,
float pitch,
float roll,
float fov,
float width,
float height,
float aspect,
float nearClipPlane,
float farClipPlane)
80 Matrix.RotationYawPitchRoll(yaw, pitch, roll, out worldToCamera);
81 this.position = position;
82 this.orthographicSize = 1;
83 this.mode = CameraMode.Free;
84 this.fieldOfView = fov;
88 this.nearClipPlane = nearClipPlane;
89 this.farClipPlane = farClipPlane;
90 UpdateWorldToCamera();
97 public float Width {
get;
private set; }
102 public float Height {
get;
private set; }
114 return nearClipPlane;
118 nearClipPlane = value;
137 farClipPlane = value;
196 return orthographicSize;
200 orthographicSize = value;
215 return isOrthographic;
219 isOrthographic = value;
252 return worldToCamera;
257 mode = CameraMode.Free;
259 worldToCamera = value;
297 UpdateWorldToCamera();
317 UpdateWorldToCamera();
323 return string.Format(
"Mode: {0}, NearClipPlane: {1}, FarClipPlane: {2}, FieldOfView: {3}, Aspect: {4}", mode, nearClipPlane, farClipPlane, fieldOfView, aspect);
328 var tempMatrix = Matrix.Identity;
329 var rotateZ = Matrix.RotationZ(yaw) * Matrix.RotationX(roll);
330 tempMatrix.Column1 = Vector3.Transform((
Vector3)matrix.Column1, rotateZ);
331 tempMatrix.Column3 = Vector3.Transform((
Vector3)matrix.Column3, rotateZ);
332 tempMatrix.Column2 = (Vector4)
Vector3.Cross((
Vector3)tempMatrix.Column3, (
Vector3)tempMatrix.Column1);
336 return Matrix.Translation(-position) * tempMatrix * Matrix.RotationX(pitch);
339 private void UpdateWorldToCamera()
347 var defaultCamera = worldToCamera;
348 defaultCamera.M41 = 0;
349 defaultCamera.M42 = 0;
350 defaultCamera.M43 = 0;
351 worldToCamera = Matrix.Translation(-
Position) * defaultCamera;
355 private void UpdateProjection()
float Aspect
Gets or sets the aspect.
float Height
Gets the height of the camera.
Matrix WorldToCamera
Gets or sets the world to camera matrix.
float Width
Gets the width of the camera.
Vector3 Target
Gets or sets the target.
float OrthographicSize
Gets or sets the camera half vertical size in orthographic mode.
bool IsOrthographic
Gets or sets a value indicating whether this instance is orthographic.
Camera(Vector3 position, float yaw, float pitch, float roll, float fov, float width, float height, float aspect, float nearClipPlane, float farClipPlane)
Initializes a new instance of the Camera class.
static Matrix YawPitchRoll(Vector3 position, Matrix matrix, float yaw, float pitch, float roll)
Matrix Projection
Gets or sets the projection matrix.
Camera(Vector3 position, Vector3 target, float fov, float width, float height, float aspect, float nearClipPlane, float farClipPlane)
Initializes a new instance of the Camera class.
float FieldOfView
Gets or sets the vertical field of view.
override string ToString()
CameraMode Mode
Gets or sets the mode of this camera.
Vector3 Position
Gets or sets the position.
float NearClipPlane
Gets or sets the near clip plane.
SiliconStudio.Core.Mathematics.Vector3 Vector3
Camera()
Initializes a new instance of the Camera class.
float FarClipPlane
Gets or sets the far clip plane.