diff options
| author | Adrian Ulbrich <adrian.ulbrich.2003@gmail.com> | 2019-11-06 21:07:49 +0100 |
|---|---|---|
| committer | Adrian Ulbrich <adrian.ulbrich.2003@gmail.com> | 2019-11-06 21:07:49 +0100 |
| commit | e63155370c817a1d9c16ef798b0a55e6fe328941 (patch) | |
| tree | ab4a65ab60f2e547008eb6c1fe409633521bbf1f /Unicity.Renderer/Camera.cs | |
| parent | 5d4b4023bddd12e27c6756793aea2ff36d49e124 (diff) | |
| download | Unicity-e63155370c817a1d9c16ef798b0a55e6fe328941.tar.gz Unicity-e63155370c817a1d9c16ef798b0a55e6fe328941.tar.bz2 Unicity-e63155370c817a1d9c16ef798b0a55e6fe328941.zip | |
3d support
Diffstat (limited to 'Unicity.Renderer/Camera.cs')
| -rw-r--r-- | Unicity.Renderer/Camera.cs | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/Unicity.Renderer/Camera.cs b/Unicity.Renderer/Camera.cs new file mode 100644 index 0000000..b58b571 --- /dev/null +++ b/Unicity.Renderer/Camera.cs @@ -0,0 +1,50 @@ +using OpenTK; + +namespace Unicity.Renderer +{ + public enum CameraProjectionMode + { + Ortographic, + Perspective + } + + public class Camera + { + float x = 0f; + float y = 0f; + float z = 0f; + + Matrix4 projectionMatrix = Matrix4.Identity; + + CameraProjectionMode projectionMode = CameraProjectionMode.Ortographic; + + public Camera(CameraProjectionMode projectionMode = CameraProjectionMode.Ortographic) + { + this.projectionMode = projectionMode; + } + + public void Initialize() + { + switch (projectionMode) + { + case CameraProjectionMode.Ortographic: + projectionMatrix = Matrix4.CreateOrthographic(600f, 600.0f, 0.1f, 100f); + break; + case CameraProjectionMode.Perspective: + projectionMatrix = Matrix4.CreatePerspectiveFieldOfView(MathHelper.DegreesToRadians(45f), 1f, 0.1f, 100f); + break; + + } + } + + public void UpdateView(Shader shader) + { + Matrix4 modelMatrix = Matrix4.CreateRotationX(MathHelper.DegreesToRadians(-55.0f)); + Matrix4 viewMatrix = Matrix4.CreateTranslation(0.0f, 0.0f, -8.0f); + + shader.SetUniform("model", modelMatrix); + shader.SetUniform("view", viewMatrix); + shader.SetUniform("projection", projectionMatrix); + } + } +} |
