Add thickness to a few components.

Add an ALL surface
This commit is contained in:
bkuker 2013-03-04 15:12:48 -05:00
parent 8b633bcd95
commit 701aa4b151
4 changed files with 101 additions and 65 deletions

View File

@ -120,7 +120,7 @@ public class FigureRenderer extends RocketRenderer {
gl.glMaterialfv(GL.GL_BACK, GLLightingFunc.GL_DIFFUSE, color, 0); gl.glMaterialfv(GL.GL_BACK, GLLightingFunc.GL_DIFFUSE, color, 0);
gl.glMaterialfv(GL.GL_BACK, GLLightingFunc.GL_AMBIENT, color, 0); gl.glMaterialfv(GL.GL_BACK, GLLightingFunc.GL_AMBIENT, color, 0);
cr.getGeometry(c, Surface.OUTSIDE).render(gl); cr.getGeometry(c, Surface.ALL).render(gl);
} }
@Override @Override

View File

@ -75,10 +75,10 @@ public abstract class RocketRenderer {
if (isDrawnTransparent(c)) { if (isDrawnTransparent(c)) {
gl.glEnable(GL.GL_CULL_FACE); gl.glEnable(GL.GL_CULL_FACE);
gl.glCullFace(GL.GL_FRONT); gl.glCullFace(GL.GL_FRONT);
cr.getGeometry(c, Surface.OUTSIDE).render(gl); cr.getGeometry(c, Surface.ALL).render(gl);
gl.glDisable(GL.GL_CULL_FACE); gl.glDisable(GL.GL_CULL_FACE);
} else { } else {
cr.getGeometry(c, Surface.OUTSIDE).render(gl); cr.getGeometry(c, Surface.ALL).render(gl);
} }
} }
@ -117,14 +117,14 @@ public abstract class RocketRenderer {
// Draw as lines, set Z to nearest // Draw as lines, set Z to nearest
gl.glPolygonMode(GL.GL_FRONT_AND_BACK, GL2GL3.GL_LINE); gl.glPolygonMode(GL.GL_FRONT_AND_BACK, GL2GL3.GL_LINE);
gl.glDepthRange(0, 0); gl.glDepthRange(0, 0);
cr.getGeometry(c, Surface.OUTSIDE).render(gl); cr.getGeometry(c, Surface.ALL).render(gl);
// Draw polygons, always passing depth test, // Draw polygons, always passing depth test,
// setting Z to farthest // setting Z to farthest
gl.glPolygonMode(GL.GL_FRONT_AND_BACK, GL2GL3.GL_FILL); gl.glPolygonMode(GL.GL_FRONT_AND_BACK, GL2GL3.GL_FILL);
gl.glDepthRange(1, 1); gl.glDepthRange(1, 1);
gl.glDepthFunc(GL.GL_ALWAYS); gl.glDepthFunc(GL.GL_ALWAYS);
cr.getGeometry(c, Surface.OUTSIDE).render(gl); cr.getGeometry(c, Surface.ALL).render(gl);
gl.glDepthFunc(GL.GL_LESS); gl.glDepthFunc(GL.GL_LESS);
gl.glDepthRange(0, 1); gl.glDepthRange(0, 1);
} }
@ -133,6 +133,7 @@ public abstract class RocketRenderer {
gl.glMaterialfv(GL.GL_FRONT_AND_BACK, GLLightingFunc.GL_EMISSION, colorBlack, 0); gl.glMaterialfv(GL.GL_FRONT_AND_BACK, GLLightingFunc.GL_EMISSION, colorBlack, 0);
} // done with selection outline } // done with selection outline
gl.glEnable(GL.GL_CULL_FACE);
// Draw all inner components // Draw all inner components
for (RocketComponent c : configuration) { for (RocketComponent c : configuration) {
if (isDrawn(c)) { if (isDrawn(c)) {
@ -141,6 +142,7 @@ public abstract class RocketRenderer {
} }
} }
} }
gl.glDisable(GL.GL_CULL_FACE);
renderMotors(gl, configuration); renderMotors(gl, configuration);
@ -195,7 +197,7 @@ public abstract class RocketRenderer {
} }
protected void renderMotor(GL2 gl, Motor motor) { protected void renderMotor(GL2 gl, Motor motor) {
cr.getGeometry(motor, Surface.OUTSIDE).render(gl); cr.getGeometry(motor, Surface.ALL).render(gl);
} }
} }

View File

@ -56,12 +56,16 @@ public class ComponentRenderer {
public Geometry getGeometry(final RocketComponent c, final Surface which) { public Geometry getGeometry(final RocketComponent c, final Surface which) {
return new Geometry() { return new Geometry() {
@Override @Override
public void render(GL2 gl) { public void render(GL2 gl) {
if (which == Surface.ALL) {
renderGeometry(gl, c, Surface.INSIDE);
renderGeometry(gl, c, Surface.EDGES);
renderGeometry(gl, c, Surface.OUTSIDE);
} else {
renderGeometry(gl, c, which); renderGeometry(gl, c, which);
} }
}
}; };
} }
@ -90,14 +94,17 @@ public class ComponentRenderer {
if (c instanceof BodyTube) { if (c instanceof BodyTube) {
renderTube(gl, (BodyTube) c, which); renderTube(gl, (BodyTube) c, which);
} else if (c instanceof LaunchLug) { } else if (c instanceof LaunchLug) {
renderLug(gl, (LaunchLug) c); renderLug(gl, (LaunchLug) c, which);
} else if (c instanceof RingComponent) { } else if (c instanceof RingComponent) {
if (which == Surface.OUTSIDE)
renderRing(gl, (RingComponent) c); renderRing(gl, (RingComponent) c);
} else if (c instanceof Transition) { } else if (c instanceof Transition) {
renderTransition(gl, (Transition) c); renderTransition(gl, (Transition) c, which);
} else if (c instanceof MassObject) { } else if (c instanceof MassObject) {
if (which == Surface.OUTSIDE)
renderMassObject(gl, (MassObject) c); renderMassObject(gl, (MassObject) c);
} else if (c instanceof FinSet) { } else if (c instanceof FinSet) {
if (which == Surface.OUTSIDE)
renderFinSet(gl, (FinSet) c); renderFinSet(gl, (FinSet) c);
} else { } else {
renderOther(gl, c); renderOther(gl, c);
@ -118,16 +125,25 @@ public class ComponentRenderer {
gl.glEnd(); gl.glEnd();
} }
private void renderTransition(GL2 gl, Transition t) { private void renderTransition(GL2 gl, Transition t, Surface which) {
//TODO take into account thickness.
if (which == Surface.INSIDE) {
gl.glFrontFace(GL.GL_CCW);
}
gl.glRotated(90, 0, 1.0, 0); gl.glRotated(90, 0, 1.0, 0);
if (which == Surface.OUTSIDE || which == Surface.INSIDE) {
if (t.getType() == Transition.Shape.CONICAL) { if (t.getType() == Transition.Shape.CONICAL) {
glu.gluCylinder(q, t.getForeRadius(), t.getAftRadius(), glu.gluCylinder(q, t.getForeRadius(), t.getAftRadius(),
t.getLength(), LOD, 1); t.getLength(), LOD, 1);
} else { } else {
TransitionRenderer.drawTransition(gl, t, LOD, LOD); TransitionRenderer.drawTransition(gl, t, LOD, LOD);
} }
}
if (which == Surface.EDGES || which == Surface.INSIDE) {
// Render AFT shoulder // Render AFT shoulder
gl.glPushMatrix(); gl.glPushMatrix();
gl.glTranslated(0, 0, t.getLength()); gl.glTranslated(0, 0, t.getLength());
@ -163,12 +179,14 @@ public class ComponentRenderer {
glu.gluDisk(q, t.getForeShoulderRadius(), 0, LOD, 2); glu.gluDisk(q, t.getForeShoulderRadius(), 0, LOD, 2);
} }
gl.glPopMatrix(); gl.glPopMatrix();
}
if (which == Surface.INSIDE) {
gl.glFrontFace(GL.GL_CW);
}
} }
private void renderTube(GL2 gl, BodyTube t, Surface which) { private void renderTube(GL2 gl, BodyTube t, Surface which) {
//TODO REfactor without the extra transforms
//outside //outside
gl.glRotated(90, 0, 1.0, 0); gl.glRotated(90, 0, 1.0, 0);
if (which == Surface.OUTSIDE) if (which == Surface.OUTSIDE)
@ -187,14 +205,14 @@ public class ComponentRenderer {
//inside //inside
gl.glTranslated(0, 0, -t.getLength());
if (which == Surface.INSIDE) if (which == Surface.INSIDE)
glu.gluCylinder(q, t.getInnerRadius(), t.getInnerRadius(), glu.gluCylinder(q, t.getInnerRadius(), t.getInnerRadius(),
t.getLength(), LOD, 1); -t.getLength(), LOD, 1);
} }
private void renderRing(GL2 gl, RingComponent r) { private void renderRing(GL2 gl, RingComponent r) {
gl.glRotated(90, 0, 1.0, 0); gl.glRotated(90, 0, 1.0, 0);
glu.gluCylinder(q, r.getOuterRadius(), r.getOuterRadius(), glu.gluCylinder(q, r.getOuterRadius(), r.getOuterRadius(),
r.getLength(), LOD, 1); r.getLength(), LOD, 1);
@ -206,17 +224,33 @@ public class ComponentRenderer {
gl.glTranslated(0, 0, r.getLength()); gl.glTranslated(0, 0, r.getLength());
glu.gluDisk(q, r.getInnerRadius(), r.getOuterRadius(), LOD, 2); glu.gluDisk(q, r.getInnerRadius(), r.getOuterRadius(), LOD, 2);
gl.glTranslated(0, 0, -r.getLength());
glu.gluCylinder(q, r.getInnerRadius(), r.getInnerRadius(), glu.gluCylinder(q, r.getInnerRadius(), r.getInnerRadius(),
r.getLength(), LOD, 1); -r.getLength(), LOD, 1);
} }
private void renderLug(GL2 gl, LaunchLug t) { private void renderLug(GL2 gl, LaunchLug t, Surface which) {
//outside
gl.glRotated(90, 0, 1.0, 0); gl.glRotated(90, 0, 1.0, 0);
if (which == Surface.OUTSIDE)
glu.gluCylinder(q, t.getOuterRadius(), t.getOuterRadius(), glu.gluCylinder(q, t.getOuterRadius(), t.getOuterRadius(),
t.getLength(), LOD, 1); t.getLength(), LOD, 1);
//edges
gl.glRotated(180, 0, 1.0, 0);
if (which == Surface.EDGES)
glu.gluDisk(q, t.getInnerRadius(), t.getOuterRadius(), LOD, 2);
gl.glRotated(180, 0, 1.0, 0);
gl.glTranslated(0, 0, t.getLength());
if (which == Surface.EDGES)
glu.gluDisk(q, t.getInnerRadius(), t.getOuterRadius(), LOD, 2);
//inside
if (which == Surface.INSIDE)
glu.gluCylinder(q, t.getInnerRadius(), t.getInnerRadius(),
-t.getLength(), LOD, 1);
} }
private void renderMassObject(GL2 gl, MassObject o) { private void renderMassObject(GL2 gl, MassObject o) {

View File

@ -4,7 +4,7 @@ import javax.media.opengl.GL2;
public interface Geometry { public interface Geometry {
public static enum Surface { public static enum Surface {
OUTSIDE, INSIDE, EDGES; ALL, OUTSIDE, INSIDE, EDGES;
} }
public void render(GL2 gl); public void render(GL2 gl);