Skip to content

Commit c03b313

Browse files
committed
same changes related to processing#2259
1 parent a5cb3c4 commit c03b313

3 files changed

Lines changed: 24 additions & 26 deletions

File tree

core/src/processing/opengl/PGraphics2D.java

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,11 @@ public void frustum(float left, float right, float bottom, float top,
119119

120120
@Override
121121
protected void defaultPerspective() {
122-
// super.ortho(width/2f, (3f/2f) * width, -height/2f, height/2f, -1, +1);
123-
super.ortho(0, width, 0, height, -1, +1);
122+
// The camera part of the modelview is simply the identity matrix, so in
123+
// order to the ortho projection to be consistent with this, it needs to be
124+
// set as follows, because ortho() will shift the viewing rectangle at
125+
// (width/2, height/2) and will also apply the axis inversion along Y:
126+
super.ortho(width/2f, (3f/2f) * width, -height/2f, height/2f, -1, +1);
124127
}
125128

126129

@@ -157,8 +160,7 @@ public void camera(float eyeX, float eyeY, float eyeZ,
157160

158161
@Override
159162
protected void defaultCamera() {
160-
super.camera(width/2f, height/2f);
161-
// resetMatrix();
163+
resetMatrix();
162164
}
163165

164166

@@ -182,11 +184,6 @@ protected void end2D() {
182184
popProjection();
183185
}
184186

185-
@Override
186-
public void resetMatrix() {
187-
super.resetMatrix();
188-
defaultCamera();
189-
}
190187

191188
//////////////////////////////////////////////////////////////
192189

core/src/processing/opengl/PGraphics3D.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,20 @@ protected void begin2D() {
8787
pushProjection();
8888
ortho(0, width, 0, height, -1, +1);
8989
pushMatrix();
90-
camera(width/2, height/2);
90+
91+
// Set camera for 2D rendering, it simply centers at (width/2, height/2)
92+
float centerX = width/2;
93+
float centerY = height/2;
94+
modelview.reset();
95+
modelview.translate(-centerX, -centerY);
96+
97+
modelviewInv.set(modelview);
98+
modelviewInv.invert();
99+
100+
camera.set(modelview);
101+
cameraInv.set(modelviewInv);
102+
103+
updateProjmodelview();
91104
}
92105

93106

core/src/processing/opengl/PGraphicsOpenGL.java

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2508,7 +2508,7 @@ void sortTriangles() {
25082508
// an 'in-place' implementation of quick I whipped together late at night
25092509
// based off of the algorithm found on wikipedia: http://en.wikipedia.org/wiki/Quicksort
25102510
private void quickSortTris(int leftI, int rightI) {
2511-
if(leftI < rightI) {
2511+
if (leftI < rightI) {
25122512
int pivotIndex = (leftI + rightI)/2;
25132513
int newPivotIndex = partition(leftI,rightI,pivotIndex);
25142514
quickSortTris(leftI, newPivotIndex-1);
@@ -4390,21 +4390,6 @@ public void camera(float eyeX, float eyeY, float eyeZ,
43904390
}
43914391

43924392

4393-
// Sets a camera for 2D rendering, which only involves centering
4394-
public void camera(float centerX, float centerY) {
4395-
modelview.reset();
4396-
modelview.translate(-centerX, -centerY);
4397-
4398-
modelviewInv.set(modelview);
4399-
modelviewInv.invert();
4400-
4401-
camera.set(modelview);
4402-
cameraInv.set(modelviewInv);
4403-
4404-
updateProjmodelview();
4405-
}
4406-
4407-
44084393
/**
44094394
* Print the current camera matrix.
44104395
*/
@@ -4453,6 +4438,9 @@ public void ortho(float left, float right,
44534438
public void ortho(float left, float right,
44544439
float bottom, float top,
44554440
float near, float far) {
4441+
// Translating the origin to (widht/2, height/2) since the matrix math
4442+
// below assumes the center of the screen to be (0, 0), but in Processing
4443+
// it is (w/2, h/2).
44564444
left -= width/2f;
44574445
right -= width/2f;
44584446
bottom -= height/2f;

0 commit comments

Comments
 (0)