Format for cleaner pull request

This commit is contained in:
bkuker 2013-01-07 16:26:56 -05:00
parent e11d48566e
commit d1586d3d34

View File

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