-
Notifications
You must be signed in to change notification settings - Fork 0
/
project.js
2593 lines (2417 loc) · 74.3 KB
/
project.js
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
var canvas;
var gl;
var vPosition;
var vTextCoord;
// Animation variables
var frameArray = []; // Holds the thetas at each frames
var lastIndexFrame = 0;
var lastFrameJSON;
var frameJSON;
var intervalID;
var near = -19.487171000000007;
var far = 19.487171000000007;
var radius = 1.0;
var theta = -0.872664625997;
var phi = 1.570796326794896;
var dr = (5.0 * Math.PI) / 180.0;
var thetaFloor = 0.174570886003;
var phiFloor = 2.617993877994;
var eyeFloor;
var left = -4.0;
var right = 4.0;
var ytop = 4.0;
var bottom = -4.0;
var eye;
var BODY_MESH;
var TAIL1_MESH;
var TAIL2_MESH;
var TAIL3_MESH;
var TAIL4_MESH;
var NECK11_MESH;
var NECK21_MESH;
var NECK31_MESH;
var NECK12_MESH;
var NECK22_MESH;
var NECK32_MESH;
var NECK13_MESH;
var NECK23_MESH;
var NECK33_MESH;
var NECK14_MESH;
var NECK24_MESH;
var NECK34_MESH;
var NECK15_MESH;
var NECK25_MESH;
var NECK35_MESH;
var HEAD1_MESH;
var HEAD2_MESH;
var HEAD3_MESH;
var EYE1_MESH;
var EYE2_MESH;
var EYE3_MESH;
var MOUTH1_MESH;
var MOUTH2_MESH;
var MOUTH3_MESH;
var LEG11_MESH;
var LEG12_MESH;
var LEG13_MESH;
var LEG21_MESH;
var LEG22_MESH;
var LEG23_MESH;
var LEG31_MESH;
var LEG32_MESH;
var LEG33_MESH;
var LEG34_MESH;
var LEG41_MESH;
var LEG42_MESH;
var LEG43_MESH;
var LEG44_MESH;
var FLOOR_MESH;
var GROUND_MESH;
const at = vec3(0.0, 0.0, 0.0);
const up = vec3(0.0, 1.0, 0.0);
// Tranformation Matrix variables
var modelViewMatrix, projectionMatrix;
var modelViewLoc, projectionLoc;
var matrixStack = [];
var slider_bodyX = 0;
var slider_bodyY = 0;
var slider_bodyZ = 0;
var slider_bodyRY = 0;
// The angles of joints
var thetaAngle = [];
// Mesh IDs
var BODY_ID = 0;
var TAIL1_ID = 1;
var TAIL2_ID = 2;
var TAIL3_ID = 3;
var TAIL4_ID = 4;
var NECK11_ID = 5;
var NECK21_ID = 6;
var NECK31_ID = 7;
var NECK12_ID = 8;
var NECK22_ID = 9;
var NECK32_ID = 10;
var NECK13_ID = 11;
var NECK23_ID = 12;
var NECK33_ID = 13;
var NECK14_ID = 14;
var NECK24_ID = 15;
var NECK34_ID = 16;
var NECK15_ID = 17;
var NECK25_ID = 18;
var NECK35_ID = 19;
var HEAD1_ID = 20;
var HEAD2_ID = 21;
var HEAD3_ID = 22;
var EYE1_ID = 23;
var EYE2_ID = 24;
var EYE3_ID = 25;
var MOUTH1_ID = 26;
var MOUTH2_ID = 27;
var MOUTH3_ID = 28;
var LEG11_ID = 29;
var LEG12_ID = 30;
var LEG13_ID = 31;
var LEG21_ID = 32;
var LEG22_ID = 33;
var LEG23_ID = 34;
var LEG31_ID = 35;
var LEG32_ID = 36;
var LEG33_ID = 37;
var LEG34_ID = 38;
var LEG41_ID = 39;
var LEG42_ID = 40;
var LEG43_ID = 41;
var LEG44_ID = 42;
// Hydra nodes array
var numOfNodes = 2;
var hydraFigure = [];
for (var i = 0; i < numOfNodes; i++) {
hydraFigure[i] = createNode(null, null, null, null);
}
//-------------------------------------------
function scale4(a, b, c) {
var result = mat4();
result[0][0] = a;
result[1][1] = b;
result[2][2] = c;
return result;
}
//-------------------------------------------
function createNode(transform, render, sibling, child) {
var node = {
transform: transform,
render: render,
sibling: sibling,
child: child,
};
return node;
}
function initHydraNodes(id) {
var m = mat4();
switch (id) {
case BODY_ID:
m = mult(m, scale4(1.5, 3, 3));
m = mult(m, translate(-0.5, 1.2, 0));
hydraFigure[BODY_ID] = createNode(m, bodyRender, null, TAIL1_ID);
var m = mat4();
break;
case TAIL1_ID:
m = translate(0.6, -0.15, 0);
hydraFigure[TAIL1_ID] = createNode(m, tail1Render, NECK11_ID, TAIL2_ID);
var m = mat4();
break;
case TAIL2_ID:
m = translate(0.33, -0.06, 0);
m = hydraFigure[TAIL2_ID] = createNode(m, tail2Render, null, TAIL3_ID);
var m = mat4();
break;
case TAIL3_ID:
m = translate(0.29, 0.13, 0);
m = hydraFigure[TAIL3_ID] = createNode(m, tail3Render, null, TAIL4_ID);
var m = mat4();
break;
case TAIL4_ID:
m = scale4(0.7, 0.7, 0.7);
m = mult(m, translate(0.23, 0.2, 0));
m = hydraFigure[TAIL4_ID] = createNode(m, tail4Render, null, null);
var m = mat4();
break;
case NECK11_ID:
m = translate(-0.38, 0.35, 0.095);
m = hydraFigure[NECK11_ID] = createNode(
m,
neck11Render,
NECK21_ID,
NECK12_ID
);
var m = mat4();
break;
case NECK21_ID:
m = translate(-0.38, 0.35, 0);
m = hydraFigure[NECK21_ID] = createNode(
m,
neck21Render,
NECK31_ID,
NECK22_ID
);
var m = mat4();
break;
case NECK31_ID:
m = translate(-0.38, 0.35, -0.095);
m = hydraFigure[NECK31_ID] = createNode(
m,
neck31Render,
LEG11_ID,
NECK32_ID
);
var m = mat4();
break;
case NECK12_ID:
m = translate(-0.05, 0.16, 0.002);
m = hydraFigure[NECK12_ID] = createNode(m, neck12Render, null, NECK13_ID);
var m = mat4();
break;
case NECK22_ID:
m = translate(-0.05, 0.16, 0.002);
m = hydraFigure[NECK22_ID] = createNode(m, neck22Render, null, NECK23_ID);
var m = mat4();
break;
case NECK32_ID:
m = translate(-0.05, 0.16, 0.002);
m = hydraFigure[NECK32_ID] = createNode(m, neck32Render, null, NECK33_ID);
var m = mat4();
break;
case NECK13_ID:
m = mult(m, translate(-0.075, 0.17, 0.002));
m = hydraFigure[NECK13_ID] = createNode(m, neck13Render, null, NECK14_ID);
var m = mat4();
break;
case NECK23_ID:
m = mult(m, translate(-0.056, 0.12, 0.002));
m = hydraFigure[NECK23_ID] = createNode(m, neck23Render, null, NECK24_ID);
var m = mat4();
break;
case NECK33_ID:
m = mult(m, translate(-0.056, 0.12, 0.002));
m = hydraFigure[NECK33_ID] = createNode(m, neck33Render, null, NECK34_ID);
var m = mat4();
break;
case NECK14_ID:
m = mult(m, translate(-0.065, 0.07, 0.002));
m = hydraFigure[NECK14_ID] = createNode(m, neck14Render, null, NECK15_ID);
var m = mat4();
break;
case NECK24_ID:
m = mult(m, translate(-0.065, 0.07, 0.002));
m = hydraFigure[NECK24_ID] = createNode(m, neck24Render, null, NECK25_ID);
var m = mat4();
break;
case NECK34_ID:
m = mult(m, translate(-0.065, 0.07, 0.002));
m = hydraFigure[NECK34_ID] = createNode(m, neck34Render, null, NECK35_ID);
var m = mat4();
break;
case NECK15_ID:
m = mult(m, translate(-0.09, 0.027, 0.004));
m = hydraFigure[NECK15_ID] = createNode(m, neck15Render, null, HEAD1_ID);
var m = mat4();
break;
case NECK25_ID:
m = mult(m, translate(-0.09, 0.027, 0.004));
m = hydraFigure[NECK25_ID] = createNode(m, neck25Render, null, HEAD2_ID);
var m = mat4();
break;
case NECK35_ID:
m = mult(m, translate(-0.09, 0.027, 0.004));
m = hydraFigure[NECK35_ID] = createNode(m, neck35Render, null, HEAD3_ID);
var m = mat4();
break;
case HEAD1_ID:
m = mult(m, translate(-0.09, 0.027, 0.004));
m = hydraFigure[HEAD1_ID] = createNode(m, head1Render, null, EYE1_ID);
var m = mat4();
break;
case HEAD2_ID:
m = mult(m, translate(-0.09, 0.027, 0.004));
m = hydraFigure[HEAD2_ID] = createNode(m, head2Render, null, EYE2_ID);
var m = mat4();
break;
case HEAD3_ID:
m = mult(m, translate(-0.09, 0.027, 0.004));
m = hydraFigure[HEAD3_ID] = createNode(m, head3Render, null, EYE3_ID);
var m = mat4();
break;
case EYE1_ID:
m = mult(m, translate(-0.02, 0.055, 0));
m = hydraFigure[EYE1_ID] = createNode(m, eye1Render, MOUTH1_ID, null);
var m = mat4();
break;
case EYE2_ID:
m = mult(m, translate(-0.02, 0.055, 0));
m = hydraFigure[EYE2_ID] = createNode(m, eye2Render, MOUTH2_ID, null);
var m = mat4();
break;
case EYE3_ID:
m = mult(m, translate(-0.02, 0.055, 0));
m = hydraFigure[EYE3_ID] = createNode(m, eye3Render, MOUTH3_ID, null);
var m = mat4();
break;
case MOUTH1_ID:
m = mult(m, translate(-0.08, -0.03, 0.004));
m = hydraFigure[MOUTH1_ID] = createNode(m, mouth1Render, null, null);
var m = mat4();
break;
case MOUTH2_ID:
m = mult(m, translate(-0.08, -0.03, 0.004));
m = hydraFigure[MOUTH2_ID] = createNode(m, mouth2Render, null, null);
var m = mat4();
break;
case MOUTH3_ID:
m = mult(m, translate(-0.08, -0.03, 0.004));
m = hydraFigure[MOUTH3_ID] = createNode(m, mouth3Render, null, null);
var m = mat4();
break;
case LEG11_ID:
m = mult(m, translate(-0.2, -0.23, -0.08));
m = hydraFigure[LEG11_ID] = createNode(
m,
leg11Render,
LEG21_ID,
LEG12_ID
);
var m = mat4();
console.log(LEG11_ID);
break;
case LEG21_ID:
m = mult(m, translate(-0.2, -0.33, 0.08));
m = hydraFigure[LEG21_ID] = createNode(
m,
leg21Render,
LEG31_ID,
LEG22_ID
);
var m = mat4();
console.log(LEG21_ID);
break;
case LEG31_ID:
m = mult(m, translate(0.32, -0.27, 0.105));
m = hydraFigure[LEG31_ID] = createNode(
m,
leg31Render,
LEG41_ID,
LEG32_ID
);
var m = mat4();
console.log(LEG31_ID);
break;
case LEG41_ID:
m = mult(m, translate(0.32, -0.27, -0.11));
m = hydraFigure[LEG41_ID] = createNode(m, leg41Render, null, LEG42_ID);
var m = mat4();
console.log(LEG41_ID);
break;
case LEG12_ID:
m = mult(m, translate(-0.11, -0.14, -0.04));
m = hydraFigure[LEG12_ID] = createNode(m, leg12Render, null, LEG13_ID);
var m = mat4();
console.log(LEG12_ID);
break;
case LEG22_ID:
m = mult(m, translate(-0.11, -0.14, 0.04));
m = hydraFigure[LEG22_ID] = createNode(m, leg22Render, null, LEG23_ID);
var m = mat4();
console.log(LEG22_ID);
break;
case LEG32_ID:
m = mult(m, translate(0.1, -0.124, -0.043));
m = hydraFigure[LEG32_ID] = createNode(m, leg32Render, null, LEG33_ID);
var m = mat4();
console.log(LEG32_ID);
break;
case LEG42_ID:
m = mult(m, translate(0.1, -0.124, 0.01));
m = hydraFigure[LEG42_ID] = createNode(m, leg42Render, null, LEG43_ID);
var m = mat4();
break;
case LEG13_ID:
m = mult(m, translate(-0.12, -0.04, -0.04));
m = hydraFigure[LEG13_ID] = createNode(m, leg13Render, null, null);
var m = mat4();
break;
case LEG23_ID:
m = mult(m, translate(-0.12, -0.04, 0.04));
m = hydraFigure[LEG23_ID] = createNode(m, leg23Render, null, null);
var m = mat4();
break;
case LEG33_ID:
m = mult(m, translate(0.05, -0.084, -0.02));
m = hydraFigure[LEG33_ID] = createNode(m, leg33Render, null, LEG34_ID);
var m = mat4();
break;
case LEG43_ID:
m = mult(m, translate(0.05, -0.084, 0.0));
m = hydraFigure[LEG43_ID] = createNode(m, leg43Render, null, LEG44_ID);
var m = mat4();
break;
case LEG34_ID:
m = mult(m, translate(-0.2, -0.084, 0.075));
m = hydraFigure[LEG34_ID] = createNode(m, leg34Render, null, null);
var m = mat4();
break;
case LEG44_ID:
m = mult(m, translate(-0.2, -0.094, -0.015));
m = hydraFigure[LEG44_ID] = createNode(m, leg44Render, null, null);
var m = mat4();
break;
}
}
var program;
function preorder(id) {
if (id == null) return;
matrixStack.push(modelViewMatrix);
modelViewMatrix = mult(modelViewMatrix, hydraFigure[id].transform);
hydraFigure[id].render();
if (hydraFigure[id].child != null) {
preorder(hydraFigure[id].child);
}
modelViewMatrix = matrixStack.pop();
if (hydraFigure[id].sibling != null) {
preorder(hydraFigure[id].sibling);
}
}
var instanceMatrix;
function groundRender() {
console.log( "girdi" );
instanceMatrix = translate(-0.12, -0.02, 0);
instanceMatrix = mult(instanceMatrix, rotate(0, 0, 0, 1));
instanceMatrix = mult(instanceMatrix, translate(0.12, 0.02, 0));
modelViewMatrix = mult(modelViewMatrix, instanceMatrix);
gl.uniformMatrix4fv(modelViewLoc, false, flatten(modelViewMatrix));
gl.bindBuffer(gl.ARRAY_BUFFER, GROUND_MESH.vertexBuffer);
gl.vertexAttribPointer(
vPosition,
GROUND_MESH.vertexBuffer.itemSize,
gl.FLOAT,
false,
0,
0
);
gl.enableVertexAttribArray(vPosition);
gl.bindBuffer(gl.ARRAY_BUFFER, GROUND_MESH.textureBuffer);
gl.vertexAttribPointer(vTextCoord, 2, gl.FLOAT, false, 0, 0);
gl.enableVertexAttribArray(vTextCoord);
var texture = gl.createTexture();
gl.bindTexture(gl.TEXTURE_2D, texture);
// Fill the texture with a 1x1 blue pixel.
gl.texImage2D(
gl.TEXTURE_2D,
0,
gl.RGBA,
1,
1,
0,
gl.RGBA,
gl.UNSIGNED_BYTE,
new Uint8Array([0, 0, 255, 255])
);
gl.bindTexture(gl.TEXTURE_2D, texture);
gl.texImage2D(
gl.TEXTURE_2D,
0,
gl.RGBA,
gl.RGBA,
gl.UNSIGNED_BYTE,
document.getElementById("ground-img")
);
gl.generateMipmap(gl.TEXTURE_2D);
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, GROUND_MESH.indexBuffer);
gl.drawElements(
gl.TRIANGLES,
GROUND_MESH.indexBuffer.numItems,
gl.UNSIGNED_SHORT,
0
);
}
function floorRender() {
//console.log( "girdi" );
instanceMatrix = translate(-0.12, -0.02, 0);
instanceMatrix = mult(instanceMatrix, rotate(30, 0, 1, 0));
instanceMatrix = mult(instanceMatrix, translate(0.12, 0.02, 0));
modelViewMatrix = mult(modelViewMatrix, instanceMatrix);
gl.uniformMatrix4fv(modelViewLoc, false, flatten(modelViewMatrix));
gl.bindBuffer(gl.ARRAY_BUFFER, FLOOR_MESH.vertexBuffer);
gl.vertexAttribPointer(
vPosition,
FLOOR_MESH.vertexBuffer.itemSize,
gl.FLOAT,
false,
0,
0
);
gl.enableVertexAttribArray(vPosition);
gl.bindBuffer(gl.ARRAY_BUFFER, FLOOR_MESH.textureBuffer);
gl.vertexAttribPointer(vTextCoord, 2, gl.FLOAT, false, 0, 0);
gl.enableVertexAttribArray(vTextCoord);
var texture = gl.createTexture();
gl.bindTexture(gl.TEXTURE_2D, texture);
// Fill the texture with a 1x1 blue pixel.
gl.texImage2D(
gl.TEXTURE_2D,
0,
gl.RGBA,
1,
1,
0,
gl.RGBA,
gl.UNSIGNED_BYTE,
new Uint8Array([0, 0, 255, 255])
);
gl.bindTexture(gl.TEXTURE_2D, texture);
gl.texImage2D(
gl.TEXTURE_2D,
0,
gl.RGBA,
gl.RGBA,
gl.UNSIGNED_BYTE,
document.getElementById("floor-img")
);
gl.generateMipmap(gl.TEXTURE_2D);
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, FLOOR_MESH.indexBuffer);
gl.drawElements(
gl.TRIANGLES,
FLOOR_MESH.indexBuffer.numItems,
gl.UNSIGNED_SHORT,
0
);
}
function bodyRender() {
instanceMatrix = rotate(60, 1, 0, 0);
instanceMatrix = mult(
instanceMatrix,
translate(slider_bodyX, slider_bodyY - 0.5, slider_bodyZ)
);
instanceMatrix = mult(instanceMatrix, rotate(slider_bodyRY, 0, 1, 0));
modelViewMatrix = mult(modelViewMatrix, instanceMatrix);
gl.uniformMatrix4fv(modelViewLoc, false, flatten(modelViewMatrix));
gl.bindBuffer(gl.ARRAY_BUFFER, BODY_MESH.vertexBuffer);
gl.vertexAttribPointer(
vPosition,
BODY_MESH.vertexBuffer.itemSize,
gl.FLOAT,
false,
0,
0
);
gl.enableVertexAttribArray(vPosition);
//console.log("reached3");
gl.bindBuffer(gl.ARRAY_BUFFER, BODY_MESH.textureBuffer);
gl.vertexAttribPointer(vTextCoord, 2, gl.FLOAT, false, 0, 0);
gl.enableVertexAttribArray(vTextCoord);
var texture = gl.createTexture();
gl.bindTexture(gl.TEXTURE_2D, texture);
// Fill the texture with a 1x1 blue pixel.
gl.texImage2D(
gl.TEXTURE_2D,
0,
gl.RGBA,
1,
1,
0,
gl.RGBA,
gl.UNSIGNED_BYTE,
new Uint8Array([0, 0, 255, 255])
);
//console.log("reached1");
gl.bindTexture(gl.TEXTURE_2D, texture);
gl.texImage2D(
gl.TEXTURE_2D,
0,
gl.RGBA,
gl.RGBA,
gl.UNSIGNED_BYTE,
document.getElementById("body-img")
);
gl.generateMipmap(gl.TEXTURE_2D);
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, BODY_MESH.indexBuffer);
gl.drawElements(
gl.TRIANGLES,
BODY_MESH.indexBuffer.numItems,
gl.UNSIGNED_SHORT,
0
);
}
function tail1Render() {
instanceMatrix = translate(-0.3, 0.075, 0);
instanceMatrix = mult(instanceMatrix, rotate(thetaAngle[TAIL1_ID], 0, 0, 1));
instanceMatrix = mult(instanceMatrix, translate(0.3, -0.075, 0));
modelViewMatrix = mult(modelViewMatrix, instanceMatrix);
gl.uniformMatrix4fv(modelViewLoc, false, flatten(modelViewMatrix));
gl.bindBuffer(gl.ARRAY_BUFFER, TAIL1_MESH.vertexBuffer);
gl.vertexAttribPointer(
vPosition,
TAIL1_MESH.vertexBuffer.itemSize,
gl.FLOAT,
false,
0,
0
);
gl.enableVertexAttribArray(vPosition);
gl.bindBuffer(gl.ARRAY_BUFFER, TAIL1_MESH.textureBuffer);
gl.vertexAttribPointer(vTextCoord, 2, gl.FLOAT, false, 0, 0);
gl.enableVertexAttribArray(vTextCoord);
var texture = gl.createTexture();
gl.bindTexture(gl.TEXTURE_2D, texture);
// Fill the texture with a 1x1 blue pixel.
gl.texImage2D(
gl.TEXTURE_2D,
0,
gl.RGBA,
1,
1,
0,
gl.RGBA,
gl.UNSIGNED_BYTE,
new Uint8Array([0, 0, 255, 255])
);
gl.bindTexture(gl.TEXTURE_2D, texture);
gl.texImage2D(
gl.TEXTURE_2D,
0,
gl.RGBA,
gl.RGBA,
gl.UNSIGNED_BYTE,
document.getElementById("neck-img")
);
gl.generateMipmap(gl.TEXTURE_2D);
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, TAIL1_MESH.indexBuffer);
gl.drawElements(
gl.TRIANGLES,
TAIL1_MESH.indexBuffer.numItems,
gl.UNSIGNED_SHORT,
0
);
}
function tail2Render() {
instanceMatrix = translate(-0.12, -0.02, 0);
instanceMatrix = mult(instanceMatrix, rotate(thetaAngle[TAIL2_ID], 0, 0, 1));
instanceMatrix = mult(instanceMatrix, translate(0.12, 0.02, 0));
modelViewMatrix = mult(modelViewMatrix, instanceMatrix);
gl.uniformMatrix4fv(modelViewLoc, false, flatten(modelViewMatrix));
gl.bindBuffer(gl.ARRAY_BUFFER, TAIL2_MESH.vertexBuffer);
gl.vertexAttribPointer(
vPosition,
TAIL2_MESH.vertexBuffer.itemSize,
gl.FLOAT,
false,
0,
0
);
gl.enableVertexAttribArray(vPosition);
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, TAIL2_MESH.indexBuffer);
gl.drawElements(
gl.TRIANGLES,
TAIL2_MESH.indexBuffer.numItems,
gl.UNSIGNED_SHORT,
0
);
}
function tail3Render() {
instanceMatrix = translate(-0.1, -0.07, 0);
instanceMatrix = mult(instanceMatrix, rotate(thetaAngle[TAIL3_ID], 0, 0, 1));
instanceMatrix = mult(instanceMatrix, translate(0.1, 0.07, 0));
modelViewMatrix = mult(modelViewMatrix, instanceMatrix);
gl.uniformMatrix4fv(modelViewLoc, false, flatten(modelViewMatrix));
gl.bindBuffer(gl.ARRAY_BUFFER, TAIL3_MESH.vertexBuffer);
gl.vertexAttribPointer(
vPosition,
TAIL3_MESH.vertexBuffer.itemSize,
gl.FLOAT,
false,
0,
0
);
gl.enableVertexAttribArray(vPosition);
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, TAIL3_MESH.indexBuffer);
gl.drawElements(
gl.TRIANGLES,
TAIL3_MESH.indexBuffer.numItems,
gl.UNSIGNED_SHORT,
0
);
}
function tail4Render() {
instanceMatrix = translate(-0.07, -0.04, 0);
instanceMatrix = mult(instanceMatrix, rotate(thetaAngle[TAIL4_ID], 0, 0, 1));
instanceMatrix = mult(instanceMatrix, translate(0.07, 0.04, 0));
modelViewMatrix = mult(modelViewMatrix, instanceMatrix);
gl.uniformMatrix4fv(modelViewLoc, false, flatten(modelViewMatrix));
gl.bindBuffer(gl.ARRAY_BUFFER, TAIL4_MESH.vertexBuffer);
gl.vertexAttribPointer(
vPosition,
TAIL4_MESH.vertexBuffer.itemSize,
gl.FLOAT,
false,
0,
0
);
gl.enableVertexAttribArray(vPosition);
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, TAIL4_MESH.indexBuffer);
gl.drawElements(
gl.TRIANGLES,
TAIL4_MESH.indexBuffer.numItems,
gl.UNSIGNED_SHORT,
0
);
}
function neck11Render() {
instanceMatrix = translate(0.03, -0.08, 2);
// Angle value
instanceMatrix = mult(instanceMatrix, rotate(thetaAngle[NECK11_ID], 0, 0, 1));
instanceMatrix = mult(instanceMatrix, translate(-0.03, 0.08, -2));
modelViewMatrix = mult(modelViewMatrix, instanceMatrix);
gl.uniformMatrix4fv(modelViewLoc, false, flatten(modelViewMatrix));
gl.bindBuffer(gl.ARRAY_BUFFER, NECK11_MESH.vertexBuffer);
gl.vertexAttribPointer(
vPosition,
NECK11_MESH.vertexBuffer.itemSize,
gl.FLOAT,
false,
0,
0
);
gl.enableVertexAttribArray(vPosition);
gl.bindBuffer(gl.ARRAY_BUFFER, NECK11_MESH.textureBuffer);
gl.vertexAttribPointer(vTextCoord, 2, gl.FLOAT, false, 0, 0);
gl.enableVertexAttribArray(vTextCoord);
var texture = gl.createTexture();
gl.bindTexture(gl.TEXTURE_2D, texture);
// Fill the texture with a 1x1 blue pixel.
gl.texImage2D(
gl.TEXTURE_2D,
0,
gl.RGBA,
1,
1,
0,
gl.RGBA,
gl.UNSIGNED_BYTE,
new Uint8Array([0, 0, 255, 255])
);
gl.bindTexture(gl.TEXTURE_2D, texture);
gl.texImage2D(
gl.TEXTURE_2D,
0,
gl.RGBA,
gl.RGBA,
gl.UNSIGNED_BYTE,
document.getElementById("neck-img")
);
gl.generateMipmap(gl.TEXTURE_2D);
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, NECK11_MESH.indexBuffer);
gl.drawElements(
gl.TRIANGLES,
NECK11_MESH.indexBuffer.numItems,
gl.UNSIGNED_SHORT,
0
);
}
function neck21Render() {
instanceMatrix = translate(0.03, -0.08, 2);
// Angle value
instanceMatrix = mult(instanceMatrix, rotate(thetaAngle[NECK21_ID], 0, 0, 1));
instanceMatrix = mult(instanceMatrix, translate(-0.03, 0.08, -2));
modelViewMatrix = mult(modelViewMatrix, instanceMatrix);
gl.uniformMatrix4fv(modelViewLoc, false, flatten(modelViewMatrix));
gl.bindBuffer(gl.ARRAY_BUFFER, NECK21_MESH.vertexBuffer);
gl.vertexAttribPointer(
vPosition,
NECK21_MESH.vertexBuffer.itemSize,
gl.FLOAT,
false,
0,
0
);
gl.enableVertexAttribArray(vPosition);
gl.bindBuffer(gl.ARRAY_BUFFER, NECK21_MESH.textureBuffer);
gl.vertexAttribPointer(vTextCoord, 2, gl.FLOAT, false, 0, 0);
gl.enableVertexAttribArray(vTextCoord);
var texture = gl.createTexture();
gl.bindTexture(gl.TEXTURE_2D, texture);
// Fill the texture with a 1x1 blue pixel.
gl.texImage2D(
gl.TEXTURE_2D,
0,
gl.RGBA,
1,
1,
0,
gl.RGBA,
gl.UNSIGNED_BYTE,
new Uint8Array([0, 0, 255, 255])
);
gl.bindTexture(gl.TEXTURE_2D, texture);
gl.texImage2D(
gl.TEXTURE_2D,
0,
gl.RGBA,
gl.RGBA,
gl.UNSIGNED_BYTE,
document.getElementById("neck-img")
);
gl.generateMipmap(gl.TEXTURE_2D);
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, NECK21_MESH.indexBuffer);
gl.drawElements(
gl.TRIANGLES,
NECK21_MESH.indexBuffer.numItems,
gl.UNSIGNED_SHORT,
0
);
}
function neck31Render() {
instanceMatrix = translate(0.03, -0.08, 2);
// Angle value
instanceMatrix = mult(instanceMatrix, rotate(thetaAngle[NECK31_ID], 0, 0, 1));
instanceMatrix = mult(instanceMatrix, translate(-0.03, 0.08, -2));
modelViewMatrix = mult(modelViewMatrix, instanceMatrix);
gl.uniformMatrix4fv(modelViewLoc, false, flatten(modelViewMatrix));
gl.bindBuffer(gl.ARRAY_BUFFER, NECK31_MESH.vertexBuffer);
gl.vertexAttribPointer(
vPosition,
NECK31_MESH.vertexBuffer.itemSize,
gl.FLOAT,
false,
0,
0
);
gl.enableVertexAttribArray(vPosition);
gl.bindBuffer(gl.ARRAY_BUFFER, NECK31_MESH.textureBuffer);
gl.vertexAttribPointer(vTextCoord, 2, gl.FLOAT, false, 0, 0);
gl.enableVertexAttribArray(vTextCoord);
var texture = gl.createTexture();
gl.bindTexture(gl.TEXTURE_2D, texture);
// Fill the texture with a 1x1 blue pixel.
gl.texImage2D(
gl.TEXTURE_2D,
0,
gl.RGBA,
1,
1,
0,
gl.RGBA,
gl.UNSIGNED_BYTE,
new Uint8Array([0, 0, 255, 255])
);
gl.bindTexture(gl.TEXTURE_2D, texture);
gl.texImage2D(
gl.TEXTURE_2D,
0,
gl.RGBA,
gl.RGBA,
gl.UNSIGNED_BYTE,
document.getElementById("neck-img")
);
gl.generateMipmap(gl.TEXTURE_2D);
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, NECK31_MESH.indexBuffer);
gl.drawElements(
gl.TRIANGLES,
NECK31_MESH.indexBuffer.numItems,
gl.UNSIGNED_SHORT,
0
);
}
function neck12Render() {
instanceMatrix = mat4();
instanceMatrix = translate(0.05, -0.1, 0);
instanceMatrix = mult(instanceMatrix, rotate(thetaAngle[NECK12_ID], 0, 0, 1));
instanceMatrix = mult(instanceMatrix, translate(-0.05, 0.1, 0));
instanceMatrix = mult(instanceMatrix, scale4(0.7, 0.7, 0.7));
modelViewMatrix = mult(modelViewMatrix, instanceMatrix);
gl.uniformMatrix4fv(modelViewLoc, false, flatten(modelViewMatrix));
gl.bindBuffer(gl.ARRAY_BUFFER, NECK12_MESH.vertexBuffer);
gl.enableVertexAttribArray(vPosition);
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, NECK21_MESH.indexBuffer);
gl.drawElements(
gl.TRIANGLES,
NECK21_MESH.indexBuffer.numItems,
gl.UNSIGNED_SHORT,
0
);
}
function neck22Render() {
instanceMatrix = mat4();
instanceMatrix = translate(0.05, -0.1, 0);
instanceMatrix = mult(instanceMatrix, rotate(thetaAngle[NECK22_ID], 0, 0, 1));
instanceMatrix = mult(instanceMatrix, translate(-0.05, 0.1, 0));
modelViewMatrix = mult(modelViewMatrix, instanceMatrix);
gl.uniformMatrix4fv(modelViewLoc, false, flatten(modelViewMatrix));
gl.bindBuffer(gl.ARRAY_BUFFER, NECK22_MESH.vertexBuffer);
gl.vertexAttribPointer(
vPosition,
NECK22_MESH.vertexBuffer.itemSize,
gl.FLOAT,
false,
0,
0
);
gl.enableVertexAttribArray(vPosition);
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, NECK22_MESH.indexBuffer);
gl.drawElements(
gl.TRIANGLES,
NECK22_MESH.indexBuffer.numItems,
gl.UNSIGNED_SHORT,
0
);
}
function neck32Render() {
instanceMatrix = mat4();
instanceMatrix = translate(0.05, -0.1, 0);
instanceMatrix = mult(instanceMatrix, rotate(thetaAngle[NECK32_ID], 0, 0, 1));
instanceMatrix = mult(instanceMatrix, translate(-0.05, 0.1, 0));
modelViewMatrix = mult(modelViewMatrix, instanceMatrix);
gl.uniformMatrix4fv(modelViewLoc, false, flatten(modelViewMatrix));
gl.bindBuffer(gl.ARRAY_BUFFER, NECK32_MESH.vertexBuffer);
gl.vertexAttribPointer(
vPosition,
NECK32_MESH.vertexBuffer.itemSize,
gl.FLOAT,
false,
0,
0
);
gl.enableVertexAttribArray(vPosition);
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, NECK32_MESH.indexBuffer);
gl.drawElements(
gl.TRIANGLES,
NECK32_MESH.indexBuffer.numItems,
gl.UNSIGNED_SHORT,
0
);
}
function neck13Render() {
instanceMatrix = mat4();
instanceMatrix = translate(0.03, -0.05, 0);
instanceMatrix = mult(instanceMatrix, rotate(thetaAngle[NECK13_ID], 0, 0, 1));
instanceMatrix = mult(instanceMatrix, translate(-0.03, 0.05, 0));
instanceMatrix = mult(instanceMatrix, scale4(1.4, 1.4, 1.4));
modelViewMatrix = mult(modelViewMatrix, instanceMatrix);
gl.uniformMatrix4fv(modelViewLoc, false, flatten(modelViewMatrix));
gl.bindBuffer(gl.ARRAY_BUFFER, NECK13_MESH.vertexBuffer);
gl.vertexAttribPointer(
vPosition,
NECK13_MESH.vertexBuffer.itemSize,