Consider the simplest series of operations that must
Consider the simplest series of operations that must take place to convert the 3D model data into a rendered image: 1. Load the 3D points that compose the vertices (corners) of each triangle. The vertices are indexed so they can be referenced by index later. 2. Load the connectivity information for the triangles. For example, a triangle might connect vertices 2, 5, and 7. The actual vertex information will be referenced using the information and indices established in step 1. 3. Perform some sort of mathematical conversion between the 3D coordinates for each vertex and the 2D coordinates used for the pixels on the screen. This conversion should take into account the position of the viewer of the scene as well as perspective. 4. Draw each triangle in turn using a 2D graphics context, but instead of using the 3D coordinates loaded in step 1, use the 2D coordinates that were calculated in step 3. 5. Display the image. That s it. Steps 1, 2, 4, and 5 should be straightforward. Steps 1 and 2 involve some relatively simple file I/O, while steps 4 and 5 use Java s AWT 2D graphics functions to draw a simple line into the screen. Step 3 is where much of the work takes place that qualifies this as a 3D application. In fact, in the MyJava3D example application, we cheat and use some of the Java 3D data structures. This allows us to use the existing Lightwave OBJ loader provided with Java 3D to avoid doing the tiresome file I/O ourselves. It also provides useful data structures for describing 3D points, objects to be rendered, and so on. 2.2 Projecting from 3D world coordinates to 2D screen coordinates Performing a simple projection from 3D coordinates to 2D coordinates is relatively uncomplicated, though it does involve some matrix algebra that I shan t explain in detail. (There are plenty of graphics textbooks that will step you through them in far greater detail than I could here.) There are also many introductory 3D graphics courses that cover this material online. A list of good links to frequently asked questions (FAQs) and other information is available from 3D Ark at http://www.3dark.com/resources/faqs.html. If you would like to pick up a free online book that discusses matrix and vector algebra related to 3D graphics, try Sbastien Loisel s Zed3D, A compact reference for 3D computer graphics programming. It is available as a ZIP archive from http://www.math.mcgill.ca/~loisel/. If you have some money to spend, I would recommend picking up the bible for these sorts of topics: Computer Graphics Principles and Practice, by James Foley, Andries van Dam, Steven Feiner, and John Hughes (Addison-Wesley, 1990). 2.2.1 A simple 3D projection routine Here is my simple 3D-projection routine. The projectPointmethod takes two Point3dinstances, the first is the input 3D-coordinate while the second will be used to store the result of the projection from 3D to 2D coordinates (the z attribute will be 0). Point3dis one of the classes defined by Java 3D. Refer to the Java 3D JavaDoc for details. Essentially, it has three public members, x, y, and z that store the coordinates in the three axes. 14
Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Tomcat Web Hosting services