You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

97 lines
1.8 KiB

  1. //
  2. // Lol Engine
  3. //
  4. // Copyright: (c) 2010-2013 Sam Hocevar <sam@hocevar.net>
  5. // This program is free software; you can redistribute it and/or
  6. // modify it under the terms of the Do What The Fuck You Want To
  7. // Public License, Version 2, as published by Sam Hocevar. See
  8. // http://www.wtfpl.net/ for more details.
  9. //
  10. #if defined HAVE_CONFIG_H
  11. # include "config.h"
  12. #endif
  13. #include <cstring>
  14. #include <cstdlib>
  15. #include "core.h"
  16. #if defined _WIN32 || defined _XBOX
  17. # define strcasecmp _stricmp
  18. # undef near
  19. # undef far
  20. #endif
  21. namespace lol
  22. {
  23. Camera::Camera()
  24. {
  25. m_gamegroup = GAMEGROUP_BEFORE;
  26. m_drawgroup = DRAWGROUP_CAMERA;
  27. /* Create a default perspective */
  28. SetProjection(mat4::perspective(45.f, 800.f, 600.f, -1000.f, 1000.f));
  29. SetView(mat4::lookat(vec3(0.f, 50.f, 50.f),
  30. vec3(0.f),
  31. vec3(0.f, 1.f, 0.f)));
  32. }
  33. Camera::~Camera()
  34. {
  35. }
  36. void Camera::SetView(mat4 const &view)
  37. {
  38. m_view_matrix = view;
  39. m_position = inverse(view)[3].xyz;
  40. }
  41. void Camera::SetView(vec3 eye, vec3 target, vec3 up)
  42. {
  43. m_view_matrix = mat4::lookat(eye, target, up);
  44. m_position = eye;
  45. }
  46. void Camera::SetView(vec3 pos, quat rot)
  47. {
  48. m_view_matrix = mat4::lookat(pos,
  49. pos + rot.transform(vec3(0.f, 0.f, -1.f)),
  50. rot.transform(vec3(0.f, 1.f, 0.f)));
  51. m_position = pos;
  52. }
  53. void Camera::SetProjection(mat4 const &proj)
  54. {
  55. m_proj_matrix = proj;
  56. }
  57. mat4 Camera::GetView()
  58. {
  59. return m_view_matrix;
  60. }
  61. mat4 Camera::GetProjection()
  62. {
  63. return m_proj_matrix;
  64. }
  65. vec3 Camera::GetPosition()
  66. {
  67. return m_position;
  68. }
  69. void Camera::TickGame(float seconds)
  70. {
  71. WorldEntity::TickGame(seconds);
  72. }
  73. void Camera::TickDraw(float seconds)
  74. {
  75. WorldEntity::TickDraw(seconds);
  76. }
  77. } /* namespace lol */