From 332dd8550a2301427dd942d2a77cb59ebd3ec92e Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Tue, 31 Dec 2019 18:23:02 +0100 Subject: Enable compilation using JogAmp 2.4.0 (one demo needs vecmath, dependency issue) --- src/net/java/joglutils/model/ModelFactory.java | 1 + .../java/joglutils/model/ResourceRetriever.java | 2 +- .../model/examples/DisplayListRenderer.java | 351 +++++++++++---------- .../java/joglutils/model/examples/ModelTest.java | 252 ++++++++------- src/net/java/joglutils/model/geometry/Mesh.java | 2 - src/net/java/joglutils/model/loader/MaxLoader.java | 1 + .../joglutils/model/loader/WaveFrontLoader.java | 1 + 7 files changed, 314 insertions(+), 296 deletions(-) (limited to 'src/net/java/joglutils/model') diff --git a/src/net/java/joglutils/model/ModelFactory.java b/src/net/java/joglutils/model/ModelFactory.java index 778f319..c1e2645 100644 --- a/src/net/java/joglutils/model/ModelFactory.java +++ b/src/net/java/joglutils/model/ModelFactory.java @@ -11,6 +11,7 @@ package net.java.joglutils.model; import java.util.HashMap; + import net.java.joglutils.model.geometry.Model; import net.java.joglutils.model.loader.LoaderFactory; diff --git a/src/net/java/joglutils/model/ResourceRetriever.java b/src/net/java/joglutils/model/ResourceRetriever.java index 3b81190..566ed9c 100644 --- a/src/net/java/joglutils/model/ResourceRetriever.java +++ b/src/net/java/joglutils/model/ResourceRetriever.java @@ -3,8 +3,8 @@ package net.java.joglutils.model; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; -import java.net.URL; import java.net.MalformedURLException; +import java.net.URL; /** * Utility class that allows transparent reading of files from the current diff --git a/src/net/java/joglutils/model/examples/DisplayListRenderer.java b/src/net/java/joglutils/model/examples/DisplayListRenderer.java index 4989356..4f3c63f 100644 --- a/src/net/java/joglutils/model/examples/DisplayListRenderer.java +++ b/src/net/java/joglutils/model/examples/DisplayListRenderer.java @@ -9,164 +9,173 @@ package net.java.joglutils.model.examples; -import net.java.joglutils.model.*; -import com.sun.opengl.util.texture.*; -import com.sun.opengl.util.texture.awt.*; import java.awt.image.BufferedImage; import java.io.IOException; import java.net.URL; import java.util.HashMap; + import javax.imageio.ImageIO; -import javax.media.opengl.*; + +import com.jogamp.opengl.GL; +import com.jogamp.opengl.GL2; +import com.jogamp.opengl.GL2GL3; +import com.jogamp.opengl.GLAutoDrawable; +import com.jogamp.opengl.GLProfile; +import com.jogamp.opengl.fixedfunc.GLLightingFunc; +import com.jogamp.opengl.fixedfunc.GLMatrixFunc; +import com.jogamp.opengl.util.texture.Texture; +import com.jogamp.opengl.util.texture.TextureCoords; +import com.jogamp.opengl.util.texture.awt.AWTTextureIO; + import net.java.joglutils.model.ResourceRetriever; +import net.java.joglutils.model.iModel3DRenderer; import net.java.joglutils.model.geometry.Bounds; import net.java.joglutils.model.geometry.Material; import net.java.joglutils.model.geometry.Mesh; import net.java.joglutils.model.geometry.Model; import net.java.joglutils.model.geometry.Vec4; -import net.java.joglutils.model.iModel3DRenderer; /** * * @author RodgersGB - * + * * modifications made by Brian Wood and Z-Knight */ public class DisplayListRenderer implements iModel3DRenderer { private static DisplayListRenderer instance = new DisplayListRenderer(); - private DisplayListCache listCache = new DisplayListCache(); + private final DisplayListCache listCache = new DisplayListCache(); private HashMap texture; private int modelBoundsList = -1; private int objectBoundsList = 1; private boolean isDebugging = true; - + /** Creates a new instance of DisplayListModel3D */ public DisplayListRenderer() { } - + public static DisplayListRenderer getInstance() { return instance; } - public void debug(boolean value) { + public void debug(final boolean value) { this.isDebugging = value; } - - public void render(Object context, Model model) + + public void render(final Object context, final Model model) { GL2 gl = null; - + if (context instanceof GL2) gl = (GL2) context; - + else if (context instanceof GLAutoDrawable) gl = ((GLAutoDrawable) context).getGL().getGL2(); - + if (gl == null) { return; } - + if (model == null) { return; } - + int displayList = listCache.get(model); - + if(displayList < 0) { displayList = initialize(gl, model); if (this.isDebugging) System.out.println("Initialized the display list for model: " + model.getSource()); } - + // save some current state variables - boolean isTextureEnabled = gl.glIsEnabled(GL2.GL_TEXTURE_2D); - boolean isLightingEnabled = gl.glIsEnabled(GL2.GL_LIGHTING); - boolean isMaterialEnabled = gl.glIsEnabled(GL2.GL_COLOR_MATERIAL); - + final boolean isTextureEnabled = gl.glIsEnabled(GL.GL_TEXTURE_2D); + final boolean isLightingEnabled = gl.glIsEnabled(GLLightingFunc.GL_LIGHTING); + final boolean isMaterialEnabled = gl.glIsEnabled(GLLightingFunc.GL_COLOR_MATERIAL); + // check lighting - if (!model.isUsingLighting()) { gl.glDisable(GL2.GL_LIGHTING); } - + if (!model.isUsingLighting()) { gl.glDisable(GLLightingFunc.GL_LIGHTING); } + // check texture - if (model.isUsingTexture()) { gl.glEnable(GL2.GL_TEXTURE_2D); } - else { gl.glDisable(GL2.GL_TEXTURE_2D); } - + if (model.isUsingTexture()) { gl.glEnable(GL.GL_TEXTURE_2D); } + else { gl.glDisable(GL.GL_TEXTURE_2D); } + // check wireframe - if (model.isRenderingAsWireframe()) { gl.glPolygonMode(GL2.GL_FRONT_AND_BACK, GL2.GL_LINE); } - else { gl.glPolygonMode(GL2.GL_FRONT_AND_BACK, GL2.GL_FILL); } - - gl.glDisable(GL2.GL_COLOR_MATERIAL); - + if (model.isRenderingAsWireframe()) { gl.glPolygonMode(GL.GL_FRONT_AND_BACK, GL2GL3.GL_LINE); } + else { gl.glPolygonMode(GL.GL_FRONT_AND_BACK, GL2GL3.GL_FILL); } + + gl.glDisable(GLLightingFunc.GL_COLOR_MATERIAL); + gl.glPushMatrix(); - + // check for unit size model if (model.isUnitizeSize()) { - float scale = 1.0f/model.getBounds().getRadius(); + final float scale = 1.0f/model.getBounds().getRadius(); gl.glScalef(scale, scale, scale); } - + if (model.isCentered()) { - Vec4 center = model.getCenterPoint(); + final Vec4 center = model.getCenterPoint(); gl.glTranslatef(-center.x, -center.y, -center.z); } - + if (model.isRenderModel()) gl.glCallList(displayList); - + // Disabled lighting for drawing the boundary lines so they are all white (or whatever I chose) - gl.glDisable(GL2.GL_LIGHTING); + gl.glDisable(GLLightingFunc.GL_LIGHTING); if (model.isRenderModelBounds()) gl.glCallList(modelBoundsList); if (model.isRenderObjectBounds()) gl.glCallList(objectBoundsList); - + gl.glPopMatrix(); // Reset the flags back for lighting and texture if (isTextureEnabled) { - gl.glEnable(GL2.GL_TEXTURE_2D); + gl.glEnable(GL.GL_TEXTURE_2D); } else { - gl.glDisable(GL2.GL_TEXTURE_2D); + gl.glDisable(GL.GL_TEXTURE_2D); } if (isLightingEnabled) { - gl.glEnable(GL2.GL_LIGHTING); + gl.glEnable(GLLightingFunc.GL_LIGHTING); } else { - gl.glDisable(GL2.GL_LIGHTING); + gl.glDisable(GLLightingFunc.GL_LIGHTING); } if (isMaterialEnabled) { - gl.glEnable(GL2.GL_COLOR_MATERIAL); + gl.glEnable(GLLightingFunc.GL_COLOR_MATERIAL); } else { - gl.glDisable(GL2.GL_COLOR_MATERIAL); + gl.glDisable(GLLightingFunc.GL_COLOR_MATERIAL); } } - + /** * Load the model and associated materials, etc - * + * * @param gl * @param file * @return */ - private int initialize(GL2 gl, Model model) + private int initialize(final GL2 gl, final Model model) { if (this.isDebugging) System.out.println("Initialize Model: " + model.getSource()); - - int numMaterials = model.getNumberOfMaterials(); - + + final int numMaterials = model.getNumberOfMaterials(); + if (this.isDebugging && numMaterials > 0) { - System.out.println("\n Loading " + numMaterials + " Materials:"); + System.out.println("\n Loading " + numMaterials + " Materials:"); } - - String file = model.getSource(); + + final String file = model.getSource(); texture = new HashMap(); for (int i=0; i 0) { - System.out.println(" Load Materials: Done"); + System.out.println(" Load Materials: Done"); } - + if (this.isDebugging) System.out.println("\n Generate Lists:"); - int compiledList = listCache.generateList(model, gl, 3); - + final int compiledList = listCache.generateList(model, gl, 3); + if (this.isDebugging) - System.out.println(" Model List"); + System.out.println(" Model List"); gl.glNewList(compiledList, GL2.GL_COMPILE); genList(gl, model); gl.glEndList(); - + modelBoundsList = compiledList + 1; if (this.isDebugging) - System.out.println(" Boundary List"); + System.out.println(" Boundary List"); gl.glNewList(modelBoundsList, GL2.GL_COMPILE); genModelBoundsList(gl, model); gl.glEndList(); - + objectBoundsList = compiledList + 2; - + if (this.isDebugging) - System.out.println(" Object Boundary List"); + System.out.println(" Object Boundary List"); gl.glNewList(objectBoundsList, GL2.GL_COMPILE); genObjectBoundsList(gl, model); gl.glEndList(); - + if (this.isDebugging) { System.out.println(" Generate Lists: Done"); System.out.println("Load Model: Done"); } - + return compiledList; } - + /** * Load a texture given by the specified URL and assign it to the texture * id that is passed in. - * + * * @param url * @param id */ - private void loadTexture(URL url, int id) { + private void loadTexture(final GLProfile glp, final URL url, final int id) { if ( url != null ) { BufferedImage bufferedImage = null; try { bufferedImage = ImageIO.read(url); - } catch (Exception e) { + } catch (final Exception e) { System.err.println(" ... FAILED loading texture with exception: "+e.getMessage()); return; } - - texture.put(id, AWTTextureIO.newTexture(bufferedImage, true)); + + texture.put(id, AWTTextureIO.newTexture(glp, bufferedImage, true)); } } - + /** * Generate the model display list - * + * * @param gl */ - private void genList(GL2 gl, Model model) { + private void genList(final GL2 gl, final Model model) { TextureCoords coords; - + for (int i=0; i=0 && id <= model.getNumberOfMeshes()) { if (model.getMesh(id).bounds != null) { drawBounds(gl, model.getMesh(id).bounds); } } } - + /** - * Draw the boundary of the model (the large box representing the entire + * Draw the boundary of the model (the large box representing the entire * model and not the object in it) - * + * * @param gLDrawable */ - private void genModelBoundsList(GLAutoDrawable gLDrawable, Model model) { - GL2 gl = gLDrawable.getGL().getGL2(); + private void genModelBoundsList(final GLAutoDrawable gLDrawable, final Model model) { + final GL2 gl = gLDrawable.getGL().getGL2(); drawBounds(gl, model.getBounds()); } - + /** - * Draw the boundary of the model (the large box representing the entire + * Draw the boundary of the model (the large box representing the entire * model and not the object in it) - * + * * @param gl */ - private void genModelBoundsList(GL2 gl, Model model) { + private void genModelBoundsList(final GL2 gl, final Model model) { drawBounds(gl, model.getBounds()); } - + /** * Draw the boundaries over all of the objects of the model * * @param gLDrawable */ - private void genObjectBoundsList(GLAutoDrawable gLDrawable, Model model) { - GL2 gl = gLDrawable.getGL().getGL2(); + private void genObjectBoundsList(final GLAutoDrawable gLDrawable, final Model model) { + final GL2 gl = gLDrawable.getGL().getGL2(); genObjectBoundsList(gl, model); - } - + } + /** * Draw the boundaries over all of the objects of the model - * + * * @param gl */ - private void genObjectBoundsList(GL2 gl, Model model) { + private void genObjectBoundsList(final GL2 gl, final Model model) { for (int i=0; ilistCache; + private final HashMap listCache; /** Creates a new instance of WWDisplayListCache */ private DisplayListCache() { @@ -529,37 +538,37 @@ public class DisplayListRenderer implements iModel3DRenderer { listCache.clear(); } - public int get(Object objID) { + public int get(final Object objID) { if (listCache.containsKey(objID)) return listCache.get(objID); else return -1; } - public void remove(Object objID, GL2 gl, int howMany) { - Integer list = listCache.get(objID); + public void remove(final Object objID, final GL2 gl, final int howMany) { + final Integer list = listCache.get(objID); if(list != null) gl.glDeleteLists(list, howMany); - + listCache.remove(objID); } /** - * Returns an integer identifier for an OpenGL display list based on the - * object being passed in. If the object already has a display list + * Returns an integer identifier for an OpenGL display list based on the + * object being passed in. If the object already has a display list * allocated, the existing ID is returned. */ - public int generateList(Object objID, GL2 gl, int howMany) { - Integer list = null; + public int generateList(final Object objID, final GL2 gl, final int howMany) { + Integer list = null; list = listCache.get(objID); if(list == null){ list = new Integer(gl.glGenLists(howMany)); - listCache.put(objID, list); - } + listCache.put(objID, list); + } return list; - } + } } } diff --git a/src/net/java/joglutils/model/examples/ModelTest.java b/src/net/java/joglutils/model/examples/ModelTest.java index f92ebd8..3973216 100644 --- a/src/net/java/joglutils/model/examples/ModelTest.java +++ b/src/net/java/joglutils/model/examples/ModelTest.java @@ -32,77 +32,85 @@ * You acknowledge that this software is not designed or intended for use * in the design, construction, operation or maintenance of any nuclear * facility. - * + * * Modifications made by Z-Knight */ package net.java.joglutils.model.examples; -import net.java.joglutils.model.*; -import com.sun.opengl.util.Animator; import java.awt.Frame; +import java.awt.Point; import java.awt.event.KeyEvent; import java.awt.event.KeyListener; +import java.awt.event.MouseEvent; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; -import javax.media.opengl.awt.GLCanvas; -import javax.swing.*; + +import javax.swing.SwingUtilities; import javax.swing.event.MouseInputAdapter; -import java.awt.event.MouseEvent; -import javax.media.opengl.*; -import java.awt.*; -import javax.media.opengl.glu.GLU; + +import com.jogamp.opengl.GL; +import com.jogamp.opengl.GL2; +import com.jogamp.opengl.GL2ES1; +import com.jogamp.opengl.GLAutoDrawable; +import com.jogamp.opengl.GLEventListener; +import com.jogamp.opengl.awt.GLCanvas; +import com.jogamp.opengl.fixedfunc.GLLightingFunc; +import com.jogamp.opengl.fixedfunc.GLMatrixFunc; +import com.jogamp.opengl.glu.GLU; +import com.jogamp.opengl.util.Animator; + import net.java.joglutils.model.ModelFactory; import net.java.joglutils.model.ModelLoadException; -import net.java.joglutils.model.geometry.Model; import net.java.joglutils.model.iModel3DRenderer; +import net.java.joglutils.model.geometry.Model; public class ModelTest { - + /** Creates a new instance of Main */ public ModelTest() { } - public static void main(String[] args) + public static void main(final String[] args) { - Frame frame = new Frame(); - GLCanvas canvas = new GLCanvas(); + final Frame frame = new Frame(); + final GLCanvas canvas = new GLCanvas(); final Renderer renderer = new Renderer(); - - MouseHandler inputMouseHandler = new MouseHandler(renderer); - canvas.addMouseListener(inputMouseHandler); - canvas.addMouseMotionListener(inputMouseHandler); + + final MouseHandler inputMouseHandler = new MouseHandler(renderer); + canvas.addMouseListener(inputMouseHandler); + canvas.addMouseMotionListener(inputMouseHandler); canvas.addKeyListener(new KeyListener() { - public void keyTyped(KeyEvent e) { - Model model = renderer.getModel(); + public void keyTyped(final KeyEvent e) { + final Model model = renderer.getModel(); if (model == null) return; - + switch (e.getKeyChar()) { case 'w': model.setRenderAsWireframe(!model.isRenderingAsWireframe()); break; - + case 'l': model.setUseLighting(!model.isUsingLighting()); break; } } - public void keyPressed(KeyEvent e) { + public void keyPressed(final KeyEvent e) { } - public void keyReleased(KeyEvent e) { + public void keyReleased(final KeyEvent e) { } }); - + canvas.addGLEventListener(renderer); frame.add(canvas); frame.add(canvas); frame.setSize(600, 600); final Animator animator = new Animator(canvas); frame.addWindowListener(new WindowAdapter() { - public void windowClosing(WindowEvent e) { + public void windowClosing(final WindowEvent e) { // Run this on another thread than the AWT event queue to // make sure the call to Animator.stop() completes before // exiting @@ -120,71 +128,71 @@ public class ModelTest { static class Renderer implements GLEventListener { - private GLU glu = new GLU(); + private final GLU glu = new GLU(); private Model model; private iModel3DRenderer modelRenderer; - + /** Scale Factor for zooming */ private float scaleAll = 1.0f; - + /** Rotation factor around X */ private float rotX = 0.0f; - - /** Rotation factor around Y */ + + /** Rotation factor around Y */ private float rotY = 0.0f; - + /** A mouse point */ - private Point mousePoint = new Point(); - + private final Point mousePoint = new Point(); + /** The closest that one can zoom in to */ private static final float MIN_SCALE = 0.1f; - + /** The farthest that one can zoom out to */ private static final float MAX_SCALE = 10000.9f; - + /** The radius of the boundary of the model that is loaded */ private float radius = 1.0f; - + /** Ambient light array */ float[] lightAmbient = {0.3f, 0.3f, 0.3f, 1.0f}; - + /** Diffuse light array */ float[] lightDiffuse = {0.5f, 0.5f, 0.5f, 1.0f}; - + /** Specular light array */ float[] lightSpecular = {0.5f, 0.5f, 0.5f, 1.0f}; - + /** * Display method - * + * * @param gLDrawable */ - public void display(GLAutoDrawable gLDrawable) + public void display(final GLAutoDrawable gLDrawable) { final GL2 gl = gLDrawable.getGL().getGL2(); - gl.glClear(GL2.GL_COLOR_BUFFER_BIT | GL2.GL_DEPTH_BUFFER_BIT); + gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); gl.glLoadIdentity(); - + glu.gluLookAt(0,0,10, 0,0,0, 0,1,0); - + // Make sure the rotations don't keep growing if (Math.abs(rotX) >= 360.0f) rotX = 0.0f; if (Math.abs(rotY) >= 360.0f) rotY = 0.0f; - - // Draw the scene (by default, the lighting, material and textures + + // Draw the scene (by default, the lighting, material and textures // are enabled/disabled within the renderer for the model) gl.glPushMatrix(); // Scale the model (used for zooming purposes) gl.glScalef(scaleAll, scaleAll, scaleAll); - + // Rotate the model based on mouse inputs gl.glRotatef(rotY, 1.0f, 0.0f, 0.0f); gl.glRotatef(rotX, 0.0f, 1.0f, 0.0f); - + // Render the model modelRenderer.render(gl, model); gl.glPopMatrix(); - + gl.glFlush(); } @@ -194,32 +202,32 @@ public class ModelTest { * @param modeChanged Indicates if the video mode has changed. * @param deviceChanged Indicates if the video device has changed. */ - public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged) {} + public void displayChanged(final GLAutoDrawable drawable, final boolean modeChanged, final boolean deviceChanged) {} /** Called by the drawable immediately after the OpenGL context is * initialized for the first time. Can be used to perform one-time OpenGL * initialization such as setup of lights and display lists. * @param gLDrawable The GLDrawable object. */ - public void init(GLAutoDrawable gLDrawable) + public void init(final GLAutoDrawable gLDrawable) { final GL2 gl = gLDrawable.getGL().getGL2(); - + try { // Get an instance of the display list renderer a renderer modelRenderer = DisplayListRenderer.getInstance(); - + // Turn on debugging modelRenderer.debug(true); - + // Call the factory for a model from a local file //model = ModelFactory.createModel("C:\\models\\apollo.3ds"); - + // Call the factory for a model from a jar file model = ModelFactory.createModel("net/java/joglutils/model/examples/models/max3ds/apollo.3ds"); //model = ModelFactory.createModel("net/java/joglutils/model/examples/models/obj/penguin.obj"); - + // When loading the model, adjust the center to the boundary center model.centerModelOnPosition(true); @@ -236,37 +244,37 @@ public class ModelTest { // Get the radius of the model to use for lighting and view presetting radius = model.getBounds().getRadius(); - + } - catch (ModelLoadException ex) + catch (final ModelLoadException ex) { ex.printStackTrace(); } - + // Set the light - float lightPosition[] = { 0, 50000000, 0, 1.0f }; - float[] model_ambient = {0.5f, 0.5f, 0.5f, 1.0f}; - - gl.glLightModelfv(GL2.GL_LIGHT_MODEL_AMBIENT, model_ambient, 0); - gl.glLightfv(GL2.GL_LIGHT0, GL2.GL_POSITION, lightPosition, 0); - gl.glLightfv(GL2.GL_LIGHT0, GL2.GL_DIFFUSE, lightDiffuse, 0); - gl.glLightfv(GL2.GL_LIGHT0, GL2.GL_AMBIENT, lightAmbient, 0); - gl.glLightfv(GL2.GL_LIGHT0, GL2.GL_SPECULAR, lightSpecular, 0); - - gl.glEnable(GL2.GL_LIGHT0); - gl.glEnable(GL2.GL_LIGHTING); - gl.glEnable(GL2.GL_NORMALIZE); - - gl.glEnable(GL2.GL_CULL_FACE); - gl.glShadeModel(GL2.GL_SMOOTH); + final float lightPosition[] = { 0, 50000000, 0, 1.0f }; + final float[] model_ambient = {0.5f, 0.5f, 0.5f, 1.0f}; + + gl.glLightModelfv(GL2ES1.GL_LIGHT_MODEL_AMBIENT, model_ambient, 0); + gl.glLightfv(GLLightingFunc.GL_LIGHT0, GLLightingFunc.GL_POSITION, lightPosition, 0); + gl.glLightfv(GLLightingFunc.GL_LIGHT0, GLLightingFunc.GL_DIFFUSE, lightDiffuse, 0); + gl.glLightfv(GLLightingFunc.GL_LIGHT0, GLLightingFunc.GL_AMBIENT, lightAmbient, 0); + gl.glLightfv(GLLightingFunc.GL_LIGHT0, GLLightingFunc.GL_SPECULAR, lightSpecular, 0); + + gl.glEnable(GLLightingFunc.GL_LIGHT0); + gl.glEnable(GLLightingFunc.GL_LIGHTING); + gl.glEnable(GLLightingFunc.GL_NORMALIZE); + + gl.glEnable(GL.GL_CULL_FACE); + gl.glShadeModel(GLLightingFunc.GL_SMOOTH); gl.glClearColor(0.0f, 0.0f, 0.0f, 1.0f); gl.glClearDepth(1.0f); - gl.glEnable(GL2.GL_DEPTH_TEST); - gl.glDepthFunc(GL2.GL_LEQUAL); - gl.glHint(GL2.GL_PERSPECTIVE_CORRECTION_HINT, GL2.GL_NICEST); + gl.glEnable(GL.GL_DEPTH_TEST); + gl.glDepthFunc(GL.GL_LEQUAL); + gl.glHint(GL2ES1.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST); //gl.glLightModeli(GL2.GL_LIGHT_MODEL_TWO_SIDE, 0); - - gl.glMatrixMode(GL2.GL_MODELVIEW); + + gl.glMatrixMode(GLMatrixFunc.GL_MODELVIEW); gl.glPushMatrix(); } @@ -284,7 +292,7 @@ public class ModelTest { * @param width The new width of the window. * @param height The new height of the window. */ - public void reshape(GLAutoDrawable gLDrawable, int x, int y, int width, int height) + public void reshape(final GLAutoDrawable gLDrawable, final int x, final int y, final int width, int height) { final GL2 gl = gLDrawable.getGL().getGL2(); @@ -292,32 +300,32 @@ public class ModelTest { height = 1; final float h = (float)width / (float)height; gl.glViewport(0, 0, width, height); - gl.glMatrixMode(GL2.GL_PROJECTION); + gl.glMatrixMode(GLMatrixFunc.GL_PROJECTION); gl.glLoadIdentity(); gl.glOrtho(-1, 1, -1, 1, -50, 50); - gl.glMatrixMode(GL2.GL_MODELVIEW); + gl.glMatrixMode(GLMatrixFunc.GL_MODELVIEW); gl.glLoadIdentity(); } - - public void dispose(GLAutoDrawable drawable) { + + public void dispose(final GLAutoDrawable drawable) { } - /** + /** * Get the point at the start of the mouse drag - * + * * @param MousePt */ - void startDrag( Point MousePt ) { + void startDrag( final Point MousePt ) { mousePoint.x = MousePt.x; - mousePoint.y = MousePt.y; - } - + mousePoint.y = MousePt.y; + } + /** * Calculate the delta and rotation values for the dragging of the mouse * @param MousePt */ - void drag( Point MousePt ) { - Point delta = new Point(); + void drag( final Point MousePt ) { + final Point delta = new Point(); delta.x = MousePt.x - mousePoint.x; delta.y = MousePt.y - mousePoint.y; @@ -327,64 +335,64 @@ public class ModelTest { rotX += delta.x * 2.0f / scaleAll; rotY += delta.y * 2.0f / scaleAll; } - - /** + + /** * Get the point at the start of the mouse zoom action * @param MousePt */ - void startZoom( Point MousePt ) { + void startZoom( final Point MousePt ) { mousePoint.x = MousePt.x; mousePoint.y = MousePt.y; } - - /** + + /** * Caclaulte the scaling parameters for zooming while the zoom drag * is ongoing - * + * * @param MousePt */ - void zoom( Point MousePt ) { - Point delta = new Point(); + void zoom( final Point MousePt ) { + final Point delta = new Point(); delta.x = MousePt.x - mousePoint.x; delta.y = MousePt.y - mousePoint.y; mousePoint.x = MousePt.x; mousePoint.y = MousePt.y; - float addition = -(delta.x + delta.y) / 250.0f; + final float addition = -(delta.x + delta.y) / 250.0f; if (addition < 0.0 && (scaleAll+addition) > MIN_SCALE) { - scaleAll += addition; - } + scaleAll += addition; + } if (addition > 0.0 && (scaleAll+addition) < MAX_SCALE) { scaleAll += addition; - } + } } public Model getModel() { return model; } - public void setModel(Model model) { + public void setModel(final Model model) { this.model = model; } } - + /** * Moue handler class that allows the user to rotate and zoom on the model - * - * + * + * */ static class MouseHandler extends MouseInputAdapter { - private Renderer renderer; + private final Renderer renderer; /** * Creates a new instance of the moouse handler - * + * * @param renderer */ - public MouseHandler(Renderer renderer) { + public MouseHandler(final Renderer renderer) { //System.out.println(" Mouse Handler "); this.renderer = renderer; } @@ -392,10 +400,10 @@ public class ModelTest { /** * Handles the mouse click events - * + * * @param e */ - public void mouseClicked(MouseEvent e) { + public void mouseClicked(final MouseEvent e) { if (SwingUtilities.isRightMouseButton(e)) { //System.out.println(" ---> RIGHT MOUSE BUTTON CLICKED "); } @@ -404,15 +412,15 @@ public class ModelTest { /** * Handles the mouse press events - * + * * @param mouseEvent */ - public void mousePressed(MouseEvent mouseEvent) { + public void mousePressed(final MouseEvent mouseEvent) { if (SwingUtilities.isLeftMouseButton(mouseEvent)) { - //System.out.println(" ---> LEFT MOUSE BUTTON PRESSED "); + //System.out.println(" ---> LEFT MOUSE BUTTON PRESSED "); renderer.startDrag(mouseEvent.getPoint()); } else if (SwingUtilities.isMiddleMouseButton(mouseEvent)) { - //System.out.println(" ---> MIDDLE MOUSE BUTTON PRESSED "); + //System.out.println(" ---> MIDDLE MOUSE BUTTON PRESSED "); renderer.startZoom(mouseEvent.getPoint()); } } @@ -420,15 +428,15 @@ public class ModelTest { /** * Handles the mouse drag events - * + * * @param mouseEvent */ - public void mouseDragged(MouseEvent mouseEvent) { + public void mouseDragged(final MouseEvent mouseEvent) { if (SwingUtilities.isLeftMouseButton(mouseEvent)) { - //System.out.println(" ---> LEFT MOUSE BUTTON DRAGGED "); + //System.out.println(" ---> LEFT MOUSE BUTTON DRAGGED "); renderer.drag(mouseEvent.getPoint()); } else if (SwingUtilities.isMiddleMouseButton(mouseEvent)) { - //System.out.println(" ---> MIDDLE MOUSE BUTTON DRAGGED "); + //System.out.println(" ---> MIDDLE MOUSE BUTTON DRAGGED "); renderer.zoom(mouseEvent.getPoint()); } } diff --git a/src/net/java/joglutils/model/geometry/Mesh.java b/src/net/java/joglutils/model/geometry/Mesh.java index 76af31e..57a3bf3 100644 --- a/src/net/java/joglutils/model/geometry/Mesh.java +++ b/src/net/java/joglutils/model/geometry/Mesh.java @@ -36,8 +36,6 @@ package net.java.joglutils.model.geometry; -import java.util.Vector; - public class Mesh { public int numOfVerts = 0; diff --git a/src/net/java/joglutils/model/loader/MaxLoader.java b/src/net/java/joglutils/model/loader/MaxLoader.java index d71baeb..7ba6887 100644 --- a/src/net/java/joglutils/model/loader/MaxLoader.java +++ b/src/net/java/joglutils/model/loader/MaxLoader.java @@ -41,6 +41,7 @@ import java.io.DataInputStream; import java.io.File; import java.io.IOException; import java.io.InputStream; + import net.java.joglutils.model.ResourceRetriever; import net.java.joglutils.model.geometry.Bounds; import net.java.joglutils.model.geometry.Face; diff --git a/src/net/java/joglutils/model/loader/WaveFrontLoader.java b/src/net/java/joglutils/model/loader/WaveFrontLoader.java index 2f9c1b1..e21539d 100644 --- a/src/net/java/joglutils/model/loader/WaveFrontLoader.java +++ b/src/net/java/joglutils/model/loader/WaveFrontLoader.java @@ -18,6 +18,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.Vector; + import net.java.joglutils.model.ModelLoadException; import net.java.joglutils.model.ResourceRetriever; import net.java.joglutils.model.geometry.Bounds; -- cgit v1.2.3