Basic shape rendering can be done using some of the default shape rendering nodes.
The sphere is approximated by triangles. The number of triangles depends on a precision parameter.
The sphere node constructor has the following parameters :
precision : define the number of points which are used on a single circle. The higher this parameter goes, the better the sphere is approximated.
radius : the radius value in model unit.
origin : the sphere centre coordinates.
Sample code
//Create a pink sphere//create an attribute to define the color cgGraphicAttribute attr = new cgGraphicAttribute(); attr.setFillColor(Color.PINK); // Build a sphere node with a precision of 40 (one circle of the sphere is composed with 40 vertices), a radius of 1 and a position of (0,0,0). cgJOGL3DSphereNode sphere = new cgJOGL3DSphereNode(40, 1., new Point3d(0, 0, 0)); //set the attribute on the sphere sphere.setAttribute(attr); //add the sphere to the scene graph parent.addNode(sphere);
Sample code
//Create a cyan box//create an attribute to define the color cgGraphicAttribute attr = new cgGraphicAttribute(); attr.setFillColor(Color.CYAN); // Build a box node centered on the point (5,5,5) with a size of 2 along X axis, 3 along Y axis and 4 along Z axis cgJOGL3DBoxNode box = new cgJOGL3DBoxNode(new Point3d(5, 5, 5), 2, 3, 4); //set the attribute on the box box.setAttribute(attr); //add the box to the scene graph parent.addNode(box);
The cylinder is approximated by triangles. The number of triangles depends on precision parameters.
Sample code
//Create a magenta cylinder box//create an attribute to define the color cgGraphicAttribute attr = new cgGraphicAttribute(); attr.setFillColor(Color.MAGENTA); // Build a cylinder with a precision of 12, a radius of 2, an height of 4, a position of (10,10,-8) and an orientation of (1,1,1). cgJOGL3DCylinderNode cylinder = new cgJOGL3DCylinderNode(12, 2, 4, new Point3d(10, 10, -8), new Vector3d(1, 1, 1)); //add the cylinder to the scene graph parent.addNode(cylinder)
The polygon node allows the user to draw polygon and textured polygon.
Sample code
// Build a polygon float[] xcoords = new float[] { -10, 0, 3, -15 }; float[] ycoords = new float[] { -5, -3, 8, 11 }; float[] zcoords = new float[] { -15, -16, -18, -17 }; cgJOGL3DPolygonNode simplePolygon = new cgJOGL3DPolygonNode(xcoords, ycoords, zcoords, null, null, null); //Build a textured polygon BufferedImage texture = ImageIO.read(textureFile); float[] xcoords = new float[] { -10, 0, 0, -10 }; float[] ycoords = new float[] { -5, -5, 5, 5 }; float[] zcoords = new float[] { 0, 0, 0, 0 }; float[] sTexCoords = new float[]{0,1,1,0}; float[] tTexCoords = new float[]{0,0,1,1}; cgJOGL3DPolygonNode texturedPolygon = new cgJOGL3DPolygonNode(xcoords, ycoords, zcoords, texture, sTexCoords, tTexCoords);