-
Notifications
You must be signed in to change notification settings - Fork 0
/
scene.h
59 lines (55 loc) · 1.54 KB
/
scene.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
//
// Created by Lenovo on 2022/4/26.
//
#ifndef JRENDERENGINE_INCLUDE_SCENE_H_
#define JRENDERENGINE_INCLUDE_SCENE_H_
#include "transform.h"
#include <memory>
#include <vector>
#include <string>
#include <map>
using namespace std;
class SceneObject{
private:
string name;
Transform transform_;
vector<SceneObject*> children_;
SceneObject* parent_= nullptr;
map<type_info,vector<void *>> components_;
public:
SceneObject() = default;
~SceneObject() = default;
SceneObject(const string &name);
void SetLocalTranslation(glm::vec3 translation);
void SetLocalRotation(glm::vec3 rotation);
void SetLocalScale(glm::vec3 scale);
void SetParent(SceneObject* parent);
void AddChild(SceneObject* child);
[[nodiscard]] const glm::mat4 &GetWorldTransform() const;
template<class T> T& GetComponent(){
if(components_.find(typeid(T))!=components_.end() && !components_[typeid(T)].empty()){
return static_pointer_cast<T&>(components_[typeid(T)][0]);
}else{
return nullptr;
}
}
template<class T> vector<void *> GetComponents(){
if(components_.find(typeid(T))!=components_.end() && !components_[typeid(T)].empty()){
return components_[typeid(T)];
}else{
return {};
}
}
template<class T> void AddComponent(T& component){
if(components_.find(typeid(T))!=components_.end()){
components_[typeid(T)].push_back(component);
}else{
vector<T&> v;v.push_back(component);
components_[typeid(T)] = v;
}
}
};
class Scene {
SceneObject root;
};
#endif //JRENDERENGINE_INCLUDE_SCENE_H_