Skip to content

Commit 1ac8e43

Browse files
authored
removed create vector error
1 parent 961dc63 commit 1ac8e43

File tree

1 file changed

+11
-19
lines changed

1 file changed

+11
-19
lines changed

src/webgl/p5.Camera.js

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2435,6 +2435,7 @@ p5.Camera = class Camera {
24352435
const rotation = p5.Matrix.identity(this._renderer._pInst);
24362436
rotation.rotate(this._renderer._pInst._toRadians(a), x, y, z);
24372437

2438+
// Apply the rotation matrix to the center vector
24382439
/* eslint-disable max-len */
24392440
const rotatedCenter = [
24402441
centerX * rotation.mat4[0] + centerY * rotation.mat4[4] + centerZ * rotation.mat4[8],
@@ -2443,21 +2444,17 @@ p5.Camera = class Camera {
24432444
];
24442445
/* eslint-enable max-len */
24452446

2446-
// add eye position back into center
2447+
// Translate the rotated center back to world coordinates
24472448
rotatedCenter[0] += this.eyeX;
24482449
rotatedCenter[1] += this.eyeY;
24492450
rotatedCenter[2] += this.eyeZ;
24502451

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 */
24612458

24622459
this.camera(
24632460
this.eyeX,
@@ -2466,15 +2463,10 @@ p5.Camera = class Camera {
24662463
rotatedCenter[0],
24672464
rotatedCenter[1],
24682465
rotatedCenter[2],
2469-
this.up.x,
2470-
this.up.y,
2471-
this.up.z
2466+
upX,
2467+
upY,
2468+
upZ
24722469
);
2473-
2474-
// Update up vector
2475-
this.upX = up.x;
2476-
this.upY = up.y;
2477-
this.upZ = up.z;
24782470
}
24792471

24802472
/**

0 commit comments

Comments
 (0)