JCarnac3D-OGL provides a ready to use grid and axis shape : cgJOGL3DAxisGridBoxNode
This shape node implements an auto adaptive algorithm to refine the grid/axes depending on the zoom factor. It also tries to show the grid in the back of the view to avoid hiding other par of the model.
Note that this axis node can be inserted anywhere in the scene graph and that you can have several grids in a single view.
Sample code
// create a number format for the axes labels. NumberFormat format = DecimalFormat.getInstance(); format.setMaximumFractionDigits(2); cgAxisLabelFormatter formatter = new cgAxisLabelFormatterAdapter(format); //create the grid and axes node. cgJOGL3DAxisGridBoxNode grid = new cgJOGL3DAxisGridBoxNode( 0, 0, 0, 100, 100, 100,//bounding box minX, minY, minZ, maxX, maxY, maxZ new NumericAdaptiveTickGenerator(50),//x axis tick generator (with 50 pixels gap) new NumericAdaptiveTickGenerator(50),//y axis tick generator (with 50 pixels gap) new NumericAdaptiveTickGenerator(50),//z axis tick generator (with 50 pixels gap) 10, 20, 0,//x axis tick size, label size and gap size 10, 20, 0,//y axis tick size, label size and gap size 10, 20, 0,//z axis tick size, label size and gap size formatter, formatter, formatter,//formatters for x,y and z axis. "X", 40, 150,//x axis title, size and gap between title and axis line "Y", 40, 150,//y axis title, size and gap between title and axis line "Z", 40, 150);//z axis title, size and gap between title and axis line // set grid attributes. Here we set the same attributes for all parameters (label, lines) cgGraphicAttribute attr = new cgGraphicAttribute(); attr.setLineColor(Color.black); attr.setLineWidth(2); attr.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 14)); grid.setXAxisAttribute(attr); grid.setXGridLinesAttribute(attr); grid.setXAxisAnnotationAttribute(attr); grid.setXAxisTitleAttribute(attr); grid.setYAxisAttribute(attr); grid.setYGridLinesAttribute(attr); grid.setYAxisAnnotationAttribute(attr); grid.setYAxisTitleAttribute(attr); grid.setZAxisAttribute(attr); grid.setZGridLinesAttribute(attr); grid.setZAxisAnnotationAttribute(attr); grid.setZAxisTitleAttribute(attr); //at last, insert the grid node into the scene graph rootNode.addNode(grid);