< Zurück | Inhalt | Weiter >

From AwtRenderingEngine.java


/**


* Definition of the RenderingEngine interface. A RenderingEngine

* can render 3D geometry (described using a Java 3D GeometryArray)


* into a 2D Graphics context.


*/


public interface RenderingEngine


{


/**


* Add a GeometryArray to the RenderingEngine. All GeometryArrays


* will be rendered.


*/


public void addGeometry( GeometryArray geometryArray );


/**


* Render a single frame into the Graphics.


*/


public void render( Graphics graphics, GeometryUpdater updater );


/**


* Get the current Screen position used by the RenderEngine.


*/


public Vector3d getScreenPosition();


/**


* Get the current View Angle used by the RenderEngine. View


* angles are expressed in degrees.


*/


public Vector3d getViewAngle();


/**


* Set the current View Angle used by the RenderEngine.


*/


public void setViewAngle( Vector3d viewAngle );

/**


* Get the current View Angle used by the RenderEngine. View


* angles are expressed in degrees.


*/


public Vector3d getLightAngle();


/**


* Set the current View Angle used by the RenderEngine.


*/


public void setLightAngle( Vector3d angle );


/**


* Set the Screen size used by the RenderEngine.


*/


public void setScreenSize( int width, int height );


/**


* Set the scale used by the RenderEngine.


*/


public void setScale( double scale );


/**


* Get the scale used by the RenderEngine.


*/


public double getScale();


}


image


The RenderingEngine interface is implemented by the AwtRenderingEngine class, which uses simple Graphics rendering calls (drawPolygon, setColor, drawLine, drawPoint) to render the 3D models.


The RenderingEngine instance is driven by a RenderingSurface, an instance of a JPanel that provides a Graphics object for its client area and receives the frames of the rendered scene. The RenderingSurface extends AnimatingSurface, which creates a rendering thread, and calls

repaint on the JPanel, forcing the scene to be continuously redrawn.


The Surface class, which is the base class for AnimatingSurface (both taken from Sun Java 2D demos), allows you to specify Java 2D rendering hints such as RenderingHints.VALUE_ANTIALIAS_OFF, which switches off antialiasing, and RenderingHints.VALUE_RENDER_SPEED, which tells the Graphics object to optimize for speed rather than rendering quality. It is interesting to see the effect of switching on antialiasing (figure 2.4 is on, figure 2.7 is off), as rendering APIs or 3D graphics hardware does not commonly support this functionality.


image


Figure 2.7 MyJava3D rendering with Java2D antialiasing enabled


The RotatingGeometryUpdater class is used to increase the X−angle of the viewer after each subsequent frame.