Skip to content

Commit 1f6d205

Browse files
committed
added cameraUp()
1 parent 13e2d9a commit 1f6d205

File tree

4 files changed

+37
-32
lines changed

4 files changed

+37
-32
lines changed

core/src/processing/core/PGraphics.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4087,6 +4087,11 @@ public void printMatrix() {
40874087
// CAMERA
40884088

40894089

4090+
public void cameraUp() {
4091+
showMethodWarning("cameraUp");
4092+
}
4093+
4094+
40904095
public void beginCamera() {
40914096
showMethodWarning("beginCamera");
40924097
}

core/src/processing/opengl/PGL.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,7 @@ protected Texture wrapBackTexture(Texture texture) {
544544
glColorTex.get(backTex), TEXTURE_2D, RGBA,
545545
fboWidth, fboHeight, NEAREST, NEAREST,
546546
CLAMP_TO_EDGE, CLAMP_TO_EDGE);
547-
texture.invertedY(graphics.glCoordsEnabled);
547+
texture.invertedY(graphics.cameraUp);
548548
texture.colorBuffer(true);
549549
graphics.setCache(graphics, texture);
550550
} else {
@@ -561,7 +561,7 @@ protected Texture wrapFrontTexture(Texture texture) {
561561
glColorTex.get(frontTex), TEXTURE_2D, RGBA,
562562
fboWidth, fboHeight, NEAREST, NEAREST,
563563
CLAMP_TO_EDGE, CLAMP_TO_EDGE);
564-
texture.invertedY(graphics.glCoordsEnabled);
564+
texture.invertedY(graphics.cameraUp);
565565
texture.colorBuffer(true);
566566
} else {
567567
texture.glName = glColorTex.get(frontTex);

core/src/processing/opengl/PGraphicsOpenGL.java

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,6 @@ public void dispose() {
105105
/** Current flush mode. */
106106
protected int flushMode = FLUSH_WHEN_FULL;
107107

108-
/**
109-
* Keeps track of ENABLE_OPENGL_COORDINATES hint
110-
*/
111-
protected boolean glCoordsEnabled = false;
112108

113109
// ........................................................
114110

@@ -278,6 +274,12 @@ public void dispose() {
278274
/** Flag to indicate that we are inside beginCamera/endCamera block. */
279275
protected boolean manipulatingCamera;
280276

277+
/**
278+
* Sets the coordinates to "first person" setting: Y axis up, origin at
279+
* screen center
280+
*/
281+
protected boolean cameraUp = false;
282+
281283
// ........................................................
282284

283285
// All the matrices required for camera and geometry transformations.
@@ -1583,7 +1585,7 @@ protected void restoreGL() {
15831585
pgl.disable(PGL.SCISSOR_TEST);
15841586
}
15851587

1586-
pgl.frontFace(glCoordsEnabled ? PGL.CCW : PGL.CW);
1588+
pgl.frontFace(cameraUp ? PGL.CCW : PGL.CW);
15871589
pgl.disable(PGL.CULL_FACE);
15881590

15891591
pgl.activeTexture(PGL.TEXTURE0);
@@ -3467,7 +3469,7 @@ public void text(char c, float x, float y) {
34673469
defaultFontOrDeath("text");
34683470
}
34693471

3470-
int sign = glCoordsEnabled ? -1 : +1;
3472+
int sign = cameraUp ? -1 : +1;
34713473

34723474
if (textAlignY == CENTER) {
34733475
y += sign * textAscent() / 2;
@@ -3490,7 +3492,7 @@ public void text(String str, float x, float y) {
34903492
defaultFontOrDeath("text");
34913493
}
34923494

3493-
int sign = glCoordsEnabled ? -1 : +1;
3495+
int sign = cameraUp ? -1 : +1;
34943496

34953497
int length = str.length();
34963498
if (length > textBuffer.length) {
@@ -3542,7 +3544,7 @@ public void text(String str, float x1, float y1, float x2, float y2) {
35423544
defaultFontOrDeath("text");
35433545
}
35443546

3545-
int sign = glCoordsEnabled ? -1 : +1;
3547+
int sign = cameraUp ? -1 : +1;
35463548

35473549
float hradius, vradius;
35483550
switch (rectMode) {
@@ -3619,23 +3621,23 @@ public void text(String str, float x1, float y1, float x2, float y2) {
36193621

36203622
if (textAlignY == CENTER) {
36213623
float lineHigh = textAscent() + textLeading * (lineCount - 1);
3622-
float y = glCoordsEnabled ? y2 - textAscent() - (boxHeight - lineHigh) / 2 :
3624+
float y = cameraUp ? y2 - textAscent() - (boxHeight - lineHigh) / 2 :
36233625
y1 + textAscent() + (boxHeight - lineHigh) / 2;
36243626
for (int i = 0; i < lineCount; i++) {
36253627
textLineAlignImpl(textBuffer, textBreakStart[i], textBreakStop[i], lineX, y);
36263628
y += sign * textLeading;
36273629
}
36283630

36293631
} else if (textAlignY == BOTTOM) {
3630-
float y = glCoordsEnabled ? y1 + textDescent() + textLeading * (lineCount - 1) :
3632+
float y = cameraUp ? y1 + textDescent() + textLeading * (lineCount - 1) :
36313633
y2 - textDescent() - textLeading * (lineCount - 1);
36323634
for (int i = 0; i < lineCount; i++) {
36333635
textLineAlignImpl(textBuffer, textBreakStart[i], textBreakStop[i], lineX, y);
36343636
y += sign * textLeading;
36353637
}
36363638

36373639
} else { // TOP or BASELINE just go to the default
3638-
float y = glCoordsEnabled ? y2 - textAscent() : y1 + textAscent();
3640+
float y = cameraUp ? y2 - textAscent() : y1 + textAscent();
36393641
for (int i = 0; i < lineCount; i++) {
36403642
textLineAlignImpl(textBuffer, textBreakStart[i], textBreakStop[i], lineX, y);
36413643
y += sign * textLeading;
@@ -3767,7 +3769,7 @@ protected void textCharImpl(char ch, float x, float y) {
37673769

37683770
// The default text setting assumes an Y axis pointing down, so
37693771
// inverting in the the case Y points up
3770-
int sign = glCoordsEnabled ? -1 : +1;
3772+
int sign = cameraUp ? -1 : +1;
37713773

37723774
float x1 = x + lextent * textSize;
37733775
float y1 = y - sign * textent * textSize;
@@ -4627,6 +4629,12 @@ public void printCamera() {
46274629
}
46284630

46294631

4632+
@Override
4633+
public void cameraUp() {
4634+
cameraUp = true;
4635+
}
4636+
4637+
46304638
protected void defaultCamera() {
46314639
camera();
46324640
}
@@ -6067,7 +6075,7 @@ protected void loadTextureImpl(int sampling, boolean mipmap) {
60676075
Texture.Parameters params = new Texture.Parameters(ARGB,
60686076
sampling, mipmap);
60696077
texture = new Texture(this, pixelWidth, pixelHeight, params);
6070-
texture.invertedY(glCoordsEnabled);
6078+
texture.invertedY(cameraUp);
60716079
texture.colorBuffer(true);
60726080
setCache(this, texture);
60736081
}
@@ -6078,7 +6086,7 @@ protected void createPTexture() {
60786086
updatePixelSize();
60796087
if (texture != null) {
60806088
ptexture = new Texture(this, pixelWidth, pixelHeight, texture.getParameters());
6081-
ptexture.invertedY(glCoordsEnabled);
6089+
ptexture.invertedY(cameraUp);
60826090
ptexture.colorBuffer(true);
60836091
}
60846092
}
@@ -6218,7 +6226,7 @@ public void filter(PShader shader) {
62186226
if (filterTexture == null || filterTexture.contextIsOutdated()) {
62196227
filterTexture = new Texture(this, texture.width, texture.height,
62206228
texture.getParameters());
6221-
filterTexture.invertedY(glCoordsEnabled);
6229+
filterTexture.invertedY(cameraUp);
62226230
filterImage = wrapTexture(filterTexture);
62236231
}
62246232
filterTexture.set(texture);
@@ -6288,7 +6296,7 @@ public void copy(int sx, int sy, int sw, int sh,
62886296
loadTexture();
62896297
if (filterTexture == null || filterTexture.contextIsOutdated()) {
62906298
filterTexture = new Texture(this, texture.width, texture.height, texture.getParameters());
6291-
filterTexture.invertedY(glCoordsEnabled);
6299+
filterTexture.invertedY(cameraUp);
62926300
filterImage = wrapTexture(filterTexture);
62936301
}
62946302
filterTexture.put(texture, sx, height - (sy + sh), sw, height - sy);
@@ -6608,7 +6616,7 @@ protected Texture addTexture(PImage img, Texture.Parameters params) {
66086616
img.parent = parent;
66096617
}
66106618
Texture tex = new Texture(this, img.pixelWidth, img.pixelHeight, params);
6611-
tex.invertedY(!glCoordsEnabled); // Pixels are read upside down
6619+
tex.invertedY(!cameraUp); // Pixels are read upside down
66126620
setCache(img, tex);
66136621
return tex;
66146622
}
@@ -6972,7 +6980,7 @@ protected void setGLSettings() {
69726980
// polygons are CCW in window coordinates, whereas are CW
69736981
// in the left-handed system that is Processing's default (with
69746982
// its Y axis pointing down)
6975-
pgl.frontFace(glCoordsEnabled ? PGL.CCW : PGL.CW);
6983+
pgl.frontFace(cameraUp ? PGL.CCW : PGL.CW);
69766984
pgl.disable(PGL.CULL_FACE);
69776985

69786986
// Processing uses only one texture unit.

libraries/vr/src/processing/vr/PGraphicsVR.java

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,6 @@ protected PGL createPGL(PGraphicsOpenGL pg) {
5959
}
6060

6161

62-
public void vrCoordinates(boolean v) {
63-
if (glCoordsEnabled != v) {
64-
flush();
65-
glCoordsEnabled = v;
66-
}
67-
}
68-
69-
7062
@Override
7163
public PMatrix3D getEyeMatrix() {
7264
PMatrix3D mat = new PMatrix3D();
@@ -192,7 +184,7 @@ protected void eyeTransform(Eye e) {
192184
defCameraFOV = fov.getTop()* DEG_TO_RAD;
193185
defCameraZ = (float) (height / (2 * Math.tan(defCameraFOV)));
194186
cameraAspect = (float)width / height;
195-
if (glCoordsEnabled) {
187+
if (cameraUp) {
196188
defCameraX = 0;
197189
defCameraY = 0;
198190
} else {
@@ -209,7 +201,7 @@ protected void headTransform(HeadTransform ht) {
209201

210202
// Forward, right, and up vectors are given in the original system with Y
211203
// pointing up. Need to invert y coords in the non-gl case:
212-
float yf = glCoordsEnabled ? +1 : -1;
204+
float yf = cameraUp ? +1 : -1;
213205

214206
headTransform.getForwardVector(forwardVector, 0);
215207
headTransform.getRightVector(rightVector, 0);
@@ -262,14 +254,14 @@ protected void setVRCamera() {
262254

263255
// Calculating Y vector
264256
float y0 = 0;
265-
float y1 = glCoordsEnabled ? + 1: -1;
257+
float y1 = cameraUp ? + 1: -1;
266258
float y2 = 0;
267259

268260
// Computing X vector as Y cross Z
269261
float x0 = y1 * z2 - y2 * z1;
270262
float x1 = -y0 * z2 + y2 * z0;
271263
float x2 = y0 * z1 - y1 * z0;
272-
if (!glCoordsEnabled) {
264+
if (!cameraUp) {
273265
// Inverting X axis
274266
x0 *= -1;
275267
x1 *= -1;

0 commit comments

Comments
 (0)