CHAPTER 2 3D graphics programming 2.1 Learning 3D
CHAPTER 2 3D graphics programming 2.1 Learning 3D graphics programming 2.2 Projecting from 3D world coordinates to 2D screen coordinates 2.3 Lighting effects 2.4 Putting it together MyJava3D 2.5 Summary 3D graphics programming is a fairly complex topic, worthy of a book unto itself (and there are many), but this introduction should serve as a good roadmap for further reading and give an appreciation for what Java 3D and your OpenGL or DirectX drivers are doing behind the scenes. In this chapter, I describe some of the fundamental underlying graphics techniques that allow a computer to transform a 3D scene description into a rendered image. I ll explain much of the needed terminology; however, if you need more information, I recommend the online 3D graphics glossaries from Mondo Media (http://www.mondomed.com/mlabs/glossary.html), 3Dgaming.com (http://www.3dgaming.com/fps/techshop/glossary/), and Chalmers Medialab (http://oss.medialab.chalmers.se/dictionary/). 2.1 Learning 3D graphics programming Given the enormous variety of teaching and learning styles, there probably is no best way of teaching 3D graphics programming. I learned 3D graphics programming by experimenting. I wrote my first 3D graphics program about 10 years ago. It was written in C and ran on my venerable Intel 80386 with a whole 256 KB of RAM! Needless to say, it didn t use Java 3D or OpenGL. The program was a modified port of a simple BASIC program that I “borrowed” from a simple little BASIC programming book. I later ported the program to run on Solaris using the GKS rendering API. The program was a very simple wire frame 3D model viewer and editor. You could load 3D shapes described using ASCII text files and then display them on screen. You could also interactively rotate the shapes about one axis. Times have certainly changed. The interesting thing about my first 3D effort is that I built upon my general programming knowledge and some simple 2D rendering techniques, such as drawing a line to the screen. That s what we ll do here. In this chapter, we will turn the clock back 10 years and build some sections of that program all over again, this time using Java, Java 2D, and some of the Java 3D utilities. This should remove some of the mystery from the operations performed by 3D graphics libraries like Java 3D and OpenGL. At the end of the day, we are simply converting from 3D coordinates to 2D coordinates and drawing a bunch of points and lines. We can use the source code as a basis for introducing the basics of 3D graphics programming and highlight some of the fundamental operations that a graphics library such as Java 3D provides. By looking at the example, you ll see the additional operations that a real graphics API provides, and that our homegrown, primitive API does not. To begin, look at the output from a simple Java 3D program and compare it with the test-bed application MyJava3D. Figure 2.1 was rendered by a simple Java 3D program (the LoaderTest example), which loads a 12
Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Java Web Hosting services