-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Solves issue #7059 #7113
Solves issue #7059 #7113
Changes from 3 commits
260fd59
4366334
eeed9c9
420067b
d7fc17d
c10c423
09343bf
54547c3
c2e87bd
b7436b8
6e9f46c
d8a87a0
bd4a5a3
8163082
a0ce81d
de3c777
85244c0
23accfe
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -236,4 +236,41 @@ suite('Environment', function() { | |||
assert.isNumber(myp5.displayDensity(), pd); | ||||
}); | ||||
}); | ||||
|
||||
suite('2D context test', function() { | ||||
beforeEach(function() { | ||||
myp5.createCanvas(100, 100); | ||||
}); | ||||
|
||||
test('worldToScreen for 2D context', function() { | ||||
let worldPos = myp5.createVector(50, 50); | ||||
let screenPos = myp5.worldToScreen(worldPos); | ||||
assert.closeTo(screenPos.x, 50, 0.1); | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This one is great! Can we add a test of rotation in 2D too? |
||||
assert.closeTo(screenPos.y, 50, 0.1); | ||||
}); | ||||
|
||||
}); | ||||
|
||||
suite('3D context test', function() { | ||||
beforeEach(function() { | ||||
myp5.createCanvas(100, 100, myp5.WEBGL); | ||||
}); | ||||
|
||||
test('worldToScreen for 3D context', function() { | ||||
let worldPos = myp5.createVector(0, 0, 0); | ||||
let screenPos = myp5.worldToScreen(worldPos); | ||||
assert.isTrue(screenPos.x >= 0 && screenPos.x <= 100); | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you think we can assert exact coordinates for the 3D tests like we do for the 2D tests instead of having a range like this? e.g. 50, 50 in this case, and I think 50, 100 in the second case? |
||||
assert.isTrue(screenPos.y >= 0 && screenPos.y <= 100); | ||||
}); | ||||
|
||||
test('worldToScreen with rotation', function() { | ||||
myp5.push(); | ||||
myp5.rotateY(myp5.PI / 2); | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar comment here: just rotating won't affect the coordinates, so could we do a translation after this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. actually, ignore that, as mentioned above, it should be ok as long as you're converting a nonzero coordinate. But it feels odd that the resulting coordinate would still be 50,50 since the untransformed example above also ends up at that. should this value be something else? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Maybe it should be What are your thoughts on this @davepagurek please let me know?! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh, I definitely didn't catch that this was a p5.js/test/unit/core/environment.js Line 242 in 420067b
So I think this result does actually make sense, and maybe we should just add one more test of rotation about the Z axis so that we can confirm that an example like the one you use in the 2D tests also works in WebGL. |
||||
let worldPos = myp5.createVector(50, 0, 0); | ||||
let screenPos = myp5.worldToScreen(worldPos); | ||||
myp5.pop(); | ||||
assert.isTrue(screenPos.x >= 0 && screenPos.x <= 100); | ||||
assert.isTrue(screenPos.y >= 0 && screenPos.y <= 100); | ||||
}); | ||||
}); | ||||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh, maybe it's this -- we split up
uMVMatrix
intouModelMatrix
anduViewMatrix
, and only updateuMVMatrix
right before we draw a shape here:p5.js/src/webgl/p5.Shader.js
Lines 579 to 584 in 4fbbaf5
Maybe we can refactor the bit that sets
uMVMatrix
into a function on the renderer, likecalculateCombinedMatrix()
, which gets called in_setMatrixUniforms
above, and then you can also call it here right before you makecameraCoordinates
?