#pragma once #include #include /** * The Scene panel's camera. Not part of any scene the editor edits, and never * saved with one. * * In 3D it orbits a pivot point at some distance; in 2D it looks straight * down -Z at the pivot through an orthographic projection, like a 2D game * camera. */ class EditorCamera { public: enum class Mode { Scene3D, Scene2D }; Mode mode = Mode::Scene3D; // Turns around the pivot by a mouse movement in pixels. 3D only. void orbit(glm::vec2 pixels); // Moves the pivot so the scene follows a mouse movement in pixels across a // viewport `viewportHeight` pixels tall. void pan(glm::vec2 pixels, float viewportHeight); // Moves in (positive) or out by mouse wheel steps. void zoom(float steps); // Moves the pivot along the camera's axes: x right, y up, z backwards. // `direction` needn't be normalized. 3D only. void fly(glm::vec3 direction, float deltaTime); // Centers on `target`, backing off enough to see a sphere of `radius`. void frame(glm::vec3 target, float radius); sophia::TransformComponent getTransform() const; sophia::CameraComponent getCamera() const; private: glm::quat getRotation() const; glm::vec3 pivot{0.f, 0.f, 0.f}; // 3D: looking at the pivot from in front, a little to the right and above. float yaw = glm::radians(30.f); float pitch = glm::radians(-25.f); float distance = 8.f; float fov = glm::radians(60.f); // 2D: world units visible from the bottom of the view to the top. float orthoHeight = 10.f; };