174 lines
3.1 KiB
C++
174 lines
3.1 KiB
C++
#include "SceneNode.h"
|
|
|
|
namespace BlueCore
|
|
{
|
|
|
|
#define DEBUG_SCENEGRAPH
|
|
|
|
SceneNode::SceneNode() :
|
|
Named("unnamed SceneNode"), _Parent(0)
|
|
{
|
|
#ifdef DEBUG_SCENEGRAPH
|
|
clog << "SceneNode 'Unnamed SceneNode' created." << endline;
|
|
#endif
|
|
}
|
|
|
|
SceneNode::SceneNode(const std::string &name) :
|
|
Named(name), _Parent(0)
|
|
{
|
|
#ifdef DEBUG_SCENEGRAPH
|
|
clog << "SceneNode '" << name << "' created." << endline;
|
|
#endif
|
|
}
|
|
|
|
SceneNode::~SceneNode()
|
|
{
|
|
detachAll();
|
|
|
|
#ifdef DEBUG_SCENEGRAPH
|
|
clog << "SceneNode '" << getName() << "' deleted." << endline;
|
|
#endif
|
|
}
|
|
|
|
void SceneNode::attach(SceneNode *node)
|
|
{
|
|
if (node == 0)
|
|
return;
|
|
|
|
_Children.push_back(node);
|
|
|
|
node->_Parent = this;
|
|
|
|
node->addReference();
|
|
|
|
#ifdef DEBUG_SCENEGRAPH
|
|
clog << "SceneNode '" << node->getName() << "' attached to '"
|
|
<< this->getName() << "'" << endline;
|
|
|
|
#endif
|
|
}
|
|
|
|
void SceneNode::detach(SceneNode *node)
|
|
{
|
|
node->_Parent = 0;
|
|
node->removeReference();
|
|
|
|
_Children.remove(node);
|
|
|
|
#ifdef DEBUG_SCENEGRAPH
|
|
clog << "SceneNode '" << node->getName() << "' detach from '"
|
|
<< this->getName() << "'" << endline;
|
|
#endif
|
|
}
|
|
|
|
void SceneNode::detachAll()
|
|
{
|
|
SceneNodeList::iterator i;
|
|
|
|
for (i = _Children.begin(); i != _Children.end(); i++)
|
|
{
|
|
( *i )->_Parent = 0;
|
|
( *i )->removeReference();
|
|
}
|
|
|
|
_Children.clear();
|
|
}
|
|
|
|
SceneNode *SceneNode::getParent() const
|
|
{
|
|
return _Parent;
|
|
}
|
|
|
|
void SceneNode::detachFromParent()
|
|
{
|
|
if (_Parent)
|
|
_Parent->detach( this);
|
|
}
|
|
|
|
const SceneNode::SceneNodeList& SceneNode::getChildren() const
|
|
{
|
|
return _Children;
|
|
}
|
|
|
|
void SceneNode::update(Scalar time)
|
|
{
|
|
updateAbsoluteTransformation();
|
|
|
|
// if (isActive() )
|
|
{
|
|
SceneNodeList::iterator i;
|
|
|
|
for (i = _Children.begin(); i != _Children.end(); i++)
|
|
( *i )->update(time);
|
|
}
|
|
}
|
|
|
|
void SceneNode::queue(RenderQueue *queue, Camera *camera)
|
|
{
|
|
if (isActive())
|
|
{
|
|
if (_Model.valid())
|
|
queue->addOpaqueItem(_Model, _AbsoluteTransformation.translation,
|
|
_AbsoluteTransformation.rotation);
|
|
|
|
SceneNodeList::iterator i;
|
|
for (i = _Children.begin(); i != _Children.end(); i++)
|
|
{
|
|
( *i )->queue(queue, camera);
|
|
}
|
|
}
|
|
}
|
|
|
|
const Transformation& SceneNode::getRelativeTransformation()
|
|
{
|
|
return _RelativeTransformation;
|
|
}
|
|
|
|
const Transformation& SceneNode::getAbsoluteTransformation()
|
|
{
|
|
return _AbsoluteTransformation;
|
|
}
|
|
|
|
void SceneNode::setRelativeTranslation(const Vector3 &translation)
|
|
{
|
|
_RelativeTransformation.translation = translation;
|
|
}
|
|
|
|
void SceneNode::setRelativeRotation(const Quaternion &rotation)
|
|
{
|
|
_RelativeTransformation.rotation = rotation;
|
|
}
|
|
|
|
void SceneNode::updateAbsoluteTransformation()
|
|
{
|
|
if (_Parent)
|
|
{
|
|
_AbsoluteTransformation.translation = _Parent->getAbsoluteTransformation().translation
|
|
+_Parent->getAbsoluteTransformation().rotation.inversed().apply(_RelativeTransformation.translation);
|
|
}
|
|
else
|
|
_AbsoluteTransformation.translation = _RelativeTransformation.translation;
|
|
}
|
|
|
|
void SceneNode::setRigidBody(RigidBody* body)
|
|
{
|
|
_RigidBody = body;
|
|
}
|
|
|
|
RigidBody* SceneNode::getRigidBody()
|
|
{
|
|
return _RigidBody.pointer();
|
|
}
|
|
|
|
void SceneNode::setModel(Model* model)
|
|
{
|
|
_Model = model;
|
|
}
|
|
|
|
Model* SceneNode::getModel()
|
|
{
|
|
return _Model.pointer();
|
|
}
|
|
|
|
} // namespace BlueCore
|