O'Reilly logo

Killer Game Programming in Java by Andrew Davison

Stay ahead with the world's most comprehensive technology and business learning platform.

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

Start Free Trial

No credit card required

Chapter 17. Using a Lathe to Make Shapes

I've run up against the lack of useful shapes in Java 3D many times: there's only so much that can be done with the Box, Cone, Cylinder, and Sphere classes. One way of getting past this limitation is to use Java 3D's GeometryArray (or one of its subclasses) to specify a geometry in terms of separate arrays of positional coordinates, colors, normals, and texture coordinates. This is pretty daunting, and I like to avoid it if possible.

An alternative to this low-level shape building is to follow the approach outlined in Chapter 16: create the shape in a 3D modeling package and load it into Java 3D. The drawback is that you need to learn the modeling software. Most of these packages have so many bells and whistles that it's hard to get what you need done.

This chapter describes a compromise between the complexity of Java 3D GeometryArrays and the loading of ready-made models. The edge of a shape is defined in terms of straight lines and simple curves. This edge (or lathe curve) is rotated around the y-axis to create a 3D volume, called a lathe shape. This approach, often called surface or sweep revolution, is packaged up in a LatheShape3D class.

Color or texture information can be added easily. A lathe shape is pink by default, but this can be changed to a different color or texture. In both cases, the shape will reflect light (i.e., a shape's faces always have normals). A color is defined using two Color3f objects: one for ambient illumination ...

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

Start Free Trial

No credit card required