|
Creating your own Cylinder using TriangleStripArray |
|
|
The GeometryStripArray is an abstract class from which strip primitives (for
creating compound lines and surfaces) are derived. GeometryStripArray is the
superclass of LineStripArray, TriangleStripArray,and TriangleFanArray.
This program shows how to use a TriangleFanArray object to model the geometry
of a Cone. The TriangleFanArray contains four independent fans: two exterior
faces(circular disks) and two internal faces (cones). Only one TriangleFanArray
object is needed to represent the four fans.
public class OwnCylinder extends JFrame{
public OwnCylinder() {
...
}
/**
* Create the geometry for the cylinder
*/
private Geometry createGeometry() {
float height = 0.5f;
float radius = 0.1f;
int verticesNum = 40;
float[] vertices = new float[verticesNum * 3];
float perR = (float) (2 * Math.PI / (verticesNum / 2 - 1));
for (int i = 0; i < verticesNum; i += 2) {
vertices[(i + 1) * 3] = vertices[i * 3] = (float) (radius * Math
.cos(i / 2 * perR));
vertices[(i + 1) * 3 + 2] = vertices[i * 3 + 2] = (float) (radius * Math
.sin(i / 2 * perR));
vertices[i * 3 + 1] = height;
vertices[(i + 1) * 3 + 1] = 0;
}
TriangleStripArray quadArray = new TriangleStripArray(verticesNum,
GeometryArray.COORDINATES,new int[] { verticesNum });
quadArray.setCoordinates(0, vertices);
return quadArray;
}
public BranchGroup createSceneGraph() {
BranchGroup objRoot = new BranchGroup();
// Add the cylinder
objRoot.addChild(new Shape3D(createGeometry()));
return objRoot;
}
public static void main(String[] args) {
...
}
}
|
Related Tips
|
Page 1 of 0 ( 0 comments )
You can share your information about this topic using the form below!
Please do not post your questions with this form! Thanks.