Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
CameraSetter.cs
Go to the documentation of this file.
1 // Copyright (c) 2014 Silicon Studio Corp. (http://siliconstudio.co.jp)
2 // This file is distributed under GPL v3. See LICENSE.md for details.
3 
4 using System;
5 
6 using SiliconStudio.Core;
7 using SiliconStudio.Core.Mathematics;
8 using SiliconStudio.Paradox.Effects.Modules;
9 using SiliconStudio.Paradox.Engine;
10 
11 namespace SiliconStudio.Paradox.Effects
12 {
13  /// <summary>
14  /// A processor that updates camera view and projection along the setup of <see cref="RenderTargetSetter"/>
15  /// </summary>
16  public class CameraSetter : Renderer
17  {
18  /// <summary>
19  /// Initializes a new instance of the <see cref="Renderer" /> class.
20  /// </summary>
21  /// <param name="services">The services.</param>
22  public CameraSetter(IServiceRegistry services) : base(services)
23  {
24  }
25 
26  /// <summary>
27  /// Gets or sets the camera.
28  /// </summary>
29  /// <value>The camera.</value>
30  public CameraComponent Camera { get; set; }
31 
32  protected override void OnRendering(RenderContext context)
33  {
34  var pass = context.CurrentPass;
35 
36  if (Camera == null)
37  return;
38 
39  if(Camera.Entity == null)
40  throw new Exception("The camera component provided to 'CameraSetter' should be associated to an entity");
41 
42  var viewParameters = pass.Parameters;
43 
44  Matrix projection;
45  Matrix worldToCamera;
46  Camera.Calculate(out projection, out worldToCamera);
47 
48  viewParameters.Set(TransformationKeys.View, worldToCamera);
49  viewParameters.Set(TransformationKeys.Projection, projection);
50  viewParameters.Set(CameraKeys.NearClipPlane, Camera.NearPlane);
51  viewParameters.Set(CameraKeys.FarClipPlane, Camera.FarPlane);
52  viewParameters.Set(CameraKeys.FieldOfView, Camera.VerticalFieldOfView);
53  viewParameters.Set(CameraKeys.Aspect, Camera.AspectRatio);
54  viewParameters.Set(CameraKeys.FocusDistance, Camera.FocusDistance);
55  }
56  }
57 }
Performs render pipeline transformations attached to a specific RenderPass.
Definition: Renderer.cs:13
A service registry is a IServiceProvider that provides methods to register and unregister services...
A processor that updates camera view and projection along the setup of RenderTargetSetter ...
Definition: CameraSetter.cs:16
Describes the camera projection and view.
CameraSetter(IServiceRegistry services)
Initializes a new instance of the Renderer class.
Definition: CameraSetter.cs:22
Thread-local storage context used during rendering.
override void OnRendering(RenderContext context)
Definition: CameraSetter.cs:32
Represents a 4x4 mathematical matrix.
Definition: Matrix.cs:47