Skip to content

Commit 4e18ee7

Browse files
authored
Merge branch 'main' into all-contributors/add-himanshuukholiya
2 parents 9eb7f17 + a023d54 commit 4e18ee7

File tree

5 files changed

+97
-8
lines changed

5 files changed

+97
-8
lines changed

.all-contributorsrc

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6233,7 +6233,8 @@
62336233
"avatar_url": "https://avatars.githubusercontent.com/u/7389189?v=4",
62346234
"profile": "https://github.com/AaratiAkkapeddi",
62356235
"contributions": [
6236-
"code"
6236+
"code",
6237+
"ideas"
62376238
]
62386239
},
62396240
{
@@ -6710,6 +6711,24 @@
67106711
"contributions": [
67116712
"code"
67126713
]
6714+
},
6715+
{
6716+
"login": "mclark414",
6717+
"name": "mclark414",
6718+
"avatar_url": "https://avatars.githubusercontent.com/u/26391144?v=4",
6719+
"profile": "https://github.com/mclark414",
6720+
"contributions": [
6721+
"ideas"
6722+
]
6723+
},
6724+
{
6725+
"login": "mxramsey",
6726+
"name": "Mx. Ramsey",
6727+
"avatar_url": "https://avatars.githubusercontent.com/u/161327383?v=4",
6728+
"profile": "https://github.com/mxramsey",
6729+
"contributions": [
6730+
"ideas"
6731+
]
67136732
}
67146733
],
67156734
"repoType": "github",

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1044,7 +1044,7 @@ We recognize all types of contributions. This project follows the [all-contribut
10441044
<td align="center" valign="top" width="16.66%"><a href="https://github.com/c-dacanay"><img src="https://avatars.githubusercontent.com/u/54914834?v=4?s=120" width="120px;" alt="c-dacanay"/><br /><sub><b>c-dacanay</b></sub></a><br /><a href="#design-c-dacanay" title="Design">🎨</a> <a href="#eventOrganizing-c-dacanay" title="Event Organizing">📋</a> <a href="#example-c-dacanay" title="Examples">💡</a></td>
10451045
<td align="center" valign="top" width="16.66%"><a href="https://github.com/mathewpan2"><img src="https://avatars.githubusercontent.com/u/112679001?v=4?s=120" width="120px;" alt="mathewpan2"/><br /><sub><b>mathewpan2</b></sub></a><br /><a href="https://github.com/processing/p5.js/commits?author=mathewpan2" title="Code">💻</a></td>
10461046
<td align="center" valign="top" width="16.66%"><a href="https://github.com/cog25"><img src="https://avatars.githubusercontent.com/u/74242561?v=4?s=120" width="120px;" alt="cog25"/><br /><sub><b>cog25</b></sub></a><br /><a href="#translation-cog25" title="Translation">🌍</a></td>
1047-
<td align="center" valign="top" width="16.66%"><a href="https://github.com/AaratiAkkapeddi"><img src="https://avatars.githubusercontent.com/u/7389189?v=4?s=120" width="120px;" alt="Aarati Akkapeddi "/><br /><sub><b>Aarati Akkapeddi </b></sub></a><br /><a href="https://github.com/processing/p5.js/commits?author=AaratiAkkapeddi" title="Code">💻</a></td>
1047+
<td align="center" valign="top" width="16.66%"><a href="https://github.com/AaratiAkkapeddi"><img src="https://avatars.githubusercontent.com/u/7389189?v=4?s=120" width="120px;" alt="Aarati Akkapeddi "/><br /><sub><b>Aarati Akkapeddi </b></sub></a><br /><a href="https://github.com/processing/p5.js/commits?author=AaratiAkkapeddi" title="Code">💻</a> <a href="#ideas-AaratiAkkapeddi" title="Ideas, Planning, & Feedback">🤔</a></td>
10481048
</tr>
10491049
<tr>
10501050
<td align="center" valign="top" width="16.66%"><a href="https://mayaarguelles.com/"><img src="https://avatars.githubusercontent.com/u/29130029?v=4?s=120" width="120px;" alt="Maya Arguelles"/><br /><sub><b>Maya Arguelles</b></sub></a><br /><a href="https://github.com/processing/p5.js/commits?author=mayaarguelles" title="Code">💻</a></td>
@@ -1113,6 +1113,8 @@ We recognize all types of contributions. This project follows the [all-contribut
11131113
<tr>
11141114
<td align="center" valign="top" width="16.66%"><a href="https://github.com/webermayank"><img src="https://avatars.githubusercontent.com/u/111176033?v=4?s=120" width="120px;" alt="Mayank Verma"/><br /><sub><b>Mayank Verma</b></sub></a><br /><a href="https://github.com/processing/p5.js/commits?author=webermayank" title="Code">💻</a></td>
11151115
<td align="center" valign="top" width="16.66%"><a href="https://github.com/himanshuukholiya"><img src="https://avatars.githubusercontent.com/u/128818464?v=4?s=120" width="120px;" alt="Himanshu Kholiya"/><br /><sub><b>Himanshu Kholiya</b></sub></a><br /><a href="https://github.com/processing/p5.js/commits?author=himanshuukholiya" title="Code">💻</a></td>
1116+
<td align="center" valign="top" width="16.66%"><a href="https://github.com/mclark414"><img src="https://avatars.githubusercontent.com/u/26391144?v=4?s=120" width="120px;" alt="mclark414"/><br /><sub><b>mclark414</b></sub></a><br /><a href="#ideas-mclark414" title="Ideas, Planning, & Feedback">🤔</a></td>
1117+
<td align="center" valign="top" width="16.66%"><a href="https://github.com/mxramsey"><img src="https://avatars.githubusercontent.com/u/161327383?v=4?s=120" width="120px;" alt="Mx. Ramsey"/><br /><sub><b>Mx. Ramsey</b></sub></a><br /><a href="#ideas-mxramsey" title="Ideas, Planning, & Feedback">🤔</a></td>
11161118
</tr>
11171119
</tbody>
11181120
</table>

src/accessibility/outputs.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -579,8 +579,13 @@ p5.prototype._getPos = function (x, y) {
579579
function _canvasLocator(args, canvasWidth, canvasHeight) {
580580
const noRows = 10;
581581
const noCols = 10;
582-
let locX = Math.floor(args[0] / canvasWidth * noRows);
583-
let locY = Math.floor(args[1] / canvasHeight * noCols);
582+
let x = args[0];
583+
let y = args[1];
584+
if (x < 0 || x >= canvasWidth || y < 0 || y >= canvasHeight) {
585+
return null;
586+
}
587+
let locX = Math.floor(x / canvasWidth * noRows);
588+
let locY = Math.floor(y / canvasHeight * noCols);
584589
if (locX === noRows) {
585590
locX = locX - 1;
586591
}

src/webgl/p5.Camera.js

Lines changed: 12 additions & 4 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,28 @@ 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

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 */
2458+
24512459
this.camera(
24522460
this.eyeX,
24532461
this.eyeY,
24542462
this.eyeZ,
24552463
rotatedCenter[0],
24562464
rotatedCenter[1],
24572465
rotatedCenter[2],
2458-
this.upX,
2459-
this.upY,
2460-
this.upZ
2466+
upX,
2467+
upY,
2468+
upZ
24612469
);
24622470
}
24632471

test/unit/webgl/p5.Camera.js

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,61 @@ suite('p5.Camera', function() {
277277
assert.strictEqual(myCam.upY, orig.uy, 'up Y pos changed');
278278
assert.strictEqual(myCam.upZ, orig.uz, 'up Z pos changed');
279279
});
280+
281+
suite('Camera Tilt and Up Vector', function() {
282+
test('Tilt() correctly updates the up vector', function() {
283+
var orig = getVals(myCam); // Store original camera values
284+
285+
// Apply tilt to the camera
286+
myCam.tilt(30); // Tilt by 30 degrees
287+
288+
// Compute expected up vector (normalized)
289+
let forward = myp5.createVector(
290+
myCam.centerX - myCam.eyeX,
291+
myCam.centerY - myCam.eyeY,
292+
myCam.centerZ - myCam.eyeZ
293+
);
294+
let up = myp5.createVector(orig.ux, orig.uy, orig.uz);
295+
let right = p5.Vector.cross(forward, up);
296+
let expectedUp = p5.Vector.cross(right, forward).normalize();
297+
298+
// Verify that the up vector has changed
299+
assert.notStrictEqual(myCam.upX, orig.ux, 'upX should be updated');
300+
assert.notStrictEqual(myCam.upY, orig.uy, 'upY should be updated');
301+
assert.notStrictEqual(myCam.upZ, orig.uz, 'upZ should be updated');
302+
303+
// Verify up vector matches expected values within a small margin of error
304+
assert.closeTo(myCam.upX, expectedUp.x, 0.001, 'upX mismatch');
305+
assert.closeTo(myCam.upY, expectedUp.y, 0.001, 'upY mismatch');
306+
assert.closeTo(myCam.upZ, expectedUp.z, 0.001, 'upZ mismatch');
307+
});
308+
309+
test('Tilt() with negative angle correctly updates the up vector', function() {
310+
var orig = getVals(myCam); // Store original camera values
311+
312+
myCam.tilt(-30); // Tilt by -30 degrees
313+
314+
// Compute expected up vector (normalized)
315+
let forward = myp5.createVector(
316+
myCam.centerX - myCam.eyeX,
317+
myCam.centerY - myCam.eyeY,
318+
myCam.centerZ - myCam.eyeZ
319+
);
320+
let up = myp5.createVector(orig.ux, orig.uy, orig.uz);
321+
let right = p5.Vector.cross(forward, up);
322+
let expectedUp = p5.Vector.cross(right, forward).normalize();
323+
324+
// Verify that the up vector has changed
325+
assert.notStrictEqual(myCam.upX, orig.ux, 'upX should be updated');
326+
assert.notStrictEqual(myCam.upY, orig.uy, 'upY should be updated');
327+
assert.notStrictEqual(myCam.upZ, orig.uz, 'upZ should be updated');
328+
329+
// Verify up vector matches expected values within a small margin of error
330+
assert.closeTo(myCam.upX, expectedUp.x, 0.001, 'upX mismatch');
331+
assert.closeTo(myCam.upY, expectedUp.y, 0.001, 'upY mismatch');
332+
assert.closeTo(myCam.upZ, expectedUp.z, 0.001, 'upZ mismatch');
333+
});
334+
});
280335
});
281336

282337
suite('Rotation with angleMode(DEGREES)', function() {

0 commit comments

Comments
 (0)