# class hiro::draw::VisualCameraController

## Overview

Provides an automatic interface to camera manipulation by runtime user interaction. More…

    #include <VisualCameraController.h>

    class VisualCameraController: public glw::WindowEventObserver {
    public:
        // typedefs

        typedef std::function<void(uint32_t)> OnCameraChangeCallback;

        // construction

        VisualCameraController();
        ~VisualCameraController();

        // methods

        void SetScenes(const std::vector<hiro::draw::PScene>& scenes);
        void AddScene(const hiro::draw::PScene& scene);
        void Update(double delta_time);
        void SetCameraMode(uint32_t scene_id, hiro::draw::CameraMode mode);
        hiro::draw::CameraMode GetCameraMode(uint32_t scene_id) const;
        void SetCameraPoi(uint32_t scene_id, const glm::vec3& poi);
        glm::vec3 GetCameraPoi(uint32_t scene_id) const;
        void SetCameraGroup(const std::set<uint32_t>& scene_ids);
        const std::set<uint32_t>& GetCameraGroup() const;
        void UpdateGroupedCameras(const uint32_t source_scene_id) const;
        void SubscribeEventCameraChanged(const hiro::draw::VisualCameraController::OnCameraChangeCallback& func);
        void SetCameraSensitivity(float sens);
        float GetCameraSensitivity();

    protected:
        // methods

        virtual void OnMouseMove(double xpos, double ypos);
        virtual void OnMouseDown(int button, int mods);
        virtual void OnMouseUp(int button, int mods);
        virtual void NotifyOnCameraChange(uint32_t scene_id);
        virtual void OnMouseWheel(double xoffset, double yoffset);
        virtual void OnKeyDown(int key, int mods, bool is_repeat);
        virtual void OnKeyUp(int key, int mods);
    };

### Inherited Members

    protected:
        // methods

        virtual void OnMouseMove(double xpos, double ypos);
        virtual void OnMouseDown(int button, int mods);
        virtual void OnMouseUp(int button, int mods);
        virtual void OnMouseWheel(double xoffset, double yoffset);
        virtual void OnCharacter(char codepoint);
        virtual void OnKeyDown(int key, int mods, bool is_repeat);
        virtual void OnKeyUp(int key, int mods);
        virtual void OnTouch(unsigned int num_of_contacts, unsigned int* id, double* xpos, double* ypos, double* cwidth, double* cheight);
        virtual void OnTouchGestBegin();
        virtual void OnTouchGestEnd();
        virtual void OnTouchGestZoom(double distance, double xpos, double ypos);
        virtual void OnTouchGestPan(double distance, double xpos, double ypos);
        virtual void OnWindowMove(int xpos, int ypos);
        virtual void OnWindowRefresh();
        virtual void OnWindowResize(int width, int height);
        virtual void OnContentScale(float xscale, float yscale);
        virtual void OnFramebufferResize(int width, int height);
        virtual void OnWindowIconify(int is_iconified);
        virtual void OnWindowFocus(int is_focused);
        virtual void OnWindowClose();
        virtual void OnFilesDropped(const std::vector<std::string>& files);

## Detailed Documentation

Provides an automatic interface to camera manipulation by runtime user interaction.

For each Scene added to CameraController, an interaction is enabled. Cameras can be grouped in order to control multiple using a single action.

A method Update needs to be called every frame in order to function properly.

### Typedefs

    typedef std::function<void(uint32_t)> OnCameraChangeCallback

Callback function which is called each time a scene camera changes it’s state.

First parameter defines an index of the scene for which the change happened.

### Construction

    VisualCameraController()

Creates object with no scene to manipulate with.

### Methods

    void SetScenes(const std::vector<hiro::draw::PScene>& scenes)

Set scenes, whose internal cameras are to be controlled by mouse.

    void AddScene(const hiro::draw::PScene& scene)

Add scene to the list of scenes, whose internal cameras are to be controlled by mouse.

    void Update(double delta_time)

Update all controlled cameras once a render cycle. Obligatory for smoothened and animated cameras.

    void SetCameraMode(uint32_t scene_id, hiro::draw::CameraMode mode)

Changes behavioral mode for a camera of specified scene.

    hiro::draw::CameraMode GetCameraMode(uint32_t scene_id) const

Returns behavioral mode for a camera of specified scene.

    void SetCameraPoi(uint32_t scene_id, const glm::vec3& poi)

Sets up point of interest for camera, which will automatically look at the point.

If camera mode is set to one of orbital modes, camera will orbit the point.

    glm::vec3 GetCameraPoi(uint32_t scene_id) const

Returns point of interest for camera.

    void SetCameraGroup(const std::set<uint32_t>& scene_ids)

Sets up group of scene ids, whose cameras are grouped and behave simultaneously.

    const std::set<uint32_t>& GetCameraGroup() const

Returns group of scene ids, whose cameras are grouped and behave simultaneously.

    void UpdateGroupedCameras(const uint32_t source_scene_id) const

All cameras in group with source scene are updated by a camera of source scene.

This method needs to be called when camera of source scene is changed manually, in order to work correctly.

    void SubscribeEventCameraChanged(const hiro::draw::VisualCameraController::OnCameraChangeCallback& func)

Sets up optional callback function, which will be called each time a scene camera changes it’s state.