Skip to content
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Added test on Rotated Up Vector
  • Loading branch information
Forchapeatl authored Apr 6, 2025
commit 80cf66e1fa05ce05fbd1fa2cf9218cea4b5ab84d
48 changes: 48 additions & 0 deletions test/unit/webgl/p5.Camera.js
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,54 @@
});
});

suite('Camera Tilt and Up Vector', function() {
test('Tilt() correctly updates the up vector', function() {
var orig = getVals(myCam); // Store original camera values

// Apply tilt to the camera
myCam.tilt(30); // Tilt by 30 degrees
// Compute expected up vector (normalized)
let forward = myp5.createVector(
myCam.centerX - myCam.eyeX,
myCam.centerY - myCam.eyeY,
myCam.centerZ - myCam.eyeZ
);
let up = myp5.createVector(orig.ux, orig.uy, orig.uz);
let right = p5.Vector.cross(forward, up);
let expectedUp = p5.Vector.cross(right, forward).normalize();
// Verify that the up vector has changed
assert.notStrictEqual(myCam.upX, orig.ux, 'upX should be updated');

Check failure on line 308 in test/unit/webgl/p5.Camera.js

View workflow job for this annotation

GitHub Actions / test

test/unit/webgl/p5.Camera.js > p5.Camera > Camera Tilt and Up Vector > Tilt() correctly updates the up vector

AssertionError: upX should be updated: expected +0 to not equal +0 ❯ test/unit/webgl/p5.Camera.js:308:14
assert.notStrictEqual(myCam.upY, orig.uy, 'upY should be updated');
assert.notStrictEqual(myCam.upZ, orig.uz, 'upZ should be updated');
// Verify up vector matches expected values within a small margin of error
assert.closeTo(myCam.upX, expectedUp.x, 0.001, 'upX mismatch');
assert.closeTo(myCam.upY, expectedUp.y, 0.001, 'upY mismatch');
assert.closeTo(myCam.upZ, expectedUp.z, 0.001, 'upZ mismatch');
});

test('Tilt() with negative angle correctly updates the up vector', function() {
var orig = getVals(myCam); // Store original camera values
myCam.tilt(-30); // Tilt by -30 degrees
// Compute expected up vector (normalized)
let forward = myp5.createVector(
myCam.centerX - myCam.eyeX,
myCam.centerY - myCam.eyeY,
myCam.centerZ - myCam.eyeZ
);
let up = myp5.createVector(orig.ux, orig.uy, orig.uz);
let right = p5.Vector.cross(forward, up);
let expectedUp = p5.Vector.cross(right, forward).normalize();
// Verify that the up vector has changed
assert.notStrictEqual(myCam.upX, orig.ux, 'upX should be updated');

Check failure on line 330 in test/unit/webgl/p5.Camera.js

View workflow job for this annotation

GitHub Actions / test

test/unit/webgl/p5.Camera.js > p5.Camera > Camera Tilt and Up Vector > Tilt() with negative angle correctly updates the up vector

AssertionError: upX should be updated: expected +0 to not equal +0 ❯ test/unit/webgl/p5.Camera.js:330:14
assert.notStrictEqual(myCam.upY, orig.uy, 'upY should be updated');
assert.notStrictEqual(myCam.upZ, orig.uz, 'upZ should be updated');
// Verify up vector matches expected values within a small margin of error
assert.closeTo(myCam.upX, expectedUp.x, 0.001, 'upX mismatch');
assert.closeTo(myCam.upY, expectedUp.y, 0.001, 'upY mismatch');
assert.closeTo(myCam.upZ, expectedUp.z, 0.001, 'upZ mismatch');
});
});

suite('Rotation with angleMode(DEGREES)', function() {
beforeEach(function() {
myp5.push();
Expand Down
Loading