## With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

No credit card required

# The Lathe Shape

A `LatheShape3D` object first creates a lathe curve using the points supplied by the user and then decorates it with color or a texture. The choice between color and texture is represented by two constructors:

```    public LatheShape3D(double xsIn[], double ysIn[], Texture tex)
{ LatheCurve lc = new LatheCurve(xsIn, ysIn);
buildShape(lc.getXs(), lc.getYs(), lc.getHeight(), tex);
}

public LatheShape3D(double xsIn[], double ysIn[],
Color3f darkCol, Color3f lightCol)
// two colors required: a dark and normal version of the color
{ LatheCurve lc = new LatheCurve(xsIn, ysIn);
buildShape(lc.getXs(), lc.getYs(), lc.getHeight(),
darkCol, lightCol);
}```

Both versions of `buildShape()` call `createGeometry()` to build a `QuadArray` for the shape. Then the four-argument version of `buildShape()` lays down a texture, and the five-argument version calls `createAppearance()` to add color.

## Creating the Geometry

`createGeometry()` passes the lathe curve coordinates to `surfaceRevolve()`, which returns the coordinates of the resulting shape. The coordinates are used to initialize a `QuadArray`, complete with normals (to reflect light) and texture coordinates if a texture is going to be wrapped around the shape:

` private void createGeometry(double[] xs, double[] ys, boolean usingTexture) { double verts[] = surfaceRevolve(xs, ys); // use GeometryInfo to compute normals GeometryInfo geom = new GeometryInfo(GeometryInfo.QUAD_ARRAY); geom.setCoordinates(verts); if (usingTexture) { geom.setTextureCoordinateParams(1, ...`

## With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

No credit card required