From e63155370c817a1d9c16ef798b0a55e6fe328941 Mon Sep 17 00:00:00 2001 From: Adrian Ulbrich Date: Wed, 6 Nov 2019 21:07:49 +0100 Subject: 3d support --- Unicity.Renderer/Camera.cs | 50 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 Unicity.Renderer/Camera.cs (limited to 'Unicity.Renderer/Camera.cs') 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); + } + } +} -- cgit v1.2.3