Skip to content
Snippets Groups Projects
Commit 19f16d6a authored by Matej Lukes's avatar Matej Lukes
Browse files

gui reverted to version that is on master

parent a2a02811
No related branches found
No related tags found
No related merge requests found
<?xml version="1.0" encoding="UTF-8"?>
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_7">
<output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/test-classes" />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Maven: org.netbeans.api:org-netbeans-api-annotations-common:RELEASE82" level="project" />
<orderEntry type="module" module-name="MeshModel" />
<orderEntry type="library" name="Maven: java3d:j3d-core-utils:1.3.1" level="project" />
<orderEntry type="library" name="Maven: java3d:vecmath:1.3.1" level="project" />
<orderEntry type="library" name="Maven: java3d:j3d-core:1.3.1" level="project" />
<orderEntry type="library" name="Maven: com.github.mokiat:java-data-front:v2.0.0" level="project" />
<orderEntry type="library" name="Maven: javax.vecmath:vecmath:1.5.2" level="project" />
<orderEntry type="library" name="Maven: org.jogamp.jogl:jogl-all-mobile:2.0.2-rc12" level="project" />
<orderEntry type="library" name="Maven: org.jogamp.jogl:jogl-all:2.0-rc11" level="project" />
</component>
</module>
\ No newline at end of file
...@@ -56,22 +56,6 @@ ...@@ -56,22 +56,6 @@
<artifactId>org-netbeans-api-annotations-common</artifactId> <artifactId>org-netbeans-api-annotations-common</artifactId>
<version>${netbeans.version}</version> <version>${netbeans.version}</version>
</dependency> </dependency>
<dependency>
<groupId>cz.findetis</groupId>
<artifactId>MeshModel</artifactId>
<version>2.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.jogamp.jogl</groupId>
<artifactId>jogl-all-mobile</artifactId>
<version>2.0.2-rc12</version>
</dependency>
<dependency>
<groupId>org.jogamp.jogl</groupId>
<artifactId>jogl-all</artifactId>
<version>2.0-rc11</version>
</dependency>
</dependencies> </dependencies>
<properties> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
......
This diff is collapsed.
package cz.fidentis.analyst.gui;
import cz.fidentis.analyst.mesh.core.MeshFacet;
import cz.fidentis.analyst.mesh.core.MeshModel;
import java.util.ArrayList;
import javax.media.opengl.GL;
import static javax.media.opengl.GL.GL_DEPTH_TEST;
import static javax.media.opengl.GL.GL_FRONT_AND_BACK;
import static javax.media.opengl.GL.GL_VIEWPORT;
import javax.media.opengl.GL2;
import static javax.media.opengl.GL2GL3.GL_FILL;
import static javax.media.opengl.GL2GL3.GL_LINE;
import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.GLEventListener;
import static javax.media.opengl.fixedfunc.GLMatrixFunc.GL_MODELVIEW_MATRIX;
import static javax.media.opengl.fixedfunc.GLMatrixFunc.GL_PROJECTION_MATRIX;
import javax.media.opengl.glu.GLU;
import javax.vecmath.Vector3d;
import javax.vecmath.Vector3f;
/**
*
* @author Natalia Bebjakova
*/
public class GeneralGLEventListener implements GLEventListener {
/**
* Color behind the model is black
*/
protected static float[] backgroundColor = {0.8f, 0.8f, 0.8f, 0.0f};
/**
* array of models that are displayed (just one so far)
*/
private ArrayList<MeshModel> models = new ArrayList<>();
/**
* GLCanvas which listener belongs to
*/
protected Canvas glCanvas;
/**
* GLU object.
*/
protected GLU glu;
protected GL2 gl;
/**
* The last viewport.
*/
protected int[] viewport = new int[4];
/**
* The last model matrix.
*/
protected float[] modelViewMatrix = new float[16];
/**
* The last projection matrix.
*/
protected float[] projectionMatrix = new float[16];
/**
* The X coordinate of the last known mouse position during the scene rotation.
*/
int mouseX = 0;
/**
* The Y coordinate of the last know mouse position during the scene rotation.
*/
int mouseY = 0;
protected Vector3f defaultPosition = new Vector3f(0, 0, 300);
protected Vector3f currentPosition = new Vector3f(0, 0, 300);
protected double zCenter = 0;
protected double xCenter = 0;
protected double yCenter = 0;
protected double zCameraPosition;
protected double xCameraPosition;
protected double yCameraPosition;
protected double zUpPosition = 0;
protected double xUpPosition = 0;
protected double yUpPosition = 1;
/**
* Decides if model is diplayed as wire-frame
*/
protected boolean wireModel = false;
/**
* Decides if model is diplayed with textures
*/
protected boolean drawTextures = false;
/**
* Creates new EventListener
* @param canvas GLCanvas which listener belongs to
*/
public GeneralGLEventListener(Canvas canvas) {
this.glCanvas = canvas;
}
/**
* Invoked when main frame is created
* @param glad Glad object
*/
@Override
public void init(GLAutoDrawable glad) {
this.gl = (GL2) glad.getGL();
glu = new GLU();
gl.setSwapInterval(1);
gl.glEnable(GL2.GL_LIGHTING);
gl.glEnable(GL2.GL_LIGHT0);
gl.glEnable(GL2.GL_DEPTH_TEST);
gl.glClearColor(0,0,0,0); // background for GLCanvas
gl.glClear(GL2.GL_COLOR_BUFFER_BIT);
gl.glShadeModel(GL2.GL_SMOOTH); // use smooth shading
gl.glDepthFunc(GL2.GL_LESS);
gl.glDepthRange(0.0, 1.0);
gl.glEnable(GL_DEPTH_TEST);
gl.glEnable(GL2.GL_NORMALIZE);
gl.glDisable(GL2.GL_CULL_FACE);
}
/**
* Invoked when main frame is closed
* @param glad Glad object
*/
@Override
public void dispose(GLAutoDrawable glad) {
}
/**
* Invoked every frame.
* @param glad Glad object
*/
@Override
public void display(GLAutoDrawable glad) {
wireModel = glCanvas.getDrawWired(); // is wire-frame or not
gl.glClearColor(0,0,0,0); // background for GLCanvas
gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
gl.glLoadIdentity();
// sets model to proper position
glu.gluLookAt(xCameraPosition, yCameraPosition, zCameraPosition, xCenter, yCenter, zCenter, xUpPosition, yUpPosition, zUpPosition);
gl.glShadeModel(GL2.GL_SMOOTH);
gl.glGetIntegerv(GL_VIEWPORT, viewport, 0);
gl.glGetFloatv(GL_MODELVIEW_MATRIX, modelViewMatrix, 0);
gl.glGetFloatv(GL_PROJECTION_MATRIX, projectionMatrix, 0);
//if there is any model, draw
if (models.get(0) != null) {
if (wireModel) {
gl.glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
drawWithoutTextures(models.get(0));
} else {
gl.glPolygonMode( GL_FRONT_AND_BACK, GL_FILL);
drawWithoutTextures(models.get(0));
}
}
gl.glPopMatrix();
gl.glFlush();
/*if (drawTextures) {
gl.glCallList(modelDL);
} else {
gl.glCallList(modelDLwithoutTxt);
}*/
}
public void drawWithoutTextures(MeshModel model) {
for (int i = 0; i < model.getFacets().size(); i++) {
renderFacet(model.getFacets().get(i));
}
}
private void renderFacet(MeshFacet facet) {
gl.glBegin(GL2.GL_TRIANGLES); //vertices are rendered as triangles
// get the normal and tex coords indicies for face i
for (int v = 0; v < facet.getCornerTable().getSize(); v++) {
Vector3d norm = facet.getVertices().get(facet.getCornerTable().getRow(v).getVertexIndex()).getNormal(); // render the normals
gl.glNormal3d(norm.getX(), norm.getY(), norm.getZ());
Vector3d vert = facet.getVertices().get(facet.getCornerTable().getRow(v).getVertexIndex()).getPosition(); // render the vertices
gl.glVertex3d(vert.getX(), vert.getY(), vert.getZ());
}
gl.glEnd();
}
/**
* Prepared for future textures
*/
/*public void reloadTextures() {
for (int i = 0; i < models.size(); i++) {
if (models.get(i) != null) {
if (models.get(i).getMatrials() != null) {
for (int j = 0; j < models.get(i).getMatrials().getMatrials().size(); j++) {
models.get(i).getMatrials().reloadTextures(gl);
}
}
}
}
}*/
/**
*
* @param glad Glad object
* @param x x
* @param y y
* @param width New width
* @param height New Height
*/
@Override
public void reshape(GLAutoDrawable glad, int x, int y, int width, int height) {
if (height == 0) {
height = 1; // to avoid division by 0 in aspect ratio below
}
gl.glViewport(x, y, width, height); // size of drawing area
float h = (float) height / (float) width;
gl.glMatrixMode(GL2.GL_PROJECTION);
gl.glLoadIdentity();
glu.gluPerspective(65, width / (float) height, 5.0f, 1500.0f);
gl.glMatrixMode(GL2.GL_MODELVIEW);
gl.glLoadIdentity();
gl.glTranslatef(0.0f, 0.0f, -40.0f);
}
/**
*
* @param model Set model to be displayed
*/
public void setModels(MeshModel model) {
models.add(0, model);
}
/**
*
* @param models Set models to be displayed
*/
public void setModels(ArrayList<MeshModel> models) {
this.models = models;
}
/**
*
* @return Returns displayed model
*/
public MeshModel getModel() {
return models.get(0);
}
/**
* Removes all models
*/
public void removeModel() {
models.clear();
}
/**
*
* @param x New x position
* @param y New y position
* @param z New z position
*/
public void setCameraPosition(float x, float y, float z) {
currentPosition.setX(x);
currentPosition.setY(y);
currentPosition.setZ(z);
setNewCameraPosition(currentPosition);
zCameraPosition = defaultPosition.getZ();
xCameraPosition = defaultPosition.getX();
yCameraPosition = defaultPosition.getY();
}
/**
*
* @param position New position of camera
*/
public void setNewCameraPosition(Vector3f position) {
xCameraPosition = position.getX();
yCameraPosition = position.getY();
zCameraPosition = position.getZ();
}
/**
*
* @param degree degree of rotation
*/
public void rotateUp(double degree) {
rotate(-degree, 0);
}
/**
*
* @param degree degree of rotation
*/
public void rotateDown(double degree) {
rotate(degree, 0);
}
/**
*
* @param degree degree of rotation
*/
public void rotateLeft(double degree) {
rotate(0, degree);
}
/**
*
* @param degree degree of rotation
*/
public void rotateRight(double degree) {
rotate(0, -degree);
}
private Vector3f getXaxis() {
Vector3f xAxis = new Vector3f((float) ((yCameraPosition - yCenter) * zUpPosition - (zCameraPosition - zCenter) * yUpPosition),
(float) ((zCameraPosition - zCenter) * xUpPosition - (xCameraPosition - xCenter) * zUpPosition),
(float) ((xCameraPosition - xCenter) * yUpPosition - xUpPosition * (yCameraPosition - yCenter)));
float length = (float) Math.sqrt(xAxis.getX() * xAxis.getX() + xAxis.getY() * xAxis.getY() + xAxis.getZ() * xAxis.getZ());
xAxis.setX(xAxis.getX() / length);
xAxis.setY(xAxis.getY() / length);
xAxis.setZ(xAxis.getZ() / length);
return xAxis;
}
private Vector3f getYaxis() {
Vector3f yAxis = new Vector3f((float) xUpPosition, (float) yUpPosition, (float) zUpPosition);
float length = (float) Math.sqrt(yAxis.getX() * yAxis.getX() + yAxis.getY() * yAxis.getY() + yAxis.getZ() * yAxis.getZ());
yAxis.setX(yAxis.getX() / length);
yAxis.setY(yAxis.getY() / length);
yAxis.setZ(yAxis.getZ() / length);
return yAxis;
}
/**
* Rotates object around axes that apear as horizontal and vertical axe on
* screen (paralel to the sceen edges), intersecting at the center of
* screen( i.e head center).
*
* @param xAngle angle around vertical axe on screen
* @param yAngle angle around horizontal axe on screen
*/
public void rotate(double xAngle, double yAngle) {
Vector3f xAxis = getXaxis();
Vector3f yAxis = getYaxis();
Vector3f point = new Vector3f((float) xCameraPosition, (float) yCameraPosition, (float) zCameraPosition);
Vector3f camera = rotateAroundAxe(point, xAxis, Math.toRadians(xAngle));
camera = rotateAroundAxe(camera, yAxis, Math.toRadians(yAngle));
point = new Vector3f((float) xUpPosition, (float) yUpPosition, (float) zUpPosition);
Vector3f up = rotateAroundAxe(point, xAxis, Math.toRadians(xAngle));
up = rotateAroundAxe(up, yAxis, Math.toRadians(yAngle));
xUpPosition = up.getX();
yUpPosition = up.getY();
zUpPosition = up.getZ();
setNewCameraPosition(camera);
}
public void move(double xShift, double yShift) {
Vector3f xAxis = getXaxis();
Vector3f yAxis = getYaxis();
Vector3f shift = new Vector3f((float) (xAxis.x * xShift + yAxis.x * yShift), (float) (xAxis.y * xShift + yAxis.y * yShift), (float) (xAxis.z * xShift + yAxis.z * yShift));
Vector3f camera = new Vector3f((float) xCameraPosition + shift.x, (float) yCameraPosition + shift.y, (float) zCameraPosition + shift.z);
xCenter += shift.x;
yCenter += shift.y;
zCenter += shift.z;
setNewCameraPosition(camera);
}
/**
* Calculate the new position f point from given angle and rotation axe.
*
* @param point original position
* @param u vector of rotation axe
* @param angle angle of rotation
* @return new position
*/
public Vector3f rotateAroundAxe(Vector3f point, Vector3f u, double angle) {
Vector3f p;
float x = (float) ((Math.cos(angle) + u.getX() * u.getX() * (1 - Math.cos(angle))) * point.getX()
+ (u.getX() * u.getY() * (1 - Math.cos(angle)) - u.getZ() * Math.sin(angle)) * point.getY()
+ (u.getX() * u.getZ() * (1 - Math.cos(angle)) + u.getY() * Math.sin(angle)) * point.getZ());
float y = (float) ((u.getX() * u.getY() * (1 - Math.cos(angle)) + u.getZ() * Math.sin(angle)) * point.getX()
+ (Math.cos(angle) + u.getY() * u.getY() * (1 - Math.cos(angle))) * point.getY()
+ (u.getY() * u.getZ() * (1 - Math.cos(angle)) - u.getX() * Math.sin(angle)) * point.getZ());
float z = (float) ((u.getX() * u.getZ() * (1 - Math.cos(angle)) - u.getY() * Math.sin(angle)) * point.getX()
+ (u.getY() * u.getZ() * (1 - Math.cos(angle)) + u.getX() * Math.sin(angle)) * point.getY()
+ (Math.cos(angle) + u.getZ() * u.getZ() * (1 - Math.cos(angle))) * point.getZ());
p = new Vector3f(x, y, z);
return p;
}
/**
* Sets model to the starting position
*/
public void rotationAndSizeRestart() {
xUpPosition = 0;
yUpPosition = 1;
zUpPosition = 0;
setNewCameraPosition(defaultPosition);
xCenter = 0;
yCenter = 0;
zCenter = 0;
}
/**
*
* @param distance Distance to be zoom in
*/
public void zoomIn(double distance) {
double x = xCameraPosition - xCenter;
double y = yCameraPosition - yCenter;
double z = zCameraPosition - zCenter;
double sqrt = Math.sqrt(x * x + y * y + z * z);
if (sqrt > 0) {
xCameraPosition = xCenter + ((sqrt - distance) * x / sqrt);
yCameraPosition = yCenter + ((sqrt - distance) * y / sqrt);
zCameraPosition = zCenter + ((sqrt - distance) * z / sqrt);
}
}
/**
*
* @param distance Distance to be zoom out
*/
public void zoomOut(double distance) {
double x = xCameraPosition - xCenter;
double y = yCameraPosition - yCenter;
double z = zCameraPosition - zCenter;
double sqrt = Math.sqrt(x * x + y * y + z * z);
if (sqrt == 0) {
sqrt = 1;
}
xCameraPosition = xCenter + ((sqrt + distance) * x / sqrt);
yCameraPosition = yCenter + ((sqrt + distance) * y / sqrt);
zCameraPosition = zCenter + ((sqrt + distance) * z / sqrt);
}
/**
*
* @return Returns backround color of the listener
*/
public static float[] getBackgroundColor() {
return backgroundColor;
}
/**
*
* @param backgroundColor backround color of the listener
*/
public static void setBackgroundColor(float[] backgroundColor) {
GeneralGLEventListener.backgroundColor = backgroundColor;
}
/**
*
* @param drawWire Decides if model is displayed as wire-frame
*/
public void setWireMode(boolean drawWire) {
wireModel = drawWire;
}
/**
*
* @param drawTextures Decides if model is displayed with textures
*/
public void setDrawTextures(boolean drawTextures) {
this.drawTextures = drawTextures;
}
}
This diff is collapsed.
package cz.fidentis.analyst.gui;
import java.io.File;
import javax.swing.filechooser.FileFilter;
/**
*
* @author Natalia Bebjakova
*/
public class ModelFileFilter extends FileFilter {
private String[] extension;
private String description;
public ModelFileFilter(String[] extension, String description)
{
this.extension = extension;
this.description = description;
}
@Override
public boolean accept(File f)
{
boolean accepted = false;
for (int i=0; i<extension.length;i++) {
if(f.isDirectory() || f.getName().endsWith(extension[i])) {
accepted = true;
}
}
return accepted;
}
/*
* @see javax.swing.filechooser.FileFilter
*/
@Override
public String getDescription() {
return description;
}
}
\ No newline at end of file
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