From 3f02de7ce1f30d85a98737888d61f2ac11133708 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 31 Dec 2010 15:53:53 +0100 Subject: [PATCH] Renamed AbstractObject -> Object, draw() is now dummy instead of pure virtual. --- examples/triangle/Triangle.cpp | 2 +- examples/triangle/Triangle.h | 6 ++-- src/CMakeLists.txt | 2 +- src/Camera.cpp | 2 +- src/Camera.h | 14 ++------ src/{AbstractObject.cpp => Object.cpp} | 8 ++--- src/{AbstractObject.h => Object.h} | 34 +++++++++++-------- src/Scene.cpp | 4 +-- src/Scene.h | 10 +++--- src/Test/CMakeLists.txt | 2 +- ...{AbstractObjectTest.cpp => ObjectTest.cpp} | 6 ++-- .../{AbstractObjectTest.h => ObjectTest.h} | 16 +++------ 12 files changed, 47 insertions(+), 59 deletions(-) rename src/{AbstractObject.cpp => Object.cpp} (82%) rename src/{AbstractObject.h => Object.h} (85%) rename src/Test/{AbstractObjectTest.cpp => ObjectTest.cpp} (90%) rename src/Test/{AbstractObjectTest.h => ObjectTest.h} (58%) diff --git a/examples/triangle/Triangle.cpp b/examples/triangle/Triangle.cpp index 3713f1ecf..cd17e6d6e 100644 --- a/examples/triangle/Triangle.cpp +++ b/examples/triangle/Triangle.cpp @@ -19,7 +19,7 @@ namespace Magnum { namespace Examples { -Triangle::Triangle(AbstractObject* parent): AbstractObject(parent), mesh(Mesh::Triangles, 3) { +Triangle::Triangle(Object* parent): Object(parent), mesh(Mesh::Triangles, 3) { /* Vertices and colors, interleaved */ Vector4 data[] = { Vector4(-0.5f, -0.5f, 0.0f), Vector4(1.0f, 0.0f, 0.0f), /* Red lower left vertex */ diff --git a/examples/triangle/Triangle.h b/examples/triangle/Triangle.h index 80f43e0de..9ff45040b 100644 --- a/examples/triangle/Triangle.h +++ b/examples/triangle/Triangle.h @@ -15,15 +15,15 @@ GNU Lesser General Public License version 3 for more details. */ -#include "AbstractObject.h" +#include "Object.h" #include "Mesh.h" #include "IdentityShader.h" namespace Magnum { namespace Examples { -class Triangle: public AbstractObject { +class Triangle: public Object { public: - Triangle(AbstractObject* parent = 0); + Triangle(Object* parent = 0); virtual void draw(const Matrix4& transformationMatrix, const Matrix4& projectionMatrix); diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 829209029..eb0aaa3e7 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -6,7 +6,7 @@ find_package(GLEW REQUIRED) add_subdirectory(Math) set(Magnum_SRCS - AbstractObject.cpp + Object.cpp AbstractShaderProgram.cpp Camera.cpp IndexedMesh.cpp diff --git a/src/Camera.cpp b/src/Camera.cpp index 72f2de11b..bbb791c73 100644 --- a/src/Camera.cpp +++ b/src/Camera.cpp @@ -17,7 +17,7 @@ namespace Magnum { -Camera::Camera(AbstractObject* parent): AbstractObject(parent), viewportWidth(0), viewportHeight(0), _aspectRatioPolicy(Extend) { +Camera::Camera(Object* parent): Object(parent), viewportWidth(0), viewportHeight(0), _aspectRatioPolicy(Extend) { setOrthographic(2, 1, 1000); } diff --git a/src/Camera.h b/src/Camera.h index 085699ee1..136bc3702 100644 --- a/src/Camera.h +++ b/src/Camera.h @@ -19,7 +19,7 @@ * @brief Class Magnum::Camera */ -#include "AbstractObject.h" +#include "Object.h" namespace Magnum { @@ -28,7 +28,7 @@ namespace Magnum { * * @todo Subclasses - perspective, FBO postprocessing etc. */ -class Camera: public AbstractObject { +class Camera: public Object { public: /** @brief Aspect ratio policy */ enum AspectRatioPolicy { @@ -43,7 +43,7 @@ class Camera: public AbstractObject { * * Calls setOrthographic(2, 1, 1000). */ - Camera(AbstractObject* parent = 0); + Camera(Object* parent = 0); /** @brief Aspect ratio policy */ AspectRatioPolicy aspectRatioPolicy() const { return _aspectRatioPolicy; } @@ -96,14 +96,6 @@ class Camera: public AbstractObject { */ void setViewport(int width, int height); - /** - * @brief Draw camera - * - * Subclasses can draw for example an HUD. Default implementation does - * nothing. - */ - virtual void draw(const Magnum::Matrix4& transformationMatrix, const Magnum::Matrix4& projectionMatrix) {} - private: Matrix4 rawProjectionMatrix; Matrix4 _projectionMatrix; diff --git a/src/AbstractObject.cpp b/src/Object.cpp similarity index 82% rename from src/AbstractObject.cpp rename to src/Object.cpp index a3a47c592..2dee248b5 100644 --- a/src/AbstractObject.cpp +++ b/src/Object.cpp @@ -13,13 +13,13 @@ GNU Lesser General Public License version 3 for more details. */ -#include "AbstractObject.h" +#include "Object.h" using namespace std; namespace Magnum { -void AbstractObject::setParent(AbstractObject* parent) { +void Object::setParent(Object* parent) { if(_parent == parent) return; /* Remove the object from old parent children list */ @@ -34,12 +34,12 @@ void AbstractObject::setParent(AbstractObject* parent) { _parent = parent; } -AbstractObject::~AbstractObject() { +Object::~Object() { /* Remove the object from parent's children */ setParent(0); /* Delete all children */ - for(set::const_iterator it = _children.begin(); it != _children.end(); ++it) + for(set::const_iterator it = _children.begin(); it != _children.end(); ++it) delete *it; } diff --git a/src/AbstractObject.h b/src/Object.h similarity index 85% rename from src/AbstractObject.h rename to src/Object.h index 290af20f7..3dec16f00 100644 --- a/src/AbstractObject.h +++ b/src/Object.h @@ -1,5 +1,5 @@ -#ifndef Magnum_AbstractObject_h -#define Magnum_AbstractObject_h +#ifndef Magnum_Object_h +#define Magnum_Object_h /* Copyright © 2010 Vladimír Vondruš @@ -16,7 +16,7 @@ */ /** @file - * @brief Class Magnum::AbstractObject + * @brief Class Magnum::Object */ #include @@ -31,8 +31,8 @@ namespace Magnum { * @todo Transform transformation when changing parent, so the object stays in * place. */ -class AbstractObject { - DISABLE_COPY(AbstractObject) +class Object { + DISABLE_COPY(Object) public: /** @@ -41,7 +41,7 @@ class AbstractObject { * * Sets all transformations to their default values. */ - inline AbstractObject(AbstractObject* parent = 0): _parent(0) { + inline Object(Object* parent = 0): _parent(0) { setParent(parent); } @@ -51,16 +51,16 @@ class AbstractObject { * Removes itself from parent's children list and destroys all own * children. */ - virtual ~AbstractObject(); + virtual ~Object(); /** @brief Parent object */ - inline AbstractObject* parent() const { return _parent; } + inline Object* parent() const { return _parent; } /** @brief Child objects */ - inline const std::set& children() const { return _children; } + inline const std::set& children() const { return _children; } /** @brief Set parent object */ - void setParent(AbstractObject* parent); + void setParent(Object* parent); /** @brief Transformation matrix */ inline Matrix4 transformation() const { return _transformation; } @@ -87,7 +87,7 @@ class AbstractObject { * Sets parent and transformation from another object, so they will * appear in the same place. */ - inline void setTransformationFrom(const AbstractObject& another) { + inline void setTransformationFrom(const Object& another) { setParent(another.parent()); setTransformation(another.transformation()); } @@ -134,12 +134,16 @@ class AbstractObject { rotate(angle, Vector3(x, y, z), global); } - /** @brief Draw object */ - virtual void draw(const Matrix4& transformationMatrix, const Matrix4& projectionMatrix) = 0; + /** + * @brief Draw object + * + * Default implementation does nothing. + */ + virtual void draw(const Matrix4& transformationMatrix, const Matrix4& projectionMatrix) {} private: - AbstractObject* _parent; - std::set _children; + Object* _parent; + std::set _children; Matrix4 _transformation; }; diff --git a/src/Scene.cpp b/src/Scene.cpp index b86bb2eaa..d31826cb2 100644 --- a/src/Scene.cpp +++ b/src/Scene.cpp @@ -52,8 +52,8 @@ void Scene::draw() { drawChildren(this, _camera->cameraMatrix()); } -void Scene::drawChildren(AbstractObject* object, const Matrix4& transformationMatrix) { - for(set::const_iterator it = object->children().begin(); it != object->children().end(); ++it) { +void Scene::drawChildren(Object* object, const Matrix4& transformationMatrix) { + for(set::const_iterator it = object->children().begin(); it != object->children().end(); ++it) { /* Transformation matrix for the object */ Matrix4 matrix = transformationMatrix*(*it)->transformation(); diff --git a/src/Scene.h b/src/Scene.h index e054290b8..372d3da8c 100644 --- a/src/Scene.h +++ b/src/Scene.h @@ -24,10 +24,10 @@ namespace Magnum { /** @brief Scene */ -class Scene: public AbstractObject { +class Scene: public Object { private: - AbstractObject::setTransformation; - AbstractObject::setParent; + Object::setParent; + Object::setTransformation; public: /** @brief Features */ @@ -38,7 +38,7 @@ class Scene: public AbstractObject { }; /** @brief Constructor */ - inline Scene(): AbstractObject(0), _features(0), _camera(0) { + inline Scene(): Object(0), _features(0), _camera(0) { setClearColor(0.1f, 0.1f, 0.1f, 1.0f); } @@ -90,7 +90,7 @@ class Scene: public AbstractObject { unsigned int viewportWidth, viewportHeight; inline virtual void draw(const Magnum::Matrix4& transformationMatrix, const Magnum::Matrix4& projectionMatrix) {} - void drawChildren(AbstractObject* object, const Matrix4& transformationMatrix); + void drawChildren(Object* object, const Matrix4& transformationMatrix); }; } diff --git a/src/Test/CMakeLists.txt b/src/Test/CMakeLists.txt index 4870d1582..919f63675 100644 --- a/src/Test/CMakeLists.txt +++ b/src/Test/CMakeLists.txt @@ -1,2 +1,2 @@ -magnum_add_test(AbstractObjectTest AbstractObjectTest.h AbstractObjectTest.cpp Magnum) +magnum_add_test(ObjectTest ObjectTest.h ObjectTest.cpp Magnum) magnum_add_test(CameraTest CameraTest.h CameraTest.cpp Magnum) diff --git a/src/Test/AbstractObjectTest.cpp b/src/Test/ObjectTest.cpp similarity index 90% rename from src/Test/AbstractObjectTest.cpp rename to src/Test/ObjectTest.cpp index 896fddc47..3a13d2b63 100644 --- a/src/Test/AbstractObjectTest.cpp +++ b/src/Test/ObjectTest.cpp @@ -13,15 +13,15 @@ GNU Lesser General Public License version 3 for more details. */ -#include "AbstractObjectTest.h" +#include "ObjectTest.h" #include -QTEST_APPLESS_MAIN(Magnum::Test::AbstractObjectTest) +QTEST_APPLESS_MAIN(Magnum::Test::ObjectTest) namespace Magnum { namespace Test { -void AbstractObjectTest::parenting() { +void ObjectTest::parenting() { Object root; Object* childOne = new Object(&root); diff --git a/src/Test/AbstractObjectTest.h b/src/Test/ObjectTest.h similarity index 58% rename from src/Test/AbstractObjectTest.h rename to src/Test/ObjectTest.h index 40696d469..8e311d828 100644 --- a/src/Test/AbstractObjectTest.h +++ b/src/Test/ObjectTest.h @@ -1,5 +1,5 @@ -#ifndef Magnum_Test_AbstractObjectTest_h -#define Magnum_Test_AbstractObjectTest_h +#ifndef Magnum_Test_ObjectTest_h +#define Magnum_Test_ObjectTest_h /* Copyright © 2010 Vladimír Vondruš @@ -17,19 +17,11 @@ #include -#include "AbstractObject.h" +#include "Object.h" namespace Magnum { namespace Test { -class Object: public AbstractObject { - public: - inline Object(AbstractObject* parent = 0): AbstractObject(parent) {} - inline virtual void draw(const Magnum::Matrix4& transformationMatrix, const Magnum::Matrix4& projectionMatrix) {} - - inline const std::set& children() { return AbstractObject::children(); } -}; - -class AbstractObjectTest: public QObject { +class ObjectTest: public QObject { Q_OBJECT private slots: