From: Mikko Rasa Date: Wed, 8 Nov 2017 06:42:24 +0000 (+0200) Subject: Add a new Placeable base class X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=00d926c3fe134820139a925cfac28cd64729db93;p=libs%2Fgl.git Add a new Placeable base class --- diff --git a/source/animatedobject.cpp b/source/animatedobject.cpp index 269665f6..d2157fd1 100644 --- a/source/animatedobject.cpp +++ b/source/animatedobject.cpp @@ -26,11 +26,6 @@ AnimatedObject::~AnimatedObject() delete shdata; } -void AnimatedObject::set_matrix(const Matrix &m) -{ - matrix = m; -} - void AnimatedObject::set_pose_matrix(unsigned link, const Matrix &m) { if(shdata) diff --git a/source/animatedobject.h b/source/animatedobject.h index b7f48005..23333ee5 100644 --- a/source/animatedobject.h +++ b/source/animatedobject.h @@ -11,8 +11,7 @@ namespace Msp { namespace GL { /** -An object instance that can be animated. Despite the name, this can also be -useful for displaying objects at a static position. +An object instance that can be animated by an AnimationPlayer. */ class AnimatedObject: public ObjectInstance { @@ -30,7 +29,6 @@ public: }; private: - Matrix matrix; std::vector pose_data; ProgramData *shdata; @@ -38,7 +36,6 @@ public: AnimatedObject(const Object &); ~AnimatedObject(); - void set_matrix(const Matrix &); void set_pose_matrix(unsigned, const Matrix &); void set_uniform(const std::string &, const KeyFrame::AnimatedUniform &); diff --git a/source/objectinstance.h b/source/objectinstance.h index 6a874976..273d3485 100644 --- a/source/objectinstance.h +++ b/source/objectinstance.h @@ -3,7 +3,7 @@ #include #include "object.h" -#include "renderable.h" +#include "placeable.h" namespace Msp { namespace GL { @@ -11,14 +11,14 @@ namespace GL { class ProgramData; /** -Represents a single instance of an Object. A derived class can overload the -hook functions to specify a model matrix and other instance-specific parameters -for the rendered objects. +Represents a single instance of an Object. Thanks to being derived from +Placeable in can be positioned without additional effort. Other instance +parameters can be set by overriding the hook functions. ObjectInstances can benefit from being put in an InstanceScene, which will render all instances of the same object consecutively. */ -class ObjectInstance: public Renderable +class ObjectInstance: public PlacedRenderable { protected: const Object &object; diff --git a/source/placeable.cpp b/source/placeable.cpp new file mode 100644 index 00000000..c7ea7920 --- /dev/null +++ b/source/placeable.cpp @@ -0,0 +1,12 @@ +#include "placeable.h" + +namespace Msp { +namespace GL { + +void Placeable::set_matrix(const Matrix &m) +{ + matrix = m; +} + +} // namespace GL +} // namespace Msp diff --git a/source/placeable.h b/source/placeable.h new file mode 100644 index 00000000..2879f975 --- /dev/null +++ b/source/placeable.h @@ -0,0 +1,43 @@ +#ifndef MSP_GL_PLACEABLE_H_ +#define MSP_GL_PLACEABLE_H_ + +#include "matrix.h" +#include "renderable.h" + +namespace Msp { +namespace GL { + +/** +A base class for things that can be positioned and oriented in 3D space. +*/ +class Placeable +{ +protected: + Matrix matrix; + + Placeable() { } + +public: + virtual void set_matrix(const Matrix &); + + /** Returns the Placeable's matrix. This function returns a pointer for + compatibility with Renderable. The returned pointer is never null. */ + virtual const Matrix *get_matrix() const { return &matrix; } +}; + + +class PlacedRenderable: public Renderable, public Placeable +{ +protected: + PlacedRenderable() { } + +public: + /* Reimplement to clear ambiguity between Renderable and Placeable. This + overrides both base classes' implementations. */ + virtual const Matrix *get_matrix() const { return &matrix; } +}; + +} // namespace GL +} // namespace Msp + +#endif