Subversion Repositories Games.Carmageddon

Rev

Blame | Last modification | View Log | Download | RSS feed

  1. #if 0 // Pierre-Marie Baty -- looks like disabled code
  2.  
  3. #include "cameras/debug_camera.h"
  4. #include <SDL.h>
  5.  
  6. mat4 view, projection;
  7. vec3 cam_pos = { 0, 0, 0 };
  8. vec3 cam_front = { 0, 0, -1 };
  9. vec3 cam_up = { 0, 1, 0 };
  10. float cam_speed = 0.5f;
  11.  
  12. float vc[4][4] = {
  13.     { 0.45397636, 0.0, 0.89101368, 0 }, { 0.1117821, 0.99209929, -0.056953594, 0 }, { -0.88397402, 0.12545498, 0.45038962, 0 }, { -69.239441, 20.735441, -52.417336, 1 }
  14. };
  15.  
  16. float lastX = 400, lastY = 300;
  17. int firstMouse = 1;
  18. float yaw = 0, pitch = 0;
  19.  
  20. int gDebugCamera_active = 0;
  21.  
  22. void DebugCamera_Update(void) {
  23.     const Uint8* state = SDL_GetKeyboardState(NULL);
  24.     if (state[SDL_SCANCODE_UP]) {
  25.         vec3 s;
  26.         glm_vec3_scale(cam_front, cam_speed, s);
  27.         glm_vec3_add(cam_pos, s, cam_pos);
  28.     }
  29.     if (state[SDL_SCANCODE_DOWN]) {
  30.         vec3 s;
  31.         glm_vec3_scale(cam_front, -cam_speed, s);
  32.         glm_vec3_add(cam_pos, s, cam_pos);
  33.     }
  34.     if (state[SDL_SCANCODE_LEFT]) {
  35.         vec3 cr;
  36.         glm_cross(cam_front, cam_up, cr);
  37.         glm_normalize(cr);
  38.         glm_vec3_scale(cr, cam_speed, cr);
  39.         glm_vec3_add(cam_pos, cr, cam_pos);
  40.     }
  41.     if (state[SDL_SCANCODE_RIGHT]) {
  42.         vec3 cr;
  43.         glm_cross(cam_front, cam_up, cr);
  44.         glm_normalize(cr);
  45.         glm_vec3_scale(cr, -cam_speed, cr);
  46.         glm_vec3_add(cam_pos, cr, cam_pos);
  47.     }
  48.     if (state[SDL_SCANCODE_F12]) {
  49.         gDebugCamera_active = !gDebugCamera_active;
  50.         // if (!gDebugCamera_active) {
  51.         //     printf("DEBUGCAMERAACTIVE\n");
  52.         //     gDebugCamera_active = 1;
  53.         // }
  54.     }
  55.  
  56.     int xpos, ypos;
  57.     SDL_GetMouseState(&xpos, &ypos);
  58.  
  59.     if (firstMouse) {
  60.         lastX = xpos;
  61.         lastY = ypos;
  62.         firstMouse = false;
  63.     }
  64.  
  65.     float xoffset = xpos - lastX;
  66.     float yoffset = lastY - ypos;
  67.     lastX = xpos;
  68.     lastY = ypos;
  69.  
  70.     float sensitivity = 0.7f;
  71.     xoffset *= sensitivity;
  72.     yoffset *= sensitivity;
  73.  
  74.     yaw += xoffset;
  75.     pitch += yoffset;
  76.  
  77.     if (pitch > 89.0f)
  78.         pitch = 89.0f;
  79.     if (pitch < -89.0f)
  80.         pitch = -89.0f;
  81.  
  82.     vec3 direction;
  83.     direction[0] = cos(glm_rad(yaw)) * cos(glm_rad(pitch));
  84.     direction[1] = sin(glm_rad(pitch));
  85.     direction[2] = sin(glm_rad(yaw)) * cos(glm_rad(pitch));
  86.     glm_normalize_to(direction, cam_front);
  87. }
  88.  
  89. extern float gCamera_hither;
  90. extern float gCamera_yon;
  91.  
  92. float* DebugCamera_Projection(void) {
  93.     glm_perspective(glm_rad(55.55), 320.0f / 200.0f /*4.0f / 3.0f*/, gCamera_hither, gCamera_yon, projection);
  94.     return (float*)&projection;
  95. }
  96.  
  97. float* DebugCamera_View(void) {
  98.     vec3 look;
  99.     glm_vec3_add(cam_pos, cam_front, look);
  100.     glm_lookat(cam_pos, look, cam_up, view);
  101.     return (float*)&view;
  102. }
  103.  
  104. void DebugCamera_SetPosition(float x, float y, float z) {
  105.     if (cam_pos[0] == 0) {
  106.         cam_pos[0] = x;
  107.         cam_pos[1] = y;
  108.         cam_pos[2] = z;
  109.     }
  110. }
  111.  
  112. #endif // 0
  113.