Black Art of Java Game Programming PHẦN 10 doc

100 272 0
Black Art of Java Game Programming PHẦN 10 doc

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

Black Art of Java Game Programming:Sources of Java Information Black Art of Java Game Programming by Joel Fan Sams, Macmillan Computer Publishing ISBN: 1571690433 Pub Date: 11/01/96 Table of Contents Appendix C: Sources of Java Information The Internet The Internet, of course, is an unequaled fount of information about Java. Check out the Web sites and newsgroups that specialize in Java. Java Web Sites There are an incredible number of Web sites with information about Java. Here are just a few Web sites to get you started: • http://java.sun.com/. This site has the latest, definitive Java news and documentation. • http://www.javaworld.com/. This is the site of a popular Java magazine. • http://www.gamelan.com/. This site is a searchable directory of Java applets from around the Web. • http://www.io.org/∼mentor/. This site maintains a newsletter devoted to Java issues. • http://cafe.symantec.com/, http://www.borland.com/, http://www.microsoft.com/. Symantec, Borland, and Microsoft are three companies that have created Java development environments. Java Newsgroups Sometimes, the fastest way to resolve a question about Java (or anything else) is to post the question to a newsgroup. Start with the series of newsgroups under comp.lang.java, such as • comp.lang.java • comp.lang.java.api • comp.lang.java.programmer • comp.lang.java.security • comp.lang.java.tech file:///D|/Downloads/Books/Computer/Java/Blac f%20Java%20Game%20Programming/appendix-c.html (1 von 2) [13.03.2002 13:21:15] Black Art of Java Game Programming:Sources of Java Information Sound and Image Resources There are numerous archives of public-domain sounds and images on the Internet that you can use in your games. As of this writing, Java supports .au files (U-LAW audio format) recorded at 8 bits with an 8KHz sampling rate. Attempts to use other audio file formats, or even .au files with different sampling rates, can cause your program to crash! Similarly, images should be in the GIF format to ensure maximum portability of your games. Here are some sites with sound and image resources: • To convert between sound file formats, use a utility such as SoX (Sound Exchange). SoX can be obtained at http://www.spies.com/Sox/. SoX works on UNIX and PC platforms. • The Net has many shareware image editors that allow you to convert between all kinds of image file formats. One of the best is Lview, available at http://world.std.com/%7Emmedia/lviewp.html/. Lview lets you save images in the GIF89a format, which allows you to specify a transparent color for your bitmap. Lview is available for PCs. • A good place to get public domain sound and image files is http://sunsite.unc.edu/pub/multimedia/. Again, remember to convert what you download to the appropriate Java-compatible format. • Another interesting multimedia site is somewhere in Poland, http://info.fuw.edu.pl/multimedia.html. Of course, this list is just a microscopic sample of what’s out there. Search the Net and you’ll find many more resources! Table of Contents file:///D|/Downloads/Books/Computer/Java/Blac f%20Java%20Game%20Programming/appendix-c.html (2 von 2) [13.03.2002 13:21:15] Black Art of Java Game Programming:Basic JDK Tools Black Art of Java Game Programming by Joel Fan Sams, Macmillan Computer Publishing ISBN: 1571690433 Pub Date: 11/01/96 Table of Contents Appendix D: Basic JDK Tools The Java Developer’s Kit (JDK) consists of the following programs: • javac. This program is the Java compiler that compiles source files written in the Java language to bytecodes. • java. This program is the Java interpreter that runs Java programs. • jdb. This tool is the Java debugger that helps you track down bugs in Java programs. • javah. This tool allows you to interface Java code with programs written in other languages. • javap. This tool disassembles compiled Java bytecodes. • javadoc. This program creates HTML documentation for Java source code. • appletviewer. This program allows you to execute applets without using a Web browser. The following sections cover selected details of the javac, java, and appletviewer commands. You will find the complete JDK documentation at the URL http://java.sun.com/. javac - The Java Compiler javac compiles Java source code. Synopsis javac [options] filename.java Description The javac command compiles Java source code into bytecodes that can be executed by the Java interpreter. The source files must have the .java extension, and each compiled class is stored in a corresponding .class file. For example, the bytecodes for a class called Murder are stored in the file Murder.class. file:///D|/Downloads/Books/Computer/Java/Blac f%20Java%20Game%20Programming/appendix-d.html (1 von 5) [13.03.2002 13:21:15] Black Art of Java Game Programming:Basic JDK Tools If a referenced class is not defined within the source files passed to javac, then javac searches the classpath for this class. The classpath is specified by the CLASSPATH environment variable, or the - classpath option. Options Following are some options you can place on the command line when invoking javac. -classpath path This option specifies the path that javac uses to find classes. Specifying the classpath with this option overrides the CLASSPATH environment variable. For UNIX machines, directories in the path are delimited by colons, as in the following: /escape/users/fan/classes:/usr/local/java/classes:. For Windows machines, directories in the path are delimited by semicolons: C:\ira\programs\java\classes;C:\tools\java\classes;. -d directory This option specifies the root directory where the .class files are saved. By default, javac saves .class files in the current directory. -O This option optimizes the compiled code by inlining static, final, and private methods. You should use this option when compiling your games; however, keep in mind that the resulting .class files may be larger in size. In addition, versions of some browsers may not work correctly with optimized code. -verbose With this option, the compiler prints the files being compiled and the class files that are loaded. Environment Variables The CLASSPATH environment variable specifies the path that javac uses to find user-defined classes. Directories are separated by colons (UNIX) or semicolons (Windows). See the -classpath option above for examples of paths. java - The Java Interpreter file:///D|/Downloads/Books/Computer/Java/Blac f%20Java%20Game%20Programming/appendix-d.html (2 von 5) [13.03.2002 13:21:15] Black Art of Java Game Programming:Basic JDK Tools java executes Java programs. Synopsis java [options] classname <args> Description The java command executes the Java bytecodes found in classname.class. The source file for classname.class must include a main() method, from which execution starts (see Chapter 1/Three Sample Applications for further details). The CLASSPATH environment variable, or the -classpath option, specifies the location of user- defined classes. Options Following are some options you can place on the command line when invoking java. -cs, -checksource This option tells java to compare the modification time of the compiled class file to that of the source file. If the source file is more recent, it is recompiled, and the resulting class file is loaded and executed. -classpath path This option specifies the path that javac uses to find classes. Specifying the classpath with this option overrides the CLASSPATH environment variable. For UNIX machines, directories in the path are delimited by colons, as in the following: .:/escape/users/fan/classes:/usr/local/java/classes For Windows machines, directories in the path are delimited by semicolons: .;C:\ira\programs\java\classes;C:\tools\java\classes -noasyngc This option turns off asynchronous garbage collection. Thus, the garbage collector executes only when it is called explicitly or the program runs out of memory. Normally, it runs concurrently with the program as a separate thread. file:///D|/Downloads/Books/Computer/Java/Blac f%20Java%20Game%20Programming/appendix-d.html (3 von 5) [13.03.2002 13:21:15] Black Art of Java Game Programming:Basic JDK Tools -noverify This option turns off the bytecode verifier. -v, -verbose This option tells java to print a message to standard output each time a class file is loaded. -verify This option tells the bytecode verifier to check all classes that are loaded. Environment Variables The CLASSPATH environment variable specifies the path that java uses to find user-defined classes. Directories are separated by colons (UNIX) or semicolons (Windows). See the -classpath option above for examples of paths. appletviewer - The Java Applet Viewer appletviewer executes Java applets. Synopsis appletviewer urls Description The appletviewer loads, displays, and executes each applet referenced by the documents found at the specified URLs. The applets are referenced using the APPLET tag (see the Applet Tags section in Appendix A for more information). Each applet is displayed in its own window. Environment Variables The CLASSPATH environment variable specifies the path that appletviewer uses to find user-defined classes. Directories are separated by colons (UNIX) or semicolons (Windows), as with the java and javac commands. If CLASSPATH is not set, the appletviewer searches for classes in the current directory and the system classes. appletviewer does not support the -classpath option found in java and javac. file:///D|/Downloads/Books/Computer/Java/Blac f%20Java%20Game%20Programming/appendix-d.html (4 von 5) [13.03.2002 13:21:15] Black Art of Java Game Programming:Basic JDK Tools Table of Contents file:///D|/Downloads/Books/Computer/Java/Blac f%20Java%20Game%20Programming/appendix-d.html (5 von 5) [13.03.2002 13:21:15] Black Art of Java Game Programming:3D Transforms (Calin Tenitchi) Black Art of Java Game Programming by Joel Fan Sams, Macmillan Computer Publishing ISBN: 1571690433 Pub Date: 11/01/96 Table of Contents Appendix E: 3D Transforms This chapter provides supplemental information to augment your understanding of the math and 3D concepts introduced in Chapter 11, Into the Third Dimension, and Chapter 12, Building 3D Applets with App3Dcore. We will kick-start the process of understanding 3D by making 3D rotations with an informal discussion of rotating points from 2D to 3D. Rotating Points in 3D The step from rotating a two-dimensional point in a plane to rotating a three-dimensional point in a volume is not as painful as it first might seem. When working in two dimensions, we use a coordinate system that is made of two axes, x and y. These two axes make a plane that can be compared to a piece of paper. This plane is called the “x-y plane”, since it is defined by the two principal axes, as shown in Figure E-1. Figure E-1 A two-dimensional coordinate system A point can be placed anywhere within the bounds of the plane by simply specifying x and y and then rotated by “turning” the whole plane. Imagine putting your hand on the paper and then turning it. What you should see is that the axes remain in the same position while the point follows the paper. Listing E-1 gives the formula for rotating a point in the x-y plane. Listing E-1 Rotating a point by theta radians counterclockwise in an x-y plane Xnew = X*Math.cos(theta)-Y*Math.sin(theta) Ynew = X*Math.sin(theta)+Y*Math.cos(theta) Moving to the third dimension is done by adding the z-axis. This new axis turns the two-dimensional plane into a volume, and points can be placed anywhere within it by specifying the x, y, and z coordinates. The difference between 2D and 3D is that the z-axis introduces two new principal planes: the y-z and z-x planes. The point shown in Figure E-2 can be rotated by turning any of the three principal planes. A full 3D rotation is done by rotating one plane at a time by a specified angle. file:///D|/Downloads/Books/Computer/Java/Bla %20Java%20Game%20Programming/appendix-e.html (1 von 22) [13.03.2002 13:21:26] Black Art of Java Game Programming:3D Transforms (Calin Tenitchi) Figure E-2 A 3D coordinate system Another way of looking at rotation in 3D is to imagine that you grab one of the axes with your thumb and index finger and turn it. You should “see” that the points rotate about the axis that you are turning while the other axes stand still. Looking at Figure E-1 again, you could also imagine that there is a z-axis pointing out from the paper and that a rotation in two dimensions is done by turning it. Therefore, you could think of a two-dimensional rotation as rotation about an imaginary z-axis. A 3D Rotation Step by Step Let’s go through the three steps that will rotate a point about all three axes. Step 1. Rotating About the Z-Axis This rotation is done in the x-y plane, and it is exactly the same as in the two-dimensional case. The source coordinates X and Y are transformed to Xa and Ya while Z remains the same. This is shown in Figure E-3. Figure E-3 Rotating about the z-axis or in the x-y plane The resulting point Xa, Ya, Za will be used as the source point for the next rotation. Step 2. Rotating About the X-Axis The next rotation would be about the x-axis. What we actually do is rotate the point in the y-z plane. Another way of looking at it is as a two-dimensional rotation, but with Y and Z as principal axes (see Figure E-4). Figure E-4 Rotation about the x-axis or in the y-z plane (two ways of looking at it) file:///D|/Downloads/Books/Computer/Java/Bla %20Java%20Game%20Programming/appendix-e.html (2 von 22) [13.03.2002 13:21:26] Black Art of Java Game Programming:3D Transforms (Calin Tenitchi) Step 3. Rotating About the Y-Axis Using the resulting point from the last operation, the final transformation is made in the same way as described above, and the full 3D rotation is complete, as shown in Figure E-5 and Listing E-2. x c =x b ·cosc+z b ·sinc y c =y b z c =-x b ·sinc+z b ·cosc Listing E-2 Rotating a point in 3D // X,Y,Z will be rotated by a,b,c radians about all principal // axis. The result will be stored in Xnew, Ynew, Znew. // rotate the point in x-y-plane and store the result in // Xa,ya,Za. Xa = X*Math.cos(a)-Y*Math.sin(a); Ya = X*Math.sin(a)+Y*Math.cos(a); Za = Z; // z coordinate is not affected by this rotation // rotate the resulting point in the y-z-plane Xb = X; // x coordinate is not affected by this rotation Yb = Y*Math.cos(b)-Z*Math.sin(b); Zb = Y*Math.sin(b)+Z*Math.cos(b); // rotate the resulting point in the z-x-plane Xc = X*Math.cos(c)+Z*Math.sin(c); Yc = Y; // z coordinate is not affected by this rotation Zc = -X*Math.sin(c)+Z*Math.cos(c); Xnew = Xc; Ynew = Yc; Znew = Zc; Figure E-5 Rotation in the z-x plane Creating a Rotating Points Applet Just to see that this is actually working, Figure E-6 and Listing E-3 show an applet that spins a number of random 3D points around. Listing E-3 Rotating points file:///D|/Downloads/Books/Computer/Java/Bla %20Java%20Game%20Programming/appendix-e.html (3 von 22) [13.03.2002 13:21:26] [...]... and the implementation is very straightforward Table of Contents file:///D|/Downloads/Books/Computer /Java/ Bl 2 0Java% 2 0Game% 2 0Programming/ appendix-e.html (22 von 22) [13.03.2002 13:21:26] Black Art of Java Game Programming: Index Black Art of Java Game Programming by Joel Fan Sams, Macmillan Computer Publishing ISBN: 1571690433 Pub Date: 11/01/96 Table of Contents Index Symbols + (plus sign), string concatenation,... file:///D|/Downloads/Books/Computer /Java/ Bl 2 0Java% 2 0Game% 2 0Programming/ appendix-e.html (10 von 22) [13.03.2002 13:21:26] Black Art of Java Game Programming: 3D Transforms (Calin Tenitchi) normal to the plane that V1 and V2 make, as seen in Figure E-20 This “feature” will be used to calculate the normal of a polygon Figure E-20 Calculating the normal of a plane The Value of Cross Product Cross product is... Algebra Basics file:///D|/Downloads/Books/Computer /Java/ Bla %2 0Java% 2 0Game% 2 0Programming/ appendix-e.html (5 von 22) [13.03.2002 13:21:26] Black Art of Java Game Programming: 3D Transforms (Calin Tenitchi) Computer graphics algorithms make use of many mathematical concepts and techniques This section will provide a description of some of the basic notions of linear algebra Since almost all 3D transformations... 834-840 java. awt, 841-846 java. lang, 846-856 App3Dcore building applications bouncing boxes, 447-455 collisions and object interations, 455-458 creating game layer, 461 classes, 463-471 workings, 462-463 file:///D|/Downloads/Books/Computer /Java/ Bla %2 0Java% 2 0Game% 2 0Programming/ book-index.html (6 von 71) [13.03.2002 13:21:33] Black Art of Java Game Programming: Index description, 443 implementing games,... methods starting with “concat” are actually selective matrix multiplications What this means is that only the elements that are affected are recalculated, saving lots of time /** * A 3d matrix that hides the making of the different * transforms file:///D|/Downloads/Books/Computer /Java/ Bl 2 0Java% 2 0Game% 2 0Programming/ appendix-e.html (20 von 22) [13.03.2002 13:21:26] Black Art of Java Game Programming: 3D... Figure E -10 file:///D|/Downloads/Books/Computer /Java/ Bla %2 0Java% 2 0Game% 2 0Programming/ appendix-e.html (6 von 22) [13.03.2002 13:21:26] Black Art of Java Game Programming: 3D Transforms (Calin Tenitchi) Figure E -10 A vector is defined as the difference between two points A vector can be described as a directed line segment that has two properties: magnitude and direction Magnitude is the length of the... method, handling menu actions, 255 closing, 208- 210 communicating killed messages, 202 cursor settings, 252 customizing file:///D|/Downloads/Books/Computer /Java/ Bla %2 0Java% 2 0Game% 2 0Programming/ book-index.html (3 von 71) [13.03.2002 13:21:32] Black Art of Java Game Programming: Index applet parameters, 263-264 customization Dialog, 256-261 GameFrame, 252, 258-259 GameFrame Container, 253-254 handling menu... UFOSprite class, 182-183 Video Game loop, 157-158 aligning text (threads), 383-384 alignments BorderLayout, 247 FlowLayout, 246 animatedIntroClass (Daleks! game ), 594 object, 596 setInfo( ) method, 597 file:///D|/Downloads/Books/Computer /Java/ Bla %2 0Java% 2 0Game% 2 0Programming/ book-index.html (5 von 71) [13.03.2002 13:21:33] Black Art of Java Game Programming: Index start( ) method, 598 animateIntro... appendix It is done in the following way: file:///D|/Downloads/Books/Computer /Java/ Bl 2 0Java% 2 0Game% 2 0Programming/ appendix-e.html (11 von 22) [13.03.2002 13:21:26] Black Art of Java Game Programming: 3D Transforms (Calin Tenitchi) The result of this operation is a vector of the same size as the operand There is another way of looking at this operation, though Suppose that the rows in the matrix are seen... order to show that a 4x4 matrix is not harder to work with than a 3x3 matrix, Figure E-26 shows an example of a set of transforms expressed in one matrix file:///D|/Downloads/Books/Computer /Java/ Bl 2 0Java% 2 0Game% 2 0Programming/ appendix-e.html (17 von 22) [13.03.2002 13:21:26] Black Art of Java Game Programming: 3D Transforms (Calin Tenitchi) Figure E-26 Source and destination As you can see, this transformation . Black Art of Java Game Programming: Sources of Java Information Black Art of Java Game Programming by Joel Fan Sams, Macmillan Computer Publishing. Interpreter file:///D|/Downloads/Books/Computer /Java/ Blac f%2 0Java% 2 0Game% 2 0Programming/ appendix-d.html (2 von 5) [13.03.2002 13:21:15] Black Art of Java Game Programming: Basic JDK Tools java executes Java programs. Synopsis java [options]. Table of Contents file:///D|/Downloads/Books/Computer /Java/ Blac f%2 0Java% 2 0Game% 2 0Programming/ appendix-c.html (2 von 2) [13.03.2002 13:21:15] Black Art of Java Game Programming: Basic JDK Tools Black

Ngày đăng: 12/08/2014, 09:21

Từ khóa liên quan

Mục lục

  • Black Art Of Java Game Programming

    • Black Art of Java Game Programming:Sources of Java Information

    • Black Art of Java Game Programming:Basic JDK Tools

    • Black Art of Java Game Programming:3D Transforms (Calin Tenitchi)

    • Black Art of Java Game Programming:Index

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan