delete shdata;
}
-void AnimatedObject::set_matrix(const Matrix &m)
-{
- matrix = m;
-}
-
void AnimatedObject::set_pose_matrix(unsigned link, const Matrix &m)
{
if(shdata)
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
{
};
private:
- Matrix matrix;
std::vector<float> pose_data;
ProgramData *shdata;
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 &);
#include <string>
#include "object.h"
-#include "renderable.h"
+#include "placeable.h"
namespace Msp {
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;
--- /dev/null
+#include "placeable.h"
+
+namespace Msp {
+namespace GL {
+
+void Placeable::set_matrix(const Matrix &m)
+{
+ matrix = m;
+}
+
+} // namespace GL
+} // namespace Msp
--- /dev/null
+#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