Java程序辅导

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

客服在线QQ:2653320439 微信:ittutor Email:itutor@qq.com
wx: cjtutor
QQ: 2653320439
The University of Melbourne
Department of Computer Science and Software Engineering
433-380 Graphics and computation
Lab 2
held in ICT 1.08 (during your normal tutorial time)
To be done in pairs
Aim
The purpose of this laboratory excercise is:
• For you to practice programming in OpenGL and JOGL
• For you to gain understanding of lighting and surface geometry issues in OpenGL
• For you to get a start on some issues you will face in the project
The Task
Download and run the Java code for Lesson 5 (Lab2.java) of the nehe tutorials from the 380 project
resources web page under the directory nehe tutorials. Note the differences between this code and
your solution to Lab 1. Notice that the objects do not display as required — they are supposed to
look like those in Lab 1.
Your task will be to add a (visible) light source (e.g. a “sun”), and properties to the objects so that
they display in colour with lighting effects.
Specifically, the light source should:
• Have an ambient property which leaves surfaces not in the light dimmed (gl.GL AMBIENT)
• Have a diffuse property which illuminates faces pointing toward the light source (gl.GL DIFFUSE)
• Be “visible”, possibly by adding a nearby object (lit by the light source) that seems to simulate
it. You may wish to make use of the following code which draws a circle in OpenGL:
int i;
float cosine, sine;
gl.glBegin(gl.GL_POLYGON);
for (i=0;i<100;i++) {
cosine = (float) Math.cos(i*2*Math.PI/100.0);
sine = (float) Math.sin(i*2*Math.PI/100.0);
gl.glVertex3f(cosine,sine,0.0f);
}
gl.glEnd();
You have now seen two new techniques for drawing polygons in OpenGL.
Specifically, the objects should:
• Have a material property instead of the Color3f property (gl.glMaterialfv)
• Have a normal property that is calculated from the given points (gl.glNormal3fv)
You can find information on all of these properties in the JOGL javadoc API or the Red Book —
both linked from the subject web page.
Surface normals should be calculated (at least) once per face1. You may find the method described
in Foley et al. useful, or online resources such as Wikipedia (http://www.wikipedia.org).
Foley et al., the JOGL javadoc, and the Red Book should be sufficient to complete this exercise, but
you may find other resources (including your tutor) valuable.
The geometry of these figures is intentionally simple, so that you can make sure (using System.out.println)
that your surface normal calculations are correct.
Being able to calculate surface normals and set up the lighting will be important steps in Project 1.
1You may choose to try to calculate vertex normals, as mentioned in the lectures — but this may be difficult in
the time frame of the lab.