Pipeline graphique
 Tout Structures de données Espaces de nommage Fichiers Fonctions Variables Définitions de type Énumérations Valeurs énumérées Macros
addobject.cpp
Aller à la documentation de ce fichier.
1 #include "addobject.h"
2 
7 AddObject::AddObject(QVector<BaseObject*> *obj,QWidget *parent) : QDialog(parent)
8 {
9 
10  object = obj;
11  name_object = new QLabel("Fichier : ",this);
12  name_couleur= new QLabel("Couleur de lobject : ",this);
13  name_position = new QLabel("Position de l'object' : ",this);
14  name_echelle = new QLabel("Echele de l'object: ",this);
15  name_rotation = new QLabel("Rotation de l'object' : ",this);
16  name_luminositer = new QLabel("Parametre luminositer : ",this);
17 
18  m_Scale_x = new QDoubleSpinBox(this);
19  m_Scale_y = new QDoubleSpinBox(this);
20  m_Scale_z = new QDoubleSpinBox(this);
21 
22  m_Scale_x->setValue(1.0);
23  m_Scale_y->setValue(1.0);
24  m_Scale_z->setValue(1.0);
25 
26  m_rotate_x = new QDoubleSpinBox(this);
27  m_rotate_x->setValue(0);
28  m_rotate_y = new QDoubleSpinBox(this);
29  m_rotate_y->setValue(0);
30  m_rotate_z = new QDoubleSpinBox(this);
31  m_rotate_z->setValue(0);
32 
33  m_pos_x = new QDoubleSpinBox(this);
34  m_pos_x->setValue(0);
35  m_pos_x->setMinimum(-150);
36  m_pos_y = new QDoubleSpinBox(this);
37  m_pos_y->setValue(0);
38  m_pos_y->setMinimum(-150);
39  m_pos_z = new QDoubleSpinBox(this);
40  m_pos_z->setValue(0);
41  m_pos_z->setMinimum(-150);
42 
43 
44  m_color_r = new QSpinBox(this);
45  m_color_r->setValue(0);
46  m_color_g = new QSpinBox(this);
47  m_color_g->setValue(61);
48  m_color_b = new QSpinBox(this);
49  m_color_b->setValue(245);
50 
51  m_ks = new QDoubleSpinBox(this);
52  m_ks->setValue(0.5);
53  m_kd = new QDoubleSpinBox(this);
54  m_kd->setValue(0.5);
55  m_nd = new QSpinBox(this);
56  m_nd->setValue(30);
57 
58  m_OK = new QPushButton("Valider",this);
59  m_Anuller = new QPushButton("Annuller",this);
60 
61  m_openfile = new QPushButton("ouvrir",this);
62  m_chemin = new QLineEdit(this);
63 
64  connect(m_OK,SIGNAL(clicked()),this,SLOT(clickOK()));
65  connect(m_openfile,SIGNAL(clicked()),this,SLOT(clickgetPath()));
66  connect(m_Anuller,SIGNAL(clicked()),this,SLOT(close()));
67 
68 
69  QVBoxLayout *layoutglobal = new QVBoxLayout(this);
70  this->setLayout(layoutglobal);
71 
72  QHBoxLayout *layoutfichier = new QHBoxLayout();
73  layoutfichier->addWidget(m_chemin);
74  layoutfichier->addWidget(m_openfile);
75 
76  QHBoxLayout *layouttranslation = new QHBoxLayout();
77  layouttranslation->addWidget(m_pos_x);
78  layouttranslation->addWidget(m_pos_y);
79  layouttranslation->addWidget(m_pos_z);
80 
81  QHBoxLayout *layoutrotation = new QHBoxLayout();
82  layoutrotation->addWidget(m_rotate_x);
83  layoutrotation->addWidget(m_rotate_y);
84  layoutrotation->addWidget(m_rotate_z);
85 
86  QHBoxLayout *layoutscale = new QHBoxLayout();
87  layoutscale->addWidget(m_Scale_x);
88  layoutscale->addWidget(m_Scale_y);
89  layoutscale->addWidget(m_Scale_z);
90 
91  QHBoxLayout *layoutcolor = new QHBoxLayout();
92  layoutcolor->addWidget(m_color_r);
93  layoutcolor->addWidget(m_color_g);
94  layoutcolor->addWidget(m_color_b);
95 
96  QHBoxLayout *layoutlum = new QHBoxLayout();
97  layoutlum->addWidget(m_ks);
98  layoutlum->addWidget(m_kd);
99  layoutlum->addWidget(m_nd);
100 
101  QHBoxLayout *layoutbouton = new QHBoxLayout();
102  layoutbouton->addWidget(m_OK);
103  layoutbouton->addWidget(m_Anuller);
104 
105  layoutglobal->addWidget(name_object);
106  layoutglobal->addLayout(layoutfichier);
107 
108  layoutglobal->addWidget(name_position);
109  layoutglobal->addLayout(layouttranslation);
110 
111  layoutglobal->addWidget(name_rotation);
112  layoutglobal->addLayout(layoutrotation);
113 
114  layoutglobal->addWidget(name_echelle);
115  layoutglobal->addLayout(layoutscale);
116 
117  layoutglobal->addWidget(name_couleur);
118  layoutglobal->addLayout(layoutcolor);
119 
120  layoutglobal->addWidget(name_luminositer);
121  layoutglobal->addLayout(layoutlum);
122 
123  layoutglobal->addLayout(layoutbouton);
124 
125 }
131 {
132  delete name_object;
133  delete name_couleur;
134  delete name_position;
135  delete name_echelle;
136  delete name_rotation;
137  delete name_luminositer;
138  delete m_Scale_x;
139  delete m_Scale_y;
140  delete m_Scale_z;
141  delete m_rotate_x;
142  delete m_rotate_y;
143  delete m_rotate_z;
144  delete m_pos_x;
145  delete m_pos_y;
146  delete m_pos_z;
147  delete m_color_r;
148  delete m_color_g;
149  delete m_color_b;
150  delete m_ks;
151  delete m_kd;
152  delete m_nd;
153  delete m_OK;
154  delete m_openfile;
155  delete m_chemin;
156  delete m_Anuller;
157 }
163 {
164  QFileDialog fen(this,"Open PLY", QDir::currentPath(),"PLY Files (*.ply)");
165  fen.setWindowModality(Qt::ApplicationModal);
166 
167  m_chemin->setText(fen.getOpenFileName());
168 }
174 {
175  BaseObject *Obj = new BaseObject() ;
176 
177 
178 
179  if(Obj->LoadPLY(m_chemin->text().toStdString(),false) == false)
180  {
181  QMessageBox::warning(this, tr("Erreur"),"Erreur lors du chargement du fichier", QMessageBox::Ok);
182  return;
183  }
184  for(unsigned int i = 0; i < Obj->getNbInstance(); i++)
185  {
186  Math::matrice44 translation;
187  Math::matrice44 temps;
188  Math::matrice44 temps2;
189  Math::matrice44 rotate;
190  Math::matrice44 scale;
191 
192  translation.translate(m_pos_x->value(), m_pos_y->value(), m_pos_z->value());
193  scale.scale(m_Scale_x->value(),m_Scale_y->value(),m_Scale_z->value());
194 
195 
197  temps.rotationX(m_rotate_x->value());
198  temps2.rotationY(m_rotate_y->value());
199 
200  rotate.mul(temps,temps2);
201  temps2 =rotate;
202  temps.rotationZ(m_rotate_z->value());
203 
204  rotate.mul(temps2,temps);
205 
206  ObjectInstance &instance = Obj->getInstance(i);
207 
208  instance.world.mul(translation,rotate);
209 
210  temps = instance.world;
211  instance.world.mul(temps,scale);
212 
213  instance.world.view();
214 
215 
216  instance.material.kd = m_kd->value();
217  instance.material.ks = m_ks->value();
218  instance.material.ns = m_nd->value();
219  instance.material.col.r = m_color_r->value();
220  instance.material.col.g = m_color_g->value();
221  instance.material.col.b = m_color_b->value();
222  }
223 
224  object->append(Obj);
225  this->close();
226 }
void mul(matrice44 &M1, matrice44 &M2)
M.mul(M1,M2) multiplication de 2 matrices 4x4.
Definition: libMath.h:235
QDoubleSpinBox * m_Scale_z
Definition: addobject.h:43
void rotationZ(float th)
M.rotationZ(th), construit la matrice de transformation 4x4 associé à une rotation d'axe Z et d'angle...
Definition: libMath.h:279
void rotationY(float th)
M.rotationY(th), construit la matrice de transformation 4x4 associé à une rotation d'axe Y et d'angle...
Definition: libMath.h:277
void rotationX(float th)
M.rotationX(th), construit la matrice de transformation 4x4 associé à une rotation d'axe X et d'angle...
Definition: libMath.h:275
QDoubleSpinBox * m_pos_y
Definition: addobject.h:50
QDoubleSpinBox * m_rotate_z
Definition: addobject.h:47
unsigned char r
Definition: definition.h:61
QDoubleSpinBox * m_kd
Definition: addobject.h:58
QLabel * name_object
Definition: addobject.h:34
ObjectInstance & getInstance(unsigned int i)
Definition: Object.h:30
QDoubleSpinBox * m_rotate_x
Definition: addobject.h:45
QSpinBox * m_color_g
Definition: addobject.h:54
void clickgetPath()
AddObject::clickgetPath() C'est un Slot qui ouvre une fenetre afin de selectionner un fichier PLY...
Definition: addobject.cpp:162
void view()
M.view(), affichage de la matrice.
Definition: libMath.h:265
QLabel * name_position
Definition: addobject.h:36
unsigned int getNbInstance()
Definition: Object.h:36
QSpinBox * m_color_b
Definition: addobject.h:55
Material material
caractéristique du matériau de l'instance
Definition: Object.h:14
AddObject(QVector< BaseObject * > *obj, QWidget *parent=0)
AddObject::AddObject() Constructeur de la fenetre pour ajouter un object a la scene.
Definition: addobject.cpp:7
QLabel * name_couleur
Definition: addobject.h:35
QSpinBox * m_color_r
Definition: addobject.h:53
float ns
Definition: Material.h:10
QLabel * name_rotation
Definition: addobject.h:38
QPushButton * m_OK
Definition: addobject.h:61
float kd
coefficient de réflexion diffuse
Definition: Material.h:8
QDoubleSpinBox * m_Scale_y
Definition: addobject.h:42
QDoubleSpinBox * m_pos_z
Definition: addobject.h:51
Math::matrice44 world
matrice de transformation globale de l'instance
Definition: Object.h:15
unsigned char g
Definition: definition.h:61
QPushButton * m_Anuller
Definition: addobject.h:64
QDoubleSpinBox * m_ks
Definition: addobject.h:57
rgb col
couleur de l'objet
Definition: Material.h:7
bool LoadPLY(std::string PlyFilename, bool bInvertNormal=false)
BaseObject::LoadPLY(std::string PlyFilename, bool bInvertNormal) Charge un fichier PLY dans la memoir...
Definition: Object.cpp:112
~AddObject()
AddObject::~AddObject() Destructeur de la fenetre pour ajouter un object a la scene.
Definition: addobject.cpp:130
float ks
coefficient de réflexion spéculaire
Definition: Material.h:9
QLabel * name_luminositer
Definition: addobject.h:39
QDoubleSpinBox * m_rotate_y
Definition: addobject.h:46
QPushButton * m_openfile
Definition: addobject.h:62
QSpinBox * m_nd
Definition: addobject.h:59
QLineEdit * m_chemin
Definition: addobject.h:63
QDoubleSpinBox * m_Scale_x
Definition: addobject.h:41
unsigned char b
Definition: definition.h:61
void translate(vecteur3d v)
M.translate(V), construit la matrice de transformation 4x4 associée à une translation de vecteur V...
Definition: libMath.h:271
structure pour les matrices 4x4
Definition: libMath.h:209
void clickOK()
AddObject::clickOK() C'est un Slot qui crée un object et l'ajoute a la liste des object et pour finir...
Definition: addobject.cpp:173
QDoubleSpinBox * m_pos_x
Definition: addobject.h:49
QLabel * name_echelle
Definition: addobject.h:37
void scale(float a, float b, float c)
M.scale(a,b,c), construit une matrice de mise à l'échelle de facteur (a,b,c) respectivement pour les ...
Definition: libMath.h:267