Java程序辅导

C C++ Java Python Processing编程在线培训 程序编写 软件开发 视频讲解

客服在线QQ:2653320439 微信:ittutor Email:itutor@qq.com
wx: cjtutor
QQ: 2653320439
CS293 Graphics, Lab 2, Elementary Animation Experiments
In the AP labs don't forget you need to set your environment path as in the first lab to point to a 
folder where the JOGL dll files are. Note, if you add any spaces immediately after a ';' in a path 
variable it does not work. Also, Java will not automatically detect where the files are. These labs 
are set up using NetBeans 5.0.
Use a web browser (preferably Firefox or Opera) to open the web page for the course:
http://www.computing.surrey.ac.uk/courses/cs288/graphics.html
Download these files from the course web site:
● Lab002_BasicAnimation.pdf
● doublebuf.zip
Fixing the JOGL library call
First uncompress the doublebuf.zip file in your CS293 course directory, or any folder where you 
want to keep lab code. Open the folder as a project in NetBeans. You should get error messages 
at this point as the JOGL library that is referred to in the project properties does not exist in your 
installation. 
Open the properties page for your project. 
Remove the reference to the JOGL library 
there (if there is one). Now add your 
JOGL library, which must be the one you 
set up in the previous lab. Return to the 
navigation pane, and you should now have 
an error free view of the code that 
compiles and executes.
Run the code and check that you see  a 
rotating torus.To make the torus rotate left 
click the mouse. To stop right click.
Open the doublebuf.java file in NetBeans. 
Note that this class extends other classes, 
and implements these interfaces:
● GLEventListener
● KeyListener
● MouseListener
doublebuf.java also extends the class glskeleton, which is an internal class within the project. Its 
job is to set up various default fields and methods that allow doublebuf to be relatively simple. 
This example is modified from a JOGL tutorial example by Kiet Le.
Rotate a torus.
The current application rotates a wire frame torus very badly because it does not use an 
appropriate glPushMatrix() and glPopMatrix(). Add these at the proper place so that the rotation 
is constant. Try changing the tor_simplex field and see what this does. Change the other 
parameters for the glutWireTorus command and see what effect it has.
Next change the rotation vector used in the gl.glRotatef(spin, 0.0f, 0.0f, 1.0f) command so that 
the torus rotates around a vector that is not the z axis.
Add a second torus next to the first. This will require using the glTranslatef command. Change 
the code so that only one of the tori rotates.
Add a third torus and then a small cube with glut.glutWireCube. Make all three tori be stationary 
and get the cube to rotate in such a way that it passes through the centre of one of the tori and 
then back round to the beginning. Let the cube have a circular orbit for this part of the exerrcise. 
Choose the centre of the orbit to be at the centre of the middle torus. Ensure that the orbit does 
not intersect any part of any torus.
To get this to work first simply get the cube rotating in a circle, then use trial and error to move 
this orbit to the right place. To achieve this you must aplly glRotated and glTranslated to the 
cube in some way. But you must make sure these transformations do not affect the tori.
Next keep the cube stationary and rotate all three tori, but so that they remain fixed relative to 
one another. Below is an image of how the three tori might look when lined up. An extra line has 
been added from the cube to the origin to give an idea of the translation needed.
Note this image has lighting added which you are not expected to do at this stage.
Only rotate your point of view.
As a final exercise for this lab, keep all the tori fixed and move only your point of view using the 
glu.gluLookAt command. First rotate your point of view in a circular orbit round the tori. Can 
you get the point of view to fly through one torus and then round over the top back to where it 
started in a circle?
What is most interesting, looking in the direction of flight or at the center of rotation?