Skip to content

Commit

Permalink
remove RenderPassPanel
Browse files Browse the repository at this point in the history
  • Loading branch information
i-make-robots committed Dec 19, 2023
1 parent 75045ee commit e417c8d
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 98 deletions.
6 changes: 0 additions & 6 deletions src/main/java/com/marginallyclever/ro3/RO3Frame.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import com.marginallyclever.ro3.node.NodeDetailView;
import com.marginallyclever.ro3.node.nodetreeview.NodeTreeView;
import com.marginallyclever.ro3.render.OpenGLPanel;
import com.marginallyclever.ro3.render.RenderPassPanel;
import com.marginallyclever.ro3.render.Viewport;
import com.marginallyclever.robotoverlord.swing.actions.AboutAction;
import org.slf4j.Logger;
Expand All @@ -31,7 +30,6 @@
public class RO3Frame extends JFrame {
private static final Logger logger = LoggerFactory.getLogger(RO3Frame.class);
private final OpenGLPanel renderPanel;
private final RenderPassPanel rpp = new RenderPassPanel();
private final LogPanel logPanel = new LogPanel();
private final List<DockingPanel> windows = new ArrayList<>();

Expand Down Expand Up @@ -206,9 +204,5 @@ private void createPanels() {
DockingPanel logView = new DockingPanel("Log");
logView.add(logPanel, BorderLayout.CENTER);
windows.add(logView);

DockingPanel renderPassesView = new DockingPanel("Render");
renderPassesView.add(rpp, BorderLayout.CENTER);
windows.add(renderPassesView);
}
}
71 changes: 0 additions & 71 deletions src/main/java/com/marginallyclever/ro3/render/RenderPassPanel.java

This file was deleted.

44 changes: 28 additions & 16 deletions src/main/java/com/marginallyclever/ro3/render/Viewport.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class Viewport extends OpenGLPanel implements GLEventListener {
private Camera camera;
private final JToolBar toolBar = new JToolBar();
private final DefaultComboBoxModel<Camera> cameraListModel = new DefaultComboBoxModel<>();
private final JPopupMenu overlayMenu = new JPopupMenu();
private final JPopupMenu renderPassMenu = new JPopupMenu();
private final List<Boolean> buttonPressed = new ArrayList<>();
private int mx, my;

Expand All @@ -47,10 +47,10 @@ private void addRenderPassSelection() {
JButton button = new JButton("Render");
toolBar.add(button);

overlayMenu.removeAll();
renderPassMenu.removeAll();

// Add an ActionListener to the JButton to show the JPopupMenu when clicked
button.addActionListener(e -> overlayMenu.show(button, button.getWidth()/2, button.getHeight()/2));
button.addActionListener(e -> renderPassMenu.show(button, button.getWidth()/2, button.getHeight()/2));

for(RenderPass renderPass : Registry.renderPasses.getList()) {
addRenderPass(renderPass);
Expand Down Expand Up @@ -86,19 +86,34 @@ private void removeRenderPass(RenderPass renderPass) {
}

private void addRenderPassInternal(RenderPass renderPass) {
JCheckBox checkBox = new JCheckBox(renderPass.getName());
checkBox.setSelected(renderPass.getActiveStatus() == RenderPass.ALWAYS);
checkBox.addActionListener(e -> {
renderPass.setActiveStatus(checkBox.isSelected() ? RenderPass.ALWAYS : RenderPass.NEVER);
JPanel panel = new JPanel(new BorderLayout());
panel.setBorder(BorderFactory.createEmptyBorder(2,2,0,2));
JButton button = new JButton();
setRenderPassButtonLabel(button, renderPass.getActiveStatus());
button.addActionListener(e -> {
renderPass.setActiveStatus((renderPass.getActiveStatus() + 1) % RenderPass.MAX_STATUS );
setRenderPassButtonLabel(button, renderPass.getActiveStatus());
});
overlayMenu.add(checkBox);
panel.add(button, BorderLayout.WEST);
JLabel label = new JLabel(renderPass.getName());
label.setBorder(BorderFactory.createEmptyBorder(0,5,0,0));
panel.add(label, BorderLayout.CENTER);
renderPassMenu.add(panel);
}

void setRenderPassButtonLabel(JButton button, int status) {
switch(status) {
case RenderPass.NEVER -> button.setText("N");
case RenderPass.SOMETIMES -> button.setText("S");
case RenderPass.ALWAYS -> button.setText("A");
}
}

private void removeRenderPassInternal(RenderPass renderPass) {
for(Component c : overlayMenu.getComponents()) {
for(Component c : renderPassMenu.getComponents()) {
if(c instanceof JCheckBox checkBox) {
if(checkBox.getText().equals(renderPass.getName())) {
overlayMenu.remove(c);
renderPassMenu.remove(c);
return;
}
}
Expand Down Expand Up @@ -133,6 +148,7 @@ public Component getListCellRendererComponent(JList<?> list, Object value, int i

cameraSelector.addItemListener(e -> {
camera = (Camera) e.getItem();
Registry.setActiveCamera(camera);
});
if(cameraListModel.getSize()>0) cameraSelector.setSelectedIndex(0);
toolBar.add(cameraSelector);
Expand Down Expand Up @@ -212,12 +228,8 @@ public void mouseDragged(MouseEvent e) {
private void panTiltCamera(int dx, int dy) {
Matrix4d local = camera.getLocal();
double [] panTiltAngles = getPanTiltFromMatrix(local);
double beforePan = (panTiltAngles[0]+360) % 360;
double beforeTilt = ((panTiltAngles[1]+90) % 360) -90;
panTiltAngles[0] = beforePan + dx;
panTiltAngles[1] = beforeTilt + dy;
panTiltAngles[1] = Math.max(0,Math.min(180,panTiltAngles[1]));
System.out.println("before= "+beforePan+","+beforeTilt+"\tafter=" + panTiltAngles[0] + "," + panTiltAngles[1] + "\tdiff="+dx+","+dy);
panTiltAngles[0] = (panTiltAngles[0] + dx+360) % 360;
panTiltAngles[1] = Math.max(0,Math.min(180,panTiltAngles[1] + dy));
Matrix3d panTilt = buildPanTiltMatrix(panTiltAngles);
Vector3d t = new Vector3d();
local.get(t);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,11 @@ public void display(GLAutoDrawable glAutoDrawable) {}

@Override
public void draw() {
Camera camera = Registry.getActiveCamera();
if(camera==null) return;

GL3 gl3 = GLContext.getCurrentGL().getGL3();
shader.use(gl3);
Camera camera = Registry.cameras.getList().get(0);
shader.setMatrix4d(gl3,"projectionMatrix",camera.getChosenProjectionMatrix(canvasWidth,canvasHeight));
shader.setMatrix4d(gl3,"viewMatrix",camera.getViewMatrix());
Vector3d cameraWorldPos = MatrixHelper.getPosition(camera.getWorld());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,13 @@ public void display(GLAutoDrawable glAutoDrawable) {}

@Override
public void draw() {
Camera camera = Registry.getActiveCamera();
if(camera==null) return;

GL3 gl3 = GLContext.getCurrentGL().getGL3();
gl3.glDisable(GL3.GL_DEPTH_TEST);
gl3.glDisable(GL3.GL_TEXTURE_2D);
shader.use(gl3);
Camera camera = Registry.cameras.getList().get(0);
shader.setMatrix4d(gl3,"projectionMatrix",camera.getChosenProjectionMatrix(canvasWidth,canvasHeight));
shader.setMatrix4d(gl3,"viewMatrix",camera.getViewMatrix());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,11 @@ public void display(GLAutoDrawable glAutoDrawable) {}

@Override
public void draw() {
Camera camera = Registry.getActiveCamera();
if(camera==null) return;

GL3 gl3 = GLContext.getCurrentGL().getGL3();
shader.use(gl3);
Camera camera = Registry.cameras.getList().get(0);
shader.setMatrix4d(gl3,"projectionMatrix",camera.getChosenProjectionMatrix(canvasWidth,canvasHeight));
shader.setMatrix4d(gl3,"viewMatrix",camera.getViewMatrix());
Vector3d cameraWorldPos = MatrixHelper.getPosition(camera.getWorld());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,11 @@ public void display(GLAutoDrawable glAutoDrawable) {}

@Override
public void draw() {
Camera camera = Registry.getActiveCamera();
if(camera==null) return;

GL3 gl3 = GLContext.getCurrentGL().getGL3();
shader.use(gl3);
Camera camera = Registry.cameras.getList().get(0);
shader.setMatrix4d(gl3,"viewMatrix",camera.getViewMatrix());
shader.setMatrix4d(gl3,"projectionMatrix",camera.getChosenProjectionMatrix(canvasWidth,canvasHeight));
Vector3d cameraWorldPos = MatrixHelper.getPosition(camera.getWorld());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,11 @@ public void display(GLAutoDrawable glAutoDrawable) {}

@Override
public void draw() {
Camera camera = Registry.getActiveCamera();
if(camera==null) return;

GL3 gl3 = GLContext.getCurrentGL().getGL3();
shader.use(gl3);
Camera camera = Registry.cameras.getList().get(0);
shader.setMatrix4d(gl3,"projectionMatrix",camera.getChosenProjectionMatrix(canvasWidth,canvasHeight));
shader.setMatrix4d(gl3,"viewMatrix",camera.getViewMatrix());
Vector3d cameraWorldPos = MatrixHelper.getPosition(camera.getWorld());
Expand Down

0 comments on commit e417c8d

Please sign in to comment.