Skip to Main Content
Killer Game Programming in Java
book

Killer Game Programming in Java

by Andrew Davison
May 2005
Intermediate to advanced content levelIntermediate to advanced
998 pages
26h
English
O'Reilly Media, Inc.
Content preview from Killer Game Programming in Java

Floating Spheres

Sphere is a utility class from Java 3D's com.sun.j3d.utils.geometry package, a subclass of the Primitive class, which is a Group node with a Shape3D child (see Figure 15-3). Its geometry is stored in a Java 3D TriangleStripArray, which specifies the sphere as an array of connected triangles. I don't have to adjust this geometry, but the sphere's appearance and position do require changes.

The Appearance node is a container for references of to much information, including coloring , line, point, polygon, rendering, transparency, and texture attributes.

ColouringAttributes fixes the color of a shape and is unaffected by scene lighting. For a shape requiring interaction between color and light, the Material component is employed. For light to affect a shape's color, three conditions must be met:

  • The shape's geometry must include normals.

  • The shape's Appearance node must have a Material component.

  • The Material component must have enabled lighting with setLightingEnable().

The utility Sphere class can automatically creates normals, so the first condition is easily satisfied.

Coloring the Spheres

The Java 3D Material component controls what color a shape exhibits when lit by different kinds of lights:

    Material mat = new Material(ambientColor, emissiveColor,
                                diffuseColor, specularColor, shininess);

The ambient color argument specifies the shape's color when lit by ambient light: this gives the object a uniform color. The emissive color contributes the color that the shape produces ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Java Game Development with LibGDX: From Beginner to Professional

Java Game Development with LibGDX: From Beginner to Professional

Lee Stemkoski

Publisher Resources

ISBN: 0596007302Supplemental ContentErrata Page