CameraClass.cs 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. using System;
  2. using System.Threading.Tasks;
  3. using System.Windows.Forms;
  4. using SlimDX;
  5. using SlimDX.D3DCompiler;
  6. using SlimDX.Direct3D11;
  7. using SlimDX.DXGI;
  8. using SlimDX.Windows;
  9. using Device = SlimDX.Direct3D11.Device;
  10. using Resource = SlimDX.Direct3D11.Resource;
  11. using Buffer = SlimDX.Direct3D11.Buffer;
  12. namespace EQ2ModelViewer
  13. {
  14. public class CameraClass
  15. {
  16. private float m_positionX;
  17. private float m_positionY;
  18. private float m_positionZ;
  19. private float m_rotationX;
  20. private float m_rotationY;
  21. private float m_rotationZ;
  22. private Matrix m_ViewMatrix;
  23. public void SetPosition(float x, float y, float z)
  24. {
  25. m_positionX = x;
  26. m_positionY = y;
  27. m_positionZ = z;
  28. }
  29. public void SetPosition(Vector3 pos)
  30. {
  31. SetPosition(pos.X, pos.Y, pos.Z);
  32. }
  33. public void SetRotation(float x, float y, float z)
  34. {
  35. m_rotationX = x;
  36. m_rotationY = y;
  37. m_rotationZ = z;
  38. }
  39. public void SetRotation(Vector3 rot)
  40. {
  41. SetRotation(rot.X, rot.Y, rot.Z);
  42. }
  43. public Vector3 GetPosition()
  44. {
  45. return new Vector3(m_positionX, m_positionY, m_positionZ);
  46. }
  47. public Vector3 GetRotation()
  48. {
  49. return new Vector3(m_rotationX, m_rotationY, m_rotationZ);
  50. }
  51. public void Render()
  52. {
  53. Vector3 up = new Vector3(0.0f, 1.0f, 0.0f);
  54. Vector3 pos = new Vector3(m_positionX, m_positionY, m_positionZ);
  55. Vector3 lookAt = new Vector3(0.0f, 0.0f, 1.0f);
  56. float pitch = m_rotationX * 0.0174532925f;
  57. float yaw = m_rotationY * 0.0174532925f;
  58. float roll = m_rotationZ * 0.0174532925f;
  59. Matrix rotationMatrix = Matrix.RotationYawPitchRoll(yaw, pitch, roll);
  60. lookAt = Vector3.TransformCoordinate(lookAt, rotationMatrix);
  61. up = Vector3.TransformCoordinate(up, rotationMatrix);
  62. lookAt = pos + lookAt;
  63. m_ViewMatrix = Matrix.LookAtLH(pos, lookAt, up);
  64. }
  65. public Matrix GetViewMatrix()
  66. {
  67. return m_ViewMatrix;
  68. }
  69. }
  70. }