File tree Expand file tree Collapse file tree 1 file changed +20
-3
lines changed Expand file tree Collapse file tree 1 file changed +20
-3
lines changed Original file line number Diff line number Diff line change @@ -2448,17 +2448,34 @@ p5.Camera = class Camera {
2448
2448
rotatedCenter [ 1 ] += this . eyeY ;
2449
2449
rotatedCenter [ 2 ] += this . eyeZ ;
2450
2450
2451
+ // Compute new up vector to prevent flipping
2452
+ let forward = createVector (
2453
+ rotatedCenter [ 0 ] - this . eyeX ,
2454
+ rotatedCenter [ 1 ] - this . eyeY ,
2455
+ rotatedCenter [ 2 ] - this . eyeZ
2456
+ ) . normalize ( ) ;
2457
+
2458
+ let up = createVector ( this . upX , this . upY , this . upZ ) ;
2459
+ let right = p5 . Vector . cross ( forward , up ) . normalize ( ) ; // Right vector
2460
+ up = p5 . Vector . cross ( right , forward ) . normalize ( ) ; // Corrected up vector
2461
+
2462
+
2451
2463
this . camera (
2452
2464
this . eyeX ,
2453
2465
this . eyeY ,
2454
2466
this . eyeZ ,
2455
2467
rotatedCenter [ 0 ] ,
2456
2468
rotatedCenter [ 1 ] ,
2457
2469
rotatedCenter [ 2 ] ,
2458
- this . upX ,
2459
- this . upY ,
2460
- this . upZ
2470
+ this . up . x ,
2471
+ this . up . y ,
2472
+ this . up . z
2461
2473
) ;
2474
+
2475
+ // Update up vector
2476
+ this . upX = up . x ;
2477
+ this . upY = up . y ;
2478
+ this . upZ = up . z ;
2462
2479
}
2463
2480
2464
2481
/**
You can’t perform that action at this time.
0 commit comments