Merge pull request #36 from bkuker/kruland-integration-stickers
Sticker decal mode & decal improvements
This commit is contained in:
commit
fa58cb6338
BIN
core/resources/datafiles/examples/Sticker Decals.ork
Normal file
BIN
core/resources/datafiles/examples/Sticker Decals.ork
Normal file
Binary file not shown.
@ -741,6 +741,7 @@ AppearanceCfg.lbl.texture.repeat = Repeat:
|
||||
TextureWrap.Repeat = Repeat
|
||||
TextureWrap.Mirror = Repeat & Mirror
|
||||
TextureWrap.Clamp = Clamp Edge Pixels
|
||||
TextureWrap.Sticker = Sticker
|
||||
|
||||
! RocketConfig
|
||||
RocketCfg.lbl.Designname = Design name:
|
||||
|
||||
@ -11,7 +11,7 @@ import net.sf.openrocket.util.Coordinate;
|
||||
public class Decal {
|
||||
|
||||
public static enum EdgeMode {
|
||||
REPEAT("TextureWrap.Repeat"), MIRROR("TextureWrap.Mirror"), CLAMP("TextureWrap.Clamp");
|
||||
REPEAT("TextureWrap.Repeat"), MIRROR("TextureWrap.Mirror"), CLAMP("TextureWrap.Clamp"), STICKER("TextureWrap.Sticker");
|
||||
private final String transName;
|
||||
EdgeMode(final String name){
|
||||
this.transName = name;
|
||||
|
||||
@ -249,14 +249,7 @@ public class AppearancePanel extends JPanel {
|
||||
{ // Color
|
||||
add(new JLabel(trans.get("AppearanceCfg.lbl.color.Color")));
|
||||
//mDefault.addEnableComponent(colorButton, false);
|
||||
colorButton.setEnabled(ab.getImage() == null);
|
||||
add(colorButton);
|
||||
ab.addChangeListener(new StateChangeListener() {
|
||||
@Override
|
||||
public void stateChanged(EventObject e) {
|
||||
colorButton.setEnabled(ab.getImage() == null);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
{ // Scale
|
||||
|
||||
@ -17,12 +17,39 @@ import net.sf.openrocket.rocketcomponent.Transition;
|
||||
import net.sf.openrocket.startup.Application;
|
||||
import net.sf.openrocket.util.Color;
|
||||
|
||||
public class FigureRenderStrategy extends RenderStrategy {
|
||||
public class FigureRenderer extends RocketRenderer {
|
||||
private final float[] color = new float[4];
|
||||
|
||||
public FigureRenderStrategy() {
|
||||
super(null);
|
||||
|
||||
public FigureRenderer() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(GLAutoDrawable drawable) {
|
||||
super.init(drawable);
|
||||
|
||||
GL2 gl = drawable.getGL().getGL2();
|
||||
|
||||
gl.glLightModelfv(GL2ES1.GL_LIGHT_MODEL_AMBIENT,
|
||||
new float[] { 0,0,0 }, 0);
|
||||
|
||||
float amb = 0.3f;
|
||||
float dif = 1.0f - amb;
|
||||
float spc = 1.0f;
|
||||
gl.glLightfv(GLLightingFunc.GL_LIGHT1, GLLightingFunc.GL_AMBIENT,
|
||||
new float[] { amb, amb, amb, 1 }, 0);
|
||||
gl.glLightfv(GLLightingFunc.GL_LIGHT1, GLLightingFunc.GL_DIFFUSE,
|
||||
new float[] { dif, dif, dif, 1 }, 0);
|
||||
gl.glLightfv(GLLightingFunc.GL_LIGHT1, GLLightingFunc.GL_SPECULAR,
|
||||
new float[] { spc, spc, spc, 1 }, 0);
|
||||
|
||||
gl.glEnable(GLLightingFunc.GL_LIGHT1);
|
||||
gl.glEnable(GLLightingFunc.GL_LIGHTING);
|
||||
gl.glShadeModel(GLLightingFunc.GL_SMOOTH);
|
||||
|
||||
gl.glEnable(GLLightingFunc.GL_NORMALIZE);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isDrawn(RocketComponent c) {
|
||||
@ -45,11 +72,12 @@ public class FigureRenderStrategy extends RenderStrategy {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
private static final HashMap<Class<?>, Color> defaultColorCache = new HashMap<Class<?>, Color>();
|
||||
|
||||
@Override
|
||||
public void preGeometry(GL2 gl, RocketComponent c, float alpha) {
|
||||
public void renderComponent(GL2 gl, RocketComponent c, float alpha) {
|
||||
|
||||
gl.glLightModeli(GL2ES1.GL_LIGHT_MODEL_TWO_SIDE, 1);
|
||||
Color figureColor = c.getColor();
|
||||
if (figureColor == null) {
|
||||
@ -90,36 +118,7 @@ public class FigureRenderStrategy extends RenderStrategy {
|
||||
gl.glMaterialfv(GL.GL_BACK, GLLightingFunc.GL_DIFFUSE, color, 0);
|
||||
gl.glMaterialfv(GL.GL_BACK, GLLightingFunc.GL_AMBIENT, color, 0);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postGeometry(GL2 gl, RocketComponent c, float alpha) {
|
||||
//Nothing to do here
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(GLAutoDrawable drawable) {
|
||||
GL2 gl = drawable.getGL().getGL2();
|
||||
|
||||
gl.glLightModelfv(GL2ES1.GL_LIGHT_MODEL_AMBIENT,
|
||||
new float[] { 0,0,0 }, 0);
|
||||
|
||||
float amb = 0.3f;
|
||||
float dif = 1.0f - amb;
|
||||
float spc = 1.0f;
|
||||
gl.glLightfv(GLLightingFunc.GL_LIGHT1, GLLightingFunc.GL_AMBIENT,
|
||||
new float[] { amb, amb, amb, 1 }, 0);
|
||||
gl.glLightfv(GLLightingFunc.GL_LIGHT1, GLLightingFunc.GL_DIFFUSE,
|
||||
new float[] { dif, dif, dif, 1 }, 0);
|
||||
gl.glLightfv(GLLightingFunc.GL_LIGHT1, GLLightingFunc.GL_SPECULAR,
|
||||
new float[] { spc, spc, spc, 1 }, 0);
|
||||
|
||||
gl.glEnable(GLLightingFunc.GL_LIGHT1);
|
||||
gl.glEnable(GLLightingFunc.GL_LIGHTING);
|
||||
gl.glShadeModel(GLLightingFunc.GL_SMOOTH);
|
||||
|
||||
gl.glEnable(GLLightingFunc.GL_NORMALIZE);
|
||||
cr.renderGeometry(gl, c);
|
||||
}
|
||||
|
||||
private static int getShine(RocketComponent c) {
|
||||
@ -15,54 +15,45 @@ import javax.media.opengl.fixedfunc.GLMatrixFunc;
|
||||
import net.sf.openrocket.appearance.Appearance;
|
||||
import net.sf.openrocket.appearance.Decal;
|
||||
import net.sf.openrocket.document.OpenRocketDocument;
|
||||
import net.sf.openrocket.logging.LogHelper;
|
||||
import net.sf.openrocket.rocketcomponent.RocketComponent;
|
||||
import net.sf.openrocket.startup.Application;
|
||||
import net.sf.openrocket.util.Color;
|
||||
|
||||
import com.jogamp.opengl.util.texture.Texture;
|
||||
import com.jogamp.opengl.util.texture.TextureData;
|
||||
import com.jogamp.opengl.util.texture.TextureIO;
|
||||
|
||||
public class RealisticRenderStrategy extends RenderStrategy {
|
||||
|
||||
public class RealisticRenderer extends RocketRenderer {
|
||||
private final float[] colorBlack = { 0, 0, 0, 1 };
|
||||
private final float[] colorClear = { 0, 0, 0, 0 };
|
||||
private final float[] colorWhite = { 1, 1, 1, 1 };
|
||||
private final float[] color = new float[4];
|
||||
private static final LogHelper log = Application.getLogger();
|
||||
|
||||
private boolean needClearCache = false;
|
||||
private Map<String, Texture> oldTexCache = new HashMap<String, Texture>();
|
||||
private Map<String, Texture> texCache = new HashMap<String, Texture>();
|
||||
private float anisotrophy = 0;
|
||||
|
||||
public RealisticRenderStrategy(OpenRocketDocument document) {
|
||||
super(document);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateFigure() {
|
||||
needClearCache = true;
|
||||
public RealisticRenderer(OpenRocketDocument document) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(GLAutoDrawable drawable) {
|
||||
super.init(drawable);
|
||||
|
||||
oldTexCache = new HashMap<String, Texture>();
|
||||
texCache = new HashMap<String, Texture>();
|
||||
|
||||
GL2 gl = drawable.getGL().getGL2();
|
||||
|
||||
gl.glLightModelfv(GL2ES1.GL_LIGHT_MODEL_AMBIENT,
|
||||
new float[] { 0, 0, 0 }, 0);
|
||||
gl.glLightModelfv(GL2ES1.GL_LIGHT_MODEL_AMBIENT, new float[] { 0, 0, 0 }, 0);
|
||||
|
||||
float amb = 0.3f;
|
||||
float dif = 1.0f - amb;
|
||||
float spc = 1.0f;
|
||||
gl.glLightfv(GLLightingFunc.GL_LIGHT1, GLLightingFunc.GL_AMBIENT,
|
||||
new float[] { amb, amb, amb, 1 }, 0);
|
||||
gl.glLightfv(GLLightingFunc.GL_LIGHT1, GLLightingFunc.GL_DIFFUSE,
|
||||
new float[] { dif, dif, dif, 1 }, 0);
|
||||
gl.glLightfv(GLLightingFunc.GL_LIGHT1, GLLightingFunc.GL_SPECULAR,
|
||||
new float[] { spc, spc, spc, 1 }, 0);
|
||||
gl.glLightfv(GLLightingFunc.GL_LIGHT1, GLLightingFunc.GL_AMBIENT, new float[] { amb, amb, amb, 1 }, 0);
|
||||
gl.glLightfv(GLLightingFunc.GL_LIGHT1, GLLightingFunc.GL_DIFFUSE, new float[] { dif, dif, dif, 1 }, 0);
|
||||
gl.glLightfv(GLLightingFunc.GL_LIGHT1, GLLightingFunc.GL_SPECULAR, new float[] { spc, spc, spc, 1 }, 0);
|
||||
|
||||
gl.glEnable(GLLightingFunc.GL_LIGHT1);
|
||||
gl.glEnable(GLLightingFunc.GL_LIGHTING);
|
||||
@ -77,8 +68,17 @@ public class RealisticRenderStrategy extends RenderStrategy {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateFigure() {
|
||||
super.updateFigure();
|
||||
|
||||
needClearCache = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose(GLAutoDrawable drawable) {
|
||||
super.dispose(drawable);
|
||||
|
||||
oldTexCache = null;
|
||||
texCache = null;
|
||||
}
|
||||
@ -94,23 +94,23 @@ public class RealisticRenderStrategy extends RenderStrategy {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void preGeometry(GL2 gl, RocketComponent c, float alpha) {
|
||||
public void renderComponent(GL2 gl, RocketComponent c, float alpha) {
|
||||
|
||||
if (needClearCache) {
|
||||
clearCaches(gl);
|
||||
needClearCache = false;
|
||||
}
|
||||
|
||||
Appearance a = getAppearance(c);
|
||||
final Appearance a = getAppearance(c);
|
||||
final Decal t = a.getTexture();
|
||||
final Texture tex = getTexture(t);
|
||||
|
||||
gl.glLightModeli(GL2ES1.GL_LIGHT_MODEL_TWO_SIDE, 1);
|
||||
gl.glLightModeli(GL2.GL_LIGHT_MODEL_COLOR_CONTROL, GL2.GL_SEPARATE_SPECULAR_COLOR);
|
||||
|
||||
|
||||
if (a.getTexture() != null) {
|
||||
color[0] = color[1] = color[2] = 1;
|
||||
} else {
|
||||
convertColor(a.getPaint(), color);
|
||||
color[3] = alpha;
|
||||
}
|
||||
convertColor(a.getPaint(), color);
|
||||
color[3] = alpha;
|
||||
gl.glMaterialfv(GL.GL_FRONT, GLLightingFunc.GL_DIFFUSE, color, 0);
|
||||
gl.glMaterialfv(GL.GL_BACK, GLLightingFunc.GL_DIFFUSE, color, 0);
|
||||
gl.glMaterialfv(GL.GL_FRONT, GLLightingFunc.GL_AMBIENT, color, 0);
|
||||
@ -124,17 +124,15 @@ public class RealisticRenderStrategy extends RenderStrategy {
|
||||
gl.glMaterialfv(GL.GL_BACK, GLLightingFunc.GL_SPECULAR, colorBlack, 0);
|
||||
gl.glMateriali(GL.GL_BACK, GLLightingFunc.GL_SHININESS, 0);
|
||||
|
||||
Decal t = a.getTexture();
|
||||
Texture tex = null;
|
||||
if (t != null) {
|
||||
tex = getTexture(t);
|
||||
}
|
||||
cr.renderGeometry(gl, c);
|
||||
|
||||
if (t != null && tex != null) {
|
||||
gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR_MIPMAP_LINEAR);
|
||||
gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR);
|
||||
|
||||
tex.enable(gl);
|
||||
tex.bind(gl);
|
||||
|
||||
gl.glMatrixMode(GL.GL_TEXTURE);
|
||||
gl.glPushMatrix();
|
||||
|
||||
@ -148,28 +146,35 @@ public class RealisticRenderStrategy extends RenderStrategy {
|
||||
gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_T, toEdgeMode(t.getEdgeMode()));
|
||||
gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_S, toEdgeMode(t.getEdgeMode()));
|
||||
|
||||
|
||||
gl.glTexParameterfv(GL.GL_TEXTURE_2D, GL2.GL_TEXTURE_BORDER_COLOR, colorClear, 0);
|
||||
gl.glMaterialfv(GL.GL_FRONT, GLLightingFunc.GL_DIFFUSE, colorWhite, 0);
|
||||
gl.glMaterialfv(GL.GL_BACK, GLLightingFunc.GL_DIFFUSE, colorWhite, 0);
|
||||
gl.glMaterialfv(GL.GL_FRONT, GLLightingFunc.GL_AMBIENT, colorWhite, 0);
|
||||
gl.glMaterialfv(GL.GL_BACK, GLLightingFunc.GL_AMBIENT, colorWhite, 0);
|
||||
|
||||
gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
|
||||
gl.glEnable(GL.GL_BLEND);
|
||||
gl.glDepthFunc(GL.GL_LEQUAL);
|
||||
|
||||
gl.glMatrixMode(GLMatrixFunc.GL_MODELVIEW);
|
||||
|
||||
if (anisotrophy > 0) {
|
||||
gl.glTexParameterf(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAX_ANISOTROPY_EXT, anisotrophy);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postGeometry(GL2 gl, RocketComponent c, float alpha) {
|
||||
Appearance a = getAppearance(c);
|
||||
Decal t = a.getTexture();
|
||||
Texture tex = null;
|
||||
if (t != null) {
|
||||
tex = getTexture(t);
|
||||
}
|
||||
if (tex != null) {
|
||||
|
||||
cr.renderGeometry(gl, c);
|
||||
|
||||
if (t.getEdgeMode() == Decal.EdgeMode.STICKER) {
|
||||
gl.glDepthFunc(GL.GL_LESS);
|
||||
}
|
||||
|
||||
gl.glMatrixMode(GL.GL_TEXTURE);
|
||||
gl.glPopMatrix();
|
||||
gl.glMatrixMode(GLMatrixFunc.GL_MODELVIEW);
|
||||
tex.disable(gl);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void clearCaches(GL2 gl) {
|
||||
@ -184,6 +189,9 @@ public class RealisticRenderStrategy extends RenderStrategy {
|
||||
}
|
||||
|
||||
private Texture getTexture(Decal t) {
|
||||
if (t == null)
|
||||
return null;
|
||||
|
||||
String imageName = t.getImage().getName();
|
||||
|
||||
// Return the Cached value if available
|
||||
@ -202,7 +210,7 @@ public class RealisticRenderStrategy extends RenderStrategy {
|
||||
try {
|
||||
log.debug("Loading texture " + t);
|
||||
InputStream is = t.getImage().getBytes();
|
||||
TextureData data = TextureIO.newTextureData(GLProfile.getDefault(), is, true, null);
|
||||
TextureData data = TextureIO.newTextureData(GLProfile.getDefault(), is, GL.GL_RGBA, GL.GL_RGBA, true, null);
|
||||
tex = TextureIO.newTexture(data);
|
||||
} catch (Throwable e) {
|
||||
log.error("Error loading Texture", e);
|
||||
@ -229,6 +237,8 @@ public class RealisticRenderStrategy extends RenderStrategy {
|
||||
return GL.GL_MIRRORED_REPEAT;
|
||||
case CLAMP:
|
||||
return GL.GL_CLAMP_TO_EDGE;
|
||||
case STICKER:
|
||||
return GL2.GL_CLAMP_TO_BORDER;
|
||||
default:
|
||||
return GL.GL_CLAMP_TO_EDGE;
|
||||
}
|
||||
@ -1,37 +0,0 @@
|
||||
package net.sf.openrocket.gui.figure3d;
|
||||
|
||||
import javax.media.opengl.GL2;
|
||||
import javax.media.opengl.GLAutoDrawable;
|
||||
|
||||
import net.sf.openrocket.document.OpenRocketDocument;
|
||||
import net.sf.openrocket.rocketcomponent.RocketComponent;
|
||||
|
||||
public abstract class RenderStrategy {
|
||||
|
||||
protected final OpenRocketDocument document;
|
||||
|
||||
public RenderStrategy( OpenRocketDocument 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 init(GLAutoDrawable drawable) {
|
||||
|
||||
}
|
||||
|
||||
public void dispose(GLAutoDrawable drawable) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -21,6 +21,7 @@ import javax.media.opengl.GLAutoDrawable;
|
||||
import javax.media.opengl.GLCapabilities;
|
||||
import javax.media.opengl.GLEventListener;
|
||||
import javax.media.opengl.GLProfile;
|
||||
import javax.media.opengl.GLRunnable;
|
||||
import javax.media.opengl.awt.GLCanvas;
|
||||
import javax.media.opengl.fixedfunc.GLLightingFunc;
|
||||
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 };
|
||||
|
||||
RocketRenderer rr = new RocketRenderer();
|
||||
RocketRenderer rr = new FigureRenderer();
|
||||
|
||||
public RocketFigure3d(OpenRocketDocument document, Configuration config) {
|
||||
this.document = document;
|
||||
@ -393,7 +394,7 @@ public class RocketFigure3d extends JPanel implements GLEventListener {
|
||||
GL2 gl = drawable.getGL().getGL2();
|
||||
gl.glClearDepth(1.0f); // clear z-buffer to the farthest
|
||||
|
||||
gl.glDepthFunc(GL.GL_LEQUAL); // the type of depth test to do
|
||||
gl.glDepthFunc(GL.GL_LESS); // the type of depth test to do
|
||||
|
||||
float amb = 0.5f;
|
||||
float dif = 1.0f;
|
||||
@ -425,7 +426,7 @@ public class RocketFigure3d extends JPanel implements GLEventListener {
|
||||
|
||||
gl.glMatrixMode(GLMatrixFunc.GL_PROJECTION);
|
||||
gl.glLoadIdentity();
|
||||
glu.gluPerspective(fovY, ratio, 0.05f, 100f);
|
||||
glu.gluPerspective(fovY, ratio, 0.1f, 50f);
|
||||
gl.glMatrixMode(GLMatrixFunc.GL_MODELVIEW);
|
||||
|
||||
redrawExtras = true;
|
||||
@ -631,13 +632,20 @@ public class RocketFigure3d extends JPanel implements GLEventListener {
|
||||
this.csl = newListener;
|
||||
}
|
||||
|
||||
public void setType(int t) {
|
||||
if (t == TYPE_FIGURE) {
|
||||
rr.setRenderStrategy(new FigureRenderStrategy());
|
||||
} else {
|
||||
rr.setRenderStrategy(new RealisticRenderStrategy(document));
|
||||
}
|
||||
repaint();
|
||||
public void setType(final int t) {
|
||||
canvas.invoke(true, new GLRunnable() {
|
||||
@Override
|
||||
public boolean run(GLAutoDrawable drawable) {
|
||||
rr.dispose(drawable);
|
||||
if (t == TYPE_FIGURE) {
|
||||
rr = new FigureRenderer();
|
||||
} else {
|
||||
rr = new RealisticRenderer(document);
|
||||
}
|
||||
rr.init(drawable);
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -23,50 +23,33 @@ import net.sf.openrocket.util.Coordinate;
|
||||
/*
|
||||
* @author Bill Kuker <bkuker@billkuker.com>
|
||||
*/
|
||||
public class RocketRenderer {
|
||||
@SuppressWarnings("unused")
|
||||
private static final LogHelper log = Application.getLogger();
|
||||
public abstract class RocketRenderer {
|
||||
protected static final LogHelper log = Application.getLogger();
|
||||
|
||||
RenderStrategy currentStrategy = new FigureRenderStrategy();
|
||||
RenderStrategy nextStrategy;
|
||||
|
||||
ComponentRenderer cr;
|
||||
final ComponentRenderer cr = new ComponentRenderer();
|
||||
|
||||
private final float[] selectedEmissive = { 1, 0, 0, 1 };
|
||||
private final float[] colorBlack = { 0, 0, 0, 1 };
|
||||
|
||||
|
||||
public void setRenderStrategy(RenderStrategy r) {
|
||||
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) {
|
||||
cr = new ComponentRenderer();
|
||||
cr.init(drawable);
|
||||
}
|
||||
|
||||
public void dispose(GLAutoDrawable drawable) {
|
||||
currentStrategy.dispose(drawable);
|
||||
}
|
||||
|
||||
public void updateFigure() {
|
||||
currentStrategy.updateFigure();
|
||||
cr.updateFigure();
|
||||
}
|
||||
|
||||
public abstract void renderComponent(GL2 gl, RocketComponent c, float alpha);
|
||||
|
||||
public RocketComponent pick(GLAutoDrawable drawable,
|
||||
Configuration configuration, Point p, Set<RocketComponent> ignore) {
|
||||
checkRenderStrategy(drawable);
|
||||
public abstract boolean isDrawn(RocketComponent c);
|
||||
|
||||
public abstract boolean isDrawnTransparent(RocketComponent c);
|
||||
|
||||
public RocketComponent pick(GLAutoDrawable drawable, Configuration configuration, Point p,
|
||||
Set<RocketComponent> ignore) {
|
||||
final GL2 gl = drawable.getGL().getGL2();
|
||||
gl.glEnable(GL.GL_DEPTH_TEST);
|
||||
|
||||
@ -81,12 +64,11 @@ public class RocketRenderer {
|
||||
// if index is 0x0ABC the color ends up as
|
||||
// 0xA0B0C000 with each nibble in the coresponding
|
||||
// high bits of the RG and B channels.
|
||||
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);
|
||||
pickParts.add(c);
|
||||
|
||||
if (currentStrategy.isDrawnTransparent(c)) {
|
||||
if (isDrawnTransparent(c)) {
|
||||
gl.glEnable(GL.GL_CULL_FACE);
|
||||
gl.glCullFace(GL.GL_FRONT);
|
||||
cr.renderGeometry(gl, c);
|
||||
@ -101,8 +83,7 @@ public class RocketRenderer {
|
||||
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);
|
||||
final int pickIndex = ((pickColor >> 20) & 0xF00) | ((pickColor >> 16) & 0x0F0) | ((pickColor >> 12) & 0x00F);
|
||||
|
||||
if (pickIndex < 0 || pickIndex > pickParts.size() - 1)
|
||||
return null;
|
||||
@ -110,9 +91,7 @@ public class RocketRenderer {
|
||||
return pickParts.get(pickIndex);
|
||||
}
|
||||
|
||||
public void render(GLAutoDrawable drawable, Configuration configuration,
|
||||
Set<RocketComponent> selection) {
|
||||
checkRenderStrategy(drawable);
|
||||
public void render(GLAutoDrawable drawable, Configuration configuration, Set<RocketComponent> selection) {
|
||||
|
||||
if (cr == null)
|
||||
throw new IllegalStateException(this + " Not Initialized");
|
||||
@ -122,24 +101,22 @@ public class RocketRenderer {
|
||||
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);
|
||||
{ // 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
|
||||
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
|
||||
// Draw polygons, always passing depth test,
|
||||
// setting Z to farthest
|
||||
gl.glPolygonMode(GL.GL_FRONT_AND_BACK, GL2GL3.GL_FILL);
|
||||
gl.glDepthRange(1, 1);
|
||||
gl.glDepthFunc(GL.GL_ALWAYS);
|
||||
@ -149,14 +126,13 @@ public 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
|
||||
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 (currentStrategy.isDrawn(c)) {
|
||||
if (!currentStrategy.isDrawnTransparent(c)) {
|
||||
if (isDrawn(c)) {
|
||||
if (!isDrawnTransparent(c)) {
|
||||
renderComponent(gl, c, 1.0f);
|
||||
}
|
||||
}
|
||||
@ -169,8 +145,8 @@ public class RocketRenderer {
|
||||
gl.glEnable(GL.GL_CULL_FACE);
|
||||
gl.glCullFace(GL.GL_FRONT);
|
||||
for (RocketComponent c : configuration) {
|
||||
if (currentStrategy.isDrawn(c)) {
|
||||
if (currentStrategy.isDrawnTransparent(c)) {
|
||||
if (isDrawn(c)) {
|
||||
if (isDrawnTransparent(c)) {
|
||||
renderComponent(gl, c, 1.0f);
|
||||
}
|
||||
}
|
||||
@ -182,8 +158,8 @@ public class RocketRenderer {
|
||||
gl.glEnable(GL.GL_CULL_FACE);
|
||||
gl.glCullFace(GL.GL_BACK);
|
||||
for (RocketComponent c : configuration) {
|
||||
if (currentStrategy.isDrawn(c)) {
|
||||
if (currentStrategy.isDrawnTransparent(c)) {
|
||||
if (isDrawn(c)) {
|
||||
if (isDrawnTransparent(c)) {
|
||||
renderComponent(gl, c, 0.2f);
|
||||
}
|
||||
}
|
||||
@ -202,9 +178,8 @@ public class RocketRenderer {
|
||||
double length = motor.getLength();
|
||||
double radius = motor.getDiameter() / 2;
|
||||
|
||||
Coordinate[] position = ((RocketComponent) mount)
|
||||
.toAbsolute(new Coordinate(((RocketComponent) mount)
|
||||
.getLength() + mount.getMotorOverhang() - length));
|
||||
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);
|
||||
@ -213,10 +188,4 @@ public class RocketRenderer {
|
||||
|
||||
}
|
||||
|
||||
public void renderComponent(GL2 gl, RocketComponent c, float alpha) {
|
||||
currentStrategy.preGeometry(gl, c, alpha);
|
||||
cr.renderGeometry(gl, c);
|
||||
currentStrategy.postGeometry(gl, c, alpha);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user