Java Programing

May 3, 2007

Figure 2.6 MyJava3D rendering without light intensity calculations

Filed under: Java 3D Programming — webmaster @ 8:26 am

Figure 2.6 MyJava3D rendering without light intensity calculations The computeIntensitymethod calculates the color intensity to use when rendering a triangle. It accepts a GeometryArraycontaining the 3D points for the geometry, an index that is the first point to be rendered, and a count of the number of points (vertices) that compose the item to be rendered. The method then computes the average normal vector for the points to be rendered by inspecting the normal vectors stored within the GeometryArray. For a triangle (three vertices) this will be the vector normal to the plane of the surface. The angle between the surface normal and the viewer is then calculated (beta). If the cosine of this angle is less than or equal to zero, the facet cannot be seen by the viewer and an intensity of zero will be returned. Otherwise, the method computes the angle between the light source position vector and the surface normal vector of the surface (theta). If the cosine of this angle is less than or equal to zero, none of the light from the light source illuminates the surface, so its light intensity is set to that of the ambient light. Otherwise, the surface normal vector is multiplied by the cosine of theta, the resulting vector is normalized, and then the light vector subtracted from it and the resulting vector normalized again. The angle between this vector and the viewer vector (alpha) is then determined. The intensity of the surface is the sum of the ambient light, the diffuse lighting from the surface multiplied by the cosine of the theta, and the specular light from the surface multiplied by the cosine of alpha raised to the glossiness power. The last term is the Phong shading, which creates the highlights that are seen in illuminated curved objects. Note that in this simple MyJava3D example only one light is being used to illuminate the scene in Java3D, OpenGL, or Direct3D many lights can be positioned within the scene and the rendering engine will compute the combined effects of all the lights on every surface. Please refer to chapter 10 for a further discussion of lighting equations and example illustrations created using Java 3D. From AwtRenderingEngine.java private int computeIntensity( GeometryArray geometryArray, int index, int numPoints ) { int intensity = 0; if ( computeIntensity != false ) { 20

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Tomcat Web Hosting services

No Comments

No comments yet.

RSS feed for comments on this post. TrackBack URI

Sorry, the comment form is closed at this time.

Powered by Java Web Hosting