| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340 |
- /*
- * Copyright (C) 2022 The V-Gears Team
- *
- * This file is part of V-Gears
- *
- * V-Gears is free software: you can redistribute it and/or modify it under
- * terms of the GNU General Public License as published by the Free Software
- * Foundation, version 3.0 (GPLv3) of the License.
- *
- * V-Gears is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- */
- #pragma once
- #include <OgreCamera.h>
- #include <OgreSingleton.h>
- #include "engine/Event.h"
- #include "engine/Manager.h"
- /**
- * The camera manager.
- */
- class CameraManager : public Manager, public Ogre::Singleton<CameraManager>{
- public:
- /**
- * Constructor.
- *
- * Initializes the camera with default parameters attached to the root scene
- * manager.
- */
- CameraManager();
- /**
- * Destructor.
- */
- virtual ~CameraManager();
- /**
- * Handles camera actions.
- *
- * Handles the scene manager camera actions based on events.
- *
- * @param[in] event Event that triggers the camera action.
- */
- void Input(const VGears::Event& event) override;
- /**
- * Handles camera actions.
- *
- * Handles the scene manager camera actions based on events.
- *
- * @param[in] event Event that triggers the camera action.
- * @param[in] time_since_last_frame For speed calculation.
- */
- void Input(const VGears::Event& event , Ogre::Real time_since_last_frame);
- /**
- * Trigered when the viewport is resized.
- *
- * Resets the aspect ratio.
- */
- void OnResize() override;
- /**
- * Updates debug information.
- */
- void UpdateDebug() override;
- /**
- * Clears all field information in the camera manager.
- */
- void ClearField() override;
- /**
- * Clears all battle information in the camera manager.
- */
- void ClearBattle() override;
- /**
- * Clears all world map information in the camera manager.
- */
- void ClearWorld() override;
- /**
- * Enables or disables the free camera.
- *
- * A free camera moves depending on player input, not according to a
- * script. For example, a camera following the PC is a free camera.
- *
- * @param[in] enable True to enable free camera, false to disable it.
- */
- void SetCameraFree(const bool enable);
- /**
- * Sets the camera properties.
- *
- * @param[in] position Camera coordinates.
- * @param[in] orientation Camera rotation, in quaternion format.
- * @param[in] fov Field of view, in radians.
- */
- void Set2DCamera(
- const Ogre::Vector3 position, const Ogre::Quaternion orientation,
- const Ogre::Radian fov
- );
- /**
- * Places the camera where the camera of a movie is, to draw the models over it. The field
- * camera is kept, and the scroll of the background doesn't move the camera until
- * {@see EndMovieCamera}.
- *
- * @param[in] position Camera coordinates.
- * @param[in] orientation Camera rotation.
- * @param[in] fov Vertical field of view.
- */
- void SetMovieCamera(
- const Ogre::Vector3& position, const Ogre::Quaternion& orientation, const Ogre::Radian& fov
- );
- /**
- * Puts the camera of the field back, with its scroll.
- */
- void EndMovieCamera();
- /**
- * Starts the battle camera
- *
- * Saves the position and orientation of the current camera to return once the battle is
- * over.
- *
- * @param[in] position Initial position of the battle camera.
- * @param[in] orientation Initial orientation of the battle camera. It indicates the point
- * the camera will look at.
- */
- void StartBattleCamera(const Ogre::Vector3 position, const Ogre::Vector3 orientation);
- /**
- * Ends the battle camera
- *
- * Returns the camera to the state it was when {@see StartBattleCamera} was called.
- */
- void EndBattleCamera();
- /**
- * Sets the camera scroll.
- *
- * Moves the camera to the desired position. If the camera is in free
- * mode, it sets the position, but it won't actually move the camera.
- *
- * @param[in] position Position to scroll the camera to.
- */
- void Set2DScroll(const Ogre::Vector2& position);
- /**
- * Retrieves the camera position.
- *
- * @return The camera current position, relative to absolute origin.
- */
- const Ogre::Vector2& Get2DScroll() const;
- /**
- * Calculates the position of a point in screen.
- *
- * The calculation is done using A map position and the camera scroll.
- *
- * @param[in] point Position of the map to be translated to screen
- * position.
- * @return Position of POINT in screen coordinates.
- */
- const Ogre::Vector3 ProjectPointToScreen(const Ogre::Vector3& point);
- /**
- * Sets the battle camera, like {@see SetBattleCameraUpright}.
- *
- * Unlike {@see StartBattleCamera}, it doesn't save the state of the field camera, so it
- * can be used to change the camera during a battle.
- *
- * @param[in] position Camera position.
- * @param[in] orientation Point the camera looks at.
- */
- void SetBattleCamera(const Ogre::Vector3 position, const Ogre::Vector3 orientation);
- /**
- * Sets the battle camera, always with the Z axis of the scene pointing up.
- *
- * It also moves the camera down to compensate for the part of the screen that the battle
- * interface covers.
- *
- * @param[in] position Camera position.
- * @param[in] look_at Point the camera looks at.
- */
- void SetBattleCameraUpright(const Ogre::Vector3 position, const Ogre::Vector3 look_at);
- /**
- * Projects a point of the scene into the coordinates of the UI.
- *
- * To be called from Lua scripts. UI units are the ones used by the UI widgets: 720 units
- * are the height of the screen, with the origin at the top left corner.
- *
- * @param[in] x X coordinate of the point.
- * @param[in] y Y coordinate of the point.
- * @param[in] z Z coordinate of the point.
- * @return X and Y in UI units, and the depth of the point (negative if it's behind the
- * camera).
- */
- std::tuple<float, float, float> ScriptProjectToUi(const float x, const float y, const float z);
- /**
- * Retrieves the camera.
- *
- * @return The current camera.
- */
- Ogre::Camera* GetCurrentCamera();
- /**
- * Retrieves the viewport.
- *
- * @return The camera viewport.
- */
- Ogre::Viewport* getViewport();
- /**
- * Sets the camera position and orientation.
- *
- * It's only meand to be used for 3D cameras (battle, world map...), and using it while on
- * a field can have unexpected results.
- *
- * @param[in] x X coordinate for the camera position.
- * @param[in] y Y coordinate for the camera position.
- * @param[in] z Z coordinate for the camera position.
- * @param[in] d_x X coordinate of the point the camera looks at.
- * @param[in] d_y Y coordinate of the point the camera looks at.
- * @param[in] d_z Z coordinate of the point the camera looks at.
- */
- void ScriptSetCamera(
- const int x, const int y, const int z, const int d_x, const int d_y, const int d_z
- );
- private:
- /**
- * Initializes the camera parameters.
- *
- * Must be called on construction.
- */
- void InitCommands();
- /**
- * Updates while the camera is in the field.
- */
- void UpdateField() override;
- /**
- * Updates while the camera is in battle.
- */
- void UpdateBattle() override;
- /**
- * Updates while the camera is in the world map.
- */
- void UpdateWorld() override;
- /**
- * The camera.
- */
- Ogre::Camera *camera_;
- /**
- * The viewport.
- */
- Ogre::Viewport *viewport_;
- /**
- * The initial position of the camera, saved when created.
- */
- Ogre::Vector3 position_initial_;
- /**
- * The initial orientation of the camera, saved when created.
- */
- Ogre::Quaternion orientation_initial_;
- /**
- * A backup of the field or world camera position for when the battle camera is activated.
- */
- Ogre::Vector3 position_backup_;
- /**
- * Field of view of the camera before a battle, restored when the battle ends.
- */
- Ogre::Radian fov_backup_;
- /**
- * A backup of the field or world camera orientation for when the battle camera is active.
- */
- Ogre::Quaternion orientation_backup_;
- /**
- * Flag to indicate a free camera.
- *
- * A free camera moves depending on player input, not according to a
- * script. For example, a camera following the PC is a free camera.
- */
- bool camera_free_;
- /**
- * Flag to indicate the free camera has rotated.
- */
- bool camera_free_rotate_;
- /**
- * Camera position.
- */
- Ogre::Vector3 d2_position_;
- /**
- * Camera orientation.
- */
- Ogre::Quaternion d2_orientation_;
- /**
- * The field of view.
- */
- Ogre::Radian d2_fov_;
- /**
- * The camera scroll.
- */
- Ogre::Vector2 d2_scroll_;
- /**
- * Whether the camera is the one of a movie.
- */
- bool movie_camera_ = false;
- };
|