Skip to content
Snippets Groups Projects
Commit bc860017 authored by Radek Ošlejšek's avatar Radek Ošlejšek
Browse files

Update

parent 58669b7c
No related branches found
No related tags found
No related merge requests found
...@@ -17,7 +17,7 @@ import java.awt.Cursor; ...@@ -17,7 +17,7 @@ import java.awt.Cursor;
public class Canvas extends javax.swing.JPanel { public class Canvas extends javax.swing.JPanel {
private final GLCanvas glCanvas; private final GLCanvas glCanvas;
private final SceneRenderer scene; private final SceneRenderer sceneRenderer;
private final CanvasListener listener; private final CanvasListener listener;
private final MouseRotationListener manipulator; private final MouseRotationListener manipulator;
private final RotationAnimator animator; private final RotationAnimator animator;
...@@ -42,7 +42,7 @@ public class Canvas extends javax.swing.JPanel { ...@@ -42,7 +42,7 @@ public class Canvas extends javax.swing.JPanel {
glCanvas.requestFocusInWindow(); glCanvas.requestFocusInWindow();
glCanvas.setSize(getWidth() - getInsets().left - getInsets().right, getHeight() - getInsets().top - getInsets().bottom); glCanvas.setSize(getWidth() - getInsets().left - getInsets().right, getHeight() - getInsets().top - getInsets().bottom);
scene = new SceneRenderer(); sceneRenderer = new SceneRenderer();
animator = new RotationAnimator(this); animator = new RotationAnimator(this);
...@@ -62,7 +62,7 @@ public class Canvas extends javax.swing.JPanel { ...@@ -62,7 +62,7 @@ public class Canvas extends javax.swing.JPanel {
* @return the scene * @return the scene
*/ */
public SceneRenderer getScene() { public SceneRenderer getScene() {
return scene; return sceneRenderer;
} }
/** /**
...@@ -353,7 +353,7 @@ public class Canvas extends javax.swing.JPanel { ...@@ -353,7 +353,7 @@ public class Canvas extends javax.swing.JPanel {
}//GEN-LAST:event_rightNavigationButton1MouseReleased }//GEN-LAST:event_rightNavigationButton1MouseReleased
private void resetButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_resetButtonMouseClicked private void resetButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_resetButtonMouseClicked
scene.getCamera().initLocation(); sceneRenderer.getCamera().initLocation();
glCanvas.display(); glCanvas.display();
}//GEN-LAST:event_resetButtonMouseClicked }//GEN-LAST:event_resetButtonMouseClicked
...@@ -367,15 +367,15 @@ public class Canvas extends javax.swing.JPanel { ...@@ -367,15 +367,15 @@ public class Canvas extends javax.swing.JPanel {
}//GEN-LAST:event_resetButtonMouseExited }//GEN-LAST:event_resetButtonMouseExited
private void whiteBackroundButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_whiteBackroundButtonMouseClicked private void whiteBackroundButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_whiteBackroundButtonMouseClicked
scene.setBrightBackground(); sceneRenderer.setBrightBackground();
scene.renderScene(); sceneRenderer.renderScene();
whiteBackroundButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/whiteBackroundCanvasPressed.png"))); whiteBackroundButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/whiteBackroundCanvasPressed.png")));
blackBackroundButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/blackBackroundCanvas.png"))); blackBackroundButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/blackBackroundCanvas.png")));
}//GEN-LAST:event_whiteBackroundButtonMouseClicked }//GEN-LAST:event_whiteBackroundButtonMouseClicked
private void blackBackroundButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_blackBackroundButtonMouseClicked private void blackBackroundButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_blackBackroundButtonMouseClicked
scene.setDarkBackground(); sceneRenderer.setDarkBackground();
scene.renderScene(); sceneRenderer.renderScene();
whiteBackroundButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/whiteBackroundCanvas.png"))); whiteBackroundButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/whiteBackroundCanvas.png")));
blackBackroundButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/blackBackroundCanvasPressed.png"))); blackBackroundButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/blackBackroundCanvasPressed.png")));
}//GEN-LAST:event_blackBackroundButtonMouseClicked }//GEN-LAST:event_blackBackroundButtonMouseClicked
......
...@@ -27,7 +27,7 @@ public class RotationAnimator { ...@@ -27,7 +27,7 @@ public class RotationAnimator {
NONE NONE
} }
private final Camera camera; private final Canvas canvas;
/** /**
* Frequency of the rotation or zoom animations * Frequency of the rotation or zoom animations
...@@ -59,7 +59,7 @@ public class RotationAnimator { ...@@ -59,7 +59,7 @@ public class RotationAnimator {
if (canvas == null) { if (canvas == null) {
throw new IllegalArgumentException("canvas is null"); throw new IllegalArgumentException("canvas is null");
} }
this.camera = canvas.getScene().getCamera(); this.canvas = canvas;
this.animator = new FPSAnimator(canvas.getGLCanvas(), FPS, true); this.animator = new FPSAnimator(canvas.getGLCanvas(), FPS, true);
} }
...@@ -74,6 +74,7 @@ public class RotationAnimator { ...@@ -74,6 +74,7 @@ public class RotationAnimator {
throw new UnsupportedOperationException(); // this should no happen throw new UnsupportedOperationException(); // this should no happen
} }
final Camera camera = canvas.getScene().getCamera();
animator.start(); animator.start();
timer = new Timer(); timer = new Timer();
startClickTime = System.currentTimeMillis(); startClickTime = System.currentTimeMillis();
...@@ -114,6 +115,7 @@ public class RotationAnimator { ...@@ -114,6 +115,7 @@ public class RotationAnimator {
*/ */
public void stopAnimation() { public void stopAnimation() {
timer.cancel(); timer.cancel();
final Camera camera = canvas.getScene().getCamera();
if ((System.currentTimeMillis() - startClickTime) < 500) { if ((System.currentTimeMillis() - startClickTime) < 500) {
switch (direction) { switch (direction) {
case ROTATE_RIGHT: case ROTATE_RIGHT:
......
...@@ -5,8 +5,8 @@ import cz.fidentis.analyst.mesh.core.MeshModel; ...@@ -5,8 +5,8 @@ import cz.fidentis.analyst.mesh.core.MeshModel;
import java.util.List; import java.util.List;
/** /**
* A drawable object, i.e., a mesh model with drawing information like * A drawable triangular mesh, i.e., a mesh model with drawing information like
* material, transparency, color, etc. The objects draws itself via provided scene renderer. * material, transparency, color, relative transformations in the scene etc.
* *
* @author Radek Oslejsek * @author Radek Oslejsek
*/ */
...@@ -14,6 +14,8 @@ public class DrawableMesh { ...@@ -14,6 +14,8 @@ public class DrawableMesh {
private final MeshModel model; private final MeshModel model;
// TO DO - R. Pajersky: add transformation attributes and methods
/** /**
* Constructor. * Constructor.
* *
......
...@@ -5,10 +5,34 @@ ...@@ -5,10 +5,34 @@
*/ */
package cz.fidentis.analyst.newgui.scene; package cz.fidentis.analyst.newgui.scene;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
/** /**
* * Abstract class for ...
* @author oslejsek *
* @author Radek Oslejsek
*/ */
public abstract class Scene { public abstract class Scene {
private final Set<DrawableMesh> allDrawables = new HashSet<>();
private final SceneRenderer sceneRenderer = new SceneRenderer();
public Set<DrawableMesh> getAllDrawables() {
return Collections.unmodifiableSet(allDrawables);
}
public SceneRenderer getSceneRenderer() {
return sceneRenderer;
}
/**
* Returns scene camera.
* @return scene camera
*/
public Camera getCamera() {
return sceneRenderer.getCamera();
}
} }
...@@ -5,10 +5,30 @@ ...@@ -5,10 +5,30 @@
*/ */
package cz.fidentis.analyst.newgui.scene; package cz.fidentis.analyst.newgui.scene;
import cz.fidentis.analyst.face.HumanFace;
/** /**
* *
* @author oslejsek * @author oslejsek
*/ */
public class SceneOneToOne extends Scene { public class SceneOneToOne extends Scene {
private HumanFace primaryFace;
private HumanFace secondaryFace;
public HumanFace getPrimaryFace() {
return primaryFace;
}
public void setPrimaryFace(HumanFace primaryFace) {
this.primaryFace = primaryFace;
}
public HumanFace getSecondaryFace() {
return secondaryFace;
}
public void setSecondaryFace(HumanFace secondaryFace) {
this.secondaryFace = secondaryFace;
}
} }
...@@ -8,23 +8,22 @@ import static com.jogamp.opengl.GL2GL3.GL_FILL; ...@@ -8,23 +8,22 @@ import static com.jogamp.opengl.GL2GL3.GL_FILL;
import static com.jogamp.opengl.GL2GL3.GL_LINE; import static com.jogamp.opengl.GL2GL3.GL_LINE;
import com.jogamp.opengl.glu.GLU; import com.jogamp.opengl.glu.GLU;
import cz.fidentis.analyst.mesh.core.MeshFacet; import cz.fidentis.analyst.mesh.core.MeshFacet;
import java.awt.Color;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import javax.vecmath.Point3d; import javax.vecmath.Point3d;
import javax.vecmath.Vector3d; import javax.vecmath.Vector3d;
import javax.vecmath.Vector4f;
/** /**
* An object responsible for handling {@link DrawableMesh}s included in the scene * Handles {@link DrawableMesh}s - objects to be drawn, and (re-)renders them on demand.
* (in the OpenGL context of the OpenGL canvas) and their rendering.
* *
* @author Natalia Bebjakova * @author Natalia Bebjakova
* @author Radek Oslejsek * @author Radek Oslejsek
*/ */
public class SceneRenderer { public class SceneRenderer {
private static final Vector4f BRIGHT_BACKGROUND = new Vector4f(0.9f, 0.9f, 0.9f, 0); private static final Color BRIGHT_BACKGROUND = new Color(0.9f, 0.9f, 0.9f, 0);
private static final Vector4f DARK_BACKGROUND = new Vector4f(0.25f, 0.25f, 0.25f, 0); private static final Color DARK_BACKGROUND = new Color(0.25f, 0.25f, 0.25f, 0);
private final GLU glu = new GLU(); private final GLU glu = new GLU();
private GL2 gl; private GL2 gl;
...@@ -144,6 +143,7 @@ public class SceneRenderer { ...@@ -144,6 +143,7 @@ public class SceneRenderer {
for (DrawableMesh obj: drawables) { for (DrawableMesh obj: drawables) {
for (MeshFacet facet: obj.getFacets()) { for (MeshFacet facet: obj.getFacets()) {
// TO DO - R. Pajersky: add transformation (glPushMatrix, glRotate, ...)
renderFacet(facet); renderFacet(facet);
} }
} }
...@@ -160,9 +160,16 @@ public class SceneRenderer { ...@@ -160,9 +160,16 @@ public class SceneRenderer {
*/ */
protected void clearScene() { // join with the renderScene() ??? protected void clearScene() { // join with the renderScene() ???
if (brightBackground) { if (brightBackground) {
gl.glClearColor(BRIGHT_BACKGROUND.x, BRIGHT_BACKGROUND.y, BRIGHT_BACKGROUND.z, BRIGHT_BACKGROUND.w); gl.glClearColor(
BRIGHT_BACKGROUND.getRed(),
BRIGHT_BACKGROUND.getBlue(),
BRIGHT_BACKGROUND.getGreen(),
BRIGHT_BACKGROUND.getAlpha());
} else { } else {
gl.glClearColor(DARK_BACKGROUND.x, DARK_BACKGROUND.y, DARK_BACKGROUND.z, DARK_BACKGROUND.w); gl.glClearColor(DARK_BACKGROUND.getRed(),
DARK_BACKGROUND.getBlue(),
DARK_BACKGROUND.getGreen(),
DARK_BACKGROUND.getAlpha());
} }
gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
gl.glLoadIdentity(); gl.glLoadIdentity();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment