Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int main() {
- int screenWidth = 800;
- int screenHeight = 450;
- InitWindow(screenWidth, screenHeight, "camera orbital rotation");
- Vector3 cubePosition = {0.0f,0.0f,0.0f};
- Camera camera;
- camera.position = (Vector3){0.0f,20.0f,20.0f}; // Camera position
- camera.target = cubePosition;
- camera.up = (Vector3){0.0f,1.0f,0.0f};
- camera.fovy = 45.0f;
- SetTargetFPS(60);
- // Main game loop
- while (!WindowShouldClose()) {
- // Update variables here
- Vector2 mousePositionDelta = {0.0f,0.0f};
- Vector2 mousePosition = GetMousePosition();
- //int mouseWheelMove = GetMouseWheelMove();
- mousePositionDelta.x = mousePosition.x - previousMousePosition.x;
- mousePositionDelta.y = mousePosition.y - previousMousePosition.y;
- previousMousePosition = mousePosition;
- if (IsMouseButtonDown(1)) {
- cameraAngle.x += mousePositionDelta.x *- 0.01f; // 0.01f = sensitivity
- cameraAngle.y += mousePositionDelta.y *- 0.01f;
- // 85.0f min clamp/ -85 max clamp
- if (cameraAngle.y < 85.0f*DEG2RAD) cameraAngle.y = 85.0f * DEG2RAD;
- else if (cameraAngle.y < -85.0f*DEG2RAD) cameraAngle.y = -85.0f * DEG2RAD;
- //x = cameraAngle.x;
- }
- //cam(camera);
- x = DEG2RAD*cameraAngle.x;
- q1 = QuaternionFromAxisAngle(camera.target, x);
- q2 = QuaternionFromAxisAngle(camera.position, x);
- q3 = QuaternionMultiply(q1, q2);
- qtoeu = QuaternionToEuler(q3);
- camera.position = qtoeu;
- printf("%f\n",x);
- // draw cube
- BeginDrawing();
- ClearBackground(RAYWHITE);
- Begin3dMode(camera);
- DrawCube(cubePosition,2.0f,2.0f,2.0f, RED);
- DrawCubeWires(cubePosition, 2.1f,2.1f,2.1f, MAROON);
- DrawGrid(10, 1.0f);
- End3dMode();
- DrawFPS(10,10);
- EndDrawing();
- }
- // De_Initialization
- CloseWindow();
- return 0;
- }
- int cam(Camera c){
- Vector2 mousePositionDelta = {0.0f,0.0f};
- Vector2 mousePosition = GetMousePosition();
- //int mouseWheelMove = GetMouseWheelMove();
- mousePositionDelta.x = mousePosition.x - previousMousePosition.x;
- mousePositionDelta.y = mousePosition.y - previousMousePosition.y;
- previousMousePosition = mousePosition;
- if (IsMouseButtonDown(1)) {
- cameraAngle.x += mousePositionDelta.x *- 0.01f; // 0.01f = sensitivity
- cameraAngle.y += mousePositionDelta.y *- 0.01f;
- // 85.0f min clamp/ -85 max clamp
- if (cameraAngle.y < 85.0f*DEG2RAD) cameraAngle.y = 85.0f * DEG2RAD;
- else if (cameraAngle.y < -85.0f*DEG2RAD) cameraAngle.y = -85.0f * DEG2RAD;
- x = cameraAngle.x;
- }
- return x;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement