-
Notifications
You must be signed in to change notification settings - Fork 121
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GRAPHICS: Add a new CameraManager for Ogre
- Loading branch information
Showing
6 changed files
with
246 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
/* xoreos - A reimplementation of BioWare's Aurora engine | ||
* | ||
* xoreos is the legal property of its developers, whose names can be | ||
* found in the AUTHORS file distributed with this source | ||
* distribution. | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU General Public License | ||
* as published by the Free Software Foundation; either version 3 | ||
* of the License, or (at your option) any later version. | ||
* | ||
* This program 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. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
* | ||
* | ||
* The Infinity, Aurora, Odyssey, Eclipse and Lycium engines, Copyright (c) BioWare corp. | ||
* The Electron engine, Copyright (c) Obsidian Entertainment and BioWare corp. | ||
*/ | ||
|
||
/** @file graphics/cameraman.cpp | ||
* A camera manager. | ||
*/ | ||
|
||
#include <OgreRoot.h> | ||
#include <OgreCamera.h> | ||
#include <OgreViewport.h> | ||
#include <OgreRenderWindow.h> | ||
|
||
#include "graphics/cameraman.h" | ||
|
||
DECLARE_SINGLETON(Graphics::CameraManager) | ||
|
||
namespace Graphics { | ||
|
||
CameraManager::CameraManager() : _camera(0) { | ||
} | ||
|
||
CameraManager::~CameraManager() { | ||
deinit(); | ||
} | ||
|
||
void CameraManager::init() { | ||
Ogre::SceneManager *scene = Ogre::Root::getSingleton().getSceneManagerIterator().begin()->second; | ||
if (!scene) | ||
return; | ||
|
||
_camera = scene->createCamera("camera"); | ||
|
||
_camera->setNearClipDistance(1.0); | ||
_camera->setFarClipDistance(1000.0); | ||
_camera->setFOVy(Ogre::Degree(60.0)); | ||
} | ||
|
||
void CameraManager::deinit() { | ||
Ogre::SceneManager *scene = Ogre::Root::getSingleton().getSceneManagerIterator().begin()->second; | ||
if (!scene) | ||
return; | ||
|
||
if (_camera) | ||
scene->destroyCamera(_camera); | ||
|
||
_camera = 0; | ||
} | ||
|
||
Ogre::Viewport *CameraManager::createViewport(Ogre::RenderWindow *window) { | ||
return window->addViewport(_camera); | ||
} | ||
|
||
void CameraManager::setAspectRatio(float aspect) { | ||
_camera->setAspectRatio(aspect); | ||
} | ||
|
||
void CameraManager::reset() { | ||
_camera->setPosition(0.0, 0.0, 0.0); | ||
_camera->setOrientation(Ogre::Quaternion()); | ||
_camera->lookAt(0.0, 0.0, 0.0); | ||
} | ||
|
||
void CameraManager::getPosition(float &x, float &y, float &z) const { | ||
const Ogre::Vector3 &pos = _camera->getPosition(); | ||
|
||
x = pos.x; | ||
y = pos.y; | ||
z = pos.z; | ||
} | ||
|
||
void CameraManager::getDirection(float &x, float &y, float &z) const { | ||
const Ogre::Vector3 dir = _camera->getDirection(); | ||
|
||
x = dir.x; | ||
y = dir.y; | ||
z = dir.z; | ||
} | ||
|
||
void CameraManager::setPosition(float x, float y, float z) { | ||
_camera->setPosition(x, y, z); | ||
} | ||
|
||
void CameraManager::setDirection(float x, float y, float z) { | ||
_camera->setDirection(x, y, z); | ||
} | ||
|
||
void CameraManager::lookAt(float x, float y, float z) { | ||
_camera->lookAt(x, y, z); | ||
} | ||
|
||
void CameraManager::setOrientation(float radian, float x, float y, float z) { | ||
_camera->setOrientation(Ogre::Quaternion(Ogre::Radian(radian), Ogre::Vector3(x, y, z))); | ||
} | ||
|
||
void CameraManager::move(float x, float y, float z) { | ||
_camera->move(Ogre::Vector3(x, y, z)); | ||
} | ||
|
||
void CameraManager::moveRelative(float x, float y, float z) { | ||
_camera->moveRelative(Ogre::Vector3(x, y, z)); | ||
} | ||
|
||
void CameraManager::rotate(float radian, float x, float y, float z) { | ||
_camera->rotate(Ogre::Quaternion(Ogre::Radian(radian), Ogre::Vector3(x, y, z))); | ||
} | ||
|
||
void CameraManager::roll(float radian) { | ||
_camera->roll(Ogre::Radian(radian)); | ||
} | ||
|
||
void CameraManager::yaw(float radian) { | ||
_camera->yaw(Ogre::Radian(radian)); | ||
} | ||
|
||
void CameraManager::pitch(float radian) { | ||
_camera->pitch(Ogre::Radian(radian)); | ||
} | ||
|
||
} // End of namespace Graphics |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/* xoreos - A reimplementation of BioWare's Aurora engine | ||
* | ||
* xoreos is the legal property of its developers, whose names can be | ||
* found in the AUTHORS file distributed with this source | ||
* distribution. | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU General Public License | ||
* as published by the Free Software Foundation; either version 3 | ||
* of the License, or (at your option) any later version. | ||
* | ||
* This program 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. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
* | ||
* | ||
* The Infinity, Aurora, Odyssey, Eclipse and Lycium engines, Copyright (c) BioWare corp. | ||
* The Electron engine, Copyright (c) Obsidian Entertainment and BioWare corp. | ||
*/ | ||
|
||
/** @file graphics/cameraman.h | ||
* A camera manager. | ||
*/ | ||
|
||
#ifndef GRAPHICS_CAMERAMAN_H | ||
#define GRAPHICS_CAMERAMAN_H | ||
|
||
#include "common/singleton.h" | ||
|
||
namespace Ogre { | ||
class RenderWindow; | ||
class Viewport; | ||
class Camera; | ||
} | ||
|
||
namespace Graphics { | ||
|
||
class CameraManager : public Common::Singleton<CameraManager> { | ||
public: | ||
CameraManager(); | ||
~CameraManager(); | ||
|
||
void init(); | ||
void deinit(); | ||
|
||
/** Create a viewport for the camera in that window. */ | ||
Ogre::Viewport *createViewport(Ogre::RenderWindow *window); | ||
/** Adjust the aspect ratio of the camera. */ | ||
void setAspectRatio(float aspect); | ||
|
||
/** Reset the position and orientation of the camera. */ | ||
void reset(); | ||
|
||
void getPosition(float &x, float &y, float &z) const; | ||
void getDirection(float &x, float &y, float &z) const; | ||
|
||
void setPosition(float x, float y, float z); | ||
void setDirection(float x, float y, float z); | ||
|
||
void lookAt(float x, float y, float z); | ||
|
||
void setOrientation(float radian, float x, float y, float z); | ||
|
||
void move(float x, float y, float z); | ||
void moveRelative(float x, float y, float z); | ||
|
||
void rotate(float radian, float x, float y, float z); | ||
|
||
void roll(float radian); | ||
void yaw(float radian); | ||
void pitch(float radian); | ||
|
||
private: | ||
Ogre::Camera *_camera; ///< The OGRE camera. | ||
}; | ||
|
||
} // End of namespace Graphics | ||
|
||
/** Shortcut for accessing the camera manager. */ | ||
#define CameraMan Graphics::CameraManager::instance() | ||
|
||
#endif // GRAPHICS_CAMERAMAN_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters