Moving from RenderStrategies to RocketRenderer subclasses.
This commit is contained in:
parent
e8ac5d4dea
commit
a857fb93be
@ -8,12 +8,8 @@ import javax.media.opengl.GL2ES1;
|
|||||||
import javax.media.opengl.GLAutoDrawable;
|
import javax.media.opengl.GLAutoDrawable;
|
||||||
import javax.media.opengl.fixedfunc.GLLightingFunc;
|
import javax.media.opengl.fixedfunc.GLLightingFunc;
|
||||||
|
|
||||||
import net.sf.openrocket.rocketcomponent.BodyTube;
|
|
||||||
import net.sf.openrocket.rocketcomponent.ExternalComponent;
|
import net.sf.openrocket.rocketcomponent.ExternalComponent;
|
||||||
import net.sf.openrocket.rocketcomponent.NoseCone;
|
|
||||||
import net.sf.openrocket.rocketcomponent.RocketComponent;
|
import net.sf.openrocket.rocketcomponent.RocketComponent;
|
||||||
import net.sf.openrocket.rocketcomponent.SymmetricComponent;
|
|
||||||
import net.sf.openrocket.rocketcomponent.Transition;
|
|
||||||
import net.sf.openrocket.startup.Application;
|
import net.sf.openrocket.startup.Application;
|
||||||
import net.sf.openrocket.util.Color;
|
import net.sf.openrocket.util.Color;
|
||||||
|
|
||||||
@ -24,31 +20,8 @@ public class FigureRenderStrategy extends RenderStrategy {
|
|||||||
super(null);
|
super(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isDrawn(RocketComponent c) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isDrawnTransparent(RocketComponent c) {
|
|
||||||
if (c instanceof BodyTube)
|
|
||||||
return true;
|
|
||||||
if (c instanceof NoseCone)
|
|
||||||
return false;
|
|
||||||
if (c instanceof SymmetricComponent) {
|
|
||||||
if (((SymmetricComponent) c).isFilled())
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (c instanceof Transition) {
|
|
||||||
Transition t = (Transition) c;
|
|
||||||
return !t.isAftShoulderCapped() && !t.isForeShoulderCapped();
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static final HashMap<Class<?>, Color> defaultColorCache = new HashMap<Class<?>, Color>();
|
private static final HashMap<Class<?>, Color> defaultColorCache = new HashMap<Class<?>, Color>();
|
||||||
|
|
||||||
@Override
|
|
||||||
public void preGeometry(GL2 gl, RocketComponent c, float alpha) {
|
public void preGeometry(GL2 gl, RocketComponent c, float alpha) {
|
||||||
gl.glLightModeli(GL2ES1.GL_LIGHT_MODEL_TWO_SIDE, 1);
|
gl.glLightModeli(GL2ES1.GL_LIGHT_MODEL_TWO_SIDE, 1);
|
||||||
Color figureColor = c.getColor();
|
Color figureColor = c.getColor();
|
||||||
@ -92,12 +65,6 @@ public class FigureRenderStrategy extends RenderStrategy {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void postGeometry(GL2 gl, RocketComponent c, float alpha) {
|
|
||||||
//Nothing to do here
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void init(GLAutoDrawable drawable) {
|
public void init(GLAutoDrawable drawable) {
|
||||||
GL2 gl = drawable.getGL().getGL2();
|
GL2 gl = drawable.getGL().getGL2();
|
||||||
|
44
core/src/net/sf/openrocket/gui/figure3d/FigureRenderer.java
Normal file
44
core/src/net/sf/openrocket/gui/figure3d/FigureRenderer.java
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
package net.sf.openrocket.gui.figure3d;
|
||||||
|
|
||||||
|
import javax.media.opengl.GL2;
|
||||||
|
|
||||||
|
import net.sf.openrocket.rocketcomponent.BodyTube;
|
||||||
|
import net.sf.openrocket.rocketcomponent.NoseCone;
|
||||||
|
import net.sf.openrocket.rocketcomponent.RocketComponent;
|
||||||
|
import net.sf.openrocket.rocketcomponent.SymmetricComponent;
|
||||||
|
import net.sf.openrocket.rocketcomponent.Transition;
|
||||||
|
|
||||||
|
public class FigureRenderer extends RocketRenderer {
|
||||||
|
|
||||||
|
protected FigureRenderer() {
|
||||||
|
super(new FigureRenderStrategy());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void renderComponent(GL2 gl, RocketComponent c, float alpha) {
|
||||||
|
((FigureRenderStrategy)currentStrategy).preGeometry(gl, c, alpha);
|
||||||
|
cr.renderGeometry(gl, c);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isDrawn(RocketComponent c) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isDrawnTransparent(RocketComponent c) {
|
||||||
|
if (c instanceof BodyTube)
|
||||||
|
return true;
|
||||||
|
if (c instanceof NoseCone)
|
||||||
|
return false;
|
||||||
|
if (c instanceof SymmetricComponent) {
|
||||||
|
if (((SymmetricComponent) c).isFilled())
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (c instanceof Transition) {
|
||||||
|
Transition t = (Transition) c;
|
||||||
|
return !t.isAftShoulderCapped() && !t.isForeShoulderCapped();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
@ -86,17 +86,6 @@ public class RealisticRenderStrategy extends RenderStrategy {
|
|||||||
texCache = null;
|
texCache = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isDrawn(RocketComponent c) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isDrawnTransparent(RocketComponent c) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void preGeometry(GL2 gl, RocketComponent c, float alpha) {
|
public void preGeometry(GL2 gl, RocketComponent c, float alpha) {
|
||||||
if (needClearCache) {
|
if (needClearCache) {
|
||||||
clearCaches(gl);
|
clearCaches(gl);
|
||||||
@ -158,7 +147,6 @@ public class RealisticRenderStrategy extends RenderStrategy {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void postGeometry(GL2 gl, RocketComponent c, float alpha) {
|
public void postGeometry(GL2 gl, RocketComponent c, float alpha) {
|
||||||
Appearance a = getAppearance(c);
|
Appearance a = getAppearance(c);
|
||||||
Decal t = a.getTexture();
|
Decal t = a.getTexture();
|
||||||
|
@ -0,0 +1,31 @@
|
|||||||
|
package net.sf.openrocket.gui.figure3d;
|
||||||
|
|
||||||
|
import javax.media.opengl.GL2;
|
||||||
|
|
||||||
|
import net.sf.openrocket.document.OpenRocketDocument;
|
||||||
|
import net.sf.openrocket.rocketcomponent.RocketComponent;
|
||||||
|
|
||||||
|
public class RealisticRenderer extends RocketRenderer {
|
||||||
|
public RealisticRenderer(OpenRocketDocument doc) {
|
||||||
|
super(new RealisticRenderStrategy(doc));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void renderComponent(GL2 gl, RocketComponent c, float alpha) {
|
||||||
|
((RealisticRenderStrategy)currentStrategy).preGeometry(gl, c, alpha);
|
||||||
|
cr.renderGeometry(gl, c);
|
||||||
|
((RealisticRenderStrategy)currentStrategy).postGeometry(gl, c, alpha);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isDrawn(RocketComponent c) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isDrawnTransparent(RocketComponent c) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,10 +1,8 @@
|
|||||||
package net.sf.openrocket.gui.figure3d;
|
package net.sf.openrocket.gui.figure3d;
|
||||||
|
|
||||||
import javax.media.opengl.GL2;
|
|
||||||
import javax.media.opengl.GLAutoDrawable;
|
import javax.media.opengl.GLAutoDrawable;
|
||||||
|
|
||||||
import net.sf.openrocket.document.OpenRocketDocument;
|
import net.sf.openrocket.document.OpenRocketDocument;
|
||||||
import net.sf.openrocket.rocketcomponent.RocketComponent;
|
|
||||||
|
|
||||||
public abstract class RenderStrategy {
|
public abstract class RenderStrategy {
|
||||||
|
|
||||||
@ -14,14 +12,6 @@ public abstract class RenderStrategy {
|
|||||||
this.document = document;
|
this.document = document;
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract boolean isDrawn(RocketComponent c);
|
|
||||||
|
|
||||||
public abstract boolean isDrawnTransparent(RocketComponent c);
|
|
||||||
|
|
||||||
public abstract void preGeometry(GL2 gl, RocketComponent c, float alpha);
|
|
||||||
|
|
||||||
public abstract void postGeometry(GL2 gl, RocketComponent c, float alpha);
|
|
||||||
|
|
||||||
public void updateFigure() {
|
public void updateFigure() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -21,6 +21,7 @@ import javax.media.opengl.GLAutoDrawable;
|
|||||||
import javax.media.opengl.GLCapabilities;
|
import javax.media.opengl.GLCapabilities;
|
||||||
import javax.media.opengl.GLEventListener;
|
import javax.media.opengl.GLEventListener;
|
||||||
import javax.media.opengl.GLProfile;
|
import javax.media.opengl.GLProfile;
|
||||||
|
import javax.media.opengl.GLRunnable;
|
||||||
import javax.media.opengl.awt.GLCanvas;
|
import javax.media.opengl.awt.GLCanvas;
|
||||||
import javax.media.opengl.fixedfunc.GLLightingFunc;
|
import javax.media.opengl.fixedfunc.GLLightingFunc;
|
||||||
import javax.media.opengl.fixedfunc.GLMatrixFunc;
|
import javax.media.opengl.fixedfunc.GLMatrixFunc;
|
||||||
@ -87,7 +88,7 @@ public class RocketFigure3d extends JPanel implements GLEventListener {
|
|||||||
|
|
||||||
float[] lightPosition = new float[] { 1, 4, 1, 0 };
|
float[] lightPosition = new float[] { 1, 4, 1, 0 };
|
||||||
|
|
||||||
RocketRenderer rr = new RocketRenderer();
|
RocketRenderer rr = new FigureRenderer();
|
||||||
|
|
||||||
public RocketFigure3d(OpenRocketDocument document, Configuration config) {
|
public RocketFigure3d(OpenRocketDocument document, Configuration config) {
|
||||||
this.document = document;
|
this.document = document;
|
||||||
@ -638,13 +639,20 @@ public class RocketFigure3d extends JPanel implements GLEventListener {
|
|||||||
this.csl = newListener;
|
this.csl = newListener;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setType(int t){
|
public void setType(final int t){
|
||||||
|
canvas.invoke(true, new GLRunnable() {
|
||||||
|
@Override
|
||||||
|
public boolean run(GLAutoDrawable drawable) {
|
||||||
|
rr.dispose(drawable);
|
||||||
if ( t == TYPE_FIGURE ){
|
if ( t == TYPE_FIGURE ){
|
||||||
rr.setRenderStrategy(new FigureRenderStrategy());
|
rr = new FigureRenderer();
|
||||||
} else {
|
} else {
|
||||||
rr.setRenderStrategy(new RealisticRenderStrategy(document));
|
rr = new RealisticRenderer(document);
|
||||||
}
|
}
|
||||||
repaint();
|
rr.init(drawable);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -23,35 +23,23 @@ import net.sf.openrocket.util.Coordinate;
|
|||||||
/*
|
/*
|
||||||
* @author Bill Kuker <bkuker@billkuker.com>
|
* @author Bill Kuker <bkuker@billkuker.com>
|
||||||
*/
|
*/
|
||||||
public class RocketRenderer {
|
public abstract class RocketRenderer {
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
private static final LogHelper log = Application.getLogger();
|
private static final LogHelper log = Application.getLogger();
|
||||||
|
|
||||||
RenderStrategy currentStrategy = new FigureRenderStrategy();
|
final RenderStrategy currentStrategy;
|
||||||
RenderStrategy nextStrategy;
|
final ComponentRenderer cr = new ComponentRenderer();
|
||||||
|
|
||||||
ComponentRenderer cr;
|
|
||||||
|
|
||||||
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 };
|
||||||
|
|
||||||
|
protected RocketRenderer(RenderStrategy s){
|
||||||
public void setRenderStrategy(RenderStrategy r) {
|
currentStrategy = s;
|
||||||
nextStrategy = r;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void checkRenderStrategy(GLAutoDrawable drawable) {
|
|
||||||
if (nextStrategy == null)
|
|
||||||
return;
|
|
||||||
currentStrategy.dispose(drawable);
|
|
||||||
nextStrategy.init(drawable);
|
|
||||||
currentStrategy = nextStrategy;
|
|
||||||
nextStrategy = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void init(GLAutoDrawable drawable) {
|
public void init(GLAutoDrawable drawable) {
|
||||||
cr = new ComponentRenderer();
|
|
||||||
cr.init(drawable);
|
cr.init(drawable);
|
||||||
|
currentStrategy.init(drawable);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void dispose(GLAutoDrawable drawable) {
|
public void dispose(GLAutoDrawable drawable) {
|
||||||
@ -66,7 +54,6 @@ public class RocketRenderer {
|
|||||||
|
|
||||||
public RocketComponent pick(GLAutoDrawable drawable,
|
public RocketComponent pick(GLAutoDrawable drawable,
|
||||||
Configuration configuration, Point p, Set<RocketComponent> ignore) {
|
Configuration configuration, Point p, Set<RocketComponent> ignore) {
|
||||||
checkRenderStrategy(drawable);
|
|
||||||
final GL2 gl = drawable.getGL().getGL2();
|
final GL2 gl = drawable.getGL().getGL2();
|
||||||
gl.glEnable(GL.GL_DEPTH_TEST);
|
gl.glEnable(GL.GL_DEPTH_TEST);
|
||||||
|
|
||||||
@ -86,7 +73,7 @@ public class RocketRenderer {
|
|||||||
(byte) ((pickParts.size() << 4) & 0xF0), (byte) 1);
|
(byte) ((pickParts.size() << 4) & 0xF0), (byte) 1);
|
||||||
pickParts.add(c);
|
pickParts.add(c);
|
||||||
|
|
||||||
if (currentStrategy.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.renderGeometry(gl, c);
|
cr.renderGeometry(gl, c);
|
||||||
@ -112,7 +99,6 @@ public class RocketRenderer {
|
|||||||
|
|
||||||
public void render(GLAutoDrawable drawable, Configuration configuration,
|
public void render(GLAutoDrawable drawable, Configuration configuration,
|
||||||
Set<RocketComponent> selection) {
|
Set<RocketComponent> selection) {
|
||||||
checkRenderStrategy(drawable);
|
|
||||||
|
|
||||||
if (cr == null)
|
if (cr == null)
|
||||||
throw new IllegalStateException(this + " Not Initialized");
|
throw new IllegalStateException(this + " Not Initialized");
|
||||||
@ -155,8 +141,8 @@ public class RocketRenderer {
|
|||||||
|
|
||||||
// Draw all inner components
|
// Draw all inner components
|
||||||
for (RocketComponent c : configuration) {
|
for (RocketComponent c : configuration) {
|
||||||
if (currentStrategy.isDrawn(c)) {
|
if (isDrawn(c)) {
|
||||||
if (!currentStrategy.isDrawnTransparent(c)) {
|
if (!isDrawnTransparent(c)) {
|
||||||
renderComponent(gl, c, 1.0f);
|
renderComponent(gl, c, 1.0f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -169,8 +155,8 @@ public class RocketRenderer {
|
|||||||
gl.glEnable(GL.GL_CULL_FACE);
|
gl.glEnable(GL.GL_CULL_FACE);
|
||||||
gl.glCullFace(GL.GL_FRONT);
|
gl.glCullFace(GL.GL_FRONT);
|
||||||
for (RocketComponent c : configuration) {
|
for (RocketComponent c : configuration) {
|
||||||
if (currentStrategy.isDrawn(c)) {
|
if (isDrawn(c)) {
|
||||||
if (currentStrategy.isDrawnTransparent(c)) {
|
if (isDrawnTransparent(c)) {
|
||||||
renderComponent(gl, c, 1.0f);
|
renderComponent(gl, c, 1.0f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -182,8 +168,8 @@ public class RocketRenderer {
|
|||||||
gl.glEnable(GL.GL_CULL_FACE);
|
gl.glEnable(GL.GL_CULL_FACE);
|
||||||
gl.glCullFace(GL.GL_BACK);
|
gl.glCullFace(GL.GL_BACK);
|
||||||
for (RocketComponent c : configuration) {
|
for (RocketComponent c : configuration) {
|
||||||
if (currentStrategy.isDrawn(c)) {
|
if (isDrawn(c)) {
|
||||||
if (currentStrategy.isDrawnTransparent(c)) {
|
if (isDrawnTransparent(c)) {
|
||||||
renderComponent(gl, c, 0.2f);
|
renderComponent(gl, c, 0.2f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -213,10 +199,9 @@ public class RocketRenderer {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void renderComponent(GL2 gl, RocketComponent c, float alpha) {
|
public abstract void renderComponent(GL2 gl, RocketComponent c, float alpha);
|
||||||
currentStrategy.preGeometry(gl, c, alpha);
|
|
||||||
cr.renderGeometry(gl, c);
|
|
||||||
currentStrategy.postGeometry(gl, c, alpha);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
public abstract boolean isDrawn(RocketComponent c);
|
||||||
|
|
||||||
|
public abstract boolean isDrawnTransparent(RocketComponent c);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user