77 lines
1.7 KiB
C++
77 lines
1.7 KiB
C++
#pragma once
|
|
|
|
#include "entities/Component.h"
|
|
//#include "entities/Entity.h"
|
|
#include "utils/Transform.h"
|
|
|
|
|
|
#include <osgEarth/GeoTransform>
|
|
|
|
#include "osg/Vec3"
|
|
#include "osg/MatrixTransform"
|
|
|
|
class SceneComponent : public Component {
|
|
Q_OBJECT
|
|
|
|
public:
|
|
explicit SceneComponent(SceneComponent* parent = nullptr);
|
|
~SceneComponent();
|
|
|
|
std::vector<class SceneComponent*> GetChildren() const;
|
|
void AttachEntity(class Entity* owner) override;
|
|
bool SetAttribute(const char* name, const char* value) override;
|
|
bool SaveAttribute(tinyxml2::XMLElement* element) override;
|
|
void Begin() override;
|
|
void Update(double dt) override;
|
|
void End() override;
|
|
|
|
bool OnDestroy() override;
|
|
bool AttachTo(SceneComponent* parent) override;
|
|
|
|
virtual void AddToRender();
|
|
|
|
SceneComponent* GetRootComponent() const;
|
|
|
|
template<class T>
|
|
T* GetComponent() {
|
|
for (auto& componet : childer_) {
|
|
if (componet->GetTypeName() == T::GetTypeName()) {
|
|
return reinterpret_cast<T*>(componet);
|
|
}
|
|
}
|
|
return nullptr;
|
|
}
|
|
|
|
osg::MatrixTransform* GetMatrixTransform() const {
|
|
return geo_.valid() ? geo_.get() : mt_.get();
|
|
}
|
|
const Transform* GetTransform() const {
|
|
return &transform_;
|
|
}
|
|
Transform* GetTransform() {
|
|
return &transform_;
|
|
}
|
|
void SetLocation(const osg::Vec3& location);
|
|
const osg::Vec3& GetLocation() const;
|
|
|
|
void AttachScene(class Entity* entity);
|
|
void AttachParent(class Entity* entity);
|
|
void AttachParent(SceneComponent* parent);
|
|
void UpdateLocationAndRotation();
|
|
|
|
protected:
|
|
void RemoveRender();
|
|
void RemoveParent();
|
|
|
|
protected:
|
|
SceneComponent* parent_{ nullptr };
|
|
std::vector<SceneComponent*> children_;
|
|
osg::ref_ptr<osg::MatrixTransform> mt_;
|
|
|
|
#ifndef USE_OCEAN
|
|
osg::ref_ptr<osgEarth::GeoTransform> geo_{nullptr};
|
|
#endif
|
|
|
|
protected:
|
|
Transform transform_;
|
|
}; |