Advertisement
Guest User

Untitled

a guest
Jan 21st, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.91 KB | None | 0 0
  1. int main() {
  2.     int screenWidth = 800;
  3.     int screenHeight = 450;
  4.  
  5.     InitWindow(screenWidth, screenHeight, "camera orbital rotation");
  6.    
  7.     Vector3 cubePosition = {0.0f,0.0f,0.0f};
  8.  
  9.     Camera camera;
  10.     camera.position = (Vector3){0.0f,20.0f,20.0f};   // Camera position
  11.     camera.target = cubePosition;
  12.     camera.up = (Vector3){0.0f,1.0f,0.0f};
  13.     camera.fovy = 45.0f;
  14.  
  15.     SetTargetFPS(60);
  16.  
  17.     // Main game loop
  18.     while (!WindowShouldClose()) {
  19.         // Update variables here
  20.        
  21.         Vector2 mousePositionDelta = {0.0f,0.0f};
  22.         Vector2 mousePosition = GetMousePosition();
  23.         //int mouseWheelMove = GetMouseWheelMove();
  24.    
  25.         mousePositionDelta.x = mousePosition.x - previousMousePosition.x;
  26.         mousePositionDelta.y = mousePosition.y - previousMousePosition.y;
  27.  
  28.         previousMousePosition = mousePosition;
  29.  
  30.         if (IsMouseButtonDown(1)) {
  31.             cameraAngle.x += mousePositionDelta.x *- 0.01f;     // 0.01f = sensitivity
  32.             cameraAngle.y += mousePositionDelta.y *- 0.01f;
  33.  
  34.             // 85.0f min clamp/ -85 max clamp
  35.             if (cameraAngle.y < 85.0f*DEG2RAD) cameraAngle.y = 85.0f * DEG2RAD;
  36.             else if (cameraAngle.y < -85.0f*DEG2RAD) cameraAngle.y = -85.0f * DEG2RAD;
  37.  
  38.             //x = cameraAngle.x;
  39.  
  40.         }
  41.        
  42.         //cam(camera);
  43.         x = DEG2RAD*cameraAngle.x;
  44.         q1 = QuaternionFromAxisAngle(camera.target, x);
  45.         q2 = QuaternionFromAxisAngle(camera.position, x);
  46.         q3 = QuaternionMultiply(q1, q2);
  47.         qtoeu = QuaternionToEuler(q3);
  48.        
  49.         camera.position = qtoeu;
  50.        
  51.         printf("%f\n",x);
  52.        
  53.        
  54.         // draw cube
  55.         BeginDrawing();
  56.             ClearBackground(RAYWHITE);
  57.  
  58.             Begin3dMode(camera);
  59.                 DrawCube(cubePosition,2.0f,2.0f,2.0f, RED);
  60.                 DrawCubeWires(cubePosition, 2.1f,2.1f,2.1f, MAROON);
  61.  
  62.                 DrawGrid(10, 1.0f);
  63.  
  64.             End3dMode();
  65.  
  66.             DrawFPS(10,10);
  67.  
  68.         EndDrawing();
  69.     }
  70.  
  71.     // De_Initialization
  72.     CloseWindow();
  73.  
  74.     return 0;
  75. }
  76.  
  77. int cam(Camera c){
  78.  
  79.     Vector2 mousePositionDelta = {0.0f,0.0f};
  80.     Vector2 mousePosition = GetMousePosition();
  81.     //int mouseWheelMove = GetMouseWheelMove();
  82.  
  83.    
  84.    
  85.     mousePositionDelta.x = mousePosition.x - previousMousePosition.x;
  86.     mousePositionDelta.y = mousePosition.y - previousMousePosition.y;
  87.  
  88.     previousMousePosition = mousePosition;
  89.  
  90.     if (IsMouseButtonDown(1)) {
  91.         cameraAngle.x += mousePositionDelta.x *- 0.01f;     // 0.01f = sensitivity
  92.         cameraAngle.y += mousePositionDelta.y *- 0.01f;
  93.  
  94.         // 85.0f min clamp/ -85 max clamp
  95.         if (cameraAngle.y < 85.0f*DEG2RAD) cameraAngle.y = 85.0f * DEG2RAD;
  96.         else if (cameraAngle.y < -85.0f*DEG2RAD) cameraAngle.y = -85.0f * DEG2RAD;
  97.  
  98.         x = cameraAngle.x;
  99.  
  100.     }
  101.     return x;
  102.    
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement