bprocessor-commit Mailing List for B-processor (Page 171)
Status: Pre-Alpha
Brought to you by:
henryml
You can subscribe to this list here.
2005 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
(12) |
Jul
(117) |
Aug
(151) |
Sep
(157) |
Oct
(81) |
Nov
(117) |
Dec
(119) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2006 |
Jan
(183) |
Feb
(130) |
Mar
(117) |
Apr
(61) |
May
(82) |
Jun
(45) |
Jul
(149) |
Aug
(173) |
Sep
(199) |
Oct
(165) |
Nov
(107) |
Dec
(137) |
2007 |
Jan
(124) |
Feb
(58) |
Mar
(123) |
Apr
(80) |
May
(130) |
Jun
(64) |
Jul
(31) |
Aug
(42) |
Sep
(114) |
Oct
(167) |
Nov
(239) |
Dec
(200) |
2008 |
Jan
(43) |
Feb
(43) |
Mar
(4) |
Apr
(9) |
May
(5) |
Jun
(1) |
Jul
(3) |
Aug
(3) |
Sep
(13) |
Oct
(9) |
Nov
(12) |
Dec
|
2009 |
Jan
|
Feb
(20) |
Mar
(7) |
Apr
(12) |
May
(34) |
Jun
(72) |
Jul
|
Aug
(3) |
Sep
(31) |
Oct
(2) |
Nov
(8) |
Dec
(4) |
2010 |
Jan
(5) |
Feb
(32) |
Mar
(8) |
Apr
(7) |
May
(36) |
Jun
|
Jul
(11) |
Aug
(15) |
Sep
(7) |
Oct
(2) |
Nov
(13) |
Dec
(80) |
2011 |
Jan
|
Feb
|
Mar
(8) |
Apr
(12) |
May
(32) |
Jun
(9) |
Jul
(5) |
Aug
|
Sep
(2) |
Oct
|
Nov
|
Dec
(8) |
2012 |
Jan
|
Feb
|
Mar
(3) |
Apr
(5) |
May
(2) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2013 |
Jan
|
Feb
|
Mar
|
Apr
|
May
(22) |
Jun
(5) |
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: Jesper P. <je...@us...> - 2005-07-27 10:26:38
|
Update of /cvsroot/bprocessor/tools/hibernate In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2587/hibernate Log Message: Directory /cvsroot/bprocessor/tools/hibernate added to the repository |
From: Jesper P. <je...@us...> - 2005-07-27 10:25:31
|
Update of /cvsroot/bprocessor/tools/ehcache In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2457/ehcache Log Message: Directory /cvsroot/bprocessor/tools/ehcache added to the repository |
From: Jesper P. <je...@us...> - 2005-07-27 10:24:47
|
Update of /cvsroot/bprocessor/tools/dom4j In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2387/dom4j Log Message: Directory /cvsroot/bprocessor/tools/dom4j added to the repository |
From: Jesper P. <je...@us...> - 2005-07-27 10:24:08
|
Update of /cvsroot/bprocessor/tools/commons-logging In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2332/commons-logging Log Message: Directory /cvsroot/bprocessor/tools/commons-logging added to the repository |
From: Jesper P. <je...@us...> - 2005-07-27 10:23:33
|
Update of /cvsroot/bprocessor/tools/commons-collections In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2231/commons-collections Log Message: Directory /cvsroot/bprocessor/tools/commons-collections added to the repository |
From: Jesper P. <je...@us...> - 2005-07-27 10:23:02
|
Update of /cvsroot/bprocessor/tools/cglib In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2149/cglib Log Message: Directory /cvsroot/bprocessor/tools/cglib added to the repository |
From: Jesper P. <je...@us...> - 2005-07-27 10:22:19
|
Update of /cvsroot/bprocessor/tools/asm In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2081/asm Log Message: Directory /cvsroot/bprocessor/tools/asm added to the repository |
From: Jesper P. <je...@us...> - 2005-07-27 10:21:32
|
Update of /cvsroot/bprocessor/tools/antlr In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1974/antlr Log Message: Directory /cvsroot/bprocessor/tools/antlr added to the repository |
From: rimestad <rim...@us...> - 2005-07-27 08:36:21
|
Update of /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16648 Modified Files: DrawTool.java Log Message: use equals instead of == Index: DrawTool.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool/DrawTool.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** DrawTool.java 26 Jul 2005 12:35:44 -0000 1.1 --- DrawTool.java 27 Jul 2005 08:36:12 -0000 1.2 *************** *** 46,61 **** */ protected void moved(MouseEvent e) { ! int x = e.getX(); ! int y = e.getY(); ! View v = glv.getView(); ! double[] coord = v.toCanvasCoords(new double[] {x, y}); ! ! coord = snapToGrid(coord); ! // snap to vertexes ! coord = aligned(coord); ! //check for snap point change ! checkVertexSnap(coord); ! //change the activeEdge according to mouse position ! changeTo(coord); } --- 46,63 ---- */ protected void moved(MouseEvent e) { ! if (view.getActiveEdge != null) { ! int x = e.getX(); ! int y = e.getY(); ! View v = glv.getView(); ! double[] coord = v.toCanvasCoords(new double[] {x, y}); ! ! coord = snapToGrid(coord); ! // snap to vertexes ! coord = aligned(coord); ! //check for snap point change ! checkVertexSnap(coord); ! //change the activeEdge according to mouse position ! changeTo(coord); ! } } *************** *** 154,158 **** glv.getView().setAlignVertex(null); } else { ! // we did end a edgelist endSurface(coord); } --- 156,160 ---- glv.getView().setAlignVertex(null); } else { ! // we did end a edgelist endSurface(coord); } *************** *** 179,194 **** */ protected Vertex vertexCollide(double[] coord) { - Set vertexes = VertexFacade.getInstance().findAll(); - Iterator it = vertexes.iterator(); Edge e = glv.getView().getActiveEdge(); ! while (it.hasNext()) { ! Vertex v = (Vertex)it.next(); ! if (collide(v.getX(), coord[0]) && ! collide(v.getY(), coord[1]) && ! collide(v.getZ(), coord[2]) && ! e != null && ! v != e.getTo() && ! v != e.getFrom()) { ! return v; } } --- 181,197 ---- */ protected Vertex vertexCollide(double[] coord) { Edge e = glv.getView().getActiveEdge(); ! if (e != null) { ! Set vertexes = VertexFacade.getInstance().findAll(); ! Iterator it = vertexes.iterator(); ! while (it.hasNext()) { ! Vertex v = (Vertex)it.next(); ! if (collide(v.getX(), coord[0]) && ! collide(v.getY(), coord[1]) && ! collide(v.getZ(), coord[2]) && ! !v.equals(e.getTo()) && ! !v.equals(e.getFrom())) { ! return v; ! } } } *************** *** 216,220 **** View view = glv.getView(); Edge e = view.getActiveEdge(); ! if (v != null && v != view.getActiveEdge().getTo() && v != view.getActiveEdge().getFrom()) { view.setAlignVertex(v); view.setSnapVertex(v); --- 219,223 ---- View view = glv.getView(); Edge e = view.getActiveEdge(); ! if (v != null && !v.equals(e.getTo()) && !v.equals(e.getFrom())) { view.setAlignVertex(v); view.setSnapVertex(v); |
From: rimestad <rim...@us...> - 2005-07-26 12:50:18
|
Update of /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17189/src/net/sourceforge/bprocessor/gl Removed Files: AbstractViewListener.java GLKeyListener.java GLMouseListener.java View3DListener.java ViewXYListener.java ViewXZListener.java ViewYZListener.java Log Message: removed due to refactoring into packages --- GLMouseListener.java DELETED --- --- GLKeyListener.java DELETED --- --- ViewXZListener.java DELETED --- --- AbstractViewListener.java DELETED --- --- ViewXYListener.java DELETED --- --- ViewYZListener.java DELETED --- --- View3DListener.java DELETED --- |
From: rimestad <rim...@us...> - 2005-07-26 12:48:32
|
Update of /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16916 Modified Files: GLView.java Log Message: funtionality refactored to tools. Now it only binds the GL together Index: GLView.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/GLView.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** GLView.java 22 Jul 2005 11:25:57 -0000 1.3 --- GLView.java 26 Jul 2005 12:48:23 -0000 1.4 *************** *** 7,27 **** package net.sourceforge.bprocessor.gl; ! import net.sourceforge.bprocessor.kernel.notification.Notification; ! import net.sourceforge.bprocessor.kernel.notification.Notifier; import net.sourceforge.bprocessor.gui.GUI; - import net.sourceforge.bprocessor.model.Edge; - import net.sourceforge.bprocessor.model.EdgeFacade; - import net.sourceforge.bprocessor.model.Surface; - import net.sourceforge.bprocessor.model.SurfaceFacade; - import net.sourceforge.bprocessor.model.Vertex; - import net.sourceforge.bprocessor.model.VertexFacade; - import java.util.EventListener; - import java.util.HashSet; - import java.util.Iterator; - import java.util.Set; - import java.awt.event.MouseListener; - import java.awt.event.MouseMotionListener; - import java.awt.event.MouseWheelListener; import net.java.games.jogl.GLCanvas; import net.java.games.jogl.GLCapabilities; --- 7,16 ---- package net.sourceforge.bprocessor.gl; ! import net.sourceforge.bprocessor.gl.tool.Tool; ! import net.sourceforge.bprocessor.gl.tool.ToolFactory; ! import net.sourceforge.bprocessor.gl.view.View; ! import net.sourceforge.bprocessor.gl.view.ViewFactory; import net.sourceforge.bprocessor.gui.GUI; import net.java.games.jogl.GLCanvas; import net.java.games.jogl.GLCapabilities; *************** *** 37,84 **** private static Logger log = Logger.getLogger(GLView.class); - /** An vertex counter */ - private static long vertexNum = 0; - - /** An edge counter */ - private static long edgeNum = 0; - - /** An surface counter */ - private static long surfaceNum = 0; - - /** The snap variable */ - public static final double EPSILON = 0.4; - - /** The 3D view mode */ - protected static final int MODE_3D = 0; - - /** The x z plane view */ - protected static final int MODE_XZ = 1; - - /** The x y plane view */ - protected static final int MODE_XY = 2; - - /** The y z plane view */ - protected static final int MODE_YZ = 3; - - /** The 3D listener*/ - private static AbstractViewListener view3D; - - /**The XY listener */ - private static AbstractViewListener viewXY; - - /** The XZ listener */ - private static AbstractViewListener viewXZ; - - /** The */ - private static AbstractViewListener viewYZ; - /** GL canvas */ private GLCanvas glc; /** current event listener */ ! private AbstractViewListener currentListener; ! /** The current Edge list */ ! private Set edges; /** --- 26,37 ---- private static Logger log = Logger.getLogger(GLView.class); /** GL canvas */ private GLCanvas glc; /** current event listener */ ! private View view; ! /** current working tool */ ! private Tool tool; /** *************** *** 89,107 **** glc = GLDrawableFactory.getFactory().createGLCanvas(glCap); ! currentListener = new ViewYZListener(); ! glc.addGLEventListener(currentListener); ! ! view3D = new View3DListener(); ! viewXY = new ViewXYListener(); ! viewXZ = new ViewXZListener(); ! viewYZ = new ViewYZListener(); ! ! EventListener mil = new GLMouseListener(this); ! glc.addMouseListener((MouseListener)mil); ! glc.addMouseMotionListener((MouseMotionListener)mil); ! glc.addMouseWheelListener((MouseWheelListener)mil); ! glc.addKeyListener(new GLKeyListener(this)); ! edges = new HashSet(); GUI.getInstance().registerPanel(glc, GUI.SPLIT_MIDDLE); --- 42,52 ---- glc = GLDrawableFactory.getFactory().createGLCanvas(glCap); ! view = ViewFactory.getFactory().getDefault(); ! glc.addGLEventListener(view); ! tool = ToolFactory.getFactory(this).getDefault(); ! glc.addMouseListener(tool); ! glc.addMouseMotionListener(tool); ! glc.addKeyListener(tool); GUI.getInstance().registerPanel(glc, GUI.SPLIT_MIDDLE); *************** *** 109,352 **** /** ! * Change the view ! * @param mode The view mode ! */ ! public void changeView(int mode) { ! glc.removeGLEventListener(currentListener); ! ! if (mode == MODE_3D) { ! currentListener = view3D; ! } else if (mode == MODE_XZ) { ! currentListener = viewXZ; ! } else if (mode == MODE_XY) { ! currentListener = viewXY; ! } else if (mode == MODE_YZ) { ! currentListener = viewYZ; ! } else { ! log.error("[changeView] mode non-existing"); ! } ! glc.addGLEventListener(currentListener); ! this.repaint(); ! } ! ! /** ! * Repaint the canvas ! */ ! public void repaint() { ! glc.getGL().glFlush(); ! glc.repaint(); ! } ! ! /** ! * Add the last edge to the edgelist => surface ! * @param coord The end coordinate ! */ ! protected void endSurface(double[] coord) { ! Edge activeEdge = currentListener.getActiveEdge(); ! Vertex to = vertexCollide(coord); ! if (to != null) { ! // we have to change excisting surface ! removeVertex(activeEdge.getTo()); ! activeEdge.setTo(to); ! } else { ! activeEdge.getTo().setX(coord[0]); ! activeEdge.getTo().setY(coord[1]); ! activeEdge.getTo().setZ(coord[2]); ! } ! Surface s = surface(); ! s.setEdges(edges); ! currentListener.setAlignVertex(null); ! edges = new HashSet(); ! currentListener.setActiveEdge(null); ! } ! ! /** ! * Add an edge to the parent edgelist ! * @param coord The to point */ ! protected void addEdge(double[] coord) { ! if (edges.isEmpty()) { ! Edge activeEdge = edge(); ! currentListener.setActiveEdge(activeEdge); ! Vertex from = vertex(); ! from.setX(coord[0]); ! from.setY(coord[1]); ! from.setZ(coord[2]); ! activeEdge.setFrom(from); ! Vertex to = vertex(); ! to.setX(coord[0]); ! to.setY(coord[1]); ! to.setZ(coord[2]); ! activeEdge.setTo(to); ! edges.add(activeEdge); ! currentListener.setAlignVertex(null); } else { ! if (vertexCollide(coord) == null) { ! // we did not end an edgelist ! Edge activeEdge = currentListener.getActiveEdge(); ! Vertex from = activeEdge.getTo(); ! activeEdge = edge(); ! currentListener.setActiveEdge(activeEdge); ! activeEdge.setFrom(from); ! Vertex to = vertex(); ! to.setX(coord[0]); ! to.setY(coord[1]); ! to.setZ(coord[2]); ! activeEdge.setTo(to); ! edges.add(activeEdge); ! currentListener.setAlignVertex(null); ! } else { ! // we did end a edgelist ! endSurface(coord); ! } } } /** ! * Change the to vertex coordinates for the active edge ! * @param coord The new coordinate ! */ ! protected void changeTo(double[] coord) { ! Edge activeEdge = currentListener.getActiveEdge(); ! if (activeEdge != null && !edges.isEmpty()) { ! activeEdge.getTo().setX(coord[0]); ! activeEdge.getTo().setY(coord[1]); ! activeEdge.getTo().setZ(coord[2]); ! } ! } ! ! /** ! * Check if the current point is a vertex if so, it registers the vertex as ! * snapVertex and alignVertex in the AbstractListener. ! * @param coord the cordinate to check for snap (x, y, z) */ ! protected void checkVertexSnap(double[] coord) { ! Vertex v = vertexCollide(coord); ! if (v != null) { ! currentListener.setAlignVertex(v); ! currentListener.setSnapVertex(v); } else { ! removeVertexSnap(); ! } ! } ! ! /** ! * Set the snapVertex variable to null ! */ ! protected void removeVertexSnap() { ! currentListener.setSnapVertex(null); ! } ! ! /** ! * Check if this cordinate collide with another vertex ! * @param coord The cordinate to check for collision at ! * @return The excisting vertex at coord, null if there ain't any ! */ ! private Vertex vertexCollide(double[] coord) { ! Set vertexes = VertexFacade.getInstance().findAll(); ! Iterator it = vertexes.iterator(); ! while (it.hasNext()) { ! Vertex v = (Vertex)it.next(); ! if (collide(v.getX(), coord[0]) && ! collide(v.getY(), coord[1]) && ! collide(v.getZ(), coord[2]) && ! currentListener.getActiveEdge() != null && ! currentListener.getActiveEdge().getTo() != v && ! currentListener.getActiveEdge().getFrom() != v) { ! return v; ! } ! } ! return null; ! } ! ! /** ! * Check if a and b is as close as EPSILON ! * @param a The target ! * @param b The value ! * @return true if |a - b| < EPSILON false otherwise ! */ ! private boolean collide(double a, double b) { ! return Math.abs(a - b) < EPSILON; ! } ! ! /** ! * Take a coordinate and check if it should snap to grid ! * @param coords The coordinates to check for snapping ! * @return the snapped coordinates ! */ ! public double[] snapToGrid(double[] coords) { ! if (Math.abs(coords[0] - Math.round(coords[0])) < EPSILON) { ! coords[0] = Math.round(coords[0]); ! } ! if (Math.abs(coords[1] - Math.round(coords[1])) < EPSILON) { ! coords[1] = Math.round(coords[1]); ! } ! if (Math.abs(coords[2] - Math.round(coords[2])) < EPSILON) { ! coords[2] = Math.round(coords[2]); } ! return coords; ! } ! ! /** ! * Make and register a new vertex ! * @return The new Vertex ! */ ! private Vertex vertex() { ! Vertex v = new Vertex("V" + vertexNum); ! vertexNum++; ! VertexFacade.getInstance().add(v); ! ! Notification n = new Notification(Notification.VERTEX_CREATED, v.getId()); ! Notifier.getInstance().sendNotification(n); ! ! return v; ! } ! ! /** ! * Remove a vertex for good ! * @param v Vertex to remove ! */ ! private void removeVertex(Vertex v) { ! VertexFacade.getInstance().remove(v); ! ! Notification n = new Notification(Notification.VERTEX_DELETED, v.getId()); ! Notifier.getInstance().sendNotification(n); } /** ! * Make and register a new edge ! * @return The new Edge */ ! private Edge edge() { ! Edge e = new Edge("E" + edgeNum); ! edgeNum++; ! EdgeFacade.getInstance().add(e); ! ! Notification n = new Notification(Notification.EDGE_CREATED, e.getId()); ! Notifier.getInstance().sendNotification(n); ! ! return e; } /** ! * Make and register a new Surface ! * @return The new Surface */ ! private Surface surface() { ! Surface s = new Surface("S" + surfaceNum); ! surfaceNum++; ! SurfaceFacade.getInstance().add(s); ! ! Notification n = new Notification(Notification.SURFACE_CREATED, s.getId()); ! Notifier.getInstance().sendNotification(n); ! return s; } /** ! * Return the current used GLEventListener ! * @return The current GLEventListener */ ! public AbstractViewListener getEventListener() { ! return currentListener; } } --- 54,112 ---- /** ! * Change the tool ! * @param mode The new tool */ ! public void changeTool(int mode) { ! glc.removeMouseListener(tool); ! glc.removeMouseMotionListener(tool); ! glc.removeKeyListener(tool); ! tool = ToolFactory.getFactory(this).get(mode); ! if (tool != null) { ! glc.addMouseListener(tool); ! glc.addMouseMotionListener(tool); ! glc.addKeyListener(tool); } else { ! log.error("[changeMode] tool was null"); } } /** ! * Change the view ! * @param v The view */ ! public void changeView(int v) { ! glc.removeGLEventListener(view); ! view = ViewFactory.getFactory().get(v); ! if (view != null) { ! glc.addGLEventListener(view); } else { ! log.error("[changeView] View was null shifts to default"); ! view = ViewFactory.getFactory().getDefault(); ! glc.addGLEventListener(view); } ! this.repaint(); } /** ! * Repaint the canvas */ ! public void repaint() { ! glc.repaint(); } /** ! * Return the current used view ! * @return The current view */ ! public View getView() { ! return view; } /** ! * return the current tool in use ! * @return the tool */ ! public Tool getTool() { ! return tool; } } |
From: rimestad <rim...@us...> - 2005-07-26 12:45:57
|
Update of /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/view In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16307 Added Files: package.html Log Message: The package info --- NEW FILE: package.html --- <body> Defines the package that contains the 3D views (GL) </body> |
From: rimestad <rim...@us...> - 2005-07-26 12:45:13
|
Update of /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/view In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16125 Added Files: ViewFactory.java Log Message: A factory that generates views --- NEW FILE: ViewFactory.java --- //--------------------------------------------------------------------------------- // $Id: ViewFactory.java,v 1.1 2005/07/26 12:44:58 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 net.sourceforge.bprocessor.kernel.notification.Notifier; import org.apache.log4j.Logger; /** * The View factory */ public class ViewFactory { /** The logger */ private static Logger log = Logger.getLogger(ViewFactory.class); /** The 3D view*/ private static View view3D; /** The XY view */ private static View viewXY; /** The XZ view */ private static View viewXZ; /** The YZ view*/ private static View viewYZ; /** */ private static ViewFactory factory; /** * Constructor */ private ViewFactory() { view3D = new View3D(); viewXY = new ViewXY(); viewXZ = new ViewXZ(); viewYZ = new ViewYZ(); Notifier n = Notifier.getInstance(); n.addListener(view3D); n.addListener(viewXY); n.addListener(viewXZ); n.addListener(viewYZ); } /** * Get the factory * @return The factory */ public static synchronized ViewFactory getFactory() { if (factory == null) { factory = new ViewFactory(); } return factory; } /** * Get the default view * @return The view */ public View getDefault() { return get(View.VIEW_3D); } /** * Get the i view * @param i the wanted view number * @return the view */ public View get(int i) { if (i == View.VIEW_3D) { return view3D; } else if (i == View.VIEW_XZ) { return viewXZ; } else if (i == View.VIEW_XY) { return viewXY; } else if (i == View.VIEW_YZ) { return viewYZ; } else { log.error("[get] no such view " + i); return null; } } } |
From: rimestad <rim...@us...> - 2005-07-26 12:44:07
|
Update of /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/view In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15937 Added Files: AbstractView.java Log Message: implements common methods for the views --- NEW FILE: AbstractView.java --- //--------------------------------------------------------------------------------- // $Id: AbstractView.java,v 1.1 2005/07/26 12:43:56 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 net.sourceforge.bprocessor.kernel.notification.Notification; import net.sourceforge.bprocessor.model.Edge; import net.sourceforge.bprocessor.model.EdgeFacade; import net.sourceforge.bprocessor.model.Vertex; import net.sourceforge.bprocessor.model.VertexFacade; import net.sourceforge.bprocessor.model.Surface; import java.util.Iterator; import java.util.Set; import net.java.games.jogl.GL; import net.java.games.jogl.GLDrawable; import net.java.games.jogl.GLU; import net.java.games.jogl.GLUquadric; import net.java.games.jogl.util.GLUT; import org.apache.log4j.Logger; /** * The 3D view listener */ public abstract class AbstractView implements View { /** The logger */ private static Logger log = Logger.getLogger(AbstractView.class); /** the color of the x axis */ public static final double[] X_AXIS_COLOR = new double[] {0.0, 1.0, 0.0}; /** the color of the y axis */ public static final double[] Y_AXIS_COLOR = new double[] {1.0, 0.0, 0.0}; /** the color of the z axis */ public static final double[] Z_AXIS_COLOR = new double[] {0.0, 0.0, 1.0}; /** the std line color*/ public static final double[] STD_LINE_COLOR = new double[] {0.0, 0.0, 0.0}; /** Used for the actual drawing line */ public static final double[] DRAW_COLOR = new double[] {1.0, 1.0, 0.0}; /** Used for the actual drawing line */ public static final double[] GRID_COLOR = new double[] {0.85, 0.85, 0.85}; /** The view transformation matrix (it is shown transposed) see p. 187 [GL BIBLE]*/ protected static double[] viewTrans = new double[] {1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0}; /** The width of the window */ protected static double width; /** The height of the window */ protected static double height; /** The screen aspect */ protected static double aspect; /** The size of the viewing area */ protected static double size = 25.0; /** The Active edge */ protected static Edge activeEdge = null; /** The Snap vertex */ protected static Vertex snapVertex = null; /** For clever snapping */ protected static double[] alignPoint = null; /** The alignment vertex */ protected static Vertex alignVertex = null; /** The selected vertex */ protected static Vertex selectedVertex = null; /** The GL */ protected GL gl = null; /** The zoomFactor in the parent view */ protected double zoomFactor = 1.0; /** * The initialization part of the 3D view * @param gld The GLDrawable object */ public void init(GLDrawable gld) { if (log.isDebugEnabled()) { log.debug("[init]"); } gl = gld.getGL(); this.width = gld.getSize().getWidth(); this.height = gld.getSize().getHeight(); this.aspect = this.width / this.height; gl.glClearColor(0.7f, 0.7f, 0.7f, 0.0f); gl.glViewport(0, 0, (int)width, (int)height); } /** * The function responsible for drawing at each update * @param gld The GLDrawable object */ public void display(GLDrawable gld) { gl = gld.getGL(); gl.glClear(GL.GL_COLOR_BUFFER_BIT); gl.glViewport(0, 0, (int)width, (int)height); camera(gld); grid(); coords(); gl.glColor3dv(STD_LINE_COLOR); gl.glLineWidth(1.0f); drawAll(gld); } /** * Called by the drawable during the first repaint after the component has been resized. * @param gld The GLDrawable * @param x The new x coordinate * @param y The new y coordinate * @param width The new window width * @param height The new window height */ public void reshape(GLDrawable gld, int x, int y, int width, int height) { this.width = width; this.height = height; this.aspect = this.width / this.height; } /** * Called by the drawable when the display mode or the display device * associated with the GLDrawable has changed. * @param gld The GLDrawable * @param modeChanged The new graphical mode * @param deviceChanged The new graphical device */ public void displayChanged(GLDrawable gld, boolean modeChanged, boolean deviceChanged) { } /** * Draw all the existing elements * @param gld The GLDrawable */ protected void drawAll(GLDrawable gld) { Set edges = EdgeFacade.getInstance().findAll(); GL gl = gld.getGL(); GLU glu = gld.getGLU(); GLUT glut = new GLUT(); Iterator it = edges.iterator(); gl.glColor3dv(STD_LINE_COLOR); while (it.hasNext()) { Edge e = (Edge)it.next(); drawEdge(e); } // draw activeEdge different if it is parallel with axis if (activeEdge != null) { Vertex to = activeEdge.getTo(); Vertex from = activeEdge.getFrom(); if (from.getY() == to.getY() && from.getZ() == to.getZ()) { gl.glColor3dv(X_AXIS_COLOR); } else if (from.getX() == to.getX() && from.getZ() == to.getZ()) { gl.glColor3dv(Y_AXIS_COLOR); } else if (from.getX() == to.getX() && from.getY() == to.getY()) { gl.glColor3dv(Z_AXIS_COLOR); } else { gl.glColor3dv(STD_LINE_COLOR); } gl.glBegin(GL.GL_LINES); gl.glVertex3d(from.getX(), from.getY(), from.getZ()); gl.glVertex3d(to.getX(), to.getY(), to.getZ()); gl.glEnd(); } // draw alignment line if (alignPoint != null && alignVertex != null) { if (alignPoint[1] == alignVertex.getY() && alignPoint[2] == alignVertex.getZ()) { gl.glColor3dv(X_AXIS_COLOR); } else if (alignPoint[0] == alignVertex.getX() && alignPoint[2] == alignVertex.getZ()) { gl.glColor3dv(Y_AXIS_COLOR); } else if (alignPoint[0] == alignVertex.getX() && alignPoint[1] == alignVertex.getY()) { gl.glColor3dv(Z_AXIS_COLOR); } else { gl.glColor3dv(DRAW_COLOR); } gl.glBegin(GL.GL_LINES); gl.glVertex3d(alignPoint[0], alignPoint[1], alignPoint[2]); gl.glVertex3d(alignVertex.getX(), alignVertex.getY(), alignVertex.getZ()); gl.glEnd(); } // draw snap point if any if (snapVertex != null) { gl.glColor3d(0.0, 1.0, 0.0); gl.glPointSize(5.0f); gl.glBegin(GL.GL_POINTS); gl.glVertex3d(snapVertex.getX(), snapVertex.getY(), snapVertex.getZ()); gl.glEnd(); gl.glPointSize(1.0f); } // draw selection if (selectedVertex != null) { gl.glColor3d(0.0, 1.0, 0.0); gl.glPushMatrix(); gl.glTranslated(selectedVertex.getX(), selectedVertex.getY(), selectedVertex.getZ()); GLUquadric quad = glu.gluNewQuadric(); glu.gluQuadricDrawStyle(quad, GLU.GLU_FILL); glu.gluSphere(quad, 0.3, 15, 15); glu.gluDeleteQuadric(quad); gl.glPopMatrix(); } } /** * Draw a surface * @param s The surface to draw */ private void drawSurface(Surface s) { Set edges = s.getEdges(); Iterator it = edges.iterator(); while (it.hasNext()) { Edge e = (Edge)it.next(); drawEdge(e); } } /** * Draw an Edge * @param e The Edge to draw */ private void drawEdge(Edge e) { Vertex to = e.getTo(); Vertex from = e.getFrom(); if (to != null && from != null) { gl.glBegin(GL.GL_LINES); gl.glVertex3d(to.getX(), to.getY(), to.getZ()); gl.glVertex3d(from.getX(), from.getY(), from.getZ()); gl.glEnd(); } } /** * Change the rotation about the x axis. Only usable in 3D * @param change The change in R+ (is divided with the window height) */ public void translateRotationX(double change) { } /** * Change the rotation about the y axis. Only usable in 3D * @param change The change in R+ (is divided with the window height) */ public void translateRotationY(double change) { } /** * Change the zoom factor of the camera take only R+ * 1-oo is increase zoom and 0-1 decrease 1 keep the current zoom * @param zoom the zoom factor change */ public void zoom(double zoom) { if (zoom > 0) { zoom *= getZoomFactor(); setZoomFactor(zoom); } } /** * setter for zoomFactor * @param z The new zoomFactor */ public void setZoomFactor(double z) { zoomFactor = z; } /** * getter for zoomFactor * @return The parent zoomFactor */ public double getZoomFactor() { return zoomFactor; } /** * Getter for activeEdge * @return activeEdge */ public Edge getActiveEdge() { return activeEdge; } /** * Set activeEdge * @param e The activeEdge */ public void setActiveEdge(Edge e) { activeEdge = e; } /** * Getter for snapVertex * @return snapVertex */ public Vertex getSnapVertex() { return snapVertex; } /** * Setter for snapVertex * @param v The new snapVertex */ public void setSnapVertex(Vertex v) { snapVertex = v; } /** * Getter for alignVertex * @return alignVertex */ public Vertex getAlignVertex() { return alignVertex; } /** * Setter for alignVertex * @param v The new alignVertex */ public void setAlignVertex(Vertex v) { alignVertex = v; } /** * Setter for alignPoint * @param coord The new alignPoint */ public void setAlignPoint(double[] coord) { alignPoint = coord; } /** * Getter for alignPoint * @return alignPoint */ public double[] getAlignPoint() { return alignPoint; } /** * Handle a notification * @param n The notification */ public void handleNotification(Notification n) { if (n.getType().equals(Notification.VERTEX_SELECTED)) { selectedVertex = VertexFacade.getInstance().findById(n.getObject()); } } /** * Should the listener handle this notification * @param type The notification type * @return Returns true on SELECTED events; otherwise false */ public boolean isNotificationEnabled(String type) { if (type.equals(Notification.VERTEX_SELECTED)) { return true; } return false; } /** * The camera init function * @param gld The GLDrawable object */ public abstract void camera(GLDrawable gld); /** * The drawing of cordinatesystem */ protected abstract void coords(); /** * The drawing of grid */ protected abstract void grid(); /** * Move the center left/right, up/down, forward/backward * @param mv the move vector */ public abstract void translateCenter(double [] mv); /** * Return the 3D coordinates for the canvas matching the given 2D coords * @return The relative 3D coordinates * @param coords The window coordinates */ public abstract double[] toCanvasCoords(double[] coords); } |
From: rimestad <rim...@us...> - 2005-07-26 12:43:38
|
Update of /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/view In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15807 Added Files: ViewXY.java ViewXZ.java ViewYZ.java Log Message: the 2D views --- NEW FILE: ViewYZ.java --- //--------------------------------------------------------------------------------- // $Id: ViewYZ.java,v 1.1 2005/07/26 12:43:21 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 net.java.games.jogl.GL; import net.java.games.jogl.GLDrawable; import net.java.games.jogl.GLU; import org.apache.log4j.Logger; /** * The Y-Z plane view */ public class ViewYZ extends AbstractView { /** The logger */ private static Logger log = Logger.getLogger(ViewYZ.class); /** The relative center of the view */ private static double[] center = new double[] {0.0, 0.0, 0.0}; /** * The camera setup function * @param gld The GLDrawable object */ public void camera(GLDrawable gld) { if (log.isDebugEnabled()) { log.debug("[display]"); } gl = gld.getGL(); GLU glu = gld.getGLU(); gl.glMatrixMode(GL.GL_PROJECTION); gl.glLoadIdentity(); double size = this.size * getZoomFactor(); if (width <= height) { gl.glOrtho(-size, size, -(size * (height / width)), (size * (height / width)), -25.0, 25.0); } else { gl.glOrtho(-(size * aspect), size * aspect, -size, size, -25.0, 25.0); } gl.glMatrixMode(GL.GL_MODELVIEW); gl.glLoadIdentity(); glu.gluLookAt(-10.0, center[1], center[2], center[0], center[1], center[2], 0.0, 1.0, 0.0); } /** * Move the center left/right, up/down, left/right * @param mv the move vector */ public void translateCenter(double [] mv) { if (mv.length == 3) { this.center[0] += mv[2]; this.center[1] += mv[1]; this.center[2] += mv[0]; } else { log.error("[translateViewMatrix] Wrong parameter size"); } } /** * Draw a grid */ protected void grid() { double size; if (aspect > 1) { size = this.size * getZoomFactor() * aspect; } else { size = this.size * getZoomFactor() / aspect; } gl.glLineWidth(1.0f); gl.glColor3dv(GRID_COLOR); gl.glBegin(GL.GL_LINES); for (int y = -(int)size; y <= size; y++) { gl.glVertex3d(0.0, (double)y, -size); gl.glVertex3d(0.0, (double)y, size); } for (int z = -(int)size; z <= size; z++) { gl.glVertex3d(0.0, -size, (double)z); gl.glVertex3d(0.0, size, (double)z); } gl.glEnd(); } /** * Draw a coordinate system */ protected void coords() { gl.glLineWidth(2.0f); gl.glBegin(GL.GL_LINES); gl.glColor3dv(Y_AXIS_COLOR); gl.glVertex3d(0.0, 0.0, 0.0); gl.glVertex3d(0.0, 10.0, 0.0); gl.glColor3dv(Z_AXIS_COLOR); gl.glVertex3d(0.0, 0.0, 0.0); gl.glVertex3d(0.0, 0.0, 10.0); gl.glEnd(); } /** * Return the 3D coordinates for the canvas matching the given 2D coords * @return The relative 3D coordinates * @param coords The window coordinates */ public double[] toCanvasCoords(double[] coords) { if (coords.length == 2) { double pixelwidth, pixelheight; if (aspect < 1) { pixelheight = height / (2 * size * getZoomFactor() * (1 / aspect)); pixelwidth = width / (2 * size * getZoomFactor()); } else { pixelheight = height / (2 * size * getZoomFactor()); pixelwidth = width / (2 * size * getZoomFactor() * aspect); } double returnx = 0; double returny = height / (2 * pixelheight) - coords[1] / pixelheight + center[1]; double returnz = coords[0] / pixelwidth + center[2] - width / (2 * pixelwidth); return new double[] {returnx, returny, returnz}; } else { log.warn("Too many arguments"); return new double[] {0.0, 0.0, 0.0}; } } } --- NEW FILE: ViewXY.java --- //--------------------------------------------------------------------------------- // $Id: ViewXY.java,v 1.1 2005/07/26 12:43:21 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 net.java.games.jogl.GL; import net.java.games.jogl.GLDrawable; import net.java.games.jogl.GLU; import org.apache.log4j.Logger; /** * The X-Y plane view */ public class ViewXY extends AbstractView { /** The logger */ private static Logger log = Logger.getLogger(ViewXY.class); /** The relative center of the view */ private static double[] center = new double[] {0.0, 0.0, 0.0}; /** * The camera setup function * @param gld The GLDrawable object */ public void camera(GLDrawable gld) { if (log.isDebugEnabled()) { log.debug("[display]"); } gl = gld.getGL(); GLU glu = gld.getGLU(); gl.glMatrixMode(GL.GL_PROJECTION); gl.glLoadIdentity(); double size = this.size * getZoomFactor(); if (width <= height) { gl.glOrtho(-size, size, -(size * (height / width)), (size * (height / width)), -25.0, 25.0); } else { gl.glOrtho(-(size * aspect), size * aspect, -size, size, -25.0, 25.0); } gl.glMatrixMode(GL.GL_MODELVIEW); gl.glLoadIdentity(); glu.gluLookAt(center[0], center[1], 10.0, center[0], center[1], center[2], 0.0, 1.0, 0.0); } /** * Move the center left/right, up/down, left/right * @param mv the move vector */ public void translateCenter(double [] mv) { if (mv.length == 3) { this.center[0] += mv[0]; this.center[1] += mv[1]; this.center[2] += mv[2]; } else { log.error("[translateViewMatrix] Wrong parameter size"); } } /** * Draw a grid */ protected void grid() { gl.glLineWidth(1.0f); gl.glColor3dv(GRID_COLOR); gl.glBegin(GL.GL_LINES); double size; if (aspect > 1) { size = this.size * getZoomFactor() * aspect; } else { size = this.size * getZoomFactor() / aspect; } for (int x = -(int)size; x <= (int)size; x++) { gl.glVertex3d((double) x, -size, 0.0); gl.glVertex3d((double) x, size, 0.0); } for (int y = -(int)size; y <= (int)size; y++) { gl.glVertex3d(-size, (double) y, 0.0); gl.glVertex3d(size, (double) y, 0.0); } gl.glEnd(); } /** * Draw a coordinate system */ protected void coords() { gl.glLineWidth(2.0f); gl.glBegin(GL.GL_LINES); gl.glColor3dv(X_AXIS_COLOR); gl.glVertex3d(0.0, 0.0, 0.0); gl.glVertex3d(10.0, 0.0, 0.0); gl.glColor3dv(Y_AXIS_COLOR); gl.glVertex3d(0.0, 0.0, 0.0); gl.glVertex3d(0.0, 10.0, 0.0); gl.glEnd(); } /** * Return the 3D coordinates for the canvas matching the given 2D coords * @return The relative 3D coordinates * @param coords The window coordinates */ public double[] toCanvasCoords(double[] coords) { if (coords.length == 2) { double pixelwidth, pixelheight; if (aspect < 1) { pixelheight = height / (2 * size * getZoomFactor() * (1 / aspect)); pixelwidth = width / (2 * size * getZoomFactor()); } else { pixelheight = height / (2 * size * getZoomFactor()); pixelwidth = width / (2 * size * getZoomFactor() * aspect); } double returnx = coords[0] / pixelwidth + center[0] - width / (2 * pixelwidth); double returny = -coords[1] / pixelheight + center[1] + height / (2 * pixelheight); double returnz = 0; return new double[] {returnx, returny, returnz}; } else { log.warn("Too many arguments"); return new double[] {0.0, 0.0, 0.0}; } } } --- NEW FILE: ViewXZ.java --- //--------------------------------------------------------------------------------- // $Id: ViewXZ.java,v 1.1 2005/07/26 12:43:21 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 net.java.games.jogl.GL; import net.java.games.jogl.GLDrawable; import net.java.games.jogl.GLU; import org.apache.log4j.Logger; /** * The X-Z plane view */ public class ViewXZ extends AbstractView { /** The logger */ private static Logger log = Logger.getLogger(ViewXZ.class); /** The relative center of the view */ private static double[] center = new double[] {0.0, 0.0, 0.0}; /** * The camera setup function * @param gld The GLDrawable object */ public void camera(GLDrawable gld) { if (log.isDebugEnabled()) { log.debug("[display]"); } gl = gld.getGL(); GLU glu = gld.getGLU(); // Matrix mode have to be projection for perspecive gl.glMatrixMode(GL.GL_PROJECTION); gl.glLoadIdentity(); double size = this.size * getZoomFactor(); if (width <= height) { gl.glOrtho(-size, size, -(size * (height / width)), (size * (height / width)), -25.0, 25.0); } else { gl.glOrtho(-(size * aspect), size * aspect, -size, size, -25.0, 25.0); } // MatrixMode have to be MODELVIEW for positioning gl.glMatrixMode(GL.GL_MODELVIEW); gl.glLoadIdentity(); glu.gluLookAt(center[0], -10.0, center[2], center[0], center[1], center[2], 0.0, 0.0, 1.0); } /** * Move the center left/right, up/down, left/right * @param mv the move vector */ public void translateCenter(double [] mv) { if (mv.length == 3) { this.center[0] += mv[0]; this.center[1] += mv[2]; this.center[2] += mv[1]; } else { log.error("[translateViewMatrix] Wrong parameter size"); } } /** * Draw a grid */ protected void grid() { gl.glLineWidth(1.0f); gl.glColor3dv(GRID_COLOR); gl.glBegin(GL.GL_LINES); double size; if (aspect > 1) { size = this.size * getZoomFactor() * aspect; } else { size = this.size * getZoomFactor() / aspect; } for (int x = -(int)size; x <= (int)size; x++) { gl.glVertex3d((double) x, 0.0, -size); gl.glVertex3d((double) x, 0.0, size); } for (int z = -(int)size; z <= (int)size; z++) { gl.glVertex3d(-size, 0.0, (double) z); gl.glVertex3d(size, 0.0, (double) z); } gl.glEnd(); } /** * Draw a coordinate system */ protected void coords() { gl.glLineWidth(2.0f); gl.glBegin(GL.GL_LINES); gl.glColor3dv(X_AXIS_COLOR); gl.glVertex3d(0.0, 0.0, 0.0); gl.glVertex3d(10.0, 0.0, 0.0); gl.glColor3dv(Z_AXIS_COLOR); gl.glVertex3d(0.0, 0.0, 0.0); gl.glVertex3d(0.0, 0.0, 10.0); gl.glEnd(); } /** * Return the 3D coordinates for the canvas matching the given 2D coords * @return The relative 3D coordinates * @param coords The window coordinates */ public double[] toCanvasCoords(double[] coords) { if (coords.length == 2) { double pixelwidth, pixelheight; if (aspect < 1) { pixelheight = height / (2 * size * getZoomFactor() * (1 / aspect)); pixelwidth = width / (2 * size * getZoomFactor()); } else { pixelheight = height / (2 * size * getZoomFactor()); pixelwidth = width / (2 * size * getZoomFactor() * aspect); } double returnx = coords[0] / pixelwidth + center[0] - width / (2 * pixelwidth); double returny = 0; double returnz = height / (2 * pixelheight) - coords[1] / pixelheight + center[2]; return new double[] {returnx, returny, returnz}; } else { log.warn("Too many arguments"); return new double[] {0.0, 0.0, 0.0}; } } } |
From: rimestad <rim...@us...> - 2005-07-26 12:42:11
|
Update of /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/view In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15526 Added Files: View3D.java Log Message: The 3D view --- NEW FILE: View3D.java --- //--------------------------------------------------------------------------------- // $Id: View3D.java,v 1.1 2005/07/26 12:41:58 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 net.java.games.jogl.GL; import net.java.games.jogl.GLDrawable; import net.java.games.jogl.GLU; import org.apache.log4j.Logger; /** * The 3D view */ public class View3D extends AbstractView { /** The logger */ private static Logger log = Logger.getLogger(View3D.class); /** The relative center of the view */ private static double[] center = new double[] {0.0, 0.0, 0.0}; /** The rotaion about the X axis */ private static double rotationX = 0; /** The rotation about the Y axis */ private static double rotationY = -30; /** * The camera setup function * @param gld The GLDrawable object */ public void camera(GLDrawable gld) { if (log.isDebugEnabled()) { log.debug("[display]"); } gl = gld.getGL(); GLU glu = gld.getGLU(); gl.glShadeModel(GL.GL_FLAT); gl.glMatrixMode(GL.GL_PROJECTION); gl.glLoadIdentity(); double aspect = width / height; if (aspect < 1.0) { // fovy, aspect, near, far (relative to camera position) glu.gluPerspective(aspect * 60.0, 1.0, 0.0, 50.0); } else { glu.gluPerspective(60.0, aspect, 0.0, 50.0); } gl.glMatrixMode(GL.GL_MODELVIEW); gl.glLoadIdentity(); glu.gluLookAt(0.0, 15.0 * getZoomFactor(), 20.0 * getZoomFactor(), center[0], center[1], center[2], 0.0, 1.0, 0.0); gl.glMultMatrixd(viewTrans); gl.glRotated(rotationX, 1.0, 0.0, 0.0); gl.glRotated(rotationY, 0.0, 1.0, 0.0); } /** * Move the center left/right, up/down, forward/backward * @param mv the move vector */ public void translateCenter(double [] mv) { if (mv.length == 3) { this.viewTrans[12] -= mv[0]; this.viewTrans[13] += mv[2]; this.viewTrans[14] += mv[1]; } else { log.error("[translateViewMatrix] Wrong parameter size"); } } /** * Change the rotation about the x axis * @param change The change in R+ (is divided with the window height) */ public void translateRotationX(double change) { rotationX -= change / height; } /** * Change the rotation about the y axis * @param change The change in R+ (is divided with the window height) */ public void translateRotationY(double change) { rotationY -= change / width; } /** * Draw a grid */ protected void grid() { gl.glLineWidth(1.0f); gl.glColor3dv(GRID_COLOR); gl.glBegin(GL.GL_LINES); double size = this.size; if (aspect > 1) { size *= aspect; } else { size /= aspect; } for (int x = -(int)size; x <= (int)size; x++) { gl.glVertex3d((double) x, 0.0, -size); gl.glVertex3d((double) x, 0.0, size); } for (int z = -(int)size; z <= (int)size; z++) { gl.glVertex3d(-size, 0.0, (double) z); gl.glVertex3d(size, 0.0, (double) z); } gl.glEnd(); } /** * Draw a coordinate system */ protected void coords() { gl.glLineWidth(2.0f); gl.glBegin(GL.GL_LINES); gl.glColor3dv(X_AXIS_COLOR); gl.glVertex3d(0.0, 0.0, 0.0); gl.glVertex3d(10.0, 0.0, 0.0); gl.glColor3dv(Y_AXIS_COLOR); gl.glVertex3d(0.0, 0.0, 0.0); gl.glVertex3d(0.0, 10.0, 0.0); gl.glColor3dv(Z_AXIS_COLOR); gl.glVertex3d(0.0, 0.0, 0.0); gl.glVertex3d(0.0, 0.0, 10.0); gl.glEnd(); } /** * Return the 3D coordinates for the canvas matching the given 2D coords * @return The relative 3D coordinates * @param coords The window coordinates */ public double[] toCanvasCoords(double[] coords) { if (coords.length == 2) { return new double[] {0.0, 0.0, 0.0}; } else { log.warn("Too many arguments"); return new double[] {0.0, 0.0, 0.0}; } } } |
From: rimestad <rim...@us...> - 2005-07-26 12:40:44
|
Update of /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/view In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14909 Added Files: View.java Log Message: The interfacefor views --- NEW FILE: View.java --- //--------------------------------------------------------------------------------- // $Id: View.java,v 1.1 2005/07/26 12:40:30 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 net.sourceforge.bprocessor.kernel.notification.NotificationListener; import net.sourceforge.bprocessor.model.Edge; import net.sourceforge.bprocessor.model.Vertex; import net.java.games.jogl.GLEventListener; /** * The View Interface */ public interface View extends GLEventListener, NotificationListener { /** The 3D view view */ public static final int VIEW_3D = 0; /** The x z plane view */ public static final int VIEW_XZ = 1; /** The x y plane view */ public static final int VIEW_XY = 2; /** The y z plane view */ public static final int VIEW_YZ = 3; /** * Return the 3D coordinates for the canvas matching the given 2D coords * @param coords The window coordinates * @return The relative 3D coordinates */ public double[] toCanvasCoords(double[] coords); /** * Move the center left/right, up/down, forward/backward * @param mv the move vector */ public void translateCenter(double[] mv); /** * Change the zoom factor of the camera take only R+ * 1-oo is increase zoom and 0-1 decrease 1 keep the current zoom * @param zoom the zoom factor change */ public void zoom(double zoom); /** * Change the rotation about the x axis. Only usable in 3D * @param change The change in R+ (is divided with the window height) */ public void translateRotationX(double change); /** * Change the rotation about the y axis. Only usable in 3D * @param change The change in R+ (is divided with the window height) */ public void translateRotationY(double change); /** * Set activeEdge * @param e The activeEdge */ public void setActiveEdge(Edge e); /** * Getter for activeEdge * @return activeEdge */ public Edge getActiveEdge(); /** * Setter for snapVertex * @param v The new snapVertex */ public void setSnapVertex(Vertex v); /** * Getter for snapVertex * @return snapVertex */ public Vertex getSnapVertex(); /** * Setter for alignVertex * @param v The new alignVertex */ public void setAlignVertex(Vertex v); /** * Getter for alignVertex * @return alignVertex */ public Vertex getAlignVertex(); /** * Setter for alignPoint * @param coord The new alignPoint */ public void setAlignPoint(double[] coord); /** * Getter for alignPoint * @return alignPoint */ public double[] getAlignPoint(); } |
From: rimestad <rim...@us...> - 2005-07-26 12:38:04
|
Update of /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13885 Added Files: package.html Log Message: package information --- NEW FILE: package.html --- <body> Defines the package that contains the key and mouse tools for the 3D view (GL) </body> |
From: rimestad <rim...@us...> - 2005-07-26 12:37:42
|
Update of /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13819 Added Files: ToolFactory.java Log Message: A factory for generating tools --- NEW FILE: ToolFactory.java --- //--------------------------------------------------------------------------------- // $Id: ToolFactory.java,v 1.1 2005/07/26 12:37:23 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.tool; import net.sourceforge.bprocessor.gl.GLView; import org.apache.log4j.Logger; /** * A factory for tools */ public class ToolFactory { /** The logger */ private static Logger log = Logger.getLogger(ToolFactory.class); /** The factory */ private static ToolFactory factory; /** draw tool */ private Tool draw; /** select tool */ private Tool select; /** * Constructor * @param glv the GLView */ private ToolFactory(GLView glv) { draw = new DrawTool(glv); select = new SelectTool(glv); } /** * Get the factory * @param glv The GLView * @return The factory */ public static synchronized ToolFactory getFactory(GLView glv) { if (factory == null) { factory = new ToolFactory(glv); } return factory; } /** * Get the default tool * @return The tool */ public Tool getDefault() { return get(Tool.SELECT_TOOL); } /** * Get the tool i if it is a legal tool * @param i The tool number * @return The tool */ public Tool get(int i) { if (i == Tool.SELECT_TOOL) { return select; } else if (i == Tool.DRAW_TOOL) { return draw; } else { log.error("[get] No such tool " + i); return null; } } } |
From: rimestad <rim...@us...> - 2005-07-26 12:36:20
|
Update of /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13506 Added Files: Tool.java Log Message: The interface for tools --- NEW FILE: Tool.java --- //--------------------------------------------------------------------------------- // $Id: Tool.java,v 1.1 2005/07/26 12:36:11 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.tool; import java.awt.event.KeyListener; import java.awt.event.MouseListener; import java.awt.event.MouseMotionListener; /** * The tool interface */ public interface Tool extends MouseListener, MouseMotionListener, KeyListener { /** The select tool */ public static final int SELECT_TOOL = 0; /** The draw tool */ public static final int DRAW_TOOL = 1; } |
From: rimestad <rim...@us...> - 2005-07-26 12:35:55
|
Update of /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13420 Added Files: DrawTool.java Log Message: Implements tools for surface drawing --- NEW FILE: DrawTool.java --- //--------------------------------------------------------------------------------- // $Id: DrawTool.java,v 1.1 2005/07/26 12:35:44 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.tool; import net.sourceforge.bprocessor.model.Edge; import net.sourceforge.bprocessor.model.Surface; import net.sourceforge.bprocessor.model.Vertex; import net.sourceforge.bprocessor.model.VertexFacade; import net.sourceforge.bprocessor.gl.view.View; import net.sourceforge.bprocessor.gl.GLView; import java.awt.event.MouseEvent; import java.util.HashSet; import java.util.Iterator; import java.util.Set; import org.apache.log4j.Logger; /** * The abstracttool */ public class DrawTool extends AbstractTool { /** The logger */ private static Logger log = Logger.getLogger(DrawTool.class); /** The current Edge list */ private Set edges; /** * KeyListener for the GL Canvas * @param glv The 3D canvas */ public DrawTool(GLView glv) { super(glv); edges = new HashSet(); } /** * Invoked when the mouse cursor has been moved * @param e The MouseEvent object */ protected void moved(MouseEvent e) { int x = e.getX(); int y = e.getY(); View v = glv.getView(); double[] coord = v.toCanvasCoords(new double[] {x, y}); coord = snapToGrid(coord); // snap to vertexes coord = aligned(coord); //check for snap point change checkVertexSnap(coord); //change the activeEdge according to mouse position changeTo(coord); } /** * Invoked when the mouse is held pressed and moved * @param e The MouseEvent object */ protected void dragged(MouseEvent e) { } /** * Invoked when a mouse button has been pressed on a component. * @param e The MouseEvent object */ protected void pressed(MouseEvent e) { int currentButton = e.getButton(); View v = glv.getView(); double[] coords = v.toCanvasCoords(new double[]{pressPos[0], pressPos[1]}); // snap to grid coords = snapToGrid(coords); // snap to vertex coords = aligned(coords); if (log.isDebugEnabled()) { log.debug("[mousePressed] " + currentButton + "coords(" + coords[0] + ", " + coords[1] + ", " + coords[2] + ")"); } if (e.getClickCount() >= 2) { if (currentButton == MouseEvent.BUTTON1) { // double click on Button1 => surface end endSurface(coords); } } else { // we did not double click if (currentButton == MouseEvent.BUTTON1) { addEdge(coords); } } removeVertexSnap(); } /** * Invoked when a mouse button has been released on a component. * @param e The MouseEvent */ protected void released(MouseEvent e) { } /** * Add the last edge to the edgelist => surface * @param coord The end coordinate */ protected void endSurface(double[] coord) { Edge activeEdge = glv.getView().getActiveEdge(); if (activeEdge != null) { Vertex to = vertexCollide(coord); if (to != null) { // we have to change excisting surface removeVertex(activeEdge.getTo()); activeEdge.setTo(to); updateEdge(activeEdge); } else { to = activeEdge.getTo(); updateVertex(to, coord); } Surface s = createSurface(edges); glv.getView().setAlignVertex(null); glv.getView().setActiveEdge(null); edges = new HashSet(); } } /** * Add an edge to the parent edgelist * @param coord The to point */ protected void addEdge(double[] coord) { if (edges.isEmpty()) { Vertex from = createVertex(coord); Vertex to = createVertex(coord); Edge activeEdge = createEdge(to, from); glv.getView().setActiveEdge(activeEdge); edges.add(activeEdge); glv.getView().setAlignVertex(null); } else { if (vertexCollide(coord) == null) { // we did not end an edgelist Edge activeEdge = glv.getView().getActiveEdge(); Vertex from = activeEdge.getTo(); Vertex to = createVertex(coord); activeEdge = createEdge(to, from); glv.getView().setActiveEdge(activeEdge); edges.add(activeEdge); glv.getView().setAlignVertex(null); } else { // we did end a edgelist endSurface(coord); } } } /** * Change the to vertex coordinates for the active edge * @param coord The new coordinate */ protected void changeTo(double[] coord) { Edge activeEdge = glv.getView().getActiveEdge(); if (activeEdge != null && !edges.isEmpty()) { Vertex v = activeEdge.getTo(); updateVertex(v, coord); } } /** * Check if this cordinate collide with another vertex * @param coord The cordinate to check for collision at * @return The excisting vertex at coord, null if there ain't any */ protected Vertex vertexCollide(double[] coord) { Set vertexes = VertexFacade.getInstance().findAll(); Iterator it = vertexes.iterator(); Edge e = glv.getView().getActiveEdge(); while (it.hasNext()) { Vertex v = (Vertex)it.next(); if (collide(v.getX(), coord[0]) && collide(v.getY(), coord[1]) && collide(v.getZ(), coord[2]) && e != null && v != e.getTo() && v != e.getFrom()) { return v; } } return null; } /** * Check if a and b is as close as EPSILON * @param a The target * @param b The value * @return true if |a - b| < EPSILON false otherwise */ protected boolean collide(double a, double b) { return Math.abs(a - b) < EPSILON; } /** * Check if the current point is a vertex if so, it registers the vertex as * snapVertex and alignVertex in the AbstractListener. * @param coord the cordinate to check for snap (x, y, z) */ protected void checkVertexSnap(double[] coord) { Vertex v = vertexCollide(coord); View view = glv.getView(); Edge e = view.getActiveEdge(); if (v != null && v != view.getActiveEdge().getTo() && v != view.getActiveEdge().getFrom()) { view.setAlignVertex(v); view.setSnapVertex(v); } else { removeVertexSnap(); } } /** * Set the snapVertex variable to null */ protected void removeVertexSnap() { glv.getView().setSnapVertex(null); } /** * Check if v is aligned horizontally or vertically with alignVertex * @param coord The coordinate to check for alignment with * @return The alignmentpoint, if there ain't any the original point is returned */ protected double[] aligned(double[] coord) { double[] res = new double[] {coord[0], coord[1], coord[2]}; Vertex v = glv.getView().getAlignVertex(); if (v != null) { if (Math.abs(coord[0] - v.getX()) < EPSILON) { res[0] = v.getX(); } if (Math.abs(coord[1] - v.getY()) < EPSILON) { res[1] = v.getY(); } if (Math.abs(coord[2] - v.getZ()) < EPSILON) { res[2] = v.getZ(); } if (res[0] != coord[0] && res[1] != coord[1] && res[2] != coord[2]) { glv.getView().setAlignPoint(null); return coord; } else { glv.getView().setAlignPoint(res); return res; } } glv.getView().setAlignPoint(null); return coord; } } |
From: rimestad <rim...@us...> - 2005-07-26 12:34:20
|
Update of /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13185 Added Files: SelectTool.java Log Message: Implements tools for selection --- NEW FILE: SelectTool.java --- //--------------------------------------------------------------------------------- // $Id: SelectTool.java,v 1.1 2005/07/26 12:34:09 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.tool; import net.sourceforge.bprocessor.gl.GLView; import net.sourceforge.bprocessor.gl.view.View; import net.sourceforge.bprocessor.kernel.notification.Notification; import net.sourceforge.bprocessor.kernel.notification.Notifier; import net.sourceforge.bprocessor.model.Vertex; import net.sourceforge.bprocessor.model.VertexFacade; import java.awt.event.MouseEvent; import java.util.Iterator; import java.util.Set; import org.apache.log4j.Logger; /** * The abstracttool */ public class SelectTool extends AbstractTool { /** The logger */ private static Logger log = Logger.getLogger(SelectTool.class); /** * KeyListener for the GL Canvas * @param glv The 3D canvas */ public SelectTool(GLView glv) { super(glv); } /** * Invoked when the mouse cursor has been moved * @param e The MouseEvent object */ protected void moved(MouseEvent e) { } /** * Invoked when the mouse is held pressed and moved * @param e The MouseEvent object */ protected void dragged(MouseEvent e) { } /** * Invoked when a mouse button has been pressed on a component. * @param e The MouseEvent object */ protected void pressed(MouseEvent e) { } /** * Invoked when a mouse button has been released on a component. * @param e The MouseEvent */ protected void released(MouseEvent e) { if (e.getButton() == MouseEvent.BUTTON1) { int x = e.getX(); int y = e.getY(); View view = glv.getView(); double[] coords = view.toCanvasCoords(new double[]{x, y}); Vertex v = vertexCollide(coords); if (v != null) { Notification n = new Notification(Notification.VERTEX_SELECTED, v.getId()); Notifier.getInstance().sendNotification(n); } } } /** * Check if this cordinate collide with another vertex * @param coord The cordinate to check for collision at * @return The excisting vertex at coord, null if there ain't any */ protected Vertex vertexCollide(double[] coord) { Set vertexes = VertexFacade.getInstance().findAll(); Iterator it = vertexes.iterator(); while (it.hasNext()) { Vertex v = (Vertex)it.next(); if (collide(v.getX(), coord[0]) && collide(v.getY(), coord[1]) && collide(v.getZ(), coord[2])) { return v; } } return null; } /** * Check if a and b is as close as EPSILON * @param a The target * @param b The value * @return true if |a - b| < EPSILON false otherwise */ protected boolean collide(double a, double b) { return Math.abs(a - b) < EPSILON; } } |
From: rimestad <rim...@us...> - 2005-07-26 12:33:48
|
Update of /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13069 Added Files: AbstractTool.java Log Message: Implements common methods for all tools --- NEW FILE: AbstractTool.java --- //--------------------------------------------------------------------------------- // $Id: AbstractTool.java,v 1.1 2005/07/26 12:33:39 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.tool; import net.sourceforge.bprocessor.kernel.notification.Notifier; import net.sourceforge.bprocessor.kernel.notification.Notification; import net.sourceforge.bprocessor.model.Edge; import net.sourceforge.bprocessor.model.EdgeFacade; import net.sourceforge.bprocessor.model.Surface; import net.sourceforge.bprocessor.model.SurfaceFacade; import net.sourceforge.bprocessor.model.Vertex; import net.sourceforge.bprocessor.model.VertexFacade; import net.sourceforge.bprocessor.gl.view.View; import net.sourceforge.bprocessor.gl.GLView; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.KeyEvent; import java.awt.event.MouseEvent; import java.util.Set; import javax.swing.Timer; import org.apache.log4j.Logger; /** * The abstracttool */ public abstract class AbstractTool implements Tool { /** The logger */ private static Logger log = Logger.getLogger(AbstractTool.class); /** The mouse position last time the mouse was pressed initializes to (0,0) */ protected int[] pressPos = new int[2]; /** The mouse movement in x axis since press */ protected int dx = 0; /** The mouse movement in y axis since press */ protected int dy = 0; /** An vertex counter */ private static long vertexNum = 0; /** An edge counter */ private static long edgeNum = 0; /** An surface counter */ private static long surfaceNum = 0; /** The snap variable */ protected static final double EPSILON = 0.4; /** The zoom action listener */ private ActionListener zoomAction; /** The move action listener */ private ActionListener moveAction; /** The carmera move timer */ private Timer timer; /** The 3DView */ protected GLView glv = null; /** * KeyListener for the GL Canvas * @param glv The 3D canvas */ public AbstractTool(GLView glv) { this.glv = glv; timer = new Timer(10, null); timer.start(); moveAction = new CameraMoveTimer(this, glv); zoomAction = new CameraZoomTimer(this, glv); } /** * Invoked when a key has been pressed. * @param e The KeyEvent */ public void keyPressed(KeyEvent e) { View v = glv.getView(); if (e.getKeyCode() == KeyEvent.VK_UP) { v.translateCenter(new double[] {0.0, 1.0, 0.0}); } else if (e.getKeyCode() == KeyEvent.VK_DOWN) { v.translateCenter(new double[] {0.0, -1.0, 0.0}); } else if (e.getKeyCode() == KeyEvent.VK_LEFT) { v.translateCenter(new double[] {-1.0, 0.0, 0.0}); } else if (e.getKeyCode() == KeyEvent.VK_RIGHT) { v.translateCenter(new double[] {1.0, 0.0, 0.0}); } else if (e.getKeyChar() == KeyEvent.VK_COMMA) { v.zoom(1.1); } else if (e.getKeyChar() == KeyEvent.VK_PERIOD) { v.zoom(0.9); } else if (e.getKeyCode() == KeyEvent.VK_Q) { glv.changeTool(Tool.SELECT_TOOL); } else if (e.getKeyCode() == KeyEvent.VK_W) { glv.changeTool(Tool.DRAW_TOOL); } glv.repaint(); } /** * Invoked when a key has been released. * @param e The KeyEvent */ public void keyReleased(KeyEvent e) { if (e.getKeyChar() == KeyEvent.VK_1) { glv.changeView(View.VIEW_3D); } else if (e.getKeyChar() == KeyEvent.VK_2) { glv.changeView(View.VIEW_XZ); } else if (e.getKeyChar() == KeyEvent.VK_3) { glv.changeView(View.VIEW_XY); } else if (e.getKeyChar() == KeyEvent.VK_4) { glv.changeView(View.VIEW_YZ); } } /** * Invoked when a key has been typed. * @param e The KeyEvent */ public void keyTyped(KeyEvent e) { } /** * Invoked when a mouse button is held down while moving the mouse * @param e The MouseEvent object */ public void mouseDragged(MouseEvent e) { int x = e.getX(); int y = e.getY(); if (e.getButton() == MouseEvent.BUTTON3) { this.dx = x - pressPos[0]; this.dy = y - pressPos[1]; } dragged(e); glv.repaint(); } /** * Invoked when the mouse cursor has been moved * @param e The MouseEvent object */ public void mouseMoved(MouseEvent e) { moved(e); glv.repaint(); } /** * Invoked when the mouse button has been clicked (pressed and released) on a component. * @param e The MouseEvent object */ public void mouseClicked(MouseEvent e) { } /** * Invoked when the mouse enters a component. * @param e The MouseEvent object */ public void mouseEntered(MouseEvent e) { } /** * Invoked when the mouse exits a component. * @param e The MouseEvent object */ public void mouseExited(MouseEvent e) { } /** * Invoked when a mouse button has been pressed on a component. * @param e The MouseEvent object */ public void mousePressed(MouseEvent e) { int currentButton = e.getButton(); pressPos[0] = e.getX(); pressPos[1] = e.getY(); if (currentButton == MouseEvent.BUTTON2) { timer.addActionListener(zoomAction); } else if (currentButton == MouseEvent.BUTTON3) { timer.addActionListener(moveAction); } pressed(e); glv.repaint(); } /** * Invoked when a mouse button has been released on a component. * @param e The MouseEvent */ public void mouseReleased(MouseEvent e) { int currentButton = e.getButton(); if (currentButton == MouseEvent.BUTTON3) { timer.removeActionListener(moveAction); this.dx = 0; this.dy = 0; } else if (currentButton == MouseEvent.BUTTON2) { timer.removeActionListener(zoomAction); this.dx = 0; this.dy = 0; } released(e); glv.repaint(); } /** * @return The x distance the mouse has moved since press */ protected int getdx() { return dx; } /** * @return The y distance the mouse has moved since press */ protected int getdy() { return dy; } /** * Take a coordinate and check if it should snap to grid * @param coords The coordinates to check for snapping * @return the snapped coordinates */ protected double[] snapToGrid(double[] coords) { if (Math.abs(coords[0] - Math.round(coords[0])) < EPSILON) { coords[0] = Math.round(coords[0]); } if (Math.abs(coords[1] - Math.round(coords[1])) < EPSILON) { coords[1] = Math.round(coords[1]); } if (Math.abs(coords[2] - Math.round(coords[2])) < EPSILON) { coords[2] = Math.round(coords[2]); } return coords; } /** * Make and register a new vertex * @param coord The coordinates to create with * @return The new Vertex */ protected Vertex createVertex(double[] coord) { if (coord.length == 3) { Vertex v = new Vertex("V" + vertexNum); vertexNum++; VertexFacade.getInstance().add(v); v.setX(coord[0]); v.setY(coord[1]); v.setZ(coord[2]); Notification n = new Notification(Notification.VERTEX_CREATED, v.getId()); Notifier.getInstance().sendNotification(n); return v; } else { log.error("[createVertex] wrong argument length was: " + coord.length); return null; } } /** * Update the coordinates of the vertex v * @param v The vertex to change coordinates on * @param coord The new coordinates */ protected void updateVertex(Vertex v, double[] coord) { if (coord.length == 3) { v.setX(coord[0]); v.setY(coord[1]); v.setZ(coord[2]); Notification n = new Notification(Notification.VERTEX_MODIFIED, v.getId()); Notifier.getInstance().sendNotification(n); } else { log.error("[updateVertex] wrong argument length was: " + coord.length); } } /** * Remove a vertex for good * @param v Vertex to remove */ protected void removeVertex(Vertex v) { VertexFacade.getInstance().remove(v); Notification n = new Notification(Notification.VERTEX_DELETED, v.getId()); Notifier.getInstance().sendNotification(n); } /** * Make and register a new edge * @param to the to vertex * @param from the from vertex * @return The new Edge */ protected Edge createEdge(Vertex to, Vertex from) { Edge e = new Edge("E" + edgeNum); edgeNum++; EdgeFacade.getInstance().add(e); e.setTo(to); e.setFrom(from); Notification n = new Notification(Notification.EDGE_CREATED, e.getId()); Notifier.getInstance().sendNotification(n); return e; } /** * Updates the edge * @param e The edge to update */ protected void updateEdge(Edge e) { Notification n = new Notification(Notification.EDGE_MODIFIED, e.getId()); Notifier.getInstance().sendNotification(n); } /** * Make and register a new Surface * @param set The set of edges in the surface * @return The new Surface */ protected Surface createSurface(Set set) { Surface s = new Surface("S" + surfaceNum); surfaceNum++; SurfaceFacade.getInstance().add(s); s.setEdges(set); Notification n = new Notification(Notification.SURFACE_CREATED, s.getId()); Notifier.getInstance().sendNotification(n); return s; } /** * Invoked when the mouse cursor has been moved * @param e The MouseEvent object */ protected abstract void moved(MouseEvent e); /** * Invoked when the mouse is held pressed and moved * @param e The MouseEvent object */ protected abstract void dragged(MouseEvent e); /** * Invoked when a mouse button has been pressed on a component. * @param e The MouseEvent object */ protected abstract void pressed(MouseEvent e); /** * Invoked when a mouse button has been released on a component. * @param e The MouseEvent */ protected abstract void released(MouseEvent e); /** * Carama move timer class */ private class CameraMoveTimer implements ActionListener { /** The calling mouselistener */ private AbstractTool at; /** The current GLView */ private GLView glv; /** * The Constructor * @param at the abstract tool * @param glv the GLView */ public CameraMoveTimer(AbstractTool at, GLView glv) { this.at = at; this.glv = glv; } /** * executed every time camaraMove is sceduled * @param e The ActionEvent */ public void actionPerformed(ActionEvent e) { View v = glv.getView(); v.translateRotationX(at.getdy()); v.translateRotationY(at.getdx()); glv.repaint(); } } /** * Camara zoom timer */ private class CameraZoomTimer implements ActionListener { /** The calling mouselistener */ private AbstractTool at; /** The current GLView */ private GLView glv; /** * The Constructor * @param at the abstract tool * @param glv the GLView */ public CameraZoomTimer(AbstractTool at, GLView glv) { this.at = at; this.glv = glv; } /** * executed every time camaraMove is sceduled * @param e The ActionEvent */ public void actionPerformed(ActionEvent e) { View v = glv.getView(); if (at.getdy() > 0) { v.zoom(0.9); } else { v.zoom(1.0); } glv.repaint(); } } } |
From: rimestad <rim...@us...> - 2005-07-26 12:28:03
|
Update of /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/view In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11741/view Log Message: Directory /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/view added to the repository |
From: rimestad <rim...@us...> - 2005-07-26 12:27:44
|
Update of /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11675/tool Log Message: Directory /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool added to the repository |