Skip to content
This repository was archived by the owner on Jun 24, 2024. It is now read-only.

Commit e110169

Browse files
committed
adds toggling of rendering into each cubemap face.
1 parent 04d2a25 commit e110169

File tree

2 files changed

+82
-5
lines changed

2 files changed

+82
-5
lines changed

src/codeanticode/planetarium/Dome.java

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ public class Dome extends PGraphics3D {
6969

7070
protected boolean requestedRenderDomeChange = false;
7171
protected boolean requestedRenderDome;
72+
73+
private boolean[] faceDraw = {true, true, true, true, true, false};
7274

7375
protected float domeLeft, domeRight, domeTop, domeBottom;
7476
protected float domeDX, domeDY, domeDZ;
@@ -210,7 +212,9 @@ public void beginDraw() {
210212
pgl.viewport(0, 0, cubeMapSize, cubeMapSize);
211213
super.perspective(90.0f * DEG_TO_RAD, 1.0f, 1.0f, cameraFar);
212214

213-
beginFaceDraw(PGL.TEXTURE_CUBE_MAP_POSITIVE_X);
215+
if (getFaceDraw(DomeCamera.POSITIVE_X)) {
216+
beginFaceDraw(PGL.TEXTURE_CUBE_MAP_POSITIVE_X);
217+
}
214218
}
215219
}
216220

@@ -220,10 +224,12 @@ public void endDraw() {
220224
endFaceDraw();
221225

222226
// Draw the rest of the cubemap faces
223-
for (int face = PGL.TEXTURE_CUBE_MAP_NEGATIVE_X; face <= PGL.TEXTURE_CUBE_MAP_POSITIVE_Z; face++) {
224-
beginFaceDraw(face);
225-
parent.draw();
226-
endFaceDraw();
227+
for (int face = PGL.TEXTURE_CUBE_MAP_NEGATIVE_X; face <= PGL.TEXTURE_CUBE_MAP_NEGATIVE_Z; face++) {
228+
if (getFaceDraw(face - PGL.TEXTURE_CUBE_MAP_POSITIVE_X)) {
229+
beginFaceDraw(face);
230+
parent.draw();
231+
endFaceDraw();
232+
}
227233
}
228234

229235
endPGL();
@@ -457,6 +463,20 @@ protected void setDomeAperture(float theAperture) {
457463
}
458464
}
459465

466+
protected boolean getFaceDraw(int theFace) {
467+
if (theFace >= 0 && theFace <= faceDraw.length) {
468+
return faceDraw[theFace];
469+
}
470+
return false;
471+
}
472+
473+
protected void setFaceDraw(int theFace, boolean doDraw) {
474+
if (theFace >= 0 && theFace <= faceDraw.length) {
475+
faceDraw[theFace] = doDraw;
476+
System.out.println("face no. " + theFace + " rendering " + doDraw);
477+
}
478+
}
479+
460480
private void welcome() {
461481
System.out.println("##library.name## ##library.prettyVersion## by ##author##");
462482
}

src/codeanticode/planetarium/DomeCamera.java

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,68 @@ public void imageToForeground(PImage theImage, int x0, int y0, int w, int h) {
9292
renderer.imageToForeground(theImage, x0, y0, w, h);
9393
}
9494

95+
/* TODO: figure out a way for this to work
9596
public void imageToBackground(PImage theImage, int x0, int y0, int w, int h) {
9697
renderer.imageToBackground(theImage, x0, y0, w, h);
9798
}
99+
*/
98100

101+
102+
/**
103+
* Returns the currently rendered face index.
104+
*
105+
* @return 0 == DomeCamera.POSITIVE_X
106+
* 1 == DomeCamera.NEGATIVE_X
107+
* 2 == DomeCamera.POSITIVE_Y
108+
* 3 == DomeCamera.NEGATIVE_Y
109+
* 4 == DomeCamera.POSITIVE_Z
110+
* 5 == DomeCamera.NEGATIVE_Z
111+
*/
99112
public int getFace() {
100113
return renderer.getCurrentFace() - PGL.TEXTURE_CUBE_MAP_POSITIVE_X;
101114
}
115+
116+
/**
117+
* Toggles the rendering into a cubemap face by index.
118+
*
119+
* @param theFace 0 == DomeCamera.POSITIVE_X
120+
* 1 == DomeCamera.NEGATIVE_X
121+
* 2 == DomeCamera.POSITIVE_Y
122+
* 3 == DomeCamera.NEGATIVE_Y
123+
* 4 == DomeCamera.POSITIVE_Z
124+
* 5 == DomeCamera.NEGATIVE_Z
125+
*/
126+
public void toggleFaceDraw(int theFace) {
127+
renderer.setFaceDraw(theFace, !renderer.getFaceDraw(theFace));
128+
}
129+
130+
/**
131+
* Sets the rendering into a cubemap face by index.
132+
*
133+
* @param theFace 0 == DomeCamera.POSITIVE_X
134+
* 1 == DomeCamera.NEGATIVE_X
135+
* 2 == DomeCamera.POSITIVE_Y
136+
* 3 == DomeCamera.NEGATIVE_Y
137+
* 4 == DomeCamera.POSITIVE_Z
138+
* 5 == DomeCamera.NEGATIVE_Z
139+
* @param doDraw true or false
140+
*/
141+
public void setFaceDraw(int theFace, boolean doDraw) {
142+
renderer.setFaceDraw(theFace, doDraw);
143+
}
144+
145+
/**
146+
* Informs if a given face is being rendered into.
147+
*
148+
* @param theFace 0 == DomeCamera.POSITIVE_X
149+
* 1 == DomeCamera.NEGATIVE_X
150+
* 2 == DomeCamera.POSITIVE_Y
151+
* 3 == DomeCamera.NEGATIVE_Y
152+
* 4 == DomeCamera.POSITIVE_Z
153+
* 5 == DomeCamera.NEGATIVE_Z
154+
* @return true if the given camera is being updated.
155+
*/
156+
public boolean getFaceDraw(int theFace) {
157+
return renderer.getFaceDraw(theFace);
158+
}
102159
}

0 commit comments

Comments
 (0)