Advertisement
Guest User

Untitled

a guest
Feb 15th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.51 KB | None | 0 0
  1. using OpenTK;
  2. using OpenTK.Graphics.OpenGL;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using Wicked.Global;
  9. using Wicked.Shaders;
  10. using System.Windows.Forms;
  11.  
  12. namespace Wicked.Editor
  13. {
  14.     public class SceneCamera
  15.     {
  16.         private enum MouseButton
  17.         {
  18.             None,
  19.             Left,
  20.             Right
  21.         }
  22.  
  23.         public Matrix4 Proj;
  24.         public Matrix4 View;
  25.  
  26.         public float MoveSpeed = 0.2f;
  27.         public float MouseSensitivity = 0.0025f;
  28.  
  29.         private MouseButton _currentMouse = MouseButton.None;
  30.         private Vector3 _cameraPos = Vector3.Zero;
  31.  
  32.         public SceneCamera()
  33.         {
  34.             Proj = Matrix4.CreatePerspectiveFieldOfView((float)MathHelper.DegreesToRadians(45.0), Links.GLControl.Width / Links.GLControl.Height, 0.1f, 100.0f);
  35.             View = Matrix4.Identity;
  36.  
  37.             Links.GLControl.KeyDown += Engine_KeyDown;
  38.             Links.GLControl.MouseDown += GLControl_MouseDown;
  39.             Links.GLControl.MouseUp += GLControl_MouseUp;
  40.         }
  41.  
  42.         private void GLControl_MouseUp(object sender, MouseEventArgs e)
  43.         {
  44.             _currentMouse = MouseButton.None;
  45.         }
  46.  
  47.         private void GLControl_MouseDown(object sender, MouseEventArgs e)
  48.         {
  49.             if (e.Button == MouseButtons.Left)
  50.             {
  51.                 //AddRotation(OpenTK.Input.Mouse.GetState().X, OpenTK.Input.Mouse.GetState().Y);
  52.             }
  53.         }
  54.  
  55.         private void Engine_KeyDown(object sender, KeyEventArgs e)
  56.         {
  57.             switch(e.KeyCode)
  58.             {
  59.                 case Keys.W:
  60.                     Move(0, 0, 1);
  61.                     break;
  62.                 case Keys.S:
  63.                     Move(0, 0, -1);
  64.                     break;
  65.                 case Keys.A:
  66.                     Move(1, 0, 0);
  67.                     break;
  68.                 case Keys.D:
  69.                     Move(-1, 0, 0);
  70.                     break;
  71.                 default:
  72.                     break;
  73.             }
  74.         }
  75.  
  76.         public void Update()
  77.         {
  78.             //if (_lastMousePos != new Vector2(OpenTK.Input.Mouse.GetState().X, OpenTK.Input.Mouse.GetState().Y))
  79.             //CheckMouse();
  80.         }
  81.  
  82.         public void Move(float x, float y, float z)
  83.         {
  84.             _cameraPos += new Vector3(x,y,z) * MoveSpeed;
  85.             View = Matrix4.LookAt(_cameraPos, _cameraPos + Vector3.UnitZ, Vector3.UnitY);
  86.         }
  87.     }
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement