-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgrafo-escena.cpp
1055 lines (881 loc) · 27.6 KB
/
grafo-escena.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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// *********************************************************************
// **
// ** Gestión de una grafo de escena (implementación)
// ** Copyright (C) 2016 Carlos Ureña
// **
// ** This program is free software: you can redistribute it and/or modify
// ** it under the terms of the GNU General Public License as published by
// ** the Free Software Foundation, either version 3 of the License, or
// ** (at your option) any later version.
// **
// ** This program is distributed in the hope that it will be useful,
// ** but WITHOUT ANY WARRANTY; without even the implied warranty of
// ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// ** GNU General Public License for more details.
// **
// ** You should have received a copy of the GNU General Public License
// ** along with this program. If not, see <http://www.gnu.org/licenses/>.
// **
// *********************************************************************
#include "aux.hpp"
#include "matrices-tr.hpp"
#include "shaders.hpp"
#include "grafo-escena.hpp"
#include "materiales.hpp"
using namespace std ;
// *********************************************************************
// Entrada del nodo del Grafo de Escena
// ---------------------------------------------------------------------
// Constructor para entrada de tipo sub-objeto
EntradaNGE::EntradaNGE( Objeto3D * pObjeto )
{
assert( pObjeto != NULL );
tipo = TipoEntNGE::objeto ;
objeto = pObjeto ;
}
// ---------------------------------------------------------------------
// Constructor para entrada de tipo "matriz de transformación"
EntradaNGE::EntradaNGE( const Matriz4f & pMatriz )
{
tipo = TipoEntNGE::transformacion ;
matriz = new Matriz4f() ; // matriz en el heap, puntero propietario
*matriz = pMatriz;
}
// ---------------------------------------------------------------------
// Constructor para entrada de tipo "matriz de transformación"
EntradaNGE::EntradaNGE( Material * pMaterial )
{
assert( pMaterial != NULL );
tipo = TipoEntNGE::material ;
material = pMaterial ;
}
// -----------------------------------------------------------------------------
// Destructor de una entrada
EntradaNGE::~EntradaNGE()
{
/** no fnciona debido a que se hacen copias (duplicados) de punteros
if ( tipo == TipoEntNGE::transformacion )
{
assert( matriz != NULL );
delete matriz ;
matriz = NULL ;
}
* **/
}
// *****************************************************************************
// Nodo del grafo de escena: contiene una lista de entradas
// *****************************************************************************
// -----------------------------------------------------------------------------
// Visualiza usando OpenGL
void NodoGrafoEscena::visualizarGL( ContextoVis & cv )
{
glMatrixMode (GL_MODELVIEW);
glPushMatrix ();
// Guardamos el material activo anterior
cv.pilaMateriales.push();
for (unsigned i = 0; i < entradas.size(); i++)
switch (entradas[i].tipo) {
case TipoEntNGE::objeto:
if (cv.modoSeleccionFBO && leerIdentificador() >= 0) {
FijarColorIdent(leerIdentificador());
}
entradas[i].objeto->visualizarGL (cv);
break;
case TipoEntNGE::transformacion:
glMatrixMode (GL_MODELVIEW);
glMultMatrixf (*(entradas[i].matriz));
break;
case TipoEntNGE::material:
if(!cv.modoSeleccionFBO)
cv.pilaMateriales.activarMaterial(entradas[i].material);
break;
default:
std::cout << "Tipo no conocido" << std::endl;
}
// Restauramos el material activo anterior y lo activamos (pop lo hace todo)
cv.pilaMateriales.pop();
glMatrixMode (GL_MODELVIEW);
glPopMatrix();
}
// -----------------------------------------------------------------------------
NodoGrafoEscena::NodoGrafoEscena()
{
ponerNombre("Nodo escena anónimo");
}
// -----------------------------------------------------------------------------
void NodoGrafoEscena::fijarColorNodo( const Tupla3f & nuevo_color )
{
for(auto e : entradas){
if(e.tipo == TipoEntNGE::objeto)
e.objeto->fijarColorNodo(nuevo_color);
}
}
// -----------------------------------------------------------------------------
// Añadir una entrada (al final).
// genérica
unsigned NodoGrafoEscena::agregar( const EntradaNGE & entrada )
{
entradas.push_back(entrada);
return entradas.size()-1;
}
// -----------------------------------------------------------------------------
// construir una entrada y añadirla (al final)
// objeto (copia solo puntero)
unsigned NodoGrafoEscena::agregar( Objeto3D * pObjeto )
{
return agregar( EntradaNGE( pObjeto ) );
}
// ---------------------------------------------------------------------
// construir una entrada y añadirla (al final)
// matriz (copia objeto)
unsigned NodoGrafoEscena::agregar( const Matriz4f & pMatriz )
{
return agregar( EntradaNGE( pMatriz ) );
}
// ---------------------------------------------------------------------
// material (copia solo puntero)
unsigned NodoGrafoEscena::agregar( Material * pMaterial )
{
return agregar( EntradaNGE( pMaterial ) );
}
// devuelve el puntero a la matriz en la i-ésima entrada
Matriz4f* NodoGrafoEscena::leerPtrMatriz( unsigned indice )
{
assert(entradas[indice].tipo == TipoEntNGE::transformacion);
return entradas[indice].matriz;
}
// -----------------------------------------------------------------------------
// si 'centro_calculado' es 'false', recalcula el centro usando los centros
// de los hijos (el punto medio de la caja englobante de los centros de hijos)
void NodoGrafoEscena::calcularCentroOC()
{
// DONE: práctica 5: calcular y guardar el centro del nodo
// en coordenadas de objeto (hay que hacerlo recursivamente)
// (si el centro ya ha sido calculado, no volver a hacerlo)
// ........
Matriz4f cumulative_transformation_m = MAT_Ident();
std::vector<Tupla3f> centros;
if (!centro_calculado){
for (auto entrada : entradas){
switch(entrada.tipo) {
case TipoEntNGE::objeto:
centros.push_back(cumulative_transformation_m * entrada.objeto->leerCentroOC());
break;
case TipoEntNGE::transformacion:
cumulative_transformation_m = cumulative_transformation_m * (*entrada.matriz);
break;
default:
break;
}
}
}
ponerCentroOC(calcularCentroCajaEnglobante(centros));
centro_calculado = true;
}
// -----------------------------------------------------------------------------
// método para buscar un objeto con un identificador y devolver un puntero al mismo
bool NodoGrafoEscena::buscarObjeto
(
const int ident_busc, // identificador a buscar
const Matriz4f & mmodelado, // matriz de modelado
Objeto3D ** objeto, // (salida) puntero al puntero al objeto
Tupla3f & centro_wc // (salida) centro del objeto en coordenadas del mundo
)
{
// DONE: práctica 5: buscar un sub-objeto con un identificador
// ........
if (ident_busc == leerIdentificador()){
*objeto = this;
centro_wc = mmodelado*leerCentroOC();
return true;
}
Matriz4f nueva_mmodelado = mmodelado;
// TEST
unsigned counter = 0;
for (auto &entrada: entradas){
switch(entrada.tipo) {
case TipoEntNGE::objeto:
if (entrada.objeto->buscarObjeto(ident_busc, nueva_mmodelado, objeto, centro_wc)){
return true;
}
break;
case TipoEntNGE::transformacion:
nueva_mmodelado = nueva_mmodelado * (*entrada.matriz);
break;
default:
break;
}
}
return false;
}
// *****************************************************************************
// Nodo del grafo de escena, con una lista añadida de parámetros
// *****************************************************************************
// -----------------------------------------------------------------------------
// devuelve el numero de grados de libertad
int NodoGrafoEscenaParam::numParametros()
{
return parametros.size();
}
// -----------------------------------------------------------------------------
// devuelve un puntero al i-ésimo grado de libertad
Parametro * NodoGrafoEscenaParam::leerPtrParametro( unsigned i )
{
return ¶metros[i];
}
// -----------------------------------------------------------------------------
void NodoGrafoEscenaParam::siguienteCuadro()
{
for (auto& param: parametros)
param.siguiente_cuadro();
}
//------------------------------------------------------------------------------
Grua::Grua(){
int i;
agregar(new Palo1);
//Palo horizontal
agregar(MAT_Traslacion(21,0,0));
agregar(MAT_Traslacion(0,126,0));
agregar(MAT_Rotacion(90,0,0,1));
//Matriz parametro prueba
i = agregar(MAT_Ident());
agregar(new Palo2);
//Parámetro de prueba
Parametro param(
"parametro de prueba",
leerPtrMatriz(i),
[=] (float v) {return MAT_Rotacion(v, 1, 0, 0);},
false,
0.0,
10.0,
4
);
parametros.push_back(param);
}
Grua::Palo2::Palo2() : Palo1(){
agregar (new Trozo2);
}
Grua::Palo2::Trozo2::Trozo2(){
agregar (MAT_Escalado(1,7,1));
agregar (new Cubo);
agregar (MAT_Traslacion(0,0,6));
agregar (new Cubo);
agregar (MAT_Traslacion(0,0,-6));
agregar (MAT_Escalado(1,(float)1/7,7));
agregar (MAT_Traslacion(0,6,0));
agregar (new Cubo);
}
Grua::Palo1::Palo1(){
Trozo1* t1 = new Trozo1;
Matriz4f m = MAT_Traslacion(0,7,0);
for (int i = 0; i < 20; ++i) {
agregar(t1);
agregar(m);
}
}
Grua::Palo1::Trozo1::Trozo1(){
agregar(new Pilares);
agregar(new Tapa1);
agregar(new Tapa2);
}
Grua::Palo1::Trozo1::Pilares::Pilares(){
Matriz4f m = MAT_Escalado(1,7,1);
EntradaNGE mat = EntradaNGE(m);
Cubo* c = new Cubo();
EntradaNGE cub = EntradaNGE(c);
agregar(mat);
agregar(cub);
agregar(MAT_Traslacion(6,0,0));
agregar(cub);
agregar(MAT_Traslacion(0,0,6));
agregar(cub);
agregar(MAT_Traslacion(-6,0,0));
agregar(cub);
}
Grua::Palo1::Trozo1::Tapa1::Tapa1(){
Cubo* c = new Cubo();
agregar(MAT_Traslacion(0,0,1));
agregar(MAT_Escalado(1,1,5));
agregar(c);
agregar(MAT_Traslacion(6,0,0));
agregar(c);
agregar(MAT_Traslacion(0,6,0));
agregar(c);
agregar(MAT_Traslacion(-6,0,0));
agregar(c);
}
Grua::Palo1::Trozo1::Tapa2::Tapa2(){
Cubo* c = new Cubo();
agregar(MAT_Traslacion(1,0,0));
agregar(MAT_Escalado(5,1,1));
agregar(c);
agregar(MAT_Traslacion(0,0,6));
agregar(c);
agregar(MAT_Traslacion(0,6,0));
agregar(c);
agregar(MAT_Traslacion(0,0,-6));
agregar(c);
}
Muneco::Muneco(){
Tupla3f color = {(float)229/255, (float)235/255, (float)25/255};
Cilindro* c = new Cilindro(
2,
20,
true,
true,
false
);
Esfera* e = new Esfera(
20,
20,
false,
true,
false
);
Cola* cola = new Cola();
Brazo* br1 = new Brazo;
Brazo* br2 = new Brazo;
Ojo* ojo = new Ojo();
//Fijar Color
c->fijarColorNodo(color);
e->fijarColorNodo(color);
cola->fijarColorNodo(color);
br1->fijarColorNodo(color);
br2->fijarColorNodo(color);
/* int i_rot_principal = agregar(MAT_Ident()); */
agregar(MAT_Escalado(1,2,1));
// Primer cilindro del cuerpo
agregar(c);
agregar(MAT_Traslacion(0,1,0));
// Cola
agregar(MAT_Escalado(1, 1.0/2, 1));
agregar(cola);
agregar(MAT_Escalado(1, 2, 1));
// Esfera de articulación y rotación
agregar(e);
int i_rotacion1 = agregar(MAT_Ident());
// Segundo cilindro del cuerpo
agregar(c);
agregar(MAT_Traslacion(0,1,0));
// Esfera de articulación y rotación
agregar(e);
int i_rotacion2 = agregar(MAT_Ident());
// Tercer cilindro del cuerpo
agregar(c);
agregar(MAT_Traslacion(0, 1.5, 0));
// Brazo izq
agregar(br1);
// Brazo der
agregar(MAT_Escalado(-1, 1, 1));
agregar(br2);
agregar(MAT_Escalado(-1, 1, 1));
agregar(MAT_Traslacion(0, -0.5, 0));
// Esfera de articulación y rotación
agregar(e);
int i_rotacion3 = agregar(MAT_Ident());
// Cilindro cabeza
agregar(c);
// Ojos
agregar(MAT_Traslacion(-0.3, 0.7, 1));
agregar(MAT_Escalado(1, 0.5, 1));
agregar(ojo);
agregar(MAT_Traslacion(0.6, 0, 0));
agregar(ojo);
agregar(MAT_Escalado(1, 2, 1));
agregar(MAT_Traslacion(-0.3, -0.7, -1));
//Rotación 1
Parametro rotacion1(
"Rotacion primera articulación del cuerpo",
leerPtrMatriz(i_rotacion1),
[=] (float v) {return MAT_Rotacion(v, 0, 0, 1);},
true,
0,
10,
0.1
);
//Rotación 2
Parametro rotacion2(
"Rotacion segunda articulación del cuerpo",
leerPtrMatriz(i_rotacion2),
[=] (float v) {return MAT_Rotacion(v, 0, 0, 1);},
true,
0,
10.0,
0.1
);
//Rotación 3
Parametro rotacion3(
"Rotacion tercera articulación del cuerpo",
leerPtrMatriz(i_rotacion3),
[=] (float v) {return MAT_Rotacion(v, 0, 0, 1);},
true,
0,
10.0,
0.1
);
//Rotación hombro brazo 1
Parametro rotacion_hombro1(
"Rotacion hombro brazo 1",
br1->getArticulacionHombro(),
[=] (float v) {return MAT_Rotacion(v, 0, 1, 0);},
true,
0,
30,
0.1
);
//Rotación hombro brazo 2
Parametro rotacion_hombro2(
"Rotacion hombro brazo 2",
br2->getArticulacionHombro(),
[=] (float v) {return MAT_Rotacion(v, 0, 1, 0);},
true,
0,
50,
0.1
);
// Rotación codo brazo 1
Parametro rotacion_codo1(
"Rotacion codo brazo 1",
br1->getArticulacionCodo(),
[=] (float v) {return MAT_Rotacion(v, 0, 0, 1);},
true,
-10,
90,
0.1
);
//Rotación codo brazo 2
Parametro rotacion_codo2(
"Rotacion codo brazo 2",
br2->getArticulacionCodo(),
[=] (float v) {return MAT_Rotacion(v, 0, 0, 1);},
true,
-20,
80,
0.1
);
for (int i = 0; i < cola->numArticulaciones(); ++i) {
Parametro movimiento_cola(
"Movimiento " + std::to_string(i) + "a articulación de la cola",
cola->getArticulacion(i),
[=] (float v) {return MAT_Rotacion(v, 0, 0, 1);},
true,
0,
45,
0.1
);
parametros.push_back(movimiento_cola);
}
/* parametros.push_back(rot_principal); */
parametros.push_back(rotacion1);
parametros.push_back(rotacion2);
parametros.push_back(rotacion3);
parametros.push_back(rotacion_hombro1);
parametros.push_back(rotacion_hombro2);
parametros.push_back(rotacion_codo1);
parametros.push_back(rotacion_codo2);
}
Muneco::Brazo::Brazo(){
Cilindro* c = new Cilindro(2, 20, true, true, false);
Esfera* e = new Esfera(20, 20, false, true, false);
agregar(MAT_Traslacion(-1, -0.5, 0));
indice_hombro = agregar(MAT_Ident()); // Articulación hombro
agregar(MAT_Rotacion(75, 0, 0, 1));
agregar(MAT_Escalado(0.25, 1, 0.25));
agregar(e);
agregar(c);
agregar(MAT_Traslacion(0, 1, 0));
agregar(c);
agregar(MAT_Traslacion(0, 1, 0));
indice_codo = agregar(MAT_Ident()); // Articulación codo
agregar(e);
agregar(c);
agregar(MAT_Traslacion(0, 1, 0));
agregar(c);
agregar(MAT_Traslacion(0, 1, 0));
agregar(c);
}
Matriz4f* Muneco::Brazo::getArticulacionHombro(){
return leerPtrMatriz(indice_hombro);
}
Matriz4f* Muneco::Brazo::getArticulacionCodo(){
return leerPtrMatriz(indice_codo);
}
Muneco::Cola::Cola(){
Cilindroide* c = new Cilindroide(0.8, 2, 20, true, true, false);
Esfera* e = new Esfera(20, 20, true, true, false);
Matriz4f escalado = MAT_Escalado(0.8, 0.8, 0.8);
agregar(MAT_Rotacion(-90, 1, 0, 0));
/* agregar(MAT_Escalado(0.6, 1,0.6)); */
agregar(c);
agregar(MAT_Traslacion(0, 1, 0));
agregar(escalado);
ind.push_back(agregar(MAT_Ident()));
agregar(e);
agregar(c);
agregar(MAT_Traslacion(0, 1, 0));
agregar(escalado);
ind.push_back(agregar(MAT_Ident()));
agregar(e);
agregar(c);
agregar(MAT_Traslacion(0, 1, 0));
agregar(escalado);
ind.push_back(agregar(MAT_Ident()));
agregar(e);
agregar(c);
agregar(MAT_Traslacion(0, 1, 0));
agregar(escalado);
ind.push_back(agregar(MAT_Ident()));
agregar(e);
agregar(c);
agregar(MAT_Traslacion(0, 1, 0));
agregar(escalado);
ind.push_back(agregar(MAT_Ident()));
agregar(e);
agregar(c);
agregar(MAT_Traslacion(0, 1, 0));
agregar(escalado);
ind.push_back(agregar(MAT_Ident()));
agregar(e);
agregar(c);
agregar(MAT_Traslacion(0, 1, 0));
agregar(escalado);
ind.push_back(agregar(MAT_Ident()));
agregar(e);
agregar(c);
agregar(MAT_Traslacion(0, 1, 0));
agregar(escalado);
agregar(e);
}
Matriz4f* Muneco::Cola::getArticulacion(int i){
return leerPtrMatriz(ind[i]);
}
unsigned Muneco::Cola::numArticulaciones(){
return ind.size();
}
Muneco::Ojo::Ojo(){
Esfera* e1 = new Esfera(20, 20, true, true, false); // Esfera de fuera
Esfera* e2 = new Esfera(20, 20, true, true, false); // Pupila
e1->fijarColorNodo({1,1,1});
e2->fijarColorNodo({0,0,0});
agregar(MAT_Escalado(0.2, 0.2, 0.15));
agregar(e1);
agregar(MAT_Traslacion(-0.2, -0.2, 0.3));
agregar(MAT_Escalado(0.7, 0.7, 1));
agregar(e2);
}
Lata::Lata(){
ponerIdentificador(1);
ponerNombre("Lata");
agregar(new TapaArriba());
agregar(new Cuerpo());
agregar(new TapaAbajo());
}
Lata::Cuerpo::Cuerpo(){
ponerIdentificador(-1);
ponerNombre("Cuerpo lata");
agregar(new MaterialLata());
agregar(new MallaRevol("../plys/lata-pcue.ply", 50, false ,false, true));
}
Lata::TapaArriba::TapaArriba(){
ponerIdentificador(-1);
ponerNombre("Tapa arriba lata");
agregar(new MaterialTapasLata());
agregar(new MallaRevol("../plys/lata-psup.ply", 50, true, false, true));
}
Lata::TapaAbajo::TapaAbajo(){
ponerIdentificador(-1);
ponerNombre("Tapa abajo lata");
agregar(new MaterialTapasLata());
agregar(new MallaRevol("../plys/lata-pinf.ply", 50, true, false, true));
}
PeonMadera::PeonMadera(){
ponerIdentificador(2);
ponerNombre("Peon madera");
agregar(new MaterialPeonMadera());
agregar(new MallaRevol("../plys/peon.ply", 50, true, false, true));
}
PeonBlanco::PeonBlanco(){
ponerIdentificador(3);
ponerNombre("Peon blanco");
agregar(new MaterialPeonBlanco());
agregar(new MallaRevol("../plys/peon.ply", 50, true, false, true));
}
PeonNegro::PeonNegro(){
ponerIdentificador(4);
ponerNombre("Peon negro");
agregar(new MaterialPeonNegro());
agregar(new MallaRevol("../plys/peon.ply", 50, true, false, true));
}
EscenaP4::EscenaP4(){
agregar(new Lata());
agregar(MAT_Escalado((float) 1/7,(float) 1/7,(float) 1/7));
agregar(MAT_Traslacion(0, 1, 12));
agregar(new Dado);
agregar(MAT_Traslacion(0, -1,-12));
agregar(MAT_Escalado((float) 7,(float) 7,(float) 7));
agregar(MAT_Traslacion(0, 0.25, 1));
agregar(MAT_Escalado((float) 1/5,(float) 1/5,(float) 1/5));
agregar(new PeonMadera);
agregar(MAT_Traslacion(3, 0, 0));
agregar(new PeonBlanco);
agregar(MAT_Traslacion(3, 0, 0));
agregar(new PeonNegro);
}
//---------------------------------------------------------------------------------
// EJERCICIOS RELACIÓN
// 33-.
void tronco(){
std::vector<Tupla3f> vertices;
std::vector<Tupla3i> caras;
std::vector<int> linea1;
std::vector<int> linea2;
std::vector<int> linea3;
// Inicialización de vértices
vertices.push_back({0, 0, 0});
vertices.push_back({1, 0, 0});
vertices.push_back({1, 1, 0});
vertices.push_back({2, 2, 0});
vertices.push_back({1.5, 2.5, 0});
vertices.push_back({0.5, 1.5, 0});
vertices.push_back({0, 3, 0});
vertices.push_back({-0.5, 3, 0});
vertices.push_back({0, 1.5, 0});
caras.push_back({0, 1, 2});
caras.push_back({0, 2, 8});
caras.push_back({2, 5, 8});
caras.push_back({2, 4, 5});
caras.push_back({2, 3, 4});
caras.push_back({5, 6, 8});
caras.push_back({6, 7, 8});
linea1.push_back(1);
linea1.push_back(2);
linea1.push_back(3);
linea2.push_back(4);
linea2.push_back(5);
linea2.push_back(6);
linea3.push_back(7);
linea3.push_back(8);
linea3.push_back(0);
glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
glEnableClientState( GL_VERTEX_ARRAY ); // habilitar array de vértices
glVertexPointer( 3, GL_FLOAT, 0, vertices.data() ); // establecer dirección y estructura
glColor3f(0.5, 0.5, 1); // Azul clarito(?)
glDrawElements( GL_TRIANGLES, caras.size()*3L, GL_UNSIGNED_INT, caras.data() );
glColor3f(0.0, 0.0, 1); // Azul
glLineWidth(3.0);
glDrawElements( GL_LINE_STRIP, linea1.size(), GL_UNSIGNED_INT, linea1.data() );
glDrawElements( GL_LINE_STRIP, linea2.size(), GL_UNSIGNED_INT, linea2.data() );
glDrawElements( GL_LINE_STRIP, linea3.size(), GL_UNSIGNED_INT, linea3.data() );
glDisableClientState( GL_VERTEX_ARRAY );
}
void arbol(unsigned niveles){
if (niveles > 0){
tronco();
glPushMatrix();
glTranslatef(1.5, 2.5, 0);
glRotatef(-45.0, 0.0, 0.0, 1.0);
glScalef(sqrt(0.5), sqrt(0.5), sqrt(0.5));
arbol(niveles-1);
glPopMatrix();
glPushMatrix();
glTranslatef(-0.5, 3, 0);
glScalef(0.5, 0.5, 0.5);
arbol(niveles-1);
glPopMatrix();
}
}
//Examen Grado
Test::Test(Material* m){
agregar(m);
/* agregar(new MaterialEsmeralda); */
agregar(new Esfera(20, 20, true, false, true));
}
// Examen Prácticas Año Pasado
Moneda::Moneda(){
agregar(new CaraSuperior);
agregar(new Borde);
agregar(new CaraInferior);
}
CaraSuperior::CaraSuperior(){
agregar(MAT_Traslacion(0.0, 0.05, 0));
agregar(new MaterialCaras());
agregar(new Disco(50));
}
CaraInferior::CaraInferior(){
agregar(MAT_Rotacion(180, 0, 0, 1));
agregar(new MaterialCaras());
Disco * d = new Disco(50);
d->invertirCoordText(true, false);
agregar(d);
}
Borde::Borde(){
agregar(MAT_Escalado(1, 0.05, 1));
agregar(new MaterialBorde());
agregar(new Cilindro(2, 50, false, false, true));
}
// Examen fotocopia
CuboColores::CuboColores(){
agregar(new MaterialDado());
agregar(new CaraArriba());
agregar(new CaraAbajo());
agregar(new CaraIzq());
agregar(new CaraDer());
agregar(new CaraFrente());
agregar(new CaraAtras());
}
// EXAMEN P4
Dado::Dado(){
ponerIdentificador(5);
agregar(new MaterialDadoP4);
agregar(new DadoP4());
}
// Examen Prácticas
Arbusto::Rama::Rama(){
agregar(MAT_Ident());
agregar(new Esfera(20, 20, true, true, false));
agregar(MAT_Rotacion(-90, 0, 0, 1));
agregar(MAT_Escalado(0.5, 4, 0.5));
agregar(new Cilindro(2, 20, true, true, false));
agregar(MAT_Escalado(2, 1.0/4, 2));
agregar(MAT_Traslacion(0, 4, 0));
agregar(new Esfera(20, 20, true, true, false));
}
Matriz4f* Arbusto::Rama::getArticulacion(){
return leerPtrMatriz(0);
}
Arbusto::Rama1::Rama1(){
agregar(MAT_Ident());
articulaciones[0] = leerPtrMatriz(0);
agregar(new Rama());
agregar(MAT_Traslacion(4, 0, 0));
Rama* r1 = new Rama();
Rama* r2 = new Rama();
articulaciones[1] = r1->getArticulacion();
articulaciones[2] = r2->getArticulacion();
agregar(r1);
agregar(r2);
}
Matriz4f* Arbusto::Rama1::getArticulacion(unsigned i){
return articulaciones[i];
}
Arbusto::Arbusto(){
int i_rot_total;
Rama1* r11 = new Rama1();
Rama1* r12 = new Rama1();
i_rot_total = agregar(MAT_Ident());
agregar(new Rama());
agregar(MAT_Traslacion(4, 0, 0));
agregar(r11);
agregar(r12);
Parametro rot1(
"Rotación total",
leerPtrMatriz(i_rot_total),
[=] (float v) {return MAT_Rotacion(v, 0, 0, 1);},
true,
22,
22,
0.1
);
Parametro rot2(
"Rotación total",
r11->getArticulacion(0),
[=] (float v) {return MAT_Rotacion(v, 0, 0, 1);},
true,
22,
22,
0.1
);
Parametro rot3(
"Rotación total",
r11->getArticulacion(1),
[=] (float v) {return MAT_Rotacion(v, 0, 0, 1);},
true,
22,
22,
0.1
);
Parametro rot4(
"Rotación total",
r11->getArticulacion(2),
[=] (float v) {return MAT_Rotacion(v, 0, 0, 1);},
true,
67,
22,
0.1
);
Parametro rot5(
"Rotación total",
r12->getArticulacion(0),
[=] (float v) {return MAT_Rotacion(v, 0, 0, 1);},
true,
67,
22,
0.1
);
Parametro rot6(
"Rotación total",
r12->getArticulacion(1),
[=] (float v) {return MAT_Rotacion(v, 0, 0, 1);},
true,
22,
22,
0.1
);
Parametro rot7(
"Rotación total",
r12->getArticulacion(2),
[=] (float v) {return MAT_Rotacion(v, 0, 0, 1);},
true,
67,
22,
0.1
);
parametros.push_back(rot1);
parametros.push_back(rot2);
parametros.push_back(rot3);