Computer Graphics - OpenGL Assignment

paltryboarpigΛογισμικό & κατασκευή λογ/κού

3 Νοε 2013 (πριν από 3 χρόνια και 7 μήνες)

83 εμφανίσεις

Matthew Bates

cwwp64

24/02
/2012

Computer Graphics
-

OpenGL Assignment

Implementation

Modelling

The modelling of the 3D objects was done using Blender. Once the vertex mesh was created, Blender was also used
to UV map textures to faces, providing texture coordinates and normal values. I
used the OBJ file format because it
was lightweight and easy to parse
. On exporting from Blender, I checked the triangulate faces option to ensure that
each face would definitely be defined as a triangle and so that GL_TRIANGLES could be used later. I wrot
e a simple
parser to take an OBJ file and produce a list of faces representing a model. The Face class represents a single 3
-
dimensional triangle with an associated texture. Using Blender provided an easy way to create models with textures
and normals incl
uded and because the models are separate from the program, models can easily be changed or
replaced.

Each 3D model is rendered, using glNormal, gl
TexCoord

and then glVertex through the drawObject method which
takes a list of faces as a parameter.

Texturing

Before each face is rendered, its associated texture as specified in the face object is bound to the GL context so that
the texture will be mapped to the next set of vertices drawn. The texture files are, in most, created by myself using
image manipulatio
n software, although the space texture in the background is taken from a Google Image Search :
-

http://farm3.staticflickr.com/2444/4081217898_b7bae8fdba_z.jpg?zz=1
.

Lighting

The program includes global ambient light, a two point lights. These are situated
at both the front and back of the
scene to provide adequate lighting on both sides of the car.

Movement

There are 3 moving parts in the system. The car itself can ‘drive’ around the track, which in turn causes the wheels to
rotate. The doors can also be op
ened, which swing on a ‘hinge’. The view of the scene can also be manipulated to
look at the model from different angles.

Track

The shape of the track is calculated using geometry rather than a model from Blender. Varying alpha values are used
to create th
e transparent effect on the track a
nd the colours are allocated by cycling through an array.

Hot Keys

Up
-

drives the car forward

W
-

increase x axis rotation

F
-

maximise screen

Down
-

reverses the car backward

S
-

decrease x axis rotation

Esc
-

close
the program

Left
-

rotates the scene clockwise

A
-

decrease z axis rotation

+

or
MouseWheel
-

zoom in

Right
-

rotates the scene counter
-
clockwise

D
-

increase z axis rotation

-

or
MouseWheel
-

zoom out

Views



Track Mode
-

Renders a simple environment and places the car on a track. The user is able to drive the car
around the
circular
track, open the car doors and rotate the scene.



View Mode
-

Renders the model without any environment

and places the model close to the camera
. The
model can be rotated freely in this view.

Matthew Bates

cwwp64

24/02
/2012



Figure 1
-

screenshot of the track mode

Figure 2
-

screenshot of the view mode


Limitations & Improvements

Although the low vertex count means that the application generally runs smoothly, the
efficiency isn’t great. Using
vertex buffers, display lists or even triangle strips would improve the frame rate
. Using a lower level language such as
C or C++ also could have improved performance.

Some physics features such as acceleration and drift would

have been nice to give the car a more realistic feel. Better
yet, a game engine, to allow a better interactive experience would have been excellent.

I would have liked to have made the windows of the car transparent, but transparency was already used in g
eneration
of the road so it didn’t seem necessary. Because the windows are textured, the blend function would have to change
to
glBlendFunc
(
GL_ONE, GL_ONE)

rather
than
glBlendFunc
(
GL_SRC_ALPHA
,
GL_ONE_MINUS_SRC_ALPHA).

Installation

To run the program, you
need to import the Computer Graphics folder into a new Eclipse Project. The JOGL jar
files are located in lib folder and are on the build path of the project. The system dependant libraries are located in the
root of the folder and may have to be replaced
with the dlls which match your system.

Also ensure that the img and
obj folders are within reach of the classpath.

References


15 Transparency, Translucency, and Blending
.

(2006 , March 16). Retrieved February 2012, from OpenGl.org:
http://ww
w.opengl.org/resources/faq/technical/transparency.htm

Angel, E. (2007).
OpenGL: A Primer

(3rd ed.). Addison
-
Wesley.

NeonHelium Productions. (n.d.).
NeHe Productions
.

Retrieved February 2012, from NeHe Productions:
http://nehe.gamedev.net/

Shreiner, D. (2009).
OpenGL Programming Guide

(7th ed.). Addison
-
Wesley.

Software Libraries

JOGL
-

Java binding for OpenGL
-

http://jogamp.org/jogl/www/