#ifndef TRANSFORM_HPP
#define TRANSFORM_HPP
#include <vector>
#include "TransformNode.hpp"
namespace wren {
class Transform : public TransformNode {
public:
static Transform *createTransform() { return new Transform(); }
static Transform *copyTransform(Transform *source) { return new Transform(source); }
void attachChild(Node *child);
void detachChild(Node *child);
const std::vector<Node *> &children() const { return mChildren; }
void updateFromParent() override {
if (isVisible()) {
for (Node *n : mChildren)
n->updateFromParent();
}
}
int computeChildCount() const override;
void setMatrixDirty() const override {
TransformNode::setMatrixDirty();
for (Node *n : mChildren)
n->setMatrixDirty();
}
protected:
Transform();
explicit Transform(Transform *source);
virtual ~Transform();
private:
void recomputeAabb() const override {
if (mChildren.size()) {
std::vector<primitive::Aabb> aabbs;
aabbs.reserve(mChildren.size());
for (Node *child : mChildren)
aabbs.push_back(child->aabb());
mAabb = primitive::Aabb(aabbs);
} else
mAabb = primitive::Aabb(position(), position());
}
void recomputeBoundingSphere() const override {
if (mChildren.size()) {
std::vector<primitive::Sphere> spheres;
spheres.reserve(mChildren.size());
for (Node *child : mChildren)
spheres.push_back(child->boundingSphere());
mBoundingSphere = primitive::mergeBoundingSpheres(spheres);
} else
mBoundingSphere = primitive::Sphere(position(), 0.0f);
}
std::vector<Node *> mChildren;
};
}
#endif