-
Notifications
You must be signed in to change notification settings - Fork 1
/
SingleObject.cpp
137 lines (109 loc) · 4.07 KB
/
SingleObject.cpp
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/*
* File: SingleObjet.cpp
* Author: Aztyu
*
* Created on 22 décembre 2014, 15:06
*/
#include "SingleObject.h"
#include "GroupObject.h"
using namespace std;
SingleObject::SingleObject(irr::scene::ISceneNode* obj, const char* name, irr::scene::ISceneNode* parent, object type): Object(obj, name, parent){
this->parent = NULL;
this->type = type;
}
SingleObject::SingleObject(irr::scene::ISceneNode* obj, const char* name, irr::scene::ISceneNode* parent, float total_scale, object type) : Object(obj, name, parent, total_scale) {
this->parent = NULL;
this->type = type;
}
SingleObject::SingleObject(irr::scene::ISceneNode* obj, const char* name, irr::scene::ISceneNode* parent, irr::core::vector3df position, object type) : Object(obj, name, parent, position){
this->parent = NULL;
this->type = type;
}
SingleObject::~SingleObject() {
if(parent != NULL){
static_cast<GroupObject*>(parent)->removeMember();
}
cout << "Object deleted" << endl;
}
void SingleObject::selectObject() {
this->objet->getMaterial(0).EmissiveColor = irr::video::SColor(255, 213, 228, 56);
}
void SingleObject::groupSelectObject() {
this->objet->getMaterial(0).EmissiveColor = irr::video::SColor(255, 248, 158, 37);
}
void SingleObject::unselectObject() {
this->objet->getMaterial(0).EmissiveColor = 0;
}
void SingleObject::exportObject(TiXmlElement* windows) {
TiXmlElement * window;
window = new TiXmlElement( "Object" );
windows->LinkEndChild( window );
window->SetAttribute("name", this->getName().c_str());
window->SetAttribute("type", this->getType());
TiXmlElement * position;
position = new TiXmlElement( "position" );
window->LinkEndChild( position );
irr::core::vector3df position_vector = this->getPosition();
position->SetDoubleAttribute("x", position_vector.X);
position->SetDoubleAttribute("y", position_vector.Y);
position->SetDoubleAttribute("z", position_vector.Z);
TiXmlElement * rotation;
rotation = new TiXmlElement( "rotation" );
window->LinkEndChild( rotation );
irr::core::vector3df rotation_vector = this->getRotation();
rotation->SetDoubleAttribute("x", rotation_vector.X);
rotation->SetDoubleAttribute("y", rotation_vector.Y);
rotation->SetDoubleAttribute("z", rotation_vector.Z);
TiXmlElement * scale;
scale = new TiXmlElement( "scale" );
window->LinkEndChild( scale );
irr::core::vector3df scale_vector = this->getScale();
scale->SetDoubleAttribute("x", scale_vector.X);
scale->SetDoubleAttribute("y", scale_vector.Y);
scale->SetDoubleAttribute("z", scale_vector.Z);
}
void SingleObject::setParent(Object* new_parent){
if(new_parent == NULL){
if(this->parent != NULL){
irr::core::matrix4 transformation = this->getSceneNode()->getAbsoluteTransformation();
GroupObject* old_parent = static_cast<GroupObject*>(this->parent);
this->objet->setParent(this->default_parent);
this->parent = NULL;
this->setPosition(transformation.getTranslation()); //Garde la position actuelle de l'objet lors du chamgement de parent
this->setRotation(transformation.getRotationDegrees()); //Garde la rotation actuelle de l'objet lors du changement de parent
this->modifyScaleBy(old_parent->getScale());
}else{
this->objet->setParent(this->default_parent);
this->parent = NULL;
}
}else{
objet->setParent(new_parent->getSceneNode());
this->parent = new_parent;
}
}
bool SingleObject::hasParent() {
return this->parent != NULL;
}
SingleObject* SingleObject::getPointer(){
return this;
}
object SingleObject::getType() {
return this->type;
}
std::string SingleObject::getClassType() {
return "SingleObject";
}
Object* SingleObject::getParent() {
if(hasParent()){
return this->parent;
}else{
return NULL;
}
}
void SingleObject::Remove() {
this->objet->remove();
this->objet = NULL;
}
bool SingleObject::isInGroup() {
return this->parent != NULL;
}