@@ -498,30 +498,116 @@ double cosineAngleBetweenLines(mmdata::LinePair2D linePair) {
498
498
return angle_cosine;
499
499
}
500
500
501
- void createLookAtMatrix (const mmdata::Vector3D &dir,
502
- mmdata::Matrix4x4 &out_matrix) {
501
+ // Implementation detail. Do not reveal this to users of the API.
502
+ void impl_createLookAtMatrix (const mmdata::Vector3D &dir,
503
+ const mmdata::Vector3D &temp_up,
504
+ mmdata::Vector3D &out_forward,
505
+ mmdata::Vector3D &out_right,
506
+ mmdata::Vector3D &out_up) {
507
+ out_forward.x_ = dir.x_ ;
508
+ out_forward.y_ = dir.y_ ;
509
+ out_forward.z_ = dir.z_ ;
510
+ out_forward = mmmath::normalize (out_forward);
511
+
512
+ out_right = mmmath::cross (temp_up, out_forward);
513
+ out_right = mmmath::normalize (out_right);
514
+
515
+ out_up = mmmath::cross (out_forward, out_right);
516
+ out_up = mmmath::normalize (out_up);
517
+ }
518
+
519
+ void createLookAtMatrixAxisX (const mmdata::Vector3D &dir,
520
+ mmdata::Matrix4x4 &out_matrix) {
503
521
const auto temp_up = mmdata::Vector3D (0.0 , 1.0 , 0.0 );
522
+ auto forward = mmdata::Vector3D ();
523
+ auto right = mmdata::Vector3D ();
524
+ auto up = mmdata::Vector3D ();
525
+ impl_createLookAtMatrix (dir, temp_up, forward, right, up);
526
+
527
+ // X axis. Looking towards this axis.
528
+ out_matrix.m00_ = forward.x_ ;
529
+ out_matrix.m01_ = forward.y_ ;
530
+ out_matrix.m02_ = forward.z_ ;
531
+ out_matrix.m03_ = 0.0 ;
532
+
533
+ // Y axis.
534
+ out_matrix.m10_ = up.x_ ;
535
+ out_matrix.m11_ = up.y_ ;
536
+ out_matrix.m12_ = up.z_ ;
537
+ out_matrix.m13_ = 0.0 ;
538
+
539
+ // Z axis.
540
+ out_matrix.m20_ = right.x_ ;
541
+ out_matrix.m21_ = right.y_ ;
542
+ out_matrix.m22_ = right.z_ ;
543
+ out_matrix.m23_ = 0.0 ;
544
+
545
+ // Translations (unused).
546
+ out_matrix.m30_ = 0.0 ;
547
+ out_matrix.m31_ = 0.0 ;
548
+ out_matrix.m32_ = 0.0 ;
549
+ out_matrix.m33_ = 1.0 ;
550
+ }
551
+
552
+ void createLookAtMatrixAxisY (const mmdata::Vector3D &dir,
553
+ mmdata::Matrix4x4 &out_matrix) {
554
+ auto forward = mmdata::Vector3D ();
555
+ auto right = mmdata::Vector3D ();
556
+ auto up = mmdata::Vector3D ();
557
+ const auto temp_up = mmdata::Vector3D (0.0 , 0.0 , 1.0 );
558
+ impl_createLookAtMatrix (dir, temp_up, forward, right, up);
504
559
505
- auto forward = mmdata::Vector3D (dir.x_ , dir.y_ , dir.z_ );
506
- forward = mmmath::normalize (forward);
560
+ // X axis.
561
+ out_matrix.m00_ = right.x_ ;
562
+ out_matrix.m01_ = right.y_ ;
563
+ out_matrix.m02_ = right.z_ ;
564
+ out_matrix.m03_ = 0.0 ;
507
565
508
- auto right = mmmath::cross (temp_up, forward);
509
- right = mmmath::normalize (right);
566
+ // Y axis. Looking towards this axis.
567
+ out_matrix.m10_ = forward.x_ ;
568
+ out_matrix.m11_ = forward.y_ ;
569
+ out_matrix.m12_ = forward.z_ ;
570
+ out_matrix.m13_ = 0.0 ;
510
571
511
- auto up = mmmath::cross (forward, right);
512
- up = mmmath::normalize (up);
572
+ // Z axis.
573
+ out_matrix.m20_ = up.x_ ;
574
+ out_matrix.m21_ = up.y_ ;
575
+ out_matrix.m22_ = up.z_ ;
576
+ out_matrix.m23_ = 0.0 ;
513
577
578
+ // Translations (unused).
579
+ out_matrix.m30_ = 0.0 ;
580
+ out_matrix.m31_ = 0.0 ;
581
+ out_matrix.m32_ = 0.0 ;
582
+ out_matrix.m33_ = 1.0 ;
583
+ }
584
+
585
+ void createLookAtMatrixAxisZ (const mmdata::Vector3D &dir,
586
+ mmdata::Matrix4x4 &out_matrix) {
587
+ auto forward = mmdata::Vector3D ();
588
+ auto right = mmdata::Vector3D ();
589
+ auto up = mmdata::Vector3D ();
590
+ const auto temp_up = mmdata::Vector3D (0.0 , 1.0 , 0.0 );
591
+ impl_createLookAtMatrix (dir, temp_up, forward, right, up);
592
+
593
+ // X axis.
514
594
out_matrix.m00_ = right.x_ ;
515
595
out_matrix.m01_ = right.y_ ;
516
596
out_matrix.m02_ = right.z_ ;
517
597
out_matrix.m03_ = 0.0 ;
598
+
599
+ // Y axis.
518
600
out_matrix.m10_ = up.x_ ;
519
601
out_matrix.m11_ = up.y_ ;
520
602
out_matrix.m12_ = up.z_ ;
521
603
out_matrix.m13_ = 0.0 ;
604
+
605
+ // Z axis. Looking towards this axis.
522
606
out_matrix.m20_ = forward.x_ ;
523
607
out_matrix.m21_ = forward.y_ ;
524
608
out_matrix.m22_ = forward.z_ ;
609
+
610
+ // Translations (unused).
525
611
out_matrix.m23_ = 0.0 ;
526
612
out_matrix.m30_ = 0.0 ;
527
613
out_matrix.m31_ = 0.0 ;
0 commit comments