diff --git a/include/ientity.h b/include/ientity.h index 137e9e593c..a37e55159c 100644 --- a/include/ientity.h +++ b/include/ientity.h @@ -6,6 +6,7 @@ #include "irender.h" #include "inameobserver.h" #include "iscenegraph.h" +#include "itransformnode.h" #include #include "string/predicate.h" @@ -263,11 +264,17 @@ class Entity virtual void forEachAttachment(AttachmentFunc func) const = 0; }; -/// Interface for a INode subclass that contains an Entity -class IEntityNode : - public IRenderEntity, - public virtual scene::INode, - public scene::Cloneable +/** + * \brief Interface for a node which represents an entity. + * + * As well as providing access to the entity data with getEntity(), every + * IEntityNode can clone itself and apply a transformation matrix to its + * children (which might be brushes, patches or other entities). + */ +class IEntityNode : public IRenderEntity, + public virtual scene::INode, + public scene::Cloneable, + public IMatrixTransform { public: virtual ~IEntityNode() {} diff --git a/include/itransformnode.h b/include/itransformnode.h index 8490a96110..9b3a26b3a8 100644 --- a/include/itransformnode.h +++ b/include/itransformnode.h @@ -4,14 +4,14 @@ class Matrix4; -/// \brief A transform node. +/// A node which can transform the coordinate space of its children class ITransformNode { public: virtual ~ITransformNode() {} /// \brief Returns the transform which maps the node's local-space into the local-space of its parent node. - virtual const Matrix4& localToParent() const = 0; + virtual const Matrix4& localToParent() const = 0; }; typedef std::shared_ptr ITransformNodePtr; @@ -19,3 +19,12 @@ inline ITransformNodePtr Node_getTransformNode(const scene::INodePtr& node) { return std::dynamic_pointer_cast(node); } + +/// An ITransformNode which can provide non-const access to its transform matrix +class IMatrixTransform: public ITransformNode +{ +public: + + /// Return a modifiable reference to a contained transformation matrix + virtual Matrix4& localToParent() = 0; +}; \ No newline at end of file diff --git a/libs/transformlib.h b/libs/transformlib.h index 5b18204811..829dc8fbb2 100644 --- a/libs/transformlib.h +++ b/libs/transformlib.h @@ -17,28 +17,6 @@ class IdentityTransform : } }; -/// \brief A transform node which stores a generic transformation matrix. -class MatrixTransform : - public ITransformNode -{ - Matrix4 _localToParent; -public: - MatrixTransform() : - _localToParent(Matrix4::getIdentity()) - {} - - Matrix4& localToParent() - { - return _localToParent; - } - - /// \brief Returns the stored local->parent transform. - const Matrix4& localToParent() const - { - return _localToParent; - } -}; - namespace scene { diff --git a/radiantcore/entity/EntityNode.cpp b/radiantcore/entity/EntityNode.cpp index 5efc70ca40..5f44b050a2 100644 --- a/radiantcore/entity/EntityNode.cpp +++ b/radiantcore/entity/EntityNode.cpp @@ -32,9 +32,9 @@ EntityNode::EntityNode(const EntityNode& other) : Namespaced(other), TargetableNode(_spawnArgs, *this), Transformable(other), - MatrixTransform(other), _eclass(other._eclass), _spawnArgs(other._spawnArgs), + _localToParent(other._localToParent), _namespaceManager(_spawnArgs), _nameKey(_spawnArgs), _renderableName(_nameKey), @@ -143,8 +143,7 @@ void EntityNode::createAttachedEntities() // Set the attached entity's transform matrix according to the // required offset - MatrixTransform& mt = dynamic_cast(*attachedEnt); - mt.localToParent() = Matrix4::getTranslation(a.offset); + attachedEnt->localToParent() = Matrix4::getTranslation(a.offset); } ); } diff --git a/radiantcore/entity/EntityNode.h b/radiantcore/entity/EntityNode.h index eda54d010b..d2f846b64e 100644 --- a/radiantcore/entity/EntityNode.h +++ b/radiantcore/entity/EntityNode.h @@ -32,8 +32,7 @@ class EntityNode : public SelectionTestable, public Namespaced, public TargetableNode, - public Transformable, - public MatrixTransform // influences local2world of child nodes + public Transformable { protected: // The entity class @@ -42,6 +41,9 @@ class EntityNode : // The actual entity (which contains the key/value pairs) SpawnArgs _spawnArgs; + // Transformation applied to this node and its children + Matrix4 _localToParent = Matrix4::getIdentity(); + // The class taking care of all the namespace-relevant stuff NamespaceManager _namespaceManager; @@ -106,6 +108,10 @@ class EntityNode : virtual float getShaderParm(int parmNum) const override; virtual const Vector3& getDirection() const override; + // IMatrixTransform implementation + const Matrix4& localToParent() const override { return _localToParent; } + Matrix4& localToParent() override { return _localToParent; } + // SelectionTestable implementation virtual void testSelect(Selector& selector, SelectionTest& test) override;