diff --git a/core/src/net/sf/openrocket/gui/figure3d/RocketRenderer.java b/core/src/net/sf/openrocket/gui/figure3d/RocketRenderer.java index 74be92755..959908620 100644 --- a/core/src/net/sf/openrocket/gui/figure3d/RocketRenderer.java +++ b/core/src/net/sf/openrocket/gui/figure3d/RocketRenderer.java @@ -25,41 +25,41 @@ import net.sf.openrocket.util.Coordinate; */ public abstract class RocketRenderer { protected static final LogHelper log = Application.getLogger(); - + final ComponentRenderer cr = new ComponentRenderer(); - + private final float[] selectedEmissive = { 1, 0, 0, 1 }; private final float[] colorBlack = { 0, 0, 0, 1 }; - + public void init(GLAutoDrawable drawable) { cr.init(drawable); } - + public void dispose(GLAutoDrawable drawable) { } - + public void updateFigure() { cr.updateFigure(); } - + public abstract void renderComponent(GL2 gl, RocketComponent c, float alpha); - + public abstract boolean isDrawn(RocketComponent c); - + public abstract boolean isDrawnTransparent(RocketComponent c); - + public RocketComponent pick(GLAutoDrawable drawable, Configuration configuration, Point p, Set ignore) { final GL2 gl = drawable.getGL().getGL2(); gl.glEnable(GL.GL_DEPTH_TEST); - + // Store a vector of pickable parts. final Vector pickParts = new Vector(); - + for (RocketComponent c : configuration) { if (ignore != null && ignore.contains(c)) continue; - + // Encode the index of the part as a color // if index is 0x0ABC the color ends up as // 0xA0B0C000 with each nibble in the coresponding @@ -67,7 +67,7 @@ public abstract class RocketRenderer { gl.glColor4ub((byte) ((pickParts.size() >> 4) & 0xF0), (byte) ((pickParts.size() << 0) & 0xF0), (byte) ((pickParts.size() << 4) & 0xF0), (byte) 1); pickParts.add(c); - + if (isDrawnTransparent(c)) { gl.glEnable(GL.GL_CULL_FACE); gl.glCullFace(GL.GL_FRONT); @@ -77,44 +77,44 @@ public abstract class RocketRenderer { cr.renderGeometry(gl, c); } } - + ByteBuffer bb = ByteBuffer.allocateDirect(4); - + gl.glReadPixels(p.x, p.y, 1, 1, GL.GL_RGB, GL.GL_UNSIGNED_BYTE, bb); - + final int pickColor = bb.getInt(); final int pickIndex = ((pickColor >> 20) & 0xF00) | ((pickColor >> 16) & 0x0F0) | ((pickColor >> 12) & 0x00F); - + if (pickIndex < 0 || pickIndex > pickParts.size() - 1) return null; - + return pickParts.get(pickIndex); } - + public void render(GLAutoDrawable drawable, Configuration configuration, Set selection) { - + if (cr == null) throw new IllegalStateException(this + " Not Initialized"); - + GL2 gl = drawable.getGL().getGL2(); - + gl.glEnable(GL.GL_DEPTH_TEST); // enables depth testing gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA); - + { // Draw selection outline at nearest Z gl.glMaterialfv(GL.GL_FRONT_AND_BACK, GLLightingFunc.GL_EMISSION, selectedEmissive, 0); gl.glMaterialfv(GL.GL_FRONT_AND_BACK, GLLightingFunc.GL_DIFFUSE, colorBlack, 0); gl.glMaterialfv(GL.GL_FRONT_AND_BACK, GLLightingFunc.GL_AMBIENT, colorBlack, 0); gl.glMaterialfv(GL.GL_FRONT_AND_BACK, GLLightingFunc.GL_SPECULAR, colorBlack, 0); gl.glLineWidth(5.0f); - + for (RocketComponent c : configuration) { if (selection.contains(c)) { // Draw as lines, set Z to nearest gl.glPolygonMode(GL.GL_FRONT_AND_BACK, GL2GL3.GL_LINE); gl.glDepthRange(0, 0); cr.renderGeometry(gl, c); - + // Draw polygons, always passing depth test, // setting Z to farthest gl.glPolygonMode(GL.GL_FRONT_AND_BACK, GL2GL3.GL_FILL); @@ -128,7 +128,7 @@ public abstract class RocketRenderer { gl.glPolygonMode(GL.GL_FRONT_AND_BACK, GL2GL3.GL_FILL); gl.glMaterialfv(GL.GL_FRONT_AND_BACK, GLLightingFunc.GL_EMISSION, colorBlack, 0); } // done with selection outline - + // Draw all inner components for (RocketComponent c : configuration) { if (isDrawn(c)) { @@ -137,9 +137,9 @@ public abstract class RocketRenderer { } } } - + renderMotors(gl, configuration); - + // Draw Tube and Transition back faces, blended with depth test // so that they show up behind. gl.glEnable(GL.GL_CULL_FACE); @@ -152,7 +152,7 @@ public abstract class RocketRenderer { } } gl.glDisable(GL.GL_CULL_FACE); - + // Draw T&T front faces blended, without depth test gl.glEnable(GL.GL_BLEND); gl.glEnable(GL.GL_CULL_FACE); @@ -166,9 +166,9 @@ public abstract class RocketRenderer { } gl.glDisable(GL.GL_BLEND); gl.glDisable(GL.GL_CULL_FACE); - + } - + private void renderMotors(GL2 gl, Configuration configuration) { String motorID = configuration.getFlightConfigurationID(); Iterator iterator = configuration.motorIterator(); @@ -177,15 +177,15 @@ public abstract class RocketRenderer { Motor motor = mount.getMotor(motorID); double length = motor.getLength(); double radius = motor.getDiameter() / 2; - + Coordinate[] position = ((RocketComponent) mount).toAbsolute(new Coordinate(((RocketComponent) mount) .getLength() + mount.getMotorOverhang() - length)); - + for (int i = 0; i < position.length; i++) { cr.renderMotor(gl, position[i], length, radius); } } - + } - + }