Browse Source

Renamed AbstractObject -> Object, draw() is now dummy instead of pure virtual.

vectorfields
Vladimír Vondruš 16 years ago
parent
commit
3f02de7ce1
  1. 2
      examples/triangle/Triangle.cpp
  2. 6
      examples/triangle/Triangle.h
  3. 2
      src/CMakeLists.txt
  4. 2
      src/Camera.cpp
  5. 14
      src/Camera.h
  6. 8
      src/Object.cpp
  7. 34
      src/Object.h
  8. 4
      src/Scene.cpp
  9. 10
      src/Scene.h
  10. 2
      src/Test/CMakeLists.txt
  11. 6
      src/Test/ObjectTest.cpp
  12. 16
      src/Test/ObjectTest.h

2
examples/triangle/Triangle.cpp

@ -19,7 +19,7 @@
namespace Magnum { namespace Examples { 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 */ /* Vertices and colors, interleaved */
Vector4 data[] = { Vector4 data[] = {
Vector4(-0.5f, -0.5f, 0.0f), Vector4(1.0f, 0.0f, 0.0f), /* Red lower left vertex */ Vector4(-0.5f, -0.5f, 0.0f), Vector4(1.0f, 0.0f, 0.0f), /* Red lower left vertex */

6
examples/triangle/Triangle.h

@ -15,15 +15,15 @@
GNU Lesser General Public License version 3 for more details. GNU Lesser General Public License version 3 for more details.
*/ */
#include "AbstractObject.h" #include "Object.h"
#include "Mesh.h" #include "Mesh.h"
#include "IdentityShader.h" #include "IdentityShader.h"
namespace Magnum { namespace Examples { namespace Magnum { namespace Examples {
class Triangle: public AbstractObject { class Triangle: public Object {
public: public:
Triangle(AbstractObject* parent = 0); Triangle(Object* parent = 0);
virtual void draw(const Matrix4& transformationMatrix, const Matrix4& projectionMatrix); virtual void draw(const Matrix4& transformationMatrix, const Matrix4& projectionMatrix);

2
src/CMakeLists.txt

@ -6,7 +6,7 @@ find_package(GLEW REQUIRED)
add_subdirectory(Math) add_subdirectory(Math)
set(Magnum_SRCS set(Magnum_SRCS
AbstractObject.cpp Object.cpp
AbstractShaderProgram.cpp AbstractShaderProgram.cpp
Camera.cpp Camera.cpp
IndexedMesh.cpp IndexedMesh.cpp

2
src/Camera.cpp

@ -17,7 +17,7 @@
namespace Magnum { 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); setOrthographic(2, 1, 1000);
} }

14
src/Camera.h

@ -19,7 +19,7 @@
* @brief Class Magnum::Camera * @brief Class Magnum::Camera
*/ */
#include "AbstractObject.h" #include "Object.h"
namespace Magnum { namespace Magnum {
@ -28,7 +28,7 @@ namespace Magnum {
* *
* @todo Subclasses - perspective, FBO postprocessing etc. * @todo Subclasses - perspective, FBO postprocessing etc.
*/ */
class Camera: public AbstractObject { class Camera: public Object {
public: public:
/** @brief Aspect ratio policy */ /** @brief Aspect ratio policy */
enum AspectRatioPolicy { enum AspectRatioPolicy {
@ -43,7 +43,7 @@ class Camera: public AbstractObject {
* *
* Calls <tt>setOrthographic(2, 1, 1000)</tt>. * Calls <tt>setOrthographic(2, 1, 1000)</tt>.
*/ */
Camera(AbstractObject* parent = 0); Camera(Object* parent = 0);
/** @brief Aspect ratio policy */ /** @brief Aspect ratio policy */
AspectRatioPolicy aspectRatioPolicy() const { return _aspectRatioPolicy; } AspectRatioPolicy aspectRatioPolicy() const { return _aspectRatioPolicy; }
@ -96,14 +96,6 @@ class Camera: public AbstractObject {
*/ */
void setViewport(int width, int height); 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: private:
Matrix4 rawProjectionMatrix; Matrix4 rawProjectionMatrix;
Matrix4 _projectionMatrix; Matrix4 _projectionMatrix;

8
src/AbstractObject.cpp → src/Object.cpp

@ -13,13 +13,13 @@
GNU Lesser General Public License version 3 for more details. GNU Lesser General Public License version 3 for more details.
*/ */
#include "AbstractObject.h" #include "Object.h"
using namespace std; using namespace std;
namespace Magnum { namespace Magnum {
void AbstractObject::setParent(AbstractObject* parent) { void Object::setParent(Object* parent) {
if(_parent == parent) return; if(_parent == parent) return;
/* Remove the object from old parent children list */ /* Remove the object from old parent children list */
@ -34,12 +34,12 @@ void AbstractObject::setParent(AbstractObject* parent) {
_parent = parent; _parent = parent;
} }
AbstractObject::~AbstractObject() { Object::~Object() {
/* Remove the object from parent's children */ /* Remove the object from parent's children */
setParent(0); setParent(0);
/* Delete all children */ /* Delete all children */
for(set<AbstractObject*>::const_iterator it = _children.begin(); it != _children.end(); ++it) for(set<Object*>::const_iterator it = _children.begin(); it != _children.end(); ++it)
delete *it; delete *it;
} }

34
src/AbstractObject.h → src/Object.h

@ -1,5 +1,5 @@
#ifndef Magnum_AbstractObject_h #ifndef Magnum_Object_h
#define Magnum_AbstractObject_h #define Magnum_Object_h
/* /*
Copyright © 2010 Vladimír Vondruš <mosra@centrum.cz> Copyright © 2010 Vladimír Vondruš <mosra@centrum.cz>
@ -16,7 +16,7 @@
*/ */
/** @file /** @file
* @brief Class Magnum::AbstractObject * @brief Class Magnum::Object
*/ */
#include <set> #include <set>
@ -31,8 +31,8 @@ namespace Magnum {
* @todo Transform transformation when changing parent, so the object stays in * @todo Transform transformation when changing parent, so the object stays in
* place. * place.
*/ */
class AbstractObject { class Object {
DISABLE_COPY(AbstractObject) DISABLE_COPY(Object)
public: public:
/** /**
@ -41,7 +41,7 @@ class AbstractObject {
* *
* Sets all transformations to their default values. * Sets all transformations to their default values.
*/ */
inline AbstractObject(AbstractObject* parent = 0): _parent(0) { inline Object(Object* parent = 0): _parent(0) {
setParent(parent); setParent(parent);
} }
@ -51,16 +51,16 @@ class AbstractObject {
* Removes itself from parent's children list and destroys all own * Removes itself from parent's children list and destroys all own
* children. * children.
*/ */
virtual ~AbstractObject(); virtual ~Object();
/** @brief Parent object */ /** @brief Parent object */
inline AbstractObject* parent() const { return _parent; } inline Object* parent() const { return _parent; }
/** @brief Child objects */ /** @brief Child objects */
inline const std::set<AbstractObject*>& children() const { return _children; } inline const std::set<Object*>& children() const { return _children; }
/** @brief Set parent object */ /** @brief Set parent object */
void setParent(AbstractObject* parent); void setParent(Object* parent);
/** @brief Transformation matrix */ /** @brief Transformation matrix */
inline Matrix4 transformation() const { return _transformation; } inline Matrix4 transformation() const { return _transformation; }
@ -87,7 +87,7 @@ class AbstractObject {
* Sets parent and transformation from another object, so they will * Sets parent and transformation from another object, so they will
* appear in the same place. * appear in the same place.
*/ */
inline void setTransformationFrom(const AbstractObject& another) { inline void setTransformationFrom(const Object& another) {
setParent(another.parent()); setParent(another.parent());
setTransformation(another.transformation()); setTransformation(another.transformation());
} }
@ -134,12 +134,16 @@ class AbstractObject {
rotate(angle, Vector3(x, y, z), global); 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: private:
AbstractObject* _parent; Object* _parent;
std::set<AbstractObject*> _children; std::set<Object*> _children;
Matrix4 _transformation; Matrix4 _transformation;
}; };

4
src/Scene.cpp

@ -52,8 +52,8 @@ void Scene::draw() {
drawChildren(this, _camera->cameraMatrix()); drawChildren(this, _camera->cameraMatrix());
} }
void Scene::drawChildren(AbstractObject* object, const Matrix4& transformationMatrix) { void Scene::drawChildren(Object* object, const Matrix4& transformationMatrix) {
for(set<AbstractObject*>::const_iterator it = object->children().begin(); it != object->children().end(); ++it) { for(set<Object*>::const_iterator it = object->children().begin(); it != object->children().end(); ++it) {
/* Transformation matrix for the object */ /* Transformation matrix for the object */
Matrix4 matrix = transformationMatrix*(*it)->transformation(); Matrix4 matrix = transformationMatrix*(*it)->transformation();

10
src/Scene.h

@ -24,10 +24,10 @@
namespace Magnum { namespace Magnum {
/** @brief Scene */ /** @brief Scene */
class Scene: public AbstractObject { class Scene: public Object {
private: private:
AbstractObject::setTransformation; Object::setParent;
AbstractObject::setParent; Object::setTransformation;
public: public:
/** @brief Features */ /** @brief Features */
@ -38,7 +38,7 @@ class Scene: public AbstractObject {
}; };
/** @brief Constructor */ /** @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); setClearColor(0.1f, 0.1f, 0.1f, 1.0f);
} }
@ -90,7 +90,7 @@ class Scene: public AbstractObject {
unsigned int viewportWidth, viewportHeight; unsigned int viewportWidth, viewportHeight;
inline virtual void draw(const Magnum::Matrix4& transformationMatrix, const Magnum::Matrix4& projectionMatrix) {} 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);
}; };
} }

2
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) magnum_add_test(CameraTest CameraTest.h CameraTest.cpp Magnum)

6
src/Test/AbstractObjectTest.cpp → src/Test/ObjectTest.cpp

@ -13,15 +13,15 @@
GNU Lesser General Public License version 3 for more details. GNU Lesser General Public License version 3 for more details.
*/ */
#include "AbstractObjectTest.h" #include "ObjectTest.h"
#include <QtTest/QTest> #include <QtTest/QTest>
QTEST_APPLESS_MAIN(Magnum::Test::AbstractObjectTest) QTEST_APPLESS_MAIN(Magnum::Test::ObjectTest)
namespace Magnum { namespace Test { namespace Magnum { namespace Test {
void AbstractObjectTest::parenting() { void ObjectTest::parenting() {
Object root; Object root;
Object* childOne = new Object(&root); Object* childOne = new Object(&root);

16
src/Test/AbstractObjectTest.h → src/Test/ObjectTest.h

@ -1,5 +1,5 @@
#ifndef Magnum_Test_AbstractObjectTest_h #ifndef Magnum_Test_ObjectTest_h
#define Magnum_Test_AbstractObjectTest_h #define Magnum_Test_ObjectTest_h
/* /*
Copyright © 2010 Vladimír Vondruš <mosra@centrum.cz> Copyright © 2010 Vladimír Vondruš <mosra@centrum.cz>
@ -17,19 +17,11 @@
#include <QtCore/QObject> #include <QtCore/QObject>
#include "AbstractObject.h" #include "Object.h"
namespace Magnum { namespace Test { namespace Magnum { namespace Test {
class Object: public AbstractObject { class ObjectTest: public QObject {
public:
inline Object(AbstractObject* parent = 0): AbstractObject(parent) {}
inline virtual void draw(const Magnum::Matrix4& transformationMatrix, const Magnum::Matrix4& projectionMatrix) {}
inline const std::set<AbstractObject*>& children() { return AbstractObject::children(); }
};
class AbstractObjectTest: public QObject {
Q_OBJECT Q_OBJECT
private slots: private slots:
Loading…
Cancel
Save