-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinfinicity.c
1672 lines (1160 loc) · 48 KB
/
infinicity.c
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
/** @file Demonstrates 3D shapes of the big city.
*
* @author Soheil Sepahyar
*/
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <GL/glew.h>
#include <GLFW/glfw3.h>
#include "libkuhl.h"
float aspectRatio;
GLuint texId = 0;
static GLuint program = 0; /**< id value for the GLSL program */
static GLuint program1 = 0; /**< id value for the GLSL program */
static kuhl_geometry triangle;
//static kuhl_geometry quad;
//static kuhl_geometry left_windows;
//static kuhl_geometry right_windows;
float BHeight = 1;
float BWidth = 1;
float BDepth = 1;
//static kuhl_geometry triangle2;
float CBHeight = 1;
float CBWidth = 1;
float CBDepth = 1;
//static kuhl_geometry Cquad;
//static kuhl_geometry left_Cwindows;
//static kuhl_geometry right_Cwindows;
////////////////////////////////////////////////////////////
float x_amount = 0;
float y_amount = 0;
float z_amount = 0;
static kuhl_geometry buildingBottom[10][10];
static kuhl_geometry windowBottomfront[10][10];
static kuhl_geometry windowBottomleft[10][10];
static kuhl_geometry windowBottomright[10][10];
//////////////////////////////////////////////////////////////////////
static kuhl_geometry buildingTop[10][10];
static kuhl_geometry buildingTop[10][10];
static kuhl_geometry windowTopfront[10][10];
static kuhl_geometry windowTopleft[10][10];
static kuhl_geometry windowTopright[10][10];
//////////////////////////////////////////////////////////////////////
int isComplex[10][10]; // tells us if the building is complex or not.
////////////////////////////////////////////////////////////////////// // ALl thing relates to camera settings
int which_one_FBRLUD = 0;
float amount_of_moving_FB = 520;
float amount_of_moving_LR = 60;
float amount_of_up_down = 60;
float varx = 50;
float vary = 50;
float varz = 0;
/* Called by GLFW whenever a key is pressed. */
void keyboard(GLFWwindow* window, int key, int scancode, int action, int mods)
{
/* If the library handles this keypress, return */
if (kuhl_keyboard_handler(window, key, scancode, action, mods))
return;
if(action == GLFW_PRESS)
return;
switch(key)
{
#if 0
#endif
case GLFW_KEY_SPACE:
which_one_FBRLUD = 0;
z_amount += 2;
amount_of_moving_FB -= 1;
varz--;
break;
case GLFW_KEY_B:
which_one_FBRLUD = 1;
amount_of_moving_FB += 1;
varz++;
break;
case GLFW_KEY_R:
which_one_FBRLUD = 2;
amount_of_moving_LR += 1;
varx++;
break;
case GLFW_KEY_L:
which_one_FBRLUD = 3;
amount_of_moving_LR -= 1;
varx--;
break;
case GLFW_KEY_U:
which_one_FBRLUD = 3;
amount_of_up_down += 1;
vary++;
break;
case GLFW_KEY_D:
which_one_FBRLUD = 3;
amount_of_up_down -= 1;
vary--;
break;
}
}
/** Draws the 3D scene. */
void display()
{
/* Render the scene once for each viewport. Frequently one
* viewport will fill the entire screen. However, this loop will
* run twice for HMDs (once for the left eye and once for the
* right). */
viewmat_begin_frame();
for(int viewportID=0; viewportID<viewmat_num_viewports(); viewportID++)
{
viewmat_begin_eye(viewportID);
/* Where is the viewport that we are drawing onto and what is its size? */
int viewport[4]; // x,y of lower left corner, BWidth, BHeight
viewmat_get_viewport(viewport, viewportID);
/* Tell OpenGL the area of the window that we will be drawing in. */
glViewport(viewport[0], viewport[1], viewport[2], viewport[3]);
/* Clear the current viewport. Without glScissor(), glClear()
* clears the entire screen. We could call glClear() before
* this viewport loop---but in order for all variations of
* this code to work (Oculus support, etc), we can only draw
* after viewmat_begin_eye(). */
glScissor(viewport[0], viewport[1], viewport[2], viewport[3]);
glEnable(GL_SCISSOR_TEST);
glClearColor(.1,.1,.1,0); // set clear color to grey
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glDisable(GL_SCISSOR_TEST);
glEnable(GL_DEPTH_TEST); // turn on BDepth testing
kuhl_errorcheck();
/* Get the view matrix and the projection matrix */
float viewMat[16], perspective[16];
viewmat_get(viewMat, perspective, viewportID);
if (which_one_FBRLUD == 0)
{
mat4f_lookat_new( viewMat, amount_of_moving_LR ,amount_of_up_down , amount_of_moving_FB, varx ,vary,varz, 0,1,0);
}
if (which_one_FBRLUD == 1)
{
mat4f_lookat_new( viewMat, amount_of_moving_LR ,amount_of_up_down , amount_of_moving_FB , varx ,vary, varz, 0,1,0);
}
if (which_one_FBRLUD == 2)
{
mat4f_lookat_new( viewMat, amount_of_moving_LR ,amount_of_up_down ,amount_of_moving_FB , varx ,vary,varz, 0,1,0);
}
if (which_one_FBRLUD == 3)
{
mat4f_lookat_new( viewMat, amount_of_moving_LR ,amount_of_up_down ,amount_of_moving_FB , varx ,vary,varz, 0,1,0);
}
if (which_one_FBRLUD == 4)
{
mat4f_lookat_new( viewMat, amount_of_moving_LR ,amount_of_up_down ,amount_of_moving_FB , varx ,vary,varz, 0,1,0);
}
if (which_one_FBRLUD == 5)
{
mat4f_lookat_new( viewMat, amount_of_moving_LR ,amount_of_up_down ,amount_of_moving_FB , varx ,vary,varz, 0,1,0);
}
/* Calculate an angle to rotate the object. glfwGetTime() gets
* the time in seconds since GLFW was initialized. Rotates 45 degrees every second. */
float angle = fmod(glfwGetTime()*45, 360);
/* Make sure all computers/processes use the same angle */
dgr_setget("angle", &angle, sizeof(GLfloat));
/* Create a 4x4 rotation matrix based on the angle we computed. */
float rotateMat[16];
mat4f_rotateAxis_new(rotateMat, 0 /* angle */, 0,1,0);
/* Create a scale matrix. */
float scaleMat[16];
mat4f_scale_new(scaleMat, 1, 1, 1);
float translation[16];
//mat4f_translate_new(translation, -10, 0, -10);
/* Combine the scale and rotation matrices into a single model matrix.
modelMat = scaleMat * rotateMat
*/
float modelMat[16];
mat4f_mult_mat4f_new(modelMat, scaleMat, rotateMat);
float modelview[16];
/* Draw the geometry using the matrices that we sent to the
* vertex programs immediately above */
//kuhl_geometry_draw(&triangle);
//kuhl_geometry_draw(&quad);
//kuhl_geometry_draw(&left_windows);
//kuhl_geometry_draw(&right_windows();
float translation2[16];
/////////////////////////////////////////////////////////////////////////////////////
for(int i = 0; i < 10; i++)
{
for(int j = 0; j < 10; j++)
{
mat4f_translate_new(translation, 0 , 0, (20 + (j*5)));
mat4f_mult_mat4f_new(modelMat, modelMat, translation);
/* Construct a modelview matrix: modelview = viewMat * modelMat */
mat4f_mult_mat4f_new(modelview, viewMat, modelMat);
/* Tell OpenGL which GLSL program the subsequent
* glUniformMatrix4fv() calls are for. */
kuhl_errorcheck();
glUseProgram(program);
kuhl_errorcheck();
/* Send the perspective projection matrix to the vertex program. */
glUniformMatrix4fv(kuhl_get_uniform("Projection"),
1, // number of 4x4 float matrices
0, // transpose
perspective); // value
/* Send the modelview matrix to the vertex program. */
glUniformMatrix4fv(kuhl_get_uniform("ModelView"),
1, // number of 4x4 float matrices
0, // transpose
modelview); // value
kuhl_errorcheck();
kuhl_geometry_draw(&buildingBottom[i][j]);
kuhl_geometry_draw(&windowBottomfront[i][j]);
kuhl_geometry_draw(&windowBottomleft[i][j]);
kuhl_geometry_draw(&windowBottomright[i][j]);
if (isComplex[i][j] == true)
{
kuhl_geometry_draw(&buildingTop[i][j]);
kuhl_geometry_draw(&windowTopfront[i][j]);
kuhl_geometry_draw(&windowTopleft[i][j]);
kuhl_geometry_draw(&windowTopright[i][j]);
}
}
mat4f_translate_new(translation2,(20 + (i * 20)), 0, 0);
mat4f_mult_mat4f_new(modelMat, scaleMat, rotateMat);
mat4f_mult_mat4f_new(modelMat, modelMat, translation2);
mat4f_mult_mat4f_new(modelview, viewMat, modelMat);
// /* Send the perspective projection matrix to the vertex program. */
// glUniformMatrix4fv(kuhl_get_uniform("Projection"),
// 1, // number of 4x4 float matrices
// 0, // transpose
// perspective); // value
// /* Send the modelview matrix to the vertex program. */
// glUniformMatrix4fv(kuhl_get_uniform("ModelView"),
// 1, // number of 4x4 float matrices
// 0, // transpose
// modelview); // value
// kuhl_errorcheck();
// /* Send the perspective projection matrix to the vertex program. */
kuhl_errorcheck();
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/* Get the view matrix and the projection matrix */
float viewMatC[16], perspectiveC[16];
viewmat_get(viewMatC, perspectiveC, viewportID);
/* Calculate an angle to rotate the object. glfwGetTime() gets
* the time in seconds since GLFW was initialized. Rotates 45 degrees every second. */
float angleC = fmod(glfwGetTime()*45, 360);
/* Make sure all computers/processes use the same angle */
dgr_setget("angle", &angleC, sizeof(GLfloat));
/* Create a 4x4 rotation matrix based on the angle we computed. */
float rotateMatC[16];
mat4f_rotateAxis_new(rotateMatC, 0 /* angle */, 0,1,0);
/* Create a scale matrix. */
float scaleMatC[16];
mat4f_scale_new(scaleMatC, 0.5, 1, 1 );
float scaleMatC2[16];
mat4f_scale_new(scaleMatC2, 1, 1, 1 );
float translationC[16];
mat4f_translate_new(translationC, 200, 0, 250 + (amount_of_moving_FB - 519));
//mat4f_translate_new(translationC, 0 , 0, (20 + (j*5)));
//mat4f_mult_mat4f_new(modelMat, modelMat, translation);
/* Construct a modelview matrix: modelview = viewMat * modelMat */
/* Combine the scale and rotation matrices into a single model matrix.
modelMat = scaleMat * rotateMat
*/
float modelMatC[16];
mat4f_mult_mat4f_new(modelMatC, scaleMatC, rotateMatC);
mat4f_mult_mat4f_new(modelMatC, modelMatC, translationC);
//float modelviewC[16];
//mat4f_mult_mat4f_new(modelMatC, scaleMatC2, rotateMatC);
mat4f_mult_mat4f_new(modelview, viewMat, modelMatC);
kuhl_errorcheck();
glUseProgram(program1);
kuhl_errorcheck();
/* Send the perspective projection matrix to the vertex program. */
glUniformMatrix4fv(kuhl_get_uniform("Projection"),
1, // number of 4x4 float matrices
0, // transpose
perspectiveC); // value
/* Send the modelview matrix to the vertex program. */
glUniformMatrix4fv(kuhl_get_uniform("ModelView"),
1, // number of 4x4 float matrices
0, // transpose
modelview); // value
kuhl_errorcheck();
kuhl_geometry_draw(&triangle);
glUseProgram(0); // stop using a GLSL program.
viewmat_end_eye(viewportID);
} // finish viewport loop
viewmat_end_frame();
/* Check for errors. If there are errors, consider adding more
* calls to kuhl_errorcheck() in your code. */
kuhl_errorcheck();
}
/* This illustrates how to draw a quad by drawing two triangles and reusing vertices. */ // For front window
void init_geometrySimpleWindows(kuhl_geometry *geom, GLuint prog)
{
GLfloat * vertices = (GLfloat*) malloc((3 * 6 * 6000) * sizeof(GLfloat)); // We should use dynamic array in order to use for nested loops for our purpose
int my_counter = 0;
for(float i = 0; i < (BHeight) - 0.5 ; i += 0.5)
{
for(float j = 0; j < (BWidth) - 0.5 ; j+= 0.5)
{
kuhl_geometry_new(geom, prog, 6 * (BHeight * BWidth * 4), // num vertices //******** here
GL_TRIANGLES); // primitive type
vertices[my_counter++] = j;
vertices[my_counter++] = i;
vertices[my_counter++] = (BDepth) + 0.15;
vertices[my_counter++] = j + 0.5 ;
vertices[my_counter++] = i;
vertices[my_counter++] = (BDepth) + 0.15;
vertices[my_counter++] = j + 0.5;
vertices[my_counter++] = i + 0.5;
vertices[my_counter++] = (BDepth) + 0.15;
vertices[my_counter++] = j;
vertices[my_counter++] = i;
vertices[my_counter++] = (BDepth) + 0.15;
vertices[my_counter++] = j + 0.5;
vertices[my_counter++] = i + 0.5;
vertices[my_counter++] = (BDepth) + 0.15;
vertices[my_counter++] = j;
vertices[my_counter++] = i + 0.5;
vertices[my_counter++] = (BDepth) + 0.15;
j+= 0.1;
}
i += 0.1;
}
kuhl_geometry_attrib(geom, vertices, // data // Drawing front Windows
3, // number of components (x,y,z)
"in_Position", // GLSL variable
KG_WARN); // warn if attribute is missing in GLSL program?
GLfloat * colors = (GLfloat*) malloc((3 * 6 * 6000) * sizeof(GLfloat)); // We should use dynamic array in order to use for nested loops for our purpose
int my_counter_colors = 0;
for(float i = 0; i < (BHeight) - 0.5 ; i += 0.5)
{
for(float j = 0; j < (BWidth) - 0.5 ; j+= 0.5)
{
float my_num = drand48();
if(my_num <= 0.1)
{
colors[my_counter_colors++] = 0.6;
colors[my_counter_colors++] = 0.6;
colors[my_counter_colors++] = 0;
colors[my_counter_colors++] = 0.6;
colors[my_counter_colors++] = 0.6;
colors[my_counter_colors++] = 0;
colors[my_counter_colors++] = 0.6;
colors[my_counter_colors++] = 0.6;
colors[my_counter_colors++] = 0;
colors[my_counter_colors++] = 0.6;
colors[my_counter_colors++] = 0.6;
colors[my_counter_colors++] = 0;
colors[my_counter_colors++] = 0.6;
colors[my_counter_colors++] = 0.6;
colors[my_counter_colors++] = 0;
colors[my_counter_colors++] = 0.6;
colors[my_counter_colors++] = 0.6;
colors[my_counter_colors++] = 0;
}
else
{
colors[my_counter_colors++] = 0.01;
colors[my_counter_colors++] = 0.01;
colors[my_counter_colors++] = 0;
colors[my_counter_colors++] = 0.01;
colors[my_counter_colors++] = 0.01;
colors[my_counter_colors++] = 0;
colors[my_counter_colors++] = 0.01;
colors[my_counter_colors++] = 0.01;
colors[my_counter_colors++] = 0;
colors[my_counter_colors++] = 0.01;
colors[my_counter_colors++] = 0.01;
colors[my_counter_colors++] = 0;
colors[my_counter_colors++] = 0.01;
colors[my_counter_colors++] = 0.01;
colors[my_counter_colors++] = 0;
colors[my_counter_colors++] = 0.01;
colors[my_counter_colors++] = 0.01;
colors[my_counter_colors++] = 0;
}
}
}
kuhl_geometry_attrib(geom, colors, 3, "in_Color", KG_WARN);
}
///////////////////////////////////////////////
/* This illustrates how to draw a quad by drawing two triangles and reusing vertices. */
void init_geometrySimpleWindows3(kuhl_geometry *geom, GLuint prog)
{
GLfloat * vertices_side = (GLfloat*) malloc((3 * 6 * 6000) * sizeof(GLfloat)); // We should use dynamic array in order to use for nested loops for our purpose
int my_counter_side = 0;
for(float i = 0; i < (BHeight) - 0.5 ; i += 0.5)
{
for(float j = 0; j < (BDepth) - 0.5 ; j+= 0.5)
{
kuhl_geometry_new(geom, prog, 6 * (BHeight * BDepth * 4), // num vertices //******** here
GL_TRIANGLES); // primitive type
vertices_side[my_counter_side++] = ((BWidth) + 0.15);
vertices_side[my_counter_side++] = i;
vertices_side[my_counter_side++] = j;
vertices_side[my_counter_side++] = ((BWidth) + 0.15);
vertices_side[my_counter_side++] = i;
vertices_side[my_counter_side++] = j + 0.5;
vertices_side[my_counter_side++] = ((BWidth) + 0.15);
vertices_side[my_counter_side++] = i + 0.5;
vertices_side[my_counter_side++] = j + 0.5;
vertices_side[my_counter_side++] = ((BWidth) + 0.15);
vertices_side[my_counter_side++] = i;
vertices_side[my_counter_side++] = j;
vertices_side[my_counter_side++] = ((BWidth) + 0.15);
vertices_side[my_counter_side++] = i + 0.5;
vertices_side[my_counter_side++] = j + 0.5;
vertices_side[my_counter_side++] = ((BWidth) + 0.15);
vertices_side[my_counter_side++] = i + 0.5;
vertices_side[my_counter_side++] = j;
j+= 0.1;
}
i += 0.1;
}
kuhl_geometry_attrib(geom, vertices_side, // data // Side windows
3, // number of components (x,y,z)
"in_Position", // GLSL variable
1); // warn if attribute is missing in GLSL program?
// kuhl_geometry_attrib(cube, vertexData, 3, "in_Position", 1);
GLfloat * colors = (GLfloat*) malloc((3 * 6 * 6000) * sizeof(GLfloat)); // We should use dynamic array in order to use for nested loops for our purpose
int my_counter_colors = 0;
for(float i = -(BHeight/2.0); i < (BHeight/2) - 0.3 ; i += 0.5)
{
for(float j = -(BDepth/2.0); j < (BDepth/2) - 0.5 ; j+= 0.5)
{
float my_num = drand48();
if(my_num <= 0.1)
{
colors[my_counter_colors++] = 0.6;
colors[my_counter_colors++] = 0.6;
colors[my_counter_colors++] = 0;
colors[my_counter_colors++] = 0.6;
colors[my_counter_colors++] = 0.6;
colors[my_counter_colors++] = 0;
colors[my_counter_colors++] = 0.6;
colors[my_counter_colors++] = 0.6;
colors[my_counter_colors++] = 0;
colors[my_counter_colors++] = 0.6;
colors[my_counter_colors++] = 0.6;
colors[my_counter_colors++] = 0;
colors[my_counter_colors++] = 0.6;
colors[my_counter_colors++] = 0.6;
colors[my_counter_colors++] = 0;
colors[my_counter_colors++] = 0.6;
colors[my_counter_colors++] = 0.6;
colors[my_counter_colors++] = 0;
}
else
{
colors[my_counter_colors++] = 0.01;
colors[my_counter_colors++] = 0.01;
colors[my_counter_colors++] = 0;
colors[my_counter_colors++] = 0.01;
colors[my_counter_colors++] = 0.01;
colors[my_counter_colors++] = 0;
colors[my_counter_colors++] = 0.01;
colors[my_counter_colors++] = 0.01;
colors[my_counter_colors++] = 0;
colors[my_counter_colors++] = 0.01;
colors[my_counter_colors++] = 0.01;
colors[my_counter_colors++] = 0;
colors[my_counter_colors++] = 0.01;
colors[my_counter_colors++] = 0.01;
colors[my_counter_colors++] = 0;
colors[my_counter_colors++] = 0.01;
colors[my_counter_colors++] = 0.01;
colors[my_counter_colors++] = 0;
}
}
}
kuhl_geometry_attrib(geom, colors, 3, "in_Color", KG_WARN);
}
///////////////////////////////////////////////
/* This illustrates how to draw a quad by drawing two triangles and reusing vertices. */
void init_geometrySimpleWindows2(kuhl_geometry *geom, GLuint prog)
{
GLfloat * vertices_side = (GLfloat*) malloc((3 * 6 * 6000) * sizeof(GLfloat)); // We should use dynamic array in order to use for nested loops for our purpose
int my_counter_side = 0;
for(float i = 0; i < (BHeight) - 0.5 ; i += 0.5)
{
for(float j = 0; j < (BDepth) - 0.5 ; j+= 0.5)
{
kuhl_geometry_new(geom, prog, 6 * (BHeight * BDepth * 4), // num vertices //******** here
GL_TRIANGLES); // primitive type
vertices_side[my_counter_side++] = -0.15;
vertices_side[my_counter_side++] = i;
vertices_side[my_counter_side++] = j;
vertices_side[my_counter_side++] = -0.15;
vertices_side[my_counter_side++] = i;
vertices_side[my_counter_side++] = j + 0.5;
vertices_side[my_counter_side++] = -0.15;
vertices_side[my_counter_side++] = i + 0.5;
vertices_side[my_counter_side++] = j + 0.5;
vertices_side[my_counter_side++] = -0.15;
vertices_side[my_counter_side++] = i;
vertices_side[my_counter_side++] = j;
vertices_side[my_counter_side++] = -0.15;
vertices_side[my_counter_side++] = i + 0.5;
vertices_side[my_counter_side++] = j + 0.5;
vertices_side[my_counter_side++] = -0.15;
vertices_side[my_counter_side++] = i + 0.5;
vertices_side[my_counter_side++] = j;
j+= 0.1;
}
i += 0.1;
}
kuhl_geometry_attrib(geom, vertices_side, // data // Side windows
3, // number of components (x,y,z)
"in_Position", // GLSL variable
1); // warn if attribute is missing in GLSL program?
// kuhl_geometry_attrib(cube, vertexData, 3, "in_Position", 1);
GLfloat * colors = (GLfloat*) malloc((3 * 6 * 6000) * sizeof(GLfloat)); // We should use dynamic array in order to use for nested loops for our purpose
int my_counter_colors = 0;
for(float i = -(BHeight/2.0); i < (BHeight/2) - 0.3 ; i += 0.5)
{
for(float j = -(BDepth/2.0); j < (BDepth/2) - 0.5 ; j+= 0.5)
{
float my_num = drand48();
if(my_num <= 0.1)
{
colors[my_counter_colors++] = 0.6;
colors[my_counter_colors++] = 0.6;
colors[my_counter_colors++] = 0;
colors[my_counter_colors++] = 0.6;
colors[my_counter_colors++] = 0.6;
colors[my_counter_colors++] = 0;
colors[my_counter_colors++] = 0.6;
colors[my_counter_colors++] = 0.6;
colors[my_counter_colors++] = 0;
colors[my_counter_colors++] = 0.6;
colors[my_counter_colors++] = 0.6;
colors[my_counter_colors++] = 0;
colors[my_counter_colors++] = 0.6;
colors[my_counter_colors++] = 0.6;
colors[my_counter_colors++] = 0;
colors[my_counter_colors++] = 0.6;
colors[my_counter_colors++] = 0.6;
colors[my_counter_colors++] = 0;
}
else
{
colors[my_counter_colors++] = 0.01;
colors[my_counter_colors++] = 0.01;
colors[my_counter_colors++] = 0;
colors[my_counter_colors++] = 0.01;
colors[my_counter_colors++] = 0.01;
colors[my_counter_colors++] = 0;
colors[my_counter_colors++] = 0.01;
colors[my_counter_colors++] = 0.01;
colors[my_counter_colors++] = 0;
colors[my_counter_colors++] = 0.01;
colors[my_counter_colors++] = 0.01;
colors[my_counter_colors++] = 0;
colors[my_counter_colors++] = 0.01;
colors[my_counter_colors++] = 0.01;
colors[my_counter_colors++] = 0;
colors[my_counter_colors++] = 0.01;
colors[my_counter_colors++] = 0.01;
colors[my_counter_colors++] = 0;
}
}
}
kuhl_geometry_attrib(geom, colors, 3, "in_Color", KG_WARN);
}
/* This illustrates how to draw 3 sides of a cube. */
void init_geometrySimpleBuilding(kuhl_geometry *cube, GLuint program)
{
// 4*3 is the number of vertices. If you add more, you should increase this number!
kuhl_geometry_new(cube, program, 12*3, GL_TRIANGLES);
/* The data that we want to draw. Each set of three numbers is a
* position. */
GLfloat vertexData[] = {(0 * BWidth), (0 * BHeight), (0 * BDepth), // -Z face 0
( 1* BWidth), (0 * BHeight), (0 * BDepth), // 1
( 1* BWidth), ( 1* BHeight), (0 * BDepth), // 2
(0 * BWidth), ( 1* BHeight), (0 * BDepth), // 3
(0 * BWidth), (0 * BHeight), ( 1* BDepth), // +Z face 4
( 1* BWidth), (0 * BHeight), ( 1* BDepth), // 5
( 1* BWidth), ( 1* BHeight), ( 1* BDepth), // 6
(0 * BWidth), ( 1* BHeight), ( 1* BDepth), // 7
(0 * BWidth), (0 * BHeight), (0 * BDepth), // -X face //0
(0 * BWidth), ( 1* BHeight), (0 * BDepth), // 3
(0 * BWidth), ( 1* BHeight), ( 1* BDepth), // 7
(0 * BWidth), (0 * BHeight), ( 1* BDepth), // 4
(1* BWidth), (0 * BHeight), (0 * BDepth), // 5 // x face
(1* BWidth), ( 1* BHeight), (0 * BDepth), // 1
(1* BWidth), ( 1* BHeight), ( 1* BDepth), // 6
(1* BWidth), (0 * BHeight), ( 1* BDepth), // 5
(0 * BWidth), ( 1* BHeight ),( 1* BDepth), // 7 // y
( 1* BWidth), ( 1* BHeight ),( 1* BDepth), // 6
( 1* BWidth), ( 1* BHeight ),(0 * BDepth), // 2
(0 * BWidth), ( 1* BHeight ),(0 * BDepth), // 3
(0 * BWidth), ( 0 * BHeight),( 1* BDepth), // 0 // -y
( 1* BWidth), ( 0 * BHeight),( 1* BDepth), // 1
( 1* BWidth), ( 0 * BHeight),(0 * BDepth), //5
(0 * BWidth), ( 0 * BHeight),(0 * BDepth) // 4
};
kuhl_geometry_attrib(cube, vertexData, 3, "in_Position", 1);
/* The colors of each of the vertices */
GLfloat colorData[] = {0.2,0.2,0.2,
0.2,0.2,0.2,
0.2,0.2,0.2,
0.2,0.2,0.2,
0.2,0.2,0.2,
0.2,0.2,0.2,
0.2,0.2,0.2,
0.2,0.2,0.2,
0.2,0.2,0.2,
0.2,0.2,0.2,
0.2,0.2,0.2,
0.2,0.2,0.2,
0.2,0.2,0.2,
0.2,0.2,0.2,
0.2,0.2,0.2,
0.2,0.2,0.2,
0.2,0.2,0.2,
0.2,0.2,0.2,
0.2,0.2,0.2,
0.2,0.2,0.2,
0.2,0.2,0.2,
0.2,0.2,0.2,
0.2,0.2,0.2,
0.2,0.2,0.2};
kuhl_geometry_attrib(cube, colorData, 3, "in_Color", KG_WARN);
// Since we can't draw quads in OpenGL 3.0+, we'll make quads out of our vertices: Two triangles form a quad.
GLuint indexData[] = { 0, 1, 2, // first triangle is index 0, 1, and 2 in the list of vertices
0, 2, 3,
4, 5, 6, // second quad
4, 6, 7,
8, 9, 10, // third quad
8, 10, 11,
12,13,14,
12,14,15,
16,17,18,
16,18,19,
20,21,22,
20,22,23
};
//3*6 is the length of the indices array. Since we are drawing
//triangles, it should be a multiple of 3.
kuhl_geometry_indices(cube, indexData, 12 * 3);
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // All the complex building
/* This illustrates how to draw a quad by drawing two triangles and reusing vertices. */
void init_geometryComplexWindows(kuhl_geometry *geom, GLuint prog)
{
GLfloat * vertices = (GLfloat*) malloc((3 * 6 * 6000) * sizeof(GLfloat)); // We should use dynamic array in order to use for nested loops for our purpose
int my_counter = 0;
for(float i = 0; i < (CBHeight) - 0.5 ; i += 0.5)
{
for(float j = 0; j < (CBWidth) - 0.5 ; j+= 0.5)
{
kuhl_geometry_new(geom, prog, 6 * (CBHeight * CBWidth * 4), // num vertices //******** here
GL_TRIANGLES); // primitive type
vertices[my_counter++] = j + (BWidth/2) - (CBWidth/2);
vertices[my_counter++] = i + (BHeight);
vertices[my_counter++] = (CBDepth) + 0.15 + (BDepth/2) - (CBDepth/2);
vertices[my_counter++] = j + 0.5 + (BWidth/2) - (CBWidth/2) ;
vertices[my_counter++] = i + (BHeight);
vertices[my_counter++] = (CBDepth) + 0.15 + (BDepth/2) - (CBDepth/2);
vertices[my_counter++] = j + 0.5 + (BWidth/2) - (CBWidth/2);
vertices[my_counter++] = i + 0.5 + (BHeight);
vertices[my_counter++] = (CBDepth) + 0.15 + (BDepth/2) - (CBDepth/2);
vertices[my_counter++] = j + (BWidth/2) - (CBWidth/2);
vertices[my_counter++] = i + (BHeight);
vertices[my_counter++] = (CBDepth) + 0.15 + (BDepth/2) - (CBDepth/2);
vertices[my_counter++] = j + 0.5 + (BWidth/2) - (CBWidth/2);
vertices[my_counter++] = i + 0.5 + (BHeight);
vertices[my_counter++] = (CBDepth) + 0.15 + (BDepth/2) - (CBDepth/2);
vertices[my_counter++] = j + (BWidth/2) - (CBWidth/2);
vertices[my_counter++] = i + 0.5 + (BHeight);
vertices[my_counter++] = (CBDepth) + 0.15 + (BDepth/2) - (CBDepth/2);
j+= 0.1;
}
i += 0.1;
}
kuhl_geometry_attrib(geom, vertices, // data // Drawing front Windows
3, // number of components (x,y,z)
"in_Position", // GLSL variable
KG_WARN); // warn if attribute is missing in GLSL program?
GLfloat * colors = (GLfloat*) malloc((3 * 6 * 6000) * sizeof(GLfloat)); // We should use dynamic array in order to use for nested loops for our purpose
int my_counter_colors = 0;
for(float i = -(CBHeight/2.0); i < (CBHeight/2) - 0.3 ; i += 0.5)
{
for(float j = -(CBWidth/2.0); j < (CBWidth/2) - 0.5 ; j+= 0.5)
{
float my_num = drand48();
if(my_num <= 0.1)
{
colors[my_counter_colors++] = 0.6;
colors[my_counter_colors++] = 0.6;
colors[my_counter_colors++] = 0;
colors[my_counter_colors++] = 0.6;
colors[my_counter_colors++] = 0.6;
colors[my_counter_colors++] = 0;
colors[my_counter_colors++] = 0.6;
colors[my_counter_colors++] = 0.6;
colors[my_counter_colors++] = 0;