[Bprocessor-commit] gl/src/net/sourceforge/bprocessor/gl/view GLPreviewPanel.java, NONE, 1.1 Displa
Status: Pre-Alpha
Brought to you by:
henryml
From: rimestad <rim...@us...> - 2007-11-19 17:50:23
|
Update of /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/view In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv28489/src/net/sourceforge/bprocessor/gl/view Modified Files: Display.java Added Files: GLPreviewPanel.java Log Message: Created a preview Panel --- NEW FILE: GLPreviewPanel.java --- //--------------------------------------------------------------------------------- // $Id: GLPreviewPanel.java,v 1.1 2007/11/19 17:50:17 rimestad Exp $ // // Copyright (c) 2005 The BProcessor Team (http://bprocessor.sourceforge.net) // Released under the Lesser GNU Public License v2.1 //--------------------------------------------------------------------------------- package net.sourceforge.bprocessor.gl.view; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Dimension; import java.util.LinkedList; import javax.media.opengl.DebugGL; import javax.media.opengl.GL; import javax.media.opengl.GLAutoDrawable; import javax.media.opengl.GLCanvas; import javax.media.opengl.GLEventListener; import javax.media.opengl.glu.GLU; import javax.swing.BorderFactory; import net.sourceforge.bprocessor.gui.PreviewPanel; import net.sourceforge.bprocessor.model.Camera; import net.sourceforge.bprocessor.model.Geometric; /** * A gl preview panel */ public class GLPreviewPanel extends PreviewPanel implements GLEventListener { private GLCanvas glCanvas; private Camera camera; private Geometric geometric; private double aspect; private int displayList; private GL gl; private GLU glu; /** * Default constructor * @param glCanvas The glcanvas */ public GLPreviewPanel(GLCanvas glCanvas) { super(); this.setLayout(new BorderLayout()); this.glCanvas = glCanvas; this.add(glCanvas, BorderLayout.CENTER); this.glCanvas.addGLEventListener(this); this.setMinimumSize(new Dimension(150, 200)); this.setPreferredSize(new Dimension(150, 200)); this.setMaximumSize(new Dimension(150, 200)); this.setBackground(Color.white); this.setBorder(BorderFactory.createLineBorder(Color.black)); this.camera = new Camera("Preview", new double[]{0, 0, 0}, new double[]{10, 10, 10}, new double[]{0, 0, 1}, Camera.PERSPECTIVE); repaint(); } /** {@inheritDoc} */ @Override public void preview(Geometric geometric) { this.geometric = geometric; LinkedList<Geometric> cams = new LinkedList<Geometric>(); cams.add(geometric); this.camera = new Camera("Preview", new double[]{0, 0, 0}, new double[]{100, 100, 100}, new double[]{0, 0, 1}, Camera.PERSPECTIVE); camera.zoomOn(cams, (double)150 / (double)200); repaint(); } /** {@inheritDoc} */ @Override public void repaint() { if (glCanvas != null) { glCanvas.repaint(); } } ////////////////////////////////////////////// // GLEventListener methods ////////////////////////////////////////////// /** {@inheritDoc} */ public void init(GLAutoDrawable gld) { gl = gld.getGL(); glu = new GLU(); //ENABLE FOR DEBUG gld.setGL(new DebugGL(gld.getGL())); this.aspect = (double)getWidth() / (double)getHeight(); double w = gld.getWidth(); double h = gld.getHeight(); gl.glClearColor(1, 1, 1, 0); gl.glViewport(0, 0, getWidth(), getHeight()); gl.glLineStipple(4, (short)0xAAAA); gl.glEnable(GL.GL_LIGHT0); //Tell if both sides of the model should be lighted gl.glLightModeli(GL.GL_LIGHT_MODEL_TWO_SIDE, 0); gl.glLightfv(GL.GL_LIGHT0, GL.GL_AMBIENT, new float[] {0.3f, 0.3f, 0.3f, 1.0f}, 0); gl.glLightfv(GL.GL_LIGHT0, GL.GL_DIFFUSE, new float[] {0.7f, 0.7f, 0.7f, 1.0f}, 0); gl.glLightfv(GL.GL_LIGHT0, GL.GL_POSITION, new float[] {0.0f, 0.0f, 0.0f, 1.0f}, 0); gl.glEnable(GL.GL_LINE_SMOOTH); gl.glEnable(GL.GL_POINT_SMOOTH); gl.glEnable(GL.GL_BLEND); gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA); gl.glDepthMask(true); gl.glDepthFunc(GL.GL_LEQUAL); gl.glEnable(GL.GL_COLOR_MATERIAL); gl.glColorMaterial(GL.GL_FRONT_AND_BACK, GL.GL_AMBIENT_AND_DIFFUSE); gl.glEnable(GL.GL_DEPTH_TEST); gl.glMatrixMode(GL.GL_PROJECTION); gl.glLoadIdentity(); double tal = Math.tan(Math.toRadians(camera.getFocalwidth() / 2)); gl.glFrustum(-tal, tal, -tal / aspect, tal / aspect, 1, camera.dist() * 2); gl.glMatrixMode(GL.GL_MODELVIEW); gl.glLoadIdentity(); new GLU().gluLookAt(camera.getCamera()[0], camera.getCamera()[1], camera.getCamera()[2], camera.getCenter()[0], camera.getCenter()[1], camera.getCenter()[2], camera.getRoll()[0], camera.getRoll()[1], camera.getRoll()[2]); compileGeometric(gld); } private void compileGeometric(GLAutoDrawable gld) { GL gl = gld.getGL(); Display.construction(true); Display.edgesEnabled(false); Display.mode(View.LIGHTING_MODE); Display.transparency(true); Display.target(null); if (this.displayList == 0) { this.displayList = gl.glGenLists(1); } gl.glNewList(this.displayList, GL.GL_COMPILE); Display.draw(gld.getGL(), glu, this.camera, this.geometric); gl.glEndList(); } /** {@inheritDoc} */ public void display(GLAutoDrawable gld) { gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); gl.glRenderMode(GL.GL_RENDER); gl.glRotated(5, 0 , 0, 1); gl.glColor3fv(View.lineColor, 0); gl.glLineWidth(1.0f); gl.glPushMatrix(); gl.glCallList(this.displayList); gl.glPopMatrix(); gld.swapBuffers(); } /** {@inheritDoc} */ public void displayChanged(GLAutoDrawable gld, boolean arg1, boolean arg2) { // TODO Auto-generated method stub } /** {@inheritDoc} */ public void reshape(GLAutoDrawable gld, int x, int y, int width, int height) { gld.getGL().glViewport(x, y, width, height); } } Index: Display.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/view/Display.java,v retrieving revision 1.59 retrieving revision 1.60 diff -C2 -d -r1.59 -r1.60 *** Display.java 19 Nov 2007 11:07:58 -0000 1.59 --- Display.java 19 Nov 2007 17:50:17 -0000 1.60 *************** *** 1189,1193 **** /** ! * * @param gld gld * @param gl gl --- 1189,1219 ---- /** ! * Draw the given geometric ! * @param gl gl the gl context ! * @param glu the glu ! * @param camera the camera ! * @param geometric The geometric ! */ ! public static void draw(GL gl, GLU glu, Camera camera, Geometric geometric) { ! Display.gl = gl; ! Display.glu = glu; ! Display.initialize(); ! Display.selecting(false); ! Display.project = Project.getInstance(); ! Display.camera = camera; ! Display.active = Project.getInstance().world(); ! if (geometric instanceof Space) { ! Display.draw((Space)geometric, true); ! } else if (geometric instanceof Surface) { ! Display.draw((Surface)geometric, true); ! } else if (geometric instanceof Edge) { ! Display.draw((Edge)geometric); ! } else if (geometric instanceof Vertex) { ! Display.draw((Vertex)geometric); ! } ! } ! ! /** ! * Draw the project and the selection * @param gld gld * @param gl gl |