Skip to content

Commit

Permalink
added DrawGroundPlane
Browse files Browse the repository at this point in the history
  • Loading branch information
i-make-robots committed Dec 23, 2023
1 parent 4518a1e commit 89e8bb7
Show file tree
Hide file tree
Showing 12 changed files with 189 additions and 275 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.marginallyclever</groupId>
<artifactId>RobotOverlord</artifactId>
<version>2.90.0</version>
<version>2.92.0</version>
<name>Robot Overlord</name>
<description>A friendly 3D user interface for controlling robots.</description>
<url>http://www.marginallyclever.com/</url>
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/marginallyclever/ro3/Registry.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public static void start() {
pose.add("Camera", Camera::new);

renderPasses.add(new DrawBackground());
renderPasses.add(new DrawGroundPlane());
renderPasses.add(new DrawMeshes());
renderPasses.add(new DrawBoundingBoxes());
renderPasses.add(new DrawCameras());
Expand Down
44 changes: 1 addition & 43 deletions src/main/java/com/marginallyclever/ro3/render/OpenGLPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,16 @@
import org.slf4j.LoggerFactory;

import java.awt.event.*;
import java.util.List;
import java.util.ArrayList;
import javax.swing.*;
import java.awt.*;

/**
* {@link OpenGLPanel} is a {@link DockingPanel} that contains a {@link GLJPanel} and an {@link FPSAnimator}.
*/
public class OpenGLPanel extends JPanel implements GLEventListener, MouseListener, MouseMotionListener, MouseWheelListener, KeyListener {
public class OpenGLPanel extends JPanel implements GLEventListener, MouseListener, MouseMotionListener, MouseWheelListener {
private static final Logger logger = LoggerFactory.getLogger(OpenGLPanel.class);
protected GLJPanel glCanvas;
protected int canvasWidth, canvasHeight;
private final FPSAnimator animator = new FPSAnimator(GraphicsPreferences.framesPerSecond.get());
private final List<GLEventListener> listeners = new ArrayList<>();

public OpenGLPanel() {
super(new BorderLayout());
Expand All @@ -48,7 +44,6 @@ public void addNotify() {
glCanvas.addMouseListener(this);
glCanvas.addMouseMotionListener(this);
glCanvas.addMouseWheelListener(this);
glCanvas.addKeyListener(this);
}

@Override
Expand All @@ -58,7 +53,6 @@ public void removeNotify() {
glCanvas.removeMouseListener(this);
glCanvas.removeMouseMotionListener(this);
glCanvas.removeMouseWheelListener(this);
glCanvas.removeKeyListener(this);
}

private GLCapabilities getCapabilities() {
Expand All @@ -80,21 +74,11 @@ private GLCapabilities getCapabilities() {
}

public void addGLEventListener(GLEventListener listener) {
listeners.add(listener);
glCanvas.addGLEventListener(listener);
}

public void removeGLEventListener(GLEventListener listener) {
glCanvas.removeGLEventListener(listener);
listeners.remove(listener);
}

public int getGLEventListenersCount() {
return listeners.size();
}

public GLEventListener getGLEventListener(int index) {
return listeners.get(index);
}

public void stopAnimationSystem() {
Expand Down Expand Up @@ -131,15 +115,12 @@ public void init(GLAutoDrawable glAutoDrawable) {
@Override
public void dispose(GLAutoDrawable glAutoDrawable) {
logger.info("dispose");
GL3 gl3 = glAutoDrawable.getGL().getGL3();
Registry.textureFactory.unloadAll();
}

@Override
public void reshape(GLAutoDrawable glAutoDrawable, int x, int y, int width, int height) {
//logger.debug("reshape {}x{}",width,height);
canvasWidth = width;
canvasHeight = height;
}

@Override
Expand Down Expand Up @@ -168,27 +149,4 @@ public void mouseMoved(MouseEvent e) {}

@Override
public void mouseWheelMoved(MouseWheelEvent e) {}

public int getCanvasHeight() {
return canvasHeight;
}

public int getCanvasWidth() {
return canvasWidth;
}

@Override
public void keyTyped(KeyEvent e) {
System.out.println("keyTyped "+e);
}

@Override
public void keyPressed(KeyEvent e) {
System.out.println("keyPressed "+e);
}

@Override
public void keyReleased(KeyEvent e) {
System.out.println("keyReleased "+e);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package com.marginallyclever.ro3.render.renderpasses;

import com.jogamp.opengl.GLAutoDrawable;
import com.marginallyclever.ro3.render.RenderPass;

/**
* {@link AbstractRenderPass} handles common methods for all {@link RenderPass}.
*/
public abstract class AbstractRenderPass implements RenderPass {
private String name;
private int activeStatus = ALWAYS;
protected int canvasWidth, canvasHeight;

protected AbstractRenderPass() {}

protected AbstractRenderPass(String name) {
this();
this.name = name;
}

public void setName(String name) {
this.name = name;
}

/**
* @return the localized name of this pass.
*/
@Override
public String getName() {
return name;
}

/**
* @return NEVER, SOMETIMES, or ALWAYS
*/
@Override
public int getActiveStatus() {
return activeStatus;
}

/**
* @param status NEVER, SOMETIMES, or ALWAYS
*/
@Override
public void setActiveStatus(int status) {
activeStatus = status;
}

@Override
public void draw() {

}

@Override
public void init(GLAutoDrawable glAutoDrawable) {

}

@Override
public void dispose(GLAutoDrawable glAutoDrawable) {

}

@Override
public void display(GLAutoDrawable glAutoDrawable) {

}

@Override
public void reshape(GLAutoDrawable glAutoDrawable, int x, int y, int width, int height) {
canvasWidth = width;
canvasHeight = height;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,16 @@
* <p>Draw the background. This may be a skybox or a solid color.</p>
* <p>TODO <a href="https://antongerdelan.net/opengl/cubemaps.html">use the OpenGL cube map texture</a>?</p>
*/
public class DrawBackground implements RenderPass {
public class DrawBackground extends AbstractRenderPass {
private static final Logger logger = LoggerFactory.getLogger(DrawBackground.class);
private int activeStatus = ALWAYS;
private final ColorRGB eraseColor = new ColorRGB(64,64,128);
private ShaderProgram shader;
private final Mesh mesh = new Mesh();
private final TextureWithMetadata texture;
private int canvasWidth, canvasHeight;

public DrawBackground() {
super("Erase/Background");

// build a box
mesh.setRenderStyle(GL3.GL_QUADS);

Expand Down Expand Up @@ -83,22 +83,6 @@ public DrawBackground() {
texture.setDoNotExport(true);
}

/**
* @return NEVER, SOMETIMES, or ALWAYS
*/
@Override
public int getActiveStatus() {
return activeStatus;
}

/**
* @param status NEVER, SOMETIMES, or ALWAYS
*/
@Override
public void setActiveStatus(int status) {
activeStatus = status;
}

/**
* @return the localized name of this overlay
*/
Expand Down Expand Up @@ -126,15 +110,6 @@ public void dispose(GLAutoDrawable glAutoDrawable) {
shader.delete(gl3);
}

@Override
public void reshape(GLAutoDrawable glAutoDrawable, int x, int y, int width, int height) {
canvasWidth = width;
canvasHeight = height;
}

@Override
public void display(GLAutoDrawable glAutoDrawable) {}

@Override
public void draw() {
GL3 gl3 = GLContext.getCurrentGL().getGL3();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@
/**
* Draw the bounding box of each {@link MeshInstance} in the scene.
*/
public class DrawBoundingBoxes implements RenderPass {
public class DrawBoundingBoxes extends AbstractRenderPass {
private static final Logger logger = LoggerFactory.getLogger(DrawBoundingBoxes.class);
private int activeStatus = ALWAYS;
private ShaderProgram shader;
private final Mesh mesh = new Mesh();
private int canvasWidth, canvasHeight;

public DrawBoundingBoxes() {
super("Bounding Boxes");

mesh.setRenderStyle(GL3.GL_LINES);
// add 8 points of a unit cube centered on the origin
mesh.addVertex(-0.5f, 0.5f, 0.5f);
Expand Down Expand Up @@ -65,30 +65,6 @@ public DrawBoundingBoxes() {
mesh.addIndex(3); mesh.addIndex(7);
}

/**
* @return NEVER, SOMETIMES, or ALWAYS
*/
@Override
public int getActiveStatus() {
return activeStatus;
}

/**
* @param status NEVER, SOMETIMES, or ALWAYS
*/
@Override
public void setActiveStatus(int status) {
activeStatus = status;
}

/**
* @return the localized name of this overlay
*/
@Override
public String getName() {
return "Bounding Boxes";
}

@Override
public void init(GLAutoDrawable glAutoDrawable) {
GL3 gl3 = glAutoDrawable.getGL().getGL3();
Expand All @@ -108,15 +84,6 @@ public void dispose(GLAutoDrawable glAutoDrawable) {
shader.delete(gl3);
}

@Override
public void reshape(GLAutoDrawable glAutoDrawable, int x, int y, int width, int height) {
canvasWidth = width;
canvasHeight = height;
}

@Override
public void display(GLAutoDrawable glAutoDrawable) {}

@Override
public void draw() {
Camera camera = Registry.getActiveCamera();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@
/**
* Draws each {@link Camera} as a pyramid approximating the perspective view frustum.
*/
public class DrawCameras implements RenderPass {
public class DrawCameras extends AbstractRenderPass {
private static final Logger logger = LoggerFactory.getLogger(DrawCameras.class);
private int activeStatus = ALWAYS;
private final Mesh mesh = new Mesh();
private ShaderProgram shader;
private int canvasWidth,canvasHeight;

public DrawCameras() {
super("Cameras");

// add mesh to a list that can be unloaded and reloaded as needed.
mesh.setRenderStyle(GL3.GL_LINES);
Vector3d a = new Vector3d(-1,-1,-1);
Expand All @@ -47,30 +47,6 @@ public DrawCameras() {
mesh.addColor(0,0,0,1); mesh.addVertex((float)a.x, (float)a.y, (float)a.z);
}

/**
* @return NEVER, SOMETIMES, or ALWAYS
*/
@Override
public int getActiveStatus() {
return activeStatus;
}

/**
* @param status NEVER, SOMETIMES, or ALWAYS
*/
@Override
public void setActiveStatus(int status) {
activeStatus = status;
}

/**
* @return the localized name of this overlay
*/
@Override
public String getName() {
return "Cameras";
}

@Override
public void init(GLAutoDrawable glAutoDrawable) {
GL3 gl3 = glAutoDrawable.getGL().getGL3();
Expand All @@ -90,15 +66,6 @@ public void dispose(GLAutoDrawable glAutoDrawable) {
shader.delete(gl3);
}

@Override
public void reshape(GLAutoDrawable glAutoDrawable, int x, int y, int width, int height) {
canvasWidth = width;
canvasHeight = height;
}

@Override
public void display(GLAutoDrawable glAutoDrawable) {}

@Override
public void draw() {
Camera camera = Registry.getActiveCamera();
Expand Down
Loading

0 comments on commit 89e8bb7

Please sign in to comment.