@@ -397,11 +397,124 @@ function vtkCamera(publicAPI, model) {
397
397
398
398
mat4 . scale ( result , result , tmpvec1 ) ;
399
399
mat4 . translate ( result , result , model . physicalTranslation ) ;
400
+
401
+ // let rot = mat4.identity(new Float64Array(16));
402
+ //mat4.fromRotation(rot, model.physicalYawAngle / 180 * 3.14, model.physicalViewUp);
403
+ //// mat4.invert(rot, rot);
404
+ //mat4.mul(result, rot, result);
405
+
406
+ //let tmpRot = mat4.identity(new Float64Array(16));
407
+ //let matInv = mat4.identity(new Float64Array(16));
408
+ //mat4.rotateY(tmpRot, tmpRot, model.physicalYawAngle / 180 * 3.14);
409
+ //mat4.transpose(tmpRot, tmpRot);
410
+ //mat4.invert(matInv, )
411
+ // mat4.mul(result, tmpRot, result);
412
+ } ;
413
+
414
+ publicAPI . applyPhysicalYaw = ( angle ) => {
415
+ model . physicalYawAngle += angle ;
416
+ if ( model . physicalYawAngle > 360 ) {
417
+ model . physicalYawAngle -= 360 ;
418
+ } else if ( model . physicalYawAngle < 0 ) {
419
+ model . physicalYawAngle += 360 ;
420
+ }
400
421
} ;
401
422
402
423
publicAPI . computeViewParametersFromViewMatrix = ( vmat ) => {
403
424
// invert to get view to world
404
- mat4 . invert ( tmpMatrix , vmat ) ;
425
+ let worldToViewPos = new Float64Array ( 4 ) ;
426
+ let viewToWorldPos = new Float64Array ( 4 ) ;
427
+ let v2wMatrix = new Float64Array ( 16 ) ;
428
+ worldToViewPos [ 0 ] = vmat [ 12 ] ;
429
+ worldToViewPos [ 1 ] = vmat [ 13 ] ;
430
+ worldToViewPos [ 2 ] = vmat [ 14 ] ;
431
+ worldToViewPos [ 3 ] = 1 ;
432
+ mat4 . invert ( v2wMatrix , vmat ) ;
433
+ viewToWorldPos [ 0 ] = v2wMatrix [ 12 ] ;
434
+ viewToWorldPos [ 1 ] = v2wMatrix [ 13 ] ;
435
+ viewToWorldPos [ 2 ] = v2wMatrix [ 14 ] ;
436
+ viewToWorldPos [ 3 ] = 1 ;
437
+ mat4 . copy ( tmpMatrix , v2wMatrix ) ;
438
+ //console.log('View -> World');
439
+ //console.log(v2wMatrix);
440
+ //mat4.copy(tmpMatrix, vmat);
441
+ //v[0] = tmpMatrix[12]; //tmpMatrix[12] = 0;
442
+ //tmpMatrix[13] = 0;
443
+ //tmpMatrix[14] = 0;
444
+ //mat4.invert(tmpMatrix, tmpMatrix);
445
+
446
+ ////
447
+ ////
448
+ //// mat4.invert(tmpMatrix, tmpMatrix);
449
+ //// mat4.rotateY(tmpMatrix, tmpMatrix, model.physicalYawAngle / 180 * 3.14);
450
+ //// mat4.translate(tmpMatrix, tmpMatrix, [-v[0], -v[1], -v[2]]);
451
+
452
+ ////// Correct center of rotation, incorrect view translation
453
+ ////mat4.invert(tmpMatrix, tmpMatrix);
454
+ ////mat4.rotateY(tmpMatrix, tmpMatrix, model.physicalYawAngle / 180 * 3.14);
455
+
456
+ //// Correct view translation, incorrect center of rotation
457
+ //// mat4.invert(tmpMatrix, tmpMatrix););
458
+ ////let tmp = mat4.identity(new Float64Array(16));
459
+ ////tmpMatrix[12] = 0;
460
+ ////tmpMatrix[14] = 0;
461
+ //mat4.invert(tmpMatrix, tmpMatrix);
462
+
463
+ let w2vTranslate = mat4 . identity ( new Float64Array ( 16 ) ) ;
464
+ let rotate = mat4 . identity ( new Float64Array ( 16 ) ) ;
465
+ let rotateRev = mat4 . identity ( new Float64Array ( 16 ) ) ;
466
+ let w2vTranslateReverse = mat4 . identity ( new Float64Array ( 16 ) ) ;
467
+ let v2wTranslate = mat4 . identity ( new Float64Array ( 16 ) ) ;
468
+ let v2wTranslateReverse = mat4 . identity ( new Float64Array ( 16 ) ) ;
469
+
470
+ mat4 . translate ( v2wTranslate , v2wTranslate , [
471
+ - viewToWorldPos [ 0 ] ,
472
+ - viewToWorldPos [ 1 ] ,
473
+ - viewToWorldPos [ 2 ] ,
474
+ ] ) ;
475
+ mat4 . rotateY ( rotate , rotate , ( model . physicalYawAngle / 180 ) * 3.14 ) ;
476
+ mat4 . rotateY (
477
+ rotateRev ,
478
+ rotateRev ,
479
+ ( ( - 1 * model . physicalYawAngle ) / 180 ) * 3.14
480
+ ) ;
481
+ mat4 . translate ( v2wTranslateReverse , v2wTranslateReverse , viewToWorldPos ) ;
482
+ mat4 . translate ( w2vTranslate , w2vTranslate , [
483
+ - worldToViewPos [ 0 ] ,
484
+ - worldToViewPos [ 1 ] ,
485
+ - worldToViewPos [ 2 ] ,
486
+ ] ) ;
487
+ mat4 . translate ( w2vTranslateReverse , w2vTranslateReverse , worldToViewPos ) ;
488
+
489
+ //mat4.mul(tmpMatrix, w2vTranslate, vmat);
490
+ //mat4.mul(tmpMatrix, rotate, tmpMatrix);
491
+ //mat4.mul(tmpMatrix, w2vTranslateReverse, tmpMatrix);
492
+ //mat4.invert(tmpMatrix, tmpMatrix);
493
+
494
+ // FIXME works post-snap? mat4.mul(v2wTranslateReverse, v2wTranslate, rotate);
495
+ // mat4.mul(v2wTranslate, v2wTranslate, rotate);
496
+ //mat4.mul(v2wTranslateReverse, v2wTranslateReverse, rotate);
497
+ mat4 . mul ( v2wTranslateReverse , v2wTranslate , rotate ) ;
498
+ mat4 . mul ( tmpMatrix , v2wTranslateReverse , v2wMatrix ) ;
499
+ mat4 . mul ( tmpMatrix , tmpMatrix , rotate ) ;
500
+ mat4 . mul ( tmpMatrix , v2wTranslate , tmpMatrix ) ;
501
+
502
+ //mat4.rotateY(tmpMatrix, tmpMatrix, -1 * model.physicalYawAngle / 180 * 3.14);
503
+ //mat4.translate(tmpMatrix, tmpMatrix, [0, 0, 0.01 * model.physicalYawAngle]);
504
+ //mat4.translate(tmpMatrix, tmpMatrix, v);
505
+ //mat4.invert(tmpMatrix, tmpMatrix);
506
+ ////
507
+ //mat4.invert(tmpMatrix, tmpMatrix);
508
+ //tmpMatrix[12] = v[0];
509
+ //tmpMatrix[13] = v[1];
510
+ //tmpMatrix[14] = v[2];
511
+
512
+ // FIXME try pushing through the cone position at <0,0,-1>
513
+ //v[0] = 0;
514
+ //v[1] = 0;
515
+ //v[1] = -1;
516
+ //vec3.transformMat4(tmpvec1, v, tmpMatrix);
517
+ // console.log(v);
405
518
406
519
// note with glmatrix operations happen in
407
520
// the reverse order
@@ -443,6 +556,27 @@ function vtkCamera(publicAPI, model) {
443
556
// world -> view
444
557
mat4 . multiply ( tmpMatrix , mat , tmpMatrix ) ;
445
558
559
+ console . log ( 'orig' ) ;
560
+ console . log ( tmpMatrix ) ;
561
+ let rot = mat4 . identity ( new Float64Array ( 16 ) ) ;
562
+ let v = new Float64Array ( 3 ) ;
563
+ v [ 0 ] = tmpMatrix [ 12 ] ;
564
+ v [ 1 ] = tmpMatrix [ 13 ] ;
565
+ v [ 2 ] = tmpMatrix [ 14 ] ;
566
+ //mat4.rotateY(rot, rot, model.physicalYawAngle / 180 * 3.14);
567
+ // mat4.transpose(rot, rot);
568
+ //mat4.translate(tmpMatrix, tmpMatrix, [-v[0], -v[1], -v[2]]);
569
+ mat4 . mul ( tmpMatrix , tmpMatrix , rot ) ;
570
+ tmpMatrix [ 12 ] = v [ 0 ] ;
571
+ tmpMatrix [ 13 ] = v [ 1 ] ;
572
+ tmpMatrix [ 14 ] = v [ 2 ] ;
573
+ //mat4.mul(tmpMatrix, rot, tmpMatrix);
574
+ //mat4.translate(tmpMatrix, tmpMatrix, v);
575
+
576
+ console . log ( tmpMatrix ) ;
577
+ let tmp = tmpMatrix [ 12 ] ;
578
+ //tmpMatrix[12] = tmpMatrix[14];
579
+ //tmpMatrix[14] = tmp;
446
580
publicAPI . computeViewParametersFromViewMatrix ( tmpMatrix ) ;
447
581
} ;
448
582
@@ -721,6 +855,8 @@ export const DEFAULT_VALUES = {
721
855
physicalScale : 1.0 ,
722
856
physicalViewUp : [ 0 , 1 , 0 ] ,
723
857
physicalViewNorth : [ 0 , 0 , - 1 ] ,
858
+
859
+ physicalYawAngle : 0 ,
724
860
} ;
725
861
726
862
// ----------------------------------------------------------------------------
0 commit comments