Skip to content

Commit

Permalink
GRAPHICS: Add a SceneManager for Ogre
Browse files Browse the repository at this point in the history
  • Loading branch information
DrMcCoy committed Jan 19, 2014
1 parent 890972b commit 429740e
Show file tree
Hide file tree
Showing 8 changed files with 498 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/engines/enginemanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
#include "graphics/cursorman.h"
#include "graphics/textureman.h"

#include "graphics/aurora/sceneman.h"

#include "events/events.h"
#include "events/requests.h"

Expand Down Expand Up @@ -225,6 +227,8 @@ void EngineManager::cleanup(GameInstance &game) const {

RequestMan.sync();

SceneMan.clear();

CursorMan.clear();
TextureMan.clear();

Expand Down
10 changes: 10 additions & 0 deletions src/graphics/aurora/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,15 @@ include $(top_srcdir)/Makefile.common

noinst_LTLIBRARIES = libaurora.la

noinst_HEADERS = \
types.h \
meshutil.h \
sceneman.h \
renderable.h \
$(EMPTY)

libaurora_la_SOURCES = \
meshutil.cpp \
sceneman.cpp \
renderable.cpp \
$(EMPTY)
176 changes: 176 additions & 0 deletions src/graphics/aurora/renderable.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
/* 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/aurora/renderable.cpp
* Base class for renderable objects.
*/

#include <OgreSceneNode.h>

#include "graphics/aurora/renderable.h"
#include "graphics/aurora/sceneman.h"

namespace Graphics {

namespace Aurora {

Renderable::Renderable() : _rootNode(0), _visible(false) {
_basePosition[0] = 0.0;
_basePosition[1] = 0.0;
_basePosition[2] = 0.0;

_baseOrientation[0] = 0.0;
_baseOrientation[1] = 1.0;
_baseOrientation[2] = 0.0;
_baseOrientation[3] = 0.0;

_baseScale[0] = 1.0;
_baseScale[1] = 1.0;
_baseScale[2] = 1.0;
}

Renderable::~Renderable() {
}

Ogre::SceneNode *Renderable::getRootNode() {
return _rootNode;
}

void Renderable::setVisible(bool visible) {
LOCK_FRAME();

_visible = visible;
_rootNode->setVisible(visible);
}

bool Renderable::isVisible() const {
return _visible;
}

void Renderable::setBasePosition(float x, float y, float z) {
_basePosition[0] = x;
_basePosition[1] = y;
_basePosition[2] = z;

setPosition(0.0, 0.0, 0.0);
}

void Renderable::setBaseOrientation(float radian, float x, float y, float z) {
_baseOrientation[0] = radian;
_baseOrientation[1] = x;
_baseOrientation[2] = y;
_baseOrientation[3] = z;

setOrientation(0.0, 1.0, 0.0, 0.0);
}

void Renderable::setBaseScale(float x, float y, float z) {
_baseScale[0] = x;
_baseScale[1] = y;
_baseScale[2] = z;

setScale(1.0, 1.0, 1.0);
}

void Renderable::getPosition(float &x, float &y, float &z) const {
const Ogre::Vector3 &p = _rootNode->getPosition();

x = p.x - _basePosition[0];
y = p.y - _basePosition[1];
z = p.z - _basePosition[2];
}

void Renderable::getOrientation(float &radian, float &x, float &y, float &z) const {
Ogre::Quaternion base(Ogre::Radian(_baseOrientation[0]),
Ogre::Vector3(_baseOrientation[1], _baseOrientation[2], _baseOrientation[3]));

const Ogre::Quaternion &q = base.Inverse() * _rootNode->getOrientation();


Ogre::Radian angle;
Ogre::Vector3 axis;

q.ToAngleAxis(angle, axis);

radian = angle.valueRadians();
x = axis.x;
y = axis.y;
z = axis.z;
}

void Renderable::getScale(float &x, float &y, float &z) const {
LOCK_FRAME();

const Ogre::Vector3 &s = _rootNode->getScale();

x = s.x / _baseScale[0];
y = s.y / _baseScale[1];
z = s.z / _baseScale[2];
}

void Renderable::setPosition(float x, float y, float z) {
LOCK_FRAME();

_rootNode->setPosition(x + _basePosition[0], y + _basePosition[1], z + _basePosition[2]);
}

void Renderable::setOrientation(float radian, float x, float y, float z) {
LOCK_FRAME();

Ogre::Quaternion base(Ogre::Radian(_baseOrientation[0]),
Ogre::Vector3(_baseOrientation[1], _baseOrientation[2], _baseOrientation[3]));
Ogre::Quaternion modi(Ogre::Quaternion(Ogre::Radian(radian), Ogre::Vector3(x, y, z)));

_rootNode->setOrientation(base);
_rootNode->rotate(modi);
}

void Renderable::setScale(float x, float y, float z) {
LOCK_FRAME();

_rootNode->setScale(x * _baseScale[0], y * _baseScale[1], z * _baseScale[2]);
}

void Renderable::move(float x, float y, float z) {
LOCK_FRAME();

_rootNode->translate(x, y, z);
}

void Renderable::rotate(float radian, float x, float y, float z) {
LOCK_FRAME();

_rootNode->rotate(Ogre::Quaternion(Ogre::Radian(radian), Ogre::Vector3(x, y, z)));
}

void Renderable::scale(float x, float y, float z) {
LOCK_FRAME();

_rootNode->scale(x, y, z);
}

} // End of namespace Aurora

} // End of namespace Graphics
94 changes: 94 additions & 0 deletions src/graphics/aurora/renderable.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/* 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/aurora/renderable.h
* Base class for renderable objects.
*/

#ifndef GRAPHICS_AURORA_RENDERABLE_H
#define GRAPHICS_AURORA_RENDERABLE_H

namespace Ogre {
class SceneNode;
}

namespace Graphics {

namespace Aurora {

class Renderable {
public:
Renderable();
virtual ~Renderable();

Ogre::SceneNode *getRootNode();

bool isVisible() const;

virtual void setVisible(bool visible);

/** Set the base position. All positioning will be done relative to the base position. */
void setBasePosition(float x, float y, float z);
/** Set the base orientation. All orienting will be done relative to the base orientation. */
void setBaseOrientation(float radian, float x, float y, float z);
/** Set the base scale. All scaling will be done relative to the base scale. */
void setBaseScale(float x, float y, float z);

/** Get the current position of the renderable. */
virtual void getPosition(float &x, float &y, float &z) const;
/** Get the current orientation of the renderable. */
virtual void getOrientation(float &radian, float &x, float &y, float &z) const;
/** Get the current scale of the renderable. */
virtual void getScale(float &x, float &y, float &z) const;

/** Set the current position of the renderable. */
virtual void setPosition(float x, float y, float z);
/** Set the current orientation of the renderable. */
virtual void setOrientation(float radian, float x, float y, float z);
/** Set the current scale of the renderable. */
virtual void setScale(float x, float y, float z);

/** Move the renderable, relative to its current position. */
virtual void move (float x, float y, float z);
/** Rotate the renderable, relative to its current orientation. */
virtual void rotate(float radian, float x, float y, float z);
/** Scale the renderable, relative to its current scale. */
virtual void scale(float x, float y, float z);

protected:
Ogre::SceneNode *_rootNode;

bool _visible;

float _basePosition[3];
float _baseOrientation[4];
float _baseScale[3];
};

} // End of namespace Aurora

} // End of namespace Graphics

#endif // GRAPHICS_AURORA_RENDERABLE_H
79 changes: 79 additions & 0 deletions src/graphics/aurora/sceneman.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/* 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/aurora/sceneman.cpp
* A scene manager.
*/

#include "common/threads.h"

#include "graphics/aurora/sceneman.h"
#include "graphics/aurora/renderable.h"

#include "events/requests.h"

DECLARE_SINGLETON(Graphics::Aurora::SceneManager)

namespace Graphics {

namespace Aurora {


SceneManager::SceneManager() : _modelType(kModelTypeNone) {
}

SceneManager::~SceneManager() {
}

void SceneManager::destroy() {
Common::Singleton<SceneManager>::destroy();
}

void SceneManager::clear() {
_modelType = kModelTypeNone;
}

void SceneManager::registerModelType(ModelType type) {
_modelType = type;
}

void SceneManager::destroy(Renderable *r) {
if (!r)
return;

if (!Common::isMainThread()) {
Events::MainThreadFunctor<void> functor(boost::bind(&SceneManager::destroy, this, r));

return RequestMan.callInMainThread(functor);
}

LOCK_FRAME();

delete r;
}

} // End of namespace Aurora

} // End of namespace Graphics

0 comments on commit 429740e

Please sign in to comment.