質問編集履歴
13
タイトルを修正
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
GLSLで画面描画に使う行列
|
1
|
+
GLSLで画面描画に使う行列でZ軸の値がおかしくなる原因が知りたい
|
test
CHANGED
File without changes
|
12
提示コードを修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -456,7 +456,7 @@
|
|
456
456
|
|
457
457
|
|
458
458
|
|
459
|
-
pos.x = 1;
|
459
|
+
pos.x = 1.0f;
|
460
460
|
|
461
461
|
pos.y = 0;
|
462
462
|
|
@@ -464,39 +464,39 @@
|
|
464
464
|
|
465
465
|
|
466
466
|
|
467
|
-
pos.w = 1;
|
467
|
+
pos.w = 1.0f;
|
468
|
-
|
468
|
+
|
469
|
-
float r = 1;
|
469
|
+
float r = 1.0f;
|
470
470
|
|
471
471
|
|
472
472
|
|
473
473
|
float rotate[16] = {
|
474
474
|
|
475
|
-
(pos.x * pos.x
|
475
|
+
(pos.x * pos.x * (1 - cos(r)) + cos(r)),
|
476
|
-
|
476
|
+
|
477
|
-
(pos.x * pos.y * (
|
477
|
+
(pos.x * pos.y * (1 - cos(r)) - (pos.z * sin(r))),
|
478
|
-
|
478
|
+
|
479
|
-
(
|
479
|
+
(pos.x * pos.z * (1 - cos(r)) + (pos.y * sin(r))),
|
480
480
|
|
481
481
|
0,
|
482
482
|
|
483
483
|
|
484
484
|
|
485
|
-
(pos.x * pos.
|
485
|
+
(pos.x * pos.y * (1 - cos(r)) + (pos.z * sin(r))),
|
486
|
-
|
486
|
+
|
487
|
-
(pos.y * pos.y * (1
|
487
|
+
(pos.y * pos.y * (1 - cos(r)) + cos(r)),
|
488
|
-
|
488
|
+
|
489
|
-
(pos.y * pos.z * (1
|
489
|
+
(pos.y * pos.z * (1 - cos(r)) - (pos.x * sin(r))),
|
490
490
|
|
491
491
|
0,
|
492
492
|
|
493
493
|
|
494
494
|
|
495
|
-
(pos.x * pos.z * (1
|
495
|
+
(pos.x * pos.z * (1 - cos(r)) - (pos.y * sin(r))),
|
496
|
-
|
496
|
+
|
497
|
-
(pos.y * pos.z * (1
|
497
|
+
(pos.y * pos.z * (1 - cos(r)) + (pos.x * sin(r))),
|
498
|
-
|
498
|
+
|
499
|
-
(pos.
|
499
|
+
(pos.z * pos.z * (1 - cos(r)) + cos(r)),
|
500
500
|
|
501
501
|
0,
|
502
502
|
|
@@ -504,16 +504,12 @@
|
|
504
504
|
|
505
505
|
0,0,0,1
|
506
506
|
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
507
|
};
|
514
508
|
|
515
509
|
|
516
510
|
|
511
|
+
// print_(rotate);
|
512
|
+
|
517
513
|
|
518
514
|
|
519
515
|
//平行移動
|
@@ -534,18 +530,30 @@
|
|
534
530
|
|
535
531
|
{
|
536
532
|
|
537
|
-
1,0,0,p.x,
|
538
|
-
|
539
|
-
0,1,0,p.y,
|
540
|
-
|
541
|
-
0,0,1,p.z,
|
542
|
-
|
543
|
-
0,0,0,
|
533
|
+
1,0,0,0,
|
534
|
+
|
535
|
+
0,1,0,0,
|
536
|
+
|
537
|
+
0,0,1,0,
|
538
|
+
|
539
|
+
p.x,p.y,p.z,1,
|
544
540
|
|
545
541
|
};
|
546
542
|
|
547
543
|
|
548
544
|
|
545
|
+
// print_(move);
|
546
|
+
|
547
|
+
|
548
|
+
|
549
|
+
float t[16];
|
550
|
+
|
551
|
+
mul(rotate, move, t);
|
552
|
+
|
553
|
+
// print_(t);
|
554
|
+
|
555
|
+
|
556
|
+
|
549
557
|
//スケール行列
|
550
558
|
|
551
559
|
float scale[16] = {
|
@@ -562,27 +570,21 @@
|
|
562
570
|
|
563
571
|
|
564
572
|
|
565
|
-
|
573
|
+
print_(scale);
|
566
|
-
|
567
|
-
|
568
|
-
|
569
|
-
|
570
|
-
|
574
|
+
|
575
|
+
|
576
|
+
|
571
|
-
float t[16];
|
577
|
+
float t2[16];
|
572
|
-
|
573
|
-
|
578
|
+
|
574
|
-
|
575
|
-
// print_(t);
|
576
|
-
|
577
|
-
|
578
|
-
|
579
|
-
|
580
|
-
|
581
|
-
float t2[16];//M
|
582
|
-
|
583
|
-
mul
|
579
|
+
mul(scale, t, t2);
|
584
|
-
|
580
|
+
|
585
|
-
|
581
|
+
print_(t);
|
582
|
+
|
583
|
+
|
584
|
+
|
585
|
+
|
586
|
+
|
587
|
+
|
586
588
|
|
587
589
|
|
588
590
|
|
@@ -594,9 +596,9 @@
|
|
594
596
|
|
595
597
|
float t3[16];
|
596
598
|
|
597
|
-
mul
|
599
|
+
mul(Vertex[i], t2, t3);
|
598
|
-
|
600
|
+
|
599
|
-
|
601
|
+
// print_(t2);
|
600
602
|
|
601
603
|
|
602
604
|
|
@@ -604,9 +606,9 @@
|
|
604
606
|
|
605
607
|
float t4[16];
|
606
608
|
|
607
|
-
mul
|
609
|
+
mul(mp, t2, t4);
|
608
|
-
|
610
|
+
|
609
|
-
|
611
|
+
// print_(t4);
|
610
612
|
|
611
613
|
}
|
612
614
|
|
11
提示コードを編集しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -454,18 +454,6 @@
|
|
454
454
|
|
455
455
|
struct position pos;
|
456
456
|
|
457
|
-
/*
|
458
|
-
|
459
|
-
pos.x = Vertex[0][0] * (cos(0) / 2);
|
460
|
-
|
461
|
-
pos.y = Vertex[0][1] * (sin(0) / 2);
|
462
|
-
|
463
|
-
pos.z = Vertex[0][2] * (sin(0) / 2);
|
464
|
-
|
465
|
-
pos.w = Vertex[0][3] * cos(0) / 2;
|
466
|
-
|
467
|
-
*/
|
468
|
-
|
469
457
|
|
470
458
|
|
471
459
|
pos.x = 1;
|
@@ -474,145 +462,195 @@
|
|
474
462
|
|
475
463
|
pos.z = 0;
|
476
464
|
|
465
|
+
|
466
|
+
|
477
467
|
pos.w = 1;
|
478
468
|
|
479
469
|
float r = 1;
|
480
470
|
|
481
|
-
|
471
|
+
|
482
472
|
|
483
473
|
float rotate[16] = {
|
484
474
|
|
485
|
-
|
486
|
-
|
487
|
-
( 1 - (2 * pos.y * pos.y) - (2 * pos.z * pos.z)),
|
488
|
-
|
489
|
-
((2 * pos.x * pos.y) + (2 * pos.w * pos.z) ),
|
490
|
-
|
491
|
-
((2 * pos.x * pos.z) - (2 * pos.w * pos.y))
|
492
|
-
|
493
|
-
,0
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
(1 - (2 * pos.z * pos.y) - (2 * pos.w * pos.z)),
|
500
|
-
|
501
|
-
(1 - (2 * pos.x * pos.x) - (2 * pos.z * pos.z)),
|
502
|
-
|
503
|
-
((2 * pos.y * pos.z) + (2 * pos.w * pos.x))
|
504
|
-
|
505
|
-
,0
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
(
|
475
|
+
(pos.x * pos.x * (1 * -cos(r)) * -cos(r)),
|
476
|
+
|
510
|
-
|
477
|
+
(pos.x * pos.y * ( 1 * -cos(r) + (pos.z * sin(r))) ),
|
478
|
+
|
479
|
+
( pos.x * pos.z *(1 * -cos(r)) - (pos.y * sin(r)) ),
|
480
|
+
|
481
|
+
0,
|
482
|
+
|
483
|
+
|
484
|
+
|
485
|
+
(pos.x * pos.x * (1 * -cos(r)) * (-pos.z * sin(r)) ),
|
486
|
+
|
511
|
-
(
|
487
|
+
(pos.y * pos.y * (1 * -cos(r) + cos(r))),
|
488
|
+
|
512
|
-
|
489
|
+
(pos.y * pos.z * (1 * -cos(r)) * (-pos.x * sin(r)) ),
|
490
|
+
|
491
|
+
0,
|
492
|
+
|
493
|
+
|
494
|
+
|
495
|
+
(pos.x * pos.z * (1 * -cos(r)) * (+pos.y * sin(r)) ),
|
496
|
+
|
497
|
+
(pos.y * pos.z * (1 * -cos(r) * (pos.x * sin(r))) ),
|
498
|
+
|
513
|
-
(
|
499
|
+
(pos.x * pos.x * (1 * -cos(r)) + cos(r)),
|
514
|
-
|
500
|
+
|
515
|
-
,
|
501
|
+
0,
|
516
|
-
|
517
|
-
|
518
|
-
|
502
|
+
|
503
|
+
|
504
|
+
|
519
|
-
|
505
|
+
0,0,0,1
|
506
|
+
|
507
|
+
|
508
|
+
|
509
|
+
|
520
510
|
|
521
511
|
|
522
512
|
|
523
513
|
};
|
524
514
|
|
515
|
+
|
516
|
+
|
517
|
+
|
518
|
+
|
525
|
-
|
519
|
+
//平行移動
|
520
|
+
|
526
|
-
|
521
|
+
struct position p;
|
522
|
+
|
527
|
-
|
523
|
+
p.x = 0;
|
524
|
+
|
528
|
-
|
525
|
+
p.y = 0;
|
526
|
+
|
527
|
+
p.z = 0;
|
528
|
+
|
529
|
+
p.w = 1;
|
530
|
+
|
531
|
+
|
532
|
+
|
533
|
+
float move[16] =
|
534
|
+
|
535
|
+
{
|
536
|
+
|
537
|
+
1,0,0,p.x,
|
538
|
+
|
539
|
+
0,1,0,p.y,
|
540
|
+
|
541
|
+
0,0,1,p.z,
|
542
|
+
|
543
|
+
0,0,0,1,
|
544
|
+
|
545
|
+
};
|
546
|
+
|
547
|
+
|
548
|
+
|
549
|
+
//スケール行列
|
550
|
+
|
529
|
-
float
|
551
|
+
float scale[16] = {
|
530
|
-
|
531
|
-
|
552
|
+
|
532
|
-
|
533
|
-
(pos.x * pos.y * ( 1 - cos(r) + (pos.z * sin(r))) ),
|
534
|
-
|
535
|
-
( pos.x * pos.z *(1 - cos(r)) - (pos.y * sin(r)) ),
|
536
|
-
|
537
|
-
0,
|
553
|
+
1,0,0,0,
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
|
554
|
+
|
542
|
-
|
543
|
-
(pos.y * pos.y * (1 - cos(r) + cos(r))),
|
544
|
-
|
545
|
-
(pos.y * pos.z * (1 - cos(r)) * (-pos.x * sin(r)) ),
|
546
|
-
|
547
|
-
0,
|
555
|
+
0,1,0,0,
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
556
|
+
|
552
|
-
|
553
|
-
(pos.y * pos.z * (1 - cos(r) * (pos.x * sin(r))) ),
|
554
|
-
|
555
|
-
(pos.x * pos.x * (1 - cos(r)) + cos(r)),
|
556
|
-
|
557
|
-
0,
|
557
|
+
0,0,1,0,
|
558
|
-
|
559
|
-
|
560
558
|
|
561
559
|
0,0,0,1
|
562
560
|
|
563
|
-
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
|
568
|
-
|
569
561
|
};
|
570
562
|
|
571
563
|
|
572
564
|
|
573
565
|
|
574
566
|
|
575
|
-
|
567
|
+
|
576
|
-
|
577
|
-
|
568
|
+
|
578
|
-
|
579
|
-
|
569
|
+
|
580
|
-
|
581
|
-
|
570
|
+
|
582
|
-
|
583
|
-
p.z = 0;
|
584
|
-
|
585
|
-
p.w = 1;
|
586
|
-
|
587
|
-
|
588
|
-
|
589
|
-
float
|
571
|
+
float t[16];
|
572
|
+
|
573
|
+
mul_A_B(rotate, move, t);
|
574
|
+
|
575
|
+
// print_(t);
|
576
|
+
|
577
|
+
|
578
|
+
|
579
|
+
|
580
|
+
|
581
|
+
float t2[16];//M
|
582
|
+
|
583
|
+
mul_A_B(scale, t, t2);
|
584
|
+
|
585
|
+
print_(t2);
|
586
|
+
|
587
|
+
|
588
|
+
|
589
|
+
|
590
|
+
|
591
|
+
for (int i = 0; i < 6; i++)
|
590
592
|
|
591
593
|
{
|
592
594
|
|
593
|
-
1
|
595
|
+
float t3[16];
|
596
|
+
|
594
|
-
|
597
|
+
mul_A_B(Vertex[i], t2, t3);
|
598
|
+
|
599
|
+
// print_(t2);
|
600
|
+
|
601
|
+
|
602
|
+
|
603
|
+
|
604
|
+
|
605
|
+
float t4[16];
|
606
|
+
|
607
|
+
mul_A_B(mp, t2, t4);
|
608
|
+
|
609
|
+
// print_(t4);
|
610
|
+
|
611
|
+
}
|
612
|
+
|
613
|
+
|
614
|
+
|
615
|
+
|
616
|
+
|
617
|
+
float a[16] =
|
618
|
+
|
619
|
+
{
|
620
|
+
|
595
|
-
0,
|
621
|
+
0,3,2,5,
|
596
|
-
|
597
|
-
|
622
|
+
|
598
|
-
|
599
|
-
0,
|
623
|
+
0,2,2,1,
|
624
|
+
|
625
|
+
|
626
|
+
|
627
|
+
0,7,4,3,
|
628
|
+
|
629
|
+
0,3,3,7,
|
630
|
+
|
631
|
+
|
600
632
|
|
601
633
|
};
|
602
634
|
|
603
635
|
|
604
636
|
|
605
|
-
|
637
|
+
|
606
|
-
|
638
|
+
|
607
|
-
float
|
639
|
+
float b[16] =
|
608
|
-
|
640
|
+
|
609
|
-
|
641
|
+
{
|
610
|
-
|
642
|
+
|
611
|
-
0,
|
643
|
+
0,3,5,5,
|
612
|
-
|
644
|
+
|
613
|
-
0,
|
645
|
+
0,5,8,6,
|
614
|
-
|
646
|
+
|
647
|
+
|
648
|
+
|
615
|
-
|
649
|
+
8,7,3,3,
|
650
|
+
|
651
|
+
5,8,3,8,
|
652
|
+
|
653
|
+
|
616
654
|
|
617
655
|
};
|
618
656
|
|
@@ -620,105 +658,11 @@
|
|
620
658
|
|
621
659
|
|
622
660
|
|
623
|
-
|
624
|
-
|
625
|
-
|
626
|
-
|
627
|
-
|
628
|
-
|
629
|
-
float t[16];
|
630
|
-
|
631
|
-
mul_A_B(rotate, move, t);
|
632
|
-
|
633
|
-
// print_(t);
|
634
|
-
|
635
|
-
|
636
|
-
|
637
|
-
|
638
|
-
|
639
|
-
float t2[16];//M
|
640
|
-
|
641
|
-
mul_A_B(scale, t, t2);
|
642
|
-
|
643
|
-
// print_(t2);
|
644
|
-
|
645
|
-
|
646
|
-
|
647
|
-
for (int i = 0; i < 6; i++)
|
648
|
-
|
649
|
-
{
|
650
|
-
|
651
|
-
float t3[16];
|
652
|
-
|
653
|
-
mul_A_B(Vertex[i], t2, t3);
|
654
|
-
|
655
|
-
// print_(t2);
|
656
|
-
|
657
|
-
|
658
|
-
|
659
|
-
|
660
|
-
|
661
|
-
float t4[16];
|
662
|
-
|
663
|
-
mul_A_B(mp, t2, t4);
|
664
|
-
|
665
|
-
print_(t4);
|
666
|
-
|
667
|
-
}
|
668
|
-
|
669
|
-
|
670
|
-
|
671
|
-
|
672
|
-
|
673
|
-
float a[16] =
|
674
|
-
|
675
|
-
{
|
676
|
-
|
677
|
-
0,3,2,5,
|
678
|
-
|
679
|
-
0,2,2,1,
|
680
|
-
|
681
|
-
|
682
|
-
|
683
|
-
0,7,4,3,
|
684
|
-
|
685
|
-
0,3,3,7,
|
686
|
-
|
687
|
-
|
688
|
-
|
689
|
-
};
|
690
|
-
|
691
|
-
|
692
|
-
|
693
|
-
|
694
|
-
|
695
|
-
float b[16] =
|
696
|
-
|
697
|
-
{
|
698
|
-
|
699
|
-
0,3,5,5,
|
700
|
-
|
701
|
-
0,5,8,6,
|
702
|
-
|
703
|
-
|
704
|
-
|
705
|
-
8,7,3,3,
|
706
|
-
|
707
|
-
5,8,3,8,
|
708
|
-
|
709
|
-
|
710
|
-
|
711
|
-
};
|
712
|
-
|
713
|
-
|
714
|
-
|
715
|
-
|
716
|
-
|
717
661
|
float c[16] = { 0 };
|
718
662
|
|
719
663
|
|
720
664
|
|
721
|
-
mul_A_B(a,b,c);
|
665
|
+
//mul_A_B(a,b,c);
|
722
666
|
|
723
667
|
|
724
668
|
|
10
文章を再度編集しました。
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
GLSLで画面描画に使う行列で
|
1
|
+
GLSLで画面描画に使う行列 ロドリゲス回転行列で何を誤ったのか知りたい。
|
test
CHANGED
@@ -2,11 +2,7 @@
|
|
2
2
|
|
3
3
|
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
5
|
+
追記 ロドリゲス回転行列がおかしいとの修正依頼を多数受けまして自分なりに修正しましたがもうどうしてもわかりません何をしたのか教えてくれますでしょうか?printf();でデバッグするとどうやらrotateの部分で値がおかしいためすべて狂ってるみたいです。
|
10
6
|
|
11
7
|
|
12
8
|
|
9
文章を編集
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
GLSLで画面描画に使う行列
|
1
|
+
GLSLで画面描画に使う行列でZ軸がおかしくなる原因と対処法が知りたい
|
test
CHANGED
@@ -330,6 +330,60 @@
|
|
330
330
|
|
331
331
|
|
332
332
|
|
333
|
+
//行列計算 a x b
|
334
|
+
|
335
|
+
void mul_A_B(float a[16], float b[16], float result[16])
|
336
|
+
|
337
|
+
{
|
338
|
+
|
339
|
+
result[0] = (a[0] * b[0]) + (a[1] * b[4]) + (a[2] * b[8] ) + (a[3] * b[12]);
|
340
|
+
|
341
|
+
result[1] = (a[0] * b[1]) + (a[1] * b[5]) + (a[2] * b[9] ) + (a[3] * b[13]);
|
342
|
+
|
343
|
+
result[2] = (a[0] * b[2]) + (a[1] * b[6]) + (a[2] * b[10]) + (a[3] * b[14]);
|
344
|
+
|
345
|
+
result[3] = (a[0] * b[3]) + (a[1] * b[7]) + (a[2] * b[11]) + (a[3] * b[15]);
|
346
|
+
|
347
|
+
|
348
|
+
|
349
|
+
result[4] = (a[4] * b[0]) + (a[5] * b[4]) + (a[6] * b[8]) + (a[7] * b[12]);
|
350
|
+
|
351
|
+
result[5] = (a[4] * b[1]) + (a[5] * b[5]) + (a[6] * b[9]) + (a[7] * b[13]);
|
352
|
+
|
353
|
+
result[6] = (a[4] * b[2]) + (a[5] * b[6]) + (a[6] * b[10]) + (a[7] * b[14]);
|
354
|
+
|
355
|
+
result[7] = (a[4] * b[3]) + (a[5] * b[7]) + (a[6] * b[11]) + (a[7] * b[15]);
|
356
|
+
|
357
|
+
|
358
|
+
|
359
|
+
|
360
|
+
|
361
|
+
result[8] = (a[8] * b[0]) + (a[9] * b[4]) + (a[10] * b[8]) + (a[11] * b[12]);
|
362
|
+
|
363
|
+
result[9] = (a[8] * b[1]) + (a[9] * b[5]) + (a[10] * b[9]) + (a[11] * b[13]);
|
364
|
+
|
365
|
+
result[10] = (a[8] * b[2]) + (a[9] * b[6]) + (a[10] * b[10]) + (a[11] * b[14]);
|
366
|
+
|
367
|
+
result[11] = (a[8] * b[3]) + (a[9] * b[7]) + (a[10] * b[11]) + (a[11] * b[15]);
|
368
|
+
|
369
|
+
|
370
|
+
|
371
|
+
result[12] = (a[12] * b[0]) + (a[13] * b[4]) + (a[14] * b[8]) + (a[15] * b[12]);
|
372
|
+
|
373
|
+
result[13] = (a[12] * b[1]) + (a[13] * b[5]) + (a[14] * b[9]) + (a[15] * b[13]);
|
374
|
+
|
375
|
+
result[14] = (a[12] * b[2]) + (a[13] * b[6]) + (a[14] * b[10]) + (a[15] * b[14]);
|
376
|
+
|
377
|
+
result[15] = (a[12] * b[3]) + (a[13] * b[7]) + (a[14] * b[11]) + (a[15] * b[15]);
|
378
|
+
|
379
|
+
}
|
380
|
+
|
381
|
+
|
382
|
+
|
383
|
+
|
384
|
+
|
385
|
+
|
386
|
+
|
333
387
|
//ベクトルと行列の掛け算
|
334
388
|
|
335
389
|
void mul_vec3_matrix(float m[16], float v[3], float r[3])
|
@@ -578,9 +632,9 @@
|
|
578
632
|
|
579
633
|
float t[16];
|
580
634
|
|
581
|
-
mul(rotate, move, t);
|
635
|
+
mul_A_B(rotate, move, t);
|
582
|
-
|
636
|
+
|
583
|
-
|
637
|
+
// print_(t);
|
584
638
|
|
585
639
|
|
586
640
|
|
@@ -588,9 +642,9 @@
|
|
588
642
|
|
589
643
|
float t2[16];//M
|
590
644
|
|
591
|
-
mul(scale, t, t2);
|
645
|
+
mul_A_B(scale, t, t2);
|
592
|
-
|
646
|
+
|
593
|
-
|
647
|
+
// print_(t2);
|
594
648
|
|
595
649
|
|
596
650
|
|
@@ -600,9 +654,9 @@
|
|
600
654
|
|
601
655
|
float t3[16];
|
602
656
|
|
603
|
-
mul(Vertex[i], t2, t3);
|
657
|
+
mul_A_B(Vertex[i], t2, t3);
|
604
|
-
|
658
|
+
|
605
|
-
|
659
|
+
// print_(t2);
|
606
660
|
|
607
661
|
|
608
662
|
|
@@ -610,9 +664,9 @@
|
|
610
664
|
|
611
665
|
float t4[16];
|
612
666
|
|
613
|
-
mul(mp, t2, t4);
|
667
|
+
mul_A_B(mp, t2, t4);
|
614
|
-
|
668
|
+
|
615
|
-
|
669
|
+
print_(t4);
|
616
670
|
|
617
671
|
}
|
618
672
|
|
@@ -620,6 +674,64 @@
|
|
620
674
|
|
621
675
|
|
622
676
|
|
677
|
+
float a[16] =
|
678
|
+
|
679
|
+
{
|
680
|
+
|
681
|
+
0,3,2,5,
|
682
|
+
|
683
|
+
0,2,2,1,
|
684
|
+
|
685
|
+
|
686
|
+
|
687
|
+
0,7,4,3,
|
688
|
+
|
689
|
+
0,3,3,7,
|
690
|
+
|
691
|
+
|
692
|
+
|
693
|
+
};
|
694
|
+
|
695
|
+
|
696
|
+
|
697
|
+
|
698
|
+
|
699
|
+
float b[16] =
|
700
|
+
|
701
|
+
{
|
702
|
+
|
703
|
+
0,3,5,5,
|
704
|
+
|
705
|
+
0,5,8,6,
|
706
|
+
|
707
|
+
|
708
|
+
|
709
|
+
8,7,3,3,
|
710
|
+
|
711
|
+
5,8,3,8,
|
712
|
+
|
713
|
+
|
714
|
+
|
715
|
+
};
|
716
|
+
|
717
|
+
|
718
|
+
|
719
|
+
|
720
|
+
|
721
|
+
float c[16] = { 0 };
|
722
|
+
|
723
|
+
|
724
|
+
|
725
|
+
mul_A_B(a,b,c);
|
726
|
+
|
727
|
+
|
728
|
+
|
729
|
+
// print_(c);
|
730
|
+
|
731
|
+
|
732
|
+
|
733
|
+
|
734
|
+
|
623
735
|
|
624
736
|
|
625
737
|
return 0;
|
8
提示コードを再度修正しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -404,6 +404,8 @@
|
|
404
404
|
|
405
405
|
struct position pos;
|
406
406
|
|
407
|
+
/*
|
408
|
+
|
407
409
|
pos.x = Vertex[0][0] * (cos(0) / 2);
|
408
410
|
|
409
411
|
pos.y = Vertex[0][1] * (sin(0) / 2);
|
@@ -412,7 +414,17 @@
|
|
412
414
|
|
413
415
|
pos.w = Vertex[0][3] * cos(0) / 2;
|
414
416
|
|
415
|
-
|
417
|
+
*/
|
418
|
+
|
419
|
+
|
420
|
+
|
421
|
+
pos.x = 1;
|
422
|
+
|
423
|
+
pos.y = 0;
|
424
|
+
|
425
|
+
pos.z = 0;
|
426
|
+
|
427
|
+
pos.w = 1;
|
416
428
|
|
417
429
|
float r = 1;
|
418
430
|
|
@@ -466,32 +478,44 @@
|
|
466
478
|
|
467
479
|
float rotate[16] = {
|
468
480
|
|
481
|
+
(pos.x * pos.x * (1 - cos(r)) * -cos(r)),
|
482
|
+
|
483
|
+
(pos.x * pos.y * ( 1 - cos(r) + (pos.z * sin(r))) ),
|
484
|
+
|
485
|
+
( pos.x * pos.z *(1 - cos(r)) - (pos.y * sin(r)) ),
|
486
|
+
|
487
|
+
0,
|
488
|
+
|
489
|
+
|
490
|
+
|
491
|
+
(pos.x * pos.x * (1 - cos(r)) * (-pos.z * sin(r)) ),
|
492
|
+
|
493
|
+
(pos.y * pos.y * (1 - cos(r) + cos(r))),
|
494
|
+
|
495
|
+
(pos.y * pos.z * (1 - cos(r)) * (-pos.x * sin(r)) ),
|
496
|
+
|
497
|
+
0,
|
498
|
+
|
499
|
+
|
500
|
+
|
501
|
+
(pos.x * pos.z * (1 - cos(r)) * (+pos.y * sin(r)) ),
|
502
|
+
|
503
|
+
(pos.y * pos.z * (1 - cos(r) * (pos.x * sin(r))) ),
|
504
|
+
|
469
|
-
(pos.x * pos.x
|
505
|
+
(pos.x * pos.x * (1 - cos(r)) + cos(r)),
|
470
|
-
|
471
|
-
|
506
|
+
|
472
|
-
|
473
|
-
,(pos.x * pos.z + (1 - cos(r)) - pos.y * sin(r)),0,
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
(pos.x * pos.x + (1 - cos(r)) + sin(r)),
|
478
|
-
|
479
|
-
(pos.y * pos.y + (1 - cos(r)) + cos(r)),
|
480
|
-
|
481
|
-
(pos.y * pos.z + (1 - cos(r)) + pos.x * sin(r)),0,
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
(pos.x * pos.z + (1 - cos(r)) - pos.z * sin(r)),
|
486
|
-
|
487
|
-
(pos.y * pos.z + (1 - cos(r)) - pos.x * sin(r)),
|
488
|
-
|
489
|
-
|
507
|
+
0,
|
490
508
|
|
491
509
|
|
492
510
|
|
493
511
|
0,0,0,1
|
494
512
|
|
513
|
+
|
514
|
+
|
515
|
+
|
516
|
+
|
517
|
+
|
518
|
+
|
495
519
|
};
|
496
520
|
|
497
521
|
|
7
提示コードを編集しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -416,6 +416,8 @@
|
|
416
416
|
|
417
417
|
float r = 1;
|
418
418
|
|
419
|
+
/*
|
420
|
+
|
419
421
|
float rotate[16] = {
|
420
422
|
|
421
423
|
|
@@ -444,18 +446,56 @@
|
|
444
446
|
|
445
447
|
((2 * pos.x * pos.z) - (2 * pos.w * pos.z)),
|
446
448
|
|
447
|
-
|
448
|
-
|
449
449
|
((2 * pos.y * pos.z) - (2 * pos.w * pos.z)),
|
450
450
|
|
451
|
-
|
452
|
-
|
453
451
|
(1 - (2 * pos.x * pos.x) - (2 * pos.y * pos.y))
|
454
452
|
|
455
|
-
,
|
453
|
+
,0
|
454
|
+
|
455
|
+
|
456
|
+
|
457
|
+
,0,0,0,1//追記
|
458
|
+
|
459
|
+
|
456
460
|
|
457
461
|
};
|
458
462
|
|
463
|
+
*/
|
464
|
+
|
465
|
+
|
466
|
+
|
467
|
+
float rotate[16] = {
|
468
|
+
|
469
|
+
(pos.x * pos.x + (1 - cos(r)) + cos(r)),
|
470
|
+
|
471
|
+
(pos.x * pos.y + (1 - cos(r)) + pos.z * sin(r))
|
472
|
+
|
473
|
+
,(pos.x * pos.z + (1 - cos(r)) - pos.y * sin(r)),0,
|
474
|
+
|
475
|
+
|
476
|
+
|
477
|
+
(pos.x * pos.x + (1 - cos(r)) + sin(r)),
|
478
|
+
|
479
|
+
(pos.y * pos.y + (1 - cos(r)) + cos(r)),
|
480
|
+
|
481
|
+
(pos.y * pos.z + (1 - cos(r)) + pos.x * sin(r)),0,
|
482
|
+
|
483
|
+
|
484
|
+
|
485
|
+
(pos.x * pos.z + (1 - cos(r)) - pos.z * sin(r)),
|
486
|
+
|
487
|
+
(pos.y * pos.z + (1 - cos(r)) - pos.x * sin(r)),
|
488
|
+
|
489
|
+
(pos.z * pos.z + (1 - cos(r)) + cos(r)),0,
|
490
|
+
|
491
|
+
|
492
|
+
|
493
|
+
0,0,0,1
|
494
|
+
|
495
|
+
};
|
496
|
+
|
497
|
+
|
498
|
+
|
459
499
|
|
460
500
|
|
461
501
|
//平行移動
|
@@ -516,7 +556,7 @@
|
|
516
556
|
|
517
557
|
mul(rotate, move, t);
|
518
558
|
|
519
|
-
|
559
|
+
//print_(t);
|
520
560
|
|
521
561
|
|
522
562
|
|
@@ -526,7 +566,7 @@
|
|
526
566
|
|
527
567
|
mul(scale, t, t2);
|
528
568
|
|
529
|
-
//
|
569
|
+
// print_(t2);
|
530
570
|
|
531
571
|
|
532
572
|
|
@@ -538,7 +578,7 @@
|
|
538
578
|
|
539
579
|
mul(Vertex[i], t2, t3);
|
540
580
|
|
541
|
-
|
581
|
+
print_(t2);
|
542
582
|
|
543
583
|
|
544
584
|
|
@@ -548,7 +588,7 @@
|
|
548
588
|
|
549
589
|
mul(mp, t2, t4);
|
550
590
|
|
551
|
-
print_(t4);
|
591
|
+
// print_(t4);
|
552
592
|
|
553
593
|
}
|
554
594
|
|
6
文章と提示コードを編集しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -12,6 +12,14 @@
|
|
12
12
|
|
13
13
|
|
14
14
|
|
15
|
+
追記
|
16
|
+
|
17
|
+
参考サイト: http://marupeke296.sakura.ne.jp/DXG_No58_RotQuaternionTrans.html
|
18
|
+
|
19
|
+
② クォータニオン→回転行列変換より回転行列を使いかました。
|
20
|
+
|
21
|
+
|
22
|
+
|
15
23
|
|
16
24
|
|
17
25
|
下記サイトの163ページの透視射形変換行列の数式を移しました。
|
@@ -128,6 +136,10 @@
|
|
128
136
|
|
129
137
|
float z;
|
130
138
|
|
139
|
+
|
140
|
+
|
141
|
+
float w;
|
142
|
+
|
131
143
|
};
|
132
144
|
|
133
145
|
|
@@ -136,23 +148,23 @@
|
|
136
148
|
|
137
149
|
//頂点バッファー
|
138
150
|
|
139
|
-
float Vertex[6][
|
151
|
+
float Vertex[6][4] =
|
140
|
-
|
152
|
+
|
141
|
-
{
|
153
|
+
{
|
142
|
-
|
154
|
+
|
143
|
-
{-0.5, 0.5, 1.0},
|
155
|
+
{-0.5, 0.5, 1.0,1.0},
|
144
|
-
|
156
|
+
|
145
|
-
{-0.5, -0.5, 1.0},
|
157
|
+
{-0.5, -0.5, 1.0,1.0},
|
146
|
-
|
158
|
+
|
147
|
-
{0.5, -0.5, 1.0},
|
159
|
+
{0.5, -0.5, 1.0,1.0},
|
148
|
-
|
149
|
-
|
150
|
-
|
160
|
+
|
161
|
+
|
162
|
+
|
151
|
-
{-0.5, 0.5, 1.0},
|
163
|
+
{-0.5, 0.5, 1.0,1.0},
|
152
|
-
|
164
|
+
|
153
|
-
{0.5, 0.5, 1.0 },
|
165
|
+
{0.5, 0.5, 1.0,1.0 },
|
154
|
-
|
166
|
+
|
155
|
-
{0.5, -0.5, 1.0}
|
167
|
+
{0.5, -0.5, 1.0,1.0}
|
156
168
|
|
157
169
|
};
|
158
170
|
|
@@ -318,6 +330,8 @@
|
|
318
330
|
|
319
331
|
|
320
332
|
|
333
|
+
//ベクトルと行列の掛け算
|
334
|
+
|
321
335
|
void mul_vec3_matrix(float m[16], float v[3], float r[3])
|
322
336
|
|
323
337
|
{
|
@@ -340,7 +354,7 @@
|
|
340
354
|
|
341
355
|
|
342
356
|
|
343
|
-
|
357
|
+
//画面表示
|
344
358
|
|
345
359
|
void print_(float tmp[16])
|
346
360
|
|
@@ -390,11 +404,13 @@
|
|
390
404
|
|
391
405
|
struct position pos;
|
392
406
|
|
393
|
-
pos.x =
|
407
|
+
pos.x = Vertex[0][0] * (cos(0) / 2);
|
394
|
-
|
408
|
+
|
395
|
-
pos.y = 0;
|
409
|
+
pos.y = Vertex[0][1] * (sin(0) / 2);
|
396
|
-
|
410
|
+
|
397
|
-
pos.z = 0;
|
411
|
+
pos.z = Vertex[0][2] * (sin(0) / 2);
|
412
|
+
|
413
|
+
pos.w = Vertex[0][3] * cos(0) / 2;
|
398
414
|
|
399
415
|
|
400
416
|
|
@@ -404,35 +420,39 @@
|
|
404
420
|
|
405
421
|
|
406
422
|
|
423
|
+
( 1 - (2 * pos.y * pos.y) - (2 * pos.z * pos.z)),
|
424
|
+
|
407
|
-
(pos.x * pos.
|
425
|
+
((2 * pos.x * pos.y) + (2 * pos.w * pos.z) ),
|
426
|
+
|
408
|
-
|
427
|
+
((2 * pos.x * pos.z) - (2 * pos.w * pos.y))
|
428
|
+
|
429
|
+
,0
|
430
|
+
|
431
|
+
|
432
|
+
|
433
|
+
|
434
|
+
|
435
|
+
(1 - (2 * pos.z * pos.y) - (2 * pos.w * pos.z)),
|
436
|
+
|
437
|
+
(1 - (2 * pos.x * pos.x) - (2 * pos.z * pos.z)),
|
438
|
+
|
409
|
-
(pos.
|
439
|
+
((2 * pos.y * pos.z) + (2 * pos.w * pos.x))
|
440
|
+
|
410
|
-
|
441
|
+
,0
|
442
|
+
|
443
|
+
|
444
|
+
|
411
|
-
|
445
|
+
((2 * pos.x * pos.z) - (2 * pos.w * pos.z)),
|
412
|
-
|
413
|
-
|
446
|
+
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
447
|
+
|
418
|
-
|
448
|
+
|
419
|
-
(pos.y * pos.
|
449
|
+
((2 * pos.y * pos.z) - (2 * pos.w * pos.z)),
|
420
|
-
|
421
|
-
|
450
|
+
|
422
|
-
|
423
|
-
|
451
|
+
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
452
|
+
|
428
|
-
|
429
|
-
(pos.y * pos.z + (1 - cos(r)) - pos.x * sin(r)),
|
430
|
-
|
431
|
-
(pos.
|
453
|
+
(1 - (2 * pos.x * pos.x) - (2 * pos.y * pos.y))
|
432
|
-
|
454
|
+
|
433
|
-
|
455
|
+
,1
|
434
|
-
|
435
|
-
|
436
456
|
|
437
457
|
};
|
438
458
|
|
@@ -448,6 +468,8 @@
|
|
448
468
|
|
449
469
|
p.z = 0;
|
450
470
|
|
471
|
+
p.w = 1;
|
472
|
+
|
451
473
|
|
452
474
|
|
453
475
|
float move[16] =
|
5
提示コードを編集
test
CHANGED
File without changes
|
test
CHANGED
@@ -108,7 +108,27 @@
|
|
108
108
|
|
109
109
|
|
110
110
|
|
111
|
-
|
111
|
+
//透視射形行列
|
112
|
+
|
113
|
+
float mp[16];
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
//座標構造体
|
118
|
+
|
119
|
+
struct position
|
120
|
+
|
121
|
+
{
|
122
|
+
|
123
|
+
public:
|
124
|
+
|
125
|
+
float x;
|
126
|
+
|
127
|
+
float y;
|
128
|
+
|
129
|
+
float z;
|
130
|
+
|
131
|
+
};
|
112
132
|
|
113
133
|
|
114
134
|
|
@@ -122,7 +142,7 @@
|
|
122
142
|
|
123
143
|
{-0.5, 0.5, 1.0},
|
124
144
|
|
125
|
-
{-0.5, -0.5, 1.0
|
145
|
+
{-0.5, -0.5, 1.0},
|
126
146
|
|
127
147
|
{0.5, -0.5, 1.0},
|
128
148
|
|
@@ -138,55 +158,259 @@
|
|
138
158
|
|
139
159
|
|
140
160
|
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
str
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
p
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
161
|
+
|
162
|
+
|
163
|
+
|
164
|
+
|
165
|
+
//透視投影変換行列を作る
|
166
|
+
|
167
|
+
void create_matri_mp(float top, float bottom, float left, float right,
|
168
|
+
|
169
|
+
float near, float far, float result[16])
|
170
|
+
|
171
|
+
{
|
172
|
+
|
173
|
+
result[0] = (2 * near) / (right - left);
|
174
|
+
|
175
|
+
result[5] = (2 * near) / (top - bottom);
|
176
|
+
|
177
|
+
|
178
|
+
|
179
|
+
result[8] = (right + left) / (right - left);
|
180
|
+
|
181
|
+
|
182
|
+
|
183
|
+
result[9] = (top + bottom) / (top - bottom);
|
184
|
+
|
185
|
+
|
186
|
+
|
187
|
+
result[10] = (far + near) / (far - near);
|
188
|
+
|
189
|
+
|
190
|
+
|
191
|
+
result[11] = -1;
|
192
|
+
|
193
|
+
result[14] = (2 * far * near) / (far - near);
|
194
|
+
|
195
|
+
|
196
|
+
|
197
|
+
|
198
|
+
|
199
|
+
}
|
200
|
+
|
201
|
+
|
202
|
+
|
203
|
+
//行列を表示
|
204
|
+
|
205
|
+
void print_matrix(const char* str, float mp[4][4])
|
206
|
+
|
207
|
+
{
|
208
|
+
|
209
|
+
printf("name: %s\n", str);
|
210
|
+
|
211
|
+
for (int i = 0; i < 4; i++)
|
212
|
+
|
213
|
+
{
|
214
|
+
|
215
|
+
for (int j = 0; j < 4; j++)
|
216
|
+
|
217
|
+
{
|
218
|
+
|
219
|
+
printf("[ %.2f ] , ", mp[i][j]);
|
220
|
+
|
221
|
+
}
|
222
|
+
|
223
|
+
printf("\n");
|
224
|
+
|
225
|
+
}
|
226
|
+
|
227
|
+
}
|
228
|
+
|
229
|
+
|
230
|
+
|
231
|
+
|
232
|
+
|
233
|
+
//行列掛け算
|
234
|
+
|
235
|
+
//void mul(float a[4][4], float b[4][4])
|
236
|
+
|
237
|
+
void mul(float a[16], float b[16], float result[16])
|
238
|
+
|
239
|
+
{
|
240
|
+
|
241
|
+
result[0] = (a[0] * b[0]) + (a[4] * b[1]) + (a[8] * b[2]) + (a[12] * b[3]);
|
242
|
+
|
243
|
+
|
244
|
+
|
245
|
+
result[1] = (a[1] * b[0]) + (a[5] * b[1]) + (a[9] * b[2]) + (a[13] * b[3]);
|
246
|
+
|
247
|
+
|
248
|
+
|
249
|
+
result[2] = (a[2] * b[0]) + (a[6] * b[1]) + (a[10] * b[2]) + (a[14] * b[3]);
|
250
|
+
|
251
|
+
|
252
|
+
|
253
|
+
result[3] = (a[3] * b[0]) + (a[7] * b[1]) + (a[11] * b[2]) + (a[15] * b[3]);
|
254
|
+
|
255
|
+
|
256
|
+
|
257
|
+
/////////
|
258
|
+
|
259
|
+
|
260
|
+
|
261
|
+
result[4] = (a[0] * b[4]) + (a[4] * b[5]) + (a[8] * b[6]) + (a[12] * b[7]);
|
262
|
+
|
263
|
+
|
264
|
+
|
265
|
+
result[5] = (a[1] * b[4]) + (a[5] * b[5]) + (a[9] * b[6]) + (a[13] * b[7]);
|
266
|
+
|
267
|
+
|
268
|
+
|
269
|
+
result[6] = (a[2] * b[4]) + (a[6] * b[5]) + (a[10] * b[6]) + (a[14] * b[7]);
|
270
|
+
|
271
|
+
|
272
|
+
|
273
|
+
result[7] = (a[3] * b[4]) + (a[7] * b[5]) + (a[11] * b[6]) + (a[15] * b[7]);
|
274
|
+
|
275
|
+
|
276
|
+
|
277
|
+
/////////
|
278
|
+
|
279
|
+
result[8] = (a[0] * b[8]) + (a[4] * b[9]) + (a[8] * b[10]) + (a[12] * b[11]);
|
280
|
+
|
281
|
+
|
282
|
+
|
283
|
+
result[9] = (a[1] * b[8]) + (a[5] * b[9]) + (a[9] * b[10]) + (a[13] * b[11]);
|
284
|
+
|
285
|
+
|
286
|
+
|
287
|
+
result[10] = (a[2] * b[8]) + (a[6] * b[9]) + (a[10] * b[10]) + (a[14] * b[11]);
|
288
|
+
|
289
|
+
|
290
|
+
|
291
|
+
result[11] = (a[3] * b[8]) + (a[7] * b[9]) + (a[11] * b[10]) + (a[15] * b[11]);
|
292
|
+
|
293
|
+
|
294
|
+
|
295
|
+
/////////
|
296
|
+
|
297
|
+
|
298
|
+
|
299
|
+
result[12] = (a[0] * b[12]) + (a[4] * b[13]) + (a[8] * b[14]) + (a[12] * b[15]);
|
300
|
+
|
301
|
+
|
302
|
+
|
303
|
+
result[13] = (a[1] * b[12]) + (a[5] * b[13]) + (a[9] * b[14]) + (a[13] * b[15]);
|
304
|
+
|
305
|
+
|
306
|
+
|
307
|
+
result[14] = (a[2] * b[12]) + (a[6] * b[13]) + (a[10] * b[14]) + (a[14] * b[15]);
|
308
|
+
|
309
|
+
|
310
|
+
|
311
|
+
result[15] = (a[3] * b[12]) + (a[7] * b[13]) + (a[11] * b[14]) + (a[15] * b[15]);
|
312
|
+
|
313
|
+
|
314
|
+
|
315
|
+
|
316
|
+
|
317
|
+
}
|
318
|
+
|
319
|
+
|
320
|
+
|
321
|
+
void mul_vec3_matrix(float m[16], float v[3], float r[3])
|
322
|
+
|
323
|
+
{
|
324
|
+
|
325
|
+
printf("\n\n");
|
326
|
+
|
327
|
+
for (int j = 0; j < 3; j++)
|
328
|
+
|
329
|
+
{
|
330
|
+
|
331
|
+
printf("[ %.2f ] ", r[j]);
|
332
|
+
|
333
|
+
}
|
334
|
+
|
335
|
+
printf("\n");
|
336
|
+
|
337
|
+
}
|
338
|
+
|
339
|
+
|
340
|
+
|
341
|
+
|
342
|
+
|
343
|
+
|
344
|
+
|
345
|
+
void print_(float tmp[16])
|
346
|
+
|
347
|
+
{
|
348
|
+
|
349
|
+
for (int i = 0; i < 16; i++)
|
350
|
+
|
351
|
+
{
|
352
|
+
|
353
|
+
if (i % 4 == 0)
|
354
|
+
|
355
|
+
{
|
356
|
+
|
357
|
+
printf("\n");
|
358
|
+
|
359
|
+
}
|
360
|
+
|
361
|
+
|
362
|
+
|
363
|
+
printf(" [ %.2f ] ", tmp[i]);
|
364
|
+
|
365
|
+
}
|
366
|
+
|
367
|
+
|
368
|
+
|
369
|
+
printf("\n\n");
|
370
|
+
|
371
|
+
|
372
|
+
|
373
|
+
}
|
374
|
+
|
375
|
+
|
376
|
+
|
377
|
+
|
378
|
+
|
379
|
+
int main()
|
380
|
+
|
381
|
+
{
|
382
|
+
|
383
|
+
create_matri_mp(1.0f, -1.0f, -1.0f, 1.0f, 1.0, 10.f, mp);//透視射形変換行列mp
|
384
|
+
|
385
|
+
|
386
|
+
|
387
|
+
|
388
|
+
|
389
|
+
//回転行列
|
390
|
+
|
391
|
+
struct position pos;
|
392
|
+
|
393
|
+
pos.x = 1;
|
394
|
+
|
395
|
+
pos.y = 0;
|
396
|
+
|
397
|
+
pos.z = 0;
|
398
|
+
|
399
|
+
|
400
|
+
|
401
|
+
float r = 1;
|
402
|
+
|
403
|
+
float rotate[16] = {
|
404
|
+
|
405
|
+
|
184
406
|
|
185
407
|
(pos.x * pos.x + (1 - cos(r)) + cos(r)),
|
186
408
|
|
187
409
|
(pos.x * pos.y + (1 - cos(r)) + pos.z * sin(r))
|
188
410
|
|
189
|
-
,(pos.x * pos.z + (1 - cos(r)) - pos.y * sin(r)),
|
411
|
+
,(pos.x * pos.z + (1 - cos(r)) - pos.y * sin(r)),
|
412
|
+
|
413
|
+
0,
|
190
414
|
|
191
415
|
|
192
416
|
|
@@ -194,7 +418,9 @@
|
|
194
418
|
|
195
419
|
(pos.y * pos.y + (1 - cos(r)) + cos(r)),
|
196
420
|
|
197
|
-
(pos.y * pos.z + (1 - cos(r)) + pos.x * sin(r)),
|
421
|
+
(pos.y * pos.z + (1 - cos(r)) + pos.x * sin(r)),
|
422
|
+
|
423
|
+
0,
|
198
424
|
|
199
425
|
|
200
426
|
|
@@ -202,331 +428,115 @@
|
|
202
428
|
|
203
429
|
(pos.y * pos.z + (1 - cos(r)) - pos.x * sin(r)),
|
204
430
|
|
205
|
-
(pos.z * pos.z + (1 - cos(r)) + cos(r)),
|
431
|
+
(pos.z * pos.z + (1 - cos(r)) + cos(r)),
|
432
|
+
|
206
|
-
|
433
|
+
0,
|
434
|
+
|
435
|
+
|
436
|
+
|
207
|
-
};
|
437
|
+
};
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
438
|
+
|
439
|
+
|
440
|
+
|
213
|
-
//平行移動
|
441
|
+
//平行移動
|
442
|
+
|
214
|
-
|
443
|
+
struct position p;
|
444
|
+
|
215
|
-
|
445
|
+
p.x = 0;
|
216
|
-
|
446
|
+
|
217
|
-
|
447
|
+
p.y = 0;
|
218
|
-
|
448
|
+
|
219
|
-
|
449
|
+
p.z = 0;
|
220
|
-
|
221
|
-
|
222
|
-
|
450
|
+
|
451
|
+
|
452
|
+
|
223
|
-
float move[16] =
|
453
|
+
float move[16] =
|
224
|
-
|
225
|
-
{
|
226
|
-
|
227
|
-
1,0,0,mx,
|
228
|
-
|
229
|
-
0,1,0,my,
|
230
|
-
|
231
|
-
0,0,1,mz,
|
232
|
-
|
233
|
-
0,0,0,1,
|
234
|
-
|
235
|
-
};
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
//透視投影変換行列を作る
|
242
|
-
|
243
|
-
void create_matri_mp(float top, float bottom, float left, float right,
|
244
|
-
|
245
|
-
float near, float far, float result[16])
|
246
|
-
|
247
|
-
{
|
248
|
-
|
249
|
-
result[0] = (2 * near) / (right - left);
|
250
|
-
|
251
|
-
result[5] = (2 * near) / (top - bottom);
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
result[8] = (right + left) / (right - left);
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
result[9] = (top + bottom) / (top - bottom);
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
result[10] = (far + near) / (far - near);
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
result[11] = -1;
|
268
|
-
|
269
|
-
result[14] = (2 * far * near) / (far - near);
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
}
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
//行列を表示
|
280
|
-
|
281
|
-
void print_matrix(const char* str,float mp[4][4])
|
282
|
-
|
283
|
-
{
|
284
|
-
|
285
|
-
printf("name: %s\n",str);
|
286
|
-
|
287
|
-
for (int i = 0; i < 4; i++)
|
288
454
|
|
289
455
|
{
|
290
456
|
|
457
|
+
1,0,0,p.x,
|
458
|
+
|
459
|
+
0,1,0,p.y,
|
460
|
+
|
461
|
+
0,0,1,p.z,
|
462
|
+
|
463
|
+
0,0,0,1,
|
464
|
+
|
465
|
+
};
|
466
|
+
|
467
|
+
|
468
|
+
|
469
|
+
//スケール行列
|
470
|
+
|
471
|
+
float scale[16] = {
|
472
|
+
|
473
|
+
1,0,0,0,
|
474
|
+
|
475
|
+
0,1,0,0,
|
476
|
+
|
477
|
+
0,0,1,0,
|
478
|
+
|
479
|
+
0,0,0,1
|
480
|
+
|
481
|
+
};
|
482
|
+
|
483
|
+
|
484
|
+
|
485
|
+
|
486
|
+
|
487
|
+
|
488
|
+
|
489
|
+
|
490
|
+
|
491
|
+
|
492
|
+
|
493
|
+
float t[16];
|
494
|
+
|
495
|
+
mul(rotate, move, t);
|
496
|
+
|
497
|
+
// print_(t);
|
498
|
+
|
499
|
+
|
500
|
+
|
501
|
+
|
502
|
+
|
503
|
+
float t2[16];//M
|
504
|
+
|
505
|
+
mul(scale, t, t2);
|
506
|
+
|
507
|
+
// print_(t2);
|
508
|
+
|
509
|
+
|
510
|
+
|
291
|
-
|
511
|
+
for (int i = 0; i < 6; i++)
|
292
|
-
|
512
|
+
|
293
|
-
|
513
|
+
{
|
514
|
+
|
294
|
-
|
515
|
+
float t3[16];
|
516
|
+
|
517
|
+
mul(Vertex[i], t2, t3);
|
518
|
+
|
295
|
-
print
|
519
|
+
// print_(t2);
|
296
|
-
|
520
|
+
|
521
|
+
|
522
|
+
|
523
|
+
|
524
|
+
|
297
|
-
|
525
|
+
float t4[16];
|
526
|
+
|
298
|
-
|
527
|
+
mul(mp, t2, t4);
|
528
|
+
|
299
|
-
print
|
529
|
+
print_(t4);
|
300
530
|
|
301
531
|
}
|
302
532
|
|
303
|
-
|
533
|
+
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
534
|
+
|
310
|
-
|
311
|
-
|
535
|
+
|
312
|
-
|
313
|
-
|
536
|
+
|
314
|
-
|
315
|
-
|
537
|
+
|
316
|
-
|
317
|
-
|
538
|
+
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
result[1] = (a[1] * b[0]) + (a[5] * b[1]) + (a[9] * b[2]) + (a[13] * b[3]);
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
result[2] = (a[2] * b[0]) + (a[6] * b[1]) + (a[10] * b[2]) + (a[14] * b[3]);
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
result[3] = (a[3] * b[0]) + (a[7] * b[1]) + (a[11] * b[2]) + (a[15] * b[3]);
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
/////////
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
result[4] = (a[0] * b[4]) + (a[4] * b[5]) + (a[8] * b[6]) + (a[12] * b[7]);
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
result[5] = (a[1] * b[4]) + (a[5] * b[5]) + (a[9] * b[6]) + (a[13] * b[7]);
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
result[6] = (a[2] * b[4]) + (a[6] * b[5]) + (a[10] * b[6]) + (a[14] * b[7]);
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
result[7] = (a[3] * b[4]) + (a[7] * b[5]) + (a[11] * b[6]) + (a[15] * b[7]);
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
/////////
|
354
|
-
|
355
|
-
result[8] = (a[0] * b[8]) + (a[4] * b[9]) + (a[8] * b[10]) + (a[12] * b[11]);
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
result[9] = (a[1] * b[8]) + (a[5] * b[9]) + (a[9] * b[10]) + (a[13] * b[11]);
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
result[10] = (a[2] * b[8]) + (a[6] * b[9]) + (a[10] * b[10]) + (a[14] * b[11]);
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
result[11] = (a[3] * b[8]) + (a[7] * b[9]) + (a[11] * b[10]) + (a[15] * b[11]);
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
/////////
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
result[12] = (a[0] * b[12]) + (a[4] * b[13]) + (a[8] * b[14]) + (a[12] * b[15]);
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
result[13] = (a[1] * b[12]) + (a[5] * b[13]) + (a[9] * b[14]) + (a[13] * b[15]);
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
result[14] = (a[2] * b[12]) + (a[6] * b[13]) + (a[10] * b[14]) + (a[14] * b[15]);
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
result[15] = (a[3] * b[12]) + (a[7] * b[13]) + (a[11] * b[14]) + (a[15] * b[15]);
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
}
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
void mul_vec3_matrix(float m[16],float v[3],float r[3])
|
398
|
-
|
399
|
-
{
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
printf("\n\n");
|
418
|
-
|
419
|
-
for (int j = 0; j < 3; j++)
|
420
|
-
|
421
|
-
{
|
422
|
-
|
423
|
-
printf("[ %.2f ] ", r[j]);
|
424
|
-
|
425
|
-
}
|
426
|
-
|
427
|
-
printf("\n");
|
428
|
-
|
429
|
-
}
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
void print_(float tmp[16])
|
438
|
-
|
439
|
-
{
|
440
|
-
|
441
|
-
for (int i = 0; i < 16; i++)
|
442
|
-
|
443
|
-
{
|
444
|
-
|
445
|
-
if (i % 4 == 0)
|
446
|
-
|
447
|
-
{
|
448
|
-
|
449
|
-
printf("\n");
|
450
|
-
|
451
|
-
}
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
printf(" [ %.2f ] ", tmp[i]);
|
456
|
-
|
457
|
-
}
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
printf("\n\n");
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
}
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
int main()
|
472
|
-
|
473
|
-
{
|
474
|
-
|
475
|
-
create_matri_mp(1.0f,-1.0f,-1.0f,1.0f,1.0,10.f,mp);
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
float t[16];
|
484
|
-
|
485
|
-
mul(rotate,move,t);
|
486
|
-
|
487
|
-
// print_(t);
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
float t2[16];//M
|
494
|
-
|
495
|
-
mul(scale, t, t2);
|
496
|
-
|
497
|
-
// print_(t2);
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
for (int i = 0; i < 6; i++)
|
502
|
-
|
503
|
-
{
|
504
|
-
|
505
|
-
float t3[16];
|
506
|
-
|
507
|
-
mul(Vertex[i], t2, t3);
|
508
|
-
|
509
|
-
// print_(t2);
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
float t4[16];
|
516
|
-
|
517
|
-
mul(mp, t2, t4);
|
518
|
-
|
519
|
-
print_(t4);
|
520
|
-
|
521
|
-
}
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
539
|
+
return 0;
|
530
540
|
|
531
541
|
}
|
532
542
|
|
4
文章とタイトルを編集
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
GLSLで画面描画に使う
|
1
|
+
GLSLで画面描画に使う行列を上手く設定できない
|
test
CHANGED
@@ -1,14 +1,12 @@
|
|
1
|
-
シェーダーで行う計算をCPUで普通に計算するテストコードを実装したいのですが予測通り最後**で3次元目がよくわからない値**に変わっているため
|
1
|
+
シェーダーで行う計算をCPUで普通に計算するテストコードを実装したいのですが予測通り最後**で3次元目がよくわからない値**に変わっているため画面に表示されない等の不具合が発生しているということを突き止めたのですがこれはなぜこんな値になっているのでしょうか?
|
2
|
-
|
2
|
+
|
3
|
+
|
4
|
+
|
5
|
+
|
6
|
+
|
7
|
+
|
8
|
+
|
3
|
-
|
9
|
+
透視変換行列並びにスケール、回転、平行移動の行列は正しいのでしょうか?調べましたが行列コード以外間違えているとはありえないと思うのですが教えてくれますでしょうか?
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
最後の行列の値の設定関数**create_matri_mp();**関数ですがこれが悪いのでしょか?数式は変更できないため行列計算が間違えているのでしょうか?両方確認しましたがどれが間違えているのかどうしてもわかりません。また本来来るべき値とは1.0なのでしょうか?
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
教えてくれますでしょうか?
|
12
10
|
|
13
11
|
|
14
12
|
|
@@ -30,7 +28,7 @@
|
|
30
28
|
|
31
29
|
|
32
30
|
|
33
|
-
![イメージ説明](c
|
31
|
+
![イメージ説明](31bc325353f2442b580fdde7e68c97c7.png)
|
34
32
|
|
35
33
|
|
36
34
|
|
@@ -110,7 +108,7 @@
|
|
110
108
|
|
111
109
|
|
112
110
|
|
113
|
-
float mp[
|
111
|
+
float mp[16];//透視射形行列
|
114
112
|
|
115
113
|
|
116
114
|
|
@@ -124,7 +122,7 @@
|
|
124
122
|
|
125
123
|
{-0.5, 0.5, 1.0},
|
126
124
|
|
127
|
-
{-0.5, -0.5, 1.0},
|
125
|
+
{-0.5, -0.5, 1.0 },
|
128
126
|
|
129
127
|
{0.5, -0.5, 1.0},
|
130
128
|
|
@@ -132,7 +130,7 @@
|
|
132
130
|
|
133
131
|
{-0.5, 0.5, 1.0},
|
134
132
|
|
135
|
-
{0.5, 0.5, 1.0},
|
133
|
+
{0.5, 0.5, 1.0 },
|
136
134
|
|
137
135
|
{0.5, -0.5, 1.0}
|
138
136
|
|
@@ -142,15 +140,15 @@
|
|
142
140
|
|
143
141
|
//スケール行列
|
144
142
|
|
145
|
-
float scale[
|
143
|
+
float scale[16] = {
|
146
|
-
|
144
|
+
|
147
|
-
|
145
|
+
1,0,0,0,
|
148
|
-
|
146
|
+
|
149
|
-
|
147
|
+
0,1,0,0,
|
150
|
-
|
148
|
+
|
151
|
-
|
149
|
+
0,0,1,0,
|
152
|
-
|
150
|
+
|
153
|
-
|
151
|
+
0,0,0,1
|
154
152
|
|
155
153
|
};
|
156
154
|
|
@@ -182,7 +180,7 @@
|
|
182
180
|
|
183
181
|
float r = 1;
|
184
182
|
|
185
|
-
float rotate[
|
183
|
+
float rotate[16] = {
|
186
184
|
|
187
185
|
(pos.x * pos.x + (1 - cos(r)) + cos(r)),
|
188
186
|
|
@@ -222,7 +220,7 @@
|
|
222
220
|
|
223
221
|
|
224
222
|
|
225
|
-
float move[
|
223
|
+
float move[16] =
|
226
224
|
|
227
225
|
{
|
228
226
|
|
@@ -238,63 +236,43 @@
|
|
238
236
|
|
239
237
|
|
240
238
|
|
241
|
-
|
239
|
+
|
242
240
|
|
243
241
|
//透視投影変換行列を作る
|
244
242
|
|
245
243
|
void create_matri_mp(float top, float bottom, float left, float right,
|
246
244
|
|
247
|
-
float near, float far, float result[
|
245
|
+
float near, float far, float result[16])
|
248
|
-
|
246
|
+
|
249
|
-
{
|
247
|
+
{
|
250
|
-
|
248
|
+
|
251
|
-
result[0]
|
249
|
+
result[0] = (2 * near) / (right - left);
|
252
|
-
|
250
|
+
|
253
|
-
result[
|
251
|
+
result[5] = (2 * near) / (top - bottom);
|
254
|
-
|
252
|
+
|
253
|
+
|
254
|
+
|
255
|
-
result[
|
255
|
+
result[8] = (right + left) / (right - left);
|
256
|
-
|
257
|
-
|
256
|
+
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
257
|
+
|
262
|
-
|
263
|
-
|
258
|
+
|
264
|
-
|
265
|
-
result[
|
259
|
+
result[9] = (top + bottom) / (top - bottom);
|
266
|
-
|
267
|
-
|
260
|
+
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
261
|
+
|
272
|
-
|
273
|
-
|
262
|
+
|
274
|
-
|
275
|
-
result[
|
263
|
+
result[10] = (far + near) / (far - near);
|
264
|
+
|
265
|
+
|
266
|
+
|
276
|
-
|
267
|
+
result[11] = -1;
|
268
|
+
|
277
|
-
result[
|
269
|
+
result[14] = (2 * far * near) / (far - near);
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
270
|
+
|
282
|
-
|
283
|
-
|
271
|
+
|
284
|
-
|
285
|
-
|
272
|
+
|
286
|
-
|
287
|
-
|
273
|
+
|
288
|
-
|
274
|
+
|
289
|
-
}
|
275
|
+
}
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
276
|
|
299
277
|
|
300
278
|
|
@@ -332,214 +310,216 @@
|
|
332
310
|
|
333
311
|
//void mul(float a[4][4], float b[4][4])
|
334
312
|
|
335
|
-
void mul(float a[
|
336
|
-
|
337
|
-
{
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
result[
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
result[
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
result[
|
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
|
-
result[
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
result[3]
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
result[
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
result[
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
313
|
+
void mul(float a[16], float b[16], float result[16])
|
314
|
+
|
315
|
+
{
|
316
|
+
|
317
|
+
result[0] = (a[0] * b[0]) + (a[4] * b[1]) + (a[8] * b[2]) + (a[12] * b[3]);
|
318
|
+
|
319
|
+
|
320
|
+
|
321
|
+
result[1] = (a[1] * b[0]) + (a[5] * b[1]) + (a[9] * b[2]) + (a[13] * b[3]);
|
322
|
+
|
323
|
+
|
324
|
+
|
325
|
+
result[2] = (a[2] * b[0]) + (a[6] * b[1]) + (a[10] * b[2]) + (a[14] * b[3]);
|
326
|
+
|
327
|
+
|
328
|
+
|
329
|
+
result[3] = (a[3] * b[0]) + (a[7] * b[1]) + (a[11] * b[2]) + (a[15] * b[3]);
|
330
|
+
|
331
|
+
|
332
|
+
|
333
|
+
/////////
|
334
|
+
|
335
|
+
|
336
|
+
|
337
|
+
result[4] = (a[0] * b[4]) + (a[4] * b[5]) + (a[8] * b[6]) + (a[12] * b[7]);
|
338
|
+
|
339
|
+
|
340
|
+
|
341
|
+
result[5] = (a[1] * b[4]) + (a[5] * b[5]) + (a[9] * b[6]) + (a[13] * b[7]);
|
342
|
+
|
343
|
+
|
344
|
+
|
345
|
+
result[6] = (a[2] * b[4]) + (a[6] * b[5]) + (a[10] * b[6]) + (a[14] * b[7]);
|
346
|
+
|
347
|
+
|
348
|
+
|
349
|
+
result[7] = (a[3] * b[4]) + (a[7] * b[5]) + (a[11] * b[6]) + (a[15] * b[7]);
|
350
|
+
|
351
|
+
|
352
|
+
|
353
|
+
/////////
|
354
|
+
|
355
|
+
result[8] = (a[0] * b[8]) + (a[4] * b[9]) + (a[8] * b[10]) + (a[12] * b[11]);
|
356
|
+
|
357
|
+
|
358
|
+
|
359
|
+
result[9] = (a[1] * b[8]) + (a[5] * b[9]) + (a[9] * b[10]) + (a[13] * b[11]);
|
360
|
+
|
361
|
+
|
362
|
+
|
363
|
+
result[10] = (a[2] * b[8]) + (a[6] * b[9]) + (a[10] * b[10]) + (a[14] * b[11]);
|
364
|
+
|
365
|
+
|
366
|
+
|
367
|
+
result[11] = (a[3] * b[8]) + (a[7] * b[9]) + (a[11] * b[10]) + (a[15] * b[11]);
|
368
|
+
|
369
|
+
|
370
|
+
|
371
|
+
/////////
|
372
|
+
|
373
|
+
|
374
|
+
|
375
|
+
result[12] = (a[0] * b[12]) + (a[4] * b[13]) + (a[8] * b[14]) + (a[12] * b[15]);
|
376
|
+
|
377
|
+
|
378
|
+
|
379
|
+
result[13] = (a[1] * b[12]) + (a[5] * b[13]) + (a[9] * b[14]) + (a[13] * b[15]);
|
380
|
+
|
381
|
+
|
382
|
+
|
383
|
+
result[14] = (a[2] * b[12]) + (a[6] * b[13]) + (a[10] * b[14]) + (a[14] * b[15]);
|
384
|
+
|
385
|
+
|
386
|
+
|
387
|
+
result[15] = (a[3] * b[12]) + (a[7] * b[13]) + (a[11] * b[14]) + (a[15] * b[15]);
|
388
|
+
|
389
|
+
|
390
|
+
|
391
|
+
|
392
|
+
|
393
|
+
}
|
394
|
+
|
395
|
+
|
396
|
+
|
397
|
+
void mul_vec3_matrix(float m[16],float v[3],float r[3])
|
398
|
+
|
399
|
+
{
|
400
|
+
|
401
|
+
|
402
|
+
|
403
|
+
|
404
|
+
|
405
|
+
|
406
|
+
|
407
|
+
|
408
|
+
|
409
|
+
|
410
|
+
|
411
|
+
|
412
|
+
|
413
|
+
|
414
|
+
|
415
|
+
|
416
|
+
|
417
|
+
printf("\n\n");
|
418
|
+
|
419
|
+
for (int j = 0; j < 3; j++)
|
418
420
|
|
419
421
|
{
|
420
422
|
|
423
|
+
printf("[ %.2f ] ", r[j]);
|
424
|
+
|
425
|
+
}
|
426
|
+
|
427
|
+
printf("\n");
|
428
|
+
|
429
|
+
}
|
430
|
+
|
431
|
+
|
432
|
+
|
433
|
+
|
434
|
+
|
435
|
+
|
436
|
+
|
437
|
+
void print_(float tmp[16])
|
438
|
+
|
439
|
+
{
|
440
|
+
|
421
|
-
|
441
|
+
for (int i = 0; i < 16; i++)
|
442
|
+
|
443
|
+
{
|
444
|
+
|
445
|
+
if (i % 4 == 0)
|
422
446
|
|
423
447
|
{
|
424
448
|
|
425
|
-
for (int j = 0; j < 4; j++)
|
426
|
-
|
427
|
-
{
|
428
|
-
|
429
|
-
printf("[ %.2f ] ", result[i][j]);
|
430
|
-
|
431
|
-
}
|
432
|
-
|
433
|
-
|
434
|
-
|
435
449
|
printf("\n");
|
436
450
|
|
437
451
|
}
|
438
452
|
|
453
|
+
|
454
|
+
|
455
|
+
printf(" [ %.2f ] ", tmp[i]);
|
456
|
+
|
439
457
|
}
|
440
458
|
|
441
|
-
|
442
|
-
|
443
|
-
}
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
void mul_vec3_matrix(float m[4][4],float v[3],float r[3])
|
448
|
-
|
449
|
-
{
|
450
|
-
|
451
|
-
r[0] = (m[0][0] * v[0]) + (m[0][1] * v[1]) + (m[0][2] * v[2]);
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
r[1] = (m[1][0] * v[0]) + (m[1][1] * v[1]) + (m[1][2] * v[2]);
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
r[2] = (m[2][0] * v[0]) + (m[2][1] * v[1]) + (m[2][2] * v[2]);
|
460
|
-
|
461
|
-
|
462
|
-
|
463
459
|
|
464
460
|
|
465
461
|
printf("\n\n");
|
466
462
|
|
463
|
+
|
464
|
+
|
465
|
+
}
|
466
|
+
|
467
|
+
|
468
|
+
|
469
|
+
|
470
|
+
|
471
|
+
int main()
|
472
|
+
|
473
|
+
{
|
474
|
+
|
475
|
+
create_matri_mp(1.0f,-1.0f,-1.0f,1.0f,1.0,10.f,mp);
|
476
|
+
|
477
|
+
|
478
|
+
|
479
|
+
|
480
|
+
|
481
|
+
|
482
|
+
|
483
|
+
float t[16];
|
484
|
+
|
485
|
+
mul(rotate,move,t);
|
486
|
+
|
487
|
+
// print_(t);
|
488
|
+
|
489
|
+
|
490
|
+
|
491
|
+
|
492
|
+
|
493
|
+
float t2[16];//M
|
494
|
+
|
495
|
+
mul(scale, t, t2);
|
496
|
+
|
497
|
+
// print_(t2);
|
498
|
+
|
499
|
+
|
500
|
+
|
467
|
-
for (int
|
501
|
+
for (int i = 0; i < 6; i++)
|
468
502
|
|
469
503
|
{
|
470
504
|
|
505
|
+
float t3[16];
|
506
|
+
|
507
|
+
mul(Vertex[i], t2, t3);
|
508
|
+
|
471
|
-
print
|
509
|
+
// print_(t2);
|
510
|
+
|
511
|
+
|
512
|
+
|
513
|
+
|
514
|
+
|
515
|
+
float t4[16];
|
516
|
+
|
517
|
+
mul(mp, t2, t4);
|
518
|
+
|
519
|
+
print_(t4);
|
472
520
|
|
473
521
|
}
|
474
522
|
|
475
|
-
printf("\n");
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
}
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
int main()
|
494
|
-
|
495
|
-
{
|
496
|
-
|
497
|
-
create_matri_mp(1.0f,-1.0f,-1.0f,1.0f,1.0,10.f,mp);
|
498
|
-
|
499
|
-
// print_matrix("透視射形",mp);
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
float t[4][4];
|
508
|
-
|
509
|
-
mul(rotate,move,t);
|
510
|
-
|
511
|
-
printf("\n\n\n\n\n");
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
float t2[4][4];//M
|
520
|
-
|
521
|
-
mul(scale, t, t2);
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
float t3[4];
|
528
|
-
|
529
|
-
mul_vec3_matrix(t2, Vertex[0], t3);
|
530
|
-
|
531
|
-
float t4[4];
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
mul_vec3_matrix(mp,t3,t4);
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
|
542
|
-
|
543
523
|
|
544
524
|
|
545
525
|
|
3
タイトルを編集しました。
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
GLSLで画面描画に使う行列を
|
1
|
+
GLSLで画面描画に使う透視投影変換行列を上手く設定できないZの値がマイナスになってしまう
|
test
CHANGED
@@ -6,6 +6,8 @@
|
|
6
6
|
|
7
7
|
最後の行列の値の設定関数**create_matri_mp();**関数ですがこれが悪いのでしょか?数式は変更できないため行列計算が間違えているのでしょうか?両方確認しましたがどれが間違えているのかどうしてもわかりません。また本来来るべき値とは1.0なのでしょうか?
|
8
8
|
|
9
|
+
|
10
|
+
|
9
11
|
教えてくれますでしょうか?
|
10
12
|
|
11
13
|
|
2
文章を編集しました参考サイトを追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -12,6 +12,22 @@
|
|
12
12
|
|
13
13
|
|
14
14
|
|
15
|
+
|
16
|
+
|
17
|
+
下記サイトの163ページの透視射形変換行列の数式を移しました。
|
18
|
+
|
19
|
+
参考サイト: https://tokoik.github.io/GLFWdraft.pdf
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
|
26
|
+
|
27
|
+
|
28
|
+
|
29
|
+
|
30
|
+
|
15
31
|
![イメージ説明](ca6577bf0fa866270240428e4a02568e.png)
|
16
32
|
|
17
33
|
|
1
文章を編集しました
test
CHANGED
File without changes
|
test
CHANGED
@@ -4,7 +4,9 @@
|
|
4
4
|
|
5
5
|
|
6
6
|
|
7
|
-
最後の行列の値の設定関数**create_matri_mp();**関数ですがこれが悪いのでしょか?数式は変更できないため行列計算が間違えているのでしょうか?両方確認しましたがどれが間違えているのかどうしてもわかりません。
|
7
|
+
最後の行列の値の設定関数**create_matri_mp();**関数ですがこれが悪いのでしょか?数式は変更できないため行列計算が間違えているのでしょうか?両方確認しましたがどれが間違えているのかどうしてもわかりません。また本来来るべき値とは1.0なのでしょうか?
|
8
|
+
|
9
|
+
教えてくれますでしょうか?
|
8
10
|
|
9
11
|
|
10
12
|
|