< Zurück | Inhalt

C.3 GeomBuffer

Java 3D programmers coming from an OpenGL background will recognize much of the code used to define the vertices and normal vectors of the Box primitive, defined in com.sun.j3d.utils.geometry.Box.

GeomBuffer gbuf = new GeomBuffer(4);

//extract of code to generate the geometry of a Box gbuf.begin(GeomBuffer.QUAD_STRIP);

gbuf.normal3d( (double) normals[i].x*sign, (double) normals[i].y*sign, (double) normals[i].z*sign);

gbuf.texCoord2d(tcoords[i*8 + j*2], tcoords[i*8 + j*2 + 1]); gbuf.vertex3d( (double) verts[i*12 + j*3]*xdim, (double) verts[i*12+ j*3 + 1]*ydim,

(double) verts[i*12+ j*3 + 2]*zdim ); gbuf.end();

//create a Shape3D object to wrap the GeomBuffer Shape3D shape =

new Shape3D( gbuf.getGeom( GeomBuffer.GENERATE_NORMALS ) );

The GeomBuffer class has been designed to allow OpenGL programmers to quickly and easily generate Java 3D geometry in a manner similar to defining an OpenGL display list (for example). In the preceding example a GeomBuffer is created to hold four vertices defined as a quad strip which draws a connected group of quadrilaterals. One quadrilateral is defined for each pair of vertices presented after the first pair. Vertices 2n − 1, 2n, 2n + 2, and 2n + 1 define quadrilateral n, and n quadrilaterals are drawn.

The GeomBuffer class is used in many of the classes derived from Primitive since, I suspect, this code has been ported from an OpenGL−based implementation and the GeomBuffer was created to simplify porting.

int QUAD_STRIP = 0x01; int TRIANGLES = 0x02; int QUADS = 0x04;

At present, an instance of a GeomBuffer can contain only a single primitive type; that is, one cannot mix quad strips and Triangles (for example) in a single GeomBuffer.

Except for a bug that causes the GeomBuffer to generate a TriangleStripArray for a QUAD_STRIP instead of a QuadStripArray, the class is easy to use and allows OpenGL code to be quickly inserted into a Java 3D application.



Angell, Ian. High Resolution Computer Graphics Using C. Halstead Press, 1990. Arvo, James (ed.). Graphics Gems II. Academic Press, 1991.

Barrilleaux, Jon. 3D User Interfaces with Java 3D. Manning Publications, 2000. DeLoura, Mark, ed. Game Programming Gems, Charles River Media, 2000.

DeLoura, Mark, ed. Game Programming Gems 2, Charles River Media, 2001.

Eberly, David H. 3D Game Engine Design : A Practical Approach to Real−Time Computer Graphics, Morgan−Kaufmann, 2000.

Ebert, David, et al. Texturing and Modeling: A Procedural Approach. Academic Press, 1994. Foley, J.D., et al. Computer Graphics: Principles and Practice, 2nd ed. Addison−Wesley, 1990. Foley, J.D., et al. Introduction to Computer Graphics, Addison−Wesley, 1993.

Glaeser, Georg. Fast Algorithms for 3D Graphics. Springer−Verlag, 1994. Glassner, Andrew (ed.). Graphics Gems. Academic Press, 1990.

Glassner, Andrew, Principles of Digital Image Synthesis, Vols. 1 and 2. Morgan−Kaufman, 1995. Gonzalez, Rafael and Richard Woods. Digital Image Processing. Addison−Wesley, 1992.

Harrington, Steve. Computer Graphics: A Programming Approach, 2nd ed. McGraw−Hill, 1987. Heckbert, Paul. Graphics Gems IV. Academic Press, 1994.

Hoffman, Christoph. Geometric and Solid Modeling: An Introduction. Morgan−Kaufman, 1989. Kirk, David (ed.). Graphics Gems III. Academic Press, 1992.

Laszlo, Michael J. Computational Geometry and Computer Graphics in C++. Prentice Hall, 1996.

Magnenat−Thalmann, Nadia and Daniel Thalmann. Image Synthesis: Theory and Practice. Springer−Verlag, 1987.

Moller, Tomas. Real−Time Rendering, A. K. Peters Ltd, 1999.

Mortenson, Michael. Computer Graphics: An Introduction to the Mathematics and Geometry. Industrial Press, 1989.

Neider, Jackie, et al. OpenGL Programming Guide. Addison−Wesley, 1994. OpenGL ARB OpenGL Reference Manual. Addison−Wesley, 1994.

O'Rourke, Joseph. Computational Geometry in C. Cambridge University Press, 1994. Robinson, Mathew et al. Swing, Manning Publications, 1999.

Rogers, David F. and J. Alan Adams. Mathematical Elements for Computer Graphics, 2nd Ed. McGraw−Hill, 1990.

Rogers, David and Rae Earnshaw (ed.). State of the Art in Computer Graphics: Visualization and Modeling. Springer−Verlag, 1991.

Sowizral, Henry, et al. The Java 3D API Specification. Addison−Wesley, 2000. Vince, John. 3D Computer Animation. Addison−Wesley, 1992.

Watt, Alan. 3D Computer Graphics, 2nd ed. Addison−Wesley, 1993.

Watt, Alan, et al. 3D Games, Volume 1: Real−time Rendering and Software Technology. Addison−Wesley, 2000.

Watt, Alan et al. Advanced Animation and Rendering Techniques. Addison−Wesley, 1993. Wolberg, George. Digital Image Warping, IEEE Computer Science Press, 1990.

Woo, Mason, et al. OpenGL Programming Guide, 3rd Ed., Addison−Wesley, 1999. Wright, Richard S. Jr., et al. OpenGL Super Bible, 2nd Ed., Waite Group, 1999.

[previous] | [main]