Merge remote-tracking branch 'bkuker/photobooth-split' into photobooth-split
This commit is contained in:
commit
cae915f351
@ -26,9 +26,9 @@ void main(void)
|
|||||||
|
|
||||||
vec4 flameColor = gl_LightSource[2].diffuse;
|
vec4 flameColor = gl_LightSource[2].diffuse;
|
||||||
float flameFactor = max (dot (vec3(0,0,1), diffuseNormal), 0.0);
|
float flameFactor = max (dot (vec3(0,0,1), diffuseNormal), 0.0);
|
||||||
flameFactor = flameFactor * (1 - z / 1.0);
|
flameFactor = flameFactor * (1.0 - z / 1.0);
|
||||||
flameFactor = flameFactor * diffuseMaterial.a * gl_Color.a * 10;
|
flameFactor = flameFactor * diffuseMaterial.a * gl_Color.a * 10.0;
|
||||||
flameFactor = clamp(flameFactor,0,1);
|
flameFactor = clamp(flameFactor,0.0,1.0);
|
||||||
|
|
||||||
vec4 light = diffuseLight * diffuseBump + ambientLight;
|
vec4 light = diffuseLight * diffuseBump + ambientLight;
|
||||||
|
|
||||||
|
@ -23,6 +23,7 @@ import javax.swing.JMenu;
|
|||||||
import javax.swing.JMenuBar;
|
import javax.swing.JMenuBar;
|
||||||
import javax.swing.JMenuItem;
|
import javax.swing.JMenuItem;
|
||||||
import javax.swing.KeyStroke;
|
import javax.swing.KeyStroke;
|
||||||
|
import javax.swing.SwingUtilities;
|
||||||
import javax.swing.filechooser.FileFilter;
|
import javax.swing.filechooser.FileFilter;
|
||||||
|
|
||||||
import net.sf.openrocket.database.Databases;
|
import net.sf.openrocket.database.Databases;
|
||||||
@ -154,43 +155,48 @@ public class PhotoFrame extends JFrame {
|
|||||||
photoPanel.addImageCallback(new PhotoPanel.ImageCallback() {
|
photoPanel.addImageCallback(new PhotoPanel.ImageCallback() {
|
||||||
@Override
|
@Override
|
||||||
public void performAction(final BufferedImage image) {
|
public void performAction(final BufferedImage image) {
|
||||||
log.info("Got image {} to save...", image);
|
SwingUtilities.invokeLater(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
log.info("Got image {} to save...", image);
|
||||||
|
|
||||||
final FileFilter png = new SimpleFileFilter("PNG Image", ".png"); // TODO
|
final FileFilter png = new SimpleFileFilter("PNG Image", ".png"); // TODO
|
||||||
// Trans
|
// Trans
|
||||||
|
|
||||||
final JFileChooser chooser = new JFileChooser();
|
final JFileChooser chooser = new JFileChooser();
|
||||||
|
|
||||||
chooser.addChoosableFileFilter(png);
|
chooser.addChoosableFileFilter(png);
|
||||||
chooser.setFileFilter(png);
|
chooser.setFileFilter(png);
|
||||||
chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
|
chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
|
||||||
|
|
||||||
chooser.setCurrentDirectory(((SwingPreferences) Application.getPreferences())
|
chooser.setCurrentDirectory(((SwingPreferences) Application.getPreferences())
|
||||||
.getDefaultDirectory());
|
.getDefaultDirectory());
|
||||||
final int option = chooser.showSaveDialog(PhotoFrame.this);
|
final int option = chooser.showSaveDialog(PhotoFrame.this);
|
||||||
|
|
||||||
if (option != JFileChooser.APPROVE_OPTION) {
|
if (option != JFileChooser.APPROVE_OPTION) {
|
||||||
log.info(Markers.USER_MARKER, "User decided not to save, option=" + option);
|
log.info(Markers.USER_MARKER, "User decided not to save, option=" + option);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final File file = FileHelper.forceExtension(chooser.getSelectedFile(), "png");
|
final File file = FileHelper.forceExtension(chooser.getSelectedFile(), "png");
|
||||||
if (file == null) {
|
if (file == null) {
|
||||||
log.info(Markers.USER_MARKER, "User did not select a file");
|
log.info(Markers.USER_MARKER, "User did not select a file");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
((SwingPreferences) Application.getPreferences()).setDefaultDirectory(chooser
|
((SwingPreferences) Application.getPreferences()).setDefaultDirectory(chooser
|
||||||
.getCurrentDirectory());
|
.getCurrentDirectory());
|
||||||
log.info(Markers.USER_MARKER, "User chose to save image as {}", file);
|
log.info(Markers.USER_MARKER, "User chose to save image as {}", file);
|
||||||
|
|
||||||
if (FileHelper.confirmWrite(file, PhotoFrame.this)) {
|
if (FileHelper.confirmWrite(file, PhotoFrame.this)) {
|
||||||
try {
|
try {
|
||||||
ImageIO.write(image, "png", file);
|
ImageIO.write(image, "png", file);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new Error(e);
|
throw new Error(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -335,7 +341,7 @@ public class PhotoFrame extends JFrame {
|
|||||||
pa.setVisible(true);
|
pa.setVisible(true);
|
||||||
|
|
||||||
GeneralRocketLoader grl = new GeneralRocketLoader(new File(
|
GeneralRocketLoader grl = new GeneralRocketLoader(new File(
|
||||||
"C:/Users/bkuker/git/openrocket/swing/resources/datafiles/examples/A simple model rocket.ork"));
|
"/Users/bkuker/git/openrocket/swing/resources/datafiles/examples/A simple model rocket.ork"));
|
||||||
OpenRocketDocument doc = grl.load();
|
OpenRocketDocument doc = grl.load();
|
||||||
pa.photoPanel.setDoc(doc);
|
pa.photoPanel.setDoc(doc);
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ package net.sf.openrocket.gui.figure3d.photo;
|
|||||||
|
|
||||||
import java.awt.BorderLayout;
|
import java.awt.BorderLayout;
|
||||||
import java.awt.Component;
|
import java.awt.Component;
|
||||||
|
import java.awt.Rectangle;
|
||||||
import java.awt.SplashScreen;
|
import java.awt.SplashScreen;
|
||||||
import java.awt.event.MouseEvent;
|
import java.awt.event.MouseEvent;
|
||||||
import java.awt.event.MouseWheelEvent;
|
import java.awt.event.MouseWheelEvent;
|
||||||
@ -79,6 +80,7 @@ public class PhotoPanel extends JPanel implements GLEventListener {
|
|||||||
|
|
||||||
void addImageCallback(ImageCallback a) {
|
void addImageCallback(ImageCallback a) {
|
||||||
imageCallbacks.add(a);
|
imageCallbacks.add(a);
|
||||||
|
repaint();
|
||||||
}
|
}
|
||||||
|
|
||||||
private RocketRenderer rr;
|
private RocketRenderer rr;
|
||||||
@ -93,14 +95,15 @@ public class PhotoPanel extends JPanel implements GLEventListener {
|
|||||||
rr = new RealisticRenderer(doc);
|
rr = new RealisticRenderer(doc);
|
||||||
rr.init(drawable);
|
rr.init(drawable);
|
||||||
|
|
||||||
doc.getDefaultConfiguration().addChangeListener(new StateChangeListener() {
|
doc.getDefaultConfiguration().addChangeListener(
|
||||||
@Override
|
new StateChangeListener() {
|
||||||
public void stateChanged(EventObject e) {
|
@Override
|
||||||
log.debug("Repainting on config state change");
|
public void stateChanged(EventObject e) {
|
||||||
needUpdate = true;
|
log.debug("Repainting on config state change");
|
||||||
PhotoPanel.this.repaint();
|
needUpdate = true;
|
||||||
}
|
PhotoPanel.this.repaint();
|
||||||
});
|
}
|
||||||
|
});
|
||||||
|
|
||||||
doc.addDocumentChangeListener(new DocumentChangeListener() {
|
doc.addDocumentChangeListener(new DocumentChangeListener() {
|
||||||
@Override
|
@Override
|
||||||
@ -150,14 +153,16 @@ public class PhotoPanel extends JPanel implements GLEventListener {
|
|||||||
|
|
||||||
final GLCapabilities caps = new GLCapabilities(glp);
|
final GLCapabilities caps = new GLCapabilities(glp);
|
||||||
|
|
||||||
if (Application.getPreferences().getBoolean(Preferences.OPENGL_ENABLE_AA, true)) {
|
if (Application.getPreferences().getBoolean(
|
||||||
|
Preferences.OPENGL_ENABLE_AA, true)) {
|
||||||
caps.setSampleBuffers(true);
|
caps.setSampleBuffers(true);
|
||||||
caps.setNumSamples(6);
|
caps.setNumSamples(6);
|
||||||
} else {
|
} else {
|
||||||
log.trace("GL - Not enabling AA by user pref");
|
log.trace("GL - Not enabling AA by user pref");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Application.getPreferences().getBoolean(Preferences.OPENGL_USE_FBO, false)) {
|
if (Application.getPreferences().getBoolean(
|
||||||
|
Preferences.OPENGL_USE_FBO, false)) {
|
||||||
log.trace("GL - Creating GLJPanel");
|
log.trace("GL - Creating GLJPanel");
|
||||||
canvas = new GLJPanel(caps);
|
canvas = new GLJPanel(caps);
|
||||||
} else {
|
} else {
|
||||||
@ -170,7 +175,8 @@ public class PhotoPanel extends JPanel implements GLEventListener {
|
|||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
log.error("An error occurred creating 3d View", t);
|
log.error("An error occurred creating 3d View", t);
|
||||||
canvas = null;
|
canvas = null;
|
||||||
this.add(new JLabel("Unable to load 3d Libraries: " + t.getMessage()));
|
this.add(new JLabel("Unable to load 3d Libraries: "
|
||||||
|
+ t.getMessage()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -189,7 +195,8 @@ public class PhotoPanel extends JPanel implements GLEventListener {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void mouseWheelMoved(MouseWheelEvent e) {
|
public void mouseWheelMoved(MouseWheelEvent e) {
|
||||||
p.setViewDistance(p.getViewDistance() + 0.1 * e.getWheelRotation());
|
p.setViewDistance(p.getViewDistance() + 0.1
|
||||||
|
* e.getWheelRotation());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -206,7 +213,8 @@ public class PhotoPanel extends JPanel implements GLEventListener {
|
|||||||
final double x2 = (width - 2 * e.getX()) / width;
|
final double x2 = (width - 2 * e.getX()) / width;
|
||||||
final double y2 = (2 * e.getY() - height) / height;
|
final double y2 = (2 * e.getY() - height) / height;
|
||||||
|
|
||||||
p.setViewAltAz(p.getViewAlt() - (y1 - y2), p.getViewAz() + (x1 - x2));
|
p.setViewAltAz(p.getViewAlt() - (y1 - y2), p.getViewAz()
|
||||||
|
+ (x1 - x2));
|
||||||
|
|
||||||
lastX = e.getX();
|
lastX = e.getX();
|
||||||
lastY = e.getY();
|
lastY = e.getY();
|
||||||
@ -219,12 +227,23 @@ public class PhotoPanel extends JPanel implements GLEventListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void repaint() {
|
public void paintImmediately(Rectangle r) {
|
||||||
|
super.paintImmediately(r);
|
||||||
if (canvas != null)
|
if (canvas != null)
|
||||||
((GLAutoDrawable) canvas).display();
|
((GLAutoDrawable) canvas).display();
|
||||||
super.repaint();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void paintImmediately(int x, int y, int w, int h) {
|
||||||
|
super.paintImmediately(x, y, w, h);
|
||||||
|
if (canvas != null)
|
||||||
|
((GLAutoDrawable) canvas).display();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @Override public void repaint() { if (canvas != null) ((GLAutoDrawable)
|
||||||
|
* canvas).display(); super.repaint(); }
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void display(final GLAutoDrawable drawable) {
|
public void display(final GLAutoDrawable drawable) {
|
||||||
GL2 gl = drawable.getGL().getGL2();
|
GL2 gl = drawable.getGL().getGL2();
|
||||||
@ -253,9 +272,12 @@ public class PhotoPanel extends JPanel implements GLEventListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!imageCallbacks.isEmpty()) {
|
if (!imageCallbacks.isEmpty()) {
|
||||||
BufferedImage i = (new AWTGLReadBufferUtil(GLProfile.get(GLProfile.GL2), false)).readPixelsToBufferedImage(
|
BufferedImage i = (new AWTGLReadBufferUtil(
|
||||||
drawable.getGL(), 0, 0, drawable.getWidth(), drawable.getHeight(), true);
|
GLProfile.get(GLProfile.GL2), false))
|
||||||
final Vector<ImageCallback> cbs = new Vector<PhotoPanel.ImageCallback>(imageCallbacks);
|
.readPixelsToBufferedImage(drawable.getGL(), 0, 0,
|
||||||
|
drawable.getWidth(), drawable.getHeight(), true);
|
||||||
|
final Vector<ImageCallback> cbs = new Vector<PhotoPanel.ImageCallback>(
|
||||||
|
imageCallbacks);
|
||||||
imageCallbacks.clear();
|
imageCallbacks.clear();
|
||||||
for (ImageCallback ia : cbs) {
|
for (ImageCallback ia : cbs) {
|
||||||
try {
|
try {
|
||||||
@ -291,12 +313,21 @@ public class PhotoPanel extends JPanel implements GLEventListener {
|
|||||||
float amb = (float) p.getAmbiance();
|
float amb = (float) p.getAmbiance();
|
||||||
float dif = 1.0f - amb;
|
float dif = 1.0f - amb;
|
||||||
float spc = 1.0f;
|
float spc = 1.0f;
|
||||||
gl.glLightfv(GLLightingFunc.GL_LIGHT1, GLLightingFunc.GL_AMBIENT, new float[] { amb * color[0], amb * color[1],
|
gl.glLightfv(
|
||||||
amb * color[2], 1 }, 0);
|
GLLightingFunc.GL_LIGHT1,
|
||||||
gl.glLightfv(GLLightingFunc.GL_LIGHT1, GLLightingFunc.GL_DIFFUSE, new float[] { dif * color[0], dif * color[1],
|
GLLightingFunc.GL_AMBIENT,
|
||||||
dif * color[2], 1 }, 0);
|
new float[] { amb * color[0], amb * color[1], amb * color[2], 1 },
|
||||||
gl.glLightfv(GLLightingFunc.GL_LIGHT1, GLLightingFunc.GL_SPECULAR, new float[] { spc * color[0],
|
0);
|
||||||
spc * color[1], spc * color[2], 1 }, 0);
|
gl.glLightfv(
|
||||||
|
GLLightingFunc.GL_LIGHT1,
|
||||||
|
GLLightingFunc.GL_DIFFUSE,
|
||||||
|
new float[] { dif * color[0], dif * color[1], dif * color[2], 1 },
|
||||||
|
0);
|
||||||
|
gl.glLightfv(
|
||||||
|
GLLightingFunc.GL_LIGHT1,
|
||||||
|
GLLightingFunc.GL_SPECULAR,
|
||||||
|
new float[] { spc * color[0], spc * color[1], spc * color[2], 1 },
|
||||||
|
0);
|
||||||
|
|
||||||
convertColor(p.getSkyColor(), color);
|
convertColor(p.getSkyColor(), color);
|
||||||
gl.glClearColor(color[0], color[1], color[2], 1);
|
gl.glClearColor(color[0], color[1], color[2], 1);
|
||||||
@ -341,12 +372,16 @@ public class PhotoPanel extends JPanel implements GLEventListener {
|
|||||||
gl.glRotated(p.getViewAlt() * (180.0 / Math.PI), 1, 0, 0);
|
gl.glRotated(p.getViewAlt() * (180.0 / Math.PI), 1, 0, 0);
|
||||||
gl.glRotated(p.getViewAz() * (180.0 / Math.PI), 0, 1, 0);
|
gl.glRotated(p.getViewAz() * (180.0 / Math.PI), 0, 1, 0);
|
||||||
|
|
||||||
float[] lightPosition = new float[] { (float) Math.cos(p.getLightAlt()) * (float) Math.sin(p.getLightAz()),//
|
float[] lightPosition = new float[] {
|
||||||
|
(float) Math.cos(p.getLightAlt())
|
||||||
|
* (float) Math.sin(p.getLightAz()),//
|
||||||
(float) Math.sin(p.getLightAlt()),//
|
(float) Math.sin(p.getLightAlt()),//
|
||||||
(float) Math.cos(p.getLightAlt()) * (float) Math.cos(p.getLightAz()), //
|
(float) Math.cos(p.getLightAlt())
|
||||||
|
* (float) Math.cos(p.getLightAz()), //
|
||||||
0 };
|
0 };
|
||||||
|
|
||||||
gl.glLightfv(GLLightingFunc.GL_LIGHT1, GLLightingFunc.GL_POSITION, lightPosition, 0);
|
gl.glLightfv(GLLightingFunc.GL_LIGHT1, GLLightingFunc.GL_POSITION,
|
||||||
|
lightPosition, 0);
|
||||||
|
|
||||||
// Change to LEFT Handed coordinates
|
// Change to LEFT Handed coordinates
|
||||||
gl.glScaled(1, 1, -1);
|
gl.glScaled(1, 1, -1);
|
||||||
@ -358,20 +393,23 @@ public class PhotoPanel extends JPanel implements GLEventListener {
|
|||||||
if (p.isFlame()) {
|
if (p.isFlame()) {
|
||||||
convertColor(p.getFlameColor(), color);
|
convertColor(p.getFlameColor(), color);
|
||||||
|
|
||||||
gl.glLightfv(GLLightingFunc.GL_LIGHT2, GLLightingFunc.GL_AMBIENT, new float[] { 0, 0, 0, 1 }, 0);
|
gl.glLightfv(GLLightingFunc.GL_LIGHT2, GLLightingFunc.GL_AMBIENT,
|
||||||
gl.glLightfv(GLLightingFunc.GL_LIGHT2, GLLightingFunc.GL_DIFFUSE, new float[] { color[0], color[1],
|
new float[] { 0, 0, 0, 1 }, 0);
|
||||||
color[2], 1 }, 0);
|
gl.glLightfv(GLLightingFunc.GL_LIGHT2, GLLightingFunc.GL_DIFFUSE,
|
||||||
gl.glLightfv(GLLightingFunc.GL_LIGHT2, GLLightingFunc.GL_SPECULAR, new float[] { color[0], color[1],
|
new float[] { color[0], color[1], color[2], 1 }, 0);
|
||||||
color[2], 1 }, 0);
|
gl.glLightfv(GLLightingFunc.GL_LIGHT2, GLLightingFunc.GL_SPECULAR,
|
||||||
|
new float[] { color[0], color[1], color[2], 1 }, 0);
|
||||||
|
|
||||||
Bounds b = calculateBounds();
|
Bounds b = calculateBounds();
|
||||||
gl.glLightf(GLLightingFunc.GL_LIGHT2, GLLightingFunc.GL_QUADRATIC_ATTENUATION, 20f);
|
gl.glLightf(GLLightingFunc.GL_LIGHT2,
|
||||||
gl.glLightfv(GLLightingFunc.GL_LIGHT2, GLLightingFunc.GL_POSITION, new float[] { (float) (b.xMax + .1f), 0,
|
GLLightingFunc.GL_QUADRATIC_ATTENUATION, 20f);
|
||||||
0, 1 }, 0);
|
gl.glLightfv(GLLightingFunc.GL_LIGHT2, GLLightingFunc.GL_POSITION,
|
||||||
|
new float[] { (float) (b.xMax + .1f), 0, 0, 1 }, 0);
|
||||||
gl.glEnable(GLLightingFunc.GL_LIGHT2);
|
gl.glEnable(GLLightingFunc.GL_LIGHT2);
|
||||||
} else {
|
} else {
|
||||||
gl.glDisable(GLLightingFunc.GL_LIGHT2);
|
gl.glDisable(GLLightingFunc.GL_LIGHT2);
|
||||||
gl.glLightfv(GLLightingFunc.GL_LIGHT2, GLLightingFunc.GL_DIFFUSE, new float[] { 0, 0, 0, 1 }, 0);
|
gl.glLightfv(GLLightingFunc.GL_LIGHT2, GLLightingFunc.GL_DIFFUSE,
|
||||||
|
new float[] { 0, 0, 0, 1 }, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
rr.render(drawable, configuration, new HashSet<RocketComponent>());
|
rr.render(drawable, configuration, new HashSet<RocketComponent>());
|
||||||
@ -384,12 +422,14 @@ public class PhotoPanel extends JPanel implements GLEventListener {
|
|||||||
Motor motor = mount.getMotorConfiguration().get(motorID).getMotor();
|
Motor motor = mount.getMotorConfiguration().get(motorID).getMotor();
|
||||||
double length = motor.getLength();
|
double length = motor.getLength();
|
||||||
|
|
||||||
Coordinate[] position = ((RocketComponent) mount).toAbsolute(new Coordinate(((RocketComponent) mount)
|
Coordinate[] position = ((RocketComponent) mount)
|
||||||
.getLength() + mount.getMotorOverhang() - length));
|
.toAbsolute(new Coordinate(((RocketComponent) mount)
|
||||||
|
.getLength() + mount.getMotorOverhang() - length));
|
||||||
|
|
||||||
for (int i = 0; i < position.length; i++) {
|
for (int i = 0; i < position.length; i++) {
|
||||||
gl.glPushMatrix();
|
gl.glPushMatrix();
|
||||||
gl.glTranslated(position[i].x + motor.getLength(), position[i].y, position[i].z);
|
gl.glTranslated(position[i].x + motor.getLength(),
|
||||||
|
position[i].y, position[i].z);
|
||||||
FlameRenderer.drawExhaust(gl, p, motor);
|
FlameRenderer.drawExhaust(gl, p, motor);
|
||||||
gl.glPopMatrix();
|
gl.glPopMatrix();
|
||||||
}
|
}
|
||||||
@ -426,7 +466,8 @@ public class PhotoPanel extends JPanel implements GLEventListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void reshape(final GLAutoDrawable drawable, final int x, final int y, final int w, final int h) {
|
public void reshape(final GLAutoDrawable drawable, final int x,
|
||||||
|
final int y, final int w, final int h) {
|
||||||
log.trace("GL - reshape()");
|
log.trace("GL - reshape()");
|
||||||
ratio = (double) w / (double) h;
|
ratio = (double) w / (double) h;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user