@@ -2435,6 +2435,7 @@ p5.Camera = class Camera {
2435
2435
const rotation = p5 . Matrix . identity ( this . _renderer . _pInst ) ;
2436
2436
rotation . rotate ( this . _renderer . _pInst . _toRadians ( a ) , x , y , z ) ;
2437
2437
2438
+ // Apply the rotation matrix to the center vector
2438
2439
/* eslint-disable max-len */
2439
2440
const rotatedCenter = [
2440
2441
centerX * rotation . mat4 [ 0 ] + centerY * rotation . mat4 [ 4 ] + centerZ * rotation . mat4 [ 8 ] ,
@@ -2443,21 +2444,17 @@ p5.Camera = class Camera {
2443
2444
] ;
2444
2445
/* eslint-enable max-len */
2445
2446
2446
- // add eye position back into center
2447
+ // Translate the rotated center back to world coordinates
2447
2448
rotatedCenter [ 0 ] += this . eyeX ;
2448
2449
rotatedCenter [ 1 ] += this . eyeY ;
2449
2450
rotatedCenter [ 2 ] += this . eyeZ ;
2450
2451
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
2452
+ // Rotate the up vector to keep the correct camera orientation
2453
+ /* eslint-disable max-len */
2454
+ const upX = this . upX * rotation . mat4 [ 0 ] + this . upY * rotation . mat4 [ 4 ] + this . upZ * rotation . mat4 [ 8 ] ;
2455
+ const upY = this . upX * rotation . mat4 [ 1 ] + this . upY * rotation . mat4 [ 5 ] + this . upZ * rotation . mat4 [ 9 ] ;
2456
+ const upZ = this . upX * rotation . mat4 [ 2 ] + this . upY * rotation . mat4 [ 6 ] + this . upZ * rotation . mat4 [ 10 ] ;
2457
+ /* eslint-enable max-len */
2461
2458
2462
2459
this . camera (
2463
2460
this . eyeX ,
@@ -2466,15 +2463,10 @@ p5.Camera = class Camera {
2466
2463
rotatedCenter [ 0 ] ,
2467
2464
rotatedCenter [ 1 ] ,
2468
2465
rotatedCenter [ 2 ] ,
2469
- this . up . x ,
2470
- this . up . y ,
2471
- this . up . z
2466
+ upX ,
2467
+ upY ,
2468
+ upZ
2472
2469
) ;
2473
-
2474
- // Update up vector
2475
- this . upX = up . x ;
2476
- this . upY = up . y ;
2477
- this . upZ = up . z ;
2478
2470
}
2479
2471
2480
2472
/**
0 commit comments